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

Commit ca9b8838 authored by chihtinglo's avatar chihtinglo
Browse files

fix(edt): Avoid inverting gray scale images in EDT

Checking the saturation of the images to identify if the image contains
only gray scale colors. To exclude the purely black and purely white
images, we also check the values of the colors.

Bug: 438210124
Bug: 439592926
Test: manually. attach screenshot to the bug
Flag: android.view.accessibility.force_invert_color
Change-Id: I11c7e663dbb9360cb5d86e3ff72014ecb1f4a698
parent 0c1c5c98
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -163,9 +163,10 @@ bool transformPaint(ColorTransform transform, SkPaint* paint) {
bool transformPaint(ColorTransform transform, SkPaint* paint, BitmapPalette palette) {
    bool shouldInvert = false;
    if (transform == ColorTransform::Invert) {
        if (palette != BitmapPalette::Barcode && palette != BitmapPalette::Colorful) {
            // When the transform is Invert we invert any image that is not deemed "colorful"
            // or a barcode, regardless of calculated image brightness.
        if (palette != BitmapPalette::GrayScale && palette != BitmapPalette::Barcode &&
            palette != BitmapPalette::Colorful) {
            // When the transform is Invert we invert any image that is not deemed "colorful",
            // "gray-scale" or a barcode, regardless of calculated image brightness.
            shouldInvert = true;
        }
    }
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ void ColorArea::addArea(const SkRect& bounds, const SkPaint& paint,
            break;
        case android::BitmapPalette::Colorful:
        case android::BitmapPalette::Barcode:
        case android::BitmapPalette::GrayScale:
        case android::BitmapPalette::Unknown:
            addArea(area, Unknown);
            break;
+13 −1
Original line number Diff line number Diff line
@@ -554,6 +554,7 @@ BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr,

    MinMaxAverage hue, saturation, value;
    int sampledCount = 0;
    Histogram<10> saturationHistogram;
    Histogram<10> valueHistogram;

    // Sample a grid of 100 pixels to get an overall estimation of the colors in play
@@ -570,7 +571,9 @@ BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr,
            float hsv[3];
            SkColorToHSV(color, hsv);
            hue.add(hsv[0]);
            saturation.add(hsv[1]);
            float s = hsv[1];
            saturation.add(s);
            saturationHistogram.add(s);
            float val = hsv[2];
            value.add(val);
            valueHistogram.add(val);
@@ -606,6 +609,15 @@ BitmapPalette Bitmap::computePalette(const SkImageInfo& info, const void* addr,
                return BitmapPalette::Barcode;
            }
        }

        // Identify if the image is grayscale by checking if most samples have low saturation,
        // but it is not purely black or purely white.
        int expectedGrayScaleSamples = sampledCount * 0.9;
        int graySamples = saturationHistogram[0];
        if (graySamples > expectedGrayScaleSamples && value.delta() > 0.05f) {
            return BitmapPalette::GrayScale;
        }

        if (saturation.delta() > 0.1f ||
            (hue.delta() > 20 && saturation.average() > 0.2f && value.average() < 0.9f)) {
            return BitmapPalette::Colorful;
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ enum class BitmapPalette {
    Dark,
    Colorful,
    Barcode,
    GrayScale,
};

namespace uirenderer {