Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unpackColorSpace tests to tex-image-and-sub-image-2d-with-video #3404

Merged
merged 5 commits into from May 17, 2022

Conversation

ccameron-chromium
Copy link
Contributor

Change the test to use named colors, such as 'Red' and 'Green', and add the utility function namedColorInColorSpace to provide color space conversion.

Several tests replicate the behavior of converting a color from an 8-bit RGBA value to how that color will appear when sampled with a given internal format. Move this functionality to a colorAsSampledWithInternalFormat function.

Some of the tests started failing when using RGBA4 as an internal format, because the values being tested were no longer 0 or 255. Add a tolerance utility function to compute the appropriate for a given internalformat, format, and type.

To all test cases in tex-image-and-sub-image-2d-with-video.js, add an unpackColorSpace parameter. Cross-product all tests with the set of all color spaces. Add a utility function to perform this cross-product.

@CLAassistant
Copy link

CLAassistant commented Apr 27, 2022

CLA assistant check
All committers have signed the CLA.

*/
var crossProductTestCasesWithUnpackColorSpaces = function(cases, unpackColorSpaces)
{
var caseWithColorSpace = function(c, cs) { return Object.assign({}, c, {unpackColorSpace:cs}); }
Copy link
Contributor

Choose a reason for hiding this comment

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

return Object.assign({}, c, {unpackColorSpace:cs})

can be shortened to

return {...c, ...{unpackColorSpace:cs}};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This didn't work when I tested against FF, so I left it unchanged.

Copy link
Contributor

Choose a reason for hiding this comment

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

How did you test? Works in Firefox just fine AFAIK

https://jsgist.org/?src=c212a3fa63ff82bc55c88b73fd996b1b

I've been using it for years

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, no idea what I did wrong. Now it works fine. Updated.

{
var caseWithColorSpace = function(c, cs) { return Object.assign({}, c, {unpackColorSpace:cs}); }
var casesList = unpackColorSpaces.map(cs => cases.map(c => caseWithColorSpace(c, cs)));
return [].concat.apply([], casesList);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this just be

return caseList;

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

casesList ends up being
[[list of cases with srgb], [list of cases with display-p3]]
and so the concat moves them all into a single list.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case you can use flat

return caseList.flat()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Member

@kenrussell kenrussell left a comment

Choose a reason for hiding this comment

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

Thanks @ccameron-chromium for writing this - looks like a solid improvement to start handling color spaces. I verified that this is a no-op in current Chrome Canary on macOS, but didn't test it with experimental web features turned on.

Approving now; a few small comments and questions throughout.

*/
var crossProductTestCasesWithUnpackColorSpaces = function(cases, unpackColorSpaces)
{
var caseWithColorSpace = function(c, cs) { return {...c, ...{unpackColorSpace:cs}}; }
Copy link
Member

Choose a reason for hiding this comment

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

Seeing the earlier discussion with @greggman , having done some reading, and not having seen this trick before - could you please add a comment like:

// Merge test case and unpackColorSpace using spread operator

? I spent some time wondering if two iterables with multiple items each were being folded into a dictionary.

Copy link
Contributor

@greggman greggman May 8, 2022

Choose a reason for hiding this comment

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

I want to respond constructively. Using the spread operator in 2022 is normal idiomatic JavaScript. Does it really need it described? I get that you didn't know it but now that you do if you browse most modern JavaScript you'll see it everywhere. For example here's the react docs using it. Here's the redux toolkit using it. And svelte

If you really feel it's important then sure, keep the comment but then it seems like every use of the spread operator will need to be explained by a comment since you can't assume devs will find this one explanation.

Is it just this particular one off usage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm certainly not helping the situation by using 1 and 2 character variable names almost exclusively :)

I've updated the variable names to be more self-documenting.

sdk/tests/js/webgl-test-utils.js Show resolved Hide resolved
sdk/tests/js/webgl-test-utils.js Show resolved Hide resolved
if ('unpackColorSpace' in gl)
return ['srgb', 'display-p3'];
else
return [null];
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to use undefined rather than null here? (Maybe not.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to undefined.

var namedColorInColorSpace = function(colorName, colorSpace) {
var result;
switch (colorSpace) {
case null:
Copy link
Member

Choose a reason for hiding this comment

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

If null is changed to undefined in unpackColorSpacesToTest, above, then this would have to be changed too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@kenrussell kenrussell left a comment

Choose a reason for hiding this comment

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

Looks good!

If run time of these tests appears to be a problem then we can revisit these changes.

@kenrussell kenrussell merged commit 9361dbf into KhronosGroup:main May 17, 2022
kenrussell added a commit to kenrussell/WebGL that referenced this pull request May 21, 2022
kenrussell added a commit that referenced this pull request May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants