Struct surf_n_term::image::Image

source ·
pub struct Image { /* private fields */ }
Expand description

Arc wrapped RGBA surface with precomputed hash

Implementations§

source§

impl Image

source

pub fn new(surf: impl Surface<Item = impl Color>) -> Self

Create new image from the RGBA surface

source

pub fn from_parts(data: Arc<[RGBA]>, shape: Shape) -> Self

Create new image from parts

source

pub fn crop<RS, CS>(&self, rows: RS, cols: CS) -> Self
where RS: ViewBounds, CS: ViewBounds,

Crop image

source

pub fn resize(&self, size: Size) -> Self

Resize image using bi-linear interpolation

source

pub fn size_cells(&self, pixels_per_cell: Size) -> Size

Size in cells

source

pub fn quantize( &self, palette_size: usize, dither: bool, bg: Option<RGBA> ) -> Option<(ColorPalette, SurfaceOwned<usize>)>

Quantize image

Perform palette extraction and Floyd–Steinberg dithering.

source

pub fn write_png(&self, w: impl Write) -> Result<(), EncodingError>

Write image as PNG

source

pub fn ascii_view(&self) -> ImageAsciiView

ASCII image view

Trait Implementations§

source§

impl Clone for Image

source§

fn clone(&self) -> Image

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Image

source§

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

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

impl<'de> Deserialize<'de> for Image

Image deserializer encoding is { data: base64(deflate(image)), size: Size, channels: u8 }

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<SurfaceOwned<RGBA>> for Image

source§

fn from(value: SurfaceOwned<RGBA>) -> Self

Converts to this type from the input type.
source§

impl Hash for Image

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Image

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Image

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Image

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Image

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Surface for Image

§

type Item = RGBA

source§

fn shape(&self) -> Shape

Shape describes data layout inside Self::data() slice.
source§

fn data(&self) -> &[Self::Item]

Slice containing all the items Read more
source§

fn is_empty(&self) -> bool

Check if surface is empty
source§

fn height(&self) -> usize

Height of the surface
source§

fn width(&self) -> usize

Width of the surface
source§

fn size(&self) -> Size

Size of the surface
source§

fn hash(&self) -> u64
where Self::Item: Hash,

source§

fn get(&self, pos: Position) -> Option<&Self::Item>

Get immutable reference to the element specified by row and column
source§

fn iter(&self) -> SurfaceIter<'_, Self::Item>

Iterator over immutable references to the items of the view in the row-major order
source§

fn view<RS, CS>(&self, rows: RS, cols: CS) -> SurfaceView<'_, Self::Item>
where RS: ViewBounds, CS: ViewBounds, Self: Sized,

Create an immutable sub-surface restricted by rows and cols bounds.
source§

fn as_ref(&self) -> SurfaceView<'_, Self::Item>

source§

fn view_owned<RS, CS>(self, rows: RS, cols: CS) -> SurfaceOwnedView<Self>
where RS: ViewBounds, CS: ViewBounds, Self: Sized,

Create owned sub-surface restricted by rows and cols bounds.
source§

fn transpose(self) -> SurfaceOwnedView<Self>
where Self: Sized,

source§

fn map<F, T>(&self, f: F) -> SurfaceOwned<T>
where F: FnMut(Position, &Self::Item) -> T, Self: Sized,

source§

fn to_owned_surf(&self) -> SurfaceOwned<Self::Item>
where Self::Item: Clone,

Create owned copy of the surface
source§

impl View for Image

source§

fn render( &self, ctx: &ViewContext, surf: TerminalSurface<'_>, layout: ViewLayout<'_> ) -> Result<(), Error>

Render view into a given surface with the provided layout
source§

fn layout( &self, ctx: &ViewContext, ct: BoxConstraint, layout: ViewMutLayout<'_> ) -> Result<(), Error>

Compute layout of the view based on the constraints
source§

fn layout_new<'a>( &self, ctx: &ViewContext, ct: BoxConstraint, store: &'a mut ViewLayoutStore ) -> Result<ViewMutLayout<'a>, Error>

source§

fn boxed<'a>(self) -> BoxView<'a>
where Self: Sized + Send + Sync + 'a,

Convert into boxed view
source§

fn debug(&self, size: Size) -> ViewDebug<&Self>
where Self: Sized,

Wrapper around view that implements std::fmt::Debug which renders view. Only supposed to be used for debugging.
source§

fn trace_layout<T>(self, trace: T) -> TraceLayout<Self, T>
where T: Fn(&BoxConstraint, ViewLayout<'_>), Self: Sized,

Wrapper around view that calls trace function on every layout call
source§

fn tag<T>(self, tag: T) -> Tag<T, Self>
where T: Any + Clone, Self: Sized,

Tag the view
source§

impl Eq for Image

Auto Trait Implementations§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnwindSafe for Image

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<V> IntoView for V
where V: View,

§

type View = V

Result view type
source§

fn into_view(self) -> <V as IntoView>::View

Convert into a View
source§

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

§

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>,

§

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>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,