【发布时间】:2019-04-27 17:21:14
【问题描述】:
我无法将 png IDAT 块膨胀回 RGB 数据。
void PNG::IDAT()
{
int index = 0;
char CMF = m_data[index];
index++;
//big endian
char CM = CMF & 0b00001111;
char CINFO = CMF & 0b11110000;
//For CM = 8, CINFO is the base-2 logarithm of the LZ77 window size, minus eight(CINFO = 7 indicates a 32K window size).
char FLG = m_data[index];
index++;
char FCHECK = FLG & 0b00011111;
//The FCHECK value must be such that CMF and FLG, when viewed as a 16 - bit unsigned integer stored in MSB order(CMF * 256 + FLG), is a multiple of 31. //effort
char FDICT = FLG & 0b00100000;
char FLEVEl = FLG & 0b11000000;
char DICTID[4];
if (FDICT > 0)
{
memcpy(DICTID, &m_data[index], 4);
index += 4;
}
uLong outputLength = compressBound(m_length);
char* output = new char[outputLength];
z_stream infstream;
infstream.zalloc = Z_NULL;
infstream.zfree = Z_NULL;
infstream.opaque = Z_NULL;
infstream.avail_in = m_length; // size of input
infstream.next_in = (Bytef *)m_data; // input char array
infstream.avail_out = outputLength; // size of output
infstream.next_out = (Bytef *)output; // output char array
inflateInit2(&infstream, 16 + MAX_WBITS);
inflate(&infstream, Z_NO_FLUSH);
inflateEnd(&infstream);
for (size_t i = 0; i < outputLength; i+= 3)
{
pixel temp;
temp.r = output[i + 0];
temp.g = output[i + 1];
temp.b = output[i + 2];
m_pixels.push_back(temp);
}
}
Inflate 返回错误代码 -3,表示“Z_DATA_ERROR”。我遵循了 RFC-1950 和 RFC-1951 标准,但我对哪些字节实际上需要流式传输到 inflate 函数以及哪些需要被剥离感到困惑。
m_data 实际上只是块中的数据,没有长度、类型和 CRC。
m_length 又只是该块给定的长度。
输入也是纯 RGB,压缩模式 0,过滤模式 0 和隔行模式 0。
CM 是 8。
CMINFO 是 112。
FCHECK 为 30。
FDICT 为 0。
FLEVEL 为 64。
TL;DR: 究竟 zlib 中的 inflate 函数想要/需要什么?
这也是我正在尝试读取的图像的十六进制值的图片。 picture link because stackoverflow doesn't allow new users to post pics
【问题讨论】:
-
该文本图片是否显示了您尝试解压缩的确切起点?它从其他一些未压缩的数据块开始。
-
@usr2564301 啊,我的错,这是全图link
标签: c++ binary png zlib inflate