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 DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL;
00163 DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL;
00164 DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL;
00165
00166
00167
00168 static volatile uint64_t attribute_used __attribute__((aligned(8))) b5Dither;
00169 static volatile uint64_t attribute_used __attribute__((aligned(8))) g5Dither;
00170 static volatile uint64_t attribute_used __attribute__((aligned(8))) g6Dither;
00171 static volatile uint64_t attribute_used __attribute__((aligned(8))) r5Dither;
00172
00173 static uint64_t __attribute__((aligned(8))) dither4[2]={
00174 0x0103010301030103LL,
00175 0x0200020002000200LL,};
00176
00177 static uint64_t __attribute__((aligned(8))) dither8[2]={
00178 0x0602060206020602LL,
00179 0x0004000400040004LL,};
00180
00181 #undef HAVE_MMX
00182
00183
00184 #undef RENAME
00185 #define HAVE_MMX
00186 #undef HAVE_MMX2
00187 #undef HAVE_3DNOW
00188 #define RENAME(a) a ## _MMX
00189 #include "yuv2rgb_template.c"
00190
00191
00192 #undef RENAME
00193 #define HAVE_MMX
00194 #define HAVE_MMX2
00195 #undef HAVE_3DNOW
00196 #define RENAME(a) a ## _MMX2
00197 #include "yuv2rgb_template.c"
00198
00199 #endif
00200
00201 const int32_t Inverse_Table_6_9[8][4] = {
00202 {117504, 138453, 13954, 34903},
00203 {117504, 138453, 13954, 34903},
00204 {104597, 132201, 25675, 53279},
00205 {104597, 132201, 25675, 53279},
00206 {104448, 132798, 24759, 53109},
00207 {104597, 132201, 25675, 53279},
00208 {104597, 132201, 25675, 53279},
00209 {117579, 136230, 16907, 35559}
00210 };
00211
00212 #define RGB(i) \
00213 U = pu[i]; \
00214 V = pv[i]; \
00215 r = (void *)c->table_rV[V]; \
00216 g = (void *)(c->table_gU[U] + c->table_gV[V]); \
00217 b = (void *)c->table_bU[U];
00218
00219 #define DST1(i) \
00220 Y = py_1[2*i]; \
00221 dst_1[2*i] = r[Y] + g[Y] + b[Y]; \
00222 Y = py_1[2*i+1]; \
00223 dst_1[2*i+1] = r[Y] + g[Y] + b[Y];
00224
00225 #define DST2(i) \
00226 Y = py_2[2*i]; \
00227 dst_2[2*i] = r[Y] + g[Y] + b[Y]; \
00228 Y = py_2[2*i+1]; \
00229 dst_2[2*i+1] = r[Y] + g[Y] + b[Y];
00230
00231 #define DST1RGB(i) \
00232 Y = py_1[2*i]; \
00233 dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y]; \
00234 Y = py_1[2*i+1]; \
00235 dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];
00236
00237 #define DST2RGB(i) \
00238 Y = py_2[2*i]; \
00239 dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y]; \
00240 Y = py_2[2*i+1]; \
00241 dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];
00242
00243 #define DST1BGR(i) \
00244 Y = py_1[2*i]; \
00245 dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y]; \
00246 Y = py_1[2*i+1]; \
00247 dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];
00248
00249 #define DST2BGR(i) \
00250 Y = py_2[2*i]; \
00251 dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y]; \
00252 Y = py_2[2*i+1]; \
00253 dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];
00254
00255 #define PROLOG(func_name, dst_type) \
00256 static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \
00257 int srcSliceH, uint8_t* dst[], int dstStride[]){\
00258 int y;\
00259 \
00260 if (c->srcFormat == PIX_FMT_YUV422P){\
00261 srcStride[1] *= 2;\
00262 srcStride[2] *= 2;\
00263 }\
00264 for (y=0; y<srcSliceH; y+=2){\
00265 dst_type *dst_1= (dst_type*)(dst[0] + (y+srcSliceY )*dstStride[0]);\
00266 dst_type *dst_2= (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
00267 dst_type av_unused *r, *b;\
00268 dst_type *g;\
00269 uint8_t *py_1= src[0] + y*srcStride[0];\
00270 uint8_t *py_2= py_1 + srcStride[0];\
00271 uint8_t *pu= src[1] + (y>>1)*srcStride[1];\
00272 uint8_t *pv= src[2] + (y>>1)*srcStride[2];\
00273 unsigned int h_size= c->dstW>>3;\
00274 while (h_size--) {\
00275 int av_unused U, V;\
00276 int Y;\
00277
00278 #define EPILOG1(dst_delta)\
00279 pu += 4;\
00280 pv += 4;\
00281 py_1 += 8;\
00282 py_2 += 8;\
00283 dst_1 += dst_delta;\
00284 dst_2 += dst_delta;\
00285 }\
00286 if (c->dstW & 4) {\
00287 int av_unused U, V;\
00288 int Y;\
00289
00290 #define EPILOG2()\
00291 }\
00292 }\
00293 return srcSliceH;\
00294 }
00295
00296 #define EPILOG(dst_delta)\
00297 EPILOG1(dst_delta)\
00298 EPILOG2()
00299
00300 PROLOG(yuv2rgb_c_32, uint32_t)
00301 RGB(0);
00302 DST1(0);
00303 DST2(0);
00304
00305 RGB(1);
00306 DST2(1);
00307 DST1(1);
00308
00309 RGB(2);
00310 DST1(2);
00311 DST2(2);
00312
00313 RGB(3);
00314 DST2(3);
00315 DST1(3);
00316 EPILOG1(8)
00317 RGB(0);
00318 DST1(0);
00319 DST2(0);
00320
00321 RGB(1);
00322 DST2(1);
00323 DST1(1);
00324 EPILOG2()
00325
00326 PROLOG(yuv2rgb_c_24_rgb, uint8_t)
00327 RGB(0);
00328 DST1RGB(0);
00329 DST2RGB(0);
00330
00331 RGB(1);
00332 DST2RGB(1);
00333 DST1RGB(1);
00334
00335 RGB(2);
00336 DST1RGB(2);
00337 DST2RGB(2);
00338
00339 RGB(3);
00340 DST2RGB(3);
00341 DST1RGB(3);
00342 EPILOG1(24)
00343 RGB(0);
00344 DST1RGB(0);
00345 DST2RGB(0);
00346
00347 RGB(1);
00348 DST2RGB(1);
00349 DST1RGB(1);
00350 EPILOG2()
00351
00352
00353 PROLOG(yuv2rgb_c_24_bgr, uint8_t)
00354 RGB(0);
00355 DST1BGR(0);
00356 DST2BGR(0);
00357
00358 RGB(1);
00359 DST2BGR(1);
00360 DST1BGR(1);
00361
00362 RGB(2);
00363 DST1BGR(2);
00364 DST2BGR(2);
00365
00366 RGB(3);
00367 DST2BGR(3);
00368 DST1BGR(3);
00369 EPILOG1(24)
00370 RGB(0);
00371 DST1BGR(0);
00372 DST2BGR(0);
00373
00374 RGB(1);
00375 DST2BGR(1);
00376 DST1BGR(1);
00377 EPILOG2()
00378
00379
00380
00381 PROLOG(yuv2rgb_c_16, uint16_t)
00382 RGB(0);
00383 DST1(0);
00384 DST2(0);
00385
00386 RGB(1);
00387 DST2(1);
00388 DST1(1);
00389
00390 RGB(2);
00391 DST1(2);
00392 DST2(2);
00393
00394 RGB(3);
00395 DST2(3);
00396 DST1(3);
00397 EPILOG(8)
00398
00399
00400
00401 PROLOG(yuv2rgb_c_8, uint8_t)
00402 RGB(0);
00403 DST1(0);
00404 DST2(0);
00405
00406 RGB(1);
00407 DST2(1);
00408 DST1(1);
00409
00410 RGB(2);
00411 DST1(2);
00412 DST2(2);
00413
00414 RGB(3);
00415 DST2(3);
00416 DST1(3);
00417 EPILOG(8)
00418
00419
00420 PROLOG(yuv2rgb_c_8_ordered_dither, uint8_t)
00421 const uint8_t *d32= dither_8x8_32[y&7];
00422 const uint8_t *d64= dither_8x8_73[y&7];
00423 #define DST1bpp8(i,o) \
00424 Y = py_1[2*i]; \
00425 dst_1[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \
00426 Y = py_1[2*i+1]; \
00427 dst_1[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]];
00428
00429 #define DST2bpp8(i,o) \
00430 Y = py_2[2*i]; \
00431 dst_2[2*i] = r[Y+d32[8+o]] + g[Y+d32[8+o]] + b[Y+d64[8+o]]; \
00432 Y = py_2[2*i+1]; \
00433 dst_2[2*i+1] = r[Y+d32[9+o]] + g[Y+d32[9+o]] + b[Y+d64[9+o]];
00434
00435
00436 RGB(0);
00437 DST1bpp8(0,0);
00438 DST2bpp8(0,0);
00439
00440 RGB(1);
00441 DST2bpp8(1,2);
00442 DST1bpp8(1,2);
00443
00444 RGB(2);
00445 DST1bpp8(2,4);
00446 DST2bpp8(2,4);
00447
00448 RGB(3);
00449 DST2bpp8(3,6);
00450 DST1bpp8(3,6);
00451 EPILOG(8)
00452
00453
00454
00455
00456 PROLOG(yuv2rgb_c_4, uint8_t)
00457 int acc;
00458 #define DST1_4(i) \
00459 Y = py_1[2*i]; \
00460 acc = r[Y] + g[Y] + b[Y]; \
00461 Y = py_1[2*i+1]; \
00462 acc |= (r[Y] + g[Y] + b[Y])<<4; \
00463 dst_1[i] = acc;
00464
00465 #define DST2_4(i) \
00466 Y = py_2[2*i]; \
00467 acc = r[Y] + g[Y] + b[Y]; \
00468 Y = py_2[2*i+1]; \
00469 acc |= (r[Y] + g[Y] + b[Y])<<4; \
00470 dst_2[i] = acc;
00471
00472 RGB(0);
00473 DST1_4(0);
00474 DST2_4(0);
00475
00476 RGB(1);
00477 DST2_4(1);
00478 DST1_4(1);
00479
00480 RGB(2);
00481 DST1_4(2);
00482 DST2_4(2);
00483
00484 RGB(3);
00485 DST2_4(3);
00486 DST1_4(3);
00487 EPILOG(4)
00488
00489 PROLOG(yuv2rgb_c_4_ordered_dither, uint8_t)
00490 const uint8_t *d64= dither_8x8_73[y&7];
00491 const uint8_t *d128=dither_8x8_220[y&7];
00492 int acc;
00493
00494 #define DST1bpp4(i,o) \
00495 Y = py_1[2*i]; \
00496 acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
00497 Y = py_1[2*i+1]; \
00498 acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4; \
00499 dst_1[i]= acc;
00500
00501 #define DST2bpp4(i,o) \
00502 Y = py_2[2*i]; \
00503 acc = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \
00504 Y = py_2[2*i+1]; \
00505 acc |= (r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]])<<4; \
00506 dst_2[i]= acc;
00507
00508
00509 RGB(0);
00510 DST1bpp4(0,0);
00511 DST2bpp4(0,0);
00512
00513 RGB(1);
00514 DST2bpp4(1,2);
00515 DST1bpp4(1,2);
00516
00517 RGB(2);
00518 DST1bpp4(2,4);
00519 DST2bpp4(2,4);
00520
00521 RGB(3);
00522 DST2bpp4(3,6);
00523 DST1bpp4(3,6);
00524 EPILOG(4)
00525
00526
00527
00528 PROLOG(yuv2rgb_c_4b, uint8_t)
00529 RGB(0);
00530 DST1(0);
00531 DST2(0);
00532
00533 RGB(1);
00534 DST2(1);
00535 DST1(1);
00536
00537 RGB(2);
00538 DST1(2);
00539 DST2(2);
00540
00541 RGB(3);
00542 DST2(3);
00543 DST1(3);
00544 EPILOG(8)
00545
00546 PROLOG(yuv2rgb_c_4b_ordered_dither, uint8_t)
00547 const uint8_t *d64= dither_8x8_73[y&7];
00548 const uint8_t *d128=dither_8x8_220[y&7];
00549
00550 #define DST1bpp4b(i,o) \
00551 Y = py_1[2*i]; \
00552 dst_1[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \
00553 Y = py_1[2*i+1]; \
00554 dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
00555
00556 #define DST2bpp4b(i,o) \
00557 Y = py_2[2*i]; \
00558 dst_2[2*i] = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \
00559 Y = py_2[2*i+1]; \
00560 dst_2[2*i+1] = r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]];
00561
00562
00563 RGB(0);
00564 DST1bpp4b(0,0);
00565 DST2bpp4b(0,0);
00566
00567 RGB(1);
00568 DST2bpp4b(1,2);
00569 DST1bpp4b(1,2);
00570
00571 RGB(2);
00572 DST1bpp4b(2,4);
00573 DST2bpp4b(2,4);
00574
00575 RGB(3);
00576 DST2bpp4b(3,6);
00577 DST1bpp4b(3,6);
00578 EPILOG(8)
00579
00580 PROLOG(yuv2rgb_c_1_ordered_dither, uint8_t)
00581 const uint8_t *d128=dither_8x8_220[y&7];
00582 char out_1=0, out_2=0;
00583 g= c->table_gU[128] + c->table_gV[128];
00584
00585 #define DST1bpp1(i,o) \
00586 Y = py_1[2*i]; \
00587 out_1+= out_1 + g[Y+d128[0+o]]; \
00588 Y = py_1[2*i+1]; \
00589 out_1+= out_1 + g[Y+d128[1+o]];
00590
00591 #define DST2bpp1(i,o) \
00592 Y = py_2[2*i]; \
00593 out_2+= out_2 + g[Y+d128[8+o]]; \
00594 Y = py_2[2*i+1]; \
00595 out_2+= out_2 + g[Y+d128[9+o]];
00596
00597 DST1bpp1(0,0);
00598 DST2bpp1(0,0);
00599
00600 DST2bpp1(1,2);
00601 DST1bpp1(1,2);
00602
00603 DST1bpp1(2,4);
00604 DST2bpp1(2,4);
00605
00606 DST2bpp1(3,6);
00607 DST1bpp1(3,6);
00608
00609 dst_1[0]= out_1;
00610 dst_2[0]= out_2;
00611 EPILOG(1)
00612
00613 SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
00614 {
00615 #if defined(HAVE_MMX2) || defined(HAVE_MMX)
00616 if (c->flags & SWS_CPU_CAPS_MMX2){
00617 switch(c->dstFormat){
00618 case PIX_FMT_RGB32: return yuv420_rgb32_MMX2;
00619 case PIX_FMT_BGR24: return yuv420_rgb24_MMX2;
00620 case PIX_FMT_BGR565: return yuv420_rgb16_MMX2;
00621 case PIX_FMT_BGR555: return yuv420_rgb15_MMX2;
00622 }
00623 }
00624 if (c->flags & SWS_CPU_CAPS_MMX){
00625 switch(c->dstFormat){
00626 case PIX_FMT_RGB32: return yuv420_rgb32_MMX;
00627 case PIX_FMT_BGR24: return yuv420_rgb24_MMX;
00628 case PIX_FMT_BGR565: return yuv420_rgb16_MMX;
00629 case PIX_FMT_BGR555: return yuv420_rgb15_MMX;
00630 }
00631 }
00632 #endif
00633 #ifdef HAVE_VIS
00634 {
00635 SwsFunc t= yuv2rgb_init_vis(c);
00636 if (t) return t;
00637 }
00638 #endif
00639 #ifdef HAVE_MLIB
00640 {
00641 SwsFunc t= yuv2rgb_init_mlib(c);
00642 if (t) return t;
00643 }
00644 #endif
00645 #ifdef HAVE_ALTIVEC
00646 if (c->flags & SWS_CPU_CAPS_ALTIVEC)
00647 {
00648 SwsFunc t = yuv2rgb_init_altivec(c);
00649 if (t) return t;
00650 }
00651 #endif
00652
00653 #ifdef ARCH_BFIN
00654 if (c->flags & SWS_CPU_CAPS_BFIN)
00655 {
00656 SwsFunc t = ff_bfin_yuv2rgb_get_func_ptr (c);
00657 if (t) return t;
00658 }
00659 #endif
00660
00661 av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found\n");
00662
00663 switch(c->dstFormat){
00664 case PIX_FMT_BGR32:
00665 case PIX_FMT_RGB32: return yuv2rgb_c_32;
00666 case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb;
00667 case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr;
00668 case PIX_FMT_RGB565:
00669 case PIX_FMT_BGR565:
00670 case PIX_FMT_RGB555:
00671 case PIX_FMT_BGR555: return yuv2rgb_c_16;
00672 case PIX_FMT_RGB8:
00673 case PIX_FMT_BGR8: return yuv2rgb_c_8_ordered_dither;
00674 case PIX_FMT_RGB4:
00675 case PIX_FMT_BGR4: return yuv2rgb_c_4_ordered_dither;
00676 case PIX_FMT_RGB4_BYTE:
00677 case PIX_FMT_BGR4_BYTE: return yuv2rgb_c_4b_ordered_dither;
00678 case PIX_FMT_MONOBLACK: return yuv2rgb_c_1_ordered_dither;
00679 default:
00680 assert(0);
00681 }
00682 return NULL;
00683 }
00684
00685 static int div_round (int dividend, int divisor)
00686 {
00687 if (dividend > 0)
00688 return (dividend + (divisor>>1)) / divisor;
00689 else
00690 return -((-dividend + (divisor>>1)) / divisor);
00691 }
00692
00693 int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)
00694 {
00695 const int isRgb = isBGR(c->dstFormat);
00696 const int bpp = fmt_depth(c->dstFormat);
00697 int i;
00698 uint8_t table_Y[1024];
00699 uint32_t *table_32 = 0;
00700 uint16_t *table_16 = 0;
00701 uint8_t *table_8 = 0;
00702 uint8_t *table_332 = 0;
00703 uint8_t *table_121 = 0;
00704 uint8_t *table_1 = 0;
00705 int entry_size = 0;
00706 void *table_r = 0, *table_g = 0, *table_b = 0;
00707 void *table_start;
00708
00709 int64_t crv = inv_table[0];
00710 int64_t cbu = inv_table[1];
00711 int64_t cgu = -inv_table[2];
00712 int64_t cgv = -inv_table[3];
00713 int64_t cy = 1<<16;
00714 int64_t oy = 0;
00715
00716
00717 if (!fullRange){
00718 cy= (cy*255) / 219;
00719 oy= 16<<16;
00720 }else{
00721 crv= (crv*224) / 255;
00722 cbu= (cbu*224) / 255;
00723 cgu= (cgu*224) / 255;
00724 cgv= (cgv*224) / 255;
00725 }
00726
00727 cy = (cy *contrast )>>16;
00728 crv= (crv*contrast * saturation)>>32;
00729 cbu= (cbu*contrast * saturation)>>32;
00730 cgu= (cgu*contrast * saturation)>>32;
00731 cgv= (cgv*contrast * saturation)>>32;
00732
00733 oy -= 256*brightness;
00734
00735 for (i = 0; i < 1024; i++) {
00736 int j;
00737
00738 j= (cy*(((i - 384)<<16) - oy) + (1<<31))>>32;
00739 j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
00740 table_Y[i] = j;
00741 }
00742
00743 switch (bpp) {
00744 case 32:
00745 table_start= table_32 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));
00746
00747 entry_size = sizeof (uint32_t);
00748 table_r = table_32 + 197;
00749 table_b = table_32 + 197 + 685;
00750 table_g = table_32 + 197 + 2*682;
00751
00752 for (i = -197; i < 256+197; i++)
00753 ((uint32_t *)table_r)[i] = table_Y[i+384] << (isRgb ? 16 : 0);
00754 for (i = -132; i < 256+132; i++)
00755 ((uint32_t *)table_g)[i] = table_Y[i+384] << 8;
00756 for (i = -232; i < 256+232; i++)
00757 ((uint32_t *)table_b)[i] = table_Y[i+384] << (isRgb ? 0 : 16);
00758 break;
00759
00760 case 24:
00761 table_start= table_8 = av_malloc ((256 + 2*232) * sizeof (uint8_t));
00762
00763 entry_size = sizeof (uint8_t);
00764 table_r = table_g = table_b = table_8 + 232;
00765
00766 for (i = -232; i < 256+232; i++)
00767 ((uint8_t * )table_b)[i] = table_Y[i+384];
00768 break;
00769
00770 case 15:
00771 case 16:
00772 table_start= table_16 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
00773
00774 entry_size = sizeof (uint16_t);
00775 table_r = table_16 + 197;
00776 table_b = table_16 + 197 + 685;
00777 table_g = table_16 + 197 + 2*682;
00778
00779 for (i = -197; i < 256+197; i++) {
00780 int j = table_Y[i+384] >> 3;
00781
00782 if (isRgb)
00783 j <<= ((bpp==16) ? 11 : 10);
00784
00785 ((uint16_t *)table_r)[i] = j;
00786 }
00787 for (i = -132; i < 256+132; i++) {
00788 int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);
00789
00790 ((uint16_t *)table_g)[i] = j << 5;
00791 }
00792 for (i = -232; i < 256+232; i++) {
00793 int j = table_Y[i+384] >> 3;
00794
00795 if (!isRgb)
00796 j <<= ((bpp==16) ? 11 : 10);
00797
00798 ((uint16_t *)table_b)[i] = j;
00799 }
00800 break;
00801
00802 case 8:
00803 table_start= table_332 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
00804
00805 entry_size = sizeof (uint8_t);
00806 table_r = table_332 + 197;
00807 table_b = table_332 + 197 + 685;
00808 table_g = table_332 + 197 + 2*682;
00809
00810 for (i = -197; i < 256+197; i++) {
00811 int j = (table_Y[i+384 - 16] + 18)/36;
00812
00813 if (isRgb)
00814 j <<= 5;
00815
00816 ((uint8_t *)table_r)[i] = j;
00817 }
00818 for (i = -132; i < 256+132; i++) {
00819 int j = (table_Y[i+384 - 16] + 18)/36;
00820
00821 if (!isRgb)
00822 j <<= 1;
00823
00824 ((uint8_t *)table_g)[i] = j << 2;
00825 }
00826 for (i = -232; i < 256+232; i++) {
00827 int j = (table_Y[i+384 - 37] + 43)/85;
00828
00829 if (!isRgb)
00830 j <<= 6;
00831
00832 ((uint8_t *)table_b)[i] = j;
00833 }
00834 break;
00835 case 4:
00836 case 4|128:
00837 table_start= table_121 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
00838
00839 entry_size = sizeof (uint8_t);
00840 table_r = table_121 + 197;
00841 table_b = table_121 + 197 + 685;
00842 table_g = table_121 + 197 + 2*682;
00843
00844 for (i = -197; i < 256+197; i++) {
00845 int j = table_Y[i+384 - 110] >> 7;
00846
00847 if (isRgb)
00848 j <<= 3;
00849
00850 ((uint8_t *)table_r)[i] = j;
00851 }
00852 for (i = -132; i < 256+132; i++) {
00853 int j = (table_Y[i+384 - 37]+ 43)/85;
00854
00855 ((uint8_t *)table_g)[i] = j << 1;
00856 }
00857 for (i = -232; i < 256+232; i++) {
00858 int j =table_Y[i+384 - 110] >> 7;
00859
00860 if (!isRgb)
00861 j <<= 3;
00862
00863 ((uint8_t *)table_b)[i] = j;
00864 }
00865 break;
00866
00867 case 1:
00868 table_start= table_1 = av_malloc (256*2 * sizeof (uint8_t));
00869
00870 entry_size = sizeof (uint8_t);
00871 table_g = table_1;
00872 table_r = table_b = NULL;
00873
00874 for (i = 0; i < 256+256; i++) {
00875 int j = table_Y[i + 384 - 110]>>7;
00876
00877 ((uint8_t *)table_g)[i] = j;
00878 }
00879 break;
00880
00881 default:
00882 table_start= NULL;
00883 av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp);
00884
00885 return -1;
00886 }
00887
00888 for (i = 0; i < 256; i++) {
00889 c->table_rV[i] = (uint8_t *)table_r + entry_size * div_round (crv * (i-128), 76309);
00890 c->table_gU[i] = (uint8_t *)table_g + entry_size * div_round (cgu * (i-128), 76309);
00891 c->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
00892 c->table_bU[i] = (uint8_t *)table_b + entry_size * div_round (cbu * (i-128), 76309);
00893 }
00894
00895 av_free(c->yuvTable);
00896 c->yuvTable= table_start;
00897 return 0;
00898 }