1 /*
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <stdlib.h>
12 #include <time.h>
13
14 #include "libyuv/rotate.h"
15 #include "../unit_test/unit_test.h"
16
17 namespace libyuv {
18
PrintArray(uint8 * array,int w,int h)19 void PrintArray(uint8 *array, int w, int h) {
20 for (int i = 0; i < h; ++i) {
21 for (int j = 0; j < w; ++j) {
22 printf("%4d", (signed char)array[i * w + j]);
23 }
24 printf("\n");
25 }
26 }
27
TEST_F(libyuvTest,Transpose)28 TEST_F(libyuvTest, Transpose) {
29 int iw, ih, ow, oh;
30 int err = 0;
31
32 for (iw = 8; iw < rotate_max_w_ && !err; ++iw) {
33 for (ih = 8; ih < rotate_max_h_ && !err; ++ih) {
34 int i;
35 ow = ih;
36 oh = iw;
37
38 align_buffer_16(input, iw * ih)
39 align_buffer_16(output_1, ow * oh)
40 align_buffer_16(output_2, iw * ih)
41
42 for (i = 0; i < iw * ih; ++i) {
43 input[i] = i;
44 }
45
46 TransposePlane(input, iw, output_1, ow, iw, ih);
47 TransposePlane(output_1, ow, output_2, oh, ow, oh);
48
49 for (i = 0; i < iw * ih; ++i) {
50 if (input[i] != output_2[i]) {
51 err++;
52 }
53 }
54
55 if (err) {
56 printf("input %dx%d \n", iw, ih);
57 PrintArray(input, iw, ih);
58
59 printf("transpose 1\n");
60 PrintArray(output_1, ow, oh);
61
62 printf("transpose 2\n");
63 PrintArray(output_2, iw, ih);
64 }
65
66 free_aligned_buffer_16(input)
67 free_aligned_buffer_16(output_1)
68 free_aligned_buffer_16(output_2)
69 }
70 }
71
72 EXPECT_EQ(0, err);
73 }
74
TEST_F(libyuvTest,TransposeUV)75 TEST_F(libyuvTest, TransposeUV) {
76 int iw, ih, ow, oh;
77 int err = 0;
78
79 for (iw = 16; iw < rotate_max_w_ && !err; iw += 2) {
80 for (ih = 8; ih < rotate_max_h_ && !err; ++ih) {
81 int i;
82
83 ow = ih;
84 oh = iw >> 1;
85
86 align_buffer_16(input, iw * ih)
87 align_buffer_16(output_a1, ow * oh)
88 align_buffer_16(output_b1, ow * oh)
89 align_buffer_16(output_a2, iw * ih)
90 align_buffer_16(output_b2, iw * ih)
91
92 for (i = 0; i < iw * ih; i += 2) {
93 input[i] = i >> 1;
94 input[i + 1] = -(i >> 1);
95 }
96
97 TransposeUV(input, iw, output_a1, ow, output_b1, ow, iw >> 1, ih);
98
99 TransposePlane(output_a1, ow, output_a2, oh, ow, oh);
100 TransposePlane(output_b1, ow, output_b2, oh, ow, oh);
101
102 for (i = 0; i < iw * ih; i += 2) {
103 if (input[i] != output_a2[i >> 1]) {
104 err++;
105 }
106 if (input[i + 1] != output_b2[i >> 1]) {
107 err++;
108 }
109 }
110
111 if (err) {
112 printf("input %dx%d \n", iw, ih);
113 PrintArray(input, iw, ih);
114
115 printf("transpose 1\n");
116 PrintArray(output_a1, ow, oh);
117 PrintArray(output_b1, ow, oh);
118
119 printf("transpose 2\n");
120 PrintArray(output_a2, oh, ow);
121 PrintArray(output_b2, oh, ow);
122 }
123
124 free_aligned_buffer_16(input)
125 free_aligned_buffer_16(output_a1)
126 free_aligned_buffer_16(output_b1)
127 free_aligned_buffer_16(output_a2)
128 free_aligned_buffer_16(output_b2)
129 }
130 }
131
132 EXPECT_EQ(0, err);
133 }
134
TEST_F(libyuvTest,RotatePlane90)135 TEST_F(libyuvTest, RotatePlane90) {
136 int iw, ih, ow, oh;
137 int err = 0;
138
139 for (iw = 8; iw < rotate_max_w_ && !err; ++iw) {
140 for (ih = 8; ih < rotate_max_h_ && !err; ++ih) {
141 int i;
142
143 ow = ih;
144 oh = iw;
145
146 align_buffer_16(input, iw * ih)
147 align_buffer_16(output_0, iw * ih)
148 align_buffer_16(output_90, ow * oh)
149 align_buffer_16(output_180, iw * ih)
150 align_buffer_16(output_270, ow * oh)
151
152 for (i = 0; i < iw * ih; ++i) {
153 input[i] = i;
154 }
155
156 RotatePlane90(input, iw, output_90, ow, iw, ih);
157 RotatePlane90(output_90, ow, output_180, oh, ow, oh);
158 RotatePlane90(output_180, oh, output_270, ow, oh, ow);
159 RotatePlane90(output_270, ow, output_0, iw, ow, oh);
160
161 for (i = 0; i < iw * ih; ++i) {
162 if (input[i] != output_0[i]) {
163 err++;
164 }
165 }
166
167 if (err) {
168 printf("input %dx%d \n", iw, ih);
169 PrintArray(input, iw, ih);
170
171 printf("output 90\n");
172 PrintArray(output_90, ow, oh);
173
174 printf("output 180\n");
175 PrintArray(output_180, iw, ih);
176
177 printf("output 270\n");
178 PrintArray(output_270, ow, oh);
179
180 printf("output 0\n");
181 PrintArray(output_0, iw, ih);
182 }
183
184 free_aligned_buffer_16(input)
185 free_aligned_buffer_16(output_0)
186 free_aligned_buffer_16(output_90)
187 free_aligned_buffer_16(output_180)
188 free_aligned_buffer_16(output_270)
189 }
190 }
191
192 EXPECT_EQ(0, err);
193 }
194
TEST_F(libyuvTest,RotateUV90)195 TEST_F(libyuvTest, RotateUV90) {
196 int iw, ih, ow, oh;
197 int err = 0;
198
199 for (iw = 16; iw < rotate_max_w_ && !err; iw += 2) {
200 for (ih = 8; ih < rotate_max_h_ && !err; ++ih) {
201 int i;
202
203 ow = ih;
204 oh = iw >> 1;
205
206 align_buffer_16(input, iw * ih)
207 align_buffer_16(output_0_u, ow * oh)
208 align_buffer_16(output_0_v, ow * oh)
209 align_buffer_16(output_90_u, ow * oh)
210 align_buffer_16(output_90_v, ow * oh)
211 align_buffer_16(output_180_u, ow * oh)
212 align_buffer_16(output_180_v, ow * oh)
213
214 for (i = 0; i < iw * ih; i += 2) {
215 input[i] = i >> 1;
216 input[i + 1] = -(i >> 1);
217 }
218
219 RotateUV90(input, iw, output_90_u, ow, output_90_v, ow, iw >> 1, ih);
220
221 RotatePlane90(output_90_u, ow, output_180_u, oh, ow, oh);
222 RotatePlane90(output_90_v, ow, output_180_v, oh, ow, oh);
223
224 RotatePlane180(output_180_u, ow, output_0_u, ow, ow, oh);
225 RotatePlane180(output_180_v, ow, output_0_v, ow, ow, oh);
226
227 for (i = 0; i < (ow * oh); ++i) {
228 if (output_0_u[i] != (uint8)i) {
229 err++;
230 }
231 if (output_0_v[i] != (uint8)(-i)) {
232 err++;
233 }
234 }
235
236 if (err) {
237 printf("input %dx%d \n", iw, ih);
238 PrintArray(input, iw, ih);
239
240 printf("output 90_u\n");
241 PrintArray(output_90_u, ow, oh);
242
243 printf("output 90_v\n");
244 PrintArray(output_90_v, ow, oh);
245
246 printf("output 180_u\n");
247 PrintArray(output_180_u, oh, ow);
248
249 printf("output 180_v\n");
250 PrintArray(output_180_v, oh, ow);
251
252 printf("output 0_u\n");
253 PrintArray(output_0_u, oh, ow);
254
255 printf("output 0_v\n");
256 PrintArray(output_0_v, oh, ow);
257 }
258
259 free_aligned_buffer_16(input)
260 free_aligned_buffer_16(output_0_u)
261 free_aligned_buffer_16(output_0_v)
262 free_aligned_buffer_16(output_90_u)
263 free_aligned_buffer_16(output_90_v)
264 free_aligned_buffer_16(output_180_u)
265 free_aligned_buffer_16(output_180_v)
266 }
267 }
268
269 EXPECT_EQ(0, err);
270 }
271
TEST_F(libyuvTest,RotateUV180)272 TEST_F(libyuvTest, RotateUV180) {
273 int iw, ih, ow, oh;
274 int err = 0;
275
276 for (iw = 16; iw < rotate_max_w_ && !err; iw += 2) {
277 for (ih = 8; ih < rotate_max_h_ && !err; ++ih) {
278 int i;
279
280 ow = iw >> 1;
281 oh = ih;
282
283 align_buffer_16(input, iw * ih)
284 align_buffer_16(output_0_u, ow * oh)
285 align_buffer_16(output_0_v, ow * oh)
286 align_buffer_16(output_90_u, ow * oh)
287 align_buffer_16(output_90_v, ow * oh)
288 align_buffer_16(output_180_u, ow * oh)
289 align_buffer_16(output_180_v, ow * oh)
290
291 for (i = 0; i < iw * ih; i += 2) {
292 input[i] = i >> 1;
293 input[i + 1] = -(i >> 1);
294 }
295
296 RotateUV180(input, iw, output_180_u, ow, output_180_v, ow, iw >> 1, ih);
297
298 RotatePlane90(output_180_u, ow, output_90_u, oh, ow, oh);
299 RotatePlane90(output_180_v, ow, output_90_v, oh, ow, oh);
300
301 RotatePlane90(output_90_u, oh, output_0_u, ow, oh, ow);
302 RotatePlane90(output_90_v, oh, output_0_v, ow, oh, ow);
303
304 for (i = 0; i < (ow * oh); ++i) {
305 if (output_0_u[i] != (uint8)i) {
306 err++;
307 }
308 if (output_0_v[i] != (uint8)(-i)) {
309 err++;
310 }
311 }
312
313 if (err) {
314 printf("input %dx%d \n", iw, ih);
315 PrintArray(input, iw, ih);
316
317 printf("output 180_u\n");
318 PrintArray(output_180_u, oh, ow);
319
320 printf("output 180_v\n");
321 PrintArray(output_180_v, oh, ow);
322
323 printf("output 90_u\n");
324 PrintArray(output_90_u, oh, ow);
325
326 printf("output 90_v\n");
327 PrintArray(output_90_v, oh, ow);
328
329 printf("output 0_u\n");
330 PrintArray(output_0_u, ow, oh);
331
332 printf("output 0_v\n");
333 PrintArray(output_0_v, ow, oh);
334 }
335
336 free_aligned_buffer_16(input)
337 free_aligned_buffer_16(output_0_u)
338 free_aligned_buffer_16(output_0_v)
339 free_aligned_buffer_16(output_90_u)
340 free_aligned_buffer_16(output_90_v)
341 free_aligned_buffer_16(output_180_u)
342 free_aligned_buffer_16(output_180_v)
343 }
344 }
345
346 EXPECT_EQ(0, err);
347 }
348
TEST_F(libyuvTest,RotateUV270)349 TEST_F(libyuvTest, RotateUV270) {
350 int iw, ih, ow, oh;
351 int err = 0;
352
353 for (iw = 16; iw < rotate_max_w_ && !err; iw += 2) {
354 for (ih = 8; ih < rotate_max_h_ && !err; ++ih) {
355 int i;
356
357 ow = ih;
358 oh = iw >> 1;
359
360 align_buffer_16(input, iw * ih)
361 align_buffer_16(output_0_u, ow * oh)
362 align_buffer_16(output_0_v, ow * oh)
363 align_buffer_16(output_270_u, ow * oh)
364 align_buffer_16(output_270_v, ow * oh)
365 align_buffer_16(output_180_u, ow * oh)
366 align_buffer_16(output_180_v, ow * oh)
367
368 for (i = 0; i < iw * ih; i += 2) {
369 input[i] = i >> 1;
370 input[i + 1] = -(i >> 1);
371 }
372
373 RotateUV270(input, iw, output_270_u, ow, output_270_v, ow,
374 iw >> 1, ih);
375
376 RotatePlane270(output_270_u, ow, output_180_u, oh, ow, oh);
377 RotatePlane270(output_270_v, ow, output_180_v, oh, ow, oh);
378
379 RotatePlane180(output_180_u, ow, output_0_u, ow, ow, oh);
380 RotatePlane180(output_180_v, ow, output_0_v, ow, ow, oh);
381
382 for (i = 0; i < (ow * oh); ++i) {
383 if (output_0_u[i] != (uint8)i) {
384 err++;
385 }
386 if (output_0_v[i] != (uint8)(-i)) {
387 err++;
388 }
389 }
390
391 if (err) {
392 printf("input %dx%d \n", iw, ih);
393 PrintArray(input, iw, ih);
394
395 printf("output 270_u\n");
396 PrintArray(output_270_u, ow, oh);
397
398 printf("output 270_v\n");
399 PrintArray(output_270_v, ow, oh);
400
401 printf("output 180_u\n");
402 PrintArray(output_180_u, oh, ow);
403
404 printf("output 180_v\n");
405 PrintArray(output_180_v, oh, ow);
406
407 printf("output 0_u\n");
408 PrintArray(output_0_u, oh, ow);
409
410 printf("output 0_v\n");
411 PrintArray(output_0_v, oh, ow);
412 }
413
414 free_aligned_buffer_16(input)
415 free_aligned_buffer_16(output_0_u)
416 free_aligned_buffer_16(output_0_v)
417 free_aligned_buffer_16(output_270_u)
418 free_aligned_buffer_16(output_270_v)
419 free_aligned_buffer_16(output_180_u)
420 free_aligned_buffer_16(output_180_v)
421 }
422 }
423
424 EXPECT_EQ(0, err);
425 }
426
TEST_F(libyuvTest,RotatePlane180)427 TEST_F(libyuvTest, RotatePlane180) {
428 int iw, ih, ow, oh;
429 int err = 0;
430
431 for (iw = 8; iw < rotate_max_w_ && !err; ++iw)
432 for (ih = 8; ih < rotate_max_h_ && !err; ++ih) {
433 int i;
434
435 ow = iw;
436 oh = ih;
437
438 align_buffer_16(input, iw * ih)
439 align_buffer_16(output_0, iw * ih)
440 align_buffer_16(output_180, iw * ih)
441
442 for (i = 0; i < iw * ih; ++i) {
443 input[i] = i;
444 }
445
446 RotatePlane180(input, iw, output_180, ow, iw, ih);
447 RotatePlane180(output_180, ow, output_0, iw, ow, oh);
448
449 for (i = 0; i < iw * ih; ++i) {
450 if (input[i] != output_0[i]) {
451 err++;
452 }
453 }
454
455 if (err) {
456 printf("input %dx%d \n", iw, ih);
457 PrintArray(input, iw, ih);
458
459 printf("output 180\n");
460 PrintArray(output_180, iw, ih);
461
462 printf("output 0\n");
463 PrintArray(output_0, iw, ih);
464 }
465
466 free_aligned_buffer_16(input)
467 free_aligned_buffer_16(output_0)
468 free_aligned_buffer_16(output_180)
469 }
470
471 EXPECT_EQ(0, err);
472 }
473
TEST_F(libyuvTest,RotatePlane270)474 TEST_F(libyuvTest, RotatePlane270) {
475 int iw, ih, ow, oh;
476 int err = 0;
477
478 for (iw = 8; iw < rotate_max_w_ && !err; ++iw) {
479 for (ih = 8; ih < rotate_max_h_ && !err; ++ih) {
480 int i;
481
482 ow = ih;
483 oh = iw;
484
485 align_buffer_16(input, iw * ih)
486 align_buffer_16(output_0, iw * ih)
487 align_buffer_16(output_90, ow * oh)
488 align_buffer_16(output_180, iw * ih)
489 align_buffer_16(output_270, ow * oh)
490
491 for (i = 0; i < iw * ih; ++i)
492 input[i] = i;
493
494 RotatePlane270(input, iw, output_270, ow, iw, ih);
495 RotatePlane270(output_270, ow, output_180, oh, ow, oh);
496 RotatePlane270(output_180, oh, output_90, ow, oh, ow);
497 RotatePlane270(output_90, ow, output_0, iw, ow, oh);
498
499 for (i = 0; i < iw * ih; ++i) {
500 if (input[i] != output_0[i]) {
501 err++;
502 }
503 }
504
505 if (err) {
506 printf("input %dx%d \n", iw, ih);
507 PrintArray(input, iw, ih);
508
509 printf("output 270\n");
510 PrintArray(output_270, ow, oh);
511
512 printf("output 180\n");
513 PrintArray(output_180, iw, ih);
514
515 printf("output 90\n");
516 PrintArray(output_90, ow, oh);
517
518 printf("output 0\n");
519 PrintArray(output_0, iw, ih);
520 }
521
522 free_aligned_buffer_16(input)
523 free_aligned_buffer_16(output_0)
524 free_aligned_buffer_16(output_90)
525 free_aligned_buffer_16(output_180)
526 free_aligned_buffer_16(output_270)
527 }
528 }
529
530 EXPECT_EQ(0, err);
531 }
532
TEST_F(libyuvTest,RotatePlane90and270)533 TEST_F(libyuvTest, RotatePlane90and270) {
534 int iw, ih, ow, oh;
535 int err = 0;
536
537 for (iw = 16; iw < rotate_max_w_ && !err; iw += 4)
538 for (ih = 16; ih < rotate_max_h_ && !err; ih += 4) {
539 int i;
540
541 ow = ih;
542 oh = iw;
543
544 align_buffer_16(input, iw * ih)
545 align_buffer_16(output_0, iw * ih)
546 align_buffer_16(output_90, ow * oh)
547
548 for (i = 0; i < iw * ih; ++i) {
549 input[i] = i;
550 }
551
552 RotatePlane90(input, iw, output_90, ow, iw, ih);
553 RotatePlane270(output_90, ow, output_0, iw, ow, oh);
554
555 for (i = 0; i < iw * ih; ++i) {
556 if (input[i] != output_0[i]) {
557 err++;
558 }
559 }
560
561 if (err) {
562 printf("intput %dx%d\n", iw, ih);
563 PrintArray(input, iw, ih);
564
565 printf("output \n");
566 PrintArray(output_90, ow, oh);
567
568 printf("output \n");
569 PrintArray(output_0, iw, ih);
570 }
571
572 free_aligned_buffer_16(input)
573 free_aligned_buffer_16(output_0)
574 free_aligned_buffer_16(output_90)
575 }
576
577 EXPECT_EQ(0, err);
578 }
579
TEST_F(libyuvTest,RotatePlane90Pitch)580 TEST_F(libyuvTest, RotatePlane90Pitch) {
581 int iw, ih;
582 int err = 0;
583
584 for (iw = 16; iw < rotate_max_w_ && !err; iw += 4)
585 for (ih = 16; ih < rotate_max_h_ && !err; ih += 4) {
586 int i;
587
588 int ow = ih;
589 int oh = iw;
590
591 align_buffer_16(input, iw * ih)
592 align_buffer_16(output_0, iw * ih)
593 align_buffer_16(output_90, ow * oh)
594
595 for (i = 0; i < iw * ih; ++i) {
596 input[i] = i;
597 }
598
599 RotatePlane90(input, iw,
600 output_90 + (ow >> 1), ow,
601 iw >> 1, ih >> 1);
602 RotatePlane90(input + (iw >> 1), iw,
603 output_90 + (ow >> 1) + ow * (oh >> 1), ow,
604 iw >> 1, ih >> 1);
605 RotatePlane90(input + iw * (ih >> 1), iw,
606 output_90, ow,
607 iw >> 1, ih >> 1);
608 RotatePlane90(input + (iw >> 1) + iw * (ih >> 1), iw,
609 output_90 + ow * (oh >> 1), ow,
610 iw >> 1, ih >> 1);
611
612 RotatePlane270(output_90, ih, output_0, iw, ow, oh);
613
614 for (i = 0; i < iw * ih; ++i) {
615 if (input[i] != output_0[i]) {
616 err++;
617 }
618 }
619
620 if (err) {
621 printf("intput %dx%d\n", iw, ih);
622 PrintArray(input, iw, ih);
623
624 printf("output \n");
625 PrintArray(output_90, ow, oh);
626
627 printf("output \n");
628 PrintArray(output_0, iw, ih);
629 }
630
631 free_aligned_buffer_16(input)
632 free_aligned_buffer_16(output_0)
633 free_aligned_buffer_16(output_90)
634 }
635
636 EXPECT_EQ(0, err);
637 }
638
TEST_F(libyuvTest,RotatePlane270Pitch)639 TEST_F(libyuvTest, RotatePlane270Pitch) {
640 int iw, ih, ow, oh;
641 int err = 0;
642
643 for (iw = 16; iw < rotate_max_w_ && !err; iw += 4) {
644 for (ih = 16; ih < rotate_max_h_ && !err; ih += 4) {
645 int i;
646
647 ow = ih;
648 oh = iw;
649
650 align_buffer_16(input, iw * ih)
651 align_buffer_16(output_0, iw * ih)
652 align_buffer_16(output_270, ow * oh)
653
654 for (i = 0; i < iw * ih; ++i) {
655 input[i] = i;
656 }
657
658 RotatePlane270(input, iw,
659 output_270 + ow * (oh >> 1), ow,
660 iw >> 1, ih >> 1);
661 RotatePlane270(input + (iw >> 1), iw,
662 output_270, ow,
663 iw >> 1, ih >> 1);
664 RotatePlane270(input + iw * (ih >> 1), iw,
665 output_270 + (ow >> 1) + ow * (oh >> 1), ow,
666 iw >> 1, ih >> 1);
667 RotatePlane270(input + (iw >> 1) + iw * (ih >> 1), iw,
668 output_270 + (ow >> 1), ow,
669 iw >> 1, ih >> 1);
670
671 RotatePlane90(output_270, ih, output_0, iw, ow, oh);
672
673 for (i = 0; i < iw * ih; ++i) {
674 if (input[i] != output_0[i]) {
675 err++;
676 }
677 }
678
679 if (err) {
680 printf("intput %dx%d\n", iw, ih);
681 PrintArray(input, iw, ih);
682
683 printf("output \n");
684 PrintArray(output_270, ow, oh);
685
686 printf("output \n");
687 PrintArray(output_0, iw, ih);
688 }
689
690 free_aligned_buffer_16(input)
691 free_aligned_buffer_16(output_0)
692 free_aligned_buffer_16(output_270)
693 }
694 }
695
696 EXPECT_EQ(0, err);
697 }
698
TEST_F(libyuvTest,I420Rotate90)699 TEST_F(libyuvTest, I420Rotate90) {
700 int err = 0;
701
702 int yw = 1024;
703 int yh = 768;
704 int b = 128;
705 int uvw = (yw + 1) >> 1;
706 int uvh = (yh + 1) >> 1;
707
708 int i, j;
709
710 int y_plane_size = (yw + b * 2) * (yh + b * 2);
711 int uv_plane_size = (uvw + b * 2) * (uvh + b * 2);
712
713 srandom(time(NULL));
714
715 align_buffer_16(orig_y, y_plane_size)
716 align_buffer_16(orig_u, uv_plane_size)
717 align_buffer_16(orig_v, uv_plane_size)
718 align_buffer_16(ro0_y, y_plane_size)
719 align_buffer_16(ro0_u, uv_plane_size)
720 align_buffer_16(ro0_v, uv_plane_size)
721 align_buffer_16(ro90_y, y_plane_size)
722 align_buffer_16(ro90_u, uv_plane_size)
723 align_buffer_16(ro90_v, uv_plane_size)
724 align_buffer_16(ro270_y, y_plane_size)
725 align_buffer_16(ro270_u, uv_plane_size)
726 align_buffer_16(ro270_v, uv_plane_size)
727 memset(orig_y, 0, y_plane_size);
728 memset(orig_u, 0, uv_plane_size);
729 memset(orig_v, 0, uv_plane_size);
730 memset(ro0_y, 0, y_plane_size);
731 memset(ro0_u, 0, uv_plane_size);
732 memset(ro0_v, 0, uv_plane_size);
733 memset(ro90_y, 0, y_plane_size);
734 memset(ro90_u, 0, uv_plane_size);
735 memset(ro90_v, 0, uv_plane_size);
736 memset(ro270_y, 0, y_plane_size);
737 memset(ro270_u, 0, uv_plane_size);
738 memset(ro270_v, 0, uv_plane_size);
739
740 // fill image buffers with random data
741 for (i = b; i < (yh + b); ++i) {
742 for (j = b; j < (yw + b); ++j) {
743 orig_y[i * (yw + b * 2) + j] = random() & 0xff;
744 }
745 }
746
747 for (i = b; i < (uvh + b); ++i) {
748 for (j = b; j < (uvw + b); ++j) {
749 orig_u[i * (uvw + b * 2) + j] = random() & 0xff;
750 orig_v[i * (uvw + b * 2) + j] = random() & 0xff;
751 }
752 }
753
754 int y_off_0 = b * (yw + b * 2) + b;
755 int uv_off_0 = b * (uvw + b * 2) + b;
756 int y_off_90 = b * (yh + b * 2) + b;
757 int uv_off_90 = b * (uvh + b * 2) + b;
758
759 int y_st_0 = yw + b * 2;
760 int uv_st_0 = uvw + b * 2;
761 int y_st_90 = yh + b * 2;
762 int uv_st_90 = uvh + b * 2;
763
764 I420Rotate(orig_y+y_off_0, y_st_0,
765 orig_u+uv_off_0, uv_st_0,
766 orig_v+uv_off_0, uv_st_0,
767 ro90_y+y_off_90, y_st_90,
768 ro90_u+uv_off_90, uv_st_90,
769 ro90_v+uv_off_90, uv_st_90,
770 yw, yh,
771 kRotateClockwise);
772
773 I420Rotate(ro90_y+y_off_90, y_st_90,
774 ro90_u+uv_off_90, uv_st_90,
775 ro90_v+uv_off_90, uv_st_90,
776 ro270_y+y_off_90, y_st_90,
777 ro270_u+uv_off_90, uv_st_90,
778 ro270_v+uv_off_90, uv_st_90,
779 yh, yw,
780 kRotate180);
781
782 I420Rotate(ro270_y+y_off_90, y_st_90,
783 ro270_u+uv_off_90, uv_st_90,
784 ro270_v+uv_off_90, uv_st_90,
785 ro0_y+y_off_0, y_st_0,
786 ro0_u+uv_off_0, uv_st_0,
787 ro0_v+uv_off_0, uv_st_0,
788 yh, yw,
789 kRotateClockwise);
790
791 for (i = 0; i < y_plane_size; ++i) {
792 if (orig_y[i] != ro0_y[i]) {
793 ++err;
794 }
795 }
796
797 for (i = 0; i < uv_plane_size; ++i) {
798 if (orig_u[i] != ro0_u[i]) {
799 ++err;
800 }
801 if (orig_v[i] != ro0_v[i]) {
802 ++err;
803 }
804 }
805
806 free_aligned_buffer_16(orig_y)
807 free_aligned_buffer_16(orig_u)
808 free_aligned_buffer_16(orig_v)
809 free_aligned_buffer_16(ro0_y)
810 free_aligned_buffer_16(ro0_u)
811 free_aligned_buffer_16(ro0_v)
812 free_aligned_buffer_16(ro90_y)
813 free_aligned_buffer_16(ro90_u)
814 free_aligned_buffer_16(ro90_v)
815 free_aligned_buffer_16(ro270_y)
816 free_aligned_buffer_16(ro270_u)
817 free_aligned_buffer_16(ro270_v)
818
819 EXPECT_EQ(0, err);
820 }
821
TEST_F(libyuvTest,I420Rotate270)822 TEST_F(libyuvTest, I420Rotate270) {
823 int err = 0;
824
825 int yw = 1024;
826 int yh = 768;
827 int b = 128;
828 int uvw = (yw + 1) >> 1;
829 int uvh = (yh + 1) >> 1;
830
831 int i, j;
832
833 int y_plane_size = (yw + b * 2) * (yh + b * 2);
834 int uv_plane_size = (uvw + b * 2) * (uvh + b * 2);
835
836 srandom(time(NULL));
837
838 align_buffer_16(orig_y, y_plane_size)
839 align_buffer_16(orig_u, uv_plane_size)
840 align_buffer_16(orig_v, uv_plane_size)
841 align_buffer_16(ro0_y, y_plane_size)
842 align_buffer_16(ro0_u, uv_plane_size)
843 align_buffer_16(ro0_v, uv_plane_size)
844 align_buffer_16(ro90_y, y_plane_size)
845 align_buffer_16(ro90_u, uv_plane_size)
846 align_buffer_16(ro90_v, uv_plane_size)
847 align_buffer_16(ro270_y, y_plane_size)
848 align_buffer_16(ro270_u, uv_plane_size)
849 align_buffer_16(ro270_v, uv_plane_size)
850 memset(orig_y, 0, y_plane_size);
851 memset(orig_u, 0, uv_plane_size);
852 memset(orig_v, 0, uv_plane_size);
853 memset(ro0_y, 0, y_plane_size);
854 memset(ro0_u, 0, uv_plane_size);
855 memset(ro0_v, 0, uv_plane_size);
856 memset(ro90_y, 0, y_plane_size);
857 memset(ro90_u, 0, uv_plane_size);
858 memset(ro90_v, 0, uv_plane_size);
859 memset(ro270_y, 0, y_plane_size);
860 memset(ro270_u, 0, uv_plane_size);
861 memset(ro270_v, 0, uv_plane_size);
862
863 // fill image buffers with random data
864 for (i = b; i < (yh + b); ++i) {
865 for (j = b; j < (yw + b); ++j) {
866 orig_y[i * (yw + b * 2) + j] = random() & 0xff;
867 }
868 }
869
870 for (i = b; i < (uvh + b); ++i) {
871 for (j = b; j < (uvw + b); ++j) {
872 orig_u[i * (uvw + b * 2) + j] = random() & 0xff;
873 orig_v[i * (uvw + b * 2) + j] = random() & 0xff;
874 }
875 }
876
877 int y_off_0 = b * (yw + b * 2) + b;
878 int uv_off_0 = b * (uvw + b * 2) + b;
879 int y_off_90 = b * (yh + b * 2) + b;
880 int uv_off_90 = b * (uvh + b * 2) + b;
881
882 int y_st_0 = yw + b * 2;
883 int uv_st_0 = uvw + b * 2;
884 int y_st_90 = yh + b * 2;
885 int uv_st_90 = uvh + b * 2;
886
887 I420Rotate(orig_y+y_off_0, y_st_0,
888 orig_u+uv_off_0, uv_st_0,
889 orig_v+uv_off_0, uv_st_0,
890 ro270_y+y_off_90, y_st_90,
891 ro270_u+uv_off_90, uv_st_90,
892 ro270_v+uv_off_90, uv_st_90,
893 yw, yh,
894 kRotateCounterClockwise);
895
896 I420Rotate(ro270_y+y_off_90, y_st_90,
897 ro270_u+uv_off_90, uv_st_90,
898 ro270_v+uv_off_90, uv_st_90,
899 ro90_y+y_off_90, y_st_90,
900 ro90_u+uv_off_90, uv_st_90,
901 ro90_v+uv_off_90, uv_st_90,
902 yh, yw,
903 kRotate180);
904
905 I420Rotate(ro90_y+y_off_90, y_st_90,
906 ro90_u+uv_off_90, uv_st_90,
907 ro90_v+uv_off_90, uv_st_90,
908 ro0_y+y_off_0, y_st_0,
909 ro0_u+uv_off_0, uv_st_0,
910 ro0_v+uv_off_0, uv_st_0,
911 yh, yw,
912 kRotateCounterClockwise);
913
914 for (i = 0; i < y_plane_size; ++i) {
915 if (orig_y[i] != ro0_y[i]) {
916 ++err;
917 }
918 }
919
920 for (i = 0; i < uv_plane_size; ++i) {
921 if (orig_u[i] != ro0_u[i]) {
922 ++err;
923 }
924 if (orig_v[i] != ro0_v[i]) {
925 ++err;
926 }
927 }
928
929 free_aligned_buffer_16(orig_y)
930 free_aligned_buffer_16(orig_u)
931 free_aligned_buffer_16(orig_v)
932 free_aligned_buffer_16(ro0_y)
933 free_aligned_buffer_16(ro0_u)
934 free_aligned_buffer_16(ro0_v)
935 free_aligned_buffer_16(ro90_y)
936 free_aligned_buffer_16(ro90_u)
937 free_aligned_buffer_16(ro90_v)
938 free_aligned_buffer_16(ro270_y)
939 free_aligned_buffer_16(ro270_u)
940 free_aligned_buffer_16(ro270_v)
941
942 EXPECT_EQ(0, err);
943 }
944
TEST_F(libyuvTest,NV12ToI420Rotate90)945 TEST_F(libyuvTest, NV12ToI420Rotate90) {
946 int err = 0;
947
948 int yw = 1024;
949 int yh = 768;
950 int b = 128;
951 int uvw = (yw + 1) >> 1;
952 int uvh = (yh + 1) >> 1;
953 int i, j;
954
955 int y_plane_size = (yw + b * 2) * (yh + b * 2);
956 int uv_plane_size = (uvw + b * 2) * (uvh + b * 2);
957 int o_uv_plane_size = (uvw * 2 + b * 2) * (uvh + b * 2);
958
959 srandom(time(NULL));
960
961 align_buffer_16(orig_y, y_plane_size)
962 align_buffer_16(orig_uv, o_uv_plane_size)
963 align_buffer_16(ro0_y, y_plane_size)
964 align_buffer_16(ro0_u, uv_plane_size)
965 align_buffer_16(ro0_v, uv_plane_size)
966 align_buffer_16(ro90_y, y_plane_size)
967 align_buffer_16(ro90_u, uv_plane_size)
968 align_buffer_16(ro90_v, uv_plane_size)
969 memset(orig_y, 0, y_plane_size);
970 memset(orig_uv, 0, uv_plane_size);
971 memset(ro0_y, 0, y_plane_size);
972 memset(ro0_u, 0, uv_plane_size);
973 memset(ro0_v, 0, uv_plane_size);
974 memset(ro90_y, 0, y_plane_size);
975 memset(ro90_u, 0, uv_plane_size);
976 memset(ro90_v, 0, uv_plane_size);
977
978 // fill image buffers with random data
979 for (i = b; i < (yh + b); ++i) {
980 for (j = b; j < (yw + b); ++j) {
981 orig_y[i * (yw + b * 2) + j] = random() & 0xff;
982 }
983 }
984
985 for (i = b; i < (uvh + b); ++i) {
986 for (j = b; j < (uvw * 2 + b); j += 2) {
987 uint8 random_number = random() & 0x7f;
988 orig_uv[i * (uvw * 2 + b * 2) + j] = random_number;
989 orig_uv[i * (uvw * 2 + b * 2) + j + 1] = -random_number;
990 }
991 }
992
993 int y_off_0 = b * (yw + b * 2) + b;
994 int uv_off_0 = b * (uvw + b * 2) + b;
995 int y_off_90 = b * (yh + b * 2) + b;
996 int uv_off_90 = b * (uvh + b * 2) + b;
997
998 int y_st_0 = yw + b * 2;
999 int uv_st_0 = uvw + b * 2;
1000 int y_st_90 = yh + b * 2;
1001 int uv_st_90 = uvh + b * 2;
1002
1003 NV12ToI420Rotate(orig_y+y_off_0, y_st_0,
1004 orig_uv+y_off_0, y_st_0,
1005 ro90_y+y_off_90, y_st_90,
1006 ro90_u+uv_off_90, uv_st_90,
1007 ro90_v+uv_off_90, uv_st_90,
1008 yw, yh,
1009 kRotateClockwise);
1010
1011 I420Rotate(ro90_y+y_off_90, y_st_90,
1012 ro90_u+uv_off_90, uv_st_90,
1013 ro90_v+uv_off_90, uv_st_90,
1014 ro0_y+y_off_0, y_st_0,
1015 ro0_u+uv_off_0, uv_st_0,
1016 ro0_v+uv_off_0, uv_st_0,
1017 yh, yw,
1018 kRotateCounterClockwise);
1019
1020 for (i = 0; i < y_plane_size; ++i) {
1021 if (orig_y[i] != ro0_y[i])
1022 ++err;
1023 }
1024
1025 int zero_cnt = 0;
1026
1027 for (i = 0; i < uv_plane_size; ++i) {
1028 if ((signed char)ro0_u[i] != -(signed char)ro0_v[i]) {
1029 ++err;
1030 }
1031 if (ro0_u[i] != 0) {
1032 ++zero_cnt;
1033 }
1034 }
1035
1036 if (!zero_cnt) {
1037 ++err;
1038 }
1039
1040 free_aligned_buffer_16(orig_y)
1041 free_aligned_buffer_16(orig_uv)
1042 free_aligned_buffer_16(ro0_y)
1043 free_aligned_buffer_16(ro0_u)
1044 free_aligned_buffer_16(ro0_v)
1045 free_aligned_buffer_16(ro90_y)
1046 free_aligned_buffer_16(ro90_u)
1047 free_aligned_buffer_16(ro90_v)
1048
1049 EXPECT_EQ(0, err);
1050 }
1051
TEST_F(libyuvTest,NV12ToI420Rotate270)1052 TEST_F(libyuvTest, NV12ToI420Rotate270) {
1053 int err = 0;
1054
1055 int yw = 1024;
1056 int yh = 768;
1057 int b = 128;
1058 int uvw = (yw + 1) >> 1;
1059 int uvh = (yh + 1) >> 1;
1060
1061 int i, j;
1062
1063 int y_plane_size = (yw + b * 2) * (yh + b * 2);
1064 int uv_plane_size = (uvw + b * 2) * (uvh + b * 2);
1065 int o_uv_plane_size = (uvw * 2 + b * 2) * (uvh + b * 2);
1066
1067 srandom(time(NULL));
1068
1069 align_buffer_16(orig_y, y_plane_size)
1070 align_buffer_16(orig_uv, o_uv_plane_size)
1071 align_buffer_16(ro0_y, y_plane_size)
1072 align_buffer_16(ro0_u, uv_plane_size)
1073 align_buffer_16(ro0_v, uv_plane_size)
1074 align_buffer_16(ro270_y, y_plane_size)
1075 align_buffer_16(ro270_u, uv_plane_size)
1076 align_buffer_16(ro270_v, uv_plane_size)
1077 memset(orig_y, 0, y_plane_size);
1078 memset(orig_uv, 0, o_uv_plane_size);
1079 memset(ro0_y, 0, y_plane_size);
1080 memset(ro0_u, 0, uv_plane_size);
1081 memset(ro0_v, 0, uv_plane_size);
1082 memset(ro270_y, 0, y_plane_size);
1083 memset(ro270_u, 0, uv_plane_size);
1084 memset(ro270_v, 0, uv_plane_size);
1085
1086 // fill image buffers with random data
1087 for (i = b; i < (yh + b); ++i) {
1088 for (j = b; j < (yw + b); ++j) {
1089 orig_y[i * (yw + b * 2) + j] = random() & 0xff;
1090 }
1091 }
1092
1093 for (i = b; i < (uvh + b); ++i) {
1094 for (j = b; j < (uvw * 2 + b); j += 2) {
1095 uint8 random_number = random() & 0x7f;
1096 orig_uv[i * (uvw * 2 + b * 2) + j] = random_number;
1097 orig_uv[i * (uvw * 2 + b * 2) + j + 1] = -random_number;
1098 }
1099 }
1100
1101 int y_off_0 = b * (yw + b * 2) + b;
1102 int uv_off_0 = b * (uvw + b * 2) + b;
1103 int y_off_270 = b * (yh + b * 2) + b;
1104 int uv_off_270 = b * (uvh + b * 2) + b;
1105
1106 int y_st_0 = yw + b * 2;
1107 int uv_st_0 = uvw + b * 2;
1108 int y_st_270 = yh + b * 2;
1109 int uv_st_270 = uvh + b * 2;
1110
1111 NV12ToI420Rotate(orig_y+y_off_0, y_st_0,
1112 orig_uv+y_off_0, y_st_0,
1113 ro270_y+y_off_270, y_st_270,
1114 ro270_u+uv_off_270, uv_st_270,
1115 ro270_v+uv_off_270, uv_st_270,
1116 yw, yh,
1117 kRotateCounterClockwise);
1118
1119 I420Rotate(ro270_y+y_off_270, y_st_270,
1120 ro270_u+uv_off_270, uv_st_270,
1121 ro270_v+uv_off_270, uv_st_270,
1122 ro0_y+y_off_0, y_st_0,
1123 ro0_u+uv_off_0, uv_st_0,
1124 ro0_v+uv_off_0, uv_st_0,
1125 yh, yw,
1126 kRotateClockwise);
1127
1128 for (i = 0; i < y_plane_size; ++i) {
1129 if (orig_y[i] != ro0_y[i])
1130 ++err;
1131 }
1132
1133 int zero_cnt = 0;
1134
1135 for (i = 0; i < uv_plane_size; ++i) {
1136 if ((signed char)ro0_u[i] != -(signed char)ro0_v[i]) {
1137 ++err;
1138 }
1139 if (ro0_u[i] != 0) {
1140 ++zero_cnt;
1141 }
1142 }
1143
1144 if (!zero_cnt) {
1145 ++err;
1146 }
1147
1148 free_aligned_buffer_16(orig_y)
1149 free_aligned_buffer_16(orig_uv)
1150 free_aligned_buffer_16(ro0_y)
1151 free_aligned_buffer_16(ro0_u)
1152 free_aligned_buffer_16(ro0_v)
1153 free_aligned_buffer_16(ro270_y)
1154 free_aligned_buffer_16(ro270_u)
1155 free_aligned_buffer_16(ro270_v)
1156
1157 EXPECT_EQ(0, err);
1158 }
1159
TEST_F(libyuvTest,NV12ToI420Rotate180)1160 TEST_F(libyuvTest, NV12ToI420Rotate180) {
1161 int err = 0;
1162
1163 int yw = 1024;
1164 int yh = 768;
1165 int b = 128;
1166 int uvw = (yw + 1) >> 1;
1167 int uvh = (yh + 1) >> 1;
1168
1169 int i, j;
1170
1171 int y_plane_size = (yw + b * 2) * (yh + b * 2);
1172 int uv_plane_size = (uvw + b * 2) * (uvh + b * 2);
1173 int o_uv_plane_size = (uvw * 2 + b * 2) * (uvh + b * 2);
1174
1175 srandom(time(NULL));
1176
1177 align_buffer_16(orig_y, y_plane_size)
1178 align_buffer_16(orig_uv, o_uv_plane_size)
1179 align_buffer_16(ro0_y, y_plane_size)
1180 align_buffer_16(ro0_u, uv_plane_size)
1181 align_buffer_16(ro0_v, uv_plane_size)
1182 align_buffer_16(ro180_y, y_plane_size)
1183 align_buffer_16(ro180_u, uv_plane_size)
1184 align_buffer_16(ro180_v, uv_plane_size)
1185 memset(orig_y, 0, y_plane_size);
1186 memset(orig_uv, 0, o_uv_plane_size);
1187 memset(ro0_y, 0, y_plane_size);
1188 memset(ro0_u, 0, uv_plane_size);
1189 memset(ro0_v, 0, uv_plane_size);
1190 memset(ro180_y, 0, y_plane_size);
1191 memset(ro180_u, 0, uv_plane_size);
1192 memset(ro180_v, 0, uv_plane_size);
1193
1194 // fill image buffers with random data
1195 for (i = b; i < (yh + b); ++i) {
1196 for (j = b; j < (yw + b); ++j) {
1197 orig_y[i * (yw + b * 2) + j] = random() & 0xff;
1198 }
1199 }
1200
1201 for (i = b; i < (uvh + b); ++i) {
1202 for (j = b; j < (uvw * 2 + b); j += 2) {
1203 uint8 random_number = random() & 0x7f;
1204 orig_uv[i * (uvw * 2 + b * 2) + j] = random_number;
1205 orig_uv[i * (uvw * 2 + b * 2) + j + 1] = -random_number;
1206 }
1207 }
1208
1209 int y_off = b * (yw + b * 2) + b;
1210 int uv_off = b * (uvw + b * 2) + b;
1211
1212 int y_st = yw + b * 2;
1213 int uv_st = uvw + b * 2;
1214
1215 NV12ToI420Rotate(orig_y+y_off, y_st,
1216 orig_uv+y_off, y_st,
1217 ro180_y+y_off, y_st,
1218 ro180_u+uv_off, uv_st,
1219 ro180_v+uv_off, uv_st,
1220 yw, yh,
1221 kRotate180);
1222
1223 I420Rotate(ro180_y+y_off, y_st,
1224 ro180_u+uv_off, uv_st,
1225 ro180_v+uv_off, uv_st,
1226 ro0_y+y_off, y_st,
1227 ro0_u+uv_off, uv_st,
1228 ro0_v+uv_off, uv_st,
1229 yw, yh,
1230 kRotate180);
1231
1232 for (i = 0; i < y_plane_size; ++i) {
1233 if (orig_y[i] != ro0_y[i]) {
1234 ++err;
1235 }
1236 }
1237
1238 int zero_cnt = 0;
1239
1240 for (i = 0; i < uv_plane_size; ++i) {
1241 if ((signed char)ro0_u[i] != -(signed char)ro0_v[i]) {
1242 ++err;
1243 }
1244 if (ro0_u[i] != 0) {
1245 ++zero_cnt;
1246 }
1247 }
1248
1249 if (!zero_cnt) {
1250 ++err;
1251 }
1252
1253 free_aligned_buffer_16(orig_y)
1254 free_aligned_buffer_16(orig_uv)
1255 free_aligned_buffer_16(ro0_y)
1256 free_aligned_buffer_16(ro0_u)
1257 free_aligned_buffer_16(ro0_v)
1258 free_aligned_buffer_16(ro180_y)
1259 free_aligned_buffer_16(ro180_u)
1260 free_aligned_buffer_16(ro180_v)
1261
1262 EXPECT_EQ(0, err);
1263 }
1264
TEST_F(libyuvTest,NV12ToI420RotateNegHeight90)1265 TEST_F(libyuvTest, NV12ToI420RotateNegHeight90) {
1266 int y_err = 0, uv_err = 0;
1267
1268 int yw = 1024;
1269 int yh = 768;
1270 int b = 128;
1271 int uvw = (yw + 1) >> 1;
1272 int uvh = (yh + 1) >> 1;
1273 int i, j;
1274
1275 int y_plane_size = (yw + b * 2) * (yh + b * 2);
1276 int uv_plane_size = (uvw + b * 2) * (uvh + b * 2);
1277 int o_uv_plane_size = (uvw * 2 + b * 2) * (uvh + b * 2);
1278
1279 srandom(time(NULL));
1280
1281 align_buffer_16(orig_y, y_plane_size)
1282 align_buffer_16(orig_uv, o_uv_plane_size)
1283 align_buffer_16(roa_y, y_plane_size)
1284 align_buffer_16(roa_u, uv_plane_size)
1285 align_buffer_16(roa_v, uv_plane_size)
1286 align_buffer_16(rob_y, y_plane_size)
1287 align_buffer_16(rob_u, uv_plane_size)
1288 align_buffer_16(rob_v, uv_plane_size)
1289 align_buffer_16(roc_y, y_plane_size)
1290 align_buffer_16(roc_u, uv_plane_size)
1291 align_buffer_16(roc_v, uv_plane_size)
1292 memset(orig_y, 0, y_plane_size);
1293 memset(orig_uv, 0, o_uv_plane_size);
1294 memset(roa_y, 0, y_plane_size);
1295 memset(roa_u, 0, uv_plane_size);
1296 memset(roa_v, 0, uv_plane_size);
1297 memset(rob_y, 0, y_plane_size);
1298 memset(rob_u, 0, uv_plane_size);
1299 memset(rob_v, 0, uv_plane_size);
1300 memset(roc_y, 0, y_plane_size);
1301 memset(roc_u, 0, uv_plane_size);
1302 memset(roc_v, 0, uv_plane_size);
1303
1304 // fill image buffers with random data
1305 for (i = b; i < (yh + b); ++i) {
1306 for (j = b; j < (yw + b); ++j) {
1307 orig_y[i * (yw + b * 2) + j] = random() & 0xff;
1308 }
1309 }
1310
1311 for (i = b; i < (uvh + b); ++i) {
1312 for (j = b; j < (uvw * 2 + b); j += 2) {
1313 uint8 random_number = random() & 0x7f;
1314 orig_uv[i * (uvw * 2 + b * 2) + j] = random_number;
1315 orig_uv[i * (uvw * 2 + b * 2) + j + 1] = -random_number;
1316 }
1317 }
1318
1319 int y_off_0 = b * (yw + b * 2) + b;
1320 int uv_off_0 = b * (uvw + b * 2) + b;
1321 int y_off_90 = b * (yh + b * 2) + b;
1322 int uv_off_90 = b * (uvh + b * 2) + b;
1323
1324 int y_st_0 = yw + b * 2;
1325 int uv_st_0 = uvw + b * 2;
1326 int y_st_90 = yh + b * 2;
1327 int uv_st_90 = uvh + b * 2;
1328
1329 NV12ToI420Rotate(orig_y+y_off_0, y_st_0,
1330 orig_uv+y_off_0, y_st_0,
1331 roa_y+y_off_90, y_st_90,
1332 roa_u+uv_off_90, uv_st_90,
1333 roa_v+uv_off_90, uv_st_90,
1334 yw, -yh,
1335 kRotateClockwise);
1336
1337 I420Rotate(roa_y+y_off_90, y_st_90,
1338 roa_u+uv_off_90, uv_st_90,
1339 roa_v+uv_off_90, uv_st_90,
1340 rob_y+y_off_0, y_st_0,
1341 rob_u+uv_off_0, uv_st_0,
1342 rob_v+uv_off_0, uv_st_0,
1343 yh, -yw,
1344 kRotateCounterClockwise);
1345
1346 I420Rotate(rob_y+y_off_0, y_st_0,
1347 rob_u+uv_off_0, uv_st_0,
1348 rob_v+uv_off_0, uv_st_0,
1349 roc_y+y_off_0, y_st_0,
1350 roc_u+uv_off_0, uv_st_0,
1351 roc_v+uv_off_0, uv_st_0,
1352 yw, yh,
1353 kRotate180);
1354
1355 for (i = 0; i < y_plane_size; ++i) {
1356 if (orig_y[i] != roc_y[i]) {
1357 ++y_err;
1358 }
1359 }
1360
1361 if (y_err) {
1362 printf("input %dx%d \n", yw, yh);
1363 PrintArray(orig_y, y_st_0, yh + b * 2);
1364
1365 printf("rotate a\n");
1366 PrintArray(roa_y, y_st_90, y_st_0);
1367
1368 printf("rotate b\n");
1369 PrintArray(rob_y, y_st_90, y_st_0);
1370
1371 printf("rotate c\n");
1372 PrintArray(roc_y, y_st_0, y_st_90);
1373 }
1374
1375 int zero_cnt = 0;
1376
1377 for (i = 0; i < uv_plane_size; ++i) {
1378 if ((signed char)roc_u[i] != -(signed char)roc_v[i]) {
1379 ++uv_err;
1380 }
1381 if (rob_u[i] != 0) {
1382 ++zero_cnt;
1383 }
1384 }
1385
1386 if (!zero_cnt) {
1387 ++uv_err;
1388 }
1389
1390 if (uv_err) {
1391 printf("input %dx%d \n", uvw * 2, uvh);
1392 PrintArray(orig_uv, y_st_0, uvh + b * 2);
1393
1394 printf("rotate a\n");
1395 PrintArray(roa_u, uv_st_90, uv_st_0);
1396 PrintArray(roa_v, uv_st_90, uv_st_0);
1397
1398 printf("rotate b\n");
1399 PrintArray(rob_u, uv_st_90, uv_st_0);
1400 PrintArray(rob_v, uv_st_90, uv_st_0);
1401
1402 printf("rotate c\n");
1403 PrintArray(roc_u, uv_st_0, uv_st_90);
1404 PrintArray(roc_v, uv_st_0, uv_st_90);
1405 }
1406
1407 free_aligned_buffer_16(orig_y)
1408 free_aligned_buffer_16(orig_uv)
1409 free_aligned_buffer_16(roa_y)
1410 free_aligned_buffer_16(roa_u)
1411 free_aligned_buffer_16(roa_v)
1412 free_aligned_buffer_16(rob_y)
1413 free_aligned_buffer_16(rob_u)
1414 free_aligned_buffer_16(rob_v)
1415 free_aligned_buffer_16(roc_y)
1416 free_aligned_buffer_16(roc_u)
1417 free_aligned_buffer_16(roc_v)
1418
1419 EXPECT_EQ(0, y_err + uv_err);
1420 }
1421
TEST_F(libyuvTest,NV12ToI420RotateNegHeight180)1422 TEST_F(libyuvTest, NV12ToI420RotateNegHeight180) {
1423 int y_err = 0, uv_err = 0;
1424
1425 int yw = 1024;
1426 int yh = 768;
1427 int b = 128;
1428 int uvw = (yw + 1) >> 1;
1429 int uvh = (yh + 1) >> 1;
1430 int i, j;
1431
1432 int y_plane_size = (yw + b * 2) * (yh + b * 2);
1433 int uv_plane_size = (uvw + b * 2) * (uvh + b * 2);
1434 int o_uv_plane_size = (uvw * 2 + b * 2) * (uvh + b * 2);
1435
1436 srandom(time(NULL));
1437
1438 align_buffer_16(orig_y, y_plane_size)
1439 align_buffer_16(orig_uv, o_uv_plane_size)
1440 align_buffer_16(roa_y, y_plane_size)
1441 align_buffer_16(roa_u, uv_plane_size)
1442 align_buffer_16(roa_v, uv_plane_size)
1443 align_buffer_16(rob_y, y_plane_size)
1444 align_buffer_16(rob_u, uv_plane_size)
1445 align_buffer_16(rob_v, uv_plane_size)
1446 memset(orig_y, 0, y_plane_size);
1447 memset(orig_uv, 0, o_uv_plane_size);
1448 memset(roa_y, 0, y_plane_size);
1449 memset(roa_u, 0, uv_plane_size);
1450 memset(roa_v, 0, uv_plane_size);
1451 memset(rob_y, 0, y_plane_size);
1452 memset(rob_u, 0, uv_plane_size);
1453 memset(rob_v, 0, uv_plane_size);
1454
1455 // fill image buffers with random data
1456 for (i = b; i < (yh + b); ++i) {
1457 for (j = b; j < (yw + b); ++j) {
1458 orig_y[i * (yw + b * 2) + j] = random() & 0xff;
1459 }
1460 }
1461
1462 for (i = b; i < (uvh + b); ++i) {
1463 for (j = b; j < (uvw * 2 + b); j += 2) {
1464 uint8 random_number = random() & 0x7f;
1465 orig_uv[i * (uvw * 2 + b * 2) + j] = random_number;
1466 orig_uv[i * (uvw * 2 + b * 2) + j + 1] = -random_number;
1467 }
1468 }
1469
1470 int y_off = b * (yw + b * 2) + b;
1471 int uv_off = b * (uvw + b * 2) + b;
1472
1473 int y_st = yw + b * 2;
1474 int uv_st = uvw + b * 2;
1475
1476 NV12ToI420Rotate(orig_y+y_off, y_st,
1477 orig_uv+y_off, y_st,
1478 roa_y+y_off, y_st,
1479 roa_u+uv_off, uv_st,
1480 roa_v+uv_off, uv_st,
1481 yw, -yh,
1482 kRotate180);
1483
1484 I420Rotate(roa_y+y_off, y_st,
1485 roa_u+uv_off, uv_st,
1486 roa_v+uv_off, uv_st,
1487 rob_y+y_off, y_st,
1488 rob_u+uv_off, uv_st,
1489 rob_v+uv_off, uv_st,
1490 yw, -yh,
1491 kRotate180);
1492
1493 for (i = 0; i < y_plane_size; ++i) {
1494 if (orig_y[i] != rob_y[i])
1495 ++y_err;
1496 }
1497
1498 if (y_err) {
1499 printf("input %dx%d \n", yw, yh);
1500 PrintArray(orig_y, y_st, yh + b * 2);
1501
1502 printf("rotate a\n");
1503 PrintArray(roa_y, y_st, yh + b * 2);
1504
1505 printf("rotate b\n");
1506 PrintArray(rob_y, y_st, yh + b * 2);
1507 }
1508
1509 int zero_cnt = 0;
1510
1511 for (i = 0; i < uv_plane_size; ++i) {
1512 if ((signed char)rob_u[i] != -(signed char)rob_v[i]) {
1513 ++uv_err;
1514 }
1515 if (rob_u[i] != 0) {
1516 ++zero_cnt;
1517 }
1518 }
1519
1520 if (!zero_cnt) {
1521 ++uv_err;
1522 }
1523
1524 if (uv_err) {
1525 printf("input %dx%d \n", uvw * 2, uvh);
1526 PrintArray(orig_uv, y_st, uvh + b * 2);
1527
1528 printf("rotate a\n");
1529 PrintArray(roa_u, uv_st, uvh + b * 2);
1530 PrintArray(roa_v, uv_st, uvh + b * 2);
1531
1532 printf("rotate b\n");
1533 PrintArray(rob_u, uv_st, uvh + b * 2);
1534 PrintArray(rob_v, uv_st, uvh + b * 2);
1535 }
1536
1537 free_aligned_buffer_16(orig_y)
1538 free_aligned_buffer_16(orig_uv)
1539 free_aligned_buffer_16(roa_y)
1540 free_aligned_buffer_16(roa_u)
1541 free_aligned_buffer_16(roa_v)
1542 free_aligned_buffer_16(rob_y)
1543 free_aligned_buffer_16(rob_u)
1544 free_aligned_buffer_16(rob_v)
1545
1546 EXPECT_EQ(0, y_err + uv_err);
1547 }
1548
1549 } // namespace libyuv
1550