Skip to content

Commit

Permalink
Some small corrections and fix automatic adjustement of atlas size
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut committed Feb 6, 2024
1 parent 732a930 commit c340e2b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<release version="0.4.4" urgency="medium" type="development">
<description>
<ul>
<li> ... </li>
<li> Fixes corruption of sixel image on high resolution (#1049) </li>
</ul>
</description>
</release>
Expand Down
6 changes: 3 additions & 3 deletions src/vtbackend/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ Image::Data RasterizedImage::fragment(CellLocation pos) const
Image::Data fragData;
fragData.resize(_cellSize.area() * 4); // RGBA
auto const availableWidth =
min(unbox<int>(_image->width()) - *pixelOffset.column, unbox<int>(_cellSize.width));
min(unbox<int>(_image->width()) - unbox(pixelOffset.column), unbox<int>(_cellSize.width));
auto const availableHeight =
min(unbox<int>(_image->height()) - *pixelOffset.line, unbox<int>(_cellSize.height));
min(unbox<int>(_image->height()) - unbox(pixelOffset.line), unbox<int>(_cellSize.height));

// auto const availableSize = Size{availableWidth, availableHeight};
// std::cout << fmt::format(
Expand Down Expand Up @@ -90,7 +90,7 @@ Image::Data RasterizedImage::fragment(CellLocation pos) const
for (int y = 0; y < availableHeight; ++y)
{
auto const startOffset = static_cast<size_t>(
((*pixelOffset.line + y) * unbox<int>(_image->width()) + *pixelOffset.column) * 4);
((pixelOffset.line + y) * unbox<int>(_image->width()) + unbox(pixelOffset.column)) * 4);
const auto* const source = &_image->data()[startOffset];
target = copy(source, source + static_cast<ptrdiff_t>(availableWidth) * 4, target);

Expand Down
21 changes: 11 additions & 10 deletions src/vtbackend/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1887,9 +1887,9 @@ CRISPY_REQUIRES(CellConcept<Cell>)
void Screen<Cell>::sixelImage(ImageSize pixelSize, Image::Data&& rgbaData)
{
auto const columnCount =
ColumnCount::cast_from(ceilf(float(*pixelSize.width) / float(*_state->cellPixelSize.width)));
ColumnCount::cast_from(ceil(pixelSize.width.as<double>() / _state->cellPixelSize.width.as<double>()));
auto const lineCount =
LineCount::cast_from(ceilf(float(*pixelSize.height) / float(*_state->cellPixelSize.height)));
LineCount::cast_from(ceil(pixelSize.height.as<double>() / _state->cellPixelSize.height.as<double>()));
auto const extent = GridSize { lineCount, columnCount };
auto const autoScrollAtBottomMargin = !_terminal->isModeEnabled(DECMode::NoSixelScrolling);
auto const topLeft = autoScrollAtBottomMargin ? logicalCursorPosition() : CellLocation {};
Expand Down Expand Up @@ -1939,29 +1939,30 @@ void Screen<Cell>::renderImage(shared_ptr<Image const> image,

auto const linesAvailable = pageSize().lines - topLeft.line.as<LineCount>();
auto const linesToBeRendered = min(gridSize.lines, linesAvailable);
auto const columnsAvailable = *pageSize().columns - *topLeft.column;
auto const columnsToBeRendered = ColumnCount(min(columnsAvailable, *gridSize.columns));
auto const columnsAvailable = pageSize().columns - topLeft.column;
auto const columnsToBeRendered = ColumnCount(min(columnsAvailable, gridSize.columns));
auto const gapColor = RGBAColor {}; // TODO: _cursor.graphicsRendition.backgroundColor;

// TODO: make use of imageOffset and imageSize
auto const rasterizedImage = make_shared<RasterizedImage>(
std::move(image), alignmentPolicy, resizePolicy, gapColor, gridSize, _state->cellPixelSize);
const auto lastSixelBand = imageSize.height.value % 6;
const auto lastSixelBand = unbox(imageSize.height) % 6;
const LineOffset offset = [&]() {
auto offset =
LineOffset::cast_from(std::ceil(static_cast<float>(imageSize.height.value - lastSixelBand)
/ float(*_state->cellPixelSize.height)))
LineOffset::cast_from(std::ceil((imageSize.height - lastSixelBand).as<double>()
/ _state->cellPixelSize.height.as<double>()))
- 1 * (lastSixelBand == 0);
auto const h = imageSize.height.value - 1;
auto const h = unbox(imageSize.height) - 1;

Check warning on line 1955 in src/vtbackend/Screen.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: variable name 'h' is too short, expected at least 3 characters [readability-identifier-length] ```cpp auto const h = unbox(imageSize.height) - 1; ^ ```
// VT340 has this behavior where for some heights it text cursor is placed not
// at the final sixel line but a line above it.
// See
// https://github.com/hackerb9/vt340test/blob/main/glitches.md#text-cursor-is-left-one-row-too-high-for-certain-sixel-heights
if (h % 6 > h % _state->cellPixelSize.height.value)
if (h % 6 > h % unbox(_state->cellPixelSize.height))

Check warning on line 1960 in src/vtbackend/Screen.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: 6 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] ```cpp if (h % 6 > h % unbox(_state->cellPixelSize.height)) ^ ```
return offset - 1;

Check warning on line 1961 in src/vtbackend/Screen.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: statement should be inside braces [readability-braces-around-statements] ```suggestion if (h % 6 > h % unbox(_state->cellPixelSize.height)) { return offset - 1; } ```
return offset;
}();
if (*linesToBeRendered)

if (unbox(linesToBeRendered))
{
for (GridSize::Offset const offset: GridSize { linesToBeRendered, columnsToBeRendered })
{
Expand Down
1 change: 0 additions & 1 deletion src/vtbackend/SixelParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <crispy/range.h>

#include <array>
#include <memory>
#include <optional>
#include <string_view>
Expand Down
4 changes: 2 additions & 2 deletions src/vtbackend/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ struct GridSize

constexpr Offset makeOffset(int offset) noexcept
{
return Offset { LineOffset(offset / *_width), ColumnOffset(offset % *_width) };
return Offset { LineOffset(offset / unbox(_width)), ColumnOffset(offset % unbox(_width)) };
}
};

[[nodiscard]] constexpr iterator begin() const noexcept { return iterator { columns, 0 }; }
[[nodiscard]] constexpr iterator end() const noexcept { return iterator { columns, *columns * *lines }; }
[[nodiscard]] constexpr iterator end() const noexcept { return iterator { columns, unbox(columns) * unbox(lines) }; }
};

constexpr CellLocation operator+(CellLocation a, GridSize::Offset b) noexcept
Expand Down
2 changes: 1 addition & 1 deletion src/vtpty/PageSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct PageSize
LineCount lines;
ColumnCount columns;

[[nodiscard]] int area() const noexcept { return *lines * *columns; }
[[nodiscard]] int area() const noexcept { return unbox(lines) * unbox(columns); }
};

constexpr PageSize operator+(PageSize pageSize, LineCount lines) noexcept
Expand Down
5 changes: 4 additions & 1 deletion src/vtrasterizer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ Renderer::Renderer(vtbackend::PageSize pageSize,
Decorator hyperlinkNormal,
Decorator hyperlinkHover):
_atlasHashtableSlotCount { crispy::nextPowerOfTwo(atlasHashtableSlotCount.value) },
_atlasTileCount { std::max(atlasTileCount.value, static_cast<uint32_t>(pageSize.area())) },
_atlasTileCount {
std::max(atlasTileCount.value, static_cast<uint32_t>(pageSize.area() * 3))
}, // TODO instead of pagesize use size for fullscreen window
// 3 required for huge sixel images rendering due to initial page size smaller than
_atlasDirectMapping { atlasDirectMapping },
//.
_fontDescriptions { std::move(fontDescriptions) },
Expand Down

0 comments on commit c340e2b

Please sign in to comment.