2
0

rotate_argb_test.cc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright 2012 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. #include <stdlib.h>
  11. #include "../unit_test/unit_test.h"
  12. #include "libyuv/cpu_id.h"
  13. #include "libyuv/rotate_argb.h"
  14. namespace libyuv {
  15. void TestRotateBpp(int src_width,
  16. int src_height,
  17. int dst_width,
  18. int dst_height,
  19. libyuv::RotationMode mode,
  20. int benchmark_iterations,
  21. int disable_cpu_flags,
  22. int benchmark_cpu_info,
  23. const int kBpp) {
  24. if (src_width < 1) {
  25. src_width = 1;
  26. }
  27. if (src_height < 1) {
  28. src_height = 1;
  29. }
  30. if (dst_width < 1) {
  31. dst_width = 1;
  32. }
  33. if (dst_height < 1) {
  34. dst_height = 1;
  35. }
  36. int src_stride_argb = src_width * kBpp;
  37. int src_argb_plane_size = src_stride_argb * abs(src_height);
  38. align_buffer_page_end(src_argb, src_argb_plane_size);
  39. for (int i = 0; i < src_argb_plane_size; ++i) {
  40. src_argb[i] = fastrand() & 0xff;
  41. }
  42. int dst_stride_argb = dst_width * kBpp;
  43. int dst_argb_plane_size = dst_stride_argb * dst_height;
  44. align_buffer_page_end(dst_argb_c, dst_argb_plane_size);
  45. align_buffer_page_end(dst_argb_opt, dst_argb_plane_size);
  46. memset(dst_argb_c, 2, dst_argb_plane_size);
  47. memset(dst_argb_opt, 3, dst_argb_plane_size);
  48. if (kBpp == 1) {
  49. MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
  50. RotatePlane(src_argb, src_stride_argb, dst_argb_c, dst_stride_argb,
  51. src_width, src_height, mode);
  52. MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
  53. for (int i = 0; i < benchmark_iterations; ++i) {
  54. RotatePlane(src_argb, src_stride_argb, dst_argb_opt, dst_stride_argb,
  55. src_width, src_height, mode);
  56. }
  57. } else if (kBpp == 4) {
  58. MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
  59. ARGBRotate(src_argb, src_stride_argb, dst_argb_c, dst_stride_argb,
  60. src_width, src_height, mode);
  61. MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
  62. for (int i = 0; i < benchmark_iterations; ++i) {
  63. ARGBRotate(src_argb, src_stride_argb, dst_argb_opt, dst_stride_argb,
  64. src_width, src_height, mode);
  65. }
  66. }
  67. // Rotation should be exact.
  68. for (int i = 0; i < dst_argb_plane_size; ++i) {
  69. EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]);
  70. }
  71. free_aligned_buffer_page_end(dst_argb_c);
  72. free_aligned_buffer_page_end(dst_argb_opt);
  73. free_aligned_buffer_page_end(src_argb);
  74. }
  75. static void ARGBTestRotate(int src_width,
  76. int src_height,
  77. int dst_width,
  78. int dst_height,
  79. libyuv::RotationMode mode,
  80. int benchmark_iterations,
  81. int disable_cpu_flags,
  82. int benchmark_cpu_info) {
  83. TestRotateBpp(src_width, src_height, dst_width, dst_height, mode,
  84. benchmark_iterations, disable_cpu_flags, benchmark_cpu_info, 4);
  85. }
  86. TEST_F(LibYUVRotateTest, ARGBRotate0_Opt) {
  87. ARGBTestRotate(benchmark_width_, benchmark_height_, benchmark_width_,
  88. benchmark_height_, kRotate0, benchmark_iterations_,
  89. disable_cpu_flags_, benchmark_cpu_info_);
  90. }
  91. TEST_F(LibYUVRotateTest, ARGBRotate90_Opt) {
  92. ARGBTestRotate(benchmark_width_, benchmark_height_, benchmark_height_,
  93. benchmark_width_, kRotate90, benchmark_iterations_,
  94. disable_cpu_flags_, benchmark_cpu_info_);
  95. }
  96. TEST_F(LibYUVRotateTest, ARGBRotate180_Opt) {
  97. ARGBTestRotate(benchmark_width_, benchmark_height_, benchmark_width_,
  98. benchmark_height_, kRotate180, benchmark_iterations_,
  99. disable_cpu_flags_, benchmark_cpu_info_);
  100. }
  101. TEST_F(LibYUVRotateTest, ARGBRotate270_Opt) {
  102. ARGBTestRotate(benchmark_width_, benchmark_height_, benchmark_height_,
  103. benchmark_width_, kRotate270, benchmark_iterations_,
  104. disable_cpu_flags_, benchmark_cpu_info_);
  105. }
  106. static void TestRotatePlane(int src_width,
  107. int src_height,
  108. int dst_width,
  109. int dst_height,
  110. libyuv::RotationMode mode,
  111. int benchmark_iterations,
  112. int disable_cpu_flags,
  113. int benchmark_cpu_info) {
  114. TestRotateBpp(src_width, src_height, dst_width, dst_height, mode,
  115. benchmark_iterations, disable_cpu_flags, benchmark_cpu_info, 1);
  116. }
  117. TEST_F(LibYUVRotateTest, RotatePlane0_Opt) {
  118. TestRotatePlane(benchmark_width_, benchmark_height_, benchmark_width_,
  119. benchmark_height_, kRotate0, benchmark_iterations_,
  120. disable_cpu_flags_, benchmark_cpu_info_);
  121. }
  122. TEST_F(LibYUVRotateTest, RotatePlane90_Opt) {
  123. TestRotatePlane(benchmark_width_, benchmark_height_, benchmark_height_,
  124. benchmark_width_, kRotate90, benchmark_iterations_,
  125. disable_cpu_flags_, benchmark_cpu_info_);
  126. }
  127. TEST_F(LibYUVRotateTest, RotatePlane180_Opt) {
  128. TestRotatePlane(benchmark_width_, benchmark_height_, benchmark_width_,
  129. benchmark_height_, kRotate180, benchmark_iterations_,
  130. disable_cpu_flags_, benchmark_cpu_info_);
  131. }
  132. TEST_F(LibYUVRotateTest, RotatePlane270_Opt) {
  133. TestRotatePlane(benchmark_width_, benchmark_height_, benchmark_height_,
  134. benchmark_width_, kRotate270, benchmark_iterations_,
  135. disable_cpu_flags_, benchmark_cpu_info_);
  136. }
  137. TEST_F(LibYUVRotateTest, DISABLED_RotatePlane0_Odd) {
  138. TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
  139. benchmark_width_ - 3, benchmark_height_ - 1, kRotate0,
  140. benchmark_iterations_, disable_cpu_flags_,
  141. benchmark_cpu_info_);
  142. }
  143. TEST_F(LibYUVRotateTest, DISABLED_RotatePlane90_Odd) {
  144. TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
  145. benchmark_height_ - 1, benchmark_width_ - 3, kRotate90,
  146. benchmark_iterations_, disable_cpu_flags_,
  147. benchmark_cpu_info_);
  148. }
  149. TEST_F(LibYUVRotateTest, DISABLED_RotatePlane180_Odd) {
  150. TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
  151. benchmark_width_ - 3, benchmark_height_ - 1, kRotate180,
  152. benchmark_iterations_, disable_cpu_flags_,
  153. benchmark_cpu_info_);
  154. }
  155. TEST_F(LibYUVRotateTest, DISABLED_RotatePlane270_Odd) {
  156. TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
  157. benchmark_height_ - 1, benchmark_width_ - 3, kRotate270,
  158. benchmark_iterations_, disable_cpu_flags_,
  159. benchmark_cpu_info_);
  160. }
  161. } // namespace libyuv