-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpixeltypes.py
1121 lines (946 loc) · 28.1 KB
/
pixeltypes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Forward declaration of hsv2rgb_rainbow here,
# to avoid circular dependencies.
# Representation of an HSV pixel (hue, saturation, value (aka brightness)).
class CHSV(object):
@property
def hue(self):
return self._hue
@hue.setter
def hue(self, value):
self._hue = value
@property
def h(self):
return self._hue
@h.setter
def h(self, value):
self._hue = value
@property
def saturation(self):
return self._saturation
@saturation.setter
def saturation(self, value):
self._saturation = value
@property
def sat(self):
return self._saturation
@sat.setter
def sat(self, value):
self._saturation = value
@property
def s(self):
return self._saturation
@s.setter
def s(self, value):
self._saturation = value
@property
def value(self):
return self._value
@value.setter
def value(self, value):
self._value = value
@property
def val(self):
return self._value
@val.setter
def val(self, value):
self._value = value
@property
def v(self):
return self._value
@v.setter
def v(self, value):
self._value = value
@property
def raw(self):
return [self._hue, self._saturation, self._value]
def __getitem__(self, index):
return self.raw[index]
def __init__(self, iH=None, iS=None, iV=None, rhs=None):
if isinstance(iH, CHSV):
self._hue, self._saturation, self._value = iH.raw
elif rhs is not None:
self._hue, self._saturation, self._value = rhs.raw
else:
if iH is None:
iH = 0
if iS is None:
iS = 0
if iV is None:
iV = 0
self._hue = iH
self._saturation = iS
self._value = iV
def setHSV(self, iH, iS, iV):
self._hue = iH
self._saturation = iS
self._value = iV
return self
# Pre-defined hue values for HSV objects
HUE_RED = 0
HUE_ORANGE = 32
HUE_YELLOW = 64
HUE_GREEN = 96
HUE_AQUA = 128
HUE_BLUE = 160
HUE_PURPLE = 192
HUE_PINK = 224
# Representation of an RGB pixel (Red, Green, Blue)
class CRGB(object):
@property
def white(self):
return self._white
@white.setter
def white(self, value):
self._white = value
@property
def w(self):
return self._white
@w.setter
def w(self, value):
self._white = value
@property
def red(self):
return self._red
@red.setter
def red(self, value):
self._red = value
@property
def r(self):
return self._red
@r.setter
def r(self, value):
self._red = value
@property
def green(self):
return self._green
@green.setter
def green(self, value):
self._green = value
@property
def g(self):
return self._green
@g.setter
def g(self, value):
self._green = value
@property
def blue(self):
return self._blue
@blue.setter
def blue(self, value):
self._blue = value
@property
def b(self):
return self._blue
@b.setter
def b(self, value):
self._blue = value
@property
def raw(self):
if self._white is None:
return [self._red, self._green, self._blue]
else:
return [self._red, self._green, self._blue, self._white]
def get_data_stream(self, rgb_order):
rgb_order = str(rgb_order / 10000).split('.')[-1]
while rgb_order.count('0') > 1:
rgb_order = rgb_order[1:]
rgb_order = list(int(item) for item in list(rgb_order))
if 3 in rgb_order and self._white is None:
rgbw = CRGB()
rgb2rgbw(self, rgbw)
values = [rgbw.r, rgbw.b, rgbw.g, rgbw.w]
else:
values = [self._red, self._green, self._blue, self._white]
bytes_ = []
for index in rgb_order:
bytes_.append(values[index])
bit_array = []
for byte in bytes_:
bits = []
for i in range(7, -1, -1):
bits += [int(get_bit(byte, i))]
bit_array += [bits[:]]
return bit_array
def __getitem__(self, index):
return self.raw[index]
def __init__(self, iR=None, iG=None, iB=None, iW=None, colorcode=None, rhs=None):
if isinstance(iR, CRGB):
raw = iR.raw
if len(raw) == 4:
self._red, self._green, self._blue, self._white = raw
else:
self._white = None
self._red, self._green, self._blue = raw
if isinstance(iR, CHSV):
self._red = 0
self._green = 0
self._blue = 0
self._white = None
hsv2rgb_rainbow(iR, self)
elif isinstance(rhs, CRGB):
raw = iR.raw
if len(raw) == 4:
self._red, self._green, self._blue, self._white = raw
else:
self._white = None
self._red, self._green, self._blue = raw
elif isinstance(rhs, CHSV):
self._red = 0
self._green = 0
self._blue = 0
self._white = None
hsv2rgb_rainbow(rhs, self)
elif isinstance(colorcode, int):
self._red = (colorcode >> 16) & 0xFF
self._green = (colorcode >> 8) & 0xFF
self._blue = (colorcode >> 0) & 0xFF
if colorcode > 16777215:
self._white = (colorcode >> 24) & 0xFF
else:
self._white = None
else:
if iR is None:
iR = 0
if iG is None:
iG = 0
if iB is None:
iB = 0
self._red = iR
self._green = iG
self._blue = iB
self._white = iW
def setRGB(self, nR, nG, nB, nW=None):
self._red = nR
self._green = nG
self._blue = nB
self._white = nW
return self
def setHSV(self, hue, sat, val):
if self._white is not None:
rgb = CRGB()
hsv2rgb_rainbow(CHSV(hue, sat, val), rgb)
rgb2rgbw(rgb, self)
else:
hsv2rgb_rainbow(CHSV(hue, sat, val), self)
return self
def setHue(self, hue):
hsv2rgb_rainbow(CHSV(hue, 255, 255), self)
return self
def setColorCode(self, colorcode):
if colorcode > 16777215:
self._white = (colorcode >> 24) & 0xFF
else:
self._white = None
self._red = (colorcode >> 16) & 0xFF
self._green = (colorcode >> 8) & 0xFF
self._blue = (colorcode >> 0) & 0xFF
return self
def __iadd__(self, rhs):
if self._white is None and rhs.w is None:
self._red = qadd8(self._red, rhs.r)
self._green = qadd8(self._green, rhs.g)
self._blue = qadd8(self._blue, rhs.b)
elif self._white is not None and rhs.w is not None:
self._white = qadd8(self._white, rhs.w)
self._red = qadd8(self._red, rhs.r)
self._green = qadd8(self._green, rhs.g)
self._blue = qadd8(self._blue, rhs.b)
elif rhs.w is not None:
rgb = CRGB()
rgbw2rgb(rhs, rgb)
rgb.r = qadd8(self._red, rgb.r)
rgb.g = qadd8(self._green, rgb.g)
rgb.b = qadd8(self._blue, rgb.b)
rgb2rgbw(rgb, self)
else:
rgb = CRGB()
rgbw2rgb(self, rgb)
rgb.r = qadd8(rgb.r, rhs.r)
rgb.g = qadd8(rgb.g, rhs.g)
rgb.b = qadd8(rgb.b, rhs.b)
rgb2rgbw(rgb, self)
return self
def addToRGB(self, d):
self._red = qadd8(self._red, d)
self._green = qadd8(self._green, d)
self._blue = qadd8(self._blue, d)
if self._white is not None:
self._white = qadd8(self._white, d)
return self
def __isub__(self, rhs):
if isinstance(rhs, CRGB):
if self._white is None and rhs.w is None:
self._red = qsub8(self._red, rhs.r)
self._green = qsub8(self._green, rhs.g)
self._blue = qsub8(self._blue, rhs.b)
elif self._white is not None and rhs.w is not None:
self._white = qsub8(self._white, rhs.w)
self._red = qsub8(self._red, rhs.r)
self._green = qsub8(self._green, rhs.g)
self._blue = qsub8(self._blue, rhs.b)
elif rhs.w is not None:
rgb = CRGB()
rgbw2rgb(rhs, rgb)
rgb.r = qsub8(self._red, rgb.r)
rgb.g = qsub8(self._green, rgb.g)
rgb.b = qsub8(self._blue, rgb.b)
rgb2rgbw(rgb, self)
else:
rgb = CRGB()
rgbw2rgb(self, rgb)
rgb.r = qsub8(rgb.r, rhs.r)
rgb.g = qsub8(rgb.g, rhs.g)
rgb.b = qsub8(rgb.b, rhs.b)
rgb2rgbw(rgb, self)
else:
self.subtractFromRGB(rhs)
return self
def subtractFromRGB(self, d):
self._red = qsub8(self._red, d)
self._green = qsub8(self._green, d)
self._blue = qsub8(self._blue, d)
if self._white is not None:
self._white = qsub8(self._white, d)
return self
def __idiv__(self, d):
self._red /= d
self._green /= d
self._blue /= d
if self._white is not None:
self._white /= d
return self
def __irshift__(self, d):
self._red >>= d
self._green >>= d
self._blue >>= d
if self._white is not None:
self._white >>= d
return self
def __imul__(self, d):
self._red = qmul8(self._red, d)
self._green = qmul8(self._green, d)
self._blue = qmul8(self._blue, d)
if self._white is not None:
self._white = qmul8(self._white, d)
return self
def nscale8_video(self, scaledown):
if self._white is None:
self._red, self._green, self._blue = nscale8x3_video(
self._red,
self._green,
self._blue,
scaledown
)
else:
self._red, self._green, self._blue, self._white = nscale8x4_video(
self._red,
self._green,
self._blue,
self._white,
scaledown
)
return self
def __imod__(self, scaledown):
self.nscale8_video(scaledown)
return self
def fadeLightBy(self, fadefactor):
self.nscale8_video(255 - fadefactor)
return self
def scale8(self, scaledown):
if isinstance(scaledown, CRGB):
out = CRGB()
out.r = scale8(self._red, scaledown.r)
out.g = scale8(self._green, scaledown.g)
out.b = scale8(self._blue, scaledown.b)
out.w = scale8(self._white, scaledown.w)
return out
else:
if self._white is None:
self._red, self._green, self._blue = nscale8x3(
self._red,
self._green,
self._blue,
scaledown
)
else:
self._red, self._green, self._blue, self._white = nscale8x4(
self._red,
self._green,
self._blue,
self._white,
scaledown
)
return self
def nscale8(self, scaledown):
self._red = scale8(self._red, scaledown.r)
self._green = scale8(self._green, scaledown.g)
self._blue = scale8(self._blue, scaledown.b)
self._white = scale8(self._white, scaledown.w)
return self
def fadeToBlackBy(self, fadefactor):
if self._white is None:
self._red, self._green, self._blue = nscale8x3(
self._red,
self._green,
self._blue,
255 - fadefactor
)
else:
self._red, self._green, self._blue, self._white = nscale8x4(
self._red,
self._green,
self._blue,
self._white,
255 - fadefactor
)
return self
def __ior__(self, rhs):
if isinstance(rhs, CRGB):
if rhs.r > self._red:
self._red = rhs.r
if rhs.g > self._green:
self._green = rhs.g
if rhs.b > self._blue:
self._blue = rhs.b
if self._white is not None and rhs.w is not None:
if rhs.w > self._white:
self._white = rhs.w
elif rhs.w is not None:
self._white = rhs.w
else:
if rhs > self._red:
self._red = rhs
if rhs > self._green:
self._green = rhs
if rhs > self._blue:
self._blue = rhs
if self._white is not None and rhs > self._white:
self._white = rhs
return self
def __iand__(self, rhs):
if isinstance(rhs, CRGB):
if rhs.r < self._red:
self._red = rhs.r
if rhs.g < self._green:
self._green = rhs.g
if rhs.b < self._blue:
self._blue = rhs.b
if self._white is not None and rhs.w is not None:
if rhs.w < self.white:
self._white = rhs.w
elif rhs.w is not None:
self._white = rhs.w
else:
if rhs < self._red:
self._red = rhs
if rhs < self._green:
self._green = rhs
if rhs < self._blue:
self._blue = rhs
if self._white is not None and rhs < self._white:
self._white = rhs
return self
def __bool__(self):
return self._red != 0 or self._green != 0 or self._blue != 0 or int(self._white) != 0
def __neg__(self):
retval = CRGB()
retval.r = 255 - self._red
retval.g = 255 - self._green
retval.b = 255 - self._blue
if self._white is not None:
retval.w = 255 - self._white
return retval
#
# #if (defined SmartMatrix_h || defined SmartMatrix3_h)
# operator rgb24() const {
# rgb24 ret;
# ret.red = r;
# ret.green = g;
# ret.blue = b;
# return ret;
# }
# #endif
def getLuma(self):
# Y' = 0.2126 R' + 0.7152 G' + 0.0722 B'
# 54 183 18 (!)
if self._white is None:
rgb = self
else:
rgb = CRGB()
rgbw2rgb(self, rgb)
luma = (
scale8_LEAVING_R1_DIRTY(rgb.r, 54) +
scale8_LEAVING_R1_DIRTY(rgb.g, 183) +
scale8_LEAVING_R1_DIRTY(rgb.b, 18)
)
cleanup_R1()
return luma
def getAverageLight(self):
if FASTLED_SCALE8_FIXED == 1:
eightyfive = 85
else:
eightyfive = 86
if self._white is None:
rgb = self
else:
rgb = CRGB()
rgbw2rgb(self, rgb)
avg = (
scale8_LEAVING_R1_DIRTY(rgb.r, eightyfive) +
scale8_LEAVING_R1_DIRTY(rgb.g, eightyfive) +
scale8_LEAVING_R1_DIRTY(rgb.b, eightyfive)
)
cleanup_R1()
return avg
def maximizeBrightness(self, limit=255):
if self.white is None:
rgb = self
else:
rgb = CRGB()
rgbw2rgb(self, rgb)
max_ = rgb.r
if rgb.g > max_:
max_ = rgb.g
if rgb.b > max_:
max_ = rgb.b
# stop div/0 when color is black
if max_ > 0:
factor = (limit * 256) / max_
rgb.r = (rgb.r * factor) / 256
rgb.g = (rgb.g * factor) / 256
rgb.b = (rgb.b * factor) / 256
if self._white is None:
self._red = rgb.r
self._green = rgb.g
self._blue = rgb.b
else:
rgb2rgbw(rgb, self)
def lerp8(self, other, frac):
if self._white is None:
rgb = self
else:
rgb = CRGB()
rgbw2rgb(self, rgb)
rgb.r = lerp8by8(rgb.r << 8, other.r << 8, frac)
rgb.g = lerp8by8(rgb.g << 8, other.g << 8, frac)
rgb.b = lerp8by8(rgb.b << 8, other.b << 8, frac)
return rgb
def lerp16(self, other, frac):
if self._white is None:
rgb = self
else:
rgb = CRGB()
rgbw2rgb(self, rgb)
rgb.r = lerp16by16(rgb.r << 8, other.r << 8, frac) >> 8
rgb.g = lerp16by16(rgb.g << 8, other.g << 8, frac) >> 8
rgb.b = lerp16by16(rgb.b << 8, other.b << 8, frac) >> 8
return rgb
def getParity(self):
if self._white is None:
rgb = self
else:
rgb = CRGB()
rgbw2rgb(self, rgb)
sum_ = rgb.r + rgb.g + rgb.b
return sum_ & 0x01
def setParity(self, parity):
curparity = self.getParity()
if parity == curparity:
return
if self._white is None:
rgb = self
else:
rgb = CRGB()
rgbw2rgb(self, rgb)
if parity:
# going 'up'
if 255 > rgb.b > 0:
if rgb.r == rgb.g == rgb.b:
rgb.r += 1
rgb.g += 1
rgb.b += 1
elif 255 > rgb.r > 0:
rgb.r += 1
elif 255 > rgb.g > 0:
rgb.g += 1
else:
if rgb.r == rgb.g == rgb.b:
rgb.r ^= 0x01
rgb.g ^= 0x01
rgb.b ^= 0x01
else:
# going 'down'
if rgb.b > 1:
if rgb.r == rgb.g == rgb.b:
rgb.r -= 1
rgb.g -= 1
rgb.b -= 1
elif rgb.g > 1:
rgb.g -= 1
elif rgb.r > 1:
rgb.r -= 1
else:
if rgb.r == rgb.g == rgb.b:
rgb.r ^= 0x01
rgb.g ^= 0x01
rgb.b ^= 0x01
if self._white is None:
self._red = rgb.r
self._green = rgb.g
self._blue = rgb.b
else:
rgb2rgbw(rgb, self)
def __eq__(self, rhs):
return self._red == rhs.r and self._green == rhs.g and self._blue == rhs.b and self._white == rhs.w
def __ne__(self, rhs):
return not self.__eq__(rhs)
def __lt__(self, rhs):
sl = self._red + self._green + self._blue + int(self._white)
sr = rhs.r + rhs.g + rhs.b + int(rhs.w)
return sl < sr
def __gt__(self, rhs):
sl = self._red + self._green + self._blue + int(self._white)
sr = rhs.r + rhs.g + rhs.b + int(rhs.w)
return sl > sr
def __le__(self, rhs):
sl = self._red + self._green + self._blue + int(self._white)
sr = rhs.r + rhs.g + rhs.b + int(rhs.w)
return sl <= sr
def __ge__(self, rhs):
sl = self._red + self._green + self._blue + int(self._white)
sr = rhs.r + rhs.g + rhs.b + int(rhs.w)
return sl >= sr
def __add__(self, p2):
if self._white is None and p2.w is None:
return CRGB(
qadd8(self._red, p2.r),
qadd8(self._green, p2.g),
qadd8(self._blue, p2.b)
)
elif self._white is not None and p2.w is not None:
return CRGB(
qadd8(self._red, p2.r),
qadd8(self._green, p2.g),
qadd8(self._blue, p2.b),
qadd8(self._white, p2.w)
)
elif self._white is not None:
return CRGB(
qadd8(self._red, p2.r),
qadd8(self._green, p2.g),
qadd8(self._blue, p2.b),
self._white
)
else:
return CRGB(
qadd8(self._red, p2.r),
qadd8(self._green, p2.g),
qadd8(self._blue, p2.b),
p2.w
)
def __sub__(self, p2):
if self._white is None and p2.w is None:
return CRGB(
qsub8(self._red, p2.r),
qsub8(self._green, p2.g),
qsub8(self._blue, p2.b)
)
elif self._white is not None and p2.w is not None:
return CRGB(
qsub8(self._red, p2.r),
qsub8(self._green, p2.g),
qsub8(self._blue, p2.b),
qsub8(self._white, p2.w)
)
elif self._white is not None:
return CRGB(
qsub8(self._red, p2.r),
qsub8(self._green, p2.g),
qsub8(self._blue, p2.b),
self._white
)
else:
return CRGB(
qsub8(self._red, p2.r),
qsub8(self._green, p2.g),
qsub8(self._blue, p2.b),
p2.w
)
def __mul__(self, d):
if self._white is None:
return CRGB(
qmul8(self._red, d),
qmul8(self._green, d),
qmul8(self._blue, d)
)
else:
return CRGB(
qmul8(self._red, d),
qmul8(self._green, d),
qmul8(self._blue, d),
qmul8(self._white, d)
)
def __floordiv__(self, d):
if self._white is None:
return CRGB(
self._red // d,
self._green // d,
self._blue // d
)
else:
return CRGB(
self._red // d,
self._green // d,
self._blue // d,
self._white // d
)
def __and__(self, p2):
if self._white is None and p2.w is None:
return CRGB(
self._red if self._red < p2.r else p2.r,
self._green if self._green < p2.g else p2.g,
self._blue if self._blue < p2.b else p2.b
)
elif self._white is not None and p2.w is not None:
return CRGB(
self._red if self._red < p2.r else p2.r,
self._green if self._green < p2.g else p2.g,
self._blue if self._blue < p2.b else p2.b,
self._white if self._white < p2.w else p2.w
)
elif self._white is not None:
return CRGB(
self._red if self._red < p2.r else p2.r,
self._green if self._green < p2.g else p2.g,
self._blue if self._blue < p2.b else p2.b,
self._white
)
else:
return CRGB(
self._red if self._red < p2.r else p2.r,
self._green if self._green < p2.g else p2.g,
self._blue if self._blue < p2.b else p2.b,
p2.w
)
def __or__(self, p2):
if self._white is None and p2.w is None:
return CRGB(
self._red if self._red > p2.r else p2.r,
self._green if self._green > p2.g else p2.g,
self._blue if self._blue > p2.b else p2.b,
)
elif self._white is not None and p2.w is not None:
return CRGB(
self._red if self._red > p2.r else p2.r,
self._green if self._green > p2.g else p2.g,
self._blue if self._blue > p2.b else p2.b,
self._white if self._white > p2.w else p2.w
)
elif self._white is not None:
return CRGB(
self._red if self._red > p2.r else p2.r,
self._green if self._green > p2.g else p2.g,
self._blue if self._blue > p2.b else p2.b,
self._white
)
else:
return CRGB(
self._red if self._red > p2.r else p2.r,
self._green if self._green > p2.g else p2.g,
self._blue if self._blue > p2.b else p2.b,
p2.w
)
def __mod__(self, d):
retval = CRGB(self)
retval.nscale8_video(d)
return retval
# RGB orderings, used when instantiating controllers to determine what
# order the controller should send RGB data out in, RGB being the default
# ordering.
RGB = 12
RGBW = 123
RGWB = 132
RWGB = 312
WRGB = 3012
RBG = 21
RBGW = 213
RBWG = 231
RWBG = 321
WRBG = 3021
GRB = 102
GRBW = 1023
GRWB = 1032
GWRB = 1302
WGRB = 3102
GBR = 120
GBRW = 1203
GBWR = 1230
GWBR = 1320
WGBR = 3120
BRG = 201
BRGW = 2013
BRWG = 2031
BWRG = 2301
WBRG = 3201
BGR = 210
BGRW = 2103
BGWR = 2130
BWGR = 2310
WBGR = 3210
AliceBlue = 0xF0F8FF
Amethyst = 0x9966CC
AntiqueWhite = 0xFAEBD7
Aqua = 0x00FFFF
Aquamarine = 0x7FFFD4
Azure = 0xF0FFFF
Beige = 0xF5F5DC
Bisque = 0xFFE4C4
Black = 0x000000
BlanchedAlmond = 0xFFEBCD
Blue = 0x0000FF
BlueViolet = 0x8A2BE2
Brown = 0xA52A2A
BurlyWood = 0xDEB887
CadetBlue = 0x5F9EA0
Chartreuse = 0x7FFF00
Chocolate = 0xD2691E
Coral = 0xFF7F50
CornflowerBlue = 0x6495ED
Cornsilk = 0xFFF8DC
Crimson = 0xDC143C
Cyan = 0x00FFFF
DarkBlue = 0x00008B
DarkCyan = 0x008B8B
DarkGoldenrod = 0xB8860B
DarkGray = 0xA9A9A9
DarkGrey = 0xA9A9A9
DarkGreen = 0x006400
DarkKhaki = 0xBDB76B
DarkMagenta = 0x8B008B
DarkOliveGreen = 0x556B2F
DarkOrange = 0xFF8C00
DarkOrchid = 0x9932CC
DarkRed = 0x8B0000
DarkSalmon = 0xE9967A
DarkSeaGreen = 0x8FBC8F
DarkSlateBlue = 0x483D8B
DarkSlateGray = 0x2F4F4F