]> git.vomp.tv Git - vompclient.git/blob - surfacemvp.h
Preparations for dynamic mode switching
[vompclient.git] / surfacemvp.h
1 /*\r
2     Copyright 2004-2005 Chris Tallon\r
3     Portions copyright 2004 Jon Gettler\r
4 \r
5     This file is part of VOMP.\r
6 \r
7     VOMP is free software; you can redistribute it and/or modify\r
8     it under the terms of the GNU General Public License as published by\r
9     the Free Software Foundation; either version 2 of the License, or\r
10     (at your option) any later version.\r
11 \r
12     VOMP is distributed in the hope that it will be useful,\r
13     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15     GNU General Public License for more details.\r
16 \r
17     You should have received a copy of the GNU General Public License\r
18     along with VOMP; if not, write to the Free Software\r
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
20 */\r
21 \r
22 #ifndef SURFACEMVP_H\r
23 #define SURFACEMVP_H\r
24 \r
25 #include <stdio.h>\r
26 #include <string.h>\r
27 #include <unistd.h>\r
28 #include <sys/mman.h>\r
29 #include <sys/ioctl.h>\r
30 \r
31 extern "C"\r
32 {\r
33   #include <jpeglib.h>\r
34 }\r
35 \r
36 #include "defines.h"\r
37 #include "surface.h"\r
38 \r
39 // Structures for surface management\r
40 \r
41 typedef struct\r
42 {\r
43   unsigned long num;\r
44   unsigned long unknown[4];\r
45   unsigned long width;\r
46   unsigned long height;\r
47   char unknown2;\r
48 } stbgfx_display_t;\r
49 \r
50 typedef struct\r
51 {\r
52   unsigned long unknown;\r
53   unsigned long win_unknown;\r
54   unsigned long addr;\r
55   unsigned long size;\r
56   unsigned long unknown2;\r
57   unsigned long width;\r
58   unsigned long height;\r
59   unsigned long unknown3;\r
60   unsigned long unknown4;\r
61   unsigned long width2;\r
62   unsigned long unknown5;\r
63   unsigned long unknown6;\r
64 } stbgfx_map_item_t;\r
65 \r
66 typedef struct {\r
67   stbgfx_map_item_t map[3];\r
68   unsigned long other[2];\r
69 } stbgfx_map_t;\r
70 \r
71 typedef struct\r
72 {\r
73   unsigned long handle; /* surface handle */\r
74   unsigned long width;\r
75   unsigned long height;\r
76   unsigned long flags;\r
77   long unknown;   //unsigned long\r
78   unsigned long depth;  /* number of subplanes */\r
79 } stbgfx_sfc_t;\r
80 \r
81 typedef struct\r
82 {\r
83   stbgfx_display_t display;\r
84   stbgfx_map_t map;\r
85   stbgfx_sfc_t sfc;\r
86   unsigned char *base[3];\r
87 } osd_surface_t;\r
88 \r
89 \r
90 // Structures for surface drawing\r
91 \r
92 typedef struct\r
93 {\r
94   unsigned long handle;\r
95   unsigned long x;\r
96   unsigned long y;\r
97   unsigned long width;\r
98   unsigned long height;\r
99   unsigned long colour;\r
100 } osd_fillblt_t;\r
101 \r
102 typedef struct {\r
103   unsigned long dst_handle;\r
104   unsigned long dst_x;\r
105   unsigned long dst_y;\r
106   unsigned long width;\r
107   unsigned long height;\r
108   unsigned long src_handle;\r
109   unsigned long src_x;\r
110   unsigned long src_y;\r
111   unsigned long u1;\r
112   unsigned long u2;\r
113   unsigned char u3;\r
114 } osd_bitblt_t;\r
115 \r
116 // Surface ioctls\r
117 \r
118 #define GFX_FB_SFC_ALLOC  _IOWR(0xfb,1,int*)\r
119 #define GFX_FB_SFC_FREE   _IOW(0xfb,2,int)\r
120 #define GFX_FB_MAP    _IOWR(0xfb,3,int*)\r
121 #define GFX_FB_SFC_UNMAP  _IOW(0xfb,4,int)\r
122 #define GFX_FB_SET_PAL_1  _IOWR(0xfb,5,int*)\r
123 #define GFX_FB_SET_PAL_2  _IOW(0xfb,6,int*)\r
124 #define GFX_FB_OSD_SURFACE  _IO(0xfb,7)\r
125 #define GFX_FB_SFC_SET_SHARE  _IOW(0xfb,8,int)\r
126 #define GFX_FB_OSD_CUR_SETATTR  _IOW(0xfb,9,int*)\r
127 #define GFX_FB_ATTACH   _IOW(0xfb,11,int)\r
128 #define GFX_FB_SFC_DETACH _IOW(0xfb,12,int*)\r
129 #define GFX_FB_MOVE_DISPLAY _IOWR(0xfb,13,int)\r
130 #define GFX_FB_SET_DISPLAY  _IOW(0xfb,14,int)\r
131 #define GFX_FB_OSD_CUR_MOVE_1 _IOW(0xfb,15,int*)\r
132 #define GFX_FB_OSD_CUR_MOVE_2 _IOW(0xfb,16,int)\r
133 #define GFX_FB_SET_OSD    _IOW(0xfb,18,int)\r
134 #define GFX_FB_SET_DISP_CTRL  _IOW(0xfb,21,int*)\r
135 #define GFX_FB_GET_DISP_CTRL  _IOWR(0xfb,22,int*)\r
136 #define GFX_FB_SET_VIS_DEV_CTL  _IOWR(0xfb,23,int*)\r
137 #define GFX_FB_GET_VIS_DEV_CTL  _IOWR(0xfb,24,int*)\r
138 #define GFX_FB_OSD_BITBLT _IOW(0xfb,51,osd_bitblt_t*)\r
139 #define GFX_FB_OSD_FILLBLT  _IOW(0xfb,53,osd_fillblt_t*)\r
140 #define GFX_FB_OSD_ADVFILLBLT _IOW(0xfb,54,osd_afillblt_t*)\r
141 #define GFX_FB_OSD_BLEND  _IOW(0xfb,55,int*)\r
142 #define GFX_FB_OSD_ADVBLEND _IOW(0xfb,56,int*)\r
143 #define GFX_FB_OSD_RESIZE _IOW(0xfb,58,int*)\r
144 #define GFX_FB_ENGINE_WAIT  _IOW(0xfb,60,int)\r
145 #define GFX_FB_RESET_ENGINE _IO(0xfb,61)\r
146 #define GFX_FB_SET_ENGINE_MODE  _IOW(0xfb,62,int)\r
147 #define GFX_FB_GET_ENGINE_MODE  _IO(0xfb,63)\r
148 #define GFX_FB_GET_SFC_INFO _IO(0xfb,64,int*)\r
149 #define GFX_FB_OSD_SFC_CLIP _IOW(0xfb,65,osd_clip_rec_t*)\r
150 #define GFX_FB_OSD_COLOURKEY  _IOW(0xfb,67,int*)\r
151 #define GFX_FB_GET_SFC_PSEUDO _IOWR(0xfb,68,int*)\r
152 \r
153 class SurfaceMVP : public Surface\r
154 {\r
155   public:\r
156     SurfaceMVP(int id = 0);\r
157     virtual ~SurfaceMVP();\r
158 \r
159     int create(UINT width, UINT height);\r
160     void display();\r
161     unsigned long getSurfaceHandle();\r
162 \r
163     int fillblt(int x, int y, int width, int height, const DrawStyle& c);\r
164 \r
165     void drawHorzLine(int x1, int x2, int y, const DrawStyle& c);\r
166     void drawVertLine(int x, int y1, int y2, const DrawStyle& c);\r
167     void drawBitmap(int x, int y, const Bitmap& bm, const DisplayRegion& region);\r
168     int updateToScreen(int sx, int sy, int w, int h, int dx, int dy);\r
169     void readPixel(int x, int y, unsigned char* r, unsigned char* g, unsigned char* b);\r
170     void screenShot(const char* fileName);\r
171 \r
172     static void initConversionTables()\r
173     {\r
174       initConversionTables(100,100,100);\r
175     }\r
176     //init tables with factors for R,G,B - each in percent\r
177     static void initConversionTables(int r, int g, int b);\r
178 \r
179     int blt(int fd, unsigned long shandle, int sx, int sy, int width, int height, unsigned long dhandle, int dx, int dy);\r
180 \r
181   private:\r
182     int fdOsd;\r
183     osd_surface_t surface;\r
184 \r
185     void yuv2rgb(int y, int u, int v, unsigned char* pr, unsigned char* pg, unsigned char* pb);\r
186     /*\r
187      * rgb2yuv() - convert an RGB pixel to YUV\r
188      */\r
189     inline void rgb2yuv(unsigned char r, unsigned char g, unsigned char b, unsigned char *y, unsigned char *u, unsigned char *v)\r
190     {\r
191       int Y, U, V;\r
192 \r
193       Y = conv_YB[b] + conv_YG[g] + conv_YR[r];\r
194       U = conv_UB[b] + conv_UG[g] + conv_UR[r] + 128;\r
195       V = conv_VB[b] + conv_VG[g] + conv_VR[r] + 128;\r
196 \r
197       if (Y > 255)\r
198         Y = 255;\r
199       else if (Y < 0)\r
200         Y = 0;\r
201       if (U > 255)\r
202         U = 255;\r
203       else if (U < 0)\r
204         U = 0;\r
205       if (V > 255)\r
206         V = 255;\r
207       else if (V < 0)\r
208         V = 0;\r
209 \r
210       *y = Y;\r
211       *u = U;\r
212       *v = V;\r
213     }\r
214 \r
215 \r
216     // Implicit inlines\r
217     void c2rgba(unsigned long c, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)\r
218     {\r
219       *a = (c & 0xff000000) >> 24;\r
220       *r = (c & 0x00ff0000) >> 16;\r
221       *g = (c & 0x0000ff00) >> 8;\r
222       *b = (c & 0x000000ff);\r
223     }\r
224 \r
225     static int conv_YB[256];\r
226     static int conv_YG[256];\r
227     static int conv_YR[256];\r
228     static int conv_UB[256];\r
229     static int conv_UG[256];\r
230     static int conv_UR[256];\r
231     static int conv_VB[256];\r
232     static int conv_VG[256];\r
233     static int conv_VR[256];\r
234 \r
235     static int conv_BY[256];\r
236     static int conv_GY[256];\r
237     static int conv_RY[256];\r
238     static int conv_BU[256];\r
239     static int conv_GU[256];\r
240     static int conv_RU[256];\r
241     static int conv_BV[256];\r
242     static int conv_GV[256];\r
243     static int conv_RV[256];\r
244   protected:\r
245     void drawPixel(int x, int y, unsigned int c, bool fastdraw=false);\r
246     void drawPixel(int x, int y, Colour& c, bool fastdraw=false);\r
247 \r
248 };\r
249 \r
250 #endif\r