Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 166 additions & 48 deletions README.md

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions src/XTerm.NET.Tests/Graphics/ImageAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,53 @@ public static (int Col, int Row)? TileAt(Terminal terminal, int col, int screenR
return (source.X / image.CellWidth, source.Y / image.CellHeight);
}

/// <summary>The Sixel pixels on a screen row, or null when no Sixel has painted it.</summary>
public static SixelStrip? StripOn(Terminal terminal, int screenRow)
=> terminal.Buffer.Lines[terminal.Buffer.YBase + screenRow]?.Sixel;

/// <summary>
/// Whether a screen position shows Sixel pixels -- the question <see cref="IsImageAt"/> asks of a
/// Kitty run, asked of the pixels Sixel paints instead.
/// </summary>
public static bool IsSixelAt(Terminal terminal, int col, int screenRow)
{
var line = terminal.Buffer.Lines[terminal.Buffer.YBase + screenRow];
return line?.Sixel is { } strip && col < line.Length && strip.HasPixelsAt(col);
}

/// <summary>
/// The Sixel pixel at (<paramref name="x"/>, <paramref name="y"/>) inside a cell, as RGBA, or null
/// when the cell shows none.
/// </summary>
public static (byte R, byte G, byte B, byte A)? SixelPixel(Terminal terminal, int col, int screenRow, int x = 0, int y = 0)
{
if (!IsSixelAt(terminal, col, screenRow))
return null;

var strip = StripOn(terminal, screenRow)!;
var offset = y * strip.Stride + (col * strip.CellWidth + x) * TerminalImage.BytesPerPixel;
var p = strip.Pixels.Span;
return (p[offset + 2], p[offset + 1], p[offset], p[offset + 3]);
}

/// <summary>How many cells of the buffer show Sixel pixels, clipped to each line's width.</summary>
public static int VisibleSixelCells(Terminal terminal)
{
var count = 0;
for (var i = 0; i < terminal.Buffer.Lines.Length; i++)
{
var line = terminal.Buffer.Lines[i];
if (line?.Sixel is not { } strip)
continue;

for (var c = 0; c < System.Math.Min(strip.Columns, line.Length); c++)
if (strip.HasPixelsAt(c))
count++;
}

return count;
}

/// <summary>Every run on a screen row, in the order they were placed.</summary>
public static IReadOnlyList<LinePlacement> PlacementsOn(Terminal terminal, int screenRow)
{
Expand Down
Loading
Loading