From 4dce4f0b2c120d6ed96a4ac72230f2d1b94f26fd Mon Sep 17 00:00:00 2001 From: nanoqsh Date: Tue, 1 Aug 2023 17:59:44 +0600 Subject: [PATCH] Atlas format --- atlas/src/atlas.rs | 2 ++ im/src/lib.rs | 10 ++++++++++ staff/src/main.rs | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/atlas/src/atlas.rs b/atlas/src/atlas.rs index 9f53e7e..73791eb 100644 --- a/atlas/src/atlas.rs +++ b/atlas/src/atlas.rs @@ -47,6 +47,7 @@ fn decode_sprites(data: Vec, names: &HashMap) -> Result, pub map: Map, } @@ -81,6 +82,7 @@ impl Atlas { } Ok(Self { + format, png: im::encode_png(&map)?, map: Map(sprites .into_iter() diff --git a/im/src/lib.rs b/im/src/lib.rs index 02aae53..f23c5c0 100644 --- a/im/src/lib.rs +++ b/im/src/lib.rs @@ -17,6 +17,16 @@ pub enum Format { Rgba = 4, } +impl fmt::Display for Format { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Self::Gray => write!(f, "gray"), + Self::Rgb => write!(f, "rgb"), + Self::Rgba => write!(f, "rgba"), + } + } +} + impl From for ColorType { fn from(format: Format) -> Self { match format { diff --git a/staff/src/main.rs b/staff/src/main.rs index 3c0efa7..ab6288f 100644 --- a/staff/src/main.rs +++ b/staff/src/main.rs @@ -176,7 +176,7 @@ fn run(cli: Cli) -> Result<(), Error> { } => { let data = read_sprites(sprites)?; let names_path = names.unwrap_or_else(|| PathBuf::from("names.json")); - let Atlas { png, map } = atlas::make( + let Atlas { png, map, format } = atlas::make( data, &Parameters { padding: Indent::new(xp, yp)?, @@ -191,6 +191,7 @@ fn run(cli: Cli) -> Result<(), Error> { }, )?; + println!("the atlas packed with {format} format"); let name = name.as_deref().unwrap_or("atlas"); let outdir = make_outdir(outdir)?; write_png(&png, name, &outdir)?;