[cairo] Paint image in overlay mode

Thomas Dybdahl Ahle thomas at ahle.dk
Thu Nov 16 13:22:13 PST 2006


Hi, I'm trying to paint an image in gimp "overlay" mode.
I've found the algorithm for overlay:

* Perform an RGB[A] overlay operation between the pixel sources
* ctx->A and ctx->B, using the generalized algorithm:
* D =  A * (B + (2 * B) * (255 - A))

But I don't know where to go from that. Is there some kind of filter
feature in cairo, that runs a function on all pixels?

I think I need to create an offscreen image, and update that one each
time the user changes the gtk theme (not very often)

Right now, I paint the image using this code:

cr = widget.window.cairo_create()
surface = cairo.ImageSurface.create_from_png(imgpath)
cr.rectangle (event.area.x, event.area.y, event.area.width,
event.area.height)
cr.set_source_surface(surface, 0, 0)
pattern = cr.get_source()
pattern.set_extend(cairo.EXTEND_REPEAT)
cr.fill()

Yes it is python code, but I guess the way it works is the same.

Can I somehow create an offscreen surface, that I can paint in the
backgroundcolor and append that overlay algorithm?

Also how do I get the pixeldata from the imagesurface?

-- 
Best Regards, Thomas



More information about the cairo mailing list