rotate_argb_test.cc 7.11 KB
Newer Older
1
/*
2
 *  Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 4 5 6
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS. All contributing project authors may
8 9 10 11 12 13 14
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include <stdlib.h>

#include "libyuv/cpu_id.h"
#include "libyuv/rotate_argb.h"
15
#include "libyuv/row.h"
16
#include "../unit_test/unit_test.h"
17 18 19

namespace libyuv {

20 21 22
void TestRotateBpp(int src_width, int src_height,
                   int dst_width, int dst_height,
                   libyuv::RotationMode mode,
23
                   int benchmark_iterations, int disable_cpu_flags,
24 25 26 27 28 29 30 31 32 33 34 35 36 37
                   const int kBpp) {
  if (src_width < 1) {
    src_width = 1;
  }
  if (src_height < 1) {
    src_height = 1;
  }
  if (dst_width < 1) {
    dst_width = 1;
  }
  if (dst_height < 1) {
    dst_height = 1;
  }
  int src_stride_argb = src_width * kBpp;
38
  int src_argb_plane_size = src_stride_argb * abs(src_height);
39
  align_buffer_64(src_argb, src_argb_plane_size);
40 41
  for (int i = 0; i < src_argb_plane_size; ++i) {
    src_argb[i] = random() & 0xff;
42 43
  }

44 45
  int dst_stride_argb = dst_width * kBpp;
  int dst_argb_plane_size = dst_stride_argb * dst_height;
46 47
  align_buffer_64(dst_argb_c, dst_argb_plane_size);
  align_buffer_64(dst_argb_opt, dst_argb_plane_size);
48 49 50
  memset(dst_argb_c, 2, dst_argb_plane_size);
  memset(dst_argb_opt, 3, dst_argb_plane_size);

51
  if (kBpp == 1) {
52
    MaskCpuFlags(disable_cpu_flags);  // Disable all CPU optimization.
53 54 55 56 57 58 59 60 61 62 63
    RotatePlane(src_argb, src_stride_argb,
                dst_argb_c, dst_stride_argb,
                src_width, src_height, mode);

    MaskCpuFlags(-1);  // Enable all CPU optimization.
    for (int i = 0; i < benchmark_iterations; ++i) {
      RotatePlane(src_argb, src_stride_argb,
                  dst_argb_opt, dst_stride_argb,
                  src_width, src_height, mode);
    }
  } else if (kBpp == 4) {
64
    MaskCpuFlags(disable_cpu_flags);  // Disable all CPU optimization.
65 66
    ARGBRotate(src_argb, src_stride_argb,
               dst_argb_c, dst_stride_argb,
67
               src_width, src_height, mode);
68 69 70 71 72 73

    MaskCpuFlags(-1);  // Enable all CPU optimization.
    for (int i = 0; i < benchmark_iterations; ++i) {
      ARGBRotate(src_argb, src_stride_argb,
                 dst_argb_opt, dst_stride_argb,
                 src_width, src_height, mode);
74 75 76
    }
  }

77 78 79 80 81
  // Rotation should be exact.
  for (int i = 0; i < dst_argb_plane_size; ++i) {
    EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]);
  }

82 83 84
  free_aligned_buffer_64(dst_argb_c);
  free_aligned_buffer_64(dst_argb_opt);
  free_aligned_buffer_64(src_argb);
85 86
}

87 88 89
static void ARGBTestRotate(int src_width, int src_height,
                           int dst_width, int dst_height,
                           libyuv::RotationMode mode,
90
                           int benchmark_iterations, int disable_cpu_flags) {
91 92
  TestRotateBpp(src_width, src_height,
                dst_width, dst_height,
93
                mode, benchmark_iterations, disable_cpu_flags, 4);
94
}
95

96 97 98
TEST_F(libyuvTest, ARGBRotate0) {
  ARGBTestRotate(benchmark_width_, benchmark_height_,
                 benchmark_width_, benchmark_height_,
99
                 kRotate0, benchmark_iterations_, disable_cpu_flags_);
100 101 102
}

TEST_F(libyuvTest, ARGBRotate90) {
103 104
  ARGBTestRotate(benchmark_width_, benchmark_height_,
                 benchmark_height_, benchmark_width_,
105
                 kRotate90, benchmark_iterations_, disable_cpu_flags_);
106 107 108
}

TEST_F(libyuvTest, ARGBRotate180) {
109 110
  ARGBTestRotate(benchmark_width_, benchmark_height_,
                 benchmark_width_, benchmark_height_,
111
                 kRotate180, benchmark_iterations_, disable_cpu_flags_);
112 113 114
}

TEST_F(libyuvTest, ARGBRotate270) {
115 116
  ARGBTestRotate(benchmark_width_, benchmark_height_,
                 benchmark_height_, benchmark_width_,
117
                 kRotate270, benchmark_iterations_, disable_cpu_flags_);
118 119 120
}

TEST_F(libyuvTest, ARGBRotate0_Odd) {
121 122
  ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
                 benchmark_width_ - 3, benchmark_height_ - 1,
123
                 kRotate0, benchmark_iterations_, disable_cpu_flags_);
124 125 126
}

TEST_F(libyuvTest, ARGBRotate90_Odd) {
127 128
  ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
                 benchmark_height_ - 1, benchmark_width_ - 3,
129
                 kRotate90, benchmark_iterations_, disable_cpu_flags_);
130 131 132
}

TEST_F(libyuvTest, ARGBRotate180_Odd) {
133 134
  ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
                 benchmark_width_ - 3, benchmark_height_ - 1,
135
                 kRotate180, benchmark_iterations_, disable_cpu_flags_);
136 137 138
}

TEST_F(libyuvTest, ARGBRotate270_Odd) {
139 140
  ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
                 benchmark_height_ - 1, benchmark_width_ - 3,
141
                 kRotate270, benchmark_iterations_, disable_cpu_flags_);
142 143 144 145 146
}

static void TestRotatePlane(int src_width, int src_height,
                            int dst_width, int dst_height,
                            libyuv::RotationMode mode,
147
                            int benchmark_iterations, int disable_cpu_flags) {
148 149
  TestRotateBpp(src_width, src_height,
                dst_width, dst_height,
150
                mode, benchmark_iterations, disable_cpu_flags, 1);
151 152 153 154 155
}

TEST_F(libyuvTest, RotatePlane0) {
  TestRotatePlane(benchmark_width_, benchmark_height_,
                  benchmark_width_, benchmark_height_,
156
                  kRotate0, benchmark_iterations_, disable_cpu_flags_);
157 158 159 160 161
}

TEST_F(libyuvTest, RotatePlane90) {
  TestRotatePlane(benchmark_width_, benchmark_height_,
                  benchmark_height_, benchmark_width_,
162
                  kRotate90, benchmark_iterations_, disable_cpu_flags_);
163 164 165 166 167
}

TEST_F(libyuvTest, RotatePlane180) {
  TestRotatePlane(benchmark_width_, benchmark_height_,
                  benchmark_width_, benchmark_height_,
168
                  kRotate180, benchmark_iterations_, disable_cpu_flags_);
169 170 171 172 173
}

TEST_F(libyuvTest, RotatePlane270) {
  TestRotatePlane(benchmark_width_, benchmark_height_,
                  benchmark_height_, benchmark_width_,
174
                  kRotate270, benchmark_iterations_, disable_cpu_flags_);
175 176 177 178 179
}

TEST_F(libyuvTest, RotatePlane0_Odd) {
  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
                  benchmark_width_ - 3, benchmark_height_ - 1,
180
                  kRotate0, benchmark_iterations_, disable_cpu_flags_);
181 182 183 184 185
}

TEST_F(libyuvTest, RotatePlane90_Odd) {
  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
                  benchmark_height_ - 1, benchmark_width_ - 3,
186
                  kRotate90, benchmark_iterations_, disable_cpu_flags_);
187 188 189 190 191
}

TEST_F(libyuvTest, RotatePlane180_Odd) {
  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
                  benchmark_width_ - 3, benchmark_height_ - 1,
192
                  kRotate180, benchmark_iterations_, disable_cpu_flags_);
193 194 195 196 197
}

TEST_F(libyuvTest, RotatePlane270_Odd) {
  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
                  benchmark_height_ - 1, benchmark_width_ - 3,
198
                  kRotate270, benchmark_iterations_, disable_cpu_flags_);
199 200 201
}

}  // namespace libyuv