Update sixdraw.

This commit is contained in:
CismonX 2021-01-08 08:21:28 +08:00
parent 1a9cbf9302
commit 53f467a336
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
1 changed files with 15 additions and 9 deletions

View File

@ -172,26 +172,32 @@ static void
print_sixel_dot(struct sixdraw_ctx *ctx, unsigned x, unsigned y)
{
char *sixel_seq = get_sixel_buffer();
size_t offset = sizeof(SIXEL_SEQ_HEAD) - 1;
offset += sprintf(sixel_seq + offset, "%d;%d", ctx->ch_width, ctx->ch_height);
size_t seq_len = sizeof(SIXEL_SEQ_HEAD) - 1;
seq_len += sprintf(sixel_seq + seq_len, "%d;%d", ctx->ch_width, ctx->ch_height);
// Select color
// Select color.
unsigned red, green, blue;
get_sixel_color(ctx->line_color, &red, &green, &blue);
offset += sprintf(sixel_seq + offset, "#0;2;%d;%d;%d#0", red, green, blue);
seq_len += sprintf(sixel_seq + seq_len, "#0;2;%d;%d;%d#0", red, green, blue);
// Move cursor
// Move cursor.
unsigned row = y / ctx->ch_height + 1;
unsigned col = x / ctx->ch_width + 1;
dprintf(ctx->out_fd, CTLSEQS_CUP("%d", "%d"), row, col);
// Print dot
// Draw dot.
row = y % ctx->ch_height;
col = x % ctx->ch_width;
offset += sprintf(sixel_seq + offset, "%.*s", row / 6, "----------------");
offset += sprintf(sixel_seq + offset, "!%u?%c" CTLSEQS_ST, col, (1 << row % 6) + 0x3F);
seq_len += sprintf(sixel_seq + seq_len, "%.*s", row / 6, "------------------------");
seq_len += sprintf(sixel_seq + seq_len, "!%u?%c" CTLSEQS_ST, col, (1 << row % 6) + 0x3F);
write(ctx->out_fd, sixel_seq, offset);
// Output sixel sequence.
do {
ssize_t nbytes = write(ctx->out_fd, sixel_seq, seq_len);
if (nbytes > 0) {
seq_len -= nbytes;
}
} while (seq_len > 0);
}
static bool