Removed shadow warnings : postproc.c decodframe.c threading.c
[aom.git] / test / set_roi.cc
blob3b6112efbe57c36f6d8f27f520f68e55fd1b3279
1 /*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
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 */
12 #include <math.h>
13 #include <stddef.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <sys/types.h>
19 #include "third_party/googletest/src/include/gtest/gtest.h"
20 #include "vpx/vpx_integer.h"
21 #include "vpx_mem/vpx_mem.h"
22 extern "C" {
23 #include "vp8/encoder/onyx_int.h"
26 namespace {
28 TEST(Vp8RoiMapTest, ParameterCheck) {
29 int delta_q[MAX_MB_SEGMENTS] = { -2, -25, 0, 31 };
30 int delta_lf[MAX_MB_SEGMENTS] = { -2, -25, 0, 31 };
31 unsigned int threshold[MAX_MB_SEGMENTS] = { 0, 100, 200, 300 };
33 const int internalq_trans[] = {
34 0, 1, 2, 3, 4, 5, 7, 8,
35 9, 10, 12, 13, 15, 17, 18, 19,
36 20, 21, 23, 24, 25, 26, 27, 28,
37 29, 30, 31, 33, 35, 37, 39, 41,
38 43, 45, 47, 49, 51, 53, 55, 57,
39 59, 61, 64, 67, 70, 73, 76, 79,
40 82, 85, 88, 91, 94, 97, 100, 103,
41 106, 109, 112, 115, 118, 121, 124, 127,
44 // Initialize elements of cpi with valid defaults.
45 VP8_COMP cpi;
46 cpi.mb.e_mbd.mb_segement_abs_delta = SEGMENT_DELTADATA;
47 cpi.cyclic_refresh_mode_enabled = 0;
48 cpi.mb.e_mbd.segmentation_enabled = 0;
49 cpi.mb.e_mbd.update_mb_segmentation_map = 0;
50 cpi.mb.e_mbd.update_mb_segmentation_data = 0;
51 cpi.common.mb_rows = 240 >> 4;
52 cpi.common.mb_cols = 320 >> 4;
53 const int mbs = (cpi.common.mb_rows * cpi.common.mb_cols);
54 vpx_memset(cpi.segment_feature_data, 0, sizeof(cpi.segment_feature_data));
56 // Segment map
57 cpi.segmentation_map = reinterpret_cast<unsigned char *>(vpx_calloc(mbs, 1));
59 // Allocate memory for the source memory map.
60 unsigned char *roi_map =
61 reinterpret_cast<unsigned char *>(vpx_calloc(mbs, 1));
62 vpx_memset(&roi_map[mbs >> 2], 1, (mbs >> 2));
63 vpx_memset(&roi_map[mbs >> 1], 2, (mbs >> 2));
64 vpx_memset(&roi_map[mbs -(mbs >> 2)], 3, (mbs >> 2));
66 // Do a test call with valid parameters.
67 int roi_retval = vp8_set_roimap(&cpi, roi_map, cpi.common.mb_rows,
68 cpi.common.mb_cols, delta_q, delta_lf,
69 threshold);
70 EXPECT_EQ(0, roi_retval)
71 << "vp8_set_roimap roi failed with default test parameters";
73 // Check that the values in the cpi structure get set as expected.
74 if (roi_retval == 0) {
75 // Check that the segment map got set.
76 const int mapcompare = memcmp(roi_map, cpi.segmentation_map, mbs);
77 EXPECT_EQ(0, mapcompare) << "segment map error";
79 // Check the q deltas (note the need to translate into
80 // the interanl range of 0-127.
81 for (int i = 0; i < MAX_MB_SEGMENTS; ++i) {
82 const int transq = internalq_trans[abs(delta_q[i])];
83 if (abs(cpi.segment_feature_data[MB_LVL_ALT_Q][i]) != transq) {
84 EXPECT_EQ(transq, cpi.segment_feature_data[MB_LVL_ALT_Q][i])
85 << "segment delta_q error";
86 break;
90 // Check the loop filter deltas
91 for (int i = 0; i < MAX_MB_SEGMENTS; ++i) {
92 if (cpi.segment_feature_data[MB_LVL_ALT_LF][i] != delta_lf[i]) {
93 EXPECT_EQ(delta_lf[i], cpi.segment_feature_data[MB_LVL_ALT_LF][i])
94 << "segment delta_lf error";
95 break;
99 // Check the breakout thresholds
100 for (int i = 0; i < MAX_MB_SEGMENTS; ++i) {
101 unsigned int breakout =
102 static_cast<unsigned int>(cpi.segment_encode_breakout[i]);
104 if (threshold[i] != breakout) {
105 EXPECT_EQ(threshold[i], breakout)
106 << "breakout threshold error";
107 break;
111 // Segmentation, and segmentation update flages should be set.
112 EXPECT_EQ(1, cpi.mb.e_mbd.segmentation_enabled)
113 << "segmentation_enabled error";
114 EXPECT_EQ(1, cpi.mb.e_mbd.update_mb_segmentation_map)
115 << "update_mb_segmentation_map error";
116 EXPECT_EQ(1, cpi.mb.e_mbd.update_mb_segmentation_data)
117 << "update_mb_segmentation_data error";
120 // Try a range of delta q and lf parameters (some legal, some not)
121 for (int i = 0; i < 1000; ++i) {
122 int rand_deltas[4];
123 int deltas_valid;
124 rand_deltas[0] = (rand() % 160) - 80;
125 rand_deltas[1] = (rand() % 160) - 80;
126 rand_deltas[2] = (rand() % 160) - 80;
127 rand_deltas[3] = (rand() % 160) - 80;
129 deltas_valid = ((abs(rand_deltas[0]) <= 63) &&
130 (abs(rand_deltas[1]) <= 63) &&
131 (abs(rand_deltas[2]) <= 63) &&
132 (abs(rand_deltas[3]) <= 63)) ? 0 : -1;
134 // Test with random delta q values.
135 roi_retval = vp8_set_roimap(&cpi, roi_map, cpi.common.mb_rows,
136 cpi.common.mb_cols, rand_deltas,
137 delta_lf, threshold);
138 EXPECT_EQ(deltas_valid, roi_retval) << "dq range check error";
140 // One delta_q error shown at a time
141 if (deltas_valid != roi_retval)
142 break;
144 // Test with random loop filter values.
145 roi_retval = vp8_set_roimap(&cpi, roi_map, cpi.common.mb_rows,
146 cpi.common.mb_cols, delta_q,
147 rand_deltas, threshold);
148 EXPECT_EQ(deltas_valid, roi_retval) << "dlf range check error";
150 // One delta loop filter error shown at a time
151 if (deltas_valid != roi_retval)
152 break;
155 // Test that we report and error if cyclic refresh is enabled.
156 cpi.cyclic_refresh_mode_enabled = 1;
157 roi_retval = vp8_set_roimap(&cpi, roi_map, cpi.common.mb_rows,
158 cpi.common.mb_cols, delta_q,
159 delta_lf, threshold);
160 EXPECT_EQ(-1, roi_retval) << "cyclic refresh check error";
161 cpi.cyclic_refresh_mode_enabled = 0;
163 // Test invalid number of rows or colums.
164 roi_retval = vp8_set_roimap(&cpi, roi_map, cpi.common.mb_rows + 1,
165 cpi.common.mb_cols, delta_q,
166 delta_lf, threshold);
167 EXPECT_EQ(-1, roi_retval) << "MB rows bounds check error";
169 roi_retval = vp8_set_roimap(&cpi, roi_map, cpi.common.mb_rows,
170 cpi.common.mb_cols - 1, delta_q,
171 delta_lf, threshold);
172 EXPECT_EQ(-1, roi_retval) << "MB cols bounds check error";
175 // Free allocated memory
176 if (cpi.segmentation_map)
177 vpx_free(cpi.segmentation_map);
178 if (roi_map)
179 vpx_free(roi_map);
182 } // namespace