Mercurial > hg > dmlib
diff tools/lib64gfx.c @ 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 | 13e54305e5fc |
children | 82cb32297ed2 |
line wrap: on
line diff
--- a/tools/lib64gfx.c Wed Sep 25 12:13:28 2019 +0300 +++ b/tools/lib64gfx.c Tue Oct 08 14:49:00 2019 +0300 @@ -1330,6 +1330,128 @@ } +// +// Helper functions for pixel format decoding +// +int dmC64GetGenericSCPixel(Uint8 *col, + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbank, const int bitmap) +{ + if ((img->bitmap[bitmap].data[bmoffs] >> vshift) & 1) + *col = img->screen[vbank].data[scroffs] >> 4; + else + *col = img->screen[vbank].data[scroffs] & 15; + + return DMERR_OK; +} + + +int dmC64GetGenericMCPixel(Uint8 *col, + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbank, const int bitmap, + const int cbank, const int bgcolor) +{ + switch ((img->bitmap[bitmap].data[bmoffs] >> vshift) & 3) + { + case 0: *col = bgcolor & 15; break; + case 1: *col = img->screen[vbank].data[scroffs] >> 4; break; + case 2: *col = img->screen[vbank].data[scroffs] & 15; break; + default: *col = img->color[cbank].data[scroffs] & 15; break; + } + + return DMERR_OK; +} + + +int dmC64GetGenericCharSCPixel(Uint8 *col, + const DMC64Image *img, const int scroffs, const int rasterX, + const int chrbank, const size_t chroffs, const int chr, + const int cbank, const int bgcolor) +{ + if (chroffs >= img->charData[chrbank].size) + { + return dmError(DMERR_INVALID_DATA, + "Character map index #%d out of bounds for char ROM data.\n", + chr); + } + + const int vshift = 7 - (rasterX & 7); + if ((img->charData[chrbank].data[chroffs] >> vshift) & 1) + *col = img->color[cbank].data[scroffs] & 15; + else + *col = bgcolor & 15; + + return DMERR_OK; +} + + +int dmC64GetGenericCharMCPixel(Uint8 *col, + const DMC64Image *img, const int scroffs, const int rasterX, + const int chrbank, const size_t chroffs, const int chr, + const int cbank, const int bgcolor, + const int bgd022, const int bgd023) +{ + if (chroffs >= img->charData[chrbank].size) + { + return dmError(DMERR_INVALID_DATA, + "Character map index #%d out of bounds for char ROM data.\n", + chr); + } + + const int ccol = img->color[cbank].data[scroffs]; + if (ccol & 8) + { + const int vshift = 6 - (rasterX & 6); + switch ((img->charData[chrbank].data[chroffs] >> vshift) & 3) + { + case 0: *col = bgcolor & 15; break; + case 1: *col = bgd022 & 15; break; + case 2: *col = bgd023 & 15; break; + case 3: *col = ccol & 7; + } + } + else + { + const int vshift = 7 - (rasterX & 7); + if ((img->charData[chrbank].data[chroffs] >> vshift) & 1) + *col = ccol & 7; + else + *col = bgcolor & 15; + } + + return DMERR_OK; +} + + +int dmC64GetGenericCharECMPixel(Uint8 *col, + const DMC64Image *img, const int scroffs, const int rasterX, + const int chrbank, const size_t chroffs, const int chr, + const int cbank, const int bgcolor, + const int bgd022, const int bgd023, const int bgd024) +{ + if (chroffs >= img->charData[0].size) + { + return dmError(DMERR_INVALID_DATA, + "Character map index #%d out of bounds for char ROM data.\n", + chr); + } + + const int vshift = 7 - (rasterX & 7); + if ((img->charData[chrbank].data[chroffs] >> vshift) & 1) + *col = img->color[cbank].data[scroffs] & 15; + else + switch ((chr >> 6) & 3) + { + case 0: *col = bgcolor & 15; break; + case 1: *col = bgd022 & 15; break; + case 2: *col = bgd023 & 15; break; + case 3: *col = bgd024 & 15; break; + } + + return DMERR_OK; +} + + static int fmtGetGenericSCPixel(DMC64ScanLine *scan, const DMC64Image *img, const int rasterX, const int rasterY) {