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
impl ImageResource
Sourcepub fn sniff_baseline_jpeg_dct(bytes: Vec<u8>) -> Option<JpegDct>
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
FFD8SOI 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) — viewerDCTDecodesupport 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.
Sourcepub fn intrinsic_dims_pt(&self) -> (f64, f64)
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
impl Clone for ImageResource
Source§fn clone(&self) -> ImageResource
fn clone(&self) -> ImageResource
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more