Make blend algorithm work with arbitrary length
This commit is contained in:
parent
ef254769b9
commit
a4c7a38636
1 changed files with 8 additions and 7 deletions
|
@ -54,28 +54,29 @@ class Filling(Enum):
|
||||||
GREATEST = 3 # Repeat the longest color streaks
|
GREATEST = 3 # Repeat the longest color streaks
|
||||||
|
|
||||||
def blendLedBar(colors: List[Color],
|
def blendLedBar(colors: List[Color],
|
||||||
|
res_length: Optional[int] = LedBarLen,
|
||||||
blending: Optional[InterpType] = InterpType.NEAREST,
|
blending: Optional[InterpType] = InterpType.NEAREST,
|
||||||
filling: Optional[Filling] = Filling.GREATEST,
|
filling: Optional[Filling] = Filling.GREATEST,
|
||||||
void_color: Optional[Color] = Color("black")) -> List[Color]:
|
void_color: Optional[Color] = Color("black")) -> List[Color]:
|
||||||
total_len = len(colors)
|
total_len = len(colors)
|
||||||
(deduped, rep_nb) = remove_duplicates(colors)
|
(deduped, rep_nb) = remove_duplicates(colors)
|
||||||
if len(deduped) > LedBarLen:
|
if len(deduped) > res_length:
|
||||||
# After dedup, there are still too many colors. Only show the first ones
|
# After dedup, there are still too many colors. Only show the first ones
|
||||||
logging.warning(f"LED bar interpolation: More than {LedBarLen} colors. Dropping colors")
|
logging.warning(f"LED bar interpolation: More than {res_length} colors. Dropping colors")
|
||||||
return deduped[:LedBarLen]
|
return deduped[:res_length]
|
||||||
|
|
||||||
if len(colors) > LedBarLen:
|
if len(colors) > res_length:
|
||||||
# TODO: Try and dedup some colors to save space
|
# TODO: Try and dedup some colors to save space
|
||||||
return colors[:LedBarLen]
|
return colors[:res_length]
|
||||||
|
|
||||||
if blending == InterpType.NEAREST:
|
if blending == InterpType.NEAREST:
|
||||||
factor = LedBarLen // total_len
|
factor = res_length // total_len
|
||||||
|
|
||||||
# First pass
|
# First pass
|
||||||
for i in range(len(rep_nb)):
|
for i in range(len(rep_nb)):
|
||||||
rep_nb[i] *= factor
|
rep_nb[i] *= factor
|
||||||
|
|
||||||
gap = LedBarLen - total_len * factor
|
gap = res_length - total_len * factor
|
||||||
|
|
||||||
# TODO: Add GREATEST
|
# TODO: Add GREATEST
|
||||||
# The idea is to first add a repetition to the already longest
|
# The idea is to first add a repetition to the already longest
|
||||||
|
|
Loading…
Reference in a new issue