1
1
/*
2
- * Copyrgght (c) 2006, Daisuke Okanohara
2
+ * Copyright (c) 2006, Daisuke Okanohara
3
3
* Copyright (c) 2008-2010, Cybozu Labs, Inc.
4
4
* All rights reserved.
5
- *
5
+ *
6
6
* Redistribution and use in source and binary forms, with or without
7
7
* modification, are permitted provided that the following conditions are met:
8
- *
8
+ *
9
9
* * Redistributions of source code must retain the above copyright notice,
10
10
* this list of conditions and the following disclaimer.
11
11
* * Redistributions in binary form must reproduce the above copyright notice,
14
14
* * Neither the name of the copyright holders nor the names of its
15
15
* contributors may be used to endorse or promote products derived from this
16
16
* software without specific prior written permission.
17
- *
17
+ *
18
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
20
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -63,28 +63,28 @@ template <class Iter> class rc_encoder_t : public rc_type_t {
63
63
}
64
64
uint newL = L + r*low;
65
65
if (newL < L) {
66
- // overflow occured (newL >= 2^32)
67
- // buffer FF FF .. FF -> buffer+1 00 00 .. 00
66
+ // overflow occured (newL >= 2^32)
67
+ // buffer FF FF .. FF -> buffer+1 00 00 .. 00
68
68
buffer++;
69
69
for (;carryN > 0 ; carryN--) {
70
- *iter++ = buffer;
71
- buffer = 0 ;
70
+ *iter++ = buffer;
71
+ buffer = 0 ;
72
72
}
73
73
}
74
74
L = newL;
75
75
while (R < TOP) {
76
76
const byte newBuffer = (L >> 24 );
77
77
if (start) {
78
- buffer = newBuffer;
79
- start = false ;
78
+ buffer = newBuffer;
79
+ start = false ;
80
80
} else if (newBuffer == 0xFF ) {
81
- carryN++;
81
+ carryN++;
82
82
} else {
83
- *iter++ = buffer;
84
- for (; carryN != 0 ; carryN--) {
85
- *iter++ = 0xFF ;
86
- }
87
- buffer = newBuffer;
83
+ *iter++ = buffer;
84
+ for (; carryN != 0 ; carryN--) {
85
+ *iter++ = 0xFF ;
86
+ }
87
+ buffer = newBuffer;
88
88
}
89
89
L <<= 8 ;
90
90
R <<= 8 ;
@@ -101,7 +101,7 @@ template <class Iter> class rc_encoder_t : public rc_type_t {
101
101
uint t8 = t >> 24 , l8 = L >> 24 ;
102
102
*iter++ = l8;
103
103
if (t8 != l8) {
104
- break ;
104
+ break ;
105
105
}
106
106
t <<= 8 ;
107
107
L <<= 8 ;
@@ -151,7 +151,7 @@ template<int _BASE> struct rc_decoder_search_t<short, 256, _BASE> : public rc_de
151
151
__m128i b = _mm_cmplt_epi16 (v, y);
152
152
mask = (_mm_movemask_epi8 (b) << 16 ) | _mm_movemask_epi8 (a);
153
153
if (mask) {
154
- return i + (__builtin_ctz (mask) >> 1 ) - 1 ;
154
+ return i + (__builtin_ctz (mask) >> 1 ) - 1 ;
155
155
}
156
156
}
157
157
return 255 ;
@@ -175,25 +175,25 @@ template <class Iterator, class SearchType> class rc_decoder_t : public rc_type_
175
175
uint decode (const uint total, const freq_type* cumFreq) {
176
176
const uint r = R / total;
177
177
const int targetPos = std::min (total-1 , D / r);
178
-
179
- // find target s.t. cumFreq[target] <= targetPos < cumFreq[target+1]
178
+
179
+ // find target s.t. cumFreq[target] <= targetPos < cumFreq[target+1]
180
180
const uint target =
181
181
search_type::get_index (cumFreq, targetPos + search_type::BASE);
182
182
const uint low = cumFreq[target] - search_type::BASE;
183
183
const uint high = cumFreq[target+1 ] - search_type::BASE;
184
-
184
+
185
185
D -= r * low;
186
186
if (high != total) {
187
187
R = r * (high-low);
188
188
} else {
189
189
R -= r * low;
190
190
}
191
-
191
+
192
192
while (R < TOP) {
193
193
R <<= 8 ;
194
194
D = (D << 8 ) | next ();
195
195
}
196
-
196
+
197
197
return target;
198
198
}
199
199
byte next () {
0 commit comments