-
Notifications
You must be signed in to change notification settings - Fork 2
/
olive.c
575 lines (516 loc) · 17.2 KB
/
olive.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
#ifndef OLIVE_C_
#define OLIVE_C_
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#ifndef OLIVECDEF
#define OLIVECDEF static inline
#endif
#ifndef OLIVEC_AA_RES
#define OLIVEC_AA_RES 2
#endif
#define OLIVEC_SWAP(T, a, b) do { T t = a; a = b; b = t; } while (0)
#define OLIVEC_SIGN(T, x) ((T)((x) > 0) - (T)((x) < 0))
#define OLIVEC_ABS(T, x) (OLIVEC_SIGN(T, x)*(x))
typedef struct {
size_t width, height;
const char *glyphs;
} Olivec_Font;
#define DEFAULT_FONT_HEIGHT 6
#define DEFAULT_FONT_WIDTH 6
static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] = {
['a'] = {
{0, 0, 0, 0, 0},
{0, 1, 1, 0, 0},
{0, 0, 0, 1, 0},
{0, 1, 1, 1, 0},
{1, 0, 0, 1, 0},
{0, 1, 1, 1, 0},
},
['b'] = {
{1, 0, 0, 0, 0},
{1, 1, 1, 0, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 1, 1, 0, 0},
},
['c'] = {
{0, 0, 0, 0, 0},
{0, 1, 1, 0, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 1, 0},
{0, 1, 1, 0, 0},
},
['d'] = {
{0, 0, 0, 1, 0},
{0, 1, 1, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{0, 1, 1, 1, 0},
},
['e'] = {
{0, 0, 0, 0, 0},
{0, 1, 1, 0, 0},
{1, 0, 0, 1, 0},
{1, 1, 1, 1, 0},
{1, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
},
['f'] = {
{0, 0, 1, 1, 0},
{0, 1, 0, 0, 0},
{1, 1, 1, 1, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 1, 0, 0, 0},
},
['g'] = {},
['h'] = {
{1, 0, 0, 0, 0},
{1, 1, 1, 0, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
},
['i'] = {},
['j'] = {},
['k'] = {},
['l'] = {
{0, 1, 1, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 1, 0, 0},
{0, 1, 1, 1, 0},
},
['m'] = {},
['n'] = {},
['o'] = {
{0, 0, 0, 0, 0},
{0, 1, 1, 0, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{0, 1, 1, 0, 0},
},
['p'] = {
{1, 1, 1, 0, 0},
{1, 0, 0, 1, 0},
{1, 0, 0, 1, 0},
{1, 1, 1, 0, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
},
['q'] = {},
['r'] = {
{0, 0, 0, 0, 0},
{1, 0, 1, 1, 0},
{1, 1, 0, 0, 1},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
},
['s'] = {},
['t'] = {},
['u'] = {},
['v'] = {},
['w'] = {
{0, 0, 0, 0, 0},
{1, 0, 0, 0, 1},
{1, 0, 1, 0, 1},
{1, 0, 1, 0, 1},
{1, 0, 1, 0, 1},
{0, 1, 1, 1, 1},
},
['x'] = {},
['y'] = {},
['z'] = {},
['A'] = {},
['B'] = {},
['C'] = {},
['D'] = {},
['E'] = {},
['F'] = {},
['G'] = {},
['H'] = {},
['I'] = {},
['J'] = {},
['K'] = {},
['L'] = {},
['M'] = {},
['N'] = {},
['O'] = {},
['P'] = {},
['Q'] = {},
['R'] = {},
['S'] = {},
['T'] = {},
['U'] = {},
['V'] = {},
['W'] = {},
['X'] = {},
['Y'] = {},
['Z'] = {},
[','] = {}
};
static Olivec_Font default_font = {
.glyphs = &default_font_glyphs[0][0][0],
.width = DEFAULT_FONT_WIDTH,
.height = DEFAULT_FONT_HEIGHT,
};
typedef struct {
uint32_t *pixels;
size_t width;
size_t height;
size_t stride;
} Olivec_Canvas;
#define OLIVEC_CANVAS_NULL ((Olivec_Canvas) {0})
#define OLIVEC_PIXEL(oc, x, y) (oc).pixels[(y)*(oc).stride + (x)]
OLIVECDEF Olivec_Canvas olivec_canvas(uint32_t *pixels, size_t width, size_t height, size_t stride);
OLIVECDEF Olivec_Canvas olivec_subcanvas(Olivec_Canvas oc, int x, int y, int w, int h);
OLIVECDEF void olivec_blend_color(uint32_t *c1, uint32_t c2);
OLIVECDEF void olivec_fill(Olivec_Canvas oc, uint32_t color);
OLIVECDEF void olivec_rect(Olivec_Canvas oc, int x, int y, int w, int h, uint32_t color);
OLIVECDEF void olivec_circle(Olivec_Canvas oc, int cx, int cy, int r, uint32_t color);
// TODO: lines with different thiccness
// Implement olivec_line in terms of olivec_triangle. This may make it easier to implement variable thiccness.
OLIVECDEF void olivec_line(Olivec_Canvas oc, int x1, int y1, int x2, int y2, uint32_t color);
OLIVECDEF void olivec_triangle(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t color);
OLIVECDEF void olivec_triangle3(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t c1, uint32_t c2, uint32_t c3);
OLIVECDEF void olivec_text(Olivec_Canvas oc, const char *text, int x, int y, Olivec_Font font, size_t size, uint32_t color);
// The point of this function is to produce two ranges x1..x2 and y1..y2 that are guaranteed to be safe to iterate over the canvas of size pixels_width by pixels_height without any boundary checks.
//
// if (olivec_normalize_rect(x, y, w, h, WIDTH, HEIGHT, &x1, &y1, &x2, &y2)) {
// for (int x = x1; x <= x2; ++x) {
// for (int y = y1; y <= y2; ++y) {
// OLIVEC_PIXEL(oc, x, y) = 0x69696969;
// }
// }
// } else {
// // Rectangle is invisible cause it's completely out-of-bounds
// }
OLIVECDEF bool olivec_normalize_rect(int x, int y, int w, int h, size_t pixels_width, size_t pixels_height, int *x1, int *x2, int *y1, int *y2);
#endif // OLIVE_C_
#ifdef OLIVEC_IMPLEMENTATION
OLIVECDEF Olivec_Canvas olivec_canvas(uint32_t *pixels, size_t width, size_t height, size_t stride)
{
Olivec_Canvas oc = {
.pixels = pixels,
.width = width,
.height = height,
.stride = stride,
};
return oc;
}
OLIVECDEF bool olivec_normalize_rect(int x, int y, int w, int h,
size_t pixels_width, size_t pixels_height,
int *x1, int *x2, int *y1, int *y2)
{
*x1 = x;
*y1 = y;
// Convert the rectangle to 2-points representation
*x2 = *x1 + OLIVEC_SIGN(int, w)*(OLIVEC_ABS(int, w) - 1);
if (*x1 > *x2) OLIVEC_SWAP(int, *x1, *x2);
*y2 = *y1 + OLIVEC_SIGN(int, h)*(OLIVEC_ABS(int, h) - 1);
if (*y1 > *y2) OLIVEC_SWAP(int, *y1, *y2);
// Cull out invisible rectangle
if (*x1 >= (int) pixels_width) return false;
if (*x2 < 0) return false;
if (*y1 >= (int) pixels_height) return false;
if (*y2 < 0) return false;
// Clamp the rectangle to the boundaries
if (*x1 < 0) *x1 = 0;
if (*x2 >= (int) pixels_width) *x2 = (int) pixels_width - 1;
if (*y1 < 0) *y1 = 0;
if (*y2 >= (int) pixels_height) *y2 = (int) pixels_height - 1;
return true;
}
OLIVECDEF Olivec_Canvas olivec_subcanvas(Olivec_Canvas oc, int x, int y, int w, int h)
{
int x1, x2, y1, y2;
if (!olivec_normalize_rect(x, y, w, h, oc.width, oc.height, &x1, &x2, &y1, &y2)) return OLIVEC_CANVAS_NULL;
oc.pixels = &OLIVEC_PIXEL(oc, x1, y1);
oc.width = x2 - x1 + 1;
oc.height = y2 - y1 + 1;
return oc;
}
#define OLIVEC_RED(color) (((color)&0x000000FF)>>(8*0))
#define OLIVEC_GREEN(color) (((color)&0x0000FF00)>>(8*1))
#define OLIVEC_BLUE(color) (((color)&0x00FF0000)>>(8*2))
#define OLIVEC_ALPHA(color) (((color)&0xFF000000)>>(8*3))
#define OLIVEC_RGBA(r, g, b, a) ((((r)&0xFF)<<(8*0)) | (((g)&0xFF)<<(8*1)) | (((b)&0xFF)<<(8*2)) | (((a)&0xFF)<<(8*3)))
OLIVECDEF void olivec_blend_color(uint32_t *c1, uint32_t c2)
{
uint32_t r1 = OLIVEC_RED(*c1);
uint32_t g1 = OLIVEC_GREEN(*c1);
uint32_t b1 = OLIVEC_BLUE(*c1);
uint32_t a1 = OLIVEC_ALPHA(*c1);
uint32_t r2 = OLIVEC_RED(c2);
uint32_t g2 = OLIVEC_GREEN(c2);
uint32_t b2 = OLIVEC_BLUE(c2);
uint32_t a2 = OLIVEC_ALPHA(c2);
r1 = (r1*(255 - a2) + r2*a2)/255; if (r1 > 255) r1 = 255;
g1 = (g1*(255 - a2) + g2*a2)/255; if (g1 > 255) g1 = 255;
b1 = (b1*(255 - a2) + b2*a2)/255; if (b1 > 255) b1 = 255;
*c1 = OLIVEC_RGBA(r1, g1, b1, a1);
}
OLIVECDEF void olivec_fill(Olivec_Canvas oc, uint32_t color)
{
for (size_t y = 0; y < oc.height; ++y) {
for (size_t x = 0; x < oc.width; ++x) {
OLIVEC_PIXEL(oc, x, y) = color;
}
}
}
OLIVECDEF void olivec_rect(Olivec_Canvas oc, int x, int y, int w, int h, uint32_t color)
{
int x1, x2, y1, y2;
if (!olivec_normalize_rect(x, y, w, h, oc.width, oc.height, &x1, &x2, &y1, &y2)) return;
for (int x = x1; x <= x2; ++x) {
for (int y = y1; y <= y2; ++y) {
olivec_blend_color(&OLIVEC_PIXEL(oc, x, y), color);
}
}
}
OLIVECDEF void olivec_circle(Olivec_Canvas oc, int cx, int cy, int r, uint32_t color)
{
int x1, y1, x2, y2;
int r1 = r + OLIVEC_SIGN(int, r);
if (!olivec_normalize_rect(cx - r1, cy - r1, 2*r1, 2*r1, oc.width, oc.height, &x1, &x2, &y1, &y2)) return;
for (int y = y1; y <= y2; ++y) {
for (int x = x1; x <= x2; ++x) {
int count = 0;
for (int sox = 0; sox < OLIVEC_AA_RES; ++sox) {
for (int soy = 0; soy < OLIVEC_AA_RES; ++soy) {
// TODO: switch to 64 bits to make the overflow less likely
// Also research the probability of overflow
int res1 = (OLIVEC_AA_RES + 1);
int dx = (x*res1*2 + 2 + sox*2 - res1*cx*2 - res1);
int dy = (y*res1*2 + 2 + soy*2 - res1*cy*2 - res1);
if (dx*dx + dy*dy <= res1*res1*r*r*2*2) count += 1;
}
}
uint32_t alpha = ((color&0xFF000000)>>(3*8))*count/OLIVEC_AA_RES/OLIVEC_AA_RES;
uint32_t updated_color = (color&0x00FFFFFF)|(alpha<<(3*8));
olivec_blend_color(&OLIVEC_PIXEL(oc, x, y), updated_color);
}
}
}
// TODO: AA for line
OLIVECDEF void olivec_line(Olivec_Canvas oc, int x1, int y1, int x2, int y2, uint32_t color)
{
// TODO: fix the olivec_draw_line stairs
int dx = x2 - x1;
int dy = y2 - y1;
if (dx != 0) {
int c = y1 - dy*x1/dx;
if (x1 > x2) OLIVEC_SWAP(int, x1, x2);
for (int x = x1; x <= x2; ++x) {
// TODO: move boundary checks out side of the loops in olivec_draw_line
if (0 <= x && x < (int) oc.width) {
int sy1 = dy*x/dx + c;
int sy2 = dy*(x + 1)/dx + c;
if (sy1 > sy2) OLIVEC_SWAP(int, sy1, sy2);
for (int y = sy1; y <= sy2; ++y) {
if (0 <= y && y < (int) oc.height) {
olivec_blend_color(&OLIVEC_PIXEL(oc, x, y), color);
}
}
}
}
} else {
int x = x1;
if (0 <= x && x < (int) oc.width) {
if (y1 > y2) OLIVEC_SWAP(int, y1, y2);
for (int y = y1; y <= y2; ++y) {
if (0 <= y && y < (int) oc.height) {
olivec_blend_color(&OLIVEC_PIXEL(oc, x, y), color);
}
}
}
}
}
uint32_t mix_colors3(uint32_t c1, uint32_t c2, uint32_t c3, int t1, int t2, int t3, int den)
{
// TODO: estimate how much overflows are an issue in integer only environment
int64_t r1 = OLIVEC_RED(c1);
int64_t g1 = OLIVEC_GREEN(c1);
int64_t b1 = OLIVEC_BLUE(c1);
int64_t a1 = OLIVEC_ALPHA(c1);
int64_t r2 = OLIVEC_RED(c2);
int64_t g2 = OLIVEC_GREEN(c2);
int64_t b2 = OLIVEC_BLUE(c2);
int64_t a2 = OLIVEC_ALPHA(c2);
int64_t r3 = OLIVEC_RED(c3);
int64_t g3 = OLIVEC_GREEN(c3);
int64_t b3 = OLIVEC_BLUE(c3);
int64_t a3 = OLIVEC_ALPHA(c3);
if (den != 0) {
int64_t r4 = (r1*t1 + r2*t2 + r3*t3)/den;
int64_t g4 = (g1*t1 + g2*t2 + g3*t3)/den;
int64_t b4 = (b1*t1 + b2*t2 + b3*t3)/den;
int64_t a4 = (a1*t1 + a2*t2 + a3*t3)/den;
return OLIVEC_RGBA(r4, g4, b4, a4);
}
return 0;
}
void barycentric(int x1, int y1, int x2, int y2, int x3, int y3,
int xp, int yp,
int *u1, int *u2, int *det)
{
*det = ((x1 - x3)*(y2 - y3) - (x2 - x3)*(y1 - y3));
*u1 = ((y2 - y3)*(xp - x3) + (x3 - x2)*(yp - y3));
*u2 = ((y3 - y1)*(xp - x3) + (x1 - x3)*(yp - y3));
// u3 = det - u1 - u2
}
OLIVECDEF void olivec_triangle3(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3,
uint32_t c1, uint32_t c2, uint32_t c3)
{
if (y1 > y2) {
OLIVEC_SWAP(int, x1, x2);
OLIVEC_SWAP(int, y1, y2);
OLIVEC_SWAP(int, c1, c2);
}
if (y2 > y3) {
OLIVEC_SWAP(int, x2, x3);
OLIVEC_SWAP(int, y2, y3);
OLIVEC_SWAP(int, c2, c3);
}
if (y1 > y2) {
OLIVEC_SWAP(int, x1, x2);
OLIVEC_SWAP(int, y1, y2);
OLIVEC_SWAP(int, c1, c2);
}
int dx12 = x2 - x1;
int dy12 = y2 - y1;
int dx13 = x3 - x1;
int dy13 = y3 - y1;
for (int y = y1; y <= y2; ++y) {
// TODO: move boundary checks outside of loops in olivec_fill_triangle
if (0 <= y && (size_t) y < oc.height) {
int s1 = dy12 != 0 ? (y - y1)*dx12/dy12 + x1 : x1;
int s2 = dy13 != 0 ? (y - y1)*dx13/dy13 + x1 : x1;
if (s1 > s2) OLIVEC_SWAP(int, s1, s2);
for (int x = s1; x <= s2; ++x) {
if (0 <= x && (size_t) x < oc.width) {
int u1, u2, det;
barycentric(x1, y1, x2, y2, x3, y3, x, y, &u1, &u2, &det);
uint32_t color = mix_colors3(c1, c2, c3, u1, u2, det - u1 - u2, det);
olivec_blend_color(&OLIVEC_PIXEL(oc, x, y), color);
}
}
}
}
int dx32 = x2 - x3;
int dy32 = y2 - y3;
int dx31 = x1 - x3;
int dy31 = y1 - y3;
for (int y = y2; y <= y3; ++y) {
if (0 <= y && (size_t) y < oc.height) {
int s1 = dy32 != 0 ? (y - y3)*dx32/dy32 + x3 : x3;
int s2 = dy31 != 0 ? (y - y3)*dx31/dy31 + x3 : x3;
if (s1 > s2) OLIVEC_SWAP(int, s1, s2);
for (int x = s1; x <= s2; ++x) {
if (0 <= x && (size_t) x < oc.width) {
int u1, u2, det;
barycentric(x1, y1, x2, y2, x3, y3, x, y, &u1, &u2, &det);
uint32_t color = mix_colors3(c1, c2, c3, u1, u2, det - u1 - u2, det);
olivec_blend_color(&OLIVEC_PIXEL(oc, x, y), color);
}
}
}
}
}
// TODO: AA for triangle
OLIVECDEF void olivec_triangle(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t color)
{
if (y1 > y2) {
OLIVEC_SWAP(int, x1, x2);
OLIVEC_SWAP(int, y1, y2);
}
if (y2 > y3) {
OLIVEC_SWAP(int, x2, x3);
OLIVEC_SWAP(int, y2, y3);
}
if (y1 > y2) {
OLIVEC_SWAP(int, x1, x2);
OLIVEC_SWAP(int, y1, y2);
}
int dx12 = x2 - x1;
int dy12 = y2 - y1;
int dx13 = x3 - x1;
int dy13 = y3 - y1;
for (int y = y1; y <= y2; ++y) {
// TODO: move boundary checks outside of loops in olivec_fill_triangle
if (0 <= y && (size_t) y < oc.height) {
int s1 = dy12 != 0 ? (y - y1)*dx12/dy12 + x1 : x1;
int s2 = dy13 != 0 ? (y - y1)*dx13/dy13 + x1 : x1;
if (s1 > s2) OLIVEC_SWAP(int, s1, s2);
for (int x = s1; x <= s2; ++x) {
if (0 <= x && (size_t) x < oc.width) {
olivec_blend_color(&OLIVEC_PIXEL(oc, x, y), color);
}
}
}
}
int dx32 = x2 - x3;
int dy32 = y2 - y3;
int dx31 = x1 - x3;
int dy31 = y1 - y3;
for (int y = y2; y <= y3; ++y) {
if (0 <= y && (size_t) y < oc.height) {
int s1 = dy32 != 0 ? (y - y3)*dx32/dy32 + x3 : x3;
int s2 = dy31 != 0 ? (y - y3)*dx31/dy31 + x3 : x3;
if (s1 > s2) OLIVEC_SWAP(int, s1, s2);
for (int x = s1; x <= s2; ++x) {
if (0 <= x && (size_t) x < oc.width) {
olivec_blend_color(&OLIVEC_PIXEL(oc, x, y), color);
}
}
}
}
}
OLIVECDEF void olivec_text(Olivec_Canvas oc, const char *text, int tx, int ty, Olivec_Font font, size_t glyph_size, uint32_t color)
{
for (size_t i = 0; *text; ++i, ++text) {
int gx = tx + i*font.width*glyph_size;
int gy = ty;
const char *glyph = &font.glyphs[(*text)*sizeof(char)*font.width*font.height];
for (int dy = 0; (size_t) dy < font.height; ++dy) {
for (int dx = 0; (size_t) dx < font.width; ++dx) {
int px = gx + dx*glyph_size;
int py = gy + dy*glyph_size;
if (0 <= px && px < (int) oc.width && 0 <= py && py < (int) oc.height) {
if (glyph[dy*font.width + dx]) {
olivec_rect(oc, px, py, glyph_size, glyph_size, color);
}
}
}
}
}
}
// TODO: olivec_copy does not work correctly with dst out of bounds
// TODO: bilinear interpolation for olivec_copy
void olivec_copy(Olivec_Canvas src, Olivec_Canvas dst)
{
for (size_t y = 0; y < dst.height; ++y) {
for (size_t x = 0; x < dst.width; ++x) {
size_t nx = x*src.width/dst.width;
size_t ny = y*src.height/dst.height;
OLIVEC_PIXEL(dst, x, y) = OLIVEC_PIXEL(src, nx, ny);
}
}
}
#endif // OLIVEC_IMPLEMENTATION
// TODO: 3D triangles with z-buffering
// TODO: 3D textures
// TODO: Stencil
// TODO: Benchmarking
// TODO: SIMD implementations
// TODO: olivec_ring
// TODO: olivec_ellipse
// TODO: bezier curves