Commit dc003e6b for libheif
commit dc003e6bb3c774975110ef4af193cd0eb4340d58
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Mon Jan 12 21:14:49 2026 +0100
heif-enc: check that --bit-depth is 9-16 (#1662)
diff --git a/examples/heif_enc.cc b/examples/heif_enc.cc
index 6e8cdcda..65771a83 100644
--- a/examples/heif_enc.cc
+++ b/examples/heif_enc.cc
@@ -295,7 +295,7 @@ void show_help(const char* argv0)
<< " --no-alpha do not save alpha channel\n"
<< " --no-thumb-alpha do not save alpha channel in thumbnail image\n"
<< " --verbose enable logging output (more will increase logging level)\n"
- << " -b, --bit-depth # bit-depth of generated HEIF/AVIF file when using 16-bit PNG input (default: 10 bit)\n"
+ << " -b, --bit-depth # bit-depth of generated HEIF/AVIF file when using 16-bit PNG input, valid range: 9-16 (default: 10 bit)\n"
<< " --premultiplied-alpha input image has premultiplied alpha\n"
#if WITH_HEADER_COMPRESSION
<< " --enable-metadata-compression ALGO enable metadata item compression (experimental)\n"
@@ -1275,6 +1275,10 @@ int main(int argc, char** argv)
break;
case 'b':
output_bit_depth = atoi(optarg);
+ if (output_bit_depth < 9 || output_bit_depth > 16) {
+ std::cerr << "Output bit depth for HDR images must be 9-16 bits.\n";
+ return 5;
+ }
break;
case 'A':
force_enc_av1f = true;