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

Commit d7be5c5e authored by Andreas Huber's avatar Andreas Huber
Browse files

Color conversion now supports YUV420p->RGB565 conversion even if the width is odd.

Change-Id: I1ef3ead94eab3811ead8830e104a9dad211ae3fd
related-to-bug: 4363071
parent 593aebae
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -187,8 +187,7 @@ status_t ColorConverter::convertCbYCrY(

status_t ColorConverter::convertYUV420Planar(
        const BitmapParams &src, const BitmapParams &dst) {
    if (!((dst.mWidth & 1) == 0
            && (src.mCropLeft & 1) == 0
    if (!((src.mCropLeft & 1) == 0
            && src.cropWidth() == dst.cropWidth()
            && src.cropHeight() == dst.cropHeight())) {
        return ERROR_UNSUPPORTED;
@@ -196,8 +195,8 @@ status_t ColorConverter::convertYUV420Planar(

    uint8_t *kAdjustedClip = initClip();

    uint32_t *dst_ptr = (uint32_t *)dst.mBits
        + (dst.mCropTop * dst.mWidth + dst.mCropLeft) / 2;
    uint16_t *dst_ptr = (uint16_t *)dst.mBits
        + dst.mCropTop * dst.mWidth + dst.mCropLeft;

    const uint8_t *src_y =
        (const uint8_t *)src.mBits + src.mCropTop * src.mWidth + src.mCropLeft;
@@ -260,7 +259,11 @@ status_t ColorConverter::convertYUV420Planar(
                | ((kAdjustedClip[g2] >> 2) << 5)
                | (kAdjustedClip[b2] >> 3);

            dst_ptr[x / 2] = (rgb2 << 16) | rgb1;
            if (x + 1 < src.cropWidth()) {
                *(uint32_t *)(&dst_ptr[x]) = (rgb2 << 16) | rgb1;
            } else {
                dst_ptr[x] = rgb1;
            }
        }

        src_y += src.mWidth;
@@ -270,7 +273,7 @@ status_t ColorConverter::convertYUV420Planar(
            src_v += src.mWidth / 2;
        }

        dst_ptr += dst.mWidth / 2;
        dst_ptr += dst.mWidth;
    }

    return OK;