-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add joinChannel and toColourspace commands #513
Conversation
…olorspace Add feature joinChannels to add additional image channels to the input image
Hello, thanks Matt, this doesn't seem to compile at the moment due to the use of an |
I don't have xcode, so it's hard to say what the problem is. I tried changing |
@@ -7,6 +7,7 @@ | |||
"beforeEach": true, | |||
"afterEach": true, | |||
"describe": true, | |||
"it": true | |||
"it": true, | |||
"Promise": true |
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.
Promises aren't natively supported in older versions of Node - please use var Promise = require('bluebird');
in any files that need it.
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.
Ok -- that makes sense. Thanks
The Buffer-or-filesystem approach of |
* CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha | ||
|
||
Buffers may be any of the image formats supported by sharp: JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data. In the case of a RAW buffer, the `options` object should contain a `raw` attribute, which follows the format of the attribute of the same name in the `sharp()` constructor. See `sharp()` for details. See `raw()` for pixel ordering. | ||
|
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.
Do we need to include information that the images to be joined must be the same dimension?
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.
They actually don't have to be of the same dimension -- vips will expand the image to fit the largest channel.
This PR definitely proves I need to abstract away the image loading logic copypasta (filesystem vs compressed Buffer vs raw Buffer) as there are now four occurrences :) |
If you were to abstract the image loading logic it would perhaps make it simpler to have buffers or filespaths as inputs. What in particular feels clunky about it? I tried to mimic the file or buffer input options in other functions that accept image input. Would it be easier if they weren't in an array -- i.e. you need to call |
use BluebirdPromise instead of Promise to support old versions of node
(Tomorrow) I'll attempt to extract the common logic (in both JS and C++) for image loading so it can be used by any operation that requires another image as part of its input. |
@lovell I've updated this to be based on the |
Actually -- what's the best way to handle this. Should I close this and open a new pull request against pencil? |
Thanks for the updates - I'll be merging |
Matt, the |
Yes -- today or tomorrow! Thanks! |
When I
Is it possible that the new version of vips hasn't been pushed? Anyway, I merged your |
Removing the |
Yes, that fixes it. I don't think running it automatically sounds right. I wasn't aware npm had a Anyway, it appears all the tests pass on this merged branch. Does this look good to you? |
Sharp.prototype.joinChannel = function(images, options) { | ||
if (Array.isArray(images)) { | ||
images.forEach(function(image, index) { | ||
this.options.joinChannelIn[index] = this._createInputDescriptor(image, options); |
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.
Should this use push()
rather than be index based? This would allow .joinChannel(array1).joinChannel(array2)
.
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.
Yes. Woops. I'll make that change.
Looking great, thanks. Always a pleasure to see a new feature PR with more lines of tests and documentation than the code to implement it :) |
Changes Unknown when pulling 6f79a99 on mhirsch:joinChannel_and_toColourspace into * on lovell:master*. |
Thanks again Matt! |
Added 7ada9db to fix a small InputDescriptor leak. |
This PR is a little large -- sorry for that. These two features are somewhat entangled, and I ended up writing
toColourspace()
in service of what I was trying to do withjoinChannels()
.Add feature toColourspace / toColorspace to write output in desired colorspace
This implements a feature very much like the one described in #218. This code is tested in
colourspace.js
andjoinChannel.js
, but by its nature adds the potential for a lot of complexity. I expect some additional tests will be required. This supersedes #503, which I'll close.Add feature joinChannels to add additional image channels to the input image
This allows you to join additional channels onto the image. In some cases it is necessary to use
toColourspace()
to set the output to what you intend. For example, if you open a grayscale image and add three channels, by default that will be interpreted as an sRGB image with an alpha channel. It is necessary to also calltoColourspace('cmyk')
to ask the image to be interpreted as a CMYK image.