Skip to content

Conversation

@lukepighetti
Copy link
Contributor

@lukepighetti lukepighetti commented Apr 27, 2025

Resolves #166589

I'm not sure how to update the Goldens but here are the three I have locally. Test was written to ensure that transparency is preserved.

golden files

ColorFilter.saturation(1)

color_filter_saturation_full

ColorFilter.saturation(0.5)

color_filter_saturation_partial

ColorFilter.saturation(0)

color_filter_saturation_none


Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. engine flutter/engine related. See also e: labels. labels Apr 27, 2025
@lukepighetti lukepighetti force-pushed the lukepighetti/color-filter-apr-27 branch from 28ae2f1 to 081ab97 Compare April 27, 2025 23:30
@lukepighetti lukepighetti marked this pull request as ready for review April 27, 2025 23:34
@lukepighetti lukepighetti changed the title WIP: ColorFilter.saturation ColorFilter.saturation Apr 27, 2025
@github-actions github-actions bot added the platform-web Web applications specifically label Apr 28, 2025
@lukepighetti lukepighetti marked this pull request as draft April 28, 2025 13:39
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@lukepighetti
Copy link
Contributor Author

trying to understand the intricacies of what parts of the codebase need to be updated. builds are failing on web and it's not clear to me what the next steps are. will keep trying to apply pressure on this

@benthillerkus
Copy link
Contributor

There's also this file where a test could be added:
https://github.com/lukepighetti/flutter/blob/1e29389a7c1b0456feadf74914fb6de05e34e048/engine/src/flutter/testing/dart/color_filter_test.dart

Unfortunately it's in the engine and running the test isn't as easy as pressing the run button in VSCode (and setting everything up correctly seems really complicated), so I can' confirm, but I think this would do:

/// [red] with a 0.5 saturation adjustment layer in Affinity Photo
// Might not match up with the result of the matrix calc exactly
const int redHalfSaturation = 0xFF853F2D;

....

  group('ColorFilter - saturation', () {
    test('saturation - 0', () async {
      final Paint paint =
          Paint()
            ..color = green
            ..colorFilter = const ColorFilter.saturation(0);
  
      Uint32List bytes = await getBytesForPaint(paint);
      expect(bytes[0], greenGreyscaled);
  
      // TODO(135699): enable this
      if (impellerEnabled) {
        return;
      }
  
      paint.invertColors = true;
      bytes = await getBytesForPaint(paint);
      expect(bytes[0], greenInvertedGreyscaled);
    });
  
    test('saturation - 1 - transparent', () async {
      final Paint paint =
          Paint()
            ..color = transparent
            ..colorFilter = const ColorFilter.saturation(1);
  
      Uint32List bytes = await getBytesForPaint(paint);
      expect(bytes[0], transparent);
    });
  
    test('saturation - 1 - green', () async {
      final Paint paint =
          Paint()
            ..color = green
            ..colorFilter = const ColorFilter.saturation(1);
  
      Uint32List bytes = await getBytesForPaint(paint);
      expect(bytes[0], green);
    });
  
    test('saturation - 1 - red', () async {
      final Paint paint =
          Paint()
            ..color = red
            ..colorFilter = const ColorFilter.saturation(1);
  
      Uint32List bytes = await getBytesForPaint(paint);
      expect(bytes[0], red);
    });
  
    test('saturation - 0.5 - red', () async {
      final Paint paint =
          Paint()
            ..color = red
            ..colorFilter = const ColorFilter.saturation(0.5);
  
      Uint32List bytes = await getBytesForPaint(paint);
      expect(bytes[0], redHalfSaturation);
    });
  });

@benthillerkus
Copy link
Contributor

trying to understand the intricacies of what parts of the codebase need to be updated. builds are failing on web and it's not clear to me what the next steps are. will keep trying to apply pressure on this

https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8716341066034125713/+/u/build_wasm_release_flutter_web_sdk:flutter_web_sdk_archive/stdout?format=raw

org-dartlang-sdk:///lib/ui/painting.dart:446:61: Error: Couldn't find constructor 'engine.EngineColorFilter.saturation'.
  const factory ColorFilter.saturation(double saturation) = engine.EngineColorFilter.saturation;
                                                            ^
org-dartlang-sdk:///lib/ui/painting.dart:446:61: Error: Redirection constructor target not found: 'engine.EngineColorFilter.saturation'
  const factory ColorFilter.saturation(double saturation) = engine.EngineColorFilter.saturation;
   

This is what's failing which is fair, because there is indeed no such thing https://github.com/lukepighetti/flutter/blob/1e29389a7c1b0456feadf74914fb6de05e34e048/engine/src/flutter/lib/web_ui/lib/src/engine/color_filter.dart#L110

But this class is really curious, it seems to be a copy paste of the section from ui/painting.dart, just with the internal fields made public.
Since the matrix is hidden on the ColorFilter, we can't easily just pass it into the EngineColorFilter.matrix factory, so the .saturation factory would probably have to be copy pasted 1:1 to the EngineColorFilter?

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending a PR! 🎊
See comment below to get this working on web.

const factory ColorFilter.matrix(List<double> matrix) = engine.EngineColorFilter.matrix;
const factory ColorFilter.linearToSrgbGamma() = engine.EngineColorFilter.linearToSrgbGamma;
const factory ColorFilter.srgbToLinearGamma() = engine.EngineColorFilter.srgbToLinearGamma;
const factory ColorFilter.saturation(double saturation) = engine.EngineColorFilter.saturation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if Github did not lose said comment. 😅
See engine/src/flutter/lib/web_ui/lib/src/engine/color_filter.dart
You need to define EngineColorFilter.saturation
Search for EngineColorFilter.srgbToLinearGamma as an example.

@Piinks
Copy link
Contributor

Piinks commented Apr 28, 2025

I'm not sure how to update the Goldens

Once CI is green, the bot will check for golden file changes and leave a comment to the dashboard where we can check them out. 👍

@Piinks
Copy link
Contributor

Piinks commented Jul 8, 2025

Hey @lukepighetti! Greetings from stale PR triage 👋
Is this one still on your radar?

@Piinks
Copy link
Contributor

Piinks commented Sep 15, 2025

Unfortunately since we have not heard back we'll have to regrettably close this PR. I have marked the issue with a the partial patch label in case anyone wants to pick this up and address the feedback. Thanks!

@Piinks Piinks closed this Sep 15, 2025
@ksokolovskyi ksokolovskyi mentioned this pull request Oct 3, 2025
9 tasks
github-merge-queue bot pushed a commit that referenced this pull request Oct 8, 2025
Closes #166589

This PR is a continuation of
#167898, which was closed due to
the lack of web implementation. Thanks to @lukepighetti and
@benthillerkus for their work on the closed PR.

### Description

- Adds `ColorFilter.saturation`



https://github.com/user-attachments/assets/67d8acf0-35d0-42de-a24b-f24eed14e9a8


## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
Closes flutter#166589

This PR is a continuation of
flutter#167898, which was closed due to
the lack of web implementation. Thanks to @lukepighetti and
@benthillerkus for their work on the closed PR.

### Description

- Adds `ColorFilter.saturation`



https://github.com/user-attachments/assets/67d8acf0-35d0-42de-a24b-f24eed14e9a8


## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. platform-web Web applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Add Desaturate widget

3 participants