Skip to content

Commit

Permalink
Feat: remove duplicates (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
baseplate-admin authored May 22, 2024
1 parent ca545be commit 40ce2bf
Show file tree
Hide file tree
Showing 7 changed files with 1,051 additions and 909 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ path = "src/rust/lib.rs"
pyo3 = "0.21.2"
color-thief = "0.2"
image = "0.25.1"
itertools = "0.13.0"

[profile.release.package."*"]
codegen-units = 1
Expand Down
2 changes: 1 addition & 1 deletion examples/test_time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from python.modern_colorthief.modern_colorthief import get_color, get_palette
from modern_colorthief import get_color, get_palette
from fast_colorthief import get_dominant_color, get_palette as f_get_palette
import timeit
from colorthief import ColorThief
Expand Down
1,810 changes: 905 additions & 905 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use color_thief::ColorFormat;
use image::DynamicImage;
use itertools::Itertools;
use pyo3::prelude::*;

fn get_image_buffer(img: image::DynamicImage) -> (Vec<u8>, ColorFormat) {
Expand Down Expand Up @@ -66,9 +67,10 @@ fn get_palette(
)
.unwrap();

let color_vec = colors
let color_vec: Vec<(u8, u8, u8)> = colors
.iter()
.map(|color| (color.r, color.g, color.b))
.unique()
.collect();

Ok(color_vec)
Expand Down
Binary file added tests/kaiju_no_8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions tests/test_deduplication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import modern_colorthief
from pathlib import Path
import os

BASE_DIR = Path(__file__).resolve().parent

path = os.path.join(BASE_DIR, "kaiju_no_8.jpg")
TARGET = [
(166, 209, 209),
(102, 134, 121),
(147, 56, 48),
(117, 142, 144),
(70, 69, 62),
(184, 76, 59),
(9, 14, 11),
(200, 198, 192),
(105, 165, 156),
(100, 111, 112),
(63, 128, 116),
(137, 167, 154),
(187, 195, 191),
(232, 244, 243),
(29, 13, 10),
(87, 83, 77),
(142, 134, 120),
(194, 232, 236),
(170, 161, 120),
(216, 45, 20),
(67, 93, 84),
(228, 51, 19),
(63, 103, 113),
(196, 230, 212),
(96, 28, 21),
(102, 109, 91),
(194, 36, 21),
(55, 74, 78),
(66, 148, 157),
(154, 207, 188),
(36, 31, 18),
(103, 49, 32),
(42, 49, 44),
(204, 36, 20),
(212, 144, 142),
(226, 178, 170),
(176, 156, 92),
(170, 88, 85),
(167, 173, 158),
(55, 169, 155),
(40, 34, 32),
(19, 132, 117),
(24, 47, 41),
(171, 57, 54),
(140, 190, 171),
(140, 191, 191),
(184, 54, 37),
(143, 120, 79),
(96, 96, 93),
(17, 94, 82),
(186, 120, 107),
(116, 116, 144),
(65, 145, 142),
(102, 91, 74),
(105, 194, 192),
(188, 25, 19),
(212, 130, 122),
(138, 175, 174),
(181, 39, 37),
(104, 190, 176),
(71, 188, 176),
(168, 143, 106),
(52, 55, 49),
(226, 203, 194),
(7, 61, 50),
(117, 95, 72),
(196, 27, 21),
(100, 78, 50),
(201, 174, 149),
(164, 34, 30),
(41, 95, 85),
(60, 164, 132),
(180, 20, 20),
(183, 182, 149),
(118, 50, 46),
(58, 51, 33),
(148, 31, 20),
(28, 19, 28),
(52, 44, 46),
(230, 60, 28),
(107, 160, 129),
(231, 188, 188),
(76, 180, 188),
(228, 36, 18),
(113, 212, 204),
(106, 157, 111),
(143, 20, 16),
(204, 172, 128),
(152, 188, 120),
(132, 108, 60),
(172, 29, 24),
(60, 52, 50),
(158, 104, 98),
(111, 126, 88),
(116, 212, 212),
(59, 89, 57),
(160, 212, 228),
(206, 172, 168),
(185, 26, 28),
(85, 68, 64),
(52, 116, 76),
(181, 12, 12),
(108, 148, 172),
(212, 28, 21),
(64, 116, 88),
(8, 40, 44),
(116, 124, 68),
(20, 84, 44),
(180, 28, 19),
(228, 60, 44),
(180, 164, 140),
(185, 20, 4),
(180, 20, 12),
(184, 20, 20),
]


def test_deduplication():
x = modern_colorthief.get_palette(path, 255)

assert x == TARGET

0 comments on commit 40ce2bf

Please sign in to comment.