forked from hundredrabbits/Orca-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgbuffer.c
80 lines (77 loc) · 2.12 KB
/
gbuffer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "gbuffer.h"
void gbuffer_copy_subrect(Glyph *src, Glyph *dest, Usz src_height,
Usz src_width, Usz dest_height, Usz dest_width,
Usz src_y, Usz src_x, Usz dest_y, Usz dest_x,
Usz height, Usz width) {
if (src_height <= src_y || src_width <= src_x || dest_height <= dest_y ||
dest_width <= dest_x)
return;
Usz ny_0 = src_height - src_y;
Usz ny_1 = dest_height - dest_y;
Usz ny = height;
if (ny_0 < ny)
ny = ny_0;
if (ny_1 < ny)
ny = ny_1;
if (ny == 0)
return;
Usz row_copy_0 = src_width - src_x;
Usz row_copy_1 = dest_width - dest_x;
Usz row_copy = width;
if (row_copy_0 < row_copy)
row_copy = row_copy_0;
if (row_copy_1 < row_copy)
row_copy = row_copy_1;
Usz copy_bytes = row_copy * sizeof(Glyph);
Glyph *src_p = src + src_y * src_width + src_x;
Glyph *dest_p = dest + dest_y * dest_width + dest_x;
Isz src_stride;
Isz dest_stride;
if (src_y >= dest_y) {
src_stride = (Isz)src_width;
dest_stride = (Isz)dest_width;
} else {
src_p += (ny - 1) * src_width;
dest_p += (ny - 1) * dest_width;
src_stride = -(Isz)src_width;
dest_stride = -(Isz)dest_width;
}
Usz iy = 0;
for (;;) {
memmove(dest_p, src_p, copy_bytes);
++iy;
if (iy == ny)
break;
src_p += src_stride;
dest_p += dest_stride;
}
}
void gbuffer_fill_subrect(Glyph *gbuffer, Usz f_height, Usz f_width, Usz y,
Usz x, Usz height, Usz width, Glyph fill_char) {
if (y >= f_height || x >= f_width)
return;
Usz rows_0 = f_height - y;
Usz rows = height;
if (rows_0 < rows)
rows = rows_0;
if (rows == 0)
return;
Usz columns_0 = f_width - x;
Usz columns = width;
if (columns_0 < columns)
columns = columns_0;
Usz fill_bytes = columns * sizeof(Glyph);
Glyph *p = gbuffer + y * f_width + x;
Usz iy = 0;
for (;;) {
memset(p, fill_char, fill_bytes);
++iy;
if (iy == rows)
break;
p += f_width;
}
}
void mbuffer_clear(Mark *mbuf, Usz height, Usz width) {
Usz cleared_size = height * width;
memset(mbuf, 0, cleared_size);
}