Skip to content

Commit

Permalink
Fix AnsiImage::writeToTerminal() optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWoodworth committed Oct 4, 2021
1 parent e99933d commit 8dd549c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions source/core/graphics/AnsiImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ void AnsiImage::setPixel(int32_t x, int32_t y, AnsiPixel* ansiPixel) {
}

void AnsiImage::writeToTerminal(Terminal* terminal) {
uint8_t lastFgColor = 0;
uint8_t lastBgColor = 0;

for (int32_t y = 0; y < this->height; y++) {
for (int32_t x = 0; x < this->width; x++) {
AnsiPixel* pixel = this->getPixel(x, y);
Expand All @@ -26,11 +29,11 @@ void AnsiImage::writeToTerminal(Terminal* terminal) {
continue;
}

if (pixel->getForeground() != lastFgColor) {
if (x == 0 || pixel->getForeground() != lastFgColor) {
terminal->setColor(pixel->getForeground(), true);
lastFgColor = pixel->getForeground();
}
if (pixel->getBackground() != lastBgColor) {
if (x == 0 || pixel->getBackground() != lastBgColor) {
terminal->setColor(pixel->getBackground(), false);
lastBgColor = pixel->getBackground();
}
Expand Down

0 comments on commit 8dd549c

Please sign in to comment.