在iOS中加载4通道纹理数据

问题描述:

我想从iOS中的文件加载4通道纹理数据,因此我将纹理视为(连续)地图

I want to load 4-channel texture data from a file in iOS, so I consider the texture as a (continuous) map

[0,1]x[0,1] -> [0,1]x[0,1]x[0,1]x[0,1]

如果我使用fileformat .png ,XCode / iOS会将该文件视为图像,因此将每个组件相乘 rgb 使用 a (预乘alpha),破坏我的数据。我该怎么解决这个问题?示例可能是

If I use the fileformat .png, XCode/iOS consider the file as an image, and so multiplies each component rgb with a (premultiplied alpha), corrupting my data. How should I solve this? Examples may be


  • 使用两个纹理组件 rgb (3通道)

  • postdivide alpha

  • 使用其他文件格式

  • use two textures with components rgb (3-channel)
  • postdivide alpha
  • use another file format

其中,我认为最好的解决方案是使用其他文件格式。 GL压缩文件格式(PVRTC?)不是Apple平台独立的,似乎是低分辨率(4位)( reference )。

Of these, I consider the best solution to be to use another file format. The GL-compressed file format (PVRTC?) is not Apple-platform independent and seems to be of low resolution (4 bits) (reference).

编辑:
如果我自己的答案如下,则无法在iOS中获取png的4通道数据。由于OpenGL是关于创建图像而不是呈现图像,因此应该可以以某种方式加载4通道数据。 png是图像的文件格式(和压缩取决于所有4个通道但是一个通道的压缩独立于其他通道),因此有人可能会说我应该使用其他文件格式。那么我应该使用哪种其他压缩文件格式,哪些易于在iOS中阅读/集成?

If my own answer below is true, it is not possible to get the 4 channel data of png's in iOS. Since OpenGL is about creating images rather than presenting images, it should be possible to load 4-channel data in some way. png is a fileformat for images (and compression depends on all 4 channels but compression of one channel is independent of the other channels), so one may argue that I should use another file format. So which other compressed file formats should I use, which is easy to read/integrated in iOS?

更新:组合提到了一种加载4通道的方法预乘纹理,所以我不得不给他正确答案。但是,该解决方案有一些我不喜欢的限制。我的下一个问题是从iOS中的png文件访问原始4通道数据:)

UPDATE: "combinatorial" mentioned a way to load 4-channel non-premultiplied textures, so I had to give him the correct answer. However, that solution had some restrictions I didn't like. My next question is then "Access raw 4-channel data from png files in iOS" :)

我认为这是一个糟糕的库设计,无法读取4通道png数据。我不喜欢系统试图比我自己聪明。

I think it is a bad library design not making it possible to read 4 channel png data. I don't like systems trying to be smarter than myself.

正如您考虑PVRTC然后使用 GLKit 可以是一个选项。这包括 GLKTextureLoader 加载纹理而不预先乘以alpha。使用例如:

As you considered PVRTC then using GLKit could be an option. This includes GLKTextureLoader which allows you to load textures without pre-multiplying alpha. Using for example:

+ (GLKTextureInfo *)textureWithContentsOfFile:(NSString *)fileName options:(NSDictionary *)textureOperations error:(NSError **)outError

并传递包含以下内容的选项字典:

and passing an options dictionary containing:

GLKTextureLoaderApplyPremultiplication = NO