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

Commit 9dab9ece authored by Lajos Molnar's avatar Lajos Molnar
Browse files

stagefright:ColorConverter: add support for BT.601/709/2020 limited and full range

Previously, 10-bit sources supported only BT.709 and BT.2020 limited range, and 8-bit
sources only BT.601 limited range.

- Added matrix coefficients for all supported color spaces.
- Combined the various vendor YUV420Planar conversions into a base routine.
- Fix BT709 support for libyuv (current libyuv only supports limited range)
- Added fall-back from libyuv for unsupported color spaces (newer libyuv does support
  all of our color spaces, but we cannot use these yet.)
- Added rounding.
- Reduce the divisor of the 10-bit transform matrix to match the other 8-bit
  matrices. The actual matrix was purely divisable so no actual precision is lost.

Bug: 206040283
Test: manual Photos && atest MediaMetadataRetrieverTest.java
Change-Id: I607c9a7e903378a81e4784cc222f7e76bf836d41
parent e054011b
Loading
Loading
Loading
Loading
+327 −248

File changed.

Preview size limit exceeded, changes collapsed.

+15 −3
Original line number Diff line number Diff line
@@ -47,15 +47,20 @@ struct ColorConverter {
            size_t dstCropLeft, size_t dstCropTop,
            size_t dstCropRight, size_t dstCropBottom);

    struct Coeffs; // matrix coefficients

private:
    struct ColorSpace {
        uint32_t mStandard;
        uint32_t mRange;
        uint32_t mTransfer;

        bool isBt709();
        bool isBt2020();
        bool isJpeg();
        bool isBt2020() const;

        // libyuv helper methods
        bool isH420() const;
        bool isI420() const;
        bool isJ420() const;
    };

    struct BitmapParams {
@@ -84,6 +89,9 @@ private:
    uint8_t *initClip();
    uint16_t *initClip10Bit();

    // returns the YUV2RGB matrix coefficients according to the color aspects and bit depth
    const struct Coeffs *getMatrix() const;

    status_t convertCbYCrY(
            const BitmapParams &src, const BitmapParams &dst);

@@ -111,6 +119,10 @@ private:
    status_t convertYUV420SemiPlanar(
            const BitmapParams &src, const BitmapParams &dst);

    status_t convertYUV420SemiPlanarBase(
            const BitmapParams &src, const BitmapParams &dst,
            const uint8_t *src_y, const uint8_t *src_u, size_t row_inc, bool isNV21 = false);

    status_t convertTIYUV420PackedSemiPlanar(
            const BitmapParams &src, const BitmapParams &dst);