On Aug 13, 2011, at 5:21 PM, Jim Thorton wrote: Hola. I know that I can use AppleScript to open the Color Picker window. If the user picks a color, you will get a 16-bit-per-channel color like {52428, 54484, 45232}. If you want to manually convert this color into an 8-bit-per-channel color for an RGB color, I guess you need to divide each component by 256. Well, I would get RGB(204,212,176). And that's what I get if I select RGB Sliders from the color sliders drop-down menu. But you can never convert this RGB color back into what it was. If you multiple each component by 256, you would get {52224,54272,45056}, which differs from the original color.
Is there any way to convert an RGB color back into the original 16-bit-per-channel color?
Well, you obviously can't recover information lost from the down-conversion to 8-bits, but the standard way to convert from 8- to 16-bits per component is to copy the byte into the high byte of the 16-bit value. e.g., 0x03 becomes 0x0303, 0xFE becomes 0xFEFE. The reason to do this is so that the 8-bit values 0 through 255 (0xFF) produce 16-bit values 0 to 65,535 (0xFFFF) with an even distribution of values.
Multiply the 8-bit value by 256 to shift it left by eight bits, then add it to the original 8-bit value to get the appropriate 16-bit value.
-- Chris Page
The other, other AppleScript Chris
|