Skip to content

Commit dc84465

Browse files
committed
Add a palette ioctl.
1 parent f4e2c70 commit dc84465

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/ioctls/gfx.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ pub const COMMAND_MOVE_CURSOR: u64 = 3;
5555
/// Use [`draw_line_value`] to construct a value.
5656
pub const COMMAND_DRAW_LINE: u64 = 4;
5757

58+
/// Set a palette entry
59+
///
60+
/// The command contains [ <padding> | II | RR | GG | BB ]
61+
///
62+
/// II, RR, GG and BB are 8-bit values where II is the index into the 256 long
63+
/// palette, and RR, GG and BB are the 24-bit RGB colour for that index.
64+
///
65+
/// Use [`set_palette_value`] to construct a value.
66+
pub const COMMAND_SET_PALETTE: u64 = 5;
67+
5868
/// Calculate a 64-bit value argument for the [`COMMAND_CHUNKY_PLOT`] gfx ioctl
5969
pub fn chunky_plot_value(x: u16, y: u16, colour: u32) -> u64 {
6070
(x as u64) << 48 | (y as u64) << 32 | (colour & 0xFFFFFF) as u64
@@ -77,4 +87,13 @@ pub fn draw_line_value(end_x: u16, end_y: u16, colour: u32) -> u64 {
7787
(end_x as u64) << 48 | (end_y as u64) << 32 | (colour & 0xFFFFFF) as u64
7888
}
7989

90+
/// Calculate a 64-bit value argument for the [`COMMAND_SET_PALETTE`] gfx ioctl
91+
pub fn set_palette_value(index: u8, r: u8, g: u8, b: u8) -> u64 {
92+
let mut result = (index as u64) << 24;
93+
result |= (r as u64) << 16;
94+
result |= (g as u64) << 8;
95+
result |= b as u64;
96+
result
97+
}
98+
8099
// End of file

0 commit comments

Comments
 (0)