I've been trying for days to get a simple dissolve transition filter to work but
I've just not been able to get it to work.
Here is the walk method that is called when the transition should occur
and the overridden drawRect method:
the objects current and buffer are both a of a subclass of NSView and
I've checked that initialImage respectively finalImage are indeed correctly
created and looks as they should.
What happens when I execute the walk method is nothing. When I debug
it I see that the drawRect is called once during the startAnimation call.
I've also tried several variants of how the drawRect method draws the
context without progress.
Don't bother to suspect stuff like ClearBitmapImageRep() and prepareFrameBuffer because as I stated I really made sure that the
initialImage & finalImage are right 🙂
I've just not been able to get it to work.
Here is the walk method that is called when the transition should occur
and the overridden drawRect method:
-(void)walk: (NSString*)stack card: (int)card{
NSBitmapImageRep *initialContentBitmap = [current bitmapImageRepForCachingDisplayInRect:[current bounds]];
ClearBitmapImageRep(initialContentBitmap);
[current cacheDisplayInRect:[current bounds] toBitmapImageRep:initialContentBitmap];
CIImage *initialImage = [[CIImage alloc] initWithBitmapImageRep:initialContentBitmap];
[self prepareBuffer:stack card:card];
NSBitmapImageRep *finalContentBitmap = [buffer bitmapImageRepForCachingDisplayInRect:[buffer bounds]];
ClearBitmapImageRep(finalContentBitmap);
[buffer cacheDisplayInRect:[buffer bounds] toBitmapImageRep:finalContentBitmap];
CIImage *finalImage = [[CIImage alloc] initWithBitmapImageRep:finalContentBitmap];
filter = [[CIFilter filterWithName😡"CIDissolveTransition"] retain];
[filter setDefaults];
[filter setValue:initialImage forKey😡"inputImage"];
[filter setValue:finalImage forKey😡"inputTargetImage"];
[initialImage release];
[finalImage release];
animation = [[NSAnimation alloc] initWithDuration:0 animationCurve:NSAnimationLinear];
[animation setDelegate:self];
[animation setFrameRate:30];
[animation startAnimation];
[animation release];
[filter release];
[self setNeedsDisplay:1];
}
- (void)drawRect: (NSRect)rect {
[super drawRect:rect];
// If we're in the middle of animating, composite the animation result atop the base TabView content.
if (animation != nil) {
// Get outputCIImage for the current phase of the animation. (This doesn't actually cause the image to be rendered just yet.)
[filter setValue:[NSNumber numberWithFloat:[animation currentValue]] forKey😡"inputTime"];
CIImage *outputCIImage = [filter valueForKey😡"outputImage"];
CGRect cg = CGRectMake(NSMinX(rect), NSMinY(rect),
NSWidth(rect), NSHeight(rect));
if(context == nil)
{
context = [CIContext contextWithCGContext:
[[NSGraphicsContext currentContext] graphicsPort]
options: nil];
[context retain];
}
[context drawImage: outputCIImage
atPoint: cg.origin
fromRect: cg];
}
}
the objects current and buffer are both a of a subclass of NSView and
I've checked that initialImage respectively finalImage are indeed correctly
created and looks as they should.
What happens when I execute the walk method is nothing. When I debug
it I see that the drawRect is called once during the startAnimation call.
I've also tried several variants of how the drawRect method draws the
context without progress.
Don't bother to suspect stuff like ClearBitmapImageRep() and prepareFrameBuffer because as I stated I really made sure that the
initialImage & finalImage are right 🙂