1 /*
2  * yuv2rgb.h
3  *
4  * Copyright (C) 2001-2018 the xine project
5  * This file is part of xine, a free video player.
6  *
7  * based on work from mpeg2dec:
8  * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
9  *
10  * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
11  *
12  * mpeg2dec is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * mpeg2dec is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
25  */
26 
27 #ifndef XINE_YUV2RGB_H
28 #define XINE_YUV2RGB_H
29 
30 #include <inttypes.h>
31 
32 #include <xine/attributes.h>
33 
34 typedef struct yuv2rgb_s yuv2rgb_t;
35 
36 typedef struct yuv2rgb_factory_s yuv2rgb_factory_t;
37 
38 /*
39  * function types for functions which can be replaced
40  * by hardware-accelerated versions
41  */
42 
43 typedef void (*yuv2rgb_fun_t) (yuv2rgb_t *this,
44                                uint8_t       *restrict image,
45                                const uint8_t *restrict py,
46                                const uint8_t *restrict pu,
47                                const uint8_t *restrict pv);
48 
49 typedef void (*yuy22rgb_fun_t) (yuv2rgb_t *this,
50                                 uint8_t       *restrict image,
51                                 const uint8_t *restrict p);
52 
53 typedef uint32_t (*yuv2rgb_single_pixel_fun_t) (yuv2rgb_t *this, uint8_t y, uint8_t u, uint8_t v);
54 
55 /*
56  * modes supported - feel free to implement yours
57  */
58 
59 #define MODE_8_RGB    1
60 #define MODE_8_BGR    2
61 #define MODE_15_RGB   3
62 #define MODE_15_BGR   4
63 #define MODE_16_RGB   5
64 #define MODE_16_BGR   6
65 #define MODE_24_RGB   7
66 #define MODE_24_BGR   8
67 #define MODE_32_RGB   9
68 #define MODE_32_BGR  10
69 #define MODE_8_GRAY  11
70 #define MODE_PALETTE 12
71 
72 /*
73  * colormatrix values - (mpeg_matrix_index << 1) | fullrange
74  */
75 
76 #define CM_DEFAULT   10
77 #define CM_SD        10
78 #define CM_HD         2
79 #define CM_FULLRANGE  1
80 
81 struct yuv2rgb_s {
82   /*
83    * configure converter for scaling factors
84    */
85   int (*configure) (yuv2rgb_t *this,
86                     int source_width, int source_height,
87                     int y_stride, int uv_stride,
88                     int dest_width, int dest_height,
89                     int rgb_stride);
90 
91   /*
92    * start a new field or frame if dest is NULL
93    */
94   int (*next_slice) (yuv2rgb_t *this, uint8_t **dest);
95 
96   /*
97    * free resources
98    */
99   void (*dispose) (yuv2rgb_t *this);
100 
101   /*
102    * this is the function to call for the yuv2rgb and scaling process
103    */
104   yuv2rgb_fun_t     yuv2rgb_fun;
105 
106   /*
107    * this is the function to call for the yuy2->rgb and scaling process
108    */
109   yuy22rgb_fun_t    yuy22rgb_fun;
110 
111   /*
112    * this is the function to call for the yuv2rgb for a single pixel
113    * (used for converting clut colors)
114    */
115 
116   yuv2rgb_single_pixel_fun_t yuv2rgb_single_pixel_fun;
117 };
118 
119 /*
120  * convenience class to easily create a lot of converters
121  */
122 
123 struct yuv2rgb_factory_s {
124   yuv2rgb_t* (*create_converter) (yuv2rgb_factory_t *this);
125 
126   /*
127    * set color space conversion levels
128    * for all converters produced by this factory
129    */
130   void (*set_csc_levels) (yuv2rgb_factory_t *this,
131     int brightness, int contrast, int saturation, int colormatrix);
132 
133   /*
134    * free resources
135    */
136   void (*dispose) (yuv2rgb_factory_t *this);
137 };
138 
139 yuv2rgb_factory_t *yuv2rgb_factory_init (int mode, int swapped, const uint8_t *colormap) XINE_PROTECTED;
140 
141 
142 #endif /* XINE_YUV2RGB_H */
143