I have a CALayer in OS X that has its magnification and magnification filters setup like below, yet the magnification setting seems to be used regardless of the layer's size.
layer.magnificationFilter = kCAFilterNearest;
layer.minificationFilter = kCAFilterTrilinear;
The trilinear filtering works when the layer is small, but when enlarged, the layer is drawn with what looks like linear + the largest mipmap level, instead of nearest neighbor. As a test, I set the magnification filter to kCAFilterNearest, which causes it to render with kCAFilterNearest for all scale levels - so it seems the magnificationFilter is being used regardless of the size the layer is being drawn.
I tried this same code on iOS and it worked as expected, so this must be some quirk of OS X's rendering.
full code:
@implementation MipView
- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
NSImage *image = [NSImage imageNamed:@"image"];
CALayer *layer = [CALayer layer];
layer.magnificationFilter = kCAFilterNearest;
layer.minificationFilter = kCAFilterTrilinear;
layer.frame = CGRectMake(0, 0, image.size.width, image.size.height);
layer.contents = (__bridge id _Nullable)[image CGImageForProposedRect:NULL context:nil hints:nil];
[self setLayer:[CALayer layer]];
[self setWantsLayer:YES];
[self.layer addSublayer:layer];
return self;
}
- (IBAction)slider:(id)sender {
self.layer.sublayerTransform = CATransform3DMakeScale([sender doubleValue], [sender doubleValue], 1);
}
@end
Is there a way to get Core Animation use the magnification filter value when the layer is scaled up?
This is a bug in OS X. The core animation engineers seem to be looking into it, but haven't fixed it as of maxOS Sierra beta 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With