Don't re-create all of your objects every frame or time execute is called, you
should cache them (probably best to cache on startExecution and release the
cached objects on stopExecution). Cache the context and re-use it (looks like
you are already caching the backing?). Secondly, cache the image, (you can
retain the output provider the factory methods make for you), and only change
it if your input string changes. Also, depending on what time base you have
set, it has implications for how rendering happens. I imagine time base none is
sensible here.
On Apr 28, 2011, at 9:45 AM, luca palmili wrote:
> Hi,
> what is the best way to render a string and output it as an image in a custom
> QC plugin?
> I tried 2 approaches:
>
> _1_ using NSAttributed string:
> Create an NSAttributed String S
> Convert S in a texture T with genTextureWithBounds
> Create an outputImageProvider using T
> ..it works, but it is still a bit slow when I render houndreds of strings.
>
> _2_ using Quartz2D primitives:
> Create a bitmap context from QC context with CGBitmapContextCreate
> Use Quartz2D functions to draw text on the context created
> (CGContextSelectFont/CGContextShowTextAtPoint, etc)
> Release the context created
> Create an outputImageProvider
> here is the code of the second approach:
>
> ////////////////////////////////////////////////////////////////
> - (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time
> withArguments:(NSDictionary*)arguments
> {
> CGLContextObj cgl_ctx = [context CGLContextObj];
> CGContextRef myContext;
>
> /* Create CGContext and draw text into it */
> myContext = CGBitmapContextCreate(baseAddress, w, h, 8, rowBytes,
> [context colorSpace], kCGImageAlphaPremultipliedFirst |
> kCGBitmapByteOrder32Host);
> if(myContext == NULL) {
> free(baseAddress);
> return NO;
> }
> CGContextClearRect(myContext, CGRectMake(0,0,w, h));
> CGContextSelectFont (myContext,
> "Helvetica-Bold",
> 100,
> kCGEncodingMacRoman);
> CGContextSetCharacterSpacing (myContext, 10);
> CGContextSetTextDrawingMode (myContext, kCGTextFill);
> CGContextSetRGBFillColor (myContext, 1, 1, 1, 1);
> CGContextShowTextAtPoint (myContext, 0, (h/2), "some text", 11);
>
> /* We don't need context anymore */
> CGContextRelease(myContext);
>
> #if __BIG_ENDIAN__
> _placeHolderProvider = [[context
> outputImageProviderFromBufferWithPixelFormat:QCPlugInPixelFormatARGB8
> pixelsWide:w pixelsHigh:h baseAddress:baseAddress bytesPerRow:rowBytes
> releaseCallback:_BufferReleaseCallback releaseContext:NULL
> colorSpace:[context colorSpace] shouldColorMatch:YES] retain];
> #else
> _placeHolderProvider = [[context
> outputImageProviderFromBufferWithPixelFormat:QCPlugInPixelFormatBGRA8
> pixelsWide:w pixelsHigh:h baseAddress:baseAddress bytesPerRow:rowBytes
> releaseCallback:_BufferReleaseCallback releaseContext:NULL
> colorSpace:[context colorSpace] shouldColorMatch:YES] retain];
> #endif
> self.outputImage = _placeHolderProvider;
>
> return YES;
> }
> ////////////////////////////////////////////////////////////////
>
> ..but this approach has got very low performance compared to the first one.
> ..are there other ways to output a string as an image? How can I improve
> performance?
>
> Thank you,
> Luke
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Quartzcomposer-dev mailing list ([email protected])
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/quartzcomposer-dev/doktorp%40mac.com
>
> This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com
This email sent to [email protected]