Bug 227539 - PixelBufferConversion.h functions should be tested so they can be modified
Summary: PixelBufferConversion.h functions should be tested so they can be modified
Status: ASSIGNED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kimmo Kinnunen
URL:
Keywords: InRadar
Depends on:
Blocks: 227538
  Show dependency treegraph
 
Reported: 2021-06-30 11:03 PDT by Kimmo Kinnunen
Modified: 2021-07-07 11:04 PDT (History)
5 users (show)

See Also:


Attachments
Patch (18.51 KB, patch)
2021-06-30 11:09 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff
Patch (18.80 KB, patch)
2021-07-01 01:16 PDT, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kimmo Kinnunen 2021-06-30 11:03:11 PDT
PixelBufferConversion.h functions should be tested so they can be modified more easily
Comment 1 Kimmo Kinnunen 2021-06-30 11:09:08 PDT
Created attachment 432611 [details]
Patch
Comment 2 Kenneth Russell 2021-06-30 17:24:15 PDT
Comment on attachment 432611 [details]
Patch

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

Looks good overall; couple of tiny questions. Setting r+ to allow this to be landed asynchronously.

One question: on which EWS bot did the new test run? Looked through a few, but didn't find it.

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:5526
> +		FD3160BF12B0272A00C1A359 /* (null) in Headers */ = {isa = PBXBuildFile; };

This change looks wrong.

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:31778
> +				FD3160BF12B0272A00C1A359 /* (null) in Headers */,

Similarly here.

> Tools/TestWebKitAPI/Tests/WebCore/PixelBufferConversionTest.cpp:111
> +    v = v * 255 / alpha;

Here and in the premultiply routine: I never remember what intermediate types C++ promotes these mathematical expressions to. Is there a need to upcast to floating-point before dividing by alpha or 255, and then downcast back to uint8_t?

> Tools/TestWebKitAPI/Tests/WebCore/PixelBufferConversionTest.cpp:228
> +    EXPECT_EQ(expectedPixels, resultPixels);

No tolerance necessary?
Comment 3 Kimmo Kinnunen 2021-07-01 01:16:53 PDT
Created attachment 432669 [details]
Patch
Comment 4 Kimmo Kinnunen 2021-07-01 08:51:53 PDT
(In reply to Kenneth Russell from comment #2)
> Comment on attachment 432611 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=432611&action=review
> 
> Looks good overall; couple of tiny questions. Setting r+ to allow this to be
> landed asynchronously.

Thanks for looking and commenting!
I'll revise the patch a bit later, intending to add few more test-cases.

> /Tests/WebCore/PixelBufferConversionTest.cpp:111
> > +    v = v * 255 / alpha;
> 
> Here and in the premultiply routine: I never remember what intermediate
> types C++ promotes these mathematical expressions to. Is there a need to
> upcast to floating-point before dividing by alpha or 255, and then downcast
> back to uint8_t?

Not in the sense that if the definition of the premultiplication equation is in ints, these should be in ints.
The equations in the test-case are intended to replicate the "this is the equation webkit uses for premultiplication" exactly.

> 
> > Tools/TestWebKitAPI/Tests/WebCore/PixelBufferConversionTest.cpp:228
> > +    EXPECT_EQ(expectedPixels, resultPixels);
> 
> No tolerance necessary?

The idea is that the premultiplication should be deterministic.
Comment 5 Kimmo Kinnunen 2021-07-01 09:01:53 PDT
> v = v * 255 / alpha;
> 
> Here and in the premultiply routine: I never remember what intermediate
> types C++ promotes these mathematical expressions to. 

And the types are (as far as I understand the C++ type promotion):
uint8_t v
int 255 
uint8_t alpha

Promotes v to int to do the multiplication.
Promotes alpha to int to do the division.
Casts the result to uint8_t for the assignment.

All of the promotions in the equations just use the "int promotion rule", where types smaller than int are promoted to int to do any arithmetic.
Comment 6 Radar WebKit Bug Importer 2021-07-07 11:04:17 PDT
<rdar://problem/80279213>