Use libdeflater crc
This commit is contained in:
parent
ae010773d1
commit
460b9883cf
5 changed files with 13 additions and 10 deletions
|
|
@ -36,3 +36,9 @@ pub fn inflate(data: &[u8], out_size: usize) -> PngResult<Vec<u8>> {
|
|||
dest.truncate(len);
|
||||
Ok(dest)
|
||||
}
|
||||
|
||||
pub fn crc32(data: &[u8]) -> u32 {
|
||||
let mut crc = Crc::new();
|
||||
crc.update(data);
|
||||
crc.sum()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ pub mod miniz_stream;
|
|||
#[cfg(feature = "libdeflater")]
|
||||
mod deflater;
|
||||
#[cfg(feature = "libdeflater")]
|
||||
pub use deflater::crc32;
|
||||
#[cfg(feature = "libdeflater")]
|
||||
pub use deflater::deflate as libdeflater_deflate;
|
||||
#[cfg(feature = "libdeflater")]
|
||||
pub use deflater::inflate as libdeflater_inflate;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::colors::{BitDepth, ColorType};
|
||||
use crate::deflate::crc32;
|
||||
use crate::error::PngError;
|
||||
use crate::PngResult;
|
||||
use crc::{Crc, CRC_32_ISO_HDLC};
|
||||
use indexmap::IndexSet;
|
||||
use std::io;
|
||||
use std::io::{Cursor, Read};
|
||||
|
|
@ -130,7 +130,7 @@ pub fn parse_next_header<'a>(
|
|||
let header_bytes = byte_data
|
||||
.get(header_start..header_start + 4 + length as usize)
|
||||
.ok_or(PngError::TruncatedData)?;
|
||||
if !fix_errors && Crc::<u32>::new(&CRC_32_ISO_HDLC).checksum(header_bytes) != crc {
|
||||
if !fix_errors && crc32(header_bytes) != crc {
|
||||
return Err(PngError::new(&format!(
|
||||
"CRC Mismatch in {} header; May be recoverable by using --fix",
|
||||
String::from_utf8_lossy(chunk_name)
|
||||
|
|
|
|||
|
|
@ -26,12 +26,11 @@ mod rayon;
|
|||
|
||||
use crate::atomicmin::AtomicMin;
|
||||
use crate::colors::BitDepth;
|
||||
use crate::deflate::libdeflater_inflate;
|
||||
use crate::deflate::{crc32, libdeflater_inflate};
|
||||
use crate::evaluate::Evaluator;
|
||||
use crate::png::PngData;
|
||||
use crate::png::PngImage;
|
||||
use crate::reduction::*;
|
||||
use crc::{Crc, CRC_32_ISO_HDLC};
|
||||
use image::{DynamicImage, GenericImageView, ImageFormat, Pixel};
|
||||
use log::{debug, error, info, warn};
|
||||
use rayon::prelude::*;
|
||||
|
|
@ -966,10 +965,7 @@ fn srgb_rendering_intent(mut iccp: &[u8]) -> Option<u8> {
|
|||
}
|
||||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" => {
|
||||
// Known-bad profiles are identified by their CRC
|
||||
match (
|
||||
Crc::<u32>::new(&CRC_32_ISO_HDLC).checksum(&icc_data),
|
||||
icc_data.len(),
|
||||
) {
|
||||
match (crc32(&icc_data), icc_data.len()) {
|
||||
(0x5d51_29ce, 3024) | (0x182e_a552, 3144) | (0xf29e_526d, 3144) => {
|
||||
Some(rendering_intent)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ use crate::error::PngError;
|
|||
use crate::filters::*;
|
||||
use crate::headers::*;
|
||||
use crate::interlace::{deinterlace_image, interlace_image};
|
||||
use crc::{Crc, CRC_32_ISO_HDLC};
|
||||
use indexmap::IndexMap;
|
||||
use rgb::ComponentSlice;
|
||||
use rgb::RGBA8;
|
||||
|
|
@ -370,7 +369,7 @@ fn write_png_block(key: &[u8], header: &[u8], output: &mut Vec<u8>) {
|
|||
header_data.extend_from_slice(header);
|
||||
output.reserve(header_data.len() + 8);
|
||||
output.extend_from_slice(&(header_data.len() as u32 - 4).to_be_bytes());
|
||||
let crc = Crc::<u32>::new(&CRC_32_ISO_HDLC).checksum(&header_data);
|
||||
let crc = deflate::crc32(&header_data);
|
||||
output.append(&mut header_data);
|
||||
output.extend_from_slice(&crc.to_be_bytes());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue