Mirai's Miscellaneous Misadventures

M54 / core / images.c

1/* license: AGPLv3 or later */
2/* copyright 2024 zamfofex */
3
4#include "../mimimi.h"
5
6void mimimi_stamp(struct mimimi_image *target, int x1, int y1, struct mimimi_image *source)
7{
8	int x, y;
9	int x0, y0;
10	int x2, y2;
11	int width, height;
12	unsigned char color;
13	
14	x0 = 0;
15	y0 = 0;
16	
17	if (x1 < 0) x0 = -x1;
18	if (y1 < 0) y0 = -y1;
19	
20	width = source->width;
21	height = source->height;
22	
23	if (width + x1 > target->width) width = target->width - x1;
24	if (height + y1 > target->height) height = target->height - y1;
25	
26	for (y = y0 ; y < height ; y++) {
27		for (x = x0 ; x < width ; x++) {
28			color = source->colors[x + y * source->width];
29			if (color == 0) continue;
30			x2 = x + x1;
31			y2 = y + y1;
32			target->colors[x2 + y2 * target->width] = color;
33		}
34	}
35}