[cairo] [PATCH] Use NEAREST filter when possible

Bill Spitzak spitzak at gmail.com
Tue Aug 12 10:40:11 PDT 2014


I think using CAIRO_SCALING_EPSILON if it is 0.00015 will work. The 
example I have fails after adding M_PI_2 together 12 times and sending 
the result to cairo_rotate. Adjusting these seems to make no difference 
so I now think it is causing the translate factors to fail.

Will post another patch using the constant.

On 08/11/2014 11:31 PM, Chris Wilson wrote:
> 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
>


More information about the cairo mailing list