|
|
Pointer to an NSImage in a void* pointer variable?
|
|
|
|
Mac Elite
Join Date: Mar 2001
Location: England
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
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'."
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Mar 2001
Location: England
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
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 Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|