-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a2bdcd
commit db0131c
Showing
5 changed files
with
175 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ target | |
.DS_Store | ||
*.out.png | ||
/.idea | ||
/.vscode | ||
/node_modules |
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,75 @@ | ||
use std::io::Cursor; | ||
use byteorder::{BigEndian, ReadBytesExt}; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
#[repr(u8)] | ||
pub enum DisposalType { | ||
None = 0, | ||
Background = 1, | ||
Previous = 2, | ||
} | ||
|
||
impl From<u8> for DisposalType { | ||
fn from(val: u8) -> Self { | ||
match val { | ||
0 => DisposalType::None, | ||
1 => DisposalType::Background, | ||
2 => DisposalType::Previous, | ||
_ => panic!("Unrecognized disposal type"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
#[repr(u8)] | ||
pub enum BlendType { | ||
Source = 0, | ||
Over = 1, | ||
} | ||
|
||
impl From<u8> for BlendType { | ||
fn from(val: u8) -> Self { | ||
match val { | ||
0 => BlendType::Source, | ||
1 => BlendType::Over, | ||
_ => panic!("Unrecognized blend type"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ApngFrame { | ||
pub sequence_number: u32, | ||
pub width: u32, | ||
pub height: u32, | ||
pub x_offset: u32, | ||
pub y_offset: u32, | ||
pub delay_num: u16, | ||
pub delay_den: u16, | ||
pub dispose_op: DisposalType, | ||
pub blend_op: BlendType, | ||
/// The compressed, filtered data from the fdAT chunks | ||
pub frame_data: Vec<u8>, | ||
/// The uncompressed, optionally filtered data from the fdAT chunks | ||
pub raw_data: Vec<u8>, | ||
} | ||
|
||
impl<'a> From<&'a [u8]> for ApngFrame { | ||
/// Converts a fcTL header to an `ApngFrame`. Will panic if `data` is less than 26 bytes. | ||
fn from(data: &[u8]) -> Self { | ||
let mut cursor = Cursor::new(data); | ||
ApngFrame { | ||
sequence_number: cursor.read_u32::<BigEndian>().unwrap(), | ||
width: cursor.read_u32::<BigEndian>().unwrap(), | ||
height: cursor.read_u32::<BigEndian>().unwrap(), | ||
x_offset: cursor.read_u32::<BigEndian>().unwrap(), | ||
y_offset: cursor.read_u32::<BigEndian>().unwrap(), | ||
delay_num: cursor.read_u16::<BigEndian>().unwrap(), | ||
delay_den: cursor.read_u16::<BigEndian>().unwrap(), | ||
dispose_op: cursor.read_u8().unwrap().into(), | ||
blend_op: cursor.read_u8().unwrap().into(), | ||
frame_data: Vec::new(), | ||
raw_data: Vec::new(), | ||
} | ||
} | ||
} |
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
db0131c
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.
Started #79.…
db0131c
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.
Any available builds with this change?
db0131c
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.
It's still incomplete at this point. It can read in an APNG but will write out a non animated PNG.