Re: Write pre filtered and compressed data

John Bowler <[email protected]>
Newsgroups gmane.comp.graphics.png.devel
Message-ID <CAP7U399Cv5e91csq2b25N5gFY_=oSdN5KtpbHdQrpSaJjejZ8A@mail.gmail.com>
On Sun, Feb 26, 2017 at 8:44 AM, Sagen de Jonge <[email protected]> wrote:
> Hi,
>
> 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 <[email protected]>
+1 (541) 450-9885
PO BOX 3151
KERBY OR 97531-3151
USA

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.