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
8b788538
Verified
Commit
8b788538
authored
2 years ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Stub out reduce operation
parent
f5331ed7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/cli_args.rs
+15
-3
15 additions, 3 deletions
src/cli_args.rs
src/commands/mod.rs
+2
-0
2 additions, 0 deletions
src/commands/mod.rs
src/commands/reduce.rs
+47
-0
47 additions, 0 deletions
src/commands/reduce.rs
with
64 additions
and
3 deletions
src/cli_args.rs
+
15
−
3
View file @
8b788538
...
@@ -2,7 +2,7 @@ use clap::Parser;
...
@@ -2,7 +2,7 @@ use clap::Parser;
use
serde
::{
Deserialize
,
Serialize
};
use
serde
::{
Deserialize
,
Serialize
};
// use crate::commands::{calculate_mapping, execute_pipeline, extrude, flip, palette, remap_image, rescale, rotate, write_palette, FlipDirection, RotateDegree, Rotate};
// use crate::commands::{calculate_mapping, execute_pipeline, extrude, flip, palette, remap_image, rescale, rotate, write_palette, FlipDirection, RotateDegree, Rotate};
use
crate
::
commands
::{
Extrude
,
Flip
,
Palette
,
Pipeline
,
Remap
,
Rotate
,
Scale
};
use
crate
::
commands
::{
Extrude
,
Flip
,
Palette
,
Pipeline
,
Reduce
,
Remap
,
Rotate
,
Scale
};
use
crate
::
load_image
;
use
crate
::
load_image
;
...
@@ -33,9 +33,12 @@ pub enum Args {
...
@@ -33,9 +33,12 @@ pub enum Args {
#[clap(name
=
"remap"
)]
#[clap(name
=
"remap"
)]
#[serde(alias
=
"remap"
)]
#[serde(alias
=
"remap"
)]
Remap
(
Remap
),
Remap
(
Remap
),
#[clap(name
=
"
remap
"
)]
#[clap(name
=
"
pipeline
"
)]
#[serde(alias
=
"
remap
"
)]
#[serde(alias
=
"
pipeline
"
)]
Pipeline
(
Pipeline
),
Pipeline
(
Pipeline
),
#[clap(name
=
"reduce"
)]
#[serde(alias
=
"reduce"
)]
Reduce
(
Reduce
),
}
}
impl
Args
{
impl
Args
{
...
@@ -85,6 +88,15 @@ impl Args {
...
@@ -85,6 +88,15 @@ impl Args {
output
.save
(
&
remap
.output
)
.map_err
(
anyhow
::
Error
::
from
)
output
.save
(
&
remap
.output
)
.map_err
(
anyhow
::
Error
::
from
)
}
}
Args
::
Reduce
(
reduce
)
=>
{
if
let
Some
(
amount
)
=
reduce
.colours
{
log
::
info!
(
"Num cols {}"
,
amount
);
}
else
{
log
::
info!
(
"No Limit"
);
}
Ok
(())
}
Args
::
Pipeline
(
pipeline
)
=>
pipeline
.execute
(),
Args
::
Pipeline
(
pipeline
)
=>
pipeline
.execute
(),
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/commands/mod.rs
+
2
−
0
View file @
8b788538
...
@@ -5,6 +5,7 @@ mod pipeline;
...
@@ -5,6 +5,7 @@ mod pipeline;
mod
remap
;
mod
remap
;
mod
rotate
;
mod
rotate
;
mod
scale
;
mod
scale
;
mod
reduce
;
pub
use
extrude
::
Extrude
;
pub
use
extrude
::
Extrude
;
pub
use
flip
::
Flip
;
pub
use
flip
::
Flip
;
...
@@ -13,3 +14,4 @@ pub use pipeline::Pipeline;
...
@@ -13,3 +14,4 @@ pub use pipeline::Pipeline;
pub
use
remap
::
Remap
;
pub
use
remap
::
Remap
;
pub
use
rotate
::
Rotate
;
pub
use
rotate
::
Rotate
;
pub
use
scale
::
Scale
;
pub
use
scale
::
Scale
;
pub
use
reduce
::
Reduce
;
This diff is collapsed.
Click to expand it.
src/commands/reduce.rs
0 → 100644
+
47
−
0
View file @
8b788538
use
crate
::
commands
::
palette
::
ColourMapping
;
use
crate
::
commands
::
Palette
;
use
crate
::
utils
::{
RgbaOutputFormat
,
TypedOutputFormat
};
use
anyhow
::
Error
;
use
clap
::
Parser
;
use
image
::{
GenericImage
,
ImageBuffer
,
Rgba
,
RgbaImage
};
use
serde
::{
Deserialize
,
Serialize
};
use
std
::
collections
::
HashMap
;
/// Limit the number of colours by quantity or threshold
#[derive(Debug,
Clone,
Parser,
Serialize,
Deserialize)]
#[clap(author,
version
=
"0.3.0"
)]
pub
struct
Reduce
{
/// The path to the image file
#[serde(default)]
pub
input
:
String
,
/// The path to write the recoloured image
#[serde(default)]
pub
output
:
String
,
/// The number of colours to use for quantizing
#[clap(short,
long)]
pub
colours
:
Option
<
u32
>
,
/// The colour difference threshold to limit colour reduction
#[clap(short,
long)]
pub
threshold
:
Option
<
f32
>
,
}
impl
Reduce
{
pub
fn
run
<
T
:
GenericImage
>
(
&
self
,
mut
image
:
&
T
)
->
anyhow
::
Result
<
RgbaOutputFormat
>
{
Err
(
Error
::
msg
(
"Reduce is not implemented"
))
// TODO: Reduce impl
// let mut palette = Palette::extract_from(image)?;
//
// let similarity = HashMap::with_capacity(palette.len());
// let mapping: ColourMapping = ColourMapping::new();
//
// while !palette.is_empty() {
// let next = palette.pop();
// }
//
// Ok(RgbaImage::from_fn(image.width(), image.height(), |x, y| {
// Rgba::from([0, 0, 0, 0])
// }))
}
}
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