00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "contributors.h"
00018
00019 #include <limits.h>
00020
00021 #include "global.h"
00022 #include "image.h"
00023 #include "img_chroma.h"
00024
00025
00026
00027
00028
00029
00030
00031
00032 static void generateChroma00( ImageParameters *p_Img, int size_x_minus1, int size_y_minus1, imgpel **wImgDst, imgpel **imgUV)
00033 {
00034 int i, j;
00035 int jpad = 0;
00036 imgpel *wBufDst;
00037 imgpel *wBufSrc0;
00038
00039 wBufDst = wImgDst[jpad++];
00040 wBufSrc0 = imgUV[0];
00041
00042 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00043 {
00044 *wBufDst = *wBufSrc0;
00045 ++wBufDst;
00046 }
00047
00048 memcpy(wBufDst, wBufSrc0, size_x_minus1 * sizeof(imgpel));
00049 wBufDst += size_x_minus1;
00050 wBufSrc0 += size_x_minus1;
00051
00052 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00053 {
00054 *wBufDst = *wBufSrc0;
00055 ++wBufDst;
00056 }
00057
00058 for (j = -p_Img->pad_size_uv_y; j < -1; j++, jpad++)
00059 {
00060 memcpy(wImgDst[jpad], wImgDst[jpad - 1], (2 * p_Img->pad_size_uv_x + size_x_minus1) * sizeof(imgpel));
00061 }
00062
00063 for (j = 0; j < size_y_minus1; j++)
00064 {
00065 wBufDst = wImgDst[jpad++];
00066 wBufSrc0 = imgUV[j ];
00067
00068 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00069 {
00070 *wBufDst = *wBufSrc0;
00071 ++wBufDst;
00072 }
00073
00074 memcpy(wBufDst, wBufSrc0, size_x_minus1 * sizeof(imgpel));
00075 wBufDst += size_x_minus1;
00076 wBufSrc0 += size_x_minus1;
00077
00078 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00079 {
00080 *wBufDst = *wBufSrc0;
00081 ++wBufDst;
00082 }
00083 }
00084
00085 wBufDst = wImgDst[jpad++];
00086 wBufSrc0 = imgUV[size_y_minus1];
00087
00088 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00089 {
00090 *wBufDst = *wBufSrc0;
00091 ++wBufDst;
00092 }
00093
00094 memcpy(wBufDst, wBufSrc0, size_x_minus1 * sizeof(imgpel));
00095 wBufDst += size_x_minus1;
00096 wBufSrc0 += size_x_minus1;
00097
00098 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00099 {
00100 *wBufDst = *wBufSrc0;
00101 ++wBufDst;
00102 }
00103
00104 for (j = 1; j < p_Img->pad_size_uv_y; j++, jpad++)
00105 {
00106 memcpy(wImgDst[jpad], wImgDst[jpad - 1], (2 * p_Img->pad_size_uv_x + size_x_minus1) * sizeof(imgpel));
00107 }
00108 }
00109
00110
00111
00112
00113
00114
00115
00116 static void generateChroma01( ImageParameters *p_Img, int size_x_minus1, int size_y_minus1, int weight00, int weight01, imgpel **wImgDst, imgpel **imgUV)
00117 {
00118 int i, j;
00119 int jpad = 0;
00120 int cur_value;
00121 imgpel *wBufDst;
00122 imgpel *wBufSrc0;
00123
00124 wBufDst = wImgDst[jpad++];
00125 wBufSrc0 = imgUV[0];
00126
00127 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00128 {
00129 *(wBufDst++) = *wBufSrc0;
00130 }
00131
00132 for (i = 0; i < size_x_minus1; i++)
00133 {
00134 cur_value = weight00 * (*wBufSrc0++);
00135 cur_value += weight01 * (*wBufSrc0 );
00136 *(wBufDst++) = (imgpel) rshift_rnd_sf(cur_value, 6);
00137 }
00138
00139 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00140 {
00141 *(wBufDst++) = *wBufSrc0;
00142 }
00143
00144 for (j = -p_Img->pad_size_uv_y; j < -1; j++, jpad++)
00145 {
00146 memcpy(wImgDst[jpad], wImgDst[jpad - 1], (2 * p_Img->pad_size_uv_x + size_x_minus1) * sizeof(imgpel));
00147 }
00148
00149 for (j = 0; j < size_y_minus1; j++)
00150 {
00151 wBufDst = wImgDst[jpad++];
00152 wBufSrc0 = imgUV[j ];
00153
00154 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00155 {
00156 *(wBufDst++) = *wBufSrc0;
00157 }
00158
00159 for (i = 0; i < size_x_minus1; i++)
00160 {
00161 cur_value = weight00 * (*wBufSrc0++);
00162 cur_value += weight01 * (*wBufSrc0 );
00163 *(wBufDst++) = (imgpel) rshift_rnd_sf(cur_value, 6);
00164 }
00165
00166 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00167 {
00168 *(wBufDst++) = *wBufSrc0;
00169 }
00170 }
00171
00172 wBufDst = wImgDst[jpad++];
00173 wBufSrc0 = imgUV[size_y_minus1];
00174
00175 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00176 {
00177 *(wBufDst++) = *wBufSrc0;
00178 }
00179
00180 for (i = 0; i < size_x_minus1; i++)
00181 {
00182 cur_value = weight00 * (*wBufSrc0++);
00183 cur_value += weight01 * (*wBufSrc0 );
00184 *(wBufDst++) = (imgpel) rshift_rnd_sf(cur_value, 6);
00185 }
00186
00187 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00188 {
00189 *(wBufDst++) = *wBufSrc0;
00190 }
00191
00192 for (j = 1; j < p_Img->pad_size_uv_y; j++, jpad++)
00193 {
00194 memcpy(wImgDst[jpad], wImgDst[jpad - 1], (2 * p_Img->pad_size_uv_x + size_x_minus1) * sizeof(imgpel));
00195 }
00196 }
00197
00198
00199
00200
00201
00202
00203
00204 static void generateChroma10(ImageParameters *p_Img, int size_x_minus1, int size_y_minus1, int weight00, int weight10, imgpel **wImgDst, imgpel **imgUV)
00205 {
00206 int i, j;
00207 int jpad = 0;
00208 int cur_value;
00209 imgpel *wBufDst;
00210 imgpel *wBufSrc0, *wBufSrc1;
00211
00212 wBufDst = wImgDst[jpad++];
00213 wBufSrc0 = imgUV[0];
00214
00215
00216 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00217 {
00218 *(wBufDst++) = *wBufSrc0;
00219 }
00220
00221 memcpy(wBufDst, wBufSrc0, size_x_minus1 * sizeof(imgpel));
00222 wBufDst += size_x_minus1;
00223 wBufSrc0 += size_x_minus1;
00224
00225 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00226 {
00227 *(wBufDst++) = *wBufSrc0;
00228 }
00229
00230 for (j = -p_Img->pad_size_uv_y; j < -1; j++, jpad++)
00231 {
00232 memcpy(wImgDst[jpad], wImgDst[jpad - 1], (2 * p_Img->pad_size_uv_x + size_x_minus1) * sizeof(imgpel));
00233 }
00234
00235 for (j = 0; j < size_y_minus1; j++)
00236 {
00237 wBufDst = wImgDst[jpad++];
00238 wBufSrc0 = imgUV[j ];
00239 wBufSrc1 = imgUV[j + 1];
00240
00241 cur_value = rshift_rnd_sf(weight00 * (*wBufSrc0) + weight10 * (*wBufSrc1), 6 );
00242 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00243 {
00244 *(wBufDst++) = (imgpel) cur_value;
00245 }
00246
00247 for (i = 0; i < size_x_minus1; i++)
00248 {
00249 cur_value = weight00 * (*wBufSrc0++) + weight10 * (*wBufSrc1++);
00250 *(wBufDst++) = (imgpel) rshift_rnd_sf(cur_value, 6);
00251 }
00252
00253 cur_value = rshift_rnd_sf(weight00 * (*wBufSrc0) + weight10 * (*wBufSrc1), 6 );
00254 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00255 {
00256 *(wBufDst++) = (imgpel) cur_value;
00257 }
00258 }
00259
00260 wBufDst = wImgDst[jpad++];
00261 wBufSrc0 = imgUV[size_y_minus1];
00262
00263 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00264 {
00265 *(wBufDst++) = *wBufSrc0;
00266 }
00267
00268 memcpy(wBufDst, wBufSrc0, size_x_minus1 * sizeof(imgpel));
00269 wBufDst += size_x_minus1;
00270 wBufSrc0 += size_x_minus1;
00271
00272 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00273 {
00274 *(wBufDst++) = *wBufSrc0;
00275 }
00276
00277 for (j = 1; j < p_Img->pad_size_uv_y; j++, jpad++)
00278 {
00279 memcpy(wImgDst[jpad], wImgDst[jpad - 1], (2 * p_Img->pad_size_uv_x + size_x_minus1) * sizeof(imgpel));
00280 }
00281 }
00282
00283
00284
00285
00286
00287
00288
00289 static void generateChromaXX( ImageParameters *p_Img, int size_x_minus1, int size_y_minus1, int weight00, int weight01, int weight10, int weight11, imgpel **wImgDst, imgpel **imgUV)
00290 {
00291 int i, j;
00292 int jpad = 0;
00293 int cur_value;
00294 imgpel *wBufDst;
00295 imgpel *wBufSrc0, *wBufSrc1;
00296 int weight0001 = weight00 + weight01;
00297 int weight1011 = weight10 + weight11;
00298 int weight0010 = weight00 + weight10;
00299 int weight0111 = weight01 + weight11;
00300
00301 wBufDst = wImgDst[jpad++];
00302 wBufSrc0 = imgUV[0];
00303
00304 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00305 {
00306 *(wBufDst++) = *wBufSrc0;
00307 }
00308
00309 for (i = 0; i < size_x_minus1; i++)
00310 {
00311 cur_value = weight0010 * (*wBufSrc0++);
00312 cur_value += weight0111 * (*wBufSrc0 );
00313 *(wBufDst++) = (imgpel) rshift_rnd_sf(cur_value, 6);
00314 }
00315
00316 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00317 {
00318 *(wBufDst++) = *wBufSrc0;
00319 }
00320
00321 for (j = -p_Img->pad_size_uv_y; j < -1; j++, jpad++)
00322 {
00323 memcpy(wImgDst[jpad], wImgDst[jpad - 1], (2 * p_Img->pad_size_uv_x + size_x_minus1) * sizeof(imgpel));
00324 }
00325
00326 for (j = 0; j < size_y_minus1; j++)
00327 {
00328 wBufDst = wImgDst[jpad++];
00329 wBufSrc0 = imgUV[j ];
00330 wBufSrc1 = imgUV[j + 1];
00331
00332 cur_value = rshift_rnd_sf(weight0001 * (*wBufSrc0) + weight1011 * (*wBufSrc1), 6 );
00333 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00334 {
00335 *(wBufDst++) = (imgpel) cur_value;
00336 }
00337
00338 for (i = 0; i < size_x_minus1; i++)
00339 {
00340 cur_value = weight00 * (*wBufSrc0++) + weight10 * (*wBufSrc1++);
00341 cur_value += weight01 * (*wBufSrc0 ) + weight11 * (*wBufSrc1 );
00342 *(wBufDst++) = (imgpel) rshift_rnd_sf(cur_value, 6);
00343 }
00344
00345 cur_value = rshift_rnd_sf(weight0001 * (*wBufSrc0) + weight1011 * (*wBufSrc1), 6 );
00346 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00347 {
00348 *(wBufDst++) = (imgpel) cur_value;
00349 }
00350 }
00351
00352 wBufDst = wImgDst[jpad++];
00353 wBufSrc0 = imgUV[size_y_minus1];
00354
00355 for (i = -p_Img->pad_size_uv_x; i < 0; i++)
00356 {
00357 *(wBufDst++) = *wBufSrc0;
00358 }
00359
00360 for (i = 0; i < size_x_minus1; i++)
00361 {
00362 cur_value = weight0010 * (*wBufSrc0++);
00363 cur_value += weight0111 * (*wBufSrc0 );
00364 *(wBufDst++) = (imgpel) rshift_rnd_sf(cur_value, 6);
00365 }
00366
00367 for (i = 0; i < p_Img->pad_size_uv_x; i++)
00368 {
00369 *(wBufDst++) = *wBufSrc0;
00370 }
00371
00372 for (j = 1; j < p_Img->pad_size_uv_y; j++, jpad++)
00373 {
00374 memcpy(wImgDst[jpad], wImgDst[jpad - 1], (2 * p_Img->pad_size_uv_x + size_x_minus1) * sizeof(imgpel));
00375 }
00376 }
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387 void getSubImagesChroma( ImageParameters *p_Img, InputParameters *p_Inp, StorablePicture *s )
00388 {
00389 int uv, k, l, m;
00390 int weight00, weight01, weight10, weight11;
00391 int subimages_y, subimages_x, subx, suby;
00392 int size_x_minus1, size_y_minus1;
00393 imgpel ****curr_img_sub;
00394 imgpel **curr_img;
00395
00396
00397 int mul_x, mul_y;
00398 int mm, kk;
00399
00400 size_x_minus1 = s->size_x_cr - 1;
00401 size_y_minus1 = s->size_y_cr - 1;
00402
00403 if ( p_Img->yuv_format == YUV420 )
00404 {
00405 subimages_x = 8;
00406 subimages_y = 8;
00407 mul_x = mul_y = 1;
00408 }
00409 else if ( p_Img->yuv_format == YUV422 )
00410 {
00411 subimages_x = 8;
00412 subimages_y = 4;
00413 mul_y = 2;
00414 mul_x = 1;
00415 }
00416 else
00417 {
00418 subimages_x = 4;
00419 subimages_y = 4;
00420 mul_x = mul_y = 2;
00421 }
00422
00423
00424 for ( uv = 0; uv < 2; uv++ )
00425 {
00426 curr_img = s->imgUV[uv];
00427 curr_img_sub = s->p_img_sub[uv + 1];
00428
00429 for ( suby = 0, k = 0; suby < subimages_y; suby++, k += mul_y )
00430 {
00431 m = (8 - k);
00432 mm = m << 3;
00433 kk = k << 3;
00434 for ( subx = 0, l = 0; subx < subimages_x; subx++, l += mul_x )
00435 {
00436 weight01 = m * l;
00437 weight00 = mm - weight01;
00438 weight11 = k * l;
00439 weight10 = kk - weight11;
00440
00441
00442 if (weight01 == 0 && weight10 == 0 && weight11 == 0)
00443 {
00444 generateChroma00( p_Img, size_x_minus1, size_y_minus1, curr_img_sub[suby][subx], curr_img);
00445 }
00446 else if (weight10 == 0 && weight11 == 0)
00447 {
00448 generateChroma01( p_Img, size_x_minus1, size_y_minus1, weight00, weight01, curr_img_sub[suby][subx], curr_img);
00449 }
00450 else if (weight01 == 0 && weight11 == 0)
00451 {
00452 generateChroma10( p_Img, size_x_minus1, size_y_minus1, weight00, weight10, curr_img_sub[suby][subx], curr_img);
00453 }
00454 else
00455 {
00456 generateChromaXX( p_Img, size_x_minus1, size_y_minus1, weight00, weight01, weight10, weight11, curr_img_sub[suby][subx], curr_img);
00457 }
00458 }
00459 }
00460 }
00461 }
00462