31 |
const int block, |
const int block, |
32 |
const uint16_t * scan_table, |
const uint16_t * scan_table, |
33 |
const unsigned int lambda, |
const unsigned int lambda, |
34 |
const uint16_t * mpeg_quant_matrices) |
const uint16_t * mpeg_quant_matrices, |
35 |
|
const unsigned int quant_sq) |
36 |
{ |
{ |
37 |
int sum; |
int sum; |
38 |
int bits; |
int bits; |
67 |
distortion = sse8_16bit(data, zero_block, 8*sizeof(int16_t)); |
distortion = sse8_16bit(data, zero_block, 8*sizeof(int16_t)); |
68 |
} |
} |
69 |
|
|
70 |
return bits + (lambda*distortion)/(quant*quant); |
return bits + (lambda*distortion)/quant_sq; |
71 |
} |
} |
72 |
|
|
73 |
|
|
80 |
const int block, |
const int block, |
81 |
const uint16_t * scan_table, |
const uint16_t * scan_table, |
82 |
const unsigned int lambda, |
const unsigned int lambda, |
83 |
const uint16_t * mpeg_quant_matrices) |
const uint16_t * mpeg_quant_matrices, |
84 |
|
const unsigned int quant_sq) |
85 |
{ |
{ |
86 |
int sum; |
int sum; |
87 |
int bits; |
int bits; |
116 |
distortion = sse8_16bit(data, zero_block, 8*sizeof(int16_t)); |
distortion = sse8_16bit(data, zero_block, 8*sizeof(int16_t)); |
117 |
} |
} |
118 |
|
|
119 |
return bits + (lambda*distortion)/(quant*quant); |
return bits + (lambda*distortion)/quant_sq; |
|
} |
|
|
|
|
|
|
|
|
static void |
|
|
transfer_8to16sub2ro(int16_t * const dct, |
|
|
const uint8_t * const cur, |
|
|
const uint8_t * ref1, |
|
|
const uint8_t * ref2, |
|
|
const uint32_t stride) |
|
|
{ |
|
|
uint32_t i, j; |
|
|
|
|
|
for (j = 0; j < 8; j++) { |
|
|
for (i = 0; i < 8; i++) { |
|
|
uint8_t c = cur[j * stride + i]; |
|
|
int r = (ref1[j * stride + i] + ref2[j * stride + i] + 1) / 2; |
|
|
dct[j * 8 + i] = (int16_t) c - (int16_t) r; |
|
|
} |
|
|
} |
|
120 |
} |
} |
121 |
|
|
122 |
static void |
static void |
124 |
{ |
{ |
125 |
|
|
126 |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
127 |
int32_t rd = 3*BITS_MULT; /* note to self: 3 bits minimum, but maybe 4 if it's forward mode */ |
int32_t rd = (3+2)*BITS_MULT; /* 3 bits for mode + 2 for vector (minimum) */ |
128 |
VECTOR * current; |
VECTOR * current; |
129 |
const uint8_t * ptr; |
const uint8_t * ptr; |
130 |
int i, xc, yc; |
int i, xc, yc; |
143 |
xc = x/2; yc = y/2; |
xc = x/2; yc = y/2; |
144 |
} |
} |
145 |
|
|
146 |
rd += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision); |
rd += BITS_MULT*(d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision)-2); |
147 |
|
|
148 |
for(i = 0; i < 4; i++) { |
for(i = 0; i < 4; i++) { |
149 |
int s = 8*((i&1) + (i>>1)*data->iEdgedWidth); |
int s = 8*((i&1) + (i>>1)*data->iEdgedWidth); |
150 |
transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth); |
transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth); |
151 |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i, data->scan_table, data->lambda[i], data->mpeg_quant_matrices); |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
152 |
|
&cbp, i, data->scan_table, data->lambda[i], data->mpeg_quant_matrices, data->quant_sq); |
153 |
if (rd >= data->iMinSAD[0]) return; |
if (rd >= data->iMinSAD[0]) return; |
154 |
} |
} |
155 |
|
|
160 |
/* chroma U */ |
/* chroma U */ |
161 |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
162 |
transfer_8to16subro(in, data->CurU, ptr, data->iEdgedWidth/2); |
transfer_8to16subro(in, data->CurU, ptr, data->iEdgedWidth/2); |
163 |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4, data->scan_table, data->lambda[4], data->mpeg_quant_matrices); |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
164 |
|
&cbp, 4, data->scan_table, data->lambda[4], data->mpeg_quant_matrices, data->quant_sq); |
165 |
if (rd >= data->iMinSAD[0]) return; |
if (rd >= data->iMinSAD[0]) return; |
166 |
|
|
167 |
/* chroma V */ |
/* chroma V */ |
168 |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
169 |
transfer_8to16subro(in, data->CurV, ptr, data->iEdgedWidth/2); |
transfer_8to16subro(in, data->CurV, ptr, data->iEdgedWidth/2); |
170 |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table, data->lambda[5], data->mpeg_quant_matrices); |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
171 |
|
&cbp, 5, data->scan_table, data->lambda[5], data->mpeg_quant_matrices, data->quant_sq); |
172 |
|
|
173 |
if (cbp) rd += BITS_MULT * 7; |
if (cbp) rd += BITS_MULT * 7; |
174 |
|
|
180 |
} |
} |
181 |
} |
} |
182 |
|
|
|
|
|
183 |
static void |
static void |
184 |
CheckCandidateRDDirect(const int x, const int y, SearchData * const data, const unsigned int Direction) |
CheckCandidateRDDirect(const int x, const int y, SearchData * const data, const unsigned int Direction) |
185 |
{ |
{ |
226 |
} |
} |
227 |
|
|
228 |
transfer_8to16sub2ro(in, data->Cur + s, ReferenceF, ReferenceB, data->iEdgedWidth); |
transfer_8to16sub2ro(in, data->Cur + s, ReferenceF, ReferenceB, data->iEdgedWidth); |
229 |
rd += Block_CalcBits_BVOP_direct(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, k, data->scan_table, data->lambda[k], data->mpeg_quant_matrices); |
rd += Block_CalcBits_BVOP_direct(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
230 |
|
&cbp, k, data->scan_table, data->lambda[k], data->mpeg_quant_matrices, data->quant_sq); |
231 |
if (rd > *(data->iMinSAD)) return; |
if (rd > *(data->iMinSAD)) return; |
232 |
} |
} |
233 |
|
|
241 |
ReferenceF = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xcf, ycf, data->iEdgedWidth/2, data->rounding); |
ReferenceF = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xcf, ycf, data->iEdgedWidth/2, data->rounding); |
242 |
ReferenceB = interpolate8x8_switch2(data->RefQ + 16, data->b_RefP[4], 0, 0, xcb, ycb, data->iEdgedWidth/2, data->rounding); |
ReferenceB = interpolate8x8_switch2(data->RefQ + 16, data->b_RefP[4], 0, 0, xcb, ycb, data->iEdgedWidth/2, data->rounding); |
243 |
transfer_8to16sub2ro(in, data->CurU, ReferenceF, ReferenceB, data->iEdgedWidth/2); |
transfer_8to16sub2ro(in, data->CurU, ReferenceF, ReferenceB, data->iEdgedWidth/2); |
244 |
rd += Block_CalcBits_BVOP_direct(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4, data->scan_table, data->lambda[4], data->mpeg_quant_matrices); |
rd += Block_CalcBits_BVOP_direct(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
245 |
|
&cbp, 4, data->scan_table, data->lambda[4], data->mpeg_quant_matrices, data->quant_sq); |
246 |
if (rd >= data->iMinSAD[0]) return; |
if (rd >= data->iMinSAD[0]) return; |
247 |
|
|
248 |
/* chroma V */ |
/* chroma V */ |
249 |
ReferenceF = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xcf, ycf, data->iEdgedWidth/2, data->rounding); |
ReferenceF = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xcf, ycf, data->iEdgedWidth/2, data->rounding); |
250 |
ReferenceB = interpolate8x8_switch2(data->RefQ + 16, data->b_RefP[5], 0, 0, xcb, ycb, data->iEdgedWidth/2, data->rounding); |
ReferenceB = interpolate8x8_switch2(data->RefQ + 16, data->b_RefP[5], 0, 0, xcb, ycb, data->iEdgedWidth/2, data->rounding); |
251 |
transfer_8to16sub2ro(in, data->CurV, ReferenceF, ReferenceB, data->iEdgedWidth/2); |
transfer_8to16sub2ro(in, data->CurV, ReferenceF, ReferenceB, data->iEdgedWidth/2); |
252 |
rd += Block_CalcBits_BVOP_direct(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table, data->lambda[5], data->mpeg_quant_matrices); |
rd += Block_CalcBits_BVOP_direct(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
253 |
|
&cbp, 5, data->scan_table, data->lambda[5], data->mpeg_quant_matrices, data->quant_sq); |
254 |
|
|
255 |
if (cbp) |
if (cbp) |
256 |
rd += BITS_MULT * 6; |
rd += BITS_MULT * 6; |
265 |
} |
} |
266 |
} |
} |
267 |
|
|
|
|
|
|
|
|
|
|
|
268 |
static void |
static void |
269 |
CheckCandidateRDInt(const int x, const int y, SearchData * const data, const unsigned int Direction) |
CheckCandidateRDInt(const int x, const int y, SearchData * const data, const unsigned int Direction) |
270 |
{ |
{ |
310 |
rd += BITS_MULT * (d_mv_bits(xf, yf, data->predMV, data->iFcode, data->qpel^data->qpel_precision) |
rd += BITS_MULT * (d_mv_bits(xf, yf, data->predMV, data->iFcode, data->qpel^data->qpel_precision) |
311 |
+ d_mv_bits(xb, yb, data->bpredMV, data->iFcode, data->qpel^data->qpel_precision)); |
+ d_mv_bits(xb, yb, data->bpredMV, data->iFcode, data->qpel^data->qpel_precision)); |
312 |
|
|
|
|
|
313 |
for(i = 0; i < 4; i++) { |
for(i = 0; i < 4; i++) { |
314 |
int s = 8*((i&1) + (i>>1)*data->iEdgedWidth); |
int s = 8*((i&1) + (i>>1)*data->iEdgedWidth); |
315 |
if (rd >= *data->iMinSAD) return; |
if (rd >= *data->iMinSAD) return; |
316 |
transfer_8to16sub2ro(in, data->Cur + s, ReferenceF + s, ReferenceB + s, data->iEdgedWidth); |
transfer_8to16sub2ro(in, data->Cur + s, ReferenceF + s, ReferenceB + s, data->iEdgedWidth); |
317 |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i, data->scan_table, data->lambda[i], data->mpeg_quant_matrices); |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, |
318 |
|
i, data->scan_table, data->lambda[i], data->mpeg_quant_matrices, data->quant_sq); |
319 |
} |
} |
320 |
|
|
321 |
/* chroma */ |
/* chroma */ |
328 |
ReferenceF = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xcf, ycf, data->iEdgedWidth/2, data->rounding); |
ReferenceF = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xcf, ycf, data->iEdgedWidth/2, data->rounding); |
329 |
ReferenceB = interpolate8x8_switch2(data->RefQ + 16, data->b_RefP[4], 0, 0, xcb, ycb, data->iEdgedWidth/2, data->rounding); |
ReferenceB = interpolate8x8_switch2(data->RefQ + 16, data->b_RefP[4], 0, 0, xcb, ycb, data->iEdgedWidth/2, data->rounding); |
330 |
transfer_8to16sub2ro(in, data->CurU, ReferenceF, ReferenceB, data->iEdgedWidth/2); |
transfer_8to16sub2ro(in, data->CurU, ReferenceF, ReferenceB, data->iEdgedWidth/2); |
331 |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4, data->scan_table, data->lambda[4], data->mpeg_quant_matrices); |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, |
332 |
|
4, data->scan_table, data->lambda[4], data->mpeg_quant_matrices, data->quant_sq); |
333 |
if (rd >= data->iMinSAD[0]) return; |
if (rd >= data->iMinSAD[0]) return; |
334 |
|
|
335 |
|
|
337 |
ReferenceF = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xcf, ycf, data->iEdgedWidth/2, data->rounding); |
ReferenceF = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xcf, ycf, data->iEdgedWidth/2, data->rounding); |
338 |
ReferenceB = interpolate8x8_switch2(data->RefQ + 16, data->b_RefP[5], 0, 0, xcb, ycb, data->iEdgedWidth/2, data->rounding); |
ReferenceB = interpolate8x8_switch2(data->RefQ + 16, data->b_RefP[5], 0, 0, xcb, ycb, data->iEdgedWidth/2, data->rounding); |
339 |
transfer_8to16sub2ro(in, data->CurV, ReferenceF, ReferenceB, data->iEdgedWidth/2); |
transfer_8to16sub2ro(in, data->CurV, ReferenceF, ReferenceB, data->iEdgedWidth/2); |
340 |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table, data->lambda[5], data->mpeg_quant_matrices); |
rd += Block_CalcBits_BVOP(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, |
341 |
|
5, data->scan_table, data->lambda[5], data->mpeg_quant_matrices, data->quant_sq); |
342 |
|
|
343 |
if (cbp) rd += BITS_MULT * 7; |
if (cbp) rd += BITS_MULT * 7; |
344 |
|
|