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:

   1. Create an NSAttributed String S
   2. Convert S in a texture T with genTextureWithBounds
   3. Create an outputImageProvider using T

..it works, but it is still a bit slow when I render houndreds of strings.

_2_ using Quartz2D primitives:

   1. Create a bitmap context from QC context with CGBitmapContextCreate
   2. Use Quartz2D functions to draw text on the context created
   (CGContextSelectFont/CGContextShowTextAtPoint, etc)
   3. Release the context created
   4. 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/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to