1 person found this helpful
There are two things going on. One is a single channel can not contain a RGB color. For channels you should use fillColor.gray.gray = someValue; You can use an RGB color but it will be converted( see below )
The other thing is unless the document is in Grayscale mode that gray color has to be converted into whatever the document's color mode is and that conversion is made using the defalut gray profile in the apps color settings. For example if I run your code with the defalut gray profile set to 'dot gain 20%' I get the same results( 149, 149, 149 ). But if I change it to 'Gray Gamma 2.2' I get 129, 129, 129 which is closer to what you seem to expect.
This same number anomaly bugged me for a while until I figured it out. Michael is correct that the single channels are interpretted as grayscale K values in the set grayscale space. I do not believe it is just the conversion from color to grayscale however.
I concluded that in some circumstances, Photoshop writes to the channel with a conversion from color to gray K values and sometimes it does not.
The issue of the 149 stems from writing directly in the channel without conversion, yet reading back out with a conversion. 128s are written in without conversion. The numbers in the isolated channel are interpretted as grayscale K values 128/255=50%. When reading back out this grayscale value, it looks at both the present grayscale space and the present color space. When you have a grayscale space of 20% Dot Gain and an sRGB color space, a K value of 50% would be converted to an RGB value of 149. The acutal value that comes out is dependent on both the grayscale space and the color space set at the moment. (you would get a smaller number with a larger gamut color space)
So you ended up doing a round trip writing into the channel and reading back out of the channel. You would end up with the same number if there was a color space conversion both directions. With your code, you have no conversion writing in, yet you have a conversion reading out. Depending on what you are tyring to do, this may be what you need. If not there are alternative approaches and Michael mentioned one of several possibilities. If this needs more clarification, ask more question and let us know what you are tyring to achieve. Writing to the channel with conversion can be done.
So why you may ask did Photoshop do it this way. I think because the channels play double duties. 1) As grayscale values tied to the set grayscale space and 2) As values used directly in determining opacity/transparency. They chose reading as if always #1. That's my best guess. Hope this helps.