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
impl Image
Sourcepub fn from_bytes(buf: &[u8]) -> Result<Image, Error>
pub fn from_bytes(buf: &[u8]) -> Result<Image, Error>
Decode a whole image from an in-memory buffer.
Sourcepub fn from_bytes_with(
buf: &[u8],
params: DecodeParameters,
) -> Result<Image, Error>
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.
Sourcepub fn from_file<P>(path: P) -> Result<Image, Error>
pub fn from_file<P>(path: P) -> Result<Image, Error>
Decode a whole image from a file (the file is read into memory first; no extra feature is required).
Sourcepub fn from_file_with<P>(
path: P,
params: DecodeParameters,
) -> Result<Image, Error>
pub fn from_file_with<P>( path: P, params: DecodeParameters, ) -> Result<Image, Error>
Decode from a file with the given decoder settings.
Sourcepub fn width(&self) -> u32
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.
Sourcepub fn height(&self) -> u32
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.
Sourcepub fn orig_width(&self) -> u32
pub fn orig_width(&self) -> u32
Full image extent width (x1 - x0), not reduced by the decode
resolution factor.
Sourcepub fn orig_height(&self) -> u32
pub fn orig_height(&self) -> u32
Full image extent height (y1 - y0), not reduced by the decode
resolution factor.
Sourcepub fn color_space(&self) -> ColorSpace
pub fn color_space(&self) -> ColorSpace
The image colour space.
Sourcepub fn save_as_file<P>(&self, path: P) -> Result<(), Error>
pub fn save_as_file<P>(&self, path: P) -> Result<(), Error>
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).
Sourcepub fn save_as_file_with<P>(
&self,
path: P,
params: EncodeParameters,
) -> Result<(), Error>
pub fn save_as_file_with<P>( &self, path: P, params: EncodeParameters, ) -> Result<(), Error>
Like Self::save_as_file with explicit encoder parameters.
Sourcepub fn num_components(&self) -> u32
pub fn num_components(&self) -> u32
Number of components.
Sourcepub fn has_icc_profile(&self) -> bool
pub fn has_icc_profile(&self) -> bool
Whether an ICC profile is attached.
Sourcepub fn components(&self) -> &[CoreImageComp]
pub fn components(&self) -> &[CoreImageComp]
The component planes.
Sourcepub fn into_core_image(self) -> CoreImage
pub fn into_core_image(self) -> CoreImage
The raw decoded data (escape hatch to the low-level API).
Sourcepub fn from_core_image(core: CoreImage) -> Image
pub fn from_core_image(core: CoreImage) -> Image
Build an image from raw component planes (the input side of
encode/encode_jp2).
Sourcepub fn encode(self, params: EncodeParameters) -> Result<Vec<u8>, Error>
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).
Sourcepub fn encode_jp2(self, params: EncodeParameters) -> Result<Vec<u8>, Error>
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).
Sourcepub fn encode_to_writer<W>(
self,
params: EncodeParameters,
writer: W,
) -> Result<(), Error>
pub fn encode_to_writer<W>( self, params: EncodeParameters, writer: W, ) -> Result<(), Error>
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.
Sourcepub fn encode_jp2_to_writer<W>(
self,
params: EncodeParameters,
writer: W,
) -> Result<(), Error>
pub fn encode_jp2_to_writer<W>( self, params: EncodeParameters, writer: W, ) -> Result<(), Error>
JP2-container flavour of Self::encode_to_writer (R4-I9).
Trait Implementations§
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> 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
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> ⓘ
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> ⓘ
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