Banjo API 1.0.0-rc.2
Low-level C99 game development API
Loading...
Searching...
No Matches
pixel_mode.c
Go to the documentation of this file.
1
11
12#include <banjo/log.h>
13#include <banjo/main.h>
14#include <banjo/pixel.h>
15
16void display_value(bj_pixel_mode mode, uint8_t red, uint8_t green, uint8_t blue) {
17 // bj_get_pixel_value() converts 8-bit RGB components (0-255) into a packed
18 // integer value according to the specified pixel format. The packing order
19 // and bit depth vary by format.
20 const uint32_t val = bj_get_pixel_value(mode, red, green, blue);
21
22 // Convert the packed value to binary string for visualization of bit layout.
23 char binarystr[33] = {0};
24 for(size_t b = 0 ; b < 32 ; ++b) {
25 binarystr[31-b] = '0' + ((val >> b) & 0x01);
26 }
27
28 bj_info("R:%d, G:%d, B:%d -[0x%08x]--> %ld\t0x%08x\t0b%s",
29 red, green, blue, mode, 0, val, binarystr
30 );
31}
32
33int main(int argc, char* argv[]) {
34 (void)argc;
35 (void)argv;
36
37 // RGB565: 16-bit format with 5 bits red, 6 bits green, 5 bits blue.
38 // Uses less memory (2 bytes per pixel) but lower colour precision.
39 // Green gets 6 bits because human eyes are most sensitive to green.
43
44 // XRGB1555: 16-bit format with 1 unused bit, then 5 bits each for RGB.
45 // Also 2 bytes per pixel but with equal precision across all channels.
49
50 // XRGB8888: 32-bit format with 8 bits per channel (full precision).
51 // Uses 4 bytes per pixel but retains all 8 bits of input colour data.
52 // The 'X' byte is unused padding for alignment.
56
57 return 0;
58}
int main(int argc, char *argv[])
Definition audio_pcm.c:177
#define bj_info(...)
Log a message using the BJ_LOG_INFO level.
Definition log.h:141
uint32_t bj_get_pixel_value(enum bj_pixel_mode mode, uint8_t red, uint8_t green, uint8_t blue)
Returns an opaque value representing a pixel colour, given its RGB composition.
bj_pixel_mode
Representation of a pixel encoding.
Definition pixel.h:86
@ BJ_PIXEL_MODE_RGB565
16bpp 565-RGB
Definition pixel.h:93
@ BJ_PIXEL_MODE_XRGB8888
32bpp RGB
Definition pixel.h:94
@ BJ_PIXEL_MODE_XRGB1555
16bpp 555-RGB
Definition pixel.h:92
Logging utility functions.
Portable main() replacement with platform-aware entry shim.
Header file for general pixel manipulation facilities.
void display_value(bj_pixel_mode mode, uint8_t red, uint8_t green, uint8_t blue)
Definition pixel_mode.c:16