Move preserved header list, drop sBIT
This commit is contained in:
parent
a5832706bd
commit
31edea99f7
2 changed files with 9 additions and 11 deletions
|
|
@ -69,7 +69,7 @@ pub enum Headers {
|
|||
None,
|
||||
/// Remove specific chunks
|
||||
Strip(Vec<String>),
|
||||
/// Headers that won't affect rendering (all but cICP, iCCP, sBIT, sRGB, pHYs)
|
||||
/// Remove all chunks that won't affect rendering
|
||||
Safe,
|
||||
/// Remove all non-critical chunks except these
|
||||
Keep(IndexSet<String>),
|
||||
|
|
@ -77,6 +77,11 @@ pub enum Headers {
|
|||
All,
|
||||
}
|
||||
|
||||
impl Headers {
|
||||
/// List of chunks that will be kept when using the `Safe` option
|
||||
pub const KEEP_SAFE: [[u8; 4]; 4] = [*b"cICP", *b"iCCP", *b"sRGB", *b"pHYs"];
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn file_header_is_valid(bytes: &[u8]) -> bool {
|
||||
let expected_header: [u8; 8] = [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A];
|
||||
|
|
|
|||
13
src/lib.rs
13
src/lib.rs
|
|
@ -881,16 +881,9 @@ fn perform_strip(png: &mut PngData, opts: &Options) {
|
|||
raw.aux_headers.remove(hdr.as_bytes());
|
||||
}
|
||||
}
|
||||
Headers::Safe => {
|
||||
const PRESERVED_HEADERS: [[u8; 4]; 5] =
|
||||
[*b"cICP", *b"iCCP", *b"sBIT", *b"sRGB", *b"pHYs"];
|
||||
let keys: Vec<[u8; 4]> = raw.aux_headers.keys().cloned().collect();
|
||||
for hdr in &keys {
|
||||
if !PRESERVED_HEADERS.contains(hdr) {
|
||||
raw.aux_headers.remove(hdr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Headers::Safe => raw
|
||||
.aux_headers
|
||||
.retain(|hdr, _| Headers::KEEP_SAFE.contains(hdr)),
|
||||
Headers::All => {
|
||||
raw.aux_headers = IndexMap::new();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue