From e5898ad4b0d004190bc270f13deaa019af6fa144 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 29 Sep 2017 10:00:21 +0530 Subject: [PATCH] More work on displaying images --- kitty/graphics.c | 15 +++++++++++++++ kitty/graphics.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/kitty/graphics.c b/kitty/graphics.c index c175ad224..3d3480711 100644 --- a/kitty/graphics.c +++ b/kitty/graphics.c @@ -320,6 +320,7 @@ handle_add_command(GraphicsManager *self, const GraphicsCommand *g, const uint8_ img->data_loaded = false; free_refs_data(img); *is_dirty = true; + self->layers_dirty = true; } else { img->internal_id = internal_id_counter++; img->client_id = g->id; @@ -475,6 +476,7 @@ handle_put_command(GraphicsManager *self, const GraphicsCommand *g, Cursor *c, b if (img->refs == NULL) { REPORT_ERROR("Out of memory growing image refs array"); img->refcap = 0; return; } } *is_dirty = true; + self->layers_dirty = true; ImageRef *ref = NULL; for (size_t i=0; i < img->refcnt; i++) { if ((unsigned)img->refs[i].start_row == c->x && (unsigned)img->refs[i].start_column == c->y) { @@ -486,6 +488,19 @@ handle_put_command(GraphicsManager *self, const GraphicsCommand *g, Cursor *c, b ref->src_x = g->x_offset; ref->src_y = g->y_offset; ref->src_width = g->width ? g->width : img->width; ref->src_height = g->height ? g->height : img->height; ref->src_width = MIN(ref->src_width, img->width - (img->width > ref->src_x ? ref->src_x : img->width)); ref->src_height = MIN(ref->src_height, img->height - (img->height > ref->src_y ? ref->src_y : img->height)); + ref->z_index = g->z_index; + ref->start_row = c->y; ref->start_column = c->x; + uint32_t num_cols = g->num_cells, num_rows = g->num_lines; + if (num_cols == 0) { + num_cols = ref->src_width / global_state.cell_width; + if (ref->src_width > num_cols * global_state.cell_width) num_cols += 1; + } + if (num_rows == 0) { + num_rows = ref->src_height / global_state.cell_height; + if (ref->src_height > num_rows * global_state.cell_height) num_rows += 1; + } + ref->end_row = ref->start_row + num_rows; + ref->end_column = ref->start_column + num_cols; } // }}} diff --git a/kitty/graphics.h b/kitty/graphics.h index fbe1470da..ef1406a32 100644 --- a/kitty/graphics.h +++ b/kitty/graphics.h @@ -13,6 +13,8 @@ typedef struct { uint32_t width, height, x_offset, y_offset, data_height, data_width, num_cells, num_lines; int32_t z_index; size_t payload_sz; + + bool layers_dirty; } GraphicsCommand; typedef struct { @@ -30,6 +32,7 @@ typedef struct { typedef struct { uint32_t src_width, src_height, src_x, src_y; uint32_t dest_x_offset, dest_y_offset; + int z_index; int start_row, start_column, end_row, end_column; } ImageRef;