danomatika / loaf

loaf: lua, osc, and openFrameworks
http://danomatika.com/code/loaf
GNU General Public License v3.0
53 stars 4 forks source link

Strange behaviour of ofPixels:getColor() on grayscale images #6

Closed dom1817 closed 3 years ago

dom1817 commented 5 years ago

ofPixels:getColor() returns an RGBA value instead of a single value, even if allocated using the of.PIXEL_GRAY format. All the other settings are updated properly.

local pixels = of.Pixels()
pixels:allocatePixelFormat(width, height, of.PIXELS_GRAY)

print("------------------------------------------------")
print("Pixel color:", pixels:getColor(1,1))
print("Size:", pixels:size())
print("Bits per pixels", pixels:getBitsPerPixel())
print("Pixel channels", pixels:getNumChannels())
print("------------------------------------------------")

Returns:

------------------------------------------------
Pixel color:        0, 0, 0, 255 ?
Size:           389550.0
Bits per pixels     8.0
Pixel channels      1.0
------------------------------------------------
danomatika commented 3 years ago

That is expected as ofColor uses RGBA internally: https://github.com/openframeworks/openFrameworks/blob/e6e4ee1da88f507f36bad503cd329b31eaadccac/libs/openFrameworks/types/ofColor.h#L83