use crate::{Canvas, Glyph, GlyphMode, Ink, Role, Size, geom, ink};
const BRAILLE_BIT: [[u8; 4]; 2] = [[0x01, 0x02, 0x04, 0x40], [0x08, 0x10, 0x20, 0x80]];
#[inline]
pub fn dot_bit(x: i32, y: i32) -> u8 {
BRAILLE_BIT[x.rem_euclid(Dots::CELL_W) as usize][y.rem_euclid(Dots::CELL_H) as usize]
}
#[inline]
pub fn braille(mask: u8) -> Glyph {
let ascii = match mask.count_ones() {
0 => ' ',
1 => '.',
2 => ':',
3 | 4 => '+',
_ => '#',
};
let ch = char::from_u32(0x2800 + u32::from(mask)).unwrap_or(ascii);
Glyph::new(ch, ascii)
}
#[inline]
fn intensity(ink: Ink) -> u8 {
match ink.role {
Role::Div => ink.level.abs_diff(128),
Role::Phase => 0,
_ => ink.level,
}
}
#[inline]
pub fn stronger(a: Ink, b: Ink) -> Ink {
match (is_empty(a), is_empty(b)) {
(_, true) => a,
(true, false) => b,
(false, false) if intensity(b) > intensity(a) => b,
(false, false) => a,
}
}
#[inline]
pub fn stipple_keep(salt: u64, x: i32, y: i32, p: f64) -> bool {
p > 0.0 && crate::rng::hash01(salt ^ crate::rng::cell_key(x, y)) < p
}
pub const ASCII_RAMP: [char; 9] = ['.', ':', '-', '=', '+', '*', '#', '%', '@'];
#[inline]
pub fn ascii_ramp_cell(top: Ink, bottom: Ink) -> Option<(char, Ink)> {
let ink = stronger(top, bottom);
if is_empty(ink) {
return None;
}
Some((
ASCII_RAMP[usize::from(ink.level) * ASCII_RAMP.len() / 256],
ink,
))
}
#[inline]
pub fn disc_cover(x: i32, y: i32, c: (f64, f64), r: f64) -> f64 {
let d = (f64::from(x) + 0.5 - c.0).hypot(f64::from(y) + 0.5 - c.1);
let cover = r + 0.5 - d;
if cover > 0.0 { cover.min(1.0) } else { 0.0 }
}
pub fn disc_pixels(c: (f64, f64), r: f64, mut f: impl FnMut(i32, i32, f64)) {
if !(c.0.is_finite() && c.1.is_finite() && r.is_finite()) || r < 0.0 {
return;
}
let reach = r + 0.5;
let (x0, x1) = ((c.0 - reach).floor() as i32, (c.0 + reach).ceil() as i32);
let (y0, y1) = ((c.1 - reach).floor() as i32, (c.1 + reach).ceil() as i32);
for y in y0..=y1 {
for x in x0..=x1 {
let cover = disc_cover(x, y, c, r);
if cover > 0.0 {
f(x, y, cover);
}
}
}
}
fn segment(x0: f64, y0: f64, x1: f64, y1: f64, lattice: Size, mut f: impl FnMut(i32, i32)) {
if !(x0.is_finite() && y0.is_finite() && x1.is_finite() && y1.is_finite()) {
return;
}
let (w, h) = (i32::from(lattice.width()), i32::from(lattice.height()));
let m = f64::from(w + h);
let (lo_x, hi_x) = (-m, f64::from(w) + m);
let (lo_y, hi_y) = (-m, f64::from(h) + m);
let inside = |x: f64, y: f64| (lo_x..=hi_x).contains(&x) && (lo_y..=hi_y).contains(&y);
let (mut a, mut b) = ((x0.round(), y0.round()), (x1.round(), y1.round()));
if !(inside(a.0, a.1) && inside(b.0, b.1)) {
let (dx, dy) = (x1 * 0.5 - x0 * 0.5, y1 * 0.5 - y0 * 0.5);
let (mut t0, mut t1) = (0.0f64, 2.0f64);
for (p, q) in [
(-dx, x0 - lo_x),
(dx, hi_x - x0),
(-dy, y0 - lo_y),
(dy, hi_y - y0),
] {
if p == 0.0 {
if q < 0.0 {
return; }
} else if p < 0.0 {
t0 = t0.max(q / p);
} else {
t1 = t1.min(q / p);
}
}
if t0 > t1 {
return;
}
let at = |t: f64| {
(
(x0 + t * dx).round().clamp(lo_x, hi_x),
(y0 + t * dy).round().clamp(lo_y, hi_y),
)
};
(a, b) = (at(t0), at(t1));
}
let cap = 4 * (w as usize + h as usize);
for (x, y) in geom::line(a.0 as i32, a.1 as i32, b.0 as i32, b.1 as i32).take(cap) {
f(x, y);
}
}
fn sub_axis(n: u16, k: u32) -> u16 {
u16::try_from(u32::from(n) * k).unwrap_or(u16::MAX)
}
#[derive(Debug, Clone)]
pub struct Dots {
cells: Size,
masks: Vec<u8>,
inks: Vec<Ink>,
}
impl Default for Dots {
fn default() -> Self {
Self::new(Size::new(1, 1))
}
}
impl Dots {
pub const CELL_W: i32 = 2;
pub const CELL_H: i32 = 4;
pub fn new(cells: Size) -> Self {
Self {
cells,
masks: vec![0; cells.area()],
inks: vec![Ink::BLANK; cells.area()],
}
}
#[inline]
pub fn from_cells(x: f64, y: f64) -> (f64, f64) {
(
x * f64::from(Self::CELL_W) - 0.5,
y * f64::from(Self::CELL_H) - 0.5,
)
}
pub fn dot_size(&self) -> Size {
Size::new(
sub_axis(self.cells.width(), Self::CELL_W as u32),
sub_axis(self.cells.height(), Self::CELL_H as u32),
)
}
pub fn resize(&mut self, cells: Size) {
self.cells = cells;
self.masks.clear();
self.masks.resize(cells.area(), 0);
self.inks.clear();
self.inks.resize(cells.area(), Ink::BLANK);
}
pub fn clear(&mut self) {
self.masks.fill(0);
}
#[inline]
fn locate(&self, x: i32, y: i32) -> Option<(usize, u8)> {
let w = i32::from(self.cells.width());
let h = i32::from(self.cells.height());
let in_x = (0..w * Self::CELL_W).contains(&x);
let in_y = (0..h * Self::CELL_H).contains(&y);
(in_x && in_y).then(|| {
let (cx, cy) = ((x / Self::CELL_W) as usize, (y / Self::CELL_H) as usize);
(cy * w as usize + cx, dot_bit(x, y))
})
}
#[inline]
pub fn set(&mut self, x: i32, y: i32, ink: Ink) {
let Some((i, bit)) = self.locate(x, y) else {
return;
};
if self.masks[i] == 0 || intensity(ink) >= intensity(self.inks[i]) {
self.inks[i] = ink;
}
self.masks[i] |= bit;
}
#[inline]
pub fn plot(&mut self, x: f64, y: f64, ink: Ink) {
if x.is_finite() && y.is_finite() {
self.set(x.round() as i32, y.round() as i32, ink);
}
}
#[inline]
pub fn stipple(&mut self, x: i32, y: i32, p: f64, salt: u64, ink: Ink) {
if stipple_keep(salt, x, y, p) {
self.set(x, y, ink);
}
}
pub fn stipple_puff(&mut self, cx: f64, cy: f64, sigma: f64, peak: f64, salt: u64, ink: Ink) {
if !(cx.is_finite() && cy.is_finite() && peak > 0.0) {
return;
}
self.plot(cx, cy, ink);
if !(sigma.is_finite() && sigma > 0.0) {
return;
}
let size = self.dot_size();
let (w, h) = (f64::from(size.width()), f64::from(size.height()));
let reach = 3.0 * sigma;
let x0 = (cx - reach).ceil().max(0.0);
let x1 = (cx + reach).floor().min(w - 1.0);
let y0 = (cy - reach).ceil().max(0.0);
let y1 = (cy + reach).floor().min(h - 1.0);
if x0 > x1 || y0 > y1 {
return;
}
let (reach2, k) = (reach * reach, -0.5 / (sigma * sigma));
for y in y0 as i32..=y1 as i32 {
let dy = f64::from(y) - cy;
for x in x0 as i32..=x1 as i32 {
let dx = f64::from(x) - cx;
let r2 = dx * dx + dy * dy;
if r2 <= reach2 {
self.stipple(x, y, peak * (k * r2).exp(), salt, ink);
}
}
}
}
pub fn line(&mut self, x0: f64, y0: f64, x1: f64, y1: f64, ink: Ink) {
let size = self.dot_size();
segment(x0, y0, x1, y1, size, |x, y| self.set(x, y, ink));
}
pub fn disc(&mut self, x: f64, y: f64, r: f64, ink: Ink) {
if !(x.is_finite() && y.is_finite() && r.is_finite() && r >= 0.0) {
return;
}
let size = self.dot_size();
let (w, h) = (f64::from(size.width()), f64::from(size.height()));
let (x0, x1) = ((x - r).ceil().max(0.0), (x + r).floor().min(w - 1.0));
let (y0, y1) = ((y - r).ceil().max(0.0), (y + r).floor().min(h - 1.0));
let mut dy = y0;
while dy <= y1 {
let mut dx = x0;
while dx <= x1 {
if (dx - x).hypot(dy - y) <= r {
self.set(dx as i32, dy as i32, ink);
}
dx += 1.0;
}
dy += 1.0;
}
self.plot(x, y, ink);
}
pub fn contour(
&mut self,
values: &[f32],
w: usize,
h: usize,
level: f32,
to_dot: impl Fn(f64, f64) -> (f64, f64),
ink: Ink,
) {
self.contour_by(values, w, h, level, to_dot, |_, _| Some(ink));
}
pub fn contour_by(
&mut self,
values: &[f32],
w: usize,
h: usize,
level: f32,
to_dot: impl Fn(f64, f64) -> (f64, f64),
mut ink: impl FnMut(usize, usize) -> Option<Ink>,
) {
if w < 2 || h < 2 || values.len() < w.saturating_mul(h) {
return;
}
for j in 0..h - 1 {
let (top, bottom) = (
&values[j * w..(j + 1) * w],
&values[(j + 1) * w..(j + 2) * w],
);
for i in 0..w - 1 {
let l = [top[i], top[i + 1], bottom[i + 1], bottom[i]];
let below = l.map(|v| v < level);
if below == [true; 4] || below == [false; 4] {
continue;
}
if let Some(ink) = ink(i, j) {
self.contour_cell(l, level, (i, j), &to_dot, ink);
}
}
}
}
pub fn contour_cell(
&mut self,
corners: [f32; 4],
level: f32,
(i, j): (usize, usize),
to_dot: impl Fn(f64, f64) -> (f64, f64),
ink: Ink,
) {
const AT: [(f64, f64); 4] = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)];
if !corners.iter().all(|v| v.is_finite()) || !level.is_finite() {
return;
}
let mut pts = [(0.0f64, 0.0f64); 4];
let mut n = 0;
for a in 0..4 {
let b = (a + 1) % 4;
let (la, lb) = (corners[a], corners[b]);
if (la < level) != (lb < level) {
let f = f64::from((level - la) / (lb - la));
let (pa, pb) = (AT[a], AT[b]);
let (x, y) = (pa.0 + (pb.0 - pa.0) * f, pa.1 + (pb.1 - pa.1) * f);
pts[n] = to_dot(i as f64 + x, j as f64 + y);
n += 1;
}
}
for p in pts[..n].chunks_exact(2) {
self.line(p[0].0, p[0].1, p[1].0, p[1].1, ink);
}
}
pub fn contour_cell_refined(
&mut self,
corners: [f32; 4],
level: f32,
(i, j): (usize, usize),
k: usize,
to_dot: impl Fn(f64, f64) -> (f64, f64),
ink: Ink,
) {
let k = k.min(16);
if k <= 1 {
self.contour_cell(corners, level, (i, j), to_dot, ink);
return;
}
let c = corners;
let kf = k as f32;
let at = |u: usize, v: usize| {
let (a, b) = (u as f32 / kf, v as f32 / kf);
let top = c[0] + (c[1] - c[0]) * a;
let bottom = c[3] + (c[2] - c[3]) * a;
top + (bottom - top) * b
};
let (x0, y0, kd) = (i as f64, j as f64, k as f64);
let map = |x: f64, y: f64| to_dot(x0 + x / kd, y0 + y / kd);
for v in 0..k {
for u in 0..k {
let sub = [at(u, v), at(u + 1, v), at(u + 1, v + 1), at(u, v + 1)];
let below = sub.map(|x| x < level);
if below == [true; 4] || below == [false; 4] {
continue;
}
self.contour_cell(sub, level, (u, v), map, ink);
}
}
}
pub fn is_lit(&self, x: i32, y: i32) -> bool {
self.locate(x, y)
.is_some_and(|(i, bit)| self.masks[i] & bit != 0)
}
#[inline]
pub fn cell_mask(&self, cx: i32, cy: i32) -> Option<u8> {
let (w, h) = (
i32::from(self.cells.width()),
i32::from(self.cells.height()),
);
((0..w).contains(&cx) && (0..h).contains(&cy))
.then(|| self.masks[cy as usize * w as usize + cx as usize])
}
pub fn blit(&self, canvas: &mut Canvas) {
self.blit_with(canvas, |_, _| Ink::BLANK);
}
pub fn blit_over(&self, canvas: &mut Canvas, under: &Pixels) {
if canvas.mode() == GlyphMode::Ascii {
self.blit(canvas);
} else {
self.blit_with(canvas, |x, y| under.cell_bg(x, y));
}
}
fn blit_with(&self, canvas: &mut Canvas, mut bg: impl FnMut(i32, i32) -> Ink) {
const BLOCK: usize = 16;
let mut blocks = self.masks.chunks_exact(BLOCK);
let mut start = 0;
for block in &mut blocks {
if block != [0; BLOCK] {
self.blit_run(canvas, start, block, &mut bg);
}
start += BLOCK;
}
self.blit_run(canvas, start, blocks.remainder(), &mut bg);
}
fn blit_run(
&self,
canvas: &mut Canvas,
start: usize,
masks: &[u8],
bg: &mut impl FnMut(i32, i32) -> Ink,
) {
let w = usize::from(self.cells.width());
for (i, &mask) in (start..).zip(masks) {
if mask != 0 {
let (x, y) = ((i % w) as i32, (i / w) as i32);
canvas.put_bg(x, y, braille(mask), self.inks[i], bg(x, y));
}
}
}
}
#[derive(Debug, Clone)]
pub struct Density {
dots: Size,
buf: Vec<f32>,
}
impl Default for Density {
fn default() -> Self {
Self::new(Size::new(1, 1))
}
}
impl Density {
pub fn new(cells: Size) -> Self {
let mut d = Self {
dots: Size::new(1, 1),
buf: Vec::new(),
};
d.resize(cells);
d
}
pub fn dot_size(&self) -> Size {
self.dots
}
pub fn resize(&mut self, cells: Size) {
self.dots = Size::new(
sub_axis(cells.width(), Dots::CELL_W as u32),
sub_axis(cells.height(), Dots::CELL_H as u32),
);
self.buf.clear();
self.buf.resize(self.dots.area(), 0.0);
}
pub fn clear(&mut self) {
self.buf.fill(0.0);
}
pub fn decay(&mut self, k: f32) {
fade(&mut self.buf, k);
}
#[inline]
fn index(&self, x: i32, y: i32) -> Option<usize> {
let (w, h) = (i32::from(self.dots.width()), i32::from(self.dots.height()));
((0..w).contains(&x) && (0..h).contains(&y))
.then(|| y as usize * usize::from(self.dots.width()) + x as usize)
}
#[inline]
fn add(&mut self, x: i32, y: i32, w: f32) {
if let Some(i) = self.index(x, y) {
self.buf[i] += w;
}
}
#[inline]
pub fn deposit(&mut self, x: f64, y: f64, w: f32) {
if x.is_finite() && y.is_finite() && w.is_finite() {
self.add(x.round() as i32, y.round() as i32, w);
}
}
#[inline]
pub fn get(&self, x: i32, y: i32) -> Option<f32> {
self.index(x, y).map(|i| self.buf[i])
}
pub fn to_dots(&self, dots: &mut Dots, threshold: f32, mut map: impl FnMut(f32) -> Ink) {
let w = usize::from(self.dots.width());
for (y, row) in self.buf.chunks_exact(w).enumerate() {
for (x, &v) in row.iter().enumerate() {
if v >= threshold {
dots.set(x as i32, y as i32, map(v));
}
}
}
}
}
fn fade(buf: &mut [f32], k: f32) {
if k.is_nan() || k >= 1.0 {
return;
}
let k = k.max(0.0);
for v in buf {
*v *= k;
}
}
#[derive(Debug, Clone)]
pub struct Glow {
px: Size,
buf: Vec<f32>,
}
impl Default for Glow {
fn default() -> Self {
Self::new(Size::new(1, 1))
}
}
impl Glow {
const DOTS_PER_PIXEL: i32 = 2;
pub fn new(cells: Size) -> Self {
let mut g = Self {
px: Size::new(1, 1),
buf: Vec::new(),
};
g.resize(cells);
g
}
pub fn pixel_size(&self) -> Size {
self.px
}
pub fn resize(&mut self, cells: Size) {
self.px = Size::new(cells.width(), sub_axis(cells.height(), 2));
self.buf.clear();
self.buf.resize(self.px.area(), 0.0);
}
pub fn clear(&mut self) {
self.buf.fill(0.0);
}
pub fn decay(&mut self, k: f32) {
fade(&mut self.buf, k);
}
pub fn splat(&mut self, x: f64, y: f64, kernel: &[(i32, i32, f32)], scale: f32) {
if !(x.is_finite() && y.is_finite()) {
return;
}
let (px, py) = (
(x.round() as i32).div_euclid(Self::DOTS_PER_PIXEL),
(y.round() as i32).div_euclid(Self::DOTS_PER_PIXEL),
);
let (w, h) = (i32::from(self.px.width()), i32::from(self.px.height()));
for &(dx, dy, k) in kernel {
let (x, y) = (px.saturating_add(dx), py.saturating_add(dy));
let add = scale * k;
if (0..w).contains(&x) && (0..h).contains(&y) && add.is_finite() {
self.buf[y as usize * w as usize + x as usize] += add;
}
}
}
#[inline]
pub fn splat_bilinear(&mut self, x: f64, y: f64, w: f32) {
if !(x.is_finite() && y.is_finite() && w.is_finite()) {
return;
}
let (pw, ph) = (usize::from(self.px.width()), usize::from(self.px.height()));
let (x0, y0) = (x.floor(), y.floor());
let (fx, fy) = ((x - x0) as f32, (y - y0) as f32);
for (dx, dy, k) in [
(0.0, 0.0, (1.0 - fx) * (1.0 - fy)),
(1.0, 0.0, fx * (1.0 - fy)),
(0.0, 1.0, (1.0 - fx) * fy),
(1.0, 1.0, fx * fy),
] {
let (px, py) = (x0 + dx, y0 + dy);
if px >= 0.0 && py >= 0.0 && (px as usize) < pw && (py as usize) < ph {
self.buf[py as usize * pw + px as usize] += w * k;
}
}
}
#[inline]
pub fn values(&self) -> &[f32] {
&self.buf
}
#[inline]
pub fn get(&self, x: i32, y: i32) -> Option<f32> {
let (w, h) = (i32::from(self.px.width()), i32::from(self.px.height()));
((0..w).contains(&x) && (0..h).contains(&y))
.then(|| self.buf[y as usize * w as usize + x as usize])
}
}
#[derive(Debug, Clone)]
pub struct Tone {
inv_white: f32,
lut: [u8; Tone::LUT],
}
impl Default for Tone {
fn default() -> Self {
Self::asinh(1.0, 1.0)
}
}
impl Tone {
pub const LUT: usize = 1024;
pub fn asinh(knee: f32, white: f32) -> Self {
let sane = |v: f32| {
if v.is_finite() && v > 0.0 {
f64::from(v)
} else {
1.0
}
};
let white = sane(white);
let knee = sane(knee).max(white / 1000.0);
let norm = (white / knee).asinh();
let last = (Self::LUT - 1) as f64;
let lut = std::array::from_fn(|i| {
let s = i as f64 / last;
ink::level(255.0 * (white * s * s / knee).asinh() / norm)
});
Self {
inv_white: (1.0 / white) as f32,
lut,
}
}
#[inline]
pub fn level(&self, v: f32) -> u8 {
let pos = (v * self.inv_white).sqrt() * (Self::LUT - 1) as f32;
self.lut[(pos.round() as usize).min(Self::LUT - 1)]
}
}
const UPPER: Glyph = Glyph::new('▀', '#');
const LOWER: Glyph = Glyph::new('▄', '#');
#[derive(Debug, Clone)]
pub struct Pixels {
cells: Size,
px: Vec<Ink>,
}
impl Default for Pixels {
fn default() -> Self {
Self::new(Size::new(1, 1))
}
}
#[inline]
fn is_empty(ink: Ink) -> bool {
ink.role == Role::Background
}
impl Pixels {
pub fn new(cells: Size) -> Self {
Self {
cells,
px: vec![Ink::BLANK; 2 * cells.area()],
}
}
pub fn pixel_size(&self) -> Size {
Size::new(self.cells.width(), sub_axis(self.cells.height(), 2))
}
pub fn resize(&mut self, cells: Size) {
self.cells = cells;
self.px.clear();
self.px.resize(2 * cells.area(), Ink::BLANK);
}
pub fn fill(&mut self, ink: Ink) {
self.px.fill(ink);
}
pub fn clear(&mut self) {
self.fill(Ink::BLANK);
}
#[inline]
fn index(&self, x: i32, y: i32) -> Option<usize> {
let w = i32::from(self.cells.width());
let h = 2 * i32::from(self.cells.height());
((0..w).contains(&x) && (0..h).contains(&y)).then(|| y as usize * w as usize + x as usize)
}
#[inline]
pub fn set(&mut self, x: i32, y: i32, ink: Ink) {
if let Some(i) = self.index(x, y) {
self.px[i] = ink;
}
}
#[inline]
pub fn get(&self, x: i32, y: i32) -> Option<Ink> {
self.index(x, y).map(|i| self.px[i])
}
#[inline]
pub fn cell_bg(&self, x: i32, y: i32) -> Ink {
let px = |py: i32| self.get(x, py).unwrap_or(Ink::BLANK);
let ink = stronger(px(2 * y), px(2 * y + 1));
if is_empty(ink) { Ink::BLANK } else { ink }
}
pub fn backdrop(&self, canvas: &mut Canvas) {
if canvas.mode() != GlyphMode::Unicode {
return;
}
let w = self.cells.width().min(canvas.size().width());
let h = self.cells.height().min(canvas.size().height());
for y in 0..i32::from(h) {
for x in 0..i32::from(w) {
let Some(&cell) = canvas.get(x, y) else {
continue;
};
if cell.bg != Ink::BLANK || matches!(cell.ch, '▀' | '▄' | '█') {
continue;
}
let under = self.cell_bg(x, y);
if under != Ink::BLANK {
canvas.put_bg(x, y, Glyph::ascii(cell.ch), cell.ink, under);
}
}
}
}
pub fn shade(&mut self, mut shader: impl FnMut(i32, i32) -> Ink) {
let w = usize::from(self.cells.width());
for (y, row) in self.px.chunks_exact_mut(w).enumerate() {
for (x, px) in row.iter_mut().enumerate() {
*px = shader(x as i32, y as i32);
}
}
}
pub fn dissolve(&mut self, floor: u8) {
let half = f64::from(floor) / 2.0;
for px in &mut self.px {
let i = intensity(*px);
if is_empty(*px) || px.role == Role::Phase || i >= floor {
continue;
}
let u = ((f64::from(i) - half) / half).clamp(0.0, 1.0);
let faded = (f64::from(i) * u * u * (3.0 - 2.0 * u)).round() as u8;
*px = match (faded, px.role) {
(0, _) => Ink::BLANK,
(f, Role::Div) if px.level >= 128 => Ink::new(Role::Div, 128 + f),
(f, Role::Div) => Ink::new(Role::Div, 128 - f),
(f, role) => Ink::new(role, f),
};
}
}
pub fn blit<F>(&self, canvas: &mut Canvas, mut ascii: F)
where
F: FnMut(i32, i32, Ink, Ink) -> Option<(char, Ink)>,
{
let w = usize::from(self.cells.width());
let unicode = canvas.mode() == GlyphMode::Unicode;
for (cy, pair) in self.px.chunks_exact(2 * w).enumerate() {
let (tops, bottoms) = pair.split_at(w);
for (cx, (&top, &bottom)) in tops.iter().zip(bottoms).enumerate() {
let (x, y) = (cx as i32, cy as i32);
if !unicode {
if let Some((ch, ink)) = ascii(x, y, top, bottom) {
canvas.put(x, y, Glyph::ascii(ch), ink);
}
continue;
}
half_block(canvas, x, y, top, bottom);
}
}
}
}
#[inline]
pub fn half_block(canvas: &mut Canvas, x: i32, y: i32, top: Ink, bottom: Ink) {
match (is_empty(top), is_empty(bottom)) {
(true, true) => {}
(false, true) => canvas.put(x, y, UPPER, top),
(true, false) => canvas.put(x, y, LOWER, bottom),
(false, false) => canvas.put_bg(x, y, UPPER, top, bottom),
}
}