Add raw pixel data support to boolean and withOverlay ops

The previously-scattered image opening logic has been refactored to a
single ImageDescriptor struct/Object available to both JS and C++ code

This removed about 150 LOC but more importantly reduces the complexity
of adding/exposing new operations that require an input image.
This commit is contained in:
Lovell Fuller
2016-07-26 22:26:55 +01:00
parent 36bfbdee0d
commit e6bfa52b0b
11 changed files with 589 additions and 696 deletions

View File

@@ -457,7 +457,7 @@ Overlay (composite) a image containing an alpha channel over the processed (resi
`image` is one of the following, and must be the same size or smaller than the processed image:
* Buffer containing PNG, WebP, GIF or SVG image data, or
* Buffer containing PNG, WebP, GIF, SVG, raw pixel image data, or
* String containing the path to an image file, with most major transparency formats supported.
`options`, if present, is an Object with the following optional attributes:
@@ -467,6 +467,7 @@ Overlay (composite) a image containing an alpha channel over the processed (resi
* `left` is an integral Number representing the pixel offset from the left edge.
* `tile` is a Boolean, defaulting to `false`. When set to `true` repeats the overlay image across the entire image with the given `gravity`.
* `cutout` is a Boolean, defaulting to `false`. When set to `true` applies only the alpha channel of the overlay image to the image to be overlaid, giving the appearance of one image being cut out of another.
* `raw` an Object containing `width`, `height` and `channels` when providing uncompressed data.
If both `top` and `left` are provided, they take precedence over `gravity`.
@@ -523,11 +524,11 @@ sharp('input.png')
In the above example if `input.png` is a 3 channel RGB image, `output.png` will be a 1 channel grayscale image where each pixel `P = R & G & B`.
For example, if `I(1,1) = [247, 170, 14] = [0b11110111, 0b10101010, 0b00001111]` then `O(1,1) = 0b11110111 & 0b10101010 & 0b00001111 = 0b00000010 = 2`.
#### boolean(image, operation)
#### boolean(image, operation, [options])
Perform a bitwise boolean operation with `image`, where `image` is one of the following:
* Buffer containing PNG, WebP, GIF or SVG image data, or
* Buffer containing JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data, or
* String containing the path to an image file
This operation creates an output image where each pixel is the result of the selected bitwise boolean `operation` between the corresponding pixels of the input images.
@@ -537,6 +538,10 @@ The boolean operation can be one of the following:
* `or` performs a bitwise or operation, like the c-operator `|`.
* `eor` performs a bitwise exclusive or operation, like the c-operator `^`.
`options`, if present, is an Object with the following optional attributes:
* `raw` an Object containing `width`, `height` and `channels` when providing uncompressed data.
### Output
#### toFile(path, [callback])

View File

@@ -21,11 +21,16 @@ Requires libvips v8.3.2
[#511](https://github.com/lovell/sharp/pull/511)
[@mhirsch](https://github.com/mhirsch)
* Add support for raw pixel data with boolean and withOverlay operations.
[#516](https://github.com/lovell/sharp/pull/516)
[@mhirsch](https://github.com/mhirsch)
* Ensure ICC profiles are removed from PNG output unless withMetadata used.
[#521](https://github.com/lovell/sharp/issues/521)
[@ChrisPinewood](https://github.com/ChrisPinewood)
* Remove deprecated interpolateWith method - use resize(w, h, { interpolator: ... })
[#310](https://github.com/lovell/sharp/issues/310)
### v0.15 - "*outfit*"