From 6736d6764ba2541eeaa48b45b002acadb20b9b05 Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Mon, 1 Oct 2018 21:38:19 +0800 Subject: mkf uses graph_st --- csrc/mkf/graph_struct.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 csrc/mkf/graph_struct.c (limited to 'csrc/mkf/graph_struct.c') 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 + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include +#include +#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; +} -- cgit v1.2.3