feat: base colorizer project
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
1
colorizer/.gitignore
vendored
Normal file
1
colorizer/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
129
colorizer/Cargo.lock
generated
Normal file
129
colorizer/Cargo.lock
generated
Normal file
@@ -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",
|
||||||
|
]
|
||||||
7
colorizer/Cargo.toml
Normal file
7
colorizer/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "colorizer"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clipboard = "0.5.0"
|
||||||
1
colorizer/src/core/mod.rs
Normal file
1
colorizer/src/core/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod ranged;
|
||||||
78
colorizer/src/core/ranged/foreign_operations.rs
Normal file
78
colorizer/src/core/ranged/foreign_operations.rs
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
cmp::Ordering,
|
||||||
|
ops::{Add, Div, Mul, Sub},
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<const LOW: BaseNumber, const HIGH: BaseNumber> PartialEq<BaseNumber>
|
||||||
|
for RangedInt<{ LOW }, { HIGH }>
|
||||||
|
{
|
||||||
|
fn eq(&self, other: &BaseNumber) -> bool {
|
||||||
|
self.0 == *other
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ne(&self, other: &BaseNumber) -> bool {
|
||||||
|
self.0 != *other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const LOW: BaseNumber, const HIGH: BaseNumber> PartialOrd<BaseNumber>
|
||||||
|
for RangedInt<{ LOW }, { HIGH }>
|
||||||
|
{
|
||||||
|
fn partial_cmp(&self, other: &BaseNumber) -> Option<Ordering> {
|
||||||
|
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<const LOW: BaseNumber, const HIGH: BaseNumber> Add<BaseNumber>
|
||||||
|
for RangedInt<{ LOW }, { HIGH }>
|
||||||
|
{
|
||||||
|
type Output = BaseNumber;
|
||||||
|
fn add(self, rhs: BaseNumber) -> Self::Output {
|
||||||
|
self.0 + rhs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Sub<BaseNumber>
|
||||||
|
for RangedInt<{ LOW }, { HIGH }>
|
||||||
|
{
|
||||||
|
type Output = BaseNumber;
|
||||||
|
fn sub(self, rhs: BaseNumber) -> Self::Output {
|
||||||
|
self.0 - rhs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Div<BaseNumber>
|
||||||
|
for RangedInt<{ LOW }, { HIGH }>
|
||||||
|
{
|
||||||
|
type Output = BaseNumber;
|
||||||
|
fn div(self, rhs: BaseNumber) -> Self::Output {
|
||||||
|
self.0 / rhs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Mul<BaseNumber>
|
||||||
|
for RangedInt<{ LOW }, { HIGH }>
|
||||||
|
{
|
||||||
|
type Output = BaseNumber;
|
||||||
|
fn mul(self, rhs: BaseNumber) -> Self::Output {
|
||||||
|
self.0 * rhs
|
||||||
|
}
|
||||||
|
}
|
||||||
16
colorizer/src/core/ranged/mod.rs
Normal file
16
colorizer/src/core/ranged/mod.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
mod foreign_operations;
|
||||||
|
mod self_operations;
|
||||||
|
|
||||||
|
pub type BaseNumber = i16;
|
||||||
|
|
||||||
|
#[derive(Eq, Clone)]
|
||||||
|
pub struct RangedInt<const LOW: BaseNumber, const HIGH: BaseNumber>(BaseNumber);
|
||||||
|
|
||||||
|
impl<const LOW: BaseNumber, const HIGH: BaseNumber> 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
66
colorizer/src/core/ranged/self_operations.rs
Normal file
66
colorizer/src/core/ranged/self_operations.rs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
cmp::Ordering,
|
||||||
|
ops::{Add, Div, Mul, Sub},
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<const LOW: BaseNumber, const HIGH: BaseNumber> 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<const LOW: BaseNumber, const HIGH: BaseNumber> PartialOrd for RangedInt<{ LOW }, { HIGH }> {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
|
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<const LOW: BaseNumber, const HIGH: BaseNumber> Add for RangedInt<{ LOW }, { HIGH }> {
|
||||||
|
type Output = BaseNumber;
|
||||||
|
fn add(self, rhs: Self) -> Self::Output {
|
||||||
|
self.0 + rhs.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Sub for RangedInt<{ LOW }, { HIGH }> {
|
||||||
|
type Output = BaseNumber;
|
||||||
|
fn sub(self, rhs: Self) -> Self::Output {
|
||||||
|
self.0 - rhs.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Div for RangedInt<{ LOW }, { HIGH }> {
|
||||||
|
type Output = BaseNumber;
|
||||||
|
fn div(self, rhs: Self) -> Self::Output {
|
||||||
|
self.0 / rhs.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Mul for RangedInt<{ LOW }, { HIGH }> {
|
||||||
|
type Output = BaseNumber;
|
||||||
|
fn mul(self, rhs: Self) -> Self::Output {
|
||||||
|
self.0 * rhs.0
|
||||||
|
}
|
||||||
|
}
|
||||||
20
colorizer/src/main.rs
Normal file
20
colorizer/src/main.rs
Normal file
@@ -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();
|
||||||
|
}
|
||||||
8
colorizer/src/test/transmuter.test.rs
Normal file
8
colorizer/src/test/transmuter.test.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#[cfg(test)]
|
||||||
|
pub mod tests {
|
||||||
|
#[test]
|
||||||
|
fn test_success() {
|
||||||
|
let my_hello = "Hello world!";
|
||||||
|
assert_eq!(my_hello, "Hello world!");
|
||||||
|
}
|
||||||
|
}
|
||||||
60
colorizer/src/transmuter/colors.rs
Normal file
60
colorizer/src/transmuter/colors.rs
Normal file
@@ -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<RGB> for Color {
|
||||||
|
fn from(color: RGB) -> Self {
|
||||||
|
Self(color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<HSL> for Color {
|
||||||
|
fn from(color: HSL) -> Self {
|
||||||
|
Color(RGB::from(color))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<HSL> 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
2
colorizer/src/transmuter/mod.rs
Normal file
2
colorizer/src/transmuter/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
mod colors;
|
||||||
|
mod parsers;
|
||||||
1
colorizer/src/transmuter/parsers.rs
Normal file
1
colorizer/src/transmuter/parsers.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
Reference in New Issue
Block a user