且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从原始数据加载devIL映像

更新时间:2023-11-10 13:58:16

如果图像格式具有标题,则通常可以假定它包含一些正确读取文件其余部分所必需的重要信息.***不要使用无意义的数据" 填充它.

If an image format has a header, you can generally assume it contains some important information necessary to correctly read the rest of the file. Filling it with "meaningless data" is inadvisable at best.

由于在DevIL中对于.raw标头没有实际的struct,因此让我们看一下iLoadRawInternal ()的实现,以找出最初的13个字节应该是什么.

Since there is no actual struct in DevIL for the .raw header, let us take a look at the implementation of iLoadRawInternal () to figure out what those first 13-bytes are supposed to be.

// Internal function to load a raw image
ILboolean iLoadRawInternal()
{
    if (iCurImage == NULL) {
        ilSetError(IL_ILLEGAL_OPERATION);
        return IL_FALSE;
    }    

    iCurImage->Width = GetLittleUInt();   /* Bytes: 0-3   {Image Width}     */
    iCurImage->Height = GetLittleUInt();  /* Bytes: 4-7   {Image Height}    */
    iCurImage->Depth = GetLittleUInt();   /* Bytes: 8-11  {Image Depth}     */
    iCurImage->Bpp = (ILubyte)igetc();    /* Byte:  12    {Bytes per-pixel} */

注意: /* comments */是我自己的

GetLittleUInt ()以little-endian顺序读取32位无符号整数,并适当提高读取位置. igetc ()对单个字节执行相同的操作.

GetLittleUInt () reads a 32-bit unsigned integer in little-endian order and advances the read location appropriately. igetc () does the same for a single byte.

struct RAW_HEADER {
  uint32_t width;
  uint32_t height;
  uint32_t depth;  // This is depth as in the number of 3D slices (not bit depth)
  uint8_t  bpp;    // **Bytes** per-pixel (1 = Luminance, 3 = RGB, 4 = RGBA)
};

如果您在il_raw.c中阅读了iLoadRawInternal ()的其余实现,您将看到在标头DevIL中没有正确的值将无法计算正确的文件大小.填写正确的值应该会有所帮助.

If you read the rest of the implementation of iLoadRawInternal () in il_raw.c, you will see that without proper values in the header DevIL will not be able to calculate the correct file size. Filling in the correct values should help.