Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Added float32 support to decodeImageFromPixels #40068

Merged
merged 4 commits into from
Mar 15, 2023

Conversation

gaaclarke
Copy link
Member

fixes flutter/flutter#121730

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

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

@gaaclarke gaaclarke force-pushed the decodeImageFromPixels-float32 branch from 2c50f7b to b43c685 Compare March 4, 2023 00:47
@gaaclarke gaaclarke marked this pull request as ready for review March 4, 2023 00:49
@gaaclarke gaaclarke requested a review from dnfield March 4, 2023 00:49
@gaaclarke
Copy link
Member Author

I'm going to move this back to a draft until #40031 lands. I suspect that as this is written it will create a texture that is in the f32 format. That can cause things like getByteData to fail since it is looking for f32 or bgr10_xr. We can add that test after that lands.

@gaaclarke gaaclarke marked this pull request as draft March 6, 2023 19:19
@gaaclarke gaaclarke force-pushed the decodeImageFromPixels-float32 branch 2 times, most recently from 62453fb to a54af45 Compare March 7, 2023 18:17
@gaaclarke
Copy link
Member Author

I've rebased this onto #40031 and #40097, after those land I'll rebase this onto main and this should be ready to review.

@gaaclarke gaaclarke force-pushed the decodeImageFromPixels-float32 branch from a54af45 to 0fb933c Compare March 14, 2023 22:27
@gaaclarke gaaclarke marked this pull request as ready for review March 14, 2023 22:27
@gaaclarke
Copy link
Member Author

@dnfield the dependent PR has landed so this is ready for review now.

Comment on lines +90 to +91
case kRGBA_F32_SkColorType:
return kRGBA_F16_SkColorType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not

Suggested change
case kRGBA_F32_SkColorType:
return kRGBA_F16_SkColorType;
case kRGBA_F32_SkColorType:
case kRGBA_F16_SkColorType:
return kRGBA_F16_SkColorType;

Copy link
Member Author

Choose a reason for hiding this comment

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

There isn't a way to send in kRGBA_F16_SkColorType directly. If we decide to implement that it will probably be better to do that in its own pr with its own tests.

switch (pixel_format) {
case PixelFormat::kRGBA8888:
color_type = kRGBA_8888_SkColorType;
break;
case PixelFormat::kBGRA8888:
color_type = kBGRA_8888_SkColorType;
break;
case PixelFormat::kRGBAFloat32:
color_type = kRGBA_F32_SkColorType;
alpha_type = kUnpremul_SkAlphaType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these unpremul but the other ones are premul?

Copy link
Member Author

Choose a reason for hiding this comment

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

From the Dart API perspective it's not the only one that uses unpremultiplied, rawStraightRgba also returns unpremultiplied alpha. I'm not sure what flow of the code that goes through to achieve it, but I'm maintaining the old behavior here for old flows. I chose to make this unpremultiplied since that is the most expected result and the benefits of using premultiplied alpha don't exist here since we have to do a conversion anyway because we can't use f32 directly, we have to convert to f16.

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a comment about that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I got a bit confused between toByteData and decodeImageFromPixels. The input to toByteData was documented as non-premultiplied, but the input to decodeImageFromPixels wasn't. I've updated all the documentation for ui.PixelFormat to be explicit about pixel format. I also added a comment in this code. The important thing is I wanted ImageByteFormat.rawExtendedRgba128 and PixelFormat.rgbaFloat32 to match so people can easily download, tweak, then reupload.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 15, 2023
@auto-submit auto-submit bot merged commit cc846da into flutter:main Mar 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make decodeImageFromPixels support wide gamut colors
2 participants