- // Up to 63 bytes with the same value can be stored using a
- // single { cont, value } pair.
+ // Up to 63 bytes with the same value can be stored using
+ // a single { cont, value } pair.
// end of each plane inside a scanline). Only use this function
// to read one or more _complete_ scanlines. Else, more than
// 'size' bytes might be read and the buffer might overflow.
// end of each plane inside a scanline). Only use this function
// to read one or more _complete_ scanlines. Else, more than
// 'size' bytes might be read and the buffer might overflow.
// If ((data & 0xC0) != 0xC0), then the value read is a data
// byte. Else, it is a counter (cont = val & 0x3F) and the
// next byte is the data byte.
// If ((data & 0xC0) != 0xC0), then the value read is a data
// byte. Else, it is a counter (cont = val & 0x3F) and the
// next byte is the data byte.
// Read PCX header and check the version number (it must
// be at least 5 or higher for 8 bit and 24 bit images).
// Read PCX header and check the version number (it must
// be at least 5 or higher for 8 bit and 24 bit images).
encoding = hdr[HDR_ENCODING];
nplanes = hdr[HDR_NPLANES];
bitsperpixel = hdr[HDR_BITSPERPIXEL];
encoding = hdr[HDR_ENCODING];
nplanes = hdr[HDR_NPLANES];
bitsperpixel = hdr[HDR_BITSPERPIXEL];
// Check image format. Currently supported formats are
// 8 bits (8 bpp, 1 plane) and 24 bits (8 bpp, 3 planes).
// Check image format. Currently supported formats are
// 8 bits (8 bpp, 1 plane) and 24 bits (8 bpp, 3 planes).
// Now start reading the file, line by line, and store
// the data in the format required by wxImage.
// Now start reading the file, line by line, and store
// the data in the format required by wxImage.
// For 8 bit images, we read the palette, and then do a second
// pass replacing indexes with their RGB values;
// For 8 bit images, we read the palette, and then do a second
// pass replacing indexes with their RGB values;
// SavePCX:
// Saves a PCX file into the wxImage object pointed by image.
// Returns wxPCX_OK on success, or an error code otherwise
// SavePCX:
// Saves a PCX file into the wxImage object pointed by image.
// Returns wxPCX_OK on success, or an error code otherwise
-// (see above for error codes). Currently, always saves images
-// in 24 bit format. XXX
+// (see above for error codes). Will try to save as 8-bit
+// PCX if possible, and then fall back to 24-bit if there
+// are more than 256 different colours.
// Get image dimensions, calculate bytesperline (must be even,
// according to PCX specs) and allocate space for one complete
// scanline.
// Get image dimensions, calculate bytesperline (must be even,
// according to PCX specs) and allocate space for one complete
// scanline.
// Build header data and write it to the stream. Initially,
// set all bytes to zero (most values default to zero).
// Build header data and write it to the stream. Initially,
// set all bytes to zero (most values default to zero).
memset(hdr, 0, sizeof(hdr));
hdr[HDR_MANUFACTURER] = 10;
memset(hdr, 0, sizeof(hdr));
hdr[HDR_MANUFACTURER] = 10;