# HG changeset patch # User Matti Hamalainen # Date 1503054488 -10800 # Node ID e4bda4909d72fe6191ae8efc6ac92dadda41e8e6 # Parent 28be63226b054d254fd57a13ccda33485db0faf9 Make libgfx error mode a global variable, at least for now. diff -r 28be63226b05 -r e4bda4909d72 src/libgfx.c --- a/src/libgfx.c Fri Aug 18 03:09:26 2017 +0300 +++ b/src/libgfx.c Fri Aug 18 14:08:08 2017 +0300 @@ -15,6 +15,10 @@ #endif +int dmGFXErrorMode = DM_ERRMODE_FAIL; + + + BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, BOOL alpha) { if (c1->r == c2->r && @@ -950,7 +954,7 @@ } -static BOOL dmPCXDecodeRLERow(FILE *fp, Uint8 *buf, const size_t bufLen, const int errorMode) +static BOOL dmPCXDecodeRLERow(FILE *fp, Uint8 *buf, const size_t bufLen) { size_t offs = 0; do @@ -967,19 +971,20 @@ count = data & 0x3F; if (count == 0) { - switch (errorMode) + switch (dmGFXErrorMode) { - case 1: + case DM_ERRMODE_RECOV_1: // Use as literal skip = TRUE; count = 1; break; - case 2: + case DM_ERRMODE_RECOV_2: // Ignore completely skip = TRUE; break; + case DM_ERRMODE_FAIL: default: // Error out on "invalid" data return FALSE; @@ -996,7 +1001,7 @@ buf[offs++] = data; // Check for remaining output count, error out if we wish to - if (count > 0 && errorMode != 0) + if (count > 0 && dmGFXErrorMode == DM_ERRMODE_FAIL) return FALSE; } while (offs < bufLen); @@ -1074,6 +1079,9 @@ goto error; } + dmMsg(3, "PCX: nplanes=%d, bpp=%d, bpl=%d\n", + hdr.nplanes, hdr.bitsPerPlane, hdr.bpl); + // Allocate image if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1)) == NULL) { @@ -1103,7 +1111,7 @@ for (int yc = 0; yc < img->height; yc++) { // Decode row of RLE'd data - if (!dmPCXDecodeRLERow(fp, pcx.buf, pcx.bufLen, 0)) + if (!dmPCXDecodeRLERow(fp, pcx.buf, pcx.bufLen)) { res = dmError(DMERR_INVALID_DATA, "PCX: Error decoding RLE compressed data.\n"); @@ -1137,7 +1145,7 @@ */ default: - res = dmError(DMERR_INVALID_DATA, + res = dmError(DMERR_NOT_SUPPORTED, "PCX: Unsupported number of bits per plane %d.\n", hdr.bitsPerPlane); goto error; diff -r 28be63226b05 -r e4bda4909d72 src/libgfx.h --- a/src/libgfx.h Fri Aug 18 03:09:26 2017 +0300 +++ b/src/libgfx.h Fri Aug 18 14:08:08 2017 +0300 @@ -38,6 +38,14 @@ }; +enum +{ + DM_ERRMODE_FAIL = 0, + DM_ERRMODE_RECOV_1, + DM_ERRMODE_RECOV_2, +}; + + // Bitmapped image struct (can be one of types specified by DM_IFMT_*) typedef struct { @@ -78,6 +86,7 @@ extern DMImageFormat dmImageFormatList[IMGFMT_LAST]; +extern int dmGFXErrorMode; DMImage * dmImageAlloc(int width, int height);