From e5092ad4ebe80c2ca564392d96ee3079039afb98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?joseLu=C3=ADs?= Date: Sat, 19 Jun 2021 13:04:45 +0200 Subject: [PATCH] [rust] add ncvisual_from_rgb_* functions and methods - update some docs. --- rust/src/bindings.rs | 4 ++- rust/src/direct/methods.rs | 3 ++ rust/src/visual/methods.rs | 64 ++++++++++++++++++++++++++++++++++++-- rust/src/visual/mod.rs | 6 ++-- 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/rust/src/bindings.rs b/rust/src/bindings.rs index 6e95434e5..c17660971 100644 --- a/rust/src/bindings.rs +++ b/rust/src/bindings.rs @@ -8,7 +8,7 @@ // BUG ISSUES: // https://github.com/rust-lang/rust-bindgen/issues/1470 #[allow(clippy::all)] -// https://github.com/rust-lang/rust-bindgen/issues/2066 +// https://github.com/rust-lang/rust-bindgen/issues/1651 #[allow(unknown_lints, deref_nullptr)] pub mod ffi { //! Rust FFI bindings, automatically generated with bindgen. @@ -744,6 +744,8 @@ pub use ffi::{ ncvisual_from_bgra, ncvisual_from_file, ncvisual_from_plane, + ncvisual_from_rgb_loose, + ncvisual_from_rgb_packed, ncvisual_from_rgba, ncvisual_media_defblitter, ncvisual_polyfill_yx, diff --git a/rust/src/direct/methods.rs b/rust/src/direct/methods.rs index cda4a990f..9b516f68f 100644 --- a/rust/src/direct/methods.rs +++ b/rust/src/direct/methods.rs @@ -30,6 +30,9 @@ impl NcDirect { /// `flags` is a bitmask over: /// - [NCDIRECT_OPTION_INHIBIT_CBREAK][crate::NCDIRECT_OPTION_INHIBIT_CBREAK] /// - [NCDIRECT_OPTION_INHIBIT_SETLOCALE][crate::NCDIRECT_OPTION_INHIBIT_SETLOCALE] + /// - [NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS][crate::NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS] + /// - [NCDIRECT_OPTION_VERBOSE][crate::NCDIRECT_OPTION_VERBOSE] + /// - [NCDIRECT_OPTION_VERY_VERBOSE][crate::NCDIRECT_OPTION_VERY_VERBOSE] /// /// *C style function: [ncdirect_init()][crate::ncdirect_init].* pub fn with_flags<'a>(flags: NcDirectFlags) -> NcResult<&'a mut NcDirect> { diff --git a/rust/src/visual/methods.rs b/rust/src/visual/methods.rs index d752769ab..fceb27112 100644 --- a/rust/src/visual/methods.rs +++ b/rust/src/visual/methods.rs @@ -4,9 +4,9 @@ use core::ptr::null_mut; use libc::c_void; use crate::{ - cstring, error, error_ref_mut, rstring, Nc, NcBlitter, NcDim, NcDirect, NcDirectF, NcDirectV, - NcError, NcIntResult, NcPixel, NcPlane, NcResult, NcRgba, NcScale, NcTime, NcVGeom, NcVisual, - NcVisualOptions, NCBLIT_PIXEL, NCRESULT_ERR, + cstring, error, error_ref_mut, rstring, Nc, NcBlitter, NcComponent, NcDim, NcDirect, NcDirectF, + NcDirectV, NcError, NcIntResult, NcPixel, NcPlane, NcResult, NcRgba, NcScale, NcTime, NcVGeom, + NcVisual, NcVisualOptions, NCBLIT_PIXEL, NCRESULT_ERR, }; /// # NcVisualOptions Constructors @@ -176,6 +176,64 @@ impl NcVisual { ] } + /// Like [`from_rgba`][NcVisual#method.from_rgba], but the pixels are + /// 4-byte RGBX. Alpha is filled in throughout using 'alpha'. + /// + /// `rowstride` must be a multiple of 4. + /// + /// *C style function: [ncvisual_from_rgb_loose()][crate::ncvisual_from_rgb_loose].* + pub fn from_rgb_loose<'a>( + rgba: &[u8], + rows: NcDim, + rowstride: NcDim, + cols: NcDim, + alpha: NcComponent, + ) -> NcResult<&'a mut NcVisual> { + error_ref_mut![ + unsafe { + crate::ncvisual_from_rgb_loose( + rgba.as_ptr() as *const c_void, + rows as i32, + rowstride as i32, + cols as i32, + alpha as i32, + ) + }, + &format!( + "NcVisual::from_rgb_loose(rgba, {}, {}, {}, {})", + rows, rowstride, cols, alpha + ) + ] + } + + /// Like [`from_rgba`][NcVisual#method.from_rgba], but the pixels are + /// 3-byte RGB. Alpha is filled in throughout using 'alpha'. + /// + /// *C style function: [ncvisual_from_rgb_packed()][crate::ncvisual_from_rgb_packed].* + pub fn from_rgb_packed<'a>( + rgba: &[u8], + rows: NcDim, + rowstride: NcDim, + cols: NcDim, + alpha: NcComponent, + ) -> NcResult<&'a mut NcVisual> { + error_ref_mut![ + unsafe { + crate::ncvisual_from_rgb_packed( + rgba.as_ptr() as *const c_void, + rows as i32, + rowstride as i32, + cols as i32, + alpha as i32, + ) + }, + &format!( + "NcVisual::from_rgb_packed(rgba, {}, {}, {}, {})", + rows, rowstride, cols, alpha + ) + ] + } + /// Prepares an NcVisual, and its underlying NcPlane, based off RGBA content /// in memory at `rgba`. /// diff --git a/rust/src/visual/mod.rs b/rust/src/visual/mod.rs index adb09ab64..5590f797a 100644 --- a/rust/src/visual/mod.rs +++ b/rust/src/visual/mod.rs @@ -1,6 +1,6 @@ -// functions already exported by bindgen : 24 +// functions already exported by bindgen : 26 // ----------------------------------------- -// (W) wrap: 20 +// (W) wrap: 22 // (#) test: 0 // ----------------------------------------- //W ncdirectf_free @@ -16,6 +16,8 @@ //W ncvisual_from_file //W ncvisual_from_plane //W ncvisual_from_rgba +//W ncvisual_from_rgb_packed +//W ncvisual_from_rgb_loose //W ncvisual_inflate //W ncvisual_blitter_geom //W ncvisual_media_defblitter