20
static struct prng_rand_t g_prng_rand_state;
21
#define SRAND(seed) prng_srand(seed, &g_prng_rand_state)
22
#define RAND() prng_rand(&g_prng_rand_state)
24
static int RandomInt(int a, int b)
26
float random = ((float)RAND()) / (float)uint64_t(-1);
28
float r = random * diff;
32
static int RandomInt2(int a, int b)
34
float random = ((float)RAND()) / (float)uint64_t(-1);
36
float r = random * diff;
37
return (a + (int)r + 1) / 2 * 2;
40
static int test_mat_pixel_drawing_c1(int w, int h)
42
ncnn::Mat a(w, h, (size_t)1u, 1);
43
ncnn::Mat b(h, w, (size_t)1u, 1);
46
unsigned char* color = (unsigned char*)&_color;
50
ncnn::draw_rectangle_c1(a, w, h, 0, 0, w, h, _color, -1);
51
ncnn::draw_rectangle_c1(b, h, w, 0, 0, h, w, _color, -1);
54
int rx = RandomInt(0, w);
55
int ry = RandomInt(0, h);
56
int rw = RandomInt(0, w - rx);
57
int rh = RandomInt(0, h - ry);
59
ncnn::draw_rectangle_c1(a, w, h, rx, ry, rw, rh, _color, 3);
60
ncnn::draw_rectangle_c1(b, h, w, ry, rx, rh, rw, _color, 3);
64
ncnn::draw_rectangle_c1(a, w, h, w - 10, -10, 20, 30, _color, -1);
65
ncnn::draw_rectangle_c1(b, h, w, -10, w - 10, 30, 20, _color, -1);
67
ncnn::draw_rectangle_c1(a, w, h, -rw / 2, -rh / 3, rw, rh, _color, 7);
68
ncnn::draw_rectangle_c1(b, h, w, -rh / 3, -rw / 2, rh, rw, _color, 7);
72
ncnn::draw_rectangle_c1(a, w, h, rx + w / 2, ry + h / 2, rw, rh, _color, 1);
73
ncnn::draw_rectangle_c1(b, h, w, ry + h / 2, rx + w / 2, rh, rw, _color, 1);
75
ncnn::draw_rectangle_c1(a, w, h, -rw / 2, -rh / 3, rw, rh, _color, 7);
76
ncnn::draw_rectangle_c1(b, h, w, -rh / 3, -rw / 2, rh, rw, _color, 7);
79
int cx = RandomInt(0, w);
80
int cy = RandomInt(0, h);
81
int radius = RandomInt(0, std::min(w, h));
83
ncnn::draw_circle_c1(a, w, h, cx, cy, radius, _color, -1);
84
ncnn::draw_circle_c1(b, h, w, cy, cx, radius, _color, -1);
88
ncnn::draw_circle_c1(a, w, h, 10, -4, 6, _color, -1);
89
ncnn::draw_circle_c1(b, h, w, -4, 10, 6, _color, -1);
93
ncnn::draw_circle_c1(a, w, h, cx, cy, radius + std::min(w, h) / 2, _color, 5);
94
ncnn::draw_circle_c1(b, h, w, cy, cx, radius + std::min(w, h) / 2, _color, 5);
97
int x0 = RandomInt(0, w);
98
int y0 = RandomInt(0, h);
99
int x1 = RandomInt(0, w);
100
int y1 = RandomInt(0, h);
102
ncnn::draw_line_c1(a, w, h, x0, y0, x1, y1, _color, 7);
103
ncnn::draw_line_c1(b, h, w, y0, x0, y1, x1, _color, 7);
107
ncnn::draw_line_c1(a, w, h, x0 - w, y0 - h, x1 + w, y1 + h, _color, 1);
108
ncnn::draw_line_c1(b, h, w, y0 - h, x0 - w, y1 + h, x1 + w, _color, 1);
111
ncnn::Mat c(w, h, (size_t)1u, 1);
112
ncnn::kanna_rotate_c1(b, h, w, c, w, h, 5);
115
const char text[] = "saJIEWdl\nj43@o";
116
int tx = RandomInt(0, w / 2);
117
int ty = RandomInt(0, h / 2);
118
int fontpixelsize = 10;
120
ncnn::draw_text_c1(a, w, h, text, tx, ty, fontpixelsize, _color);
123
ncnn::get_text_drawing_size(text, fontpixelsize, &tw, &th);
124
const int len = strlen(text);
125
for (int i = 0; i < 8; i++)
127
const char ch[2] = {text[i], '\0'};
128
ncnn::draw_text_c1(c, w, h, ch, tx + tw / 8 * i, ty, fontpixelsize, _color);
130
for (int i = 9; i < len; i++)
132
const char ch[2] = {text[i], '\0'};
133
ncnn::draw_text_c1(c, w, h, ch, tx + tw / 8 * (i - 9), ty + th / 2, fontpixelsize, _color);
137
fontpixelsize = std::max(w, h) / 2;
139
ncnn::draw_text_c1(a, w, h, "QAQ", -3, -5, fontpixelsize, _color);
140
ncnn::get_text_drawing_size("QAQ", fontpixelsize, &tw, &th);
141
ncnn::draw_text_c1(c, w, h, "Q", -3, -5, fontpixelsize, _color);
142
ncnn::draw_text_c1(c, w, h, "A", -3 + tw / 3, -5, fontpixelsize, _color);
143
ncnn::draw_text_c1(c, w, h, "Q", -3 + tw / 3 * 2, -5, fontpixelsize, _color);
145
if (memcmp(a, c, w * h) != 0)
147
fprintf(stderr, "test_mat_pixel_drawing_c1 failed w=%d h=%d\n", w, h);
154
static int test_mat_pixel_drawing_c2(int w, int h)
156
ncnn::Mat a(w, h, (size_t)2u, 2);
157
ncnn::Mat b(h, w, (size_t)2u, 2);
160
unsigned char* color = (unsigned char*)&_color;
165
ncnn::draw_rectangle_c2(a, w, h, 0, 0, w, h, _color, -1);
166
ncnn::draw_rectangle_c2(b, h, w, 0, 0, h, w, _color, -1);
169
int rx = RandomInt(0, w);
170
int ry = RandomInt(0, h);
171
int rw = RandomInt(0, w - rx);
172
int rh = RandomInt(0, h - ry);
175
ncnn::draw_rectangle_c2(a, w, h, rx, ry, rw, rh, _color, 3);
176
ncnn::draw_rectangle_c2(b, h, w, ry, rx, rh, rw, _color, 3);
181
ncnn::draw_rectangle_c2(a, w, h, w - 10, -10, 20, 30, _color, -1);
182
ncnn::draw_rectangle_c2(b, h, w, -10, w - 10, 30, 20, _color, -1);
185
ncnn::draw_rectangle_c2(a, w, h, -rw / 2, -rh / 3, rw, rh, _color, 7);
186
ncnn::draw_rectangle_c2(b, h, w, -rh / 3, -rw / 2, rh, rw, _color, 7);
191
ncnn::draw_rectangle_c2(a, w, h, rx + w / 2, ry + h / 2, rw, rh, _color, 1);
192
ncnn::draw_rectangle_c2(b, h, w, ry + h / 2, rx + w / 2, rh, rw, _color, 1);
195
ncnn::draw_rectangle_c2(a, w, h, -rw / 2, -rh / 3, rw, rh, _color, 7);
196
ncnn::draw_rectangle_c2(b, h, w, -rh / 3, -rw / 2, rh, rw, _color, 7);
199
int cx = RandomInt(0, w);
200
int cy = RandomInt(0, h);
201
int radius = RandomInt(0, std::min(w, h));
204
ncnn::draw_circle_c2(a, w, h, cx, cy, radius, _color, -1);
205
ncnn::draw_circle_c2(b, h, w, cy, cx, radius, _color, -1);
210
ncnn::draw_circle_c2(a, w, h, 10, -4, 6, _color, -1);
211
ncnn::draw_circle_c2(b, h, w, -4, 10, 6, _color, -1);
216
ncnn::draw_circle_c2(a, w, h, cx, cy, radius + std::min(w, h) / 2, _color, 5);
217
ncnn::draw_circle_c2(b, h, w, cy, cx, radius + std::min(w, h) / 2, _color, 5);
220
int x0 = RandomInt(0, w);
221
int y0 = RandomInt(0, h);
222
int x1 = RandomInt(0, w);
223
int y1 = RandomInt(0, h);
226
ncnn::draw_line_c2(a, w, h, x0, y0, x1, y1, _color, 7);
227
ncnn::draw_line_c2(b, h, w, y0, x0, y1, x1, _color, 7);
232
ncnn::draw_line_c2(a, w, h, x0 - w, y0 - h, x1 + w, y1 + h, _color, 1);
233
ncnn::draw_line_c2(b, h, w, y0 - h, x0 - w, y1 + h, x1 + w, _color, 1);
236
ncnn::Mat c(w, h, (size_t)2u, 2);
237
ncnn::kanna_rotate_c2(b, h, w, c, w, h, 5);
240
const char text[] = "Q`~\\=f\nPN\'/<DSA";
241
int tx = RandomInt(0, w / 2);
242
int ty = RandomInt(0, h / 2);
243
int fontpixelsize = 12;
246
ncnn::draw_text_c2(a, w, h, text, tx, ty, fontpixelsize, _color);
249
ncnn::get_text_drawing_size(text, fontpixelsize, &tw, &th);
250
const int len = strlen(text);
251
for (int i = 0; i < 6; i++)
253
const char ch[2] = {text[i], '\0'};
254
ncnn::draw_text_c2(c, w, h, ch, tx + tw / 8 * i, ty, fontpixelsize, _color);
256
for (int i = 7; i < len; i++)
258
const char ch[2] = {text[i], '\0'};
259
ncnn::draw_text_c2(c, w, h, ch, tx + tw / 8 * (i - 7), ty + th / 2, fontpixelsize, _color);
263
fontpixelsize = std::max(w, h) / 3;
266
ncnn::draw_text_c2(a, w, h, "!@#$%^&", -1, -2, fontpixelsize, _color);
267
ncnn::get_text_drawing_size("!@#$%^&", fontpixelsize, &tw, &th);
268
ncnn::draw_text_c2(c, w, h, "!@#", -1, -2, fontpixelsize, _color);
269
ncnn::draw_text_c2(c, w, h, "$", -1 + tw / 7 * 3, -2, fontpixelsize, _color);
270
ncnn::draw_text_c2(c, w, h, "%^&", -1 + tw / 7 * 4, -2, fontpixelsize, _color);
272
if (memcmp(a, c, w * h * 2) != 0)
274
fprintf(stderr, "test_mat_pixel_drawing_c2 failed w=%d h=%d\n", w, h);
281
static int test_mat_pixel_drawing_c3(int w, int h)
283
ncnn::Mat a(w, h, (size_t)3u, 3);
284
ncnn::Mat b(h, w, (size_t)3u, 3);
287
unsigned char* color = (unsigned char*)&_color;
293
ncnn::draw_rectangle_c3(a, w, h, 0, 0, w, h, _color, -1);
294
ncnn::draw_rectangle_c3(b, h, w, 0, 0, h, w, _color, -1);
297
int rx = RandomInt(0, w);
298
int ry = RandomInt(0, h);
299
int rw = RandomInt(0, w - rx);
300
int rh = RandomInt(0, h - ry);
304
ncnn::draw_rectangle_c3(a, w, h, rx, ry, rw, rh, _color, 3);
305
ncnn::draw_rectangle_c3(b, h, w, ry, rx, rh, rw, _color, 3);
311
ncnn::draw_rectangle_c3(a, w, h, w - 10, -10, 20, 30, _color, -1);
312
ncnn::draw_rectangle_c3(b, h, w, -10, w - 10, 30, 20, _color, -1);
316
ncnn::draw_rectangle_c3(a, w, h, -rw / 2, -rh / 3, rw, rh, _color, 7);
317
ncnn::draw_rectangle_c3(b, h, w, -rh / 3, -rw / 2, rh, rw, _color, 7);
323
ncnn::draw_rectangle_c3(a, w, h, rx + w / 2, ry + h / 2, rw, rh, _color, 1);
324
ncnn::draw_rectangle_c3(b, h, w, ry + h / 2, rx + w / 2, rh, rw, _color, 1);
328
ncnn::draw_rectangle_c3(a, w, h, -rw / 2, -rh / 3, rw, rh, _color, 7);
329
ncnn::draw_rectangle_c3(b, h, w, -rh / 3, -rw / 2, rh, rw, _color, 7);
332
int cx = RandomInt(0, w);
333
int cy = RandomInt(0, h);
334
int radius = RandomInt(0, std::min(w, h));
338
ncnn::draw_circle_c3(a, w, h, cx, cy, radius, _color, -1);
339
ncnn::draw_circle_c3(b, h, w, cy, cx, radius, _color, -1);
345
ncnn::draw_circle_c3(a, w, h, 10, -4, 6, _color, -1);
346
ncnn::draw_circle_c3(b, h, w, -4, 10, 6, _color, -1);
352
ncnn::draw_circle_c3(a, w, h, cx, cy, radius + std::min(w, h) / 2, _color, 5);
353
ncnn::draw_circle_c3(b, h, w, cy, cx, radius + std::min(w, h) / 2, _color, 5);
356
int x0 = RandomInt(0, w);
357
int y0 = RandomInt(0, h);
358
int x1 = RandomInt(0, w);
359
int y1 = RandomInt(0, h);
363
ncnn::draw_line_c3(a, w, h, x0, y0, x1, y1, _color, 7);
364
ncnn::draw_line_c3(b, h, w, y0, x0, y1, x1, _color, 7);
370
ncnn::draw_line_c3(a, w, h, x0 - w, y0 - h, x1 + w, y1 + h, _color, 1);
371
ncnn::draw_line_c3(b, h, w, y0 - h, x0 - w, y1 + h, x1 + w, _color, 1);
374
ncnn::Mat c(w, h, (size_t)3u, 3);
375
ncnn::kanna_rotate_c3(b, h, w, c, w, h, 5);
378
const char text[] = "Q`~\\=f\nPN\'/<DSA";
379
int tx = RandomInt(0, w / 2);
380
int ty = RandomInt(0, h / 2);
381
int fontpixelsize = 12;
385
ncnn::draw_text_c3(a, w, h, text, tx, ty, fontpixelsize, _color);
388
ncnn::get_text_drawing_size(text, fontpixelsize, &tw, &th);
389
const int len = strlen(text);
390
for (int i = 0; i < 6; i++)
392
const char ch[2] = {text[i], '\0'};
393
ncnn::draw_text_c3(c, w, h, ch, tx + tw / 8 * i, ty, fontpixelsize, _color);
395
for (int i = 7; i < len; i++)
397
const char ch[2] = {text[i], '\0'};
398
ncnn::draw_text_c3(c, w, h, ch, tx + tw / 8 * (i - 7), ty + th / 2, fontpixelsize, _color);
402
fontpixelsize = std::max(w, h) / 2;
406
ncnn::draw_text_c3(a, w, h, "qwqwqwq", -13, -15, fontpixelsize, _color);
407
ncnn::get_text_drawing_size("qwqwqwq", fontpixelsize, &tw, &th);
408
ncnn::draw_text_c3(c, w, h, "qwq", -13, -15, fontpixelsize, _color);
409
ncnn::draw_text_c3(c, w, h, "w", -13 + tw / 7 * 3, -15, fontpixelsize, _color);
410
ncnn::draw_text_c3(c, w, h, "qwq", -13 + tw / 7 * 4, -15, fontpixelsize, _color);
412
if (memcmp(a, c, w * h * 3) != 0)
414
fprintf(stderr, "test_mat_pixel_drawing_c3 failed w=%d h=%d\n", w, h);
421
static int test_mat_pixel_drawing_c4(int w, int h)
423
ncnn::Mat a(w, h, (size_t)4u, 4);
424
ncnn::Mat b(h, w, (size_t)4u, 4);
427
unsigned char* color = (unsigned char*)&_color;
434
ncnn::draw_rectangle_c4(a, w, h, 0, 0, w, h, _color, -1);
435
ncnn::draw_rectangle_c4(b, h, w, 0, 0, h, w, _color, -1);
438
int rx = RandomInt(0, w);
439
int ry = RandomInt(0, h);
440
int rw = RandomInt(0, w - rx);
441
int rh = RandomInt(0, h - ry);
446
ncnn::draw_rectangle_c4(a, w, h, rx, ry, rw, rh, _color, 3);
447
ncnn::draw_rectangle_c4(b, h, w, ry, rx, rh, rw, _color, 3);
454
ncnn::draw_rectangle_c4(a, w, h, w - 10, -10, 20, 30, _color, -1);
455
ncnn::draw_rectangle_c4(b, h, w, -10, w - 10, 30, 20, _color, -1);
460
ncnn::draw_rectangle_c4(a, w, h, -rw / 2, -rh / 3, rw, rh, _color, 7);
461
ncnn::draw_rectangle_c4(b, h, w, -rh / 3, -rw / 2, rh, rw, _color, 7);
468
ncnn::draw_rectangle_c4(a, w, h, rx + w / 2, ry + h / 2, rw, rh, _color, 1);
469
ncnn::draw_rectangle_c4(b, h, w, ry + h / 2, rx + w / 2, rh, rw, _color, 1);
474
ncnn::draw_rectangle_c4(a, w, h, -rw / 2, -rh / 3, rw, rh, _color, 7);
475
ncnn::draw_rectangle_c4(b, h, w, -rh / 3, -rw / 2, rh, rw, _color, 7);
478
int cx = RandomInt(0, w);
479
int cy = RandomInt(0, h);
480
int radius = RandomInt(0, std::min(w, h));
485
ncnn::draw_circle_c4(a, w, h, cx, cy, radius, _color, -1);
486
ncnn::draw_circle_c4(b, h, w, cy, cx, radius, _color, -1);
493
ncnn::draw_circle_c4(a, w, h, 10, -4, 6, _color, -1);
494
ncnn::draw_circle_c4(b, h, w, -4, 10, 6, _color, -1);
501
ncnn::draw_circle_c4(a, w, h, cx, cy, radius + std::min(w, h) / 2, _color, 5);
502
ncnn::draw_circle_c4(b, h, w, cy, cx, radius + std::min(w, h) / 2, _color, 5);
505
int x0 = RandomInt(0, w);
506
int y0 = RandomInt(0, h);
507
int x1 = RandomInt(0, w);
508
int y1 = RandomInt(0, h);
513
ncnn::draw_line_c4(a, w, h, x0, y0, x1, y1, _color, 7);
514
ncnn::draw_line_c4(b, h, w, y0, x0, y1, x1, _color, 7);
521
ncnn::draw_line_c4(a, w, h, x0 - w, y0 - h, x1 + w, y1 + h, _color, 1);
522
ncnn::draw_line_c4(b, h, w, y0 - h, x0 - w, y1 + h, x1 + w, _color, 1);
525
ncnn::Mat c(w, h, (size_t)4u, 4);
526
ncnn::kanna_rotate_c4(b, h, w, c, w, h, 5);
529
const char text[] = "!@)\n($ 34\n2]\"M,";
530
int tx = RandomInt(0, w / 2);
531
int ty = RandomInt(0, h / 2);
532
int fontpixelsize = 23;
537
ncnn::draw_text_c4(a, w, h, text, tx, ty, fontpixelsize, _color);
540
ncnn::get_text_drawing_size(text, fontpixelsize, &tw, &th);
541
const int len = strlen(text);
542
for (int i = 0; i < 3; i++)
544
const char ch[2] = {text[i], '\0'};
545
ncnn::draw_text_c4(c, w, h, ch, tx + tw / 5 * i, ty, fontpixelsize, _color);
547
for (int i = 4; i < 9; i++)
549
const char ch[2] = {text[i], '\0'};
550
ncnn::draw_text_c4(c, w, h, ch, tx + tw / 5 * (i - 4), ty + th / 3, fontpixelsize, _color);
552
for (int i = 10; i < len; i++)
554
const char ch[2] = {text[i], '\0'};
555
ncnn::draw_text_c4(c, w, h, ch, tx + tw / 5 * (i - 10), ty + th / 3 * 2, fontpixelsize, _color);
559
fontpixelsize = std::max(w, h) / 3;
564
ncnn::draw_text_c4(a, w, h, "=_+!//zzzz", -13, -15, fontpixelsize, _color);
565
ncnn::get_text_drawing_size("=_+!//zzzz", fontpixelsize, &tw, &th);
566
ncnn::draw_text_c4(c, w, h, "=_+", -13, -15, fontpixelsize, _color);
567
ncnn::draw_text_c4(c, w, h, "!", -13 + tw / 10 * 3, -15, fontpixelsize, _color);
568
ncnn::draw_text_c4(c, w, h, "//zzzz", -13 + tw / 10 * 4, -15, fontpixelsize, _color);
570
if (memcmp(a, c, w * h * 4) != 0)
572
fprintf(stderr, "test_mat_pixel_drawing_c4 failed w=%d h=%d\n", w, h);
579
static int test_mat_pixel_drawing_0()
582
|| test_mat_pixel_drawing_c1(22, 33)
583
|| test_mat_pixel_drawing_c2(22, 23)
584
|| test_mat_pixel_drawing_c3(32, 23)
585
|| test_mat_pixel_drawing_c4(42, 13)
587
|| test_mat_pixel_drawing_c1(202, 303)
588
|| test_mat_pixel_drawing_c2(202, 203)
589
|| test_mat_pixel_drawing_c3(302, 203)
590
|| test_mat_pixel_drawing_c4(402, 103);
593
static int test_mat_pixel_drawing_yuv420sp(int w, int h)
595
ncnn::Mat a(w, h * 3 / 2, (size_t)1u, 1);
596
ncnn::Mat b(h, w * 3 / 2, (size_t)1u, 1);
599
unsigned char* color = (unsigned char*)&_color;
605
ncnn::draw_rectangle_yuv420sp(a, w, h, 0, 0, w, h, _color, -1);
606
ncnn::draw_rectangle_yuv420sp(b, h, w, 0, 0, h, w, _color, -1);
609
int rx = RandomInt2(0, w);
610
int ry = RandomInt2(0, h);
611
int rw = RandomInt2(0, w - rx);
612
int rh = RandomInt2(0, h - ry);
616
ncnn::draw_rectangle_yuv420sp(a, w, h, rx, ry, rw, rh, _color, 4);
617
ncnn::draw_rectangle_yuv420sp(b, h, w, ry, rx, rh, rw, _color, 4);
623
ncnn::draw_rectangle_yuv420sp(a, w, h, w - 10, -10, 20, 30, _color, -1);
624
ncnn::draw_rectangle_yuv420sp(b, h, w, -10, w - 10, 30, 20, _color, -1);
628
ncnn::draw_rectangle_yuv420sp(a, w, h, -rw / 2, -rh / 3, rw, rh, _color, 8);
629
ncnn::draw_rectangle_yuv420sp(b, h, w, -rh / 3, -rw / 2, rh, rw, _color, 8);
635
ncnn::draw_rectangle_yuv420sp(a, w, h, rx + w / 2, ry + h / 2, rw, rh, _color, 2);
636
ncnn::draw_rectangle_yuv420sp(b, h, w, ry + h / 2, rx + w / 2, rh, rw, _color, 2);
640
ncnn::draw_rectangle_yuv420sp(a, w, h, -rw / 2, -rh / 3, rw, rh, _color, 8);
641
ncnn::draw_rectangle_yuv420sp(b, h, w, -rh / 3, -rw / 2, rh, rw, _color, 8);
644
int cx = RandomInt2(0, w);
645
int cy = RandomInt2(0, h);
646
int radius = RandomInt2(0, std::min(w, h));
650
ncnn::draw_circle_yuv420sp(a, w, h, cx, cy, radius, _color, -1);
651
ncnn::draw_circle_yuv420sp(b, h, w, cy, cx, radius, _color, -1);
657
ncnn::draw_circle_yuv420sp(a, w, h, 10, -4, 6, _color, -1);
658
ncnn::draw_circle_yuv420sp(b, h, w, -4, 10, 6, _color, -1);
664
ncnn::draw_circle_yuv420sp(a, w, h, cx, cy, radius + std::min(w, h) / 2, _color, 6);
665
ncnn::draw_circle_yuv420sp(b, h, w, cy, cx, radius + std::min(w, h) / 2, _color, 6);
668
int x0 = RandomInt2(0, w);
669
int y0 = RandomInt2(0, h);
670
int x1 = RandomInt2(0, w);
671
int y1 = RandomInt2(0, h);
675
ncnn::draw_line_yuv420sp(a, w, h, x0, y0, x1, y1, _color, 8);
676
ncnn::draw_line_yuv420sp(b, h, w, y0, x0, y1, x1, _color, 8);
682
ncnn::draw_line_yuv420sp(a, w, h, x0 - w, y0 - h, x1 + w, y1 + h, _color, 2);
683
ncnn::draw_line_yuv420sp(b, h, w, y0 - h, x0 - w, y1 + h, x1 + w, _color, 2);
686
ncnn::Mat c(w, h * 3 / 2, (size_t)1u, 1);
687
ncnn::kanna_rotate_yuv420sp(b, h, w, c, w, h, 5);
690
const char text[] = "!@)\n($ 34\n2]\"M,";
691
int tx = RandomInt2(0, w / 2);
692
int ty = RandomInt2(0, h / 2);
693
int fontpixelsize = 24;
697
ncnn::draw_text_yuv420sp(a, w, h, text, tx, ty, fontpixelsize, _color);
700
ncnn::get_text_drawing_size(text, fontpixelsize, &tw, &th);
701
const int len = strlen(text);
702
for (int i = 0; i < 3; i++)
704
const char ch[2] = {text[i], '\0'};
705
ncnn::draw_text_yuv420sp(c, w, h, ch, tx + tw / 5 * i, ty, fontpixelsize, _color);
707
for (int i = 4; i < 9; i++)
709
const char ch[2] = {text[i], '\0'};
710
ncnn::draw_text_yuv420sp(c, w, h, ch, tx + tw / 5 * (i - 4), ty + th / 3, fontpixelsize, _color);
712
for (int i = 10; i < len; i++)
714
const char ch[2] = {text[i], '\0'};
715
ncnn::draw_text_yuv420sp(c, w, h, ch, tx + tw / 5 * (i - 10), ty + th / 3 * 2, fontpixelsize, _color);
719
fontpixelsize = (std::max(w, h) / 3 + 1) / 2 * 2;
723
ncnn::draw_text_yuv420sp(a, w, h, "=_+!//zzzz", -14, -12, fontpixelsize, _color);
724
ncnn::get_text_drawing_size("=_+!//zzzz", fontpixelsize, &tw, &th);
725
ncnn::draw_text_yuv420sp(c, w, h, "=_+", -14, -12, fontpixelsize, _color);
726
ncnn::draw_text_yuv420sp(c, w, h, "!", -14 + tw / 10 * 3, -12, fontpixelsize, _color);
727
ncnn::draw_text_yuv420sp(c, w, h, "//zzzz", -14 + tw / 10 * 4, -12, fontpixelsize, _color);
729
if (memcmp(a, c, w * h * 3 / 2) != 0)
731
fprintf(stderr, "test_mat_pixel_drawing_yuv420sp failed w=%d h=%d\n", w, h);
738
static int test_mat_pixel_drawing_1()
741
|| test_mat_pixel_drawing_yuv420sp(10, 10)
742
|| test_mat_pixel_drawing_yuv420sp(120, 160)
743
|| test_mat_pixel_drawing_yuv420sp(220, 340);
751
|| test_mat_pixel_drawing_0()
752
|| test_mat_pixel_drawing_1();