All pastes #423009 Raw Edit

cairo bitmask

public cpp v1 · immutable
·published 2007-04-03 21:15 UTC
rendered paste body
	// 400 x 400 surface, 8 pixel per byte = 400 x 50 bytes.	gchar * data = new gchar[400 * 50 ];	cairo_surface_t * mapSurface= cairo_image_surface_create_for_data((unsigned char *) data, CAIRO_FORMAT_A1, 400, 400, 50);	cairo_t * cr = cairo_create(mapSurface);	// make entire surface white and completely transparent	cairo_set_source_rgba (cr, 1, 1, 1, 0);	cairo_paint(cr);	// scale to 1 x 1.	cairo_scale(cr, 400, 400);		cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);	cairo_set_line_width(cr, 0.1);	// draw the outline of a circle in opaque black.	cairo_set_source_rgba (cr, 0, 0, 0, 1);	cairo_translate(cr, 0.5, 0.5);	cairo_arc(cr, 0, 0, 0.4, 0, M_PI * 2);	cairo_stroke(cr);	// destroy cairo stuff	cairo_destroy(cr);	cairo_surface_destroy(mapSurface);	// add row of 20 x 8 masked pixels in the left part of the image (as a test)	for (int i = 0; i < 400; i++) {		for (int j = 0; j < 20; j++) {			data[i * 50 + j] = 0xff;		}	}		// use mask as shape.	Glib::RefPtr<Gdk::Window> win = get_window();	Glib::RefPtr<Gdk::Bitmap> bitmap = Gdk::Bitmap::create(win, data, 400, 400);	input_shape_combine_mask(bitmap, 0, 0);	shape_combine_mask(bitmap, 0, 0);	delete [] data;