问题描述
我使用Android NDK和FreeImage库编写游戏,以将图像加载到我的游戏中.它以BGR格式加载图像.可以以RGB格式加载吗?还是我需要手动交换R和B组件?
I write game using Android NDK and FreeImage library to load images into my game. It loads images in BGR format. It is possible to load in RGB format? Or I need to swap R and B components manualy?
已编辑
我的设备是三星Galaxy S4(armv7体系结构).这是代码`
My device is Samsung Galaxy S4(armv7 archtecture). Here is code`
FIMEMORY* fiStream = FreeImage_OpenMemory((BYTE*)data, size);
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(fiStream);
if (FreeImage_FIFSupportsReading(fif))
{
dib = FreeImage_LoadFromMemory(fif, fiStream, 0);
}
if (!dib)
return;
data_ = FreeImage_GetBits(dib);
width_ = FreeImage_GetWidth(dib);
height_ = FreeImage_GetHeight(dib);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width_, height_, 0, GL_RGB, GL_UNSIGNED_BYTE, data_ );
推荐答案
FreeImage实际上不一定使用BGR(A)排序. FreeImage文档中的像素访问功能"部分包含以下语句(强调我的意思):
FreeImage actually doesn't neccessarily use BGR(A) ordering. Section "Pixel access functions" in the FreeImage documentation contains the following statement (emphasis mine):
这个细微的差别对用户是透明的.为了使像素访问OS 独立的FreeImage定义了一组用于设置或获取单独颜色的宏 24位或32位DIB中的组件.
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.
但是,当您要将FreeImage的原始像素数据用作OpenGL的源时,这些宏将无济于事.
However, these macros will not help you when you want to use FreeImage's raw pixel data as source for OpenGL.
但是我不知道您的问题是什么. OpenGL将接受BGR(A)和RGB(A)作为图像数据.实际上,FreeImage的选择还不错,因为BGR(A)很可能是此类平台上的本机数据格式,因此使用这种格式代表了传输图像数据的最有效方法.
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以BGR格式加载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!