Commit c50a7e5fb for imagemagick.org
commit c50a7e5fb813609060cc212a21df73a88163f7cb
Author: tomotomo <tomoppeko@gmail.com>
Date: Tue Nov 10 01:33:39 2026 +0900
Fix ScaleQuantumToAny() mapping every positive sample to full range in HDRI builds (#9112)
c8010dcb3 compared the sample with QuantumRange-65536.0, which is negative
in Q8 and Q16 builds, so reducing the depth (-depth 8, or writing an 8-bit
PNG) left every channel at either 0 or full intensity. Use the same
QuantumRange guard as the non-HDRI branch.
diff --git a/MagickCore/quantum-private.h b/MagickCore/quantum-private.h
index 87d84cd45..e8c8661b0 100644
--- a/MagickCore/quantum-private.h
+++ b/MagickCore/quantum-private.h
@@ -352,12 +352,9 @@ static inline QuantumAny ScaleQuantumToAny(const Quantum quantum,
#if defined(MAGICKCORE_HDRI_SUPPORT)
if ((IsNaN(quantum) != 0) || (quantum <= 0.0f))
return((QuantumAny) 0UL);
+#endif
if (quantum >= (Quantum) QuantumRange)
return(range);
-#else
- if (quantum >= (Quantum) QuantumRange)
- return(range);
-#endif
value=(double) range*(double) quantum/(double) QuantumRange;
#if defined(MAGICKCORE_HDRI_SUPPORT)
value+=0.5;
diff --git a/tests/cli-pipe.tap b/tests/cli-pipe.tap
index bfc62fe20..f6dc56d0a 100755
--- a/tests/cli-pipe.tap
+++ b/tests/cli-pipe.tap
@@ -18,7 +18,7 @@
#
. ./common.shi
. ${srcdir}/tests/common.shi
-echo "1..28"
+echo "1..29"
${MAGICK} pnm:- null: < ${SRCDIR}/rose.pnm && echo "ok" || echo "not ok"
${MAGICK} pnm:- info: < ${SRCDIR}/rose.pnm && echo "ok" || echo "not ok"
@@ -187,4 +187,13 @@ if [ "X$colors" = 'Xsrgba(255,0,0,1)|srgba(0,0,255,1)' ]; then
else
echo "not ok 28 - indexed ASE cel decodes to palette colors: $colors"
fi
+
+# Reducing the depth must keep a mid-range sample at its level.
+sample=`LC_ALL=C ${MAGICK} -size 1x1 xc:'#404040' -depth 8 GRAY:- 2>/dev/null |
+ od -An -tx1 | tr -d ' \n'`
+if [ "X$sample" = 'X40' ]; then
+ echo "ok 29 - depth reduction of a mid-range sample"
+else
+ echo "not ok 29 - depth reduction of a mid-range sample: $sample"
+fi
: