1#[cfg(any(feature = "tga", feature = "dds", feature = "bmp"))]
4use alloc::vec::Vec;
5#[cfg(any(feature = "tga", feature = "dds", feature = "bmp"))]
6use no_std_io::io;
7
8pub(crate) mod decoder;
10pub(crate) mod encoder;
12
13pub(crate) mod format;
14pub(crate) mod free_functions;
15#[cfg(feature = "std")]
16pub(crate) mod image_reader_type;
17pub(crate) mod limits;
18
19#[cfg(feature = "std")]
20#[deprecated(note = "this type has been moved and renamed to ai_image::ImageReader")]
21pub type Reader<R> = ImageReader<R>;
23#[deprecated(note = "this type has been moved to ai_image::Limits")]
24pub type Limits = limits::Limits;
26#[deprecated(note = "this type has been moved to ai_image::LimitSupport")]
27pub type LimitSupport = limits::LimitSupport;
29
30#[cfg(feature = "std")]
31pub(crate) use self::image_reader_type::ImageReader;
32
33#[cfg(any(feature = "tga", feature = "dds", feature = "bmp"))]
35pub(crate) trait ReadExt {
36 fn read_exact_vec(&mut self, vec: &mut Vec<u8>, len: usize) -> io::Result<()>;
37}
38
39#[cfg(any(feature = "tga", feature = "dds", feature = "bmp"))]
40impl<R: io::Read> ReadExt for R {
41 fn read_exact_vec(&mut self, vec: &mut Vec<u8>, len: usize) -> io::Result<()> {
42 let initial_len = vec.len();
43 #[allow(clippy::io_other_error)]
45 vec.try_reserve(len)
46 .map_err(|_| io::Error::new(io::ErrorKind::Other, "allocation failed"))?;
47 vec.resize(initial_len + len, 0);
48 match self.read_exact(&mut vec[initial_len..]) {
49 Ok(()) => Ok(()),
50 Err(e) => {
51 vec.truncate(initial_len);
52 Err(e)
53 }
54 }
55 }
56}