Skip to content

Commit e05d574

Browse files
committed
Initial commit of jasc-and-gpl
0 parents  commit e05d574

File tree

4 files changed

+240
-0
lines changed

4 files changed

+240
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target/
2+
**/*.rs.bk

Cargo.lock

+189
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "jasc-and-gpl"
3+
description = "A tool to convert between JASC and GIMP palettes"
4+
version = "0.1.0"
5+
authors = ["Taryn Hill <[email protected]>"]
6+
7+
[dependencies]
8+
chariot_palette = "0.1"
9+
gimp_palette = "0.1"
10+
clap = "2.23"

src/main.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use std::fs::File;
2+
use std::io::BufReader;
3+
4+
extern crate chariot_palette as jasc_palette;
5+
extern crate gimp_palette;
6+
7+
extern crate clap;
8+
use clap::{App, Arg};
9+
10+
fn main() {
11+
let matches = App::new("jasc-to-gpl")
12+
.version("0.1.0")
13+
.author("Taryn Hill <[email protected]>")
14+
.about("Convert JASC palettes (\"pal\") to GIMP (\"gpl\") palettes")
15+
.arg(Arg::with_name("jasc-path")
16+
.long("jasc-path")
17+
.value_name("jasc-path")
18+
.help("The filepath to the 'pal' to convert to 'gpl'")
19+
.required(true)
20+
.takes_value(true))
21+
.arg(Arg::with_name("gpl-path")
22+
.long("gpl-path")
23+
.help("The filepath to write the output 'gpl' to")
24+
.required(true)
25+
.takes_value(true))
26+
.get_matches();
27+
28+
let jasc_colors = {
29+
let jasc_path = matches.value_of("jasc-path").unwrap();
30+
let jasc_file = File::open(&jasc_path).expect(&format!("Could not open {}", jasc_path));
31+
let mut jasc_reader = BufReader::new(jasc_file);
32+
jasc_palette::read_from(&mut jasc_reader).expect(&format!("Failed to load a JASC palette from {}", jasc_path))
33+
};
34+
35+
let gpl_path = matches.value_of("gpl-path").unwrap();
36+
let gpl_colors = jasc_colors.iter().map(|j| gimp_palette::Color { r: j.r, g: j.g, b: j.b }).collect::<Vec<_>>();
37+
let gpl_pal = gimp_palette::Palette::new("Unnamed", gpl_colors).expect("Failed to create a GIMP palette in-memory");
38+
gpl_pal.write_to_file(&gpl_path).expect(&format!("Failed to write GIMP palette to {}", gpl_path));
39+
}

0 commit comments

Comments
 (0)