0

I have trouble unzipping with zlib and Qt. I have video-data submitted by Asterix Cat 240 protocol (radar video transmission data) which should be compressed with zlib. I stored the data inside a QByteArray and tried to extract it like that:

QByteArray compressedRawVideoDataBlock;
QByteArray rawVideoDataBlock;
QVector <QVector <quint8>> videoDataBlock;
//Video Data
resize(rawAsterix.videoDataBlockREP);
for(int r = 0; r<videoDataBlockREP; r++)//index of Video Block
{
    for(int b = 0; b<blockSize ; b++)//index of Video Byte
    {
        compressedRawVideoDataBlock.append(static_cast<quint8>(buffer->at(i)));
        videoDataBlock[r].append(static_cast<quint8>(buffer->at(i)));
        i++;
    }
}
qDebug() << gzipDecompress(compressedRawVideoDataBlock, rawVideoDataBlock);

For extracting, I tried this function (Zlib QCompressor) but it always returns false and I am not sure why.

Example Data:

videoDataBlockREP=1
blockSize=64
compressedRawVideoDataBlock.toHex() = 7801edd0010d000000c2a0f74f6d0e37884061c0800103060c183060c0800103060c183060c0800103060c183060c0800103060cbc0f0c200000010000000000
Community
  • 1
  • 1
honiahaka10
  • 772
  • 4
  • 9
  • 29

1 Answers1

2

Because you are trying to decompress a zlib stream with a gzip decompressor. Those are two different things. If you change the second argument of inflateInit2 to 15 (instead of 15 + 16), then it should work.

Also you have five extraneous zero bytes after the end of the zlib stream. That would not cause a failure, but those five bytes would remain unused.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • Thank you that seems to work! Of course I cannot tell really for now but at least the data now seems to make sense. Whate does the `+16` do in that code? Do you may have a link or something where I can understand what the code does in detail? The extraneous zero bytes are filled by Asterix protocol so I always have the same blocksize regardles of how much rangecells I get from the radar. – honiahaka10 Apr 06 '16 at 13:21
  • 2
    The `+16` is an options that tells `inflate()` to decode a gzip wrapper instead of a zlib wrapper. It is documented, not surprisingly, in the [zlib documentation](http://www.zlib.net/manual.html). – Mark Adler Apr 06 '16 at 14:31