rotate_argb_test.cc 6.64 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 15
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include <stdlib.h>
#include <time.h>

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

namespace libyuv {

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
void TestRotateBpp(int src_width, int src_height,
                   int dst_width, int dst_height,
                   libyuv::RotationMode mode,
                   int benchmark_iterations,
                   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;
  int src_argb_plane_size = src_stride_argb * 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  if (kBpp == 1) {
    MaskCpuFlags(0);  // Disable all CPU optimization.
    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) {
    MaskCpuFlags(0);  // Disable all CPU optimization.
    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 90 91 92 93 94
static void ARGBTestRotate(int src_width, int src_height,
                           int dst_width, int dst_height,
                           libyuv::RotationMode mode,
                           int benchmark_iterations) {
  TestRotateBpp(src_width, src_height,
                dst_width, dst_height,
                mode, benchmark_iterations, 4);
}
95

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

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

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

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

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

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

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

TEST_F(libyuvTest, ARGBRotate270_Odd) {
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
  ARGBTestRotate(benchmark_width_ - 3, benchmark_height_ - 1,
                 benchmark_height_ - 1, benchmark_width_ - 3,
                 kRotate270, benchmark_iterations_);
}

static void TestRotatePlane(int src_width, int src_height,
                            int dst_width, int dst_height,
                            libyuv::RotationMode mode,
                            int benchmark_iterations) {
  TestRotateBpp(src_width, src_height,
                dst_width, dst_height,
                mode, benchmark_iterations, 1);
}

TEST_F(libyuvTest, RotatePlane0) {
  TestRotatePlane(benchmark_width_, benchmark_height_,
                  benchmark_width_, benchmark_height_,
                  kRotate0, benchmark_iterations_);
}

TEST_F(libyuvTest, RotatePlane90) {
  TestRotatePlane(benchmark_width_, benchmark_height_,
                  benchmark_height_, benchmark_width_,
                  kRotate90, benchmark_iterations_);
}

TEST_F(libyuvTest, RotatePlane180) {
  TestRotatePlane(benchmark_width_, benchmark_height_,
                  benchmark_width_, benchmark_height_,
                  kRotate180, benchmark_iterations_);
}

TEST_F(libyuvTest, RotatePlane270) {
  TestRotatePlane(benchmark_width_, benchmark_height_,
                  benchmark_height_, benchmark_width_,
                  kRotate270, benchmark_iterations_);
}

TEST_F(libyuvTest, RotatePlane0_Odd) {
  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
                  benchmark_width_ - 3, benchmark_height_ - 1,
                  kRotate0, benchmark_iterations_);
}

TEST_F(libyuvTest, RotatePlane90_Odd) {
  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
                  benchmark_height_ - 1, benchmark_width_ - 3,
                  kRotate90, benchmark_iterations_);
}

TEST_F(libyuvTest, RotatePlane180_Odd) {
  TestRotatePlane(benchmark_width_ - 3, benchmark_height_ - 1,
                  benchmark_width_ - 3, benchmark_height_ - 1,
                  kRotate180, benchmark_iterations_);
}

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

}  // namespace libyuv