so I've been sifting through some code in the Go standard library trying to make sense of their image and color packages but found some code I just can't make sense of. from http://golang.org/src/pkg/image/color/color.go?s=794:834#L14
From my understanding it should convert 8bit pre-alpha-multiplied RGB values to 16 bit ones, saved in 32bit variables to stop them from overflowing when multiplying in image arthimetic.
What I can't make sense of are the lines like r |= r << 8
as I understand it this is equivalent to r = r*2^8+r
because r << 8
inserts zeros to the right and they get or'ed with the old r.
For an input of r=255 this evaluates to 65535=2^16 - 1 which is as expected, but it doesn't make sense for the values in the middle, which don't really get mapped to something proportional in the bigger range. For example 127 get's mapped to 32639 while I'd expect 32767 to represent 127. What am I missing? I think it has something to do with the pre-alpha-multiplication...
func (c RGBA) RGBA() (r, g, b, a uint32) {
r = uint32(c.R)
r |= r << 8
g = uint32(c.G)
g |= g << 8
b = uint32(c.B)
b |= b << 8
a = uint32(c.A)
a |= a << 8
return
}