00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <inttypes.h>
00030 #include <assert.h>
00031
00032 #include "config.h"
00033 #include "rgb2rgb.h"
00034 #include "swscale.h"
00035 #include "swscale_internal.h"
00036
00037 #define DITHER1XBPP // only for MMX
00038
00039 extern const uint8_t dither_8x8_32[8][8];
00040 extern const uint8_t dither_8x8_73[8][8];
00041 extern const uint8_t dither_8x8_220[8][8];
00042
00043 #if HAVE_MMX && CONFIG_GPL
00044
00045
00046 DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL;
00047 DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL;
00048 DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL;
00049
00050
00051 #undef RENAME
00052 #undef HAVE_MMX2
00053 #undef HAVE_AMD3DNOW
00054 #define HAVE_MMX2 0
00055 #define HAVE_AMD3DNOW 0
00056 #define RENAME(a) a ## _MMX
00057 #include "yuv2rgb_template.c"
00058
00059
00060 #undef RENAME
00061 #undef HAVE_MMX2
00062 #define HAVE_MMX2 1
00063 #define RENAME(a) a ## _MMX2
00064 #include "yuv2rgb_template.c"
00065
00066 #endif
00067
00068 const int32_t ff_yuv2rgb_coeffs[8][4] = {
00069 {117504, 138453, 13954, 34903},
00070 {117504, 138453, 13954, 34903},
00071 {104597, 132201, 25675, 53279},
00072 {104597, 132201, 25675, 53279},
00073 {104448, 132798, 24759, 53109},
00074 {104597, 132201, 25675, 53279},
00075 {104597, 132201, 25675, 53279},
00076 {117579, 136230, 16907, 35559}
00077 };
00078
00079 #define LOADCHROMA(i) \
00080 U = pu[i]; \
00081 V = pv[i]; \
00082 r = (void *)c->table_rV[V]; \
00083 g = (void *)(c->table_gU[U] + c->table_gV[V]); \
00084 b = (void *)c->table_bU[U];
00085
00086 #define PUTRGB(dst,src,i,o) \
00087 Y = src[2*i+o]; \
00088 dst[2*i ] = r[Y] + g[Y] + b[Y]; \
00089 Y = src[2*i+1-o]; \
00090 dst[2*i+1] = r[Y] + g[Y] + b[Y];
00091
00092 #define PUTRGB24(dst,src,i) \
00093 Y = src[2*i]; \
00094 dst[6*i+0] = r[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = b[Y]; \
00095 Y = src[2*i+1]; \
00096 dst[6*i+3] = r[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = b[Y];
00097
00098 #define PUTBGR24(dst,src,i) \
00099 Y = src[2*i]; \
00100 dst[6*i+0] = b[Y]; dst[6*i+1] = g[Y]; dst[6*i+2] = r[Y]; \
00101 Y = src[2*i+1]; \
00102 dst[6*i+3] = b[Y]; dst[6*i+4] = g[Y]; dst[6*i+5] = r[Y];
00103
00104 #define YUV2RGBFUNC(func_name, dst_type) \
00105 static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \
00106 int srcSliceH, uint8_t* dst[], int dstStride[]){\
00107 int y;\
00108 \
00109 if (c->srcFormat == PIX_FMT_YUV422P) {\
00110 srcStride[1] *= 2;\
00111 srcStride[2] *= 2;\
00112 }\
00113 for (y=0; y<srcSliceH; y+=2) {\
00114 dst_type *dst_1 = (dst_type*)(dst[0] + (y+srcSliceY )*dstStride[0]);\
00115 dst_type *dst_2 = (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
00116 dst_type av_unused *r, *b;\
00117 dst_type *g;\
00118 uint8_t *py_1 = src[0] + y*srcStride[0];\
00119 uint8_t *py_2 = py_1 + srcStride[0];\
00120 uint8_t *pu = src[1] + (y>>1)*srcStride[1];\
00121 uint8_t *pv = src[2] + (y>>1)*srcStride[2];\
00122 unsigned int h_size = c->dstW>>3;\
00123 while (h_size--) {\
00124 int av_unused U, V;\
00125 int Y;\
00126
00127 #define ENDYUV2RGBLINE(dst_delta)\
00128 pu += 4;\
00129 pv += 4;\
00130 py_1 += 8;\
00131 py_2 += 8;\
00132 dst_1 += dst_delta;\
00133 dst_2 += dst_delta;\
00134 }\
00135 if (c->dstW & 4) {\
00136 int av_unused Y, U, V;\
00137
00138 #define ENDYUV2RGBFUNC()\
00139 }\
00140 }\
00141 return srcSliceH;\
00142 }
00143
00144 #define CLOSEYUV2RGBFUNC(dst_delta)\
00145 ENDYUV2RGBLINE(dst_delta)\
00146 ENDYUV2RGBFUNC()
00147
00148 YUV2RGBFUNC(yuv2rgb_c_32, uint32_t)
00149 LOADCHROMA(0);
00150 PUTRGB(dst_1,py_1,0,0);
00151 PUTRGB(dst_2,py_2,0,1);
00152
00153 LOADCHROMA(1);
00154 PUTRGB(dst_2,py_2,1,1);
00155 PUTRGB(dst_1,py_1,1,0);
00156 LOADCHROMA(1);
00157 PUTRGB(dst_2,py_2,1,1);
00158 PUTRGB(dst_1,py_1,1,0);
00159
00160 LOADCHROMA(2);
00161 PUTRGB(dst_1,py_1,2,0);
00162 PUTRGB(dst_2,py_2,2,1);
00163
00164 LOADCHROMA(3);
00165 PUTRGB(dst_2,py_2,3,1);
00166 PUTRGB(dst_1,py_1,3,0);
00167 ENDYUV2RGBLINE(8)
00168 LOADCHROMA(0);
00169 PUTRGB(dst_1,py_1,0,0);
00170 PUTRGB(dst_2,py_2,0,1);
00171
00172 LOADCHROMA(1);
00173 PUTRGB(dst_2,py_2,1,1);
00174 PUTRGB(dst_1,py_1,1,0);
00175 ENDYUV2RGBFUNC()
00176
00177 YUV2RGBFUNC(yuv2rgb_c_24_rgb, uint8_t)
00178 LOADCHROMA(0);
00179 PUTRGB24(dst_1,py_1,0);
00180 PUTRGB24(dst_2,py_2,0);
00181
00182 LOADCHROMA(1);
00183 PUTRGB24(dst_2,py_2,1);
00184 PUTRGB24(dst_1,py_1,1);
00185
00186 LOADCHROMA(2);
00187 PUTRGB24(dst_1,py_1,2);
00188 PUTRGB24(dst_2,py_2,2);
00189
00190 LOADCHROMA(3);
00191 PUTRGB24(dst_2,py_2,3);
00192 PUTRGB24(dst_1,py_1,3);
00193 ENDYUV2RGBLINE(24)
00194 LOADCHROMA(0);
00195 PUTRGB24(dst_1,py_1,0);
00196 PUTRGB24(dst_2,py_2,0);
00197
00198 LOADCHROMA(1);
00199 PUTRGB24(dst_2,py_2,1);
00200 PUTRGB24(dst_1,py_1,1);
00201 ENDYUV2RGBFUNC()
00202
00203
00204 YUV2RGBFUNC(yuv2rgb_c_24_bgr, uint8_t)
00205 LOADCHROMA(0);
00206 PUTBGR24(dst_1,py_1,0);
00207 PUTBGR24(dst_2,py_2,0);
00208
00209 LOADCHROMA(1);
00210 PUTBGR24(dst_2,py_2,1);
00211 PUTBGR24(dst_1,py_1,1);
00212
00213 LOADCHROMA(2);
00214 PUTBGR24(dst_1,py_1,2);
00215 PUTBGR24(dst_2,py_2,2);
00216
00217 LOADCHROMA(3);
00218 PUTBGR24(dst_2,py_2,3);
00219 PUTBGR24(dst_1,py_1,3);
00220 ENDYUV2RGBLINE(24)
00221 LOADCHROMA(0);
00222 PUTBGR24(dst_1,py_1,0);
00223 PUTBGR24(dst_2,py_2,0);
00224
00225 LOADCHROMA(1);
00226 PUTBGR24(dst_2,py_2,1);
00227 PUTBGR24(dst_1,py_1,1);
00228 ENDYUV2RGBFUNC()
00229
00230
00231
00232 YUV2RGBFUNC(yuv2rgb_c_16, uint16_t)
00233 LOADCHROMA(0);
00234 PUTRGB(dst_1,py_1,0,0);
00235 PUTRGB(dst_2,py_2,0,1);
00236
00237 LOADCHROMA(1);
00238 PUTRGB(dst_2,py_2,1,1);
00239 PUTRGB(dst_1,py_1,1,0);
00240
00241 LOADCHROMA(2);
00242 PUTRGB(dst_1,py_1,2,0);
00243 PUTRGB(dst_2,py_2,2,1);
00244
00245 LOADCHROMA(3);
00246 PUTRGB(dst_2,py_2,3,1);
00247 PUTRGB(dst_1,py_1,3,0);
00248 CLOSEYUV2RGBFUNC(8)
00249
00250
00251
00252 YUV2RGBFUNC(yuv2rgb_c_8, uint8_t)
00253 LOADCHROMA(0);
00254 PUTRGB(dst_1,py_1,0,0);
00255 PUTRGB(dst_2,py_2,0,1);
00256
00257 LOADCHROMA(1);
00258 PUTRGB(dst_2,py_2,1,1);
00259 PUTRGB(dst_1,py_1,1,0);
00260
00261 LOADCHROMA(2);
00262 PUTRGB(dst_1,py_1,2,0);
00263 PUTRGB(dst_2,py_2,2,1);
00264
00265 LOADCHROMA(3);
00266 PUTRGB(dst_2,py_2,3,1);
00267 PUTRGB(dst_1,py_1,3,0);
00268 CLOSEYUV2RGBFUNC(8)
00269
00270
00271 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t)
00272 const uint8_t *d32 = dither_8x8_32[y&7];
00273 const uint8_t *d64 = dither_8x8_73[y&7];
00274 #define PUTRGB8(dst,src,i,o) \
00275 Y = src[2*i]; \
00276 dst[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \
00277 Y = src[2*i+1]; \
00278 dst[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]];
00279
00280 LOADCHROMA(0);
00281 PUTRGB8(dst_1,py_1,0,0);
00282 PUTRGB8(dst_2,py_2,0,0+8);
00283
00284 LOADCHROMA(1);
00285 PUTRGB8(dst_2,py_2,1,2+8);
00286 PUTRGB8(dst_1,py_1,1,2);
00287
00288 LOADCHROMA(2);
00289 PUTRGB8(dst_1,py_1,2,4);
00290 PUTRGB8(dst_2,py_2,2,4+8);
00291
00292 LOADCHROMA(3);
00293 PUTRGB8(dst_2,py_2,3,6+8);
00294 PUTRGB8(dst_1,py_1,3,6);
00295 CLOSEYUV2RGBFUNC(8)
00296
00297
00298
00299
00300 YUV2RGBFUNC(yuv2rgb_c_4, uint8_t)
00301 int acc;
00302 #define PUTRGB4(dst,src,i) \
00303 Y = src[2*i]; \
00304 acc = r[Y] + g[Y] + b[Y]; \
00305 Y = src[2*i+1]; \
00306 acc |= (r[Y] + g[Y] + b[Y])<<4; \
00307 dst[i] = acc;
00308
00309 LOADCHROMA(0);
00310 PUTRGB4(dst_1,py_1,0);
00311 PUTRGB4(dst_2,py_2,0);
00312
00313 LOADCHROMA(1);
00314 PUTRGB4(dst_2,py_2,1);
00315 PUTRGB4(dst_1,py_1,1);
00316
00317 LOADCHROMA(2);
00318 PUTRGB4(dst_1,py_1,2);
00319 PUTRGB4(dst_2,py_2,2);
00320
00321 LOADCHROMA(3);
00322 PUTRGB4(dst_2,py_2,3);
00323 PUTRGB4(dst_1,py_1,3);
00324 CLOSEYUV2RGBFUNC(4)
00325
00326 YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t)
00327 const uint8_t *d64 = dither_8x8_73[y&7];
00328 const uint8_t *d128 = dither_8x8_220[y&7];
00329 int acc;
00330
00331 #define PUTRGB4D(dst,src,i,o) \
00332 Y = src[2*i]; \
00333 acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
00334 Y = src[2*i+1]; \
00335 acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4; \
00336 dst[i]= acc;
00337
00338 LOADCHROMA(0);
00339 PUTRGB4D(dst_1,py_1,0,0);
00340 PUTRGB4D(dst_2,py_2,0,0+8);
00341
00342 LOADCHROMA(1);
00343 PUTRGB4D(dst_2,py_2,1,2+8);
00344 PUTRGB4D(dst_1,py_1,1,2);
00345
00346 LOADCHROMA(2);
00347 PUTRGB4D(dst_1,py_1,2,4);
00348 PUTRGB4D(dst_2,py_2,2,4+8);
00349
00350 LOADCHROMA(3);
00351 PUTRGB4D(dst_2,py_2,3,6+8);
00352 PUTRGB4D(dst_1,py_1,3,6);
00353 CLOSEYUV2RGBFUNC(4)
00354
00355
00356
00357 YUV2RGBFUNC(yuv2rgb_c_4b, uint8_t)
00358 LOADCHROMA(0);
00359 PUTRGB(dst_1,py_1,0,0);
00360 PUTRGB(dst_2,py_2,0,1);
00361
00362 LOADCHROMA(1);
00363 PUTRGB(dst_2,py_2,1,1);
00364 PUTRGB(dst_1,py_1,1,0);
00365
00366 LOADCHROMA(2);
00367 PUTRGB(dst_1,py_1,2,0);
00368 PUTRGB(dst_2,py_2,2,1);
00369
00370 LOADCHROMA(3);
00371 PUTRGB(dst_2,py_2,3,1);
00372 PUTRGB(dst_1,py_1,3,0);
00373 CLOSEYUV2RGBFUNC(8)
00374
00375 YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t)
00376 const uint8_t *d64 = dither_8x8_73[y&7];
00377 const uint8_t *d128 = dither_8x8_220[y&7];
00378
00379 #define PUTRGB4DB(dst,src,i,o) \
00380 Y = src[2*i]; \
00381 dst[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
00382 Y = src[2*i+1]; \
00383 dst[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
00384
00385 LOADCHROMA(0);
00386 PUTRGB4DB(dst_1,py_1,0,0);
00387 PUTRGB4DB(dst_2,py_2,0,0+8);
00388
00389 LOADCHROMA(1);
00390 PUTRGB4DB(dst_2,py_2,1,2+8);
00391 PUTRGB4DB(dst_1,py_1,1,2);
00392
00393 LOADCHROMA(2);
00394 PUTRGB4DB(dst_1,py_1,2,4);
00395 PUTRGB4DB(dst_2,py_2,2,4+8);
00396
00397 LOADCHROMA(3);
00398 PUTRGB4DB(dst_2,py_2,3,6+8);
00399 PUTRGB4DB(dst_1,py_1,3,6);
00400 CLOSEYUV2RGBFUNC(8)
00401
00402 YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t)
00403 const uint8_t *d128 = dither_8x8_220[y&7];
00404 char out_1 = 0, out_2 = 0;
00405 g= c->table_gU[128] + c->table_gV[128];
00406
00407 #define PUTRGB1(out,src,i,o) \
00408 Y = src[2*i]; \
00409 out+= out + g[Y+d128[0+o]]; \
00410 Y = src[2*i+1]; \
00411 out+= out + g[Y+d128[1+o]];
00412
00413 PUTRGB1(out_1,py_1,0,0);
00414 PUTRGB1(out_2,py_2,0,0+8);
00415
00416 PUTRGB1(out_2,py_2,1,2+8);
00417 PUTRGB1(out_1,py_1,1,2);
00418
00419 PUTRGB1(out_1,py_1,2,4);
00420 PUTRGB1(out_2,py_2,2,4+8);
00421
00422 PUTRGB1(out_2,py_2,3,6+8);
00423 PUTRGB1(out_1,py_1,3,6);
00424
00425 dst_1[0]= out_1;
00426 dst_2[0]= out_2;
00427 CLOSEYUV2RGBFUNC(1)
00428
00429 SwsFunc sws_yuv2rgb_get_func_ptr(SwsContext *c)
00430 {
00431 SwsFunc t = NULL;
00432 #if (HAVE_MMX2 || HAVE_MMX) && CONFIG_GPL
00433 if (c->flags & SWS_CPU_CAPS_MMX2) {
00434 switch (c->dstFormat) {
00435 case PIX_FMT_RGB32: return yuv420_rgb32_MMX2;
00436 case PIX_FMT_BGR24: return yuv420_rgb24_MMX2;
00437 case PIX_FMT_RGB565: return yuv420_rgb16_MMX2;
00438 case PIX_FMT_RGB555: return yuv420_rgb15_MMX2;
00439 }
00440 }
00441 if (c->flags & SWS_CPU_CAPS_MMX) {
00442 switch (c->dstFormat) {
00443 case PIX_FMT_RGB32: return yuv420_rgb32_MMX;
00444 case PIX_FMT_BGR24: return yuv420_rgb24_MMX;
00445 case PIX_FMT_RGB565: return yuv420_rgb16_MMX;
00446 case PIX_FMT_RGB555: return yuv420_rgb15_MMX;
00447 }
00448 }
00449 #endif
00450 #if HAVE_VIS
00451 t = sws_yuv2rgb_init_vis(c);
00452 #endif
00453 #if CONFIG_MLIB
00454 t = sws_yuv2rgb_init_mlib(c);
00455 #endif
00456 #if HAVE_ALTIVEC
00457 if (c->flags & SWS_CPU_CAPS_ALTIVEC)
00458 t = sws_yuv2rgb_init_altivec(c);
00459 #endif
00460
00461 #if ARCH_BFIN
00462 if (c->flags & SWS_CPU_CAPS_BFIN)
00463 t = sws_ff_bfin_yuv2rgb_get_func_ptr(c);
00464 #endif
00465
00466 if (t)
00467 return t;
00468
00469 av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found.\n");
00470
00471 switch (c->dstFormat) {
00472 case PIX_FMT_BGR32_1:
00473 case PIX_FMT_RGB32_1:
00474 case PIX_FMT_BGR32:
00475 case PIX_FMT_RGB32: return yuv2rgb_c_32;
00476 case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb;
00477 case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr;
00478 case PIX_FMT_RGB565:
00479 case PIX_FMT_BGR565:
00480 case PIX_FMT_RGB555:
00481 case PIX_FMT_BGR555: return yuv2rgb_c_16;
00482 case PIX_FMT_RGB8:
00483 case PIX_FMT_BGR8: return yuv2rgb_c_8_ordered_dither;
00484 case PIX_FMT_RGB4:
00485 case PIX_FMT_BGR4: return yuv2rgb_c_4_ordered_dither;
00486 case PIX_FMT_RGB4_BYTE:
00487 case PIX_FMT_BGR4_BYTE: return yuv2rgb_c_4b_ordered_dither;
00488 case PIX_FMT_MONOBLACK: return yuv2rgb_c_1_ordered_dither;
00489 default:
00490 assert(0);
00491 }
00492 return NULL;
00493 }
00494
00495 static void fill_table(uint8_t* table[256], const int elemsize, const int inc, uint8_t *y_table)
00496 {
00497 int i;
00498 int64_t cb = 0;
00499
00500 y_table -= elemsize * (inc >> 9);
00501
00502 for (i = 0; i < 256; i++) {
00503 table[i] = y_table + elemsize * (cb >> 16);
00504 cb += inc;
00505 }
00506 }
00507
00508 static void fill_gv_table(int table[256], const int elemsize, const int inc)
00509 {
00510 int i;
00511 int64_t cb = 0;
00512 int off = -(inc >> 9);
00513
00514 for (i = 0; i < 256; i++) {
00515 table[i] = elemsize * (off + (cb >> 16));
00516 cb += inc;
00517 }
00518 }
00519
00520 av_cold int sws_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange,
00521 int brightness, int contrast, int saturation)
00522 {
00523 const int isRgb = c->dstFormat==PIX_FMT_RGB32
00524 || c->dstFormat==PIX_FMT_RGB32_1
00525 || c->dstFormat==PIX_FMT_BGR24
00526 || c->dstFormat==PIX_FMT_RGB565
00527 || c->dstFormat==PIX_FMT_RGB555
00528 || c->dstFormat==PIX_FMT_RGB8
00529 || c->dstFormat==PIX_FMT_RGB4
00530 || c->dstFormat==PIX_FMT_RGB4_BYTE
00531 || c->dstFormat==PIX_FMT_MONOBLACK;
00532 const int bpp = fmt_depth(c->dstFormat);
00533 uint8_t *y_table;
00534 uint16_t *y_table16;
00535 uint32_t *y_table32;
00536 int i, base, rbase, gbase, bbase, abase;
00537 const int yoffs = fullRange ? 384 : 326;
00538
00539 int64_t crv = inv_table[0];
00540 int64_t cbu = inv_table[1];
00541 int64_t cgu = -inv_table[2];
00542 int64_t cgv = -inv_table[3];
00543 int64_t cy = 1<<16;
00544 int64_t oy = 0;
00545
00546 int64_t yb = 0;
00547
00548 if (!fullRange) {
00549 cy = (cy*255) / 219;
00550 oy = 16<<16;
00551 } else {
00552 crv = (crv*224) / 255;
00553 cbu = (cbu*224) / 255;
00554 cgu = (cgu*224) / 255;
00555 cgv = (cgv*224) / 255;
00556 }
00557
00558 cy = (cy *contrast ) >> 16;
00559 crv = (crv*contrast * saturation) >> 32;
00560 cbu = (cbu*contrast * saturation) >> 32;
00561 cgu = (cgu*contrast * saturation) >> 32;
00562 cgv = (cgv*contrast * saturation) >> 32;
00563 oy -= 256*brightness;
00564
00565
00566 crv = ((crv << 16) + 0x8000) / cy;
00567 cbu = ((cbu << 16) + 0x8000) / cy;
00568 cgu = ((cgu << 16) + 0x8000) / cy;
00569 cgv = ((cgv << 16) + 0x8000) / cy;
00570
00571 av_free(c->yuvTable);
00572
00573 switch (bpp) {
00574 case 1:
00575 c->yuvTable = av_malloc(1024);
00576 y_table = c->yuvTable;
00577 yb = -(384<<16) - oy;
00578 for (i = 0; i < 1024-110; i++) {
00579 y_table[i+110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;
00580 yb += cy;
00581 }
00582 fill_table(c->table_gU, 1, cgu, y_table + yoffs);
00583 fill_gv_table(c->table_gV, 1, cgv);
00584 break;
00585 case 4:
00586 case 4|128:
00587 rbase = isRgb ? 3 : 0;
00588 gbase = 1;
00589 bbase = isRgb ? 0 : 3;
00590 c->yuvTable = av_malloc(1024*3);
00591 y_table = c->yuvTable;
00592 yb = -(384<<16) - oy;
00593 for (i = 0; i < 1024-110; i++) {
00594 int yval = av_clip_uint8((yb + 0x8000) >> 16);
00595 y_table[i+110 ] = (yval >> 7) << rbase;
00596 y_table[i+ 37+1024] = ((yval + 43) / 85) << gbase;
00597 y_table[i+110+2048] = (yval >> 7) << bbase;
00598 yb += cy;
00599 }
00600 fill_table(c->table_rV, 1, crv, y_table + yoffs);
00601 fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024);
00602 fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048);
00603 fill_gv_table(c->table_gV, 1, cgv);
00604 break;
00605 case 8:
00606 rbase = isRgb ? 5 : 0;
00607 gbase = isRgb ? 2 : 3;
00608 bbase = isRgb ? 0 : 6;
00609 c->yuvTable = av_malloc(1024*3);
00610 y_table = c->yuvTable;
00611 yb = -(384<<16) - oy;
00612 for (i = 0; i < 1024-38; i++) {
00613 int yval = av_clip_uint8((yb + 0x8000) >> 16);
00614 y_table[i+16 ] = ((yval + 18) / 36) << rbase;
00615 y_table[i+16+1024] = ((yval + 18) / 36) << gbase;
00616 y_table[i+37+2048] = ((yval + 43) / 85) << bbase;
00617 yb += cy;
00618 }
00619 fill_table(c->table_rV, 1, crv, y_table + yoffs);
00620 fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024);
00621 fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048);
00622 fill_gv_table(c->table_gV, 1, cgv);
00623 break;
00624 case 15:
00625 case 16:
00626 rbase = isRgb ? bpp - 5 : 0;
00627 gbase = 5;
00628 bbase = isRgb ? 0 : (bpp - 5);
00629 c->yuvTable = av_malloc(1024*3*2);
00630 y_table16 = c->yuvTable;
00631 yb = -(384<<16) - oy;
00632 for (i = 0; i < 1024; i++) {
00633 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
00634 y_table16[i ] = (yval >> 3) << rbase;
00635 y_table16[i+1024] = (yval >> (18 - bpp)) << gbase;
00636 y_table16[i+2048] = (yval >> 3) << bbase;
00637 yb += cy;
00638 }
00639 fill_table(c->table_rV, 2, crv, y_table16 + yoffs);
00640 fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024);
00641 fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048);
00642 fill_gv_table(c->table_gV, 2, cgv);
00643 break;
00644 case 24:
00645 c->yuvTable = av_malloc(1024);
00646 y_table = c->yuvTable;
00647 yb = -(384<<16) - oy;
00648 for (i = 0; i < 1024; i++) {
00649 y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);
00650 yb += cy;
00651 }
00652 fill_table(c->table_rV, 1, crv, y_table + yoffs);
00653 fill_table(c->table_gU, 1, cgu, y_table + yoffs);
00654 fill_table(c->table_bU, 1, cbu, y_table + yoffs);
00655 fill_gv_table(c->table_gV, 1, cgv);
00656 break;
00657 case 32:
00658 base = (c->dstFormat == PIX_FMT_RGB32_1 || c->dstFormat == PIX_FMT_BGR32_1) ? 8 : 0;
00659 rbase = base + (isRgb ? 16 : 0);
00660 gbase = base + 8;
00661 bbase = base + (isRgb ? 0 : 16);
00662 abase = (base + 24) & 31;
00663 c->yuvTable = av_malloc(1024*3*4);
00664 y_table32 = c->yuvTable;
00665 yb = -(384<<16) - oy;
00666 for (i = 0; i < 1024; i++) {
00667 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);
00668 y_table32[i ] = (yval << rbase) + (255 << abase);
00669 y_table32[i+1024] = yval << gbase;
00670 y_table32[i+2048] = yval << bbase;
00671 yb += cy;
00672 }
00673 fill_table(c->table_rV, 4, crv, y_table32 + yoffs);
00674 fill_table(c->table_gU, 4, cgu, y_table32 + yoffs + 1024);
00675 fill_table(c->table_bU, 4, cbu, y_table32 + yoffs + 2048);
00676 fill_gv_table(c->table_gV, 4, cgv);
00677 break;
00678 default:
00679 c->yuvTable = NULL;
00680 av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
00681 return -1;
00682 }
00683 return 0;
00684 }