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

Adds convertToBlob to Canvas #3926

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

Conversation

fserb
Copy link
Contributor

@fserb fserb commented Aug 15, 2018

This is pulling a part of: https://github.com/WICG/canvas-color-space/blob/master/CanvasColorSpaceProposal.md into the spec.

This moves the convertToBlob function from offscreenCanvas into canvas (and offscreenCanvas).

@domenic @whatwg/canvas


💥 Error: Wattsi server error 💥

PR Preview failed to build. (Last tried on Jan 15, 2021, 7:58 AM UTC).

More

PR Preview relies on a number of web services to run. There seems to be an issue with the following one:

🚨 Wattsi Server - Wattsi Server is the web service used to build the WHATWG HTML spec.

🔗 Related URL

<html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx/1.10.3</center>
</body>
</html>

If you don't have enough information above to solve the error by yourself (or to understand to which web service the error is related to, if any), please file an issue.

@fserb
Copy link
Contributor Author

fserb commented Aug 15, 2018

@whatwg/canvas (In case the original didn't work)

@annevk
Copy link
Member

annevk commented Aug 16, 2018

Couple of comments:

  • Since HTMLCanvasElement comes first, we should introduce ImageEncodeOptions there.
  • I would introduce a new subsection (inc. heading) for this method. Perhaps as a previous sibling to "The OffscreenCanvas interface" (basically where you have it now, but with a heading)?
  • You cannot talk about the Canvas object since there's no such thing. In the non-normative description you can refer to canvas since you already introduced that variable. In the normative description I'd stick to "this object".

Hope that helps.

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: canvas needs tests Moving the issue forward requires someone to write tests impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation labels Aug 16, 2018
@fserb
Copy link
Contributor Author

fserb commented Aug 21, 2018

I did the ImageEncodeOptions change on the other PR. :/ Should I do it here too?

@annevk
Copy link
Member

annevk commented Aug 22, 2018

You have to pick an order and build the PRs on each other, I think. Either we extend ImageEncodeOptions first and then move it around for convertToBlob() or the other way around. The current setup doesn't lead to logical commits on master.

@annevk
Copy link
Member

annevk commented Aug 22, 2018

(The other PR is #3882 by the way, for those wondering.)

@domenic
Copy link
Member

domenic commented Aug 23, 2018

@annevk's comments generally make sense. Another point to watch out for is how you've changed things compared to the existing algorithm at https://html.spec.whatwg.org/#dom-offscreencanvas-converttoblob. Are all of these changes intentional?

  • The method now works even on detached offscreen canvases.
  • The method no longer creates a copy of the bitmap before going in parallel. That seems very bad and likely to lead to race conditions.

@fserb fserb force-pushed the colormgmt-convertToBlob branch from c71458e to 1ac158a Compare October 9, 2018 17:21
@fserb
Copy link
Contributor Author

fserb commented Oct 9, 2018

Addressed @annevk's original comment and reverted the unintended issues pointed by @domenic.

@foolip
Copy link
Member

foolip commented Oct 30, 2018

There's an Intent to Ship: Canvas Color Management on blink-dev now, pointing back to this PR and #3882. @annevk @domenic, do either of you have the bandwidth to keep reviewing this?

@fserb, I see the "needs tests" label, do the tests in https://wpt.fyi/results/2dcontext/wide-gamut-canvas fully cover the changes in this PR, or are more needed?

@foolip foolip mentioned this pull request Oct 30, 2018
@foolip
Copy link
Member

foolip commented Oct 30, 2018

I'll answer my own question about tests, looks like the only tests involving convertToBlob are for offscreen canvas, so more needed. @fserb, are you up for writing a test PR matching these spec changes?

@chrisdavidmills
Copy link

Documentation need recorded on MDN content roadmap at https://trello.com/c/N0hJJV95/129-2d-canvas-api

source Outdated
dictionary <dfn>ImageEncodeOptions</dfn> {
DOMString <span data-x="image-encode-options-type">type</span> = "image/png";
unrestricted double <span data-x="image-encode-options-quality">quality</span> = 1.0;
<span>ImageEncodePixelFormat</span> <span data-x="image-encode-options-pixelformat">pixelFormat</span> = "uint8";
Copy link
Member

Choose a reason for hiding this comment

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

This option isn't really explained in sufficient detail. Also, I thought we'd postpone adding it to a subsequent PR and only deal with convertToBlob() 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.

Okey, I'll leave just the convertToBlob part.

@annevk
Copy link
Member

annevk commented Oct 31, 2018

@foolip I'm not sure we have other reviewers available? I think the main problem I have at times is the lag between reviews and updates and that probably goes both ways. Not sure what we can do to make that better. Perhaps at times synchronously communicate?

@foolip
Copy link
Member

foolip commented Oct 31, 2018

@annevk, that was my way of asking if I should spend time reviewing this, without obviously volunteering :)

@fserb is in UTC-5, so timezones seem OK for all involved.

@fserb
Copy link
Contributor Author

fserb commented Nov 1, 2018

@foolip, we do have canvas convertToBlob tests too at 2dcontext/wide-gamut-canvas/canvas-colorManaged-convertToBlob-roundtrip.html. Is that what you were talking about?

@foolip
Copy link
Member

foolip commented Nov 1, 2018

Oh, there it is. I must have made a typo when grepping.

@fserb fserb force-pushed the colormgmt-convertToBlob branch from d8ead47 to d33ff1b Compare November 6, 2018 14:44
@fserb
Copy link
Contributor Author

fserb commented Nov 6, 2018

Trying to make those PRs smaller. This one now just moves convertToBlob to also include Canvas.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

Are there tests for this?

The one other problem here that was already a problem is that we don't parse the MIME type argument and we don't state how we set the MIME type for the resulting Blob object. It would be good to make that use the MIME type infrastructure of the web platform and be clear if any unknown parameters get passed through, result in rejection, etc.

source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
@annevk
Copy link
Member

annevk commented Nov 6, 2018

I also wonder if we should preserve the old ID for convertToBlob(). I guess it might be okay given that OffscreenCanvas is still relatively new.

@fserb
Copy link
Contributor Author

fserb commented Nov 7, 2018

Done all. PTAL.

@annevk
Copy link
Member

annevk commented Nov 8, 2018

(You also didn't reply to a bunch of the non-code questions/comments?)

@fserb
Copy link
Contributor Author

fserb commented Nov 9, 2018

Regarding the WPT tests, we have a canvas-colorManaged-convertToBlob-roundtrip.html But we could probably add more tests.

I agree that given that convertToBlob() is kinda new, we can stick to the new ID.

I'll work on additional resolution steps for the MIME type.

@fserb
Copy link
Contributor Author

fserb commented Nov 9, 2018

@annevk is that what you had in mind?

Put convertToBlob/toDataURL/toBlob together in a "Serializing canvas bitmaps" section, and merged that with the former "Serializing bitmaps to a file" section
Can't link to specific concepts since they're polymorphic
@domenic
Copy link
Member

domenic commented Nov 9, 2018

I'm pushing some last fixes. That will include reverting the MIME type work because I think it's too involved to get in to now. In particular we need to treat the three conversion functions the same way, which we currently are not. It's better to leave it as-is.

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

With my latest pushes this LGTM. @annevk for a final look?

Are there other implementers from @whatwg/canvas interested in allowing convertToBlob() on <canvas> elements, not just OffscreenCanvases?

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

The reordering makes this hard to review, but I guess it's okay? And yeah, it seems like what's still lacking is impl interest and tests. A follow-up issue for MIME types might be good too.

source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
@foolip
Copy link
Member

foolip commented Dec 5, 2018

@annevk @domenic is this good to merge now?

@foolip
Copy link
Member

foolip commented Dec 5, 2018

Scratch that question, the answer is: "seems like what's still lacking is impl interest and tests"

@fserb, will you be adding more tests for this?

@foolip
Copy link
Member

foolip commented Dec 5, 2018

On impl interest, @smfr commented in #4167 (comment) with support.

@annevk
Copy link
Member

annevk commented Dec 5, 2018

Right, I understand there's interest from Google, but we need two implementers per https://whatwg.org/working-mode#changes.

@foolip
Copy link
Member

foolip commented Dec 5, 2018

@smfr doesn't work for Google :)

@annevk
Copy link
Member

annevk commented Dec 10, 2018

That's true, though that comment wasn't very specific (seemed to be mostly about the float16 backing store). In any event, we also seem to be waiting on tests as you noted earlier.

Base automatically changed from master to main January 15, 2021 07:57
@annevk
Copy link
Member

annevk commented Apr 28, 2021

What's the status here? Has this been implemented/shipped/abandoned?

@fserb
Copy link
Contributor Author

fserb commented Apr 28, 2021

This has been implemented on Chrome but not shipped.

It's one of those things that people will need once other color management feature gets traction (as will there be no way to export a canvas with a specified color space). Which I think is why @foolip suggested that support for color management kinda implies support for this.

It's also a better API, and already implemented for OffscreenCanvas. Could we get a +1 from other impl?

@annevk
Copy link
Member

annevk commented Apr 28, 2021

Let's ping @whatwg/canvas once more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation needs implementer interest Moving the issue forward requires implementers to express interest needs tests Moving the issue forward requires someone to write tests topic: canvas
Development

Successfully merging this pull request may close these issues.

5 participants