Skip to content

Create and draw image with raw ARGB32 data #1052

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

Closed
paramaggarwal opened this issue Dec 14, 2017 · 3 comments
Closed

Create and draw image with raw ARGB32 data #1052

paramaggarwal opened this issue Dec 14, 2017 · 3 comments

Comments

@paramaggarwal
Copy link

paramaggarwal commented Dec 14, 2017

Feature

I want to render image on the canvas from raw RGBA32 data - the same format data that is the output from canvas.toBuffer('raw'). Please guide me on how to expose the relevant variable.

The final else condition here: src/Image.cc#L256-L28 needs to be to set the raw buffer as is - that should enable this usecase.

Please help - thanks.

Steps to Reproduce

var Canvas = require('canvas');
var canvas = Canvas.createCanvas(1, 1);
var ctx = canvas.getContext('2d');

var i = new Image();
i.src = new Buffer('F000', 'hex'); // single red pixel image - raw RGBA32
i.onerror = console.error;

Your Environment

  • Version of node-canvas (e.g. 1.4.0): 2.0 alpha
  • Environment (e.g. node 4.2.0 on Mac OS X 10.8): Node 9.3.0 on High Sierra
@zbjornson
Copy link
Collaborator

Does ctx.putImageData satisfy your use case? That's in RGBA32 order already.

(I could see adding support for ARGB32 since putImageData does a sort of byte-swapping from RGBA to ARGB that isn't especially fast right now.)

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/putImageData

@paramaggarwal
Copy link
Author

Oh, wow - hadn't found this when I was searching. Thanks a lot @zbjornson!

The byte-swapping is fine as it's still better than encoding/decoding PNG. Going to close this issue now - thanks!

@paramaggarwal
Copy link
Author

paramaggarwal commented Dec 20, 2017

Hello, I have a small follow-up question - what is the difference between the custom canvas.toBuffer('raw') and the standard ctx.getImageData()? Both of them seem to give the raw canvas data.

EDIT: Found my answer here: #306 (comment)

@zbjornson zbjornson removed the Feature label Apr 29, 2018
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

No branches or pull requests

2 participants