Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed bug #827
Sam Lantinga - Sun Oct  4 13:12:54 PDT 2009
 * Added support for uncompressed PCX files
  • Loading branch information
slouken committed Oct 4, 2009
1 parent 6c072c8 commit 3cdaff6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGES
@@ -1,4 +1,6 @@
1.2.8:
Sam Lantinga - Sun Oct 4 13:12:54 PDT 2009
* Added support for uncompressed PCX files
Mason Wheeler - 2009-06-10 06:29:45 PDT
* Added IMG_Init()/IMG_Quit() to prevent constantly loading and unloading DLLs
Couriersud - Mon, 12 Jan 2009 17:21:13 -0800
Expand Down
38 changes: 25 additions & 13 deletions IMG_pcx.c
Expand Up @@ -66,6 +66,7 @@ int IMG_isPCX(SDL_RWops *src)
int is_PCX;
const int ZSoft_Manufacturer = 10;
const int PC_Paintbrush_Version = 5;
const int PCX_Uncompressed_Encoding = 0;
const int PCX_RunLength_Encoding = 1;
struct PCXheader pcxh;

Expand All @@ -76,7 +77,8 @@ int IMG_isPCX(SDL_RWops *src)
if ( SDL_RWread(src, &pcxh, sizeof(pcxh), 1) == 1 ) {
if ( (pcxh.Manufacturer == ZSoft_Manufacturer) &&
(pcxh.Version == PC_Paintbrush_Version) &&
(pcxh.Encoding == PCX_RunLength_Encoding) ) {
(pcxh.Encoding == PCX_RunLength_Encoding ||
pcxh.Encoding == PCX_Uncompressed_Encoding) ) {
is_PCX = 1;
}
}
Expand Down Expand Up @@ -145,30 +147,40 @@ SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src)
goto done;

bpl = pcxh.NPlanes * pcxh.BytesPerLine;
if (bpl > surface->pitch) {
error = "bytes per line is too large (corrupt?)";
}
buf = malloc(bpl);
row = surface->pixels;
for ( y=0; y<surface->h; ++y ) {
/* decode a scan line to a temporary buffer first */
int i, count = 0;
Uint8 ch;
Uint8 *dst = (src_bits == 8) ? row : buf;
for(i = 0; i < bpl; i++) {
if(!count) {
if(!SDL_RWread(src, &ch, 1, 1)) {
error = "file truncated";
goto done;
}
if( (ch & 0xc0) == 0xc0) {
count = ch & 0x3f;
if ( pcxh.Encoding == 0 ) {
if(!SDL_RWread(src, dst, bpl, 1)) {
error = "file truncated";
goto done;
}
} else {
for(i = 0; i < bpl; i++) {
if(!count) {
if(!SDL_RWread(src, &ch, 1, 1)) {
error = "file truncated";
goto done;
}
} else
count = 1;
if( (ch & 0xc0) == 0xc0) {
count = ch & 0x3f;
if(!SDL_RWread(src, &ch, 1, 1)) {
error = "file truncated";
goto done;
}
} else
count = 1;
}
dst[i] = ch;
count--;
}
dst[i] = ch;
count--;
}

if(src_bits <= 4) {
Expand Down

0 comments on commit 3cdaff6

Please sign in to comment.