(a bit long, just for those interested, for the archives and for my lame
memory)

I've been asked by a client to implement support for embedding CMYK TIFF
in AFP without conversion to RGB. Even without the RGB conversion the
process is relatively slow. So it makes sense to investigate
optimization possibilities. The images to be embedded can be quite large
and are LZW-compressed. The first step is obviously functionality which
means teaching FOP how to embed CMYK bitmaps in AFP. Just leg work there.
The second step is optimization: investigating if LZW-compressed data
can be embedded in the target format without decompressing it, much like
what we do with JPEG and CCITT data in certain cases.

All CMYK TIFF images I looked at encoded the bitmap in multiple stripes.
The TIFF 6.0 spec recommends that approach to minimize memory usage for
processing. For each stripe, a number of bitmap rows are encoded. For
each stripe the compression algorithm is restarted. Since LZW has an
explicit EOD (end of data) command, it's not possible to simply
concatenate the stripes. The decoder would stop after the first stripe.
I'm not sure if it would be possible to concatenate the stripes by
simply removing the EOF command (which would basically mean interpreting
each command because they are not byte-aligned). The EOD makes it
impossible/difficult/impractical to embed such a TIFF image in undecoded
form in PDF as that doesn't seem to allow multiple streams for one image.
In PostScript it should be possible with a few tricks. In AFP, we'd
probably have to add support for tiling, i.e. create a tile per stripe
in the TIFF. Another possibility, though not as portable, is to use
"Include Object IOB" which supports whole TIFF files directly. On the
image loader framework side, I don't see any problems providing the
necessary streams. Of course, one could create multiple image XObjects
in PDF to align the stripes next to each other, but there's a risk of
visual side-effects (gaps, overlaps, anti-aliasing).

I've written some code that can embedd a single-stripe CMYK TIFF in PDF
as a proof of concept. I've done it for PDF because that was the easiest
to implement. I don't want to commit that right now since it
would need a lot of testing first. So in case I don't pursue this (due
to other priorities) and someone else wants that code, it's available.

Jeremias Maerki

Reply via email to