-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Proposal: CanvasRenderingContext2D#getImageData should accept optional target ImageData parameter #5707
Comments
Was already proposed in #4748 |
cc @whatwg/canvas |
Yes, this is low-hanging fruit and we should do it. |
Small quibble on the signature, presumably you don't need width and height parameters as the target already has those. And since you don't need a return value perhaps we should have a new method, e.g.,
It seems that should fail though if destination points to a detached buffer so you cannot transfer to workers, but rather have to copy, right? |
The ImageData can be constructed from a TypedArray, so you can still transfer the buffer back and forth and only create a new ImageData wrapper. |
Wouldn't that mean an unnecessary extra allocation of memory to hold the pixels, thus mem and CPU waste?
Not just useful, but necessary for avoiding memory allocation. |
This comment has been minimized.
This comment has been minimized.
Let's forward duplicate this into #10855 as that has some momentum. |
At this point
CanvasRenderingContext2D#getImageData
returns a copy of the existing buffer. This may be a performance problem for applications where one needs to process theImageData
ideally 60 times per second.One nice feature to have for
getImageData
would be an additionaltargetImageData
parameter, in that casegetImageData
would write the bytes over the target buffer rather than creating a new ImageData.Example usage:
Any feedback on that?
The text was updated successfully, but these errors were encountered: