<div dir="ltr">On Thu, Oct 23, 2008 at 1:53 PM, Carl Worth <span dir="ltr"><<a href="mailto:cworth@cworth.org">cworth@cworth.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> Suppose I have some arbitrary pre-drawn data in a cairo_surface_t. I<br><div class="Ih2E3d">
> want to blit some subrectangle not starting at the origin of this<br>
> source surface, into the target cairo_t.<br>
><br>
> The setup for this looks like:<br>
><br>
> /* pre-existing source image */<br>
> cairo_surface_t *source;<br>
><br>
> cairo_t *cr = ....; /* hook up to your window system */<br>
><br>
> /* Restrict size of paint to subrectangle requested */<br>
> cairo_rectangle(cr, dest_x, dest_y, width, height);<br>
> cairo_clip(cr);<br>
><br>
> cairo_set_source_surface(cr, source, dest_x, dest_y);<br>
><br>
> cairo_paint(cr);<br>
<br>
</div>Thank you for the very clear explanation of your problem. This is very<br>
helpful.<br>
<div class="Ih2E3d"><br>
> But this always takes a subrectangle of source starting at (0, 0). It<br>
> feels like I want to supply an extra X,Y pair to<br>
> cairo_set_source_surface() that tells where in the source image to<br>
> begin blitting. But the parameters allowed just affect the output<br>
> translation.<br>
<br>
</div>You don't need an extra paint of coordinates at all---you just need to<br>
use that coordinate the way you want to.<br>
<br>
Your cairo_rectangle(cr, dest_x, dest_y, width, height) sets up the<br>
rectangular region of the destination surface that you want to modify.<br>
And that's working just fine, right?</blockquote><div><br>Yes. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
Meanwhile, the coordinate passed to cairo_set_source_surface specifies<br>
in user-space coordinates, (which in your case are identical to your<br>
destination's device-space coordinates), where you would like the origin<br>
of the source surface to appear. You're passing dest_x and dest_y again<br>
which is why you're always seeing the source's (0,0) origin pixel at<br>
dest_x, dest_y.<br>
<br>
If you instead want a sub-rectangle starting at (source_x,source_y) then<br>
try:<br>
<div class="Ih2E3d"><br>
cairo_set_source_surface (cr, source,<br>
</div> dest_x - source_x,<br>
dest_y - source_y);<br>
<br>
This will put the surface's (0,0) at (dest_x-source_x,dest_y-source_y)<br>
which in term means that the pixel drawn at (dest_x,dest_y) should come<br>
from the surface at (source_x,source_y).<br>
<br>
I hope that helps, (though explaining this in text rather than with a<br>
picture definitely feels wrong).</blockquote><div><br>Yeah, I think I get the idea. We're just sliding the surfaces around w.r.t. each other by stipulating that final coordinate pair. I didn't realize it was legitimate to give values outside of Quadrant IV.<br>
<br>Your suggestion works. Now that your explanation makes it obvious to me that the coordinate pair accepted by cairo_set_source_surface() is just getting stuck onto the translation matrix, I ended up doing this instead just because the two separated operations make it a little clearer to me what's happening:<br>
<br> cairo_translate(cr, dst_x, dst_y);<br> cairo_set_source_surface(cr, source, -src_x, -src_y);<br></div><br>Thanks for the help!<br></div><br></div>