-void LoadPCXBuff(byte* buffer, std::size_t len, byte **pic, byte **palette, int *width, int *height )
-{
- *pic = 0;
-
- pcx_t pcx;
- int x, y, lsize;
- byte *out, *pix;
-
- /* parse the PCX file */
-
- PointerInputStream inputStream(buffer);
-
- pcx.manufacturer = istream_read_byte(inputStream);
- pcx.version = istream_read_byte(inputStream);
- pcx.encoding = istream_read_byte(inputStream);
- pcx.bits_per_pixel = istream_read_byte(inputStream);
- pcx.xmin = istream_read_int16_le(inputStream);
- pcx.ymin = istream_read_int16_le(inputStream);
- pcx.xmax = istream_read_int16_le(inputStream);
- pcx.ymax = istream_read_int16_le(inputStream);
- pcx.hres = istream_read_int16_le(inputStream);
- pcx.vres = istream_read_int16_le(inputStream);
- inputStream.read(pcx.palette, 48);
- pcx.reserved = istream_read_byte(inputStream);
- pcx.color_planes = istream_read_byte(inputStream);
- pcx.bytes_per_line = istream_read_int16_le(inputStream);
- pcx.palette_type = istream_read_int16_le(inputStream);
- inputStream.read(pcx.filler, 58);
-
-
- if (pcx.manufacturer != 0x0a
- || pcx.version != 5
- || pcx.encoding != 1
- || pcx.bits_per_pixel != 8)
- return;
-
- if (width)
- *width = pcx.xmax+1;
- if (height)
- *height = pcx.ymax+1;
-
- if (!pic)
- return;
-
- out = (byte *)malloc ( (pcx.ymax+1) * (pcx.xmax+1) );
-
- *pic = out;
- pix = out;
-
- /* RR2DO2: pcx fix */
- lsize = pcx.color_planes * pcx.bytes_per_line;
-
- /* go scanline by scanline */
- for( y = 0; y <= pcx.ymax; y++, pix += pcx.xmax + 1 )
- {
- /* do a scanline */
- for( x=0; x <= pcx.xmax; )
- {
- /* RR2DO2 */
- PCXRLEPacket packet;
- ByteStream_readPCXRLEPacket(inputStream, packet);
-
- while(packet.length-- > 0)
- {
- pix[ x++ ] = packet.data;
- }
- }
-
- /* RR2DO2: discard any other data */
- PCXRLEPacket packet;
- while( x < lsize )
- {
- ByteStream_readPCXRLEPacket(inputStream, packet);
- x++;
- }
- while( packet.length-- > 0 )
- {
- x++;
- }
- }
-
- /* validity check */
- if( std::size_t(inputStream.get() - buffer) > len)
- {
- *pic = 0;
- }
-
- if (palette)
- {
- *palette = (byte *)malloc(768);
- memcpy (*palette, buffer + len - 768, 768);
- }
+void LoadPCXBuff( byte* buffer, std::size_t len, byte **pic, byte **palette, int *width, int *height ){
+ *pic = 0;
+
+ pcx_t pcx;
+ int x, y, lsize;
+ byte *out, *pix;
+
+ /* parse the PCX file */
+
+ PointerInputStream inputStream( buffer );
+
+ pcx.manufacturer = istream_read_byte( inputStream );
+ pcx.version = istream_read_byte( inputStream );
+ pcx.encoding = istream_read_byte( inputStream );
+ pcx.bits_per_pixel = istream_read_byte( inputStream );
+ pcx.xmin = istream_read_int16_le( inputStream );
+ pcx.ymin = istream_read_int16_le( inputStream );
+ pcx.xmax = istream_read_int16_le( inputStream );
+ pcx.ymax = istream_read_int16_le( inputStream );
+ pcx.hres = istream_read_int16_le( inputStream );
+ pcx.vres = istream_read_int16_le( inputStream );
+ inputStream.read( pcx.palette, 48 );
+ pcx.reserved = istream_read_byte( inputStream );
+ pcx.color_planes = istream_read_byte( inputStream );
+ pcx.bytes_per_line = istream_read_int16_le( inputStream );
+ pcx.palette_type = istream_read_int16_le( inputStream );
+ inputStream.read( pcx.filler, 58 );
+
+
+ if ( pcx.manufacturer != 0x0a
+ || pcx.version != 5
+ || pcx.encoding != 1
+ || pcx.bits_per_pixel != 8 ) {
+ return;
+ }
+
+ if ( width ) {
+ *width = pcx.xmax + 1;
+ }
+ if ( height ) {
+ *height = pcx.ymax + 1;
+ }
+
+ if ( !pic ) {
+ return;
+ }
+
+ out = (byte *)malloc( ( pcx.ymax + 1 ) * ( pcx.xmax + 1 ) );
+
+ *pic = out;
+ pix = out;
+
+ /* RR2DO2: pcx fix */
+ lsize = pcx.color_planes * pcx.bytes_per_line;
+
+ /* go scanline by scanline */
+ for ( y = 0; y <= pcx.ymax; y++, pix += pcx.xmax + 1 )
+ {
+ /* do a scanline */
+ for ( x = 0; x <= pcx.xmax; )
+ {
+ /* RR2DO2 */
+ PCXRLEPacket packet;
+ ByteStream_readPCXRLEPacket( inputStream, packet );
+
+ while ( packet.length-- > 0 )
+ {
+ pix[ x++ ] = packet.data;
+ }
+ }
+
+ /* RR2DO2: discard any other data */
+ PCXRLEPacket packet;
+ while ( x < lsize )
+ {
+ ByteStream_readPCXRLEPacket( inputStream, packet );
+ x++;
+ }
+ while ( packet.length-- > 0 )
+ {
+ x++;
+ }
+ }
+
+ /* validity check */
+ if ( std::size_t( inputStream.get() - buffer ) > len ) {
+ *pic = 0;
+ }
+
+ if ( palette ) {
+ *palette = (byte *)malloc( 768 );
+ memcpy( *palette, buffer + len - 768, 768 );
+ }