Skip to content

Commit

Permalink
Fixed sixel image rendering with different aspect ratios
Browse files Browse the repository at this point in the history
  • Loading branch information
Utkarsh-khambra committed Sep 22, 2022
1 parent c692032 commit 7cf5865
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<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>Removes `images.sixel_cursor_conformance` config option</li>
</ul>
</description>
Expand Down
28 changes: 18 additions & 10 deletions src/terminal/SixelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,24 @@ void SixelImageBuilder::write(CellLocation const& _coord, RGBColor const& _value
if (!explicitSize_)
{
if (unbox<int>(_coord.line) >= unbox<int>(size_.height))
size_.height = Height::cast_from(_coord.line + 1);
size_.height = Height::cast_from(_coord.line.value + 1);
if (unbox<int>(_coord.column) >= unbox<int>(size_.width))
size_.width = Width::cast_from(_coord.column + 1);
size_.width = Width::cast_from(_coord.column.value + 1);
}

auto const base =
unbox<unsigned>(_coord.line) * unbox<unsigned>((explicitSize_ ? size_.width : maxSize_.width)) * 4
+ unbox<unsigned>(_coord.column) * 4;
buffer_[base + 0] = _value.red;
buffer_[base + 1] = _value.green;
buffer_[base + 2] = _value.blue;
buffer_[base + 3] = 0xFF;
for (auto i = 0; i < aspectRatio_.nominator; ++i)
{
auto const base = unbox<unsigned>(_coord.line + i)
* unbox<unsigned>((explicitSize_ ? size_.width : maxSize_.width)) * 4
+ unbox<unsigned>(_coord.column) * 4;
for (auto j = 0; j < aspectRatio_.denominator; ++j)
{
buffer_[base + 0 + 4 * j] = _value.red;
buffer_[base + 1 + 4 * j] = _value.green;
buffer_[base + 2 + 4 * j] = _value.blue;
buffer_[base + 3 + 4 * j] = 0xFF;
}
}
}
}

Expand Down Expand Up @@ -451,7 +457,7 @@ void SixelImageBuilder::setRaster(int _pan, int _pad, ImageSize _imageSize)
size_.width = clamp(_imageSize.width, Width(0), maxSize_.width);
size_.height = clamp(_imageSize.height, Height(0), maxSize_.height);

buffer_.resize(size_.area() * 4);
buffer_.resize(size_.area() * _pad * _pan * 4);
explicitSize_ = true;
}

Expand All @@ -478,12 +484,14 @@ void SixelImageBuilder::finalize()
{
if (unbox<int>(size_.height) == 1)
{
fmt::print("{}\n", aspectRatio_.nominator);
size_.height = Height::cast_from(sixelCursor_.line * aspectRatio_.nominator);
buffer_.resize(size_.area() * 4);
return;
}
if (!explicitSize_)
{
fmt::print("{}\n", aspectRatio_.nominator);
Buffer tempBuffer(static_cast<size_t>(size_.height.value * size_.width.value) * 4);
for (auto i = 0; i < unbox<int>(size_.height); ++i)
{
Expand Down

0 comments on commit 7cf5865

Please sign in to comment.