For a small image, Iâd use the RGBSurface.Pixel method and loop through all pixels in the RGB image.
A quick, approximate conversion from RGB to gray can be done with a weighted sum (rather than Markusâs average): grey = 0.299 * R + 0.587 * G + 0.114 * B This better approximates the response of the human visual system. For example, human vision is more sensitive to green, so the weighting factor for green is greater.
A more rigorous approach would involve using the color management system of your display if you have a calibrated display. If you cannot do this, you might be safe assuming your user has a âstandardâ display that is calibrated to âsRGBâ. Be aware that XOJO uses the âgeneric RBGâ model, so you may have to invoke transforms between âgeneric RGBâ and âsRGBâ to get it right.
It would be nice if XOJO could build in easy access to the systemâs color management system and be more clear about these issues in the âdocumentationâ.
RGBSurface.Transform indeed applies a LUT, but itÂs a 1D-LUT (independently mapping red to red, green to green, and blue) while turning a color image to grayscale requires a more complex 3D-LUT (mapping RGB to RGB). Looping through the pixels in the RGBSurface, calculating a weighted sum of the RGB values, and creating a new picture from the resulting grayscale pixels would be your best bet.