[cairo] [PATCH] Use NEAREST filter when possible
Chris Wilson
chris at chris-wilson.co.uk
Mon Aug 11 23:31:59 PDT 2014
On Mon, Aug 11, 2014 at 08:27:22PM -0700, Bill Spitzak wrote:
> diff --git a/src/cairo-matrix.c b/src/cairo-matrix.c
> index ba975be..ba73b53 100644
> --- a/src/cairo-matrix.c
> +++ b/src/cairo-matrix.c
> @@ -748,23 +748,26 @@ _cairo_matrix_is_integer_translation (const cairo_matrix_t *matrix,
> return FALSE;
> }
>
> +/* This only returns true if the matrix is 90 degree rotations or
> + * flips. It appears calling code is relying on this. It will return
> + * false for other rotations even if the scale is one. Approximations
> + * are allowed to handle matricies filled in using trig functions
> + * such as sin(M_PI_2).
> + */
> cairo_bool_t
> _cairo_matrix_has_unity_scale (const cairo_matrix_t *matrix)
> {
> - if (matrix->xy == 0.0 && matrix->yx == 0.0) {
> - if (! (matrix->xx == 1.0 || matrix->xx == -1.0))
> - return FALSE;
> - if (! (matrix->yy == 1.0 || matrix->yy == -1.0))
> - return FALSE;
> - } else if (matrix->xx == 0.0 && matrix->yy == 0.0) {
> - if (! (matrix->xy == 1.0 || matrix->xy == -1.0))
> - return FALSE;
> - if (! (matrix->yx == 1.0 || matrix->yx == -1.0))
> - return FALSE;
> - } else
> - return FALSE;
> + /* check that the determinant is near +/-1 */
> + double v = matrix->xx * matrix->yy - matrix->xy * matrix->yx;
> + v = v * v;
> + if (v < 0.99999 || v > 1.00001) return FALSE;
>
> - return TRUE;
> + /* check that one axis is close to zero */
> + if (fabs (matrix->xy) < 0.0001 && fabs (matrix->yx) < 0.0001)
> + return TRUE;
> + if (fabs (matrix->xx) < 0.0001 && fabs (matrix->yy) < 0.0001)
> + return TRUE;
> + return FALSE;
> }
Nice fixes below, This worries me slightly for the hardcoded constants.
I would use CAIRO_FIXED_TO_DOUBLE(1) instead, which is 1.5e-5 about 1/6
of your epsilon. Either way,
#define CAIRO_SCALING_EPSILON (CAIRO_FIXED_TO_DOUBLE(1))
-Chris
--
Chris Wilson, Intel Open Source Technology Centre
More information about the cairo
mailing list