tags:

views:

249

answers:

3

I have a big binary file with lots of files stored inside it. I'm trying to copy the data of a PCX image from the file and write it to a new file which I can then open in an image editor.

After obtaining the specs for the header of a PCX file I think that I've located the image in the big binary file. My problem is that I cannot figure out how many bytes I'm supposed to read after the header. I read about decoding PCX files, but I don't want to decode anything. I want to read the encoded image data and write that to a seperate file so the image editor can open in.

Here is the header. I've included the values of the image as I guess they can be used to determine the "end-of-file" for the image data.

struct PcxHeader
{
BYTE Identifier;        // PCX Id Number (Always 0x0A) // 10  
BYTE Version;           // Version Number    // 5  
BYTE Encoding;          // Encoding Format    // 1  
BYTE BitsPerPixel;      // Bits per Pixel    // 8  
WORD XStart;            // Left of image     // 0  
WORD YStart;            // Top of Image     // 0  
WORD XEnd;              // Right of Image    // 319  
WORD YEnd;              // Bottom of image    // 199  
WORD HorzRes;           // Horizontal Resolution   // 320  
WORD VertRes;           // Vertical Resolution   // 200  
BYTE Palette[48];       // 16-Color EGA Palette    
BYTE Reserved1;         // Reserved (Always 0)  
BYTE NumBitPlanes;      // Number of Bit Planes   // 1  
WORD BytesPerLine;      // Bytes per Scan-line   // 320  
WORD PaletteType;       // Palette Type     // 0  
WORD HorzScreenSize;    // Horizontal Screen Size   // 0  
WORD VertScreenSize;    // Vertical Screen Size   // 0  
BYTE Reserved2[54];     // Reserved (Always 0)
};
A: 

Without knowing much about the PCX file format, I can take a best guess at this:

 bytesAfterHeader = header.BytesPerLine * header.VertRes;
Ron Warholic
This is my reference for the PCX file format. http://www.fileformat.info/format/pcx/egff.htm
links77
+2  A: 

There are three components to the PCX file format:

  • 128-byte header (though less are actually used, it is 128 bytes long)
  • variable-length image data
  • optional 256 color palette (though improper PCX files exist with palette sizes other than 256 colors).

From the Wikipedia artice:

Due to the PCX compression scheme the only way to find the actual length of the image data is to read and process it. This effort is made difficult because the format allows for the compressed data to run beyond the image dimensions, often padding it to the next 8 or 16 line boundary.

In general, then, it sound like you'll have to do a "deep process" of the image data to find the complete PCX file embedded within your larger binary file.

fbrereto
So by processing you mean I have to decode it?
links77
It doesn't have to be fully decoded. For instance if you're reading the image data and you know the next 42 bytes are pixels you can skip over them without decoding them, knowing that your overall goal is to simply get to the end of the image data.
fbrereto
A: 

I'm writing a small app that opens and reading PCX files of different bit depths. If you are still interested in processing .PCX file drop me a line on [email protected] and I can send you the work i've done already.

Milton