[GIL] read/write jpeg image from/to a buffer, not a file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[GIL] read/write jpeg image from/to a buffer, not a file

Boost - Users mailing list
Hi,

Is it possible to read/write an image as JPEG from/into a memory
buffer instead of a file?

I found that reference which looks promising:
https://stackoverflow.com/questions/16259659/read-a-jpeg-image-from-memory-with-boostgil

but
grep -r jpeg_tag in boost/gil gives nothing (same with image_read_settings)
and read_image has no documentation and not the same signature.

Anyone knows something about that?

F
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [GIL] read/write jpeg image from/to a buffer, not a file

Boost - Users mailing list
On 18 July 2018 at 15:05, Frédéric via Boost-users
<[hidden email]> wrote:
> Hi,
>
> Is it possible to read/write an image as JPEG from/into a memory
> buffer instead of a file?
>
> I found that reference which looks promising:
> https://stackoverflow.com/questions/16259659/read-a-jpeg-image-from-memory-with-boostgil

I've just submitted new answer to this SO question:
https://stackoverflow.com/a/51525873/151641

Does it also address your question?

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [GIL] read/write jpeg image from/to a buffer, not a file

Boost - Users mailing list
Hi all,

On Wed, Jul 25, 2018 at 2:56 PM Mateusz Loskot via Boost-users <[hidden email]> wrote:
On 18 July 2018 at 15:05, Frédéric via Boost-users
<[hidden email]> wrote:
> Hi,
>
> Is it possible to read/write an image as JPEG from/into a memory
> buffer instead of a file?


I assume you mean using something like a stringstream as an in-memory buffer. The test suite has some examples, like:

BOOST_AUTO_TEST_CASE( stream_test )
{
    // 1. Read an image.
    std::ifstream in( jpeg_filename.c_str(), ios::binary );

    rgb8_image_t img;
    read_image( in, img, tag_t() );

    // 2. Write image to in-memory buffer.
    std::stringstream out_buffer( ios_base::in | ios_base::out | ios_base::binary );
    write_view( out_buffer, view( img ), tag_t() );

    // 3. Copy in-memory buffer to another.
    std::stringstream in_buffer( ios_base::in | ios_base::out | ios_base::binary );
    in_buffer << out_buffer.rdbuf();

    // 4. Read in-memory buffer to gil image
    rgb8_image_t dst;
    read_image( in_buffer, dst, tag_t() );

    // 5. Write out image.
    std::string filename( jpeg_out + "stream_test.jpg" );
    std::ofstream out( filename.c_str(), ios_base::binary );
    write_view( out, view( dst ), tag_t() );
}

Does that help?

Regards,
Christian​


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [GIL] read/write jpeg image from/to a buffer, not a file

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
> I've just submitted new answer to this SO question:
> https://stackoverflow.com/a/51525873/151641
>
> Does it also address your question?

Of course it does, that's exactly what I require.

Thanks,

F
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [GIL] read/write jpeg image from/to a buffer, not a file

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
> I assume you mean using something like a stringstream as an in-memory
> buffer. The test suite has some examples
>
> Does that help?

Yes, that's what I need.
I just need to upgrade to 1.68 which I postponed: I'm sticked to
1.65.1 because of API changes in boost::asio in 1.66. So I guess, now
I have no choice but upgrading!

Thanks,

F
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users