<div dir="ltr">Well that was a pain to figure out again (it is tricky to get p and x and y cancelled out of the calculation) but does this make any sense:<br><div><br>Calculate bounding box of radius-1 circle in xy transformed to uv:<br><br>Transform x,y to u,v by this matrix calculation:<br><br> |u| |a c| |x|<br> |v| = |b d|*|y|<br><br>Horizontal component:<br><br> u = ax+cy (1)<br><br>x,y describes a radius-1 circle, p is angle to the point:<br><br> p = 0..2*pi<br> x = cos(p)<br> y = sin(p)<br> x^2+y^2 = 1<br> dx/dp = -sin(p) = -y<br> dy/dp = cos(p) = x<br><br>Figure out derivative of (1) relative to p:<br><br> du/dp = a(dx/dp) + c(dy/dp)<br> = -ay + cx<br><br>The min and max u are when du/dp is zero:<br><br> -ay + cx = 0<br> cx = ay<br> c = ay/x (2)<br> y = cx/a (3)<br><br>Substitute (2) into (1) and simplify:<br><br> u = ax + ay^2/x<br> = a(x^2+y^2)/x<br> = a/x (because x^2+y^2 = 1)<br> x = a/u (4)<br><br>Substitute (4) into (3) and simplify:<br><br> y = c(a/u)/a<br> y = c/u (5)<br><br>Square (4) and (5) and add:<br><br> x^2+y^2 = (a^2+c^2)/u^2<br><br>But x^2+y^2 is 1:<br><br> 1 = (a^2+c^2)/u^2<br> u^2 = a^2+c^2<br> u = hypot(a,c)<br><br>Similarily the max/min of v is at:<br><br> v = hypot(b,d)<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 17, 2015 at 1:52 AM, Oded Gabbay <span dir="ltr"><<a href="mailto:oded.gabbay@gmail.com" target="_blank">oded.gabbay@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sat, Dec 12, 2015 at 8:06 PM, <<a href="mailto:spitzak@gmail.com">spitzak@gmail.com</a>> wrote:<br>
> From: Bill Spitzak <<a href="mailto:spitzak@gmail.com">spitzak@gmail.com</a>><br>
><br>
> This is much more accurate and less blurry. In particular the filtering does<br>
> not change as the image is rotated.<br>
> ---<br>
> demos/scale.c | 43 ++-----------------------------------------<br>
> 1 file changed, 2 insertions(+), 41 deletions(-)<br>
><br>
> diff --git a/demos/scale.c b/demos/scale.c<br>
> index d00307e..71c7791 100644<br>
> --- a/demos/scale.c<br>
> +++ b/demos/scale.c<br>
> @@ -55,50 +55,11 @@ get_widget (app_t *app, const char *name)<br>
> return widget;<br>
> }<br>
><br>
> -static double<br>
> -min4 (double a, double b, double c, double d)<br>
> -{<br>
> - double m1, m2;<br>
> -<br>
> - m1 = MIN (a, b);<br>
> - m2 = MIN (c, d);<br>
> - return MIN (m1, m2);<br>
> -}<br>
> -<br>
> -static double<br>
> -max4 (double a, double b, double c, double d)<br>
> -{<br>
> - double m1, m2;<br>
> -<br>
> - m1 = MAX (a, b);<br>
> - m2 = MAX (c, d);<br>
> - return MAX (m1, m2);<br>
> -}<br>
> -<br>
> static void<br>
> compute_extents (pixman_f_transform_t *trans, double *sx, double *sy)<br>
> {<br>
> - double min_x, max_x, min_y, max_y;<br>
> - pixman_f_vector_t v[4] =<br>
> - {<br>
> - { { 1, 1, 1 } },<br>
> - { { -1, 1, 1 } },<br>
> - { { -1, -1, 1 } },<br>
> - { { 1, -1, 1 } },<br>
> - };<br>
> -<br>
> - pixman_f_transform_point (trans, &v[0]);<br>
> - pixman_f_transform_point (trans, &v[1]);<br>
> - pixman_f_transform_point (trans, &v[2]);<br>
> - pixman_f_transform_point (trans, &v[3]);<br>
> -<br>
> - min_x = min4 (v[0].v[0], v[1].v[0], v[2].v[0], v[3].v[0]);<br>
> - max_x = max4 (v[0].v[0], v[1].v[0], v[2].v[0], v[3].v[0]);<br>
> - min_y = min4 (v[0].v[1], v[1].v[1], v[2].v[1], v[3].v[1]);<br>
> - max_y = max4 (v[0].v[1], v[1].v[1], v[2].v[1], v[3].v[1]);<br>
> -<br>
> - *sx = (max_x - min_x) / 2.0;<br>
> - *sy = (max_y - min_y) / 2.0;<br>
> + *sx = hypot (trans->m[0][0], trans->m[0][1]) / trans->m[2][2];<br>
> + *sy = hypot (trans->m[1][0], trans->m[1][1]) / trans->m[2][2];<br>
> }<br>
><br>
> typedef struct<br>
> --<br>
> 1.9.1<br>
><br>
</div></div>> _______________________________________________<br>
> Pixman mailing list<br>
> <a href="mailto:Pixman@lists.freedesktop.org">Pixman@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/pixman" rel="noreferrer" target="_blank">http://lists.freedesktop.org/mailman/listinfo/pixman</a><br>
<br>
Could you please add some comment in the code about where this<br>
calculation comes from (reference to some mathematical<br>
equation/proof), and detail the mapping of the variables in the code<br>
to the arguments of the mathematical equation ?<br>
<br>
Otherwise, this patch is:<br>
<br>
Reviewed-by: Oded Gabbay <<a href="mailto:oded.gabbay@gmail.com">oded.gabbay@gmail.com</a>><br>
</blockquote></div><br></div>