Swadge ESP32-S2/S3
APIs to develop for the Magfest Swadge
Loading...
Searching...
No Matches
wsg.h File Reference

Detailed Description

Design Philosophy

WSG is a simple image format developed for Swadge sprites. Each pixel in a WSG is from the web-safe palette of colors, with one extra value indicating transparent (paletteColor_t). The pixels are then compressed with heatshrink compression.

WSGs are handled individually, not in a sheet. The assets_preprocessor program will take PNG files and convert them to WSG. The cmake build will take the generated WSG files and generate cnfs_image.c which is included in the firmware Swadge. See assets_preprocessor in CMakeLists.txt.

WSG files can be loaded from the filesystem with helper functions in fs_wsg.h. Once loaded from the filesystem WSGs can be drawn to the display.

Usage

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.

Example

// Declare and load an image
wsg_t king_donut;
loadWsg(KID_0_WSG, &king_donut, true);
// Draw the image to the display
drawWsg(&king_donut, 100, 100, false, false, 0);
// Free the image
freeWsg(&king_donut);
void freeWsg(wsg_t *wsg)
Free the memory for a loaded WSG.
Definition fs_wsg.c:261
bool loadWsg(cnfsFileIdx_t fIdx, wsg_t *wsg, bool spiRam)
Load a WSG from ROM to RAM. WSGs placed in the assets_image folder before compilation will be automat...
Definition fs_wsg.c:32
#define drawWsg(w, x, y, lr, ud, rot)
Definition wsg.h:65
A sprite using paletteColor_t colors that can be drawn to the display.
Definition wsg.h:58

Go to the source code of this file.

Data Structures

struct  wsg_t
 A sprite using paletteColor_t colors that can be drawn to the display. More...

Macros

#define drawWsg(w, x, y, lr, ud, rot)

Functions

void rotatePixel (int32_t *x, int32_t *y, int32_t rotateDeg, int32_t width, int32_t height)
void drawWsgSolid (const wsg_t *wsg, int32_t xOff, int32_t yOff, bool flipLR, bool flipUD, int32_t rotateDeg, paletteColor_t color)
 Draw a WSG to the display.
void drawWsgSimple (const wsg_t *wsg, int16_t xOff, int16_t yOff)
 Draw a WSG to the display without flipping or rotation.
void drawWsgSimpleScaled (const wsg_t *wsg, int16_t xOff, int16_t yOff, int16_t xScale, int16_t yScale)
 Draw a WSG to the display without flipping or rotation. xScale and yScale must share the same sign or else the image will be drawn normally at 1x scale.
void drawWsgSimpleScaledUp (const wsg_t *wsg, int16_t xOff, int16_t yOff, int16_t xScale, int16_t yScale)
 Draw a WSG to the display without flipping or rotation.
void drawWsgSimpleScaledDown (const wsg_t *wsg, int16_t xOff, int16_t yOff, int16_t xScale, int16_t yScale)
 Draw a WSG to the display without flipping or rotation at half size.
void drawWsgSmoothScaled (const wsg_t *wsg, int16_t xOff, int16_t yOff, q24_8 xScale, q24_8 yScale)
 Draw a WSG to the display without flipping or rotation. Use drawWsgSimpleScaled and drawWsgSimpleHalf if halving or doubling sprites.
void drawWsgTile (const wsg_t *wsg, int32_t xOff, int32_t yOff)
 Quickly copy a WSG to the display without flipping or rotation or transparency.
void drawWsgSimpleHalf (const wsg_t *wsg, int16_t xOff, int16_t yOff)
 Draw a WSG to the display without flipping or rotation at half size.

Data Structure Documentation

◆ wsg_t

struct wsg_t
Data Fields
paletteColor_t * px The row-order array of pixels in the image.
uint16_t w The width of the image.
uint16_t h The height of the image.

Macro Definition Documentation

◆ drawWsg

#define drawWsg ( w,
x,
y,
lr,
ud,
rot )
Value:
drawWsgSolid(w, x, y, lr, ud, rot, cTransparent)
@ cTransparent
Transparent, will not draw over other pixels.
Definition palette.h:240
void drawWsgSolid(const wsg_t *wsg, int32_t xOff, int32_t yOff, bool flipLR, bool flipUD, int32_t rotateDeg, paletteColor_t solidColor)
Draw a WSG to the display.
Definition wsg.c:107

Function Documentation

◆ rotatePixel()

void rotatePixel ( int32_t * x,
int32_t * y,
int32_t rotateDeg,
int32_t width,
int32_t height )

Transform a pixel's coordinates by rotation around the sprite's center point, then reflection over Y axis, then reflection over X axis, then translation

Parameters
xThe x coordinate of the pixel location to transform
yThe y coordinate of the pixel location to transform
rotateDegThe number of degrees to rotate clockwise, must be 0-359
widthThe width of the image
heightThe height of the image

◆ drawWsgSolid()

void drawWsgSolid ( const wsg_t * wsg,
int32_t xOff,
int32_t yOff,
bool flipLR,
bool flipUD,
int32_t rotateDeg,
paletteColor_t solidColor )

Draw a WSG to the display.

Parameters
wsgThe WSG to draw to the display
xOffThe x offset to draw the WSG at
yOffThe y offset to draw the WSG at
flipLRtrue to flip the image across the Y axis
flipUDtrue to flip the image across the X axis
rotateDegThe number of degrees to rotate clockwise, must be 0-359
solidColorA single color to use for each pixel, or cTransparent to ignore

◆ drawWsgSimple()

void drawWsgSimple ( const wsg_t * wsg,
int16_t xOff,
int16_t yOff )

Draw a WSG to the display without flipping or rotation.

Parameters
wsgThe WSG to draw to the display
xOffThe x offset to draw the WSG at
yOffThe y offset to draw the WSG at

◆ drawWsgSimpleScaled()

void drawWsgSimpleScaled ( const wsg_t * wsg,
int16_t xOff,
int16_t yOff,
int16_t xScale,
int16_t yScale )

Draw a WSG to the display without flipping or rotation. xScale and yScale must share the same sign or else the image will be drawn normally at 1x scale.

Parameters
wsgThe WSG to draw to the display
xOffThe x offset to draw the WSG at
yOffThe y offset to draw the WSG at
xScaleThe amount to scale the image horizontally
yScaleThe amount to scale the image vertically

◆ drawWsgSimpleScaledUp()

void drawWsgSimpleScaledUp ( const wsg_t * wsg,
int16_t xOff,
int16_t yOff,
int16_t xScale,
int16_t yScale )

Draw a WSG to the display without flipping or rotation.

Parameters
wsgThe WSG to draw to the display
xOffThe x offset to draw the WSG at
yOffThe y offset to draw the WSG at
xScaleThe amount to scale the image horizontally
yScaleThe amount to scale the image vertically

◆ drawWsgSimpleScaledDown()

void drawWsgSimpleScaledDown ( const wsg_t * wsg,
int16_t xOff,
int16_t yOff,
int16_t xScale,
int16_t yScale )

Draw a WSG to the display without flipping or rotation at half size.

Parameters
wsgThe WSG to draw to the display
xOffThe x offset to draw the WSG at
yOffThe y offset to draw the WSG at
xScale1 draws at half scale, 2 at quarter scale, etc...
yScale1 draws at half scale, 2 at quarter scale, etc...

◆ drawWsgSmoothScaled()

void drawWsgSmoothScaled ( const wsg_t * wsg,
int16_t xOff,
int16_t yOff,
q24_8 xScale,
q24_8 yScale )

Draw a WSG to the display without flipping or rotation. Use drawWsgSimpleScaled and drawWsgSimpleHalf if halving or doubling sprites.

Parameters
wsgThe WSG to draw to the display
xOffThe x offset to draw the WSG at
yOffThe y offset to draw the WSG at
xScaleThe amount to scale the image horizontally
yScaleThe amount to scale the image vertically

◆ drawWsgTile()

void drawWsgTile ( const wsg_t * wsg,
int32_t xOff,
int32_t yOff )

Quickly copy a WSG to the display without flipping or rotation or transparency.

If the source WSG does have transparency, an indeterminate color will be drawn to the TFT

Parameters
wsgThe WSG to draw to the display
xOffThe x offset to draw the WSG at
yOffThe y offset to draw the WSG at

◆ drawWsgSimpleHalf()

void drawWsgSimpleHalf ( const wsg_t * wsg,
int16_t xOff,
int16_t yOff )

Draw a WSG to the display without flipping or rotation at half size.

Parameters
wsgThe WSG to draw to the display
xOffThe x offset to draw the WSG at
yOffThe y offset to draw the WSG at