Skip to content

Commit

Permalink
Palette wsg (#292)
Browse files Browse the repository at this point in the history
Add ability to palette-swap WSGs when drawing
  • Loading branch information
johnnywycliffe authored Sep 22, 2024
1 parent e6fde30 commit 2298b2b
Show file tree
Hide file tree
Showing 6 changed files with 507 additions and 12 deletions.
2 changes: 1 addition & 1 deletion emulator/src-lib/rawdraw
1 change: 1 addition & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ idf_component_register(SRCS "asset_loaders/common/heatshrink_encoder.c"
"display/font.c"
"display/shapes.c"
"display/wsg.c"
"display/wsgPalette.c"
"menu/menu.c"
"menu/menuManiaRenderer.c"
"menu/menu_utils.c"
Expand Down
14 changes: 4 additions & 10 deletions main/display/wsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
#include "fill.h"
#include "wsg.h"

//==============================================================================
// Function Prototypes
//==============================================================================

static void rotatePixel(int16_t* x, int16_t* y, int16_t rotateDeg, int16_t width, int16_t height);

//==============================================================================
// Functions
//==============================================================================
Expand All @@ -25,12 +19,12 @@ static void rotatePixel(int16_t* x, int16_t* y, int16_t rotateDeg, int16_t width
* then reflection over Y axis, then reflection over X axis, then translation
*
* @param x The x coordinate of the pixel location to transform
* @param y The y coordinate of the pixel location to trasform
* @param y The y coordinate of the pixel location to transform
* @param rotateDeg The number of degrees to rotate clockwise, must be 0-359
* @param width The width of the image
* @param height The height of the image
*/
static void rotatePixel(int16_t* x, int16_t* y, int16_t rotateDeg, int16_t width, int16_t height)
void rotatePixel(int16_t* x, int16_t* y, int16_t rotateDeg, int16_t width, int16_t height)
{
// This function has been micro optimized by cnlohr on 2022-09-07, using gcc version 8.4.0 (crosstool-NG
// esp-2021r2-patch3)
Expand Down Expand Up @@ -253,7 +247,7 @@ void drawWsg(const wsg_t* wsg, int16_t xOff, int16_t yOff, bool flipLR, bool fli
uint32_t dstY = srcY + yOff;

// It is too complicated to detect both directions and backoff correctly, so we just do this here.
// It does slow things down a "tiny" bit. People in the future could optimze out this check.
// It does slow things down a "tiny" bit. People in the future could optimize out this check.
if (dstY >= TFT_HEIGHT)
{
continue;
Expand Down Expand Up @@ -494,4 +488,4 @@ void drawWsgTile(const wsg_t* wsg, int32_t xOff, int32_t yOff)
pxDisp += dWidth;
pxWsg += wWidth;
}
}
}
7 changes: 6 additions & 1 deletion main/display/wsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
*
* \section wsg_usage Usage
*
* There are three ways to draw a WSG to the display each with varying complexity and speed
* There are five ways to draw a WSG to the display each with varying complexity and speed
* - drawWsg(): Draw a WSG to the display with transparency, rotation, and flipping over horizontal or vertical axes.
* This is the slowest option.
* - drawWsgSimple(): Draw a WSG to the display with transparency. This is the medium speed option and should be used if
* the WSG is not rotated or flipped.
* - drawWsgTile(): Draw a WSG to the display without transparency. Any transparent pixels will be an indeterminate
* color. This is the fastest option, and best for background tiles or images.
* - drawWsgSimpleScaled(): Draw a WSG to the display with transparency at a specified scale. Scales are integer
* values, so 2x, 3x, 4x... are the valid options.
* - drawWsgSimpleHalf(): Draw a WSG to the display with transparency at half the original resolution.
*
* \section wsg_example Example
*
Expand All @@ -45,6 +48,7 @@

#include <stdint.h>
#include <palette.h>
#include <stdbool.h>

/**
* @brief A sprite using paletteColor_t colors that can be drawn to the display
Expand All @@ -56,6 +60,7 @@ typedef struct
uint16_t h; ///< The height of the image
} wsg_t;

void rotatePixel(int16_t* x, int16_t* y, int16_t rotateDeg, int16_t width, int16_t height);
void drawWsg(const wsg_t* wsg, int16_t xOff, int16_t yOff, bool flipLR, bool flipUD, int16_t rotateDeg);
void drawWsgSimple(const wsg_t* wsg, int16_t xOff, int16_t yOff);
void drawWsgSimpleScaled(const wsg_t* wsg, int16_t xOff, int16_t yOff, int16_t xScale, int16_t yScale);
Expand Down
Loading

0 comments on commit 2298b2b

Please sign in to comment.