mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-05 07:15:30 -04:00
sixel: use a struct coord for current sixel position
This commit is contained in:
parent
1b728dcac8
commit
f193695960
2 changed files with 33 additions and 35 deletions
46
sixel.c
46
sixel.c
|
|
@ -20,8 +20,7 @@ sixel_init(struct terminal *term)
|
||||||
assert(term->sixel.image.data == NULL);
|
assert(term->sixel.image.data == NULL);
|
||||||
|
|
||||||
term->sixel.state = SIXEL_GROUND;
|
term->sixel.state = SIXEL_GROUND;
|
||||||
term->sixel.row = 0;
|
term->sixel.pos = (struct coord){0, 0};
|
||||||
term->sixel.col = 0;
|
|
||||||
term->sixel.color_idx = 0;
|
term->sixel.color_idx = 0;
|
||||||
term->sixel.max_col = 0;
|
term->sixel.max_col = 0;
|
||||||
term->sixel.param = 0;
|
term->sixel.param = 0;
|
||||||
|
|
@ -53,16 +52,16 @@ sixel_unhook(struct terminal *term)
|
||||||
free(term->sixel.palette);
|
free(term->sixel.palette);
|
||||||
term->sixel.palette = NULL;
|
term->sixel.palette = NULL;
|
||||||
|
|
||||||
if (term->sixel.col > term->sixel.max_col)
|
if (term->sixel.pos.col > term->sixel.max_col)
|
||||||
term->sixel.max_col = term->sixel.col;
|
term->sixel.max_col = term->sixel.pos.col;
|
||||||
term->sixel.row++;
|
term->sixel.pos.row++;
|
||||||
term->sixel.col = 0;
|
term->sixel.pos.col = 0;
|
||||||
|
|
||||||
struct sixel image = {
|
struct sixel image = {
|
||||||
.data = term->sixel.image.data,
|
.data = term->sixel.image.data,
|
||||||
.width = term->sixel.max_col,
|
.width = term->sixel.max_col,
|
||||||
.height = term->sixel.row * 6,
|
.height = term->sixel.pos.row * 6,
|
||||||
.rows = (term->sixel.row * 6 + term->cell_height - 1) / term->cell_height,
|
.rows = (term->sixel.pos.row * 6 + term->cell_height - 1) / term->cell_height,
|
||||||
.pos = (struct coord){term->cursor.point.col, term->grid->offset + term->cursor.point.row},
|
.pos = (struct coord){term->cursor.point.col, term->grid->offset + term->cursor.point.row},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -87,8 +86,7 @@ sixel_unhook(struct terminal *term)
|
||||||
term->sixel.image.width = 0;
|
term->sixel.image.width = 0;
|
||||||
term->sixel.image.height = 0;
|
term->sixel.image.height = 0;
|
||||||
term->sixel.max_col = 0;
|
term->sixel.max_col = 0;
|
||||||
term->sixel.col = 0;
|
term->sixel.pos = (struct coord){0, 0};
|
||||||
term->sixel.row = 0;
|
|
||||||
|
|
||||||
const size_t lines = (image.height + term->cell_height - 1) / term->cell_height;
|
const size_t lines = (image.height + term->cell_height - 1) / term->cell_height;
|
||||||
for (size_t i = 0; i < lines; i++)
|
for (size_t i = 0; i < lines; i++)
|
||||||
|
|
@ -156,26 +154,26 @@ sixel_add(struct terminal *term, uint32_t color, uint8_t sixel)
|
||||||
{
|
{
|
||||||
//LOG_DBG("adding sixel %02hhx using color 0x%06x", sixel, color);
|
//LOG_DBG("adding sixel %02hhx using color 0x%06x", sixel, color);
|
||||||
|
|
||||||
if (term->sixel.col >= term->sixel.image.width ||
|
if (term->sixel.pos.col >= term->sixel.image.width ||
|
||||||
term->sixel.row * 6 >= term->sixel.image.height)
|
term->sixel.pos.row * 6 >= term->sixel.image.height)
|
||||||
{
|
{
|
||||||
resize(term,
|
resize(term,
|
||||||
max(term->sixel.max_col, term->sixel.col + 1),
|
max(term->sixel.max_col, term->sixel.pos.col + 1),
|
||||||
(term->sixel.row + 1) * 6);
|
(term->sixel.pos.row + 1) * 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++, sixel >>= 1) {
|
for (int i = 0; i < 6; i++, sixel >>= 1) {
|
||||||
if (sixel & 1) {
|
if (sixel & 1) {
|
||||||
size_t pixel_row = term->sixel.row * 6 + i;
|
size_t pixel_row = term->sixel.pos.row * 6 + i;
|
||||||
size_t stride = term->sixel.image.width;
|
size_t stride = term->sixel.image.width;
|
||||||
size_t idx = pixel_row * stride + term->sixel.col;
|
size_t idx = pixel_row * stride + term->sixel.pos.col;
|
||||||
term->sixel.image.data[idx] = term->colors.alpha / 256 << 24 | color;
|
term->sixel.image.data[idx] = term->colors.alpha / 256 << 24 | color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(sixel == 0);
|
assert(sixel == 0);
|
||||||
|
|
||||||
term->sixel.col++;
|
term->sixel.pos.col++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -196,16 +194,16 @@ sixel_sixel(struct terminal *term, uint8_t c)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '$':
|
case '$':
|
||||||
if (term->sixel.col > term->sixel.max_col)
|
if (term->sixel.pos.col > term->sixel.max_col)
|
||||||
term->sixel.max_col = term->sixel.col;
|
term->sixel.max_col = term->sixel.pos.col;
|
||||||
term->sixel.col = 0;
|
term->sixel.pos.col = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
if (term->sixel.col > term->sixel.max_col)
|
if (term->sixel.pos.col > term->sixel.max_col)
|
||||||
term->sixel.max_col = term->sixel.col;
|
term->sixel.max_col = term->sixel.pos.col;
|
||||||
term->sixel.row++;
|
term->sixel.pos.row++;
|
||||||
term->sixel.col = 0;
|
term->sixel.pos.col = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '!':
|
case '!':
|
||||||
|
|
|
||||||
22
terminal.h
22
terminal.h
|
|
@ -356,21 +356,21 @@ struct terminal {
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
enum { SIXEL_GROUND, SIXEL_REPEAT, SIXEL_RASTER, SIXEL_COLOR, SIXEL_COLOR_SPEC} state;
|
enum { SIXEL_GROUND, SIXEL_REPEAT, SIXEL_RASTER, SIXEL_COLOR, SIXEL_COLOR_SPEC} state;
|
||||||
int row;
|
|
||||||
int col;
|
struct coord pos; /* Current sixel coordinate */
|
||||||
int color_idx;
|
int color_idx; /* Current palette index */
|
||||||
int max_col;
|
int max_col; /* Largest column index we've seen (aka the image width) */
|
||||||
unsigned params[4];
|
uint32_t *palette; /* Color palette */
|
||||||
uint32_t *palette;
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint32_t *data;
|
uint32_t *data; /* Raw image data, in ARGB */
|
||||||
int width;
|
int width; /* Image width, in pixels */
|
||||||
int height;
|
int height; /* Image height, in pixels */
|
||||||
} image;
|
} image;
|
||||||
|
|
||||||
unsigned int param;
|
unsigned params[4]; /* Collected parmaeters, for RASTER, COLOR_SPEC */
|
||||||
unsigned param_idx;
|
unsigned int param; /* Currently collecting parameter, for RASTER, COLOR_SPEC and REPEAT */
|
||||||
|
unsigned param_idx; /* Parameters seen */
|
||||||
} sixel;
|
} sixel;
|
||||||
|
|
||||||
tll(struct sixel) sixel_images;
|
tll(struct sixel) sixel_images;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue