Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Crunch
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Crunch
Commits
7a1b0355
Verified
Commit
7a1b0355
authored
1 year ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Add 'info' command to extract image info
parent
22c74f3a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cli_args.rs
+13
-1
13 additions, 1 deletion
src/cli_args.rs
src/commands/info.rs
+62
-0
62 additions, 0 deletions
src/commands/info.rs
src/commands/mod.rs
+2
-0
2 additions, 0 deletions
src/commands/mod.rs
with
77 additions
and
1 deletion
src/cli_args.rs
+
13
−
1
View file @
7a1b0355
...
...
@@ -3,7 +3,7 @@ use image::ImageFormat;
use
serde
::{
Deserialize
,
Serialize
};
use
crate
::
commands
::{
Atlas
,
Extract
,
Extrude
,
Flip
,
Palette
,
Pipeline
,
Reduce
,
Remap
,
Rotate
,
Scale
,
Split
,
Atlas
,
Extract
,
Extrude
,
Flip
,
Info
,
Palette
,
Pipeline
,
Reduce
,
Remap
,
Rotate
,
Scale
,
Split
,
};
use
crate
::
load_image
;
...
...
@@ -50,6 +50,9 @@ pub enum Args {
#[clap(name
=
"extract"
)]
#[serde(alias
=
"extract"
)]
Extract
(
Extract
),
#[clap(name
=
"info"
)]
#[serde(alias
=
"info"
)]
Info
(
Info
),
}
impl
Args
{
...
...
@@ -120,6 +123,15 @@ impl Args {
let
image_data
=
load_image
(
&
extract
.input
,
None
)
?
;
extract
.run
(
&
image_data
)
}
Args
::
Info
(
info
)
=>
{
let
image_data
=
load_image
(
&
info
.input
,
None
)
?
;
let
output
=
info
.run
(
&
image_data
)
?
;
{
let
file
=
std
::
fs
::
File
::
create
(
&
info
.output
)
?
;
serde_json
::
to_writer_pretty
(
file
,
&
output
)
?
;
}
Ok
(())
}
}
}
}
This diff is collapsed.
Click to expand it.
src/commands/info.rs
0 → 100644
+
62
−
0
View file @
7a1b0355
use
crate
::
utils
::
TypedOutputFormat
;
use
clap
::{
Parser
,
ValueEnum
};
use
image
::{
imageops
,
GenericImage
,
ImageFormat
,
Pixel
};
use
serde
::{
Deserialize
,
Serialize
};
/// Extract Information About An Image
#[derive(Debug,
Clone,
Parser,
Serialize,
Deserialize)]
#[clap(author,
version
=
"0.7.0"
)]
pub
struct
Info
{
/// The path to the image file
#[serde(default)]
pub
input
:
String
,
/// The path to write the flipped image
#[serde(default)]
pub
output
:
String
,
/// The size of each tile in the spritesheet. Assumed to be square tiles
#[clap(short,
long,
default_value
=
None)]
#[serde(default)]
pub
tile_size
:
Option
<
u32
>
,
}
#[derive(Debug,
Clone,
Serialize,
Deserialize)]
pub
struct
ImageInfo
{
image_width
:
u32
,
image_height
:
u32
,
image_format
:
String
,
tile_width
:
Option
<
u32
>
,
tile_height
:
Option
<
u32
>
,
rows
:
Option
<
u32
>
,
columns
:
Option
<
u32
>
,
}
impl
Info
{
pub
fn
run
<
T
:
GenericImage
>
(
&
self
,
image
:
&
T
)
->
anyhow
::
Result
<
ImageInfo
>
where
T
::
Pixel
:
'static
,
<
T
::
Pixel
as
Pixel
>
::
Subpixel
:
'static
,
{
let
format
=
ImageFormat
::
from_path
(
&
self
.input
)
?
;
let
image_width
=
image
.width
();
let
image_height
=
image
.height
();
let
mut
image_info
=
ImageInfo
{
image_width
,
image_height
,
image_format
:
format!
(
"{:?}"
,
format
)
.to_lowercase
(),
tile_width
:
None
,
tile_height
:
None
,
rows
:
None
,
columns
:
None
,
};
if
let
Some
(
tile_size
)
=
self
.tile_size
{
image_info
.tile_width
=
Some
(
tile_size
);
image_info
.tile_height
=
Some
(
tile_size
);
image_info
.rows
=
Some
(
image_info
.image_height
/
tile_size
);
image_info
.columns
=
Some
(
image_info
.image_width
/
tile_size
);
}
Ok
(
image_info
)
}
}
This diff is collapsed.
Click to expand it.
src/commands/mod.rs
+
2
−
0
View file @
7a1b0355
...
...
@@ -2,6 +2,7 @@ mod atlas;
mod
extract
;
mod
extrude
;
mod
flip
;
mod
info
;
mod
palette
;
mod
pipeline
;
mod
reduce
;
...
...
@@ -14,6 +15,7 @@ pub use atlas::Atlas;
pub
use
extract
::
Extract
;
pub
use
extrude
::
Extrude
;
pub
use
flip
::
Flip
;
pub
use
info
::
Info
;
pub
use
palette
::
Palette
;
pub
use
pipeline
::
Pipeline
;
pub
use
reduce
::
Reduce
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment