Commit 07883df96 for imagemagick.org
commit 07883df968f66c97e159e4c27f80c324402f7620
Author: Dirk Lemstra <dirk@lemstra.org>
Date: Sun Oct 25 17:33:14 2026 +0100
Correct encoding with group4 compression in tiff coder (#9058).
diff --git a/coders/tiff.c b/coders/tiff.c
index 2ebc4702d..7b799dca6 100644
--- a/coders/tiff.c
+++ b/coders/tiff.c
@@ -3639,13 +3639,16 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
case FaxCompression:
case Group4Compression:
{
- if (IsImageMonochrome(image) == MagickFalse)
- {
- if (IsImageGray(image) == MagickFalse)
- (void) SetImageType(image,BilevelType,exception);
- else
- (void) SetImageDepth(image,1,exception);
- }
+ if (image->alpha_trait != UndefinedPixelTrait)
+ (void) SetImageType(image,BilevelType,exception);
+ else
+ if (IsImageMonochrome(image) == MagickFalse)
+ {
+ if (IsImageGray(image) == MagickFalse)
+ (void) SetImageType(image,BilevelType,exception);
+ else
+ (void) SetImageDepth(image,1,exception);
+ }
image->depth=1;
image->number_meta_channels=0;
break;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a2f8cb8fc..42df0d7bd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -46,6 +46,7 @@ TESTS_TESTS = \
tests/cli-pipe.tap \
tests/cli-svg.tap \
tests/cli-statistic.tap \
+ tests/cli-tiff.tap \
tests/cli-uhdr.tap \
tests/cli-uhdr-encoder.tap \
tests/cli-uhdr-resize-filter.tap \
diff --git a/tests/cli-tiff.tap b/tests/cli-tiff.tap
new file mode 100644
index 000000000..4906040ef
--- /dev/null
+++ b/tests/cli-tiff.tap
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# Copyright 1999 ImageMagick Studio LLC, a non-profit organization
+# dedicated to making software imaging solutions freely available.
+#
+# You may not use this file except in compliance with the License. You may
+# obtain a copy of the License at
+#
+# https://imagemagick.org/license/
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Regression tests for TIFF.
+#
+. ./common.shi
+. ${srcdir}/tests/common.shi
+echo "1..1"
+
+${MAGICK} -size 100x100 xc:white -alpha set -colorspace gray \
+ -threshold 50% -compress group4 tiff_group4_alpha.tiff &&
+ [ "$(${IDENTIFY} -format "%C %[channels]" tiff_group4_alpha.tiff)" = \
+ "Group4 gray" ] && echo "ok" || echo "not ok"
+
+rm -f tiff_group4_alpha.tiff
+: