sixel: add sixel_destroy()

This commit is contained in:
Daniel Eklöf 2020-02-22 00:23:19 +01:00
parent 6f84b79810
commit bb82b9fabc
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 22 additions and 14 deletions

17
sixel.c
View file

@ -37,14 +37,22 @@ sixel_init(struct terminal *term)
/* TODO: default palette */ /* TODO: default palette */
} }
void
sixel_destroy(struct sixel *sixel)
{
pixman_image_unref(sixel->pix);
free(sixel->data);
sixel->pix = NULL;
sixel->data = NULL;
}
void void
sixel_unhook(struct terminal *term) sixel_unhook(struct terminal *term)
{ {
free(term->sixel.palette); free(term->sixel.palette);
term->sixel.palette = NULL; term->sixel.palette = NULL;
LOG_DBG("generating %dx%d pixman image", term->sixel.row * 6, term->sixel.max_col);
if (term->sixel.col > term->sixel.max_col) if (term->sixel.col > term->sixel.max_col)
term->sixel.max_col = term->sixel.col; term->sixel.max_col = term->sixel.col;
term->sixel.row++; term->sixel.row++;
@ -58,6 +66,8 @@ sixel_unhook(struct terminal *term)
.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},
}; };
LOG_DBG("generating %dx%d pixman image", image.width, image.height);
image.pix = pixman_image_create_bits_no_clear( image.pix = pixman_image_create_bits_no_clear(
PIXMAN_a8r8g8b8, PIXMAN_a8r8g8b8,
image.width, image.height, image.width, image.height,
@ -66,8 +76,7 @@ sixel_unhook(struct terminal *term)
tll_foreach(term->sixel_images, it) { tll_foreach(term->sixel_images, it) {
if (it->item.pos.row == image.pos.row) { if (it->item.pos.row == image.pos.row) {
pixman_image_unref(it->item.pix); sixel_destroy(&it->item);
free(it->item.data);
tll_remove(term->sixel_images, it); tll_remove(term->sixel_images, it);
} }
} }

View file

@ -5,3 +5,5 @@
void sixel_init(struct terminal *term); void sixel_init(struct terminal *term);
void sixel_put(struct terminal *term, uint8_t c); void sixel_put(struct terminal *term, uint8_t c);
void sixel_unhook(struct terminal *term); void sixel_unhook(struct terminal *term);
void sixel_destroy(struct sixel *sixel);

View file

@ -19,12 +19,13 @@
#include "log.h" #include "log.h"
#include "async.h" #include "async.h"
#include "config.h"
#include "grid.h" #include "grid.h"
#include "render.h" #include "render.h"
#include "vt.h"
#include "selection.h" #include "selection.h"
#include "config.h" #include "sixel.h"
#include "slave.h" #include "slave.h"
#include "vt.h"
#define min(x, y) ((x) < (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y))
@ -994,10 +995,8 @@ term_destroy(struct terminal *term)
tll_free(term->ptmx_buffer); tll_free(term->ptmx_buffer);
tll_free(term->tab_stops); tll_free(term->tab_stops);
tll_foreach(term->sixel_images, it) { tll_foreach(term->sixel_images, it)
pixman_image_unref(it->item.pix); sixel_destroy(&it->item);
free(it->item.data);
}
tll_free(term->sixel_images); tll_free(term->sixel_images);
free(term->foot_exe); free(term->foot_exe);
@ -1538,8 +1537,7 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows
int new_row = (term->grid->offset + r) & (term->grid->num_rows - 1); int new_row = (term->grid->offset + r) & (term->grid->num_rows - 1);
if (img_top_row == new_row) { if (img_top_row == new_row) {
pixman_image_unref(it->item.pix); sixel_destroy(&it->item);
free(it->item.data);
tll_remove(term->sixel_images, it); tll_remove(term->sixel_images, it);
} }
} }
@ -1605,8 +1603,7 @@ term_scroll_reverse_partial(struct terminal *term,
int new_row = (term->grid->offset + r) & (term->grid->num_rows - 1); int new_row = (term->grid->offset + r) & (term->grid->num_rows - 1);
if (img_bottom_row == new_row) { if (img_bottom_row == new_row) {
pixman_image_unref(it->item.pix); sixel_destroy(&it->item);
free(it->item.data);
tll_remove(term->sixel_images, it); tll_remove(term->sixel_images, it);
} }
} }