Mercurial > hg > dmlib
comparison src/libgfx.c @ 1299:b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 19 Aug 2017 03:40:49 +0300 |
parents | f0d6aac3adc4 |
children | fd442faa705f |
comparison
equal
deleted
inserted
replaced
1298:f0d6aac3adc4 | 1299:b0c0be4c76f9 |
---|---|
1098 res = dmError(DMERR_NOT_SUPPORTED, | 1098 res = dmError(DMERR_NOT_SUPPORTED, |
1099 "PCX: Not a PCX file, or unsupported variant.\n"); | 1099 "PCX: Not a PCX file, or unsupported variant.\n"); |
1100 goto error; | 1100 goto error; |
1101 } | 1101 } |
1102 | 1102 |
1103 if (hdr.nplanes == 4 && hdr.bitsPerPlane == 4) | |
1104 { | |
1105 dmMsg(2, | |
1106 "PCX: Probably invalid combination of nplanes and bpp, attempting to fix ..\n"); | |
1107 | |
1108 hdr.bitsPerPlane = 1; | |
1109 } | |
1110 | |
1103 isPaletted = (hdr.bitsPerPlane * hdr.nplanes) <= 8; | 1111 isPaletted = (hdr.bitsPerPlane * hdr.nplanes) <= 8; |
1104 | 1112 |
1105 dmMsg(2, | 1113 dmMsg(2, |
1106 "PCX: xmin=%d, ymin=%d, xmax=%d, ymax=%d, res=%dx%d, scr=%dx%d\n", | 1114 "PCX: xmin=%d, ymin=%d, xmax=%d, ymax=%d, res=%dx%d, scr=%dx%d\n", |
1107 hdr.xmin, hdr.ymin, hdr.xmax, hdr.ymax, | 1115 hdr.xmin, hdr.ymin, hdr.xmax, hdr.ymax, |
1128 } | 1136 } |
1129 | 1137 |
1130 // Allocate image | 1138 // Allocate image |
1131 if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1, | 1139 if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1, |
1132 isPaletted ? DM_IFMT_PALETTE : DM_IFMT_RGBA, | 1140 isPaletted ? DM_IFMT_PALETTE : DM_IFMT_RGBA, |
1133 isPaletted ? (hdr.bitsPerPlane * hdr.nplanes) : -1)) == NULL) | 1141 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp |
1142 // isPaletted ? (hdr.bitsPerPlane * hdr.nplanes) : -1 | |
1143 -1 | |
1144 )) == NULL) | |
1134 { | 1145 { |
1135 res = dmError(DMERR_MALLOC, | 1146 res = dmError(DMERR_MALLOC, |
1136 "PCX: Could not allocate image structure.\n"); | 1147 "PCX: Could not allocate image structure.\n"); |
1137 goto error; | 1148 goto error; |
1138 } | 1149 } |
1151 { | 1162 { |
1152 res = dmError(DMERR_MALLOC, | 1163 res = dmError(DMERR_MALLOC, |
1153 "PCX: Could not allocate RLE buffer.\n"); | 1164 "PCX: Could not allocate RLE buffer.\n"); |
1154 goto error; | 1165 goto error; |
1155 } | 1166 } |
1167 | |
1168 dmMsg(2, | |
1169 "PCX: bufLen=%d\n", | |
1170 pcx.bufLen); | |
1156 | 1171 |
1157 // Read image data | 1172 // Read image data |
1158 Uint8 *dp = img->data; | 1173 Uint8 *dp = img->data; |
1159 for (int yc = 0; yc < img->height; yc++) | 1174 for (int yc = 0; yc < img->height; yc++) |
1160 { | 1175 { |
1194 { | 1209 { |
1195 Uint8 *sptr = pcx.buf + (hdr.bpl * nplane); | 1210 Uint8 *sptr = pcx.buf + (hdr.bpl * nplane); |
1196 | 1211 |
1197 for (int xc = 0; xc < img->width; xc++) | 1212 for (int xc = 0; xc < img->width; xc++) |
1198 { | 1213 { |
1199 const int qx = xc * 2; | 1214 const int px = 7 - (xc & 7); |
1200 const int px = 7 - (qx & 7); | 1215 dp[xc] |= ((sptr[xc / 8] & (1 << px)) >> px) << nplane; |
1201 dp[xc] |= (sptr[qx / 8] & (1 << px)) >> (px - nplane); | |
1202 } | 1216 } |
1203 } | 1217 } |
1204 break; | 1218 break; |
1205 | 1219 |
1206 default: | 1220 default: |
1221 BOOL read; | 1235 BOOL read; |
1222 | 1236 |
1223 if (!dm_fread_byte(fp, &tmpb) || tmpb != 0x0C) | 1237 if (!dm_fread_byte(fp, &tmpb) || tmpb != 0x0C) |
1224 { | 1238 { |
1225 read = FALSE; | 1239 read = FALSE; |
1226 ncolors = 256; // KLUDGE | 1240 ncolors = DMPCX_PAL_COLORS; |
1227 } | 1241 } |
1228 else | 1242 else |
1229 { | 1243 { |
1230 read = TRUE; | 1244 read = TRUE; |
1231 ncolors = 256; | 1245 ncolors = 256; |