[cairo] Observations from a newb
Carl Worth
cworth at cworth.org
Thu Nov 8 12:06:31 PST 2007
On Thu, 8 Nov 2007 20:28:05 +0100, Dirk Schönberger wrote:
> First of all thanks for your help. Sorry if I am a little picky ;)
No problem. And we're here to help.
> Ok. But what if I want to transform just the image data, not the
> coordinates.
Well, then just ask for that! All of this is quite possible, (and also
not too difficult), but the answers will also point more and more to
the reasons we don't have a single "draw an image" function.
For example, one of the reasons I think it's superior to have the
idiom:
cairo_set_source_surface (cr, image, 0, 0);
cairo_paint (cr);
for the "draw an image" operation over an explicit cairo_draw_image()
function is that it lends itself toward the user naturally learning
other operations, such as "draw a cropped rectangle of an image":
cairo_set_source_surface (cr, image, 0, 0);
cairo_rectangle (cr, x, y, width, height);
cairo_fill (cr);
or "draw an image at 50% opacity":
cairo_set_source_surface (cr, image, 0, 0);
cairo_paint_with_alpha (cr, 0.5);
And you can just as easily have anything more complex than a simple
rectangular path there, (a circle, a rounded rectangle, etc.), and
combine the alpha painting at the same time, etc. etc. Trying to cram
all of that functionality into some sort of draw_image() function
would be a big mistake.
> Basically I would like to draw the image at (10,10) in user coordinates
> (i.e. without further transformations), but the image itself should be
> rendered with a scale factor of (.5, .5)
There are several ways to get that result. Here's one you might try:
cairo_translate (cr, 10, 10);
cairo_scale (cr, 0.5, 0.5);
cairo_set_source_surface (cr, image, 0, 0);
cairo_paint (cr);
Other variations might create an explicit cairo_pattern_t for the
image, and then the scaling transformation could live there. Which
versions is "better" depends largely on how you think of that scaling
transformation, (is it transient and global, or does it "belong to"
the image in some way).
> I think basically I would like to see more operations about image surfaces
> (transformations, filtering, bitmap level operations like darken, edge
> detection, gaussian blur, drop shadows etc)
I'd definitely like to see new filtering capability, (things like
Gaussian blur, for instance) get added to cairo. I don't know if
things like edge detect really belong. But I've also wanted to see
some general, programmable filtering API get added, (perhaps GLSL
based), and that could very well provide the ability for the user to
code up things like edge detection if desired.
-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071108/8064c0d5/attachment.pgp
More information about the cairo
mailing list