summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/yuv2rgb.c
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/yuv2rgb.c') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/yuv2rgb.c446
1 files changed, 278 insertions, 168 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
@@ -1,7 +1,8 @@
1/* 1/*
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:
7 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 8 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
@@ -31,8 +32,14 @@
31#include <inttypes.h> 32#include <inttypes.h>
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;
38 45
@@ -51,30 +58,67 @@ const int32_t Inverse_Table_6_9[8][4] = {
51}; 58};
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
58 pMem = xine_xmalloc (size+alignment); 65 pMem = xine_xmalloc (size+alignment);
59 66
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
65 return pMem; 72 return pMem;
66} 73}
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,
71 int y_stride, int uv_stride, 115 int y_stride, int uv_stride,
72 int dest_width, int dest_height, 116 int dest_width, int dest_height,
73 int rgb_stride) { 117 int rgb_stride) {
74 /* 118/*
75 printf ("yuv2rgb setup (%d x %d => %d x %d)\n", source_width, source_height, 119 printf ("yuv2rgb setup (%d x %d => %d x %d)\n", source_width, source_height,
76 dest_width, dest_height); 120 dest_width, dest_height);
77 */ 121 */
78 if (prof_scale_line == -1) 122 if (prof_scale_line == -1)
79 prof_scale_line = xine_profiler_allocate_slot("xshm scale line"); 123 prof_scale_line = xine_profiler_allocate_slot("xshm scale line");
80 124
@@ -85,7 +129,9 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
85 this->dest_width = dest_width; 129 this->dest_width = dest_width;
86 this->dest_height = dest_height; 130 this->dest_height = dest_height;
87 this->rgb_stride = rgb_stride; 131 this->rgb_stride = rgb_stride;
88 132 this->slice_height = source_height;
133 this->slice_offset = 0;
134
89 if (this->y_chunk) { 135 if (this->y_chunk) {
90 free (this->y_chunk); 136 free (this->y_chunk);
91 this->y_buffer = this->y_chunk = NULL; 137 this->y_buffer = this->y_chunk = NULL;
@@ -99,10 +145,23 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
99 this->v_buffer = this->v_chunk = NULL; 145 this->v_buffer = this->v_chunk = NULL;
100 } 146 }
101 147
102 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
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
108 if ((source_width == dest_width) && (source_height == dest_height)) { 167 if ((source_width == dest_width) && (source_height == dest_height)) {
@@ -138,11 +197,23 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
138 this->v_buffer = my_malloc_aligned (16, (dest_width+1)/2, &this->v_chunk); 197 this->v_buffer = my_malloc_aligned (16, (dest_width+1)/2, &this->v_chunk);
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) {
148 219
@@ -1204,16 +1275,29 @@ static scale_line_func_t find_scale_line_func(int step) {
1204 { 1, 1, scale_line_1_1, "non-scaled" }, 1275 { 1, 1, scale_line_1_1, "non-scaled" },
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
1219 1303
@@ -1272,7 +1356,7 @@ static void scale_line_4 (uint8_t *source, uint8_t *dest,
1272} 1356}
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]; \
1278 r = this->table_rV[V]; \ 1362 r = this->table_rV[V]; \
@@ -1348,7 +1432,7 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
1348 this->dest_width, this->step_dx); 1432 this->dest_width, this->step_dx);
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;; ) {
1354 dst_1 = (uint32_t*)_dst; 1438 dst_1 = (uint32_t*)_dst;
@@ -1359,16 +1443,16 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
1359 width = this->dest_width >> 3; 1443 width = this->dest_width >> 3;
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
1374 pu += 4; 1458 pu += 4;
@@ -1412,7 +1496,7 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
1412 } while( dy>=32768); 1496 } while( dy>=32768);
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;
1418 dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride ); 1502 dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride );
@@ -1423,19 +1507,19 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
1423 1507
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);
1441 1525
@@ -1479,7 +1563,7 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
1479 this->dest_width, this->step_dx); 1563 this->dest_width, this->step_dx);
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;; ) {
1485 dst_1 = _dst; 1569 dst_1 = _dst;
@@ -1490,16 +1574,16 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
1490 width = this->dest_width >> 3; 1574 width = this->dest_width >> 3;
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
1505 pu += 4; 1589 pu += 4;
@@ -1543,7 +1627,7 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
1543 } while (dy>=32768); 1627 } while (dy>=32768);
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;
1549 dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride ); 1633 dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride );
@@ -1554,19 +1638,19 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
1554 1638
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);
1572 1656
@@ -1610,7 +1694,7 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
1610 this->dest_width, this->step_dx); 1694 this->dest_width, this->step_dx);
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;; ) {
1616 dst_1 = _dst; 1700 dst_1 = _dst;
@@ -1621,16 +1705,16 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
1621 width = this->dest_width >> 3; 1705 width = this->dest_width >> 3;
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
1636 pu += 4; 1720 pu += 4;
@@ -1675,7 +1759,7 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
1675 } 1759 }
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;
1681 dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride ); 1765 dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride );
@@ -1685,19 +1769,19 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
1685 pv = _pv; 1769 pv = _pv;
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);
1703 1787
@@ -1741,7 +1825,7 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
1741 this->dest_width, this->step_dx); 1825 this->dest_width, this->step_dx);
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;; ) {
1747 dst_1 = (uint16_t*)_dst; 1831 dst_1 = (uint16_t*)_dst;
@@ -1752,16 +1836,16 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
1752 width = this->dest_width >> 3; 1836 width = this->dest_width >> 3;
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
1767 pu += 4; 1851 pu += 4;
@@ -1805,7 +1889,7 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
1805 } while( dy>=32768); 1889 } while( dy>=32768);
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;
1811 dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride ); 1895 dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride );
@@ -1815,19 +1899,19 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
1815 pv = _pv; 1899 pv = _pv;
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);
1833 1917
@@ -1871,7 +1955,7 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
1871 this->dest_width, this->step_dx); 1955 this->dest_width, this->step_dx);
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;; ) {
1877 dst_1 = (uint8_t*)_dst; 1961 dst_1 = (uint8_t*)_dst;
@@ -1882,16 +1966,16 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
1882 width = this->dest_width >> 3; 1966 width = this->dest_width >> 3;
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
1897 pu += 4; 1981 pu += 4;
@@ -1935,7 +2019,7 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
1935 } while( dy>=32768 ); 2019 } while( dy>=32768 );
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;
1941 dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride ); 2025 dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride );
@@ -1946,19 +2030,19 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
1946 2030
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);
1964 2048
@@ -1990,7 +2074,7 @@ static void yuv2rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst,
1990 scale_line_func_t scale_line = this->scale_line; 2074 scale_line_func_t scale_line = this->scale_line;
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 (;;) {
1996 scale_line (_py, _dst, this->dest_width, this->step_dx); 2080 scale_line (_py, _dst, this->dest_width, this->step_dx);
@@ -2016,7 +2100,7 @@ static void yuv2rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst,
2016 */ 2100 */
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;
2022 _py += this->y_stride; 2106 _py += this->y_stride;
@@ -2046,7 +2130,7 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
2046 this->dest_width, this->step_dx); 2130 this->dest_width, this->step_dx);
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;; ) {
2052 dst_1 = _dst; 2136 dst_1 = _dst;
@@ -2057,16 +2141,16 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
2057 width = this->dest_width >> 3; 2141 width = this->dest_width >> 3;
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
2072 pu += 4; 2156 pu += 4;
@@ -2110,7 +2194,7 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
2110 } while( dy>=32768 ); 2194 } while( dy>=32768 );
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;
2116 dst_2 = _dst + this->rgb_stride; 2200 dst_2 = _dst + this->rgb_stride;
@@ -2120,19 +2204,19 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
2120 pv = _pv; 2204 pv = _pv;
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);
2138 2222
@@ -2161,7 +2245,8 @@ static int div_round (int dividend, int divisor)
2161 return -((-dividend + (divisor>>1)) / divisor); 2245 return -((-dividend + (divisor>>1)) / 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;
2167 uint8_t table_Y[1024]; 2252 uint8_t table_Y[1024];
@@ -2177,10 +2262,13 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2177 int cgu = -Inverse_Table_6_9[this->matrix_coefficients][2]; 2262 int cgu = -Inverse_Table_6_9[this->matrix_coefficients][2];
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;
2186 } 2274 }
@@ -2188,7 +2276,10 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2188 switch (mode) { 2276 switch (mode) {
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);
2194 table_r = table_32 + 197; 2285 table_r = table_32 + 197;
@@ -2217,7 +2308,10 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2217 2308
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);
2223 table_r = table_g = table_b = table_8 + 232; 2317 table_r = table_g = table_b = table_8 + 232;
@@ -2230,7 +2324,10 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2230 case MODE_16_BGR: 2324 case MODE_16_BGR:
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);
2236 table_r = table_16 + 197; 2333 table_r = table_16 + 197;
@@ -2270,7 +2367,10 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2270 2367
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);
2276 table_r = table_8 + 197; 2376 table_r = table_8 + 197;
@@ -2294,7 +2394,10 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2294 return; 2394 return;
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);
2300 table_r = table_16 + 197; 2403 table_r = table_16 + 197;
@@ -2318,8 +2421,8 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2318 2421
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
2325 for (i = 0; i < 256; i++) { 2428 for (i = 0; i < 256; i++) {
@@ -2331,8 +2434,10 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
2331 this->table_bU[i] = (((uint8_t *)table_b) + 2434 this->table_bU[i] = (((uint8_t *)table_b) +
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
2338static uint32_t yuv2rgb_single_pixel_32 (yuv2rgb_t *this, uint8_t y, uint8_t u, uint8_t v) 2443static uint32_t yuv2rgb_single_pixel_32 (yuv2rgb_t *this, uint8_t y, uint8_t u, uint8_t v)
@@ -2448,8 +2553,8 @@ static void yuv2rgb_c_init (yuv2rgb_factory_t *this)
2448 break; 2553 break;
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
2455} 2560}
@@ -2491,8 +2596,8 @@ static void yuv2rgb_single_pixel_init (yuv2rgb_factory_t *this) {
2491 break; 2596 break;
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}
2498 2603
@@ -2520,7 +2625,7 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2520 this->dest_width, this->step_dx); 2625 this->dest_width, this->step_dx);
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 (;;) {
2526 dst_1 = (uint32_t*)_dst; 2631 dst_1 = (uint32_t*)_dst;
@@ -2532,16 +2637,16 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2532 2637
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
2547 pu += 4; 2652 pu += 4;
@@ -2564,7 +2669,7 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2564 if (height <= 0) 2669 if (height <= 0)
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 /*
2570 dy -= 32768; 2675 dy -= 32768;
@@ -2599,7 +2704,7 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2599 this->dest_width, this->step_dx); 2704 this->dest_width, this->step_dx);
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 (;;) {
2605 dst_1 = _dst; 2710 dst_1 = _dst;
@@ -2610,16 +2715,16 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2610 width = this->dest_width >> 3; 2715 width = this->dest_width >> 3;
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
2625 pu += 4; 2730 pu += 4;
@@ -2642,7 +2747,7 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2642 if (height <= 0) 2747 if (height <= 0)
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 /*
2648 dy -= 32768; 2753 dy -= 32768;
@@ -2677,7 +2782,7 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2677 this->dest_width, this->step_dx); 2782 this->dest_width, this->step_dx);
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 (;;) {
2683 dst_1 = _dst; 2788 dst_1 = _dst;
@@ -2688,16 +2793,16 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2688 width = this->dest_width >> 3; 2793 width = this->dest_width >> 3;
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
2703 pu += 4; 2808 pu += 4;
@@ -2720,7 +2825,7 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2720 if (height <= 0) 2825 if (height <= 0)
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
2726 scale_line_4 (_p+1, this->u_buffer, 2831 scale_line_4 (_p+1, this->u_buffer,
@@ -2751,7 +2856,7 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2751 this->dest_width, this->step_dx); 2856 this->dest_width, this->step_dx);
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 (;;) {
2757 dst_1 = (uint16_t*)_dst; 2862 dst_1 = (uint16_t*)_dst;
@@ -2762,16 +2867,16 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2762 width = this->dest_width >> 3; 2867 width = this->dest_width >> 3;
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
2777 pu += 4; 2882 pu += 4;
@@ -2794,7 +2899,7 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2794 if (height <= 0) 2899 if (height <= 0)
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
2800 scale_line_4 (_p+1, this->u_buffer, 2905 scale_line_4 (_p+1, this->u_buffer,
@@ -2825,7 +2930,7 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2825 this->dest_width, this->step_dx); 2930 this->dest_width, this->step_dx);
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 (;;) {
2831 dst_1 = _dst; 2936 dst_1 = _dst;
@@ -2836,16 +2941,16 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2836 width = this->dest_width >> 3; 2941 width = this->dest_width >> 3;
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
2851 pu += 4; 2956 pu += 4;
@@ -2868,7 +2973,7 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2868 if (height <= 0) 2973 if (height <= 0)
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
2874 scale_line_4 (_p+1, this->u_buffer, 2979 scale_line_4 (_p+1, this->u_buffer,
@@ -2889,7 +2994,7 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2889 2994
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 (;;) {
2895 scale_line_2 (_p, _dst, this->dest_width, this->step_dx); 3000 scale_line_2 (_p, _dst, this->dest_width, this->step_dx);
@@ -2908,11 +3013,11 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2908 if (height <= 0) 3013 if (height <= 0)
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;
2918 for (width = this->source_width; --width >= 0; ) { 3023 for (width = this->source_width; --width >= 0; ) {
@@ -2920,7 +3025,7 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2920 y += 2; 3025 y += 2;
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 }
2926} 3031}
@@ -2942,7 +3047,7 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2942 this->dest_width, this->step_dx); 3047 this->dest_width, this->step_dx);
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 (;;) {
2948 dst_1 = _dst; 3053 dst_1 = _dst;
@@ -2953,16 +3058,16 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2953 width = this->dest_width >> 3; 3058 width = this->dest_width >> 3;
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
2968 pu += 4; 3073 pu += 4;
@@ -2985,7 +3090,7 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
2985 if (height <= 0) 3090 if (height <= 0)
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
2991 scale_line_4 (_p+1, this->u_buffer, 3096 scale_line_4 (_p+1, this->u_buffer,
@@ -3033,64 +3138,59 @@ static void yuy22rgb_c_init (yuv2rgb_factory_t *this)
3033 break; 3138 break;
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
3046 this->y_chunk = this->y_buffer = NULL; 3152 this->y_chunk = this->y_buffer = NULL;
3047 this->u_chunk = this->u_buffer = NULL; 3153 this->u_chunk = this->u_buffer = NULL;
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;
3056 this->yuy22rgb_fun = factory->yuy22rgb_fun; 3169 this->yuy22rgb_fun = factory->yuy22rgb_fun;
3057 this->yuv2rgb_single_pixel_fun = factory->yuv2rgb_single_pixel_fun; 3170 this->yuv2rgb_single_pixel_fun = factory->yuv2rgb_single_pixel_fun;
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}
3062 3177
3063/* 3178/*
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
3086yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped, 3189yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
3087 uint8_t *cmap) { 3190 uint8_t *cmap) {
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));
3096 3196
@@ -3098,54 +3198,65 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
3098 this->swapped = swapped; 3198 this->swapped = 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 /*
3109 * auto-probe for the best yuv2rgb function 3212 * auto-probe for the best yuv2rgb function
3110 */ 3213 */
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
3122 if ((this->yuv2rgb_fun == NULL) && (mm & MM_ACCEL_X86_MMX)) { 3227 if ((this->yuv2rgb_fun == NULL) && (mm & MM_ACCEL_X86_MMX)) {
3123 3228
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
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" );
3128 } 3242 }
3129#endif 3243#endif
3244
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 }
3151 3262
@@ -3164,4 +3275,3 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
3164 3275
3165 return this; 3276 return this;
3166} 3277}
3167