Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decompressing deflated TIFF data

I have this code:

ifstream istream;
std::string line;
TIFHEAD header;
istream.open("pic.tif",ios::binary|ios::in);
istream.read((char*)&header, sizeof(TIFHEAD));
cout<<hex<<header.Identifier<<" "<<header.Version<<" "<<header.IFDOffset<<endl<<endl;
istream.seekg(header.IFDOffset);

WORD numEntries1;
istream.read((char *)&numEntries1, sizeof(WORD));
cout<<numEntries1<<endl;

DWORD tagOffset;
DWORD stripByte;

for(int i=0; i<numEntries1; i++) {
    TIFTAG tag;
    istream.read((char *)&tag, sizeof(TIFTAG));
    cout<<istream.tellg()<<":"<<tag.TagId<<" "<<tag.DataType<<" "<<tag.DataCount<<" "<<tag.DataOffset<<endl;
}

I also did a hexdump on pic.tif, and got about 450 lines of hex values, many of which were reflected by the tag data and header I'm printing out.

But I found that this TIFF has compression 32946, which is COMPRESSION_DEFLATE.

How can I uncompress the other hex values from the hexdump to get the actual float values from this TIFF? I know Zlib can decompress, but can it decompress deflate compression, and if so, how?

I know what the float values should be through LibTIFF, but can't use that.It's a 512x512 32 bit tiff which has float values.

Also, I can post more info about the TIFF or values from hexdump if anyone wants to see it.


1 Answers

Each segment is a standard zlib stream, i.e. deflate-compressed data with a zlib header and trailer. You can use zlib's uncompress() or inflateInit() / inflate() / inflateEnd() functions.

like image 170
Mark Adler Avatar answered Feb 27 '26 01:02

Mark Adler