Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: source/libvpx/test/vp8_boolcoder_test.cc

Issue 11555023: libvpx: Add VP9 decoder. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2012 The WebM 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 extern "C" {
12 #include "vp8/encoder/boolhuff.h"
13 #include "vp8/decoder/dboolhuff.h"
14 }
15
16 #include <math.h>
17 #include <stddef.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <sys/types.h>
22
23 #include "test/acm_random.h"
24 #include "third_party/googletest/src/include/gtest/gtest.h"
25 #include "vpx/vpx_integer.h"
26
27 namespace {
28 const int num_tests = 10;
29 } // namespace
30
31 using libvpx_test::ACMRandom;
32
33 TEST(VP8, TestBitIO) {
34 ACMRandom rnd(ACMRandom::DeterministicSeed());
35 for (int n = 0; n < num_tests; ++n) {
36 for (int method = 0; method <= 7; ++method) { // we generate various proba
37 const int bits_to_test = 1000;
38 uint8_t probas[bits_to_test];
39
40 for (int i = 0; i < bits_to_test; ++i) {
41 const int parity = i & 1;
42 probas[i] =
43 (method == 0) ? 0 : (method == 1) ? 255 :
44 (method == 2) ? 128 :
45 (method == 3) ? rnd.Rand8() :
46 (method == 4) ? (parity ? 0 : 255) :
47 // alternate between low and high proba:
48 (method == 5) ? (parity ? rnd(128) : 255 - rnd(128)) :
49 (method == 6) ?
50 (parity ? rnd(64) : 255 - rnd(64)) :
51 (parity ? rnd(32) : 255 - rnd(32));
52 }
53 for (int bit_method = 0; bit_method <= 3; ++bit_method) {
54 const int random_seed = 6432;
55 const int buffer_size = 10000;
56 ACMRandom bit_rnd(random_seed);
57 BOOL_CODER bw;
58 uint8_t bw_buffer[buffer_size];
59 vp8_start_encode(&bw, bw_buffer, bw_buffer + buffer_size);
60
61 int bit = (bit_method == 0) ? 0 : (bit_method == 1) ? 1 : 0;
62 for (int i = 0; i < bits_to_test; ++i) {
63 if (bit_method == 2) {
64 bit = (i & 1);
65 } else if (bit_method == 3) {
66 bit = bit_rnd(2);
67 }
68 vp8_encode_bool(&bw, bit, static_cast<int>(probas[i]));
69 }
70
71 vp8_stop_encode(&bw);
72
73 BOOL_DECODER br;
74 vp8dx_start_decode(&br, bw_buffer, buffer_size);
75 bit_rnd.Reset(random_seed);
76 for (int i = 0; i < bits_to_test; ++i) {
77 if (bit_method == 2) {
78 bit = (i & 1);
79 } else if (bit_method == 3) {
80 bit = bit_rnd(2);
81 }
82 GTEST_ASSERT_EQ(vp8dx_decode_bool(&br, probas[i]), bit)
83 << "pos: "<< i << " / " << bits_to_test
84 << " bit_method: " << bit_method
85 << " method: " << method;
86 }
87 }
88 }
89 }
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698