Post by Sagen de JongeHi,
Is there a way to write the pixel data from a single buffer that has all
rows pre compressed and filtered? I'm extracting images from PDF files
which use deflate compression and PNG filters so rather than decompressing
and then recompressing, I'd like to write directly.
The answer is yes, in principle (I haven't tested what I'm going to
describe), but why do you need to do it? If you just want to write
the PNG data out, unmodified, just write it directly rather than using
libpng.
If you *must* use libpng for some reason you have to tell it to treat
IDAT chunks (that's the image data) as "unknown" while reading the
file; if you don't do this the filtering and compressed data is lost.
libpng will buffer the IDAT chunks (totally unmodfiied) in the
png_info. Use two png_infos; a separate one to handle the chunks
*after* the IDAT (i.e. the onese returned by png_read_end).
After this you simply create a write structure and do a write with the
respective png_info (i.e. you don't need to create a new png_info, you
just use the ones from the read). This should work with libpng so
long as you only do it only once. If you try to write a second PNG
you will find all the text chunks disappear; it is necessary to use
png_get_text then png_set_text to make it work the second time.
(Fixed in 1.7 ;-)
--
John Bowler <***@gmail.com>
+1 (541) 450-9885
PO BOX 3151
KERBY OR 97531-3151
USA