OldSchool Library
Drawing

Topics

 Main
 
 General
 
 Colors
 Color manipulation utilities.
 
 Low level drawing
 

Macros

#define oslRgbaGet8888(data, r, g, b, a)
 Extracts the R, G, B, A (Red, Green, Blue, Alpha) component values from a 32-bit color.
 
#define oslRgbaGet4444(data, r, g, b, a)
 Extracts R, G, B, A values from a 4444 color.
 
#define oslRgbaGet5551(data, r, g, b, a)
 Extracts R, G, B, A values from a 5551 color.
 
#define oslRgbGet5650(data, r, g, b)
 Extracts R, G, B values from a 5650 color.
 
#define oslRgbaGet4444f(data, r, g, b, a)
 Extracts R, G, B, A values from a 4444 color with finer precision.
 
#define oslRgbaGet5551f(data, r, g, b, a)
 Extracts R, G, B, A values from a 5551 color with finer precision.
 
#define oslRgbGet5650f(data, r, g, b)
 Extracts R, G, B values from a 5650 color with finer precision.
 

Detailed Description

Drawing operations in OSLib.

Macro Definition Documentation

◆ oslRgbaGet8888

#define oslRgbaGet8888 ( data,
r,
g,
b,
a )
Value:
((r) = ((data) & 0xff), (g) = (((data) >> 8) & 0xff), (b) = (((data) >> 16) & 0xff), (a) = (((data) >> 24) & 0xff))

Extracts the R, G, B, A (Red, Green, Blue, Alpha) component values from a 32-bit color.

This macro takes a 32-bit color value and extracts the individual 8-bit R, G, B, and A components. The extracted values are stored in the variables provided as the second to fifth arguments.

Parameters
dataThe 32-bit color value from which to extract the components.
rThe variable to store the red component (0-255).
gThe variable to store the green component (0-255).
bThe variable to store the blue component (0-255).
aThe variable to store the alpha component (0-255).
u32 color = RGBA(1, 2, 3, 4);
u8 red, green, blue, alpha;
oslRgbaGet8888(color, red, green, blue, alpha);
oslPrintf("%i %i %i %i", red, green, blue, alpha);
#define RGBA(r, v, b, a)
Creates a 32-bit color with alpha (transparency).
Definition drawing.h:451
#define oslRgbaGet8888(data, r, g, b, a)
Extracts the R, G, B, A (Red, Green, Blue, Alpha) component values from a 32-bit color.
Definition drawing.h:543
#define oslPrintf(format...)
Prints formatted text to the current position of the cursor.
Definition oslib.h:652

This example will print: 1 2 3 4.

◆ oslRgbaGet4444

#define oslRgbaGet4444 ( data,
r,
g,
b,
a )
Value:
((r) = ((data) & 0xf) << 4, (g) = (((data) >> 4) & 0xf) << 4, (b) = (((data) >> 8) & 0xf) << 4, (a) = (((data) >> 12) & 0xf) << 4)

Extracts R, G, B, A values from a 4444 color.

This macro takes a 16-bit color value in 4444 format and extracts the individual 8-bit R, G, B, and A components. The 4-bit components are expanded to 8-bit by multiplying with 16.

Parameters
dataThe 16-bit color value in 4444 format.
rThe variable to store the red component (0-255).
gThe variable to store the green component (0-255).
bThe variable to store the blue component (0-255).
aThe variable to store the alpha component (0-255).
u32 color = RGBA12(255, 128, 0, 1);
u8 red, green, blue, alpha;
oslRgbGet4444(color, red, green, blue, alpha);
oslPrintf("%i %i %i %i", red, green, blue, alpha);
#define RGBA12(r, v, b, a)
Creates a 12-bit color with alpha.
Definition drawing.h:477

This example will print: 240 128 0 0. The alpha value was 1 but was lost due to precision limits in 12-bit mode. The red color value was 255 but lost precision due to 12-bit conversion, resulting in 240 instead of 255. For more precise results, consider using the 'f' alternate routines like oslRgbaGet4444f.

◆ oslRgbaGet5551

#define oslRgbaGet5551 ( data,
r,
g,
b,
a )
Value:
((r) = ((data) & 0x1f) << 3, (g) = (((data) >> 5) & 0x1f) << 3, (b) = (((data) >> 10) & 0x1f) << 3, (a) = (((data) >> 15) & 0x1) << 7)

Extracts R, G, B, A values from a 5551 color.

This macro takes a 16-bit color value in 5551 format and extracts the individual 8-bit R, G, B, and A components. The 5-bit components are expanded to 8-bit by multiplying with 8, and the 1-bit alpha is expanded to 8-bit by multiplying with 128.

Parameters
dataThe 16-bit color value in 5551 format.
rThe variable to store the red component (0-255).
gThe variable to store the green component (0-255).
bThe variable to store the blue component (0-255).
aThe variable to store the alpha component (0-255).
u32 color = RGBA15(31, 31, 31, 1);
u8 red, green, blue, alpha;
oslRgbaGet5551(color, red, green, blue, alpha);
oslPrintf("%i %i %i %i", red, green, blue, alpha);
#define RGBA15(r, v, b, a)
Creates a 15-bit color with alpha.
Definition drawing.h:503
#define oslRgbaGet5551(data, r, g, b, a)
Extracts R, G, B, A values from a 5551 color.
Definition drawing.h:593

This example will print the expanded values of the 5551 format color.

◆ oslRgbGet5650

#define oslRgbGet5650 ( data,
r,
g,
b )
Value:
((r) = ((data) & 0x1f) << 3, (g) = (((data) >> 5) & 0x3f) << 2, (b) = (((data) >> 11) & 0x1f) << 3)

Extracts R, G, B values from a 5650 color.

This macro takes a 16-bit color value in 5650 format and extracts the individual 8-bit R, G, and B components. The 5-bit R and B components are expanded to 8-bit by multiplying with 8, and the 6-bit G component is expanded to 8-bit by multiplying with 4.

Parameters
dataThe 16-bit color value in 5650 format.
rThe variable to store the red component (0-255).
gThe variable to store the green component (0-255).
bThe variable to store the blue component (0-255).
u32 color = RGB16(31, 63, 31);
u8 red, green, blue;
oslRgbGet5650(color, red, green, blue);
oslPrintf("%i %i %i", red, green, blue);
#define RGB16(r, v, b)
Creates a 16-bit color.
Definition drawing.h:516
#define oslRgbGet5650(data, r, g, b)
Extracts R, G, B values from a 5650 color.
Definition drawing.h:616

This example will print the expanded values of the 5650 format color.

◆ oslRgbaGet4444f

#define oslRgbaGet4444f ( data,
r,
g,
b,
a )
Value:
((r) = ((data) & 0xf) << 4 | ((data) & 0xf), (g) = (((data) >> 4) & 0xf) << 4 | (((data) >> 4) & 0xf), (b) = (((data) >> 8) & 0xf) << 4 | (((data) >> 8) & 0xf), (a) = (((data) >> 12) & 0xf) << 4 | (((data) >> 12) & 0xf))

Extracts R, G, B, A values from a 4444 color with finer precision.

This macro extracts the R, G, B, and A components from a 16-bit color value in 4444 format. It expands the 4-bit components to 8-bit values by using both bit-shifting and masking techniques to provide better color accuracy.

Parameters
dataThe 16-bit color value in 4444 format.
rThe variable to store the red component (0-255).
gThe variable to store the green component (0-255).
bThe variable to store the blue component (0-255).
aThe variable to store the alpha component (0-255).
u32 color = RGBA12(255, 128, 0, 1);
u8 red, green, blue, alpha;
oslRgbaGet4444f(color, red, green, blue, alpha);
oslPrintf("%i %i %i %i", red, green, blue, alpha);
#define oslRgbaGet4444f(data, r, g, b, a)
Extracts R, G, B, A values from a 4444 color with finer precision.
Definition drawing.h:640

This example will provide more accurate color values compared to oslRgbaGet4444.

◆ oslRgbaGet5551f

#define oslRgbaGet5551f ( data,
r,
g,
b,
a )
Value:
((r) = ((data) & 0x1f) << 3 | ((data) & 0x1f) >> 2, (g) = (((data) >> 5) & 0x1f) << 3 | (((data) >> 5) & 0x1f) >> 2, (b) = (((data) >> 10) & 0x1f) << 3 | (((data) >> 10) & 0x1f) >> 2, (a) = (((data) >> 15) & 0x1) * 255)

Extracts R, G, B, A values from a 5551 color with finer precision.

This macro extracts the R, G, B, and A components from a 16-bit color value in 5551 format. It provides more accurate color values by expanding the 5-bit components and the 1-bit alpha using bit-shifting and masking.

Parameters
dataThe 16-bit color value in 5551 format.
rThe variable to store the red component (0-255).
gThe variable to store the green component (0-255).
bThe variable to store the blue component (0-255).
aThe variable to store the alpha component (0-255).
u32 color = RGBA15(31, 31, 31, 1);
u8 red, green, blue, alpha;
oslRgbaGet5551f(color, red, green, blue, alpha);
oslPrintf("%i %i %i %i", red, green, blue, alpha);
#define oslRgbaGet5551f(data, r, g, b, a)
Extracts R, G, B, A values from a 5551 color with finer precision.
Definition drawing.h:664

This example will provide more accurate color values compared to oslRgbaGet5551.

◆ oslRgbGet5650f

#define oslRgbGet5650f ( data,
r,
g,
b )
Value:
((r) = ((data) & 0x1f) << 3 | ((data) & 0x1f) >> 2, (g) = (((data) >> 5) & 0x3f) << 2 | (((data) >> 5) & 0x3f) >> 4, (b) = (((data) >> 11) & 0x1f) << 3 | (((data) >> 10) & 0x1f) >> 2)

Extracts R, G, B values from a 5650 color with finer precision.

This macro extracts the R, G, and B components from a 16-bit color value in 5650 format. It expands the 5-bit R and B components and the 6-bit G component to 8-bit values for more accurate color representation.

Parameters
dataThe 16-bit color value in 5650 format.
rThe variable to store the red component (0-255).
gThe variable to store the green component (0-255).
bThe variable to store the blue component (0-255).
u32 color = RGB16(31, 63, 31);
u8 red, green, blue;
oslRgbGet5650f(color, red, green, blue);
oslPrintf("%i %i %i", red, green, blue);
#define oslRgbGet5650f(data, r, g, b)
Extracts R, G, B values from a 5650 color with finer precision.
Definition drawing.h:687

This example will provide more accurate color values compared to oslRgbGet5650.