From 07ba50e697e3ff6a93226f08c42c020c07edc917 Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Sun, 7 Nov 2021 00:19:53 +0100 Subject: [PATCH 1/3] Rename ImageDecoderExt to ImageDecoderRect --- README.md | 4 ++-- src/codecs/bmp/decoder.rs | 4 ++-- src/codecs/dxt.rs | 4 ++-- src/codecs/farbfeld.rs | 6 +++--- src/codecs/hdr/decoder.rs | 4 ++-- src/image.rs | 2 +- src/lib.rs | 6 +++--- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 86015a6061..6d18e11f17 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,11 @@ All image processing functions provided operate on types that implement the `Gen | OpenEXR | Rgb32F, Rgba32F (no dwa compression) | Rgb32F, Rgba32F (no dwa compression) | | farbfeld | Yes | Yes | -### The [`ImageDecoder`](https://docs.rs/image/*/image/trait.ImageDecoder.html) and [`ImageDecoderExt`](https://docs.rs/image/*/image/trait.ImageDecoderExt.html) Traits +### The [`ImageDecoder`](https://docs.rs/image/*/image/trait.ImageDecoder.html) and [`ImageDecoderRect`](https://docs.rs/image/*/image/trait.ImageDecoderRect.html) Traits All image format decoders implement the `ImageDecoder` trait which provide basic methods for getting image metadata and decoding images. Some formats -additionally provide `ImageDecoderExt` implementations which allow for +additionally provide `ImageDecoderRect` implementations which allow for decoding only part of an image at once. The most important methods for decoders are... diff --git a/src/codecs/bmp/decoder.rs b/src/codecs/bmp/decoder.rs index 1d88af47c6..c73cb27965 100644 --- a/src/codecs/bmp/decoder.rs +++ b/src/codecs/bmp/decoder.rs @@ -12,7 +12,7 @@ use crate::color::ColorType; use crate::error::{ DecodingError, ImageError, ImageResult, UnsupportedError, UnsupportedErrorKind, }; -use crate::image::{self, ImageDecoder, ImageDecoderExt, ImageFormat, Progress}; +use crate::image::{self, ImageDecoder, ImageDecoderRect, ImageFormat, Progress}; const BITMAPCOREHEADER_SIZE: u32 = 12; const BITMAPINFOHEADER_SIZE: u32 = 40; @@ -1481,7 +1481,7 @@ impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for BmpDecoder { } } -impl<'a, R: 'a + Read + Seek> ImageDecoderExt<'a> for BmpDecoder { +impl<'a, R: 'a + Read + Seek> ImageDecoderRect<'a> for BmpDecoder { fn read_rect_with_progress( &mut self, x: u32, diff --git a/src/codecs/dxt.rs b/src/codecs/dxt.rs index 95a39d041a..4d2c5799a1 100644 --- a/src/codecs/dxt.rs +++ b/src/codecs/dxt.rs @@ -12,7 +12,7 @@ use std::io::{self, Read, Seek, SeekFrom, Write}; use crate::color::ColorType; use crate::error::{ImageError, ImageResult, ParameterError, ParameterErrorKind}; -use crate::image::{self, ImageDecoder, ImageDecoderExt, ImageReadBuffer, Progress}; +use crate::image::{self, ImageDecoder, ImageDecoderRect, ImageReadBuffer, Progress}; /// What version of DXT compression are we using? /// Note that DXT2 and DXT4 are left away as they're @@ -149,7 +149,7 @@ impl<'a, R: 'a + Read> ImageDecoder<'a> for DxtDecoder { } } -impl<'a, R: 'a + Read + Seek> ImageDecoderExt<'a> for DxtDecoder { +impl<'a, R: 'a + Read + Seek> ImageDecoderRect<'a> for DxtDecoder { fn read_rect_with_progress( &mut self, x: u32, diff --git a/src/codecs/farbfeld.rs b/src/codecs/farbfeld.rs index 0ad4f9227d..ff6563f3fd 100644 --- a/src/codecs/farbfeld.rs +++ b/src/codecs/farbfeld.rs @@ -24,7 +24,7 @@ use byteorder::{BigEndian, ByteOrder, NativeEndian}; use crate::color::ColorType; use crate::error::{DecodingError, ImageError, ImageResult, UnsupportedError, UnsupportedErrorKind}; -use crate::image::{self, ImageDecoder, ImageDecoderExt, ImageEncoder, ImageFormat, Progress}; +use crate::image::{self, ImageDecoder, ImageDecoderRect, ImageEncoder, ImageFormat, Progress}; /// farbfeld Reader pub struct FarbfeldReader { @@ -208,7 +208,7 @@ impl<'a, R: 'a + Read> ImageDecoder<'a> for FarbfeldDecoder { } } -impl<'a, R: 'a + Read + Seek> ImageDecoderExt<'a> for FarbfeldDecoder { +impl<'a, R: 'a + Read + Seek> ImageDecoderRect<'a> for FarbfeldDecoder { fn read_rect_with_progress( &mut self, x: u32, @@ -288,7 +288,7 @@ impl ImageEncoder for FarbfeldEncoder { #[cfg(test)] mod tests { use crate::codecs::farbfeld::FarbfeldDecoder; - use crate::ImageDecoderExt; + use crate::ImageDecoderRect; use std::io::{Cursor, Seek, SeekFrom}; use byteorder::{ByteOrder, NativeEndian}; diff --git a/src/codecs/hdr/decoder.rs b/src/codecs/hdr/decoder.rs index 3dcc99863d..bee2ec9468 100644 --- a/src/codecs/hdr/decoder.rs +++ b/src/codecs/hdr/decoder.rs @@ -13,7 +13,7 @@ use crate::Primitive; use crate::color::{ColorType, Rgb}; use crate::error::{DecodingError, ImageError, ImageFormatHint, ImageResult, ParameterError, ParameterErrorKind, UnsupportedError, UnsupportedErrorKind}; -use crate::image::{self, ImageDecoder, ImageDecoderExt, ImageFormat, Progress}; +use crate::image::{self, ImageDecoder, ImageDecoderRect, ImageFormat, Progress}; /// Errors that can occur during decoding and parsing of a HDR image #[derive(Debug, Clone, PartialEq, Eq)] @@ -197,7 +197,7 @@ impl<'a, R: 'a + BufRead> ImageDecoder<'a> for HdrAdapter { } } -impl<'a, R: 'a + BufRead + Seek> ImageDecoderExt<'a> for HdrAdapter { +impl<'a, R: 'a + BufRead + Seek> ImageDecoderRect<'a> for HdrAdapter { fn read_rect_with_progress( &mut self, x: u32, diff --git a/src/image.rs b/src/image.rs index d45bf71d50..3b0f775183 100644 --- a/src/image.rs +++ b/src/image.rs @@ -697,7 +697,7 @@ pub trait ImageDecoder<'a>: Sized { } /// Specialized image decoding not be supported by all formats -pub trait ImageDecoderExt<'a>: ImageDecoder<'a> + Sized { +pub trait ImageDecoderRect<'a>: ImageDecoder<'a> + Sized { /// Decode a rectangular section of the image; see [`read_rect_with_progress()`](#fn.read_rect_with_progress). fn read_rect( &mut self, diff --git a/src/lib.rs b/src/lib.rs index fbb63daaf9..3e1e79f98f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,14 +73,14 @@ //! //! # Low level encoding/decoding API //! -//! The [`ImageDecoder`] and [`ImageDecoderExt`] traits are implemented for many image file +//! The [`ImageDecoder`] and [`ImageDecoderRect`] traits are implemented for many image file //! formats. They decode image data by directly on raw byte slices. Given an ImageDecoder, you can //! produce a DynamicImage via [`DynamicImage::from_decoder`]. //! //! [`ImageEncoder`] provides the analogous functionality for encoding image data. //! //! [`DynamicImage::from_decoder`]: enum.DynamicImage.html#method.from_decoder -//! [`ImageDecoderExt`]: trait.ImageDecoderExt.html +//! [`ImageDecoderRect`]: trait.ImageDecoderRect.html //! [`ImageDecoder`]: trait.ImageDecoder.html //! [`ImageEncoder`]: trait.ImageEncoder.html #![warn(missing_docs)] @@ -112,7 +112,7 @@ pub use crate::image::{ GenericImage, GenericImageView, ImageDecoder, - ImageDecoderExt, + ImageDecoderRect, ImageEncoder, ImageFormat, ImageOutputFormat, From 944b54918aa6bf41bc76fafd833548560ee4ce98 Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Sun, 7 Nov 2021 00:25:02 +0100 Subject: [PATCH 2/3] Resolve some minor lints --- src/codecs/openexr.rs | 2 +- src/codecs/png.rs | 2 +- src/dynimage.rs | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/codecs/openexr.rs b/src/codecs/openexr.rs index da52977df9..8390c42500 100644 --- a/src/codecs/openexr.rs +++ b/src/codecs/openexr.rs @@ -26,7 +26,7 @@ use exr::prelude::*; use crate::{ImageDecoder, ImageResult, ColorType, Progress, ImageError, ImageFormat, ImageEncoder, ExtendedColorType}; use std::io::{Write, Seek, Read, Cursor}; -use crate::error::{DecodingError, ImageFormatHint, LimitError, LimitErrorKind, EncodingError}; +use crate::error::{DecodingError, ImageFormatHint, EncodingError}; use crate::image::decoder_to_vec; use std::convert::TryInto; diff --git a/src/codecs/png.rs b/src/codecs/png.rs index 2d080ebf8c..3851275959 100644 --- a/src/codecs/png.rs +++ b/src/codecs/png.rs @@ -117,7 +117,7 @@ impl PngDecoder { // transformations must be set. EXPAND preserves the default behavior // expanding bpc < 8 to 8 bpc. decoder.set_transformations(png::Transformations::EXPAND); - let mut reader = decoder.read_info().map_err(ImageError::from_png)?; + let reader = decoder.read_info().map_err(ImageError::from_png)?; let (color_type, bits) = reader.output_color_type(); let color_type = match (color_type, bits) { (png::ColorType::Grayscale, png::BitDepth::Eight) => ColorType::L8, diff --git a/src/dynimage.rs b/src/dynimage.rs index 7d0ab78da3..9bc3514cbd 100644 --- a/src/dynimage.rs +++ b/src/dynimage.rs @@ -1017,6 +1017,8 @@ fn decoder_to_image<'a, I: ImageDecoder<'a>>(decoder: I) -> ImageResult return Err(ImageError::Unsupported(UnsupportedError::from_format_and_kind( ImageFormatHint::Unknown, UnsupportedErrorKind::Color(color_type.into()), From ccd172e4d1ac7960bb01b3e74af0060334f4db2a Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Sat, 13 Nov 2021 15:51:57 +0100 Subject: [PATCH 3/3] Explain known issue of GenericImage --- src/image.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/image.rs b/src/image.rs index 3b0f775183..6a400819a1 100644 --- a/src/image.rs +++ b/src/image.rs @@ -837,8 +837,6 @@ pub trait GenericImageView { /// # Panics /// /// Panics if `(x, y)` is out of bounds. - /// - /// TODO: change this signature to &P fn get_pixel(&self, x: u32, y: u32) -> Self::Pixel; /// Returns the pixel located at (x, y). Indexed from top left. @@ -895,9 +893,20 @@ pub trait GenericImage: GenericImageView { /// Panics if `(x, y)` is out of bounds. /// /// Panics for dynamic images (this method is deprecated and will be removed). + /// + /// ## Known issues + /// + /// This requires the buffer to contain a unique set of continuous channels in the exact order + /// and byte representation that the pixel type requires. This is somewhat restrictive. + /// + /// TODO: Maybe use some kind of entry API? this would allow pixel type conversion on the fly + /// while still doing only one array lookup: + /// + /// ```ignore + /// let px = image.pixel_entry_at(x,y); + /// px.set_from_rgba(rgba) + /// ``` #[deprecated(since = "0.24.0", note="Use `get_pixel` and `put_pixel` instead.")] - // TODO: Maybe use some kind of entry API? this would allow pixel type conversion on the fly while still doing only one array lookup - // `let px = image.pixel_entry_at(x,y); px.set_from_rgba(rgba)` fn get_pixel_mut(&mut self, x: u32, y: u32) -> &mut Self::Pixel; /// Put a pixel at location (x, y). Indexed from top left.