Add raw image support - #1256
Conversation
zbjornson
left a comment
There was a problem hiding this comment.
Looks good. Needs a conflict fixed again (sorry), and ideally one trivial change.
I can make the changes real quick if you want.
Conflicts: test/image.test.js
| */ | ||
| NAN_GETTER(Image::GetRawData) { | ||
| Image *img = Nan::ObjectWrap::Unwrap<Image>(info.This()); | ||
| if (img->_surface) { |
There was a problem hiding this comment.
Would prefer to have this as a guard instead, e.g.
if (!img->_surface) {
info.GetReturnValue().Set(Nan::Undefined());
return;
}
// ...| } else { | ||
| info.GetReturnValue().Set(Nan::Undefined()); | ||
| } | ||
| return; |
There was a problem hiding this comment.
No need to return at the end of the function
There was a problem hiding this comment.
Also don't need the else { set undefined } block -- that's implicit if you didn't set another return value.
| var buf = img.rawData; | ||
| assert.ok(buf instanceof Buffer); | ||
| assert.strictEqual(409600, img.rawData.length); | ||
| }); |
There was a problem hiding this comment.
Please follow standard style here (2 spaces indentation, space between function and (), no semicolons)
|
Personally not a fan of tacking more non-standard things on to the prototype 🤔 I do see the use case though. Generally, what do we think about having these as standalone exported functions? Not sure that this is a good idea, but it could be something like this: const { getRawImageBuffer } = require('canvas')
// img = ...
const buffer = getRawImageBuffer(img)Just a thought 🤔 💭 |
|
Can you please re-consider bringing this in to node-canvas, or explain what needs to be done exactly to get it in there? |
|
Hi guys, can you spare some time to review and consider merge please? |
|
I don't mind if this goes on the prototype or is an accessory function. It's slightly more convenient on the prototype (one less function to import), but agree with @LinusU that we should avoid adding more non-standard methods. I defer to others' decisions. A few of Linus's comments are still pending though, and the last commit should be removed (CI forces a build from source). |
I feel the same 😁 The comments need to be addressed before we merge though... |
|
I just sent a Pull Request addressing the comments |
64ed3d8 to
ff0f2ab
Compare
When you need to read parsed raw ARGB image data, you need to load the image, then draw it on a canvas and convert it to a buffer:
This is an unnecessary double copy of the data. This pull request contains a new method: Image.getRawData, which returns the buffer directly:
This allows for a more efficient usage of Canvas.Image.
We'd appreciate it if you'd merge this into the node-canvas module!