-
Notifications
You must be signed in to change notification settings - Fork 123
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
Josh Holmer
committed
Jul 14, 2016
1 parent
332c27c
commit 7f9ad26
Showing
16 changed files
with
2,014 additions
and
1,895 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
[*.rs] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,96 @@ | ||
use std::fmt; | ||
|
||
#[derive(Debug,PartialEq,Clone,Copy)] | ||
/// The color type used to represent this image | ||
pub enum ColorType { | ||
/// Grayscale, with one color channel | ||
Grayscale, | ||
/// RGB, with three color channels | ||
RGB, | ||
/// Indexed, with one byte per pixel representing one of up to 256 colors in the image | ||
Indexed, | ||
/// Grayscale + Alpha, with two color channels | ||
GrayscaleAlpha, | ||
/// RGBA, with four color channels | ||
RGBA, | ||
} | ||
|
||
impl fmt::Display for ColorType { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, | ||
"{}", | ||
match *self { | ||
ColorType::Grayscale => "Grayscale", | ||
ColorType::RGB => "RGB", | ||
ColorType::Indexed => "Indexed", | ||
ColorType::GrayscaleAlpha => "Grayscale + Alpha", | ||
ColorType::RGBA => "RGB + Alpha", | ||
}) | ||
} | ||
} | ||
|
||
impl ColorType { | ||
/// Get the code used by the PNG specification to denote this color type | ||
pub fn png_header_code(&self) -> u8 { | ||
match *self { | ||
ColorType::Grayscale => 0, | ||
ColorType::RGB => 2, | ||
ColorType::Indexed => 3, | ||
ColorType::GrayscaleAlpha => 4, | ||
ColorType::RGBA => 6, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug,PartialEq,Clone,Copy)] | ||
/// The number of bits to be used per channel per pixel | ||
pub enum BitDepth { | ||
/// One bit per channel per pixel | ||
One, | ||
/// Two bits per channel per pixel | ||
Two, | ||
/// Four bits per channel per pixel | ||
Four, | ||
/// Eight bits per channel per pixel | ||
Eight, | ||
/// Sixteen bits per channel per pixel | ||
Sixteen, | ||
} | ||
|
||
impl fmt::Display for BitDepth { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, | ||
"{}", | ||
match *self { | ||
BitDepth::One => "1", | ||
BitDepth::Two => "2", | ||
BitDepth::Four => "4", | ||
BitDepth::Eight => "8", | ||
BitDepth::Sixteen => "16", | ||
}) | ||
} | ||
} | ||
|
||
impl BitDepth { | ||
/// Retrieve the number of bits per channel per pixel as a `u8` | ||
pub fn as_u8(&self) -> u8 { | ||
match *self { | ||
BitDepth::One => 1, | ||
BitDepth::Two => 2, | ||
BitDepth::Four => 4, | ||
BitDepth::Eight => 8, | ||
BitDepth::Sixteen => 16, | ||
} | ||
} | ||
/// Parse a number of bits per channel per pixel into a `BitDepth` | ||
pub fn from_u8(depth: u8) -> BitDepth { | ||
match depth { | ||
1 => BitDepth::One, | ||
2 => BitDepth::Two, | ||
4 => BitDepth::Four, | ||
8 => BitDepth::Eight, | ||
16 => BitDepth::Sixteen, | ||
_ => panic!("Unsupported bit depth"), | ||
} | ||
} | ||
} |
Oops, something went wrong.