Mercurial > hg > dmlib
comparison src/libgfx.c @ 1296:228cab109c6a
More work on PCX reader.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 19 Aug 2017 01:32:46 +0300 |
parents | 7a986f33895e |
children | 5bd64397453b |
comparison
equal
deleted
inserted
replaced
1295:7a986f33895e | 1296:228cab109c6a |
---|---|
1169 { | 1169 { |
1170 res = dmError(DMERR_INVALID_DATA, | 1170 res = dmError(DMERR_INVALID_DATA, |
1171 "PCX: Error decoding RLE compressed data.\n"); | 1171 "PCX: Error decoding RLE compressed data.\n"); |
1172 goto error; | 1172 goto error; |
1173 } | 1173 } |
1174 | 1174 |
1175 // Decode bitplanes | 1175 // Decode bitplanes |
1176 switch (hdr.bitsPerPlane) | 1176 switch (hdr.bitsPerPlane) |
1177 { | 1177 { |
1178 case 32: | |
1179 case 24: | |
1180 case 16: | |
1178 case 8: | 1181 case 8: |
1179 { | 1182 { |
1180 // Actually bytes and bits per plane per pixel .. | 1183 // Actually bytes and bits per plane per pixel .. |
1181 const int bytesPerPlane = hdr.bitsPerPlane / 8; | 1184 const int bytesPerPlane = hdr.bitsPerPlane / 8; |
1182 | 1185 |
1188 memcpy(dptr, sptr, img->width * bytesPerPlane); | 1191 memcpy(dptr, sptr, img->width * bytesPerPlane); |
1189 } | 1192 } |
1190 } | 1193 } |
1191 break; | 1194 break; |
1192 | 1195 |
1193 /* | |
1194 case 1: | 1196 case 1: |
1197 memset(dp, 0, img->width); | |
1198 | |
1195 for (int nplane = 0; nplane < hdr.nplanes; nplane++) | 1199 for (int nplane = 0; nplane < hdr.nplanes; nplane++) |
1196 { | 1200 { |
1197 Uint8 *dptr = dp, | 1201 Uint8 *sptr = pcx.buf + (hdr.bpl * nplane); |
1198 *sptr = pcx.buf + (hdr.bpl * nplane); | |
1199 | 1202 |
1200 for (int xc = 0; xc < img->width; xc++) | 1203 for (int xc = 0; xc < img->width; xc++) |
1204 { | |
1205 const int qx = xc * 2; | |
1206 const int px = 7 - (qx & 7); | |
1207 dp[xc] |= (sptr[qx / 8] & (1 << px)) >> (px - nplane); | |
1208 } | |
1201 } | 1209 } |
1202 break; | 1210 break; |
1203 */ | |
1204 | 1211 |
1205 default: | 1212 default: |
1206 res = dmError(DMERR_NOT_SUPPORTED, | 1213 res = dmError(DMERR_NOT_SUPPORTED, |
1207 "PCX: Unsupported number of bits per plane %d.\n", | 1214 "PCX: Unsupported number of bits per plane %d.\n", |
1208 hdr.bitsPerPlane); | 1215 hdr.bitsPerPlane); |
1220 BOOL read; | 1227 BOOL read; |
1221 | 1228 |
1222 if (!dm_fread_byte(fp, &tmpb) || tmpb != 0x0C) | 1229 if (!dm_fread_byte(fp, &tmpb) || tmpb != 0x0C) |
1223 { | 1230 { |
1224 read = FALSE; | 1231 read = FALSE; |
1225 ncolors = DMPCX_PAL_COLORS; | 1232 ncolors = 256; // KLUDGE |
1226 } | 1233 } |
1227 else | 1234 else |
1228 { | 1235 { |
1229 read = TRUE; | 1236 read = TRUE; |
1230 ncolors = 256; | 1237 ncolors = 256; |
1238 } | 1245 } |
1239 | 1246 |
1240 if (read) | 1247 if (read) |
1241 { | 1248 { |
1242 // Okay, attempt to read the palette data | 1249 // Okay, attempt to read the palette data |
1250 dmMsg(2, "PCX: Reading palette of %d colors\n", ncolors); | |
1243 if (!dmReadPaletteData(fp, img->pal, ncolors)) | 1251 if (!dmReadPaletteData(fp, img->pal, ncolors)) |
1244 { | 1252 { |
1245 res = dmError(DMERR_FREAD, | 1253 res = dmError(DMERR_FREAD, |
1246 "PCX: Error reading palette.\n"); | 1254 "PCX: Error reading palette.\n"); |
1247 goto error; | 1255 goto error; |
1249 } | 1257 } |
1250 else | 1258 else |
1251 { | 1259 { |
1252 // If the extra palette is not available, copy the colors from | 1260 // If the extra palette is not available, copy the colors from |
1253 // the header palette to our internal palette structure. | 1261 // the header palette to our internal palette structure. |
1262 dmMsg(2, "PCX: Initializing palette from header of %d colors\n", ncolors); | |
1254 for (int i = 0; i < (img->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->ncolors); i++) | 1263 for (int i = 0; i < (img->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->ncolors); i++) |
1255 { | 1264 { |
1256 img->pal[i].r = hdr.colorMap[i].r; | 1265 img->pal[i].r = hdr.colorMap[i].r; |
1257 img->pal[i].g = hdr.colorMap[i].g; | 1266 img->pal[i].g = hdr.colorMap[i].g; |
1258 img->pal[i].b = hdr.colorMap[i].b; | 1267 img->pal[i].b = hdr.colorMap[i].b; |