-
Notifications
You must be signed in to change notification settings - Fork 229
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
pass in a raw pixelBuffer to the open command #86
Conversation
motivation for using open: jpg and png buffers are already accepted as input. I think it might be confusing to use a separate function to create images based on raw buffers. Possible code optimization might be creating a decoder in c which doesn't transform the raw input buffers, but only does the validation of the buffer size & parameters. Right now this happens in javascript. However, I don't think there's much of a speed benefit of doing that in c, it would rather be for code structuring reasons. |
I got rid of the transparency option, as this can be auto-detected based on the given width, height and buffer size. |
callback(err, err ? null : new Image(pixelsBuf, width, height, trans)); | ||
}); | ||
if(typeof type === 'object') { | ||
if(!type.width && !type.height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition can be dropped. The next two ones are sufficient.
if(!type.height) { | ||
throw Error("Missing height"); | ||
} | ||
if(typeof type.width !== "number") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
width
and height
need to be positive integers.
Can replace both of the following conditions
if(!type.width) {
throw Error("Missing width");
}
if(typeof type.height !== "number") {
throw Error("Height must be numeric");
}
With:
if (!(type.width === parseInt(type.width) && type.width > 0)){
throw Error("Width must be a positive integer");
}
This will cover both cases where type.width
is undefined, and not of the correct type.
I'm wondering if the section for validating the Then do something like: // ...
{
name: 'type',
types: ['string', 'rawBufferProperties'],
optional: true
}
// ... |
…o custom decree type
improved validation based on your feedback & created a custom decree type to validate the width and height (required positive integer). |
pass in a raw pixelBuffer to the open command
Great! I've merged this, and am going to push a few more changes, in case you want to take a look. Thanks a lot for this PR! |
cool :-) |
Referencing my previous pull request #84 - but now on the 0.0.6 branch