【发布时间】:2019-09-01 23:15:32
【问题描述】:
根据我在Camera2 api Imageformat.yuv_420_888 results on rotated image 的讨论,我想知道如何调整通过 rsGetElementAt_uchar 方法完成的查找,以便 YUV 数据旋转 90 度。 我也有一个类似谷歌提供的HdrViewfinder 的项目。问题是输出是横向的,因为用作目标表面的输出表面连接到 yuv 分配,它不关心设备是处于横向还是纵向模式。但我想调整代码使其处于纵向模式。 因此,我采用了自定义 YUVToRGBA 渲染脚本,但我不知道要更改什么来旋转输出。 有人可以帮我将以下自定义 YUVtoRGBA 脚本调整 90 度,因为我想在纵向模式下使用输出:
// Needed directive for RS to work
#pragma version(1)
// The java_package_name directive needs to use your Activity's package path
#pragma rs java_package_name(net.hydex11.cameracaptureexample)
rs_allocation inputAllocation;
int wIn, hIn;
int numTotalPixels;
// Function to invoke before applying conversion
void setInputImageSize(int _w, int _h)
{
wIn = _w;
hIn = _h;
numTotalPixels = wIn * hIn;
}
// Kernel that converts a YUV element to a RGBA one
uchar4 __attribute__((kernel)) convert(uint32_t x, uint32_t y)
{
// YUV 4:2:0 planar image, with 8 bit Y samples, followed by
// interleaved V/U plane with 8bit 2x2 subsampled chroma samples
int baseIdx = x + y * wIn;
int baseUYIndex = numTotalPixels + (y >> 1) * wIn + (x & 0xfffffe);
uchar _y = rsGetElementAt_uchar(inputAllocation, baseIdx);
uchar _u = rsGetElementAt_uchar(inputAllocation, baseUYIndex);
uchar _v = rsGetElementAt_uchar(inputAllocation, baseUYIndex + 1);
_y = _y < 16 ? 16 : _y;
short Y = ((short)_y) - 16;
short U = ((short)_u) - 128;
short V = ((short)_v) - 128;
uchar4 out;
out.r = (uchar) clamp((float)(
(Y * 298 + V * 409 + 128) >> 8), 0.f, 255.f);
out.g = (uchar) clamp((float)(
(Y * 298 - U * 100 - V * 208 + 128) >> 8), 0.f, 255.f);
out.b = (uchar) clamp((float)(
(Y * 298 + U * 516 + 128) >> 8), 0.f, 255.f); //
out.a = 255;
return out;
}
Here有人放了Java代码来旋转YUV数据。但我想在 Renderscript 中进行,因为这样更快。
任何帮助都会很棒。
最好的问候,
【问题讨论】:
-
您是否尝试过仅将纵向模式图像输入脚本以查看会发生什么?
-
不,我没有。为什么 ?是否已经针对纵向模式进行了调整?
-
好像有设置输入图像大小的方法,所以是的。
-
@Haem:不,使用输入图像大小,输出仍然是横向的。
标签: android renderscript yuv rgba