1 //Copyright Paul Reiche, Fred Ford. 1992-2002
2 
3 /*
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 #ifndef TFB_DRAW_H
20 #define TFB_DRAW_H
21 
22 #include "libs/threadlib.h"
23 
24 
25 typedef void *TFB_Canvas;
26 
27 typedef enum {
28 	TFB_SCREEN_MAIN,
29 	TFB_SCREEN_EXTRA,
30 	TFB_SCREEN_TRANSITION,
31 
32 	TFB_GFX_NUMSCREENS
33 } SCREEN;
34 
35 #include "libs/graphics/gfx_common.h"
36 #include "libs/graphics/cmap.h"
37 
38 typedef struct tfb_image
39 {
40 	TFB_Canvas NormalImg;
41 	TFB_Canvas ScaledImg;
42 	TFB_Canvas MipmapImg;
43 	TFB_Canvas FilledImg;
44 	int colormap_index;
45 	int colormap_version;
46 	HOT_SPOT NormalHs;
47 	HOT_SPOT MipmapHs;
48 	HOT_SPOT last_scale_hs;
49 	int last_scale;
50 	int last_scale_type;
51 	Color last_fill;
52 	EXTENT extent;
53 	Mutex mutex;
54 	BOOLEAN dirty;
55 } TFB_Image;
56 
57 typedef struct tfb_char
58 {
59 	EXTENT extent;
60 	EXTENT disp;
61 		// Display extent
62 	HOT_SPOT HotSpot;
63 	BYTE* data;
64 	DWORD pitch;
65 		// Pitch is for storing all chars of a page
66 		// in one rectangular pixel matrix
67 } TFB_Char;
68 
69 // we do not support paletted format for now
70 typedef struct tfb_pixelformat
71 {
72 	int BitsPerPixel;
73 	int BytesPerPixel;
74 	DWORD Rmask, Gmask, Bmask, Amask;
75 	DWORD Rshift, Gshift, Bshift, Ashift;
76 	DWORD Rloss, Gloss, Bloss, Aloss;
77 } TFB_PixelFormat;
78 
79 // Drawing commands
80 
81 void TFB_DrawScreen_Line (int x1, int y1, int x2, int y2, Color color,
82 		DrawMode, SCREEN dest);
83 void TFB_DrawScreen_Rect (RECT *rect, Color, DrawMode, SCREEN dest);
84 void TFB_DrawScreen_Image (TFB_Image *img, int x, int y, int scale,
85 		int scaleMode, TFB_ColorMap *, DrawMode, SCREEN dest);
86 void TFB_DrawScreen_Copy (const RECT *r, SCREEN src, SCREEN dest);
87 void TFB_DrawScreen_FilledImage (TFB_Image *img, int x, int y, int scale,
88 		int scaleMode, Color, DrawMode, SCREEN dest);
89 void TFB_DrawScreen_FontChar (TFB_Char *, TFB_Image *backing, int x, int y,
90 		DrawMode, SCREEN dest);
91 
92 void TFB_DrawScreen_CopyToImage (TFB_Image *img, const RECT *r, SCREEN src);
93 void TFB_DrawScreen_SetMipmap (TFB_Image *img, TFB_Image *mmimg, int hotx,
94 		int hoty);
95 void TFB_DrawScreen_DeleteImage (TFB_Image *img);
96 void TFB_DrawScreen_DeleteData (void *);
97 void TFB_DrawScreen_WaitForSignal (void);
98 void TFB_DrawScreen_ReinitVideo (int driver, int flags, int width, int height);
99 void TFB_DrawScreen_Callback (void (*callback) (void *arg), void *arg);
100 
101 TFB_Image *TFB_DrawImage_New (TFB_Canvas canvas);
102 TFB_Image *TFB_DrawImage_CreateForScreen (int w, int h, BOOLEAN withalpha);
103 TFB_Image *TFB_DrawImage_New_Rotated (TFB_Image *img, int angle);
104 void TFB_DrawImage_SetMipmap (TFB_Image *img, TFB_Image *mmimg, int hotx,
105 		int hoty);
106 void TFB_DrawImage_Delete (TFB_Image *image);
107 void TFB_DrawImage_FixScaling (TFB_Image *image, int target, int type);
108 BOOLEAN TFB_DrawImage_Intersect (TFB_Image *img1, POINT img1org,
109 		TFB_Image *img2, POINT img2org, const RECT *interRect);
110 void TFB_DrawImage_CopyRect (TFB_Image *source, const RECT *srcRect,
111 		TFB_Image *target, POINT dstPt);
112 
113 void TFB_DrawImage_Line (int x1, int y1, int x2, int y2, Color color,
114 		DrawMode, TFB_Image *target);
115 void TFB_DrawImage_Rect (RECT *rect, Color, DrawMode, TFB_Image *target);
116 void TFB_DrawImage_Image (TFB_Image *img, int x, int y, int scale,
117 		int scaleMode, TFB_ColorMap *, DrawMode, TFB_Image *target);
118 void TFB_DrawImage_FilledImage (TFB_Image *img, int x, int y, int scale,
119 		int scaleMode, Color, DrawMode, TFB_Image *target);
120 void TFB_DrawImage_FontChar (TFB_Char *, TFB_Image *backing, int x, int y,
121 		DrawMode, TFB_Image *target);
122 
123 TFB_Canvas TFB_DrawCanvas_LoadFromFile (void *dir, const char *fileName);
124 TFB_Canvas TFB_DrawCanvas_New_TrueColor (int w, int h, BOOLEAN hasalpha);
125 TFB_Canvas TFB_DrawCanvas_New_ForScreen (int w, int h, BOOLEAN withalpha);
126 TFB_Canvas TFB_DrawCanvas_New_Paletted (int w, int h, Color palette[256],
127 		int transparent_index);
128 TFB_Canvas TFB_DrawCanvas_New_ScaleTarget (TFB_Canvas canvas,
129 		TFB_Canvas oldcanvas, int type, int last_type);
130 TFB_Canvas TFB_DrawCanvas_New_RotationTarget (TFB_Canvas src, int angle);
131 TFB_Canvas TFB_DrawCanvas_ToScreenFormat (TFB_Canvas canvas);
132 BOOLEAN TFB_DrawCanvas_IsPaletted (TFB_Canvas canvas);
133 void TFB_DrawCanvas_Rescale_Nearest (TFB_Canvas src, TFB_Canvas dst,
134 		int scale, HOT_SPOT* src_hs, EXTENT* size, HOT_SPOT* dst_hs);
135 void TFB_DrawCanvas_Rescale_Bilinear (TFB_Canvas src, TFB_Canvas dst,
136 		int scale, HOT_SPOT* src_hs, EXTENT* size, HOT_SPOT* dst_hs);
137 void TFB_DrawCanvas_Rescale_Trilinear (TFB_Canvas src, TFB_Canvas mipmap,
138 		TFB_Canvas dst, int scale, HOT_SPOT* src_hs, HOT_SPOT* mm_hs,
139 		EXTENT* size, HOT_SPOT* dst_hs);
140 void TFB_DrawCanvas_GetScaledExtent (TFB_Canvas src_canvas, HOT_SPOT* src_hs,
141 		TFB_Canvas src_mipmap, HOT_SPOT* mm_hs,
142 		int scale, int type, EXTENT *size, HOT_SPOT *hs);
143 void TFB_DrawCanvas_Rotate (TFB_Canvas src, TFB_Canvas dst, int angle,
144 		EXTENT size);
145 void TFB_DrawCanvas_GetRotatedExtent (TFB_Canvas src, int angle, EXTENT *size);
146 void TFB_DrawCanvas_GetExtent (TFB_Canvas canvas, EXTENT *size);
147 void TFB_DrawCanvas_SetClipRect (TFB_Canvas canvas, const RECT *clipRect);
148 
149 void TFB_DrawCanvas_Delete (TFB_Canvas canvas);
150 
151 void TFB_DrawCanvas_Line (int x1, int y1, int x2, int y2, Color color,
152 		DrawMode, TFB_Canvas target);
153 void TFB_DrawCanvas_Rect (RECT *rect, Color, DrawMode, TFB_Canvas target);
154 void TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, int scale,
155 		int scaleMode, TFB_ColorMap *, DrawMode, TFB_Canvas target);
156 void TFB_DrawCanvas_FilledImage (TFB_Image *img, int x, int y, int scale,
157 		int scaleMode, Color, DrawMode, TFB_Canvas target);
158 void TFB_DrawCanvas_FontChar (TFB_Char *, TFB_Image *backing, int x, int y,
159 		DrawMode, TFB_Canvas target);
160 void TFB_DrawCanvas_CopyRect (TFB_Canvas source, const RECT *srcRect,
161 		TFB_Canvas target, POINT dstPt);
162 
163 BOOLEAN TFB_DrawCanvas_GetFontCharData (TFB_Canvas canvas, BYTE *outData,
164 		unsigned dataPitch);
165 Color *TFB_DrawCanvas_ExtractPalette (TFB_Canvas canvas);
166 void TFB_DrawCanvas_SetPalette (TFB_Canvas target, Color palette[256]);
167 int TFB_DrawCanvas_GetTransparentIndex (TFB_Canvas canvas);
168 void TFB_DrawCanvas_SetTransparentIndex (TFB_Canvas canvas, int i,
169 		BOOLEAN rleaccel);
170 BOOLEAN TFB_DrawCanvas_GetTransparentColor (TFB_Canvas canvas,
171 		Color *color);
172 void TFB_DrawCanvas_SetTransparentColor (TFB_Canvas canvas,
173 		Color color, BOOLEAN rleaccel);
174 void TFB_DrawCanvas_CopyTransparencyInfo (TFB_Canvas src, TFB_Canvas dst);
175 void TFB_DrawCanvas_Initialize (void);
176 void TFB_DrawCanvas_Lock (TFB_Canvas canvas);
177 void TFB_DrawCanvas_Unlock (TFB_Canvas canvas);
178 void TFB_DrawCanvas_GetScreenFormat (TFB_PixelFormat *fmt);
179 int TFB_DrawCanvas_GetStride (TFB_Canvas canvas);
180 void *TFB_DrawCanvas_GetLine (TFB_Canvas canvas, int line);
181 Color TFB_DrawCanvas_GetPixel (TFB_Canvas canvas, int x, int y);
182 BOOLEAN TFB_DrawCanvas_Intersect (TFB_Canvas canvas1, POINT c1org,
183 		TFB_Canvas canvas2, POINT c2org, const RECT *interRect);
184 
185 BOOLEAN TFB_DrawCanvas_GetPixelColors (TFB_Canvas, Color *pixels,
186 		int width, int height);
187 BOOLEAN TFB_DrawCanvas_SetPixelColors (TFB_Canvas, const Color *pixels,
188 		int width, int height);
189 BOOLEAN TFB_DrawCanvas_GetPixelIndexes (TFB_Canvas, BYTE *data,
190 		int width, int height);
191 BOOLEAN TFB_DrawCanvas_SetPixelIndexes (TFB_Canvas, const BYTE *data,
192 		int width, int height);
193 
194 const char *TFB_DrawCanvas_GetError (void);
195 
196 TFB_Canvas TFB_GetScreenCanvas (SCREEN screen);
197 
198 #endif
199 
200