Преобразование изображения CYMK в RGB с помощью BOOST :: GIL - PullRequest
2 голосов
/ 09 января 2009

Я пытаюсь использовать универсальную библиотеку изображений boost для преобразования изображений CYMK в RGB.

Следующий код не компилируется

// read cmyk image file
cmyk8_image_t img;
jpeg_read_image( "1502-T2-C-PER.jpg", img );

// convert to rgb
rgb8_image_t rgb( img.dimensions() );
copy_pixels(
    color_converted_view<rgb8_image_t>(view(img)),
    view(rgb));

Кто-нибудь знает, как это исправить?

Я основал этот код на учебном коде

void x_luminosity_gradient(const rgb32fc_view_t& src, const gray8s_view_t& dst) {
    gray8_image_t ccv_image(src.dimensions());
    copy_pixels(color_converted_view<gray8_pixel_t>(src), view(ccv_image));

Вот вывод компилятора:

1>c:\program files\boost\boost_1_35_0\boost\gil\step_iterator.hpp(164) : error C2664: 'boost::gil::detail::step_iterator_adaptor<Derived,Iterator,SFn>::step_iterator_adaptor(const Iterator &,SFn)' : cannot convert parameter 1 from 'const boost::gil::dereference_iterator_adaptor<Iterator,DFn>' to 'const boost::gil::rgb8_ptr_t &'
1>        with
1>        [
1>            Derived=boost::gil::memory_based_step_iterator<boost::gil::rgb8_ptr_t>,
1>            Iterator=boost::gil::rgb8_ptr_t ,
1>            SFn=boost::gil::memunit_step_fn<boost::gil::rgb8_ptr_t >
1>        ]
1>        and
1>        [
1>            Iterator=boost::gil::cmyk8_ptr_t ,
1>            DFn=boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_view_t,boost::gil::default_color_converter>
1>        ]
1>        Reason: cannot convert from 'const boost::gil::dereference_iterator_adaptor<Iterator,DFn>' to 'const boost::gil::rgb8_ptr_t '
1>        with
1>        [
1>            Iterator=boost::gil::cmyk8_ptr_t ,
1>            DFn=boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_view_t,boost::gil::default_color_converter>
1>        ]
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>        c:\program files\boost\boost_1_35_0\boost\gil\locator.hpp(271) : see reference to function template instantiation 'boost::gil::memory_based_step_iterator<Iterator>::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::pixel<ChannelValue,Layout>,DFn>>(const boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::pixel<ChannelValue,Layout>,DFn>> &)' being compiled
1>        with
1>        [
1>            Iterator=boost::gil::rgb8_ptr_t,
1>            ChannelValue=boost::gil::bits8,
1>            Layout=boost::gil::cmyk_layout_t,
1>            DFn=boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_view_t,boost::gil::default_color_converter>
1>        ]
1>        c:\program files\boost\boost_1_35_0\boost\gil\image_view.hpp(101) : see reference to function template instantiation 'boost::gil::memory_based_2d_locator<StepIterator>::memory_based_2d_locator<boost::gil::memory_based_step_iterator<Iterator>>(const boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<Iterator>> &)' being compiled
1>        with
1>        [
1>            StepIterator=boost::gil::memory_based_step_iterator<boost::gil::rgb8_ptr_t>,
1>            Iterator=boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_view_t,boost::gil::default_color_converter>>
1>        ]
1>        c:\documents and settings\james\my documents\code\animag\test\test.cpp(17) : see reference to function template instantiation 'boost::gil::image_view<Loc>::image_view<SrcView>(const View &)' being compiled
1>        with
1>        [
1>            Loc=boost::gil::rgb8_loc_t,
1>            SrcView=boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_view_t,boost::gil::default_color_converter>>>>>,
1>            View=boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_view_t,boost::gil::default_color_converter>>>>>
1>        ]
1>        c:\documents and settings\james\my documents\code\animag\test\test.cpp(48) : see reference to function template instantiation 'void processRGB<boost::gil::image_view<Loc>>(SrcView &)' being compiled
1>        with
1>        [
1>            Loc=boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_view_t,boost::gil::default_color_converter>>>>,
1>            SrcView=boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_view_t,boost::gil::default_color_converter>>>>>
1>        ]
1>c:\program files\boost\boost_1_35_0\boost\gil\pixel.hpp(146) : error C2440: '=' : cannot convert from 'const boost::gil::image<Pixel,IsPlanar,Alloc>' to 'boost::gil::bits8'
1>        with
1>        [
1>            Pixel=boost::gil::rgb8_pixel_t,
1>            IsPlanar=false,
1>            Alloc=std::allocator<unsigned char>
1>        ]
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>        c:\program files\boost\boost_1_35_0\boost\gil\pixel.hpp(128) : see reference to function template instantiation 'void boost::gil::pixel<ChannelValue,Layout>::assign<P>(const Channel &,boost::mpl::false_)' being compiled
1>        with
1>        [
1>            ChannelValue=boost::gil::bits8,
1>            Layout=boost::gil::rgb_layout_t,
1>            P=boost::gil::image<boost::gil::rgb8_pixel_t,false,std::allocator<unsigned char>>,
1>            Channel=boost::gil::image<boost::gil::rgb8_pixel_t,false,std::allocator<unsigned char>>
1>        ]
1>        c:\program files\boost\boost_1_35_0\boost\gil\algorithm.hpp(236) : see reference to function template instantiation 'boost::gil::pixel<ChannelValue,Layout> &boost::gil::pixel<ChannelValue,Layout>::operator =<boost::gil::image<Pixel,IsPlanar,Alloc>>(const P &)' being compiled
1>        with
1>        [
1>            ChannelValue=boost::gil::bits8,
1>            Layout=boost::gil::rgb_layout_t,
1>            Pixel=boost::gil::rgb8_pixel_t,
1>            IsPlanar=false,
1>            Alloc=std::allocator<unsigned char>,
1>            P=boost::gil::image<boost::gil::rgb8_pixel_t,false,std::allocator<unsigned char>>
1>        ]
1>        c:\program files\boost\boost_1_35_0\boost\gil\algorithm.hpp(231) : while compiling class template member function 'void boost::gil::detail::copier_n<I,O>::operator ()(boost::gil::iterator_from_2d<Loc2>,__w64 int,boost::gil::iterator_from_2d<Loc>) const'
1>        with
1>        [
1>            I=boost::gil::iterator_from_2d<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8c_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_image_t,boost::gil::default_color_converter>>>>>,
1>            O=boost::gil::iterator_from_2d<boost::gil::rgb8_loc_t>,
1>            Loc2=boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8c_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_image_t,boost::gil::default_color_converter>>>>,
1>            Loc=boost::gil::rgb8_loc_t
1>        ]
1>        c:\program files\boost\boost_1_35_0\boost\gil\algorithm.hpp(266) : see reference to class template instantiation 'boost::gil::detail::copier_n<I,O>' being compiled
1>        with
1>        [
1>            I=boost::gil::iterator_from_2d<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8c_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_image_t,boost::gil::default_color_converter>>>>>,
1>            O=boost::gil::iterator_from_2d<boost::gil::rgb8_loc_t>
1>        ]
1>        c:\program files\boost\boost_1_35_0\boost\gil\algorithm.hpp(292) : see reference to function template instantiation 'DstIterator boost::gil::detail::copy_with_2d_iterators<boost::gil::iterator_from_2d<Loc2>,boost::gil::iterator_from_2d<Loc>>(SrcIterator,SrcIterator,DstIterator)' being compiled
1>        with
1>        [
1>            DstIterator=boost::gil::iterator_from_2d<boost::gil::rgb8_loc_t>,
1>            Loc2=boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8c_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_image_t,boost::gil::default_color_converter>>>>,
1>            Loc=boost::gil::rgb8_loc_t,
1>            SrcIterator=boost::gil::iterator_from_2d<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8c_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_image_t,boost::gil::default_color_converter>>>>>
1>        ]
1>        c:\documents and settings\james\my documents\code\animag\test\test.cpp(44) : see reference to function template instantiation 'void boost::gil::copy_pixels<boost::gil::image_view<Loc>,boost::gil::image_view<boost::gil::rgb8_loc_t>>(const View1 &,const View2 &)' being compiled
1>        with
1>        [
1>            Loc=boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8c_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_image_t,boost::gil::default_color_converter>>>>,
1>            View1=boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::dereference_iterator_adaptor<boost::gil::cmyk8c_ptr_t ,boost::gil::color_convert_deref_fn<const boost::gil::pixel<boost::gil::bits8,boost::gil::cmyk_layout_t> ,boost::gil::rgb8_image_t,boost::gil::default_color_converter>>>>>,
1>            View2=boost::gil::image_view<boost::gil::rgb8_loc_t>
1>        ]

1 Ответ

7 голосов
/ 09 января 2009

Нашел проблему

// read cmyk image file
cmyk8_image_t img;
jpeg_read_image( "1502-T2-C-PER.jpg", img );

//// convert to rgb
rgb8_image_t rgb( img.dimensions() );
copy_pixels(
    color_converted_view<rgb8_pixel_t>(view(img)),
    view(rgb));

Хитрость заключается в том, чтобы использовать rgb8_pixel_t при вызове color_converted_view

...