Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate incremental decoding #1990

Merged
merged 2 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/codecs/dds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,12 @@ impl<'a, R: 'a + Read> ImageDecoder<'a> for DdsDecoder<R> {
}

fn scanline_bytes(&self) -> u64 {
#[allow(deprecated)]
self.inner.scanline_bytes()
}

fn into_reader(self) -> ImageResult<Self::Reader> {
#[allow(deprecated)]
self.inner.into_reader()
}

Expand Down
15 changes: 13 additions & 2 deletions src/codecs/dxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ impl<R: Read> DxtDecoder<R> {
}

fn read_scanline(&mut self, buf: &mut [u8]) -> io::Result<usize> {
assert_eq!(u64::try_from(buf.len()), Ok(self.scanline_bytes()));
assert_eq!(
u64::try_from(buf.len()),
Ok(
#[allow(deprecated)]
self.scanline_bytes()
)
);

let mut src =
vec![0u8; self.variant.encoded_bytes_per_block() * self.width_blocks as usize];
Expand Down Expand Up @@ -134,14 +140,19 @@ impl<'a, R: 'a + Read> ImageDecoder<'a> for DxtDecoder<R> {

fn into_reader(self) -> ImageResult<Self::Reader> {
Ok(DxtReader {
buffer: ImageReadBuffer::new(self.scanline_bytes(), self.total_bytes()),
buffer: ImageReadBuffer::new(
#[allow(deprecated)]
self.scanline_bytes(),
self.total_bytes(),
),
decoder: self,
})
}

fn read_image(mut self, buf: &mut [u8]) -> ImageResult<()> {
assert_eq!(u64::try_from(buf.len()), Ok(self.total_bytes()));

#[allow(deprecated)]
for chunk in buf.chunks_mut(self.scanline_bytes().max(1) as usize) {
self.read_scanline(chunk)?;
}
Expand Down
1 change: 1 addition & 0 deletions src/codecs/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ mod tests {
"Image MUST have the Rgb8 format"
];

#[allow(deprecated)]
let correct_bytes = dec
.into_reader()
.expect("Unable to read file")
Expand Down
6 changes: 5 additions & 1 deletion src/codecs/tga/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,11 @@ impl<'a, R: 'a + Read + Seek> ImageDecoder<'a> for TgaDecoder<R> {

fn into_reader(self) -> ImageResult<Self::Reader> {
Ok(TGAReader {
buffer: ImageReadBuffer::new(self.scanline_bytes(), self.total_bytes()),
buffer: ImageReadBuffer::new(
#[allow(deprecated)]
self.scanline_bytes(),
self.total_bytes(),
),
decoder: self,
})
}
Expand Down
9 changes: 9 additions & 0 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ where
let dimensions = decoder.dimensions();
let bytes_per_pixel = u64::from(decoder.color_type().bytes_per_pixel());
let row_bytes = bytes_per_pixel * u64::from(dimensions.0);
#[allow(deprecated)]
let scanline_bytes = decoder.scanline_bytes();
let total_bytes = width * height * bytes_per_pixel;

Expand Down Expand Up @@ -716,6 +717,7 @@ pub trait ImageDecoder<'a>: Sized {
/// Returns a reader that can be used to obtain the bytes of the image. For the best
/// performance, always try to read at least `scanline_bytes` from the reader at a time. Reading
/// fewer bytes will cause the reader to perform internal buffering.
#[deprecated = "Planned for removal. See https://github.com/image-rs/image/issues/1989"]
fn into_reader(self) -> ImageResult<Self::Reader>;

/// Returns the total number of bytes in the decoded image.
Expand All @@ -733,6 +735,7 @@ pub trait ImageDecoder<'a>: Sized {

/// Returns the minimum number of bytes that can be efficiently read from this decoder. This may
/// be as few as 1 or as many as `total_bytes()`.
#[deprecated = "Planned for removal. See https://github.com/image-rs/image/issues/1989"]
fn scanline_bytes(&self) -> u64 {
self.total_bytes()
}
Expand All @@ -759,11 +762,13 @@ pub trait ImageDecoder<'a>: Sized {
/// }
/// ```
fn read_image(self, buf: &mut [u8]) -> ImageResult<()> {
#[allow(deprecated)]
self.read_image_with_progress(buf, |_| {})
}

/// Same as `read_image` but periodically calls the provided callback to give updates on loading
/// progress.
#[deprecated = "Use read_image instead. See https://github.com/image-rs/image/issues/1989"]
fn read_image_with_progress<F: Fn(Progress)>(
self,
buf: &mut [u8],
Expand All @@ -772,13 +777,15 @@ pub trait ImageDecoder<'a>: Sized {
assert_eq!(u64::try_from(buf.len()), Ok(self.total_bytes()));

let total_bytes = self.total_bytes() as usize;
#[allow(deprecated)]
let scanline_bytes = self.scanline_bytes() as usize;
let target_read_size = if scanline_bytes < 4096 {
(4096 / scanline_bytes) * scanline_bytes
} else {
scanline_bytes
};

#[allow(deprecated)]
let mut reader = self.into_reader()?;

let mut bytes_read = 0;
Expand Down Expand Up @@ -828,6 +835,7 @@ pub trait ImageDecoderRect<'a>: ImageDecoder<'a> + Sized {
height: u32,
buf: &mut [u8],
) -> ImageResult<()> {
#[allow(deprecated)]
self.read_rect_with_progress(x, y, width, height, buf, |_| {})
}

Expand All @@ -843,6 +851,7 @@ pub trait ImageDecoderRect<'a>: ImageDecoder<'a> + Sized {
///
/// This function will panic if the output buffer isn't at least
/// `color_type().bytes_per_pixel() * color_type().channel_count() * width * height` bytes long.
#[deprecated = "Use read_image instead. See https://github.com/image-rs/image/issues/1989"]
fn read_rect_with_progress<F: Fn(Progress)>(
&mut self,
x: u32,
Expand Down