Skip to content

heifsave: limit bitdepth to supported values #4119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions libvips/foreign/heifsave.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
8, 12, 12);

VIPS_ARG_BOOL(class, "lossless", 13,
_("Lossless"),
Expand Down
Loading