Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Fastest Carbon-compatible method of putting an image on the screen?

Fastest Carbon-compatible method of putting an image on the screen?
Thread Tools
Detrius
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
Aug 18, 2005, 12:12 AM
 
Hey folks. I'm trying to figure out the fastest method of spitting an image onto the screen. This could be an image of any size. I need a method where I can do whatever computing is necessary at one point and then spit it onto the screen in a split second later.

I've tried this using CoreGraphics, which has it's upsides and downsides. I tried simply using a bitmap context, but that was pretty slow. The layers introduced in 10.4 are nice and fast--but not on the first drawing. Is there a method to force the decompression of the jpeg before the layer gets drawn to the screen?

Are there faster and/or better methods? 10.3 compatibility would be optimal. I can't imagine it's not possible to fill the screen quickly with a bitmap on 10.3. Ideas?


Thanks.
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Dair Grant
Fresh-Faced Recruit
Join Date: Jan 2002
Status: Offline
Reply With Quote
Aug 18, 2005, 08:56 AM
 
Assuming you want to let the system handle the details, use GraphicsImportCreateCGImage (10.3) to create a CGImageRef from any QT-supported image format. Then draw with CGContextDrawImage/HIViewDrawCGImage, or create an HIImageView to draw it for you. For best performance, turn off interpolation and ensure your image doesn't have alpha.

If the image is in a compressed format and you want to be sure there's no decompression while you're drawing, draw it to a CGBitmapContext, then create a CGImage from the pixels in that CGBitmapContext, then draw using that image.

Alternatively you could convert the image data into a texture and draw with OpenGL, although there are a number of caveats to that approach (need to split large images up into tiles, may not be any faster than CG depending on the system, etc) that make it more complex than using an HIView/CG.
     
Detrius  (op)
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
Aug 24, 2005, 07:29 PM
 
Originally Posted by Dair Grant
...If the image is in a compressed format and you want to be sure there's no decompression while you're drawing, draw it to a CGBitmapContext, then create a CGImage from the pixels in that CGBitmapContext, then draw using that image...
I got the QT stuff working beautifully. Now I'm working on re-implementing some of the drawing functions. I have one question: When you say to "create a CGImage from the pixels in the CGBitmapContext," are you referring to simply using CGBitmapContextCreateImage(), or instead using CGImageCreate() with the values retrieved from the bitmap context?

Here's the method I'm currently working on:

Create a CGImageRef from the QT function provided above.
Draw this CGImageRef into a 16-byte aligned CGBitmapContext.
Create a CGImageRef from this context.
Draw this CGImageRef to the screen.

The first three steps are run at the beginning of the presentation, and the fourth is done when the picture finally needs to be put on the screen.

I have noticed that using an OpenGL context for the screen seems quite a bit faster than using the QuickDraw context that I'm stuck with since I'm using the native wxWidgets stuff. This may improve though with wxWidgets compiled to support CoreGraphics... that's a different project for a little further down the road, though.
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Detrius  (op)
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
Aug 25, 2005, 02:16 AM
 
Actually, now that I'm trying to compile, I see that CGBitmapContextCreateImage() was introduced with 10.4, so I think I may have just answered my own question.
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Dair Grant
Fresh-Faced Recruit
Join Date: Jan 2002
Status: Offline
Reply With Quote
Aug 25, 2005, 04:53 AM
 
Something like:

// Get the compressed image
cgImageOne = GraphicsImportCreateCGImage(...);


// Decompress it
tmpPtr = malloc(width * height * 4);
cgContext = CGBitmapContextCreate(tmpPtr, ...);

CGContextDrawImage(cgContext, ..., cgImageOne);


// Create an uncompressed image
cgData = CGDataProviderCreateWithData(tmpPtr, ...);
cgImageTwo = CGImageCreate(width, height, ..., cgData, ...);

This will leave you with cgImageTwo, an image created out of a block of memory which cgImageOne was drawn into.

If you can require 10.4, CGBitmapContextCreateImage will let you create cgImageTwo in one step without creating a data provider/creating an image from that data provider. But it does require 10.4, whereas the above should work back to 10.3 (or earlier, but for GraphicsImportCreateCGImage).
     
Detrius  (op)
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
Aug 26, 2005, 12:16 AM
 
Cool; that's what I'm doing... creating the first CGImage from the file... drawing the different CGImageRefs into the bitmap context, and then creating a CGImageRef from its data when the program is allowed to take the time to do such stuff.
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Detrius  (op)
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
Aug 26, 2005, 12:16 AM
 
Now if I could just get all the rest of the code to magically rewrite itself for me, since I completely redid these classes...
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 04:14 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,