首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android Renderscript -在Renderscript中旋转YUV数据

Android Renderscript -在Renderscript中旋转YUV数据
EN

Stack Overflow用户
提问于 2019-08-30 18:20:28
回答 1查看 468关注 0票数 0

基于我在Camera2 api Imageformat.yuv_420_888 results on rotated image上的讨论,我想知道如何调整通过rsGetElementAt_uchar方法完成的查找,从而使YUV数据旋转90度。我也有一个像谷歌提供的HdrViewfinder这样的项目。问题是输出是横向的,因为用作目标表面的输出表面连接到yuv分配,而yuv分配并不关心设备是处于横向模式还是纵向模式。但我想调整代码,使其处于纵向模式。因此,我采用了一个自定义的YUVToRGBA渲染脚本,但我不知道如何更改才能旋转输出。有没有人可以帮我把下面的自定义YUVtoRGBA脚本调整90度,因为我想在纵向模式下使用输出:

代码语言:javascript
复制
// 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;
}

我在https://bitbucket.org/cmaster11/rsbookexamples/src/tip/CameraCaptureExample/app/src/main/rs/customYUVToRGBAConverter.fs上找到了那个自定义脚本。

有人把Here的代码放到了旋转YUV数据的地方。但我想在Renderscript中完成,因为那样会更快。

任何帮助都是最好的。

诚挚的问候,

EN

回答 1

Stack Overflow用户

发布于 2019-09-01 23:15:33

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

代码语言:javascript
复制
//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度旋转也可以用类似的方式完成。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57724927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档