Make blend algorithm work with arbitrary length

This commit is contained in:
Constantin Gierczak--Galle 2023-12-11 16:35:10 +01:00
parent ef254769b9
commit a4c7a38636

View file

@ -54,28 +54,29 @@ class Filling(Enum):
GREATEST = 3 # Repeat the longest color streaks
def blendLedBar(colors: List[Color],
res_length: Optional[int] = LedBarLen,
blending: Optional[InterpType] = InterpType.NEAREST,
filling: Optional[Filling] = Filling.GREATEST,
void_color: Optional[Color] = Color("black")) -> List[Color]:
total_len = len(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
logging.warning(f"LED bar interpolation: More than {LedBarLen} colors. Dropping colors")
return deduped[:LedBarLen]
logging.warning(f"LED bar interpolation: More than {res_length} colors. Dropping colors")
return deduped[:res_length]
if len(colors) > LedBarLen:
if len(colors) > res_length:
# TODO: Try and dedup some colors to save space
return colors[:LedBarLen]
return colors[:res_length]
if blending == InterpType.NEAREST:
factor = LedBarLen // total_len
factor = res_length // total_len
# First pass
for i in range(len(rep_nb)):
rep_nb[i] *= factor
gap = LedBarLen - total_len * factor
gap = res_length - total_len * factor
# TODO: Add GREATEST
# The idea is to first add a repetition to the already longest