1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00

Use VIPS_META_PALETTE for palette detection if available

This commit is contained in:
DarthSim 2023-11-22 20:10:57 +03:00
parent fe94f820c6
commit ed6050dcce

View File

@ -254,12 +254,28 @@ vips_get_orientation(VipsImage *image)
int int
vips_get_palette_bit_depth(VipsImage *image) vips_get_palette_bit_depth(VipsImage *image)
{ {
int palette_bit_depth; int palette, palette_bit_depth;
if ( #ifdef VIPS_META_PALETTE
vips_image_get_typeof(image, VIPS_META_PALETTE_BITS_DEPTH) == G_TYPE_INT && if (vips_image_get_typeof(image, VIPS_META_PALETTE) == G_TYPE_INT &&
vips_image_get_int(image, VIPS_META_PALETTE, &palette) == 0 &&
palette) {
if (vips_image_get_typeof(image, VIPS_META_BITS_PER_SAMPLE) == G_TYPE_INT &&
vips_image_get_int(image, VIPS_META_BITS_PER_SAMPLE, &palette_bit_depth) == 0)
return palette_bit_depth;
else
/* Image has palette but VIPS_META_BITS_PER_SAMPLE is not set.
* It's very unlikely but we should handle this
*/
return 8;
}
#else
if (vips_image_get_typeof(image, VIPS_META_PALETTE_BITS_DEPTH) == G_TYPE_INT &&
vips_image_get_int(image, VIPS_META_PALETTE_BITS_DEPTH, &palette_bit_depth) == 0) vips_image_get_int(image, VIPS_META_PALETTE_BITS_DEPTH, &palette_bit_depth) == 0)
return palette_bit_depth; return palette_bit_depth;
#endif
return 0; return 0;
} }
@ -268,6 +284,9 @@ void
vips_remove_palette_bit_depth(VipsImage *image) vips_remove_palette_bit_depth(VipsImage *image)
{ {
vips_image_remove(image, VIPS_META_PALETTE_BITS_DEPTH); vips_image_remove(image, VIPS_META_PALETTE_BITS_DEPTH);
#ifdef VIPS_META_PALETTE
vips_image_remove(image, VIPS_META_PALETTE);
#endif
} }
VipsBandFormat VipsBandFormat