cairo_matrix_t matrix;
cairo_pattern_get_matrix (img->cr_data, &matrix);
cairo_pattern_set_matrix (pattern, &matrix);
+ cairo_pattern_set_filter
+ (pattern, cairo_pattern_get_filter (img->cr_data));
cairo_pattern_destroy (img->cr_data);
}
cairo_surface_destroy (surface);
double rotation = 0.0;
compute_image_rotation (img, &rotation);
+# if defined USE_CAIRO || defined HAVE_XRENDER || defined HAVE_NS
+ /* We want scale up operations to use a nearest neighbour filter to
+ show real pixels instead of munging them, but scale down
+ operations to use a blended filter, to avoid aliasing and the like.
+
+ TODO: implement for Windows. */
+ bool scale_down = (width < img->width) || (height < img->height);
+# endif
+
/* Perform scale transformation. */
matrix3x3 matrix
/* Under NS the transform is applied to the drawing surface at
drawing time, so store it for later. */
ns_image_set_transform (img->pixmap, matrix);
+ ns_image_set_smoothing (img->pixmap, scale_down);
# elif defined USE_CAIRO
cairo_matrix_t cr_matrix = {matrix[0][0], matrix[0][1], matrix[1][0],
matrix[1][1], matrix[2][0], matrix[2][1]};
cairo_pattern_t *pattern = cairo_pattern_create_rgb (0, 0, 0);
cairo_pattern_set_matrix (pattern, &cr_matrix);
+ cairo_pattern_set_filter (pattern, scale_down
+ ? CAIRO_FILTER_BEST : CAIRO_FILTER_NEAREST);
/* Dummy solid color pattern just to record pattern matrix. */
img->cr_data = pattern;
# elif defined (HAVE_XRENDER)
XDoubleToFixed (matrix[1][2]),
XDoubleToFixed (matrix[2][2])}}};
- XRenderSetPictureFilter (FRAME_X_DISPLAY (f), img->picture, FilterBest,
- 0, 0);
+ XRenderSetPictureFilter (FRAME_X_DISPLAY (f), img->picture,
+ scale_down ? FilterBest : FilterNearest, 0, 0);
XRenderSetPictureTransform (FRAME_X_DISPLAY (f), img->picture, &tmat);
if (img->mask_picture)
{
XRenderSetPictureFilter (FRAME_X_DISPLAY (f), img->mask_picture,
- FilterBest, 0, 0);
+ scale_down ? FilterBest : FilterNearest, 0, 0);
XRenderSetPictureTransform (FRAME_X_DISPLAY (f), img->mask_picture,
&tmat);
}
unsigned long xbm_fg;
@public
NSAffineTransform *transform;
+ BOOL smoothing;
}
+ (instancetype)allocInitFromFile: (Lisp_Object)file;
- (void)dealloc;
- (Lisp_Object)getMetadata;
- (BOOL)setFrame: (unsigned int) index;
- (void)setTransform: (double[3][3]) m;
+- (void)setSmoothing: (BOOL)s;
@end
extern int ns_image_height (void *img);
extern void ns_image_set_size (void *img, int width, int height);
extern void ns_image_set_transform (void *img, double m[3][3]);
+extern void ns_image_set_smoothing (void *img, bool smooth);
extern unsigned long ns_get_pixel (void *img, int x, int y);
extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
[doTransform concat];
+ /* Smoothing is the default, so if we don't want smoothing we
+ have to turn it off. */
+ if (! img->smoothing)
+ [[NSGraphicsContext currentContext]
+ setImageInterpolation:NSImageInterpolationNone];
+
[img drawInRect:ir fromRect:ir
operation:NSCompositingOperationSourceOver
fraction:1.0 respectFlipped:YES hints:nil];
+ /* Apparently image interpolation is not reset with
+ restoreGraphicsState, so we have to manually reset it. */
+ if (! img->smoothing)
+ [[NSGraphicsContext currentContext]
+ setImageInterpolation:NSImageInterpolationDefault];
+
[[NSGraphicsContext currentContext] restoreGraphicsState];
}