Android Renderscript-旋转Renderscript中的YUV数据

Android Renderscript-旋转Renderscript中的YUV数据,android,renderscript,yuv,rgba,Android,Renderscript,Yuv,Rgba,基于我在上的讨论,我想知道如何调整通过rsGetElementAt_uchar方法完成的查找,以便将YUV数据旋转90度。 我也有一个像谷歌提供的项目。问题是输出是横向的,因为用作目标曲面的输出曲面连接到yuv分配,而yuv分配不关心设备是处于横向模式还是纵向模式。但我想调整代码,使其处于纵向模式。 因此,我使用了自定义的YUVToRGBA renderscript,但我不知道如何更改以旋转输出。 有人可以帮我将以下自定义YUVtoRGBA脚本调整90度,因为我想在纵向模式下使用输出: // N

基于我在上的讨论,我想知道如何调整通过rsGetElementAt_uchar方法完成的查找,以便将YUV数据旋转90度。 我也有一个像谷歌提供的项目。问题是输出是横向的,因为用作目标曲面的输出曲面连接到yuv分配,而yuv分配不关心设备是处于横向模式还是纵向模式。但我想调整代码,使其处于纵向模式。 因此,我使用了自定义的YUVToRGBA renderscript,但我不知道如何更改以旋转输出。 有人可以帮我将以下自定义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;
}
//RS工作所需的指令
#布拉格语版本(1)
//java_package_name指令需要使用活动的包路径
#pragma rs java_包_名称(net.hydex11.cameracaptureexample)
rs_分配输入分配;
英文欣;
整数整数像素;
//应用转换之前要调用的函数
void setInputImageSize(整数宽,整数高)
{
赢=_w;
欣=_h;
numTotalPixels=wIn*hIn;
}
//将YUV元素转换为RGBA元素的内核
uchar4_uuuuu属性_uuuuu((内核))转换(uint32_t x,uint32_t y)
{
//YUV 4:2:0平面图像,具有8位Y采样,后跟
//具有8位2x2次采样色度样本的交错V/U平面
int baseIdx=x+y*wIn;
int baseUYIndex=numTotalPixels+(y>>1)*wIn+(x&0xfffffe);
uchar _y=rsGetElementAt_uchar(输入分配,baseIdx);
uchar u=rsGetElementAt uuchar(输入分配,基本索引);
uchar _v=rsGetElementAt_uchar(输入分配,基本索引+1);
_y=_y<16?16:;
短Y=((短)Y)-16;
短U=((短)_)-128;
短V=((短)V)-128;
uchar4输出;
out.r=(uchar)卡箍((浮动)(
(Y*298+V*409+128)>>8)、0.f、255.f);
out.g=(uchar)卡箍((浮动)(
(Y*298-U*100-V*208+128)>>8)、0.f、255.f);
out.b=(uchar)卡箍((浮动)(
(Y*298+U*516+128)>>8)、0.f、255.f);//
out.a=255;
返回;
}
我在上找到了自定义脚本

有人将Java代码用于旋转YUV数据。但我想在Renderscript中执行,因为这样更快

任何帮助都会很好


非常感谢,

我假设您希望输出为RGBA格式,就像您的转换脚本一样。您应该能够使用类似于中使用的方法;也就是说,作为转换内核的第一步,只需修改x和y坐标:

//Rotate 90 deg clockwise during the conversion
uchar4 __attribute__((kernel)) convert(uint32_t inX, uint32_t inY)
{
    uint32_t x = wIn - 1 - inY;
    uint32_t y = inX;

    //...rest of the function
请注意对参数名称的更改


这假定您已正确设置输出尺寸(请参阅链接答案)。270度旋转也可以用类似的方法完成。

您是否尝试过将肖像模式图像输入脚本以查看发生了什么?不,我没有。为什么?是否已经为纵向模式进行了调整?似乎有一种方法可以设置输入图像的大小,所以是。@Haem:否,使用输入图像的大小,输出仍然是横向的。注意:我还没有测试这个解决方案。所以,我是否应该在convert()内核函数的开头放置两行
uint32\u t x=wIn-1-inY
uint32\u t y=inX