[GIL] Loading a PNG from a stream

Hello, I have the need to load a PNG from a generic input stream that has a similar interface (i.e. has a read, operator ! and fail with the same signature/semantics as std::istream). The png reading extensions don't appear to be able to load from anything other than a FILE*. In a library as modern as GIL I'm sort of suprised there is apparently no way to load from a generic stream. Anyone have an idea how to make this happen? Perhaps there is another PNG library written in C++ or a wrapper around the C libpng? Thanks, Michael Marcin

Michael Marcin wrote:
Hello,
I have the need to load a PNG from a generic input stream that has a similar interface (i.e. has a read, operator ! and fail with the same signature/semantics as std::istream). The png reading extensions don't appear to be able to load from anything other than a FILE*. In a library as modern as GIL I'm sort of suprised there is apparently no way to load from a generic stream.
Indeed, I agree. (And I remember mentioning in the review that I found the FILE API to be inappropriate for a boost C++ API.)
Anyone have an idea how to make this happen? Perhaps there is another PNG library written in C++ or a wrapper around the C libpng?
I did write iostream adapters for libpng, and would happily contribute it to boost.GIL if there is interest. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin...

Stefan Seefeld wrote:
Michael Marcin wrote:
Hello,
I have the need to load a PNG from a generic input stream that has a similar interface (i.e. has a read, operator ! and fail with the same signature/semantics as std::istream). The png reading extensions don't appear to be able to load from anything other than a FILE*. In a library as modern as GIL I'm sort of suprised there is apparently no way to load from a generic stream.
Indeed, I agree. (And I remember mentioning in the review that I found the FILE API to be inappropriate for a boost C++ API.)
Anyone have an idea how to make this happen? Perhaps there is another PNG library written in C++ or a wrapper around the C libpng?
I did write iostream adapters for libpng, and would happily contribute it to boost.GIL if there is interest.
I'm interested... could you perhaps put it in the vault? Is it still efficient for loading PNGs? Does it require the stream to backtrack? Thanks, Michael Marcin

Michael Marcin wrote:
Hello,
I have the need to load a PNG from a generic input stream that has a similar interface (i.e. has a read, operator ! and fail with the same signature/semantics as std::istream). The png reading extensions don't appear to be able to load from anything other than a FILE*. In a library as modern as GIL I'm sort of suprised there is apparently no way to load from a generic stream.
Indeed the I/O extension has not received as much development attention as the core library. There are lots of ways to improve it - using streams is just one of them. In fact I proposed at some point in the past the possibility of keeping the I/O extension out of Boost. The disadvantage is that I/O support is one of the most useful functionalities. It is hard to use GIL without some way of reading/writing to file. If anyone has the bandwidth to rewrite the I/O library we would greatly appreciate it. As for using streams, GIL's I/O is simply a translation layer to the underlying low level I/O library. In this case libpng takes FILE, so we take FILE. But if Stefan has an adaptor that would be a helpful first step. Of course, we would need such an adaptor for the other I/O formats too. Lubomir

On a related note: are there any concrete plans to move GIL into the boost repository ? Is that being planned in time for 1.35 ? Thanks, Stefan -- ...ich hab' noch einen Koffer in Berlin...
participants (4)
-
Lubomir Bourdev
-
Michael Marcin
-
Michael Marcin
-
Stefan Seefeld