summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/yuv2rgb.c
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/yuv2rgb.c') (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/yuv2rgb.c436
1 files changed, 273 insertions, 163 deletions
diff --git a/noncore/multimedia/opieplayer2/yuv2rgb.c b/noncore/multimedia/opieplayer2/yuv2rgb.c
index 8e34052..487ed20 100644
--- a/noncore/multimedia/opieplayer2/yuv2rgb.c
+++ b/noncore/multimedia/opieplayer2/yuv2rgb.c
@@ -2,5 +2,6 @@
2 * yuv2rgb.c 2 * yuv2rgb.c
3 * 3 *
4 * This file is part of xine, a unix video player. 4 * Copyright (C) 2003-2004 the xine project
5 * This file is part of xine, a free video player.
5 * 6 *
6 * based on work from mpeg2dec: 7 * based on work from mpeg2dec:
@@ -32,6 +33,12 @@
32 33
33#include "yuv2rgb.h" 34#include "yuv2rgb.h"
34#include <xine/xineutils.h>
35 35
36#define LOG_MODULE "yuv2rgb"
37#define LOG_VERBOSE
38/*
39#define LOG
40*/
41
42#include <xine/xineutils.h>
36 43
37static int prof_scale_line = -1; 44static int prof_scale_line = -1;
@@ -52,6 +59,6 @@ const int32_t Inverse_Table_6_9[8][4] = {
52 59
53 60
54static void *my_malloc_aligned (size_t alignment, size_t size, void **chunk) { 61static void *my_malloc_aligned (size_t alignment, size_t size, void **chunk)
55 62{
56 char *pMem; 63 char *pMem;
57 64
@@ -60,5 +67,5 @@ static void *my_malloc_aligned (size_t alignment, size_t size, void **chunk) {
60 *chunk = pMem; 67 *chunk = pMem;
61 68
62 while ((int) pMem % alignment) 69 while ((uintptr_t) pMem % alignment)
63 pMem++; 70 pMem++;
64 71
@@ -67,4 +74,41 @@ static void *my_malloc_aligned (size_t alignment, size_t size, void **chunk) {
67 74
68 75
76static int yuv2rgb_next_slice (yuv2rgb_t *this, uint8_t **dest)
77{
78 int y0, y1;
79
80 if (dest == NULL) {
81 this->slice_offset = 0;
82 this->slice_height = 16;
83 return 0;
84 }
85 if (this->slice_height == this->source_height) {
86 return this->dest_height;
87 }
88
89 y0 = (this->slice_offset * this->dest_height) / this->source_height;
90 y1 = ((this->slice_offset + this->slice_height) * this->dest_height) / this->source_height;
91 *dest += (this->rgb_stride * y0);
92
93 if ((this->slice_offset + this->slice_height) >= this->source_height) {
94 this->slice_offset = 0;
95 return (this->dest_height - y0);
96 } else {
97 this->slice_offset += this->slice_height;
98 return (y1 - y0);
99 }
100}
101
102static void yuv2rgb_dispose (yuv2rgb_t *this)
103{
104 free (this->y_chunk);
105 free (this->u_chunk);
106 free (this->v_chunk);
107#ifdef HAVE_MLIB
108 free (this->mlib_chunk);
109#endif
110 free (this);
111}
112
69static int yuv2rgb_configure (yuv2rgb_t *this, 113static int yuv2rgb_configure (yuv2rgb_t *this,
70 int source_width, int source_height, 114 int source_width, int source_height,
@@ -86,4 +130,6 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
86 this->dest_height = dest_height; 130 this->dest_height = dest_height;
87 this->rgb_stride = rgb_stride; 131 this->rgb_stride = rgb_stride;
132 this->slice_height = source_height;
133 this->slice_offset = 0;
88 134
89 if (this->y_chunk) { 135 if (this->y_chunk) {
@@ -100,8 +146,21 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
100 } 146 }
101 147
148#ifdef HAVE_MLIB
149 if (this->mlib_chunk) {
150 free (this->mlib_chunk);
151 this->mlib_buffer = this->mlib_chunk = NULL;
152 }
153 if (this->mlib_resize_chunk) {
154 free (this->mlib_resize_chunk);
155 this->mlib_resize_buffer = this->mlib_resize_chunk = NULL;
156 }
157#endif
102 158
103 this->step_dx = source_width * 32768 / dest_width; 159 this->step_dx = source_width * 32768 / dest_width;
104 this->step_dy = source_height * 32768 / dest_height; 160 this->step_dy = source_height * 32768 / dest_height;
105 161/*
162 printf("yuv2rgb config: src_ht=%i, dst_ht=%i\n",source_height, dest_height);
163 printf("yuv2rgb config: step_dy=%i %f\n",this->step_dy, (float)this->step_dy / 32768.0);
164*/
106 this->scale_line = find_scale_line_func(this->step_dx); 165 this->scale_line = find_scale_line_func(this->step_dx);
107 166
@@ -139,9 +198,21 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
139 if (!this->v_buffer) 198 if (!this->v_buffer)
140 return 0; 199 return 0;
200
201#if HAVE_MLIB
202 /* Only need these if we are resizing and in mlib code */
203 this->mlib_buffer = my_malloc_aligned (16, source_width*source_height*4, &this->mlib_chunk);
204 if (!this->mlib_buffer)
205 return 0;
206 /* Only need this one if we are 24 bit */
207 if((rgb_stride / dest_width) == 3) {
208 this->mlib_resize_buffer = my_malloc_aligned (16, dest_width*dest_height*4, &this->mlib_resize_chunk);
209 if (!this->mlib_resize_buffer)
210 return 0;
211 }
212 #endif
141 } 213 }
142 return 1; 214 return 1;
143} 215}
144 216
145
146static void scale_line_gen (uint8_t *source, uint8_t *dest, 217static void scale_line_gen (uint8_t *source, uint8_t *dest,
147 int width, int step) { 218 int width, int step) {
@@ -1205,14 +1276,27 @@ static scale_line_func_t find_scale_line_func(int step) {
1205 }; 1276 };
1206 int i; 1277 int i;
1278 #ifdefLOG
1279 /* to filter out multiple messages about the scale_line variant we're using */
1280 static int reported_for_step;
1281#endif
1207 1282
1208 for (i = 0; i < sizeof(scale_line)/sizeof(scale_line[0]); i++) { 1283 for (i = 0; i < sizeof(scale_line)/sizeof(scale_line[0]); i++) {
1209 if (step == scale_line[i].src_step*32768/scale_line[i].dest_step) { 1284 if (step == scale_line[i].src_step*32768/scale_line[i].dest_step) {
1210 //printf("yuv2rgb: using %s optimized scale_line\n", scale_line[i].desc); 1285 #ifdefLOG
1286 if (step != reported_for_step)
1287 printf("yuv2rgb: using %s optimized scale_line\n", scale_line[i].desc);
1288 reported_for_step = step;
1289#endif
1211 return scale_line[i].func; 1290 return scale_line[i].func;
1212 } 1291 }
1213 } 1292 }
1214 //printf("yuv2rgb: using generic scale_line with interpolation\n");
1215 return scale_line_gen;
1216 1293
1294 #ifdefLOG
1295 if (step != reported_for_step)
1296 printf("yuv2rgb: using generic scale_line with interpolation\n");
1297 reported_for_step = step;
1298#endif
1299
1300 return scale_line_gen;
1217} 1301}
1218 1302
@@ -1273,5 +1357,5 @@ static void scale_line_4 (uint8_t *source, uint8_t *dest,
1273 1357
1274 1358
1275 #define RGB(i) \ 1359 #define X_RGB(i) \
1276 U = pu[i]; \ 1360 U = pu[i]; \
1277 V = pv[i]; \ 1361 V = pv[i]; \
@@ -1349,5 +1433,5 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
1349 1433
1350 dy = 0; 1434 dy = 0;
1351 dst_height = this->dest_height; 1435 dst_height = this->next_slice (this, &_dst);
1352 1436
1353 for (height = 0;; ) { 1437 for (height = 0;; ) {
@@ -1360,14 +1444,14 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
1360 1444
1361 do { 1445 do {
1362 RGB(0); 1446 X_RGB(0);
1363 DST1(0); 1447 DST1(0);
1364 1448
1365 RGB(1); 1449 X_RGB(1);
1366 DST1(1); 1450 DST1(1);
1367 1451
1368 RGB(2); 1452 X_RGB(2);
1369 DST1(2); 1453 DST1(2);
1370 1454
1371 RGB(3); 1455 X_RGB(3);
1372 DST1(3); 1456 DST1(3);
1373 1457
@@ -1413,5 +1497,5 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
1413 } 1497 }
1414 } else { 1498 } else {
1415 height = this->source_height >> 1; 1499 height = this->next_slice (this, &_dst) >> 1;
1416 do { 1500 do {
1417 dst_1 = (uint32_t*)_dst; 1501 dst_1 = (uint32_t*)_dst;
@@ -1424,17 +1508,17 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
1424 width = this->source_width >> 3; 1508 width = this->source_width >> 3;
1425 do { 1509 do {
1426 RGB(0); 1510 X_RGB(0);
1427 DST1(0); 1511 DST1(0);
1428 DST2(0); 1512 DST2(0);
1429 1513
1430 RGB(1); 1514 X_RGB(1);
1431 DST2(1); 1515 DST2(1);
1432 DST1(1); 1516 DST1(1);
1433 1517
1434 RGB(2); 1518 X_RGB(2);
1435 DST1(2); 1519 DST1(2);
1436 DST2(2); 1520 DST2(2);
1437 1521
1438 RGB(3); 1522 X_RGB(3);
1439 DST2(3); 1523 DST2(3);
1440 DST1(3); 1524 DST1(3);
@@ -1480,5 +1564,5 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
1480 1564
1481 dy = 0; 1565 dy = 0;
1482 dst_height = this->dest_height; 1566 dst_height = this->next_slice (this, &_dst);
1483 1567
1484 for (height = 0;; ) { 1568 for (height = 0;; ) {
@@ -1491,14 +1575,14 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
1491 1575
1492 do { 1576 do {
1493 RGB(0); 1577 X_RGB(0);
1494 DST1RGB(0); 1578 DST1RGB(0);
1495 1579
1496 RGB(1); 1580 X_RGB(1);
1497 DST1RGB(1); 1581 DST1RGB(1);
1498 1582
1499 RGB(2); 1583 X_RGB(2);
1500 DST1RGB(2); 1584 DST1RGB(2);
1501 1585
1502 RGB(3); 1586 X_RGB(3);
1503 DST1RGB(3); 1587 DST1RGB(3);
1504 1588
@@ -1544,5 +1628,5 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
1544 } 1628 }
1545 } else { 1629 } else {
1546 height = this->source_height >> 1; 1630 height = this->next_slice (this, &_dst) >> 1;
1547 do { 1631 do {
1548 dst_1 = _dst; 1632 dst_1 = _dst;
@@ -1555,17 +1639,17 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
1555 width = this->source_width >> 3; 1639 width = this->source_width >> 3;
1556 do { 1640 do {
1557 RGB(0); 1641 X_RGB(0);
1558 DST1RGB(0); 1642 DST1RGB(0);
1559 DST2RGB(0); 1643 DST2RGB(0);
1560 1644
1561 RGB(1); 1645 X_RGB(1);
1562 DST2RGB(1); 1646 DST2RGB(1);
1563 DST1RGB(1); 1647 DST1RGB(1);
1564 1648
1565 RGB(2); 1649 X_RGB(2);
1566 DST1RGB(2); 1650 DST1RGB(2);
1567 DST2RGB(2); 1651 DST2RGB(2);
1568 1652
1569 RGB(3); 1653 X_RGB(3);
1570 DST2RGB(3); 1654 DST2RGB(3);
1571 DST1RGB(3); 1655 DST1RGB(3);
@@ -1611,5 +1695,5 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
1611 1695
1612 dy = 0; 1696 dy = 0;
1613 dst_height = this->dest_height; 1697 dst_height = this->next_slice (this, &_dst);
1614 1698
1615 for (height = 0;; ) { 1699 for (height = 0;; ) {
@@ -1622,14 +1706,14 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
1622 1706
1623 do { 1707 do {
1624 RGB(0); 1708 X_RGB(0);
1625 DST1BGR(0); 1709 DST1BGR(0);
1626 1710
1627 RGB(1); 1711 X_RGB(1);
1628 DST1BGR(1); 1712 DST1BGR(1);
1629 1713
1630 RGB(2); 1714 X_RGB(2);
1631 DST1BGR(2); 1715 DST1BGR(2);
1632 1716
1633 RGB(3); 1717 X_RGB(3);
1634 DST1BGR(3); 1718 DST1BGR(3);
1635 1719
@@ -1676,5 +1760,5 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
1676 1760
1677 } else { 1761 } else {
1678 height = this->source_height >> 1; 1762 height = this->next_slice (this, &_dst) >> 1;
1679 do { 1763 do {
1680 dst_1 = _dst; 1764 dst_1 = _dst;
@@ -1686,17 +1770,17 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
1686 width = this->source_width >> 3; 1770 width = this->source_width >> 3;
1687 do { 1771 do {
1688 RGB(0); 1772 X_RGB(0);
1689 DST1BGR(0); 1773 DST1BGR(0);
1690 DST2BGR(0); 1774 DST2BGR(0);
1691 1775
1692 RGB(1); 1776 X_RGB(1);
1693 DST2BGR(1); 1777 DST2BGR(1);
1694 DST1BGR(1); 1778 DST1BGR(1);
1695 1779
1696 RGB(2); 1780 X_RGB(2);
1697 DST1BGR(2); 1781 DST1BGR(2);
1698 DST2BGR(2); 1782 DST2BGR(2);
1699 1783
1700 RGB(3); 1784 X_RGB(3);
1701 DST2BGR(3); 1785 DST2BGR(3);
1702 DST1BGR(3); 1786 DST1BGR(3);
@@ -1742,5 +1826,5 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
1742 1826
1743 dy = 0; 1827 dy = 0;
1744 dst_height = this->dest_height; 1828 dst_height = this->next_slice (this, &_dst);
1745 1829
1746 for (height = 0;; ) { 1830 for (height = 0;; ) {
@@ -1753,14 +1837,14 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
1753 1837
1754 do { 1838 do {
1755 RGB(0); 1839 X_RGB(0);
1756 DST1(0); 1840 DST1(0);
1757 1841
1758 RGB(1); 1842 X_RGB(1);
1759 DST1(1); 1843 DST1(1);
1760 1844
1761 RGB(2); 1845 X_RGB(2);
1762 DST1(2); 1846 DST1(2);
1763 1847
1764 RGB(3); 1848 X_RGB(3);
1765 DST1(3); 1849 DST1(3);
1766 1850
@@ -1806,5 +1890,5 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
1806 } 1890 }
1807 } else { 1891 } else {
1808 height = this->source_height >> 1; 1892 height = this->next_slice (this, &_dst) >> 1;
1809 do { 1893 do {
1810 dst_1 = (uint16_t*)_dst; 1894 dst_1 = (uint16_t*)_dst;
@@ -1816,17 +1900,17 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
1816 width = this->source_width >> 3; 1900 width = this->source_width >> 3;
1817 do { 1901 do {
1818 RGB(0); 1902 X_RGB(0);
1819 DST1(0); 1903 DST1(0);
1820 DST2(0); 1904 DST2(0);
1821 1905
1822 RGB(1); 1906 X_RGB(1);
1823 DST2(1); 1907 DST2(1);
1824 DST1(1); 1908 DST1(1);
1825 1909
1826 RGB(2); 1910 X_RGB(2);
1827 DST1(2); 1911 DST1(2);
1828 DST2(2); 1912 DST2(2);
1829 1913
1830 RGB(3); 1914 X_RGB(3);
1831 DST2(3); 1915 DST2(3);
1832 DST1(3); 1916 DST1(3);
@@ -1872,5 +1956,5 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
1872 1956
1873 dy = 0; 1957 dy = 0;
1874 dst_height = this->dest_height; 1958 dst_height = this->next_slice (this, &_dst);
1875 1959
1876 for (height = 0;; ) { 1960 for (height = 0;; ) {
@@ -1883,14 +1967,14 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
1883 1967
1884 do { 1968 do {
1885 RGB(0); 1969 X_RGB(0);
1886 DST1(0); 1970 DST1(0);
1887 1971
1888 RGB(1); 1972 X_RGB(1);
1889 DST1(1); 1973 DST1(1);
1890 1974
1891 RGB(2); 1975 X_RGB(2);
1892 DST1(2); 1976 DST1(2);
1893 1977
1894 RGB(3); 1978 X_RGB(3);
1895 DST1(3); 1979 DST1(3);
1896 1980
@@ -1936,5 +2020,5 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
1936 } 2020 }
1937 } else { 2021 } else {
1938 height = this->source_height >> 1; 2022 height = this->next_slice (this, &_dst) >> 1;
1939 do { 2023 do {
1940 dst_1 = (uint8_t*)_dst; 2024 dst_1 = (uint8_t*)_dst;
@@ -1947,17 +2031,17 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
1947 width = this->source_width >> 3; 2031 width = this->source_width >> 3;
1948 do { 2032 do {
1949 RGB(0); 2033 X_RGB(0);
1950 DST1(0); 2034 DST1(0);
1951 DST2(0); 2035 DST2(0);
1952 2036
1953 RGB(1); 2037 X_RGB(1);
1954 DST2(1); 2038 DST2(1);
1955 DST1(1); 2039 DST1(1);
1956 2040
1957 RGB(2); 2041 X_RGB(2);
1958 DST1(2); 2042 DST1(2);
1959 DST2(2); 2043 DST2(2);
1960 2044
1961 RGB(3); 2045 X_RGB(3);
1962 DST2(3); 2046 DST2(3);
1963 DST1(3); 2047 DST1(3);
@@ -1991,5 +2075,5 @@ static void yuv2rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst,
1991 2075
1992 dy = 0; 2076 dy = 0;
1993 dst_height = this->dest_height; 2077 dst_height = this->next_slice (this, &_dst);
1994 2078
1995 for (;;) { 2079 for (;;) {
@@ -2017,5 +2101,5 @@ static void yuv2rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst,
2017 } 2101 }
2018 } else { 2102 } else {
2019 for (height = this->source_height; --height >= 0; ) { 2103 for (height = this->next_slice (this, &_dst); --height >= 0; ) {
2020 xine_fast_memcpy(_dst, _py, this->dest_width); 2104 xine_fast_memcpy(_dst, _py, this->dest_width);
2021 _dst += this->rgb_stride; 2105 _dst += this->rgb_stride;
@@ -2047,5 +2131,5 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
2047 2131
2048 dy = 0; 2132 dy = 0;
2049 dst_height = this->dest_height; 2133 dst_height = this->next_slice (this, &_dst);
2050 2134
2051 for (height = 0;; ) { 2135 for (height = 0;; ) {
@@ -2058,14 +2142,14 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
2058 2142
2059 do { 2143 do {
2060 RGB(0); 2144 X_RGB(0);
2061 DST1CMAP(0); 2145 DST1CMAP(0);
2062 2146
2063 RGB(1); 2147 X_RGB(1);
2064 DST1CMAP(1); 2148 DST1CMAP(1);
2065 2149
2066 RGB(2); 2150 X_RGB(2);
2067 DST1CMAP(2); 2151 DST1CMAP(2);
2068 2152
2069 RGB(3); 2153 X_RGB(3);
2070 DST1CMAP(3); 2154 DST1CMAP(3);
2071 2155
@@ -2111,5 +2195,5 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
2111 } 2195 }
2112 } else { 2196 } else {
2113 height = this->source_height >> 1; 2197 height = this->next_slice (this, &_dst) >> 1;
2114 do { 2198 do {
2115 dst_1 = _dst; 2199 dst_1 = _dst;
@@ -2121,17 +2205,17 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
2121 width = this->source_width >> 3; 2205 width = this->source_width >> 3;
2122 do { 2206 do {
2123 RGB(0); 2207 X_RGB(0);
2124 DST1CMAP(0); 2208 DST1CMAP(0);
2125 DST2CMAP(0); 2209 DST2CMAP(0);
2126 2210
2127 RGB(1); 2211 X_RGB(1);
2128 DST2CMAP(1); 2212 DST2CMAP(1);
2129 DST1CMAP(1); 2213 DST1CMAP(1);
2130 2214
2131 RGB(2); 2215 X_RGB(2);
2132 DST1CMAP(2); 2216 DST1CMAP(2);
2133 DST2CMAP(2); 2217 DST2CMAP(2);
2134 2218
2135 RGB(3); 2219 X_RGB(3);
2136 DST2CMAP(3); 2220 DST2CMAP(3);
2137 DST1CMAP(3); 2221 DST1CMAP(3);
@@ -2162,5 +2246,6 @@ static int div_round (int dividend, int divisor)
2162} 2246}
2163 2247
2164static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped) 2248static void yuv2rgb_set_csc_levels (yuv2rgb_factory_t *this,
2249 int brightness, int contrast, int saturation)
2165{ 2250{
2166 int i; 2251 int i;
@@ -2178,8 +2263,11 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2178 int cgv = -Inverse_Table_6_9[this->matrix_coefficients][3]; 2263 int cgv = -Inverse_Table_6_9[this->matrix_coefficients][3];
2179 2264
2265 int mode = this->mode;
2266 int swapped = this->swapped;
2267
2180 for (i = 0; i < 1024; i++) { 2268 for (i = 0; i < 1024; i++) {
2181 int j; 2269 int j;
2182 2270
2183 j = (76309 * (i - 384 - 16) + 32768) >> 16; 2271 j = (76309 * (i - 384 - 16 + brightness) + 32768) >> 16;
2184 j = (j < 0) ? 0 : ((j > 255) ? 255 : j); 2272 j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
2185 table_Y[i] = j; 2273 table_Y[i] = j;
@@ -2189,5 +2277,8 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2189 case MODE_32_RGB: 2277 case MODE_32_RGB:
2190 case MODE_32_BGR: 2278 case MODE_32_BGR:
2191 table_32 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t)); 2279 if (this->table_base == NULL) {
2280 this->table_base = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));
2281 }
2282 table_32 = this->table_base;
2192 2283
2193 entry_size = sizeof (uint32_t); 2284 entry_size = sizeof (uint32_t);
@@ -2218,5 +2309,8 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2218 case MODE_24_RGB: 2309 case MODE_24_RGB:
2219 case MODE_24_BGR: 2310 case MODE_24_BGR:
2220 table_8 = malloc ((256 + 2*232) * sizeof (uint8_t)); 2311 if (this->table_base == NULL) {
2312 this->table_base = malloc ((256 + 2*232) * sizeof (uint8_t));
2313 }
2314 table_8 = this->table_base;
2221 2315
2222 entry_size = sizeof (uint8_t); 2316 entry_size = sizeof (uint8_t);
@@ -2231,5 +2325,8 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2231 case MODE_15_RGB: 2325 case MODE_15_RGB:
2232 case MODE_16_RGB: 2326 case MODE_16_RGB:
2233 table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); 2327 if (this->table_base == NULL) {
2328 this->table_base = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
2329 }
2330 table_16 = this->table_base;
2234 2331
2235 entry_size = sizeof (uint16_t); 2332 entry_size = sizeof (uint16_t);
@@ -2271,5 +2368,8 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2271 case MODE_8_RGB: 2368 case MODE_8_RGB:
2272 case MODE_8_BGR: 2369 case MODE_8_BGR:
2273 table_8 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); 2370 if (this->table_base == NULL) {
2371 this->table_base = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
2372 }
2373 table_8 = this->table_base;
2274 2374
2275 entry_size = sizeof (uint8_t); 2375 entry_size = sizeof (uint8_t);
@@ -2295,5 +2395,8 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2295 2395
2296 case MODE_PALETTE: 2396 case MODE_PALETTE:
2297 table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); 2397 if (this->table_base == NULL) {
2398 this->table_base = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
2399 }
2400 table_16 = this->table_base;
2298 2401
2299 entry_size = sizeof (uint16_t); 2402 entry_size = sizeof (uint16_t);
@@ -2319,6 +2422,6 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2319 2422
2320 default: 2423 default:
2321 fprintf (stderr, "mode %d not supported by yuv2rgb\n", mode); 2424 lprintf ("mode %d not supported by yuv2rgb\n", mode);
2322 abort(); 2425 _x_abort();
2323 } 2426 }
2324 2427
@@ -2332,6 +2435,8 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2332 entry_size * div_round (cbu * (i-128), 76309)); 2435 entry_size * div_round (cbu * (i-128), 76309));
2333 } 2436 }
2334 this->gamma = 0; 2437
2335 this->entry_size = entry_size; 2438#if defined(ARCH_X86) || defined(ARCH_X86_64)
2439 mmx_yuv2rgb_set_csc_levels (this, brightness, contrast, saturation);
2440#endif
2336} 2441}
2337 2442
@@ -2449,6 +2554,6 @@ static void yuv2rgb_c_init (yuv2rgb_factory_t *this)
2449 2554
2450 default: 2555 default:
2451 printf ("yuv2rgb: mode %d not supported by yuv2rgb\n", this->mode); 2556 lprintf ("mode %d not supported by yuv2rgb\n", this->mode);
2452 abort(); 2557 _x_abort();
2453 } 2558 }
2454 2559
@@ -2492,6 +2597,6 @@ static void yuv2rgb_single_pixel_init (yuv2rgb_factory_t *this) {
2492 2597
2493 default: 2598 default:
2494 printf ("yuv2rgb: mode %d not supported by yuv2rgb\n", this->mode); 2599 lprintf ("mode %d not supported by yuv2rgb\n", this->mode);
2495 abort(); 2600 _x_abort();
2496 } 2601 }
2497} 2602}
@@ -2521,5 +2626,5 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2521 2626
2522 dy = 0; 2627 dy = 0;
2523 height = this->dest_height; 2628 height = this->next_slice (this, &_dst);
2524 2629
2525 for (;;) { 2630 for (;;) {
@@ -2533,14 +2638,14 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2533 do { 2638 do {
2534 2639
2535 RGB(0); 2640 X_RGB(0);
2536 DST1(0); 2641 DST1(0);
2537 2642
2538 RGB(1); 2643 X_RGB(1);
2539 DST1(1); 2644 DST1(1);
2540 2645
2541 RGB(2); 2646 X_RGB(2);
2542 DST1(2); 2647 DST1(2);
2543 2648
2544 RGB(3); 2649 X_RGB(3);
2545 DST1(3); 2650 DST1(3);
2546 2651
@@ -2565,5 +2670,5 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2565 break; 2670 break;
2566 2671
2567 _p += this->y_stride*2*(dy>>15); 2672 _p += this->y_stride*(dy>>15);
2568 dy &= 32767; 2673 dy &= 32767;
2569 /* 2674 /*
@@ -2600,5 +2705,5 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2600 2705
2601 dy = 0; 2706 dy = 0;
2602 height = this->dest_height; 2707 height = this->next_slice (this, &_dst);
2603 2708
2604 for (;;) { 2709 for (;;) {
@@ -2611,14 +2716,14 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2611 2716
2612 do { 2717 do {
2613 RGB(0); 2718 X_RGB(0);
2614 DST1RGB(0); 2719 DST1RGB(0);
2615 2720
2616 RGB(1); 2721 X_RGB(1);
2617 DST1RGB(1); 2722 DST1RGB(1);
2618 2723
2619 RGB(2); 2724 X_RGB(2);
2620 DST1RGB(2); 2725 DST1RGB(2);
2621 2726
2622 RGB(3); 2727 X_RGB(3);
2623 DST1RGB(3); 2728 DST1RGB(3);
2624 2729
@@ -2643,5 +2748,5 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2643 break; 2748 break;
2644 2749
2645 _p += this->y_stride*2*(dy>>15); 2750 _p += this->y_stride*(dy>>15);
2646 dy &= 32767; 2751 dy &= 32767;
2647 /* 2752 /*
@@ -2678,5 +2783,5 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2678 2783
2679 dy = 0; 2784 dy = 0;
2680 height = this->dest_height; 2785 height = this->next_slice (this, &_dst);
2681 2786
2682 for (;;) { 2787 for (;;) {
@@ -2689,14 +2794,14 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2689 2794
2690 do { 2795 do {
2691 RGB(0); 2796 X_RGB(0);
2692 DST1BGR(0); 2797 DST1BGR(0);
2693 2798
2694 RGB(1); 2799 X_RGB(1);
2695 DST1BGR(1); 2800 DST1BGR(1);
2696 2801
2697 RGB(2); 2802 X_RGB(2);
2698 DST1BGR(2); 2803 DST1BGR(2);
2699 2804
2700 RGB(3); 2805 X_RGB(3);
2701 DST1BGR(3); 2806 DST1BGR(3);
2702 2807
@@ -2721,5 +2826,5 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2721 break; 2826 break;
2722 2827
2723 _p += this->y_stride*2*(dy>>15); 2828 _p += this->y_stride*(dy>>15);
2724 dy &= 32767; 2829 dy &= 32767;
2725 2830
@@ -2752,5 +2857,5 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2752 2857
2753 dy = 0; 2858 dy = 0;
2754 height = this->dest_height; 2859 height = this->next_slice (this, &_dst);
2755 2860
2756 for (;;) { 2861 for (;;) {
@@ -2763,14 +2868,14 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2763 2868
2764 do { 2869 do {
2765 RGB(0); 2870 X_RGB(0);
2766 DST1(0); 2871 DST1(0);
2767 2872
2768 RGB(1); 2873 X_RGB(1);
2769 DST1(1); 2874 DST1(1);
2770 2875
2771 RGB(2); 2876 X_RGB(2);
2772 DST1(2); 2877 DST1(2);
2773 2878
2774 RGB(3); 2879 X_RGB(3);
2775 DST1(3); 2880 DST1(3);
2776 2881
@@ -2795,5 +2900,5 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2795 break; 2900 break;
2796 2901
2797 _p += this->y_stride*2*(dy>>15); 2902 _p += this->y_stride*(dy>>15);
2798 dy &= 32767; 2903 dy &= 32767;
2799 2904
@@ -2826,5 +2931,5 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2826 2931
2827 dy = 0; 2932 dy = 0;
2828 height = this->dest_height; 2933 height = this->next_slice (this, &_dst);
2829 2934
2830 for (;;) { 2935 for (;;) {
@@ -2837,14 +2942,14 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2837 2942
2838 do { 2943 do {
2839 RGB(0); 2944 X_RGB(0);
2840 DST1(0); 2945 DST1(0);
2841 2946
2842 RGB(1); 2947 X_RGB(1);
2843 DST1(1); 2948 DST1(1);
2844 2949
2845 RGB(2); 2950 X_RGB(2);
2846 DST1(2); 2951 DST1(2);
2847 2952
2848 RGB(3); 2953 X_RGB(3);
2849 DST1(3); 2954 DST1(3);
2850 2955
@@ -2869,5 +2974,5 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2869 break; 2974 break;
2870 2975
2871 _p += this->y_stride*2*(dy>>15); 2976 _p += this->y_stride*(dy>>15);
2872 dy &= 32767; 2977 dy &= 32767;
2873 2978
@@ -2890,5 +2995,5 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2890 if (this->do_scale) { 2995 if (this->do_scale) {
2891 dy = 0; 2996 dy = 0;
2892 height = this->dest_height; 2997 height = this->next_slice (this, &_dst);
2893 2998
2894 for (;;) { 2999 for (;;) {
@@ -2909,9 +3014,9 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2909 break; 3014 break;
2910 3015
2911 _p += this->y_stride*2*(dy>>15); 3016 _p += this->y_stride*(dy>>15);
2912 dy &= 32767; 3017 dy &= 32767;
2913 } 3018 }
2914 } else { 3019 } else {
2915 for (height = this->source_height; --height >= 0; ) { 3020 for (height = this->next_slice (this, &_dst); --height >= 0; ) {
2916 dst = _dst; 3021 dst = _dst;
2917 y = _p; 3022 y = _p;
@@ -2921,5 +3026,5 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2921 } 3026 }
2922 _dst += this->rgb_stride; 3027 _dst += this->rgb_stride;
2923 _p += this->y_stride*2; 3028 _p += this->y_stride;
2924 } 3029 }
2925 } 3030 }
@@ -2943,5 +3048,5 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2943 3048
2944 dy = 0; 3049 dy = 0;
2945 height = this->dest_height; 3050 height = this->next_slice (this, &_dst);
2946 3051
2947 for (;;) { 3052 for (;;) {
@@ -2954,14 +3059,14 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2954 3059
2955 do { 3060 do {
2956 RGB(0); 3061 X_RGB(0);
2957 DST1CMAP(0); 3062 DST1CMAP(0);
2958 3063
2959 RGB(1); 3064 X_RGB(1);
2960 DST1CMAP(1); 3065 DST1CMAP(1);
2961 3066
2962 RGB(2); 3067 X_RGB(2);
2963 DST1CMAP(2); 3068 DST1CMAP(2);
2964 3069
2965 RGB(3); 3070 X_RGB(3);
2966 DST1CMAP(3); 3071 DST1CMAP(3);
2967 3072
@@ -2986,5 +3091,5 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2986 break; 3091 break;
2987 3092
2988 _p += this->y_stride*2*(dy>>15); 3093 _p += this->y_stride*(dy>>15);
2989 dy &= 32767; 3094 dy &= 32767;
2990 3095
@@ -3034,12 +3139,13 @@ static void yuy22rgb_c_init (yuv2rgb_factory_t *this)
3034 3139
3035 default: 3140 default:
3036 printf ("yuv2rgb: mode %d not supported for yuy2\n", this->mode); 3141 lprintf ("mode %d not supported for yuy2\n", this->mode);
3037 } 3142 }
3038} 3143}
3039 3144
3040yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) { 3145static yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
3041 3146
3042 yuv2rgb_t *this = xine_xmalloc (sizeof (yuv2rgb_t)); 3147 yuv2rgb_t *this = xine_xmalloc (sizeof (yuv2rgb_t));
3043 3148
3149 this->swapped = factory->swapped;
3044 this->cmap = factory->cmap; 3150 this->cmap = factory->cmap;
3045 3151
@@ -3048,8 +3154,15 @@ yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
3048 this->v_chunk = this->v_buffer = NULL; 3154 this->v_chunk = this->v_buffer = NULL;
3049 3155
3156#ifdef HAVE_MLIB
3157 this->mlib_chunk = this->mlib_buffer = NULL;
3158 this->mlib_resize_chunk = this->mlib_resize_buffer = NULL;
3159 this->mlib_filter_type = MLIB_BILINEAR;
3160#endif
3161
3050 this->table_rV = factory->table_rV; 3162 this->table_rV = factory->table_rV;
3051 this->table_gU = factory->table_gU; 3163 this->table_gU = factory->table_gU;
3052 this->table_gV = factory->table_gV; 3164 this->table_gV = factory->table_gV;
3053 this->table_bU = factory->table_bU; 3165 this->table_bU = factory->table_bU;
3166 this->table_mmx = factory->table_mmx;
3054 3167
3055 this->yuv2rgb_fun = factory->yuv2rgb_fun; 3168 this->yuv2rgb_fun = factory->yuv2rgb_fun;
@@ -3058,4 +3171,6 @@ yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
3058 3171
3059 this->configure = yuv2rgb_configure; 3172 this->configure = yuv2rgb_configure;
3173 this->next_slice = yuv2rgb_next_slice;
3174 this->dispose = yuv2rgb_dispose;
3060 return this; 3175 return this;
3061} 3176}
@@ -3064,22 +3179,10 @@ yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
3064 * factory functions 3179 * factory functions
3065 */ 3180 */
3066void yuv2rgb_set_gamma (yuv2rgb_factory_t *this, int gamma) {
3067
3068 int i;
3069
3070 for (i = 0; i < 256; i++) {
3071 (uint8_t *)this->table_rV[i] += this->entry_size*(gamma - this->gamma);
3072 (uint8_t *)this->table_gU[i] += this->entry_size*(gamma - this->gamma);
3073 (uint8_t *)this->table_bU[i] += this->entry_size*(gamma - this->gamma);
3074 }
3075#ifdef ARCH_X86
3076 mmx_yuv2rgb_set_gamma(gamma);
3077#endif
3078 this->gamma = gamma;
3079}
3080 3181
3081int yuv2rgb_get_gamma (yuv2rgb_factory_t *this) { 3182static void yuv2rgb_factory_dispose (yuv2rgb_factory_t *this) {
3082 3183
3083 return this->gamma; 3184 free (this->table_base);
3185 free (this->table_mmx_base);
3186 free (this);
3084} 3187}
3085 3188
@@ -3088,8 +3191,5 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
3088 3191
3089 yuv2rgb_factory_t *this; 3192 yuv2rgb_factory_t *this;
3090
3091#ifdef ARCH_X86
3092 uint32_t mm = xine_mm_accel(); 3193 uint32_t mm = xine_mm_accel();
3093#endif
3094 3194
3095 this = malloc (sizeof (yuv2rgb_factory_t)); 3195 this = malloc (sizeof (yuv2rgb_factory_t));
@@ -3099,10 +3199,13 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
3099 this->cmap = cmap; 3199 this->cmap = cmap;
3100 this->create_converter = yuv2rgb_create_converter; 3200 this->create_converter = yuv2rgb_create_converter;
3101 this->set_gamma = yuv2rgb_set_gamma; 3201 this->set_csc_levels = yuv2rgb_set_csc_levels;
3102 this->get_gamma = yuv2rgb_get_gamma; 3202 this->dispose = yuv2rgb_factory_dispose;
3103 this->matrix_coefficients = 6; 3203 this->matrix_coefficients = 6;
3204 this->table_base = NULL;
3205 this->table_mmx = NULL;
3206 this->table_mmx_base = NULL;
3104 3207
3105 3208
3106 yuv2rgb_setup_tables (this, mode, swapped); 3209 yuv2rgb_set_csc_levels (this, 0, 128, 128);
3107 3210
3108 /* 3211 /*
@@ -3111,11 +3214,13 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
3111 3214
3112 this->yuv2rgb_fun = NULL; 3215 this->yuv2rgb_fun = NULL;
3113#ifdef ARCH_X86 3216#if defined(ARCH_X86) || defined(ARCH_X86_64)
3114 if ((this->yuv2rgb_fun == NULL) && (mm & MM_ACCEL_X86_MMXEXT)) { 3217 if ((this->yuv2rgb_fun == NULL) && (mm & MM_ACCEL_X86_MMXEXT)) {
3115 3218
3116 yuv2rgb_init_mmxext (this); 3219 yuv2rgb_init_mmxext (this);
3117 3220
3221#ifdef LOG
3118 if (this->yuv2rgb_fun != NULL) 3222 if (this->yuv2rgb_fun != NULL)
3119 printf ("yuv2rgb: using MMXEXT for colorspace transform\n"); 3223 printf ("yuv2rgb: using MMXEXT for colorspace transform\n");
3224#endif
3120 } 3225 }
3121 3226
@@ -3124,27 +3229,33 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
3124 yuv2rgb_init_mmx (this); 3229 yuv2rgb_init_mmx (this);
3125 3230
3231#ifdef LOG
3126 if (this->yuv2rgb_fun != NULL) 3232 if (this->yuv2rgb_fun != NULL)
3127 printf ("yuv2rgb: using MMX for colorspace transform\n"); 3233 printf ("yuv2rgb: using MMX for colorspace transform\n");
3234#endif
3128 } 3235 }
3236#ifdef __arm__
3237 if (this->yuv2rgb_fun == NULL) {
3238 yuv2rgb_init_arm ( this );
3239
3240 if(this->yuv2rgb_fun != NULL)
3241 printf("yuv2rgb: using arm4l assembler for colorspace transform\n" );
3242 }
3243#endif
3244
3129#endif 3245#endif
3130#if HAVE_MLIB 3246#if HAVE_MLIB
3131 if (this->yuv2rgb_fun == NULL) { 3247 if ((this->yuv2rgb_fun == NULL) && (mm & MM_ACCEL_MLIB)) {
3132 3248
3133 yuv2rgb_init_mlib (this); 3249 yuv2rgb_init_mlib (this);
3134 3250
3251#ifdef LOG
3135 if (this->yuv2rgb_fun != NULL) 3252 if (this->yuv2rgb_fun != NULL)
3136 printf ("yuv2rgb: using medialib for colorspace transform\n"); 3253 printf ("yuv2rgb: using medialib for colorspace transform\n");
3137 }
3138#endif 3254#endif
3139#ifdef __arm__
3140 if (this->yuv2rgb_fun == NULL) {
3141 yuv2rgb_init_arm ( this );
3142
3143 if(this->yuv2rgb_fun != NULL)
3144 printf("yuv2rgb: using arm4l assembler for colorspace transform\n" );
3145 } 3255 }
3146#endif 3256#endif
3147 if (this->yuv2rgb_fun == NULL) { 3257 if (this->yuv2rgb_fun == NULL) {
3148 printf ("yuv2rgb: no accelerated colorspace conversion found\n"); 3258 lprintf ("no accelerated colorspace conversion found\n");
3259
3149 yuv2rgb_c_init (this); 3260 yuv2rgb_c_init (this);
3150 } 3261 }
@@ -3165,3 +3276,2 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
3165 return this; 3276 return this;
3166} 3277}
3167