Skip to content

Update examples section #56

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ccameron-chromium
Copy link
Contributor

Update the examples section to show basic usage of the API.

@ccameron-chromium
Copy link
Contributor Author

This adds an examples section so that readers can get a sense of what common use of the API will look like.

context.putImageData(srgbImageData, 0, 0);

// This will draw P3-red to the canvas.
var p3ImageData = new ImageData(1, 1, {colorSpace:'display-p3'});

Choose a reason for hiding this comment

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

Do we expect ImageData with more than 8-bit depth in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. We removed from this proposal along with >8-bit 2D canvas support. It will be re-introduced in a separate proposal that covers high dynamic range.

Copy link
Contributor

Choose a reason for hiding this comment

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

// specified image, but will clip it to the sRGB color gamut.
var defaultCanvas = document.getElementById('DefaultCanvas');
var defaultCtx = defaultCanvas.getContext('2d');
defaultCtx.drawImage(myWCGImage, 0, 0, image.width, image.height)

Choose a reason for hiding this comment

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

Is there any formal spec on clipping behavior? Same question for getImageData.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CSS Color Module 4 goes over the formal color space conversion math and clamping. If it is ambiguous, it should be made clear. (There is no fancy conversion -- values that don't fit in the target gamut are chopped off).

Copy link
Contributor

Choose a reason for hiding this comment

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

CSS Color Module 4 goes over the formal color space conversion math

yes, [here]

and clamping.

Per-component clamping is discouraged because it can produce massive hue shifts. CSS Color 4 talks about gamut mapping but that section has not yet been specce'ed out. open issue It has been incubated though, again the algorithm is fairly simple. For some use cases, simple clamping is still what you want; so there will be both options.

If it is ambiguous, it should be made clear.

Yes, and it will be.

Also I should point out that in CSS Color 4, partly driven by the needs of Canvas for WCG & HDR, the domain and range f the RGB transfer functions are unbounded. This is to avoid any premature clipping, which would preclude round-tripping; and also because HDR will need that.

gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL,
gl.BROWSER_DEFAULT_WEBGL);
gl.colorSpace = 'display-p3';
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, image.width, image.height, 0,

Choose a reason for hiding this comment

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

Maybe use gl.SRGB8_ALPHA8 here so that image is filtered correctly. The extension for WebGL 1.0 should be universal at this point. Same comment for the ImageBitmap upload.

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 (in both locations).

fetch(myImageUrl).then(function(response) {
return response.blob();
}).then(function(blob) {
return createImageBitmap(blob, 0, 0, 1000, 1000,

Choose a reason for hiding this comment

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

Please consider omitting dimensions here.

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
Contributor

@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.

Good work expanding out these examples @ccameron-chromium . A few relatively minor requests.

Copy link
Contributor

@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, looks much better now!

Copy link
Contributor

@svgeesus svgeesus left a comment

Choose a reason for hiding this comment

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

These detailed examples look great to me.

This example selects a wide color gamut canvas only if the underlying display has a P3 gamut or larger.

```html
// Note that the gamut is named p3, but the color space is 'display-p3'.
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct - this is unfortunate but deliberate. The three MQ gamut buckets are deliberately approximate, basically "normal" "wide" and "superwide". p3 would match an Adobe RGB screen, for example.
While the color spaces, like display-p3, are much more specific and tightly defined.

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.

4 participants