Advanced Strategic Command
basegfx.cpp
Go to the documentation of this file.
1 
5 /*
6  This file is part of Advanced Strategic Command; http://www.asc-hq.de
7  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; see the file COPYING. If not, write to the
21  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22  Boston, MA 02111-1307 USA
23 */
24 
25 #include <cstring>
26 #include <cstdlib>
27 #include <math.h>
28 #include "global.h"
29 #include "basegfx.h"
30 #include "misc.h"
31 #include "newfont.h"
32 
33 #ifdef _DOS_
34  #include "dos/vesa.h"
35 #else
36  #include "sdl/graphics.h"
37 #endif
38 
41 
42 int xlatbuffersize = 66000;
43 
44 void generategrayxlattable( ppixelxlattable tab, Uint8 offset, Uint8 size, dacpalette256* pal )
45 {
46  for ( int b = 0; b <= 255; b++) {
47 // (*tab)[b] = (Uint8) (offset + size - 1 - ((*activepalette256)[b][0] + (*activepalette256)[b][1] + (*activepalette256)[b][2]) * size / 192);
48  (*tab)[b] = (Uint8) (offset + size - 1 - ( 0.299 * (*pal)[b][0] + 0.587 * (*pal)[b][1] + 0.114 * (*pal)[b][2]) * size / 64 );
49  }
50 }
51 
52 void getpicsize( void* hd2, int &width, int &height)
53 {
54  trleheader* hd = (trleheader*) hd2;
55  if (hd->id == 16973) {
56  width = hd->x;
57  height = hd->y;
58  } else {
59  width = hd->id + 1;
60  height = hd->size + 1;
61  }
62 }
63 
64 int getpicsize2( void* hd2 )
65 {
66  trleheader* hd = (trleheader*) hd2;
67  int width;
68  int height;
69  if (hd->id == 16973)
70  return hd->size + sizeof(*hd);
71  else {
72  width = hd->id + 1;
73  height = hd->size + 1;
74  return height*width+4;
75  }
76 }
77 
78 
79 
80 
81 void
82 rahmen(bool invers,
83  int x1,
84  int y1,
85  int x2,
86  int y2)
87 {
88  collategraphicoperations cgo ( x1, y1, x2, y2 );
89  int col = (invers == false) ? white : darkgray;
90 
91  line(x1, y1, x1, y2, col);
92  line(x1, y1, x2, y1, col);
93 
94  col = (invers == true) ? white : darkgray;
95  line(x2, y1, x2, y2, col);
96  line(x1, y2, x2, y2, col);
97 }
98 
99 void tdrawline :: start ( int x1, int y1, int x2, int y2 )
100 {
101  int i, deltax, deltay, numpixels, d, dinc1, dinc2, x, xinc1, xinc2, y, yinc1, yinc2;
102 
103 
104  /* calculate deltax and deltay for initialisation */
105 
106  deltax = x2 - x1;
107  if ( deltax < 0 )
108  deltax = -deltax;
109 
110  deltay = y2 - y1;
111  if ( deltay < 0 )
112  deltay = -deltay;
113 
114  /* initialize all vars based on which is the independent variable */
115  if (deltax >= deltay)
116  {
117 
118  /* x is independent variable */
119  numpixels = deltax + 1;
120  d = (2 * deltay) - deltax;
121  dinc1 = deltay << 1;
122  dinc2 = (deltay - deltax) << 1;
123  xinc1 = 1;
124  xinc2 = 1;
125  yinc1 = 0;
126  yinc2 = 1;
127  }
128  else
129  {
130 
131  /* y is independent variable */
132  numpixels = deltay + 1;
133  d = (2 * deltax) - deltay;
134  dinc1 = deltax << 1;
135  dinc2 = (deltax - deltay) << 1;
136  xinc1 = 0;
137  xinc2 = 1;
138  yinc1 = 1;
139  yinc2 = 1;
140  }
141 
142  /* make sure x and y move in the right directions */
143  if (x1 > x2)
144  {
145  xinc1 = -xinc1;
146  xinc2 = -xinc2;
147  }
148  if (y1 > y2)
149  {
150  yinc1 = -yinc1;
151  yinc2 = -yinc2;
152  }
153 
154  /* start drawing at <x1, y1> */
155  x = x1;
156  y = y1;
157 
158  /* draw the pixels */
159  for (i = 1; i <= numpixels; i++)
160  {
161  putpix( x, y );
162 
163 
164  if (d < 0)
165  {
166  d = d + dinc1;
167  x = x + xinc1;
168  y = y + yinc1;
169  }
170  else
171  {
172  d = d + dinc2;
173  x = x + xinc2;
174  y = y + yinc2;
175  }
176  }
177 }
178 
179 
180 void
181 line(int x1,
182  int y1,
183  int x2,
184  int y2,
185  Uint8 actcol)
186 {
187  collategraphicoperations cgs ( x1, y1, x2, y2 );
188  float m, b;
189  int w;
190  float yy1, yy2, xx1, xx2;
191 
192 
193 
194  if ( x1 == x2) {
195  for (w=y1;w<=y2 ;w++ )
196  putpixel(x1, w, actcol );
197 
198  } else {
199  if ( y1 == y2) {
200  for (w=x1;w<=x2 ;w++ )
201  putpixel(w, y1, actcol );
202  } else {
203  yy1 = y1;
204  yy2 = y2;
205  xx1 = x1;
206  xx2 = x2;
207  m = (yy2 - yy1) / (xx2 - xx1);
208  b = y1 - m * x1;
209  if ((m <= 1) && (m >= -1)) {
210  if (x2 < x1) {
211  w = x2;
212  x2 = x1;
213  x1 = w;
214  w = y2;
215  y2 = y1;
216  y1 = w;
217  }
218  for (w = x1; w <= x2; w++)
219  putpixel(w, (int) (m * w + b), actcol);
220 
221  } else {
222  if (y2 < y1) {
223  w = x2;
224  x2 = x1;
225  x1 = w;
226  w = y2;
227  y2 = y1;
228  y1 = w;
229  }
230  for (w = y1; w <= y2; w++) {
231  putpixel((int) ((w - b) / m), w, actcol);
232  }
233 
234  }
235  } /* endif */
236  }
237 
238 }
239 
240 void
241 xorline(int x1,
242  int y1,
243  int x2,
244  int y2,
245  Uint8 actcol)
246 {
247  collategraphicoperations cgs ( x1, y1, x2, y2 );
248 
249  float m, b;
250  int w;
251  float yy1, yy2, xx1, xx2;
252 
253  if ( x1 == x2) {
254  for (w=y1;w<=y2 ;w++ ) {
255  putpixel( x1, w, getpixel ( x1, w ) ^ actcol);
256  } /* endfor */
257  } else {
258  yy1 = y1;
259  yy2 = y2;
260  xx1 = x1;
261  xx2 = x2;
262  m = (yy2 - yy1) / (xx2 - xx1);
263  b = y1 - m * x1;
264  if ((m <= 1) && (m >= -1)) {
265  if (x2 < x1) {
266  w = x2;
267  x2 = x1;
268  x1 = w;
269  w = y2;
270  y2 = y1;
271  y1 = w;
272  }
273  for (w = x1; w <= x2; w++) {
274  putpixel(w, (int) (m * w + b), getpixel( w, (int) (m * w + b) ) ^ actcol);
275  }
276  } else {
277  if (y2 < y1) {
278  w = x2;
279  x2 = x1;
280  x1 = w;
281  w = y2;
282  y2 = y1;
283  y1 = w;
284  }
285  for (w = y1; w <= y2; w++) {
286  putpixel((int) ((w - b) / m), w, getpixel ( (int) ((w - b) / m), w ) ^ actcol);
287  }
288 
289  }
290  }
291 
292 }
293 
294 
295 
296 void
297 rectangle(int x1,
298  int y1,
299  int x2,
300  int y2,
301  Uint8 color)
302 {
303  collategraphicoperations cgs ( x1, y1, x2, y2 );
304 
305  line(x1, y1, x1, y2, color);
306  line(x1, y1, x2, y1, color);
307  line(x2, y1, x2, y2, color);
308  line(x1, y2, x2, y2, color);
309 
310 }
311 
312 
313 void xorrectangle(int x1,
314  int y1,
315  int x2,
316  int y2,
317  Uint8 color)
318 {
319  collategraphicoperations cgs ( x1, y1, x2, y2 );
320 
321  xorline(x1,y1,x1,y2,color);
322  xorline(x1,y1,x2,y1,color);
323  xorline(x2,y1,x2,y2,color);
324  xorline(x1,y2,x2,y2,color);
325 
326 }
327 
328 /*
329 void xorrectangle( tmouserect r, byte color)
330 {
331  xorrectangle ( r.x1, r.y1, r.x2, r.y2, color );
332 }
333 
334  */
335 
336 
337 void* halfpict ( void* vbuf )
338 {
339  Uint8* buf = (Uint8*) vbuf;
340 
341  Uint16* wp = (Uint16*) xlatbuffer;
342  Uint8* dest = (Uint8*) xlatbuffer;
343 
344  trleheader* hd = (trleheader*) vbuf;
345 
346  if ( hd->id == 16973 ) {
347  wp[0] = hd->x / 2;
348  wp[1] = hd->y / 2;
349 
350  if ( ( wp[0] + 1 ) * ( wp[1] + 1 ) + 4 >= xlatbuffersize )
351  throw fatalgraphicserror ( "halfpict : picture larger than buffer ! " );
352 
353  dest += 4;
354 
355  buf += sizeof ( *hd );
356 
357 
358  int linecount = 0;
359  int rowcount = 0;
360 
361  for ( int c = 0; c < hd->size; c++ ) {
362  if ( *buf == hd->rle ) {
363  for ( int i = buf[1]; i > 0; i-- ) {
364  if ( !(linecount & 1) && !(rowcount & 1)) {
365  *dest = buf[2];
366  dest++;
367  }
368  rowcount++;
369  if ( rowcount > hd->x ) {
370  rowcount = 0;
371  linecount++;
372  }
373  }
374 
375  buf += 3;
376  c += 2;
377 
378  } else {
379  if ( !(linecount & 1) && !(rowcount & 1)) {
380  *dest = *buf;
381  dest++;
382  }
383  buf++;
384  rowcount++;
385  if ( rowcount > hd->x ) {
386  rowcount = 0;
387  linecount++;
388  }
389  }
391  throw fatalgraphicserror ( "halfpict : picture larger than buffer ! " );
392 
393  }
394  } else {
395  int linecount = 0;
396  int rowcount = 0;
397 
398  Uint16* wp2 = (Uint16*) vbuf;
399 
400  wp[0] = wp2[0] / 2;
401  wp[1] = wp2[1] / 2;
402 
403  if ( ( wp[0] + 1 ) * ( wp[1] + 1 ) + 4 >= xlatbuffersize )
404  throw fatalgraphicserror ( "halfpict : picture larger than buffer ! " );
405 
406  dest += 4;
407  buf += 4;
408 
409  for ( int c = (wp2[0] + 1) * (wp2[1] + 1); c > 0; c-- ) {
410  if ( !(linecount & 1) && !(rowcount & 1)) {
411  *dest = *buf;
412  dest++;
413  }
414  buf++;
415  rowcount++;
416  if ( rowcount > wp2[0] ) {
417  rowcount = 0;
418  linecount++;
419  }
420  }
421 
422  }
423  return xlatbuffer;
424 }
425 
426 #if 0
427 void putshadow ( int x1, int y1, void* ptr, ppixelxlattable xl )
428 {
429  Uint16* w = (Uint16*) ptr;
430  Uint8* c = (Uint8*) ptr + 4;
431  int spacelength = agmp->scanlinelength - *w - 1;
432 
433  collategraphicoperations cgo ( x1, y1, x1 + w[0], y1+w[1] );
434  if ( agmp->windowstatus == 100 ) {
435  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 + agmp->linearaddress);
436  for ( int y = w[1] + 1; y > 0; y-- ) {
437  for ( int x = w[0]+1; x > 0; x-- ) {
438  if ( *c != 255 )
439  *buf = (*xl)[*buf];
440  buf++;
441  c++;
442  }
443  buf+=spacelength;
444  }
445  }
446 
447 }
448 #endif
449 void putpicturemix ( int x1, int y1, void* ptr, int rotation, Uint8* mixbuf )
450 {
451  Uint16* w = (Uint16*) ptr;
452  Uint8* c = (Uint8*) ptr + 4;
453  int spacelength = agmp->scanlinelength - *w - 1;
454 
455  collategraphicoperations cgo ( x1, y1, x1 + w[0], y1+w[1] );
456  if ( agmp->windowstatus == 100 ) {
457  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 + agmp->linearaddress);
458  for ( int y = w[1] + 1; y > 0; y-- ) {
459  for ( int x = w[0]+1; x > 0; x-- ) {
460  if ( *c != 255 ) {
461  int o = *buf << 8;
462  if ( *c >= 16 && *c < 24 )
463  *buf = mixbuf[o + *c + rotation];
464  else
465  *buf = mixbuf[o + *c];
466  }
467  buf++;
468  c++;
469  }
470  buf+=spacelength;
471  }
472  }
473 
474 }
475 
476 
477 void putinterlacedrotimage ( int x1, int y1, void* ptr, int rotation )
478 {
479  Uint16* w = (Uint16*) ptr;
480  Uint8* c = (Uint8*) ptr + 4;
481  int spacelength = agmp->scanlinelength - *w - 1;
482 
483  collategraphicoperations cgo ( x1, y1, x1 + w[0], y1+w[1] );
484  if ( agmp->windowstatus == 100 ) {
485  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 + agmp->linearaddress);
486  for ( int y = w[1] + 1; y > 0; y-- ) {
487  for ( int x = w[0]+1; x > 0; x-- ) {
488  if ( *c != 255 ) {
489  if ( ((PointerSizedInt)(buf+y)) & 1 ) {
490  if ( *c >= 16 && *c < 24 )
491  *buf = *c + rotation;
492  else
493  *buf = *c;
494  }
495  }
496  buf++;
497  c++;
498  }
499  buf+=spacelength;
500  }
501  }
502 
503 }
504 
505 
506 void rotatepict90 ( void* s, void* d )
507 {
508  Uint16* sw = (Uint16*) s;
509  Uint8* sc = (Uint8*) s + 4;
510 
511  Uint16* dw = (Uint16*) d;
512  Uint8* dc = (Uint8*) d + 4;
513 
514  dw[0] = sw[1];
515  dw[1] = sw[0];
516 
517  int dl = dw[0]+1;
518 // int dh = dw[1]+1;
519 
520  int sl = sw[0]+1;
521  int sh = sw[1]+1;
522 
523  for (int y = 0; y <= dw[1]; y++)
524  for (int x = 0; x <= dw[0]; x++)
525  dc[ y * dl + x] = sc[ ( sh - x - 1 ) * sl + y];
526 }
527  union tpix {
528  struct { Uint8 r,g,b,a; } s;
529  int all;
530 };
531 
532 
533 typedef tpix timage[ 100 ][ 100 ];
534 
535 int getimagepixel ( void* image, int x, int y )
536 {
537  int xs, ys;
538  getpicsize ( image, xs, ys );
539 
540 
541  y += ys/2;
542  x += xs/2;
543  if ( x < 0 || x >= xs || y < 0 || y >= ys )
544  return -1;
545  else {
546  Uint8* pc = (Uint8*) image;
547  return pc[ 4 + y * xs + x];
548  }
549 }
550 
551 const float pi = 3.14159265;
552 
553 Uint8* rotatepict ( void* image, int organgle )
554 {
555  int fieldxsize, fieldysize;
556  getpicsize(image, fieldxsize, fieldysize );
557 
558  float angle = ((float)organgle) / 360 * 2 * pi + pi;
559 
560  Uint8* dst = new Uint8[ imagesize ( 0, 0, fieldxsize, fieldysize ) ];
561  Uint16* wp = (Uint16*) dst;
562  wp[0] = fieldxsize-1;
563  wp[1] = fieldysize-1;
564 
565  Uint8* pnt = dst + 4;
566 
567  for ( int y = 0; y < fieldysize; y++ ) {
568  for ( int x = 0; x < fieldxsize; x++ ) {
569  int dx = x - fieldxsize/2 ;
570  int dy = fieldysize/2 - y;
571  double nx = 0;
572  double ny = 0;
573  if ( organgle != 0 && organgle != -180 && organgle != 180) {
574  float wnk ;
575  if ( dx )
576  wnk = atan2 ( double(dy), double(dx) );
577  else
578  if ( dy > 0 )
579  wnk = pi/2;
580  else
581  wnk = -pi/2;
582 
583  wnk -= angle;
584  float radius = sqrt ( double(dx * dx + dy * dy ));
585 
586  nx = radius * cos ( wnk );
587  ny = radius * sin ( wnk );
588  } else
589  if ( organgle == 0 ) {
590  nx = -dx;
591  ny = -dy;
592  } else
593  if ( organgle == 180 || organgle == -180) {
594  nx = dx;
595  ny = dy;
596  }
597 
598 
599  int newpix = getimagepixel ( image, (int)-nx, (int)ny );
600  if ( newpix == -1 )
601  *pnt = 255;
602  else
603  *pnt = newpix;
604 
605  pnt++;
606  }
607  }
608 
609  return dst;
610 }
611 
612 
613 Uint8* rotatepict_grw ( void* image, int organgle )
614 {
615  int fieldxsize, fieldysize;
616  getpicsize(image, fieldxsize, fieldysize );
617 
618  float angle = ((float)organgle) / 360 * 2 * pi + pi;
619 
620  int d = int(sqrt(double(fieldxsize*fieldxsize + fieldysize*fieldysize )));
621 
622  Uint8* dst = new Uint8[ imagesize ( 0, 0, d,d ) ];
623  Uint16* wp = (Uint16*) dst;
624  wp[0] = d-1;
625  wp[1] = d-1;
626 
627  Uint8* pnt = dst + 4;
628 
629  for ( int y = 0; y < d; y++ ) {
630  for ( int x = 0; x < d; x++ ) {
631  int dx = x - d/2 ;
632  int dy = d/2 - y;
633  float nx = 0;
634  float ny = 0;
635  if ( organgle != 0 && organgle != -180 && organgle != 180) {
636  float wnk ;
637  if ( dx )
638  wnk = atan2 ( double(dy), double(dx) );
639  else
640  if ( dy > 0 )
641  wnk = pi/2;
642  else
643  wnk = -pi/2;
644 
645  wnk -= angle;
646  float radius = sqrt ( double(dx * dx + dy * dy ));
647 
648  nx = radius * cos ( wnk );
649  ny = radius * sin ( wnk );
650  } else
651  if ( organgle == 0 ) {
652  nx = -dx;
653  ny = -dy;
654  } else
655  if ( organgle == 180 || organgle == -180) {
656  nx = dx;
657  ny = dy;
658  }
659 
660 
661  int newpix = getimagepixel ( image, (int)-nx, (int)ny );
662  if ( newpix == -1 )
663  *pnt = 255;
664  else
665  *pnt = newpix;
666 
667  pnt++;
668  }
669  }
670 
671  return dst;
672 }
673 
674 
675 void flippict ( void* s, void* d, int dir )
676 {
677  Uint16* sw = (Uint16*) s;
678  Uint8* sc = (Uint8*) s + 4;
679 
680  Uint16* dw = (Uint16*) d;
681  Uint8* dc = (Uint8*) d + 4;
682 
683  dw[1] = sw[1];
684  dw[0] = sw[0];
685 
686  int sl = sw[0]+1;
687  int sh = sw[1]+1;
688 
689  if ( dir == 1 ) {
690  for (int y = 0; y <= dw[1]; y++)
691  for (int x = 0; x <= dw[0]; x++)
692  dc[ y * sl + x] = sc[ y * sl + ( sl - 1 - x ) ];
693  } else {
694  for (int y = 0; y <= dw[1]; y++)
695  for (int x = 0; x <= dw[0]; x++)
696  dc[ y * sl + x] = sc[ ( sh - 1 - y) * sl + x ];
697  }
698 }
699 
700 
701 
702 
703 void putpixel8 ( int x1, int y1, int color )
704 {
705  collategraphicoperations cgo ( x1, y1, x1, y1 );
706  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
707  *buf = color;
708 }
709 
710 int getpixel8 ( int x1, int y1 )
711 {
712  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
713  return *buf;
714 }
715 
716 
717 void putpixel(int x1, int y1, int color)
718 {
719  collategraphicoperations cgo ( x1, y1, x1, y1 );
720  if ( agmp->byteperpix == 1 )
721  putpixel8 ( x1, y1, color );
722  else {
723  if ( agmp->windowstatus == 100 ) {
724  Uint8* pc = (Uint8*) ( agmp->linearaddress + x1 * agmp->byteperpix + y1 * agmp->scanlinelength );
725  int alpha = color >> 24;
726  if ( alpha == 0 ) {
727  pc[ agmp->redfieldposition/8 ] = color & 0xff;
728  pc[ agmp->greenfieldposition/8 ] = (color >> 8) & 0xff;
729  pc[ agmp->bluefieldposition/8 ] = (color >> 16) & 0xff;
730  } else {
731  pc[ agmp->redfieldposition/8 ] = pc[ agmp->redfieldposition/8 ] * alpha / alphabase + (color & 0xff) * (alphabase - alpha ) / alphabase;
732  pc[ agmp->greenfieldposition/8 ] = pc[ agmp->greenfieldposition/8 ] * alpha / alphabase + ((color >> 8 ) & 0xff) * (alphabase - alpha ) / alphabase;
733  pc[ agmp->bluefieldposition/8 ] = pc[ agmp->bluefieldposition/8 ] * alpha / alphabase + ((color >> 16) & 0xff) * (alphabase - alpha ) / alphabase;
734  }
735  } else {
736  /*
737  int pos = x1 * agmp->byteperpix + y1 * agmp->scanlinelength;
738  int page = pos >> 16;
739  if ( hgmp->actsetpage != page )
740  setvirtualpagepos ( page );
741 
742  Uint8* pc = (Uint8*) ( agmp->linearaddress + (pos & 0xffff) );
743 
744  int alpha = color >> 24;
745  if ( alpha == 0 ) {
746  pc[ agmp->redfieldposition/8 ] = color & 0xff;
747  pc[ agmp->greenfieldposition/8 ] = (color >> 8) & 0xff;
748  pc[ agmp->bluefieldposition/8 ] = (color >> 16) & 0xff;
749  } else {
750  pc[ agmp->redfieldposition/8 ] = pc[ agmp->redfieldposition/8 ] * alpha / alphabase + (color & 0xff) * (alphabase - alpha ) / alphabase;
751  pc[ agmp->greenfieldposition/8 ] = pc[ agmp->greenfieldposition/8 ] * alpha / alphabase + ((color >> 8 ) & 0xff) * (alphabase - alpha ) / alphabase;
752  pc[ agmp->bluefieldposition/8 ] = pc[ agmp->bluefieldposition/8 ] * alpha / alphabase + ((color >> 16) & 0xff) * (alphabase - alpha ) / alphabase;
753  }
754  */
755  }
756  }
757 
758 }
759 
760 int getpixel(int x1, int y1)
761 {
762  if ( agmp->byteperpix == 1 )
763  return getpixel8( x1, y1 );
764  else {
765  if ( agmp->windowstatus == 100 ) {
766  Uint8* pc = (Uint8*) ( agmp->linearaddress + x1 * agmp->byteperpix + y1 * agmp->scanlinelength );
767  trgbpixel pix;
768  pix.channel.r = pc[ agmp->redfieldposition/8 ];
769  pix.channel.g = pc[ agmp->greenfieldposition/8 ];
770  pix.channel.b = pc[ agmp->bluefieldposition/8 ];
771  pix.channel.a = 0;
772  return pix.rgb;
773  } else {
774  return -1;
775  }
776  }
777 }
778 
779 
780 
781 
783 {
784  pix = new trgbpixel[x*y];
785  xsize = x;
786  ysize = y;
787 }
788 
790 {
791  if ( pix ) {
792  delete[] pix;
793  pix = NULL;
794  }
795 }
796 
797 
798 int getpixelfromimage ( void* buf, int x, int y )
799 {
800  Uint16* wp = (Uint16*) buf;
801  if ( x > wp[0] || y > wp[1] || x < 0 || y < 0 )
802  return -1;
803 
804  Uint8* pc = (Uint8*) buf;
805  return pc[4 + x + y * (wp[0]+1) ];
806 }
807 
808 void TrueColorImage :: setpix ( int x, int y, int r, int g, int b, int alpha )
809 {
810  trgbpixel* p = & pix[ x + y * xsize ];
811  p->channel.r = r;
812  p->channel.g = g;
813  p->channel.b = b;
814  p->channel.a = alpha;
815 }
816 
817 void TrueColorImage :: setpix ( int x, int y, const trgbpixel& _pix )
818 {
819  pix[ x + y * xsize ] = _pix;
820 }
821 
822 
824 {
825  return pix[ x + y * xsize ];
826 }
827 
828 
830 {
831  return xsize;
832 }
833 
835 {
836  return ysize;
837 }
838 
839 
840 
841 #define f2i(x) (int(x))
842 #define f2i2(x) (int(x+0.5))
843 
844 
847 
848 
849 
850 
851 
852 
854 {
855  TrueColorImage* dst = new TrueColorImage ( src->getxsize(), src->getysize() );
856  for ( int y = 0; y < src->getysize(); y++ )
857  for ( int x = 0; x < src->getxsize(); x++ ) {
858  if ( src->getpix ( x, y ).channel.a < alphabase / 2 ) {
859  int cnt = 0;
860  int r = 0;
861  int g = 0;
862  int b = 0;
863  for ( int a = -1; a <= 1; a++ )
864  for ( int bb = -1; bb <= 1; bb++ ) {
865  int nx = x+a;
866  int ny = y+bb;
867  if ( nx >= 0 && ny >= 0 && nx < src->getxsize() && ny < src->getysize()) {
868  trgbpixel p = src->getpix( nx, ny );
869  if ( p.channel.a < alphabase/2 ) {
870  cnt++;
871  r += p.channel.r;
872  g += p.channel.g;
873  b += p.channel.b;
874  }
875  }
876  }
877 
878  dst->setpix ( x, y, r/cnt, g/cnt, b/cnt, 0 );
879  } else {
880  dst->setpix ( x, y, 0, 0, 0, alphabase );
881  }
882  }
883  return dst;
884 }
885 
886 #define sqr(a) (a)*(a)
887 #define cub(a) abs ((a)*(a)*(a))
888 
889 
890 #ifndef minimal
891  #include "basestrm.h"
892 #endif
893 
894 
895 int
896 imagesize(int x1, int y1, int x2, int y2)
897 {
898  return ((x2 - x1 + 1) * (y2 - y1 + 1) + 4);
899 }
900 
901 #if 0
903 {
904  #ifndef minimal
905  if ( truecolor2pal_table[0] == 255 ) {
906  tfindfile ff ( "tc2pal.dat" );
907  if ( !ff.getnextname().empty() ) {
908  tnfilestream stream ( "tc2pal.dat", tnstream::reading );
909  stream.readdata ( truecolor2pal_table, sizeof ( truecolor2pal_table ));
910  } else {
911  for ( int r = 0; r < 64; r++ )
912  for ( int g = 0; g < 64; g++ )
913  for ( int b = 0; b < 64; b++ ) {
914  int sml = r + ( g << 6) + ( b << 12 );
915 
916  int diff = 0xFFFFFFF;
917  int pix1 = 0;
918 
919  for ( int k=0;k<256 ;k++ ) {
920  int actdif = sqr( pal[k][0] - r ) + sqr( pal[k][1] - g ) + sqr( pal[k][2] - b );
921 
922  if (actdif < diff) {
923  diff = actdif;
924  pix1 = k;
925  }
926  }
927  truecolor2pal_table[sml] = pix1;
928  }
929  /*
930  tnfilestream stream ( "tc2pal.dat", 2 );
931  stream.writedata ( truecolor2pal_table, sizeof ( truecolor2pal_table ));
932  */
933  }
934  }
935  #endif
936  int size = imagesize ( 1, 1, img->getxsize(), img->getysize() );
937  Uint8* newimg = new Uint8[ size ] ;
938  Uint8* start = newimg;
939  Uint16* wp = (Uint16*) newimg;
940  wp[0] = img->getxsize()-1;
941  wp[1] = img->getysize()-1;
942 
943  newimg+= 4;
944 
945  for ( int y = 0; y <= wp[1]; y++ )
946  for ( int x = 0; x <= wp[0]; x++ ) {
947  trgbpixel p = img->getpix ( x, y );
948 
949 
950  if ( p.channel.a <= alphabase*2/3 ) {
951  int sml = ( p.channel.r >> 2) + (( p.channel.g >> 2) << 6) + (( p.channel.b >> 2) << 12);
952 
953  *newimg = truecolor2pal_table[sml];
954 
955  } else {
956  *newimg = 255;
957  }
958  newimg++;
959  }
960 
961  if ( newimg - start > size )
962  printf("\a");
963  return (Uint8*)wp;
964 }
965 #endif
966 
968  strcpy ( st, strng );
969 }
970 
972  st[0] = 0;
973 }
974 
975 void putmask ( int x1, int y1, void* vbuf, int newtransparence )
976 {
977  // int linecount = 0;
978  // int rowcount = 0;
979 
980  Uint16* wp = (Uint16*) vbuf;
981 
982  Uint8* basemembuf = (Uint8*) (agmp->linearaddress + y1 * agmp->bytesperscanline + x1 * agmp->byteperpix );
983  Uint8* img = (Uint8*) vbuf + 4;
984 
985  for ( int y = 0; y <= wp[1]; y++ ) {
986  Uint8* membuf = basemembuf + y * agmp->bytesperscanline;
987 
988  for ( int x = 0; x <= wp[0]; x++ ) {
989  if ( *img != newtransparence )
990  *membuf = *img;
991  membuf += agmp->byteperpix;
992  img++;
993  }
994  }
995 }
996 
998 
999 
1000 
1001 void* uncompress_rlepict ( void* pict )
1002 {
1003  trleheader* hd = (trleheader*) pict;
1004  if (hd->id == 16973) {
1005 
1006  int w, h;
1007  getpicsize( pict, w, h );
1008  w++;
1009  h++;
1010  void* newbuf = malloc ( w * h + 4 );
1011  Uint16* wp = (Uint16*) newbuf;
1012  Uint8* dest = (Uint8*) newbuf;
1013  wp[0] = w-1;
1014  wp[1] = h-1;
1015  dest +=4;
1016 
1017  Uint8* buf = (Uint8*) pict;
1018  buf += sizeof ( *hd );
1019 
1020  for ( int c = 0; c < hd->size; c++ ) {
1021  if ( *buf == hd->rle ) {
1022  for ( int i = buf[1]; i > 0; i-- ) {
1023  *dest = buf[2];
1024  dest++;
1025  }
1026  buf += 3;
1027  c += 2;
1028 
1029  } else {
1030  *dest = *buf;
1031  dest++;
1032 
1033  buf++;
1034  }
1035  }
1036  return newbuf;
1037  } else
1038  return NULL;
1039 }
1040 
1041 
1042 
1043 void ellipse ( int x1, int y1, int x2, int y2, int color, float tolerance )
1044 {
1045  collategraphicoperations cgs ( x1, y1, x2, y2 );
1046 
1047  int midx = (x1 + x2) / 2;
1048  int midy = (y1 + y2) / 2;
1049  float xr = x2 - x1;
1050  float yr = y2 - y1;
1051 
1052  tolerance = tolerance / (xr+yr) * 80;
1053 
1054  xr= (xr/2)*(xr/2);
1055  yr= (yr/2)*(yr/2);
1056 
1057  for ( int y = y1; y <= y2; y++ )
1058  for ( int x = x1; x <= x2; x++ ) {
1059  float dx = x - midx;
1060  float dy = y - midy;
1061  float tmp = dx*dx/xr + dy*dy/yr;
1062 // float tmp = dx*dx*yr + dy*dy*xr;
1063  if ( tmp <= 1 + tolerance && tmp >= 1 - tolerance )
1064  putpixel ( x, y, color );
1065  }
1066 
1067 }
1068 
1069 
1070 
1071 // Uint8 truecolor2pal_table[262144];
1072 
1073 
1075 
1076 
1078  public:
1079  tinitgfxengine ( void );
1080  } initgfx;
1081 
1083 {
1084 #ifdef use_truecolor2pal
1085  memset ( truecolor2pal_table, 255, sizeof ( truecolor2pal_table ));
1086 #endif
1089  activepalette256 = (dacpalette256*) &activepalette;
1091 }
1092 
1093 
1094 void tvirtualdisplay :: init ( int x, int y, int color, int depth )
1095 {
1097  oldparams = *agmp ;
1098  Uint8* cbuf = (Uint8*) malloc ( x * y * depth/8 );
1099  if ( !cbuf )
1100  throw fatalgraphicserror ( "could not allocate memory !");
1101 
1102  buf = cbuf;
1103  for ( int i = 0; i < (x*y*depth/8); i++ )
1104  cbuf[i] = color;
1105 
1106  agmp->resolutionx = x ;
1107  agmp->resolutiony = y ;
1108  agmp->windowstatus = 100 ;
1109  agmp->scanlinelength = x*depth/8 ;
1110  agmp->scanlinenumber = y ;
1111  agmp->bytesperscanline = x * depth/8;
1112  agmp->byteperpix = depth/8 ;
1113  agmp->linearaddress = (PointerSizedInt) buf ;
1114  agmp->bitperpix = depth;
1115  agmp->directscreenaccess = 1;
1116  if ( depth ==24 || depth==32 ) {
1117  agmp->redmasksize = 8;
1118  agmp->greenmasksize = 8;
1119  agmp->bluemasksize = 8;
1120  agmp->redfieldposition = 0;
1121  agmp->greenfieldposition = 8;
1122  agmp->bluefieldposition = 16;
1123  surface = agmp->surface = new Surface ( Surface::CreateSurface( buf, x, y, depth, 0xff, 0xff00, 0xff0000) );
1124  } else {
1125  surface = agmp->surface = new Surface ( Surface::CreateSurface( buf, x, y, depth, agmp->scanlinelength ) );
1126  agmp->surface->assignDefaultPalette();
1127  }
1128 
1129 }
1130 
1132 {
1133  return *surface;
1134 }
1135 
1137 {
1138  init ( x, y, 0, 8 );
1139 }
1140 
1141 tvirtualdisplay :: tvirtualdisplay ( int x, int y, int color, int depth )
1142 {
1143  init ( x, y, color, depth );
1144 }
1145 
1146 
1148 {
1149  delete agmp->surface;
1150  free ( buf ) ;
1151  *agmp = oldparams;
1152 }
1153 
1154 
1156 {
1157  #ifndef _DOS_
1158  status = 1;
1159  x1 = -1; y1 = -1;
1160  x2 = -1; y2 = -1;
1161  olddirectscreenaccess = agmp->directscreenaccess;
1162  agmp->directscreenaccess = 1;
1163  #endif
1164 }
1165 
1166 collategraphicoperations :: collategraphicoperations ( int _x1, int _y1, int _x2, int _y2 )
1167 {
1168  #ifndef _DOS_
1169  status = 1;
1170  x1 = _x1; y1 = _y1;
1171  x2 = _x2; y2 = _y2;
1172  olddirectscreenaccess = agmp->directscreenaccess;
1173  agmp->directscreenaccess = 1;
1174  #endif
1175 }
1176 
1177 
1179 {
1180  #ifndef _DOS_
1181  agmp->directscreenaccess = 1;
1182  status = 1;
1183  #endif
1184 }
1185 
1187 {
1188  #ifndef _DOS_
1189  status = 0;
1190  agmp->directscreenaccess = 0;
1191  if (agmp->directscreenaccess == 0)
1192  copy2screen( x1, y1, x2, y2 );
1193 
1194  #endif
1195 }
1196 
1198 {
1199  #ifndef _DOS_
1200  if ( status ) {
1201  agmp->directscreenaccess = olddirectscreenaccess;
1202  if (agmp->directscreenaccess == 0)
1203  copy2screen( x1, y1, x2, y2 );
1204  }
1205  #endif
1206 }
1207 
1209 {
1210  if (agmp->directscreenaccess == 0)
1211  copy2screen( -1, -1, -1, -1 );
1212 }
1213 
1214 void copySurface2screen( int x1, int y1, int x2, int y2 )
1215 {
1216  if (agmp->directscreenaccess == 0)
1217  copy2screen( x1, y1, x2, y2 );
1218 }
1219 
1220 
1221 
1222 
1225 
1228 
1230 // int palette16[256][4];
1232  // dacpalette256 *activepalette256;
1233 
1234 
1235 
1236 
1237 
1238 
1239 void bar(int x1, int y1, int x2, int y2, Uint8 color)
1240 {
1241  collategraphicoperations cgo ( x1, y1, x2, y2 );
1242  if ( agmp->windowstatus == 100 ) {
1243  int spacelength = agmp->scanlinelength - (x2-x1) - 1;
1244  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
1245  for ( int y = y1; y <= y2; y++ ) {
1246  for ( int x = x1; x <= x2; x++ )
1247  *(buf++) = color;
1248 
1249  buf+=spacelength;
1250  }
1251  }
1252 
1253 }
1254 
1255 
1256 void getimage(int x1, int y1, int x2, int y2, void *buffer)
1257 {
1258  if ( agmp->windowstatus == 100 ) {
1259  int spacelength = agmp->scanlinelength - (x2-x1) - 1;
1260  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
1261 
1262  Uint8* cb = (Uint8*) buffer;
1263  Uint16* wb = (Uint16*) buffer;
1264 
1265  wb[0] = x2 - x1;
1266  wb[1] = y2 - y1;
1267  cb += 4;
1268 
1269  for ( int y = y1; y <= y2; y++ ) {
1270  for ( int x = x1; x <= x2; x++ )
1271  *(cb++) = *(buf++);
1272 
1273  buf+=spacelength;
1274  }
1275  }
1276 
1277 
1278 }
1279 
1280 void putimage ( int x1, int y1, void* img )
1281 {
1282  Uint8* src = (Uint8*) img;
1283 
1284  if ( agmp->windowstatus == 100 ) {
1285  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
1286 
1287  trleheader* hd = (trleheader*) img;
1288 
1289  if ( hd->id == 16973 ) {
1290 
1291  collategraphicoperations cgo ( x1, y1, x1+hd->x, y1+hd->y );
1292 
1293  int spacelength = agmp->scanlinelength - hd->x - 1;
1294 
1295  src += sizeof ( *hd );
1296 
1297  int x = 0;
1298  for ( int c = 0; c < hd->size; c++ ) {
1299  if ( *src == hd->rle ) {
1300  x += src[1];
1301  for ( int i = src[1]; i > 0; i-- )
1302  *(buf++) = src[2];
1303 
1304  src += 3;
1305  c+=2;
1306 
1307  } else {
1308  *(buf++) = *(src++);
1309  x++;
1310  }
1311 
1312  if ( x > hd->x ) {
1313  buf += spacelength;
1314  x = 0;
1315  }
1316  }
1317  } else {
1318  Uint16* w = (Uint16*) img;
1319  collategraphicoperations cgo ( x1, y1, x1+w[0], y1+w[1] );
1320  int spacelength = agmp->scanlinelength - *w - 1;
1321  src += 4;
1322  for ( int y = w[1] + 1; y > 0; y-- ) {
1323  for ( int x = w[0]+1; x > 0; x-- )
1324  *(buf++) = *(src++);
1325 
1326  buf+=spacelength;
1327  }
1328  }
1329  }
1330 
1331 }
1332 
1333 
1334 void putimage ( int x1, int y1, TrueColorImage* tci )
1335 {
1336  for ( int y = 0; y < tci->getysize(); y++ )
1337  for ( int x = 0; x < tci->getxsize(); x++ ) {
1338  trgbpixel t = tci->getpix ( x,y );
1339  putpixel ( x1 + x, y1 + y, t.channel.r + 256*t.channel.g + 256*256*t.channel.b );
1340  }
1341 }
1342 
1343 void putimage_noalpha ( int x1, int y1, TrueColorImage* tci )
1344 {
1345  for ( int y = 0; y < tci->getysize(); y++ )
1346  for ( int x = 0; x < tci->getxsize(); x++ ) {
1347  trgbpixel t = tci->getpix ( x,y );
1348  if (t.channel.a > alphabase * 2 / 3 )
1349  putpixel ( x1 + x, y1 + y, TCalpha );
1350  else
1351  putpixel ( x1 + x, y1 + y, t.channel.r + 256*t.channel.g + 256*256*t.channel.b );
1352  }
1353 }
1354 
1356 {
1357  return ( channel.r == 0xfe && channel.g == 0xfe && channel.b == 0xfe ) ;
1358 }
1359 
1360 TrueColorImage* getimage ( int x1, int y1, int x2, int y2 )
1361 {
1362  TrueColorImage* tci = new TrueColorImage ( x2-x1+1, y2-y1+1 );
1363  for ( int y = 0; y < tci->getysize(); y++ )
1364  for ( int x = 0; x < tci->getxsize(); x++ ) {
1365  trgbpixel t;
1366  t.rgb = getpixel ( x1 + x, y1 + y );
1367  if ( t.isTransparent() )
1368  t.channel.a = alphabase;
1369  tci->setpix ( x, y, t );
1370  }
1371  return tci;
1372 }
1373 
1374 
1375 void putxlatfilter ( int x1, int y1, void* pic, Uint8* xlattables )
1376 {
1377  Uint8* src = (Uint8*) pic;
1378 
1379  if ( agmp->windowstatus == 100 ) {
1380  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
1381  trleheader* hd = (trleheader*) pic;
1382 
1383  if ( hd->id == 16973 ) {
1384  collategraphicoperations cgo ( x1, y1, x1+hd->x, y1+hd->y );
1385 
1386  int spacelength = agmp->scanlinelength - hd->x - 1;
1387  src += sizeof ( *hd );
1388 
1389  int x = 0;
1390  for ( int c = 0; c < hd->size; c++ ) {
1391  if ( *src == hd->rle ) {
1392  x += src[1];
1393  for ( int i = src[1]; i > 0; i-- ) {
1394  if ( src[2] != 255 )
1395  *buf = xlattables[ src[2] * 256 + *buf ];
1396  buf++;
1397  }
1398 
1399  src += 3;
1400  c+=2;
1401 
1402  } else {
1403  if ( *src != 255 )
1404  *buf = xlattables[ *(src++) * 256 + *buf ];
1405  else
1406  src++;
1407  buf++;
1408  x++;
1409  }
1410 
1411  if ( x > hd->x ) {
1412  buf += spacelength;
1413  x = 0;
1414  }
1415  }
1416  } else {
1417  Uint16* w = (Uint16*) pic;
1418  collategraphicoperations cgo ( x1, y1, x1+w[0], y1+w[1] );
1419  int spacelength = agmp->scanlinelength - *w - 1;
1420 
1421  src += 4;
1422  for ( int y = w[1] + 1; y > 0; y-- ) {
1423  for ( int x = w[0]+1; x > 0; x-- ) {
1424  if ( *src != 255 )
1425  *buf = xlattables[ *(src++) * 256 + *buf ];
1426  else
1427  src++;
1428  buf++;
1429  }
1430 
1431  buf+=spacelength;
1432  }
1433  }
1434  }
1435 
1436 }
1437 
1438 
1439 void putspriteimage ( int x1, int y1, void* pic )
1440 {
1441  Uint8* src = (Uint8*) pic;
1442 
1443  if ( agmp->windowstatus == 100 ) {
1444  trleheader* hd = (trleheader*) pic;
1445  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
1446  if ( hd->id == 16973 ) {
1447  collategraphicoperations cgo ( x1, y1, x1+hd->x, y1+hd->y );
1448  int spacelength = agmp->scanlinelength - hd->x - 1;
1449  src += sizeof ( *hd );
1450 
1451  int x = 0;
1452  for ( int c = 0; c < hd->size; c++ ) {
1453  if ( *src == hd->rle ) {
1454  x += src[1];
1455  if ( src[2] != 255 ) {
1456  for ( int i = src[1]; i > 0; i-- )
1457  *(buf++) = src[2];
1458  } else
1459  buf += src[1];
1460  src += 3;
1461  c+=2;
1462 
1463  } else {
1464  if ( *src != 255 )
1465  *buf = *src;
1466  buf++;
1467  src++;
1468  x++;
1469  }
1470 
1471  if ( x > hd->x ) {
1472  buf += spacelength;
1473  x = 0;
1474  }
1475  }
1476  } else {
1477  Uint16* w = (Uint16*) pic;
1478  collategraphicoperations cgo ( x1, y1, x1+w[0], y1+w[1] );
1479  int spacelength = agmp->scanlinelength - *w - 1;
1480  src += 4;
1481  for ( int y = w[1] + 1; y > 0; y-- ) {
1482  for ( int x = w[0]+1; x > 0; x-- ) {
1483  Uint8 d = *(src++);
1484  if ( d != 255 )
1485  *buf = d;
1486  buf++;
1487  }
1488 
1489  buf+=spacelength;
1490  }
1491  }
1492  }
1493 
1494 }
1495 
1496 void putrotspriteimage(int x1, int y1, void *pic, int rotationvalue)
1497 {
1498  Uint8* src = (Uint8*) pic;
1499 
1500  if ( agmp->windowstatus == 100 ) {
1501  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
1502  trleheader* hd = (trleheader*) pic;
1503 
1504  if ( hd->id == 16973 ) {
1505  collategraphicoperations cgo ( x1, y1, x1+hd->x, y1+hd->y );
1506 
1507  int spacelength = agmp->scanlinelength - hd->x - 1;
1508  src += sizeof ( *hd );
1509 
1510  int x = 0;
1511  for ( int c = 0; c < hd->size; c++ ) {
1512  if ( *src == hd->rle ) {
1513  x += src[1];
1514  Uint8 d = src[2];
1515  if ( d != 255 ) {
1516  if ( d >= 16 && d < 24 )
1517  d += rotationvalue;
1518  for ( int i = src[1]; i > 0; i-- )
1519  *(buf++) = d;
1520  } else
1521  buf += src[1];
1522 
1523  src += 3;
1524  c+=2;
1525 
1526  } else {
1527  Uint8 d = *(src++);
1528  if ( d != 255 ) {
1529  if ( d >= 16 && d < 24 )
1530  d += rotationvalue;
1531  *(buf++) = d;
1532  } else
1533  buf++;
1534 
1535  x++;
1536  }
1537 
1538  if ( x > hd->x ) {
1539  buf += spacelength;
1540  x = 0;
1541  }
1542  }
1543  } else {
1544  Uint16* w = (Uint16*) pic;
1545  collategraphicoperations cgo ( x1, y1, x1+w[0], y1+w[1] );
1546  int spacelength = agmp->scanlinelength - *w - 1;
1547  src += 4;
1548  for ( int y = w[1] + 1; y > 0; y-- ) {
1549  for ( int x = w[0]+1; x > 0; x-- ) {
1550  Uint8 d = *(src++);
1551  if ( d != 255 ) {
1552  if ( d >= 16 && d < 24 )
1553  d += rotationvalue;
1554 
1555  *buf = d;
1556  }
1557  buf++;
1558  }
1559 
1560  buf+=spacelength;
1561  }
1562  }
1563  }
1564 
1565 }
1566 
1567 void putrotspriteimage90(int x1, int y1, void *pic, int rotationvalue)
1568 {
1569  Uint16* w = (Uint16*) pic;
1570  // Uint8* c = (Uint8*) pic + 4;
1571  int spacelength = agmp->scanlinelength - w[1] - 1;
1572  collategraphicoperations cgo ( x1, y1, x1+w[1], y1+w[0] );
1573 
1574  if ( agmp->windowstatus == 100 ) {
1575  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
1576  for ( int y = 0; y <= w[0] ; y++ ) {
1577  for ( int x = 0; x <= w[1]; x++ ) {
1578  int d = getpixelfromimage ( pic, y, w[1] - x );
1579  if ( d != 255 && d != -1) {
1580  if ( d >= 16 && d < 24 )
1581  d += rotationvalue;
1582 
1583  *buf = d;
1584  }
1585  buf++;
1586  }
1587 
1588  buf+=spacelength;
1589  }
1590  }
1591 
1592 }
1593 
1594 void putrotspriteimage180(int x1, int y1, void *pic, int rotationvalue)
1595 {
1596  Uint16* w = (Uint16*) pic;
1597  collategraphicoperations cgo ( x1, y1, x1+w[0], y1+w[1] );
1598  // Uint8* c = (Uint8*) pic + 4;
1599  int spacelength = agmp->scanlinelength - *w - 1;
1600 
1601  if ( agmp->windowstatus == 100 ) {
1602  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
1603  for ( int y = 0; y <= w[1] ; y++ ) {
1604  for ( int x = 0; x <= w[0]; x++ ) {
1605  int d = getpixelfromimage ( pic, w[0] - x, w[1] - y );
1606  if ( d != 255 && d != -1) {
1607  if ( d >= 16 && d < 24 )
1608  d += rotationvalue;
1609 
1610  *buf = d;
1611  }
1612  buf++;
1613  }
1614 
1615  buf+=spacelength;
1616  }
1617  }
1618 
1619 }
1620 
1621 void putrotspriteimage270(int x1, int y1, void *pic, int rotationvalue)
1622 {
1623  Uint16* w = (Uint16*) pic;
1624  collategraphicoperations cgo ( x1, y1, x1+w[0], y1+w[1] );
1625  // Uint8* c = (Uint8*) pic + 4;
1626  int spacelength = agmp->scanlinelength - *w - 1;
1627 
1628  if ( agmp->windowstatus == 100 ) {
1629  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
1630  for ( int y = 0; y <= w[1] ; y++ ) {
1631  for ( int x = 0; x <= w[0]; x++ ) {
1632  int d = getpixelfromimage ( pic, w[1] - y, x );
1633  if ( d != 255 && d != -1) {
1634  if ( d >= 16 && d < 24 )
1635  d += rotationvalue;
1636 
1637  *buf = d;
1638  }
1639  buf++;
1640  }
1641 
1642  buf+=spacelength;
1643  }
1644  }
1645 
1646 }
1647 
1648 void puttexture ( int x1, int y1, int x2, int y2, void *texture )
1649 {
1650  collategraphicoperations cgo ( x1, y1, x2, y2 );
1651  Uint8* c = (Uint8*) texture;
1652  int spacelength = agmp->scanlinelength - (x2 - x1) - 1;
1653 
1654  if ( agmp->windowstatus == 100 ) {
1655  int offset = agmp->scanlinelength * y1 + x1;
1656  Uint8* buf = (Uint8*) agmp->linearaddress;
1657  for ( int y = y1 ; y <= y2; y++ ) {
1658  for ( int x = x1; x <= x2 ; x++ ) {
1659  buf[offset] = c[offset];
1660  offset++;
1661  }
1662 
1663  offset+=spacelength;
1664  }
1665  }
1666 
1667 }
1668 
1669 
1670 void putspritetexture ( int x1, int y1, int x2, int y2, void *texture )
1671 {
1672  collategraphicoperations cgo ( x1, y1, x2, y2 );
1673  Uint8* c = (Uint8*) texture;
1674  int spacelength = agmp->scanlinelength - (x2 - x1) - 1;
1675 
1676  if ( agmp->windowstatus == 100 ) {
1677  int offset = agmp->scanlinelength * y1 + x1;
1678  Uint8* buf = (Uint8*) agmp->linearaddress;
1679  for ( int y = y1 ; y <= y2; y++ ) {
1680  for ( int x = x1; x <= x2 ; x++ ) {
1681  Uint8 d = c[offset];
1682  if ( d != 255 )
1683  buf[offset] = d;
1684  offset++;
1685  }
1686 
1687  offset+=spacelength;
1688  }
1689  }
1690 
1691 }
1692 
1693 void putimageprt ( int x1, int y1, int x2, int y2, void *texture, int dx, int dy )
1694 {
1695  collategraphicoperations cgo ( x1, y1, x2, y2 );
1696  int spacelength = agmp->scanlinelength - (x2-x1) - 1;
1697 
1698  if ( agmp->windowstatus == 100 ) {
1699  Uint8* buf = (Uint8*) (agmp->scanlinelength * y1 + x1 * agmp->byteperpix + agmp->linearaddress);
1700  for ( int y = y1; y <= y2 ; y++ ) {
1701  for ( int x = x1; x <= x2; x++ ) {
1702  int p = getpixelfromimage ( texture, x - x1 + dx, y - y1 + dy );
1703  if ( p != -1 )
1704  *buf = p;
1705 
1706  buf++;
1707  }
1708  buf+=spacelength;
1709  }
1710  /*
1711  for ( int y = 0; y <= w[1] ; y++ ) {
1712  for ( int x = 0; x <= w[0]; x++ ) {
1713  int p = getpixelfromimage ( texture, x + dx, y + dy );
1714  if ( p != -1 )
1715  *buf = p;
1716 
1717  buf++;
1718  }
1719  buf+=spacelength;
1720  } */
1721  }
1722 
1723 }
1724 
1725 void copybuf2displaymemory(int size, void *buf)
1726 {
1728  memcpy ( (void*) agmp->linearaddress, buf, size );
1729 }
1730 
1731 #if 0
1732 void* xlatpict ( ppixelxlattable xl, void* vbuf )
1733 {
1734 
1735  Uint8* buf = (Uint8*) vbuf;
1736 
1737  Uint16* wp = (Uint16*) xlatbuffer;
1738  Uint8* dest = (Uint8*) xlatbuffer;
1739 
1740  trleheader* hd = (trleheader*) vbuf;
1741 
1742  if ( hd->id == 16973 ) {
1743  memcpy ( xlatbuffer, vbuf, sizeof ( *hd ));
1744 
1745  trleheader* desthead = (trleheader*) xlatbuffer;
1746 
1747 
1748  dest += sizeof ( *hd );
1749  buf += sizeof ( *hd );
1750 
1751  for ( int c = 0; c < hd->size; c++ )
1752  if ( *buf == hd->rle ) {
1753  *(dest++) = *(buf++);
1754  *(dest++) = *(buf++);
1755  *(dest++) = (*xl)[ *(buf++) ];
1756 
1757  c += 2;
1758 
1759  } else {
1760  int newpix = (*xl)[ *(buf++) ];
1761  if ( newpix == hd->rle ) {
1762  *(dest++) = hd->rle;
1763  *(dest++) = 1;
1764  *(dest++) = hd->rle;
1765  desthead->size += 2;
1766  } else
1767  *(dest++) = newpix;
1768  }
1769 
1770  } else {
1771  Uint16* wp2 = (Uint16*) vbuf;
1772 
1773  wp[0] = wp2[0];
1774  wp[1] = wp2[1];
1775 /*
1776  if ( ( wp[0] + 1 ) * ( wp[1] + 1 ) + 4 >= xlatbuffersize )
1777  throw fatalgraphicserror ( "halfpict : picture larger than buffer ! " );
1778 */
1779  dest += 4;
1780  buf += 4;
1781 
1782  for ( int c = (wp2[0] + 1) * (wp2[1] + 1); c > 0; c-- ) {
1783  *dest = (*xl)[ *buf ];
1784  dest++;
1785  buf++;
1786  }
1787 
1788  }
1789  return xlatbuffer;
1790 }
1791 #endif
1792 
1793 int loga2 ( int a )
1794 {
1795  int l = 0;
1796  if ( a )
1797  while ( ! (a & 1)) {
1798  a >>= 1;
1799  l++;
1800  }
1801  return l;
1802 }
1803 
1804 
1805 
1806 void showtext ( const char* text, int x, int y, int textcol )
1807 {
1808  if ( !activefontsettings.font )
1809  return;
1810 
1811  if ( !text )
1812  return;
1813 
1814  Uint8* fb = (Uint8*)(x * agmp->byteperpix + y * agmp->scanlinelength + agmp->linearaddress);
1815  int fontheight;
1816  int extraheight = 0;
1817  if ( activefontsettings.height == 0 )
1818  fontheight = activefontsettings.font->height;
1819  else
1821  fontheight = activefontsettings.font->height;
1823  } else
1824  fontheight = activefontsettings.height;
1825 
1826  const Uint8* t = (Uint8*) text;
1827  int length = 0;
1828 
1829  Uint8* characterpointer[1024];
1830  int characterwidth[1024];
1831  int characterdist[1024];
1832  int ps = 0;
1833  while ( *t ) {
1834  if ( activefontsettings.font->character[int(*t)].width ) {
1835  characterwidth[ps] = activefontsettings.font->character[int(*t)].width;
1836  characterpointer[ps] = activefontsettings.font->character[int(*t)].memposition + 2;
1837  if ( t[1] )
1838  characterdist[ps] = activefontsettings.font->kerning[int(t[1])][int(t[0])] + 2;
1839  else
1840  characterdist[ps] = 0;
1841  length +=activefontsettings.font->character[int(*t)].width;
1842  length += characterdist[ps];
1843  ps++;
1844  }
1845  t++;
1846  }
1847  int leftextralength = 0;
1848  int rightextralength = 0;
1849 
1850  if ( !activefontsettings.length )
1851  leftextralength = rightextralength = 0;
1852  else {
1853  if ( activefontsettings.justify == 0 ) {
1854  leftextralength = 0;
1855  if ( activefontsettings.length > length )
1856  rightextralength = activefontsettings.length - length;
1857  else {
1858  rightextralength = 0;
1859  length = activefontsettings.length;
1860  }
1861  } else
1862  if ( activefontsettings.justify == 1 ) {
1863  if ( activefontsettings.length > length ) {
1864  leftextralength = (activefontsettings.length - length+2)/2;
1865  rightextralength = activefontsettings.length - length - leftextralength;
1866  } else {
1867  rightextralength = 0;
1868  leftextralength = 0;
1869  length = activefontsettings.length;
1870  }
1871  } else
1872  if ( activefontsettings.justify == 2 ) {
1873  rightextralength = 0;
1874  if ( activefontsettings.length > length )
1875  leftextralength = activefontsettings.length - length;
1876  else {
1877  leftextralength = 0;
1878  length = activefontsettings.length;
1879  }
1880  }
1881 
1882  }
1883  collategraphicoperations cgo ( x, y, x +length + leftextralength + rightextralength, y + fontheight + extraheight );
1884 
1885  int suppressbkgr = 0;
1886  int spacelength = agmp->scanlinelength - (length + leftextralength + rightextralength);
1887  if ( activefontsettings.background == 255 ) {
1888  spacelength += leftextralength + rightextralength;
1889  fb += leftextralength;
1890  leftextralength = rightextralength = 0;
1891  extraheight = 0;
1892  }
1893  for ( int yl = 0; yl < fontheight; yl++ ) {
1894  if ( leftextralength )
1895  for ( int i = 0; i < leftextralength; i++ )
1896  *(fb++) = activefontsettings.background;
1897 
1898  int x = 0;
1899  ps = 0;
1900  while ( x < length ) {
1901  int cx;
1902  for ( cx = characterwidth[ps]; cx > 0 && x < length; cx--) {
1903  int pix = *(characterpointer[ps]++);
1904  if ( pix ) {
1905  if ( textcol != -1 )
1906  *fb = textcol;
1907  else
1908  *fb = pix;
1909  } else
1910  if ( activefontsettings.background != 255 ) {
1911  if ( suppressbkgr )
1912  suppressbkgr--;
1913  else
1915  }
1916  fb++;
1917  x++;
1918  } /* endfor */
1919  if ( x < length ) {
1920  if ( characterdist[ps] > 0 ) {
1921  for (int i = characterdist[ps]; i && x < length; i-- ) {
1922  if ( activefontsettings.background != 255 )
1924  fb++;
1925  x++;
1926  } /* endfor */
1927  } else {
1928  fb += characterdist[ps];
1929  x += characterdist[ps];
1930  suppressbkgr = -characterdist[ps];
1931  }
1932  } else {
1933  characterpointer[ps] += cx;
1934  }
1935  ps++;
1936  }
1937 
1938  if ( rightextralength )
1939  for ( int i = 0; i < rightextralength; i++ )
1940  *(fb++) = activefontsettings.background;
1941 
1942  fb += spacelength;
1943  }
1944  if ( extraheight )
1945  for ( int yl = extraheight; yl > 0; yl-- ) {
1946  for ( int x = length + leftextralength + rightextralength; x > 0; x-- )
1947  *(fb++) = activefontsettings.background;
1948  fb += spacelength;
1949  }
1950 
1951 }
1952 
1953 void showtext2 ( const ASCString& text, int x, int y )
1954 {
1955  showtext ( text.c_str(), x, y, activefontsettings.color );
1956 }
1957 
1958 void showtext2c ( const ASCString& text, int x, int y )
1959 {
1960  showtext ( text.c_str(), x, y, -1 );
1961 }
1962 
1963 #ifdef use_truecolor2pal
1964 void* convertSurface ( SDLmm::Surface& s, bool paletteTranslation )
1965 {
1966  s.Lock();
1967 
1968  Uint8* buf = new Uint8[ imagesize ( 1, 1, s.w(), s.h())];
1969  Uint16* wp = (Uint16*) buf;
1970  wp[0] = s.w()-1;
1971  wp[1] = s.h()-1;
1972  SDLmm::PixelFormat fmt = s.GetPixelFormat();
1973  if ( fmt.BytesPerPixel() == 1 && !paletteTranslation ) {
1974  for ( int y = 0; y < s.h(); y++ )
1975  for ( int x = 0; x < s.w(); x++ )
1976  buf[4 + s.w()*y+x] = s.GetPixel ( x, y );
1977 
1978  } else {
1979 
1980  for ( int y = 0; y < s.h(); y++ )
1981  for ( int x = 0; x < s.w(); x++ ) {
1982  Uint8 red, green, blue, alpha;
1983  fmt.GetRGBA ( s.GetPixel ( x, y ), red, green, blue, alpha);
1984 
1985  if ( alpha < 128 )
1986  buf[4 + s.w()*y+x] = 255;
1987  else
1988  buf[4 + s.w()*y+x] = truecolor2pal_table[ (red >> 2) +
1989  (( green >> 2) << 6) +
1990  (( blue >> 2) << 12) ];
1991  }
1992  }
1993 
1994  s.Unlock();
1995  return buf;
1996 }
1997 #endif
1998 
1999 SPoint getPixelRotationLocation( SPoint pos, int width, int height, int degrees )
2000 {
2001  const float pi = 3.14159265;
2002  double angle = double(-degrees) / 360 * 2 * pi;
2003 
2004  double dx = pos.x - width/2 ;
2005  double dy = height/2 - pos.y;
2006  float nx, ny;
2007  if ( degrees == 0 ) {
2008  nx = dx;
2009  ny = dy;
2010  } else
2011  if ( degrees == 180 || degrees == -180) {
2012  nx = -dx;
2013  ny = -dy;
2014  } else {
2015  float wnk ;
2016  if ( dy )
2017  wnk = atan2 ( -dx, dy );
2018  else
2019  if ( dx < 0 )
2020  wnk = pi/2;
2021  else
2022  wnk = -pi/2;
2023 
2024  wnk += angle;
2025  float radius = sqrt ( dx * dx + dy * dy );
2026 
2027  nx = -radius * sin ( wnk );
2028  ny = radius * cos ( wnk );
2029  }
2030 
2031  return SPoint( int( width/2 + nx), int ( -ny + height/2));
2032 }
2033 
2034 
tgraphmodeparameters activegraphmodeparameters
Definition: basegfx.cpp:1223
Uint8 g
Definition: basegfx.cpp:528
const int blue
Definition: basegfx.h:88
tpix timage[100][100]
Definition: basegfx.cpp:533
void xorline(int x1, int y1, int x2, int y2, Uint8 actcol)
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
tfontsettings activefontsettings
Definition: newfont.cpp:51
Uint8 background
Definition: newfont.h:171
dacpalette256 ppal
Definition: basegfx.cpp:846
void * halfpict(void *vbuf)
reduces a pictures size.
Definition: basegfx.cpp:337
tgraphmodeparameters * hgmp
Definition: basegfx.cpp:40
miscellaneous functions which are used by ASC and all its tools
void putrotspriteimage270(int x1, int y1, void *pic, int rotationvalue)
like putspriteimage, but rotates the image by 270 clock-wise
Definition: basegfx.cpp:1621
char * convertimage(TrueColorImage *img, dacpalette256 pal)
the truecolor image img is reduced to 8 bit color using the palette pal.
void showtext2c(const ASCString &text, int x, int y)
Definition: basegfx.cpp:1958
int getxsize(void)
Definition: basegfx.cpp:829
void putimage_noalpha(int x1, int y1, TrueColorImage *tci)
Definition: basegfx.cpp:1343
bool isTransparent()
Definition: basegfx.cpp:1355
Uint8 bitperpix
the size of a pixel(?) in bits
Definition: basegfx.h:71
void putimage(int x1, int y1, void *img)
puts the image pointed to by buffer to the screen
Definition: basegfx.cpp:1280
trgbpixel getpix(int x, int y)
Definition: basegfx.cpp:823
txlattables xlattables
Definition: palette.cpp:37
void putrotspriteimage90(int x1, int y1, void *pic, int rotationvalue)
like putspriteimage, but rotates the image by 90 clock-wise
Definition: basegfx.cpp:1567
void putrotspriteimage180(int x1, int y1, void *pic, int rotationvalue)
like putspriteimage, but rotates the image by 180 clock-wise
Definition: basegfx.cpp:1594
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
dacpalette256 activepalette
Definition: basegfx.cpp:1229
int getysize(void)
Definition: basegfx.cpp:834
Uint8 bluefieldposition
RGB only: the position of the first blue bit relative to the start of the pixel.
Definition: basegfx.h:70
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
void putspritetexture(int x1, int y1, int x2, int y2, void *texture)
Puts a part of texture on the screen.
Definition: basegfx.cpp:1670
Uint8 * rotatepict_grw(void *image, int organgle)
rotates the picture image by angle clockwise.
Definition: basegfx.cpp:613
Uint8 bluemasksize
RGB only: the number of bits in the blue component.
Definition: basegfx.h:69
#define fieldysize
Definition: typen.h:432
void start(int x1, int y1, int x2, int y2)
Definition: basegfx.cpp:99
#define sqr(a)
Definition: basegfx.cpp:886
void putinterlacedrotimage(int x1, int y1, void *ptr, int rotation)
obsolete. not used any more. can be removed.
Definition: basegfx.cpp:477
void bar(int x1, int y1, int x2, int y2, Uint8 color)
paints a colored bar
Definition: basegfx.cpp:1239
int resolutiony
the number of visible pixels in y direction
Definition: basegfx.h:53
unsigned long PointerSizedInt
Uint8 b
Definition: basegfx.cpp:528
Uint8 justify
Definition: newfont.h:176
struct trgbpixel::@1::@3 channel
Sint16 height
Definition: newfont.h:154
Global platform dependant definitions. This file just branches to the platform specific files in thei...
tgraphmodeparameters * agmp
Definition: basegfx.cpp:39
tinitgfxengine(void)
Definition: basegfx.cpp:1082
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
Uint8 color
Definition: newfont.h:170
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void flippict(void *s, void *d, int dir)
mirrors a picture horizontally (dir=1) or vertically (dir=0).
Definition: basegfx.cpp:675
void copybuf2displaymemory(int size, void *buf)
Definition: basegfx.cpp:1725
int directscreenaccess
if 0 no call to an update function (which copies the buffer to the screen) is performed ...
Definition: basegfx.h:73
int getpixel8(int x1, int y1)
Definition: basegfx.cpp:710
void putspriteimage(int x1, int y1, void *pic)
puts the image pointed to by buffer on the screen. All pixels with color #255 are treated as transpar...
Definition: basegfx.cpp:1439
struct tpix::@0 s
char * malloc(int)
const int white
Definition: basegfx.h:102
void rahmen(bool invers, int x1, int y1, int x2, int y2)
paints a pseudo-3D rectangle on the screen.
Definition: basegfx.cpp:82
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
virtual void putpix(int x, int y)=0
Uint8 * memposition
Definition: newfont.h:147
Uint16 x
Definition: basegfx.h:83
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
pfont font
Definition: newfont.h:169
TrueColorImage * smoothimage(TrueColorImage *src)
Definition: basegfx.cpp:853
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 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
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
signed char kerning[256][256]
Definition: newfont.h:156
#define fieldxsize
Definition: typen.h:431
A class for a single pixel.
Definition: basegfx.h:334
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
Searching for files.
Definition: basestrm.h:484
int rgb
Definition: basegfx.h:337
Uint8 greenmasksize
RGB only: the number of bits in the green component.
Definition: basegfx.h:67
int xlatbuffersize
Definition: basegfx.cpp:42
const float pi
Definition: basegfx.cpp:551
Uint16 length
Definition: newfont.h:174
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
The interface for the various streams that ASC offers, like file and memory streams.
Surface & getSurface()
Definition: basegfx.cpp:1131
Uint16 size
Definition: basegfx.h:81
void putxlatfilter(int x1, int y1, void *pic, Uint8 *xlattables)
Definition: basegfx.cpp:1375
int byteperpix
the distance between two pixel
Definition: basegfx.h:62
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
#define TCalpha
Definition: basegfx.h:351
void putpixel8(int x1, int y1, int color)
Definition: basegfx.cpp:703
SDLmm::SPoint SPoint
Definition: surface.h:27
Uint8 a
Definition: basegfx.cpp:528
Surface * surface
Definition: basegfx.h:74
const int red
Definition: basegfx.h:91
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
int graphicinitialized
Definition: basegfx.cpp:997
Uint16 width
Definition: newfont.h:145
Uint16 id
Definition: basegfx.h:80
dacpalette256 pal
Definition: palette.cpp:33
tpixelxlattable * ppixelxlattable
Definition: palette.h:75
void showtext2(const ASCString &text, int x, int y)
Definition: basegfx.cpp:1953
void assignDefaultPalette()
assigns the default ASC palette to the surface (only for 8 Bit surfaces)
Definition: surface.cpp:429
basegfx.h is the interface for the legacy graphic routines (of which some are platform dependent)...
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
void rotatepict90(void *s, void *d)
rotates the image s by 90 clockwise and writes it to d.
Definition: basegfx.cpp:506
void * uncompress_rlepict(void *pict)
uncompresses the RLE-compressed image pict.
Definition: basegfx.cpp:1001
void * xlatbuffer
Definition: basegfx.cpp:1231
void putpicturemix(int x1, int y1, void *ptr, int rotation, Uint8 *mixbuf)
Definition: basegfx.cpp:449
int all
Definition: basegfx.cpp:529
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 showtext(const char *text, int x, int y, int textcol)
Definition: basegfx.cpp:1806
void setpix(int x, int y, int r, int g, int b, int alpha=0)
Definition: basegfx.cpp:808
void putrotspriteimage(int x1, int y1, void *pic, int rotationvalue)
like putspriteimage, but all color with an 16 <= colorIndex <= 23 are increased by rotationvalue...
Definition: basegfx.cpp:1496
int copy2screen(void)
Definition: graphics.cpp:91
int resolutionx
the number of visible pixels in x direction
Definition: basegfx.h:52
int getimagepixel(void *image, int x, int y)
Definition: basegfx.cpp:535
Uint8 redfieldposition
RGB only: the position of the first red bit relative to the start of the pixel.
Definition: basegfx.h:66
class tinitgfxengine initgfx
tcharacter character[256]
Definition: newfont.h:155
int getpicsize2(void *hd2)
returns the size that the picture p occupies in memory
Definition: basegfx.cpp:64
dacpalette256 * activepalette256
Definition: basegfx.cpp:1074
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
a graphical surface.
Definition: basegfx.h:51
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
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
Uint8 * rotatepict(void *image, int organgle)
rotates the picture image by angle clockwise.
Definition: basegfx.cpp:553
a class that is thrown as exception. Should be moved to error.h ...
Definition: basegfx.h:393
int actdpmsmode
Definition: basegfx.cpp:1227
void getpicsize(void *hd2, int &width, int &height)
write the dimension of the image p to width and height
Definition: basegfx.cpp:52
SPoint getPixelRotationLocation(SPoint pos, int width, int height, int degrees)
transforms the coordinate for an image rotation
Definition: basegfx.cpp:1999
Uint8 height
Definition: newfont.h:178
tgraphmodeparameters hardwaregraphmodeparameters
Definition: basegfx.cpp:1224
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)
tvirtualdisplay(int x, int y)
Definition: basegfx.cpp:1136
void rectangle(int x1, int y1, int x2, int y2, Uint8 color)
draws a simple rectangl
Definition: basegfx.cpp:297
int bytesperscanline
the size of a line in byte
Definition: basegfx.h:59
Uint8 r
Definition: basegfx.cpp:528
int newpalgenerated
Definition: basegfx.cpp:845
fatalgraphicserror(void)
Definition: basegfx.cpp:971
int dpmscapabilities
Definition: basegfx.cpp:1226
void line(int x1, int y1, int x2, int y2, Uint8 actcol)
draws a simple line on the screen. Not very fast...
Definition: basegfx.cpp:181
A class for a RGB image. Was an attempt to rewrite the graphics engine, but should be scrapped...
Definition: basegfx.h:357
#define alphabase
Definition: basegfx.h:348