Trying to squeeze a bit more speed out of certain bottlenecks in my code. Here's one of them:

                        NSBitmapImageRep* bits = [self pathBitmapInRect:ir];
                        
                        // if any pixels in this bitmap are set, we have a hit.
                        
                        int             x, y;
                        unsigned        pixel;
                        
                        for( y = 0; y < ir.size.height; ++y )
                        {
                                for( x = 0; x < ir.size.width; ++x )
                                {
                                        [bits getPixel:&pixel atX:x y:y];
                                        
                                        if ( pixel < 255 )
                                        {
                                                hit = YES;
                                                goto endOfLoop;
                                        }
                                }
                        }
                        
                        endOfLoop:


The <bits> object is a grayscale bitmap where the background is painted white and any set pixels are painted black. I just need to know if there are *any* black pixels in the image. <ir> is an NSRect which can be any size. The imaging method (not shown) accounts for the origin of this rect, so the test scans from 0,0. The purpose is to test whether a given rect intersects a rendered object (path), not just test a point against it.

Is there any faster way of doing this than just iterating over the pixels like this? I can't think of anything but someone might have a bright idea.

tia,


Graham
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to