为什么FreeImage以BGR格式加载图像? [英] Why FreeImage loads image in BGR format?

查看:207
本文介绍了为什么FreeImage以BGR格式加载图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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):

但是,此模型使用的像素布局取决于操作系统.使用逐字节内存 为了标记像素布局,然后FreeImage在Little下方使用BGR [A]像素布局 Endian处理器(Windows,Linux),并在Big Endian处理器(Mac OS X或任何Big Endian Linux/Unix)下使用RGB [A]像素布局.做出此选择是为了简化使用 图形API的FreeImage的实现.

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.

这个细微的差别对用户是透明的.为了使像素访问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格式加载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆