Skip to content

Commit

Permalink
Add deprecated re-export of ImageReader as Reader (#2252)
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide authored Jun 2, 2024
1 parent 5de1efc commit 6e73a17
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/codecs/gif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ use crate::error::{
UnsupportedError, UnsupportedErrorKind,
};
use crate::image::{AnimationDecoder, ImageDecoder, ImageFormat};
use crate::io::Limits;
use crate::traits::Pixel;
use crate::ExtendedColorType;
use crate::ImageBuffer;
use crate::Limits;

/// GIF decoder
pub struct GifDecoder<R: Read> {
Expand Down Expand Up @@ -96,7 +96,7 @@ impl<R: BufRead + Seek> ImageDecoder for GifDecoder<R> {
}

fn set_limits(&mut self, limits: Limits) -> ImageResult<()> {
limits.check_support(&crate::io::LimitSupport::default())?;
limits.check_support(&crate::LimitSupport::default())?;

let (width, height) = self.dimensions();
limits.check_dimensions(width, height)?;
Expand Down
4 changes: 2 additions & 2 deletions src/codecs/jpeg/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::error::{
DecodingError, ImageError, ImageResult, LimitError, UnsupportedError, UnsupportedErrorKind,
};
use crate::image::{ImageDecoder, ImageFormat};
use crate::io::Limits;
use crate::Limits;

type ZuneColorSpace = zune_core::colorspace::ColorSpace;

Expand Down Expand Up @@ -90,7 +90,7 @@ impl<R: BufRead + Seek> ImageDecoder for JpegDecoder<R> {
}

fn set_limits(&mut self, limits: Limits) -> ImageResult<()> {
limits.check_support(&crate::io::LimitSupport::default())?;
limits.check_support(&crate::LimitSupport::default())?;
let (width, height) = self.dimensions();
limits.check_dimensions(width, height)?;
self.limits = limits;
Expand Down
6 changes: 3 additions & 3 deletions src/codecs/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::error::{
ParameterError, ParameterErrorKind, UnsupportedError, UnsupportedErrorKind,
};
use crate::image::{AnimationDecoder, ImageDecoder, ImageEncoder, ImageFormat};
use crate::io::Limits;
use crate::Limits;
use crate::{DynamicImage, GenericImage, ImageBuffer, Luma, LumaA, Rgb, Rgba, RgbaImage};

// http://www.w3.org/TR/PNG-Structure.html
Expand All @@ -40,7 +40,7 @@ impl<R: BufRead + Seek> PngDecoder<R> {

/// Creates a new decoder that decodes from the stream ```r``` with the given limits.
pub fn with_limits(r: R, limits: Limits) -> ImageResult<PngDecoder<R>> {
limits.check_support(&crate::io::LimitSupport::default())?;
limits.check_support(&crate::LimitSupport::default())?;

let max_bytes = usize::try_from(limits.max_alloc.unwrap_or(u64::MAX)).unwrap_or(usize::MAX);
let mut decoder = png::Decoder::new_with_limits(r, png::Limits { bytes: max_bytes });
Expand Down Expand Up @@ -204,7 +204,7 @@ impl<R: BufRead + Seek> ImageDecoder for PngDecoder<R> {
}

fn set_limits(&mut self, limits: Limits) -> ImageResult<()> {
limits.check_support(&crate::io::LimitSupport::default())?;
limits.check_support(&crate::LimitSupport::default())?;
let info = self.reader.info();
limits.check_dimensions(info.width, info.height)?;
self.limits = limits;
Expand Down
4 changes: 2 additions & 2 deletions src/codecs/tiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ impl<R: BufRead + Seek> ImageDecoder for TiffDecoder<R> {
}
}

fn set_limits(&mut self, limits: crate::io::Limits) -> ImageResult<()> {
limits.check_support(&crate::io::LimitSupport::default())?;
fn set_limits(&mut self, limits: crate::Limits) -> ImageResult<()> {
limits.check_support(&crate::LimitSupport::default())?;

let (width, height) = self.dimensions();
limits.check_dimensions(width, height)?;
Expand Down
2 changes: 1 addition & 1 deletion src/dynimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::color::{self, IntoColor};
use crate::error::{ImageError, ImageResult, ParameterError, ParameterErrorKind};
use crate::flat::FlatSamples;
use crate::image::{GenericImage, GenericImageView, ImageDecoder, ImageEncoder, ImageFormat};
use crate::io::free_functions;
use crate::image_reader::free_functions;
use crate::math::resize_dimensions;
use crate::traits::Pixel;
use crate::ImageReader;
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ pub enum LimitErrorKind {
/// The specified strict limits are not supported for this operation
Unsupported {
/// The given limits
limits: crate::io::Limits,
limits: crate::Limits,
/// The supported strict limits
supported: crate::io::LimitSupport,
supported: crate::LimitSupport,
},
}

Expand Down
6 changes: 3 additions & 3 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ pub trait ImageDecoder {
/// [`Limits`]: ./io/struct.Limits.html
/// [`Limits::check_support`]: ./io/struct.Limits.html#method.check_support
/// [`Limits::check_dimensions`]: ./io/struct.Limits.html#method.check_dimensions
fn set_limits(&mut self, limits: crate::io::Limits) -> ImageResult<()> {
limits.check_support(&crate::io::LimitSupport::default())?;
fn set_limits(&mut self, limits: crate::Limits) -> ImageResult<()> {
limits.check_support(&crate::LimitSupport::default())?;
let (width, height) = self.dimensions();
limits.check_dimensions(width, height)?;
Ok(())
Expand Down Expand Up @@ -716,7 +716,7 @@ impl<T: ?Sized + ImageDecoder> ImageDecoder for Box<T> {
fn read_image_boxed(self: Box<Self>, buf: &mut [u8]) -> ImageResult<()> {
T::read_image_boxed(*self, buf)
}
fn set_limits(&mut self, limits: crate::io::Limits) -> ImageResult<()> {
fn set_limits(&mut self, limits: crate::Limits) -> ImageResult<()> {
(**self).set_limits(limits)
}
}
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/io/mod.rs → src/image_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use crate::{error, ColorType, ImageError, ImageResult};

pub(crate) mod free_functions;
mod image_reader;
mod image_reader_type;

pub use self::image_reader::ImageReader;
pub use self::image_reader_type::ImageReader;

/// Set of supported strict limits for a decoder.
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
Expand Down
19 changes: 16 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ pub use crate::dynimage::{
image_dimensions, load_from_memory, load_from_memory_with_format, open, save_buffer,
save_buffer_with_format, write_buffer_with_format,
};
pub use crate::io::free_functions::{guess_format, load};
pub use crate::io::{ImageReader, LimitSupport, Limits};
pub use crate::image_reader::free_functions::{guess_format, load};
pub use crate::image_reader::{ImageReader, LimitSupport, Limits};

pub use crate::dynimage::DynamicImage;

Expand Down Expand Up @@ -288,7 +288,20 @@ mod buffer_par;
mod color;
mod dynimage;
mod image;
mod io;
mod image_reader;
//TODO delete this module after a few releases
/// deprecated io module the original io module has been renamed to `image_reader`
pub mod io {
#[deprecated(note = "this type has been moved and renamed to image::ImageReader")]
/// Deprecated re-export of `ImageReader` as `Reader`
pub type Reader<R> = super::ImageReader<R>;
#[deprecated(note = "this type has been moved to image::Limits")]
/// Deprecated re-export of `Limits`
pub type Limits = super::Limits;
#[deprecated(note = "this type has been moved to image::LimitSupport")]
/// Deprecated re-export of `LimitSupport`
pub type LimitSupport = super::LimitSupport;
}
mod traits;
mod utils;

Expand Down

0 comments on commit 6e73a17

Please sign in to comment.