c - 为什么 FreeImage 加载 BGR 格式的图像?

标签 c opengl-es android-ndk freeimage

我使用 Android NDK 和 FreeImage 库编写游戏,将图像加载到我的游戏中。它加载 BGR 格式的图像。可以以RGB格式加载吗?或者我需要手动交换 R 和 B 组件?

已编辑

我的设备是三星 Galaxy S4(armv7 架构)。这是代码`

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 documentation 中的“像素访问函数”部分包含以下语句(强调我的):

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.

但是,当您想要使用 FreeImage 的原始像素数据作为 OpenGL 的源时,这些宏将无法帮助您。

但我不知道你的问题是什么。 OpenGL 将接受 BGR(A) 和 RGB(A) 作为图像数据。事实上,FreeImage 的选择也不错,因为 BGR(A) 很可能是此类平台上的原生数据格式,因此使用这种格式是传输图像数据最有效的方式。

关于c - 为什么 FreeImage 加载 BGR 格式的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31103121/

相关文章:

android opengl 纹理重叠

android - 如何在 Android studio 中禁用 android native 调试器

Android C++ 而不是 C

Android NDK 在 JNI 中使用来自 c 代码的 .so 库

c - 在 Windows 中启动失败的二进制文件未找到 Eclipse for C

android - requestRender 似乎没有呈现 (opengl-es android)

c - 为什么 malloc() 和普通数组声明分配的堆栈帧大小不同?

ios - 使用 SpriteKit 的着色器仅注册黑色的 alpha

c - 字符串格式 %80[^,] 在 C 中是什么意思?

c - 为什么 pthread_create 函数将线程函数名作为参数而不是调用它?