Skip to content

Commit

Permalink
Added chunky <-> bitmap conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
tehKaiN committed Jul 23, 2018
1 parent b39efc8 commit cc64a3d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 8 deletions.
42 changes: 38 additions & 4 deletions include/ace/utils/chunky.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
);
Expand All @@ -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.
Expand All @@ -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_
37 changes: 33 additions & 4 deletions src/ace/utils/chunky.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <ace/utils/bitmap.h>
#include <fixmath/fix16.h>

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));
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
);
}
}

0 comments on commit cc64a3d

Please sign in to comment.