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 the definition of pixelated for createImageBitmap. #10491

Merged
merged 4 commits into from
Aug 5, 2024

Conversation

schenney-chromium
Copy link
Contributor

@schenney-chromium schenney-chromium commented Jul 17, 2024

The definition of pixelated image scaling in https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-resizequality-pixelated was broken by an earlier edit. Fix it by adopting the CSS definition of pixelated from https://drafts.csswg.org/css-images-3/#valdef-image-rendering-pixelated. Effort was made to integrate the CSS definition into the existing content (createImageBitmap does not support the same set of smoothing options as CSS)..

Fixed: #3485

  • At least two implementers are interested (and none opposed):
    • All browsers implement this and the spec should match the intent.
  • Tests are written and can be reviewed and commented upon at:
    • WPT html/canvas/element/manual/imagebitmap/canvas-createImageBitmap-resize.html
  • Implementation bugs are filed:
    • N/A
  • MDN issue is filed: N/A
  • The top of this comment includes a clear commit message to use.

/imagebitmap-and-animations.html ( diff )

source Outdated
Comment on lines 115863 to 115867
<p>To implement "<span data-x="dom-ResizeQuality-pixelated">pixelated</span>", for each axis
independently, first determine the integer multiple of its natural size that
puts it closest to the target size and is greater than zero. Scale it to this
integer-multiple-size using nearest neighbor, then scale it the rest of the way to the target
size using an interpolation method.</p>
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be located together with the enum value definition above.

Also, in the note directly above this it says that for pixelated there is a specific algorithm, which doesn't really appear to be the case. We should probably fix that while 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.

I can certainly move it up with the enum. I was unsure where to put it.

Pixelated is more specific than the others, but I agree it is not fully defined. Could I address that by changing "... using an interpolation method." to "... using bilinear interpolation." The latter is the actual intent.

Or am I misunderstanding and you're saying it's not formatted as an algorithm with numbered steps etc. I could do that too.

Copy link
Member

Choose a reason for hiding this comment

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

If you specify the interpolation method I think that's clear enough for now.

At some point what happens should be defined as part of the overall algorithm that manipulates an image, but that's the larger rewrite I failed at completing many years ago. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. New version up that I think addresses the issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ping. Just trying to wrap things up.

Copy link
Member

Choose a reason for hiding this comment

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

I'm unable to push my editorial tweaks because "Allow edits from maintainers" is not checked for this PR. Can you enable that?

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 not seeing the checkbox to allow edits in the location that GiitHub docs say it should exist (below the Notifications component). Am I missing something? Is there another way to communicate the edits?

Copy link
Member

Choose a reason for hiding this comment

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

The reason it's not on by default is because you're doing this from an organizational fork instead of an individual one. But in the past other Igalians like @Ms2ger have succeeded in finding and checking the box...

Anyway, I'll just give you the diff instead.

iff --git a/source b/source
index 12624faf..17ae0c22 100644
--- a/source
+++ b/source
@@ -115842,11 +115842,10 @@ <h3 split-filename="imagebitmap-and-animations">Images</h3>
   smoothing as necessary to avoid distorting the image when the target size is not a clean multiple
   of the original.</p>
 
-  <p>To implement "<span data-x="dom-ResizeQuality-pixelated">pixelated</span>", for each axis
-  independently, first determine the integer multiple of its natural size that
-  puts it closest to the target size and is greater than zero. Scale it to this
-  integer-multiple-size using nearest neighbor, then scale it the rest of the way to the target
-  size using bilinear interpolation.</p>
+  <p>To implement "<code data-x="dom-ResizeQuality-pixelated">pixelated</code>", for each axis
+  independently, first determine the integer multiple of its natural size that puts it closest to
+  the target size and is greater than zero. Scale it to this integer-multiple-size using nearest
+  neighbor, then scale it the rest of the way to the target size using bilinear interpolation.</p>
 
   <p>The "<dfn enum-value for="ResizeQuality"><code data-x="dom-ResizeQuality-low">low</code></dfn>"
   value indicates a preference for a low level of image interpolation quality. Low-quality image
@@ -115864,7 +115863,8 @@ <h3 split-filename="imagebitmap-and-animations">Images</h3>
   <p class="note">Bilinear scaling is an example of a relatively fast, lower-quality image-smoothing
   algorithm. Bicubic or Lanczos scaling are examples of image-scaling algorithms that produce
   higher-quality output. This specification does not mandate that specific interpolation algorithms
-  be used, except for "<span data-x="dom-ResizeQuality-pixelated">pixelated</span>" as described above.</p>
+  be used, except for "<code data-x="dom-ResizeQuality-pixelated">pixelated</code>" as described
+  above.</p>
 
   </div>

Copy link
Member

Choose a reason for hiding this comment

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

Hm, not sure that I did find the checkbox; I may have had to move my PRs to my own fork. I'll delete the organisational fork once this PR is in. (Grumbles at GitHub)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Edits applied. Much annoyance with GitHub authentication.

@domenic domenic merged commit 8c74909 into whatwg:main Aug 5, 2024
2 checks passed
@Ms2ger Ms2ger deleted the pixelated branch August 14, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

"pixelated" resize quality allows bilinear interpolation.
4 participants