rust: several fixes

- rename Alpha to AlphaBits
- fix pixel alpha mask
- fix syntax errors
This commit is contained in:
joseLuís 2020-08-13 17:28:58 +02:00
parent 55ad6153d2
commit 5ba618d6a8
4 changed files with 21 additions and 14 deletions

View File

@ -62,7 +62,7 @@
use crate as ffi;
use crate::types::{Alpha, Channel, ChannelPair, Color, Rgb};
use crate::types::{AlphaBits, Channel, ChannelPair, Color, Rgb};
/// Extract the 8-bit red component from a 32-bit channel.
#[inline]
@ -108,13 +108,13 @@ pub fn channel_set(channel: &mut Channel, rgb: Rgb) {
/// Extract the 2-bit alpha component from a 32-bit channel.
#[inline]
pub fn channel_alpha(channel: Channel) -> Alpha {
pub fn channel_alpha(channel: Channel) -> AlphaBits {
channel & ffi::NCCHANNEL_ALPHA_MASK
}
/// Set the 2-bit alpha component of the 32-bit channel.
#[inline]
pub fn channel_set_alpha(channel: &mut Channel, alpha: Alpha) {
pub fn channel_set_alpha(channel: &mut Channel, alpha: AlphaBits) {
let alpha_clean = alpha & ffi::NCCHANNEL_ALPHA_MASK;
*channel = alpha_clean | (*channel & !ffi::NCCHANNEL_ALPHA_MASK);
@ -197,14 +197,14 @@ pub fn channels_bg(channels: ChannelPair) -> Channel {
/// Extract 2 bits of foreground alpha from 'channels', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn channels_fg_alpha(channels: ChannelPair) -> Alpha {
pub fn channels_fg_alpha(channels: ChannelPair) -> AlphaBits {
channel_alpha(channels_fchannel(channels))
}
/// Extract 2 bits of background alpha from 'channels', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn channels_bg_alpha(channels: ChannelPair) -> Alpha {
pub fn channels_bg_alpha(channels: ChannelPair) -> AlphaBits {
channel_alpha(channels_bchannel(channels))
}
@ -273,7 +273,7 @@ pub fn channels_set_bg(channels: &mut ChannelPair, rgb: Rgb) {
/// Set the 2-bit alpha component of the foreground channel.
// TODO: TEST
#[inline]
pub fn channels_set_fg_alpha(channels: &mut ChannelPair, alpha: Alpha) {
pub fn channels_set_fg_alpha(channels: &mut ChannelPair, alpha: AlphaBits) {
let mut channel = channels_fchannel(*channels);
channel_set_alpha(&mut channel, alpha);
*channels = (channel as ChannelPair) << 32 | *channels & 0xffffffff_u64;
@ -282,7 +282,7 @@ pub fn channels_set_fg_alpha(channels: &mut ChannelPair, alpha: Alpha) {
/// Set the 2-bit alpha component of the background channel.
// TODO: TEST
#[inline]
pub fn channels_set_bg_alpha(channels: &mut ChannelPair, alpha: Alpha) {
pub fn channels_set_bg_alpha(channels: &mut ChannelPair, alpha: AlphaBits) {
let mut alpha_clean = alpha;
if alpha == ffi::CELL_ALPHA_HIGHCONTRAST {
// forbidden for background alpha, so makes it opaque

View File

@ -29,6 +29,13 @@
use crate::types::{Color, Pixel};
// Pixel Structure:
//
// 0xff000000 8 bit Alpha
// 0x00ff0000 8 bit Green
// 0x0000ff00 8 bit Blue
// 0x000000ff 8 bit Red
/// 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
@ -36,7 +43,7 @@ pub fn ncpixel(r: Color, g: Color, b: Color) -> Pixel {
/// Extract the 8-bit alpha component from a pixel
pub fn ncpixel_a(pixel: Pixel) -> Color {
((pixel & 0xff0000ff) >> 24) as Color
((pixel & 0xff000000) >> 24) as Color
}
/// Extract the 8 bit green component from a pixel

View File

@ -139,7 +139,7 @@ use core::ptr::null_mut;
use cstr_core::CString;
use crate as ffi;
use ffi::types::{Alpha, Channel, Color, IntResult};
use ffi::types::{AlphaBits, Channel, Color, IntResult};
pub fn ncplane_putstr(plane: *mut ffi::ncplane, _str: &str) -> i32 {
unsafe {
@ -518,14 +518,14 @@ pub fn ncplane_bg(plane: &ffi::ncplane) -> Channel {
/// Extract 2 bits of foreground alpha from 'struct ncplane', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn ncplane_fg_alpha(plane: &ffi::ncplane) -> Alpha {
pub fn ncplane_fg_alpha(plane: &ffi::ncplane) -> AlphaBits {
ffi::channels_fg_alpha(unsafe { ffi::ncplane_channels(plane)})
}
/// Extract 2 bits of background alpha from 'struct ncplane', shifted to LSBs.
// TODO: TEST
#[inline]
pub fn ncplane_bg_alpha(plane: &ffi::ncplane) -> Alpha {
pub fn ncplane_bg_alpha(plane: &ffi::ncplane) -> AlphaBits {
ffi::channels_bg_alpha(unsafe { ffi::ncplane_channels(plane)})
}

View File

@ -43,7 +43,7 @@ pub type Channel = u32;
///
/// ~~AA~~~~ -------- -------- --------
///
pub type Alpha = u32;
pub type AlphaBits = u32;
/// Channels: 64 bits containing a foreground and background channel
///
@ -128,7 +128,7 @@ pub type IntResult = i32; // -1 == err
///
/// NOTE: WIP unstable
/// https://github.com/dankamongmen/notcurses/issues/884
pub type Attribute: u32;
pub type Attribute = u32;
/// GCluster: 32 bits representing
@ -139,7 +139,7 @@ pub type Attribute: u32;
///
/// NOTE: WIP unstable
/// https://github.com/dankamongmen/notcurses/issues/830
pub type GraphemeCluster: u32;
pub type GraphemeCluster = u32;
// Cell: 128 bits tying together a:
//