Ensure linear op works with 16-bit input #3605

This commit is contained in:
Lovell Fuller
2023-04-01 12:08:14 +01:00
parent 97cf69c26a
commit b9c3851515
4 changed files with 16 additions and 2 deletions

View File

@@ -332,12 +332,13 @@ namespace sharp {
if (a.size() > bands) {
throw VError("Band expansion using linear is unsupported");
}
bool const uchar = !Is16Bit(image.interpretation());
if (HasAlpha(image) && a.size() != bands && (a.size() == 1 || a.size() == bands - 1 || bands - 1 == 1)) {
// Separate alpha channel
VImage alpha = image[bands - 1];
return RemoveAlpha(image).linear(a, b, VImage::option()->set("uchar", TRUE)).bandjoin(alpha);
return RemoveAlpha(image).linear(a, b, VImage::option()->set("uchar", uchar)).bandjoin(alpha);
} else {
return image.linear(a, b, VImage::option()->set("uchar", TRUE));
return image.linear(a, b, VImage::option()->set("uchar", uchar));
}
}