libtonc
Colors

Modules

 Bitmaps
 
 Tiled Backgrounds
 

Additional colors

void clr_rotate (COLOR *clrs, uint nclrs, int ror)
 Rotate nclrs colors at clrs to the right by ror.
 
void clr_blend (const COLOR *srca, const COLOR *srcb, COLOR *dst, uint nclrs, u32 alpha)
 Blends color arrays srca and srcb into dst.
 
void clr_fade (const COLOR *src, COLOR clr, COLOR *dst, uint nclrs, u32 alpha)
 Fades color arrays srca to clr into dst.
 
void clr_grayscale (COLOR *dst, const COLOR *src, uint nclrs)
 Transform colors to grayscale.
 
void clr_rgbscale (COLOR *dst, const COLOR *src, uint nclrs, COLOR clr)
 Transform colors to an rgb-scale.
 
void clr_adj_brightness (COLOR *dst, const COLOR *src, uint nclrs, FIXED bright)
 Adjust brightness by bright.
 
void clr_adj_contrast (COLOR *dst, const COLOR *src, uint nclrs, FIXED contrast)
 Adjust contrast by contrast.
 
void clr_adj_intensity (COLOR *dst, const COLOR *src, uint nclrs, FIXED intensity)
 Adjust intensity by intensity.
 
void pal_gradient (COLOR *pal, int first, int last)
 Create a gradient between pal[first] and pal[last].
 
void pal_gradient_ex (COLOR *pal, int first, int last, COLOR clr_first, COLOR clr_last)
 Create a gradient between pal[first] and pal[last].
 
IWRAM_CODE void clr_blend_fast (COLOR *srca, COLOR *srcb, COLOR *dst, uint nclrs, u32 alpha)
 Blends color arrays srca and srcb into dst.
 
IWRAM_CODE void clr_fade_fast (COLOR *src, COLOR clr, COLOR *dst, uint nclrs, u32 alpha)
 Fades color arrays srca to clr into dst.
 
INLINE COLOR RGB15 (int red, int green, int blue)
 Create a 15bit BGR color.
 
INLINE COLOR RGB15_SAFE (int red, int green, int blue)
 Create a 15bit BGR color, with proper masking of R,G,B components.
 
INLINE COLOR RGB8 (u8 red, u8 green, u8 blue)
 Create a 15bit BGR color, using 8bit components.
 
#define CLR_DEAD   0xDEAD
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_MAROON   0x0010
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_GREEN   0x0200
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_OLIVE   0x0210
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_ORANGE   0x021F
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_NAVY   0x4000
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_PURPLE   0x4010
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_TEAL   0x4200
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_GRAY   0x4210
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_MEDGRAY   0x5294
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_SILVER   0x6318
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_MONEYGREEN   0x6378
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_FUCHSIA   0x7C1F
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_SKYBLUE   0x7B34
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_CREAM   0x7BFF
 Rotate nclrs colors at clrs to the right by ror.
 
#define CLR_MASK   0x001F
 Rotate nclrs colors at clrs to the right by ror.
 
#define RED_MASK   0x001F
 Rotate nclrs colors at clrs to the right by ror.
 
#define RED_SHIFT   0
 Rotate nclrs colors at clrs to the right by ror.
 
#define GREEN_MASK   0x03E0
 Rotate nclrs colors at clrs to the right by ror.
 
#define GREEN_SHIFT   5
 Rotate nclrs colors at clrs to the right by ror.
 
#define BLUE_MASK   0x7C00
 Rotate nclrs colors at clrs to the right by ror.
 
#define BLUE_SHIFT   10
 Rotate nclrs colors at clrs to the right by ror.
 

Generic 8bpp bitmaps

void bmp8_plot (int x, int y, u32 clr, void *dstBase, uint dstP)
 Plot a single pixel on a 8-bit buffer.
 
void bmp8_hline (int x1, int y, int x2, u32 clr, void *dstBase, uint dstP)
 Draw a horizontal line on an 8bit buffer.
 
void bmp8_vline (int x, int y1, int y2, u32 clr, void *dstBase, uint dstP)
 Draw a vertical line on an 8bit buffer.
 
void bmp8_line (int x1, int y1, int x2, int y2, u32 clr, void *dstBase, uint dstP)
 Draw a line on an 8bit buffer.
 
void bmp8_rect (int left, int top, int right, int bottom, u32 clr, void *dstBase, uint dstP)
 Draw a rectangle in 8bit mode; internal routine.
 
void bmp8_frame (int left, int top, int right, int bottom, u32 clr, void *dstBase, uint dstP)
 Draw a rectangle in 8bit mode; internal routine.
 

Generic 16bpp bitmaps

void bmp16_plot (int x, int y, u32 clr, void *dstBase, uint dstP)
 Plot a single pixel on a 16-bit buffer.
 
void bmp16_hline (int x1, int y, int x2, u32 clr, void *dstBase, uint dstP)
 Draw a horizontal line on an 16bit buffer.
 
void bmp16_vline (int x, int y1, int y2, u32 clr, void *dstBase, uint dstP)
 Draw a vertical line on an 16bit buffer.
 
void bmp16_line (int x1, int y1, int x2, int y2, u32 clr, void *dstBase, uint dstP)
 Draw a line on an 16bit buffer.
 
void bmp16_rect (int left, int top, int right, int bottom, u32 clr, void *dstBase, uint dstP)
 Draw a rectangle in 16bit mode; internal routine.
 
void bmp16_frame (int left, int top, int right, int bottom, u32 clr, void *dstBase, uint dstP)
 Draw a rectangle in 16bit mode; internal routine.
 

Base Color constants

#define CLR_BLACK   0x0000
 
#define CLR_RED   0x001F
 
#define CLR_LIME   0x03E0
 
#define CLR_YELLOW   0x03FF
 
#define CLR_BLUE   0x7C00
 
#define CLR_MAG   0x7C1F
 
#define CLR_CYAN   0x7FE0
 
#define CLR_WHITE   0x7FFF
 

Detailed Description

Macro Definition Documentation

◆ BLUE_MASK

#define BLUE_MASK   0x7C00

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ BLUE_SHIFT

#define BLUE_SHIFT   10

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_CREAM

#define CLR_CREAM   0x7BFF

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_DEAD

#define CLR_DEAD   0xDEAD

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_FUCHSIA

#define CLR_FUCHSIA   0x7C1F

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_GRAY

#define CLR_GRAY   0x4210

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_GREEN

#define CLR_GREEN   0x0200

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_MAROON

#define CLR_MAROON   0x0010

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_MASK

#define CLR_MASK   0x001F

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_MEDGRAY

#define CLR_MEDGRAY   0x5294

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_MONEYGREEN

#define CLR_MONEYGREEN   0x6378

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_NAVY

#define CLR_NAVY   0x4000

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_OLIVE

#define CLR_OLIVE   0x0210

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_ORANGE

#define CLR_ORANGE   0x021F

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_PURPLE

#define CLR_PURPLE   0x4010

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_SILVER

#define CLR_SILVER   0x6318

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_SKYBLUE

#define CLR_SKYBLUE   0x7B34

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ CLR_TEAL

#define CLR_TEAL   0x4200

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ GREEN_MASK

#define GREEN_MASK   0x03E0

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ GREEN_SHIFT

#define GREEN_SHIFT   5

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ RED_MASK

#define RED_MASK   0x001F

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

◆ RED_SHIFT

#define RED_SHIFT   0

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

Function Documentation

◆ bmp16_frame()

void bmp16_frame ( int  left,
int  top,
int  right,
int  bottom,
u32  clr,
void *  dstBase,
uint  dstP 
)

Draw a rectangle in 16bit mode; internal routine.

Parameters
leftLeft side of rectangle;
topTop side of rectangle.
rightRight side of rectangle.
bottomBottom side of rectangle.
clrColor.
dstBaseCanvas pointer.
dstPCanvas pitch in bytes
Note
Does normalization, but not bounds checks.
PONDER: RB in- or exclusive?

References memset16().

Referenced by m3_frame(), m5_frame(), and se_frame().

◆ bmp16_hline()

void bmp16_hline ( int  x1,
int  y,
int  x2,
u32  clr,
void *  dstBase,
uint  dstP 
)

Draw a horizontal line on an 16bit buffer.

Parameters
x1First X-coord.
yY-coord.
x2Second X-coord.
clrColor.
dstBaseCanvas pointer (halfword-aligned plz).
dstPCanvas pitch in bytes.
Note
Does normalization, but not bounds checks.

References memset16().

Referenced by m3_hline(), m5_hline(), and se_hline().

◆ bmp16_line()

void bmp16_line ( int  x1,
int  y1,
int  x2,
int  y2,
u32  clr,
void *  dstBase,
uint  dstP 
)

Draw a line on an 16bit buffer.

Parameters
x1First X-coord.
y1First Y-coord.
x2Second X-coord.
y2Second Y-coord.
clrColor.
dstBaseCanvas pointer (halfword-aligned plz).
dstPCanvas pitch in bytes.
Note
Does normalization, but not bounds checks.

Referenced by m3_line(), and m5_line().

◆ bmp16_plot()

void bmp16_plot ( int  x,
int  y,
u32  clr,
void *  dstBase,
uint  dstP 
)

Plot a single pixel on a 16-bit buffer.

Parameters
xX-coord.
yY-coord.
clrColor.
dstBaseCanvas pointer (halfword-aligned plz).
dstPCanvas pitch in bytes.
Note
Slow as fuck. Inline plotting functionality if possible.

◆ bmp16_rect()

void bmp16_rect ( int  left,
int  top,
int  right,
int  bottom,
u32  clr,
void *  dstBase,
uint  dstP 
)

Draw a rectangle in 16bit mode; internal routine.

Parameters
leftLeft side of rectangle;
topTop side of rectangle.
rightRight side of rectangle.
bottomBottom side of rectangle.
clrColor.
dstBaseCanvas pointer.
dstPCanvas pitch in bytes
Note
Does normalization, but not bounds checks.

References memset16().

Referenced by m3_rect(), m5_rect(), and se_rect().

◆ bmp16_vline()

void bmp16_vline ( int  x,
int  y1,
int  y2,
u32  clr,
void *  dstBase,
uint  dstP 
)

Draw a vertical line on an 16bit buffer.

Parameters
xX-coord.
y1First Y-coord.
y2Second Y-coord.
clrColor.
dstBaseCanvas pointer (halfword-aligned plz).
dstPCanvas pitch in bytes.
Note
Does normalization, but not bounds checks.

Referenced by m3_vline(), m5_vline(), and se_vline().

◆ bmp8_frame()

void bmp8_frame ( int  left,
int  top,
int  right,
int  bottom,
u32  clr,
void *  dstBase,
uint  dstP 
)

Draw a rectangle in 8bit mode; internal routine.

Parameters
leftLeft side of rectangle;
topTop side of rectangle.
rightRight side of rectangle.
bottomBottom side of rectangle.
clrColor-index.
dstBaseCanvas pointer.
dstPCanvas pitch in bytes
Note
Does normalization, but not bounds checks.
PONDER: RB in- or exclusive?

References bmp8_hline(), and bmp8_vline().

Referenced by m4_frame().

◆ bmp8_hline()

void bmp8_hline ( int  x1,
int  y,
int  x2,
u32  clr,
void *  dstBase,
uint  dstP 
)

Draw a horizontal line on an 8bit buffer.

Parameters
x1First X-coord.
yY-coord.
x2Second X-coord.
clrColor index.
dstBaseCanvas pointer (halfword-aligned plz).
dstPcanvas pitch in bytes.
Note
Does normalization, but not bounds checks.

References dup8(), and memset16().

Referenced by bmp8_frame(), bmp8_line(), and m4_hline().

◆ bmp8_line()

void bmp8_line ( int  x1,
int  y1,
int  x2,
int  y2,
u32  clr,
void *  dstBase,
uint  dstP 
)

Draw a line on an 8bit buffer.

Parameters
x1First X-coord.
y1First Y-coord.
x2Second X-coord.
y2Second Y-coord.
clrColor index.
dstBaseCanvas pointer (halfword-aligned plz).
dstPCanvas pitch in bytes.
Note
Does normalization, but not bounds checks.

References bmp8_hline(), bmp8_plot(), and bmp8_vline().

Referenced by m4_line().

◆ bmp8_plot()

void bmp8_plot ( int  x,
int  y,
u32  clr,
void *  dstBase,
uint  dstP 
)

Plot a single pixel on a 8-bit buffer.

Parameters
xX-coord.
yY-coord.
clrColor.
dstBaseCanvas pointer (halfword-aligned plz).
dstPCanvas pitch in bytes.
Note
Slow as fuck. Inline plotting functionality if possible.

Referenced by bmp8_line().

◆ bmp8_rect()

void bmp8_rect ( int  left,
int  top,
int  right,
int  bottom,
u32  clr,
void *  dstBase,
uint  dstP 
)

Draw a rectangle in 8bit mode; internal routine.

Parameters
leftLeft side of rectangle;
topTop side of rectangle.
rightRight side of rectangle.
bottomBottom side of rectangle.
clrColor-index.
dstBaseCanvas pointer.
dstPCanvas pitch in bytes
Note
Does normalization, but not bounds checks.

References memset16().

Referenced by m4_rect().

◆ bmp8_vline()

void bmp8_vline ( int  x,
int  y1,
int  y2,
u32  clr,
void *  dstBase,
uint  dstP 
)

Draw a vertical line on an 8bit buffer.

Parameters
xX-coord.
y1First Y-coord.
y2Second Y-coord.
clrColor index.
dstBaseCanvas pointer (halfword-aligned plz).
dstPcanvas pitch in bytes.
Note
Does normalization, but not bounds checks.

Referenced by bmp8_frame(), bmp8_line(), and m4_vline().

◆ clr_adj_brightness()

void clr_adj_brightness ( COLOR dst,
const COLOR src,
uint  nclrs,
FIXED  bright 
)

Adjust brightness by bright.

Operation: color= color+dB;

Parameters
dstDestination color array
srcSource color array.
nclrsNumber of colors.
brightBrightness difference, dB (in .8f)
Note
Might be faster if preformed via lut.

References bf_clamp(), and RGB15().

◆ clr_adj_contrast()

void clr_adj_contrast ( COLOR dst,
const COLOR src,
uint  nclrs,
FIXED  contrast 
)

Adjust contrast by contrast.

Operation: color = color*(1+dC) - MAX*dC/2

Parameters
dstDestination color array
srcSource color array.
nclrsNumber of colors.
contrastContrast differencem dC (in .8f)
Note
Might be faster if preformed via lut.

References bf_clamp(), FIX_ONE, and RGB15().

◆ clr_adj_intensity()

void clr_adj_intensity ( COLOR dst,
const COLOR src,
uint  nclrs,
FIXED  intensity 
)

Adjust intensity by intensity.

Operation: color = (1+dI)*color.

Parameters
dstDestination color array
srcSource color array.
nclrsNumber of colors.
intensityIntensity difference, dI (in .8f)
Note
Might be faster if preformed via lut.

References bf_clamp(), FIX_ONE, and RGB15().

◆ clr_blend()

void clr_blend ( const COLOR srca,
const COLOR srcb,
COLOR dst,
uint  nclrs,
u32  alpha 
)

Blends color arrays srca and srcb into dst.

Specific transitional blending effects can be created by making a 'target' color array with other routines, then using alpha to morph into it.

Parameters
srcaSource array A.
srcbSource array B
dstDestination array.
nclrsNumber of colors.
alphaBlend weight (range: 0-32). 0 Means full srca

References BLUE_MASK, GREEN_MASK, and RED_MASK.

◆ clr_blend_fast()

IWRAM_CODE void clr_blend_fast ( COLOR srca,
COLOR srcb,
COLOR dst,
uint  nclrs,
u32  alpha 
)

Blends color arrays srca and srcb into dst.

Parameters
srcaSource array A.
srcbSource array B
dstDestination array.
nclrsNumber of colors.
alphaBlend weight (range: 0-32).
Note
Handles 2 colors per loop. Very fast.

◆ clr_fade()

void clr_fade ( const COLOR src,
COLOR  clr,
COLOR dst,
uint  nclrs,
u32  alpha 
)

Fades color arrays srca to clr into dst.

Parameters
srcSource array.
clrFinal color (at alpha=32).
dstDestination array.
nclrsNumber of colors.
alphaBlend weight (range: 0-32). 0 Means full srca

References BLUE_MASK, GREEN_MASK, and RED_MASK.

◆ clr_fade_fast()

IWRAM_CODE void clr_fade_fast ( COLOR src,
COLOR  clr,
COLOR dst,
uint  nclrs,
u32  alpha 
)

Fades color arrays srca to clr into dst.

Parameters
srcSource array.
clrFinal color (at alpha=32).
dstDestination array.
nclrsNumber of colors.
alphaBlend weight (range: 0-32).
Note
Handles 2 colors per loop. Very fast.

◆ clr_grayscale()

void clr_grayscale ( COLOR dst,
const COLOR src,
uint  nclrs 
)

Transform colors to grayscale.

Parameters
dstDestination color array
srcSource color array.
nclrsNumber of colors.

References RGB15().

Referenced by clr_rgbscale().

◆ clr_rgbscale()

void clr_rgbscale ( COLOR dst,
const COLOR src,
uint  nclrs,
COLOR  clr 
)

Transform colors to an rgb-scale.

clr indicates a color vector in RGB-space. Each source color is converted to a brightness value (i.e., grayscale) and then mapped onto that color vector. A grayscale is a special case of this, using a color with R=G=B.

Parameters
dstDestination color array
srcSource color array.
nclrsNumber of colors.
clrDestination color vector.

References clr_grayscale(), lu_div(), max(), and RGB15().

◆ clr_rotate()

void clr_rotate ( COLOR clrs,
uint  nclrs,
int  ror 
)

Rotate nclrs colors at clrs to the right by ror.

Note
I can't help but think there's a faster way ... I just can't see it atm.

References Mod().

◆ pal_gradient()

void pal_gradient ( COLOR pal,
int  first,
int  last 
)

Create a gradient between pal[first] and pal[last].

Parameters
palPalette to work on.
firstFirst index of gradient.
lastLast index of gradient.

References RGB15(), and SWAP.

Referenced by pal_gradient_ex().

◆ pal_gradient_ex()

void pal_gradient_ex ( COLOR pal,
int  first,
int  last,
COLOR  clr_first,
COLOR  clr_last 
)

Create a gradient between pal[first] and pal[last].

Parameters
palPalette to work on.
firstFirst index of gradient.
lastLast index of gradient.
clr_firstColor of first index.
clr_lastColor of last index.

References pal_gradient().