pub enum PineappleImage {
U8(PineappleBuffer<u8, Vec<u8>>),
U16(PineappleBuffer<u16, Vec<u16>>),
U32(PineappleBuffer<u32, Vec<u32>>),
U64(PineappleBuffer<u64, Vec<u64>>),
I32(PineappleBuffer<i32, Vec<i32>>),
I64(PineappleBuffer<i64, Vec<i64>>),
F32(PineappleBuffer<f32, Vec<f32>>),
F64(PineappleBuffer<f64, Vec<f64>>),
}Expand description
A wrapper for representing and storing array-shaped pixels
The enum holds all valid, or potentially valid, image formats in terms
of their subpixel data types. All external image types (e.g DynamicImage)
should be converted to a PineappleImage via a method on this enum.
§Examples
use image::{RgbImage, DynamicImage};
use pineapple_core::im::PineappleImage;
let rgb = RgbImage::new(10, 10);
let dynamic = DynamicImage::ImageRgb8(rgb);
let image = PineappleImage::new_from_default(dynamic);use image::ImageReader;
use pineapple_core::im::PineappleImage;
let dynamic = ImageReader::open("image.png")
.expect("Failed to read image")
.with_guessed_format()
.unwrap()
.decode()
.unwrap();
let image = PineappleImage::new_from_default(dynamic);Variants§
U8(PineappleBuffer<u8, Vec<u8>>)
U16(PineappleBuffer<u16, Vec<u16>>)
U32(PineappleBuffer<u32, Vec<u32>>)
U64(PineappleBuffer<u64, Vec<u64>>)
I32(PineappleBuffer<i32, Vec<i32>>)
I64(PineappleBuffer<i64, Vec<i64>>)
F32(PineappleBuffer<f32, Vec<f32>>)
F64(PineappleBuffer<f64, Vec<f64>>)
Implementations§
Source§impl PineappleImage
impl PineappleImage
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<PineappleImage, PineappleError>
pub fn open<P: AsRef<Path>>(path: P) -> Result<PineappleImage, PineappleError>
Open a new image from a provided path
§Arguments
path- A path to an image with a valid extension
use pineapple_core::im::PineappleImage;
let image = PineappleImage::open("image.png");Sourcepub fn new_from_default(
image: DynamicImage,
) -> Result<PineappleImage, PineappleError>
pub fn new_from_default( image: DynamicImage, ) -> Result<PineappleImage, PineappleError>
Initialize a new image from a DynamicImage
§Arguments
image- An 8 or 16-bit grayscale or rgb DynamicImage
§Examples
use image::{GrayImage, DynamicImage};
use pineapple_core::im::PineappleImage;
let gray = GrayImage::new(10, 10);
let dynamic = DynamicImage::ImageLuma8(gray);
let image = PineappleImage::new_from_default(dynamic);Sourcepub fn new_from_numpy(
npy: NpyFile<&[u8]>,
) -> Result<PineappleImage, PineappleError>
pub fn new_from_numpy( npy: NpyFile<&[u8]>, ) -> Result<PineappleImage, PineappleError>
Initialize a new image from a numpy array buffer
§Arguments
npy- A (height, width, channel) shaped numpy array buffer
§Examples
use npyz::NpyFile;
use pineapple_core::im::PineappleImage;
let bytes = std::fs::read("image.npy").unwrap();
let npy = NpyFile::new(&bytes[..]).unwrap();
let image = PineappleImage::new_from_numpy(npy);Sourcepub fn save<P: AsRef<Path>>(self, path: P) -> Result<(), PineappleError>
pub fn save<P: AsRef<Path>>(self, path: P) -> Result<(), PineappleError>
Save image
§Arguments
path- A path to an image with a valid extension
use pineapple_core::im::PineappleImage;
let image = PineappleImage::open("image.png").unwrap();
image.save("image.npy").unwrap();Sourcepub fn save_as_default<P: AsRef<Path>>(
self,
path: P,
) -> Result<(), PineappleError>
pub fn save_as_default<P: AsRef<Path>>( self, path: P, ) -> Result<(), PineappleError>
Save image as a default image format
§Arguments
path- Path to output image
§Examples
use image::{GrayImage, DynamicImage};
use pineapple_core::im::PineappleImage;
let gray = GrayImage::new(10, 10);
let dynamic = DynamicImage::ImageLuma8(gray);
let image = PineappleImage::new_from_default(dynamic).unwrap();
image.save_as_default("new_image.png").unwrap();Sourcepub fn save_as_numpy<P: AsRef<Path>>(
self,
path: P,
) -> Result<(), PineappleError>
pub fn save_as_numpy<P: AsRef<Path>>( self, path: P, ) -> Result<(), PineappleError>
Save image as a numpy format
§Arguments
path- Path to output image
§Examples
use image::{GrayImage, DynamicImage};
use pineapple_core::im::PineappleImage;
let gray = GrayImage::new(10, 10);
let dynamic = DynamicImage::ImageLuma8(gray);
let image = PineappleImage::new_from_default(dynamic).unwrap();
image.save_as_numpy("new_image.npy").unwrap();Source§impl PineappleImage
impl PineappleImage
Sourcepub fn crop_view(&self, x: u32, y: u32, w: u32, h: u32) -> PineappleView<'_>
pub fn crop_view(&self, x: u32, y: u32, w: u32, h: u32) -> PineappleView<'_>
Generate a zero-copy crop of an image subregion
§Arguments
x- Minimum x-coordinate (left)y- Minimum y-coordinate (bottom)w- Width of croph- Height of crop
Sourcepub fn crop(
&self,
x: u32,
y: u32,
w: u32,
h: u32,
) -> Result<PineappleImage, PineappleError>
pub fn crop( &self, x: u32, y: u32, w: u32, h: u32, ) -> Result<PineappleImage, PineappleError>
Create a new image with copied cropped contents
§Arguments
x- Minimum x-coordinate (left)y- Minimum y-coordinate (bottom)w- Width of croph- Height of crop
Sourcepub fn crop_masked(
&self,
x: u32,
y: u32,
w: u32,
h: u32,
mask: &PineappleMaskView<'_>,
mask_style: MaskingStyle,
) -> Result<PineappleImage, PineappleError>
pub fn crop_masked( &self, x: u32, y: u32, w: u32, h: u32, mask: &PineappleMaskView<'_>, mask_style: MaskingStyle, ) -> Result<PineappleImage, PineappleError>
Crops the image while applying a mask to either foreground or background pixels
§Arguments
x- Minimum x-coordinate (left)y- Minimum y-coordinate (bottom)w- Width of croph- Height of cropmask- A cropped mask viewmask_style- Foreground or background masking style
Sourcepub fn resize(
&self,
width: u32,
height: u32,
) -> Result<PineappleImage, PineappleError>
pub fn resize( &self, width: u32, height: u32, ) -> Result<PineappleImage, PineappleError>
Trait Implementations§
Source§impl Clone for PineappleImage
impl Clone for PineappleImage
Source§fn clone(&self) -> PineappleImage
fn clone(&self) -> PineappleImage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PineappleImage
impl RefUnwindSafe for PineappleImage
impl Send for PineappleImage
impl Sync for PineappleImage
impl Unpin for PineappleImage
impl UnwindSafe for PineappleImage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.