S
S
S0meb0dy N0b0dy2014-03-25 14:04:40
C++ / C#
S0meb0dy N0b0dy, 2014-03-25 14:04:40

File format specifications, how to work with them?

It is not necessary to yell strongly in the answers how to work with file specifications in C ++?
Knowledge of the language is available, there is no understanding of the specifications.
Give useful tutorials; references; sample codes, etc.
doc; pdf; rtf seems to be clear; I'm more interested in graphics.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fat Lorrie, 2014-03-25
@galexcode

We have a raw stream of bytes, with the help of the specifications and the structures described, we can determine where (with what offset and how much in size) and how to pull out the data.
For example, a BMP file consists of a file header, 14 bytes long ( BITMAPFILEHEADER type ), it describes the file size, its type (signature), etc..

typedef struct tagBITMAPFILEHEADER {
  WORD bfType; 
  DWORD bfSize; 
  WORD bfReserved1; 
  WORD bfReserved2; 
  DWORD bfOffBits; 
} BITMAPFILEHEADER;

followed by the header of the image itself BITMAPINFO containing BITMAPINFOHEADER , which directly stores the image parameters (width-height, color depth, compression features, etc.)
typedef struct tagBITMAPINFO {
  BITMAPINFOHEADER bmiHeader; // тип описан далее
  RGBQUAD          bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;

typedef struct tagBITMAPINFOHEADER {
  DWORD biSize;
  LONG  biWidth;
  LONG  biHeight;
  WORD  biPlanes;
  WORD  biBitCount;
  DWORD biCompression;
  DWORD biSizeImage;
  LONG  biXPelsPerMeter;
  LONG  biYPelsPerMeter;
  DWORD biClrUsed;
  DWORD biClrImportant;
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;

And, in fact, the image data is located starting from BITMAPFILEHEADER.bfOffBits, alternating along the color channels, aligned along the memory boundaries, etc. For example, this is described on the wiki .

G
GavriKos, 2014-03-25
@GavriKos

What for? More precisely, so - is there any point in reinventing the wheel? If you need to be able to open a file of a certain format, then it is better to look for a ready-made solution for it. For graphics - ImageLib for example. Save a ton of nerve cells.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question