Re: floats & Color APIs
Re: floats & Color APIs
- Subject: Re: floats & Color APIs
- From: Dietmar Planitzer <email@hidden>
- Date: Tue, 24 Oct 2006 22:12:48 +0200
On Oct 23, 2006, at 8:47 PM, Eric Gorr wrote:
I'm just curious...
What is the reasoning behind moving to floats to represent color in
Apple's Cocoa color APIs?
First and foremost because representing color components as floats
makes it easy to support device-independent specification of color
values. An application specifies a color in the form of floating-
point values which are in the range zero to one and the graphics
library (Quartz in our case) maps the color value to the closest
color that the current output device is capable of displaying. This
process is called quantization and may or may not include dithering.
Another important part of a device-independent color model is support
for color transformations. The application tells Quartz in what color
space the colors are defined that it sends to Quartz and then it
transforms those colors from application (user) space to the color
space of the output device. Quartz uses the color matching services
provided by ColorSync to do this.
This TN has a very good description of how colors are handled by
Quartz and ColorSync: <http://developer.apple.com/technotes/tn/
tn2035.html>
For example,
<http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/Classes/NSColor_Class/Reference/Reference.html#//
apple_ref/occ/instm/NSColor/blueComponent>
Why wasn't 1 byte or even 2 bytes considered to be enough?
Because this would mean that it would not be possible to describe all
colors that are supported by an output devices that supports more
than 8 or 16 bit per color component. Consider for example a modern
graphic card with floating-point frame buffer support.
Were the reasons purely having to do with the speed of certain
calculations?
This may have been a factor. It is certainly faster to keep data in
one representation than to keep it in different representations and
convert it whenever you need to combine your data with other data.
Consider for example compositing operations. However, actual practice
is much more complicated.
Is there any reason not to just covert these numbers to single byte
components for the purpose of file storage?
If device-independence is important to you, then store them as
floating-point values.
Regards,
Dietmar Planitzer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden