Skip to content

Commit

Permalink
Added chunkyToPlanar() fn for single pixel manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
tehKaiN committed Dec 31, 2017
1 parent aab827d commit aac212b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 31 deletions.
80 changes: 50 additions & 30 deletions include/ace/utils/chunky.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
#include <fixmath/fix16.h>

/**
* @brief Returns color indices for 16 colors in a row starting from supplied
* @brief Returns color indices for 16 colors in a row starting from supplied
* coords.
*
* @param pBitMap Bitmap, from which pixel colors will be read
* @param uwX Starting X coord, always word-aligned.
* E.g. Read from pixel 18 will start it from x = 16 anyway.
* @param uwY Row number, from which pixels will be read.
* @param pOut Color index output buffer.
*
* @see chunkyFromPlanar()
*
* @param pBitMap Bitmap, from which pixel colors will be read
* @param uwX Starting X coord, always word-aligned.
* E.g. Read from pixel 18 will start it from x = 16 anyway.
* @param uwY Row number, from which pixels will be read.
* @param pOut Color index output buffer.
*
* @see chunkyFromPlanar()
*/
void chunkyFromPlanar16(
IN tBitMap *pBitMap,
Expand All @@ -25,15 +25,15 @@ void chunkyFromPlanar16(
);

/**
* @brief Returns color index of selected pixel.
* Inefficient as hell - use if really needed or for prototyping convenience!
*
* @param pBitMap Bitmap, from which pixel color will be read.
* @param uwX Pixel X coord.
* @param uwY Pixel Y coord.
* @return Pixels palette color index.
*
* @see chunkyFromPlanar16()
* @brief Returns color index of selected pixel.
* Inefficient as hell - use if really needed or for prototyping convenience!
*
* @param pBitMap Bitmap, from which pixel color will be read.
* @param uwX Pixel X coord.
* @param uwY Pixel Y coord.
* @return Pixels palette color index.
*
* @see chunkyFromPlanar16()
*/
UBYTE chunkyFromPlanar(
IN tBitMap *pBitMap,
Expand Down Expand Up @@ -66,18 +66,18 @@ void chunkyRotate(
);

/**
* @brief Puts 16-pixel chunky row on bitmap at given coordinates.
*
* This function assumes that chunky pixels are of same depth as bitmap.
* Higher chunky bits will thus be ignored.
*
* @param pIn Source chunky pixels.
* @param uwX Destination start X coordinate.
* @param uwY Destination Y coordinate.
* @param pOut Destination bitmap.
*
* @todo Implement using 32-bit fixed points & Taylor sine approximation.
* @see chunkyFromPlanar16
* @brief Puts 16-pixel chunky row on bitmap at given coordinates.
*
* This function assumes that chunky pixels are of same depth as bitmap.
* Higher chunky bits will thus be ignored.
*
* @param pIn Source chunky pixels.
* @param uwX Destination start X coordinate.
* @param uwY Destination Y coordinate.
* @param pOut Destination bitmap.
*
* @see chunkyFromPlanar16
* @see chunkyToPlanar
*/
void chunkyToPlanar16(
IN UBYTE *pIn,
Expand All @@ -86,5 +86,25 @@ void chunkyToPlanar16(
OUT tBitMap *pOut
);

/**
* Puts single chunky pixel on bitmap at given coordinates.
*
* Inefficient as hell - use if really needed or for prototyping convenience!
*
* @param ubIn: Chunky pixel value (color index).
* @param uwX: Pixel's x position on bitmap.
* @param uwY: Pixel's y position on bitmap.
* @param pOut: Destination bitmap.
*
* @see chunkyToPlanar16
* @see chunkyFromPlanar16
* @see chunkyFromPlanar
*/
void chunkyToPlanar(
IN UBYTE ubIn,
IN UWORD uwX,
IN UWORD uwY,
OUT tBitMap *pOut
);

#endif
9 changes: 8 additions & 1 deletion src/ace/utils/chunky.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void chunkyToPlanar16(UBYTE *pIn, UWORD uwX, UWORD uwY, tBitMap *pOut) {
UWORD uwPlanarBuffer = 0;
UWORD *pPlane;
ULONG ulOffset;

ulOffset = uwY*(pOut->BytesPerRow>>1) + (uwX >> 4);
for(ubPlane = 0; ubPlane != pOut->Depth; ++ubPlane) {
for(ubPixel = 0; ubPixel != 16; ++ubPixel) {
Expand All @@ -44,6 +44,13 @@ void chunkyToPlanar16(UBYTE *pIn, UWORD uwX, UWORD uwY, tBitMap *pOut) {
}
}

void chunkyToPlanar(UBYTE ubIn, UWORD uwX, UWORD uwY, tBitMap *pOut) {
UBYTE pChunky[16];
chunkyFromPlanar16(pOut, uwX, uwY, pChunky);
pChunky[uwX & 15] = ubIn;
chunkyToPlanar16(pChunky, uwX, uwY, pOut);
}

void chunkyRotate(
UBYTE *pSource, UBYTE *pDest,
fix16_t fAngle, UBYTE ubBgColor,
Expand Down

0 comments on commit aac212b

Please sign in to comment.