You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Jeremias Maerki <de...@jeremias-maerki.ch> on 2009/09/27 19:17:37 UTC

LZW embedding experiment

(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


Re: LZW embedding experiment

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Matthias,

I put my changes here:
http://people.apache.org/~jeremias/fop/Experiment%20LZW%20Embedding.zip

Please note that "testing" is not enough in this case. As soon as you
run into a multi-strip TIFF, the whole thing currently fails. As
mentioned in my post, solving this might require interpreting the LZW
commands which kind of kills the original idea of not having to decode
the compressed data. Have fun.


On 30.09.2009 19:18:54 MatthiasR wrote:
> 
> Hello,
> 
> 
> Jeremias Maerki-2 wrote:
> > 
> > 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.
> > 
> 
> I'd be interested in testing this for PDF output. Could you please send me
> the patch?
> 
> Regards,
> Matthias Reischenbacher
> -- 
> View this message in context: http://www.nabble.com/LZW-embedding-experiment-tp25635491p25685400.html
> Sent from the FOP - Dev mailing list archive at Nabble.com.




Jeremias Maerki


Re: LZW embedding experiment

Posted by MatthiasR <ma...@gmx.at>.
Hello,


Jeremias Maerki-2 wrote:
> 
> 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.
> 

I'd be interested in testing this for PDF output. Could you please send me
the patch?

Regards,
Matthias Reischenbacher
-- 
View this message in context: http://www.nabble.com/LZW-embedding-experiment-tp25635491p25685400.html
Sent from the FOP - Dev mailing list archive at Nabble.com.