• 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
Re: Comparing NSColor instances
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing NSColor instances


  • Subject: Re: Comparing NSColor instances
  • From: Ricky Sharp <email@hidden>
  • Date: Sun, 4 Nov 2007 20:58:22 -0600


On Nov 4, 2007, at 8:29 PM, Ricky Sharp wrote:

I have the need to compare multiple NSColor instances to see if they all represent the same color. This is so I can correctly support multiple selection in a new IB 3.0 plugin.

My first approach was to "normalize" all colors like so:

NSColor* normalizedColor = [aColor colorUsingColorSpace: [NSColorSpace genericRGBColorSpace]];

Then, extract the RGB components with getRed:green:blue:alpha: so I could do a simple comparison of them.

But, when calling getRed::::, I get the following in the Console:

*** -getRed:green:blue:alpha: not defined for the NSColor NSCustomColorSpace Generic RGB colorspace 0 0 0 1; need to first convert colorspace.

Also tried deviceRGBColorSpace, but got the same results.


My assumption above was that since I was using an 'RGB' color space, that one could then call getRed:green:blue:alpha:.

I do have a working solution to where I still normalize to the same color space, but then use numberOfComponents followed by a getComponents: with a CGFloat array. I then compare the values in the array.

I should beef up the code though to handle the case where calling numberOfComponents can raise an exception (if no floating point components exist for the color).

Also, I'm never keen on doing exact compares on floating point values, so I may add in a bit of "slop" to the compare. On the other hand, if I do normalize two colors to the same color space, it should be reasonable to assume it will have identical valued components.

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________

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: Comparing NSColor instances
      • From: Ali Ozer <email@hidden>
    • Re: Comparing NSColor instances
      • From: Dave Camp <email@hidden>
    • Re: Comparing NSColor instances
      • From: John Stiles <email@hidden>
References: 
 >Comparing NSColor instances (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: Smart way to get "etched" borders in Leopard
  • Next by Date: Re: Locating managed objects within ObjectAlloc (was Re: Garbage collection, core data, and tight loops)
  • Previous by thread: Comparing NSColor instances
  • Next by thread: Re: Comparing NSColor instances
  • Index(es):
    • Date
    • Thread