Skip to content

Commit

Permalink
cleanup warning and fix bin
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoeyR committed Dec 24, 2017
1 parent c1dd9d0 commit 3a9fd36
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target/
**/*.rs.bk
Cargo.lock
/examples/out.png
/examples/*out.png
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ authors = ["Daniel Griffen <[email protected]>"]
license = "MIT"
description = "flif decoder written in pure Rust"

exclude = [
"resources/*",
]

[lib]
name = "flif"
path = "src/flif/lib.rs"
Expand Down
6 changes: 2 additions & 4 deletions examples/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extern crate png;

use flif::components::header::Channels;
use flif::Decoder;
use std::path::Path;
use std::fs::File;
use std::io::BufWriter;
use png::HasParameters;
Expand All @@ -14,7 +13,7 @@ fn main() {
}

fn decode_and_write(input: &str, output: &str) {
let file = std::fs::File::open("resources/sea_snail.flif").unwrap();
let file = std::fs::File::open(input).unwrap();

let mut decoder = Decoder::new(file);
let flif = decoder.decode().unwrap();
Expand All @@ -23,8 +22,7 @@ fn decode_and_write(input: &str, output: &str) {
println!("├───{:?}", flif.info.metadata);
println!("└───{:?}", flif.info.second_header);

let path = Path::new("resources/out.png");
let file = File::create(path).unwrap();
let file = File::create(output).unwrap();
let ref mut w = BufWriter::new(file);

let mut encoder = png::Encoder::new(w, flif.info.header.width as u32, flif.info.header.height as u32);
Expand Down
55 changes: 42 additions & 13 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
extern crate flif;
extern crate png;
extern crate structopt;
#[macro_use]
extern crate structopt_derive;

use std::fs::File;
use std::io::Read;
use std::io::{Read, Write};
use std::io::BufWriter;

use flif::components::header::Channels;
use flif::error::*;
use flif::Decoder;

use png::HasParameters;

use structopt::StructOpt;

Expand Down Expand Up @@ -53,29 +59,52 @@ fn main() {
});
}

fn decode(identify: bool, input: &str, _output: Option<String>) -> Result<()> {
fn decode(identify: bool, input: &str, output: Option<String>) -> Result<()> {
let file = File::open(input)?;
let mut decoder = Decoder::new(file);

if identify {
id_file(file)
id_file(decoder)
} else {
Err(Error::Unimplemented(
"decoding pixel data is not supported at this time",
))
let flif = decoder.decode()?;

if let Some(output) = output {
let output_file = File::create(output)?;
let ref mut w = BufWriter::new(output_file);

let mut encoder = png::Encoder::new(w, flif.info.header.width as u32, flif.info.header.height as u32);

let color_type = match flif.info.header.channels {
Channels::RGBA => png::ColorType::RGBA,
Channels::RGB => png::ColorType::RGB,
_ => panic!("unsupported color type"),
};

encoder.set(color_type).set(png::BitDepth::Eight);
let mut writer = encoder.write_header().unwrap();

let data = flif.get_raw_pixels(); // Get the raw pixel array of the FLIF image
writer.write_image_data(&data).unwrap(); // Save
Ok(())
} else {
std::io::stdout().write(&flif.get_raw_pixels())?;
Ok(())
}

}
}

fn id_file<R: Read>(reader: R) -> Result<()> {
let header = flif::components::header::Header::from_reader(reader)?;
fn id_file<R: Read>(mut decoder: Decoder<R>) -> Result<()> {
let info = decoder.identify()?;

if header.interlaced {
if info.header.interlaced {
println!("interlaced");
}
if header.animated {
println!("animated, frames: {}", header.num_frames);
if info.header.animated {
println!("animated, frames: {}", info.header.num_frames);
}
println!("channels: {:?}", header.channels);
println!("dimensions: {}W x {}H", header.width, header.height);
println!("channels: {:?}", info.header.channels);
println!("dimensions: {}W x {}H", info.header.width, info.header.height);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/flif/components/transformations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait Transformation: ::std::fmt::Debug {
struct Orig;

impl Transformation for Orig {
fn undo(&self, pixel: &mut [ColorValue]) {
fn undo(&self, _pixel: &mut [ColorValue]) {

}

Expand Down
2 changes: 1 addition & 1 deletion src/flif/components/transformations/permute_planes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl PermutePlanes {
}

impl Transformation for PermutePlanes {
fn undo(&self, pixel: &mut [ColorValue]) {
fn undo(&self, _pixel: &mut [ColorValue]) {

}

Expand Down
3 changes: 1 addition & 2 deletions src/flif/numbers/rac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,11 @@ mod tests {
unimplemented!()
}

fn read_chance(&mut self, chance: u32) -> Result<bool> {
fn read_chance(&mut self, _chance: u32) -> Result<bool> {
unimplemented!()
}

fn read(&mut self, context: &mut ChanceTable, entry: ChanceTableEntry) -> Result<bool> {
let chance = context.get_chance(entry);
let bit = self.get(entry);
context.update_entry(bit, entry);

Expand Down
3 changes: 0 additions & 3 deletions tests/png_equality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ extern crate flif;

use std::fs::File;
use flif::Decoder;
use std::path::Path;
use std::io::BufWriter;
use png::HasParameters;

#[test]
fn sea_snail() {
Expand Down

0 comments on commit 3a9fd36

Please sign in to comment.