Re: drawing an array of pixels to the screen
Re: drawing an array of pixels to the screen
- Subject: Re: drawing an array of pixels to the screen
- From: John Stiles <email@hidden>
- Date: Mon, 12 Nov 2007 13:11:55 -0800
The generated code is the same. The [][] syntax is simply syntactic
sugar which hides the multiplication.
On Nov 12, 2007, at 12:58 PM, Jason Horn wrote:
Dave,
Thanks for your input. Wouldn't something like array[x + y
*width] be slower than array2d[x][y] when you are iterating over a
large image? Does the extra multiplication operation slow you down?
- Jason
On Nov 12, 2007, at 12:07 PM, David Spooner wrote:
On 12-Nov-07, at 6:08 AM, Jean-Daniel Dupas wrote:
You can also use coords with a raw array
array2d[x][y] is the same than array[x + y *width].
AFAK, a 1D array will be the fastest representation as it is the
native representation, and any function that take a 2D array will
probably convert it into a raw array to display it.
Agreed.
I would adopt the 1d array as the internal representation.
Granted a[x][y] is nicer than a[x+y*w], but one can easily provide
an equivalent syntax.
For those functions expecting a 2d array which you can't or don't
want to change, you can create a 2d array from a 1d array by
creating a column of row pointers...
pixel *rows = malloc(n_rows * sizeof(pixel *));
for (i = 0; i < n_rows; ++i)
rows[i] = &bitmap[i * w];
dave
Le 12 nov. 07 à 13:50, Jason Horn a écrit :
John,
Thanks for your thoughts here, but you've hit exactly on the
problem. NSBitmapImageRep takes a byte array, NOT a 2d array of
pixel values. That means after every analytical operation I
perform on the 2d pixel array, I have to then transform it back
into a byte stream (or at least a flat array) before drawing
it. This slows everything down. AFIK, NSBitmapImageRep will
not take a 2d array of values. (I've tried). The crux of my
question was, once you have a 2d array (x,y) arrangement of
pixels, what's the fastest way to get it onto the screen.
- Jason
On Nov 9, 2007, at 11:56 PM, John Stiles wrote:
+NSBitmapImageRep
initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:sampl
esPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerR
ow:bitsPerPixel: is pretty efficient. You're not copying the
whole byte array, it just takes a reference to it.
However, another poster hit the nail on the head—if performance
is important to you, might as well go OpenGL. You can't get any
faster than that on OS X.
On Nov 9, 2007, at 7:27 PM, Jason Horn wrote:
I am working on a computer vision based app that detects
objects in video images. I have to implement custom
algorithms to locate and track objects, so I need to write
code that has direct access to the pixel values and keep track
of the x,y coordinates of certain objects. This is easiest to
do with the image represented as a 2D array of int values.
However, it seems that the only way to draw bitmaps to the
screen is with NSImage and NSBitmapImageRep or CIImage. Is
there another way? It seems like a waste (and a performance
hit) to convert a 2D array of pixel values into a byte stream
every time you want to display the image. Is there a way to
draw the pixel values directly to the screen (and do it quickly).
Thanks for any ideas.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the
list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the
list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40conversionworks.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden