00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 #include "vc1dsp.h"
00029 #include "libavutil/avassert.h"
00030 #include "libavutil/common.h"
00031
00032
00035 static void vc1_v_overlap_c(uint8_t* src, int stride)
00036 {
00037 int i;
00038 int a, b, c, d;
00039 int d1, d2;
00040 int rnd = 1;
00041 for(i = 0; i < 8; i++) {
00042 a = src[-2*stride];
00043 b = src[-stride];
00044 c = src[0];
00045 d = src[stride];
00046 d1 = (a - d + 3 + rnd) >> 3;
00047 d2 = (a - d + b - c + 4 - rnd) >> 3;
00048
00049 src[-2*stride] = a - d1;
00050 src[-stride] = av_clip_uint8(b - d2);
00051 src[0] = av_clip_uint8(c + d2);
00052 src[stride] = d + d1;
00053 src++;
00054 rnd = !rnd;
00055 }
00056 }
00057
00060 static void vc1_h_overlap_c(uint8_t* src, int stride)
00061 {
00062 int i;
00063 int a, b, c, d;
00064 int d1, d2;
00065 int rnd = 1;
00066 for(i = 0; i < 8; i++) {
00067 a = src[-2];
00068 b = src[-1];
00069 c = src[0];
00070 d = src[1];
00071 d1 = (a - d + 3 + rnd) >> 3;
00072 d2 = (a - d + b - c + 4 - rnd) >> 3;
00073
00074 src[-2] = a - d1;
00075 src[-1] = av_clip_uint8(b - d2);
00076 src[0] = av_clip_uint8(c + d2);
00077 src[1] = d + d1;
00078 src += stride;
00079 rnd = !rnd;
00080 }
00081 }
00082
00083 static void vc1_v_s_overlap_c(DCTELEM *top, DCTELEM *bottom)
00084 {
00085 int i;
00086 int a, b, c, d;
00087 int d1, d2;
00088 int rnd1 = 4, rnd2 = 3;
00089 for(i = 0; i < 8; i++) {
00090 a = top[48];
00091 b = top[56];
00092 c = bottom[0];
00093 d = bottom[8];
00094 d1 = a - d;
00095 d2 = a - d + b - c;
00096
00097 top[48] = ((a << 3) - d1 + rnd1) >> 3;
00098 top[56] = ((b << 3) - d2 + rnd2) >> 3;
00099 bottom[0] = ((c << 3) + d2 + rnd1) >> 3;
00100 bottom[8] = ((d << 3) + d1 + rnd2) >> 3;
00101
00102 bottom++;
00103 top++;
00104 rnd2 = 7 - rnd2;
00105 rnd1 = 7 - rnd1;
00106 }
00107 }
00108
00109 static void vc1_h_s_overlap_c(DCTELEM *left, DCTELEM *right)
00110 {
00111 int i;
00112 int a, b, c, d;
00113 int d1, d2;
00114 int rnd1 = 4, rnd2 = 3;
00115 for(i = 0; i < 8; i++) {
00116 a = left[6];
00117 b = left[7];
00118 c = right[0];
00119 d = right[1];
00120 d1 = a - d;
00121 d2 = a - d + b - c;
00122
00123 left[6] = ((a << 3) - d1 + rnd1) >> 3;
00124 left[7] = ((b << 3) - d2 + rnd2) >> 3;
00125 right[0] = ((c << 3) + d2 + rnd1) >> 3;
00126 right[1] = ((d << 3) + d1 + rnd2) >> 3;
00127
00128 right += 8;
00129 left += 8;
00130 rnd2 = 7 - rnd2;
00131 rnd1 = 7 - rnd1;
00132 }
00133 }
00134
00143 static av_always_inline int vc1_filter_line(uint8_t* src, int stride, int pq){
00144 int a0 = (2*(src[-2*stride] - src[ 1*stride]) - 5*(src[-1*stride] - src[ 0*stride]) + 4) >> 3;
00145 int a0_sign = a0 >> 31;
00146 a0 = (a0 ^ a0_sign) - a0_sign;
00147 if(a0 < pq){
00148 int a1 = FFABS((2*(src[-4*stride] - src[-1*stride]) - 5*(src[-3*stride] - src[-2*stride]) + 4) >> 3);
00149 int a2 = FFABS((2*(src[ 0*stride] - src[ 3*stride]) - 5*(src[ 1*stride] - src[ 2*stride]) + 4) >> 3);
00150 if(a1 < a0 || a2 < a0){
00151 int clip = src[-1*stride] - src[ 0*stride];
00152 int clip_sign = clip >> 31;
00153 clip = ((clip ^ clip_sign) - clip_sign)>>1;
00154 if(clip){
00155 int a3 = FFMIN(a1, a2);
00156 int d = 5 * (a3 - a0);
00157 int d_sign = (d >> 31);
00158 d = ((d ^ d_sign) - d_sign) >> 3;
00159 d_sign ^= a0_sign;
00160
00161 if( d_sign ^ clip_sign )
00162 d = 0;
00163 else{
00164 d = FFMIN(d, clip);
00165 d = (d ^ d_sign) - d_sign;
00166 src[-1*stride] = av_clip_uint8(src[-1*stride] - d);
00167 src[ 0*stride] = av_clip_uint8(src[ 0*stride] + d);
00168 }
00169 return 1;
00170 }
00171 }
00172 }
00173 return 0;
00174 }
00175
00185 static inline void vc1_loop_filter(uint8_t* src, int step, int stride, int len, int pq)
00186 {
00187 int i;
00188 int filt3;
00189
00190 for(i = 0; i < len; i += 4){
00191 filt3 = vc1_filter_line(src + 2*step, stride, pq);
00192 if(filt3){
00193 vc1_filter_line(src + 0*step, stride, pq);
00194 vc1_filter_line(src + 1*step, stride, pq);
00195 vc1_filter_line(src + 3*step, stride, pq);
00196 }
00197 src += step * 4;
00198 }
00199 }
00200
00201 static void vc1_v_loop_filter4_c(uint8_t *src, int stride, int pq)
00202 {
00203 vc1_loop_filter(src, 1, stride, 4, pq);
00204 }
00205
00206 static void vc1_h_loop_filter4_c(uint8_t *src, int stride, int pq)
00207 {
00208 vc1_loop_filter(src, stride, 1, 4, pq);
00209 }
00210
00211 static void vc1_v_loop_filter8_c(uint8_t *src, int stride, int pq)
00212 {
00213 vc1_loop_filter(src, 1, stride, 8, pq);
00214 }
00215
00216 static void vc1_h_loop_filter8_c(uint8_t *src, int stride, int pq)
00217 {
00218 vc1_loop_filter(src, stride, 1, 8, pq);
00219 }
00220
00221 static void vc1_v_loop_filter16_c(uint8_t *src, int stride, int pq)
00222 {
00223 vc1_loop_filter(src, 1, stride, 16, pq);
00224 }
00225
00226 static void vc1_h_loop_filter16_c(uint8_t *src, int stride, int pq)
00227 {
00228 vc1_loop_filter(src, stride, 1, 16, pq);
00229 }
00230
00233 static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
00234 {
00235 int i;
00236 int dc = block[0];
00237 dc = (3 * dc + 1) >> 1;
00238 dc = (3 * dc + 16) >> 5;
00239 for(i = 0; i < 8; i++){
00240 dest[0] = av_clip_uint8(dest[0] + dc);
00241 dest[1] = av_clip_uint8(dest[1] + dc);
00242 dest[2] = av_clip_uint8(dest[2] + dc);
00243 dest[3] = av_clip_uint8(dest[3] + dc);
00244 dest[4] = av_clip_uint8(dest[4] + dc);
00245 dest[5] = av_clip_uint8(dest[5] + dc);
00246 dest[6] = av_clip_uint8(dest[6] + dc);
00247 dest[7] = av_clip_uint8(dest[7] + dc);
00248 dest += linesize;
00249 }
00250 }
00251
00252 static void vc1_inv_trans_8x8_c(DCTELEM block[64])
00253 {
00254 int i;
00255 register int t1,t2,t3,t4,t5,t6,t7,t8;
00256 DCTELEM *src, *dst, temp[64];
00257
00258 src = block;
00259 dst = temp;
00260 for(i = 0; i < 8; i++){
00261 t1 = 12 * (src[ 0] + src[32]) + 4;
00262 t2 = 12 * (src[ 0] - src[32]) + 4;
00263 t3 = 16 * src[16] + 6 * src[48];
00264 t4 = 6 * src[16] - 16 * src[48];
00265
00266 t5 = t1 + t3;
00267 t6 = t2 + t4;
00268 t7 = t2 - t4;
00269 t8 = t1 - t3;
00270
00271 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
00272 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
00273 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
00274 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
00275
00276 dst[0] = (t5 + t1) >> 3;
00277 dst[1] = (t6 + t2) >> 3;
00278 dst[2] = (t7 + t3) >> 3;
00279 dst[3] = (t8 + t4) >> 3;
00280 dst[4] = (t8 - t4) >> 3;
00281 dst[5] = (t7 - t3) >> 3;
00282 dst[6] = (t6 - t2) >> 3;
00283 dst[7] = (t5 - t1) >> 3;
00284
00285 src += 1;
00286 dst += 8;
00287 }
00288
00289 src = temp;
00290 dst = block;
00291 for(i = 0; i < 8; i++){
00292 t1 = 12 * (src[ 0] + src[32]) + 64;
00293 t2 = 12 * (src[ 0] - src[32]) + 64;
00294 t3 = 16 * src[16] + 6 * src[48];
00295 t4 = 6 * src[16] - 16 * src[48];
00296
00297 t5 = t1 + t3;
00298 t6 = t2 + t4;
00299 t7 = t2 - t4;
00300 t8 = t1 - t3;
00301
00302 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
00303 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
00304 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
00305 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
00306
00307 dst[ 0] = (t5 + t1) >> 7;
00308 dst[ 8] = (t6 + t2) >> 7;
00309 dst[16] = (t7 + t3) >> 7;
00310 dst[24] = (t8 + t4) >> 7;
00311 dst[32] = (t8 - t4 + 1) >> 7;
00312 dst[40] = (t7 - t3 + 1) >> 7;
00313 dst[48] = (t6 - t2 + 1) >> 7;
00314 dst[56] = (t5 - t1 + 1) >> 7;
00315
00316 src++;
00317 dst++;
00318 }
00319 }
00320
00323 static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
00324 {
00325 int i;
00326 int dc = block[0];
00327 dc = ( 3 * dc + 1) >> 1;
00328 dc = (17 * dc + 64) >> 7;
00329 for(i = 0; i < 4; i++){
00330 dest[0] = av_clip_uint8(dest[0] + dc);
00331 dest[1] = av_clip_uint8(dest[1] + dc);
00332 dest[2] = av_clip_uint8(dest[2] + dc);
00333 dest[3] = av_clip_uint8(dest[3] + dc);
00334 dest[4] = av_clip_uint8(dest[4] + dc);
00335 dest[5] = av_clip_uint8(dest[5] + dc);
00336 dest[6] = av_clip_uint8(dest[6] + dc);
00337 dest[7] = av_clip_uint8(dest[7] + dc);
00338 dest += linesize;
00339 }
00340 }
00341
00342 static void vc1_inv_trans_8x4_c(uint8_t *dest, int linesize, DCTELEM *block)
00343 {
00344 int i;
00345 register int t1,t2,t3,t4,t5,t6,t7,t8;
00346 DCTELEM *src, *dst;
00347
00348 src = block;
00349 dst = block;
00350 for(i = 0; i < 4; i++){
00351 t1 = 12 * (src[0] + src[4]) + 4;
00352 t2 = 12 * (src[0] - src[4]) + 4;
00353 t3 = 16 * src[2] + 6 * src[6];
00354 t4 = 6 * src[2] - 16 * src[6];
00355
00356 t5 = t1 + t3;
00357 t6 = t2 + t4;
00358 t7 = t2 - t4;
00359 t8 = t1 - t3;
00360
00361 t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7];
00362 t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7];
00363 t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7];
00364 t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7];
00365
00366 dst[0] = (t5 + t1) >> 3;
00367 dst[1] = (t6 + t2) >> 3;
00368 dst[2] = (t7 + t3) >> 3;
00369 dst[3] = (t8 + t4) >> 3;
00370 dst[4] = (t8 - t4) >> 3;
00371 dst[5] = (t7 - t3) >> 3;
00372 dst[6] = (t6 - t2) >> 3;
00373 dst[7] = (t5 - t1) >> 3;
00374
00375 src += 8;
00376 dst += 8;
00377 }
00378
00379 src = block;
00380 for(i = 0; i < 8; i++){
00381 t1 = 17 * (src[ 0] + src[16]) + 64;
00382 t2 = 17 * (src[ 0] - src[16]) + 64;
00383 t3 = 22 * src[ 8] + 10 * src[24];
00384 t4 = 22 * src[24] - 10 * src[ 8];
00385
00386 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t1 + t3) >> 7));
00387 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t2 - t4) >> 7));
00388 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t2 + t4) >> 7));
00389 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t1 - t3) >> 7));
00390
00391 src ++;
00392 dest++;
00393 }
00394 }
00395
00398 static void vc1_inv_trans_4x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
00399 {
00400 int i;
00401 int dc = block[0];
00402 dc = (17 * dc + 4) >> 3;
00403 dc = (12 * dc + 64) >> 7;
00404 for(i = 0; i < 8; i++){
00405 dest[0] = av_clip_uint8(dest[0] + dc);
00406 dest[1] = av_clip_uint8(dest[1] + dc);
00407 dest[2] = av_clip_uint8(dest[2] + dc);
00408 dest[3] = av_clip_uint8(dest[3] + dc);
00409 dest += linesize;
00410 }
00411 }
00412
00413 static void vc1_inv_trans_4x8_c(uint8_t *dest, int linesize, DCTELEM *block)
00414 {
00415 int i;
00416 register int t1,t2,t3,t4,t5,t6,t7,t8;
00417 DCTELEM *src, *dst;
00418
00419 src = block;
00420 dst = block;
00421 for(i = 0; i < 8; i++){
00422 t1 = 17 * (src[0] + src[2]) + 4;
00423 t2 = 17 * (src[0] - src[2]) + 4;
00424 t3 = 22 * src[1] + 10 * src[3];
00425 t4 = 22 * src[3] - 10 * src[1];
00426
00427 dst[0] = (t1 + t3) >> 3;
00428 dst[1] = (t2 - t4) >> 3;
00429 dst[2] = (t2 + t4) >> 3;
00430 dst[3] = (t1 - t3) >> 3;
00431
00432 src += 8;
00433 dst += 8;
00434 }
00435
00436 src = block;
00437 for(i = 0; i < 4; i++){
00438 t1 = 12 * (src[ 0] + src[32]) + 64;
00439 t2 = 12 * (src[ 0] - src[32]) + 64;
00440 t3 = 16 * src[16] + 6 * src[48];
00441 t4 = 6 * src[16] - 16 * src[48];
00442
00443 t5 = t1 + t3;
00444 t6 = t2 + t4;
00445 t7 = t2 - t4;
00446 t8 = t1 - t3;
00447
00448 t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56];
00449 t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56];
00450 t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56];
00451 t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56];
00452
00453 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t5 + t1) >> 7));
00454 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t6 + t2) >> 7));
00455 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t7 + t3) >> 7));
00456 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t8 + t4) >> 7));
00457 dest[4*linesize] = av_clip_uint8(dest[4*linesize] + ((t8 - t4 + 1) >> 7));
00458 dest[5*linesize] = av_clip_uint8(dest[5*linesize] + ((t7 - t3 + 1) >> 7));
00459 dest[6*linesize] = av_clip_uint8(dest[6*linesize] + ((t6 - t2 + 1) >> 7));
00460 dest[7*linesize] = av_clip_uint8(dest[7*linesize] + ((t5 - t1 + 1) >> 7));
00461
00462 src ++;
00463 dest++;
00464 }
00465 }
00466
00469 static void vc1_inv_trans_4x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block)
00470 {
00471 int i;
00472 int dc = block[0];
00473 dc = (17 * dc + 4) >> 3;
00474 dc = (17 * dc + 64) >> 7;
00475 for(i = 0; i < 4; i++){
00476 dest[0] = av_clip_uint8(dest[0] + dc);
00477 dest[1] = av_clip_uint8(dest[1] + dc);
00478 dest[2] = av_clip_uint8(dest[2] + dc);
00479 dest[3] = av_clip_uint8(dest[3] + dc);
00480 dest += linesize;
00481 }
00482 }
00483
00484 static void vc1_inv_trans_4x4_c(uint8_t *dest, int linesize, DCTELEM *block)
00485 {
00486 int i;
00487 register int t1,t2,t3,t4;
00488 DCTELEM *src, *dst;
00489
00490 src = block;
00491 dst = block;
00492 for(i = 0; i < 4; i++){
00493 t1 = 17 * (src[0] + src[2]) + 4;
00494 t2 = 17 * (src[0] - src[2]) + 4;
00495 t3 = 22 * src[1] + 10 * src[3];
00496 t4 = 22 * src[3] - 10 * src[1];
00497
00498 dst[0] = (t1 + t3) >> 3;
00499 dst[1] = (t2 - t4) >> 3;
00500 dst[2] = (t2 + t4) >> 3;
00501 dst[3] = (t1 - t3) >> 3;
00502
00503 src += 8;
00504 dst += 8;
00505 }
00506
00507 src = block;
00508 for(i = 0; i < 4; i++){
00509 t1 = 17 * (src[ 0] + src[16]) + 64;
00510 t2 = 17 * (src[ 0] - src[16]) + 64;
00511 t3 = 22 * src[ 8] + 10 * src[24];
00512 t4 = 22 * src[24] - 10 * src[ 8];
00513
00514 dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t1 + t3) >> 7));
00515 dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t2 - t4) >> 7));
00516 dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t2 + t4) >> 7));
00517 dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t1 - t3) >> 7));
00518
00519 src ++;
00520 dest++;
00521 }
00522 }
00523
00524
00526 #define VC1_MSPEL_FILTER_16B(DIR, TYPE) \
00527 static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, int stride, int mode) \
00528 { \
00529 switch(mode){ \
00530 case 0: \
00531 return 0; \
00532 case 1: \
00533 return -4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2]; \
00534 case 2: \
00535 return -src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2]; \
00536 case 3: \
00537 return -3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2]; \
00538 } \
00539 return 0; \
00540 }
00541
00542 VC1_MSPEL_FILTER_16B(ver, uint8_t)
00543 VC1_MSPEL_FILTER_16B(hor, int16_t)
00544
00545
00548 static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int mode, int r)
00549 {
00550 switch(mode){
00551 case 0:
00552 return src[0];
00553 case 1:
00554 return (-4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2] + 32 - r) >> 6;
00555 case 2:
00556 return (-src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2] + 8 - r) >> 4;
00557 case 3:
00558 return (-3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2] + 32 - r) >> 6;
00559 }
00560 return 0;
00561 }
00562
00565 #define VC1_MSPEL_MC(OP, OPNAME)\
00566 static av_always_inline void OPNAME ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int hmode, int vmode, int rnd)\
00567 {\
00568 int i, j;\
00569 \
00570 if (vmode) { \
00571 int r;\
00572 \
00573 if (hmode) { \
00574 static const int shift_value[] = { 0, 5, 1, 5 };\
00575 int shift = (shift_value[hmode]+shift_value[vmode])>>1;\
00576 int16_t tmp[11*8], *tptr = tmp;\
00577 \
00578 r = (1<<(shift-1)) + rnd-1;\
00579 \
00580 src -= 1;\
00581 for(j = 0; j < 8; j++) {\
00582 for(i = 0; i < 11; i++)\
00583 tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode)+r)>>shift;\
00584 src += stride;\
00585 tptr += 11;\
00586 }\
00587 \
00588 r = 64-rnd;\
00589 tptr = tmp+1;\
00590 for(j = 0; j < 8; j++) {\
00591 for(i = 0; i < 8; i++)\
00592 OP(dst[i], (vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode)+r)>>7);\
00593 dst += stride;\
00594 tptr += 11;\
00595 }\
00596 \
00597 return;\
00598 }\
00599 else { \
00600 r = 1-rnd;\
00601 \
00602 for(j = 0; j < 8; j++) {\
00603 for(i = 0; i < 8; i++)\
00604 OP(dst[i], vc1_mspel_filter(src + i, stride, vmode, r));\
00605 src += stride;\
00606 dst += stride;\
00607 }\
00608 return;\
00609 }\
00610 }\
00611 \
00612 \
00613 for(j = 0; j < 8; j++) {\
00614 for(i = 0; i < 8; i++)\
00615 OP(dst[i], vc1_mspel_filter(src + i, 1, hmode, rnd));\
00616 dst += stride;\
00617 src += stride;\
00618 }\
00619 }
00620
00621 #define op_put(a, b) a = av_clip_uint8(b)
00622 #define op_avg(a, b) a = (a + av_clip_uint8(b) + 1) >> 1
00623
00624 VC1_MSPEL_MC(op_put, put_)
00625 VC1_MSPEL_MC(op_avg, avg_)
00626
00627
00628
00629 #define PUT_VC1_MSPEL(a, b)\
00630 static void put_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
00631 put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
00632 }\
00633 static void avg_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \
00634 avg_vc1_mspel_mc(dst, src, stride, a, b, rnd); \
00635 }
00636
00637 PUT_VC1_MSPEL(1, 0)
00638 PUT_VC1_MSPEL(2, 0)
00639 PUT_VC1_MSPEL(3, 0)
00640
00641 PUT_VC1_MSPEL(0, 1)
00642 PUT_VC1_MSPEL(1, 1)
00643 PUT_VC1_MSPEL(2, 1)
00644 PUT_VC1_MSPEL(3, 1)
00645
00646 PUT_VC1_MSPEL(0, 2)
00647 PUT_VC1_MSPEL(1, 2)
00648 PUT_VC1_MSPEL(2, 2)
00649 PUT_VC1_MSPEL(3, 2)
00650
00651 PUT_VC1_MSPEL(0, 3)
00652 PUT_VC1_MSPEL(1, 3)
00653 PUT_VC1_MSPEL(2, 3)
00654 PUT_VC1_MSPEL(3, 3)
00655
00656 static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y){
00657 const int A=(8-x)*(8-y);
00658 const int B=( x)*(8-y);
00659 const int C=(8-x)*( y);
00660 const int D=( x)*( y);
00661 int i;
00662
00663 av_assert2(x<8 && y<8 && x>=0 && y>=0);
00664
00665 for(i=0; i<h; i++)
00666 {
00667 dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
00668 dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
00669 dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
00670 dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
00671 dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
00672 dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
00673 dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
00674 dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
00675 dst+= stride;
00676 src+= stride;
00677 }
00678 }
00679
00680 static void put_no_rnd_vc1_chroma_mc4_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y){
00681 const int A=(8-x)*(8-y);
00682 const int B=( x)*(8-y);
00683 const int C=(8-x)*( y);
00684 const int D=( x)*( y);
00685 int i;
00686
00687 av_assert2(x<8 && y<8 && x>=0 && y>=0);
00688
00689 for(i=0; i<h; i++)
00690 {
00691 dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
00692 dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
00693 dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
00694 dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
00695 dst+= stride;
00696 src+= stride;
00697 }
00698 }
00699
00700 #define avg2(a,b) ((a+b+1)>>1)
00701 static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y){
00702 const int A=(8-x)*(8-y);
00703 const int B=( x)*(8-y);
00704 const int C=(8-x)*( y);
00705 const int D=( x)*( y);
00706 int i;
00707
00708 av_assert2(x<8 && y<8 && x>=0 && y>=0);
00709
00710 for(i=0; i<h; i++)
00711 {
00712 dst[0] = avg2(dst[0], ((A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6));
00713 dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6));
00714 dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6));
00715 dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6));
00716 dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6));
00717 dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6));
00718 dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6));
00719 dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6));
00720 dst+= stride;
00721 src+= stride;
00722 }
00723 }
00724
00725 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
00726
00727 static void sprite_h_c(uint8_t *dst, const uint8_t *src, int offset, int advance, int count)
00728 {
00729 while (count--) {
00730 int a = src[(offset >> 16) ];
00731 int b = src[(offset >> 16) + 1];
00732 *dst++ = a + ((b - a) * (offset&0xFFFF) >> 16);
00733 offset += advance;
00734 }
00735 }
00736
00737 static av_always_inline void sprite_v_template(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
00738 int two_sprites, const uint8_t *src2a, const uint8_t *src2b, int offset2,
00739 int alpha, int scaled, int width)
00740 {
00741 int a1, b1, a2, b2;
00742 while (width--) {
00743 a1 = *src1a++;
00744 if (scaled) {
00745 b1 = *src1b++;
00746 a1 = a1 + ((b1 - a1) * offset1 >> 16);
00747 }
00748 if (two_sprites) {
00749 a2 = *src2a++;
00750 if (scaled > 1) {
00751 b2 = *src2b++;
00752 a2 = a2 + ((b2 - a2) * offset2 >> 16);
00753 }
00754 a1 = a1 + ((a2 - a1) * alpha >> 16);
00755 }
00756 *dst++ = a1;
00757 }
00758 }
00759
00760 static void sprite_v_single_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset, int width)
00761 {
00762 sprite_v_template(dst, src1a, src1b, offset, 0, NULL, NULL, 0, 0, 1, width);
00763 }
00764
00765 static void sprite_v_double_noscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src2a, int alpha, int width)
00766 {
00767 sprite_v_template(dst, src1a, NULL, 0, 1, src2a, NULL, 0, alpha, 0, width);
00768 }
00769
00770 static void sprite_v_double_onescale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
00771 const uint8_t *src2a, int alpha, int width)
00772 {
00773 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, NULL, 0, alpha, 1, width);
00774 }
00775
00776 static void sprite_v_double_twoscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1,
00777 const uint8_t *src2a, const uint8_t *src2b, int offset2,
00778 int alpha, int width)
00779 {
00780 sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2, alpha, 2, width);
00781 }
00782
00783 #endif
00784
00785 av_cold void ff_vc1dsp_init(VC1DSPContext* dsp) {
00786 dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c;
00787 dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c;
00788 dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c;
00789 dsp->vc1_inv_trans_4x4 = vc1_inv_trans_4x4_c;
00790 dsp->vc1_inv_trans_8x8_dc = vc1_inv_trans_8x8_dc_c;
00791 dsp->vc1_inv_trans_4x8_dc = vc1_inv_trans_4x8_dc_c;
00792 dsp->vc1_inv_trans_8x4_dc = vc1_inv_trans_8x4_dc_c;
00793 dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_c;
00794 dsp->vc1_h_overlap = vc1_h_overlap_c;
00795 dsp->vc1_v_overlap = vc1_v_overlap_c;
00796 dsp->vc1_h_s_overlap = vc1_h_s_overlap_c;
00797 dsp->vc1_v_s_overlap = vc1_v_s_overlap_c;
00798 dsp->vc1_v_loop_filter4 = vc1_v_loop_filter4_c;
00799 dsp->vc1_h_loop_filter4 = vc1_h_loop_filter4_c;
00800 dsp->vc1_v_loop_filter8 = vc1_v_loop_filter8_c;
00801 dsp->vc1_h_loop_filter8 = vc1_h_loop_filter8_c;
00802 dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_c;
00803 dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_c;
00804
00805 dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_pixels8x8_c;
00806 dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_c;
00807 dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_c;
00808 dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_c;
00809 dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_c;
00810 dsp->put_vc1_mspel_pixels_tab[ 5] = put_vc1_mspel_mc11_c;
00811 dsp->put_vc1_mspel_pixels_tab[ 6] = put_vc1_mspel_mc21_c;
00812 dsp->put_vc1_mspel_pixels_tab[ 7] = put_vc1_mspel_mc31_c;
00813 dsp->put_vc1_mspel_pixels_tab[ 8] = put_vc1_mspel_mc02_c;
00814 dsp->put_vc1_mspel_pixels_tab[ 9] = put_vc1_mspel_mc12_c;
00815 dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_c;
00816 dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_c;
00817 dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_c;
00818 dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_c;
00819 dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_c;
00820 dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_c;
00821
00822 dsp->avg_vc1_mspel_pixels_tab[ 0] = ff_avg_pixels8x8_c;
00823 dsp->avg_vc1_mspel_pixels_tab[ 1] = avg_vc1_mspel_mc10_c;
00824 dsp->avg_vc1_mspel_pixels_tab[ 2] = avg_vc1_mspel_mc20_c;
00825 dsp->avg_vc1_mspel_pixels_tab[ 3] = avg_vc1_mspel_mc30_c;
00826 dsp->avg_vc1_mspel_pixels_tab[ 4] = avg_vc1_mspel_mc01_c;
00827 dsp->avg_vc1_mspel_pixels_tab[ 5] = avg_vc1_mspel_mc11_c;
00828 dsp->avg_vc1_mspel_pixels_tab[ 6] = avg_vc1_mspel_mc21_c;
00829 dsp->avg_vc1_mspel_pixels_tab[ 7] = avg_vc1_mspel_mc31_c;
00830 dsp->avg_vc1_mspel_pixels_tab[ 8] = avg_vc1_mspel_mc02_c;
00831 dsp->avg_vc1_mspel_pixels_tab[ 9] = avg_vc1_mspel_mc12_c;
00832 dsp->avg_vc1_mspel_pixels_tab[10] = avg_vc1_mspel_mc22_c;
00833 dsp->avg_vc1_mspel_pixels_tab[11] = avg_vc1_mspel_mc32_c;
00834 dsp->avg_vc1_mspel_pixels_tab[12] = avg_vc1_mspel_mc03_c;
00835 dsp->avg_vc1_mspel_pixels_tab[13] = avg_vc1_mspel_mc13_c;
00836 dsp->avg_vc1_mspel_pixels_tab[14] = avg_vc1_mspel_mc23_c;
00837 dsp->avg_vc1_mspel_pixels_tab[15] = avg_vc1_mspel_mc33_c;
00838
00839 dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c;
00840 dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c;
00841 dsp->put_no_rnd_vc1_chroma_pixels_tab[1] = put_no_rnd_vc1_chroma_mc4_c;
00842
00843 #if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
00844 dsp->sprite_h = sprite_h_c;
00845 dsp->sprite_v_single = sprite_v_single_c;
00846 dsp->sprite_v_double_noscale = sprite_v_double_noscale_c;
00847 dsp->sprite_v_double_onescale = sprite_v_double_onescale_c;
00848 dsp->sprite_v_double_twoscale = sprite_v_double_twoscale_c;
00849 #endif
00850
00851 if (HAVE_ALTIVEC)
00852 ff_vc1dsp_init_altivec(dsp);
00853 if (HAVE_MMX)
00854 ff_vc1dsp_init_mmx(dsp);
00855 }