mirror of
https://github.com/lovell/sharp.git
synced 2025-07-21 15:52:27 +02:00
Compare commits
No commits in common. "db3a4528eb65fe2358a6334a3536aca73c3df5de" and "94481a967ee9e4f925ee2acf078d36cc6464948f" have entirely different histories.
db3a4528eb
...
94481a967e
@ -951,6 +951,14 @@ namespace sharp {
|
|||||||
return interpretation == VIPS_INTERPRETATION_RGB16 || interpretation == VIPS_INTERPRETATION_GREY16;
|
return interpretation == VIPS_INTERPRETATION_RGB16 || interpretation == VIPS_INTERPRETATION_GREY16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Return the image alpha maximum. Useful for combining alpha bands. scRGB
|
||||||
|
images are 0 - 1 for image data, but the alpha is 0 - 255.
|
||||||
|
*/
|
||||||
|
double MaximumImageAlpha(VipsInterpretation const interpretation) {
|
||||||
|
return Is16Bit(interpretation) ? 65535.0 : 255.0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Convert RGBA value to another colourspace
|
Convert RGBA value to another colourspace
|
||||||
*/
|
*/
|
||||||
@ -995,14 +1003,16 @@ namespace sharp {
|
|||||||
}
|
}
|
||||||
// Add alpha channel(s) to alphaColour colour
|
// Add alpha channel(s) to alphaColour colour
|
||||||
if (colour[3] < 255.0 || image.has_alpha()) {
|
if (colour[3] < 255.0 || image.has_alpha()) {
|
||||||
int extraBands = image.bands() > 4 ? image.bands() - 3 : 1;
|
do {
|
||||||
alphaColour.insert(alphaColour.end(), extraBands, colour[3] * multiplier);
|
alphaColour.push_back(colour[3] * multiplier);
|
||||||
|
} while (alphaColour.size() < static_cast<size_t>(image.bands()));
|
||||||
}
|
}
|
||||||
// Ensure alphaColour colour uses correct colourspace
|
// Ensure alphaColour colour uses correct colourspace
|
||||||
alphaColour = sharp::GetRgbaAsColourspace(alphaColour, image.interpretation(), premultiply);
|
alphaColour = sharp::GetRgbaAsColourspace(alphaColour, image.interpretation(), premultiply);
|
||||||
// Add non-transparent alpha channel, if required
|
// Add non-transparent alpha channel, if required
|
||||||
if (colour[3] < 255.0 && !image.has_alpha()) {
|
if (colour[3] < 255.0 && !image.has_alpha()) {
|
||||||
image = image.bandjoin_const({ 255 * multiplier });
|
image = image.bandjoin(
|
||||||
|
VImage::new_matrix(image.width(), image.height()).new_from_image(255 * multiplier).cast(image.format()));
|
||||||
}
|
}
|
||||||
return std::make_tuple(image, alphaColour);
|
return std::make_tuple(image, alphaColour);
|
||||||
}
|
}
|
||||||
@ -1022,7 +1032,9 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage EnsureAlpha(VImage image, double const value) {
|
VImage EnsureAlpha(VImage image, double const value) {
|
||||||
if (!image.has_alpha()) {
|
if (!image.has_alpha()) {
|
||||||
image = image.bandjoin_const({ value * vips_interpretation_max_alpha(image.interpretation()) });
|
std::vector<double> alpha;
|
||||||
|
alpha.push_back(value * sharp::MaximumImageAlpha(image.interpretation()));
|
||||||
|
image = image.bandjoin_const(alpha);
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
@ -357,6 +357,12 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
bool Is16Bit(VipsInterpretation const interpretation);
|
bool Is16Bit(VipsInterpretation const interpretation);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Return the image alpha maximum. Useful for combining alpha bands. scRGB
|
||||||
|
images are 0 - 1 for image data, but the alpha is 0 - 255.
|
||||||
|
*/
|
||||||
|
double MaximumImageAlpha(VipsInterpretation const interpretation);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Convert RGBA value to another colourspace
|
Convert RGBA value to another colourspace
|
||||||
*/
|
*/
|
||||||
|
@ -60,7 +60,7 @@ class StatsWorker : public Napi::AsyncWorker {
|
|||||||
// Image is not opaque when alpha layer is present and contains a non-mamixa value
|
// Image is not opaque when alpha layer is present and contains a non-mamixa value
|
||||||
if (image.has_alpha()) {
|
if (image.has_alpha()) {
|
||||||
double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
|
double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
|
||||||
if (minAlpha != vips_interpretation_max_alpha(image.interpretation())) {
|
if (minAlpha != sharp::MaximumImageAlpha(image.interpretation())) {
|
||||||
baton->isOpaque = false;
|
baton->isOpaque = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user