Skip to content

Commit

Permalink
Merge pull request #828 from contour-terminal/fix/sixel-active-color
Browse files Browse the repository at this point in the history
[Sixel] Updating color palette must also update current pen color.
  • Loading branch information
christianparpart authored Sep 23, 2022
2 parents 8d12e8c + c51e734 commit abe099b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@
<description>
<ul>
<li>Fixes a problem with oversized glyphs being wrongly cut off (#821).</li>
<li>Fixes vertical cursor movement for sixel graphics with only newlines (#822).</li>
<li>Fixes sixel rendering for images with aspect ratios other than 1:1.</li>
<li>Fixes Sixel mode, when updating the color palette with a new color, that color must also be used for subsequent paints.</li>
<li>Fixes vertical cursor movement for Sixel graphics with only newlines (#822).</li>
<li>Fixes Sixel rendering for images with aspect ratios other than 1:1.</li>
<li>Removes `images.sixel_cursor_conformance` config option.</li>
</ul>
</description>
Expand Down
1 change: 1 addition & 0 deletions src/terminal/SixelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ void SixelParser::leaveState()
break;
}
}
events_.useColor(index); // Also use the specified color.
}
break;
}
Expand Down
11 changes: 7 additions & 4 deletions src/terminal/SixelParser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,32 +232,35 @@ TEST_CASE("SixelParser.rep", "[sixel]")

TEST_CASE("SixelParser.setAndUseColor", "[sixel]")
{
auto constexpr pinColors = std::array<RGBAColor, 4> { RGBAColor { 255, 0, 0, 255 },
auto constexpr pinColors = std::array<RGBAColor, 5> { RGBAColor { 255, 255, 255, 255 },
RGBAColor { 255, 0, 0, 255 },
RGBAColor { 0, 255, 0, 255 },
RGBAColor { 0, 0, 255, 255 },
RGBAColor { 255, 255, 255, 255 } };

auto constexpr defaultColor = RGBAColor { 0, 0, 0, 0xFF };
auto ib = sixelImageBuilder(ImageSize { Width(4), Height(6) }, defaultColor);
auto ib = sixelImageBuilder(ImageSize { Width(5), Height(6) }, defaultColor);
auto sp = SixelParser { ib };

sp.parseFragment("#1;2;100;0;0");
sp.parseFragment("#2;2;0;100;0");
sp.parseFragment("#3;2;0;0;100");
sp.parseFragment("#4;2;100;100;100");

sp.parseFragment("~"); // We paint with the last set color.
sp.parseFragment("#1~");
sp.parseFragment("#2~");
sp.parseFragment("#3~");
sp.parseFragment("#4~");
sp.done();

REQUIRE(ib.sixelCursor() == CellLocation { LineOffset(0), ColumnOffset(4) });
REQUIRE(ib.sixelCursor() == CellLocation { LineOffset(0), ColumnOffset(5) });

for (auto const [x, y]:
crispy::times(ib.size().width.as<int>()) * crispy::times(ib.size().height.as<int>()))
{
auto const& expectedColor = x < 4 && y < 6 ? pinColors.at(static_cast<size_t>(x)) : defaultColor;
auto const& expectedColor =
x < 5 && y < 6 ? pinColors.at(static_cast<size_t>(x ? x : 4)) : defaultColor;
auto const& actualColor = ib.at(CellLocation { LineOffset(y), ColumnOffset(x) });
// INFO(fmt::format("at {}, expect {}, actual {}",
// CellLocation { LineOffset(y), ColumnOffset(x) },
Expand Down

0 comments on commit abe099b

Please sign in to comment.