AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2012.02.22 08:22 "[Tiff] Creating a CMYK tiff", by dan claudiu zaharescu
2012.02.22 19:56 "Re: [Tiff] Creating a CMYK tiff", by Andreas Kleinert
2012.02.22 20:33 "Re: [Tiff] Creating a CMYK tiff", by Igor Skochinsky
2012.02.22 23:30 "Re: [Tiff] Creating a CMYK tiff", by Jürgen_Buchmüller
2012.02.23 02:02 "Re: [Tiff] Creating a CMYK tiff", by Bob Friesenhahn
2012.02.23 07:12 "Re: [Tiff] Creating a CMYK tiff", by dan claudiu zaharescu

2012.02.22 23:30 "Re: [Tiff] Creating a CMYK tiff", by Jürgen_Buchmüller

On Wed, 22 Feb 2012 00:22:29 -0800 (PST)

TIFFWriteRawStrip(image, 0, buff, buffLen);

Is it ok to call the method this way?

Should I pass to the second paramter the number of the buffer (0,1,2 and 3)?

The second parameter is the strip number. You instructed libtiff to use a strip length of <height>, which means you have just one strip, i.e. you always give 0.

Further you configured contiguous for the planar config, while it looks like you have 4 buffers with separate C, M, Y and K data? If that is true, you have separate planar data and must thus use PLANARCONFIG_SEPARATE.

If no viewer is capable of displaying the data in this form (I don't know), you would have to rearrage the data by decompressing the 4 buffers and writing 4 bytes of C, M, Y, K repeatedly to an intermediary (e.g. scanline) buffer, which you would pass to TIFFWriteScanline(), just as Igor Skochinsky already suggested.

If you have access to the raw data before it is compressed, that'd be faster and easier as well.

What fields should I se 4 times and how?

The image data can not be set as a field, because it is no field, but - well - data. TIFFSetField() is for the various TIFFTAGs listed in the manual page.

Writing image data is done through one of the TIFFWriteXXX functions, either raw (pre-compressed) or as-is (to be compressed by libtiff).

Try with PLANARCONFIG_CONTIGUOUS and rearranging the 4 buffers into a stream of 4 bytes from each buffer, i.e.:

int write_scanline(TIFF *image, uint32 width, uint32 line,

        uint8 *c, uint *m, uint8 *y, uint8 *k)

{
        uint8 *scanbuff, *dst;
        uint32 x;
        int res;

        scanbuff = malloc(4 * width);
        if (!scanbuff)
                return -1;

        for (x = 0, dst = scanbuff; x < width; x++) {
                *dst++ = *c++;
                *dst++ = *y++;
                *dst++ = *m++;
                *dst++ = *k++;
        }
        res = TIFFWriteScanline(image, (tdata_t)scanbuff, y, 0);

        free(scanbuff);
        return res;
}

...

  1. ) decompress your C, M, Y and K data or get access to the uncompressed data
  2. ) write the tiff tags as needed
  3. ) code:

        uint8 *c, *m, *y, *k;

        uint32 line;
        /* somehow set or allocate c, m, y and k array
         * with uncompressed plane data
         */
        for (line = 0; line < height; line++) {
                if (write_scanline(image, width, line, c, m, y, k) < 0)
                        break;
                c += width;
                m += width;
                y += width;
                k += width;
        }
        if (line < height)
                /* handle error */
...

This should basically be the easier path to go. HTH Juergen

--
Jürgen Buchmüller <pullmoll@t-online.de>