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: Bill Bumgarner <email@hidden>
- Date: Fri, 9 Nov 2007 21:05:38 -0800
On Nov 9, 2007, at 8:56 PM, John Stiles wrote:
+NSBitmapImageRep
initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow: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.
This has come up before. Maybe I already answered this?
In any case, the next best thing to OpenGL for blasting pixels to the
screen is NSRectFillList() with a set of 1x1 rectangles. Damned fast
and you can use NSBitmapImageReps to cache the results.
See:
http://svn.red-bean.com/restedit/trunk/source/HopView.py
Specifically:
...
def drawRect_(self, aRect):
if self.backingStore:
self.backingStore.draw()
else:
self.eraseView_(aRect)
for pointArray, rectCount, color in self.pointsCountsAndColors:
color.set()
NSRectFillList(pointArray, len(pointArray) / 4)
self.pointsCountsAndColors = []
self.backingStore =
NSBitmapImageRep.alloc().initWithFocusedViewRect_(self.bounds())
if self.pointCount > 100000:
self.pointCount = 0
self.passCount = self.passCount + 1
if self.passCount > 100:
self.stopCalculation()
...
Where pointArray is, quite literally, an array of floating point that
is treated as an array of NSRects. As long as you can break down your
sets of points by color it works great. I plot a few thousand points
of each color and then cache the results in an NSBitmapImageRep that
is blitted down on each drawRect_() invocation.
(Python via PyObjC... but the Obj-C is basically the same)
b.bum
_______________________________________________
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