Skip to main content

Image

Struct Image 

Source
pub struct Image { /* private fields */ }
Expand description

A fully decoded JPEG 2000 image (owned pixel data).

Clone deep-copies every component buffer; clone only when the source must survive a by-value encode.

Implementations§

Source§

impl Image

Source

pub fn from_bytes(buf: &[u8]) -> Result<Image, Error>

Decode a whole image from an in-memory buffer.

Source

pub fn from_bytes_with( buf: &[u8], params: DecodeParameters, ) -> Result<Image, Error>

Decode from an in-memory buffer with the given decoder settings.

Lenient mode (the default; DecodeParameters::strict(true) opts out) preserves the pixels decoded before a truncation point. Note the contract’s scope: truncation AFTER the last tile’s data (a missing EOC) delivers the fully decoded image, but truncation mid-tile — or a used-components failure — may return the header image with EMPTY component data (earlier tiles’ pixels are not moved out). The C reference behaves the same way; check Image::components() data lengths when decoding untrusted partial streams.

Source

pub fn from_file<P>(path: P) -> Result<Image, Error>
where P: AsRef<Path>,

Decode a whole image from a file (the file is read into memory first; no extra feature is required).

Source

pub fn from_file_with<P>( path: P, params: DecodeParameters, ) -> Result<Image, Error>
where P: AsRef<Path>,

Decode from a file with the given decoder settings.

Source

pub fn width(&self) -> u32

Width of the decoded image: the first component’s plane width. Reduced by the decode resolution factor (and by the decode area), like the jpeg2k Image; see Self::orig_width for the full image extent.

Source

pub fn height(&self) -> u32

Height of the decoded image: the first component’s plane height. Reduced by the decode resolution factor (and by the decode area), like the jpeg2k Image; see Self::orig_height for the full image extent.

Source

pub fn orig_width(&self) -> u32

Full image extent width (x1 - x0), not reduced by the decode resolution factor.

Source

pub fn orig_height(&self) -> u32

Full image extent height (y1 - y0), not reduced by the decode resolution factor.

Source

pub fn color_space(&self) -> ColorSpace

The image colour space.

Source

pub fn x_offset(&self) -> u32

Horizontal origin of the image (core.x0).

Source

pub fn y_offset(&self) -> u32

Vertical origin of the image (core.y0).

Source

pub fn save_as_file<P>(&self, path: P) -> Result<(), Error>
where P: AsRef<Path>,

Save the image to a JPEG 2000 file; the format is detected from the file extension (.j2k/.j2c/.jpc/.jhc = codestream, .jp2/.jph = JP2 container).

The image is cloned first (encode* consume the image, since the encoder transforms the component buffers in place).

Source

pub fn save_as_file_with<P>( &self, path: P, params: EncodeParameters, ) -> Result<(), Error>
where P: AsRef<Path>,

Like Self::save_as_file with explicit encoder parameters.

Source

pub fn num_components(&self) -> u32

Number of components.

Source

pub fn has_icc_profile(&self) -> bool

Whether an ICC profile is attached.

Source

pub fn components(&self) -> &[CoreImageComp]

The component planes.

Source

pub fn into_core_image(self) -> CoreImage

The raw decoded data (escape hatch to the low-level API).

Source

pub fn from_core_image(core: CoreImage) -> Image

Build an image from raw component planes (the input side of encode/encode_jp2).

Source

pub fn encode(self, params: EncodeParameters) -> Result<Vec<u8>, Error>

Encode the image to a JPEG 2000 codestream held in an in-memory buffer. Takes the image by value: the encoder transforms the component buffers in place, so no copy is made (clone first to keep the source).

Source

pub fn encode_jp2(self, params: EncodeParameters) -> Result<Vec<u8>, Error>

Encode the image to a JP2 file in an in-memory buffer. By-value like encode (clone first to keep the source).

Source

pub fn encode_to_writer<W>( self, params: EncodeParameters, writer: W, ) -> Result<(), Error>
where W: Write + Seek + 'static,

Encode the image into any Write + Seek sink (the encoder seeks back to patch marker lengths, so a plain Write is not enough). By-value like encode.

Source

pub fn encode_jp2_to_writer<W>( self, params: EncodeParameters, writer: W, ) -> Result<(), Error>
where W: Write + Seek + 'static,

JP2-container flavour of Self::encode_to_writer (R4-I9).

Trait Implementations§

Source§

impl Clone for Image

Source§

fn clone(&self) -> Image

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 Image

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Image

§

impl Freeze for Image

§

impl Move for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnsafeUnpin 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<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> 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<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.