Struct BiLevel

struct BiLevel

A bi-level color map

Examples

use image::imageops::colorops::{index_colors, BiLevel, ColorMap};
use image::{ImageBuffer, Luma};

let (w, h) = (16, 16);
// Create an image with a smooth horizontal gradient from black (0) to white (255).
let gray = ImageBuffer::from_fn(w, h, |x, y| -> Luma<u8> { [(255 * x / w) as u8].into() });
// Mapping the gray image through the `BiLevel` filter should map gray pixels less than half
// intensity (127) to black (0), and anything greater to white (255).
let cmap = BiLevel;
let palletized = index_colors(&gray, &cmap);
let mapped = ImageBuffer::from_fn(w, h, |x, y| {
    let p = palletized.get_pixel(x, y);
    cmap.lookup(p.0[0] as usize)
        .expect("indexed color out-of-range")
});
// Create an black and white image of expected output.
let bw = ImageBuffer::from_fn(w, h, |x, y| -> Luma<u8> {
    if x <= (w / 2) {
        [0].into()
    } else {
        [255].into()
    }
});
assert_eq!(mapped, bw);

Implementations

impl Clone for BiLevel

fn clone(self: &Self) -> BiLevel

impl ColorMap for BiLevel

fn index_of(self: &Self, color: &Luma<u8>) -> usize
fn lookup(self: &Self, idx: usize) -> Option<<Self as >::Color>
fn has_lookup(self: &Self) -> bool

Indicate NeuQuant implements lookup.

fn map_color(self: &Self, color: &mut Luma<u8>)

impl Copy for BiLevel

impl Freeze for BiLevel

impl RefUnwindSafe for BiLevel

impl Send for BiLevel

impl Sync for BiLevel

impl Unpin for BiLevel

impl UnsafeUnpin for BiLevel

impl UnwindSafe for BiLevel

impl<T> Any for BiLevel

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for BiLevel

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for BiLevel

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for BiLevel

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for BiLevel

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Pointable for BiLevel

unsafe fn init(init: <T as Pointable>::Init) -> usize
unsafe fn deref<'a>(ptr: usize) -> &'a T
unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
unsafe fn drop(ptr: usize)

impl<T> ToOwned for BiLevel

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for BiLevel

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for BiLevel

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for BiLevel

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>