Add dynamic image to sixel api#2
Merged
Merged
Conversation
The image<> template requires compile-time W and H, which is awkward
for callers that produce arbitrary-resolution frames at runtime
(terminal previews, decoded video). Add two free functions in
namespace constixel that take RGBA bytes plus runtime width/height
and emit a sixel stream via a char-callback:
rgba_to_sixel(rgba, w, h, char_out)
Quantises to constixel's built-in 256-color palette
(format_8bit::quant). Use when input has more than 256 distinct
colors or when the caller has no preferred palette.
rgba_to_sixel(rgba, w, h, palette, char_out)
Uses a caller-supplied palette of up to 256 sRGB byte triples.
The built-in quantiser is bypassed; each pixel maps to its
squared-sRGB-distance nearest entry. Use when the caller already
knows the exact palette of the source data.
Implementation reuses the existing sixel header/raster/end helpers
in spirit but inlines a runtime-sized encoder loop with run-length
compression matching sixel_image<W,H,...>. No changes to the
compile-time-sized image<> path.
Replaces the freestanding rgba_to_sixel free functions with a proper sibling of image<F,W,H>: - runtime_palette: shared <=256-entry palette type (BGR-packed). - format_8bit_dyn: 8-bit indexed format with runtime W/H carried by parameter (vs format_8bit's compile-time W/H). Default palette delegates to format_8bit::quant; custom palette uses runtime_palette. - dynamic_image<Ops>: runtime-sized image, mirrors image<F,W,H> surface (blit_RGBA, sixel, sixel_to_cout under CONSTIXEL_ENABLE_COUT). Custom palette also wired into the existing static image<F,W,H> via new constructor overloads that take std::span<const std::array<u8,3>>, gated on the format exposing a runtime_palette typedef. blit_RGBA and sixel members dispatch through if-constexpr to *_with_palette helpers when has_custom_palette_ is set; the default code path is unchanged. format_8bit gains sixel_with_palette and blit_RGBA_with_palette static methods that delegate to format_8bit_dyn (defined out-of-line to break the circular header dependency). No duplication of the sixel encoder between compile-time and runtime image types.
Microsoft Terminal #17887: when P2 is 0 or omitted in the sixel introducer, an arbitrary number of cell-height rows past the image get filled with an arbitrary color (uninitialized memory). Setting P2=1 marks unset pixels as transparent and sidesteps the bug. For fully-painted images (every pixel covered, as dynamic_image produces) P2=0 vs P2=1 are visually identical — but only P2=1 renders correctly under WT >=1.22 sixel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.