[cairo] Image rendering help?

Ian Britten britten at caris.com
Fri Oct 24 05:11:34 PDT 2008


Carl Worth wrote:
> Hi Ian,
> 
> I've had your message flagged in my email client for a while so that I
> could come back and take some time to answer it. I hadn't gotten around
> to doing so previously for a few reasons, (lots of different questions
> together, not totally minimal code, using cairomm which I don't
> necessarily understand and which *might* introduce problems of its own
> if it has bugs).
> 
> None of that is to complain, just to point out that any slightly more
> focued question might have gotten a quicker answer. But then again, I
> know that when things just aren't working it's often very hard to know
> exactly what the focused question should be.

Hi Carl,
First, many thanks for following up on this (Nice touch!)
I apologize that I probably should have posted a summary that I had
stumbled through my problem, and seem to have it working (Although I
must confess that it didn't seem to make any sense... )

And ya, I know the code wasn't completely minimal for simply image
drawing, but unfortunately, my struggles are usually with the
non-trivial cases...  (eg:  Combining multiple transformations, and
getting the desired output).  If (When?) I have any more problems,
I'll try to strip things down even more...

>> - To try to get the Image to fill my Surface, I tried adding
>>    a scale() call to the tmpMatrix before setting it on the
>>    pattern.  However, my image just disappears then :(
>>    Shouldn't a call like
>>          cairo_matrix_scale(&tmpMatrix, 2, 2);
>>    result in my image drawing at twice its size?
> 
> This one is at least a simple answer: No. A pattern matrix maps from
> user space to image space. So the effect from image space to user space
> is the opposite.
> 
> That is, you want a matrix of:
> 
> 	cairo_matrix_scale (&tmpMatrix, 0.5, 0.5);
> 
> on your pattern matrix in order to make an image appear twice as large.
> 
> I admit that this can be quite counter-intuitive.

[ No kidding ;) ]
I guess that explains why I also seemed to end up having to shift in
the opposite directions to what I was thinking...

Please don't take this as a criticism of your (great) work - I'm sure
all this stuff is powerful and flexible.  It's just hard to initially
get your head wrapped around all this transformation stuff when first
getting immersed in Cairo (And especially when trying to integrate
Cairo into an existing multi-million line framework which can't
easily change the way it's currently doing things...).  Trying to
debug (Let alone fix!) cases where wrong transformations result in
incorrect (Or no) output can really try ones patience...

> It really shouldn't be that hard to draw a scaled image, so maybe we're
> missing a section in a tutorial somewhere.

If I can make a suggestion, what might be something to consider is a
semi-advanced tutorial/snippits section, which shows not-quite-trivial
things to do  (eg:  Draw an image at a certain size+position, on a
Cartesian-oriented Context ;)

Anyways, thanks again for the follow-up.  It's always reassuring to
know that help is available!
Ian


More information about the cairo mailing list