C ++ library for reading data with raw file stream supporting endian?

I have source data streams from image files, for example:

vector<char> rawData(fileSize); ifstream inFile("image.jpg"); inFile.read(&rawData[0]); 

I want to analyze the headers of different image formats in height and width. Is there a portable library that can read ints, longs, shorts, etc. From buffer / stream converting to endianess as indicated?

I would like to do something like: short x = rawData.readLeShort(offset); or long y = rawData.readBeLong(offset)

An even better option would be a lightweight and portable image metadata library (without the extra weight of an image manipulation library) that can handle raw images. I found that Exif libraries there do not support png and gif .

+6
c ++ image endianness filestream metadata
source share
1 answer

This is not so difficult to do yourself. Here's how you can read a 32-bit number in 32-bit format:

 unsigned char buffer[4]; inFile.read(buffer, sizeof(buffer)); unsigned int number = buffer[0] + (buffer[1] << 8) + (buffer[2] << 16) + (buffer[3] << 24); 

and read the 32 bit big end number:

 unsigned char buffer[4]; inFile.read(buffer, sizeof(buffer)); unsigned int number = buffer[3] + (buffer[2] << 8) + (buffer[1] << 16) + (buffer[0] << 24); 
0
source share

All Articles