This commit is contained in:
Constantin Gierczak--Galle 2023-12-15 10:56:07 +01:00
parent e225716f52
commit c39f065872

View file

@ -59,29 +59,29 @@ def widen(colors: List[Color], width: int):
return L
def blendLedBar_simple(colors: List[Color],
res_length: int,
length: int,
blending: InterpType,
filling: Filling,
void_color: Color) -> List[Color]:
total_len = len(colors)
(deduped, rep_nb) = remove_duplicates(colors)
if len(deduped) > res_length:
if len(deduped) > length:
# After dedup, there are still too many colors. Only show the first ones
logging.warning(f"LED bar interpolation: More than {res_length} colors. Dropping colors")
return widen(deduped[:res_length], width)
logging.warning(f"LED bar interpolation: More than {length} colors. Dropping colors")
return widen(deduped[:length], width)
if len(colors) > res_length:
if len(colors) > length:
# TODO: Try and dedup some colors to save space
return colors[:res_length]
return colors[:length]
if blending == InterpType.NEAREST:
factor = res_length // total_len
factor = length // total_len
# First pass
for i in range(len(rep_nb)):
rep_nb[i] *= factor
gap = res_length - total_len * factor
gap = length - total_len * factor
# TODO: Add GREATEST
# The idea is to first add a repetition to the already longest
@ -111,10 +111,10 @@ def blendLedBar_simple(colors: List[Color],
return reduplicate(deduped, rep_nb)
def blendLedBar(colors: List[Color],
res_length: Optional[int] = LedBarLen,
length: Optional[int] = LedBarLen,
width: Optional[int] = 1,
blending: Optional[InterpType] = InterpType.NEAREST,
filling: Optional[Filling] = Filling.GREATEST,
void_color: Optional[Color] = Color("black")) -> List[Color]:
return widen(blendLedBar(colors, res_length, blending, filling, void_color),
return widen(blendLedBar(colors, length, blending, filling, void_color),
width)