2019.01.12 17:25 "[Tiff] tiffcp altering image contents (in contrast to what the manual says)?", by Binarus

2019.01.13 21:11 "Re: [Tiff] Tiff Digest, Vol 3, Issue 5", by Richard Nolde

Bob is certainly correct in stating that the issue is that the output is written using YCBCR encoding. It is possible that your viewer is not displaying this correctly. Why not simply use another compression algorithm and why use Graphics Magick at all if you are just compression and combining them? Tiffcp or tiffcrop can compress an uncompressed file on the fly while making a multi-page TIFF from a series of uncompressed single page TIFF files. If your files have various bit depths for which the same compression algorithm cannot be used, you would have to first combine all of them at a given bit depth and specify a compression algorithm that is appropriate for that bit depth. After the subsets are combined, ie, all the 1 bit bilevel images with CITT Group3 or Group4 encoding, all the RGB images with Zip or LZW or ZIP, you call tiffcp with no compression algorithm specified to build the final version.

If, as I suspect, you want them in a specific order, you run tiffcp once on each file (or group of files with the same bit depth) to do the compression and then once on the entire list of compressed files without modifying the compression.

Your script can run tiffinfo over each file and grep for the word Sample. Based on the result, you can set the compression used in the subsequent call to tiffcp in the first pass which writes out a temporary file X.tmp.tif into a separate directory. Once all the files have been compressed into the temporary directory, you call tiffcp again on the temporary files and write the multi-page result file wherever you like.

 tiffinfo CalTopoCycleMapSettings.tif
TIFF Directory at offset 0x1ad4e (109902)
  Subfile Type: (0 = 0x0)
  Image Width: 365 Image Length: 762
  Resolution: 72, 72 pixels/inch

Bits/Sample: 8

Compression Scheme: AdobeDeflate

  Photometric Interpretation: RGB color

Orientation: row 0 top, col 0 lhs Samples/Pixel: 3

  Rows/Strip: 64

Planar Configuration: single image plane

  DocumentName: /home/nolde/CalTopoCycleMapSettings.tif   Predictor: horizontal differencing 2 (0x2)

Richard Nolde

The excerpt below comes from the tiffcp.c source code.

       if (input_compression == COMPRESSION_JPEG) {                 /* Force conversion to RGB */

                TIFFSetField(in, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);         } else if (input_photometric == PHOTOMETRIC_YCBCR) {

                /* Otherwise, can't handle subsampled input */
                uint16 subsamplinghor,subsamplingver;

                TIFFGetFieldDefaulted(in, TIFFTAG_YCBCRSUBSAMPLING,
                                      &subsamplinghor, &subsamplingver);
                if (subsamplinghor!=1 || subsamplingver!=1) {
                        fprintf(stderr, "tiffcp: %s: Can't copy/convert
subsampled image.\n",
                �