Re: Altivec & NSImage (NSBitmapImageRep) question
Re: Altivec & NSImage (NSBitmapImageRep) question
- Subject: Re: Altivec & NSImage (NSBitmapImageRep) question
- From: Tommaso Pecorella <email@hidden>
- Date: Sat, 19 Jan 2002 10:27:07 +0100
At 18:15 -0800 18-01-2002, Ken Tabb <email@hidden> wrote:
Hi,
I'm in the middle of porting my Solaris computer vision (image
processing) code to Cocoa (Obj-C). The algorithms are fairly complex so
I'd quite like to use Altivec to speed things up a bit. Upon reading the
Altivec blurb at developer.apple.com/hardware/ve it would appear that I
can have either 16-way parallellism when using unsigned chars, or 4 way
parallellism when using unsigned floats.
My main use of Altivec would be pixel-crunching (on RGBA
NSBitmapImageReps taken from QuickTime movies). Looking at the TIFF
representations of the NSImages I'm getting from these bitmaps, it would
appear each channel (R, G, B and A) of each pixel in the image is stored
as a float. I don't need this level of detail (8 bits per channel, i.e.
32-bit colour, is fine for my needs) and having floats unnecessarily
would appear to only offer me 1/4 of the potential Altivec performance
gains (from above parallellism docs) as well as taking up 4 times as
much RAM as I need to be using (there are many copies of each image used
in the preprocessing, so it's a lot of memory to expect to be free).
Hi, I don't know whar methods you are using for the conversion,
however the values you receive ARE unsigned chars (8 bit). NSImage
stores (and present) float values for RGBA because it needs to have
an internal representation that's independant from the device color
space, so it shows you floats meaning that the actual RGBA used by
device will depend on the device color space.
If you look at the NSBitmapImageReps raw data, however, you'll find
plain unsigned chars values, packed depending on NSBitmapImageReps
properties (alpha channel on/off, planar on/off, etc.).
This is expecially evident when you want to build from scratch a
NSBitmapImageReps. You can allocate and inizialize it and build the
image pixel by pixel...
So, if you are absolutely sure that your NSBitmapImageReps is of a
given type, you can simply read it's contents and play with it.
Beware, however, that NSBitmapImageReps is a two-head monster (and
NSImage is whorse), since it can contain raw data OR packed TIFF
data, depending on how it is initialized/focused.
Look at Bumps saver (you can find it trough
http://www.versiontracker.com, sources are included) for an example
of both image reading _and_ direct NSBitmapImageReps pixels
manipulation.
Best regards, Tommaso ;-{))
PS: if you're an Altivec master, why don't you take the time to
improve the Bumps code ? It actually needs some more speed during
initialization...
--
--------------------------------------------------------------------------
Ing. Tommaso Pecorella
snail-mail: e-mail :
via del Pergolino 8/a
mailto:email@hidden
50139 Firenze - ITALY
RSA Key fingerprint = 232A D084 AD2F 7815 3D44 AFF0 AA52 A3AA
--------------------------------------------------------------------------