MyQCPlugIn.h…
@interface OutputImageProvider : NSObject <QCPlugInOutputImageProvider>
{
id<QCPlugInInputImageSource> _image;
}
- (id) initWithImageSource:(id)image;
@end
@interface MyQCPlugIn : QCPlugIn
{
}
@property(assign) id<QCPlugInInputImageSource> inputSourceImage;
@property(assign) id<QCPlugInOutputImageProvider> outputResultImage;
@end
MyQCPlugin.m…
@implementation MyQCPlugIn
@dynamic inputSourceImage, outputResultImage;
…
- (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary*)arguments
{
idimage;
if(image= self.inputSourceImage) {
OutputImageProvider* provider = [[OutputImageProvider alloc] initWithImageSource:image];
if(provider == nil)
return NO;
self.outputResultImage = provider;
[provider release];
}
else
self.outputResultImage = nil;
return YES;
}
…
@end
@implementation OutputImageProvider
- (id) initWithImageSource:(id<QCPlugInInputImageSource>)image
{
if(!image) {
[self release];
return nil;
}
if(self = [super init]) {
_image = [(id)image retain];
}
return self;
}
- (void) dealloc
{
[(id)_image release];
[super dealloc];
}
- (NSRect) imageBounds
{
return [_image imageBounds];
}
- (CGColorSpaceRef) imageColorSpace
{
return [_image imageColorSpace];
}
- (NSArray*) supportedBufferPixelFormats
{
return [NSArray arrayWithObjects:QCPlugInPixelFormatARGB8,
QCPlugInPixelFormatBGRA8,
QCPlugInPixelFormatRGBAf,
nil];
}
- (BOOL) renderToBuffer:(void*)baseAddress
withBytesPerRow:(NSUInteger)rowBytes
pixelFormat:(NSString*)format
forBounds:(NSRect)bounds
{
vImage_Buffer inBuffer, outBuffer;
if(![_image lockBufferRepresentationWithPixelFormat:format
colorSpace:[_image imageColorSpace]
forBounds:bounds])
return NO;
inBuffer.data = (void*)[_image bufferBaseAddress];
inBuffer.rowBytes = [_image bufferBytesPerRow];
inBuffer.width = [_image bufferPixelsWide];
inBuffer.height = [_image bufferPixelsHigh];
outBuffer.data = baseAddress;
outBuffer.rowBytes = rowBytes;
outBuffer.width = [_image bufferPixelsWide];
outBuffer.height = [_image bufferPixelsHigh];
{
memcpy(outBuffer.data, inBuffer.data, inBuffer.rowBytes * inBuffer.height);
}
[_image unlockBufferRepresentation];
return YES;
}
@end
間違いやお気づきの点がありましたらコメントもらえるとうれしいです.
0 件のコメント:
コメントを投稿