Advanced Strategic Command
basegfx.h
Go to the documentation of this file.
1 
15 /*
16  This file is part of Advanced Strategic Command; http://www.asc-hq.de
17  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
18 
19  This program is free software; you can redistribute it and/or modify
20  it under the terms of the GNU General Public License as published by
21  the Free Software Foundation; either version 2 of the License, or
22  (at your option) any later version.
23 
24  This program is distributed in the hope that it will be useful,
25  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  GNU General Public License for more details.
28 
29  You should have received a copy of the GNU General Public License
30  along with this program; see the file COPYING. If not, write to the
31  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
32  Boston, MA 02111-1307 USA
33 */
34 
35 #ifndef basegfxH
36 #define basegfxH
37 
38 #include "libs/sdlmm/src/sdlmm.h"
39 #include "global.h"
40 #include "palette.h"
41 #include "sdl/graphics.h"
42 #include "graphics/surface.h"
43 
44 #pragma pack(1)
45 
46 const int colorDepth = 4;
47 
48 
49 
52  int resolutionx ;
53  int resolutiony ;
54  int actsetpage ;
55  int windowstatus ;
56  int granularity ;
61  int videomemory ;
62  int byteperpix ;
64  int pagetoset ;
65  Uint8 redmasksize ;
67  Uint8 greenmasksize ;
69  Uint8 bluemasksize ;
71  Uint8 bitperpix ;
72  Uint8 memorymodel;
76  };
77 
78 
79 struct trleheader {
80  Uint16 id;
81  Uint16 size;
82  Uint8 rle;
83  Uint16 x;
84  Uint16 y;
85 };
86 
87 const int black = 0;
88 const int blue = 1;
89 const int green = 2;
90 const int cyan = 3;
91 const int red = 4;
92 const int magenta = 5 ;
93 const int brown = 6 ;
94 const int lightgray = 7 ;
95 const int darkgray = 8 ;
96 const int lightblue = 9 ;
97 const int lightgreen = 42 ; // 10
98 const int lightcyan = 119 ; // 11
99 const int lightred = 52 ; // 12
100 const int lightmagenta = 5 ; // 13
101 const int yellow = 103; // 14
102 const int white = 160; // 15
103 
104 extern tgraphmodeparameters *agmp;
105 extern tgraphmodeparameters *hgmp;
106 
108 
109 
112 
114 // extern int palette16[256][4];
115 extern void* xlatbuffer;
116 
117 
118 
120  extern void bar(int x1, int y1, int x2, int y2, Uint8 color);
121 
123  extern void getimage(int x1, int y1, int x2, int y2, void *buffer);
124 
126  extern void putimage(int x1, int y1, void *buffer);
127 
145  extern void putxlatfilter ( int x1, int y1, void* pictbuffer, char* xlattables );
146 
148  extern void putspriteimage(int x1, int y1, void *buffer);
149 
153  extern void putrotspriteimage(int x1, int y1, void *buffer, int rotationvalue);
154 
156  extern void putrotspriteimage90(int x1, int y1, void *buffer, int rotationvalue);
157 
159  extern void putrotspriteimage180(int x1, int y1, void *buffer, int rotationvalue);
160 
162  extern void putrotspriteimage270(int x1, int y1, void *buffer, int rotationvalue);
163 
165  extern void puttexture ( int x1, int y1, int x2, int y2, void *texture );
166 
170  extern void putspritetexture ( int x1, int y1, int x2, int y2, void *texture );
171 
177  extern void putimageprt ( int x1, int y1, int x2, int y2, void *texture, int dx, int dy );
178 
179 #if 0
180 
183  extern void* xlatpict ( ppixelxlattable xl, void* pntr );
184 #endif
185 
187  extern int loga2 ( int a );
188 
189 
191  extern SPoint getPixelRotationLocation( SPoint pos, int width, int height, int degrees );
192 
193 
195  extern void putpixel(int x1, int y1, int color);
196 
198  extern int getpixel(int x1, int y1);
199 
201  extern int imagesize(int x1, int y1, int x2, int y2);
202 
204  extern void getpicsize(void* p, int& width, int& height);
205 
207  extern int getpicsize2(void* p );
208 
211  extern void* uncompress_rlepict ( void* pict );
212 
218  extern void generategrayxlattable( ppixelxlattable tab, Uint8 offset, Uint8 size, dacpalette256* pal );
219 
220 #if 0
221 
224  extern void putshadow ( int x1, int y1, void* ptr, ppixelxlattable xl );
225 #endif
226 
227 
230 extern void rahmen( bool invers, int x1, int y1, int x2, int y2);
231 
233 extern void line(int x1, int y1, int x2, int y2, Uint8 color );
234 
238 extern void xorline( int x1, int y1, int x2, int y2, Uint8 color );
239 
241 extern void rectangle(int x1, int y1, int x2, int y2, Uint8 color );
242 
246 extern void xorrectangle(int x1, int y1, int x2, int y2, Uint8 color) ;
247 
249 void putinterlacedrotimage ( int x1, int y1, void* ptr, int rotation );
250 
253 void rotatepict90 ( void* s, void* d );
254 
257 void flippict ( void* s, void* d, int dir = 1 );
258 
263 void* halfpict ( void* vbuf );
264 
265 
268 Uint8* rotatepict ( void* image, int angle );
269 
270 
273 Uint8* rotatepict_grw ( void* image, int organgle );
274 
275 
277 extern int getpixelfromimage ( void* buf, int x, int y );
278 
282 extern void ellipse ( int x1, int y1, int x2, int y2, int color, float tolerance );
283 
285 extern void putmask ( int x1, int y1, void* vbuf, int newtransparence );
286 
290 extern void putpicturemix ( int x1, int y1, void* ptr, int rotation, char* mixbuf );
291 
292 
296 extern void copySurface2screen( void );
297 extern void copySurface2screen( int x1, int y1, int x2, int y2 );
298 
299 
300 
303 class tdrawline {
304  public:
305  void start ( int x1, int y1, int x2, int y2 );
306  virtual void putpix ( int x, int y ) = 0;
307  virtual ~tdrawline() {};
308  };
309 
313  Surface* surface;
314  void* buf;
315  tgraphmodeparameters oldparams;
316  void init ( int x, int y, int col, int depth );
317  public:
318  tvirtualdisplay ( int x, int y );
319  tvirtualdisplay ( int x, int y, int color, int depth= 8 );
320  Surface& getSurface();
321  ~tvirtualdisplay ();
322  };
323 
324 
325 
326 /**************************************************************
327 The following routines were an early attempt at rewriting the graphic engine.
328 It was never continued and the routines are hardly used at all.
329 They can be completely scrapped should the graphic engine be rewritten
330 sometime...
331 ***************************************************************/
332 
334 struct trgbpixel {
335  public:
336  union {
337  int rgb;
338  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
339  struct { Uint8 r,g,b,a; }channel;
340  #else
341  struct { Uint8 a,b,g,r; }channel;
342  #endif
343  };
344  // mix ( const trgbpixel* pix );
345  bool isTransparent();
346  };
347 
348 #define alphabase 64
349 
350 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
351 #define TCalpha 0xfefefe
352 #else
353 #define TCalpha 0xfefefe
354 #endif
355 
358  int xsize;
359  int ysize;
360  trgbpixel* pix;
361  public:
362  TrueColorImage ( int x, int y );
363  trgbpixel getpix ( int x, int y );
364  trgbpixel* getpix ( void );
365  void setpix ( int x, int y, int r, int g, int b, int alpha = 0 );
366  void setpix ( int x, int y, const trgbpixel& pix );
367  int getxsize( void );
368  int getysize( void );
369 
370  ~TrueColorImage();
371 
372  };
373 
376 extern char* convertimage ( TrueColorImage* img, dacpalette256 pal );
377 
380 // extern Uint8 truecolor2pal_table[262144];
381 
383 extern void putimage ( int x1, int y1, TrueColorImage* tci );
384 extern void putimage_noalpha ( int x1, int y1, TrueColorImage* tci );
385 
387 
388 
389 extern TrueColorImage* getimage(int x1, int y1, int x2, int y2 );
390 
391 
394  char st[1000];
395  public:
396  fatalgraphicserror ( const char* strng );
397  fatalgraphicserror ( void );
398  };
399 
407  int olddirectscreenaccess;
408  int x1, y1, x2, y2;
409  int status;
410  public:
411  collategraphicoperations ( void );
412  collategraphicoperations ( int _x1, int _y1, int _x2, int _y2 );
414  void on ( void );
415  void off ( void );
416 };
417 
418 
419 
420 #pragma pack()
421 
422 // this variable determines whether the next call to initgraphics will open a window or a fullscreen session
423 // extern int fullscreen;
424 
426 extern void setWindowCaption ( const char* s );
427 
428 #ifdef use_truecolor2pal
429 
433 extern void* convertSurface ( SDLmm::Surface& s, bool paletteTranslation = true );
434 #endif
435 
436 extern SPoint getPixelRotationLocation( SPoint pos, int width, int height, int degrees );
437 
438 #endif
const int blue
Definition: basegfx.h:88
Uint8 memorymodel
unused
Definition: basegfx.h:72
dacpalette256 activepalette
Definition: basegfx.cpp:1229
void putrotspriteimage180(int x1, int y1, void *buffer, int rotationvalue)
like putspriteimage, but rotates the image by 180 clock-wise
Definition: basegfx.cpp:1594
void setWindowCaption(const char *s)
sets the caption of the main window
Definition: graphics.cpp:34
Uint8 * rotatepict(void *image, int angle)
rotates the picture image by angle clockwise.
Definition: basegfx.cpp:553
char * convertimage(TrueColorImage *img, dacpalette256 pal)
the truecolor image img is reduced to 8 bit color using the palette pal.
int getxsize(void)
Definition: basegfx.cpp:829
void * halfpict(void *vbuf)
reduces a pictures size.
Definition: basegfx.cpp:337
bool isTransparent()
Definition: basegfx.cpp:1355
Uint8 bitperpix
the size of a pixel(?) in bits
Definition: basegfx.h:71
const int cyan
Definition: basegfx.h:90
void rectangle(int x1, int y1, int x2, int y2, Uint8 color)
draws a simple rectangl
Definition: basegfx.cpp:297
void putinterlacedrotimage(int x1, int y1, void *ptr, int rotation)
obsolete. not used any more. can be removed.
Definition: basegfx.cpp:477
void getpicsize(void *p, int &width, int &height)
write the dimension of the image p to width and height
Definition: basegfx.cpp:52
virtual ~tdrawline()
Definition: basegfx.h:307
void flippict(void *s, void *d, int dir=1)
mirrors a picture horizontally (dir=1) or vertically (dir=0).
Definition: basegfx.cpp:675
tgraphmodeparameters * agmp
Definition: basegfx.cpp:39
void putspriteimage(int x1, int y1, void *buffer)
puts the image pointed to by buffer on the screen. All pixels with color #255 are treated as transpar...
Definition: basegfx.cpp:1439
txlattables xlattables
Definition: palette.cpp:37
Uint8 b
Definition: basegfx.h:339
int getysize(void)
Definition: basegfx.cpp:834
int getpicsize2(void *p)
returns the size that the picture p occupies in memory
Definition: basegfx.cpp:64
void rahmen(bool invers, int x1, int y1, int x2, int y2)
paints a pseudo-3D rectangle on the screen.
Definition: basegfx.cpp:82
void putpixel(int x1, int y1, int color)
puts a single pixel on the screen. This is one of the few functions that work in truecolor mode too ...
Definition: basegfx.cpp:717
Uint8 bluefieldposition
RGB only: the position of the first blue bit relative to the start of the pixel.
Definition: basegfx.h:70
Uint8 bluemasksize
RGB only: the number of bits in the blue component.
Definition: basegfx.h:69
void start(int x1, int y1, int x2, int y2)
Definition: basegfx.cpp:99
An abstract class that draws a line.
Definition: basegfx.h:303
int resolutiony
the number of visible pixels in y direction
Definition: basegfx.h:53
void puttexture(int x1, int y1, int x2, int y2, void *texture)
function not used any more and obsolete. Use putimageprt instead
Definition: basegfx.cpp:1648
const int brown
Definition: basegfx.h:93
unsigned long PointerSizedInt
const int lightmagenta
Definition: basegfx.h:100
struct trgbpixel::@1::@3 channel
void putrotspriteimage90(int x1, int y1, void *buffer, int rotationvalue)
like putspriteimage, but rotates the image by 90 clock-wise
Definition: basegfx.cpp:1567
Global platform dependant definitions. This file just branches to the platform specific files in thei...
int activegraphmode
the number of the active graphic mode. Can be ignored nowadays
Definition: basegfx.h:60
A virtual screen is allocated and the agmp pointer set to it.
Definition: basegfx.h:312
void * xlatbuffer
Definition: basegfx.cpp:1231
Uint8 g
Definition: basegfx.h:339
int directscreenaccess
if 0 no call to an update function (which copies the buffer to the screen) is performed ...
Definition: basegfx.h:73
const int black
Definition: basegfx.h:87
void copySurface2screen(void)
when using SDL, all operations are not performed on the displaymemory itself (as is the case with DOS...
Definition: basegfx.cpp:1208
const int white
Definition: basegfx.h:102
void putspritetexture(int x1, int y1, int x2, int y2, void *texture)
Puts a part of texture on the screen.
Definition: basegfx.cpp:1670
virtual void putpix(int x, int y)=0
int videomemory
the amount of memory in the video card. Not used any more.
Definition: basegfx.h:61
Uint16 x
Definition: basegfx.h:83
Uint8 redmasksize
RGB only: the number of bits in the red component.
Definition: basegfx.h:65
int scanlinenumber
the number of lines (may be larger than resolutiony due to offscreen memory)
Definition: basegfx.h:58
void xorline(int x1, int y1, int x2, int y2, Uint8 color)
draws a simple line on the screen, but performs a XOR operation between the pixel already on screen a...
Definition: basegfx.cpp:241
int loga2(int a)
returns the position of the lowest bit of a which is set. This equals an inter logarithm to the base ...
Definition: basegfx.cpp:1793
TrueColorImage(int x, int y)
Definition: basegfx.cpp:782
Uint8 greenfieldposition
RGB only: the position of the first green bit relative to the start of the pixel. ...
Definition: basegfx.h:68
void ellipse(int x1, int y1, int x2, int y2, int color, float tolerance)
paints an ellipse on the screen that fills the rectangle x1/y1 - x2/y2.
Definition: basegfx.cpp:1043
void bar(int x1, int y1, int x2, int y2, Uint8 color)
paints a colored bar
Definition: basegfx.cpp:1239
int imagesize(int x1, int y1, int x2, int y2)
returns the size for a buffer that can contain an image of the given size.
Definition: basegfx.cpp:896
A class for a single pixel.
Definition: basegfx.h:334
dacpalette256 * activepalette256
Definition: basegfx.cpp:1074
Uint8 a
Definition: basegfx.h:339
Uint8 r
Definition: basegfx.h:339
Uint16 y
Definition: basegfx.h:84
PointerSizedInt linearaddress
the pointer to the actual memory (typecast to char* )
Definition: basegfx.h:63
const int green
Definition: basegfx.h:89
const int magenta
Definition: basegfx.h:92
int rgb
Definition: basegfx.h:337
Uint8 greenmasksize
RGB only: the number of bits in the green component.
Definition: basegfx.h:67
const int lightcyan
Definition: basegfx.h:98
const int lightblue
Definition: basegfx.h:96
Surface & getSurface()
Definition: basegfx.cpp:1131
void putmask(int x1, int y1, void *vbuf, int newtransparence)
puts an image on the screen , with all pixels of newtransparence treated as transparent.
Definition: basegfx.cpp:975
int pagetoset
only used in DOS with paged graphic memory
Definition: basegfx.h:64
const int lightred
Definition: basegfx.h:99
Uint16 size
Definition: basegfx.h:81
tgraphmodeparameters hardwaregraphmodeparameters
Definition: basegfx.cpp:1224
int actsetpage
only used in DOS where it may be necessary to access the graphic memory in 64 kB pages ...
Definition: basegfx.h:54
int byteperpix
the distance between two pixel
Definition: basegfx.h:62
SPoint getPixelRotationLocation(SPoint pos, int width, int height, int degrees)
transforms the coordinate for an image rotation
Definition: basegfx.cpp:1999
SDLmm::SPoint SPoint
Definition: surface.h:27
Surface * surface
Definition: basegfx.h:74
const int red
Definition: basegfx.h:91
Uint16 id
Definition: basegfx.h:80
dacpalette256 pal
Definition: palette.cpp:33
tpixelxlattable * ppixelxlattable
Definition: palette.h:75
const int lightgreen
Definition: basegfx.h:97
void putrotspriteimage(int x1, int y1, void *buffer, int rotationvalue)
like putspriteimage, but all color with an 16 <= colorIndex <= 23 are increased by rotationvalue...
Definition: basegfx.cpp:1496
void rotatepict90(void *s, void *d)
rotates the image s by 90 clockwise and writes it to d.
Definition: basegfx.cpp:506
int getpixel(int x1, int y1)
gets the color of a single pixel from the screen. This is one of the few functions that work in truec...
Definition: basegfx.cpp:760
void generategrayxlattable(ppixelxlattable tab, Uint8 offset, Uint8 size, dacpalette256 *pal)
A translation table ( to be used by xlatpict ) is generated to translate any color of palette pal to ...
Definition: basegfx.cpp:44
void setpix(int x, int y, int r, int g, int b, int alpha=0)
Definition: basegfx.cpp:808
int resolutionx
the number of visible pixels in x direction
Definition: basegfx.h:52
void putxlatfilter(int x1, int y1, void *pictbuffer, char *xlattables)
puts the image in pictbuffer on the screen performing a color translation.
void putimageprt(int x1, int y1, int x2, int y2, void *texture, int dx, int dy)
copies a part of texture to the screen.
Definition: basegfx.cpp:1693
TrueColorImage * smoothimage(TrueColorImage *src)
Definition: basegfx.cpp:853
Uint8 redfieldposition
RGB only: the position of the first red bit relative to the start of the pixel.
Definition: basegfx.h:66
tgraphmodeparameters * hgmp
Definition: basegfx.cpp:40
void putimage(int x1, int y1, void *buffer)
puts the image pointed to by buffer to the screen
Definition: basegfx.cpp:1280
void putimage_noalpha(int x1, int y1, TrueColorImage *tci)
Definition: basegfx.cpp:1343
int scanlinelength
the size of a line in byte (may be larger than resolutionx due to offscreen memory) ...
Definition: basegfx.h:57
const int darkgray
Definition: basegfx.h:95
void putrotspriteimage270(int x1, int y1, void *buffer, int rotationvalue)
like putspriteimage, but rotates the image by 270 clock-wise
Definition: basegfx.cpp:1621
int granularity
the offset in graphics memory between two pages. Can be ignored nowadays
Definition: basegfx.h:56
const int yellow
Definition: basegfx.h:101
a graphical surface.
Definition: basegfx.h:51
void putpicturemix(int x1, int y1, void *ptr, int rotation, char *mixbuf)
puts the image ptr on the screen, mixing it with the colors there.
The color palette and various color translation tables.
Uint8 dacpalette256[256][3]
Definition: palette.h:76
int windowstatus
determines whether the memory is a linear (windowstatus==100) or paged. When using SDL...
Definition: basegfx.h:55
a class that is thrown as exception. Should be moved to error.h ...
Definition: basegfx.h:393
void line(int x1, int y1, int x2, int y2, Uint8 color)
draws a simple line on the screen. Not very fast...
Definition: basegfx.cpp:181
Collects all graphic operations and updates the screen on destruction When porting ASC from DOS to SD...
Definition: basegfx.h:406
Uint8 rle
Definition: basegfx.h:82
trgbpixel * getpix(void)
Uint8 * rotatepict_grw(void *image, int organgle)
rotates the picture image by angle clockwise.
Definition: basegfx.cpp:613
void xorrectangle(int x1, int y1, int x2, int y2, Uint8 color)
draws a simple rectangle on the screen, but performs a XOR operation between the pixel already on scr...
Definition: basegfx.cpp:313
tvirtualdisplay(int x, int y)
Definition: basegfx.cpp:1136
const int lightgray
Definition: basegfx.h:94
int bytesperscanline
the size of a line in byte
Definition: basegfx.h:59
fatalgraphicserror(void)
Definition: basegfx.cpp:971
void getimage(int x1, int y1, int x2, int y2, void *buffer)
copy an image to a buffer. buffer must have been alloced before with malloc ( imagesize ( x1...
Definition: basegfx.cpp:1256
const int colorDepth
Definition: basegfx.h:46
int getpixelfromimage(void *buf, int x, int y)
returns the pixel at position x/y of the image buf or -1 if the pixel does not exist ...
Definition: basegfx.cpp:798
void * uncompress_rlepict(void *pict)
uncompresses the RLE-compressed image pict.
Definition: basegfx.cpp:1001
A class for a RGB image. Was an attempt to rewrite the graphics engine, but should be scrapped...
Definition: basegfx.h:357
tgraphmodeparameters activegraphmodeparameters
Definition: basegfx.cpp:1223