Re: Converting ColorPicker values into 24-bit color values
Re: Converting ColorPicker values into 24-bit color values
- Subject: Re: Converting ColorPicker values into 24-bit color values
- From: "Mark J. Reed" <email@hidden>
- Date: Mon, 06 Jun 2011 15:38:37 -0400
On Sat, Jun 4, 2011 at 11:24 PM, Jim Thorton
<email@hidden> wrote:
Hello AppleScripters,
A while ago, I picked a simple conversion formula at one web site (http://www.macosxautomation.com/applescript/sbrt/sbrt-04.html) for converting the RGB color values returned by ColorPicker into 24-bit RGB color values. It works fine except a very minor thing. I just happened to choose one red-like color, which Color Picker returns the following.
{58418, 477, 4919}
According to the web site above, I would just divide each value by 256.
24-bit RGB has 8 bits for each component, so there are 256 possible values: 0 through 255.
Color-picker is 48-bit RGB, so each component has 16 bits and therefore has 256 * 256 = 65,536 possible values: 0 through 65535.
Logically, then, the correct scaling conversion is to take the number from Color Picker, divide by its maximum value 65,535, and multiply the result by the new maximum value 255. So that's actually the same as dividing by 257, not 256; if you divide by 256 and round up, you'll potentially get a 256, which won't fit into a byte. The reason people divide by 256 instead is because it's computationally easier - just do a right shift by 8 bits and then, if you care about rounding, add one if the carry bit is set (but not if the result is already 255. :) Much, much faster than doing division.
RGB(228,2,19)
Well, if I go back to Color Picker, picking the same color and setting the color menu to RGB Sliders, I get the following.
RGB(227,2,19)
So which is correct?
If you divide 58418 by 257, you'll get 227.307.... which rounds down and yields the same results as Color Picker.
But again, as Stan said, I wouldn't sweat the difference between 227 and 228 in the red component. The eye is only really sensitive enough to pick out single-step differences in the green component (in fact, you really need 9 bits to get completely fluid green or greyscale). Side by side you might be able to detect the difference, but I wouldn't bet on it.
Thank you for your advice.
Jim _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
--
Mark J. Reed <
email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden