diff --git a/include/ace/utils/chunky.h b/include/ace/utils/chunky.h index f1223494..5809e25f 100644 --- a/include/ace/utils/chunky.h +++ b/include/ace/utils/chunky.h @@ -21,7 +21,9 @@ * * @see chunkyFromPlanar() */ -void chunkyFromPlanar16(tBitMap *pBitMap, UWORD uwX, UWORD uwY, UBYTE *pOut); +void chunkyFromPlanar16( + const tBitMap *pBitMap, UWORD uwX, UWORD uwY, UBYTE *pOut +); /** * @brief Returns color index of selected pixel. @@ -34,7 +36,7 @@ void chunkyFromPlanar16(tBitMap *pBitMap, UWORD uwX, UWORD uwY, UBYTE *pOut); * * @see chunkyFromPlanar16() */ -UBYTE chunkyFromPlanar(tBitMap *pBitMap, UWORD uwX, UWORD uwY); +UBYTE chunkyFromPlanar(const tBitMap *pBitMap, UWORD uwX, UWORD uwY); /** * @brief Rotates chunky pixels by given angle, on spefied background. @@ -53,7 +55,7 @@ UBYTE chunkyFromPlanar(tBitMap *pBitMap, UWORD uwX, UWORD uwY); * @param wHeight Ditto, height. */ void chunkyRotate( - UBYTE *pSource, UBYTE *pDest, + const UBYTE *pSource, UBYTE *pDest, fix16_t fSin, fix16_t fCos, UBYTE ubBgColor, WORD wWidth, WORD wHeight ); @@ -72,7 +74,7 @@ void chunkyRotate( * @see chunkyFromPlanar16 * @see chunkyToPlanar */ -void chunkyToPlanar16(UBYTE *pIn, UWORD uwX, UWORD uwY, tBitMap *pOut); +void chunkyToPlanar16(const UBYTE *pIn, UWORD uwX, UWORD uwY, tBitMap *pOut); /** * Puts single chunky pixel on bitmap at given coordinates. @@ -90,4 +92,36 @@ void chunkyToPlanar16(UBYTE *pIn, UWORD uwX, UWORD uwY, tBitMap *pOut); */ void chunkyToPlanar(UBYTE ubIn, UWORD uwX, UWORD uwY, tBitMap *pOut); +/** + * @brief Reads given portion of bitmap to chunky buffer. + * + * @param pBitmap Source bitmap image. + * @param pChunky Desitination chunky buffer. + * @param uwSrcOffsX X offset of conversion area, in pixels. + * @param uwSrcOffsY Y offset of conversion area, in pixels. + * @param uwWidth Width of conversion area, in pixels. + * @param uwHeight Height of conversion area, in pixels. + * + * @see chunkyToBitmap + */ +void chunkyFromBitmap( + const tBitMap *pBitmap, UBYTE *pChunky, + UWORD uwSrcOffsX, UWORD uwSrcOffsY, UWORD uwWidth, UWORD uwHeight +); + +/** + * @brief Writes given chunky buffer into specified portion of bitmap + * + * @param pChunky Source chunky data buffer. + * @param pBitmap Destination bitmap. + * @param uwDstOffsX X offset of conversion area, in pixels. + * @param uwDstOffsY Y offset of conversion area, in pixels. + * @param uwWidth Width of conversion area, in pixels. + * @param uwHeight Height of conversion area, in pixels. + */ +void chunkyToBitmap( + const UBYTE *pChunky, tBitMap *pBitmap, + UWORD uwDstOffsX, UWORD uwDstOffsY, UWORD uwWidth, UWORD uwHeight +); + #endif // _ACE_UTILS_CHUNKY_H_ diff --git a/src/ace/utils/chunky.c b/src/ace/utils/chunky.c index f355d5cd..525b145e 100644 --- a/src/ace/utils/chunky.c +++ b/src/ace/utils/chunky.c @@ -8,7 +8,9 @@ #include #include -void chunkyFromPlanar16(tBitMap *pBitMap, UWORD uwX, UWORD uwY, UBYTE *pOut) { +void chunkyFromPlanar16( + const tBitMap *pBitMap, UWORD uwX, UWORD uwY, UBYTE *pOut +) { UWORD uwChunk, uwMask; UBYTE i, ubPx; memset(pOut, 0, 16*sizeof(*pOut)); @@ -24,13 +26,13 @@ void chunkyFromPlanar16(tBitMap *pBitMap, UWORD uwX, UWORD uwY, UBYTE *pOut) { } } -UBYTE chunkyFromPlanar(tBitMap *pBitMap, UWORD uwX, UWORD uwY) { +UBYTE chunkyFromPlanar(const tBitMap *pBitMap, UWORD uwX, UWORD uwY) { UBYTE pIndicesChunk[16]; chunkyFromPlanar16(pBitMap, uwX, uwY, pIndicesChunk); return pIndicesChunk[uwX&0xF]; } -void chunkyToPlanar16(UBYTE *pIn, UWORD uwX, UWORD uwY, tBitMap *pOut) { +void chunkyToPlanar16(const UBYTE *pIn, UWORD uwX, UWORD uwY, tBitMap *pOut) { UBYTE ubPlane, ubPixel; UWORD uwPlanarBuffer = 0; UWORD *pPlane; @@ -57,7 +59,7 @@ void chunkyToPlanar(UBYTE ubIn, UWORD uwX, UWORD uwY, tBitMap *pOut) { } void chunkyRotate( - UBYTE *pSource, UBYTE *pDest, fix16_t fSin, fix16_t fCos, + const UBYTE *pSource, UBYTE *pDest, fix16_t fSin, fix16_t fCos, UBYTE ubBgColor, WORD wWidth, WORD wHeight ) { fix16_t fCx, fCy; @@ -88,3 +90,30 @@ void chunkyRotate( } } } + +void chunkyFromBitmap( + const tBitMap *pBitmap, UBYTE *pChunky, + UWORD uwSrcOffsX, UWORD uwSrcOffsY, UWORD uwWidth, UWORD uwHeight +) { + for(UWORD y = 0; y < uwHeight; ++y) { + for(UWORD x = 0; x < uwWidth; x += 16) { + chunkyFromPlanar16( + pBitmap, uwSrcOffsX + x, uwSrcOffsY + y, &pChunky[y*uwWidth + x] + ); + } + } +} + +void chunkyToBitmap( + const UBYTE *pChunky, tBitMap *pBitmap, + UWORD uwDstOffsX, UWORD uwDstOffsY, UWORD uwWidth, UWORD uwHeight +) { + for(UWORD y = 0; y < uwHeight; ++y) { + for(UWORD x = 0; x < uwWidth; x += 16) + chunkyToPlanar16( + &pChunky[(y*uwWidth) + x], + uwDstOffsX + x, uwDstOffsY + y, + pBitmap + ); + } +}