Skip to content

Commit

Permalink
Only fill rows needed for transparency at bottom of sixels.
Browse files Browse the repository at this point in the history
Little optimization, to not waste cycles; only the bottom sliver that
is longer than the original frame buffer needs to be transparency
filled. The other data is filled from the original framebuffer.
  • Loading branch information
hzeller committed Jul 9, 2023
1 parent 55e7b88 commit 28e973a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/framebuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ uint8_t **Framebuffer::row_data() {

void Framebuffer::AlphaComposeBackground(const bgcolor_query &get_bg,
rgba_t pattern_col, int pwidth,
int pheight) {
int pheight, int start_row) {
if (!get_bg) return; // -b none

iterator pos = begin();
iterator pos = begin() + (start_row * width());
for (/**/; pos < end(); ++pos) {
if (pos->a < 0xff) break; // First pixel that is transparent.
}
if (pos == end()) return; // Nothing transparent all the way to the end.
if (pos >= end()) return; // Nothing transparent all the way to the end.

// Need to do alpha blending, so only now we have to retrieve the bgcolor.
const rgba_t bgcolor = get_bg();
Expand Down
6 changes: 5 additions & 1 deletion src/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ class Framebuffer {
// pixel will be the pattern color. That creates a 'checkerboard-pattern'
// sometimes used to display transparent pictures.
//
// "start_row" is to start the transparency filling further down; it is
// only really needed as an optimization in the sixels canvas.
//
// This Alpha compositing merges in the linearized colors domain.
using bgcolor_query = std::function<rgba_t()>;
void AlphaComposeBackground(const bgcolor_query &get_bg, rgba_t pattern,
int pattern_width, int pattern_height);
int pattern_width, int pattern_height,
int start_row = 0);

// The raw internal buffer containing width()*height() pixels organized
// from top left to bottom right.
Expand Down
3 changes: 2 additions & 1 deletion src/sixel-canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ void SixelCanvas::Send(int x, int dy, const Framebuffer &fb_orig,
fb->AlphaComposeBackground(options_.bgcolor_getter,
options_.bg_pattern_color,
options_.pattern_size * options_.cell_x_px,
options_.pattern_size * options_.cell_y_px / 2);
options_.pattern_size * options_.cell_y_px / 2,
fb_orig.height());
// .. overwrite with whatever is in the orig.
std::copy(fb_orig.begin(), fb_orig.end(), fb->begin());

Expand Down

0 comments on commit 28e973a

Please sign in to comment.