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
000e5509
Verified
Commit
000e5509
authored
5 months ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Fix incorrect target colour generation for column palette
parent
8488fc84
No related branches found
No related tags found
No related merge requests found
Pipeline
#676
waiting for manual action with stages
Stage:
Stage:
in 11 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
src/cli_args.rs
+8
-5
8 additions, 5 deletions
src/cli_args.rs
src/commands/mod.rs
+1
-1
1 addition, 1 deletion
src/commands/mod.rs
src/commands/palette.rs
+18
-6
18 additions, 6 deletions
src/commands/palette.rs
src/format.rs
+2
-0
2 additions, 0 deletions
src/format.rs
with
31 additions
and
13 deletions
.gitignore
+
2
−
1
View file @
000e5509
/target
.idea/
exmp/
\ No newline at end of file
exmp/
/*.png
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/cli_args.rs
+
8
−
5
View file @
000e5509
...
...
@@ -2,7 +2,10 @@ use clap::Parser;
use
image
::
ImageFormat
;
use
serde
::{
Deserialize
,
Serialize
};
use
crate
::
commands
::{
Atlas
,
Extract
,
Extrude
,
Flip
,
Info
,
Palette
,
Pipeline
,
Reduce
,
Remap
,
Rotate
,
Scale
,
Split
,
Swap
};
use
crate
::
commands
::{
Atlas
,
Extract
,
Extrude
,
Flip
,
Info
,
Palette
,
Pipeline
,
Reduce
,
Remap
,
Rotate
,
Scale
,
Split
,
Swap
,
};
use
crate
::
load_image
;
...
...
@@ -51,8 +54,8 @@ pub enum Args {
#[clap(name
=
"info"
)]
#[serde(alias
=
"info"
)]
Info
(
Info
),
#[clap(name
=
"
info
"
)]
#[serde(alias
=
"
info
"
)]
#[clap(name
=
"
swap
"
)]
#[serde(alias
=
"
swap
"
)]
Swap
(
Swap
),
}
...
...
@@ -109,11 +112,11 @@ impl Args {
let
image_data
=
load_image
(
&
swap
.input
,
None
)
?
;
let
palette_data
=
load_image
(
&
swap
.palette
,
None
)
?
;
let
palette_swap
=
Palette
::
from_columns
(
&
palette_data
)
?
;
let
output
=
Rem
ap
::
remap_image
(
image_data
,
palette_swap
)
?
;
let
output
=
Sw
ap
::
swap_pixels
(
image_data
,
palette_swap
)
?
;
output
.save_with_format
(
&
swap
.output
,
ImageFormat
::
Png
)
.map_err
(
anyhow
::
Error
::
from
)
}
,
}
Args
::
Reduce
(
reduce
)
=>
{
if
let
Some
(
amount
)
=
reduce
.colours
{
log
::
info!
(
"Num cols {}"
,
amount
);
...
...
This diff is collapsed.
Click to expand it.
src/commands/mod.rs
+
1
−
1
View file @
000e5509
...
...
@@ -24,4 +24,4 @@ pub use remap::Remap;
pub
use
rotate
::
Rotate
;
pub
use
scale
::
Scale
;
pub
use
split
::
Split
;
pub
use
swap
::
Swap
;
\ No newline at end of file
pub
use
swap
::
Swap
;
This diff is collapsed.
Click to expand it.
src/commands/palette.rs
+
18
−
6
View file @
000e5509
...
...
@@ -3,12 +3,12 @@ use std::cmp::{min, Ordering};
use
std
::
collections
::
hash_map
::
RandomState
;
use
std
::
collections
::{
HashMap
,
HashSet
};
use
std
::
io
::
Write
;
use
anyhow
::
Error
;
use
deltae
::{
Delta
,
LabValue
,
DE2000
};
use
image
::{
GenericImage
,
Pixel
,
Rgba
};
use
num_traits
::
ToPrimitive
;
use
serde
::{
Deserialize
,
Serialize
};
use
std
::
io
::
Write
;
use
crate
::
format
::
PaletteFormat
;
use
crate
::
utils
::{
new_image
,
BasicRgba
};
...
...
@@ -37,7 +37,7 @@ pub fn sort_by_hue(palette: &mut PixelPalette) {
/// Create a palette file containing every distinct colour from the input image
#[derive(Parser,
Clone,
Serialize,
Deserialize,
Debug)]
#[clap(author,
version
=
"0.
3
.0"
)]
#[clap(author,
version
=
"0.
9
.0"
)]
pub
struct
Palette
{
/// The path to the image file
#[serde(default)]
...
...
@@ -98,6 +98,18 @@ impl Palette {
out_image
.save
(
self
.output
.as_str
())
?
;
}
PaletteFormat
::
Columns
=>
{
let
image_width
=
2
;
let
image_height
=
colours
.len
();
let
mut
out_image
=
new_image
(
image_width
as
u32
,
image_height
as
u32
);
for
(
idx
,
colour
)
in
colours
.iter
()
.enumerate
()
{
out_image
.put_pixel
(
0
,
idx
as
u32
,
Rgba
::
from
(
colour
));
out_image
.put_pixel
(
1
,
idx
as
u32
,
Rgba
::
from
(
colour
));
}
out_image
.save
(
self
.output
.as_str
())
?
;
}
PaletteFormat
::
Txt
=>
{
let
mut
file
=
std
::
fs
::
File
::
create
(
self
.output
.as_str
())
?
;
for
colour
in
colours
.iter
()
{
...
...
@@ -129,10 +141,10 @@ impl Palette {
]);
let
left_pixel
=
BasicRgba
::
from
(
data
);
let
data
=
Rgba
::
from
([
lef
t
.0
[
0
]
.to_u8
()
.unwrap
(),
lef
t
.0
[
1
]
.to_u8
()
.unwrap
(),
lef
t
.0
[
2
]
.to_u8
()
.unwrap
(),
lef
t
.0
[
3
]
.to_u8
()
.unwrap
(),
righ
t
.0
[
0
]
.to_u8
()
.unwrap
(),
righ
t
.0
[
1
]
.to_u8
()
.unwrap
(),
righ
t
.0
[
2
]
.to_u8
()
.unwrap
(),
righ
t
.0
[
3
]
.to_u8
()
.unwrap
(),
]);
let
right_pixel
=
BasicRgba
::
from
(
data
);
mapping
.insert
(
left_pixel
,
right_pixel
);
...
...
This diff is collapsed.
Click to expand it.
src/format.rs
+
2
−
0
View file @
000e5509
...
...
@@ -15,6 +15,8 @@ pub enum PaletteFormat {
#[default]
#[serde(alias
=
"png"
)]
Png
,
#[serde(alias
=
"columns"
)]
Columns
,
}
#[derive(Copy,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
ValueEnum,
Debug)]
...
...
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