From da34965fcd21c219db11405e77dfc117af17ee1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Tue, 11 Aug 2020 12:27:40 +0200 Subject: [PATCH 1/8] rust: implement pixel functions --- rust/libnotcurses-sys/src/pixel.rs | 168 +++++++++++++---------------- rust/libnotcurses-sys/src/types.rs | 1 + 2 files changed, 75 insertions(+), 94 deletions(-) diff --git a/rust/libnotcurses-sys/src/pixel.rs b/rust/libnotcurses-sys/src/pixel.rs index f2224bf97..70be5bc64 100644 --- a/rust/libnotcurses-sys/src/pixel.rs +++ b/rust/libnotcurses-sys/src/pixel.rs @@ -1,102 +1,82 @@ +//! The ncpixel API facilitates direct management of the pixels within an +//! ncvisual (ncvisuals keep a backing store of 32-bit RGBA pixels, and render +//! them down to terminal graphics in ncvisual_render()). +// +// - NOTE: The pixel color & alpha components are u8 instead of u32. +// Because of type enforcing, some runtime checks are now unnecessary. +// +// - NOTE: None of the functions can't fail anymore and don't have to return an error. +// +// // functions already exported by bindgen : 0 // ----------------------------------------- // -// static inline functions to reimplement: 3 -// ----------------------------------------- -// - finished : 0 -// - remaining: 10 +// static inline functions to reimplement: 10 +// ------------------------------------------ +// - finished : 10 +// - remaining: 0 // --------------- (+) implemented (#) + unit test (x) wont implement -// ncpixel -// ncpixel_a -// ncpixel_b -// ncpixel_g -// ncpixel_r -// ncpixel_set_a -// ncpixel_set_b -// ncpixel_set_g -// ncpixel_set_r -// ncpixel_set_rgb +//+ncpixel +//+ncpixel_a +//+ncpixel_b +//+ncpixel_g +//+ncpixel_r +//+ncpixel_set_a +//+ncpixel_set_b +//+ncpixel_set_g +//+ncpixel_set_r +//+ncpixel_set_rgb +use crate::types::{Color, Pixel}; -// use crate as ffi; -// use crate::types::{ChannelPair, IntResult}; +/// Get an RGB pixel from RGB values +pub fn ncpixel(r: Color, g: Color, b: Color) -> Pixel { + 0xff000000 as Pixel | r as Pixel | (b as Pixel) << 8 | (g as Pixel) << 16 +} +/// Extract the 8-bit alpha component from a pixel +pub fn ncpixel_a(pixel: Pixel) -> Color { + ((pixel & 0xff0000ff) >> 24) as Color +} -// // The ncpixel API facilitates direct management of the pixels within an -// // ncvisual (ncvisuals keep a backing store of 32-bit RGBA pixels, and render -// // them down to terminal graphics in ncvisual_render()). -// static inline uint32_t -// ncpixel(int r, int g, int b){ -// if(r < 0) r = 0; -// if(r > 255) r = 255; -// if(g < 0) g = 0; -// if(g > 255) g = 255; -// if(b < 0) b = 0; -// if(b > 255) b = 255; -// return 0xff000000ul | r | (b << 8u) | (g << 16u); -// } -// -// static inline unsigned -// ncpixel_a(uint32_t pixel){ -// return (pixel & 0xff0000fful) >> 24u; -// } -// -// static inline unsigned -// ncpixel_r(uint32_t pixel){ -// return (pixel & 0x000000fful); -// } -// -// static inline int -// ncpixel_g(uint32_t pixel){ -// return (pixel & 0x00ff0000ul) >> 16u; -// } -// -// static inline int -// ncpixel_b(uint32_t pixel){ -// return (pixel & 0x0000ff00ul) >> 8u; -// } -// -// static inline int -// ncpixel_set_a(uint32_t* pixel, int a){ -// if(a > 255 || a < 0){ -// return -1; -// } -// *pixel = (*pixel & 0x00fffffful) | (a << 24u); -// return 0; -// } -// -// static inline int -// ncpixel_set_r(uint32_t* pixel, int r){ -// if(r > 255 || r < 0){ -// return -1; -// } -// *pixel = (*pixel & 0xffffff00ul) | r; -// return 0; -// } -// -// static inline int -// ncpixel_set_g(uint32_t* pixel, int g){ -// if(g > 255 || g < 0){ -// return -1; -// } -// *pixel = (*pixel & 0xff00fffful) | (g << 16u); -// return 0; -// } -// -// static inline int -// ncpixel_set_b(uint32_t* pixel, int b){ -// if(b > 255 || b < 0){ -// return -1; -// } -// *pixel = (*pixel & 0xffff00fful) | (b << 8u); -// return 0; -// } -// -// // set the RGB values of an RGB pixel -// static inline int -// ncpixel_set_rgb(uint32_t* pixel, int r, int g, int b){ -// if(ncpixel_set_r(pixel, r) || ncpixel_set_g(pixel, g) || ncpixel_set_b(pixel, b)){ -// return -1; -// } -// return 0; -// } +/// Extract the 8 bit green component from a pixel +pub fn ncpixel_g(pixel: Pixel) -> Color { + ((pixel & 0x00ff0000) >> 16 ) as Color +} + +/// Extract the 8 bit blue component from a pixel +pub fn ncpixel_b(pixel: Pixel) -> Color { + ((pixel & 0x0000ff00) >> 8 ) as Color +} + +/// Extract the 8 bit red component from a pixel +pub fn ncpixel_r(pixel: Pixel) -> Color { + (pixel & 0x000000ff) as Color +} + +/// Set the 8-bit alpha component on a pixel +pub fn ncpixel_set_a(pixel: &mut Pixel, alpha: Color) { + *pixel = (*pixel & 0x00ffffff) | ((alpha as Pixel) << 24); +} + +/// Set the 8-bit green component on a pixel +pub fn ncpixel_set_g(pixel: &mut Pixel, green: Color) { + *pixel = (*pixel & 0xff00ffff) | ((green as Pixel) << 16); +} + +/// Set the 8-bit blue component on a pixel +pub fn ncpixel_set_b(pixel: &mut Pixel, blue: Color) { + *pixel = (*pixel & 0xffff00ff) | ((blue as Pixel) << 8); +} + +/// Set the 8-bit red component on a pixel +pub fn ncpixel_set_r(pixel: &mut Pixel, red: Color) { + *pixel = (*pixel & 0xffffff00) | red as Pixel; +} + +/// set the RGB values of an RGB pixel +pub fn ncpixel_set_rgb(pixel: &mut Pixel, red: Color, green: Color, blue: Color) { + ncpixel_set_r(pixel, red); + ncpixel_set_g(pixel, green); + ncpixel_set_b(pixel, blue); +} diff --git a/rust/libnotcurses-sys/src/types.rs b/rust/libnotcurses-sys/src/types.rs index b757b70ad..7deaa7124 100644 --- a/rust/libnotcurses-sys/src/types.rs +++ b/rust/libnotcurses-sys/src/types.rs @@ -3,4 +3,5 @@ pub type ChannelPair = u64; pub type Color = u8; pub type Rgb = u32; pub type Alpha = u32; +pub type Pixel = u32; pub type IntResult = i32; // -1 == err From ec92d13306ae8f3ba448094cd5288963a069b427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Tue, 11 Aug 2020 14:25:35 +0200 Subject: [PATCH 2/8] rust: improve info headers --- rust/libnotcurses-sys/src/cells.rs | 6 +++--- rust/libnotcurses-sys/src/channel.rs | 8 ++++---- rust/libnotcurses-sys/src/key.rs | 6 ++++-- rust/libnotcurses-sys/src/nc.rs | 6 +++--- rust/libnotcurses-sys/src/palette.rs | 6 +++--- rust/libnotcurses-sys/src/pixel.rs | 6 +++--- rust/libnotcurses-sys/src/plane.rs | 6 +++--- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/rust/libnotcurses-sys/src/cells.rs b/rust/libnotcurses-sys/src/cells.rs index 6fecb39b7..b91166a84 100644 --- a/rust/libnotcurses-sys/src/cells.rs +++ b/rust/libnotcurses-sys/src/cells.rs @@ -8,9 +8,9 @@ // - cells_rounded_box // // static inline functions to reimplement: 45 -// ------------------------------------------ -// - finished : ±2 -// - remaining: 43 +// ------------------------------------------ (done / wont / remaining) +// - implement : 2 / 0 / 43 +// - unit tests: 0 / 0 / 45 // --------------- (+) implemented (#) + unit test (x) wont implement // cell_bchannel // cell_bg diff --git a/rust/libnotcurses-sys/src/channel.rs b/rust/libnotcurses-sys/src/channel.rs index 802948d11..c9ad8cad8 100644 --- a/rust/libnotcurses-sys/src/channel.rs +++ b/rust/libnotcurses-sys/src/channel.rs @@ -25,9 +25,9 @@ // ------------------------------------------ // // static inline functions to reimplement: 38 -// ------------------------------------------ -// - finished : 37 -// - remaining: 1 +// ------------------------------------------ (done / wont / remaining) +// - implement : 34 / 3 / 1 +// - unit tests: 14 / 0 / 21 // --------------- (+) implemented (#) + unit test (x) wont implement //#channel_alpha //#channel_b @@ -109,7 +109,7 @@ pub fn channel_set_rgb(channel: &mut Channel, r: Color, g: Color, b: Color) { *channel = (*channel & !ffi::CELL_BG_RGB_MASK) | ffi::CELL_BGDEFAULT_MASK | rgb; } -/// Same as chennel_set_rgb(), but provide an assembled, packed 24 bits of rgb. +/// Same as channel_set_rgb(), but provide an assembled, packed 24 bits of rgb. // TODO: TEST #[inline] pub fn channel_set(channel: &mut Channel, rgb: Rgb) -> IntResult { diff --git a/rust/libnotcurses-sys/src/key.rs b/rust/libnotcurses-sys/src/key.rs index 358422214..1cef3cf9e 100644 --- a/rust/libnotcurses-sys/src/key.rs +++ b/rust/libnotcurses-sys/src/key.rs @@ -1,8 +1,10 @@ // functions already exported by bindgen : 0 +// ------------------------------------------ // // static inline functions to reimplement: 2 -// - finished : 2 -// - remaining: 0 +// ------------------------------------------ (done / wont / remaining) +// - implement : 2 / 0 / 0 +// - unit tests: 0 / 0 / 2 // --------------- (+) implemented (#) + unit test (x) wont implement //+nckey_mouse_p //+nckey_supppuab_p diff --git a/rust/libnotcurses-sys/src/nc.rs b/rust/libnotcurses-sys/src/nc.rs index d5fac9fd9..4b4c55f26 100644 --- a/rust/libnotcurses-sys/src/nc.rs +++ b/rust/libnotcurses-sys/src/nc.rs @@ -37,9 +37,9 @@ // notcurses_version_components // // static inline functions to reimplement: 4 -// ----------------------------------------- -// - finished : 0 -// - remaining: 4 +// ----------------------------------------- (done / wont / remaining) +// - implement : 0 / 0 / 4 +// - unit tests: 0 / 0 / 4 // --------------- (+) implemented (#) + unit test (x) wont implement // notcurses_getc_blocking // notcurses_getc_nblock diff --git a/rust/libnotcurses-sys/src/palette.rs b/rust/libnotcurses-sys/src/palette.rs index 1aea26be0..a35266121 100644 --- a/rust/libnotcurses-sys/src/palette.rs +++ b/rust/libnotcurses-sys/src/palette.rs @@ -10,9 +10,9 @@ // palette256_use // // static inline functions to reimplement: 3 -// ----------------------------------------- -// - finished : 1 -// - remaining: 2 +// ----------------------------------------- (done / wont / remaining) +// - implement : 1 / 0 / 2 +// - unit tests: 0 / 0 / 3 // --------------- (+) implemented (#) + unit test (x) wont implement //+palette256_get_rgb // palette256_set diff --git a/rust/libnotcurses-sys/src/pixel.rs b/rust/libnotcurses-sys/src/pixel.rs index 70be5bc64..1409de0d7 100644 --- a/rust/libnotcurses-sys/src/pixel.rs +++ b/rust/libnotcurses-sys/src/pixel.rs @@ -12,9 +12,9 @@ // ----------------------------------------- // // static inline functions to reimplement: 10 -// ------------------------------------------ -// - finished : 10 -// - remaining: 0 +// ------------------------------------------ (done / wont / remaining) +// - implement : 10 / 0 / 0 +// - unit tests: 0 / 0 / 10 // --------------- (+) implemented (#) + unit test (x) wont implement //+ncpixel //+ncpixel_a diff --git a/rust/libnotcurses-sys/src/plane.rs b/rust/libnotcurses-sys/src/plane.rs index b56943b95..94f50ea3a 100644 --- a/rust/libnotcurses-sys/src/plane.rs +++ b/rust/libnotcurses-sys/src/plane.rs @@ -88,9 +88,9 @@ // ncplane_yx // // static inline functions to reimplement: 42 -// ------------------------------------------ -// - finished : ±4 -// - remaining: 38 +// ------------------------------------------ (done / wont / remaining) +// - implement : 4 / 0 / 38 +// - unit tests: 0 / 0 / 42 // --------------- (+) implemented (#) + unit test (x) wont implement // ncplane_align // ncplane_at_cursor_cell From 6424e453aa39590285ae117967a304d16036d0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Tue, 11 Aug 2020 14:31:57 +0200 Subject: [PATCH 3/8] rust: add test modules skeletons --- rust/libnotcurses-sys/src/cells.rs | 12 ++++++++++++ rust/libnotcurses-sys/src/key.rs | 12 ++++++++++++ rust/libnotcurses-sys/src/nc.rs | 11 +++++++++++ rust/libnotcurses-sys/src/palette.rs | 12 ++++++++++++ rust/libnotcurses-sys/src/pixel.rs | 13 +++++++++++++ rust/libnotcurses-sys/src/plane.rs | 12 ++++++++++++ 6 files changed, 72 insertions(+) diff --git a/rust/libnotcurses-sys/src/cells.rs b/rust/libnotcurses-sys/src/cells.rs index b91166a84..0ed8984f5 100644 --- a/rust/libnotcurses-sys/src/cells.rs +++ b/rust/libnotcurses-sys/src/cells.rs @@ -449,3 +449,15 @@ pub fn cells_load_box( // cell_bg_palindex_p(const cell* cl){ // return channels_bg_palindex_p(cl->channels); // } + +#[cfg(test)] +mod test { + // use super::ffi; + // use serial_test::serial; + /* + #[test] + #[serial] + fn () { + } + */ +} diff --git a/rust/libnotcurses-sys/src/key.rs b/rust/libnotcurses-sys/src/key.rs index 1cef3cf9e..60f208e21 100644 --- a/rust/libnotcurses-sys/src/key.rs +++ b/rust/libnotcurses-sys/src/key.rs @@ -22,3 +22,15 @@ pub fn nckey_supppuab_p(w: u32)-> bool { pub fn nckey_mouse_p(r: u32)-> bool { r >= ffi::NCKEY_BUTTON1 && r <= ffi::NCKEY_RELEASE } + +#[cfg(test)] +mod test { + // use super::ffi; + // use serial_test::serial; + /* + #[test] + #[serial] + fn () { + } + */ +} diff --git a/rust/libnotcurses-sys/src/nc.rs b/rust/libnotcurses-sys/src/nc.rs index 4b4c55f26..d504c9e55 100644 --- a/rust/libnotcurses-sys/src/nc.rs +++ b/rust/libnotcurses-sys/src/nc.rs @@ -84,3 +84,14 @@ // ncplane_dim_yx(notcurses_stdplane_const(n), rows, cols); // } +#[cfg(test)] +mod test { + // use super::ffi; + // use serial_test::serial; + /* + #[test] + #[serial] + fn () { + } + */ +} diff --git a/rust/libnotcurses-sys/src/palette.rs b/rust/libnotcurses-sys/src/palette.rs index a35266121..e02b4c8e6 100644 --- a/rust/libnotcurses-sys/src/palette.rs +++ b/rust/libnotcurses-sys/src/palette.rs @@ -42,3 +42,15 @@ pub fn palette256_set_rgb(palette: &mut ffi::palette256, idx: usize, r: Color, g // } // return channel_rgb(p->chans[idx], r, g, b); // } + +#[cfg(test)] +mod test { + // use super::ffi; + // use serial_test::serial; + /* + #[test] + #[serial] + fn () { + } + */ +} diff --git a/rust/libnotcurses-sys/src/pixel.rs b/rust/libnotcurses-sys/src/pixel.rs index 1409de0d7..4d3a75d4d 100644 --- a/rust/libnotcurses-sys/src/pixel.rs +++ b/rust/libnotcurses-sys/src/pixel.rs @@ -80,3 +80,16 @@ pub fn ncpixel_set_rgb(pixel: &mut Pixel, red: Color, green: Color, blue: Color) ncpixel_set_g(pixel, green); ncpixel_set_b(pixel, blue); } + + +#[cfg(test)] +mod test { + // use super::ffi; + // use serial_test::serial; + /* + #[test] + #[serial] + fn () { + } + */ +} diff --git a/rust/libnotcurses-sys/src/plane.rs b/rust/libnotcurses-sys/src/plane.rs index 94f50ea3a..ad7d8e3b3 100644 --- a/rust/libnotcurses-sys/src/plane.rs +++ b/rust/libnotcurses-sys/src/plane.rs @@ -652,3 +652,15 @@ pub fn ncplane_perimeter( // x + xlen - 1, ctlword); // } // + +#[cfg(test)] +mod test { + // use super::ffi; + // use serial_test::serial; + /* + #[test] + #[serial] + fn () { + } + */ +} From dbec390facea2834aa6550a2899d7a74a6875396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Tue, 11 Aug 2020 16:41:16 +0200 Subject: [PATCH 4/8] rust: improve some channel functions Functions `channel_set()`, `channels_set_fg()`, `channels_set_bg()` don't return an error anymore. Instead of failing when the rgb value has any of the last 8 bits set, now it just ignores those bits. --- rust/libnotcurses-sys/src/channel.rs | 30 +++++++++------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/rust/libnotcurses-sys/src/channel.rs b/rust/libnotcurses-sys/src/channel.rs index c9ad8cad8..06e656d82 100644 --- a/rust/libnotcurses-sys/src/channel.rs +++ b/rust/libnotcurses-sys/src/channel.rs @@ -6,6 +6,9 @@ // - `channel_set_rgb()` // - `channels_set_fg_rgb()` // - `channels_set_bg_rgb()` +// - `channel_set()` +// - `channels_set_fg()` +// - `channels_set_bg()` // // - NOTE: These functions were therefore deemed unnecessary to implement: // - `channel_set_rgb_clipped()` @@ -14,9 +17,6 @@ // // - These functions still return an integer error result: // - `channel_set_alpha()` -// - `channel_set_rgb()` -// - `channels_set_fg()` -// - `channels_set_bg()` // - `channels_set_fg_alpha()` // - `channels_set_bg_alpha()` // --------------------------------------------------------------------------------------- @@ -112,12 +112,8 @@ pub fn channel_set_rgb(channel: &mut Channel, r: Color, g: Color, b: Color) { /// Same as channel_set_rgb(), but provide an assembled, packed 24 bits of rgb. // TODO: TEST #[inline] -pub fn channel_set(channel: &mut Channel, rgb: Rgb) -> IntResult { - if rgb > 0xffffff_u32 { - return -1; - } - *channel = (*channel & !ffi::CELL_BG_RGB_MASK) | ffi::CELL_BGDEFAULT_MASK | rgb; - 0 +pub fn channel_set(channel: &mut Channel, rgb: Rgb) { + *channel = (*channel & !ffi::CELL_BG_RGB_MASK) | ffi::CELL_BGDEFAULT_MASK | (rgb & 0x00ffffff); } /// Extract the 2-bit alpha component from a 32-bit channel. @@ -261,13 +257,10 @@ pub fn channels_set_fg_rgb(channels: &mut ChannelPair, r: Color, g: Color, b: Co /// Same as channels_set_fg_rgb but but set an assembled 24 bit channel at once. // TODO: TEST #[inline] -pub fn channels_set_fg(channels: &mut ChannelPair, rgb: Rgb) -> IntResult { +pub fn channels_set_fg(channels: &mut ChannelPair, rgb: Rgb) { let mut channel = channels_fchannel(*channels); - if channel_set(&mut channel, rgb) < 0 { - return -1; - } + channel_set(&mut channel, rgb); *channels = (channel as u64) << 32 | *channels & 0xffffffff_u64; - 0 } /// Set the r, g, and b channels for the background component of this 64-bit @@ -283,13 +276,10 @@ pub fn channels_set_bg_rgb(channels: &mut ChannelPair, r: Color, g: Color, b: Co /// Same as channels_set_bg_rgb but but set an assembled 24 bit channel at once. // TODO: TEST #[inline] -pub fn channels_set_bg(channels: &mut ChannelPair, rgb: Rgb) -> IntResult { +pub fn channels_set_bg(channels: &mut ChannelPair, rgb: Rgb) { let mut channel = channels_bchannel(*channels); - if channel_set(&mut channel, rgb) < 0 { - return -1; - } + channel_set(&mut channel, rgb); channels_set_bchannel(channels, channel); - 0 } /// Set the 2-bit alpha component of the foreground channel. @@ -370,7 +360,6 @@ pub fn channels_set_bg_default(channels: &mut ChannelPair) -> ChannelPair { *channels } - /// Returns the result of blending two channels. 'blends' indicates how heavily /// 'c1' ought be weighed. If 'blends' is 0, 'c1' will be entirely replaced by /// 'c2'. If 'c1' is otherwise the default color, 'c1' will not be touched, @@ -408,7 +397,6 @@ pub fn channels_set_bg_default(channels: &mut ChannelPair) -> ChannelPair { // return c1; // } - #[cfg(test)] mod test { use super::{ffi, Channel, ChannelPair}; From 7abda11404248b4a5e3858929c810226347e8279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Tue, 11 Aug 2020 16:59:39 +0200 Subject: [PATCH 5/8] add comments for ncpixel functions --- include/notcurses/notcurses.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index e706aee3f..f954c0f7e 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -2361,6 +2361,8 @@ API int ncblit_bgrx(const void* data, int linesize, // The ncpixel API facilitates direct management of the pixels within an // ncvisual (ncvisuals keep a backing store of 32-bit RGBA pixels, and render // them down to terminal graphics in ncvisual_render()). + +// Extract the 8-bit alpha component from a pixel static inline uint32_t ncpixel(int r, int g, int b){ if(r < 0) r = 0; @@ -2372,26 +2374,31 @@ ncpixel(int r, int g, int b){ return 0xff000000ul | r | (b << 8u) | (g << 16u); } +// Extract the 8-bit alpha component from a pixel static inline unsigned ncpixel_a(uint32_t pixel){ return (pixel & 0xff0000fful) >> 24u; } +// Extract the 8 bit red component from a pixel static inline unsigned ncpixel_r(uint32_t pixel){ return (pixel & 0x000000fful); } +// Extract the 8 bit green component from a pixel static inline int ncpixel_g(uint32_t pixel){ return (pixel & 0x00ff0000ul) >> 16u; } +// Extract the 8 bit blue component from a pixel static inline int ncpixel_b(uint32_t pixel){ return (pixel & 0x0000ff00ul) >> 8u; } +// Set the 8-bit alpha component of a pixel static inline int ncpixel_set_a(uint32_t* pixel, int a){ if(a > 255 || a < 0){ @@ -2401,6 +2408,7 @@ ncpixel_set_a(uint32_t* pixel, int a){ return 0; } +// Set the 8-bit red component of a pixel static inline int ncpixel_set_r(uint32_t* pixel, int r){ if(r > 255 || r < 0){ @@ -2410,6 +2418,7 @@ ncpixel_set_r(uint32_t* pixel, int r){ return 0; } +// Set the 8-bit green component of a pixel static inline int ncpixel_set_g(uint32_t* pixel, int g){ if(g > 255 || g < 0){ @@ -2419,6 +2428,7 @@ ncpixel_set_g(uint32_t* pixel, int g){ return 0; } +// Set the 8-bit blue component of a pixel static inline int ncpixel_set_b(uint32_t* pixel, int b){ if(b > 255 || b < 0){ From 7070e532d6829e59feb97bc7828e93448047f938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Tue, 11 Aug 2020 17:04:09 +0200 Subject: [PATCH 6/8] fix typos --- include/notcurses/notcurses.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index f954c0f7e..8a93e8d18 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -2607,14 +2607,14 @@ API void notcurses_cursor_disable(struct notcurses* nc); // Palette API. Some terminals only support 256 colors, but allow the full // palette to be specified with arbitrary RGB colors. In all cases, it's more // performant to use indexed colors, since it's much less data to write to the -// terminal. If you can limit yourself to 256 colors, that' probably best. +// terminal. If you can limit yourself to 256 colors, that's probably best. typedef struct palette256 { // We store the RGB values as a regular ol' channel uint32_t chans[NCPALETTESIZE]; } palette256; -// Create a new palette store. It will be initialized with notcurses's best +// Create a new palette store. It will be initialized with notcurses' best // knowledge of the currently configured palette. API palette256* palette256_new(struct notcurses* nc); From 03f2e7c8716c989c8a54373c91afe6e3ef17092b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Tue, 11 Aug 2020 18:29:49 +0200 Subject: [PATCH 7/8] rust: implement palette functions --- rust/libnotcurses-sys/src/palette.rs | 58 +++++++++++++++++----------- rust/libnotcurses-sys/src/types.rs | 1 + 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/rust/libnotcurses-sys/src/palette.rs b/rust/libnotcurses-sys/src/palette.rs index e02b4c8e6..1557d20d4 100644 --- a/rust/libnotcurses-sys/src/palette.rs +++ b/rust/libnotcurses-sys/src/palette.rs @@ -1,6 +1,5 @@ // --------------------------------------------------------------------------------------- -// NOTE: These functions now can't fail and dont't have to return an error: -// - `palette256_set_rgb()` +// NOTE: Now none of these functions can't fail and therefore don't return errors. // --------------------------------------------------------------------------------------- // // functions already exported by bindgen : 3 @@ -15,33 +14,48 @@ // - unit tests: 0 / 0 / 3 // --------------- (+) implemented (#) + unit test (x) wont implement //+palette256_get_rgb -// palette256_set -// palette256_set_rgb +//+palette256_set +//+palette256_set_rgb use crate as ffi; use crate::types::Color; +use ffi::{Channel, PaletteIndex, Rgb}; -/// Manipulate entries in the palette store 'p'. These are *not* locked. -pub fn palette256_set_rgb(palette: &mut ffi::palette256, idx: usize, r: Color, g: Color, b: Color) { - ffi::channel_set_rgb(&mut palette.chans[idx], r, g, b) +/// Set the different color components of an entry inside a palette store. +// TODO: TEST +#[inline] +pub fn palette256_set_rgb( + palette: &mut ffi::palette256, + idx: PaletteIndex, + red: Color, + green: Color, + blue: Color, +) { + ffi::channel_set_rgb(&mut palette.chans[idx as usize], red, green, blue) } -// XXX: what is the return type? -// static inline int -// palette256_set(palette256* p, int idx, unsigned rgb){ -// if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){ -// return -1; -// } -// return channel_set(&p->chans[idx], rgb); -// } +/// Same as `palette256_set_rgb()` but set an assembled 24 bit channel at once. +// TODO: TEST +#[inline] +pub fn palette256_set( + palette: &mut ffi::palette256, + idx: PaletteIndex, + rgb: Rgb) { + ffi::channel_set(&mut palette.chans[idx as usize], rgb); +} -// static inline int -// palette256_get_rgb(const palette256* p, int idx, unsigned* RESTRICT r, unsigned* RESTRICT g, unsigned* RESTRICT b){ -// if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){ -// return -1; -// } -// return channel_rgb(p->chans[idx], r, g, b); -// } +/// Extract the three 8-bit R/G/B components from an entry inside a palette store. +// TODO: TEST +#[inline] +pub fn palette256_get_rgb( + palette: &ffi::palette256, + idx: PaletteIndex, + red: &mut Color, + green: &mut Color, + blue: &mut Color, +) -> Channel { + ffi::channel_rgb(palette.chans[idx as usize], red, green, blue) +} #[cfg(test)] mod test { diff --git a/rust/libnotcurses-sys/src/types.rs b/rust/libnotcurses-sys/src/types.rs index 7deaa7124..94da72243 100644 --- a/rust/libnotcurses-sys/src/types.rs +++ b/rust/libnotcurses-sys/src/types.rs @@ -4,4 +4,5 @@ pub type Color = u8; pub type Rgb = u32; pub type Alpha = u32; pub type Pixel = u32; +pub type PaletteIndex = u8; pub type IntResult = i32; // -1 == err From efdb4ba4f1016539a365c179294eb00b9083b724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Tue, 11 Aug 2020 18:31:18 +0200 Subject: [PATCH 8/8] pass rustfmt & fix typos --- rust/libnotcurses-sys/src/channel.rs | 4 +- rust/libnotcurses-sys/src/key.rs | 4 +- rust/libnotcurses-sys/src/keycodes.rs | 212 +++++++++++++------------- rust/libnotcurses-sys/src/nc.rs | 2 - rust/libnotcurses-sys/src/palette.rs | 5 +- rust/libnotcurses-sys/src/pixel.rs | 13 +- rust/libnotcurses-sys/src/plane.rs | 2 - 7 files changed, 118 insertions(+), 124 deletions(-) diff --git a/rust/libnotcurses-sys/src/channel.rs b/rust/libnotcurses-sys/src/channel.rs index 06e656d82..486908165 100644 --- a/rust/libnotcurses-sys/src/channel.rs +++ b/rust/libnotcurses-sys/src/channel.rs @@ -254,7 +254,7 @@ pub fn channels_set_fg_rgb(channels: &mut ChannelPair, r: Color, g: Color, b: Co *channels = (channel as u64) << 32 | *channels & 0xffffffff_u64; } -/// Same as channels_set_fg_rgb but but set an assembled 24 bit channel at once. +/// Same as channels_set_fg_rgb but set an assembled 24 bit channel at once. // TODO: TEST #[inline] pub fn channels_set_fg(channels: &mut ChannelPair, rgb: Rgb) { @@ -273,7 +273,7 @@ pub fn channels_set_bg_rgb(channels: &mut ChannelPair, r: Color, g: Color, b: Co channels_set_bchannel(channels, channel); } -/// Same as channels_set_bg_rgb but but set an assembled 24 bit channel at once. +/// Same as channels_set_bg_rgb but set an assembled 24 bit channel at once. // TODO: TEST #[inline] pub fn channels_set_bg(channels: &mut ChannelPair, rgb: Rgb) { diff --git a/rust/libnotcurses-sys/src/key.rs b/rust/libnotcurses-sys/src/key.rs index 60f208e21..6667d2516 100644 --- a/rust/libnotcurses-sys/src/key.rs +++ b/rust/libnotcurses-sys/src/key.rs @@ -13,13 +13,13 @@ use crate as ffi; /// Is this char32_t a Supplementary Private Use Area-B codepoint? #[inline] -pub fn nckey_supppuab_p(w: u32)-> bool { +pub fn nckey_supppuab_p(w: u32) -> bool { w >= 0x100000 && w <= 0x10fffd } /// Is the event a synthesized mouse event? #[inline] -pub fn nckey_mouse_p(r: u32)-> bool { +pub fn nckey_mouse_p(r: u32) -> bool { r >= ffi::NCKEY_BUTTON1 && r <= ffi::NCKEY_RELEASE } diff --git a/rust/libnotcurses-sys/src/keycodes.rs b/rust/libnotcurses-sys/src/keycodes.rs index fb696f7cb..35aa03c20 100644 --- a/rust/libnotcurses-sys/src/keycodes.rs +++ b/rust/libnotcurses-sys/src/keycodes.rs @@ -4,126 +4,128 @@ // - https://github.com/rust-lang/rust-bindgen/issues/316 // - https://github.com/jethrogb/rust-cexpr/pull/15 -pub const fn suppuabize(w: u32) -> u32 {w + 0x100000} +pub const fn suppuabize(w: u32) -> u32 { + w + 0x100000 +} -pub const NCKEY_INVALID :u32 = suppuabize(0); +pub const NCKEY_INVALID: u32 = suppuabize(0); ///generated interally in response to SIGWINCH -pub const NCKEY_RESIZE :u32 = suppuabize(1); -pub const NCKEY_UP :u32 = suppuabize(2); -pub const NCKEY_RIGHT :u32 = suppuabize(3); -pub const NCKEY_DOWN :u32 = suppuabize(4); -pub const NCKEY_LEFT :u32 = suppuabize(5); -pub const NCKEY_INS :u32 = suppuabize(6); -pub const NCKEY_DEL :u32 = suppuabize(7); +pub const NCKEY_RESIZE: u32 = suppuabize(1); +pub const NCKEY_UP: u32 = suppuabize(2); +pub const NCKEY_RIGHT: u32 = suppuabize(3); +pub const NCKEY_DOWN: u32 = suppuabize(4); +pub const NCKEY_LEFT: u32 = suppuabize(5); +pub const NCKEY_INS: u32 = suppuabize(6); +pub const NCKEY_DEL: u32 = suppuabize(7); /// backspace (sometimes) -pub const NCKEY_BACKSPACE :u32 = suppuabize(8); -pub const NCKEY_PGDOWN :u32 = suppuabize(9); -pub const NCKEY_PGUP :u32 = suppuabize(10); -pub const NCKEY_HOME :u32 = suppuabize(11); -pub const NCKEY_END :u32 = suppuabize(12); -pub const NCKEY_F00 :u32 = suppuabize(20); -pub const NCKEY_F01 :u32 = suppuabize(21); -pub const NCKEY_F02 :u32 = suppuabize(22); -pub const NCKEY_F03 :u32 = suppuabize(23); -pub const NCKEY_F04 :u32 = suppuabize(24); -pub const NCKEY_F05 :u32 = suppuabize(25); -pub const NCKEY_F06 :u32 = suppuabize(26); -pub const NCKEY_F07 :u32 = suppuabize(27); -pub const NCKEY_F08 :u32 = suppuabize(28); -pub const NCKEY_F09 :u32 = suppuabize(29); -pub const NCKEY_F10 :u32 = suppuabize(30); -pub const NCKEY_F11 :u32 = suppuabize(31); -pub const NCKEY_F12 :u32 = suppuabize(32); -pub const NCKEY_F13 :u32 = suppuabize(33); -pub const NCKEY_F14 :u32 = suppuabize(34); -pub const NCKEY_F15 :u32 = suppuabize(35); -pub const NCKEY_F16 :u32 = suppuabize(36); -pub const NCKEY_F17 :u32 = suppuabize(37); -pub const NCKEY_F18 :u32 = suppuabize(38); -pub const NCKEY_F19 :u32 = suppuabize(39); -pub const NCKEY_F20 :u32 = suppuabize(40); -pub const NCKEY_F21 :u32 = suppuabize(41); -pub const NCKEY_F22 :u32 = suppuabize(42); -pub const NCKEY_F23 :u32 = suppuabize(43); -pub const NCKEY_F24 :u32 = suppuabize(44); -pub const NCKEY_F25 :u32 = suppuabize(45); -pub const NCKEY_F26 :u32 = suppuabize(46); -pub const NCKEY_F27 :u32 = suppuabize(47); -pub const NCKEY_F28 :u32 = suppuabize(48); -pub const NCKEY_F29 :u32 = suppuabize(49); -pub const NCKEY_F30 :u32 = suppuabize(50); -pub const NCKEY_F31 :u32 = suppuabize(51); -pub const NCKEY_F32 :u32 = suppuabize(52); -pub const NCKEY_F33 :u32 = suppuabize(53); -pub const NCKEY_F34 :u32 = suppuabize(54); -pub const NCKEY_F35 :u32 = suppuabize(55); -pub const NCKEY_F36 :u32 = suppuabize(56); -pub const NCKEY_F37 :u32 = suppuabize(57); -pub const NCKEY_F38 :u32 = suppuabize(58); -pub const NCKEY_F39 :u32 = suppuabize(59); -pub const NCKEY_F40 :u32 = suppuabize(60); -pub const NCKEY_F41 :u32 = suppuabize(61); -pub const NCKEY_F42 :u32 = suppuabize(62); -pub const NCKEY_F43 :u32 = suppuabize(63); -pub const NCKEY_F44 :u32 = suppuabize(64); -pub const NCKEY_F45 :u32 = suppuabize(65); -pub const NCKEY_F46 :u32 = suppuabize(66); -pub const NCKEY_F47 :u32 = suppuabize(67); -pub const NCKEY_F48 :u32 = suppuabize(68); -pub const NCKEY_F49 :u32 = suppuabize(69); -pub const NCKEY_F50 :u32 = suppuabize(70); -pub const NCKEY_F51 :u32 = suppuabize(71); -pub const NCKEY_F52 :u32 = suppuabize(72); -pub const NCKEY_F53 :u32 = suppuabize(73); -pub const NCKEY_F54 :u32 = suppuabize(74); -pub const NCKEY_F55 :u32 = suppuabize(75); -pub const NCKEY_F56 :u32 = suppuabize(76); -pub const NCKEY_F57 :u32 = suppuabize(77); -pub const NCKEY_F58 :u32 = suppuabize(78); -pub const NCKEY_F59 :u32 = suppuabize(79); -pub const NCKEY_F60 :u32 = suppuabize(80); +pub const NCKEY_BACKSPACE: u32 = suppuabize(8); +pub const NCKEY_PGDOWN: u32 = suppuabize(9); +pub const NCKEY_PGUP: u32 = suppuabize(10); +pub const NCKEY_HOME: u32 = suppuabize(11); +pub const NCKEY_END: u32 = suppuabize(12); +pub const NCKEY_F00: u32 = suppuabize(20); +pub const NCKEY_F01: u32 = suppuabize(21); +pub const NCKEY_F02: u32 = suppuabize(22); +pub const NCKEY_F03: u32 = suppuabize(23); +pub const NCKEY_F04: u32 = suppuabize(24); +pub const NCKEY_F05: u32 = suppuabize(25); +pub const NCKEY_F06: u32 = suppuabize(26); +pub const NCKEY_F07: u32 = suppuabize(27); +pub const NCKEY_F08: u32 = suppuabize(28); +pub const NCKEY_F09: u32 = suppuabize(29); +pub const NCKEY_F10: u32 = suppuabize(30); +pub const NCKEY_F11: u32 = suppuabize(31); +pub const NCKEY_F12: u32 = suppuabize(32); +pub const NCKEY_F13: u32 = suppuabize(33); +pub const NCKEY_F14: u32 = suppuabize(34); +pub const NCKEY_F15: u32 = suppuabize(35); +pub const NCKEY_F16: u32 = suppuabize(36); +pub const NCKEY_F17: u32 = suppuabize(37); +pub const NCKEY_F18: u32 = suppuabize(38); +pub const NCKEY_F19: u32 = suppuabize(39); +pub const NCKEY_F20: u32 = suppuabize(40); +pub const NCKEY_F21: u32 = suppuabize(41); +pub const NCKEY_F22: u32 = suppuabize(42); +pub const NCKEY_F23: u32 = suppuabize(43); +pub const NCKEY_F24: u32 = suppuabize(44); +pub const NCKEY_F25: u32 = suppuabize(45); +pub const NCKEY_F26: u32 = suppuabize(46); +pub const NCKEY_F27: u32 = suppuabize(47); +pub const NCKEY_F28: u32 = suppuabize(48); +pub const NCKEY_F29: u32 = suppuabize(49); +pub const NCKEY_F30: u32 = suppuabize(50); +pub const NCKEY_F31: u32 = suppuabize(51); +pub const NCKEY_F32: u32 = suppuabize(52); +pub const NCKEY_F33: u32 = suppuabize(53); +pub const NCKEY_F34: u32 = suppuabize(54); +pub const NCKEY_F35: u32 = suppuabize(55); +pub const NCKEY_F36: u32 = suppuabize(56); +pub const NCKEY_F37: u32 = suppuabize(57); +pub const NCKEY_F38: u32 = suppuabize(58); +pub const NCKEY_F39: u32 = suppuabize(59); +pub const NCKEY_F40: u32 = suppuabize(60); +pub const NCKEY_F41: u32 = suppuabize(61); +pub const NCKEY_F42: u32 = suppuabize(62); +pub const NCKEY_F43: u32 = suppuabize(63); +pub const NCKEY_F44: u32 = suppuabize(64); +pub const NCKEY_F45: u32 = suppuabize(65); +pub const NCKEY_F46: u32 = suppuabize(66); +pub const NCKEY_F47: u32 = suppuabize(67); +pub const NCKEY_F48: u32 = suppuabize(68); +pub const NCKEY_F49: u32 = suppuabize(69); +pub const NCKEY_F50: u32 = suppuabize(70); +pub const NCKEY_F51: u32 = suppuabize(71); +pub const NCKEY_F52: u32 = suppuabize(72); +pub const NCKEY_F53: u32 = suppuabize(73); +pub const NCKEY_F54: u32 = suppuabize(74); +pub const NCKEY_F55: u32 = suppuabize(75); +pub const NCKEY_F56: u32 = suppuabize(76); +pub const NCKEY_F57: u32 = suppuabize(77); +pub const NCKEY_F58: u32 = suppuabize(78); +pub const NCKEY_F59: u32 = suppuabize(79); +pub const NCKEY_F60: u32 = suppuabize(80); // ... leave room for up to 100 function keys, egads -pub const NCKEY_ENTER :u32 = suppuabize(121); +pub const NCKEY_ENTER: u32 = suppuabize(121); /// "clear-screen or erase" -pub const NCKEY_CLS :u32 = suppuabize(122); +pub const NCKEY_CLS: u32 = suppuabize(122); /// down + left on keypad -pub const NCKEY_DLEFT :u32 = suppuabize(123); -pub const NCKEY_DRIGHT :u32 = suppuabize(124); +pub const NCKEY_DLEFT: u32 = suppuabize(123); +pub const NCKEY_DRIGHT: u32 = suppuabize(124); /// up + left on keypad -pub const NCKEY_ULEFT :u32 = suppuabize(125); -pub const NCKEY_URIGHT :u32 = suppuabize(126); +pub const NCKEY_ULEFT: u32 = suppuabize(125); +pub const NCKEY_URIGHT: u32 = suppuabize(126); /// the most truly neutral of keypresses -pub const NCKEY_CENTER :u32 = suppuabize(127); -pub const NCKEY_BEGIN :u32 = suppuabize(128); -pub const NCKEY_CANCEL :u32 = suppuabize(129); -pub const NCKEY_CLOSE :u32 = suppuabize(130); -pub const NCKEY_COMMAND :u32 = suppuabize(131); -pub const NCKEY_COPY :u32 = suppuabize(132); -pub const NCKEY_EXIT :u32 = suppuabize(133); -pub const NCKEY_PRINT :u32 = suppuabize(134); -pub const NCKEY_REFRESH :u32 = suppuabize(135); +pub const NCKEY_CENTER: u32 = suppuabize(127); +pub const NCKEY_BEGIN: u32 = suppuabize(128); +pub const NCKEY_CANCEL: u32 = suppuabize(129); +pub const NCKEY_CLOSE: u32 = suppuabize(130); +pub const NCKEY_COMMAND: u32 = suppuabize(131); +pub const NCKEY_COPY: u32 = suppuabize(132); +pub const NCKEY_EXIT: u32 = suppuabize(133); +pub const NCKEY_PRINT: u32 = suppuabize(134); +pub const NCKEY_REFRESH: u32 = suppuabize(135); // // Mouse events. We try to encode some details into the char32_t (i.e. which // button was pressed);, but some is embedded in the ncinput event. The release // event is generic across buttons; callers must maintain state, if they care. -pub const NCKEY_BUTTON1 :u32 = suppuabize(201); -pub const NCKEY_BUTTON2 :u32 = suppuabize(202); -pub const NCKEY_BUTTON3 :u32 = suppuabize(203); +pub const NCKEY_BUTTON1: u32 = suppuabize(201); +pub const NCKEY_BUTTON2: u32 = suppuabize(202); +pub const NCKEY_BUTTON3: u32 = suppuabize(203); /// scrollwheel up -pub const NCKEY_BUTTON4 :u32 = suppuabize(204); +pub const NCKEY_BUTTON4: u32 = suppuabize(204); /// scrollwheel down -pub const NCKEY_BUTTON5 :u32 = suppuabize(205); -pub const NCKEY_BUTTON6 :u32 = suppuabize(206); -pub const NCKEY_BUTTON7 :u32 = suppuabize(207); -pub const NCKEY_BUTTON8 :u32 = suppuabize(208); -pub const NCKEY_BUTTON9 :u32 = suppuabize(209); -pub const NCKEY_BUTTON10 :u32 = suppuabize(210); -pub const NCKEY_BUTTON11 :u32 = suppuabize(211); -pub const NCKEY_RELEASE :u32 = suppuabize(212); +pub const NCKEY_BUTTON5: u32 = suppuabize(205); +pub const NCKEY_BUTTON6: u32 = suppuabize(206); +pub const NCKEY_BUTTON7: u32 = suppuabize(207); +pub const NCKEY_BUTTON8: u32 = suppuabize(208); +pub const NCKEY_BUTTON9: u32 = suppuabize(209); +pub const NCKEY_BUTTON10: u32 = suppuabize(210); +pub const NCKEY_BUTTON11: u32 = suppuabize(211); +pub const NCKEY_RELEASE: u32 = suppuabize(212); // Synonyms (so far as we're concerned) -pub const NCKEY_SCROLL_UP :u32 = NCKEY_BUTTON4; -pub const NCKEY_SCROLL_DOWN :u32 = NCKEY_BUTTON5; -pub const NCKEY_RETURN :u32 = NCKEY_ENTER; +pub const NCKEY_SCROLL_UP: u32 = NCKEY_BUTTON4; +pub const NCKEY_SCROLL_DOWN: u32 = NCKEY_BUTTON5; +pub const NCKEY_RETURN: u32 = NCKEY_ENTER; diff --git a/rust/libnotcurses-sys/src/nc.rs b/rust/libnotcurses-sys/src/nc.rs index d504c9e55..079ceb0bf 100644 --- a/rust/libnotcurses-sys/src/nc.rs +++ b/rust/libnotcurses-sys/src/nc.rs @@ -46,11 +46,9 @@ // notcurses_stddim_yx // notcurses_term_dim_yx - // use crate as ffi; // use crate::types::{ChannelPair, IntResult}; - // // 'ni' may be NULL if the caller is uninterested in event details. If no event // // is ready, returns 0. // static inline char32_t diff --git a/rust/libnotcurses-sys/src/palette.rs b/rust/libnotcurses-sys/src/palette.rs index 1557d20d4..6b7f75416 100644 --- a/rust/libnotcurses-sys/src/palette.rs +++ b/rust/libnotcurses-sys/src/palette.rs @@ -37,10 +37,7 @@ pub fn palette256_set_rgb( /// Same as `palette256_set_rgb()` but set an assembled 24 bit channel at once. // TODO: TEST #[inline] -pub fn palette256_set( - palette: &mut ffi::palette256, - idx: PaletteIndex, - rgb: Rgb) { +pub fn palette256_set(palette: &mut ffi::palette256, idx: PaletteIndex, rgb: Rgb) { ffi::channel_set(&mut palette.chans[idx as usize], rgb); } diff --git a/rust/libnotcurses-sys/src/pixel.rs b/rust/libnotcurses-sys/src/pixel.rs index 4d3a75d4d..d4e3db24e 100644 --- a/rust/libnotcurses-sys/src/pixel.rs +++ b/rust/libnotcurses-sys/src/pixel.rs @@ -41,12 +41,12 @@ pub fn ncpixel_a(pixel: Pixel) -> Color { /// Extract the 8 bit green component from a pixel pub fn ncpixel_g(pixel: Pixel) -> Color { - ((pixel & 0x00ff0000) >> 16 ) as Color + ((pixel & 0x00ff0000) >> 16) as Color } /// Extract the 8 bit blue component from a pixel pub fn ncpixel_b(pixel: Pixel) -> Color { - ((pixel & 0x0000ff00) >> 8 ) as Color + ((pixel & 0x0000ff00) >> 8) as Color } /// Extract the 8 bit red component from a pixel @@ -54,22 +54,22 @@ pub fn ncpixel_r(pixel: Pixel) -> Color { (pixel & 0x000000ff) as Color } -/// Set the 8-bit alpha component on a pixel +/// Set the 8-bit alpha component of a pixel pub fn ncpixel_set_a(pixel: &mut Pixel, alpha: Color) { *pixel = (*pixel & 0x00ffffff) | ((alpha as Pixel) << 24); } -/// Set the 8-bit green component on a pixel +/// Set the 8-bit green component of a pixel pub fn ncpixel_set_g(pixel: &mut Pixel, green: Color) { *pixel = (*pixel & 0xff00ffff) | ((green as Pixel) << 16); } -/// Set the 8-bit blue component on a pixel +/// Set the 8-bit blue component of a pixel pub fn ncpixel_set_b(pixel: &mut Pixel, blue: Color) { *pixel = (*pixel & 0xffff00ff) | ((blue as Pixel) << 8); } -/// Set the 8-bit red component on a pixel +/// Set the 8-bit red component of a pixel pub fn ncpixel_set_r(pixel: &mut Pixel, red: Color) { *pixel = (*pixel & 0xffffff00) | red as Pixel; } @@ -81,7 +81,6 @@ pub fn ncpixel_set_rgb(pixel: &mut Pixel, red: Color, green: Color, blue: Color) ncpixel_set_b(pixel, blue); } - #[cfg(test)] mod test { // use super::ffi; diff --git a/rust/libnotcurses-sys/src/plane.rs b/rust/libnotcurses-sys/src/plane.rs index ad7d8e3b3..fc55fc162 100644 --- a/rust/libnotcurses-sys/src/plane.rs +++ b/rust/libnotcurses-sys/src/plane.rs @@ -181,8 +181,6 @@ pub fn ncplane_perimeter( unsafe { ffi::ncplane_cursor_move_yx(plane, 0, 0) } } - - // // Resize the plane, retaining what data we can (everything, unless we're // // shrinking in some dimension). Keep the origin where it is. // static inline int