comparison tools/lib64fmts.c @ 2195:868b68c188e5

Cleanup Crest SHFLI decoding and use specific constants better.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 13 Jun 2019 22:02:04 +0300
parents c63df53fdfce
children 28871f500e84
comparison
equal deleted inserted replaced
2194:71880ce885dd 2195:868b68c188e5
1219 *col = color3 ? color3 : ( color2 ? color2 : color1 ); 1219 *col = color3 ? color3 : ( color2 ? color2 : color1 );
1220 return DMERR_OK; 1220 return DMERR_OK;
1221 } 1221 }
1222 1222
1223 1223
1224 #define DM_CREST_SHFLI_BANKS 8 1224 // Horizontal character X-offset and scanline Y-offset
1225 #define DM_CREST_SHFLI_PTRS 8 1225 #define DM_CREST_SHFLI_IMG_XOFFS 14
1226 #define DM_CREST_SHFLI_IMG_YOFFS 1
1227
1228 // True image width and height in character blocks
1229 #define DM_CREST_SHFLI_IMG_WIDTH (4 * D64_SPR_WIDTH_UT)
1230 #define DM_CREST_SHFLI_IMG_HEIGHT 21
1231
1232 #define DM_CREST_SHFLI_BANKS 8
1233 #define DM_CREST_SHFLI_PTRS 8
1234
1226 static const Uint8 fmtCrestSHFLI_Sprite_pointers[DM_CREST_SHFLI_BANKS][DM_CREST_SHFLI_PTRS] = 1235 static const Uint8 fmtCrestSHFLI_Sprite_pointers[DM_CREST_SHFLI_BANKS][DM_CREST_SHFLI_PTRS] =
1227 { 1236 {
1228 { 0x80, 0x84, 0x85, 0x89, 0x8A, 0x8E, 0x8F, 0x93 }, 1237 { 0x80, 0x84, 0x85, 0x89, 0x8A, 0x8E, 0x8F, 0x93 },
1229 { 0x94, 0x98, 0x99, 0x9D, 0x9E, 0xA2, 0xA3, 0xA7 }, 1238 { 0x94, 0x98, 0x99, 0x9D, 0x9E, 0xA2, 0xA3, 0xA7 },
1230 { 0xA8, 0xAC, 0xAD, 0xB1, 0xB2, 0xB6, 0xB7, 0xBB }, 1239 { 0xA8, 0xAC, 0xAD, 0xB1, 0xB2, 0xB6, 0xB7, 0xBB },
1285 if ((res = dmDecodeGenericRLEAlloc( 1294 if ((res = dmDecodeGenericRLEAlloc(
1286 &mem, dmGrowBufConstCopyOffs(&tmp, buf, 1), &cfg)) == DMERR_OK) 1295 &mem, dmGrowBufConstCopyOffs(&tmp, buf, 1), &cfg)) == DMERR_OK)
1287 { 1296 {
1288 const size_t fmtUncompSize = 0x1ff0; 1297 const size_t fmtUncompSize = 0x1ff0;
1289 const size_t dstSize = 16 * 1024; 1298 const size_t dstSize = 16 * 1024;
1290 const int imgXOffs = 14;
1291 const int imgWidth = 4 * D64_SPR_WIDTH_UT;
1292 Uint8 *dstBuf, *sptr, *dptr; 1299 Uint8 *dstBuf, *sptr, *dptr;
1293 1300
1294 // Check uncompressed size? 1301 // Check uncompressed size?
1295 if (mem.len != fmtUncompSize) 1302 if (mem.len != fmtUncompSize)
1296 { 1303 {
1336 // Copy sprite data points 1343 // Copy sprite data points
1337 memcpy(dptr + 0x03f8, &fmtCrestSHFLI_Sprite_pointers[nbank], DM_CREST_SHFLI_PTRS); 1344 memcpy(dptr + 0x03f8, &fmtCrestSHFLI_Sprite_pointers[nbank], DM_CREST_SHFLI_PTRS);
1338 } 1345 }
1339 1346
1340 // Now we copy and transform the bitmap and screen RAM data. 1347 // Now we copy and transform the bitmap and screen RAM data.
1341 for (int yc = 0; yc < fmt->format->chHeight * 8; yc++) 1348 for (int yc = 0; yc < DM_CREST_SHFLI_IMG_HEIGHT * 8; yc++)
1342 { 1349 {
1343 const int syy = yc / 8; 1350 const int syy = yc / 8;
1344 const int syd = yc & 7; 1351 const int syd = yc & 7;
1345 1352
1346 // In the image the first visible scanline is unused, but in 1353 // In the image the first visible scanline is unused, but in
1347 // the compressed version data starts right away, so we offset 1354 // the compressed version data starts right away, so we offset
1348 // the destination Y coordinate by one. 1355 // the destination Y coordinate by one.
1349 const int dyc = yc + 1; 1356 const int dyc = yc + DM_CREST_SHFLI_IMG_YOFFS;
1350 const int dyy = dyc / 8; 1357 const int dyy = dyc / 8;
1351 const int dyd = dyc & 7; 1358 const int dyd = dyc & 7;
1352 1359
1353 // Format of the bitmap data is one horizontal pixel row (12 bytes) 1360 // Format of the bitmap data is one horizontal pixel row (12 bytes)
1354 // times 21*8 rows, e.g. the data is "linear" rows of bytes and not 1361 // times 21*8 rows, e.g. the data is "linear" rows of bytes and not
1355 // arranged in usual c64 bitmap "char" order. Thus we reorder it. 1362 // arranged in usual c64 bitmap "char" order. Thus we reorder it.
1356 sptr = mem.data + 0x1000 + imgWidth * (syd + 8 * syy); 1363 sptr = mem.data + 0x1000 + DM_CREST_SHFLI_IMG_WIDTH * (syd + 8 * syy);
1357 dptr = dstBuf + 0x2000 + imgXOffs * 8 + (fmt->format->chWidth * dyy * 8) + dyd; 1364 dptr = dstBuf + 0x2000 + DM_CREST_SHFLI_IMG_XOFFS * 8 + (fmt->format->chWidth * dyy * 8) + dyd;
1358 1365
1359 for (int xc = 0; xc < imgWidth; xc++) 1366 for (int xc = 0; xc < DM_CREST_SHFLI_IMG_WIDTH; xc++)
1360 { 1367 {
1361 dptr[xc * 8] = sptr[xc]; 1368 dptr[xc * 8] = sptr[xc];
1362 sptr[xc] = 0xaa; 1369 sptr[xc] = 0xaa;
1363 } 1370 }
1364 1371
1365 // A bit similar arrangement is used for the screen RAM data. 1372 // A bit similar arrangement is used for the screen RAM data.
1366 // Each row of 12 bytes of data is for a bank. Next row is for 1373 // Each row of 12 bytes of data is for a bank. Next row is for
1367 // next bank, etc. 1374 // next bank, etc.
1368 sptr = mem.data + 0x1800 + imgWidth * syd + imgWidth * 8 * syy; 1375 sptr = mem.data + 0x1800 + DM_CREST_SHFLI_IMG_WIDTH * syd + DM_CREST_SHFLI_IMG_WIDTH * 8 * syy;
1369 dptr = dstBuf + imgXOffs + 0x0400 * dyd + fmt->format->chWidth * dyy; 1376 dptr = dstBuf + DM_CREST_SHFLI_IMG_XOFFS + 0x0400 * dyd + fmt->format->chWidth * dyy;
1370 1377
1371 for (int xc = 0; xc < imgWidth; xc++) 1378 for (int xc = 0; xc < DM_CREST_SHFLI_IMG_WIDTH; xc++)
1372 { 1379 {
1373 dptr[xc] = sptr[xc]; 1380 dptr[xc] = sptr[xc];
1374 sptr[xc] = 0xaa; 1381 sptr[xc] = 0xaa;
1375 } 1382 }
1376 } 1383 }
1377 1384
1378 // The sprite data is also transformed similarly, data is 1385 // The sprite data is also transformed similarly, data is
1379 // in same scanline format as the bitmap. Thus we need to 1386 // in same scanline format as the bitmap. Thus we need to
1380 // place it where it belongs based on the sprite pointers. 1387 // place it where it belongs based on the sprite pointers.
1381 for (int yc = 0; yc < fmt->format->chHeight * 8; yc++) 1388 for (int yc = 0; yc < DM_CREST_SHFLI_IMG_HEIGHT * 8; yc++)
1382 { 1389 {
1383 const int yd = yc % 21; 1390 const int yd = yc % D64_SPR_HEIGHT_PX;
1384 const Uint8 *sprPtrs = fmtCrestSHFLI_Sprite_pointers[yc % 8]; 1391 const Uint8 *sprPtrs = fmtCrestSHFLI_Sprite_pointers[yc % 8];
1385 Uint8 *sp1, *sp2, *dp; 1392 Uint8 *sp1, *sp2, *dp;
1386 1393
1387 dptr = dstBuf + 3 * yd; 1394 dptr = dstBuf + D64_SPR_WIDTH_UT * yd;
1388 sp1 = mem.data + imgWidth * yc; 1395 sp1 = mem.data + DM_CREST_SHFLI_IMG_WIDTH * yc;
1389 sp2 = sp1 + 0x0800; 1396 sp2 = sp1 + 0x0800;
1390 1397
1391 for (int xc = 0; xc < 4; xc++) 1398 for (int xc = 0; xc < DM_CREST_SHFLI_IMG_WIDTH / D64_SPR_WIDTH_UT; xc++)
1392 { 1399 {
1393 dp = dptr + D64_SPR_SIZE * sprPtrs[xc]; 1400 dp = dptr + D64_SPR_SIZE * sprPtrs[xc];
1394 for (int xd = 0; xd < D64_SPR_WIDTH_UT; xd++) 1401 for (int xd = 0; xd < D64_SPR_WIDTH_UT; xd++)
1395 dp[xd] = *sp1++; 1402 dp[xd] = *sp1++;
1396 1403
1432 1439
1433 static int fmtGetPixelCrestSHFLI(Uint8 *col, 1440 static int fmtGetPixelCrestSHFLI(Uint8 *col,
1434 const DMC64Image *img, const int rasterX, const int rasterY) 1441 const DMC64Image *img, const int rasterX, const int rasterY)
1435 { 1442 {
1436 DM_C64_GENERIC_SC_PIXEL_DEFS(img) 1443 DM_C64_GENERIC_SC_PIXEL_DEFS(img)
1437 const int sprOffsetX = 112, sprOffsetY = 1; 1444 const int sprOffsetX = DM_CREST_SHFLI_IMG_XOFFS * 8,
1445 sprOffsetY = DM_CREST_SHFLI_IMG_YOFFS;
1438 const int nbank = rasterY & 7; 1446 const int nbank = rasterY & 7;
1439 int res; 1447 int res;
1440 1448
1441 if (rasterY / 8 >= img->fmt->chHeight) 1449 if (rasterY / 8 >= DM_CREST_SHFLI_IMG_HEIGHT)
1442 { 1450 {
1443 *col = 0x0f; 1451 *col = 0x0f;
1444 return DMERR_OK; 1452 return DMERR_OK;
1445 } 1453 }
1446 1454
1838 }, 1846 },
1839 1847
1840 { // #11: Crest Super Hires FLI Editor 1.0 (SHF) 1848 { // #11: Crest Super Hires FLI Editor 1.0 (SHF)
1841 D64_FMT_HIRES | D64_FMT_FLI, 1849 D64_FMT_HIRES | D64_FMT_FLI,
1842 D64_SCR_WIDTH, D64_SCR_HEIGHT, 1850 D64_SCR_WIDTH, D64_SCR_HEIGHT,
1843 D64_SCR_CH_WIDTH, 21, 1851 D64_SCR_CH_WIDTH, 24,
1844 1, 1, 1852 1, 1,
1845 NULL, NULL, 1853 NULL, NULL,
1846 fmtGetPixelCrestSHFLI, 1854 fmtGetPixelCrestSHFLI,
1847 { 1855 {
1848 DEF_REPEAT_BLOCK_8(DS_SCREEN_RAM, 0x0000, 0 , 0x0400, 0), 1856 DEF_REPEAT_BLOCK_8(DS_SCREEN_RAM, 0x0000, 0 , 0x0400, 0),