Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Question:

Question: Those RGB numbers

This is a follow-on question to my recent post concerning properties of windows.

The Terminal Inspector allows for setting colors of a Terminal window(s). if I set the background color to a specific "crayon" color, then get properties of the window, the background color listed is (for example): {-1, -13108, 26214}

If I then run "choose color" and select the same crayon, I get: {65535, 52428, 26214}

I'm wondering what the negative numbers mean, and why there is this discrepancy.

Red_menace pointed out to me that a fourth number addresses transparency. If, with Terminal Inspector, I set transparency to about 50%, that fourth number does appear in the properties. In this case: -27441 (again a negative number)

Ignoring that my Terminal Dictionary claims background color is a string, if I run this script:

tell application "Terminal" to set background color of window 1 to {R,G,B}, either of the color sets above yields the same result.

And, if I add a fourth number [as in {R,G,B,Trans}], I can use the same script to control transparency as well as color -- but the numbers for "Trans" needed for different transparency results throws me. Examples:

{-1, -13108, 26214, 0} yields 100% transparency

{-1, -13108, 26214, -1} seems to yield 0 transparency

{-1, -13108, 26214, -10000} yields about 50% transparency

and so on (I won't even talk about postive numbers)

I guess my question is: are there any rules to this?

2.7G5 AND OTHERS, Mac OS X (10.4.6)

Posted on

Reply
Question marked as Solved
Answer:
Answer:
Hello

It looks like that Terminal returns {R, G, B} (or {R, G, B, A}) values interpreted as signed 16-bit integer and accepts {R, G, B} in both signed and unsigned integers' list.

E.g.
signed 16-bit integer [-32768, 32767]:
-1 = 0xFFFF
-13108 = 0xCCCC
26214 = 0x6666

unsigned 16-bit integer [0, 65535]:
65535 = 0xFFFF
52428 = 0xCCCC
26214 = 0x6666



You may convert unsigned short integer (U16) to signed short integer (S16) by these.

S16 to U16:
For S16 < 0, U16 = S16 + 65536
For S16 >= 0, U16 = S16
Or for any S16 in [-32768, 32767], U16 = (S16 + 65536) mod 65536

U16 to S16:
For U16 > 32767, S16 = U16 - 65536
For U16 <= 32767, S16 = U16
Or for any U16 in [0, 65535], S16 = U16 - (U16 div 32768) * 65536



I'm not sure about Terminal's transparency parameter, but it looks like alpha channel value in range [0, 65535] (unsigned) or [-32768, 32767] (signed), in other words in range [0x0000, 0xFFFF]. I think you may convert them by the same formulae as for RGB values.

Hope this may be of some help.
H

Posted on

Question marked as Solved

Aug 15, 2007 12:35 PM in response to osimp In response to osimp

Hello

It looks like that Terminal returns {R, G, B} (or {R, G, B, A}) values interpreted as signed 16-bit integer and accepts {R, G, B} in both signed and unsigned integers' list.

E.g.
signed 16-bit integer [-32768, 32767]:
-1 = 0xFFFF
-13108 = 0xCCCC
26214 = 0x6666

unsigned 16-bit integer [0, 65535]:
65535 = 0xFFFF
52428 = 0xCCCC
26214 = 0x6666



You may convert unsigned short integer (U16) to signed short integer (S16) by these.

S16 to U16:
For S16 < 0, U16 = S16 + 65536
For S16 >= 0, U16 = S16
Or for any S16 in [-32768, 32767], U16 = (S16 + 65536) mod 65536

U16 to S16:
For U16 > 32767, S16 = U16 - 65536
For U16 <= 32767, S16 = U16
Or for any U16 in [0, 65535], S16 = U16 - (U16 div 32768) * 65536



I'm not sure about Terminal's transparency parameter, but it looks like alpha channel value in range [0, 65535] (unsigned) or [-32768, 32767] (signed), in other words in range [0x0000, 0xFFFF]. I think you may convert them by the same formulae as for RGB values.

Hope this may be of some help.
H

Aug 15, 2007 12:35 PM

Reply Helpful
User profile for user: osimp

Question: Those RGB numbers