Beispiel #1
0
/*
 *	scales each pixel's rgb by the brightness factor to increase brightness
 */
int Image32::Brighten(const float& brightness,Image32& outputImage) const
{
	int r1, g1, b1;
    for (int x = 0; x < outputImage.width(); x++)
		for (int y = 0; y < outputImage.height(); y++)
		{	
			// clamp [0,255]
			r1 = (int)(pixel(x,y).r*brightness);
			if (r1 > 255)
				r1 = 255;
			if (r1 < 0)
				r1 = 0;
			g1 = (int)(pixel(x,y).g*brightness);
			if (g1 > 255)
				g1 = 255;
			if (g1 < 0)
				g1 = 0;
			b1 = (int)(pixel(x,y).b*brightness);
			if (b1 > 255)
				b1 = 255;
			if (b1 < 0)
				b1 = 0;

			// write clamped values to outputImage
			outputImage.pixel(x,y).r = r1;
			outputImage.pixel(x,y).g = g1;
			outputImage.pixel(x,y).b = b1;
		}
    return 1;
}
Beispiel #2
0
int Image32::CrossDissolve(const Image32& source,const Image32& destination,const float& blendWeight,Image32& outputImage)
{
	int height = destination.height();
	int width = destination.width();


	cout << "CrossDissolve" << "\n";
	for(int y=0; y<height; ++y){
		for(int x=0; x<width; ++x){
			outputImage.pixel(x,y).r = (blendWeight * source.pixel(x,y).r) +  ((1-blendWeight) * destination.pixel(x,y).r);
			outputImage.pixel(x,y).g = (blendWeight * source.pixel(x,y).g) +  ((1-blendWeight) * destination.pixel(x,y).g);
			outputImage.pixel(x,y).b = (blendWeight * source.pixel(x,y).b) +  ((1-blendWeight) * destination.pixel(x,y).b);
		}
	}
	
	return 1;
}
void Win32CompatibleBitmap::Set(Image32 &image)
{
///!!! надо сделать по нормальному, а не через SetPixel !!!
	clear();
	int w = image.width();
	int h = image.height();
	if (w<=0 && h<=0) return;
	
	init(w, h);
	if (!handle) return;
	
	HDC dc = CreateCompatibleDC(0);

	if (!dc) return;

	_w = w;
	_h = h;

	HGDIOBJ old = ::SelectObject(dc, handle);

	int i;
	bool masked = false;
		
	for (int y = 0; y<h; y++) {
		unsigned32 *t = image.line(y);
		char *m = (masked) ? mask.ptr()+y*w : 0;
		for (i=0; i<w; i++) {
			if (t[i] > 0x80000000)
			{
				if (!masked) {
					mask.alloc(w*h);
					memset(mask.ptr(), 1, w*h);
					masked = true;
					m = mask.ptr()+y*w;
				}
				m[i] = 0;
			}
			::SetPixel(dc, i, y, t[i]&0xFFFFFF);
		}
	}

	::SelectObject(dc, old);
	DeleteDC(dc);
}
Beispiel #4
0
int Image32::Composite(const Image32& overlay,Image32& outputImage) const
{
	int height = this->height();
	int width = this->width();
	int heightOverlay = overlay.height();
	int widthOverlay = overlay.width();

	outputImage.setSize(width, height);

	for(int y=0; y<height; ++y){
		for(int x=0; x<width; ++x){
			int alpha256 = overlay.pixel(x,y).a;
			float alpha = (float) alpha256 / 255.0;
			outputImage.pixel(x,y).r = alpha*(overlay.pixel(x,y).r) + (1.0-alpha)*(this->pixel(x,y).r);
			outputImage.pixel(x,y).g = alpha*(overlay.pixel(x,y).g) + (1.0-alpha)*(this->pixel(x,y).g);
			outputImage.pixel(x,y).b = alpha*(overlay.pixel(x,y).b) + (1.0-alpha)*(this->pixel(x,y).b);
			outputImage.pixel(x,y).a = 255;
		}
	}
	return 1;
}
	void render(geometry_type& geom, Image32& image) const 
	{
	    typedef agg::renderer_base<agg::pixfmt_rgba32> ren_base;    
	    agg::row_ptr_cache<agg::int8u> buf(image.raw_data(),image.width(),image.height(),
					       image.width()*4);
	    agg::pixfmt_rgba32 pixf(buf);
	    ren_base renb(pixf);	    
	    
	    Color const& col = stroke_.get_color();
	    double r=col.red()/255.0;
	    double g=col.green()/255.0;
	    double b=col.blue()/255.0;
	    
	    if (0) //stroke_.width() == 1.0) 
	    {				
		typedef agg::renderer_outline_aa<ren_base> renderer_oaa;
		typedef agg::rasterizer_outline_aa<renderer_oaa> rasterizer_outline_aa;
		agg::line_profile_aa prof;
		prof.width(stroke_.get_width());
		renderer_oaa ren_oaa(renb, prof);
		rasterizer_outline_aa ras_oaa(ren_oaa);

		ren_oaa.color(agg::rgba(r, g, b, stroke_.get_opacity()));
		ras_oaa.add_path(geom);
		
		
		//LineRasterizerAA<Image32> rasterizer(image);
		//rasterizer.render<SHIFT0>(geom,stroke_.get_color());
		
	    }
	    else 
	    {
		
		//typedef agg::renderer_base<agg::pixfmt_rgba32> ren_base;    	
				
		typedef agg::renderer_scanline_aa_solid<ren_base> renderer;
		renderer ren(renb);
		
		agg::rasterizer_scanline_aa<> ras;
		agg::scanline_u8 sl;
		
		if (stroke_.has_dash())
		{
		    
		    agg::conv_dash<geometry<vertex2d,vertex_vector> > dash(geom);
		    dash_array const& d = stroke_.get_dash_array();
		    dash_array::const_iterator itr = d.begin();
		    dash_array::const_iterator end = d.end();
		    while (itr != end)
		    {
			dash.add_dash(itr->first, itr->second);
			++itr;
		    }
		    agg::conv_stroke<agg::conv_dash<geometry<vertex2d,vertex_vector> > > stroke(dash);
		
		    line_join_e join=stroke_.get_line_join();
		    if ( join == MITER_JOIN)
			stroke.generator().line_join(agg::miter_join);
		    else if( join == MITER_REVERT_JOIN) 
			stroke.generator().line_join(agg::miter_join);
		    else if( join == ROUND_JOIN) 
			stroke.generator().line_join(agg::round_join);
		    else
			stroke.generator().line_join(agg::bevel_join);
		    
		    line_cap_e cap=stroke_.get_line_cap();
		    if (cap == BUTT_CAP)    
			stroke.generator().line_cap(agg::butt_cap);
		    else if (cap == SQUARE_CAP)
			stroke.generator().line_cap(agg::square_cap);
		    else 
			stroke.generator().line_cap(agg::round_cap);

		    stroke.generator().miter_limit(4.0);
		    stroke.generator().width(stroke_.get_width());
		
		    ras.clip_box(0,0,image.width(),image.height());
		    ras.add_path(stroke);
		    ren.color(agg::rgba(r, g, b, stroke_.get_opacity()));
		    agg::render_scanlines(ras, sl, ren);
		}
		else 
		{
		    agg::conv_stroke<geometry<vertex2d,vertex_vector> >  stroke(geom);
		
		    line_join_e join=stroke_.get_line_join();
		    if ( join == MITER_JOIN)
			stroke.generator().line_join(agg::miter_join);
		    else if( join == MITER_REVERT_JOIN) 
			stroke.generator().line_join(agg::miter_join);
		    else if( join == ROUND_JOIN) 
			stroke.generator().line_join(agg::round_join);
		    else
			stroke.generator().line_join(agg::bevel_join);
		    
		    line_cap_e cap=stroke_.get_line_cap();
		    if (cap == BUTT_CAP)    
			stroke.generator().line_cap(agg::butt_cap);
		    else if (cap == SQUARE_CAP)
			stroke.generator().line_cap(agg::square_cap);
		    else 
			stroke.generator().line_cap(agg::round_cap);

		    stroke.generator().miter_limit(4.0);
		    stroke.generator().width(stroke_.get_width());
		    
		    ras.clip_box(0,0,image.width(),image.height());
		    ras.add_path(stroke);
		    ren.color(agg::rgba(r, g, b, stroke_.get_opacity()));
		    agg::render_scanlines(ras, sl, ren);
		}
	    }
	    
	}