Skip to main content

load_image/
lib.rs

1#![doc = include_str!("../README.md")]
2
3mod alpha;
4mod convert;
5mod endian;
6mod error;
7mod format;
8mod image;
9mod loader;
10mod pixel_format;
11mod png;
12
13pub use crate::error::*;
14
15#[cfg(feature = "mozjpeg")]
16mod mozjpeg;
17#[cfg(all(not(feature = "mozjpeg"), feature = "jpeg"))]
18mod jpeg;
19#[cfg(any(feature = "mozjpeg", feature = "jpeg"))]
20mod exif;
21mod profiles;
22
23#[cfg_attr(feature = "lcms2", path = "lcms.rs")]
24mod cms;
25
26#[cfg(feature = "avif")]
27mod avif;
28
29#[cfg(feature = "webp")]
30mod webp;
31
32pub use crate::convert::FromOptions;
33pub use crate::format::*;
34pub use crate::image::*;
35pub use crate::loader::*;
36use std::path::Path;
37
38/// Load image from file path. Use [`Loader`] to configure it.
39///
40/// Pixels will be in sRGB color space. To load `DisplayP3` or other, use [`Loader`].
41pub fn load_path(path: impl AsRef<Path>) -> Result<Image, Error> {
42    Loader::new().load_path(path)
43}
44
45/// Load image from file data in memory. Use [`Loader`] to configure it.
46pub fn load_data(data: &[u8]) -> Result<Image, Error> {
47    Loader::new().load_data(data)
48}
49
50#[doc(hidden)]
51#[deprecated(note = "use load_path or Loader::new()")]
52pub fn load_image(path: impl AsRef<Path>, opaque: bool) -> Result<Image, Error> {
53    Loader::new().opaque(opaque).load_path(path)
54}
55
56#[doc(hidden)]
57#[deprecated(note = "use load_data or Loader::new()")]
58pub fn load_image_data(data: &[u8], opaque: bool) -> Result<Image, Error> {
59    Loader::new().opaque(opaque).load_data(data)
60}
61
62/// Re-export of related crates
63pub mod export {
64    /// Re-export of the [`rgb`](https://lib.rs/crates/rgb) crate
65    pub mod rgb {
66        pub use ::rgb::*;
67        pub type GRAY16 = ::rgb::Gray<u16>;
68        pub type GRAY8 = ::rgb::Gray<u8>;
69        pub type GRAYA16 = ::rgb::GrayAlpha<u16>;
70        pub type GRAYA8 = ::rgb::GrayAlpha<u8>;
71    }
72
73    /// Re-export of the [`imgref`](https://lib.rs/crates/imgref) crate
74    pub mod imgref {
75        use super::rgb;
76        pub use imgref::{ImgRef, ImgVec};
77
78        #[derive(Debug, Clone, PartialEq, Eq)]
79        pub enum ImgRefKind<'data> {
80            RGB8(ImgRef<'data, rgb::Rgb<u8>>),
81            RGBA8(ImgRef<'data, rgb::Rgba<u8>>),
82            RGB16(ImgRef<'data, rgb::Rgb<u16>>),
83            RGBA16(ImgRef<'data, rgb::Rgba<u16>>),
84            GRAY8(ImgRef<'data, rgb::Gray<u8>>),
85            GRAY16(ImgRef<'data, rgb::Gray<u16>>),
86            GRAYA8(ImgRef<'data, rgb::GrayAlpha<u8>>),
87            GRAYA16(ImgRef<'data, rgb::GrayAlpha<u16>>),
88        }
89
90        #[derive(Debug, Clone, PartialEq, Eq)]
91        pub enum ImgVecKind {
92            RGB8(ImgVec<rgb::Rgb<u8>>),
93            RGBA8(ImgVec<rgb::Rgba<u8>>),
94            RGB16(ImgVec<rgb::Rgb<u16>>),
95            RGBA16(ImgVec<rgb::Rgba<u16>>),
96            GRAY8(ImgVec<rgb::Gray<u8>>),
97            GRAY16(ImgVec<rgb::Gray<u16>>),
98            GRAYA8(ImgVec<rgb::GrayAlpha<u8>>),
99            GRAYA16(ImgVec<rgb::GrayAlpha<u16>>),
100        }
101    }
102}