mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
Merge pull request #45 from gwilymk/allow-agb-image-converter-to-be-used-in-any-crate
Allow agb image converter to be used in any crate
This commit is contained in:
commit
7a97591432
47
agb-image-converter/Cargo.lock
generated
47
agb-image-converter/Cargo.lock
generated
|
@ -19,6 +19,7 @@ name = "agb_image_converter"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"image",
|
"image",
|
||||||
|
"typed-builder",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -277,6 +278,24 @@ dependencies = [
|
||||||
"miniz_oxide 0.3.7",
|
"miniz_oxide 0.3.7",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-xid",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rayon"
|
name = "rayon"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
|
@ -314,6 +333,17 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.72"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-xid",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tiff"
|
name = "tiff"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
|
@ -325,6 +355,23 @@ dependencies = [
|
||||||
"weezl",
|
"weezl",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typed-builder"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "345426c7406aa355b60c5007c79a2d1f5b605540072795222f17f6443e6a9c6f"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-xid"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "weezl"
|
name = "weezl"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
|
|
|
@ -8,3 +8,4 @@ description = "Library for converting graphics for use on the Game Boy Advance"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
image = "0.23.14"
|
image = "0.23.14"
|
||||||
|
typed-builder = "0.9.0"
|
|
@ -2,6 +2,8 @@ use std::fs::File;
|
||||||
use std::io::BufWriter;
|
use std::io::BufWriter;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
mod colour;
|
mod colour;
|
||||||
mod image_loader;
|
mod image_loader;
|
||||||
mod palette16;
|
mod palette16;
|
||||||
|
@ -26,14 +28,19 @@ impl TileSize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(TypedBuilder)]
|
||||||
pub struct ImageConverterConfig {
|
pub struct ImageConverterConfig {
|
||||||
pub transparent_colour: Option<Colour>,
|
#[builder(default, setter(strip_option))]
|
||||||
pub tile_size: TileSize,
|
transparent_colour: Option<Colour>,
|
||||||
pub input_image: PathBuf,
|
tile_size: TileSize,
|
||||||
pub output_file: PathBuf,
|
input_image: PathBuf,
|
||||||
|
output_file: PathBuf,
|
||||||
|
|
||||||
|
#[builder(default, setter(strip_option))]
|
||||||
|
crate_prefix: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_image(settings: &ImageConverterConfig) {
|
pub fn convert_image(settings: ImageConverterConfig) {
|
||||||
let image = Image::load_from_file(&settings.input_image);
|
let image = Image::load_from_file(&settings.input_image);
|
||||||
|
|
||||||
let tile_size = settings.tile_size.to_size();
|
let tile_size = settings.tile_size.to_size();
|
||||||
|
@ -52,6 +59,7 @@ pub fn convert_image(settings: &ImageConverterConfig) {
|
||||||
&optimisation_results,
|
&optimisation_results,
|
||||||
&image,
|
&image,
|
||||||
settings.tile_size,
|
settings.tile_size,
|
||||||
|
settings.crate_prefix.unwrap_or("agb".to_owned()),
|
||||||
)
|
)
|
||||||
.expect("Failed to write data");
|
.expect("Failed to write data");
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,20 @@ pub(crate) fn generate_code(
|
||||||
results: &Palette16OptimisationResults,
|
results: &Palette16OptimisationResults,
|
||||||
image: &Image,
|
image: &Image,
|
||||||
tile_size: TileSize,
|
tile_size: TileSize,
|
||||||
|
crate_prefix: String,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
writeln!(
|
writeln!(
|
||||||
output,
|
output,
|
||||||
"pub const PALETTE_DATA: &[crate::display::palette16::Palette16] = &[",
|
"pub const PALETTE_DATA: &[{}::display::palette16::Palette16] = &[",
|
||||||
|
crate_prefix,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
for palette in &results.optimised_palettes {
|
for palette in &results.optimised_palettes {
|
||||||
write!(output, " crate::display::palette16::Palette16::new([")?;
|
write!(
|
||||||
|
output,
|
||||||
|
" {}::display::palette16::Palette16::new([",
|
||||||
|
crate_prefix
|
||||||
|
)?;
|
||||||
|
|
||||||
for colour in palette.clone() {
|
for colour in palette.clone() {
|
||||||
write!(output, "0x{:08x}, ", colour.to_rgb15())?;
|
write!(output, "0x{:08x}, ", colour.to_rgb15())?;
|
||||||
|
|
Loading…
Reference in a new issue