diff options
author | Iru Cai <mytbk920423@gmail.com> | 2018-10-01 21:38:19 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2018-10-01 21:38:19 +0800 |
commit | 6736d6764ba2541eeaa48b45b002acadb20b9b05 (patch) | |
tree | 61a6814db04e2550379e1fbbfd5e4a419c682af9 /csrc/mkf/graph_struct.c | |
parent | 63d7007905047e5f488e179a56d861dfaa17aa90 (diff) | |
download | rich4-6736d6764ba2541eeaa48b45b002acadb20b9b05.tar.xz |
mkf uses graph_st
Diffstat (limited to 'csrc/mkf/graph_struct.c')
-rw-r--r-- | csrc/mkf/graph_struct.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/csrc/mkf/graph_struct.c b/csrc/mkf/graph_struct.c new file mode 100644 index 0000000..52aa207 --- /dev/null +++ b/csrc/mkf/graph_struct.c @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2018 Iru Cai <mytbk920423@gmail.com> + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include <stdlib.h> +#include <string.h> +#include "graph_struct.h" + +static inline void mem_copy_words(void *dst, void *src, size_t n) +{ + memcpy(dst, src, n*2); +} + +struct graph_st * allocate_graph_st(int w, int h, int x, int y) +{ + struct graph_st * newst = (struct graph_st *)malloc(w * h * 2 + sizeof(graph_st)); + newst->width = w; + newst->height = h; + newst->x = x; + newst->y = y; + newst->gdata = newst->data; + return newst; +} + +/* crop graph a1 starting at (x, y) as laft-top coordinate, + * and get graph a2 with size w*h. + * + * this function looks buggy and can crash the game */ + +struct graph_st * crop_graph(struct graph_st *a1, struct graph_st *a2, int x, int y, int w, int h) +{ + if (a2 == NULL) { + a2 = allocate_graph_st(w, h, 0, 0); + } + + int16_t *src = &a1->gdata[a1->width * y + x]; + int16_t *dst = a2->gdata; + + for (int i = 0; i < h; i++) { + mem_copy_words(esi, ebx, w); + dst = dst + w; + src = src + a1->width; + } + return a2; +} |