[rust] add NCVISUAL_OPTION_NOINTERPOLATE

- update the `pixel-cell` example.
- change the type of ncvisual flags parameter to u32.
- minor doc fixes.
pull/1742/head
joseLuís 3 years ago
parent 3aa287b9d4
commit 852cde9a75

@ -5,7 +5,7 @@
//! It works on the following terminals: //! It works on the following terminals:
//! - kitty //! - kitty
//! - xterm (invoked with `xterm -ti vt340`) //! - xterm (invoked with `xterm -ti vt340`)
//! - alacritty (WIP https://github.com/ayosec/alacritty/tree/graphics) //! - alacritty (WIP: https://github.com/ayosec/alacritty/tree/graphics)
use rand::{distributions::Uniform, Rng}; use rand::{distributions::Uniform, Rng};
@ -24,7 +24,8 @@ fn main() -> NcResult<()> {
// print visual delimiters around our pixelized cell // print visual delimiters around our pixelized cell
println!("0▗│▖\n│─ ─\n2▝│▘"); println!("0▗│▖\n│─ ─\n2▝│▘");
println!("a cell is {}x{} pixels", pg.cell_y, pg.cell_x); println!("a cell is {}x{} pixels", pg.cell_y, pg.cell_x);
println!("\nscaled: inflated:"); println!("\ninterpolated not-interpolated");
println!(" SCALE SCALE INFLATE RESIZE");
// fill the buffer with random color pixels // fill the buffer with random color pixels
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
@ -39,14 +40,14 @@ fn main() -> NcResult<()> {
} }
// show the newly created ncvisual delimited with the box drawing characters // show the newly created ncvisual delimited with the box drawing characters
let vframe1 = NcVisual::from_rgba(buffer.as_slice(), pg.cell_y, pg.cell_x * 4, pg.cell_x)?; let v1 = NcVisual::from_rgba(buffer.as_slice(), pg.cell_y, pg.cell_x * 4, pg.cell_x)?;
let voptions = let voptions =
NcVisualOptions::without_plane(1, 2, 0, 0, pg.cell_y, pg.cell_x, NCBLIT_PIXEL, 0, 0); NcVisualOptions::without_plane(1, 2, 0, 0, pg.cell_y, pg.cell_x, NCBLIT_PIXEL, 0, 0);
vframe1.render(&mut nc, &voptions)?; v1.render(&mut nc, &voptions)?;
rsleep![&mut nc, 1]; rsleep![&mut nc, 1];
// show the ncvisual, scaled // show the ncvisual, scaled with interpolated values
let mut vplane2 = NcPlane::new_bound(&mut stdplane, 6, 2, 5, 4)?; let mut vplane2 = NcPlane::new_bound(&mut stdplane, 7, 4, 5, 4)?;
let voptions2 = NcVisualOptions::with_plane( let voptions2 = NcVisualOptions::with_plane(
&mut vplane2, &mut vplane2,
NCSCALE_SCALE, NCSCALE_SCALE,
@ -60,27 +61,65 @@ fn main() -> NcResult<()> {
0, 0,
0, 0,
); );
vframe1.render(&mut nc, &voptions2)?; v1.render(&mut nc, &voptions2)?;
rsleep![&mut nc, 1]; rsleep![&mut nc, 1];
// show the ncvisual, inflated // show the ncvisual, scaled without using interpolation
let voptions3 = let mut vplane3 = NcPlane::new_bound(&mut stdplane, 7, 19, 5, 4)?;
NcVisualOptions::without_plane(6, 9, 0, 0, pg.cell_y, pg.cell_x, NCBLIT_PIXEL, 0, 0); let voptions3 = NcVisualOptions::with_plane(
vframe1.inflate(4)?; &mut vplane3,
vframe1.render(&mut nc, &voptions3)?; NCSCALE_SCALE,
0,
0,
0,
0,
pg.cell_y,
pg.cell_x,
NCBLIT_PIXEL,
NCVISUAL_OPTION_NOINTERPOLATE,
0,
);
v1.render(&mut nc, &voptions3)?;
rsleep![&mut nc, 1];
// inflate the ncvisual (doesn't use interpolation)
let voptions4 =
NcVisualOptions::without_plane(7, 33, 0, 0, pg.cell_y, pg.cell_x, NCBLIT_PIXEL, 0, 0);
v1.inflate(4)?;
v1.render(&mut nc, &voptions4)?;
rsleep![&mut nc, 1];
// resize the ncvisual (uses interpolation)
let v5 = NcVisual::from_rgba(buffer.as_slice(), pg.cell_y, pg.cell_x * 4, pg.cell_x)?;
let voptions5 =
NcVisualOptions::without_plane(7, 45, 0, 0, pg.cell_y, pg.cell_x, NCBLIT_PIXEL, 0, 0);
v5.resize(18 * 4, 9 * 4)?; // FIXME: render function fails when downsizing (y<18 | x<9)
v5.render(&mut nc, &voptions5)?;
rsleep![&mut nc, 1]; rsleep![&mut nc, 1];
let vframe4 = NcVisual::from_rgba(buffer.as_slice(), pg.cell_y, pg.cell_x * 4, pg.cell_x)?; // resize without interpolation
let _voptions4 = // WIP: should this substitute the inflate method?
NcVisualOptions::without_plane(6, 14, 0, 0, pg.cell_y, pg.cell_x, NCBLIT_PIXEL, 0, 0); // let v6 = NcVisual::from_rgba(buffer.as_slice(), pg.cell_y, pg.cell_x * 4, pg.cell_x)?;
vframe4.resize(2, 2)?; // let voptions6 = NcVisualOptions::without_plane(
// FIXME: render function fails // 7,
// vframe4.render(&mut nc, &_voptions4)?; // 54,
rsleep![&mut nc, 2]; // 0,
// 0,
// pg.cell_y,
// pg.cell_x,
// NCBLIT_PIXEL,
// NCVISUAL_OPTION_NOINTERPOLATE,
// 0,
// );
// v6.resize(18 * 4, 9 * 4)?;
// v6.render(&mut nc, &voptions6)?;
// rsleep![&mut nc, 1];
vframe1.destroy(); sleep![3];
vframe4.destroy();
v1.destroy();
v5.destroy();
// v6.destroy();
nc.stop()?; nc.stop()?;
Ok(()) Ok(())
} }

@ -697,6 +697,7 @@ pub use ffi::{
// NCVISUAL_OPTION_CHILDPLANE // NCVISUAL_OPTION_CHILDPLANE
// NCVISUAL_OPTION_HORALIGNED // NCVISUAL_OPTION_HORALIGNED
// NCVISUAL_OPTION_NODEGRADE, // NCVISUAL_OPTION_NODEGRADE,
// NCVISUAL_OPTION_NOINTERPOLATE
// NCVISUAL_OPTION_VERALIGNED, // NCVISUAL_OPTION_VERALIGNED,
#[doc(inline)] #[doc(inline)]

@ -41,7 +41,7 @@ impl NcVisualOptions {
leny: NcDim, leny: NcDim,
lenx: NcDim, lenx: NcDim,
blitter: NcBlitter, blitter: NcBlitter,
flags: u64, flags: u32,
transcolor: NcRgba, transcolor: NcRgba,
) -> Self { ) -> Self {
Self { Self {
@ -60,7 +60,7 @@ impl NcVisualOptions {
// glyph set to use // glyph set to use
blitter, blitter,
// bitmask over NCVISUAL_OPTION_* // bitmask over NCVISUAL_OPTION_*
flags, flags: flags as u64,
transcolor, transcolor,
} }
} }
@ -73,7 +73,7 @@ impl NcVisualOptions {
leny: NcDim, leny: NcDim,
lenx: NcDim, lenx: NcDim,
blitter: NcBlitter, blitter: NcBlitter,
flags: u64, flags: u32,
transcolor: u32, transcolor: u32,
) -> Self { ) -> Self {
Self { Self {
@ -91,7 +91,7 @@ impl NcVisualOptions {
// glyph set to use // glyph set to use
blitter, blitter,
// bitmask over NCVISUAL_OPTION_* // bitmask over NCVISUAL_OPTION_*
flags, flags: flags as u64,
// This color will be treated as transparent with flag [NCVISUAL_OPTION_ADDALPHA]. // This color will be treated as transparent with flag [NCVISUAL_OPTION_ADDALPHA].
transcolor, transcolor,
} }

@ -133,7 +133,12 @@ pub const NCVISUAL_OPTION_ADDALPHA: u32 = crate::bindings::ffi::NCVISUAL_OPTION_
/// Uses [`NCCELL_ALPHA_BLEND`][crate::NCCELL_ALPHA_BLEND] with visual. /// Uses [`NCCELL_ALPHA_BLEND`][crate::NCCELL_ALPHA_BLEND] with visual.
pub const NCVISUAL_OPTION_BLEND: u32 = crate::bindings::ffi::NCVISUAL_OPTION_BLEND; pub const NCVISUAL_OPTION_BLEND: u32 = crate::bindings::ffi::NCVISUAL_OPTION_BLEND;
/// allows you to indicate that the n field of ncvisual_options refers not to the plane onto which you'd like to blit, but the parent of a new plane. A plane will be created using the other parameters in the ncvisual_options, as a child of this parent. This means things like, say, vertically centering a sprixel relative to the standard plane can be done in one step /// allows you to indicate that the n field of ncvisual_options refers not to
/// the plane onto which you'd like to blit, but the parent of a new plane.
///
/// A plane will be created using the other parameters in the ncvisual_options,
/// as a child of this parent. This means things like, say, vertically centering
/// a sprixel relative to the standard plane can be done in one step.
pub const NCVISUAL_OPTION_CHILDPLANE: u32 = crate::bindings::ffi::NCVISUAL_OPTION_CHILDPLANE; pub const NCVISUAL_OPTION_CHILDPLANE: u32 = crate::bindings::ffi::NCVISUAL_OPTION_CHILDPLANE;
/// Fails rather than gracefully degrade. See [NcBlitter]. /// Fails rather than gracefully degrade. See [NcBlitter].
@ -145,6 +150,9 @@ pub const NCVISUAL_OPTION_VERALIGNED: u32 = crate::bindings::ffi::NCVISUAL_OPTIO
/// X is an alignment, not absolute. /// X is an alignment, not absolute.
pub const NCVISUAL_OPTION_HORALIGNED: u32 = crate::bindings::ffi::NCVISUAL_OPTION_HORALIGNED; pub const NCVISUAL_OPTION_HORALIGNED: u32 = crate::bindings::ffi::NCVISUAL_OPTION_HORALIGNED;
/// Uses non-interpolative scaling.
pub const NCVISUAL_OPTION_NOINTERPOLATE: u32 = crate::bindings::ffi::NCVISUAL_OPTION_NOINTERPOLATE;
/// Blitter Mode (`NCBLIT_*`) /// Blitter Mode (`NCBLIT_*`)
/// ///
/// We never blit full blocks, but instead spaces (more efficient) with the /// We never blit full blocks, but instead spaces (more efficient) with the

Loading…
Cancel
Save