DRYer
This commit is contained in:
parent
d76e757d53
commit
c0e336a971
@ -250,7 +250,7 @@ def write_header(text: str, path: str) -> None:
|
|||||||
def graphics_parser() -> None:
|
def graphics_parser() -> None:
|
||||||
flag = frozenset
|
flag = frozenset
|
||||||
keymap: KeymapType = {
|
keymap: KeymapType = {
|
||||||
'a': ('action', flag('tTqpdf')),
|
'a': ('action', flag('tTqpdfa')),
|
||||||
'd': ('delete_action', flag('aAiIcCfFnNpPqQxXyYzZ')),
|
'd': ('delete_action', flag('aAiIcCfFnNpPqQxXyYzZ')),
|
||||||
't': ('transmission_type', flag('dfts')),
|
't': ('transmission_type', flag('dfts')),
|
||||||
'o': ('compressed', flag('z')),
|
'o': ('compressed', flag('z')),
|
||||||
|
|||||||
@ -774,13 +774,16 @@ grman_update_layers(GraphicsManager *self, unsigned int scrolled_by, float scree
|
|||||||
|
|
||||||
// Animation {{{
|
// Animation {{{
|
||||||
#define DEFAULT_GAP 40
|
#define DEFAULT_GAP 40
|
||||||
|
#define _frame_number num_lines
|
||||||
|
#define _other_frame_number num_cells
|
||||||
|
#define _gap z_index
|
||||||
|
|
||||||
static Image*
|
static Image*
|
||||||
handle_animation_frame_load_command(GraphicsManager *self, GraphicsCommand *g, Image *img, const uint8_t *payload) {
|
handle_animation_frame_load_command(GraphicsManager *self, GraphicsCommand *g, Image *img, const uint8_t *payload) {
|
||||||
uint32_t frame_number = g->num_lines, fmt = g->format ? g->format : RGBA;
|
uint32_t frame_number = g->_frame_number, fmt = g->format ? g->format : RGBA;
|
||||||
if (!frame_number || frame_number > img->extra_framecnt + 2) frame_number = img->extra_framecnt + 2;
|
if (!frame_number || frame_number > img->extra_framecnt + 2) frame_number = img->extra_framecnt + 2;
|
||||||
bool is_new_frame = frame_number == img->extra_framecnt + 2;
|
bool is_new_frame = frame_number == img->extra_framecnt + 2;
|
||||||
g->num_lines = frame_number;
|
g->_frame_number = frame_number;
|
||||||
unsigned char tt = g->transmission_type ? g->transmission_type : 'd';
|
unsigned char tt = g->transmission_type ? g->transmission_type : 'd';
|
||||||
size_t w = img->width, h = img->height;
|
size_t w = img->width, h = img->height;
|
||||||
if (tt == 'd' && self->currently_loading_data_for.image_id == img->internal_id) {
|
if (tt == 'd' && self->currently_loading_data_for.image_id == img->internal_id) {
|
||||||
@ -821,17 +824,17 @@ handle_animation_frame_load_command(GraphicsManager *self, GraphicsCommand *g, I
|
|||||||
if (is_new_frame) {
|
if (is_new_frame) {
|
||||||
key.frame_id = ++img->frame_id_counter;
|
key.frame_id = ++img->frame_id_counter;
|
||||||
if (!key.frame_id) key.frame_id = ++img->frame_id_counter;
|
if (!key.frame_id) key.frame_id = ++img->frame_id_counter;
|
||||||
if (g->num_cells) {
|
if (g->_other_frame_number) {
|
||||||
ImageAndFrame other = { .image_id = img->internal_id };
|
ImageAndFrame other = { .image_id = img->internal_id };
|
||||||
if (g->num_cells > 1) {
|
if (g->_other_frame_number > 1) {
|
||||||
other.frame_id = g->num_cells - 2;
|
other.frame_id = g->_other_frame_number - 2;
|
||||||
if (other.frame_id >= img->extra_framecnt) {
|
if (other.frame_id >= img->extra_framecnt) {
|
||||||
FAIL("ENODATA", "No data for frame with number: %u found in image: %u", g->num_cells, img->client_id);
|
FAIL("ENODATA", "No data for frame with number: %u found in image: %u", g->_other_frame_number, img->client_id);
|
||||||
}
|
}
|
||||||
other.frame_id = img->extra_frames[other.frame_id].id;
|
other.frame_id = img->extra_frames[other.frame_id].id;
|
||||||
}
|
}
|
||||||
if (!read_from_cache(self, other, &base_data, &data_sz)) {
|
if (!read_from_cache(self, other, &base_data, &data_sz)) {
|
||||||
FAIL("ENODATA", "No data for frame with number: %u found in image: %u", g->num_cells, img->client_id);
|
FAIL("ENODATA", "No data for frame with number: %u found in image: %u", g->_other_frame_number, img->client_id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
base_data = calloc(1, expected_data_sz);
|
base_data = calloc(1, expected_data_sz);
|
||||||
@ -879,7 +882,7 @@ handle_animation_frame_load_command(GraphicsManager *self, GraphicsCommand *g, I
|
|||||||
img->extra_frames[frame_number - 2].gap = DEFAULT_GAP;
|
img->extra_frames[frame_number - 2].gap = DEFAULT_GAP;
|
||||||
img->extra_frames[frame_number - 2].id = key.frame_id;
|
img->extra_frames[frame_number - 2].id = key.frame_id;
|
||||||
}
|
}
|
||||||
if (g->z_index > 0) img->extra_frames[frame_number - 2].gap = g->z_index;
|
if (g->_gap > 0) img->extra_frames[frame_number - 2].gap = g->_gap;
|
||||||
}
|
}
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
@ -897,7 +900,7 @@ handle_delete_frame_command(GraphicsManager *self, const GraphicsCommand *g, boo
|
|||||||
REPORT_ERROR("Animation command refers to non-existent image with id: %u and number: %u", g->id, g->image_number);
|
REPORT_ERROR("Animation command refers to non-existent image with id: %u and number: %u", g->id, g->image_number);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
uint32_t frame_number = MIN(img->extra_framecnt + 1, g->num_lines);
|
uint32_t frame_number = MIN(img->extra_framecnt + 1, g->_frame_number);
|
||||||
if (!frame_number) frame_number = 1;
|
if (!frame_number) frame_number = 1;
|
||||||
if (!img->extra_framecnt) return g->delete_action == 'F' ? img : NULL;
|
if (!img->extra_framecnt) return g->delete_action == 'F' ? img : NULL;
|
||||||
ImageAndFrame key = {.image_id=img->internal_id};
|
ImageAndFrame key = {.image_id=img->internal_id};
|
||||||
|
|||||||
25
kitty/parse-graphics-command.h
generated
25
kitty/parse-graphics-command.h
generated
@ -144,8 +144,9 @@ static inline void parse_graphics_code(Screen *screen,
|
|||||||
|
|
||||||
case action: {
|
case action: {
|
||||||
g.action = screen->parser_buf[pos++] & 0xff;
|
g.action = screen->parser_buf[pos++] & 0xff;
|
||||||
if (g.action != 'p' && g.action != 't' && g.action != 'q' &&
|
if (g.action != 'q' && g.action != 'd' && g.action != 'p' &&
|
||||||
g.action != 'f' && g.action != 'T' && g.action != 'd') {
|
g.action != 't' && g.action != 'T' && g.action != 'f' &&
|
||||||
|
g.action != 'a') {
|
||||||
REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag "
|
REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag "
|
||||||
"value for action: 0x%x",
|
"value for action: 0x%x",
|
||||||
g.action);
|
g.action);
|
||||||
@ -155,16 +156,16 @@ static inline void parse_graphics_code(Screen *screen,
|
|||||||
|
|
||||||
case delete_action: {
|
case delete_action: {
|
||||||
g.delete_action = screen->parser_buf[pos++] & 0xff;
|
g.delete_action = screen->parser_buf[pos++] & 0xff;
|
||||||
if (g.delete_action != 'x' && g.delete_action != 'z' &&
|
if (g.delete_action != 'F' && g.delete_action != 'n' &&
|
||||||
g.delete_action != 'X' && g.delete_action != 'i' &&
|
g.delete_action != 'x' && g.delete_action != 'I' &&
|
||||||
g.delete_action != 'n' && g.delete_action != 'a' &&
|
g.delete_action != 'p' && g.delete_action != 'i' &&
|
||||||
g.delete_action != 'F' && g.delete_action != 'I' &&
|
g.delete_action != 'C' && g.delete_action != 'Q' &&
|
||||||
g.delete_action != 'f' && g.delete_action != 'Q' &&
|
g.delete_action != 'A' && g.delete_action != 'z' &&
|
||||||
g.delete_action != 'y' && g.delete_action != 'C' &&
|
g.delete_action != 'y' && g.delete_action != 'c' &&
|
||||||
g.delete_action != 'q' && g.delete_action != 'Y' &&
|
g.delete_action != 'Z' && g.delete_action != 'N' &&
|
||||||
g.delete_action != 'p' && g.delete_action != 'Z' &&
|
g.delete_action != 'X' && g.delete_action != 'q' &&
|
||||||
g.delete_action != 'A' && g.delete_action != 'P' &&
|
g.delete_action != 'P' && g.delete_action != 'f' &&
|
||||||
g.delete_action != 'N' && g.delete_action != 'c') {
|
g.delete_action != 'Y' && g.delete_action != 'a') {
|
||||||
REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag "
|
REPORT_ERROR("Malformed GraphicsCommand control block, unknown flag "
|
||||||
"value for delete_action: 0x%x",
|
"value for delete_action: 0x%x",
|
||||||
g.delete_action);
|
g.delete_action);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user