48 |
#define SCALEBITS 16 |
#define SCALEBITS 16 |
49 |
#define FIX(X) ((1L << SCALEBITS) / (X) + 1) |
#define FIX(X) ((1L << SCALEBITS) / (X) + 1) |
50 |
|
|
51 |
static const uint32_t multipliers[32] = |
static const uint32_t multipliers[32] = { |
|
{ |
|
52 |
0, FIX(2), FIX(4), FIX(6), |
0, FIX(2), FIX(4), FIX(6), |
53 |
FIX(8), FIX(10), FIX(12), FIX(14), |
FIX(8), FIX(10), FIX(12), FIX(14), |
54 |
FIX(16), FIX(18), FIX(20), FIX(22), |
FIX(16), FIX(18), FIX(20), FIX(22), |
76 |
*/ |
*/ |
77 |
|
|
78 |
|
|
79 |
void quant_intra_c(int16_t * coeff, const int16_t * data, const uint32_t quant, const uint32_t dcscalar) |
void |
80 |
|
quant_intra_c(int16_t * coeff, |
81 |
|
const int16_t * data, |
82 |
|
const uint32_t quant, |
83 |
|
const uint32_t dcscalar) |
84 |
{ |
{ |
85 |
const uint32_t mult = multipliers[quant]; |
const uint32_t mult = multipliers[quant]; |
86 |
const uint16_t quant_m_2 = quant << 1; |
const uint16_t quant_m_2 = quant << 1; |
114 |
/* quantize inter-block |
/* quantize inter-block |
115 |
*/ |
*/ |
116 |
|
|
117 |
uint32_t quant_inter_c(int16_t *coeff, const int16_t *data, const uint32_t quant) |
uint32_t |
118 |
|
quant_inter_c(int16_t * coeff, |
119 |
|
const int16_t * data, |
120 |
|
const uint32_t quant) |
121 |
{ |
{ |
122 |
const uint32_t mult = multipliers[quant]; |
const uint32_t mult = multipliers[quant]; |
123 |
const uint16_t quant_m_2 = quant << 1; |
const uint16_t quant_m_2 = quant << 1; |
157 |
/* dequantize intra-block & clamp to [-2048,2047] |
/* dequantize intra-block & clamp to [-2048,2047] |
158 |
*/ |
*/ |
159 |
|
|
160 |
void dequant_intra_c(int16_t *data, const int16_t *coeff, const uint32_t quant, const uint32_t dcscalar) |
void |
161 |
|
dequant_intra_c(int16_t * data, |
162 |
|
const int16_t * coeff, |
163 |
|
const uint32_t quant, |
164 |
|
const uint32_t dcscalar) |
165 |
{ |
{ |
166 |
const int32_t quant_m_2 = quant << 1; |
const int32_t quant_m_2 = quant << 1; |
167 |
const int32_t quant_add = (quant & 1 ? quant : quant - 1); |
const int32_t quant_add = (quant & 1 ? quant : quant - 1); |
168 |
uint32_t i; |
uint32_t i; |
169 |
|
|
170 |
data[0] = coeff[0] * dcscalar; |
data[0] = coeff[0] * dcscalar; |
171 |
if (data[0] < -2048) |
if (data[0] < -2048) { |
|
{ |
|
172 |
data[0] = -2048; |
data[0] = -2048; |
173 |
} |
} else if (data[0] > 2047) { |
|
else if (data[0] > 2047) |
|
|
{ |
|
174 |
data[0] = 2047; |
data[0] = 2047; |
175 |
} |
} |
176 |
|
|
177 |
|
|
178 |
for (i = 1; i < 64; i++) { |
for (i = 1; i < 64; i++) { |
179 |
int32_t acLevel = coeff[i]; |
int32_t acLevel = coeff[i]; |
180 |
if (acLevel == 0) |
|
181 |
{ |
if (acLevel == 0) { |
182 |
data[i] = 0; |
data[i] = 0; |
183 |
} |
} else if (acLevel < 0) { |
|
else if (acLevel < 0) |
|
|
{ |
|
184 |
acLevel = quant_m_2 * -acLevel + quant_add; |
acLevel = quant_m_2 * -acLevel + quant_add; |
185 |
data[i] = (acLevel <= 2048 ? -acLevel : -2048); |
data[i] = (acLevel <= 2048 ? -acLevel : -2048); |
186 |
} |
} else // if (acLevel > 0) { |
|
else // if (acLevel > 0) { |
|
187 |
{ |
{ |
188 |
acLevel = quant_m_2 * acLevel + quant_add; |
acLevel = quant_m_2 * acLevel + quant_add; |
189 |
data[i] = (acLevel <= 2047 ? acLevel : 2047); |
data[i] = (acLevel <= 2047 ? acLevel : 2047); |
196 |
/* dequantize inter-block & clamp to [-2048,2047] |
/* dequantize inter-block & clamp to [-2048,2047] |
197 |
*/ |
*/ |
198 |
|
|
199 |
void dequant_inter_c(int16_t *data, const int16_t *coeff, const uint32_t quant) |
void |
200 |
|
dequant_inter_c(int16_t * data, |
201 |
|
const int16_t * coeff, |
202 |
|
const uint32_t quant) |
203 |
{ |
{ |
204 |
const uint16_t quant_m_2 = quant << 1; |
const uint16_t quant_m_2 = quant << 1; |
205 |
const uint16_t quant_add = (quant & 1 ? quant : quant - 1); |
const uint16_t quant_add = (quant & 1 ? quant : quant - 1); |
208 |
for (i = 0; i < 64; i++) { |
for (i = 0; i < 64; i++) { |
209 |
int16_t acLevel = coeff[i]; |
int16_t acLevel = coeff[i]; |
210 |
|
|
211 |
if (acLevel == 0) |
if (acLevel == 0) { |
|
{ |
|
212 |
data[i] = 0; |
data[i] = 0; |
213 |
} |
} else if (acLevel < 0) { |
|
else if (acLevel < 0) |
|
|
{ |
|
214 |
acLevel = acLevel * quant_m_2 - quant_add; |
acLevel = acLevel * quant_m_2 - quant_add; |
215 |
data[i] = (acLevel >= -2048 ? acLevel : -2048); |
data[i] = (acLevel >= -2048 ? acLevel : -2048); |
216 |
} |
} else // if (acLevel > 0) |
|
else // if (acLevel > 0) |
|
217 |
{ |
{ |
218 |
acLevel = acLevel * quant_m_2 + quant_add; |
acLevel = acLevel * quant_m_2 + quant_add; |
219 |
data[i] = (acLevel <= 2047 ? acLevel : 2047); |
data[i] = (acLevel <= 2047 ? acLevel : 2047); |