00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "contributors.h"
00017
00018 #include <limits.h>
00019
00020 #include "global.h"
00021 #include "image.h"
00022 #include "img_luma.h"
00023 #include "memalloc.h"
00024
00025 static const int ONE_FOURTH_TAP[2][3] =
00026 {
00027 {20, -5, 1},
00028 {20,-4, 0},
00029 };
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 void getSubImagesLuma( ImageParameters *p_Img, InputParameters *p_Inp, StorablePicture *s )
00047 {
00048 imgpel ****cImgSub = s->p_curr_img_sub;
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 getSubImageInteger( s, cImgSub[0][0], s->p_curr_img);
00060
00061
00062
00063
00064
00065 getHorSubImageSixTap( p_Img, s, cImgSub[0][2], cImgSub[0][0] );
00066
00067
00068
00069 getVerSubImageSixTap( p_Img, s, cImgSub[2][0], cImgSub[0][0]);
00070
00071
00072
00073 getVerSubImageSixTapTmp( p_Img, s, cImgSub[2][2]);
00074
00075
00076
00077
00078 getSubImageBiLinear ( s, cImgSub[0][1], cImgSub[0][0], cImgSub[0][2]);
00079
00080 getSubImageBiLinear ( s, cImgSub[1][0], cImgSub[0][0], cImgSub[2][0]);
00081
00082 getSubImageBiLinear ( s, cImgSub[1][1], cImgSub[0][2], cImgSub[2][0]);
00083
00084 getSubImageBiLinear ( s, cImgSub[1][2], cImgSub[0][2], cImgSub[2][2]);
00085
00086 getSubImageBiLinear ( s, cImgSub[2][1], cImgSub[2][0], cImgSub[2][2]);
00087
00088
00089 getHorSubImageBiLinear ( s, cImgSub[0][3], cImgSub[0][2], cImgSub[0][0]);
00090
00091 getHorSubImageBiLinear ( s, cImgSub[1][3], cImgSub[0][2], cImgSub[2][0]);
00092
00093 getHorSubImageBiLinear ( s, cImgSub[2][3], cImgSub[2][2], cImgSub[2][0]);
00094
00095
00096 getVerSubImageBiLinear ( s, cImgSub[3][0], cImgSub[2][0], cImgSub[0][0]);
00097
00098 getVerSubImageBiLinear ( s, cImgSub[3][1], cImgSub[2][0], cImgSub[0][2]);
00099
00100 getVerSubImageBiLinear ( s, cImgSub[3][2], cImgSub[2][2], cImgSub[0][2]);
00101
00102
00103 getDiagSubImageBiLinear( s, cImgSub[3][3], cImgSub[0][2], cImgSub[2][0]);
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 void getSubImageInteger( StorablePicture *s, imgpel **dstImg, imgpel **srcImg)
00121 {
00122 int i, j;
00123 int size_x_minus1 = s->size_x - 1;
00124
00125 imgpel *wBufSrc, *wBufDst;
00126
00127
00128 wBufDst = &( dstImg[0][0] );
00129 wBufSrc = srcImg[0];
00130
00131 for (i = 0; i < IMG_PAD_SIZE; i++)
00132 *(wBufDst++) = wBufSrc[0];
00133
00134 memcpy(wBufDst, wBufSrc, s->size_x * sizeof(imgpel));
00135 wBufDst += s->size_x;
00136
00137 for (i = 0; i < IMG_PAD_SIZE; i++)
00138 *(wBufDst++) = wBufSrc[size_x_minus1];
00139
00140
00141 for (j = 1; j < IMG_PAD_SIZE + 1; j++)
00142 {
00143 memcpy(dstImg[j], dstImg[j - 1], s->size_x_padded * sizeof(imgpel));
00144 }
00145
00146 for (j = 1; j < s->size_y; j++)
00147 {
00148 wBufDst = &( dstImg[j + IMG_PAD_SIZE][0] );
00149 wBufSrc = srcImg[j];
00150
00151 for (i = 0; i < IMG_PAD_SIZE; i++)
00152 *(wBufDst++) = wBufSrc[0];
00153
00154 memcpy(wBufDst, wBufSrc, s->size_x * sizeof(imgpel));
00155 wBufDst += s->size_x;
00156
00157 for (i = 0; i < IMG_PAD_SIZE; i++)
00158 *(wBufDst++) = wBufSrc[size_x_minus1];
00159 }
00160
00161
00162 for (j = s->size_y + IMG_PAD_SIZE; j < s->size_y_padded; j++)
00163 {
00164 memcpy(dstImg[j], dstImg[j - 1], s->size_x_padded * sizeof(imgpel));
00165 }
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 void getHorSubImageSixTap( ImageParameters *p_Img, StorablePicture *s, imgpel **dstImg, imgpel **srcImg)
00184 {
00185 int is, jpad, ipad;
00186 int ypadded_size = s->size_y_padded;
00187 int xpadded_size = s->size_x_padded;
00188
00189 imgpel *wBufSrc, *wBufDst;
00190 imgpel *srcImgA, *srcImgB, *srcImgC, *srcImgD, *srcImgE, *srcImgF;
00191 int *iBufDst;
00192 const int tap0 = ONE_FOURTH_TAP[0][0];
00193 const int tap1 = ONE_FOURTH_TAP[0][1];
00194 const int tap2 = ONE_FOURTH_TAP[0][2];
00195
00196 for (jpad = 0; jpad < ypadded_size; jpad++)
00197 {
00198 wBufSrc = srcImg[jpad];
00199 wBufDst = dstImg[jpad];
00200 iBufDst = p_Img->imgY_sub_tmp[jpad];
00201
00202 srcImgA = &wBufSrc[0];
00203 srcImgB = &wBufSrc[0];
00204 srcImgC = &wBufSrc[0];
00205 srcImgD = &wBufSrc[1];
00206 srcImgE = &wBufSrc[2];
00207 srcImgF = &wBufSrc[3];
00208
00209
00210 is =
00211 (tap0 * (*srcImgA++ + *srcImgD++) +
00212 tap1 * (*srcImgB + *srcImgE++) +
00213 tap2 * (*srcImgC + *srcImgF++));
00214
00215 *iBufDst++ = is;
00216 *wBufDst++ = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 5 ) );
00217
00218 is =
00219 (tap0 * (*srcImgA++ + *srcImgD++) +
00220 tap1 * (*srcImgB++ + *srcImgE++) +
00221 tap2 * (*srcImgC + *srcImgF++));
00222
00223 *iBufDst++ = is;
00224 *wBufDst++ = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 5 ) );
00225
00226
00227 for (ipad = 2; ipad < xpadded_size - 4; ipad++)
00228 {
00229 is =
00230 (tap0 * (*srcImgA++ + *srcImgD++) +
00231 tap1 * (*srcImgB++ + *srcImgE++) +
00232 tap2 * (*srcImgC++ + *srcImgF++));
00233
00234 *iBufDst++ = is;
00235 *wBufDst++ = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 5 ) );
00236 }
00237
00238 is = (
00239 tap0 * (*srcImgA++ + *srcImgD++) +
00240 tap1 * (*srcImgB++ + *srcImgE++) +
00241 tap2 * (*srcImgC++ + *srcImgF ));
00242
00243 *iBufDst++ = is;
00244 *wBufDst++ = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 5 ) );
00245
00246
00247 is = (
00248 tap0 * (*srcImgA++ + *srcImgD++) +
00249 tap1 * (*srcImgB++ + *srcImgE) +
00250 tap2 * (*srcImgC++ + *srcImgF));
00251
00252 *iBufDst++ = is;
00253 *wBufDst++ = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 5 ) );
00254
00255 is = (
00256 tap0 * (*srcImgA++ + *srcImgD) +
00257 tap1 * (*srcImgB++ + *srcImgE) +
00258 tap2 * (*srcImgC++ + *srcImgF));
00259
00260 *iBufDst++ = is;
00261 *wBufDst++ = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 5 ) );
00262
00263 is = (
00264 tap0 * (*srcImgA + *srcImgD) +
00265 tap1 * (*srcImgB + *srcImgE) +
00266 tap2 * (*srcImgC + *srcImgF));
00267
00268 *iBufDst = is;
00269 *wBufDst = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 5 ) );
00270
00271 }
00272 }
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 void getVerSubImageSixTap( ImageParameters *p_Img, StorablePicture *s, imgpel **dstImg, imgpel **srcImg)
00291 {
00292 int is, jpad, ipad;
00293 int ypadded_size = s->size_y_padded;
00294 int xpadded_size = s->size_x_padded;
00295 int maxy = ypadded_size - 1;
00296
00297 imgpel *wxLineDst;
00298 imgpel *srcImgA, *srcImgB, *srcImgC, *srcImgD, *srcImgE, *srcImgF;
00299 const int tap0 = ONE_FOURTH_TAP[0][0];
00300 const int tap1 = ONE_FOURTH_TAP[0][1];
00301 const int tap2 = ONE_FOURTH_TAP[0][2];
00302
00303
00304
00305 for (jpad = 0; jpad < 2; jpad++)
00306 {
00307 wxLineDst = dstImg[jpad];
00308 srcImgA = srcImg[jpad ];
00309 srcImgB = srcImg[0];
00310 srcImgC = srcImg[0];
00311 srcImgD = srcImg[jpad + 1];
00312 srcImgE = srcImg[jpad + 2];
00313 srcImgF = srcImg[jpad + 3];
00314 for (ipad = 0; ipad < xpadded_size; ipad++)
00315 {
00316 is =
00317 (tap0 * (*srcImgA++ + *srcImgD++) +
00318 tap1 * (*srcImgB++ + *srcImgE++) +
00319 tap2 * (*srcImgC++ + *srcImgF++));
00320
00321 wxLineDst[ipad] = (imgpel) iClip1 (p_Img->max_imgpel_value, rshift_rnd_sf( is, 5 ) );
00322 }
00323 }
00324
00325 for (jpad = 2; jpad < ypadded_size - 3; jpad++)
00326 {
00327 wxLineDst = dstImg[jpad];
00328 srcImgA = srcImg[jpad ];
00329 srcImgB = srcImg[jpad - 1];
00330 srcImgC = srcImg[jpad - 2];
00331 srcImgD = srcImg[jpad + 1];
00332 srcImgE = srcImg[jpad + 2];
00333 srcImgF = srcImg[jpad + 3];
00334 for (ipad = 0; ipad < xpadded_size; ipad++)
00335 {
00336 is =
00337 (tap0 * (*srcImgA++ + *srcImgD++) +
00338 tap1 * (*srcImgB++ + *srcImgE++) +
00339 tap2 * (*srcImgC++ + *srcImgF++));
00340
00341 wxLineDst[ipad] = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 5 ) );
00342 }
00343 }
00344
00345
00346 for (jpad = ypadded_size - 3; jpad < ypadded_size; jpad++)
00347 {
00348 wxLineDst = dstImg[jpad];
00349 srcImgA = srcImg[jpad ];
00350 srcImgB = srcImg[jpad - 1];
00351 srcImgC = srcImg[jpad - 2];
00352 srcImgD = srcImg[imin (maxy, jpad + 1)];
00353 srcImgE = srcImg[maxy];
00354 srcImgF = srcImg[maxy];
00355 for (ipad = 0; ipad < xpadded_size; ipad++)
00356 {
00357 is =
00358 (tap0 * (*srcImgA++ + *srcImgD++) +
00359 tap1 * (*srcImgB++ + *srcImgE++) +
00360 tap2 * (*srcImgC++ + *srcImgF++));
00361
00362 wxLineDst[ipad] = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 5 ) );
00363 }
00364 }
00365 }
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 void getVerSubImageSixTapTmp( ImageParameters *p_Img, StorablePicture *s, imgpel **dstImg)
00381 {
00382 int is, jpad, ipad;
00383 int ypadded_size = s->size_y_padded;
00384 int xpadded_size = s->size_x_padded;
00385 int maxy = ypadded_size - 1;
00386
00387 imgpel *wxLineDst;
00388 int *srcImgA, *srcImgB, *srcImgC, *srcImgD, *srcImgE, *srcImgF;
00389 const int tap0 = ONE_FOURTH_TAP[0][0];
00390 const int tap1 = ONE_FOURTH_TAP[0][1];
00391 const int tap2 = ONE_FOURTH_TAP[0][2];
00392
00393
00394 for (jpad = 0; jpad < 2; jpad++)
00395 {
00396 wxLineDst = dstImg[jpad];
00397 srcImgA = p_Img->imgY_sub_tmp[jpad ];
00398 srcImgB = p_Img->imgY_sub_tmp[0];
00399 srcImgC = p_Img->imgY_sub_tmp[0];
00400 srcImgD = p_Img->imgY_sub_tmp[jpad + 1];
00401 srcImgE = p_Img->imgY_sub_tmp[jpad + 2];
00402 srcImgF = p_Img->imgY_sub_tmp[jpad + 3];
00403
00404 for (ipad = 0; ipad < xpadded_size; ipad++)
00405 {
00406 is =
00407 (tap0 * (*srcImgA++ + *srcImgD++) +
00408 tap1 * (*srcImgB++ + *srcImgE++) +
00409 tap2 * (*srcImgC++ + *srcImgF++));
00410
00411 wxLineDst[ipad] = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 10 ) );
00412 }
00413 }
00414
00415
00416 for (jpad = 2; jpad < ypadded_size - 3; jpad++)
00417 {
00418 wxLineDst = dstImg[jpad];
00419 srcImgA = p_Img->imgY_sub_tmp[jpad ];
00420 srcImgB = p_Img->imgY_sub_tmp[jpad - 1];
00421 srcImgC = p_Img->imgY_sub_tmp[jpad - 2];
00422 srcImgD = p_Img->imgY_sub_tmp[jpad + 1];
00423 srcImgE = p_Img->imgY_sub_tmp[jpad + 2];
00424 srcImgF = p_Img->imgY_sub_tmp[jpad + 3];
00425 for (ipad = 0; ipad < xpadded_size; ipad++)
00426 {
00427 is =
00428 (tap0 * (*srcImgA++ + *srcImgD++) +
00429 tap1 * (*srcImgB++ + *srcImgE++) +
00430 tap2 * (*srcImgC++ + *srcImgF++));
00431
00432 wxLineDst[ipad] = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 10 ) );
00433 }
00434 }
00435
00436
00437 for (jpad = ypadded_size - 3; jpad < ypadded_size; jpad++)
00438 {
00439 wxLineDst = dstImg[jpad];
00440 srcImgA = p_Img->imgY_sub_tmp[jpad ];
00441 srcImgB = p_Img->imgY_sub_tmp[jpad - 1];
00442 srcImgC = p_Img->imgY_sub_tmp[jpad - 2];
00443 srcImgD = p_Img->imgY_sub_tmp[imin (maxy, jpad + 1)];
00444 srcImgE = p_Img->imgY_sub_tmp[maxy];
00445 srcImgF = p_Img->imgY_sub_tmp[maxy];
00446 for (ipad = 0; ipad < xpadded_size; ipad++)
00447 {
00448 is =
00449 (tap0 * (*srcImgA++ + *srcImgD++) +
00450 tap1 * (*srcImgB++ + *srcImgE++) +
00451 tap2 * (*srcImgC++ + *srcImgF++));
00452
00453 wxLineDst[ipad] = (imgpel) iClip1 ( p_Img->max_imgpel_value, rshift_rnd_sf( is, 10 ) );
00454 }
00455 }
00456 }
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473 void getSubImageBiLinear( StorablePicture *s, imgpel **dstImg, imgpel **srcImgL, imgpel **srcImgR)
00474 {
00475 int jpad, ipad;
00476 int ypadded_size = s->size_y_padded;
00477 int xpadded_size = s->size_x_padded;
00478
00479 imgpel *wBufSrcL, *wBufSrcR, *wBufDst;
00480
00481 for (jpad = 0; jpad < ypadded_size; jpad++)
00482 {
00483 wBufSrcL = srcImgL[jpad];
00484 wBufSrcR = srcImgR[jpad];
00485 wBufDst = dstImg[jpad];
00486
00487 for (ipad = 0; ipad < xpadded_size; ipad++)
00488 {
00489 *wBufDst++ = (imgpel) rshift_rnd_sf( *wBufSrcL++ + *wBufSrcR++, 1 );
00490 }
00491 }
00492 }
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510 void getHorSubImageBiLinear( StorablePicture *s, imgpel **dstImg, imgpel **srcImgL, imgpel **srcImgR)
00511 {
00512 int jpad, ipad;
00513 int ypadded_size = s->size_y_padded;
00514 int xpadded_size = s->size_x_padded - 1;
00515
00516 imgpel *wBufSrcL, *wBufSrcR, *wBufDst;
00517
00518 for (jpad = 0; jpad < ypadded_size; jpad++)
00519 {
00520 wBufSrcL = srcImgL[jpad];
00521 wBufSrcR = &srcImgR[jpad][1];
00522 wBufDst = dstImg[jpad];
00523
00524
00525 for (ipad = 0; ipad < xpadded_size; ipad++)
00526 {
00527 *wBufDst++ = (imgpel) rshift_rnd_sf( *wBufSrcL++ + *wBufSrcR++, 1 );
00528 }
00529
00530 *wBufDst++ = (imgpel) rshift_rnd_sf( *wBufSrcL++ + wBufSrcR[-1], 1 );
00531 }
00532 }
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550 void getVerSubImageBiLinear( StorablePicture *s, imgpel **dstImg, imgpel **srcImgT, imgpel **srcImgB)
00551 {
00552 int jpad, ipad;
00553 int ypadded_size = s->size_y_padded - 1;
00554 int xpadded_size = s->size_x_padded;
00555
00556 imgpel *wBufSrcT, *wBufSrcB, *wBufDst;
00557
00558
00559 for (jpad = 0; jpad < ypadded_size; jpad++)
00560 {
00561 wBufSrcT = srcImgT[jpad];
00562 wBufDst = dstImg[jpad];
00563 wBufSrcB = srcImgB[jpad + 1];
00564
00565 for (ipad = 0; ipad < xpadded_size; ipad++)
00566 {
00567 *wBufDst++ = (imgpel) rshift_rnd_sf(*wBufSrcT++ + *wBufSrcB++, 1);
00568 }
00569 }
00570
00571 wBufSrcT = srcImgT[ypadded_size];
00572 wBufDst = dstImg[ypadded_size];
00573 wBufSrcB = srcImgB[ypadded_size];
00574
00575 for (ipad = 0; ipad < xpadded_size; ipad++)
00576 {
00577 *wBufDst++ = (imgpel) rshift_rnd_sf(*wBufSrcT++ + *wBufSrcB++, 1);
00578 }
00579 }
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597 void getDiagSubImageBiLinear( StorablePicture *s, imgpel **dstImg, imgpel **srcImgT, imgpel **srcImgB )
00598 {
00599 int jpad, ipad;
00600 int maxx = s->size_x_padded - 1;
00601 int maxy = s->size_y_padded - 1;
00602
00603 imgpel *wBufSrcL, *wBufSrcR, *wBufDst;
00604
00605 for (jpad = 0; jpad < maxy; jpad++)
00606 {
00607 wBufSrcL = srcImgT[jpad + 1];
00608 wBufSrcR = &srcImgB[jpad][1];
00609 wBufDst = dstImg[jpad];
00610
00611 for (ipad = 0; ipad < maxx; ipad++)
00612 {
00613 *wBufDst++ = (imgpel) rshift_rnd_sf(*wBufSrcL++ + *wBufSrcR++, 1);
00614 }
00615
00616 *wBufDst++ = (imgpel) rshift_rnd_sf(*wBufSrcL++ + wBufSrcR[-1], 1);
00617 }
00618
00619 wBufSrcL = srcImgT[maxy];
00620 wBufSrcR = &srcImgB[maxy][1];
00621 wBufDst = dstImg[maxy];
00622
00623 for (ipad = 0; ipad < maxx; ipad++)
00624 {
00625 *wBufDst++ = (imgpel) rshift_rnd_sf(*wBufSrcL++ + *wBufSrcR++, 1);
00626 }
00627
00628 *wBufDst++ = (imgpel) rshift_rnd_sf(*wBufSrcL++ + wBufSrcR[-1], 1);
00629 }
00630
00631