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
00028
00029
00030
00031
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <inttypes.h>
00035 #include <assert.h>
00036
00037 #include "config.h"
00038 #include "rgb2rgb.h"
00039 #include "swscale.h"
00040 #include "swscale_internal.h"
00041
00042 #ifdef HAVE_VIS
00043 #include "yuv2rgb_vis.c"
00044 #endif
00045
00046 #ifdef HAVE_MLIB
00047 #include "yuv2rgb_mlib.c"
00048 #endif
00049
00050 #define DITHER1XBPP // only for mmx
00051
00052 const uint8_t __attribute__((aligned(8))) dither_2x2_4[2][8]={
00053 { 1, 3, 1, 3, 1, 3, 1, 3, },
00054 { 2, 0, 2, 0, 2, 0, 2, 0, },
00055 };
00056
00057 const uint8_t __attribute__((aligned(8))) dither_2x2_8[2][8]={
00058 { 6, 2, 6, 2, 6, 2, 6, 2, },
00059 { 0, 4, 0, 4, 0, 4, 0, 4, },
00060 };
00061
00062 const uint8_t __attribute__((aligned(8))) dither_8x8_32[8][8]={
00063 { 17, 9, 23, 15, 16, 8, 22, 14, },
00064 { 5, 29, 3, 27, 4, 28, 2, 26, },
00065 { 21, 13, 19, 11, 20, 12, 18, 10, },
00066 { 0, 24, 6, 30, 1, 25, 7, 31, },
00067 { 16, 8, 22, 14, 17, 9, 23, 15, },
00068 { 4, 28, 2, 26, 5, 29, 3, 27, },
00069 { 20, 12, 18, 10, 21, 13, 19, 11, },
00070 { 1, 25, 7, 31, 0, 24, 6, 30, },
00071 };
00072
00073 #if 0
00074 const uint8_t __attribute__((aligned(8))) dither_8x8_64[8][8]={
00075 { 0, 48, 12, 60, 3, 51, 15, 63, },
00076 { 32, 16, 44, 28, 35, 19, 47, 31, },
00077 { 8, 56, 4, 52, 11, 59, 7, 55, },
00078 { 40, 24, 36, 20, 43, 27, 39, 23, },
00079 { 2, 50, 14, 62, 1, 49, 13, 61, },
00080 { 34, 18, 46, 30, 33, 17, 45, 29, },
00081 { 10, 58, 6, 54, 9, 57, 5, 53, },
00082 { 42, 26, 38, 22, 41, 25, 37, 21, },
00083 };
00084 #endif
00085
00086 const uint8_t __attribute__((aligned(8))) dither_8x8_73[8][8]={
00087 { 0, 55, 14, 68, 3, 58, 17, 72, },
00088 { 37, 18, 50, 32, 40, 22, 54, 35, },
00089 { 9, 64, 5, 59, 13, 67, 8, 63, },
00090 { 46, 27, 41, 23, 49, 31, 44, 26, },
00091 { 2, 57, 16, 71, 1, 56, 15, 70, },
00092 { 39, 21, 52, 34, 38, 19, 51, 33, },
00093 { 11, 66, 7, 62, 10, 65, 6, 60, },
00094 { 48, 30, 43, 25, 47, 29, 42, 24, },
00095 };
00096
00097 #if 0
00098 const uint8_t __attribute__((aligned(8))) dither_8x8_128[8][8]={
00099 { 68, 36, 92, 60, 66, 34, 90, 58, },
00100 { 20, 116, 12, 108, 18, 114, 10, 106, },
00101 { 84, 52, 76, 44, 82, 50, 74, 42, },
00102 { 0, 96, 24, 120, 6, 102, 30, 126, },
00103 { 64, 32, 88, 56, 70, 38, 94, 62, },
00104 { 16, 112, 8, 104, 22, 118, 14, 110, },
00105 { 80, 48, 72, 40, 86, 54, 78, 46, },
00106 { 4, 100, 28, 124, 2, 98, 26, 122, },
00107 };
00108 #endif
00109
00110 #if 1
00111 const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={
00112 {117, 62, 158, 103, 113, 58, 155, 100, },
00113 { 34, 199, 21, 186, 31, 196, 17, 182, },
00114 {144, 89, 131, 76, 141, 86, 127, 72, },
00115 { 0, 165, 41, 206, 10, 175, 52, 217, },
00116 {110, 55, 151, 96, 120, 65, 162, 107, },
00117 { 28, 193, 14, 179, 38, 203, 24, 189, },
00118 {138, 83, 124, 69, 148, 93, 134, 79, },
00119 { 7, 172, 48, 213, 3, 168, 45, 210, },
00120 };
00121 #elif 1
00122
00123 const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={
00124 { 0, 143, 18, 200, 2, 156, 25, 215, },
00125 { 78, 28, 125, 64, 89, 36, 138, 74, },
00126 { 10, 180, 3, 161, 16, 195, 8, 175, },
00127 {109, 51, 93, 38, 121, 60, 105, 47, },
00128 { 1, 152, 23, 210, 0, 147, 20, 205, },
00129 { 85, 33, 134, 71, 81, 30, 130, 67, },
00130 { 14, 190, 6, 171, 12, 185, 5, 166, },
00131 {117, 57, 101, 44, 113, 54, 97, 41, },
00132 };
00133 #elif 1
00134
00135 const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={
00136 { 0, 124, 8, 193, 0, 140, 12, 213, },
00137 { 55, 14, 104, 42, 66, 19, 119, 52, },
00138 { 3, 168, 1, 145, 6, 187, 3, 162, },
00139 { 86, 31, 70, 21, 99, 39, 82, 28, },
00140 { 0, 134, 11, 206, 0, 129, 9, 200, },
00141 { 62, 17, 114, 48, 58, 16, 109, 45, },
00142 { 5, 181, 2, 157, 4, 175, 1, 151, },
00143 { 95, 36, 78, 26, 90, 34, 74, 24, },
00144 };
00145 #else
00146
00147 const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={
00148 { 0, 107, 3, 187, 0, 125, 6, 212, },
00149 { 39, 7, 86, 28, 49, 11, 102, 36, },
00150 { 1, 158, 0, 131, 3, 180, 1, 151, },
00151 { 68, 19, 52, 12, 81, 25, 64, 17, },
00152 { 0, 119, 5, 203, 0, 113, 4, 195, },
00153 { 45, 9, 96, 33, 42, 8, 91, 30, },
00154 { 2, 172, 1, 144, 2, 165, 0, 137, },
00155 { 77, 23, 60, 15, 72, 21, 56, 14, },
00156 };
00157 #endif
00158
00159 #ifdef HAVE_MMX
00160
00161
00162 static uint64_t attribute_used __attribute__((aligned(8))) mmx_00ffw = 0x00ff00ff00ff00ffULL;
00163 static uint64_t attribute_used __attribute__((aligned(8))) mmx_redmask = 0xf8f8f8f8f8f8f8f8ULL;
00164 static uint64_t attribute_used __attribute__((aligned(8))) mmx_grnmask = 0xfcfcfcfcfcfcfcfcULL;
00165
00166 static uint64_t attribute_used __attribute__((aligned(8))) M24A= 0x00FF0000FF0000FFULL;
00167 static uint64_t attribute_used __attribute__((aligned(8))) M24B= 0xFF0000FF0000FF00ULL;
00168 static uint64_t attribute_used __attribute__((aligned(8))) M24C= 0x0000FF0000FF0000ULL;
00169
00170
00171
00172 static volatile uint64_t attribute_used __attribute__((aligned(8))) b5Dither;
00173 static volatile uint64_t attribute_used __attribute__((aligned(8))) g5Dither;
00174 static volatile uint64_t attribute_used __attribute__((aligned(8))) g6Dither;
00175 static volatile uint64_t attribute_used __attribute__((aligned(8))) r5Dither;
00176
00177 static uint64_t __attribute__((aligned(8))) dither4[2]={
00178 0x0103010301030103LL,
00179 0x0200020002000200LL,};
00180
00181 static uint64_t __attribute__((aligned(8))) dither8[2]={
00182 0x0602060206020602LL,
00183 0x0004000400040004LL,};
00184
00185 #undef HAVE_MMX
00186
00187
00188 #undef RENAME
00189 #define HAVE_MMX
00190 #undef HAVE_MMX2
00191 #undef HAVE_3DNOW
00192 #define RENAME(a) a ## _MMX
00193 #include "yuv2rgb_template.c"
00194
00195
00196 #undef RENAME
00197 #define HAVE_MMX
00198 #define HAVE_MMX2
00199 #undef HAVE_3DNOW
00200 #define RENAME(a) a ## _MMX2
00201 #include "yuv2rgb_template.c"
00202
00203 #endif
00204
00205 const int32_t Inverse_Table_6_9[8][4] = {
00206 {117504, 138453, 13954, 34903},
00207 {117504, 138453, 13954, 34903},
00208 {104597, 132201, 25675, 53279},
00209 {104597, 132201, 25675, 53279},
00210 {104448, 132798, 24759, 53109},
00211 {104597, 132201, 25675, 53279},
00212 {104597, 132201, 25675, 53279},
00213 {117579, 136230, 16907, 35559}
00214 };
00215
00216 #define RGB(i) \
00217 U = pu[i]; \
00218 V = pv[i]; \
00219 r = (void *)c->table_rV[V]; \
00220 g = (void *)(c->table_gU[U] + c->table_gV[V]); \
00221 b = (void *)c->table_bU[U];
00222
00223 #define DST1(i) \
00224 Y = py_1[2*i]; \
00225 dst_1[2*i] = r[Y] + g[Y] + b[Y]; \
00226 Y = py_1[2*i+1]; \
00227 dst_1[2*i+1] = r[Y] + g[Y] + b[Y];
00228
00229 #define DST2(i) \
00230 Y = py_2[2*i]; \
00231 dst_2[2*i] = r[Y] + g[Y] + b[Y]; \
00232 Y = py_2[2*i+1]; \
00233 dst_2[2*i+1] = r[Y] + g[Y] + b[Y];
00234
00235 #define DST1RGB(i) \
00236 Y = py_1[2*i]; \
00237 dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y]; \
00238 Y = py_1[2*i+1]; \
00239 dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];
00240
00241 #define DST2RGB(i) \
00242 Y = py_2[2*i]; \
00243 dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y]; \
00244 Y = py_2[2*i+1]; \
00245 dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];
00246
00247 #define DST1BGR(i) \
00248 Y = py_1[2*i]; \
00249 dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y]; \
00250 Y = py_1[2*i+1]; \
00251 dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];
00252
00253 #define DST2BGR(i) \
00254 Y = py_2[2*i]; \
00255 dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y]; \
00256 Y = py_2[2*i+1]; \
00257 dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];
00258
00259 #define PROLOG(func_name, dst_type) \
00260 static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \
00261 int srcSliceH, uint8_t* dst[], int dstStride[]){\
00262 int y;\
00263 \
00264 if (c->srcFormat == PIX_FMT_YUV422P){\
00265 srcStride[1] *= 2;\
00266 srcStride[2] *= 2;\
00267 }\
00268 for (y=0; y<srcSliceH; y+=2){\
00269 dst_type *dst_1= (dst_type*)(dst[0] + (y+srcSliceY )*dstStride[0]);\
00270 dst_type *dst_2= (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
00271 dst_type av_unused *r, *b;\
00272 dst_type *g;\
00273 uint8_t *py_1= src[0] + y*srcStride[0];\
00274 uint8_t *py_2= py_1 + srcStride[0];\
00275 uint8_t *pu= src[1] + (y>>1)*srcStride[1];\
00276 uint8_t *pv= src[2] + (y>>1)*srcStride[2];\
00277 unsigned int h_size= c->dstW>>3;\
00278 while (h_size--) {\
00279 int av_unused U, V;\
00280 int Y;\
00281
00282 #define EPILOG1(dst_delta)\
00283 pu += 4;\
00284 pv += 4;\
00285 py_1 += 8;\
00286 py_2 += 8;\
00287 dst_1 += dst_delta;\
00288 dst_2 += dst_delta;\
00289 }\
00290 if (c->dstW & 4) {\
00291 int av_unused U, V;\
00292 int Y;\
00293
00294 #define EPILOG2()\
00295 }\
00296 }\
00297 return srcSliceH;\
00298 }
00299
00300 #define EPILOG(dst_delta)\
00301 EPILOG1(dst_delta)\
00302 EPILOG2()
00303
00304 PROLOG(yuv2rgb_c_32, uint32_t)
00305 RGB(0);
00306 DST1(0);
00307 DST2(0);
00308
00309 RGB(1);
00310 DST2(1);
00311 DST1(1);
00312
00313 RGB(2);
00314 DST1(2);
00315 DST2(2);
00316
00317 RGB(3);
00318 DST2(3);
00319 DST1(3);
00320 EPILOG1(8)
00321 RGB(0);
00322 DST1(0);
00323 DST2(0);
00324
00325 RGB(1);
00326 DST2(1);
00327 DST1(1);
00328 EPILOG2()
00329
00330 PROLOG(yuv2rgb_c_24_rgb, uint8_t)
00331 RGB(0);
00332 DST1RGB(0);
00333 DST2RGB(0);
00334
00335 RGB(1);
00336 DST2RGB(1);
00337 DST1RGB(1);
00338
00339 RGB(2);
00340 DST1RGB(2);
00341 DST2RGB(2);
00342
00343 RGB(3);
00344 DST2RGB(3);
00345 DST1RGB(3);
00346 EPILOG1(24)
00347 RGB(0);
00348 DST1RGB(0);
00349 DST2RGB(0);
00350
00351 RGB(1);
00352 DST2RGB(1);
00353 DST1RGB(1);
00354 EPILOG2()
00355
00356
00357 PROLOG(yuv2rgb_c_24_bgr, uint8_t)
00358 RGB(0);
00359 DST1BGR(0);
00360 DST2BGR(0);
00361
00362 RGB(1);
00363 DST2BGR(1);
00364 DST1BGR(1);
00365
00366 RGB(2);
00367 DST1BGR(2);
00368 DST2BGR(2);
00369
00370 RGB(3);
00371 DST2BGR(3);
00372 DST1BGR(3);
00373 EPILOG1(24)
00374 RGB(0);
00375 DST1BGR(0);
00376 DST2BGR(0);
00377
00378 RGB(1);
00379 DST2BGR(1);
00380 DST1BGR(1);
00381 EPILOG2()
00382
00383
00384
00385 PROLOG(yuv2rgb_c_16, uint16_t)
00386 RGB(0);
00387 DST1(0);
00388 DST2(0);
00389
00390 RGB(1);
00391 DST2(1);
00392 DST1(1);
00393
00394 RGB(2);
00395 DST1(2);
00396 DST2(2);
00397
00398 RGB(3);
00399 DST2(3);
00400 DST1(3);
00401 EPILOG(8)
00402
00403
00404
00405 PROLOG(yuv2rgb_c_8, uint8_t)
00406 RGB(0);
00407 DST1(0);
00408 DST2(0);
00409
00410 RGB(1);
00411 DST2(1);
00412 DST1(1);
00413
00414 RGB(2);
00415 DST1(2);
00416 DST2(2);
00417
00418 RGB(3);
00419 DST2(3);
00420 DST1(3);
00421 EPILOG(8)
00422
00423
00424 PROLOG(yuv2rgb_c_8_ordered_dither, uint8_t)
00425 const uint8_t *d32= dither_8x8_32[y&7];
00426 const uint8_t *d64= dither_8x8_73[y&7];
00427 #define DST1bpp8(i,o) \
00428 Y = py_1[2*i]; \
00429 dst_1[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \
00430 Y = py_1[2*i+1]; \
00431 dst_1[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]];
00432
00433 #define DST2bpp8(i,o) \
00434 Y = py_2[2*i]; \
00435 dst_2[2*i] = r[Y+d32[8+o]] + g[Y+d32[8+o]] + b[Y+d64[8+o]]; \
00436 Y = py_2[2*i+1]; \
00437 dst_2[2*i+1] = r[Y+d32[9+o]] + g[Y+d32[9+o]] + b[Y+d64[9+o]];
00438
00439
00440 RGB(0);
00441 DST1bpp8(0,0);
00442 DST2bpp8(0,0);
00443
00444 RGB(1);
00445 DST2bpp8(1,2);
00446 DST1bpp8(1,2);
00447
00448 RGB(2);
00449 DST1bpp8(2,4);
00450 DST2bpp8(2,4);
00451
00452 RGB(3);
00453 DST2bpp8(3,6);
00454 DST1bpp8(3,6);
00455 EPILOG(8)
00456
00457
00458
00459
00460 PROLOG(yuv2rgb_c_4, uint8_t)
00461 int acc;
00462 #define DST1_4(i) \
00463 Y = py_1[2*i]; \
00464 acc = r[Y] + g[Y] + b[Y]; \
00465 Y = py_1[2*i+1]; \
00466 acc |= (r[Y] + g[Y] + b[Y])<<4; \
00467 dst_1[i] = acc;
00468
00469 #define DST2_4(i) \
00470 Y = py_2[2*i]; \
00471 acc = r[Y] + g[Y] + b[Y]; \
00472 Y = py_2[2*i+1]; \
00473 acc |= (r[Y] + g[Y] + b[Y])<<4; \
00474 dst_2[i] = acc;
00475
00476 RGB(0);
00477 DST1_4(0);
00478 DST2_4(0);
00479
00480 RGB(1);
00481 DST2_4(1);
00482 DST1_4(1);
00483
00484 RGB(2);
00485 DST1_4(2);
00486 DST2_4(2);
00487
00488 RGB(3);
00489 DST2_4(3);
00490 DST1_4(3);
00491 EPILOG(4)
00492
00493 PROLOG(yuv2rgb_c_4_ordered_dither, uint8_t)
00494 const uint8_t *d64= dither_8x8_73[y&7];
00495 const uint8_t *d128=dither_8x8_220[y&7];
00496 int acc;
00497
00498 #define DST1bpp4(i,o) \
00499 Y = py_1[2*i]; \
00500 acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
00501 Y = py_1[2*i+1]; \
00502 acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4; \
00503 dst_1[i]= acc;
00504
00505 #define DST2bpp4(i,o) \
00506 Y = py_2[2*i]; \
00507 acc = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \
00508 Y = py_2[2*i+1]; \
00509 acc |= (r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]])<<4; \
00510 dst_2[i]= acc;
00511
00512
00513 RGB(0);
00514 DST1bpp4(0,0);
00515 DST2bpp4(0,0);
00516
00517 RGB(1);
00518 DST2bpp4(1,2);
00519 DST1bpp4(1,2);
00520
00521 RGB(2);
00522 DST1bpp4(2,4);
00523 DST2bpp4(2,4);
00524
00525 RGB(3);
00526 DST2bpp4(3,6);
00527 DST1bpp4(3,6);
00528 EPILOG(4)
00529
00530
00531
00532 PROLOG(yuv2rgb_c_4b, uint8_t)
00533 RGB(0);
00534 DST1(0);
00535 DST2(0);
00536
00537 RGB(1);
00538 DST2(1);
00539 DST1(1);
00540
00541 RGB(2);
00542 DST1(2);
00543 DST2(2);
00544
00545 RGB(3);
00546 DST2(3);
00547 DST1(3);
00548 EPILOG(8)
00549
00550 PROLOG(yuv2rgb_c_4b_ordered_dither, uint8_t)
00551 const uint8_t *d64= dither_8x8_73[y&7];
00552 const uint8_t *d128=dither_8x8_220[y&7];
00553
00554 #define DST1bpp4b(i,o) \
00555 Y = py_1[2*i]; \
00556 dst_1[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
00557 Y = py_1[2*i+1]; \
00558 dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
00559
00560 #define DST2bpp4b(i,o) \
00561 Y = py_2[2*i]; \
00562 dst_2[2*i] = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \
00563 Y = py_2[2*i+1]; \
00564 dst_2[2*i+1] = r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]];
00565
00566
00567 RGB(0);
00568 DST1bpp4b(0,0);
00569 DST2bpp4b(0,0);
00570
00571 RGB(1);
00572 DST2bpp4b(1,2);
00573 DST1bpp4b(1,2);
00574
00575 RGB(2);
00576 DST1bpp4b(2,4);
00577 DST2bpp4b(2,4);
00578
00579 RGB(3);
00580 DST2bpp4b(3,6);
00581 DST1bpp4b(3,6);
00582 EPILOG(8)
00583
00584 PROLOG(yuv2rgb_c_1_ordered_dither, uint8_t)
00585 const uint8_t *d128=dither_8x8_220[y&7];
00586 char out_1=0, out_2=0;
00587 g= c->table_gU[128] + c->table_gV[128];
00588
00589 #define DST1bpp1(i,o) \
00590 Y = py_1[2*i]; \
00591 out_1+= out_1 + g[Y+d128[0+o]]; \
00592 Y = py_1[2*i+1]; \
00593 out_1+= out_1 + g[Y+d128[1+o]];
00594
00595 #define DST2bpp1(i,o) \
00596 Y = py_2[2*i]; \
00597 out_2+= out_2 + g[Y+d128[8+o]]; \
00598 Y = py_2[2*i+1]; \
00599 out_2+= out_2 + g[Y+d128[9+o]];
00600
00601 DST1bpp1(0,0);
00602 DST2bpp1(0,0);
00603
00604 DST2bpp1(1,2);
00605 DST1bpp1(1,2);
00606
00607 DST1bpp1(2,4);
00608 DST2bpp1(2,4);
00609
00610 DST2bpp1(3,6);
00611 DST1bpp1(3,6);
00612
00613 dst_1[0]= out_1;
00614 dst_2[0]= out_2;
00615 EPILOG(1)
00616
00617 SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
00618 {
00619 #if defined(HAVE_MMX2) || defined(HAVE_MMX)
00620 if (c->flags & SWS_CPU_CAPS_MMX2){
00621 switch(c->dstFormat){
00622 case PIX_FMT_RGB32: return yuv420_rgb32_MMX2;
00623 case PIX_FMT_BGR24: return yuv420_rgb24_MMX2;
00624 case PIX_FMT_BGR565: return yuv420_rgb16_MMX2;
00625 case PIX_FMT_BGR555: return yuv420_rgb15_MMX2;
00626 }
00627 }
00628 if (c->flags & SWS_CPU_CAPS_MMX){
00629 switch(c->dstFormat){
00630 case PIX_FMT_RGB32: return yuv420_rgb32_MMX;
00631 case PIX_FMT_BGR24: return yuv420_rgb24_MMX;
00632 case PIX_FMT_BGR565: return yuv420_rgb16_MMX;
00633 case PIX_FMT_BGR555: return yuv420_rgb15_MMX;
00634 }
00635 }
00636 #endif
00637 #ifdef HAVE_VIS
00638 {
00639 SwsFunc t= yuv2rgb_init_vis(c);
00640 if (t) return t;
00641 }
00642 #endif
00643 #ifdef HAVE_MLIB
00644 {
00645 SwsFunc t= yuv2rgb_init_mlib(c);
00646 if (t) return t;
00647 }
00648 #endif
00649 #ifdef HAVE_ALTIVEC
00650 if (c->flags & SWS_CPU_CAPS_ALTIVEC)
00651 {
00652 SwsFunc t = yuv2rgb_init_altivec(c);
00653 if (t) return t;
00654 }
00655 #endif
00656
00657 #ifdef ARCH_BFIN
00658 if (c->flags & SWS_CPU_CAPS_BFIN)
00659 {
00660 SwsFunc t = ff_bfin_yuv2rgb_get_func_ptr (c);
00661 if (t) return t;
00662 }
00663 #endif
00664
00665 av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found\n");
00666
00667 switch(c->dstFormat){
00668 case PIX_FMT_BGR32:
00669 case PIX_FMT_RGB32: return yuv2rgb_c_32;
00670 case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb;
00671 case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr;
00672 case PIX_FMT_RGB565:
00673 case PIX_FMT_BGR565:
00674 case PIX_FMT_RGB555:
00675 case PIX_FMT_BGR555: return yuv2rgb_c_16;
00676 case PIX_FMT_RGB8:
00677 case PIX_FMT_BGR8: return yuv2rgb_c_8_ordered_dither;
00678 case PIX_FMT_RGB4:
00679 case PIX_FMT_BGR4: return yuv2rgb_c_4_ordered_dither;
00680 case PIX_FMT_RGB4_BYTE:
00681 case PIX_FMT_BGR4_BYTE: return yuv2rgb_c_4b_ordered_dither;
00682 case PIX_FMT_MONOBLACK: return yuv2rgb_c_1_ordered_dither;
00683 default:
00684 assert(0);
00685 }
00686 return NULL;
00687 }
00688
00689 static int div_round (int dividend, int divisor)
00690 {
00691 if (dividend > 0)
00692 return (dividend + (divisor>>1)) / divisor;
00693 else
00694 return -((-dividend + (divisor>>1)) / divisor);
00695 }
00696
00697 int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)
00698 {
00699 const int isRgb = isBGR(c->dstFormat);
00700 const int bpp = fmt_depth(c->dstFormat);
00701 int i;
00702 uint8_t table_Y[1024];
00703 uint32_t *table_32 = 0;
00704 uint16_t *table_16 = 0;
00705 uint8_t *table_8 = 0;
00706 uint8_t *table_332 = 0;
00707 uint8_t *table_121 = 0;
00708 uint8_t *table_1 = 0;
00709 int entry_size = 0;
00710 void *table_r = 0, *table_g = 0, *table_b = 0;
00711 void *table_start;
00712
00713 int64_t crv = inv_table[0];
00714 int64_t cbu = inv_table[1];
00715 int64_t cgu = -inv_table[2];
00716 int64_t cgv = -inv_table[3];
00717 int64_t cy = 1<<16;
00718 int64_t oy = 0;
00719
00720
00721 if (!fullRange){
00722 cy= (cy*255) / 219;
00723 oy= 16<<16;
00724 }else{
00725 crv= (crv*224) / 255;
00726 cbu= (cbu*224) / 255;
00727 cgu= (cgu*224) / 255;
00728 cgv= (cgv*224) / 255;
00729 }
00730
00731 cy = (cy *contrast )>>16;
00732 crv= (crv*contrast * saturation)>>32;
00733 cbu= (cbu*contrast * saturation)>>32;
00734 cgu= (cgu*contrast * saturation)>>32;
00735 cgv= (cgv*contrast * saturation)>>32;
00736
00737 oy -= 256*brightness;
00738
00739 for (i = 0; i < 1024; i++) {
00740 int j;
00741
00742 j= (cy*(((i - 384)<<16) - oy) + (1<<31))>>32;
00743 j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
00744 table_Y[i] = j;
00745 }
00746
00747 switch (bpp) {
00748 case 32:
00749 table_start= table_32 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));
00750
00751 entry_size = sizeof (uint32_t);
00752 table_r = table_32 + 197;
00753 table_b = table_32 + 197 + 685;
00754 table_g = table_32 + 197 + 2*682;
00755
00756 for (i = -197; i < 256+197; i++)
00757 ((uint32_t *)table_r)[i] = table_Y[i+384] << (isRgb ? 16 : 0);
00758 for (i = -132; i < 256+132; i++)
00759 ((uint32_t *)table_g)[i] = table_Y[i+384] << 8;
00760 for (i = -232; i < 256+232; i++)
00761 ((uint32_t *)table_b)[i] = table_Y[i+384] << (isRgb ? 0 : 16);
00762 break;
00763
00764 case 24:
00765 table_start= table_8 = av_malloc ((256 + 2*232) * sizeof (uint8_t));
00766
00767 entry_size = sizeof (uint8_t);
00768 table_r = table_g = table_b = table_8 + 232;
00769
00770 for (i = -232; i < 256+232; i++)
00771 ((uint8_t * )table_b)[i] = table_Y[i+384];
00772 break;
00773
00774 case 15:
00775 case 16:
00776 table_start= table_16 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
00777
00778 entry_size = sizeof (uint16_t);
00779 table_r = table_16 + 197;
00780 table_b = table_16 + 197 + 685;
00781 table_g = table_16 + 197 + 2*682;
00782
00783 for (i = -197; i < 256+197; i++) {
00784 int j = table_Y[i+384] >> 3;
00785
00786 if (isRgb)
00787 j <<= ((bpp==16) ? 11 : 10);
00788
00789 ((uint16_t *)table_r)[i] = j;
00790 }
00791 for (i = -132; i < 256+132; i++) {
00792 int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);
00793
00794 ((uint16_t *)table_g)[i] = j << 5;
00795 }
00796 for (i = -232; i < 256+232; i++) {
00797 int j = table_Y[i+384] >> 3;
00798
00799 if (!isRgb)
00800 j <<= ((bpp==16) ? 11 : 10);
00801
00802 ((uint16_t *)table_b)[i] = j;
00803 }
00804 break;
00805
00806 case 8:
00807 table_start= table_332 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
00808
00809 entry_size = sizeof (uint8_t);
00810 table_r = table_332 + 197;
00811 table_b = table_332 + 197 + 685;
00812 table_g = table_332 + 197 + 2*682;
00813
00814 for (i = -197; i < 256+197; i++) {
00815 int j = (table_Y[i+384 - 16] + 18)/36;
00816
00817 if (isRgb)
00818 j <<= 5;
00819
00820 ((uint8_t *)table_r)[i] = j;
00821 }
00822 for (i = -132; i < 256+132; i++) {
00823 int j = (table_Y[i+384 - 16] + 18)/36;
00824
00825 if (!isRgb)
00826 j <<= 1;
00827
00828 ((uint8_t *)table_g)[i] = j << 2;
00829 }
00830 for (i = -232; i < 256+232; i++) {
00831 int j = (table_Y[i+384 - 37] + 43)/85;
00832
00833 if (!isRgb)
00834 j <<= 6;
00835
00836 ((uint8_t *)table_b)[i] = j;
00837 }
00838 break;
00839 case 4:
00840 case 4|128:
00841 table_start= table_121 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
00842
00843 entry_size = sizeof (uint8_t);
00844 table_r = table_121 + 197;
00845 table_b = table_121 + 197 + 685;
00846 table_g = table_121 + 197 + 2*682;
00847
00848 for (i = -197; i < 256+197; i++) {
00849 int j = table_Y[i+384 - 110] >> 7;
00850
00851 if (isRgb)
00852 j <<= 3;
00853
00854 ((uint8_t *)table_r)[i] = j;
00855 }
00856 for (i = -132; i < 256+132; i++) {
00857 int j = (table_Y[i+384 - 37]+ 43)/85;
00858
00859 ((uint8_t *)table_g)[i] = j << 1;
00860 }
00861 for (i = -232; i < 256+232; i++) {
00862 int j =table_Y[i+384 - 110] >> 7;
00863
00864 if (!isRgb)
00865 j <<= 3;
00866
00867 ((uint8_t *)table_b)[i] = j;
00868 }
00869 break;
00870
00871 case 1:
00872 table_start= table_1 = av_malloc (256*2 * sizeof (uint8_t));
00873
00874 entry_size = sizeof (uint8_t);
00875 table_g = table_1;
00876 table_r = table_b = NULL;
00877
00878 for (i = 0; i < 256+256; i++) {
00879 int j = table_Y[i + 384 - 110]>>7;
00880
00881 ((uint8_t *)table_g)[i] = j;
00882 }
00883 break;
00884
00885 default:
00886 table_start= NULL;
00887 av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
00888
00889 return -1;
00890 }
00891
00892 for (i = 0; i < 256; i++) {
00893 c->table_rV[i] = (uint8_t *)table_r + entry_size * div_round (crv * (i-128), 76309);
00894 c->table_gU[i] = (uint8_t *)table_g + entry_size * div_round (cgu * (i-128), 76309);
00895 c->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
00896 c->table_bU[i] = (uint8_t *)table_b + entry_size * div_round (cbu * (i-128), 76309);
00897 }
00898
00899 av_free(c->yuvTable);
00900 c->yuvTable= table_start;
00901 return 0;
00902 }