OLD | NEW |
1 /* | 1 /* |
2 * software YUV to RGB converter | 2 * software YUV to RGB converter |
3 * | 3 * |
4 * Copyright (C) 2009 Konstantin Shishkov | 4 * Copyright (C) 2009 Konstantin Shishkov |
5 * | 5 * |
6 * 1,4,8bpp support and context / deglobalize stuff | 6 * 1,4,8bpp support and context / deglobalize stuff |
7 * by Michael Niedermayer (michaelni@gmx.at) | 7 * by Michael Niedermayer (michaelni@gmx.at) |
8 * | 8 * |
9 * This file is part of FFmpeg. | 9 * This file is part of FFmpeg. |
10 * | 10 * |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include <stdio.h> | 26 #include <stdio.h> |
27 #include <stdlib.h> | 27 #include <stdlib.h> |
28 #include <inttypes.h> | 28 #include <inttypes.h> |
29 #include <assert.h> | 29 #include <assert.h> |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "rgb2rgb.h" | 32 #include "rgb2rgb.h" |
33 #include "swscale.h" | 33 #include "swscale.h" |
34 #include "swscale_internal.h" | 34 #include "swscale_internal.h" |
35 #include "libavutil/x86_cpu.h" | 35 #include "libavutil/x86_cpu.h" |
| 36 #include "libavutil/bswap.h" |
36 | 37 |
| 38 extern const uint8_t dither_4x4_16[4][8]; |
37 extern const uint8_t dither_8x8_32[8][8]; | 39 extern const uint8_t dither_8x8_32[8][8]; |
38 extern const uint8_t dither_8x8_73[8][8]; | 40 extern const uint8_t dither_8x8_73[8][8]; |
39 extern const uint8_t dither_8x8_220[8][8]; | 41 extern const uint8_t dither_8x8_220[8][8]; |
40 | 42 |
41 const int32_t ff_yuv2rgb_coeffs[8][4] = { | 43 const int32_t ff_yuv2rgb_coeffs[8][4] = { |
42 {117504, 138453, 13954, 34903}, /* no sequence_display_extension */ | 44 {117504, 138453, 13954, 34903}, /* no sequence_display_extension */ |
43 {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */ | 45 {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */ |
44 {104597, 132201, 25675, 53279}, /* unspecified */ | 46 {104597, 132201, 25675, 53279}, /* unspecified */ |
45 {104597, 132201, 25675, 53279}, /* reserved */ | 47 {104597, 132201, 25675, 53279}, /* reserved */ |
46 {104448, 132798, 24759, 53109}, /* FCC */ | 48 {104448, 132798, 24759, 53109}, /* FCC */ |
47 {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */ | 49 {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */ |
48 {104597, 132201, 25675, 53279}, /* SMPTE 170M */ | 50 {104597, 132201, 25675, 53279}, /* SMPTE 170M */ |
49 {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */ | 51 {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */ |
50 }; | 52 }; |
51 | 53 |
| 54 const int *sws_getCoefficients(int colorspace) |
| 55 { |
| 56 if (colorspace > 7 || colorspace < 0) |
| 57 colorspace = SWS_CS_DEFAULT; |
| 58 return ff_yuv2rgb_coeffs[colorspace]; |
| 59 } |
| 60 |
52 #define LOADCHROMA(i) \ | 61 #define LOADCHROMA(i) \ |
53 U = pu[i]; \ | 62 U = pu[i]; \ |
54 V = pv[i]; \ | 63 V = pv[i]; \ |
55 r = (void *)c->table_rV[V]; \ | 64 r = (void *)c->table_rV[V]; \ |
56 g = (void *)(c->table_gU[U] + c->table_gV[V]); \ | 65 g = (void *)(c->table_gU[U] + c->table_gV[V]); \ |
57 b = (void *)c->table_bU[U]; | 66 b = (void *)c->table_bU[U]; |
58 | 67 |
59 #define PUTRGB(dst,src,i) \ | 68 #define PUTRGB(dst,src,i) \ |
60 Y = src[2*i]; \ | 69 Y = src[2*i]; \ |
61 dst[2*i ] = r[Y] + g[Y] + b[Y]; \ | 70 dst[2*i ] = r[Y] + g[Y] + b[Y]; \ |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 PUTRGB(dst_1,py_1,2); | 346 PUTRGB(dst_1,py_1,2); |
338 PUTRGB(dst_2,py_2,2); | 347 PUTRGB(dst_2,py_2,2); |
339 | 348 |
340 LOADCHROMA(3); | 349 LOADCHROMA(3); |
341 PUTRGB(dst_2,py_2,3); | 350 PUTRGB(dst_2,py_2,3); |
342 PUTRGB(dst_1,py_1,3); | 351 PUTRGB(dst_1,py_1,3); |
343 CLOSEYUV2RGBFUNC(8) | 352 CLOSEYUV2RGBFUNC(8) |
344 #endif | 353 #endif |
345 | 354 |
346 // r, g, b, dst_1, dst_2 | 355 // r, g, b, dst_1, dst_2 |
| 356 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0) |
| 357 const uint8_t *d16 = dither_4x4_16[y&3]; |
| 358 #define PUTRGB12(dst,src,i,o) \ |
| 359 Y = src[2*i]; \ |
| 360 dst[2*i] = r[Y+d16[0+o]] + g[Y+d16[0+o]] + b[Y+d16[0+o]]; \ |
| 361 Y = src[2*i+1]; \ |
| 362 dst[2*i+1] = r[Y+d16[1+o]] + g[Y+d16[1+o]] + b[Y+d16[1+o]]; |
| 363 |
| 364 LOADCHROMA(0); |
| 365 PUTRGB12(dst_1,py_1,0,0); |
| 366 PUTRGB12(dst_2,py_2,0,0+8); |
| 367 |
| 368 LOADCHROMA(1); |
| 369 PUTRGB12(dst_2,py_2,1,2+8); |
| 370 PUTRGB12(dst_1,py_1,1,2); |
| 371 |
| 372 LOADCHROMA(2); |
| 373 PUTRGB12(dst_1,py_1,2,4); |
| 374 PUTRGB12(dst_2,py_2,2,4+8); |
| 375 |
| 376 LOADCHROMA(3); |
| 377 PUTRGB12(dst_2,py_2,3,6+8); |
| 378 PUTRGB12(dst_1,py_1,3,6); |
| 379 CLOSEYUV2RGBFUNC(8) |
| 380 |
| 381 // r, g, b, dst_1, dst_2 |
347 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0) | 382 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0) |
348 const uint8_t *d32 = dither_8x8_32[y&7]; | 383 const uint8_t *d32 = dither_8x8_32[y&7]; |
349 const uint8_t *d64 = dither_8x8_73[y&7]; | 384 const uint8_t *d64 = dither_8x8_73[y&7]; |
350 #define PUTRGB8(dst,src,i,o) \ | 385 #define PUTRGB8(dst,src,i,o) \ |
351 Y = src[2*i]; \ | 386 Y = src[2*i]; \ |
352 dst[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \ | 387 dst[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \ |
353 Y = src[2*i+1]; \ | 388 Y = src[2*i+1]; \ |
354 dst[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]]; | 389 dst[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]]; |
355 | 390 |
356 LOADCHROMA(0); | 391 LOADCHROMA(0); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 case PIX_FMT_ARGB: | 573 case PIX_FMT_ARGB: |
539 case PIX_FMT_ABGR: if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT
_YUVA420P) return yuva2argb_c; | 574 case PIX_FMT_ABGR: if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT
_YUVA420P) return yuva2argb_c; |
540 case PIX_FMT_RGBA: | 575 case PIX_FMT_RGBA: |
541 case PIX_FMT_BGRA: return (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX
_FMT_YUVA420P) ? yuva2rgba_c : yuv2rgb_c_32; | 576 case PIX_FMT_BGRA: return (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX
_FMT_YUVA420P) ? yuva2rgba_c : yuv2rgb_c_32; |
542 case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb; | 577 case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb; |
543 case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr; | 578 case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr; |
544 case PIX_FMT_RGB565: | 579 case PIX_FMT_RGB565: |
545 case PIX_FMT_BGR565: | 580 case PIX_FMT_BGR565: |
546 case PIX_FMT_RGB555: | 581 case PIX_FMT_RGB555: |
547 case PIX_FMT_BGR555: return yuv2rgb_c_16; | 582 case PIX_FMT_BGR555: return yuv2rgb_c_16; |
| 583 case PIX_FMT_RGB444: |
| 584 case PIX_FMT_BGR444: return yuv2rgb_c_12_ordered_dither; |
548 case PIX_FMT_RGB8: | 585 case PIX_FMT_RGB8: |
549 case PIX_FMT_BGR8: return yuv2rgb_c_8_ordered_dither; | 586 case PIX_FMT_BGR8: return yuv2rgb_c_8_ordered_dither; |
550 case PIX_FMT_RGB4: | 587 case PIX_FMT_RGB4: |
551 case PIX_FMT_BGR4: return yuv2rgb_c_4_ordered_dither; | 588 case PIX_FMT_BGR4: return yuv2rgb_c_4_ordered_dither; |
552 case PIX_FMT_RGB4_BYTE: | 589 case PIX_FMT_RGB4_BYTE: |
553 case PIX_FMT_BGR4_BYTE: return yuv2rgb_c_4b_ordered_dither; | 590 case PIX_FMT_BGR4_BYTE: return yuv2rgb_c_4b_ordered_dither; |
554 case PIX_FMT_MONOBLACK: return yuv2rgb_c_1_ordered_dither; | 591 case PIX_FMT_MONOBLACK: return yuv2rgb_c_1_ordered_dither; |
555 default: | 592 default: |
556 assert(0); | 593 assert(0); |
557 } | 594 } |
(...skipping 24 matching lines...) Expand all Loading... |
582 cb += inc; | 619 cb += inc; |
583 } | 620 } |
584 } | 621 } |
585 | 622 |
586 av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int
fullRange, | 623 av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int
fullRange, |
587 int brightness, int contrast, int saturatio
n) | 624 int brightness, int contrast, int saturatio
n) |
588 { | 625 { |
589 const int isRgb = c->dstFormat==PIX_FMT_RGB32 | 626 const int isRgb = c->dstFormat==PIX_FMT_RGB32 |
590 || c->dstFormat==PIX_FMT_RGB32_1 | 627 || c->dstFormat==PIX_FMT_RGB32_1 |
591 || c->dstFormat==PIX_FMT_BGR24 | 628 || c->dstFormat==PIX_FMT_BGR24 |
592 || c->dstFormat==PIX_FMT_RGB565 | 629 || c->dstFormat==PIX_FMT_RGB565BE |
593 || c->dstFormat==PIX_FMT_RGB555 | 630 || c->dstFormat==PIX_FMT_RGB565LE |
| 631 || c->dstFormat==PIX_FMT_RGB555BE |
| 632 || c->dstFormat==PIX_FMT_RGB555LE |
| 633 || c->dstFormat==PIX_FMT_RGB444BE |
| 634 || c->dstFormat==PIX_FMT_RGB444LE |
594 || c->dstFormat==PIX_FMT_RGB8 | 635 || c->dstFormat==PIX_FMT_RGB8 |
595 || c->dstFormat==PIX_FMT_RGB4 | 636 || c->dstFormat==PIX_FMT_RGB4 |
596 || c->dstFormat==PIX_FMT_RGB4_BYTE | 637 || c->dstFormat==PIX_FMT_RGB4_BYTE |
597 || c->dstFormat==PIX_FMT_MONOBLACK; | 638 || c->dstFormat==PIX_FMT_MONOBLACK; |
| 639 const int isNotNe = c->dstFormat==PIX_FMT_NE(RGB565LE,RGB565BE) |
| 640 || c->dstFormat==PIX_FMT_NE(RGB555LE,RGB555BE) |
| 641 || c->dstFormat==PIX_FMT_NE(RGB444LE,RGB444BE) |
| 642 || c->dstFormat==PIX_FMT_NE(BGR565LE,BGR565BE) |
| 643 || c->dstFormat==PIX_FMT_NE(BGR555LE,BGR555BE) |
| 644 || c->dstFormat==PIX_FMT_NE(BGR444LE,BGR444BE); |
598 const int bpp = c->dstFormatBpp; | 645 const int bpp = c->dstFormatBpp; |
599 uint8_t *y_table; | 646 uint8_t *y_table; |
600 uint16_t *y_table16; | 647 uint16_t *y_table16; |
601 uint32_t *y_table32; | 648 uint32_t *y_table32; |
602 int i, base, rbase, gbase, bbase, abase, needAlpha; | 649 int i, base, rbase, gbase, bbase, abase, needAlpha; |
603 const int yoffs = fullRange ? 384 : 326; | 650 const int yoffs = fullRange ? 384 : 326; |
604 | 651 |
605 int64_t crv = inv_table[0]; | 652 int64_t crv = inv_table[0]; |
606 int64_t cbu = inv_table[1]; | 653 int64_t cbu = inv_table[1]; |
607 int64_t cgu = -inv_table[2]; | 654 int64_t cgu = -inv_table[2]; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 y_table[i+16 ] = ((yval + 18) / 36) << rbase; | 727 y_table[i+16 ] = ((yval + 18) / 36) << rbase; |
681 y_table[i+16+1024] = ((yval + 18) / 36) << gbase; | 728 y_table[i+16+1024] = ((yval + 18) / 36) << gbase; |
682 y_table[i+37+2048] = ((yval + 43) / 85) << bbase; | 729 y_table[i+37+2048] = ((yval + 43) / 85) << bbase; |
683 yb += cy; | 730 yb += cy; |
684 } | 731 } |
685 fill_table(c->table_rV, 1, crv, y_table + yoffs); | 732 fill_table(c->table_rV, 1, crv, y_table + yoffs); |
686 fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024); | 733 fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024); |
687 fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048); | 734 fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048); |
688 fill_gv_table(c->table_gV, 1, cgv); | 735 fill_gv_table(c->table_gV, 1, cgv); |
689 break; | 736 break; |
| 737 case 12: |
| 738 rbase = isRgb ? 8 : 0; |
| 739 gbase = 4; |
| 740 bbase = isRgb ? 0 : 8; |
| 741 c->yuvTable = av_malloc(1024*3*2); |
| 742 y_table16 = c->yuvTable; |
| 743 yb = -(384<<16) - oy; |
| 744 for (i = 0; i < 1024; i++) { |
| 745 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); |
| 746 y_table16[i ] = (yval >> 4) << rbase; |
| 747 y_table16[i+1024] = (yval >> 4) << gbase; |
| 748 y_table16[i+2048] = (yval >> 4) << bbase; |
| 749 yb += cy; |
| 750 } |
| 751 if (isNotNe) |
| 752 for (i = 0; i < 1024*3; i++) |
| 753 y_table16[i] = bswap_16(y_table16[i]); |
| 754 fill_table(c->table_rV, 2, crv, y_table16 + yoffs); |
| 755 fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024); |
| 756 fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048); |
| 757 fill_gv_table(c->table_gV, 2, cgv); |
| 758 break; |
690 case 15: | 759 case 15: |
691 case 16: | 760 case 16: |
692 rbase = isRgb ? bpp - 5 : 0; | 761 rbase = isRgb ? bpp - 5 : 0; |
693 gbase = 5; | 762 gbase = 5; |
694 bbase = isRgb ? 0 : (bpp - 5); | 763 bbase = isRgb ? 0 : (bpp - 5); |
695 c->yuvTable = av_malloc(1024*3*2); | 764 c->yuvTable = av_malloc(1024*3*2); |
696 y_table16 = c->yuvTable; | 765 y_table16 = c->yuvTable; |
697 yb = -(384<<16) - oy; | 766 yb = -(384<<16) - oy; |
698 for (i = 0; i < 1024; i++) { | 767 for (i = 0; i < 1024; i++) { |
699 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); | 768 uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); |
700 y_table16[i ] = (yval >> 3) << rbase; | 769 y_table16[i ] = (yval >> 3) << rbase; |
701 y_table16[i+1024] = (yval >> (18 - bpp)) << gbase; | 770 y_table16[i+1024] = (yval >> (18 - bpp)) << gbase; |
702 y_table16[i+2048] = (yval >> 3) << bbase; | 771 y_table16[i+2048] = (yval >> 3) << bbase; |
703 yb += cy; | 772 yb += cy; |
704 } | 773 } |
| 774 if(isNotNe) |
| 775 for (i = 0; i < 1024*3; i++) |
| 776 y_table16[i] = bswap_16(y_table16[i]); |
705 fill_table(c->table_rV, 2, crv, y_table16 + yoffs); | 777 fill_table(c->table_rV, 2, crv, y_table16 + yoffs); |
706 fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024); | 778 fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024); |
707 fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048); | 779 fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048); |
708 fill_gv_table(c->table_gV, 2, cgv); | 780 fill_gv_table(c->table_gV, 2, cgv); |
709 break; | 781 break; |
710 case 24: | 782 case 24: |
711 case 48: | 783 case 48: |
712 c->yuvTable = av_malloc(1024); | 784 c->yuvTable = av_malloc(1024); |
713 y_table = c->yuvTable; | 785 y_table = c->yuvTable; |
714 yb = -(384<<16) - oy; | 786 yb = -(384<<16) - oy; |
(...skipping 29 matching lines...) Expand all Loading... |
744 fill_table(c->table_bU, 4, cbu, y_table32 + yoffs + 2048); | 816 fill_table(c->table_bU, 4, cbu, y_table32 + yoffs + 2048); |
745 fill_gv_table(c->table_gV, 4, cgv); | 817 fill_gv_table(c->table_gV, 4, cgv); |
746 break; | 818 break; |
747 default: | 819 default: |
748 c->yuvTable = NULL; | 820 c->yuvTable = NULL; |
749 av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp); | 821 av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp); |
750 return -1; | 822 return -1; |
751 } | 823 } |
752 return 0; | 824 return 0; |
753 } | 825 } |
OLD | NEW |