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 > Pointer to an NSImage in a void* pointer variable?

Pointer to an NSImage in a void* pointer variable?
Thread Tools
Amorya
Mac Elite
Join Date: Mar 2001
Location: England
Status: Offline
Reply With Quote
Aug 21, 2005, 05:17 PM
 
I am trying to port a game to Mac. I'm writing a cocoa layer which sits on top of a set of platform independent libraries.

There is a data structure which holds images. I am instructed to convert the image data from PNG to a platform native format, and store it in a variable void *imageData. Can I store an NSImage in that?

Amorya
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Aug 21, 2005, 05:45 PM
 
You could point to an NSImage with a void*, but I'm not sure that would do what it's supposed to do. It would point to the NSImage object, not the actual image data. The only way to use the variable then would be something like [imageData doSomething]. If it's meant to be raw data, but you want to use NSImage for implementation purposes, you'd probably want to use the pointer returned by the -bitmapData method of the image's NSBitmapImageRep.

Of course, keep in mind that OS X does natively support PNG, so given that description, I'm not sure it's necessary to convert anything at all.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Amorya  (op)
Mac Elite
Join Date: Mar 2001
Location: England
Status: Offline
Reply With Quote
Aug 22, 2005, 07:44 AM
 
That is what I want to do, Chuckit - maybe I wasn't clear in my message!

It's not meant to be raw data. The raw data is stored elsewhere. I do want it to return the NSImage object. Every so often I get passed whatever is in the imageData variable and told to draw it. The documentation says store the image in that variable in a form that your specific API can draw - for example, the X-windows client uses pixmaps, and the GTK one uses some GTK image format.

When you say OSX natively understands PNG, am I correct in that I still need to shove it in an NSImage before I can draw it in an NSView? If so I'll go ahead with this method. If there's a way of drawing a PNG directly then I could look into that...

I'll possibly be using Core Image at some point in this, too (although I haven't learnt it yet!) - as far as I'm aware that works with NSImages too.


Thanks for your help!


Amorya
What the nerd community most often fail to realize is that all features aren't equal. A well implemented and well integrated feature in a convenient interface is worth way more than the same feature implemented crappy, or accessed through a annoying interface.
     
smeger
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Aug 22, 2005, 12:53 PM
 
Yeah, you can do this without any problems. Just make sure that your NSImage won't get autoreleased out from under you, and that you've got some way of releasing it when it's no longer needed.

A void* is an untyped pointer to any data. The size of a void* is whatever size a pointer variable is on the target CPU architecture. Objective-C objects are all pointers, so you're perfectly safe casting to/from void*.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
   
 
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 09:34 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.,