@@ -133,6 +133,9 @@ class SpectralColor(IlluminantMixin, ColorBase):
133
133
Spectral colors are the lowest level, most "raw" measurement of color.
134
134
You may convert spectral colors to any other color space, but you can't
135
135
convert any other color space back to spectral.
136
+
137
+ See `Spectral power distribution <http://en.wikipedia.org/wiki/Spectral_power_distribution>`_
138
+ on Wikipedia for some higher level details on how these work.
136
139
"""
137
140
138
141
VALUES = [
@@ -166,8 +169,8 @@ def __init__(self,
166
169
spec_780nm = 0.0 , spec_790nm = 0.0 , spec_800nm = 0.0 , spec_810nm = 0.0 ,
167
170
spec_820nm = 0.0 , spec_830nm = 0.0 , observer = '2' , illuminant = 'd50' ):
168
171
"""
169
- :param str observer: Observer angle. Either ``'2'`` or ``'10'`` degrees.
170
- :param illuminant: See :doc:`illuminants` for valid values.
172
+ :keyword str observer: Observer angle. Either ``'2'`` or ``'10'`` degrees.
173
+ :keyword str illuminant: See :doc:`illuminants` for valid values.
171
174
"""
172
175
173
176
super (SpectralColor , self ).__init__ ()
@@ -268,12 +271,22 @@ def calc_density(self, density_standard=None):
268
271
269
272
class LabColor (IlluminantMixin , ColorBase ):
270
273
"""
271
- Represents an Lab color.
274
+ Represents a CIE Lab color. For more information on CIE Lab,
275
+ see `Lab color space <http://en.wikipedia.org/wiki/Lab_color_space>`_ on
276
+ Wikipedia.
272
277
"""
273
278
274
279
VALUES = ['lab_l' , 'lab_a' , 'lab_b' ]
275
280
276
281
def __init__ (self , lab_l , lab_a , lab_b , observer = '2' , illuminant = 'd50' ):
282
+ """
283
+ :param float lab_l: L coordinate.
284
+ :param float lab_a: a coordinate.
285
+ :param float lab_b: b coordinate.
286
+ :keyword str observer: Observer angle. Either ``'2'`` or ``'10'`` degrees.
287
+ :keyword str illuminant: See :doc:`illuminants` for valid values.
288
+ """
289
+
277
290
super (LabColor , self ).__init__ ()
278
291
self .lab_l = float (lab_l )
279
292
self .lab_a = float (lab_a )
@@ -284,12 +297,25 @@ def __init__(self, lab_l, lab_a, lab_b, observer='2', illuminant='d50'):
284
297
285
298
class LCHabColor (IlluminantMixin , ColorBase ):
286
299
"""
287
- Represents an LCHab color.
300
+ Represents an CIE LCH color that was converted to LCH by passing through
301
+ CIE Lab. This differs from :py:class:`LCHuvColor`, which was converted to
302
+ LCH through CIE Luv.
303
+
304
+ See `Introduction to Colour Spaces <http://www.colourphil.co.uk/lab_lch_colour_space.shtml>`_
305
+ by Phil Cruse for an illustration of how CIE LCH differs from CIE Lab.
288
306
"""
289
307
290
308
VALUES = ['lch_l' , 'lch_c' , 'lch_h' ]
291
309
292
310
def __init__ (self , lch_l , lch_c , lch_h , observer = '2' , illuminant = 'd50' ):
311
+ """
312
+ :param float lch_l: L coordinate.
313
+ :param float lch_c: C coordinate.
314
+ :param float lch_h: H coordinate.
315
+ :keyword str observer: Observer angle. Either ``'2'`` or ``'10'`` degrees.
316
+ :keyword str illuminant: See :doc:`illuminants` for valid values.
317
+ """
318
+
293
319
super (LCHabColor , self ).__init__ ()
294
320
self .lch_l = float (lch_l )
295
321
self .lch_c = float (lch_c )
@@ -300,12 +326,25 @@ def __init__(self, lch_l, lch_c, lch_h, observer='2', illuminant='d50'):
300
326
301
327
class LCHuvColor (IlluminantMixin , ColorBase ):
302
328
"""
303
- Represents an LCHuv color.
329
+ Represents an CIE LCH color that was converted to LCH by passing through
330
+ CIE Luv. This differs from :py:class:`LCHabColor`, which was converted to
331
+ LCH through CIE Lab.
332
+
333
+ See `Introduction to Colour Spaces <http://www.colourphil.co.uk/lab_lch_colour_space.shtml>`_
334
+ by Phil Cruse for an illustration of how CIE LCH differs from CIE Lab.
304
335
"""
305
336
306
337
VALUES = ['lch_l' , 'lch_c' , 'lch_h' ]
307
338
308
339
def __init__ (self , lch_l , lch_c , lch_h , observer = '2' , illuminant = 'd50' ):
340
+ """
341
+ :param float lch_l: L coordinate.
342
+ :param float lch_c: C coordinate.
343
+ :param float lch_h: H coordinate.
344
+ :keyword str observer: Observer angle. Either ``'2'`` or ``'10'`` degrees.
345
+ :keyword str illuminant: See :doc:`illuminants` for valid values.
346
+ """
347
+
309
348
super (LCHuvColor , self ).__init__ ()
310
349
self .lch_l = float (lch_l )
311
350
self .lch_c = float (lch_c )
@@ -322,6 +361,14 @@ class LuvColor(IlluminantMixin, ColorBase):
322
361
VALUES = ['luv_l' , 'luv_u' , 'luv_v' ]
323
362
324
363
def __init__ (self , luv_l , luv_u , luv_v , observer = '2' , illuminant = 'd50' ):
364
+ """
365
+ :param float luv_l: L coordinate.
366
+ :param float luv_u: u coordinate.
367
+ :param float luv_v: v coordinate.
368
+ :keyword str observer: Observer angle. Either ``'2'`` or ``'10'`` degrees.
369
+ :keyword str illuminant: See :doc:`illuminants` for valid values.
370
+ """
371
+
325
372
super (LuvColor , self ).__init__ ()
326
373
self .luv_l = float (luv_l )
327
374
self .luv_u = float (luv_u )
@@ -338,6 +385,14 @@ class XYZColor(IlluminantMixin, ColorBase):
338
385
VALUES = ['xyz_x' , 'xyz_y' , 'xyz_z' ]
339
386
340
387
def __init__ (self , xyz_x , xyz_y , xyz_z , observer = '2' , illuminant = 'd50' ):
388
+ """
389
+ :param float xyz_x: X coordinate.
390
+ :param float xyz_y: Y coordinate.
391
+ :param float xyz_z: Z coordinate.
392
+ :keyword str observer: Observer angle. Either ``'2'`` or ``'10'`` degrees.
393
+ :keyword str illuminant: See :doc:`illuminants` for valid values.
394
+ """
395
+
341
396
super (XYZColor , self ).__init__ ()
342
397
self .xyz_x = float (xyz_x )
343
398
self .xyz_y = float (xyz_y )
@@ -376,6 +431,14 @@ class xyYColor(IlluminantMixin, ColorBase):
376
431
VALUES = ['xyy_x' , 'xyy_y' , 'xyy_Y' ]
377
432
378
433
def __init__ (self , xyy_x , xyy_y , xyy_Y , observer = '2' , illuminant = 'd50' ):
434
+ """
435
+ :param float xyy_x: x coordinate.
436
+ :param float xyy_y: y coordinate.
437
+ :param float xyy_Y: Y coordinate.
438
+ :keyword str observer: Observer angle. Either ``'2'`` or ``'10'`` degrees.
439
+ :keyword str illuminant: See :doc:`illuminants` for valid values.
440
+ """
441
+
379
442
super (xyYColor , self ).__init__ ()
380
443
self .xyy_x = float (xyy_x )
381
444
self .xyy_y = float (xyy_y )
@@ -394,6 +457,14 @@ class BaseRGBColor(ColorBase):
394
457
VALUES = ['rgb_r' , 'rgb_g' , 'rgb_b' ]
395
458
396
459
def __init__ (self , rgb_r , rgb_g , rgb_b , is_upscaled = False ):
460
+ """
461
+ :param float rgb_r: R coordinate. 0...1. 1-255 if is_upscaled=True.
462
+ :param float rgb_g: G coordinate. 0...1. 1-255 if is_upscaled=True.
463
+ :param float rgb_b: B coordinate. 0...1. 1-255 if is_upscaled=True.
464
+ :keyword bool is_upscaled: If False, RGB coordinate values are
465
+ beteween 0.0 and 1.0. If True, RGB values are between 1 and 255.
466
+ """
467
+
397
468
super (BaseRGBColor , self ).__init__ ()
398
469
if is_upscaled :
399
470
self .rgb_r = rgb_r / 255.0
@@ -403,12 +474,16 @@ def __init__(self, rgb_r, rgb_g, rgb_b, is_upscaled=False):
403
474
self .rgb_r = float (rgb_r )
404
475
self .rgb_g = float (rgb_g )
405
476
self .rgb_b = float (rgb_b )
477
+ self .is_upscaled = is_upscaled
406
478
407
479
def get_upscaled_value_tuple (self ):
408
480
"""
409
481
Scales an RGB color object from decimal 0.0-1.0 to int 0-255.
410
482
"""
411
483
484
+ if self .is_upscaled :
485
+ return self .get_value_tuple ()
486
+
412
487
# Scale up to 0-255 values.
413
488
rgb_r = int (math .floor (0.5 + self .rgb_r * 255 ))
414
489
rgb_g = int (math .floor (0.5 + self .rgb_g * 255 ))
@@ -419,6 +494,8 @@ def get_upscaled_value_tuple(self):
419
494
def get_rgb_hex (self ):
420
495
"""
421
496
Converts the RGB value to a hex value in the form of: #RRGGBB
497
+
498
+ :rtype: str
422
499
"""
423
500
424
501
rgb_r , rgb_g , rgb_b = self .get_upscaled_value_tuple ()
@@ -494,6 +571,12 @@ class HSLColor(ColorBase):
494
571
VALUES = ['hsl_h' , 'hsl_s' , 'hsl_l' ]
495
572
496
573
def __init__ (self , hsl_h , hsl_s , hsl_l ):
574
+ """
575
+ :param float hsl_h: H coordinate.
576
+ :param float hsl_s: S coordinate.
577
+ :param float hsl_l: L coordinate.
578
+ """
579
+
497
580
super (HSLColor , self ).__init__ ()
498
581
self .hsl_h = float (hsl_h )
499
582
self .hsl_s = float (hsl_s )
@@ -508,6 +591,12 @@ class HSVColor(ColorBase):
508
591
VALUES = ['hsv_h' , 'hsv_s' , 'hsv_v' ]
509
592
510
593
def __init__ (self , hsv_h , hsv_s , hsv_v ):
594
+ """
595
+ :param float hsv_h: H coordinate.
596
+ :param float hsv_s: S coordinate.
597
+ :param float hsv_v: V coordinate.
598
+ """
599
+
511
600
super (HSVColor , self ).__init__ ()
512
601
self .hsv_h = float (hsv_h )
513
602
self .hsv_s = float (hsv_s )
@@ -522,6 +611,12 @@ class CMYColor(ColorBase):
522
611
VALUES = ['cmy_c' , 'cmy_m' , 'cmy_y' ]
523
612
524
613
def __init__ (self , cmy_c , cmy_m , cmy_y ):
614
+ """
615
+ :param float cmy_c: C coordinate.
616
+ :param float cmy_m: M coordinate.
617
+ :param float cmy_y: Y coordinate.
618
+ """
619
+
525
620
super (CMYColor , self ).__init__ ()
526
621
self .cmy_c = float (cmy_c )
527
622
self .cmy_m = float (cmy_m )
@@ -536,6 +631,13 @@ class CMYKColor(ColorBase):
536
631
VALUES = ['cmyk_c' , 'cmyk_m' , 'cmyk_y' , 'cmyk_k' ]
537
632
538
633
def __init__ (self , cmyk_c , cmyk_m , cmyk_y , cmyk_k ):
634
+ """
635
+ :param float cmyk_c: C coordinate.
636
+ :param float cmyk_m: M coordinate.
637
+ :param float cmyk_y: Y coordinate.
638
+ :param float cmyk_k: K coordinate.
639
+ """
640
+
539
641
super (CMYKColor , self ).__init__ ()
540
642
self .cmyk_c = float (cmyk_c )
541
643
self .cmyk_m = float (cmyk_m )
0 commit comments