commit 2e125ac301f2e16d0bf9ae582e9d44ad2274db05 Author: Daniel Heras Quesada Date: Sun Aug 10 00:18:27 2025 +0200 feat: base colorizer project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/colorizer/.gitignore b/colorizer/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/colorizer/.gitignore @@ -0,0 +1 @@ +/target diff --git a/colorizer/Cargo.lock b/colorizer/Cargo.lock new file mode 100644 index 0000000..52e858b --- /dev/null +++ b/colorizer/Cargo.lock @@ -0,0 +1,129 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + +[[package]] +name = "clipboard" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a904646c0340239dcf7c51677b33928bf24fdf424b79a57909c0109075b2e7" +dependencies = [ + "clipboard-win", + "objc", + "objc-foundation", + "objc_id", + "x11-clipboard", +] + +[[package]] +name = "clipboard-win" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a093d6fed558e5fe24c3dfc85a68bb68f1c824f440d3ba5aca189e2998786b" +dependencies = [ + "winapi", +] + +[[package]] +name = "colorizer" +version = "0.1.0" +dependencies = [ + "clipboard", +] + +[[package]] +name = "libc" +version = "0.2.174" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "x11-clipboard" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89bd49c06c9eb5d98e6ba6536cf64ac9f7ee3a009b2f53996d405b3944f6bcea" +dependencies = [ + "xcb", +] + +[[package]] +name = "xcb" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e917a3f24142e9ff8be2414e36c649d47d6cc2ba81f16201cdef96e533e02de" +dependencies = [ + "libc", + "log", +] diff --git a/colorizer/Cargo.toml b/colorizer/Cargo.toml new file mode 100644 index 0000000..9bcf2b5 --- /dev/null +++ b/colorizer/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "colorizer" +version = "0.1.0" +edition = "2024" + +[dependencies] +clipboard = "0.5.0" diff --git a/colorizer/src/core/mod.rs b/colorizer/src/core/mod.rs new file mode 100644 index 0000000..d1ded23 --- /dev/null +++ b/colorizer/src/core/mod.rs @@ -0,0 +1 @@ +pub mod ranged; diff --git a/colorizer/src/core/ranged/foreign_operations.rs b/colorizer/src/core/ranged/foreign_operations.rs new file mode 100644 index 0000000..54839a0 --- /dev/null +++ b/colorizer/src/core/ranged/foreign_operations.rs @@ -0,0 +1,78 @@ +use super::*; + +use std::{ + cmp::Ordering, + ops::{Add, Div, Mul, Sub}, +}; + +impl PartialEq + for RangedInt<{ LOW }, { HIGH }> +{ + fn eq(&self, other: &BaseNumber) -> bool { + self.0 == *other + } + + fn ne(&self, other: &BaseNumber) -> bool { + self.0 != *other + } +} + +impl PartialOrd + for RangedInt<{ LOW }, { HIGH }> +{ + fn partial_cmp(&self, other: &BaseNumber) -> Option { + self.0.partial_cmp(other) + } + + fn ge(&self, other: &BaseNumber) -> bool { + self.0 >= *other + } + + fn le(&self, other: &BaseNumber) -> bool { + self.0 <= *other + } + + fn gt(&self, other: &BaseNumber) -> bool { + self.0 > *other + } + + fn lt(&self, other: &BaseNumber) -> bool { + self.0 < *other + } +} + +impl Add + for RangedInt<{ LOW }, { HIGH }> +{ + type Output = BaseNumber; + fn add(self, rhs: BaseNumber) -> Self::Output { + self.0 + rhs + } +} + +impl Sub + for RangedInt<{ LOW }, { HIGH }> +{ + type Output = BaseNumber; + fn sub(self, rhs: BaseNumber) -> Self::Output { + self.0 - rhs + } +} + +impl Div + for RangedInt<{ LOW }, { HIGH }> +{ + type Output = BaseNumber; + fn div(self, rhs: BaseNumber) -> Self::Output { + self.0 / rhs + } +} + +impl Mul + for RangedInt<{ LOW }, { HIGH }> +{ + type Output = BaseNumber; + fn mul(self, rhs: BaseNumber) -> Self::Output { + self.0 * rhs + } +} diff --git a/colorizer/src/core/ranged/mod.rs b/colorizer/src/core/ranged/mod.rs new file mode 100644 index 0000000..a8fd853 --- /dev/null +++ b/colorizer/src/core/ranged/mod.rs @@ -0,0 +1,16 @@ +mod foreign_operations; +mod self_operations; + +pub type BaseNumber = i16; + +#[derive(Eq, Clone)] +pub struct RangedInt(BaseNumber); + +impl RangedInt<{ LOW }, { HIGH }> { + pub const LOW: BaseNumber = LOW; + pub const HIGH: BaseNumber = HIGH; + + pub fn new(number: BaseNumber) -> Self { + Self(number.min(Self::HIGH).max(Self::LOW)) + } +} diff --git a/colorizer/src/core/ranged/self_operations.rs b/colorizer/src/core/ranged/self_operations.rs new file mode 100644 index 0000000..54b7c80 --- /dev/null +++ b/colorizer/src/core/ranged/self_operations.rs @@ -0,0 +1,66 @@ +use super::*; + +use std::{ + cmp::Ordering, + ops::{Add, Div, Mul, Sub}, +}; + +impl PartialEq for RangedInt<{ LOW }, { HIGH }> { + fn eq(&self, other: &Self) -> bool { + self.0 == other.0 + } + + fn ne(&self, other: &Self) -> bool { + self.0 != other.0 + } +} + +impl PartialOrd for RangedInt<{ LOW }, { HIGH }> { + fn partial_cmp(&self, other: &Self) -> Option { + self.0.partial_cmp(&other.0) + } + + fn ge(&self, other: &Self) -> bool { + self.0 >= other.0 + } + + fn le(&self, other: &Self) -> bool { + self.0 <= other.0 + } + + fn gt(&self, other: &Self) -> bool { + self.0 > other.0 + } + + fn lt(&self, other: &Self) -> bool { + self.0 < other.0 + } +} + +impl Add for RangedInt<{ LOW }, { HIGH }> { + type Output = BaseNumber; + fn add(self, rhs: Self) -> Self::Output { + self.0 + rhs.0 + } +} + +impl Sub for RangedInt<{ LOW }, { HIGH }> { + type Output = BaseNumber; + fn sub(self, rhs: Self) -> Self::Output { + self.0 - rhs.0 + } +} + +impl Div for RangedInt<{ LOW }, { HIGH }> { + type Output = BaseNumber; + fn div(self, rhs: Self) -> Self::Output { + self.0 / rhs.0 + } +} + +impl Mul for RangedInt<{ LOW }, { HIGH }> { + type Output = BaseNumber; + fn mul(self, rhs: Self) -> Self::Output { + self.0 * rhs.0 + } +} diff --git a/colorizer/src/main.rs b/colorizer/src/main.rs new file mode 100644 index 0000000..dab1fdb --- /dev/null +++ b/colorizer/src/main.rs @@ -0,0 +1,20 @@ +use clipboard::ClipboardContext; +use clipboard::ClipboardProvider; + +pub mod core; +mod transmuter; + +#[cfg(test)] +#[path = "./test/transmuter.test.rs"] +mod test; + +fn example() { + let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap(); + println!("{:?}", ctx.get_contents()); + ctx.set_contents("some string".to_owned()).unwrap(); +} + +fn main() { + println!("Hello, world!"); + example(); +} diff --git a/colorizer/src/test/transmuter.test.rs b/colorizer/src/test/transmuter.test.rs new file mode 100644 index 0000000..f1b8928 --- /dev/null +++ b/colorizer/src/test/transmuter.test.rs @@ -0,0 +1,8 @@ +#[cfg(test)] +pub mod tests { + #[test] + fn test_success() { + let my_hello = "Hello world!"; + assert_eq!(my_hello, "Hello world!"); + } +} diff --git a/colorizer/src/transmuter/colors.rs b/colorizer/src/transmuter/colors.rs new file mode 100644 index 0000000..3c4d34a --- /dev/null +++ b/colorizer/src/transmuter/colors.rs @@ -0,0 +1,60 @@ +use std::convert::From; + +use crate::core::ranged::{BaseNumber, RangedInt}; + +type ColorIntensity = RangedInt<0, 255>; +struct RGB(ColorIntensity, ColorIntensity, ColorIntensity); +struct HSL(RangedInt<0, 360>, RangedInt<0, 100>, RangedInt<0, 100>); +struct HSV(RangedInt<0, 360>, RangedInt<0, 100>, RangedInt<0, 100>); + +pub struct Color(RGB); + +impl Color {} + +impl RGB { + fn new(r: u8, g: u8, b: u8) -> Self { + Self( + ColorIntensity::new(r as BaseNumber), + ColorIntensity::new(g as BaseNumber), + ColorIntensity::new(b as BaseNumber), + ) + } +} + +impl From for Color { + fn from(color: RGB) -> Self { + Self(color) + } +} + +impl From for Color { + fn from(color: HSL) -> Self { + Color(RGB::from(color)) + } +} + +impl From for RGB { + fn from(color: HSL) -> Self { + // No saturation + if color.1 == 0 { + let shade = color.2 / 100 * 255; + let intensity = ColorIntensity::new(shade); + return Self(intensity.clone(), intensity.clone(), intensity.clone()); + } + + let mut temp_1: i16 = 0; + + if color.2 < 50 { + // Low lum + temp_1 = color.2.clone() * (color.1 + 100); + } else { + // High lum + temp_1 = color.2.clone() + color.1.clone() - color.2.clone() * color.1.clone(); + } + + let temp_2: i16 = color.2 * 2 - temp_1; + let hue = (color.0.clone() / 360) * 100; + + Self::new(0, 0, 0) + } +} diff --git a/colorizer/src/transmuter/mod.rs b/colorizer/src/transmuter/mod.rs new file mode 100644 index 0000000..936df40 --- /dev/null +++ b/colorizer/src/transmuter/mod.rs @@ -0,0 +1,2 @@ +mod colors; +mod parsers; diff --git a/colorizer/src/transmuter/parsers.rs b/colorizer/src/transmuter/parsers.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/colorizer/src/transmuter/parsers.rs @@ -0,0 +1 @@ +