Why FreeImage loads image in BGR format?

老子叫甜甜 提交于 2019-12-04 16:57:33

FreeImage actually doesn't neccessarily use BGR(A) ordering. Section "Pixel access functions" in the FreeImage documentation contains the following statement (emphasis mine):

However, the pixel layout used by this model is OS dependant. Using a byte by byte memory order to label the pixel layout, then FreeImage uses a BGR[A] pixel layout under a Little Endian processor (Windows, Linux) and uses a RGB[A] pixel layout under a Big Endian processor (Mac OS X or any Big Endian Linux / Unix). This choice was made to ease the use of FreeImage with graphics API.

This subtle difference is however transparent to the user. In order to make pixel access OS independent, FreeImage defines a set of macros used to set or get individual color components in a 24- or 32-bit DIB.

However, these macros will not help you when you want to use FreeImage's raw pixel data as source for OpenGL.

But I don't know what your issue with this is. OpenGL will accept BGR(A) as well as RGB(A) as image data. And actually, FreeImage's choice is not bad, as BGR(A) is most likely the native data format on such platforms, so that using this format represents the most efficient way to transfer image data.

FreeImage can be built to always load in RGB order independent of the architecture. Use #define FREEIMAGE_COLORORDER=FREEIMAGE_COLORORDER_RGB. If you're using Android.mk to build FreeImage, add the following line to it:

LOCAL_CPPFLAGS += -DFREEIMAGE_COLORORDER=FREEIMAGE_COLORORDER_RGB

Documentation for this can be found in Source/FreeImage.h if you search for FREEIMAGE_COLORORDER:

Color-Order:

The specified order of color components red, green and blue affects 24- and 32-bit images of type FIT_BITMAP as well as the colors that are part of a color palette. All other images always use RGB order. By default, color order is coupled to endianness:

little-endian -> BGR

big-endian -> RGB

However, you can always define FREEIMAGE_COLORORDER to any of the known orders FREEIMAGE_COLORORDER_BGR (0) and FREEIMAGE_COLORORDER_RGB (1) to specify your preferred color order.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!