• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Faster way to test pixels?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Faster way to test pixels?


  • Subject: Faster way to test pixels?
  • From: Graham Cox <email@hidden>
  • Date: Sun, 25 May 2008 15:55:05 +1000

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 (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


  • Follow-Ups:
    • Re: Faster way to test pixels?
      • From: "Ken Ferry" <email@hidden>
    • Re: Faster way to test pixels?
      • From: Jens Alfke <email@hidden>
    • Re: Faster way to test pixels?
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: Scope in an interface?
  • Next by Date: Re: Scope in an interface?
  • Previous by thread: Re: Scope in an interface?
  • Next by thread: Re: Faster way to test pixels?
  • Index(es):
    • Date
    • Thread