From a37721446d6e7e8775d9621f4a2c4be7e00c7709 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 25 Aug 2024 16:06:45 +0200 Subject: [PATCH 1/2] heifsave: limit bitdepth to supported values --- libvips/foreign/heifsave.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libvips/foreign/heifsave.c b/libvips/foreign/heifsave.c index e99b806301..e309e4f2bf 100644 --- a/libvips/foreign/heifsave.c +++ b/libvips/foreign/heifsave.c @@ -532,8 +532,7 @@ vips_foreign_save_heif_build(VipsObject *object) !vips_object_argument_isset(object, "subsample_mode")) heif->subsample_mode = VIPS_FOREIGN_SUBSAMPLE_OFF; - /* Default 12 bit save for 16-bit images. HEIC (for example) implements - * 8 / 10 / 12. + /* Default 12 bit save for 16-bit images. */ if (!vips_object_argument_isset(object, "bitdepth")) heif->bitdepth = @@ -542,6 +541,16 @@ vips_foreign_save_heif_build(VipsObject *object) ? 12 : 8; + /* HEIC and AVIF only implements 8 / 10 / 12 bit depth. + */ + if (heif->bitdepth != 12 && + heif->bitdepth != 10 && + heif->bitdepth != 8) { + vips_error("heifsave", _("%d-bit colour depth not supported"), + heif->bitdepth); + return -1; + } + /* Try to find the selected encoder. */ if (heif->selected_encoder != VIPS_FOREIGN_HEIF_ENCODER_AUTO) { @@ -724,7 +733,7 @@ vips_foreign_save_heif_class_init(VipsForeignSaveHeifClass *class) _("Number of bits per pixel"), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET(VipsForeignSaveHeif, bitdepth), - 1, 16, 12); + 1, 12, 12); VIPS_ARG_BOOL(class, "lossless", 13, _("Lossless"), From ea250ed8764bfa1783d128e044342098322a6161 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 25 Aug 2024 16:20:33 +0200 Subject: [PATCH 2/2] Limit minimum value too --- libvips/foreign/heifsave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvips/foreign/heifsave.c b/libvips/foreign/heifsave.c index e309e4f2bf..5dc9310250 100644 --- a/libvips/foreign/heifsave.c +++ b/libvips/foreign/heifsave.c @@ -733,7 +733,7 @@ vips_foreign_save_heif_class_init(VipsForeignSaveHeifClass *class) _("Number of bits per pixel"), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET(VipsForeignSaveHeif, bitdepth), - 1, 12, 12); + 8, 12, 12); VIPS_ARG_BOOL(class, "lossless", 13, _("Lossless"),