Bug 212945 - Extended Color: Streamline SimpleColor premulitply/unpremultiply code
Summary: Extended Color: Streamline SimpleColor premulitply/unpremultiply code
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sam Weinig
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-06-08 18:15 PDT by Sam Weinig
Modified: 2020-06-09 14:46 PDT (History)
3 users (show)

See Also:


Attachments
Patch (11.16 KB, patch)
2020-06-08 18:23 PDT, Sam Weinig
no flags Details | Formatted Diff | Diff
Patch (11.45 KB, patch)
2020-06-09 12:27 PDT, Sam Weinig
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Weinig 2020-06-08 18:15:21 PDT
Extended Color: Streamline SimpleColor premulitply/unpremultiply code
Comment 1 Sam Weinig 2020-06-08 18:23:01 PDT
Created attachment 401404 [details]
Patch
Comment 2 Sam Weinig 2020-06-08 18:23:40 PDT
Now that the signatures only take SimpleColors, I am not sure if I should just make these members of SimpleColor. For now, this feels a lot more clear.
Comment 3 Darin Adler 2020-06-09 11:21:13 PDT
For simple value types with no hidden state like SimpleColor, I personally want member functions kept to the absolute minimum. Free functions are far more flexible.

But also, I wish this was a different programming language, where syntax and encapsulation weren’t so closely tied together.
Comment 4 Sam Weinig 2020-06-09 12:27:46 PDT
Created attachment 401461 [details]
Patch
Comment 5 Darin Adler 2020-06-09 12:51:24 PDT
Comment on attachment 401461 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=401461&action=review

> Source/WebCore/ChangeLog:9
> +        - Removing overloads that didn't took the seperated components, keeping 

"didn't took the separated" is not good grammar, and spells "separated" wrong

> Source/WebCore/ChangeLog:14
> +        - Simplifying the names from makePremultipliedSimpleColor/makeUnpremultipliedSimpleColor
> +          to premultiplyFlooring/premultiplyCeiling/unpremultiply.

The use of "ceil" here as a verb with "ceiling" as its gerund is not awesome.

No call for premultiplying with rounding?

I’m not sure how I feel about these functions with verb names. I think we would call these "premultiplied" rather than "premultiply", but not sure that fully works with the rest of the naming.

> Source/WebCore/ChangeLog:15
> +        - Where component order is impotant, use valueAsARGB() explicitly to

"impotant"

> Source/WebCore/platform/graphics/Color.cpp:269
> +    // Since premultiplyCeiling() bails on zero alpha, special-case that.

Seems like something we might eventually want to address.

> Source/WebCore/platform/graphics/Color.cpp:270
> +    auto premultFrom = from.alpha() ? premultiplyCeiling(from.toSRGBASimpleColorLossy()) : Color::transparent;

I would have renamed all these "premult" to "premultiplied".

> Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp:83
> +            auto pixelColor = unpremultiply(SimpleColor { *pixel });

I’m not sure I am on board with the strategy where we use valueAsARGB() to emphasize the meaning of the returned integer, but construct SimpleColor from a 32-bit integer with no disambiguation for the meaning there. Maybe there’s a future step coming to solve that?
Comment 6 Sam Weinig 2020-06-09 13:54:19 PDT
(In reply to Darin Adler from comment #5)
> Comment on attachment 401461 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=401461&action=review
> 
> > Source/WebCore/ChangeLog:9
> > +        - Removing overloads that didn't took the seperated components, keeping 
> 
> "didn't took the separated" is not good grammar, and spells "separated" wrong
> 
> > Source/WebCore/ChangeLog:14
> > +        - Simplifying the names from makePremultipliedSimpleColor/makeUnpremultipliedSimpleColor
> > +          to premultiplyFlooring/premultiplyCeiling/unpremultiply.
> 
> The use of "ceil" here as a verb with "ceiling" as its gerund is not awesome.
> 
> No call for premultiplying with rounding?

Agreed, though I stole the name from your patch on 180620 :)

> 
> I’m not sure how I feel about these functions with verb names. I think we
> would call these "premultiplied" rather than "premultiply", but not sure
> that fully works with the rest of the naming.
> 
> > Source/WebCore/ChangeLog:15
> > +        - Where component order is impotant, use valueAsARGB() explicitly to
> 
> "impotant"

Will fix.

> 
> > Source/WebCore/platform/graphics/Color.cpp:269
> > +    // Since premultiplyCeiling() bails on zero alpha, special-case that.
> 
> Seems like something we might eventually want to address.

Yeah, since we check for 0 already there, we could totally just return transparent there. Will look into that in a follow up.

> 
> > Source/WebCore/platform/graphics/Color.cpp:270
> > +    auto premultFrom = from.alpha() ? premultiplyCeiling(from.toSRGBASimpleColorLossy()) : Color::transparent;
> 
> I would have renamed all these "premult" to "premultiplied".

Will fix.

> 
> > Source/WebCore/platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp:83
> > +            auto pixelColor = unpremultiply(SimpleColor { *pixel });
> 
> I’m not sure I am on board with the strategy where we use valueAsARGB() to
> emphasize the meaning of the returned integer, but construct SimpleColor
> from a 32-bit integer with no disambiguation for the meaning there. Maybe
> there’s a future step coming to solve that?

Yeah, my thought was to introduce a makeSimpleColorFromARGB (or some name like that) at some point and remove the constructor. From Simon's comments in other bugs, the fact that we use ARGB as the format is a bit surprising to some, so might as well make it explicit.

Thanks for the review.
Comment 7 Sam Weinig 2020-06-09 14:05:11 PDT
Committed r262810: <https://trac.webkit.org/changeset/262810>
Comment 8 Radar WebKit Bug Importer 2020-06-09 14:06:21 PDT
<rdar://problem/64179100>
Comment 9 Darin Adler 2020-06-09 14:46:55 PDT
Maybe at some point we’ll change our minds and use a different class for the premultiplied data. Presumably you can’t use it in a Color and have it work correctly. It’s another aspect of how to interpret the channel values, analogous to color space. And SimpleColor is 4 bytes that are implicitly in the sRGB space and should probably also be implicitly not premultiplied for the same reason. As opposed to a more general "4 channels with no judgment about how they are used".