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 d1ef430 commit 3dddd08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 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
22 changes: 14 additions & 8 deletions src/terminal/SixelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,19 @@ void SixelImageBuilder::write(CellLocation const& _coord, RGBColor const& _value
size_.width = Width::cast_from(_coord.column + 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 * static_cast<unsigned int>(j)] = _value.red;
buffer_[base + 1 + 4 * static_cast<unsigned int>(j)] = _value.green;
buffer_[base + 2 + 4 * static_cast<unsigned int>(j)] = _value.blue;
buffer_[base + 3 + 4 * static_cast<unsigned int>(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() * static_cast<size_t>(_pad * _pan) * 4);
explicitSize_ = true;
}

Expand Down

0 comments on commit 3dddd08

Please sign in to comment.