[ansi] Optimize write
This commit is contained in:
parent
a35f8e340b
commit
962d4925b2
|
@ -384,7 +384,6 @@ ansi_print_image_rgb24 (const uint32_t *data,
|
||||||
void *closure)
|
void *closure)
|
||||||
{
|
{
|
||||||
image_t image (width, height, data, stride);
|
image_t image (width, height, data, stride);
|
||||||
char buf[16];
|
|
||||||
|
|
||||||
unsigned int rows = (height + CELL_H - 1) / CELL_H;
|
unsigned int rows = (height + CELL_H - 1) / CELL_H;
|
||||||
unsigned int cols = (width + CELL_W - 1) / CELL_W;
|
unsigned int cols = (width + CELL_W - 1) / CELL_W;
|
||||||
|
@ -401,8 +400,9 @@ ansi_print_image_rgb24 (const uint32_t *data,
|
||||||
{
|
{
|
||||||
if (last_bg != bi.bg)
|
if (last_bg != bi.bg)
|
||||||
{
|
{
|
||||||
snprintf (buf, sizeof (buf), "\e[%dm", 40 + bi.bg);
|
char buf[] = "\e[40m";
|
||||||
write_func (closure, (unsigned char *) buf, strlen (buf));
|
buf[3] += bi.bg;
|
||||||
|
write_func (closure, (unsigned char *) buf, 5);
|
||||||
last_bg = bi.bg;
|
last_bg = bi.bg;
|
||||||
}
|
}
|
||||||
write_func (closure, (unsigned char *) " ", 1);
|
write_func (closure, (unsigned char *) " ", 1);
|
||||||
|
@ -414,8 +414,10 @@ ansi_print_image_rgb24 (const uint32_t *data,
|
||||||
{
|
{
|
||||||
if (last_bg != bi.fg || last_fg != bi.bg)
|
if (last_bg != bi.fg || last_fg != bi.bg)
|
||||||
{
|
{
|
||||||
snprintf (buf, sizeof (buf), "\e[%d;%dm", 30 + bi.bg, 40 + bi.fg);
|
char buf[] = "\e[30;40m";
|
||||||
write_func (closure, (unsigned char *) buf, strlen (buf));
|
buf[3] += bi.bg;
|
||||||
|
buf[6] += bi.fg;
|
||||||
|
write_func (closure, (unsigned char *) buf, 8);
|
||||||
last_bg = bi.fg;
|
last_bg = bi.fg;
|
||||||
last_fg = bi.bg;
|
last_fg = bi.bg;
|
||||||
}
|
}
|
||||||
|
@ -424,8 +426,10 @@ ansi_print_image_rgb24 (const uint32_t *data,
|
||||||
{
|
{
|
||||||
if (last_bg != bi.bg || last_fg != bi.fg)
|
if (last_bg != bi.bg || last_fg != bi.fg)
|
||||||
{
|
{
|
||||||
snprintf (buf, sizeof (buf), "\e[%d;%dm", 40 + bi.bg, 30 + bi.fg);
|
char buf[] = "\e[40;30m";
|
||||||
write_func (closure, (unsigned char *) buf, strlen (buf));
|
buf[3] += bi.bg;
|
||||||
|
buf[6] += bi.fg;
|
||||||
|
write_func (closure, (unsigned char *) buf, 8);
|
||||||
last_bg = bi.bg;
|
last_bg = bi.bg;
|
||||||
last_fg = bi.fg;
|
last_fg = bi.fg;
|
||||||
}
|
}
|
||||||
|
@ -433,8 +437,7 @@ ansi_print_image_rgb24 (const uint32_t *data,
|
||||||
write_func (closure, (unsigned char *) c, strlen (c));
|
write_func (closure, (unsigned char *) c, strlen (c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snprintf (buf, sizeof (buf), "\e[0m\n"); /* Reset */
|
write_func (closure, (unsigned char *) "\e[0m\n", 5); /* Reset */
|
||||||
write_func (closure, (unsigned char *) buf, strlen (buf));
|
|
||||||
last_bg = last_fg = -1;
|
last_bg = last_fg = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue