2014.12.27 23:06 "[Tiff] [PATCH] tiff2ps: fix grayscale with unassociated alpha (and other extrasamples != 0)", by Yuriy M. Kaminskiy

2014.12.29 22:29 "[Tiff] [PATCH] Signal error on unsupported sample/bit-depth in jbig codec instead of silently producing garbage", by Yuriy M. Kaminskiy

Note: this only reflects tif_jbig.c implementation limitation, not inherent limitation of jbig codec. JBIG codec (and jbigkit library) supports non-bilevel compression (however, most likely it will compress worse than Deflate and will be *much* slower).

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
NotDashEscaped: You need GnuPG to verify this message

Index: tiff-4.0.x-20141215/libtiff/tif_jbig.c

===================================================================

--- tiff-4.0.x-20141215.orig/libtiff/tif_jbig.c 2014-12-24 00:37:35.216597505 +0300
+++ tiff-4.0.x-20141215/libtiff/tif_jbig.c      2014-12-24 00:39:40.620097398 +0300

@@ -39,7 +39,18 @@

 static int JBIGSetupDecode(TIFF* tif)
 {

-       if (TIFFNumberOfStrips(tif) != 1)
+       TIFFDirectory* td = &tif->tif_dir;
+       if (td->td_bitspersample != 1) {
+               TIFFErrorExt(tif->tif_clientdata, "JBIG",
+                            "%d bits/sample is not supported in decoder", td->td_bitspersample);
+               return (0);
+       }
+       if (td->td_planarconfig != PLANARCONFIG_SEPARATE && td->td_samplesperpixel != 1) {
+               TIFFErrorExt(tif->tif_clientdata, "JBIG",
+                            "%d samples/pixel is not supported in decoder", td->td_bitspersample);
+               return (0);
+       }
+       if (TIFFNumberOfStrips(tif) != (td->td_planarconfig == PLANARCONFIG_SEPARATE ? td->td_samplesperpixel : 1))
        {
                TIFFErrorExt(tif->tif_clientdata, "JBIG", "Multistrip images not supported in decoder");
                return 0;
@@ -105,7 +116,18 @@ static int JBIGDecode(TIFF* tif, uint8* 

 static int JBIGSetupEncode(TIFF* tif)
 {
-       if (TIFFNumberOfStrips(tif) != 1)
+       TIFFDirectory* td = &tif->tif_dir;
+       if (td->td_bitspersample != 1) {
+               TIFFErrorExt(tif->tif_clientdata, "JBIG",
+                            "%d bits/sample is not supported in encoder", td->td_bitspersample);
+               return (0);
+       }
+       if (td->td_planarconfig != PLANARCONFIG_SEPARATE && td->td_samplesperpixel != 1) {
+               TIFFErrorExt(tif->tif_clientdata, "JBIG",
+                            "%d samples/pixel is not supported in encoder", td->td_bitspersample);
+               return (0);
+       }
+       if (TIFFNumberOfStrips(tif) != (td->td_planarconfig == PLANARCONFIG_SEPARATE ? td->td_samplesperpixel : 1))
        {
                TIFFErrorExt(tif->tif_clientdata, "JBIG", "Multistrip images not supported in encoder");

                return 0;

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iF4EAREIAAYFAlSh1VAACgkQKZn9iF16KMOSFwD/aAA+ZHdq1uvBuOd/A/6MCBqe n/J2SLH9c+9JBGgmzmMBAI01jsPICYtY9aLuYvgjeKhyue+hjZcrMaa6tDJ0DJZC

=H0v7

-----END PGP SIGNATURE-----