我正在编写一些代码,这些代码在没有 libpng 的情况下构建基于简单调色板的 PNG 文件。在这个阶段,输出文件只有 IHDR、PLTE、IDAT(x3) 和 IEND 块。唯一可能有点不同的是 IDAT 块中的像素索引值没有被压缩,即各种 zlib / 块头字节如下。
- CMF = 0x78。
- FLG = 0x9C(这里还有一些其他值,但始终清除第 5 位)。
- 块头字节 = 0x01 (BFINAL = 1, BTYPE = 00)。
从我可以看到的代码正确地构建了文件,但是一些图像查看器拒绝完全显示图像,如果有的话。
- MS Paint 很高兴。
- GIMP 很高兴。
- LibreOffice Draw 很高兴。
- Ristretto >> 读取 PNG 图像文件的致命错误:压缩数据不足。
- ImageMagick >> 识别:没有足够的图像数据`20160317_PNG_064.png'@error/png.c/MagickPNGErrorHandler/1645。
- 侏儒之眼 >> 图像数据不足。
我已经通过几个不同的工具将该文件放入了不同的工具中,但结果又好坏参半。
- optipng >> 图像数据不足。
- pngchunks 不报告任何错误。
- pngcheck 不报告任何错误。
这是文件 20160317_PNG_064.png 的十六进制视图
它生成的图片就是这个8x8 像素的小图像。
因此,对于下一步该尝试什么,我陷入了死胡同。感谢您提供任何和所有帮助。
EDIT_000 按照@Mark Adler 的要求,将问题缩小到此处的Adler32 计算是我用来在主函数中使用测试数据计算Adler32 值的代码。顺便说一句,这并不花哨,我的代码非常冗长。
#include <stdio.h>
#define DEBUG
static const unsigned long GC_ADLER32_BASE = 0xFFF1; // Largest prime smaller than 65536 is 65521.
unsigned long Adler32_Update
(
unsigned long Adler32,
unsigned char *Buffer,
unsigned int BufferLength
)
{
unsigned long ulW0;
unsigned long ulW1;
unsigned int uiW0;
#ifdef DEBUG
printf("\n");
printf(" Incoming Adler32 value.................0x%.8X\n", Adler32);
#endif
ulW0 = Adler32 & 0xFFFF;
ulW1 = (Adler32 >> 0x0010) & 0xFFFF;
#ifdef DEBUG
printf(" Inital sum values are..................0x%.8X, 0x%.8X\n", ulW0, ulW1);
#endif
for (uiW0 = 0x0000; uiW0 < BufferLength; uiW0 = uiW0 + 0x0001)
{
ulW0 = (ulW0 + Buffer[uiW0]) % GC_ADLER32_BASE;
ulW1 = (ulW1 + ulW0) % GC_ADLER32_BASE;
}
#ifdef DEBUG
printf(" Final sum values are...................0x%.8X, 0x%.8X\n", ulW0, ulW1);
#endif
Adler32 = (ulW1 << 0x0010) | ulW0;
#ifdef DEBUG
printf(" Outgoing Adler32 value.................0x%.8X\n", Adler32);
#endif
return (Adler32);
}
unsigned long Adler32_Get
(
unsigned char *Buffer,
unsigned int BufferLength
)
{
unsigned long Adler32;
Adler32 = 0x00000001L;
Adler32 = Adler32_Update(Adler32, Buffer, BufferLength);
return (Adler32);
}
int main
(
unsigned int argc,
unsigned char *arg[]
)
{
unsigned long Adler32;
unsigned char data[272] =
{
0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01,
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x01, 0x01,
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00, 0x01,
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x00,
0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02
};
Adler32 = Adler32_Get(data, sizeof(data));
printf("\n");
printf("The Adler32 value is ..........................0x%.8X\n", Adler32);
return(0x00);
}