[rust] add ncvisual_from_rgb_* functions and methods

- update some docs.
This commit is contained in:
joseLuís 2021-06-19 13:04:45 +02:00
parent b2b31e723a
commit e5092ad4eb
4 changed files with 71 additions and 6 deletions

View File

@ -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,

View File

@ -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> {

View File

@ -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`.
///

View File

@ -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