1

I am now learning how to use generic image library in boost, and the following codes illustrate how to write some raw data to a jpeg file:

int main(void)
{
    unsigned char *src_pixels;
    int src_row_bytes = 200;
    src_pixels = new unsigned char [200*500];
    for(int i=0; i<500; i++)
    {
        for(int j=0; j<200; j++)
            src_pixels[i*200+j]= j;
    }
    char *dst_pixels;
    dst_pixels = new char [200*500];
    for(int i=0; i<500; i++)
    {
        for(int j=0; j<200; j++)
            dst_pixels[i*200+j]= j;
    }
    gray8c_view_t my_view = interleaved_view(200,500,(const gray8_pixel_t*)src_pixels,src_row_bytes);
    gray8s_view_t your_view = interleaved_view(200,500,( gray8s_pixel_t*)dst_pixels,src_row_bytes); 

    jpeg_write_view("C:/file_1_copy.jpg", my_view);
    jpeg_write_view("C:/file_2_copy.jpg", your_view);

     delete []src_pixels;
     delete []dst_pixels;

    return 0;
}

However, it seems jpeg_write_view("C:/file_2_copy.jpg", your_view); cannot be compiled, and the following error messages are given:

Error   2   error C2338: jpeg_write_support<View>::is_supported

I do not how I could make it compile. Any suggestion will be appreciated.

`

manlio
  • 18,345
  • 14
  • 76
  • 126
feelfree
  • 11,175
  • 20
  • 96
  • 167
  • 2
    Looking at the header files ([here](http://www.boost.org/boost/gil/extension/io/jpeg_io.hpp) and [here](http://www.boost.org/boost/gil/extension/io/jpeg_io_private.hpp)) I think `jpeg_write_support::is_supported` is only true for views that have a channel type that is unsigned and of 8 bits. I don't know whether there is a good reason for that or whether its simply an oversight. Maybe someone with more knowledge will be able to help you. – llonesmiz Jul 12 '13 at 10:14
  • @cv_and_he - great then please add the solution - what to do – serup Aug 03 '16 at 09:50

1 Answers1

0

I'm using Boost v1.75 the function boost::gil::jpeg_read_image(...) is still available in this header #include <boost/gil/extension/io/jpeg/old.hpp>.

The new equivalent API (I think from Boost.GIL v1.68) is

#include <boost/gil/extension/io/jpeg.hpp>
boost::gil::write_view();

to manage JPEG use boost::gil::jpeg_tag().

Example:

boost::gil::write_view("out.jpg", img_view, boost::gil::jpeg_tag());
albezanc
  • 25
  • 7