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

Commit ec1912e8 authored by Fyodor Kyslov's avatar Fyodor Kyslov Committed by Gerrit Code Review
Browse files

Merge "APV: Add conversion to RGBA1010102 and from P210" into main

parents 0ee3ef1b 41ed5de2
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -287,6 +287,9 @@ class C2SoftApvDec::IntfImpl : public SimpleInterface<void>::BaseParams {
        if (isHalPixelFormatSupported((AHardwareBuffer_Format)AHARDWAREBUFFER_FORMAT_YCbCr_P210)) {
            pixelFormats.push_back(AHARDWAREBUFFER_FORMAT_YCbCr_P210);
        }
        if (isHalPixelFormatSupported((AHardwareBuffer_Format)HAL_PIXEL_FORMAT_RGBA_1010102)) {
            pixelFormats.push_back(HAL_PIXEL_FORMAT_RGBA_1010102);
        }

        // If color format surface isn't added to supported formats, there is no way to know
        // when the color-format is configured to surface. This is necessary to be able to
@@ -958,7 +961,6 @@ void C2SoftApvDec::process(const std::unique_ptr<C2Work>& work,
            fillEmptyWork(work);
            return;
        }

        bool reportResolutionChange = false;
        for (int i = 0; i < mOutFrames.num_frms; i++) {
            oapv_frm_info_t* finfo = &aui.frm_info[i];
@@ -1285,12 +1287,18 @@ status_t C2SoftApvDec::outputBuffer(const std::shared_ptr<C2BlockPool>& pool,
    }

    uint32_t format = HAL_PIXEL_FORMAT_YV12;
    std::shared_ptr<C2StreamColorAspectsInfo::output> codedColorAspects;
    if (mPixelFormatInfo->value != HAL_PIXEL_FORMAT_YCBCR_420_888) {
        if (isHalPixelFormatSupported((AHardwareBuffer_Format)AHARDWAREBUFFER_FORMAT_YCbCr_P210)) {
            format = AHARDWAREBUFFER_FORMAT_YCbCr_P210;
        } else if (isHalPixelFormatSupported(
                        (AHardwareBuffer_Format)HAL_PIXEL_FORMAT_YCBCR_P010)) {
            format = HAL_PIXEL_FORMAT_YCBCR_P010;
        } else if (isHalPixelFormatSupported(
                        (AHardwareBuffer_Format)HAL_PIXEL_FORMAT_RGBA_1010102)) {
            IntfImpl::Lock lock = mIntf->lock();
            codedColorAspects = mIntf->getColorAspects_l();
            format = HAL_PIXEL_FORMAT_RGBA_1010102;
        } else {
            format = HAL_PIXEL_FORMAT_YV12;
        }
@@ -1343,7 +1351,28 @@ status_t C2SoftApvDec::outputBuffer(const std::shared_ptr<C2BlockPool>& pool,
    size_t dstUStride = layout.planes[C2PlanarLayout::PLANE_U].rowInc;
    size_t dstVStride = layout.planes[C2PlanarLayout::PLANE_V].rowInc;

    if(format == AHARDWAREBUFFER_FORMAT_YCbCr_P210) {
    if(format == HAL_PIXEL_FORMAT_RGBA_1010102) {
        if (OAPV_CS_GET_BIT_DEPTH(imgbOutput->cs) == 10) {
            const uint16_t* srcY = (const uint16_t*)imgbOutput->a[0];
            const uint16_t* srcU = (const uint16_t*)imgbOutput->a[1];
            const uint16_t* srcV = (const uint16_t*)imgbOutput->a[2];
            size_t srcYStride = imgbOutput->s[0] / 2;
            size_t srcUStride = imgbOutput->s[1] / 2;
            size_t srcVStride = imgbOutput->s[2] / 2;
            dstYStride /= 4;
            if (OAPV_CS_GET_FORMAT(imgbOutput->cs) == OAPV_CF_PLANAR2) {
                ALOGV("OAPV_CS_P210 to RGBA1010102");
                convertP210ToRGBA1010102((uint32_t *)dstY, srcY, srcU, srcYStride, srcUStride,
                                           dstYStride, mWidth, mHeight, codedColorAspects);
            } else {
                ALOGE("Not supported convert format : %d", OAPV_CS_GET_FORMAT(imgbOutput->cs));
            }
        } else {
            ALOGE("Not supported convert from bitdepth:%d, format: %d, to format: %d",
                  OAPV_CS_GET_BIT_DEPTH(imgbOutput->cs), OAPV_CS_GET_FORMAT(imgbOutput->cs),
                  format);
        }
    } else if(format == AHARDWAREBUFFER_FORMAT_YCbCr_P210) {
        if(OAPV_CS_GET_BIT_DEPTH(imgbOutput->cs) == 10) {
            const uint16_t *srcY = (const uint16_t *)imgbOutput->a[0];
            const uint16_t *srcU = (const uint16_t *)imgbOutput->a[1];
+27 −0
Original line number Diff line number Diff line
@@ -1054,6 +1054,33 @@ c2_status_t C2SoftApvEnc::setEncodeArgs(oapv_frms_t* inputFrames, const C2Graphi
                    ALOGE("Not supported color format. %d", mColorFormat);
                    return C2_BAD_VALUE;
                }
            } else if (IsP210(*input)) {
                ALOGV("Convert from P210 to P210");
                if (mColorFormat == OAPV_CF_PLANAR2) {
                    uint16_t *srcY  = (uint16_t*)(input->data()[0]);
                    uint16_t *srcUV = (uint16_t*)(input->data()[1]);
                    uint16_t *dstY  = (uint16_t*)inputFrames->frm[0].imgb->a[0];
                    uint16_t *dstUV = (uint16_t*)inputFrames->frm[0].imgb->a[1];
                    size_t srcYStride = layout.planes[layout.PLANE_Y].rowInc / 2;
                    size_t srcUVStride = layout.planes[layout.PLANE_U].rowInc / 2;
                    size_t dstYStride = inputFrames->frm[0].imgb->s[0] / 2;
                    size_t dstUVStride = inputFrames->frm[0].imgb->s[1] / 2;

                    for (size_t y = 0; y < height; ++y) {
                        std::memcpy(dstY, srcY, width * sizeof(uint16_t));
                        dstY += dstYStride;
                        srcY += srcYStride;
                    }

                    for (size_t y = 0; y < height; ++y) {
                        std::memcpy(dstUV, srcUV, width * sizeof(uint16_t));
                        srcUV += srcUVStride;
                        dstUV += dstUVStride;
                    }
                } else {
                    ALOGE("Not supported color format. %d", mColorFormat);
                    return C2_BAD_VALUE;
                }
            } else if (IsNV12(*input) || IsNV21(*input)) {
                ALOGV("Convert from NV12 to P210");
                uint8_t  *srcY  = (uint8_t*)input->data()[0];
+61 −0
Original line number Diff line number Diff line
@@ -354,6 +354,67 @@ void convertYUV420Planar16ToY410OrRGBA1010102(
    }
}

void convertP210ToRGBA1010102(uint32_t* dst, const uint16_t* srcY, const uint16_t* srcUV,
                                size_t srcYStride, size_t srcUVStride, size_t dstStride,
                                size_t width, size_t height,
                                std::shared_ptr<const C2ColorAspectsStruct> aspects) {
    C2ColorAspectsStruct _aspects = FillMissingColorAspects(aspects, width, height);
    struct Coeffs coeffs = GetCoeffsForAspects(_aspects);

    int32_t _y = coeffs._y;
    int32_t _b_u = coeffs._b_u;
    int32_t _neg_g_u = -coeffs._g_u;
    int32_t _neg_g_v = -coeffs._g_v;
    int32_t _r_v = coeffs._r_v;
    int32_t _c16 = coeffs._c16;

    for (size_t y = 0; y < height; y++) {
        uint32_t *dstTop = (uint32_t *)dst;
        uint16_t *ySrcTop = (uint16_t *)srcY;
        uint16_t *uSrc = (uint16_t *)srcUV;
        uint16_t *vSrc = (uint16_t *)(srcUV + 1);
        for (size_t x = 0; x < width; x += 2) {
            int32_t u, v, y00, y01;
            u = ((*uSrc) >> 6) - 512;
            uSrc += 2;
            v = ((*vSrc) >> 6) - 512;
            vSrc += 2;

            y00 = ((*ySrcTop) >> 6) - _c16;
            ySrcTop += 1;
            y01 = ((*ySrcTop) >> 6) - _c16;
            ySrcTop += 1;

            int32_t u_b = u * _b_u;
            int32_t u_g = u * _neg_g_u;
            int32_t v_g = v * _neg_g_v;
            int32_t v_r = v * _r_v;

            int32_t yMult, b, g, r;
            yMult = y00 * _y + 512;
            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 * _y + 512;
            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;
        }
        srcY += srcYStride;
        srcUV += srcUVStride;
        dst += dstStride;
    }
}

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,
                                 size_t srcUStride, size_t srcVStride, size_t dstYStride,
+5 −0
Original line number Diff line number Diff line
@@ -94,6 +94,11 @@ void convertPlanar16ToY410OrRGBA1010102(uint8_t* dst, const uint16_t* srcY, cons
                                        std::shared_ptr<const C2ColorAspectsStruct> aspects,
                                        CONV_FORMAT_T format);

void convertP210ToRGBA1010102(uint32_t* dst, const uint16_t* srcY, const uint16_t* srcUV,
                                size_t srcYStride, size_t srcUVStride, size_t dstStride,
                                size_t width, size_t height,
                                std::shared_ptr<const C2ColorAspectsStruct> aspects);

void convertPlanar16ToP010(uint16_t* dstY, uint16_t* dstUV, const uint16_t* srcY,
                           const uint16_t* srcU, const uint16_t* srcV, size_t srcYStride,
                           size_t srcUStride, size_t srcVStride, size_t dstYStride,
+37 −0
Original line number Diff line number Diff line
@@ -337,6 +337,27 @@ bool IsYUV420_10bit(const C2GraphicView &view) {
            && layout.planes[layout.PLANE_V].rowSampling == 2);
}

bool IsYUV422_10bit(const C2GraphicView &view) {
    const C2PlanarLayout &layout = view.layout();
    return (layout.numPlanes == 3
            && layout.type == C2PlanarLayout::TYPE_YUV
            && layout.planes[layout.PLANE_Y].channel == C2PlaneInfo::CHANNEL_Y
            && layout.planes[layout.PLANE_Y].allocatedDepth == 16
            && layout.planes[layout.PLANE_Y].bitDepth == 10
            && layout.planes[layout.PLANE_Y].colSampling == 1
            && layout.planes[layout.PLANE_Y].rowSampling == 1
            && layout.planes[layout.PLANE_U].channel == C2PlaneInfo::CHANNEL_CB
            && layout.planes[layout.PLANE_U].allocatedDepth == 16
            && layout.planes[layout.PLANE_U].bitDepth == 10
            && layout.planes[layout.PLANE_U].colSampling == 2
            && layout.planes[layout.PLANE_U].rowSampling == 1
            && layout.planes[layout.PLANE_V].channel == C2PlaneInfo::CHANNEL_CR
            && layout.planes[layout.PLANE_V].allocatedDepth == 16
            && layout.planes[layout.PLANE_V].bitDepth == 10
            && layout.planes[layout.PLANE_V].colSampling == 2
            && layout.planes[layout.PLANE_V].rowSampling == 1);
}


bool IsNV12(const C2GraphicView &view) {
    if (!IsYUV420(view)) {
@@ -369,6 +390,22 @@ bool IsP010(const C2GraphicView &view) {
            && layout.planes[layout.PLANE_V].rightShift == 6);
}

bool IsP210(const C2GraphicView &view) {
    if (!IsYUV422_10bit(view)) {
        return false;
    }
    const C2PlanarLayout &layout = view.layout();
    return (layout.rootPlanes == 2
            && layout.planes[layout.PLANE_U].colInc == 4
            && layout.planes[layout.PLANE_U].rootIx == layout.PLANE_U
            && layout.planes[layout.PLANE_U].offset == 0
            && layout.planes[layout.PLANE_V].colInc == 4
            && layout.planes[layout.PLANE_V].rootIx == layout.PLANE_U
            && layout.planes[layout.PLANE_V].offset == 2
            && layout.planes[layout.PLANE_Y].rightShift == 6
            && layout.planes[layout.PLANE_U].rightShift == 6
            && layout.planes[layout.PLANE_V].rightShift == 6);
}

bool IsNV21(const C2GraphicView &view) {
    if (!IsYUV420(view)) {
Loading