Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 1482:df6dacb48970
Rename some struct members, and sanitize handling of DMC64Image allocation more.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 11 May 2018 03:29:55 +0300 |
parents | d883b4c1cf48 |
children | 1e7f7489d3e0 |
comparison
equal
deleted
inserted
replaced
1481:e967e8e3b8c3 | 1482:df6dacb48970 |
---|---|
82 return NULL; | 82 return NULL; |
83 | 83 |
84 // Initialize image information | 84 // Initialize image information |
85 img->width = fmt->width; | 85 img->width = fmt->width; |
86 img->height = fmt->height; | 86 img->height = fmt->height; |
87 img->ch_width = fmt->ch_width; | 87 img->chWidth = fmt->chWidth; |
88 img->ch_height = fmt->ch_height; | 88 img->chHeight = fmt->chHeight; |
89 img->nbanks = dmC64ImageGetNumBanks(fmt); | 89 img->nbanks = dmC64ImageGetNumBanks(fmt); |
90 | |
91 img->screenSize = img->chWidth * img->chHeight; | |
92 img->bitmapSize = img->screenSize * 8; | |
93 img->charmemSize = C64_MAX_CHARS * C64_CHR_SIZE; | |
90 | 94 |
91 // Allocate banks | 95 // Allocate banks |
92 if ((img->color = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL || | 96 if ((img->color = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL || |
93 (img->bitmap = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL || | 97 (img->bitmap = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL || |
94 (img->screen = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL || | 98 (img->screen = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL || |
95 (img->charmem = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL) | 99 (img->charmem = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL) |
96 goto err; | 100 goto err; |
97 | 101 |
98 for (int i = 0; i < img->nbanks; i++) | 102 for (int i = 0; i < img->nbanks; i++) |
99 { | 103 { |
100 if ((img->color[i] = dmMalloc0(img->ch_width * img->ch_height)) == NULL) | 104 if ((img->color[i] = dmMalloc0(img->screenSize)) == NULL) |
101 goto err; | 105 goto err; |
102 | 106 |
103 if ((img->bitmap[i] = dmMalloc0(img->ch_width * img->ch_height * 8)) == NULL) | 107 if ((img->bitmap[i] = dmMalloc0(img->bitmapSize)) == NULL) |
104 goto err; | 108 goto err; |
105 | 109 |
106 if ((img->screen[i] = dmMalloc0(img->ch_width * img->ch_height)) == NULL) | 110 if ((img->screen[i] = dmMalloc0(img->screenSize)) == NULL) |
107 goto err; | 111 goto err; |
108 | 112 |
109 if ((img->charmem[i] = dmMalloc0(C64_MAX_CHARS * C64_CHR_SIZE)) == NULL) | 113 if ((img->charmem[i] = dmMalloc0(img->charmemSize)) == NULL) |
110 goto err; | 114 goto err; |
111 } | 115 } |
112 | 116 |
113 return img; | 117 return img; |
114 | 118 |
1218 BOOL check; | 1222 BOOL check; |
1219 switch (op->type) | 1223 switch (op->type) |
1220 { | 1224 { |
1221 case DT_SCREEN_RAM: | 1225 case DT_SCREEN_RAM: |
1222 case DT_COLOR_RAM: | 1226 case DT_COLOR_RAM: |
1223 *size = fmt->ch_height * fmt->ch_width; | 1227 *size = fmt->chHeight * fmt->chWidth; |
1224 check = TRUE; | 1228 check = TRUE; |
1225 break; | 1229 break; |
1226 | 1230 |
1227 case DT_BITMAP: | 1231 case DT_BITMAP: |
1228 *size = fmt->ch_height * fmt->ch_width * 8; | 1232 *size = fmt->chHeight * fmt->chWidth * 8; |
1229 check = TRUE; | 1233 check = TRUE; |
1230 break; | 1234 break; |
1231 | 1235 |
1232 case DT_EXTRA_DATA: | 1236 case DT_EXTRA_DATA: |
1233 *size = op->size; | 1237 *size = op->size; |
1271 | 1275 |
1272 // Clear the image structure, set basics | 1276 // Clear the image structure, set basics |
1273 img->type = fmt->type; | 1277 img->type = fmt->type; |
1274 img->width = fmt->width; | 1278 img->width = fmt->width; |
1275 img->height = fmt->height; | 1279 img->height = fmt->height; |
1276 img->ch_width = fmt->ch_width; | 1280 img->chWidth = fmt->chWidth; |
1277 img->ch_height = fmt->ch_height; | 1281 img->chHeight = fmt->chHeight; |
1278 img->nbanks = dmC64ImageGetNumBanks(fmt); | 1282 img->nbanks = dmC64ImageGetNumBanks(fmt); |
1279 | 1283 |
1280 // Perform decoding | 1284 // Perform decoding |
1281 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) | 1285 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) |
1282 { | 1286 { |
1379 break; | 1383 break; |
1380 | 1384 |
1381 case D64_CHCFG_LINEAR: | 1385 case D64_CHCFG_LINEAR: |
1382 { | 1386 { |
1383 for (int bank = 0; bank < img->nbanks; bank++) | 1387 for (int bank = 0; bank < img->nbanks; bank++) |
1384 for (int offs = 0; offs < fmt->ch_height * fmt->ch_width; offs++) | 1388 for (int offs = 0; offs < fmt->chHeight * fmt->chWidth; offs++) |
1385 img->screen[bank][offs] = offs & 0xff; | 1389 img->screen[bank][offs] = offs & 0xff; |
1386 } | 1390 } |
1387 break; | 1391 break; |
1388 | 1392 |
1389 default: | 1393 default: |
1393 op->offs, i, op->bank, size, size, len, len); | 1397 op->offs, i, op->bank, size, size, len, len); |
1394 } | 1398 } |
1395 break; | 1399 break; |
1396 | 1400 |
1397 case DT_DEC_FUNCTION: | 1401 case DT_DEC_FUNCTION: |
1398 if (op->decfunction == NULL) | 1402 if (op->decFunction == NULL) |
1399 { | 1403 { |
1400 return dmError(DMERR_INTERNAL, | 1404 return dmError(DMERR_INTERNAL, |
1401 "Decode op is a function, but function ptr is NULL: " | 1405 "Decode op is a function, but function ptr is NULL: " |
1402 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", | 1406 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1403 i, op->offs, op->offs, op->bank, size, size, len, len); | 1407 i, op->offs, op->offs, op->bank, size, size, len, len); |
1404 } | 1408 } |
1405 if (!op->decfunction(img, op, buf, len)) | 1409 if (!op->decFunction(img, op, buf, len)) |
1406 { | 1410 { |
1407 return dmError(DMERR_INTERNAL, | 1411 return dmError(DMERR_INTERNAL, |
1408 "Decode op custom function failed: op #%d, " | 1412 "Decode op custom function failed: op #%d, " |
1409 "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", | 1413 "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1410 i, op->offs, op->offs, op->bank, size, size, len, len); | 1414 i, op->offs, op->offs, op->bank, size, size, len, len); |
1525 goto err; | 1529 goto err; |
1526 } | 1530 } |
1527 break; | 1531 break; |
1528 | 1532 |
1529 case DT_ENC_FUNCTION: | 1533 case DT_ENC_FUNCTION: |
1530 if (op->encfunction == NULL) | 1534 if (op->encFunction == NULL) |
1531 { | 1535 { |
1532 res = dmError(DMERR_INTERNAL, | 1536 res = dmError(DMERR_INTERNAL, |
1533 "Encode op is a function, but function ptr is NULL: " | 1537 "Encode op is a function, but function ptr is NULL: " |
1534 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", | 1538 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1535 i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); | 1539 i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); |
1536 goto err; | 1540 goto err; |
1537 } | 1541 } |
1538 /* | 1542 /* |
1539 if (!op->encfunction(op, buf, len)) | 1543 if (!op->encFunction(op, buf, len)) |
1540 { | 1544 { |
1541 res = dmError(DMERR_INTERNAL, | 1545 res = dmError(DMERR_INTERNAL, |
1542 "Encode op custom function failed: op #%d, " | 1546 "Encode op custom function failed: op #%d, " |
1543 "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", | 1547 "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1544 i, op->offs, op->offs, op->bank, size, size, len, len); | 1548 i, op->offs, op->offs, op->bank, size, size, len, len); |
1590 Uint8 *dp = dst->data; | 1594 Uint8 *dp = dst->data; |
1591 for (int yc = 0; yc < src->height; yc++) | 1595 for (int yc = 0; yc < src->height; yc++) |
1592 { | 1596 { |
1593 Uint8 *d = dp; | 1597 Uint8 *d = dp; |
1594 const int y = yc / 8, yb = yc & 7; | 1598 const int y = yc / 8, yb = yc & 7; |
1595 const int scroffsy = y * src->ch_width; | 1599 const int scroffsy = y * src->chWidth; |
1596 int xc; | 1600 int xc; |
1597 | 1601 |
1598 if (src->type & D64_FMT_CHAR) | 1602 if (src->type & D64_FMT_CHAR) |
1599 { | 1603 { |
1600 // Charmode conversion | 1604 // Charmode conversion |
1643 } | 1647 } |
1644 } | 1648 } |
1645 else | 1649 else |
1646 { | 1650 { |
1647 // Perform generic BITMAP conversion | 1651 // Perform generic BITMAP conversion |
1648 const int bmoffsy = y * src->ch_width * 8 + yb; | 1652 const int bmoffsy = y * src->chWidth * 8 + yb; |
1649 | 1653 |
1650 if ((src->type & D64_FMT_MC) == D64_FMT_HIRES) | 1654 if ((src->type & D64_FMT_MC) == D64_FMT_HIRES) |
1651 // Hi-res bitmap | 1655 // Hi-res bitmap |
1652 for (xc = 0; xc < rwidth; xc++) | 1656 for (xc = 0; xc < rwidth; xc++) |
1653 { | 1657 { |