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

Fix color space conversion test #3332

Merged
merged 7 commits into from
Jan 26, 2024

Conversation

greggman
Copy link
Contributor

@greggman greggman commented Jan 26, 2024

The issue was makeInPlaceColorConversion was not actually doing the conversion "in place". To find this I wrote a test to test makeInPlaceColorConversion

Note: I removed a maintenance_todo because colorSpace is in the IDL but it's required so it will never be undefined except on old browsers and so TS things comparing it to undefined is an error.


Requirements for PR author:

  • All missing test coverage is tracked with "TODO" or .unimplemented().
  • New helpers are /** documented */ and new helper files are found in helper_index.txt.
  • Test behaves as expected in a WebGPU implementation. (If not passing, explain above.)

Requirements for reviewer sign-off:

  • Tests are properly located in the test tree.
  • Test descriptions allow a reader to "read only the test plans and evaluate coverage completeness", and accurately reflect the test code.
  • Tests provide complete coverage (including validation control cases). Missing coverage MUST be covered by TODOs.
  • Helpers and types promote readability and maintainability.

When landing this PR, be sure to make any necessary issue status updates.

@greggman greggman requested review from shrekshao and kainino0x and removed request for shrekshao January 26, 2024 00:12
Copy link
Collaborator

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

LGTM w/ nits

});

// Convert the data via our conversion functions
const convertedData = new Uint8ClampedArray(
Copy link
Contributor

Choose a reason for hiding this comment

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

(Not a comment Just for curious).
Would you mind to explain a bit about how this test could detect the behaviour change from = assignment to Object.assign ?

Copy link
Contributor Author

@greggman greggman Jan 26, 2024

Choose a reason for hiding this comment

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

It detects it because makeInPlaceColorConversion, at least by name, is supposed to make an object that is updated "in place"

          const floatColor = { R, G, B, A: 1 };          
          conversionFn(floatColor);
          return [
            floatToU8(floatColor.R),
            floatToU8(floatColor.G),
            floatToU8(floatColor.B),
            floatToU8(floatColor.A),
          ];

This code expects that floatColor is updated. In the assignment (=) version, a new object is created inside the conversion function, That object is then discarded. The function out here is still looking at floatColor with the original unconverted values. When it goes to compare them to the values converted via 2D canvas, they don't match since they're still the unconverted values.

In order to work as it was, this code would need to change to this

          const floatColor = { R, G, B, A: 1 };          
          const convertedColor = conversionFn(floatColor);
          return [
            floatToU8(convertedColor.R),
            floatToU8(convertedColor.G),
            floatToU8(convertedColor.B),
            floatToU8(convertedColor.A),
          ];

I'm happy to change it to this style. I was just going from the momentum given that the function is called makeInPlaceColorConversion

greggman and others added 6 commits January 26, 2024 13:10
The issue was makeInPlaceColorConversion was not actually doing
the conversion "in place". To find this I wrote a test to test
makeInPlaceColorConversion
@greggman greggman force-pushed the fix-color-space-conversion-test branch from d9e1ad3 to 8cde87a Compare January 26, 2024 04:10
@greggman greggman merged commit 99ff37e into gpuweb:main Jan 26, 2024
1 check passed
@greggman greggman deleted the fix-color-space-conversion-test branch January 26, 2024 04:35
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.

3 participants