-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve APNG support #668
Open
andrews05
wants to merge
6
commits into
shssoichiro:master
Choose a base branch
from
andrews05:frames
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+213
−86
Open
Improve APNG support #668
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f68c79
Add read_be_u16 and tidy parse_next_chunk
andrews05 c2717ad
Parse fcTL/fdAT into frames
andrews05 ab0dfaf
Recompress frames
andrews05 000ddd7
Retain filter applied
andrews05 369ca2c
Refilter frames
andrews05 638e9a1
Error if fdAT invalid
andrews05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::io::Write; | ||
|
||
use crate::{ | ||
error::PngError, | ||
headers::{read_be_u16, read_be_u32}, | ||
PngResult, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
/// Animated PNG frame | ||
pub struct Frame { | ||
/// Width of the frame | ||
pub width: u32, | ||
/// Height of the frame | ||
pub height: u32, | ||
/// X offset of the frame | ||
pub x_offset: u32, | ||
/// Y offset of the frame | ||
pub y_offset: u32, | ||
/// Frame delay numerator | ||
pub delay_num: u16, | ||
/// Frame delay denominator | ||
pub delay_den: u16, | ||
/// Frame disposal operation | ||
pub dispose_op: u8, | ||
/// Frame blend operation | ||
pub blend_op: u8, | ||
/// Frame data, from fdAT chunks | ||
pub data: Vec<u8>, | ||
} | ||
|
||
impl Frame { | ||
/// Construct a new Frame from the data in a fcTL chunk | ||
pub fn from_fctl_data(byte_data: &[u8]) -> PngResult<Frame> { | ||
if byte_data.len() < 26 { | ||
return Err(PngError::TruncatedData); | ||
} | ||
Ok(Frame { | ||
width: read_be_u32(&byte_data[4..8]), | ||
height: read_be_u32(&byte_data[8..12]), | ||
x_offset: read_be_u32(&byte_data[12..16]), | ||
y_offset: read_be_u32(&byte_data[16..20]), | ||
delay_num: read_be_u16(&byte_data[20..22]), | ||
delay_den: read_be_u16(&byte_data[22..24]), | ||
dispose_op: byte_data[24], | ||
blend_op: byte_data[25], | ||
data: vec![], | ||
}) | ||
} | ||
|
||
/// Construct the data for a fcTL chunk using the given sequence number | ||
#[must_use] | ||
pub fn fctl_data(&self, sequence_number: u32) -> Vec<u8> { | ||
let mut byte_data = Vec::with_capacity(26); | ||
byte_data.write_all(&sequence_number.to_be_bytes()).unwrap(); | ||
byte_data.write_all(&self.width.to_be_bytes()).unwrap(); | ||
byte_data.write_all(&self.height.to_be_bytes()).unwrap(); | ||
byte_data.write_all(&self.x_offset.to_be_bytes()).unwrap(); | ||
byte_data.write_all(&self.y_offset.to_be_bytes()).unwrap(); | ||
byte_data.write_all(&self.delay_num.to_be_bytes()).unwrap(); | ||
byte_data.write_all(&self.delay_den.to_be_bytes()).unwrap(); | ||
byte_data.push(self.dispose_op); | ||
byte_data.push(self.blend_op); | ||
byte_data | ||
} | ||
|
||
/// Construct the data for a fdAT chunk using the given sequence number | ||
#[must_use] | ||
pub fn fdat_data(&self, sequence_number: u32) -> Vec<u8> { | ||
let mut byte_data = Vec::with_capacity(4 + self.data.len()); | ||
byte_data.write_all(&sequence_number.to_be_bytes()).unwrap(); | ||
byte_data.write_all(&self.data).unwrap(); | ||
byte_data | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, is this a BC break?
APNGNotSupported
should have been removed in v9 but it wasn’t.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it technically is, as it's a publicly viewable enum.
cargo semver-checks
is a really useful tool to answer this sort of questions:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I've added APNGNotSupported back in and it's not showing that issue. However, it is showing a bunch of issues to do with the recently-added
#[must_use]
to a number of functions, should we worry about this?I wonder if we should add this tool to our workflow...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd ignore the lints related to
#[must_use]
, as they are too pedantic to matter in practice: they only matter under non-default linter configurations that are a bit of a bad idea to blindly set up. Nevertheless, it's interesting that the tool finds out and let us know about these, just in case my opinion is wrong 🙂Adding this tool to our workflow would be a good idea. I didn't read too much on how it computes a baseline for the semver checks though, so making sure that it always picks something sane in a workflow (even if it runs from a PR, or from a release tag...) would be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, that’s kinda what I figured. Are we good to go with this PR then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before that, I want to give your seemingly good changes a more proper, in-depth look. Please allow for a bit of time until I get around doing it 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I just assumed you already had. No urgency, I appreciate the scrutiny 🙂