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