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
e5557d3f
Verified
Commit
e5557d3f
authored
1 year ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Add numeric file sort option to atlas builder
parent
f5ca59c7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#604
passed with stages
Stage:
Stage:
in 3 minutes
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+6
-0
6 additions, 0 deletions
CHANGELOG.md
Cargo.lock
+1
-1
1 addition, 1 deletion
Cargo.lock
Cargo.toml
+1
-1
1 addition, 1 deletion
Cargo.toml
src/commands/atlas.rs
+45
-2
45 additions, 2 deletions
src/commands/atlas.rs
with
53 additions
and
4 deletions
CHANGELOG.md
+
6
−
0
View file @
e5557d3f
...
...
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on
[
Keep a Changelog
](
https://keepachangelog.com/en/1.0.0/
)
,
and this project adheres to
[
Semantic Versioning
](
https://semver.org/spec/v2.0.0.html
)
.
## [0.8.2] - 2024-04-28
### Added
-
Added numeric file name sort option to atlas builder
## [0.8.1] - 2024-04-28
### Added
...
...
This diff is collapsed.
Click to expand it.
Cargo.lock
+
1
−
1
View file @
e5557d3f
...
...
@@ -233,7 +233,7 @@ dependencies = [
[[package]]
name = "crunch-cli"
version = "0.8.
1
"
version = "0.8.
2
"
dependencies = [
"anyhow",
"clap",
...
...
This diff is collapsed.
Click to expand it.
Cargo.toml
+
1
−
1
View file @
e5557d3f
[package]
name
=
"crunch-cli"
version
=
"0.8.
1
"
version
=
"0.8.
2
"
edition
=
"2021"
homepage
=
"https://microhacks.lcr.app/crunch/"
...
...
This diff is collapsed.
Click to expand it.
src/commands/atlas.rs
+
45
−
2
View file @
e5557d3f
...
...
@@ -4,6 +4,7 @@ use etagere::{AllocId, AtlasAllocator, Rectangle, Size};
use
image
::{
image_dimensions
,
GenericImage
,
Rgba
,
RgbaImage
};
use
rayon
::
prelude
::{
IntoParallelIterator
,
ParallelIterator
};
use
serde
::{
Deserialize
,
Serialize
};
use
std
::
cmp
::
Ordering
;
use
std
::
collections
::
HashMap
;
use
std
::
fmt
::
Display
;
use
std
::
fs
::
File
;
...
...
@@ -16,7 +17,7 @@ fn default_max_size() -> usize {
/// Given a set of images, create a single atlas image and metadata file containing all of the original
/// set
#[derive(Parser,
Serialize,
Deserialize,
Clone,
Debug)]
#[clap(author,
version
=
"0.8.
1
"
)]
#[clap(author,
version
=
"0.8.
2
"
)]
pub
struct
Atlas
{
/// A pattern evaluating to one or more image files
#[serde(default)]
...
...
@@ -36,6 +37,13 @@ pub struct Atlas {
/// be padded to the correct size before specifying an area
#[clap(short
=
'a'
,
long
=
"area"
)]
pub
area
:
Option
<
usize
>
,
/// Perform a numeric sort on the names of files being combined.
///
/// With this flag enabled, the files "104", "5", "2045" would be ordered as "5", "104", "2045"
/// Without this flag, those same files would be ordered by OS determination, typically ""104", "2045", "5"
#[serde(default)]
#[clap(short
=
'n'
)]
pub
numeric
:
bool
,
}
#[derive(Copy,
Clone,
Hash,
Eq,
PartialEq)]
...
...
@@ -108,9 +116,44 @@ impl Atlas {
let
pattern
=
glob
::
glob
(
self
.glob
.as_str
())
?
;
let
mut
builder
=
AtlasBuilder
::
new
((
self
.max_frame_width
,
self
.max_frame_height
));
let
mut
pattern
=
pattern
.filter_map
(
Result
::
ok
)
.collect
::
<
Vec
<
PathBuf
>>
();
if
self
.numeric
{
pattern
.sort_by
(|
a
,
b
|
{
let
a_num
:
isize
=
match
a
.file_stem
()
.and_then
(|
s
|
s
.to_str
())
.and_then
(|
s
|
s
.parse
()
.ok
())
{
Some
(
v
)
=>
v
,
_
=>
return
Ordering
::
Equal
,
};
let
b_num
:
isize
=
match
b
.file_stem
()
.and_then
(|
s
|
s
.to_str
())
.and_then
(|
s
|
s
.parse
()
.ok
())
{
Some
(
v
)
=>
v
,
_
=>
return
Ordering
::
Equal
,
};
a_num
.cmp
(
&
b_num
)
});
}
else
{
pattern
.sort_by
(|
a
,
b
|
{
let
a_num
=
match
a
.file_stem
()
.and_then
(|
s
|
s
.to_str
())
{
Some
(
v
)
=>
v
,
_
=>
return
Ordering
::
Equal
,
};
let
b_num
=
match
b
.file_stem
()
.and_then
(|
s
|
s
.to_str
())
{
Some
(
v
)
=>
v
,
_
=>
return
Ordering
::
Equal
,
};
a_num
.cmp
(
b_num
)
})
}
let
page_content_map
:
HashMap
<
usize
,
Vec
<
(
PathBuf
,
Rectangle
)
>>
=
pattern
.into_iter
()
.filter_map
(
Result
::
ok
)
.flat_map
(|
path
|
{
if
let
Some
(
fixed
)
=
&
self
.area
{
Ok
((
*
fixed
as
u32
,
*
fixed
as
u32
,
path
))
...
...
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