Add named 'alpha' channel to extractChannel op #2138

This commit is contained in:
Lovell Fuller
2020-06-07 10:43:27 +01:00
parent 7f142bddb3
commit 17ea70a102
6 changed files with 28 additions and 11 deletions

View File

@@ -645,8 +645,12 @@ class PipelineWorker : public Napi::AsyncWorker {
// Extract an image channel (aka vips band)
if (baton->extractChannel > -1) {
if (baton->extractChannel >= image.bands()) {
(baton->err).append("Cannot extract channel from image. Too few channels in image.");
return Error();
if (baton->extractChannel == 3 && sharp::HasAlpha(image)) {
baton->extractChannel = image.bands() - 1;
} else {
(baton->err).append("Cannot extract channel from image. Too few channels in image.");
return Error();
}
}
VipsInterpretation const interpretation = sharp::Is16Bit(image.interpretation())
? VIPS_INTERPRETATION_GREY16