pngpp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pngpp-devel] Png stream size


From: Alex Shulgin
Subject: Re: [pngpp-devel] Png stream size
Date: Thu, 6 Dec 2012 00:02:44 +0200

On Wed, Dec 5, 2012 at 11:49 PM, Robert Carroll <address@hidden> wrote:
Hello,

I want to write a png file to a memory buffer using png::image::write(std::ostream& stream) and boost::iostreams::stream<boost::iostreams::array_sink> to make stream adapter to the array. I'm wondering if there's a way to know how large of a buffer to allocate in advance, or if there's a better way to write to an array rather than straight to a file?

Hi there,

I don't think there's a way to do that short of writing the image twice: first, discarding the output and only counting the total size required, then with pre-allocated buffer of that size.  You can try to estimate the upper limit of size requirement, but that can be rather tedious (you'll need to study zlib and PNG file format pretty extensively to account for every possible data chunk that can be present.)

Why don't you write to an auto-expanding stringstream instead?

--
Regards,
Alex


reply via email to

[Prev in Thread] Current Thread [Next in Thread]