comparison tools/lib64gfx.h @ 2345:fe025c461760

Move pixel helper functions from being inline in lib64gfx.h to lib64gfx.c
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 08 Oct 2019 14:49:00 +0300
parents 94a653883a32
children 82cb32297ed2
comparison
equal deleted inserted replaced
2344:13e54305e5fc 2345:fe025c461760
482 y = rasterY / 8, \ 482 y = rasterY / 8, \
483 scroffs = y * (ximg)->fmt->chWidth + x; \ 483 scroffs = y * (ximg)->fmt->chWidth + x; \
484 484
485 485
486 // 486 //
487 // Inline helper functions for pixel format decoding 487 // Pixel format helpers
488 // 488 //
489 static inline int dmC64GetGenericSCPixel(Uint8 *col, 489 int dmC64GetGenericSCPixel(Uint8 *col,
490 const DMC64Image *img, const int bmoffs, const int scroffs, 490 const DMC64Image *img, const int bmoffs, const int scroffs,
491 const int vshift, const int vbank, const int bitmap) 491 const int vshift, const int vbank, const int bitmap);
492 { 492
493 if ((img->bitmap[bitmap].data[bmoffs] >> vshift) & 1) 493 int dmC64GetGenericMCPixel(Uint8 *col,
494 *col = img->screen[vbank].data[scroffs] >> 4;
495 else
496 *col = img->screen[vbank].data[scroffs] & 15;
497
498 return DMERR_OK;
499 }
500
501
502 static inline int dmC64GetGenericMCPixel(Uint8 *col,
503 const DMC64Image *img, const int bmoffs, const int scroffs, 494 const DMC64Image *img, const int bmoffs, const int scroffs,
504 const int vshift, const int vbank, const int bitmap, 495 const int vshift, const int vbank, const int bitmap,
505 const int cbank, const int bgcolor) 496 const int cbank, const int bgcolor);
506 { 497
507 switch ((img->bitmap[bitmap].data[bmoffs] >> vshift) & 3) 498 int dmC64GetGenericCharSCPixel(Uint8 *col,
508 {
509 case 0: *col = bgcolor & 15; break;
510 case 1: *col = img->screen[vbank].data[scroffs] >> 4; break;
511 case 2: *col = img->screen[vbank].data[scroffs] & 15; break;
512 default: *col = img->color[cbank].data[scroffs] & 15; break;
513 }
514
515 return DMERR_OK;
516 }
517
518
519 static inline int dmC64GetGenericCharSCPixel(Uint8 *col,
520 const DMC64Image *img, const int scroffs, const int rasterX, 499 const DMC64Image *img, const int scroffs, const int rasterX,
521 const int chrbank, const size_t chroffs, const int chr, 500 const int chrbank, const size_t chroffs, const int chr,
522 const int cbank, const int bgcolor) 501 const int cbank, const int bgcolor);
523 { 502
524 if (chroffs >= img->charData[chrbank].size) 503 int dmC64GetGenericCharMCPixel(Uint8 *col,
525 {
526 return dmError(DMERR_INVALID_DATA,
527 "Character map index #%d out of bounds for char ROM data.\n",
528 chr);
529 }
530
531 const int vshift = 7 - (rasterX & 7);
532 if ((img->charData[chrbank].data[chroffs] >> vshift) & 1)
533 *col = img->color[cbank].data[scroffs] & 15;
534 else
535 *col = bgcolor & 15;
536
537 return DMERR_OK;
538 }
539
540
541 static inline int dmC64GetGenericCharMCPixel(Uint8 *col,
542 const DMC64Image *img, const int scroffs, const int rasterX, 504 const DMC64Image *img, const int scroffs, const int rasterX,
543 const int chrbank, const size_t chroffs, const int chr, 505 const int chrbank, const size_t chroffs, const int chr,
544 const int cbank, const int bgcolor, 506 const int cbank, const int bgcolor,
545 const int bgd022, const int bgd023) 507 const int bgd022, const int bgd023);
546 { 508
547 if (chroffs >= img->charData[chrbank].size) 509 int dmC64GetGenericCharECMPixel(Uint8 *col,
548 {
549 return dmError(DMERR_INVALID_DATA,
550 "Character map index #%d out of bounds for char ROM data.\n",
551 chr);
552 }
553
554 const int ccol = img->color[cbank].data[scroffs];
555 if (ccol & 8)
556 {
557 const int vshift = 6 - (rasterX & 6);
558 switch ((img->charData[chrbank].data[chroffs] >> vshift) & 3)
559 {
560 case 0: *col = bgcolor & 15; break;
561 case 1: *col = bgd022 & 15; break;
562 case 2: *col = bgd023 & 15; break;
563 case 3: *col = ccol & 7;
564 }
565 }
566 else
567 {
568 const int vshift = 7 - (rasterX & 7);
569 if ((img->charData[chrbank].data[chroffs] >> vshift) & 1)
570 *col = ccol & 7;
571 else
572 *col = bgcolor & 15;
573 }
574
575 return DMERR_OK;
576 }
577
578
579 static inline int dmC64GetGenericCharECMPixel(Uint8 *col,
580 const DMC64Image *img, const int scroffs, const int rasterX, 510 const DMC64Image *img, const int scroffs, const int rasterX,
581 const int chrbank, const size_t chroffs, const int chr, 511 const int chrbank, const size_t chroffs, const int chr,
582 const int cbank, const int bgcolor, 512 const int cbank, const int bgcolor,
583 const int bgd022, const int bgd023, const int bgd024) 513 const int bgd022, const int bgd023, const int bgd024);
584 {
585 if (chroffs >= img->charData[0].size)
586 {
587 return dmError(DMERR_INVALID_DATA,
588 "Character map index #%d out of bounds for char ROM data.\n",
589 chr);
590 }
591
592 const int vshift = 7 - (rasterX & 7);
593 if ((img->charData[chrbank].data[chroffs] >> vshift) & 1)
594 *col = img->color[cbank].data[scroffs] & 15;
595 else
596 switch ((chr >> 6) & 3)
597 {
598 case 0: *col = bgcolor & 15; break;
599 case 1: *col = bgd022 & 15; break;
600 case 2: *col = bgd023 & 15; break;
601 case 3: *col = bgd024 & 15; break;
602 }
603
604 return DMERR_OK;
605 }
606 514
607 515
608 static inline const DMC64EncDecOp * fmtGetEncDecOp(const DMC64ImageFormat *fmt, const int index) 516 static inline const DMC64EncDecOp * fmtGetEncDecOp(const DMC64ImageFormat *fmt, const int index)
609 { 517 {
610 return &fmt->format->encdecOps[index]; 518 return &fmt->format->encdecOps[index];