Exemplo n.º 1
0
void layout_convert<rgb_t, yuv_t>( const SrcP& src, DstP& dst )
{
    //std::cout << "convert RGB to YUV" << std::endl;
    get_color( dst, yuv::y_t() )	= get_color( src, red_t() )                                         + 1.13983 * get_color( src, blue_t() );
    get_color( dst, yuv::u_t() )	= get_color( src, red_t() ) - 0.39465 * get_color( src, green_t() ) - 0.58060 * get_color( src, blue_t() );
    get_color( dst, yuv::v_t() )	= get_color( src, red_t() ) + 2.03211 * get_color( src, green_t() )                                       ;
}
Exemplo n.º 2
0
 typename PixelRef::value_type operator()( const PixelRef& p)
 {
     typename PixelRef::value_type r;
     get_color( r, red_t())		= channel_multiply( get_color( p, red_t()), get_color( p, alpha_t()));
     get_color( r, green_t())	= channel_multiply( get_color( p, green_t()), get_color( p, alpha_t()));
     get_color( r, blue_t())		= channel_multiply( get_color( p, blue_t()), get_color( p, alpha_t()));
     get_color( r, alpha_t())	= get_color( p, alpha_t());
     return r;
 }
Exemplo n.º 3
0
void layout_convert<yuv_t, rgb_t>( const SrcP& src, DstP& dst )
{
    //std::cout << "convert YUV to RGB" << std::endl;
    get_color( dst, red_t() )	=  0.299   * get_color( src, yuv::y_t() ) + 0.587   * get_color( src, yuv::u_t() ) + 0.114   * get_color( src, yuv::v_t() );
    get_color( dst, green_t() )	= -0.14713 * get_color( src, yuv::y_t() ) - 0.28886 * get_color( src, yuv::u_t() ) + 0.436   * get_color( src, yuv::v_t() );
    get_color( dst, blue_t() )	=  0.615   * get_color( src, yuv::y_t() ) - 0.51499 * get_color( src, yuv::u_t() ) - 0.10001 * get_color( src, yuv::v_t() );
}
Exemplo n.º 4
0
    void read_palette()
    {
        int entries = this->_info._num_colors;

        if( entries == 0 )
        {
            entries = 1 << this->_info._bits_per_pixel;
        }

        _palette.resize( entries );

        for( int i = 0; i < entries; ++i )
        {
            get_color( _palette[i], blue_t()  ) = _io_dev.read_uint8();
            get_color( _palette[i], green_t() ) = _io_dev.read_uint8();
            get_color( _palette[i], red_t()   ) = _io_dev.read_uint8();

            // there are 4 entries when windows header
            // but 3 for os2 header
            if( _info._header_size == bmp_header_size::_win32_info_size )
            {
                _io_dev.read_uint8();
            }

        } // for
    }
Exemplo n.º 5
0
 void operator()(const P1& src, P2& dst) const {
     get_color(dst,red_t())  =
         channel_convert<typename color_element_type<P2, red_t>::type>(get_color(src,gray_color_t()));
     get_color(dst,green_t())=
         channel_convert<typename color_element_type<P2, green_t>::type>(get_color(src,gray_color_t()));
     get_color(dst,blue_t()) =
         channel_convert<typename color_element_type<P2, blue_t>::type>(get_color(src,gray_color_t()));
     get_color(dst,alpha_t()) =
         channel_convert<typename color_element_type<P2, alpha_t>::type>(get_color(src,alpha_t()));
 }
Exemplo n.º 6
0
    void operator()( const P1& src, P2& dst) const
    {
	bits32f temp_l = channel_convert<bits32f>( get_color( src, luminance_t()));
	bits32f temp_a = channel_convert<bits32f>( get_color( src, a_color_t()));
	bits32f temp_b = channel_convert<bits32f>( get_color( src, b_color_t()));

	float r, g, b;
	detail::lab2rgb( (float) temp_l, (float) temp_a, (float) temp_b, r, g, b);

	get_color( dst, red_t())   = channel_convert<typename color_element_type<red_t  , P2>::type>((bits32f) r);
	get_color( dst, green_t()) = channel_convert<typename color_element_type<green_t, P2>::type>((bits32f) g);
	get_color( dst, blue_t())  = channel_convert<typename color_element_type<blue_t , P2>::type>((bits32f) b);
    }
Exemplo n.º 7
0
    void operator()( const P1& src, P2& dst) const
    {
	bits32f temp_red   = channel_convert<bits32f>( get_color( src, red_t()   ));
	bits32f temp_green = channel_convert<bits32f>( get_color( src, green_t() ));
	bits32f temp_blue  = channel_convert<bits32f>( get_color( src, blue_t()  ));

	float l, a, b;
	detail::rgb2lab( (float) temp_red, (float) temp_green, (float) temp_blue, l, a, b, gamma_);

	get_color( dst, luminance_t()) = channel_convert<typename color_element_type<luminance_t, P2>::type>((bits32f) l);
	get_color( dst, a_color_t())   = channel_convert<typename color_element_type<a_color_t  , P2>::type>((bits32f) a);
	get_color( dst, b_color_t())   = channel_convert<typename color_element_type<b_color_t  , P2>::type>((bits32f) b);
    }
Exemplo n.º 8
0
    typename PixelRef::value_type operator()( const PixelRef& p)
    {
        typename PixelRef::value_type r;
        typename PixelRef::channel_t a;

        a = get_color( p, alpha_t());

        if( a != 0)
        {
            get_color( r, red_t())	= chan_divide( get_color( p, red_t()), a);
            get_color( r, green_t())	= chan_divide( get_color( p, green_t()), a);
            get_color( r, blue_t())	= chan_divide( get_color( p, blue_t()), a);
            get_color( r, alpha_t())	= a;
        }
        else
        {
            get_color( r, red_t())	= 0;
            get_color( r, green_t())	= 0;
            get_color( r, blue_t())	= 0;
            get_color( r, alpha_t())	= 0;
        }

        return r;
    }
Exemplo n.º 9
0
	/// Split RGBA to RGBA components
	static void split(const pixel_t& p, channel_t& r, channel_t& g, channel_t& b, channel_t& a) throw() {
		r = get_color(p, red_t());
		g = get_color(p, green_t());
		b = get_color(p, blue_t());
		a = get_color(p, alpha_t());
	}
Exemplo n.º 10
0
void color_transformation_step(const HSLParams& params, const boost::gil::pixel<SChannelType, RGB::layout>& src,
                               boost::gil::pixel<DChannelType, HSL::layout>& dst)
{
    std::cout << "color_transformation_step RGB to HSL" << std::endl;
    typedef typename floating_channel_type_t<DChannelType>::type ChannelFloat;

    // only ChannelFloat for hsl is supported
    ChannelFloat temp_red = channel_convert<ChannelFloat>(get_color(src, red_t()));
    ChannelFloat temp_green = channel_convert<ChannelFloat>(get_color(src, green_t()));
    ChannelFloat temp_blue = channel_convert<ChannelFloat>(get_color(src, blue_t()));

    ChannelFloat hue, saturation, lightness;

    ChannelFloat min_color = std::min(temp_red, std::min(temp_green, temp_blue));
    ChannelFloat max_color = std::max(temp_red, std::max(temp_green, temp_blue));

    ChannelFloat diff = max_color - min_color;

    if(diff == 0.0)
    {
        // rgb color is gray
        get_color(dst, hsl_colorspace::hue_t()) = 0;
        get_color(dst, hsl_colorspace::saturation_t()) = 0;
        // doesn't matter which rgb channel we use, they all have the same value.
        get_color(dst, hsl_colorspace::lightness_t()) = channel_convert<DChannelType>(temp_red);
        return;
    }

    // lightness calculation
    lightness = (min_color + max_color) * 0.5f;

    // saturation calculation
    if(lightness < 0.5f)
    {
        saturation = diff / (min_color + max_color);
    }
    else
    {
        saturation = (max_color - min_color) / (2.f - diff);
    }

    // hue calculation
    if(max_color == temp_red)
    {
        // max_color is red
        hue = (double)(temp_green - temp_blue) / diff;
    }
    else if(max_color == temp_green)
    {
        // max_color is green
        // 2.0 + (b - r) / (maxColor - minColor);
        hue = 2.f + (double)(temp_blue - temp_red) / diff;
    }
    else
    {
        // max_color is blue
        hue = 4.f + (double)(temp_red - temp_green) / diff;
    }

    if(hue < 0.f)
    {
        hue += 6.f;
    }
    hue /= 6.f;

    get_color(dst, hsl_colorspace::hue_t()) = channel_convert<DChannelType>(hue);
    get_color(dst, hsl_colorspace::saturation_t()) = channel_convert<DChannelType>(saturation);
    get_color(dst, hsl_colorspace::lightness_t()) = channel_convert<DChannelType>(lightness);
}
Exemplo n.º 11
0
void convertRgbToYPbPr( const SrcP& src, DstP& dst )
{
	get_color( dst, YPbPr::Y_t()  )	=  0.299    * get_color( src, red_t() ) + 0.587    * get_color( src, green_t() ) + 0.114    * get_color( src, blue_t() );
	get_color( dst, YPbPr::Pb_t() )	= -0.168736 * get_color( src, red_t() ) - 0.331264 * get_color( src, green_t() ) + 0.5      * get_color( src, blue_t() );
	get_color( dst, YPbPr::Pr_t() )	=  0.5      * get_color( src, red_t() ) - 0.418688 * get_color( src, green_t() ) - 0.081312 * get_color( src, blue_t() );
}
Exemplo n.º 12
0
void convertYPbPrToRgb( const SrcP& src, DstP& dst )
{
	get_color( dst, red_t()   )	= get_color( src, YPbPr::Y_t() )                                              + 1.402    * get_color( src, YPbPr::Pr_t() );
	get_color( dst, green_t() )	= get_color( src, YPbPr::Y_t() ) - 0.344136 * get_color( src, YPbPr::Pb_t() ) - 0.714136 * get_color( src, YPbPr::Pr_t() );
	get_color( dst, blue_t()  )	= get_color( src, YPbPr::Y_t() ) + 1.772    * get_color( src, YPbPr::Pb_t() )                                             ;
}