Problem was lack of proper handling for EXTRASAMPLE_UNASSOCALPHA in tiff2ps. Attached patch should fix this and related issues (should be applicable to 3.9.latest and 4.0.latest) Warning: only minimal testing passed, likely should be forwarded to and handled by upstream.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NotDashEscaped: You need GnuPG to verify this message
From: Yuriy M. Kaminskiy <[email protected]> Subject: [PATCH] tiff2ps: fix unassociated alpha and other extrasamples != 0 See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=611141 Index: tiff-3.9.4/tools/tiff2ps.c =================================================================== --- tiff-3.9.4.orig/tools/tiff2ps.c 2014-12-22 08:55:32.344597548 +0300 +++ tiff-3.9.4/tools/tiff2ps.c 2014-12-22 10:49:54.632097174 +0300 @@ -1553,7 +1553,15 @@ PS_Lvl2page(FILE* fd, TIFF* tif, uint32 break; } } - byte_count -= j; + byte_count = j; + } else if (extrasamples != 0) { + int i, j = 0; + int ncomps = samplesperpixel - extrasamples; + for (i = 0; i < byte_count; i+=samplesperpixel) { + memmove(buf_data + j, buf_data + i, ncomps); + j += ncomps; + } + byte_count = j; } if (ascii85) { @@ -1881,6 +1889,8 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, unsigned char* cp; tsize_t stripsize = TIFFStripSize(tif); tstrip_t s; + int sp = planarconfiguration == PLANARCONFIG_SEPARATE ? 1 : samplesperpixel; + int nc = samplesperpixel - extrasamples; #if defined( EXP_ASCII85ENCODER ) int ascii85_l; /* Length, in bytes, of ascii85_p[] data */ @@ -1932,6 +1942,10 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, *cp = ~*cp; cp++; } + if(planarconfiguration == PLANARCONFIG_SEPARATE) { + cc /= samplesperpixel; + nc = cc * (samplesperpixel - extrasamples); + } /* * for 16 bits, the two bytes must be most significant * byte first @@ -1942,12 +1956,18 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, if (ascii85) { #if defined( EXP_ASCII85ENCODER ) if (alpha) { - int adjust, i; - for (i = 0; i < cc; i+=2) { - adjust = 255 - cp[i + 1]; - cp[i / 2] = cp[i] + adjust; + int adjust, i, j = 0; + for (i = 0; i < cc; i += sp) { + adjust = 255 - cp[i + nc]; + cp[j++] = cp[i] + adjust; } - cc /= 2; + cc = j; + } else if (sp != 1) { + int i, j = 0; + for (i = 0; i < cc; i += sp) { + cp[j++] = cp[i]; + } + cc = j; } ascii85_l = Ascii85EncodeBlock( ascii85_p, 1, cp, cc ); @@ -1955,15 +1975,15 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, if ( ascii85_l > 0 ) fwrite( ascii85_p, ascii85_l, 1, fd ); #else - while (cc-- > 0) - Ascii85Put(*cp++, fd); + for (; cc > 0; cc -= sp, cp += sp) + Ascii85Put(*cp, fd); #endif /* EXP_ASCII85_ENCODER */ } else { unsigned char c; if (alpha) { int adjust; - while (cc-- > 0) { + for ( ; cc >= sp; cc -= sp, cp += sp) { DOBREAK(breaklen, 1, fd); /* * For images with alpha, matte against @@ -1971,13 +1991,12 @@ PSDataBW(FILE* fd, TIFF* tif, uint32 w, * Cback * (1 - Aimage) * where Cback = 1. */ - adjust = 255 - cp[1]; - c = *cp++ + adjust; PUTHEX(c,fd); - cp++, cc--; + adjust = 255 - cp[nc]; + c = *cp + adjust; PUTHEX(c,fd); } } else { - while (cc-- > 0) { - c = *cp++; + for (; cc >= sp; cc -= sp, cp += sp) { + c = *cp; DOBREAK(breaklen, 1, fd); PUTHEX(c, fd); } -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iF4EAREIAAYFAlSX0T8ACgkQKZn9iF16KMOOrAD+OF914uqGQSFAtgZvlud5MnXX ZMmlThUokSBRsr2tZvwBAIx5VJmrvhWMKf0JWePZLBv6uyH/C7Kzr7VAKYG+Eur2 =zt2i -----END PGP SIGNATURE-----

