Ensure 16-bit input images embed onto alpha background

Support gamma correction of images with alpha channel
Favour shrink over affine when reducing by integral factor
This commit is contained in:
Lovell Fuller
2016-01-30 22:23:17 +00:00
parent 41e50770d1
commit 2675b2265b
10 changed files with 70 additions and 15 deletions

View File

@@ -102,11 +102,25 @@ namespace sharp {
return image;
}
/*
* Gamma encoding/decoding
*/
VImage Gamma(VImage image, double const exponent) {
if (HasAlpha(image)) {
// Separate alpha channel
VImage imageWithoutAlpha = image.extract_band(0,
VImage::option()->set("n", image.bands() - 1));
VImage alpha = image[image.bands() - 1];
return imageWithoutAlpha.gamma(VImage::option()->set("exponent", exponent)).bandjoin(alpha);
} else {
return image.gamma(VImage::option()->set("exponent", exponent));
}
}
/*
* Gaussian blur (use sigma <0 for fast blur)
*/
VImage Blur(VImage image, double const sigma) {
VImage blurred;
if (sigma < 0.0) {
// Fast, mild blur - averages neighbouring pixels
VImage blur = VImage::new_matrixv(3, 3,