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

Commit f8e8d178 authored by Candice Lo's avatar Candice Lo Committed by Android (Google) Code Review
Browse files

Merge changes I11c7e663,I67ed8ab9 into main

* changes:
  fix(edt): Avoid inverting gray scale images in EDT
  fix(edt): Invert the shadow colors in EDT
parents 7264db6d ca9b8838
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;
+12 −0
Original line number Diff line number Diff line
@@ -457,6 +457,18 @@ void RenderNode::handleForceDark(android::uirenderer::TreeInfo* info) {
            transform = ColorTransform::Invert;
        }
        mDisplayList.applyColorTransform(transform);
        if (mProperties.hasShadow()) {
            SkColor newAmbientShadowColor =
                    transformColor(ColorTransform::Invert,
                                   SkColor4f::FromColor(mProperties.getAmbientShadowColor()))
                            .toSkColor();
            SkColor newSpotShadowColor =
                    transformColor(ColorTransform::Invert,
                                   SkColor4f::FromColor(mProperties.getSpotShadowColor()))
                            .toSkColor();
            mProperties.setAmbientShadowColor(newAmbientShadowColor);
            mProperties.setSpotShadowColor(newSpotShadowColor);
        }
        return;
    }

+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 {