Re: Quickly drawing non-antialiased, discrete, pixels
Re: Quickly drawing non-antialiased, discrete, pixels
- Subject: Re: Quickly drawing non-antialiased, discrete, pixels
- From: Marco Scheurer <email@hidden>
- Date: Mon, 6 Jan 2003 17:29:29 +0100
On Monday, January 6, 2003, at 02:23 AM, Bill Bumgarner wrote:
It seems that there simply isn't an efficient way to paint sets of
individual discrete pixels under Cocoa right now. I will need to
investigate either CG or OpenGL.
Using NSRectFillList (there's also a NSRectFillListWithColors) I've
just painted 100000 pixels in ~5 seconds on a 400 MHz Powerbook (1000
in 0.02), and they are not antialiased. Not good enough?
//PixelView.h
#import <Cocoa/Cocoa.h>
#define RCOUNT 100000
@interface PixelView : NSView
{
NSRect rects[RCOUNT];
}
@end
//PixelView.m
#import "PixelView.h"
static __inline__ float randomFloatBetween(float a, float b)
{
return a + (b - a) * ((float)random() / (float) LONG_MAX);
}
@implementation PixelView
- (id) initWithFrame:(NSRect) aFrame
{
int count = RCOUNT;
[super initWithFrame:aFrame];
while (count--) {
float x = (int) randomFloatBetween (0.0, aFrame.size.width);
float y = (int) randomFloatBetween (0.0, aFrame.size.height);
rects[count] = NSMakeRect (x, y, 1.0, 1.0);
}
return self;
}
- (void) drawRect:(NSRect) aRect
{
NSTimeInterval startDate = [NSDate timeIntervalSinceReferenceDate];
NSRectFillList (rects, RCOUNT);
NSLog (@"%.2f", [NSDate timeIntervalSinceReferenceDate] -
startDate);
}
@end
Marco Scheurer
Sen:te, Lausanne, Switzerland
http://www.sente.ch
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.