Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d08e981 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "C2 vp9, av1: Add support for conversion to RGBA1010102 for 10-bit...

Merge "C2 vp9, av1: Add support for conversion to RGBA1010102 for 10-bit decode" into tm-dev am: aa88108b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/18605040



Change-Id: If114377451b901fc6d2dd128d0664b87c39c349d
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 4b815198 aa88108b
Loading
Loading
Loading
Loading
+3 −4
Original line number Original line Diff line number Diff line
@@ -585,10 +585,9 @@ bool C2SoftAomDec::outputBuffer(
        const uint16_t *srcV = (const uint16_t *)img->planes[AOM_PLANE_V];
        const uint16_t *srcV = (const uint16_t *)img->planes[AOM_PLANE_V];


        if (format == HAL_PIXEL_FORMAT_RGBA_1010102) {
        if (format == HAL_PIXEL_FORMAT_RGBA_1010102) {
            convertYUV420Planar16ToY410((uint32_t *)dstY, srcY, srcU, srcV, srcYStride / 2,
            convertYUV420Planar16ToY410OrRGBA1010102(
                                    srcUStride / 2, srcVStride / 2,
                    (uint32_t *)dstY, srcY, srcU, srcV, srcYStride / 2, srcUStride / 2,
                                    dstYStride / sizeof(uint32_t),
                    srcVStride / 2, dstYStride / sizeof(uint32_t), mWidth, mHeight);
                                    mWidth, mHeight);
        } else {
        } else {
            convertYUV420Planar16ToYV12(dstY, dstU, dstV, srcY, srcU, srcV, srcYStride / 2,
            convertYUV420Planar16ToYV12(dstY, dstU, dstV, srcY, srcU, srcV, srcYStride / 2,
                                        srcUStride / 2, srcVStride / 2, dstYStride, dstUVStride,
                                        srcUStride / 2, srcVStride / 2, dstYStride, dstUVStride,
+120 −4
Original line number Original line Diff line number Diff line
@@ -137,7 +137,118 @@ void convertYUV420Planar16ToY410(uint32_t *dst, const uint16_t *srcY, const uint
        dst += dstStride * 2;
        dst += dstStride * 2;
    }
    }
}
}
#define CLIP3(min, v, max) (((v) < (min)) ? (min) : (((max) > (v)) ? (v) : (max)))
void convertYUV420Planar16ToRGBA1010102(uint32_t *dst, const uint16_t *srcY, const uint16_t *srcU,
                                        const uint16_t *srcV, size_t srcYStride, size_t srcUStride,
                                        size_t srcVStride, size_t dstStride, size_t width,
                                        size_t height) {
    // Converting two lines at a time, slightly faster
    for (size_t y = 0; y < height; y += 2) {
        uint32_t *dstTop = (uint32_t *)dst;
        uint32_t *dstBot = (uint32_t *)(dst + dstStride);
        uint16_t *ySrcTop = (uint16_t *)srcY;
        uint16_t *ySrcBot = (uint16_t *)(srcY + srcYStride);
        uint16_t *uSrc = (uint16_t *)srcU;
        uint16_t *vSrc = (uint16_t *)srcV;


        // BT.2020 Limited Range conversion

        // B = 1.168  *(Y - 64) + 2.148  *(U - 512)
        // G = 1.168  *(Y - 64) - 0.652  *(V - 512) - 0.188  *(U - 512)
        // R = 1.168  *(Y - 64) + 1.683  *(V - 512)

        // B = 1196/1024  *(Y - 64) + 2200/1024  *(U - 512)
        // G = .................... -  668/1024  *(V - 512) - 192/1024  *(U - 512)
        // R = .................... + 1723/1024  *(V - 512)

        // min_B = (1196  *(- 64) + 2200  *(- 512)) / 1024 = -1175
        // min_G = (1196  *(- 64) - 668  *(1023 - 512) - 192  *(1023 - 512)) / 1024 = -504
        // min_R = (1196  *(- 64) + 1723  *(- 512)) / 1024 = -937

        // max_B = (1196  *(1023 - 64) + 2200  *(1023 - 512)) / 1024 = 2218
        // max_G = (1196  *(1023 - 64) - 668  *(- 512) - 192  *(- 512)) / 1024 = 1551
        // max_R = (1196  *(1023 - 64) + 1723  *(1023 - 512)) / 1024 = 1980

        int32_t mY = 1196, mU_B = 2200, mV_G = -668, mV_R = 1723, mU_G = -192;
        for (size_t x = 0; x < width; x += 2) {
            int32_t u, v, y00, y01, y10, y11;
            u = *uSrc - 512;
            uSrc += 1;
            v = *vSrc - 512;
            vSrc += 1;

            y00 = *ySrcTop - 64;
            ySrcTop += 1;
            y01 = *ySrcTop - 64;
            ySrcTop += 1;
            y10 = *ySrcBot - 64;
            ySrcBot += 1;
            y11 = *ySrcBot - 64;
            ySrcBot += 1;

            int32_t u_b = u * mU_B;
            int32_t u_g = u * mU_G;
            int32_t v_g = v * mV_G;
            int32_t v_r = v * mV_R;

            int32_t yMult, b, g, r;
            yMult = y00 * mY;
            b = (yMult + u_b) / 1024;
            g = (yMult + v_g + u_g) / 1024;
            r = (yMult + v_r) / 1024;
            b = CLIP3(0, b, 1023);
            g = CLIP3(0, g, 1023);
            r = CLIP3(0, r, 1023);
            *dstTop++ = 3 << 30 | (b << 20) | (g << 10) | r;

            yMult = y01 * mY;
            b = (yMult + u_b) / 1024;
            g = (yMult + v_g + u_g) / 1024;
            r = (yMult + v_r) / 1024;
            b = CLIP3(0, b, 1023);
            g = CLIP3(0, g, 1023);
            r = CLIP3(0, r, 1023);
            *dstTop++ = 3 << 30 | (b << 20) | (g << 10) | r;

            yMult = y10 * mY;
            b = (yMult + u_b) / 1024;
            g = (yMult + v_g + u_g) / 1024;
            r = (yMult + v_r) / 1024;
            b = CLIP3(0, b, 1023);
            g = CLIP3(0, g, 1023);
            r = CLIP3(0, r, 1023);
            *dstBot++ = 3 << 30 | (b << 20) | (g << 10) | r;

            yMult = y11 * mY;
            b = (yMult + u_b) / 1024;
            g = (yMult + v_g + u_g) / 1024;
            r = (yMult + v_r) / 1024;
            b = CLIP3(0, b, 1023);
            g = CLIP3(0, g, 1023);
            r = CLIP3(0, r, 1023);
            *dstBot++ = 3 << 30 | (b << 20) | (g << 10) | r;
        }

        srcY += srcYStride * 2;
        srcU += srcUStride;
        srcV += srcVStride;
        dst += dstStride * 2;
    }
}

void convertYUV420Planar16ToY410OrRGBA1010102(uint32_t *dst, const uint16_t *srcY,
                                              const uint16_t *srcU, const uint16_t *srcV,
                                              size_t srcYStride, size_t srcUStride,
                                              size_t srcVStride, size_t dstStride, size_t width,
                                              size_t height) {
    if (isAtLeastT()) {
        convertYUV420Planar16ToRGBA1010102(dst, srcY, srcU, srcV, srcYStride, srcUStride,
                                           srcVStride, dstStride, width, height);
    } else {
        convertYUV420Planar16ToY410(dst, srcY, srcU, srcV, srcYStride, srcUStride, srcVStride,
                                    dstStride, width, height);
    }
}
void convertYUV420Planar16ToYV12(uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, const uint16_t *srcY,
void convertYUV420Planar16ToYV12(uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, const uint16_t *srcY,
                                 const uint16_t *srcU, const uint16_t *srcV, size_t srcYStride,
                                 const uint16_t *srcU, const uint16_t *srcV, size_t srcYStride,
                                 size_t srcUStride, size_t srcVStride, size_t dstYStride,
                                 size_t srcUStride, size_t srcVStride, size_t dstYStride,
@@ -799,11 +910,16 @@ int SimpleC2Component::getHalPixelFormatForBitDepth10(bool allowRGBA1010102) {
        // Add YV12 in the end as a fall-back option
        // Add YV12 in the end as a fall-back option
        mBitDepth10HalPixelFormats.push_back(HAL_PIXEL_FORMAT_YV12);
        mBitDepth10HalPixelFormats.push_back(HAL_PIXEL_FORMAT_YV12);
    }
    }
    // From Android T onwards, HAL_PIXEL_FORMAT_RGBA_1010102 corresponds to true
    // RGBA 1010102 format unlike earlier versions where it was used to represent
    // YUVA 1010102 data
    if (!isAtLeastT()) {
        // When RGBA1010102 is not allowed and if the first supported hal pixel is format is
        // When RGBA1010102 is not allowed and if the first supported hal pixel is format is
        // HAL_PIXEL_FORMAT_RGBA_1010102, then return HAL_PIXEL_FORMAT_YV12
        // HAL_PIXEL_FORMAT_RGBA_1010102, then return HAL_PIXEL_FORMAT_YV12
        if (!allowRGBA1010102 && mBitDepth10HalPixelFormats[0] == HAL_PIXEL_FORMAT_RGBA_1010102) {
        if (!allowRGBA1010102 && mBitDepth10HalPixelFormats[0] == HAL_PIXEL_FORMAT_RGBA_1010102) {
            return HAL_PIXEL_FORMAT_YV12;
            return HAL_PIXEL_FORMAT_YV12;
        }
        }
    }
    // Return the first entry from supported formats
    // Return the first entry from supported formats
    return mBitDepth10HalPixelFormats[0];
    return mBitDepth10HalPixelFormats[0];
}
}
+5 −3
Original line number Original line Diff line number Diff line
@@ -33,9 +33,11 @@ void convertYUV420Planar8ToYV12(uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, con
                                size_t srcUStride, size_t srcVStride, size_t dstYStride,
                                size_t srcUStride, size_t srcVStride, size_t dstYStride,
                                size_t dstUVStride, uint32_t width, uint32_t height,
                                size_t dstUVStride, uint32_t width, uint32_t height,
                                bool isMonochrome = false);
                                bool isMonochrome = false);
void convertYUV420Planar16ToY410(uint32_t *dst, const uint16_t *srcY, const uint16_t *srcU,
void convertYUV420Planar16ToY410OrRGBA1010102(uint32_t *dst, const uint16_t *srcY,
                                 const uint16_t *srcV, size_t srcYStride, size_t srcUStride,
                                              const uint16_t *srcU, const uint16_t *srcV,
                                 size_t srcVStride, size_t dstStride, size_t width, size_t height);
                                              size_t srcYStride, size_t srcUStride,
                                              size_t srcVStride, size_t dstStride, size_t width,
                                              size_t height);
void convertYUV420Planar16ToYV12(uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, const uint16_t *srcY,
void convertYUV420Planar16ToYV12(uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, const uint16_t *srcY,
                                 const uint16_t *srcU, const uint16_t *srcV, size_t srcYStride,
                                 const uint16_t *srcU, const uint16_t *srcV, size_t srcYStride,
                                 size_t srcUStride, size_t srcVStride, size_t dstYStride,
                                 size_t srcUStride, size_t srcVStride, size_t dstYStride,
+3 −3
Original line number Original line Diff line number Diff line
@@ -714,9 +714,9 @@ bool C2SoftGav1Dec::outputBuffer(const std::shared_ptr<C2BlockPool> &pool,
    const uint16_t *srcV = (const uint16_t *)buffer->plane[2];
    const uint16_t *srcV = (const uint16_t *)buffer->plane[2];


    if (format == HAL_PIXEL_FORMAT_RGBA_1010102) {
    if (format == HAL_PIXEL_FORMAT_RGBA_1010102) {
        convertYUV420Planar16ToY410((uint32_t *)dstY, srcY, srcU, srcV, srcYStride / 2,
        convertYUV420Planar16ToY410OrRGBA1010102((uint32_t *)dstY, srcY, srcU, srcV, srcYStride / 2,
                                    srcUStride / 2, srcVStride / 2, dstYStride / sizeof(uint32_t),
                                                 srcUStride / 2, srcVStride / 2,
                                    mWidth, mHeight);
                                                 dstYStride / sizeof(uint32_t), mWidth, mHeight);
    } else if (format == HAL_PIXEL_FORMAT_YCBCR_P010) {
    } else if (format == HAL_PIXEL_FORMAT_YCBCR_P010) {
        convertYUV420Planar16ToP010((uint16_t *)dstY, (uint16_t *)dstU, srcY, srcU, srcV,
        convertYUV420Planar16ToP010((uint16_t *)dstY, (uint16_t *)dstU, srcY, srcU, srcV,
                                    srcYStride / 2, srcUStride / 2, srcVStride / 2, dstYStride / 2,
                                    srcYStride / 2, srcUStride / 2, srcVStride / 2, dstYStride / 2,
+1 −1
Original line number Original line Diff line number Diff line
@@ -760,7 +760,7 @@ status_t C2SoftVpxDec::outputBuffer(
                        [dstY, srcY, srcU, srcV,
                        [dstY, srcY, srcU, srcV,
                         srcYStride, srcUStride, srcVStride, dstYStride,
                         srcYStride, srcUStride, srcVStride, dstYStride,
                         width = mWidth, height = std::min(mHeight - i, kHeight)] {
                         width = mWidth, height = std::min(mHeight - i, kHeight)] {
                            convertYUV420Planar16ToY410(
                            convertYUV420Planar16ToY410OrRGBA1010102(
                                    (uint32_t *)dstY, srcY, srcU, srcV, srcYStride / 2,
                                    (uint32_t *)dstY, srcY, srcU, srcV, srcYStride / 2,
                                    srcUStride / 2, srcVStride / 2, dstYStride / sizeof(uint32_t),
                                    srcUStride / 2, srcVStride / 2, dstYStride / sizeof(uint32_t),
                                    width, height);
                                    width, height);