comparison tools/lib64gfx.c @ 2132:6528a1398e8e

Add char map helper functions and use them.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 28 May 2019 10:32:12 +0300
parents 781b1d63109a
children b8491ee3cf24
comparison
equal deleted inserted replaced
2131:781b1d63109a 2132:6528a1398e8e
1275 err: 1275 err:
1276 return res; 1276 return res;
1277 } 1277 }
1278 1278
1279 1279
1280 static int fmtGetGenericSCPixel(Uint8 *col, 1280 static int fmtGetGenericSCPixel(Uint8 *col, const DMC64Image *img,
1281 const DMC64Image *img, const int rasterX, const int rasterY) 1281 const int rasterX, const int rasterY)
1282 { 1282 {
1283 DM_C64_GENERIC_SC_PIXEL_DEFS(img) 1283 DM_C64_GENERIC_SC_PIXEL_DEFS(img)
1284 1284
1285 return dmC64GetGenericSCPixel( 1285 return dmC64GetGenericSCPixel(
1286 col, img, bmoffs, scroffs, vshift, 0, 0); 1286 col, img,
1287 } 1287 bmoffs, scroffs,
1288 1288 vshift, 0, 0);
1289 1289 }
1290 static int fmtGetGenericMCPixel(Uint8 *col, 1290
1291 const DMC64Image *img, const int rasterX, const int rasterY) 1291
1292 static int fmtGetGenericMCPixel(Uint8 *col, const DMC64Image *img,
1293 const int rasterX, const int rasterY)
1292 { 1294 {
1293 DM_C64_GENERIC_MC_PIXEL_DEFS(img) 1295 DM_C64_GENERIC_MC_PIXEL_DEFS(img)
1294 1296
1295 return dmC64GetGenericMCPixel( 1297 return dmC64GetGenericMCPixel(
1296 col, img, bmoffs, scroffs, vshift, 0, 0, 0, img->bgcolor); 1298 col, img,
1297 } 1299 bmoffs, scroffs,
1298 1300 vshift, 0,
1299 1301 0, 0, img->bgcolor);
1300 static int fmtGetGenericCharSCPixel(Uint8 *col, 1302 }
1301 const DMC64Image *img, const int rasterX, const int rasterY) 1303
1302 { 1304
1303 const int 1305 static int fmtGetGenericCharSCPixel(Uint8 *col, const DMC64Image *img,
1304 x = rasterX / 8, 1306 const int rasterX, const int rasterY)
1305 y = rasterY / 8, 1307 {
1306 scroffs = y * img->fmt->chWidth + x, 1308 DM_C64_GENERIC_CHAR_PIXEL(img)
1307 vshift = 7 - (rasterX & 7), 1309 const int chr = img->screen[0].data[scroffs];
1308 chr = img->screen[0].data[scroffs]; 1310
1309 1311 return dmC64GetGenericCharSCPixel(
1310 const size_t chroffs = (chr * D64_CHR_SIZE) + (rasterY & 7); 1312 col, img,
1311 if (chroffs >= img->charData[0].size) 1313 scroffs, rasterX,
1312 { 1314 0, (chr * D64_CHR_SIZE) + (rasterY & 7), chr,
1313 return dmError(DMERR_INVALID_DATA, 1315 0, img->bgcolor);
1314 "Character map index #%d out of bounds for char ROM data.\n", 1316 }
1315 chr); 1317
1316 } 1318
1317 1319 static int fmtGetGenericCharMCPixel(Uint8 *col, const DMC64Image *img,
1318 if ((img->charData[0].data[chroffs] >> vshift) & 1) 1320 const int rasterX, const int rasterY)
1319 *col = img->color[0].data[scroffs]; 1321 {
1320 else 1322 DM_C64_GENERIC_CHAR_PIXEL(img)
1321 *col = img->bgcolor; 1323 const int chr = img->screen[0].data[scroffs];
1322 1324
1323 return DMERR_OK; 1325 return dmC64GetGenericCharMCPixel(
1324 } 1326 col, img,
1325 1327 scroffs, rasterX,
1326 1328 0, (chr * D64_CHR_SIZE) + (rasterY & 7), chr,
1327 static int fmtGetGenericCharMCPixel(Uint8 *col, 1329 0, img->bgcolor, img->d022, img->d023);
1328 const DMC64Image *img, const int rasterX, const int rasterY) 1330 }
1329 { 1331
1330 const int 1332
1331 y = rasterY / 8, 1333 static int fmtGetGenericCharECMPixel(Uint8 *col, const DMC64Image *img,
1332 scroffs = y * img->fmt->chWidth + (rasterX / 8), 1334 const int rasterX, const int rasterY)
1333 chr = img->screen[0].data[scroffs], 1335 {
1334 ccol = img->color[0].data[scroffs]; 1336 DM_C64_GENERIC_CHAR_PIXEL(img)
1335 1337 const int chr = img->screen[0].data[scroffs];
1336 const size_t chroffs = (chr * D64_CHR_SIZE) + (rasterY & 7); 1338
1337 if (chroffs >= img->charData[0].size) 1339 return dmC64GetGenericCharECMPixel(
1338 { 1340 col, img,
1339 return dmError(DMERR_INVALID_DATA, 1341 scroffs, rasterX,
1340 "Character map index #%d out of bounds for char ROM data.\n", 1342 0, ((chr & 0x3f) * D64_CHR_SIZE) + (rasterY & 7), chr,
1341 chr); 1343 0, img->bgcolor, img->d022, img->d023, img->d024);
1342 }
1343
1344 if (ccol & 8)
1345 {
1346 const int vshift = 6 - (rasterX & 6);
1347 switch ((img->charData[0].data[chroffs] >> vshift) & 3)
1348 {
1349 case 0: *col = img->bgcolor; break;
1350 case 1: *col = img->d022; break;
1351 case 2: *col = img->d023; break;
1352 case 3: *col = ccol & 15;
1353 }
1354 }
1355 else
1356 {
1357 const int vshift = 7 - (rasterX & 7);
1358 if ((img->charData[0].data[chroffs] >> vshift) & 1)
1359 *col = ccol & 7;
1360 else
1361 *col = img->bgcolor;
1362 }
1363
1364 return DMERR_OK;
1365 }
1366
1367
1368 static int fmtGetGenericCharECMPixel(Uint8 *col,
1369 const DMC64Image *img, const int rasterX, const int rasterY)
1370 {
1371 const int
1372 x = rasterX / 8,
1373 y = rasterY / 8,
1374 scroffs = y * img->fmt->chWidth + x,
1375 vshift = 7 - (rasterX & 7),
1376 chr = img->screen[0].data[scroffs];
1377
1378 const size_t chroffs = ((chr & 0x3f) * D64_CHR_SIZE) + (rasterY & 7);
1379 if (chroffs >= img->charData[0].size)
1380 {
1381 return dmError(DMERR_INVALID_DATA,
1382 "Character map index #%d out of bounds for char ROM data.\n",
1383 chr);
1384 }
1385
1386 if ((img->charData[0].data[chroffs] >> vshift) & 1)
1387 *col = img->color[0].data[scroffs] & 15;
1388 else
1389 switch ((chr >> 6) & 3)
1390 {
1391 case 0: *col = img->bgcolor; break;
1392 case 1: *col = img->d022; break;
1393 case 2: *col = img->d023; break;
1394 case 3: *col = img->d024; break;
1395 }
1396
1397 return DMERR_OK;
1398 } 1344 }
1399 1345
1400 1346
1401 // Convert a generic "C64" format bitmap in DMC64Image struct to 1347 // Convert a generic "C64" format bitmap in DMC64Image struct to
1402 // a indexed/paletted bitmap image. 1348 // a indexed/paletted bitmap image.