color-match-tools 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. color_match_tools-3.0.0/LICENSE +21 -0
  2. color_match_tools-3.0.0/PKG-INFO +654 -0
  3. color_match_tools-3.0.0/README.md +598 -0
  4. color_match_tools-3.0.0/color_match_tools.egg-info/PKG-INFO +654 -0
  5. color_match_tools-3.0.0/color_match_tools.egg-info/SOURCES.txt +33 -0
  6. color_match_tools-3.0.0/color_match_tools.egg-info/dependency_links.txt +1 -0
  7. color_match_tools-3.0.0/color_match_tools.egg-info/entry_points.txt +2 -0
  8. color_match_tools-3.0.0/color_match_tools.egg-info/requires.txt +8 -0
  9. color_match_tools-3.0.0/color_match_tools.egg-info/top_level.txt +1 -0
  10. color_match_tools-3.0.0/color_tools/__init__.py +176 -0
  11. color_match_tools-3.0.0/color_tools/__main__.py +12 -0
  12. color_match_tools-3.0.0/color_tools/cli.py +526 -0
  13. color_match_tools-3.0.0/color_tools/config.py +73 -0
  14. color_match_tools-3.0.0/color_tools/constants.py +249 -0
  15. color_match_tools-3.0.0/color_tools/conversions.py +392 -0
  16. color_match_tools-3.0.0/color_tools/data/colors.json +3386 -0
  17. color_match_tools-3.0.0/color_tools/data/filaments.json +4263 -0
  18. color_match_tools-3.0.0/color_tools/data/maker_synonyms.json +4 -0
  19. color_match_tools-3.0.0/color_tools/data/user-colors.json +1 -0
  20. color_match_tools-3.0.0/color_tools/data/user-filaments.json +1 -0
  21. color_match_tools-3.0.0/color_tools/data/user-synonyms.json +1 -0
  22. color_match_tools-3.0.0/color_tools/distance.py +375 -0
  23. color_match_tools-3.0.0/color_tools/gamut.py +169 -0
  24. color_match_tools-3.0.0/color_tools/palette.py +826 -0
  25. color_match_tools-3.0.0/color_tools/validation.py +117 -0
  26. color_match_tools-3.0.0/pyproject.toml +58 -0
  27. color_match_tools-3.0.0/setup.cfg +4 -0
  28. color_match_tools-3.0.0/tests/test_api.py +44 -0
  29. color_match_tools-3.0.0/tests/test_config.py +106 -0
  30. color_match_tools-3.0.0/tests/test_constants.py +130 -0
  31. color_match_tools-3.0.0/tests/test_conversions.py +321 -0
  32. color_match_tools-3.0.0/tests/test_distance.py +271 -0
  33. color_match_tools-3.0.0/tests/test_gamut.py +134 -0
  34. color_match_tools-3.0.0/tests/test_palette.py +313 -0
  35. color_match_tools-3.0.0/tests/test_synonyms.py +43 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 David Terracino
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,654 @@
1
+ Metadata-Version: 2.4
2
+ Name: color-match-tools
3
+ Version: 3.0.0
4
+ Summary: Comprehensive color science library for accurate color space conversions, perceptual color distance metrics (Delta E), and color matching with CSS and 3D printing filament databases
5
+ Author-email: David Terracino <dterracino@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 David Terracino
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/dterracino/color_tools
29
+ Project-URL: Repository, https://github.com/dterracino/color_tools
30
+ Project-URL: Issues, https://github.com/dterracino/color_tools/issues
31
+ Project-URL: Changelog, https://github.com/dterracino/color_tools/blob/main/CHANGELOG.md
32
+ Project-URL: Documentation, https://github.com/dterracino/color_tools/blob/main/README.md
33
+ Keywords: color,color-science,delta-e,color-conversion,color-matching,rgb,lab,lch,hsl,xyz,ciede2000,cie94,cie76,gamut,srgb,3d-printing,filament
34
+ Classifier: Development Status :: 4 - Beta
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: Intended Audience :: Science/Research
37
+ Classifier: Topic :: Multimedia :: Graphics
38
+ Classifier: Topic :: Scientific/Engineering
39
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
40
+ Classifier: License :: OSI Approved :: MIT License
41
+ Classifier: Programming Language :: Python :: 3
42
+ Classifier: Programming Language :: Python :: 3.10
43
+ Classifier: Programming Language :: Python :: 3.11
44
+ Classifier: Programming Language :: Python :: 3.12
45
+ Classifier: Operating System :: OS Independent
46
+ Requires-Python: >=3.10
47
+ Description-Content-Type: text/markdown
48
+ License-File: LICENSE
49
+ Provides-Extra: dev
50
+ Requires-Dist: pyright>=1.1.0; extra == "dev"
51
+ Requires-Dist: build>=1.0.0; extra == "dev"
52
+ Requires-Dist: twine>=4.0.0; extra == "dev"
53
+ Provides-Extra: test
54
+ Requires-Dist: fuzzywuzzy>=0.18.0; extra == "test"
55
+ Dynamic: license-file
56
+
57
+ # Color Tools
58
+
59
+ A comprehensive Python library for color science operations, color space conversions, and color matching. This tool provides perceptually accurate color distance calculations, gamut checking, and extensive databases of CSS colors and 3D printing filament colors.
60
+
61
+ **Version:** 3.0.0 | [Changelog](CHANGELOG.md)
62
+
63
+ ## Features
64
+
65
+ - **Multiple Color Spaces**: RGB, HSL, LAB, LCH with accurate conversions
66
+ - **Perceptual Color Distance**: Delta E formulas (CIE76, CIE94, CIEDE2000, CMC)
67
+ - **Color Databases**:
68
+ - Complete CSS color names with hex/RGB/HSL/LAB/LCH values
69
+ - Extensive 3D printing filament database with manufacturer info
70
+ - Maker synonym support for flexible filament searches
71
+ - **Gamut Checking**: Verify if colors are representable in sRGB
72
+ - **Thread-Safe**: Configurable runtime settings per thread
73
+ - **Color Science Integrity**: Built-in verification of color constants
74
+
75
+ ## Installation
76
+
77
+ **Requirements:** Python 3.10+
78
+
79
+ ### For Development or Direct Use
80
+
81
+ Clone this repository and install in development mode:
82
+
83
+ ```bash
84
+ git clone <repository-url>
85
+ cd color_tools
86
+ pip install -e .
87
+ ```
88
+
89
+ This installs the package in "editable" mode, allowing you to modify the code while using it.
90
+
91
+ ### For Library Use Only
92
+
93
+ If you just want to use it as a library without the CLI:
94
+
95
+ ```bash
96
+ git clone <repository-url>
97
+ cd color_tools
98
+ pip install .
99
+ ```
100
+
101
+ ### Dependencies
102
+
103
+ The core module uses **only Python standard library** - no external dependencies required for basic functionality.
104
+
105
+ **Optional dependency**: The `validation` module requires `fuzzywuzzy` for fuzzy color name matching:
106
+
107
+ ```bash
108
+ pip install fuzzywuzzy
109
+ ```
110
+
111
+ ## Usage
112
+
113
+ Color Tools can be used in three ways:
114
+
115
+ 1. **As a Python Library**: Import functions directly in your Python code
116
+ 2. **As a CLI Tool**: Use `python -m color_tools` from the repository
117
+ 3. **As an Installed Command**: Use `color-tools` command after `pip install`
118
+
119
+ ### Library Usage
120
+
121
+ Import and use color_tools functions in your Python code:
122
+
123
+ ```python
124
+ from color_tools import rgb_to_lab, delta_e_2000, Palette, FilamentPalette
125
+
126
+ # Convert RGB to LAB color space
127
+ lab = rgb_to_lab((255, 128, 64))
128
+ print(f"LAB: {lab}") # LAB: (67.05, 42.83, 74.02)
129
+
130
+ # Calculate color difference between two LAB colors
131
+ color1 = (50, 25, -30)
132
+ color2 = (55, 20, -25)
133
+ difference = delta_e_2000(color1, color2)
134
+ print(f"Delta E: {difference}")
135
+
136
+ # Load CSS color palette and find nearest color
137
+ palette = Palette.load_default()
138
+ nearest, distance = palette.nearest_color(lab, space="lab")
139
+ print(f"Nearest CSS color: {nearest.name} (distance: {distance:.2f})")
140
+
141
+ # Load filament palette and search
142
+ filament_palette = FilamentPalette.load_default()
143
+ filament, distance = filament_palette.nearest_filament((180, 100, 200))
144
+ print(f"Nearest filament: {filament.maker} {filament.type} - {filament.color}")
145
+
146
+ # Filter filaments by criteria (supports maker synonyms)
147
+ pla_filaments = filament_palette.filter(type_name="PLA", maker="Bambu") # "Bambu" finds "Bambu Lab"
148
+ print(f"Found {len(pla_filaments)} Bambu Lab PLA filaments")
149
+ ```
150
+
151
+ **Common Library Functions:**
152
+
153
+ **Color Conversions:**
154
+
155
+ - `rgb_to_lab()`, `lab_to_rgb()` - RGB ↔ LAB conversion (most common)
156
+ - `rgb_to_lch()`, `lch_to_rgb()` - RGB ↔ LCH conversion
157
+ - `rgb_to_hsl()`, `hsl_to_rgb()` - RGB ↔ HSL conversion (0-360, 0-100, 0-100 range)
158
+ - `rgb_to_winhsl()` - RGB → Windows HSL (0-240, 0-240, 0-240 range)
159
+ - `hex_to_rgb()`, `rgb_to_hex()` - Hex ↔ RGB conversion
160
+ - `lab_to_lch()`, `lch_to_lab()` - LAB ↔ LCH conversion
161
+ - `rgb_to_xyz()`, `xyz_to_rgb()` - RGB ↔ XYZ conversion (CIE standard)
162
+ - `xyz_to_lab()`, `lab_to_xyz()` - XYZ ↔ LAB conversion (for advanced use)
163
+
164
+ **Distance Metrics:**
165
+
166
+ - `delta_e_2000()` - CIEDE2000 (recommended)
167
+ - `delta_e_94()` - CIE94
168
+ - `delta_e_76()` - CIE76
169
+ - `delta_e_cmc()` - CMC color difference
170
+ - `euclidean()` - Simple Euclidean distance
171
+
172
+ **Gamut Operations:**
173
+
174
+ - `is_in_srgb_gamut()` - Check if LAB color is displayable
175
+ - `find_nearest_in_gamut()` - Find closest displayable color
176
+ - `clamp_to_gamut()` - Force color into sRGB gamut
177
+
178
+ **Palettes:**
179
+
180
+ - `Palette.load_default()` - Load CSS color database
181
+ - `FilamentPalette.load_default()` - Load filament database
182
+ - `palette.nearest_color()` - Find nearest color match
183
+ - `palette.find_by_name()` - Look up color by name
184
+ - `palette.find_by_rgb()` - Look up by exact RGB value
185
+ - `palette.find_by_lab()` - Look up by LAB value (with rounding)
186
+ - `palette.find_by_lch()` - Look up by LCH value (with rounding)
187
+ - `filament_palette.nearest_filament()` - Find nearest filament
188
+ - `filament_palette.filter()` - Filter by maker, type, finish, color (supports maker synonyms)
189
+ - `filament_palette.find_by_maker()` - Get all filaments from a maker (supports synonyms)
190
+ - `filament_palette.find_by_type()` - Get all filaments of a type
191
+
192
+ **Configuration:**
193
+
194
+ - `set_dual_color_mode()` - Set how dual-color filaments are handled
195
+ - `get_dual_color_mode()` - Get current dual-color mode
196
+
197
+ **Data Structures:**
198
+
199
+ The library uses immutable dataclasses for color and filament records:
200
+
201
+ ```python
202
+ # ColorRecord - returned by Palette methods
203
+ color = palette.find_by_name("coral")
204
+ print(color.name) # "coral"
205
+ print(color.hex) # "#FF7F50"
206
+ print(color.rgb) # (255, 127, 80)
207
+ print(color.hsl) # (16.1, 100.0, 65.7)
208
+ print(color.lab) # (67.3, 45.4, 47.5)
209
+ print(color.lch) # (67.3, 65.7, 46.3)
210
+
211
+ # FilamentRecord - returned by FilamentPalette methods
212
+ filament, distance = filament_palette.nearest_filament((255, 0, 0))
213
+ print(filament.maker) # e.g., "Polymaker"
214
+ print(filament.type) # e.g., "PLA"
215
+ print(filament.finish) # e.g., "PolyMax"
216
+ print(filament.color) # e.g., "Red"
217
+ print(filament.hex) # e.g., "#ED2F20"
218
+ print(filament.rgb) # e.g., (237, 47, 32)
219
+ print(filament.lab) # e.g., (48.2, 68.1, 54.3) - computed on demand
220
+ print(filament.lch) # e.g., (48.2, 87.4, 38.6) - computed on demand
221
+ ```
222
+
223
+ ### CLI Usage
224
+
225
+ The CLI provides three main commands: `color`, `filament`, and `convert`.
226
+
227
+ ### Color Command
228
+
229
+ Search and query the CSS color database.
230
+
231
+ #### Find Color by Name
232
+
233
+ ```bash
234
+ python -m color_tools color --name "coral"
235
+ python -m color_tools color --name "steelblue"
236
+ ```
237
+
238
+ #### Find Nearest Color by Value
239
+
240
+ ```bash
241
+ # Find nearest CSS color to RGB(128, 64, 200) using CIEDE2000
242
+ python -m color_tools color --nearest --value 128 64 200 --space rgb
243
+
244
+ # Find nearest using LAB values with CIE94 metric
245
+ python -m color_tools color --nearest --value 50 25 -30 --space lab --metric de94
246
+
247
+ # Find nearest using HSL values
248
+ python -m color_tools color --nearest --value 16.1 100 65.7 --space hsl
249
+
250
+ # Find nearest using LCH values (perceptually uniform cylindrical space)
251
+ python -m color_tools color --nearest --value 67.3 65.7 46.3 --space lch
252
+
253
+ # Use CMC color difference formula
254
+ python -m color_tools color --nearest --value 70 15 45 --space lab --metric cmc --cmc-l 2.0 --cmc-c 1.0
255
+ ```
256
+
257
+ **Color Command Arguments:**
258
+
259
+ - `--name NAME`: Find exact color by name (case-insensitive)
260
+ - `--nearest`: Find the closest color to specified value
261
+ - `--value V1 V2 V3`: Color value tuple (format depends on `--space`)
262
+ - `--space {rgb,hsl,lab,lch}`: Color space of input value (default: lab)
263
+ - `--metric {euclidean,de76,de94,de2000,cmc,cmc21,cmc11}`: Distance metric (default: de2000)
264
+ - `--cmc-l FLOAT`: CMC lightness parameter (default: 2.0)
265
+ - `--cmc-c FLOAT`: CMC chroma parameter (default: 1.0)
266
+
267
+ ### Filament Command
268
+
269
+ Search and query the 3D printing filament database.
270
+
271
+ #### Find Nearest Filament Color
272
+
273
+ ```bash
274
+ # Find nearest filament to red color
275
+ python -m color_tools filament --nearest --value 255 0 0
276
+
277
+ # Use different color distance metrics
278
+ python -m color_tools filament --nearest --value 100 150 200 --metric cmc
279
+ python -m color_tools filament --nearest --value 100 150 200 --metric de94
280
+
281
+ # Adjust CMC parameters for different perceptual weighting
282
+ python -m color_tools filament --nearest --value 100 150 200 --metric cmc --cmc-l 1.0 --cmc-c 1.0
283
+ ```
284
+
285
+ #### Handle Dual-Color Filaments
286
+
287
+ Some filaments have two colors (e.g., "#333333-#666666"). Control how these are handled:
288
+
289
+ ```bash
290
+ # Use first color (default)
291
+ python -m color_tools filament --nearest --value 255 0 0 --dual-color-mode first
292
+
293
+ # Use second color
294
+ python -m color_tools filament --nearest --value 255 0 0 --dual-color-mode last
295
+
296
+ # Perceptually blend both colors in LAB space
297
+ python -m color_tools filament --nearest --value 255 0 0 --dual-color-mode mix
298
+ ```
299
+
300
+ #### List and Filter Filaments
301
+
302
+ ```bash
303
+ # List all manufacturers
304
+ python -m color_tools filament --list-makers
305
+
306
+ # List all filament types
307
+ python -m color_tools filament --list-types
308
+
309
+ # List all finishes
310
+ python -m color_tools filament --list-finishes
311
+
312
+ # Filter by specific criteria (supports maker synonyms)
313
+ python -m color_tools filament --maker "Bambu" --type "PLA" # "Bambu" finds "Bambu Lab"
314
+ python -m color_tools filament --finish "Matte" --color "Black"
315
+
316
+ # Filter by multiple makers (can mix canonical names and synonyms)
317
+ python -m color_tools filament --maker "Bambu" "Polymaker"
318
+
319
+ # Filter by multiple types
320
+ python -m color_tools filament --type PLA "PLA+" PETG
321
+
322
+ # Filter by multiple finishes
323
+ python -m color_tools filament --finish Basic "Silk+" Matte
324
+ ```
325
+
326
+ **Filament Command Arguments:**
327
+
328
+ **Nearest Neighbor Search:**
329
+
330
+ - `--nearest`: Find nearest filament to RGB color
331
+ - `--value R G B`: RGB color value (0-255 for each component)
332
+ - `--metric {euclidean,de76,de94,de2000,cmc}`: Distance metric (default: de2000)
333
+ - `--cmc-l FLOAT`: CMC lightness parameter (default: 2.0)
334
+ - `--cmc-c FLOAT`: CMC chroma parameter (default: 1.0)
335
+ - `--dual-color-mode {first,last,mix}`: Handle dual-color filaments (default: first)
336
+
337
+ **Filtering and Listing:**
338
+
339
+ - `--list-makers`: List all filament manufacturers
340
+ - `--list-types`: List all filament types (PLA, PETG, etc.)
341
+ - `--list-finishes`: List all finish types (Matte, Glossy, etc.)
342
+ - `--maker NAME [NAME ...]`: Filter by one or more manufacturers (e.g., --maker "Bambu" "Polymaker"). Supports maker synonyms (e.g., "Bambu" finds "Bambu Lab").
343
+ - `--type NAME [NAME ...]`: Filter by one or more filament types (e.g., --type PLA "PLA+")
344
+ - `--finish NAME [NAME ...]`: Filter by one or more finish types (e.g., --finish Basic "Silk+")
345
+ - `--color NAME`: Filter by color name
346
+
347
+ **Note:** When any filter argument (`--maker`, `--type`, `--finish`, `--color`) is provided, the command displays matching filaments.
348
+
349
+ ### Convert Command
350
+
351
+ Convert between color spaces and check gamut constraints.
352
+
353
+ #### Color Space Conversions
354
+
355
+ ```bash
356
+ # Convert RGB to LAB
357
+ python -m color_tools convert --from rgb --to lab --value 255 128 0
358
+
359
+ # Convert LAB to LCH (cylindrical LAB)
360
+ python -m color_tools convert --from lab --to lch --value 50 25 -30
361
+
362
+ # Convert LCH back to RGB
363
+ python -m color_tools convert --from lch --to rgb --value 50 33.54 -50.19
364
+ ```
365
+
366
+ #### Gamut Checking
367
+
368
+ ```bash
369
+ # Check if LAB color is representable in sRGB
370
+ python -m color_tools convert --check-gamut --value 50 100 50
371
+
372
+ # Check LCH color gamut
373
+ python -m color_tools convert --check-gamut --from lch --value 70 80 120
374
+ ```
375
+
376
+ **Convert Command Arguments:**
377
+
378
+ - `--from {rgb,hsl,lab,lch}`: Source color space
379
+ - `--to {rgb,hsl,lab,lch}`: Target color space
380
+ - `--value V1 V2 V3`: Color value tuple
381
+ - `--check-gamut`: Check if LAB/LCH color is in sRGB gamut
382
+
383
+ ### Global Arguments
384
+
385
+ These arguments work with all commands:
386
+
387
+ - `--json DIR`: Path to directory containing all JSON data files (colors.json, filaments.json, maker_synonyms.json). Must be a directory, not a file. Default: uses package data directory
388
+ - `--verify-constants`: Verify integrity of color science constants before proceeding
389
+ - `--verify-data`: Verify integrity of core data files before proceeding
390
+ - `--verify-all`: Verify integrity of both constants and data files before proceeding
391
+ - `--version`: Show version number and exit
392
+
393
+ ## Color Spaces
394
+
395
+ ### RGB
396
+
397
+ Standard 8-bit RGB values (0-255 for each component).
398
+
399
+ ### HSL
400
+
401
+ - **H** (Hue): 0-360 degrees
402
+ - **S** (Saturation): 0-100%
403
+ - **L** (Lightness): 0-100%
404
+
405
+ ### LAB (CIELAB)
406
+
407
+ Perceptually uniform color space:
408
+
409
+ - **L*** (Lightness): 0-100
410
+ - **a*** (Green-Red): typically -100 to +100
411
+ - **b*** (Blue-Yellow): typically -100 to +100
412
+
413
+ ### LCH
414
+
415
+ Cylindrical representation of LAB:
416
+
417
+ - **L*** (Lightness): 0-100
418
+ - **C*** (Chroma): 0+ (color intensity)
419
+ - **h°** (Hue): 0-360 degrees
420
+
421
+ **LCH is ideal for user interfaces** because:
422
+
423
+ - Hue can be adjusted independently (0-360°)
424
+ - Chroma controls saturation in a perceptually uniform way
425
+ - Much more intuitive than HSL for color manipulation
426
+ - Perfect for color picker wheels and gradients
427
+
428
+ ## Distance Metrics
429
+
430
+ ### Delta E Formulas
431
+
432
+ 1. **CIE76** (`de76`/`euclidean`): Simple Euclidean distance in LAB space
433
+ 2. **CIE94** (`de94`): Improved perceptual uniformity over CIE76
434
+ 3. **CIEDE2000** (`de2000`): Current gold standard, handles all edge cases
435
+ 4. **CMC** (`cmc`): Textile industry standard with configurable lightness/chroma weights
436
+
437
+ **Recommended**: Use `de2000` for most applications as it provides the best perceptual uniformity.
438
+
439
+ ### CMC Parameters
440
+
441
+ - **CMC(2:1)** (`cmc21`): Acceptability threshold
442
+ - **CMC(1:1)** (`cmc11`): Perceptibility threshold
443
+ - **Custom**: Use `--cmc-l` and `--cmc-c` for specific weighting
444
+
445
+ ## Examples
446
+
447
+ ### Find Similar Filament Colors
448
+
449
+ ```bash
450
+ # I have RGB(180, 100, 200) and want to find matching filaments
451
+ python -m color_tools filament --nearest --value 180 100 200
452
+
453
+ # Use CMC color difference (textile industry standard)
454
+ python -m color_tools filament --nearest --value 180 100 200 --metric cmc
455
+
456
+ # Use different distance metric
457
+ python -m color_tools filament --nearest --value 180 100 200 --metric de94
458
+ ```
459
+
460
+ ### Color Space Analysis
461
+
462
+ ```bash
463
+ # Convert my RGB color to LAB for analysis
464
+ python -m color_tools convert --from rgb --to lab --value 180 100 200
465
+
466
+ # Convert HSL to RGB
467
+ python -m color_tools convert --from hsl --to rgb --value 16.1 100 65.7
468
+
469
+ # Convert LAB to LCH for hue-based analysis
470
+ python -m color_tools convert --from lab --to lch --value 65.2 25.8 -15.4
471
+
472
+ # Convert LCH back to RGB
473
+ python -m color_tools convert --from lch --to rgb --value 65.2 30.1 328.3
474
+
475
+ # Check if a highly saturated LAB color can be displayed
476
+ python -m color_tools convert --check-gamut --value 50 80 60
477
+
478
+ # Find the CSS color name closest to my LAB measurement
479
+ python -m color_tools color --nearest --value 65.2 25.8 -15.4 --space lab
480
+
481
+ # Find nearest color using LCH (perceptually uniform cylindrical space)
482
+ python -m color_tools color --nearest --value 67.3 65.7 46.3 --space lch
483
+ ```
484
+
485
+ ### Batch Operations
486
+
487
+ ```bash
488
+ # Find all matte black filaments
489
+ python -m color_tools filament --finish "Matte" --color "Black"
490
+
491
+ # Find filaments with multiple finish types
492
+ python -m color_tools filament --finish Basic Matte "Silk+"
493
+
494
+ # Search across multiple manufacturers and types
495
+ python -m color_tools filament --maker "Bambu Lab" "Sunlu" --type PLA PETG
496
+
497
+ # List all available filament types from a specific maker
498
+ python -m color_tools filament --maker "Polymaker" | grep -o 'type: [^,]*' | sort -u
499
+ ```
500
+
501
+ ## Data Files
502
+
503
+ The data is organized into three separate JSON files in the `data/` directory:
504
+
505
+ ### colors.json - CSS Color Database
506
+
507
+ Array of color objects with complete color space representations:
508
+
509
+ ```json
510
+ [
511
+ {
512
+ "name": "coral",
513
+ "hex": "#FF7F50",
514
+ "rgb": [255, 127, 80],
515
+ "hsl": [16.1, 100.0, 65.7],
516
+ "lab": [67.30, 45.35, 47.49],
517
+ "lch": [67.30, 65.67, 46.3]
518
+ }
519
+ ]
520
+ ```
521
+
522
+ ### filaments.json - 3D Printing Filament Database
523
+
524
+ Array of filament objects with manufacturer info and color data:
525
+
526
+ ```json
527
+ [
528
+ {
529
+ "maker": "Bambu Lab",
530
+ "type": "PLA",
531
+ "finish": "Basic",
532
+ "color": "Black",
533
+ "hex": "#000000",
534
+ "td_value": null
535
+ }
536
+ ]
537
+ ```
538
+
539
+ ### maker_synonyms.json - Maker Name Synonyms
540
+
541
+ Mapping of canonical maker names to common synonyms/abbreviations:
542
+
543
+ ```json
544
+ {
545
+ "Bambu Lab": ["Bambu", "BLL"],
546
+ "Paramount 3D": ["Paramount", "Paramount3D"]
547
+ }
548
+ ```
549
+
550
+ **Synonym Support:** Filament searches automatically support maker synonyms. For example, searching for "Bambu" will find all "Bambu Lab" filaments.
551
+
552
+ ### User Data Files (Optional Extensions)
553
+
554
+ You can extend the core databases with your own custom data by creating optional user files in the same directory as the core data files:
555
+
556
+ - **user-colors.json** - Add custom colors (same format as colors.json)
557
+ - **user-filaments.json** - Add custom filaments (same format as filaments.json)
558
+ - **user-synonyms.json** - Add or extend maker synonyms (same format as maker_synonyms.json)
559
+
560
+ User data is automatically loaded and merged with core data. User files are optional and ignored if they don't exist. These files are **not** verified for integrity - only core data files are protected by SHA-256 hashes.
561
+
562
+ **Example user-colors.json:**
563
+
564
+ ```json
565
+ [
566
+ {
567
+ "name": "myCustomPurple",
568
+ "hex": "#9B59B6",
569
+ "rgb": [155, 89, 182],
570
+ "hsl": [283.1, 39.0, 53.1],
571
+ "lab": [48.5, 45.7, -40.2],
572
+ "lch": [48.5, 60.8, 318.6]
573
+ }
574
+ ]
575
+ ```
576
+
577
+ **Note:** Users are responsible for avoiding duplicate entries between core and user data files.
578
+
579
+ ### Data Integrity Verification
580
+
581
+ Core data files are protected with SHA-256 hashes to ensure integrity:
582
+
583
+ ```bash
584
+ # Verify data files only
585
+ python -m color_tools --verify-data
586
+
587
+ # Verify color science constants only
588
+ python -m color_tools --verify-constants
589
+
590
+ # Verify both constants and data files
591
+ python -m color_tools --verify-all
592
+ ```
593
+
594
+ User data files are not verified - you have full control over their contents.
595
+
596
+ ## Technical Notes
597
+
598
+ ### Color Science Constants
599
+
600
+ The tool includes comprehensive color science constants from international standards:
601
+
602
+ - CIE illuminants and observers
603
+ - sRGB transformation matrices
604
+ - Gamma correction parameters
605
+ - Delta E formula coefficients
606
+
607
+ All constants include integrity verification via SHA-256 hashing.
608
+
609
+ ### Thread Safety
610
+
611
+ Runtime configuration (like dual-color mode) uses `threading.local()` for thread-safe operation in multi-threaded applications.
612
+
613
+ ### Gamut Handling
614
+
615
+ The tool can detect when LAB colors fall outside the sRGB gamut and automatically find the nearest representable color by reducing chroma while preserving hue and lightness.
616
+
617
+ ## Error Handling
618
+
619
+ Common errors and solutions:
620
+
621
+ - **"Color not found"**: Check spelling and case of color names
622
+ - **"No filaments match criteria"**: Verify manufacturer/type names with `--list-makers` and `--list-types`
623
+ - **"Unknown metric"**: Use one of the supported metrics: euclidean, de76, de94, de2000, cmc
624
+ - **Out of gamut warnings**: Use `--check-gamut` to verify color representability
625
+
626
+ ## Performance
627
+
628
+ The tool uses indexed lookups for fast color matching:
629
+
630
+ - Color names: O(1) hash lookup
631
+ - RGB values: O(1) exact match
632
+ - Nearest neighbor: O(n) with optimized distance calculations
633
+
634
+ For large datasets, consider filtering by manufacturer or type before performing nearest neighbor searches.
635
+
636
+ ## Contributing
637
+
638
+ ### Constants Integrity
639
+
640
+ **CRITICAL**: The color science constants in `constants.py` should **NEVER** be modified. They represent fundamental values from international standards (CIE, sRGB specification) and changing them would break color accuracy.
641
+
642
+ To verify the constants haven't been tampered with:
643
+
644
+ ```bash
645
+ python -m color_tools --verify-constants
646
+ ```
647
+
648
+ **If constants verification fails**, this indicates either:
649
+
650
+ 1. **Accidental modification** - restore from git: `git checkout constants.py`
651
+ 2. **Malicious tampering** - investigate and restore from a known good backup
652
+ 3. **Development changes** - if you're a maintainer who legitimately needs to update constants, you'll need to regenerate the integrity hash (contact project maintainers)
653
+
654
+ The integrity check uses SHA-256 hashing to ensure the mathematical foundation remains scientifically accurate and unchanged.