Skip to content

Commit

Permalink
Atlas format
Browse files Browse the repository at this point in the history
  • Loading branch information
nanoqsh committed Aug 1, 2023
1 parent c1532c7 commit 4dce4f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions atlas/src/atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn decode_sprites(data: Vec<ImageData>, names: &HashMap<Name, Name>) -> Result<V
}

pub struct Atlas {
pub format: Format,
pub png: Vec<u8>,
pub map: Map,
}
Expand Down Expand Up @@ -81,6 +82,7 @@ impl Atlas {
}

Ok(Self {
format,
png: im::encode_png(&map)?,
map: Map(sprites
.into_iter()
Expand Down
10 changes: 10 additions & 0 deletions im/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Format> for ColorType {
fn from(format: Format) -> Self {
match format {
Expand Down
3 changes: 2 additions & 1 deletion staff/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
Expand All @@ -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)?;
Expand Down

0 comments on commit 4dce4f0

Please sign in to comment.