JFLib

pdf/src/image.rs#

Source: lib/pdf/src/image.rs

image -- raster images for a document: JPEG files as they are (DCTDecode), all other pixels
FlateDecode with PNG predictors and their alpha as a soft mask (SMask)
  • struct Image an image for Document::add_image: a JPEG passed through, or 8-bit pixels (gray, RGB, RGBA, a gfx surface) with an optional alpha channel

impl Image

  • fn jpeg(data: Vec<u8>) -> Result<Image, Error> a JPEG file, embedded unchanged: baseline, extended or progressive, 8 bits, 1, 3 or 4 components (Adobe's inverted CMYK understood)
  • fn gray(w: u32, h: u32, px: &[u8]) -> Result<Image, Error> 8-bit gray, rows from the top
  • fn rgb(w: u32, h: u32, px: &[u8]) -> Result<Image, Error> 8-bit RGB, rows from the top
  • fn rgba(w: u32, h: u32, px: &[u8]) -> Result<Image, Error> 8-bit RGBA with straight (not premultiplied) alpha, rows from the top
  • fn from_surface(s: &gfx::Surface) -> Result<Image, Error> a gfx surface: XRGB (opaque), PARGB (premultiplied, un-premultiplied here), ARGB, A8 (as gray)
  • fn with_alpha(mut self, alpha: Vec<u8>) -> Result<Image, Error> an alpha channel (one byte per pixel, rows from the top) for any image, a JPEG too
  • fn interpolate(mut self, on: bool) -> Image smooth the image when a reader scales it up (PDF /Interpolate)
  • fn size(&self) -> (u32, u32) width and height in pixels
  • fn is_jpeg(&self) -> bool
  • fn has_alpha(&self) -> bool

Source: docs/API.md in the JFLib repository.