Mercurial > hg > dmlib
comparison src/libgfx.c @ 1285:e4bda4909d72
Make libgfx error mode a global variable, at least for now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 18 Aug 2017 14:08:08 +0300 |
parents | 28be63226b05 |
children | b812fad6f33e |
comparison
equal
deleted
inserted
replaced
1284:28be63226b05 | 1285:e4bda4909d72 |
---|---|
11 #include "dmbstr.h" | 11 #include "dmbstr.h" |
12 | 12 |
13 #ifdef DM_USE_LIBPNG | 13 #ifdef DM_USE_LIBPNG |
14 #include <png.h> | 14 #include <png.h> |
15 #endif | 15 #endif |
16 | |
17 | |
18 int dmGFXErrorMode = DM_ERRMODE_FAIL; | |
19 | |
16 | 20 |
17 | 21 |
18 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, BOOL alpha) | 22 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, BOOL alpha) |
19 { | 23 { |
20 if (c1->r == c2->r && | 24 if (c1->r == c2->r && |
948 fclose(fp); | 952 fclose(fp); |
949 return res; | 953 return res; |
950 } | 954 } |
951 | 955 |
952 | 956 |
953 static BOOL dmPCXDecodeRLERow(FILE *fp, Uint8 *buf, const size_t bufLen, const int errorMode) | 957 static BOOL dmPCXDecodeRLERow(FILE *fp, Uint8 *buf, const size_t bufLen) |
954 { | 958 { |
955 size_t offs = 0; | 959 size_t offs = 0; |
956 do | 960 do |
957 { | 961 { |
958 int count; | 962 int count; |
965 { | 969 { |
966 BOOL skip = FALSE; | 970 BOOL skip = FALSE; |
967 count = data & 0x3F; | 971 count = data & 0x3F; |
968 if (count == 0) | 972 if (count == 0) |
969 { | 973 { |
970 switch (errorMode) | 974 switch (dmGFXErrorMode) |
971 { | 975 { |
972 case 1: | 976 case DM_ERRMODE_RECOV_1: |
973 // Use as literal | 977 // Use as literal |
974 skip = TRUE; | 978 skip = TRUE; |
975 count = 1; | 979 count = 1; |
976 break; | 980 break; |
977 | 981 |
978 case 2: | 982 case DM_ERRMODE_RECOV_2: |
979 // Ignore completely | 983 // Ignore completely |
980 skip = TRUE; | 984 skip = TRUE; |
981 break; | 985 break; |
982 | 986 |
987 case DM_ERRMODE_FAIL: | |
983 default: | 988 default: |
984 // Error out on "invalid" data | 989 // Error out on "invalid" data |
985 return FALSE; | 990 return FALSE; |
986 } | 991 } |
987 } | 992 } |
994 | 999 |
995 while (count-- && offs < bufLen) | 1000 while (count-- && offs < bufLen) |
996 buf[offs++] = data; | 1001 buf[offs++] = data; |
997 | 1002 |
998 // Check for remaining output count, error out if we wish to | 1003 // Check for remaining output count, error out if we wish to |
999 if (count > 0 && errorMode != 0) | 1004 if (count > 0 && dmGFXErrorMode == DM_ERRMODE_FAIL) |
1000 return FALSE; | 1005 return FALSE; |
1001 | 1006 |
1002 } while (offs < bufLen); | 1007 } while (offs < bufLen); |
1003 | 1008 |
1004 return TRUE; | 1009 return TRUE; |
1072 "PCX: Unsupported number of bitplanes %d.\n", | 1077 "PCX: Unsupported number of bitplanes %d.\n", |
1073 hdr.nplanes); | 1078 hdr.nplanes); |
1074 goto error; | 1079 goto error; |
1075 } | 1080 } |
1076 | 1081 |
1082 dmMsg(3, "PCX: nplanes=%d, bpp=%d, bpl=%d\n", | |
1083 hdr.nplanes, hdr.bitsPerPlane, hdr.bpl); | |
1084 | |
1077 // Allocate image | 1085 // Allocate image |
1078 if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1)) == NULL) | 1086 if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1)) == NULL) |
1079 { | 1087 { |
1080 res = dmError(DMERR_MALLOC, | 1088 res = dmError(DMERR_MALLOC, |
1081 "PCX: Could not allocate image structure.\n"); | 1089 "PCX: Could not allocate image structure.\n"); |
1101 // Read image data | 1109 // Read image data |
1102 Uint8 *dp = img->data; | 1110 Uint8 *dp = img->data; |
1103 for (int yc = 0; yc < img->height; yc++) | 1111 for (int yc = 0; yc < img->height; yc++) |
1104 { | 1112 { |
1105 // Decode row of RLE'd data | 1113 // Decode row of RLE'd data |
1106 if (!dmPCXDecodeRLERow(fp, pcx.buf, pcx.bufLen, 0)) | 1114 if (!dmPCXDecodeRLERow(fp, pcx.buf, pcx.bufLen)) |
1107 { | 1115 { |
1108 res = dmError(DMERR_INVALID_DATA, | 1116 res = dmError(DMERR_INVALID_DATA, |
1109 "PCX: Error decoding RLE compressed data.\n"); | 1117 "PCX: Error decoding RLE compressed data.\n"); |
1110 goto error; | 1118 goto error; |
1111 } | 1119 } |
1135 } | 1143 } |
1136 break; | 1144 break; |
1137 */ | 1145 */ |
1138 | 1146 |
1139 default: | 1147 default: |
1140 res = dmError(DMERR_INVALID_DATA, | 1148 res = dmError(DMERR_NOT_SUPPORTED, |
1141 "PCX: Unsupported number of bits per plane %d.\n", | 1149 "PCX: Unsupported number of bits per plane %d.\n", |
1142 hdr.bitsPerPlane); | 1150 hdr.bitsPerPlane); |
1143 goto error; | 1151 goto error; |
1144 } | 1152 } |
1145 | 1153 |