Name reduced JPEG estimate API

This commit is contained in:
Dylan M. Taylor committed 2026-11-12 17:55:36 -05:00
1 parent 1c3285d8a3
commit 2eff7e822f
3 files changed
+4 -4

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ pub(crate) const MAX_SHRINK: u8 = 3;
/// Output size of a JPEG reduction without decoding pixels. `None` when the reduced decoder
/// cannot handle the JPEG, including its full-size resource limits.
pub(crate) fn reduced_size(bytes: &[u8], shrink: u8) -> Option<(u32, u32, usize)> {
pub(crate) fn reduced_estimate(bytes: &[u8], shrink: u8) -> Option<(u32, u32, usize)> {
use jpeg_decoder::{CodingProcess, PixelFormat};
if !bytes.starts_with(&[0xFF, 0xD8]) || shrink == 0 || shrink > MAX_SHRINK {
return None;
+2 -2
View File
@@ -513,8 +513,8 @@ pub fn decode_rgba_reduced(bytes: &[u8], shrink: u8) -> Option<image::RgbaImage>
/// Dimensions and estimated peak bytes for a JPEG decoded at `1/2^shrink`, without decoding its
/// pixels. Progressive JPEG coefficient buffers are included. `None` when the reduced decoder
/// cannot handle the image.
pub fn reduced_jpeg_size(bytes: &[u8], shrink: u8) -> Option<(u32, u32, usize)> {
jpeg::reduced_size(bytes, shrink)
pub fn reduced_jpeg_estimate(bytes: &[u8], shrink: u8) -> Option<(u32, u32, usize)> {
jpeg::reduced_estimate(bytes, shrink)
}
/// False when `bytes` is a WebP whose `ICCP` chunk declares more bytes than the file holds or than
+1 -1
View File
@@ -200,7 +200,7 @@ fn reduced_estimates(wants: &[Want]) -> Option<(usize, usize)> {
return None;
}
let shrink = level.min(usize::from(designcraft_images::MAX_REDUCED_SHRINK));
let (_, _, decode_peak) = designcraft_images::reduced_jpeg_size(&w.bytes, shrink as u8)?;
let (_, _, decode_peak) = designcraft_images::reduced_jpeg_estimate(&w.bytes, shrink as u8)?;
for cached in levels.iter_mut().take(level + 1).skip(shrink) {
*cached = true;
}