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

Commit 355cdc38 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "fix(force invert): invert matrix and other color filters as well" into main

parents a92d9341 d8fc6caa
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -85,6 +85,17 @@ SkColor4f transformColorInverse(ColorTransform transform, SkColor4f color) {
    }
}

/**
 * Invert's the paint's current color filter by composing it with an inversion filter.
 *
 * Relies on the undocumented behavior that makeComposed() will just return this if inner is null.
 */
static void composeWithInvertedColorFilter(SkPaint& paint) {
    SkHighContrastConfig config;
    config.fInvertStyle = SkHighContrastConfig::InvertStyle::kInvertLightness;
    paint.setColorFilter(SkHighContrastFilter::Make(config)->makeComposed(paint.refColorFilter()));
}

static void applyColorTransform(ColorTransform transform, SkPaint& paint) {
    if (transform == ColorTransform::None) return;

@@ -113,10 +124,14 @@ static void applyColorTransform(ColorTransform transform, SkPaint& paint) {
    if (paint.getColorFilter()) {
        SkBlendMode mode;
        SkColor color;

        // TODO: LRU this or something to avoid spamming new color mode filters
        if (paint.getColorFilter()->asAColorMode(&color, &mode)) {
            SkColor4f transformedColor = transformColor(transform, SkColor4f::FromColor(color));
            paint.setColorFilter(SkColorFilters::Blend(transformedColor, nullptr, mode));
        } else if (transform == ColorTransform::Invert) {
            // Handle matrix and others type of filters
            composeWithInvertedColorFilter(paint);
        }
    }
}
@@ -159,9 +174,7 @@ bool transformPaint(ColorTransform transform, SkPaint* paint, BitmapPalette pale
        shouldInvert = true;
    }
    if (shouldInvert) {
        SkHighContrastConfig config;
        config.fInvertStyle = SkHighContrastConfig::InvertStyle::kInvertLightness;
        paint->setColorFilter(SkHighContrastFilter::Make(config)->makeComposed(paint->refColorFilter()));
        composeWithInvertedColorFilter(*paint);
    }
    return shouldInvert;
}