Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CALayer's magnificationFilter being ignored on OS X

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?

like image 495
Daniel Avatar asked Dec 19 '25 12:12

Daniel


1 Answers

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

like image 188
Daniel Avatar answered Dec 21 '25 04:12

Daniel