-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce option to check frame bound consistency
This restores the behaviour of previous version to NOT check it. This is not valid according to strict reading of the specification but it may appear in practice. In particular, imagemagick handles this in weird ways that are not errors but silently adjust the width and height.. Not sure about that style.
- Loading branch information
1 parent
4502553
commit 47e4187
Showing
3 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use gif::{DecodeOptions, DisposalMethod, Encoder, Frame}; | ||
|
||
#[test] | ||
fn frame_consistency_is_configurable() { | ||
let image = create_image_with_oob_frames(); | ||
let mut options = DecodeOptions::new(); | ||
|
||
{ | ||
let mut data = image.as_slice(); | ||
let mut decoder = options.clone().read_info(&mut data).unwrap(); | ||
assert!(decoder.read_next_frame().is_ok()); | ||
assert!(decoder.read_next_frame().is_err()); | ||
} | ||
|
||
{ | ||
options.check_frame_consistency(false); | ||
let mut data = image.as_slice(); | ||
let mut decoder = options.clone().read_info(&mut data).unwrap(); | ||
assert!(decoder.read_next_frame().is_ok()); | ||
assert!(decoder.read_next_frame().is_ok()); | ||
} | ||
} | ||
|
||
fn create_image_with_oob_frames() -> Vec<u8> { | ||
let mut data = vec![]; | ||
let mut encoder = Encoder::new(&mut data, 2, 2, &[0, 0, 0]).unwrap(); | ||
|
||
let mut frame = Frame { | ||
delay: 1, | ||
dispose: DisposalMethod::Any, | ||
transparent: None, | ||
needs_user_input: false, | ||
top: 0, | ||
left: 0, | ||
width: 2, | ||
height: 2, | ||
interlaced: false, | ||
palette: None, | ||
buffer: vec![0, 0, 0, 0].into(), | ||
}; | ||
|
||
encoder.write_frame(&frame).unwrap(); | ||
frame.top = 1; | ||
frame.left = 1; | ||
encoder.write_frame(&frame).unwrap(); | ||
|
||
drop(encoder); | ||
data | ||
} |