[GIL] color_converted_view with any_image_view

Hi there I just tried to convert an arbitrary jpeg image to a grayscale image and write it to a png file. The attached file fails to compile, because there is no pixel_t in an any_image_view. The compile acually complains about a missing static "make" method. This is because of sfinae applies when SrcView is substituted by any_image_view in this structure template: image_view_factory.hpp:102: template <typename SrcView, typename DstP, typename CC=default_color_converter> struct color_converted_view_type : public detail::_color_converted_view_type<SrcView, CC, DstP, typename SrcView::pixel_t> { GIL_CLASS_REQUIRE(DstP, GIL, MutableHeterogeneousPixelConcept); }; How do I have to adapt the color conversion to work with any_image_views? Best regards Andreas Pokorny

Andreas Pokorny wrote:
Hi there I just tried to convert an arbitrary jpeg image to a grayscale image and write it to a png file. The attached file fails to compile, because there is no pixel_t in an any_image_view.
Andreas, GIL went through some major changes to color conversion. Apparently I had forgotten to apply one interface change to dynamic images. I will fix this in the next release of GIL. This is how you can do it today: typedef boost::mpl::vector<gray8_image_t, gray16_image_t, rgb8_image_t, rgb16_image_t> my_img_types; any_image<my_img_types> runtime_img; jpeg_read_image("test.jpg", runtime_img); typedef any_image<my_img_types>::view_t::const_t::types_t my_civ_types; png_write_view("test_out.jpg", any_color_converted_view<my_civ_types, gray8_pixel_t>(const_view(runtime_img))); Lubomir

Hi, Thank you for that fast response. Lubomir Bourdev <lbourdev@adobe.com> wrote:
typedef boost::mpl::vector<gray8_image_t, gray16_image_t, rgb8_image_t, rgb16_image_t> my_img_types; any_image<my_img_types> runtime_img; jpeg_read_image("test.jpg", runtime_img);
typedef any_image<my_img_types>::view_t::const_t::types_t my_civ_types; png_write_view("test_out.jpg", any_color_converted_view<my_civ_types, gray8_pixel_t>(const_view(runtime_img)));
Now I get another compiler errror at pixel_iterator_traits.hpp:128: gil/core/pixel_iterator_traits.hpp|128| error: no type named 'channel_t' in 'struct gil::default_color_converter' gil/core/pixel_iterator_traits.hpp|129| error: no type named 'color_space_t' in 'struct gil::default_color_converter' A few pages later there are more error messages about pixel_traits being instantiated with gil::default_color_converter. There several other types of default_color_converter are accessed. Regards Andreas Pokorny

Andreas Pokorny wrote:
Now I get another compiler errror at pixel_iterator_traits.hpp:128:
gil/core/pixel_iterator_traits.hpp|128| error: no type named 'channel_t' in 'struct gil::default_color_converter' gil/core/pixel_iterator_traits.hpp|129| error: no type named 'color_space_t' in 'struct gil::default_color_converter'
Andreas, I did compile and run successfully my example before posting it, on gcc 4.0 and msvc8. If you still need a resolution, we can investigate it but let's do it off-line, since this is just a workaround until the next version of GIL. Send me an email and we will figure it out. If anyone else is interested in this issue please let me know via email. Lubomir

Hello, Lubomir Bourdev <lbourdev@adobe.com> wrote:
I did compile and run successfully my example before posting it, on gcc 4.0 and msvc8.
And I just built it on gcc-4.3_alpha and it worked fine. Thank you! I played with the source of color_converted_* to investigate my initial problem, but I forgot to revert my modifications. Regards Andreas Pokorny

One more thing. If you read the image just so you can color convert it and save it as PNG, it is better to color convert upon read. That way you avoid dealing with runtime images altogether. Your code will be slightly faster, will compile faster, will have a smaller footprint (both executable and runtime memory) and will handle potentially more image formats: gray8_image_t gray8_img; jpeg_read_and_convert_image("test.jpg", gray8_img); png_write_view("test_out.png", const_view(gray8_img)); Lubomir

Hello, Lubomir Bourdev <lbourdev@adobe.com> wrote:
One more thing. If you read the image just so you can color convert it and save it as PNG, it is better to color convert upon read.
That way you avoid dealing with runtime images altogether. Your code will be slightly faster, will compile faster, will have a smaller footprint (both executable and runtime memory) and will handle potentially more image formats:
gray8_image_t gray8_img; jpeg_read_and_convert_image("test.jpg", gray8_img); png_write_view("test_out.png", const_view(gray8_img));
Thank you! Now thats really cute! Best regards Andreas Pokorny
participants (2)
-
Andreas Pokorny
-
Lubomir Bourdev