Check idat_recoding for all recompression

This commit is contained in:
Andrew 2023-08-01 08:14:24 +12:00
parent 02bd47ba29
commit 73f8aad65d
2 changed files with 16 additions and 14 deletions

View file

@ -180,7 +180,7 @@ pub struct Options {
/// ///
/// Default: `true` /// Default: `true`
pub grayscale_reduction: bool, pub grayscale_reduction: bool,
/// Whether to perform IDAT recoding /// Whether to perform recoding of IDAT and other compressed chunks
/// ///
/// If any type of reduction is performed, IDAT recoding will be performed /// If any type of reduction is performed, IDAT recoding will be performed
/// regardless of this setting /// regardless of this setting
@ -904,14 +904,15 @@ fn postprocess_chunks(
None None
}; };
// sRGB-like profile can be replaced with an sRGB chunk with the same rendering intent // sRGB-like profile can be replaced with an sRGB chunk with the same rendering intent
// Otherwise try recompressing the profile
if let Some(intent) = intent { if let Some(intent) = intent {
trace!("Replacing iCCP chunk with equivalent sRGB chunk"); trace!("Replacing iCCP chunk with equivalent sRGB chunk");
png.aux_chunks[iccp_idx] = Chunk { png.aux_chunks[iccp_idx] = Chunk {
name: *b"sRGB", name: *b"sRGB",
data: vec![intent], data: vec![intent],
}; };
} else if let Ok(iccp) = construct_iccp(&icc, opts.deflate) { } else if opts.idat_recoding {
// Try recompressing the profile
if let Ok(iccp) = construct_iccp(&icc, opts.deflate) {
let cur_len = png.aux_chunks[iccp_idx].data.len(); let cur_len = png.aux_chunks[iccp_idx].data.len();
let new_len = iccp.data.len(); let new_len = iccp.data.len();
if new_len < cur_len { if new_len < cur_len {
@ -925,6 +926,7 @@ fn postprocess_chunks(
} }
} }
} }
}
// If the depth/color type has changed, some chunks may be invalid and should be dropped // If the depth/color type has changed, some chunks may be invalid and should be dropped
// While these could potentially be converted, they have no known use case today and are // While these could potentially be converted, they have no known use case today and are
@ -950,7 +952,7 @@ fn postprocess_chunks(
.iter_mut() .iter_mut()
.filter(|c| &c.name == b"fdAT") .filter(|c| &c.name == b"fdAT")
.collect(); .collect();
if !fdat.is_empty() { if opts.idat_recoding && !fdat.is_empty() {
let buffer_size = orig_ihdr.raw_data_size(); let buffer_size = orig_ihdr.raw_data_size();
fdat.par_iter_mut() fdat.par_iter_mut()
.with_max_len(1) .with_max_len(1)

View file

@ -231,7 +231,7 @@ fn main() {
) )
.arg( .arg(
Arg::new("no-recoding") Arg::new("no-recoding")
.help("No IDAT recoding unless necessary") .help("No recoding of IDAT or other compressed chunks unless necessary")
.long("nz") .long("nz")
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )