From 7cf58653f5d026663d513a1fc46a3b64ac19ef51 Mon Sep 17 00:00:00 2001 From: Utkarsh khambra Date: Thu, 22 Sep 2022 12:41:58 +0530 Subject: [PATCH] Fixed sixel image rendering with different aspect ratios --- metainfo.xml | 1 + src/terminal/SixelParser.cpp | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/metainfo.xml b/metainfo.xml index e4baa5d523..0e02c6c9de 100644 --- a/metainfo.xml +++ b/metainfo.xml @@ -104,6 +104,7 @@ diff --git a/src/terminal/SixelParser.cpp b/src/terminal/SixelParser.cpp index da5d75f05b..38a4f43c11 100644 --- a/src/terminal/SixelParser.cpp +++ b/src/terminal/SixelParser.cpp @@ -407,18 +407,24 @@ void SixelImageBuilder::write(CellLocation const& _coord, RGBColor const& _value if (!explicitSize_) { if (unbox(_coord.line) >= unbox(size_.height)) - size_.height = Height::cast_from(_coord.line + 1); + size_.height = Height::cast_from(_coord.line.value + 1); if (unbox(_coord.column) >= unbox(size_.width)) - size_.width = Width::cast_from(_coord.column + 1); + size_.width = Width::cast_from(_coord.column.value + 1); } - auto const base = - unbox(_coord.line) * unbox((explicitSize_ ? size_.width : maxSize_.width)) * 4 - + unbox(_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(_coord.line + i) + * unbox((explicitSize_ ? size_.width : maxSize_.width)) * 4 + + unbox(_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; + } + } } } @@ -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; } @@ -478,12 +484,14 @@ void SixelImageBuilder::finalize() { if (unbox(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_.height.value * size_.width.value) * 4); for (auto i = 0; i < unbox(size_.height); ++i) {