Skip to content

Commit

Permalink
Colcon 0.7.0 bump; use new fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Beinsezii committed Dec 30, 2023
1 parent f694f8d commit 719938d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
colcon = "0.6"
colcon = "0.7"
# colcon = { git = "https://github.com/Beinsezii/colcon.git" }
# disable wayland
eframe = {version = "0.24", default_features=false, features=["accesskit", "default_fonts", "x11", "wgpu"]}
Expand Down
32 changes: 24 additions & 8 deletions src/gui/lch.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::Model;
use colcon::Space;
use eframe::{
egui::{self, Label, RichText, Sense, TextureOptions, Widget},
epaint::{Color32, ColorImage, Rect, Rgba, Stroke},
};
use super::Model;
use colcon::Space;

pub struct LCH<'a> {
value: &'a mut [f32; 3],
Expand Down Expand Up @@ -83,14 +83,25 @@ impl<'a> Widget for LCH<'a> {
// CH Square
let chpaint = ui.painter_at(chrect);

let mut pixels: Vec<[f32; 3]> = (0..=100).map(|c| {
(0..72).map(|h| [self.value[0], (100 - c) as f32, h as f32 * 5.0] ).collect::<Vec<[f32; 3]>>()
}).reduce(|mut acc, e| {acc.extend_from_slice(&e); acc}).unwrap();
let mut pixels: Vec<[f32; 3]> = (0..=100)
.map(|c| {
(0..72)
.map(|h| [self.value[0], (100 - c) as f32, h as f32 * 5.0])
.collect::<Vec<[f32; 3]>>()
})
.reduce(|mut acc, e| {
acc.extend_from_slice(&e);
acc
})
.unwrap();
self.model.apply(&mut pixels, Space::LRGB);

let chimg = ColorImage {
size: [72, 101],
pixels: pixels.into_iter().map(|p| Rgba::from_rgb(p[0], p[1], p[2]).into()).collect::<Vec<Color32>>()
pixels: pixels
.into_iter()
.map(|p| Rgba::from_rgb(p[0], p[1], p[2]).into())
.collect::<Vec<Color32>>(),
};
let chtexture = ui.ctx().load_texture(
format!("{} CH", self.text),
Expand Down Expand Up @@ -126,12 +137,17 @@ impl<'a> Widget for LCH<'a> {
// L slider
let lpaint = ui.painter_at(lrect);

let mut pixels: Vec<[f32; 3]> = (0..=100).map(|l| [(100 - l) as f32, self.value[1], self.value[2]]).collect::<Vec<[f32; 3]>>();
let mut pixels: Vec<[f32; 3]> = (0..=100)
.map(|l| [(100 - l) as f32, self.value[1], self.value[2]])
.collect::<Vec<[f32; 3]>>();
self.model.apply(&mut pixels, Space::LRGB);

let limg = ColorImage {
size: [1, 101],
pixels: pixels.into_iter().map(|p| Rgba::from_rgb(p[0], p[1], p[2]).into()).collect::<Vec<Color32>>(),
pixels: pixels
.into_iter()
.map(|p| Rgba::from_rgb(p[0], p[1], p[2]).into())
.collect::<Vec<Color32>>(),
};
let ltexture = ui.ctx().load_texture(
format!("{} L", self.text),
Expand Down
20 changes: 12 additions & 8 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use std::{
ops::RangeInclusive,
};

use colcon::srgb_to_irgb;
use colcon::{srgb_to_irgb, Space};

use eframe::{
egui::{
self, CentralPanel, Context, DragValue, Frame, Grid, Label, RichText, ScrollArea, Sense,
SidePanel, Widget,
self, CentralPanel, Context, DragValue, Frame, Grid, Label, Rgba, RichText, ScrollArea,
Sense, SidePanel, Widget,
},
emath::Align2,
epaint::{Color32, Rounding, Stroke},
Expand Down Expand Up @@ -348,11 +348,9 @@ impl App for CollurgyUI {
ui.add(Label::new(self.output()).wrap(false))
});
});
let mut fill = [0.5, 0.0, 0.0];
colcon::convert_space(colcon::Space::OKLAB, colcon::Space::SRGB, &mut fill);
let fill = egui::Rgba::from_rgb(fill[0], fill[1], fill[2]);
let fill = colcon::str2space("oklab 0.5 0 0", Space::SRGB).unwrap();
CentralPanel::default()
.frame(Frame::none().fill(fill.into()))
.frame(Frame::none().fill(Rgba::from_rgb(fill[0], fill[1], fill[2]).into()))
.show(&ctx, |ui| {
// {{{
ui.horizontal(|ui| {
Expand All @@ -369,7 +367,13 @@ impl App for CollurgyUI {
),
);
ui.menu_button(format!("Model: {:?}", self.data.model), |ui| {
for model in [Model::HSV, Model::CIELCH, Model::CIELCH2023, Model::OKLCH, Model::JZCZHZ] {
for model in [
Model::HSV,
Model::CIELCH,
Model::CIELCH2023,
Model::OKLCH,
Model::JZCZHZ,
] {
if ui.button(format!("{:?}", model)).clicked() {
self.data.model = model
}
Expand Down
30 changes: 25 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashMap, ffi::OsStr, fs::read_to_string, path::PathBuf};

use colcon::{convert_space_chunked, irgb_to_hex, srgb_to_irgb, Space, hk_high2023_comp};
use colcon::{convert_space_chunked, hk_high2023_comp, irgb_to_hex, srgb_to_irgb, Space};
use serde::{Deserialize, Serialize};

mod gui;
Expand All @@ -18,11 +18,31 @@ pub enum Model {
impl Model {
fn apply(&self, colors: &mut [[f32; 3]], to: colcon::Space) {
let from = match self {
Model::HSV => {colors.iter_mut().for_each(|col| *col = [col[2] / 360.0, col[1] / 100.0, col[0] / 100.0]); Space::HSV},
Model::HSV => {
colors
.iter_mut()
.for_each(|col| *col = [col[2] / 360.0, col[1] / 100.0, col[0] / 100.0]);
Space::HSV
}
Model::CIELCH => Space::LCH,
Model::CIELCH2023 => {colors.iter_mut().for_each(|col| hk_high2023_comp(col)); Space::LCH},
Model::OKLCH => {colors.iter_mut().for_each(|col| {col[0] /= 100.0; col[1] /= 400.0;}); Space::OKLCH},
Model::JZCZHZ => {colors.iter_mut().for_each(|col| {col[0] /= 5650.0; col[1] /= 5650.0;}); Space::JZCZHZ}
Model::CIELCH2023 => {
colors.iter_mut().for_each(|col| hk_high2023_comp(col));
Space::LCH
}
Model::OKLCH => {
colors.iter_mut().for_each(|col| {
col[0] /= 100.0;
col[1] /= 400.0;
});
Space::OKLCH
}
Model::JZCZHZ => {
colors.iter_mut().for_each(|col| {
col[0] /= 5650.0;
col[1] /= 5650.0;
});
Space::JZCZHZ
}
};
convert_space_chunked(from, to, colors);
}
Expand Down

0 comments on commit 719938d

Please sign in to comment.