Skip to main content

GrayImage

Struct GrayImage 

Source
pub struct GrayImage { /* private fields */ }
Available on crate feature scan only.
Expand description

An 8-bit greyscale image: what a scanner actually works on.

Colour carries no information a barcode reader wants, so every input is reduced to luminance on the way in. Transparent pixels are composited over white first, because a barcode rendered with Color::TRANSPARENT as its background is black ink on nothing, and “nothing” prints as paper.

Implementations§

Source§

impl GrayImage

Source

pub fn from_luma(width: u32, height: u32, luma: Vec<u8>) -> Result<Self>

Wrap an existing 8-bit luminance buffer, one byte per pixel.

§Errors

Returns Error::InvalidImage if either dimension is zero, if the buffer length is not exactly width * height, or if the image is larger than the crate’s pixel-count limit.

Source

pub fn from_rgb8(width: u32, height: u32, rgb: &[u8]) -> Result<Self>

Convert a packed 8-bit RGB buffer, three bytes per pixel.

§Errors

As from_luma, for a buffer of width * height * 3.

Source

pub fn from_rgba8(width: u32, height: u32, rgba: &[u8]) -> Result<Self>

Convert a packed 8-bit RGBA buffer, four bytes per pixel, compositing over a white background.

§Errors

As from_luma, for a buffer of width * height * 4.

Source

pub fn from_png(bytes: &[u8]) -> Result<Self>

Available on crate feature png only.

Decode a PNG image.

Handles every colour type and bit depth the png crate can normalise to 8 bits, including palettes and greyscale.

§Errors

Returns Error::InvalidImage if the bytes are not a PNG this crate can read, or if the image exceeds the pixel-count limit.

Source

pub fn from_png_file(path: impl AsRef<Path>) -> Result<Self>

Available on crate features png and std only.

Read a PNG file from disk.

§Errors

Returns Error::Io if the file cannot be read, or whatever from_png reports.

Source

pub fn width(&self) -> u32

Width in pixels.

Source

pub fn height(&self) -> u32

Height in pixels.

Source

pub fn luma(&self) -> &[u8]

The luminance buffer, row-major, one byte per pixel.

Source

pub fn pixel(&self, x: u32, y: u32) -> u8

Luminance at (x, y). Out-of-bounds reads as white, matching the way BitMatrix::get tolerates out-of-bounds coordinates.

Trait Implementations§

Source§

impl Clone for GrayImage

Source§

fn clone(&self) -> GrayImage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GrayImage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for GrayImage

Source§

impl PartialEq for GrayImage

Source§

fn eq(&self, other: &GrayImage) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GrayImage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.