Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 1947:8896d5676f1b
Architectural change: remove some duplicated variables from DMC64Image
structure and replace them with a pointer to DMC64ImageCommonFormat.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 29 Jun 2018 17:17:14 +0300 |
parents | d9a0a4bccf5d |
children | f8e2728c1b7f |
comparison
equal
deleted
inserted
replaced
1946:c30dfd5e3227 | 1947:8896d5676f1b |
---|---|
48 } | 48 } |
49 | 49 |
50 | 50 |
51 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent) | 51 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent) |
52 { | 52 { |
53 char typeStr[64], typeStr2[64]; | 53 char typeStr[64]; |
54 | |
55 dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE); | |
56 | 54 |
57 if (fmt != NULL) | 55 if (fmt != NULL) |
58 { | 56 { |
59 fprintf(fh, | 57 fprintf(fh, |
60 "%sFormat : %s [%s]\n", | 58 "%sFormat : %s [%s]\n", |
61 indent, fmt->name, fmt->fext); | 59 indent, fmt->name, fmt->fext); |
62 } | 60 } |
63 | 61 |
64 if (img != NULL) | 62 if (img != NULL) |
65 { | 63 { |
66 dmC64GetImageTypeString(typeStr2, sizeof(typeStr2), img->type, TRUE); | 64 dmC64GetImageTypeString(typeStr, sizeof(typeStr), img->fmt->type, TRUE); |
67 | 65 |
68 fprintf(fh, | 66 fprintf(fh, |
69 "%sType : %s [%s]\n" | 67 "%sType : %s\n" |
70 "%sBanks : %d\n", | 68 "%sBanks : %d\n", |
71 indent, typeStr, typeStr2, | 69 indent, typeStr, |
72 indent, img->nbanks); | 70 indent, img->nbanks); |
73 | 71 |
74 if (img->type & D64_FMT_ILACE) | 72 if (img->fmt->type & D64_FMT_ILACE) |
75 { | 73 { |
76 char *tmps; | 74 char *tmps; |
77 switch (img->laceType) | 75 switch (img->laceType) |
78 { | 76 { |
79 case D64_ILACE_COLOR: tmps = "color"; break; | 77 case D64_ILACE_COLOR: tmps = "color"; break; |
84 "%sInterlace type : %s\n", | 82 "%sInterlace type : %s\n", |
85 indent, tmps); | 83 indent, tmps); |
86 } | 84 } |
87 | 85 |
88 fprintf(fh, | 86 fprintf(fh, |
89 "%sWidth x Height : %d x %d [%d x %d]\n" | 87 "%sWidth x Height : %d x %d\n" |
90 "%sCHwidth x CHheight : %d x %d [%d x %d]\n", | 88 "%sCHwidth x CHheight : %d x %d\n", |
91 indent, img->width, img->height, | 89 indent, img->fmt->width, img->fmt->height, |
92 fmt->format->width, fmt->format->height, | 90 indent, img->fmt->chWidth, img->fmt->chHeight); |
93 indent, img->chWidth, img->chHeight, | |
94 fmt->format->chWidth, fmt->format->chHeight); | |
95 } | 91 } |
96 else | 92 else |
97 { | 93 if (fmt != NULL) |
94 { | |
95 dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE); | |
98 fprintf(fh, | 96 fprintf(fh, |
99 "%sType : %s\n" | 97 "%sType : %s\n" |
100 "%sWidth x Height : %d x %d\n" | 98 "%sWidth x Height : %d x %d\n" |
101 "%sCHwidth x CHheight : %d x %d\n", | 99 "%sCHwidth x CHheight : %d x %d\n", |
102 indent, typeStr, | 100 indent, typeStr, |
222 | 220 |
223 if (img == NULL) | 221 if (img == NULL) |
224 return NULL; | 222 return NULL; |
225 | 223 |
226 // Initialize image information | 224 // Initialize image information |
227 img->type = fmt->format->type; | 225 img->fmt = fmt->format; |
228 img->width = fmt->format->width; | |
229 img->height = fmt->format->height; | |
230 img->chWidth = fmt->format->chWidth; | |
231 img->chHeight = fmt->format->chHeight; | |
232 img->nbanks = dmC64ImageGetNumBanks(fmt); | 226 img->nbanks = dmC64ImageGetNumBanks(fmt); |
233 | 227 |
234 // Allocate banks | 228 // Allocate banks |
235 if ((img->color = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL || | 229 if ((img->color = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL || |
236 (img->bitmap = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL || | 230 (img->bitmap = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL || |
859 | 853 |
860 if (buf == NULL || buf->data == NULL || img == NULL || fmt == NULL) | 854 if (buf == NULL || buf->data == NULL || img == NULL || fmt == NULL) |
861 return DMERR_NULLPTR; | 855 return DMERR_NULLPTR; |
862 | 856 |
863 // Clear the image structure, set basics | 857 // Clear the image structure, set basics |
864 img->type = fmt->format->type; | |
865 img->width = fmt->format->width; | |
866 img->height = fmt->format->height; | |
867 img->chWidth = fmt->format->chWidth; | |
868 img->chHeight = fmt->format->chHeight; | |
869 img->nbanks = dmC64ImageGetNumBanks(fmt); | 858 img->nbanks = dmC64ImageGetNumBanks(fmt); |
870 | 859 |
871 // Perform decoding | 860 // Perform decoding |
872 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) | 861 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) |
873 { | 862 { |
1236 | 1225 |
1237 // Sanity check arguments | 1226 // Sanity check arguments |
1238 if (dst == NULL || src == NULL || fmt == NULL || spec == NULL) | 1227 if (dst == NULL || src == NULL || fmt == NULL || spec == NULL) |
1239 return DMERR_NULLPTR; | 1228 return DMERR_NULLPTR; |
1240 | 1229 |
1241 if (dst->width < src->width || dst->height < src->height) | 1230 if (dst->width != src->fmt->width || dst->height != src->fmt->height) |
1242 { | 1231 { |
1243 return dmError(DMERR_INVALID_DATA, | 1232 return dmError(DMERR_INVALID_DATA, |
1244 "Invalid src vs. dst width/height %d x %d <-> %d x %d\n", | 1233 "Invalid src vs. dst width/height %d x %d <-> %d x %d\n", |
1245 src->width, src->height, dst->width, dst->height); | 1234 src->fmt->width, src->fmt->height, dst->width, dst->height); |
1246 } | 1235 } |
1247 | 1236 |
1248 dmMemset(dst->data, 0, dst->size); | 1237 dmMemset(dst->data, 0, dst->size); |
1249 | 1238 |
1250 // Check pixel getter function | 1239 // Check pixel getter function |
1251 if (fmt->format->getPixel != NULL) | 1240 if (src->fmt->getPixel != NULL) |
1252 getPixel = fmt->format->getPixel; | 1241 getPixel = src->fmt->getPixel; |
1253 else | 1242 else |
1254 getPixel = (fmt->format->type & D64_FMT_MC) ? fmtGetGenericMCPixel : fmtGetGenericSCPixel; | 1243 getPixel = (src->fmt->type & D64_FMT_MC) ? fmtGetGenericMCPixel : fmtGetGenericSCPixel; |
1255 | 1244 |
1256 // Resolution interlaced pics need to halve the source width | 1245 // Resolution interlaced pics need to halve the source width |
1257 int rwidth = src->width; | 1246 int rwidth = dst->width, rheight = dst->height; |
1258 if ((src->type & D64_FMT_ILACE) && src->laceType == D64_ILACE_RES) | 1247 if ((src->fmt->type & D64_FMT_ILACE) && |
1248 src->laceType == D64_ILACE_RES) | |
1259 rwidth /= 2; | 1249 rwidth /= 2; |
1260 | 1250 |
1261 // Perform conversion | 1251 // Perform conversion |
1262 for (int yc = 0; yc < src->height; yc++) | 1252 for (int yc = 0; yc < rheight; yc++) |
1263 { | 1253 { |
1264 Uint8 *dp = dst->data + (yc * dst->pitch); | 1254 Uint8 *dp = dst->data + (yc * dst->pitch); |
1265 const int y = yc / 8, yb = yc & 7; | 1255 const int y = yc / 8, yb = yc & 7; |
1266 const int scroffsy = y * src->chWidth; | 1256 const int scroffsy = y * src->fmt->chWidth; |
1267 const int bmoffsy = y * src->chWidth * 8 + yb; | 1257 const int bmoffsy = y * src->fmt->chWidth * 8 + yb; |
1268 | 1258 |
1269 for (int xc = 0; xc < rwidth; xc++) | 1259 for (int xc = 0; xc < rwidth; xc++) |
1270 if (src->type & D64_FMT_CHAR) | 1260 if (src->fmt->type & D64_FMT_CHAR) |
1271 { | 1261 { |
1272 // Charmode conversion | 1262 // Charmode conversion |
1273 if ((src->type & D64_FMT_MC) == D64_FMT_HIRES) | 1263 if ((src->fmt->type & D64_FMT_MC) == D64_FMT_HIRES) |
1274 { | 1264 { |
1275 // Hi-res charmap | 1265 // Hi-res charmap |
1276 const int x = xc / 8; | 1266 const int x = xc / 8; |
1277 const int scroffs = scroffsy + x; | 1267 const int scroffs = scroffsy + x; |
1278 const int chr = src->screen[0].data[scroffs]; | 1268 const int chr = src->screen[0].data[scroffs]; |
1313 } | 1303 } |
1314 } | 1304 } |
1315 else | 1305 else |
1316 { | 1306 { |
1317 // Perform generic BITMAP conversion | 1307 // Perform generic BITMAP conversion |
1318 if ((src->type & D64_FMT_MC) == D64_FMT_HIRES) | 1308 if ((src->fmt->type & D64_FMT_MC) == D64_FMT_HIRES) |
1319 { | 1309 { |
1320 // Hi-res bitmap | 1310 // Hi-res bitmap |
1321 const int x = xc / 8; | 1311 const int x = xc / 8; |
1322 const int scroffs = scroffsy + x; | 1312 const int scroffs = scroffsy + x; |
1323 const int bmoffs = bmoffsy + (x * 8); | 1313 const int bmoffs = bmoffsy + (x * 8); |
1331 const int x = xc / 4; | 1321 const int x = xc / 4; |
1332 const int scroffs = scroffsy + x; | 1322 const int scroffs = scroffsy + x; |
1333 const int bmoffs = bmoffsy + (x * 8); | 1323 const int bmoffs = bmoffsy + (x * 8); |
1334 const int vshift = 6 - ((xc * 2) & 6); | 1324 const int vshift = 6 - ((xc * 2) & 6); |
1335 | 1325 |
1336 if (src->type & D64_FMT_ILACE) | 1326 if (src->fmt->type & D64_FMT_ILACE) |
1337 { | 1327 { |
1338 switch (src->laceType) | 1328 switch (src->laceType) |
1339 { | 1329 { |
1340 case D64_ILACE_RES: | 1330 case D64_ILACE_RES: |
1341 *dp++ = getPixel(src, bmoffs, scroffs, vshift, 0, xc, yc); | 1331 *dp++ = getPixel(src, bmoffs, scroffs, vshift, 0, xc, yc); |
1346 return DMERR_NOT_SUPPORTED; | 1336 return DMERR_NOT_SUPPORTED; |
1347 } | 1337 } |
1348 } | 1338 } |
1349 else | 1339 else |
1350 { | 1340 { |
1351 *dp++ = getPixel(src, bmoffs, scroffs, vshift, 0, xc, yc); | 1341 const Uint8 col = getPixel(src, bmoffs, scroffs, vshift, 0, xc, yc); |
1342 *dp++ = col; | |
1343 if (spec->aspect) | |
1344 *dp++ = col; | |
1352 } | 1345 } |
1353 } | 1346 } |
1354 } | 1347 } |
1355 } | 1348 } |
1356 | 1349 |
1366 | 1359 |
1367 if (pdst == NULL || src == NULL || fmt == NULL || spec == NULL) | 1360 if (pdst == NULL || src == NULL || fmt == NULL || spec == NULL) |
1368 return DMERR_NULLPTR; | 1361 return DMERR_NULLPTR; |
1369 | 1362 |
1370 // Allocate image structure | 1363 // Allocate image structure |
1371 if ((*pdst = dst = dmImageAlloc(src->width, src->height, DM_COLFMT_PALETTE, -1)) == NULL) | 1364 if ((*pdst = dst = dmImageAlloc( |
1365 src->fmt->width, src->fmt->height, DM_COLFMT_PALETTE, -1)) == NULL) | |
1372 return DMERR_MALLOC; | 1366 return DMERR_MALLOC; |
1373 | 1367 |
1374 // Set partial palette information | 1368 // Set partial palette information |
1375 dst->ncolors = C64_NCOLORS; | 1369 dst->ncolors = C64_NCOLORS; |
1376 dst->constpal = TRUE; | 1370 dst->constpal = TRUE; |