Skip to main content

ImageResource

Struct ImageResource 

Source
pub struct ImageResource {
    pub samples: Vec<u8>,
    pub px_w: u32,
    pub px_h: u32,
    pub jpeg_dct: Option<JpegDct>,
    pub pdf: Option<PdfPageResource>,
}
Expand description

A decoded raster image, referenced via its ImageId. Mirrors v0.0.6’s ImageInfo (imageInfo.ml).

Every source format is flattened to 8-bit DeviceRGB and any alpha channel is dropped; transparency (/SMask) is unimplemented. jpeg_dct additionally carries the source’s original, still-DCT-encoded bytes for a baseline JPEG, so write_image_xobjects can embed those directly instead of re-encoding the flattened RGB8 samples.

Fields§

§samples: Vec<u8>

Row-major, top-to-bottom, 3-bytes-per-pixel RGB8 samples with no padding — exactly what pdf_writer::Chunk::image_xobject wants for a DeviceRGB image at bits_per_component(8).

§px_w: u32§px_h: u32§jpeg_dct: Option<JpegDct>

Some for a baseline (or extended-sequential) 8-bit JPEG with 1 or 3 color components — see sniff_baseline_jpeg_dct for exactly which qualify. None for every non-JPEG source, and for a JPEG this port cannot map to a PDF colorspace without guessing (progressive, 12-bit, or 4-component CMYK/YCCK).

§pdf: Option<PdfPageResource>

Some when this resource is an imported page of an external PDF (load-pdf-image) rather than a decoded raster image; samples/px_w/px_h are then left empty, and PDF-page consumers branch on this field instead.

Implementations§

Source§

impl ImageResource

Source

pub fn sniff_baseline_jpeg_dct(bytes: Vec<u8>) -> Option<JpegDct>

Scan raw file bytes for a JPEG SOF0 (baseline DCT) or SOF1 (extended sequential DCT) marker — the two variants a /DCTDecode XObject can safely wrap verbatim, matching upstream’s own JPEG special-case (imageInfo.ml’s bypass of decode/re-encode for Jpeg). Returns None, meaning “fall back to the flattened RGB8 embedding”, for:

  • anything that isn’t a JPEG (no FFD8 SOI marker);
  • a malformed/truncated JPEG (a segment length running past the end of the buffer, or scan data reached before any SOF marker);
  • progressive, lossless, arithmetic-coded, or hierarchical JPEGs (any SOF other than 0xC0/0xC1) — viewer DCTDecode support for these is inconsistent, so only the two universally-supported variants are trusted;
  • non-8-bit sample precision;
  • anything other than 1 or 3 color components — in particular 4-component CMYK/YCCK, whose correct embedding depends on an Adobe APP14 transform flag (some store inverted samples) this port does not interpret.

bytes is consumed so the Some case hands the file contents into JpegDct with no copy.

Source

pub fn intrinsic_dims_pt(&self) -> (f64, f64)

Intrinsic dimensions for aspect-ratio math (use-image-by-width): pixel extents for a raster resource, MediaBox point extents for an imported PDF page. Both ratios are dimensionless (px/px or pt/pt), so callers apply the same height = width * ih/iw regardless of kind — only the placement CTM needs to know which units these are.

Trait Implementations§

Source§

impl Clone for ImageResource

Source§

fn clone(&self) -> ImageResource

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 ImageResource

Source§

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

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

impl PartialEq for ImageResource

Source§

fn eq(&self, other: &ImageResource) -> 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 ImageResource

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> Clone for T
where T: Clone,

Source§

fn clone(&self) -> T

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> Debug for T
where T: Debug,

Source§

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

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.