Discussion:
[osgPlugins] bmp load vertically flipped
stefan nortd
2009-09-03 12:04:38 UTC
Permalink
Hi,

I have been doing some image stuff lately. JPEGs and PNGs load right but
BMPs are upside down. Is this a feature or a bug?

At the moment I am doing this for remedy:

Code:

osg::Image* image = osgDB::readImageFile(filename);
if(filename.substr(filename.length()-3) == "bmp") {
image->flipVertical();
}





Just thought I share this.

Thank you!

Cheers,
stefan

------------------------
stefan hechenberger

http://linear.nortd.com

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=16993#16993
Ulrich Hertlein
2009-09-03 14:02:39 UTC
Permalink
Hi Stefan,
Post by stefan nortd
I have been doing some image stuff lately. JPEGs and PNGs load right but
BMPs are upside down. Is this a feature or a bug?
I believe the problem with BMPs is that they don't define an 'up' direction.
It's up to the originating modelling package how it's stored. The loader doesn't try to
fix what it doesn't know.

Cheers,
/ulrich
stefan nortd
2009-09-03 15:14:48 UTC
Permalink
hey ulrich,

I am not sure I understand. I am loading a bmp and use it as a texture on a quad. I use the same texture coordinates for various image types but only the bmp displays upside down.

stefan

------------------------
stefan hechenberger

http://linear.nortd.com

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=17007#17007
Ulrich Hertlein
2009-09-03 15:39:56 UTC
Permalink
Hi Stefan,
Post by stefan nortd
I am not sure I understand. I am loading a bmp and use it as a texture on a quad. I use
the same texture coordinates for various image types but only the bmp displays upside
down.
Then I would say your BMP is upside down ;-)

I have a stack of objects with BMP textures that would definitively look wrong if the
loader would always flip the image. It's all down to how it was modelled.

Cheers,
/ulrich
Kawicki, Ryan H
2009-09-03 15:47:15 UTC
Permalink
Bitmaps are stored upside down internally. If the loader is not
flipping your image, then flip the image yourself.
From "http://en.wikipedia.org/wiki/BMP_file_format"
Bitmap data

This block of bytes describes the image, pixel by pixel. Pixels are
stored "upside-down" with respect to normal image raster scan order,
starting in the lower left corner, going from left to right, and then
row by row from the bottom to the top of the image.[2] Uncompressed
Windows bitmaps can also be stored from the top row to the bottom, if
the image height value is negative.

Ryan H. Kawicki
The Boeing Company
Training Systems & Services
Software Engineer
Ulrich Hertlein
2009-09-03 16:02:04 UTC
Permalink
Post by Kawicki, Ryan H
Bitmaps are stored upside down internally. If the loader is not
flipping your image, then flip the image yourself.
From "http://en.wikipedia.org/wiki/BMP_file_format"
Bitmap data
This block of bytes describes the image, pixel by pixel. Pixels are
stored "upside-down" with respect to normal image raster scan order,
starting in the lower left corner, going from left to right, and then
row by row from the bottom to the top of the image.[2] Uncompressed
Windows bitmaps can also be stored from the top row to the bottom, if
the image height value is negative.
Ah, good point. The loader actually checks for negative height values and corrects them.
Which means it's flipping the image but not exposing this information.

/ulrich
stefan nortd
2009-09-03 19:32:17 UTC
Permalink
Granted that different image types store pixels differently I would still
assume that the image loader should nevertheless be consistent across different image format. I guess this is an assumption that depends how low-level one approaches pixel data.

So I record it is not a bug in the image loader. correct?

Thank you!

Cheers,
stefan

------------------------
stefan hechenberger

http://linear.nortd.com

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=17031#17031
Chris 'Xenon' Hanson
2009-09-03 20:35:14 UTC
Permalink
Post by stefan nortd
Granted that different image types store pixels differently I would still
assume that the image loader should nevertheless be consistent across different image format. I guess this is an assumption that depends how low-level one approaches pixel data.
Agreed.
Post by stefan nortd
So I record it is not a bug in the image loader. correct?
It could be a bug, or it could be a bug in whatever created the BMP. Do we have sample
data that we can look at? I know the BMP format pretty well.
--
Chris 'Xenon' Hanson, omo sanza lettere Xenon AlphaPixel.com
PixelSense Landsat processing now available! http://www.alphapixel.com/demos/
"There is no Truth. There is only Perception. To Perceive is to Exist." - Xen
Ulrich Hertlein
2009-09-04 08:46:18 UTC
Permalink
Granted that different image types store pixels differently I would still assume that
the image loader should nevertheless be consistent across different image format. I
guess this is an assumption that depends how low-level one approaches pixel data.
So I record it is not a bug in the image loader. correct?
Agreed, it's not a bug but a missing feature.

Could you run your code with OSG_NOTIFY_LEVEL=DEBUG_INFO and grep the output for 'BMP
Image is upside-down' (which indicates 'height<0')?

The models I have do not have negative height so if your BMP does we could expose it and
flip the Image automatically.

Cheers,
/ulrich

Continue reading on narkive:
Loading...