stefanhaustein / TerminalImageViewer

Small C++ program to display images in a (modern) terminal using RGB ANSI codes and unicode block graphics characters
Other
1.56k stars 111 forks source link

Bandwidth optimization: don't emit duplicate color codes #54

Closed AlanDeSmet closed 5 years ago

AlanDeSmet commented 5 years ago

emit_color is unconditionally called within emit_image, and itself unconditionally emits the color codes. If the previous character cell had the same colors, this is redundant.

Proposed: emit_color maintains a copy of the last foreground and background used, possibly as simply as keeping the string that was emitted. If it's about to emit the same one, return without emitting anything.

Challenges:

(This is really stefanhaustein's idea, mentioned to me in an email. I'm adding it because it sounds like a fun little project to me, not because I need it. So unless someone else has a more specific requirement, I'd consider this "wishlist" level.)