static uchar4 rsYuvToRGBA_uchar4()

in renderscript-toolkit/src/main/cpp/YuvToRgb.cpp [82:113]


static uchar4 rsYuvToRGBA_uchar4(uchar y, uchar u, uchar v) {
    int16_t Y = ((int16_t)y) - 16;
    int16_t U = ((int16_t)u) - 128;
    int16_t V = ((int16_t)v) - 128;

    short4 p;
    p.x = (Y * 298 + V * 409 + 128) >> 8;
    p.y = (Y * 298 - U * 100 - V * 208 + 128) >> 8;
    p.z = (Y * 298 + U * 516 + 128) >> 8;
    p.w = 255;
    if(p.x < 0) {
        p.x = 0;
    }
    if(p.x > 255) {
        p.x = 255;
    }
    if(p.y < 0) {
        p.y = 0;
    }
    if(p.y > 255) {
        p.y = 255;
    }
    if(p.z < 0) {
        p.z = 0;
    }
    if(p.z > 255) {
        p.z = 255;
    }

    return (uchar4){static_cast<uchar>(p.x), static_cast<uchar>(p.y),
                    static_cast<uchar>(p.z), static_cast<uchar>(p.w)};
}