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

createImageBitmap: Allow resizing without cropping #1546

Closed
wants to merge 1 commit into from

Conversation

jakearchibald
Copy link
Contributor

Small change to step 2 of https://html.spec.whatwg.org/#cropped-to-the-source-rectangle-with-formatting, avoids returning just because cropping isn't set.

+@junov

@junov
Copy link
Member

junov commented Jul 13, 2016

I don't understand this change. How would you determine the crop rect in step 8 if those arguments are omitted?

@jakearchibald
Copy link
Contributor Author

Might need a small spec change, but the default crop should be no crop, as in starts at 0,0 and ends width,height.

@junov
Copy link
Member

junov commented Jul 13, 2016

Isn't that equivalent to what step 2 is already doing by returning 'input' (uncropped)?

@jakearchibald
Copy link
Contributor Author

Then when does the resize happen?

@junov
Copy link
Member

junov commented Jul 13, 2016

Ah, now I see the problem! Perhaps we should just move step 2 to after step 6.

@domenic
Copy link
Member

domenic commented Jul 13, 2016

I wonder if we should introduce another intermediate variable that is the result of scaling input. It seems a bit weird to just "scale input" in place.

Moving the return after step 6 makes sense to me. @jakearchibald, up for making that change?

@jakearchibald
Copy link
Contributor Author

Shall do

@jakearchibald
Copy link
Contributor Author

jakearchibald commented Jul 14, 2016

Updated the PR - instead of moving the step, I moved the cropping related parts to substeps.

@@ -92513,23 +92511,35 @@ dictionary <dfn>ImageBitmapOptions</dfn> {
data-x="dom-ImageBitmapOptions-resizeQuality">resizeQuality</code></dfn> option to guide the
Copy link
Member

Choose a reason for hiding this comment

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

You didn't do the intermediate variable thing that Domenic suggested to avoid resizing in-place. Should be something like "Let resizedImage be be the result of resizing input ..."

@jakearchibald
Copy link
Contributor Author

Ok, take 3.

This time I've also moved cropping before resizing, and if the crop rectangle is outside the dimensions of the original image, it's clipped to the dimensions of the input, which is consistent with drawImage.


<li><p>If the <var>sx</var>, <var>sy</var>, <var>sw</var>, and <var>sh</var> arguments are omitted, return <var>input</var>.</p></li>
<li><p>If not specified, the <var>sx</var> and <var>sy</var> arguments must default to 0, and
the <var>sw</var> and <var>sh</var> arguments must default to the intrinsic width and height of
Copy link
Member

Choose a reason for hiding this comment

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

The notion of intrinsic size needs an x-ref

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is "intrinsic" needed here, given that image bitmaps have a specific width & height? (This might be related to the whole rasterization thing, as this algorithm probably shouldn't take a bitmap)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(the current spec doesn't make an x-ref)

Copy link
Member

Choose a reason for hiding this comment

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

Right, we could just refer to the width and height attributes of input.

@jakearchibald
Copy link
Contributor Author

Updated. Will squash the commits if everyone's happy with it.


<li><p>If either or both of <code data-x="dom-ImageBitmapOptions-resizeWidth">resizeWidth</code>
and <code data-x="dom-ImageBitmapOptions-resizeHeight">resizeHeight</code> members of
<var>options</var> are less than or equal to 0, then return a promise rejected with
<span>"<code>InvalidStateError</code>"</span> <code>DOMException</code> and abort these steps.</p></li>

<li>

<p>If Let <var>sx</var>, <var>sy</var>, <var>sw</var> and <var>sh</var> are specified, let
Copy link
Member

Choose a reason for hiding this comment

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

s/Let //

@domenic
Copy link
Member

domenic commented Jul 19, 2016

Left some editorial comments. Will leave it to @junov to review the normative parts, notably the change from large sw/sh creating black pixels, to them not doing so; I kind of doubt that's web-compatible, but maybe ImageBitmap is new enough that it's fine...

<var>sourceRectangle</var> be a rectangle whose corners are the four points (<var>sx</var>,
<var>sy</var>), (<var>sx</var>+<var>sw</var>, <var>sy</var>),(<var>sx</var>+<var>sw</var>,
<var>sy</var>+<var>sh</var>), (<var>sx</var>,<var>sy</var>+<var>sh</var>). Otherwise let
<var>sourceRectangle</var> be a rectangle whose corners are the four points (0,0), (width of
Copy link
Member

Choose a reason for hiding this comment

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

width -> <span data-x="dom-ImageBitmap-width">width</span>
Same for height

Copy link
Member

Choose a reason for hiding this comment

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

I don't think that's correct, since input is bitmap data, not an ImageBitmap. The spec says

An ImageBitmap object whose [[Detached]] internal slot value is false always has associated bitmap data, with a width and a height.

but doesn't have <dfn>s around width and height here (which IMO is fine).

Copy link
Member

Choose a reason for hiding this comment

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

Right. I retract.

@junov
Copy link
Member

junov commented Jul 19, 2016

+1 for the normative changes
lgtm with editorial comments addressed

* No longer exits early if no cropping specified
* Cropping happens before resizing
* If the crop rectangle is outside the dimensions of the original image, it's clipped, which is consistent with drawImage
* If only one of resizeWidth / resizeHeight is specified, it maintains ratio with the cropped area
@jakearchibald
Copy link
Contributor Author

Editorial comments addressed & squashed. Thanks for dragging me through this.

domenic pushed a commit that referenced this pull request Jul 20, 2016
* No longer exits early if no cropping specified
* Cropping happens before resizing
* If the crop rectangle is outside the dimensions of the original image,
  it's clipped, which is consistent with drawImage
* If only one of resizeWidth / resizeHeight is specified, it maintains
  ratio with the cropped area

PR: #1546
@domenic
Copy link
Member

domenic commented Jul 20, 2016

Awesome!! Merged as a10a3a8 (I added one extra forgotten period at the end of a sentence.)

@domenic domenic closed this Jul 20, 2016
@jakearchibald
Copy link
Contributor Author

\o/

@hassanbazzi
Copy link

Sick.

alice pushed a commit to alice/html that referenced this pull request Jan 8, 2019
* No longer exits early if no cropping specified
* Cropping happens before resizing
* If the crop rectangle is outside the dimensions of the original image,
  it's clipped, which is consistent with drawImage
* If only one of resizeWidth / resizeHeight is specified, it maintains
  ratio with the cropped area

PR: whatwg#1546
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.

4 participants