Odd behaviour when loading a greyscale BMP

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
bridgeco
Posts: 13
Joined: Fri Mar 19, 2004 8:19 pm
Location: London
Contact:

Odd behaviour when loading a greyscale BMP

Post by bridgeco »

I've been using the terrain scene node, but getting some slightly unexpected results. I'm loading the heightmap from a greyscale (8 bit) bmp file, and would expect to get elevations from 0 to 255 units (pure black to pure white). However, the maximum height was coming out at 239.

I've been checking the createImageFromFile method with different types of bitmap, and seem to get inconsistent results. If I load a regular RGB (8 bit) bmp file, the pixel colours are as expected. However, if I load a greyscale bitmap, and check the colours with getRed etc, I get odd results with pure white giving (239,239,239) and pure black giving (82,66,66) r,g,b values. All bitmap images were created with Gimp (2.8.10)

As I'm just starting to use the engine, I'm not sure if I'm making some mistake, but would like to know if this behaviour is expected? This is with Irrlicht 1.8.1 (Build 9200) using renderer: OpenGL 4.0.0.

I have uploaded a simple test case at http://www.bridgecommand.co.uk/data/_up ... leTest.txt, which demonstrates this with 4 images: testBlackGreyscale.bmp testBlackRGB.bmp testWhiteGreyscale.bmp and testWhiteRGB.bmp.
-------------------------------------
Bridge Command

a 3d ship simulator for navigation training
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Odd behaviour when loading a greyscale BMP

Post by Seven »

Doesn't the terrain use the hue for height? Not sure how that converts
bridgeco
Posts: 13
Joined: Fri Mar 19, 2004 8:19 pm
Location: London
Contact:

Re: Odd behaviour when loading a greyscale BMP

Post by bridgeco »

I think the terrain loader uses getLightness(), which returns the average of max(r,g,b) and min(r,g,b). Therefore if the r, g and b values are identical, as you would expect in a greyscale image, it will return this value.

After a bit more digging, it seems as if the problem is related to the format of the BMP image used. There are different versions of the BMP header, and it seems that the one used by default by Gimp 2.8 for greyscale BMPs is not properly read by Irrlicht (and various other programs, see for example https://www.allegro.cc/forums/thread/61 ... 939#target). For the moment I can work around this by using Gimp's 'do not write color space information' export option.
-------------------------------------
Bridge Command

a 3d ship simulator for navigation training
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Odd behaviour when loading a greyscale BMP

Post by hendu »

FYI, greyscale PNGs load fine, and are maybe a hundred times smaller than the comparable BMP.
Post Reply