Advanced Strategic Command
blitter.h
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #ifndef blitterH
22  #define blitterH
23 
24 #include <cmath>
25  #include <map>
26  #include "loki/static_check.h"
27  #include "../libs/sdlmm/src/sdlmm.h"
28  #include "surface.h"
29 
30 #include "../misc.h"
31  #include "../palette.h"
32  #include "../basegfx.h"
33 #include "lighten.h"
34 
36 
38  {}
39 ;
41 
42 
43 template<int BytesPerPixel>
45 
46 template<>
48 {
49  public:
50  typedef Uint8 PixelType;
51 };
52 template<>
54 {
55  public:
56  typedef Uint16 PixelType;
57 };
58 template<>
60 {
61  public:
62  typedef Uint32 PixelType;
63 };
64 
65 
66 
68 {
69  protected:
70  int skipTarget( int x, int y )
71  {
72  return 0;
73  };
74  void init( const Surface& srv, const SPoint& pos, int xrange, int yrange )
75  {}
76  ;
77  public:
79  {}
80  ;
81 };
82 
84 {
85  int w,h;
86  int xrange;
87  SPoint dstPos;
88  protected:
89  int skipTarget( int x, int y )
90  {
91  x += dstPos.x;
92  y += dstPos.y;
93 
94  if ( x >= 0 && y >= 0 && x < w && y < h )
95  return 0;
96  else
97  if ( x < 0 )
98  return -x;
99  else
100  return xrange - x + dstPos.x;
101  };
102  void init( const Surface& srv, const SPoint& pos, int xrange, int yrange )
103  {
104  w = srv.w();
105  h = srv.h();
106  dstPos = pos;
107  this->xrange = xrange;
108  };
109  public:
110  TargetPixelSelector_Valid ( NullParamType npt = nullParam ) :w(0xffffff),h(0xffffff),xrange(1)
111  {}
112  ;
113 };
114 
115 
116 
117 
118 
119 
120 
121 template<int pixelsize>
123 {
124  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
125  const PixelType* pointer;
126  int pitch;
127  int linelength;
128  const Surface* surface;
129  protected:
130  SourcePixelSelector_Plain() : pointer(NULL), surface(NULL)
131  {}
132  ;
133 
134  void init ( const Surface& srv )
135  {
136  surface = &srv;
137  pointer = (const PixelType*)(srv.pixels());
138  linelength = srv.pitch()/sizeof(PixelType);
139  pitch = linelength - srv.w();
140  };
141 
142  PixelType getPixel(int x, int y)
143  {
144  if ( x >= 0 && y >= 0 && x < surface->w() && y < surface->h() )
145  return surface->GetPixel(SPoint(x,y));
146  else
147  return surface->GetPixelFormat().colorkey();
148  };
149 
150  PixelType nextPixel()
151  {
152  return *(pointer++);
153  };
154  void nextLine()
155  {
156  pointer += pitch;
157  };
158  void skipPixels( int pixNum )
159  {
160  pointer += pixNum;
161  };
162 
164  {
165  return 0;
166  };
167 
169  {
170  pointer += linelength;
171  };
172 
173  int getWidth()
174  {
175  return surface->w();
176  };
177  int getHeight()
178  {
179  return surface->h();
180  };
181  public:
183  {}
184  ;
185 };
186 
187 
188 template<
189 int BytesPerSourcePixel,
190 int BytesPerTargetPixel
191 >
193 {
194  public:
197  private:
198  SourcePixelType srcColorKey;
199  TargetPixelType destColorKey;
200  public:
201  ColorConverter( const Surface& sourceSurface, Surface& targetSurface )
202  {}
203  ;
205  {
206  return sp;
207  };
208 };
209 
210 
211 template<>
212 class ColorConverter<4,1>
213 {
214  int rshift, gshift, bshift;
215  public:
218  private:
219  SourcePixelType srcColorKey;
220  TargetPixelType destColorKey;
221  bool srcHasColorKey;
222  int srcColorMask;
223  public:
224 
225  ColorConverter( const Surface& sourceSurface, Surface& targetSurface )
226  {
227  rshift = sourceSurface.GetPixelFormat().Rshift() + 2;
228  gshift = sourceSurface.GetPixelFormat().Gshift() + 2;
229  bshift = sourceSurface.GetPixelFormat().Bshift() + 2;
230  srcColorMask = ~sourceSurface.GetPixelFormat().Amask();
231  srcColorKey = sourceSurface.GetPixelFormat().colorkey() & srcColorMask;
232 
233  srcHasColorKey = sourceSurface.flags() & SDL_SRCCOLORKEY;
234  if ( targetSurface.flags() & SDL_SRCCOLORKEY )
235  destColorKey = targetSurface.GetPixelFormat().colorkey();
236  else
237  destColorKey = 0xff;
238 
239 
240  };
242  {
243  #ifdef use_truecolor2pal
244  if ( srcHasColorKey && (sp & srcColorMask) == srcColorKey )
245  return destColorKey;
246  else
247  return truecolor2pal_table[ ((sp >> rshift) & 0x3f) + (((sp >> gshift) & 0x3f) << 6) + (((sp >> bshift) & 0x3f) << 12)];
248  #else
249  return destColorKey;
250  #endif
251  };
252 };
253 
254 template<>
255 class ColorConverter<1,4>
256 {
257  public:
260  private:
261  SDL_Color* palette;
262  int rshift, gshift, bshift,ashift;
263  bool hasColorKey;
264  TargetPixelType colorKey;
265  public:
266 
267  ColorConverter( const Surface& sourceSurface, Surface& targetSurface )
268  {
269  if ( targetSurface.flags() & SDL_SRCCOLORKEY ) {
270  hasColorKey = true;
271  colorKey = targetSurface.GetPixelFormat().colorkey();
272  } else {
273  hasColorKey = false;
274  colorKey = 0;
275  }
276 
277  palette = sourceSurface.GetPixelFormat().palette()->colors;
278  rshift = targetSurface.GetPixelFormat().Rshift();
279  gshift = targetSurface.GetPixelFormat().Gshift();
280  bshift = targetSurface.GetPixelFormat().Bshift();
281  if ( targetSurface.GetPixelFormat().Amask() )
282  ashift = targetSurface.GetPixelFormat().Ashift();
283  else
284  ashift = getFirstBit( ~( targetSurface.GetPixelFormat().Rmask() | targetSurface.GetPixelFormat().Gmask() | targetSurface.GetPixelFormat().Bmask()));
285 
286  };
287 
289  {
290  if ( sp == 0xff ) {
291  if ( hasColorKey )
292  return colorKey;
293  else
294  return Surface::transparent << ashift;
295  } else {
297  a <<= ashift;
298  return TargetPixelType(palette[sp].r << rshift) + TargetPixelType(palette[sp].g << gshift) + TargetPixelType(palette[sp].b << bshift) + a;
299  }
300  };
301 
302 };
303 
304 
305 
306 template<
307 int BytesPerSourcePixel,
308 int BytesPerTargetPixel,
309 template<int> class SourceColorTransform, // = ColorTransform_None,
310 template<int> class ColorMerger, // = ColorMerger_PlainOverwrite,
311 template<int> class SourcePixelSelector = SourcePixelSelector_Plain,
312 class TargetPixelSelector = TargetPixelSelector_All,
313 template<int,int> class MyColorConverter = ColorConverter
314 >
315 class MegaBlitter : public SourceColorTransform<BytesPerSourcePixel>,
316  public ColorMerger<BytesPerTargetPixel>,
317  public SourcePixelSelector<BytesPerSourcePixel>,
318  public TargetPixelSelector
319 {
320  typedef typename PixelSize2Type<BytesPerSourcePixel>::PixelType SourcePixelType;
321  typedef typename PixelSize2Type<BytesPerTargetPixel>::PixelType TargetPixelType;
322  public:
324  { }
325  ;
326  MegaBlitter( const SourceColorTransform<BytesPerSourcePixel>& scm, const ColorMerger<BytesPerTargetPixel>& cm, const SourcePixelSelector<BytesPerSourcePixel>& sps, const TargetPixelSelector& tps ) :
327  SourceColorTransform<BytesPerSourcePixel>( scm ),
328  ColorMerger<BytesPerTargetPixel>( cm ),
329  SourcePixelSelector<BytesPerSourcePixel>( sps ),
330  TargetPixelSelector( tps )
331  { }
332  ;
333 
334  int getWidth()
335  {
336  return SourcePixelSelector<BytesPerTargetPixel>::getWidth();
337  };
338  int getHeight()
339  {
340  return SourcePixelSelector<BytesPerTargetPixel>::getHeight();
341  };
342 
343  void initSource( const Surface& src )
344  {
345  SourcePixelSelector<BytesPerSourcePixel>::init( src );
346  }
347 
348 
349  void blit( const Surface& src, Surface& dst, SPoint dstPos )
350  {
351  assert( src.GetPixelFormat().BytesPerPixel() == BytesPerSourcePixel );
352  assert( dst.GetPixelFormat().BytesPerPixel() == BytesPerTargetPixel );
353 
354  SurfaceLock sl( dst );
355 
356  ColorMerger<BytesPerTargetPixel>::init( BytesPerSourcePixel == BytesPerTargetPixel ? src : dst );
357  SourcePixelSelector<BytesPerSourcePixel>::init( src );
358 
359  MyColorConverter<BytesPerSourcePixel,BytesPerTargetPixel> colorConverter( src, dst );
360 
361  SourceColorTransform<BytesPerSourcePixel>::init( src );
362 
363  int h = SourcePixelSelector<BytesPerSourcePixel>::getHeight();
364  int w = SourcePixelSelector<BytesPerSourcePixel>::getWidth();
365 
366  TargetPixelSelector::init( dst, dstPos, w, h );
367 
368  TargetPixelType* pix = (TargetPixelType*)( dst.pixels() );
369 
370  pix += dstPos.y * dst.pitch()/BytesPerTargetPixel + dstPos.x;
371 
372  int pitch = dst.pitch()/BytesPerTargetPixel - w;
373 
374  for ( int y = 0; y < h; ++y ) {
375  for ( int x = 0; x < w; ++x ) {
376  int s = TargetPixelSelector::skipTarget(x,y);
377  if ( s >= 0 && SourcePixelSelector<BytesPerSourcePixel>::getSourcePixelSkip() > s )
378  s = SourcePixelSelector<BytesPerSourcePixel>::getSourcePixelSkip();
379 
380  if ( s==0 ) {
381  ColorMerger<BytesPerTargetPixel>::assign ( colorConverter.convert( SourceColorTransform<BytesPerSourcePixel>::transform( SourcePixelSelector<BytesPerSourcePixel>::nextPixel())), pix );
382  ++pix;
383  } else {
384  if ( s > 0 ) {
385  SourcePixelSelector<BytesPerSourcePixel>::skipPixels( s );
386  pix += s;
387  x += s - 1 ;
388  } else
389  return;
390  }
391  }
392  SourcePixelSelector<BytesPerSourcePixel>::nextLine();
393  pix += pitch;
394  }
395  };
396 
397 };
398 
399 
400 template<
401 template<int> class SourceColorTransform,
402 template<int> class ColorMerger,
403 template<int> class SourcePixelSelector,
404 class TargetPixelSelector,
405 typename SourceColorTransformParameter,
406 typename ColorMergerParameter,
407 typename SourcePixelSelectorParameter,
408 typename TargetPixelSelectorParameter
409 >
410 void megaBlitter ( const Surface& src,
411  Surface& dst,
412  const SPoint& pos,
413  const SourceColorTransformParameter& scmp = nullParam,
414  const ColorMergerParameter& cmp = nullParam,
415  const SourcePixelSelectorParameter spsp = nullParam,
416  const TargetPixelSelectorParameter tpsp = nullParam )
417 {
418  switch ( src.GetPixelFormat().BytesPerPixel() ) {
419  case 1: {
420  switch ( dst.GetPixelFormat().BytesPerPixel() ) {
421  case 1: {
422  MegaBlitter<
423  1,1,
424  SourceColorTransform,
425  ColorMerger,
426  SourcePixelSelector,
427  TargetPixelSelector
428  > blitter (
429  (SourceColorTransform<1>)( scmp ),
430  (ColorMerger<1>)( cmp ),
431  (SourcePixelSelector<1>)( spsp ),
432  TargetPixelSelector(tpsp)
433  );
434  blitter.blit( src, dst, pos );
435  }
436  break;
437  case 3:
438  case 4: {
439  MegaBlitter<
440  1,4,
441  SourceColorTransform,
442  ColorMerger,
443  SourcePixelSelector,
444  TargetPixelSelector
445  > blitter (
446  (SourceColorTransform<1>)( scmp ),
447  (ColorMerger<4>)( cmp ),
448  (SourcePixelSelector<1>)( spsp ),
449  TargetPixelSelector(tpsp)
450  );
451  blitter.blit( src, dst, pos );
452  }
453  break;
454  };
455  }
456  break;
457  case 3:
458  case 4: {
459  switch ( dst.GetPixelFormat().BytesPerPixel() ) {
460  case 1: {
461  MegaBlitter<
462  4,1,
463  SourceColorTransform,
464  ColorMerger,
465  SourcePixelSelector,
466  TargetPixelSelector
467  > blitter (
468  (SourceColorTransform<4>)( scmp ),
469  (ColorMerger<1>)( cmp ),
470  (SourcePixelSelector<4>)( spsp ),
471  TargetPixelSelector(tpsp)
472  );
473  blitter.blit( src, dst, pos );
474  }
475  break;
476  case 3:
477  case 4: {
478  MegaBlitter<
479  4,4,
480  SourceColorTransform,
481  ColorMerger,
482  SourcePixelSelector,
483  TargetPixelSelector
484  > blitter (
485  (SourceColorTransform<4>)( scmp ),
486  (ColorMerger<4>)( cmp ),
487  (SourcePixelSelector<4>)( spsp ),
488  TargetPixelSelector(tpsp)
489  );
490  blitter.blit( src, dst, pos );
491  }
492  break;
493  };
494  }
495  break;
496  }
497 }
498 
499 
500 
502 
503 class Player;
504 
505 
506 template<int pixelsize>
508 {
509  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
510  protected:
512  {}
513  ;
514  PixelType transform( PixelType col)
515  {
516  return col;
517  };
518  void init( const Surface& src )
519  {}
520  ;
521  public:
523  {}
524  ;
525 };
526 
527 
528 
529 
530 template<int pixelSize>
532 {
533  const Uint8* table;
534 
535  protected:
536  ColorTransform_XLAT() : table(NULL)
537  {}
538  ;
539 
540  void init( const Surface& src )
541  {}
542  ;
543 
545  {
546  if ( table )
547  return table[col];
548  else
549  return col;
550  };
551 
552  public:
553  void setTranslationTable( const Uint8* translationTable )
554  {
555  table = translationTable;
556  };
557 
558  ColorTransform_XLAT ( NullParamType npt ) : table(NULL)
559  {}
560  ;
561 
562  ColorTransform_XLAT ( const Uint8* t ) : table ( t )
563  {}
564  ;
565 };
566 
567 
568 template<int pixelSize>
570  { }
571 ;
572 
573 
574 template<>
576 {
577  protected:
579  {}
580  ;
581 
583  {
584  int i = ((col & 0xff) + ((col >> 8) & 0xff) + ((col >> 16) & 0xff)) / 3;
585  return i + (i<<8) + (i <<16) + (col & 0xff000000);
586  };
587 
588  void init( const Surface& src )
589  {}
590  ;
591 
592  public:
594  {}
595  ;
596 };
597 
598 
600 
601 template<int pixelsize>
603 {
604  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
605  protected:
607  {}
608  ;
609  void init( const Surface& dst )
610  {}
611  ;
612  void assign ( PixelType src, PixelType* dest )
613  {
614  *dest = src;
615  };
616  public:
618  {}
619  ;
620 };
621 
622 template<int pixelsize>
624 {
625  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
626  DI_Color col;
627  mutable PixelType transformedColor;
628  public:
629  void init( const Surface& dst ) const
630  {
631  transformedColor = dst.GetPixelFormat().MapRGB( col );
632  };
633  void assign ( PixelType src, PixelType* dest ) const
634  {
635  *dest = src;
636  };
637  void assign ( PixelType* dest ) const
638  {
639  *dest = transformedColor;
640  };
641  ColorMerger_ColoredOverwrite ( DI_Color color ) : col(color)
642  {}
643  ;
644 };
645 
646 
647 template<int pixelsize>
649 {
650  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
651  int colorKey;
652  int mask;
653  protected:
654  ColorMerger_AlphaHandler() : mask ( -1 )
655  {}
656  ;
657 
658  void init( const Surface& srf )
659  {
660  if ( srf.flags() & SDL_SRCCOLORKEY ) {
661  colorKey = srf.GetPixelFormat().colorkey();
662  if ( pixelsize > 1 )
663  mask = srf.GetPixelFormat().Rmask() | srf.GetPixelFormat().Gmask() | srf.GetPixelFormat().Bmask();
664  } else
665  if ( pixelsize == 1 )
666  colorKey = 0xff;
667  else
668  colorKey = 0xfefefe00;
669  };
670 
671  bool isOpaque( PixelType src )
672  {
673  return (src & mask ) != colorKey;
674  }
675 };
676 
677 
678 template<>
680 {
681  typedef PixelSize2Type<1>::PixelType PixelType;
682  int colorKey;
683  int mask;
684  protected:
685  ColorMerger_AlphaHandler() : mask ( -1 )
686  {}
687  ;
688 
689  void init( const Surface& srf )
690  {
691  if ( srf.flags() & SDL_SRCCOLORKEY ) {
692  colorKey = srf.GetPixelFormat().colorkey();
693  } else
694  colorKey = 0xff;
695  };
696 
697  bool isOpaque( PixelType src )
698  {
699  return (src & mask ) != colorKey;
700  }
701 };
702 
703 template<>
705 {
706  typedef PixelSize2Type<4>::PixelType PixelType;
707  protected:
708  int amask, ashift;
709  PixelType colorKey;
711  int ckmask;
712  protected:
713  ColorMerger_AlphaHandler() : amask ( -1 ), ashift(0), colorKey(0), hasColorKey(false), ckmask(0)
714  {}
715  ;
716 
717  void init( const Surface& srf )
718  {
719  if ( srf.flags() & SDL_SRCCOLORKEY ) {
720  hasColorKey = true;
721  colorKey = srf.GetPixelFormat().colorkey();
722  ckmask = srf.GetPixelFormat().Rmask() | srf.GetPixelFormat().Gmask() | srf.GetPixelFormat().Bmask();
723  } else {
724  if ( srf.GetPixelFormat().Amask() ) {
725  amask = srf.GetPixelFormat().Amask();
726  ashift = srf.GetPixelFormat().Ashift();
727  } else {
728  amask = ~( srf.GetPixelFormat().Rmask() | srf.GetPixelFormat().Gmask() | srf.GetPixelFormat().Bmask() );
729  ashift = getFirstBit(amask);
730  }
731  }
732  };
733 
734  bool isOpaque( PixelType src )
735  {
736  if ( hasColorKey )
737  return (src & ckmask) != colorKey;
738  else
739  return PixelType((src & amask ) >> ashift) >= 128;
740  };
741 };
742 
743 
744 template<int pixelsize>
746 {
747  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
748  protected:
749 
750  void assign ( PixelType src, PixelType* dest )
751  {
752  if ( this->isOpaque(src ) ) {
753  *dest = src;
754  }
755  };
756 
757  public:
759  {}
760  ;
761 };
762 
763 
764 template<int pixelsize>
766 {
767  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
768  protected:
769 
770  void assign ( PixelType src, PixelType* dest )
771  {
772  if ( this->isOpaque(src ) ) {
773  *dest = src;
774  }
775  };
776 
777  public:
779  {}
780  ;
781 };
782 
783 template<>
785 {
786  typedef PixelSize2Type<4>::PixelType PixelType;
787  protected:
788 
789  void assign ( PixelType src, PixelType* dest )
790  {
791  if ( hasColorKey ) {
792  if ( (src & ckmask) != colorKey )
793  *dest = src;
794  } else {
795  PixelType alpha = PixelType((src & amask ) >> ashift);
796  if ( alpha == PixelType(Surface::opaque) )
797  *dest = src;
798  else
799  if ( alpha != PixelType(Surface::transparent)) {
800  // copied from SDL
801 
802  /*
803  * take out the middle component (green), and process
804  * the other two in parallel. One multiply less.
805  */
806  PixelType d = *dest;
807  PixelType dalpha = d & 0xff000000;
808  if ( dalpha == Surface::transparent ) {
809  *dest = src;
810  } else {
811  PixelType s1 = src & 0xff00ff;
812  PixelType d1 = d & 0xff00ff;
813  d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff;
814  src &= 0xff00;
815  d &= 0xff00;
816  d = (d + ((src - d) * alpha >> 8)) & 0xff00;
817  *dest = d1 | d | dalpha;
818  }
819  }
820 
821  }
822  };
823 
824  public:
826  {}
827  ;
828 };
829 
830 
831 
832 
833 template<int pixelsize>
835  {}
836 ;
837 
838 
839 template<>
841 {
842  typedef PixelSize2Type<1>::PixelType PixelType;
843  const Uint8* table;
844  protected:
845 
846  void assign ( PixelType src, PixelType* dest )
847  {
848  // STATIC_CHECK ( pixelsize == 1, wrong_pixel_size );
849  if ( this->isOpaque(src ) ) {
850  *dest = table[*dest];
851  }
852  };
853  public:
854  ColorMerger_AlphaShadow ( NullParamType npt = nullParam) : table ( xlattables.a.dark1 )
855  {}
856  ;
857  ColorMerger_AlphaShadow ( const Uint8* translationTable ) : table ( translationTable )
858  {}
859  ;
860 };
861 
862 template<>
864 {
865  typedef PixelSize2Type<4>::PixelType PixelType;
866  protected:
867 
868  void init( const Surface& srf )
869  {
871  };
872 
873 
874  void assign ( PixelType src, PixelType* dest )
875  {
876  if ( this->isOpaque(src ) ) {
877  *dest = ((*dest >> 1) & 0x7f7f7f7f) | (*dest & 0xff000000 );
878  }
879  };
880  public:
882  {}
883  ;
884  ColorMerger_AlphaShadow ( const Uint8* translationTable )
885  {}
886  ;
887 };
888 
889 
890 
891 template<int pixelsize>
893  {}
894 ;
895 
896 
897 template<>
899 {
900  typedef PixelSize2Type<1>::PixelType PixelType;
901  protected:
902  void assign ( PixelType src, PixelType* dest )
903  {
904  if ( this->isOpaque(src ) )
905  *dest = colormixbufchar[*dest + src*256 ];
906  };
907  public:
909  {}
910  ;
911 };
912 
913 template<>
915 {
916  typedef PixelSize2Type<4>::PixelType PixelType;
917  protected:
918  void assign ( PixelType src, PixelType* dest )
919  {
920  // STATIC_CHECK ( pixelsize == 1, wrong_pixel_size );
921  if ( this->isOpaque(src ) ) {
922  *dest = ((*dest >> 1) & 0x7f7f7f7f) + ((src >> 1) & 0x7f7f7f7f);
923  }
924  };
925  public:
927  {}
928  ;
929 };
930 
931 
932 
933 extern const int ColorMerger_Alpha_XLAT_Table_shadings[8];
934 
935 template<int pixelsize>
937 {
938  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
939  const Uint8* table;
940  protected:
941  void assign ( PixelType src, PixelType* dest )
942  {
943  if ( src == 0 || src >= 8 )
944  return;
945 
947  /*
948  // STATIC_CHECK ( pixelsize == 1, wrong_pixel_size );
949  if ( isOpaque(src ) ) {
950  *dest = table[ *dest + src*256 ];
951  }
952  */
953  };
954 
955  public:
956  void setNeutralTranslationTable( const Uint8* translationTable )
957  {
958  table = translationTable;
959  };
960 
961  ColorMerger_Alpha_XLAT_TableShifter( NullParamType npt = nullParam ) : table ( NULL )
962  {}
963  ;
964  ColorMerger_Alpha_XLAT_TableShifter ( const Uint8* translationTable ) : table ( translationTable )
965  {}
966  ;
967 };
968 
969 template<>
971 {
972  typedef PixelSize2Type<1>::PixelType PixelType;
973  const Uint8* table;
974  protected:
975  void assign ( PixelType src, PixelType* dest )
976  {
977  // STATIC_CHECK ( pixelsize == 1, wrong_pixel_size );
978  if ( this->isOpaque(src ) ) {
979  *dest = table[ *dest + src*256 ];
980  }
981  };
982 
983  public:
984  void setNeutralTranslationTable( const Uint8* translationTable )
985  {
986  table = translationTable;
987  };
988 
989  ColorMerger_Alpha_XLAT_TableShifter( NullParamType npt = nullParam ) : table ( NULL )
990  {}
991  ;
992  ColorMerger_Alpha_XLAT_TableShifter ( const Uint8* translationTable ) : table ( translationTable )
993  {}
994  ;
995 };
996 
997 
998 template<int pixelsize>
1000 {
1001  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
1002  float b;
1003  public:
1004 
1005  void assign ( PixelType src, PixelType* dest ) const
1006  {
1007  PixelType d = 0;
1008  for ( int i = 0; i < 3; ++i)
1009  d |= min( max( int( float(((*dest) >> (i*8)) & 0xff) * b ), 0 ), 255) << (i*8);
1010  d |= (*dest & 0xff000000);
1011 
1012  *dest = d;
1013  };
1014 
1015  ColorMerger_Brightness( float brightness )
1016  {
1017  b = brightness;
1018  };
1019 };
1020 
1021 
1022 template<int pixelsize>
1024 {
1025  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
1026  SDLmm::Color col;
1027  public:
1028 
1029  void assign ( PixelType src, PixelType* dest ) const
1030  {
1031  *dest = col;
1032  };
1033 
1034 
1036  {
1037  col = color;
1038  };
1039 };
1040 
1041 
1043 
1044 
1045 
1046 template<int pixelsize, class SourcePixelSelector = SourcePixelSelector_Plain<pixelsize> >
1047 class SourcePixelSelector_Rotation: public SourcePixelSelector
1048 {
1049  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
1050  int degrees;
1051  int x,y;
1052  int w,h;
1053  protected:
1054 
1055  void init ( const Surface& srv )
1056  {
1057  SourcePixelSelector::init(srv);
1058  w = SourcePixelSelector::getWidth();
1059  h = SourcePixelSelector::getHeight();
1060  };
1061 
1062 
1063  PixelType getPixel(int x, int y)
1064  {
1065  SPoint newpos = ::getPixelRotationLocation( SPoint(x,y), w, h, degrees );
1066  return SourcePixelSelector::getPixel ( newpos.x, newpos.y );
1067  };
1068 
1069  PixelType nextPixel()
1070  {
1071  return getPixel(x++, y);
1072  };
1073 
1074  void skipPixels( int pixNum )
1075  {
1076  x += pixNum;
1077  };
1078 
1080  {
1081  return 0;
1082  };
1083 
1084  void nextLine()
1085  {
1086  x = 0;
1087  y +=1;
1088  };
1089 
1090  public:
1091  void setAngle( int degrees )
1092  {
1093  this->degrees = degrees;
1094  };
1095 
1096  SourcePixelSelector_Rotation( NullParamType npt = nullParam ) : degrees(0),x(0),y(0),w(0),h(0)
1097  {}
1098 
1099  SourcePixelSelector_Rotation( int degreesToRotate ) : degrees(degreesToRotate),x(0),y(0),w(0),h(0)
1100  {}
1101 };
1102 
1103 template<int pixelsize>
1105 {
1106  public:
1108  {}
1109  SourcePixelSelector_DirectRotation( int degreesToRotate ) : SourcePixelSelector_Rotation<pixelsize>(degreesToRotate)
1110  {}
1111 }
1112 ;
1113 
1114 
1115 
1117 {
1118  protected:
1119  static map<int,int*> cache;
1120  static int xsize;
1121  static int ysize;
1122 };
1123 
1124 template<int pixelsize>
1126 {
1127  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
1128  const Surface* surface;
1129  int degrees;
1130  bool useCache;
1131  const PixelType* pixelStart;
1132  const PixelType* currentPixel;
1133  int tableIndex;
1134  int pitch;
1135  int* cacheIndex;
1136  int x,y,w,h;
1137  protected:
1138 
1139  void init ( const Surface& srv )
1140  {
1141  if ( !surface ) {
1142  surface = &srv;
1143  } else {
1144  assert ( surface == &srv );
1145  }
1146  tableIndex = 0;
1147  pixelStart = currentPixel = (PixelType*)surface->pixels();
1148  pitch = srv.pitch()/sizeof(PixelType) - srv.w();
1149  w = srv.w();
1150  h = srv.h();
1151  }
1152 
1153  PixelType nextPixel()
1154  {
1155  if ( useCache && degrees != 0 ) {
1156  ++currentPixel;
1157 
1158  assert ( cacheIndex );
1159  int index = cacheIndex[tableIndex++];
1160  if ( index >= 0 )
1161  return pixelStart[index];
1162  else
1163  return surface->GetPixelFormat().colorkey();
1164  } else {
1165  if ( degrees == 0 ) {
1166  ++tableIndex;
1167  return *(currentPixel++);
1168  } else {
1169  SPoint newpos = ::getPixelRotationLocation( SPoint(x++,y), w, h, degrees );
1170  return getSourcePixel ( newpos.x, newpos.y );
1171  }
1172  }
1173  };
1174 
1175  void skipPixels( int pixNum )
1176  {
1177  currentPixel += pixNum;
1178  tableIndex += pixNum;
1179  x += pixNum;
1180  };
1181 
1183  {
1184  return 0;
1185  };
1186 
1187  void nextLine()
1188  {
1189  currentPixel += pitch;
1190  ++y;
1191  x = 0;
1192  };
1193 
1194  int getWidth()
1195  {
1196  return surface->w();
1197  };
1199  {
1200  return surface->h();
1201  };
1202 
1203  private:
1204  PixelType getSourcePixel(int x, int y)
1205  {
1206  if ( x >= 0 && y >= 0 && x < surface->w() && y < surface->h() )
1207  return surface->GetPixel(SPoint(x,y));
1208  else
1209  return surface->GetPixelFormat().colorkey();
1210  };
1211 
1212 
1213  public:
1214  void setAngle( const Surface& srv, int degrees )
1215  {
1216  init ( srv );
1217 
1218  if ( xsize == -1 ) {
1219  xsize = surface->w();
1220  ysize = surface->h();
1221  }
1222 
1223  this->degrees = degrees;
1224  if ( degrees != 0 && surface->w() == xsize && surface->h() == ysize ) {
1225  useCache = true;
1226  if ( cache.find( degrees ) == cache.end() ) {
1227  int* index = new int[surface->w() * surface->h()];
1228  cache[degrees] = index;
1229  for ( int y = 0; y < surface->h(); ++y )
1230  for ( int x = 0; x < surface->w(); ++x ) {
1231  SPoint pnt = getPixelRotationLocation( SPoint(x,y), surface->w(),surface->h(), degrees );
1232  if ( pnt.x >= 0 && pnt.y >= 0 && pnt.x < surface->w() && pnt.y < surface->h() )
1233  *index++ = pnt.x + pnt.y * surface->pitch()/pixelsize;
1234  else
1235  *index++ = -1;
1236  }
1237  }
1238  cacheIndex = cache[degrees];
1239  }
1240  }
1241 
1242  SourcePixelSelector_CacheRotation( NullParamType npt = nullParam ) : surface(NULL), degrees(0), useCache(false),pixelStart(NULL), currentPixel(NULL),tableIndex(0),pitch(0), cacheIndex(NULL),x(0),y(0),w(0),h(0)
1243  {}
1244  ;
1245 
1246  SourcePixelSelector_CacheRotation( const Surface& srv, int degrees ) : surface(NULL), degrees(0), useCache(false),pixelStart(NULL), currentPixel(NULL),tableIndex(0),pitch(0), cacheIndex(NULL),x(0),y(0),w(0),h(0)
1247  {
1248  setAngle ( srv, degrees );
1249  };
1250 
1251  SourcePixelSelector_CacheRotation( pair<const Surface*, int> p ) : surface(NULL), degrees(0), useCache(false),pixelStart(NULL), currentPixel(NULL),tableIndex(0),pitch(0), cacheIndex(NULL),x(0),y(0),w(0),h(0)
1252  {
1253  setAngle ( *(p.first), p.second );
1254  };
1255 
1256 
1257 };
1258 
1259 
1260 template<int pixelsize, class SourcePixelSelector = SourcePixelSelector_Plain<pixelsize> >
1261 class SourcePixelSelector_Zoom: public SourcePixelSelector
1262 {
1263  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
1264  float zoomFactorX;
1265  float zoomFactorY;
1266  int x,y;
1267  protected:
1268 
1269  int getWidth()
1270  {
1271  return int( zoomFactorX * SourcePixelSelector::getWidth() );
1272  };
1274  {
1275  return int( zoomFactorY * SourcePixelSelector::getHeight() );
1276  };
1277 
1278  PixelType getPixel(int x, int y)
1279  {
1280  return SourcePixelSelector::getPixel( int(float(x) / zoomFactorX), int(float(y) / zoomFactorY));
1281  };
1282 
1283  PixelType nextPixel()
1284  {
1285  return getPixel(x++, y);
1286  };
1287 
1288  void skipPixels( int pixNum )
1289  {
1290  x += pixNum;
1291  };
1292 
1294  {
1295  return 0;
1296  };
1297 
1298  void nextLine()
1299  {
1300  x= 0;
1301  ++y;
1302  };
1303 
1304  public:
1305  void setZoom( float factor )
1306  {
1307  this->zoomFactorX = factor;
1308  this->zoomFactorY = factor;
1309  };
1310  void setZoom( float factorX, float factorY )
1311  {
1312  this->zoomFactorX = factorX;
1313  this->zoomFactorY = factorY;
1314  };
1315 
1316  float getZoomX()
1317  {
1318  return zoomFactorX;
1319  };
1320  float getZoomY()
1321  {
1322  return zoomFactorY;
1323  };
1324 
1325  void setSize( int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool forceSquare = true )
1326  {
1327  float zw = float(targetWidth) / float(sourceWidth);
1328  float zh = float(targetHeight)/ float(sourceHeight);
1329  if ( forceSquare )
1330  setZoom( min ( zw,zh));
1331  else
1332  setZoom( zw,zh );
1333  };
1334 
1335  SourcePixelSelector_Zoom( NullParamType npt = nullParam) : zoomFactorX(1),zoomFactorY(1),x(0),y(0)
1336  {}
1337  ;
1338 
1339 };
1340 
1341 template<int pixelsize>
1343 {
1344  public:
1346  {}
1347  ;
1348 };
1349 
1350 
1352 {
1353  protected:
1354  typedef map<float,int*> ZoomMap;
1356 };
1357 
1358 
1359 template<int pixelsize, class SourcePixelSelector = SourcePixelSelector_Plain<pixelsize> >
1360 class SourcePixelSelector_CacheZoom : private ZoomCache, public SourcePixelSelector
1361 {
1362  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
1363  const Surface* surface;
1364  float zoomFactor;
1365 
1366  int currSrcX;
1367  int currSrcY;
1368  int* xp;
1369  int* yp;
1370  int offsetx;
1371  int offsety;
1372  ZoomMap::iterator cacheit;
1373  protected:
1374 
1375  int getWidth()
1376  {
1377  return int( zoomFactor * SourcePixelSelector::getWidth() );
1378  };
1380  {
1381  return int( zoomFactor * SourcePixelSelector::getHeight() );
1382  };
1383 
1384  PixelType getPixel(int x, int y)
1385  {
1386  return SourcePixelSelector::getPixel( int(float(x) / zoomFactor), int(float(y) / zoomFactor));
1387  };
1388 
1389  PixelType nextPixel()
1390  {
1391  for ( int i = 0; i < *xp; ++i )
1392  SourcePixelSelector::nextPixel();
1393  ++xp;
1394 
1395  return SourcePixelSelector::nextPixel();
1396  };
1397 
1398  void skipPixels( int pixNum )
1399  {
1400  int count = pixNum;
1401  for ( int i = 0; i < pixNum; ++i ) {
1402  count += *xp;
1403  ++xp;
1404  }
1405  SourcePixelSelector::skipPixels( count );
1406  };
1407 
1409  {
1410  int s = SourcePixelSelector::getSourcePixelSkip();
1411  if ( s ) {
1412  s = int(floor( float(s) * zoomFactor )) -2; // to prevent rounding errors
1413  if ( s < 1 )
1414  return 1;
1415  else
1416  return s;
1417  } else
1418  return 0;
1419  };
1420 
1421 
1422  void nextLine()
1423  {
1424  SourcePixelSelector::nextLine();
1425  for ( int i = 0; i < *yp; ++i )
1426  SourcePixelSelector::skipWholeLine();
1427 
1428  xp = &cacheit->second[offsetx];
1429  yp++;
1430  };
1431 
1432 
1433  public:
1434 
1435 
1436  void setZoomOffset( int x, int y )
1437  {
1438  offsetx = x;
1439  offsety = y;
1440  /*
1441  for ( int i = 0; i < y; ++y )
1442  next
1443  */
1444  }
1445 
1446 
1447  void setZoom( float factor )
1448  {
1449  this->zoomFactor = factor;
1450  assert ( factor > 0 );
1451  assert ( factor <= 1 );
1452 
1453  cacheit = zoomCache.find( factor );
1454  if ( cacheit == zoomCache.end() ) {
1455  int size = max ( SDLmm::Display::GetDisplay().w(), SDLmm::Display::GetDisplay().h() );
1456 
1457  int* buf = new int[size+1];
1458  buf[0] = 0;
1459 
1460  for ( int i = 0; i < size; ++i ) {
1461  int a1 = int( floor( float(i) / zoomFactor ));
1462  int a2 = int( floor( float(i+1) / zoomFactor ));
1463 
1464  buf[i+1] = a2 - a1 - 1;
1465  }
1466 
1467  zoomCache[zoomFactor] = buf;
1468  cacheit = zoomCache.find( factor );
1469  }
1470  xp = &cacheit->second[offsetx];
1471  yp = &cacheit->second[offsety];
1472  }
1473 
1474  SourcePixelSelector_CacheZoom( NullParamType npt = nullParam ) : surface(NULL), zoomFactor(1), xp(NULL), yp(NULL), offsetx(0), offsety(0)
1475  {
1476  cacheit = zoomCache.end();
1477  };
1478 
1479  SourcePixelSelector_CacheZoom( float zoom ) : surface(NULL), zoomFactor(1), xp(NULL), yp(NULL), offsetx(0), offsety(0)
1480  {
1481  cacheit = zoomCache.end();
1482  setZoom ( zoom );
1483  };
1484 
1485 
1486 };
1487 
1488 
1489 
1490 
1491 template<int pixelsize, class SourcePixelSelector = SourcePixelSelector_Plain<pixelsize> >
1492 class SourcePixelSelector_Flip: public SourcePixelSelector
1493 {
1494  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
1495  bool hflip;
1496  bool vflip;
1497  int x,y;
1498  int w,h;
1499  protected:
1500 
1501  void init ( const Surface& srv )
1502  {
1503  SourcePixelSelector::init(srv);
1504  w = SourcePixelSelector::getWidth()-1;
1505  h = SourcePixelSelector::getHeight()-1;
1506  };
1507 
1508 
1509 
1510  PixelType getPixel(int x, int y)
1511  {
1512  return SourcePixelSelector::getPixel( hflip? w-x : x , vflip ? h-y : y );
1513  };
1514 
1515  PixelType nextPixel()
1516  {
1517  return getPixel(x++, y);
1518  };
1519 
1520  void skipPixels( int pixNum )
1521  {
1522  x += pixNum;
1523  };
1524 
1526  {
1527  return 0;
1528  };
1529 
1530  void nextLine()
1531  {
1532  x= 0;
1533  ++y;
1534  };
1535 
1536  public:
1537  void setFlipping( bool horizontal, bool vertical )
1538  {
1539  hflip = horizontal;
1540  vflip = vertical;
1541  };
1542 
1543  SourcePixelSelector_Flip( NullParamType npt = nullParam) : hflip(false),vflip(false),x(0),y(0),w(0),h(0)
1544  {}
1545  ;
1546 
1547  SourcePixelSelector_Flip( int flip) : hflip(flip&1),vflip(flip&2),x(0),y(0),w(0),h(0)
1548  {}
1549  ;
1550 
1551 };
1552 
1553 template<int pixelsize>
1555 {
1556  public:
1558  {}
1559  ;
1561  {}
1562  ;
1563 };
1564 
1565 // template<int pixelsize, class SourcePixelSelector = SourcePixelSelector_Plain<pixelsize> > // MSVC7 fails to understand that...
1566 template<int pixelsize>
1568 {
1569  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
1570  int x,y,x1,y1;
1571  int w,h;
1572  protected:
1573  SourcePixelSelector_Rectangle() : x(0),y(0),x1(0),y1(0),w(0),h(0)
1574  {}
1575  ;
1576 public:
1577 
1578  SourcePixelSelector_Rectangle( const SDLmm::SRect& rect ) : x(0),y(0),x1(0),y1(0),w(0),h(0)
1579  {
1580  setSrcRectangle( rect );
1581  }
1582 protected:
1583 
1584  int getWidth()
1585  {
1587  };
1589  {
1591  };
1592 
1593 
1594  PixelType getPixel(int x, int y)
1595  {
1596  return SourcePixelSelector_Plain<pixelsize>::getPixel( x + x1, y + y1 );
1597  };
1598 
1599  PixelType nextPixel()
1600  {
1601  return getPixel(x++, y);
1602  };
1603 
1605  {
1606  ++y;
1607  };
1608 
1609  void skipPixels( int pixNum )
1610  {
1611  x += pixNum;
1612  };
1613 
1615  {
1616  return 0;
1617  };
1618 
1619  void nextLine()
1620  {
1621  x= 0;
1622  ++y;
1623  };
1624 
1625  public:
1626  void setSrcRectangle( SPoint pos, int width, int height )
1627  {
1628  x1 = pos.x;
1629  y1 = pos.y;
1630  w = width;
1631  h = height;
1632  };
1633  void setSrcRectangle( const SDLmm::SRect& rect )
1634  {
1635  x1 = rect.x;
1636  y1 = rect.y;
1637  w = rect.w;
1638  h = rect.h;
1639  };
1640 
1641 };
1642 
1643 template<int pixelsize>
1645 {
1646  typedef typename PixelSize2Type<pixelsize>::PixelType PixelType;
1647  int y,x1,y1;
1648  int w,h;
1649 
1650  const PixelType* pointer;
1651  const PixelType* startPointer;
1652  int pitch;
1653  int linelength;
1654  const Surface* surface;
1655  protected:
1656  SourcePixelSelector_DirectRectangle() : y(0),x1(0),y1(0),w(0),h(0),pointer(NULL), surface(NULL)
1657  {}
1658  ;
1659 
1660  int getWidth()
1661  {
1662  return min(w, surface->w() -x1 );
1663  };
1665  {
1666  return min(h, surface->h()-y1 );
1667  };
1668 
1669 
1670  void init ( const Surface& srv )
1671  {
1672  surface = &srv;
1673  startPointer = pointer = (const PixelType*)(srv.pixels());
1674  linelength = srv.pitch()/sizeof(PixelType);
1675  pitch = linelength - w -1 ;
1676  y = y1;
1677  pointer += x1 + y1 * linelength;
1678  };
1679 
1680  PixelType getPixel(int x, int y)
1681  {
1682  x += x1;
1683  y += y1;
1684  if ( x >= 0 && y >= 0 && x < surface->w() && y < surface->h() )
1685  return surface->GetPixel(SPoint(x,y));
1686  else
1687  return surface->GetPixelFormat().colorkey();
1688  };
1689 
1690 
1691  PixelType nextPixel()
1692  {
1693  return *(pointer++);
1694  };
1695 
1696 
1698  {
1699  pointer += linelength;
1700  ++y;
1701  };
1702 
1703  void skipPixels( int pixNum )
1704  {
1705  pointer += pixNum;
1706  };
1707 
1709  {
1710  return 0;
1711  };
1712 
1713  void nextLine()
1714  {
1715  pointer = startPointer + x1 + (y++) * linelength;
1716  };
1717 
1718  public:
1719  void setSrcRectangle( SPoint pos, int width, int height )
1720  {
1721  x1 = pos.x;
1722  y1 = pos.y;
1723  w = width;
1724  h = height;
1725  };
1726  void setSrcRectangle( const SDLmm::SRect& rect )
1727  {
1728  x1 = rect.x;
1729  y1 = rect.y;
1730  w = rect.w;
1731  h = rect.h;
1732  };
1733 
1734 };
1735 
1736 
1738  SDLmm::SRect rect;
1739  int x2,y2;
1740  int xrange;
1741  int w,h;
1742  SPoint pos;
1743  protected:
1744  int skipTarget( int x, int y )
1745  {
1746  int nx = x + pos.x;
1747  int ny = y + pos.y;
1748  if ( nx >= rect.x && ny >= rect.y && nx < x2 && ny < y2 )
1749  return 0;
1750  else {
1751  if ( ny < rect.y )
1752  return xrange - x;
1753  else
1754  if ( nx < rect.x )
1755  return rect.x - nx;
1756  else
1757  if (ny >= y2 )
1758  return -1;
1759  else
1760  if ( nx >= x2 )
1761  return xrange - x;
1762  else
1763  return 1;
1764  }
1765  };
1766  void init( const Surface& srv, const SPoint& position, int xrange, int yrange )
1767  {
1768  w = srv.w();
1769  h = srv.h();
1770  pos = position;
1771  this->xrange = xrange;
1772  };
1773 
1774  public:
1775  void setTargetRect( const SDL_Rect& r )
1776  {
1777  rect = r;
1778  x2 = r.x + r.w;
1779  y2 = r.y + r.h;
1780  };
1781 
1782  void setClippingRect( SDL_Surface* srv )
1783  {
1784  setTargetRect( srv->clip_rect );
1785  };
1786 
1787  TargetPixelSelector_Rect ( NullParamType npt = nullParam ) :w(0xffffff),h(0xffffff) {};
1788  };
1789 
1790 
1791 /*
1792 
1793  template<class SourceColorTransform, class ColorMerger, class SourcePixelSelector>
1794  void megaBlit( const Surface& src, Surface& dst, SPoint dstPos )
1795  {
1796  switch ( dst.GetPixelFormat().BytesPerPixel() ) {
1797  case 1: megaBlit<1,SourceColorTransform,ColorMerger,SourcePixelSelector>( src, dst, dstPos ); break;
1798  case 2: megaBlit<2,SourceColorTransform,ColorMerger,SourcePixelSelector>( src, dst, dstPos ); break;
1799  case 4: megaBlit<4,SourceColorTransform,ColorMerger,SourcePixelSelector>( src, dst, dstPos ); break;
1800  };
1801  }
1802 
1803 */
1804 
1805 #endif
1806 
void assign(PixelType src, PixelType *dest)
Definition: blitter.h:918
ColorMerger_AlphaMixer(NullParamType npt=nullParam)
Definition: blitter.h:908
Color transform(Color col)
Definition: blitter.h:544
ColorTransform_Gray(NullParamType npt)
Definition: blitter.h:593
void assign(PixelType src, PixelType *dest)
Definition: blitter.h:902
void setZoom(float factor)
Definition: blitter.h:1447
void setTargetRect(const SDL_Rect &r)
Definition: blitter.h:1775
PixelType getPixel(int x, int y)
Definition: blitter.h:1384
void init(const Surface &srf)
Definition: blitter.h:689
void setClippingRect(SDL_Surface *srv)
Definition: blitter.h:1782
void skipPixels(int pixNum)
Definition: blitter.h:1288
ColorConverter(const Surface &sourceSurface, Surface &targetSurface)
Definition: blitter.h:225
void assign(PixelType src, PixelType *dest)
Definition: blitter.h:846
A Device Independent color. Shamelessly pinched from Paragui to reduce coupling.
Definition: surface.h:30
static int ysize
Definition: blitter.h:1121
TargetPixelSelector_Rect(NullParamType npt=nullParam)
Definition: blitter.h:1787
PixelType getPixel(int x, int y)
Definition: blitter.h:1063
void init(const Surface &src)
Definition: blitter.h:518
void assign(PixelType src, PixelType *dest)
Definition: blitter.h:770
SourcePixelSelector_DirectRotation(NullParamType npt=nullParam)
Definition: blitter.h:1107
TargetPixelSelector_All(NullParamType npt=nullParam)
Definition: blitter.h:78
ColorMerger_AlphaMixer(NullParamType npt=nullParam)
Definition: blitter.h:926
ColorMerger_AlphaShadow(NullParamType npt=nullParam)
Definition: blitter.h:881
void blit(const Surface &src, Surface &dst, SPoint dstPos)
Definition: blitter.h:349
void setNeutralTranslationTable(const Uint8 *translationTable)
Definition: blitter.h:956
void skipPixels(int pixNum)
Definition: blitter.h:158
txlattables xlattables
Definition: palette.cpp:37
void init(const Surface &src)
Definition: blitter.h:588
int getFirstBit(int zahl)
Count the number of zero bits on the LSB side of "zahl".
Definition: misc.cpp:45
static const Uint32 transparent
Definition: surface.h:65
void assign(PixelType src, PixelType *dest)
Definition: blitter.h:612
ColorMerger_AlphaMerge(NullParamType npt=nullParam)
Definition: blitter.h:778
void setZoom(float factor)
Definition: blitter.h:1305
ColorMerger_Alpha_XLAT_TableShifter(const Uint8 *translationTable)
Definition: blitter.h:964
SourcePixelSelector_CacheZoom(float zoom)
Definition: blitter.h:1479
bool isOpaque(PixelType src)
Definition: blitter.h:697
Uint8 * colormixbufchar
Definition: palette.cpp:39
void init(const Surface &srv)
Definition: blitter.h:1670
PixelType getPixel(int x, int y)
Definition: blitter.h:1680
ColorMerger_Alpha_XLAT_TableShifter(NullParamType npt=nullParam)
Definition: blitter.h:989
void assign(PixelType src, PixelType *dest)
Definition: blitter.h:750
bool isOpaque(PixelType src)
Definition: blitter.h:671
SourcePixelSelector_CacheZoom(NullParamType npt=nullParam)
Definition: blitter.h:1474
SourcePixelSelector_CacheRotation(const Surface &srv, int degrees)
Definition: blitter.h:1246
Uint32 PixelType
Definition: blitter.h:62
int getWidth()
Definition: blitter.h:334
void assign(PixelType src, PixelType *dest) const
Definition: blitter.h:1005
void init(const Surface &srv)
Definition: blitter.h:1501
void skipPixels(int pixNum)
Definition: blitter.h:1609
void init(const Surface &srf)
Definition: blitter.h:658
Uint16 PixelType
Definition: blitter.h:56
void assign(PixelType *dest) const
Definition: blitter.h:637
PixelSize2Type< 4 >::PixelType SourcePixelType
Definition: blitter.h:216
ColorConverter(const Surface &sourceSurface, Surface &targetSurface)
Definition: blitter.h:267
void setZoomOffset(int x, int y)
Definition: blitter.h:1436
SourcePixelSelector_DirectFlip(NullParamType npt=nullParam)
Definition: blitter.h:1557
void skipPixels(int pixNum)
Definition: blitter.h:1520
TargetPixelType convert(SourcePixelType sp)
Definition: blitter.h:241
map< float, int * > ZoomMap
Definition: blitter.h:1354
VehicleType * transform(int id, const vector< int > &translation)
Definition: edmisc.cpp:2074
int getHeight()
Definition: blitter.h:338
SourcePixelSelector_Plain(NullParamType npt)
Definition: blitter.h:182
PixelType nextPixel()
Definition: blitter.h:1283
PixelSize2Type< 1 >::PixelType SourcePixelType
Definition: blitter.h:258
void init(const Surface &dst)
Definition: blitter.h:609
Color transform(Color col)
Definition: blitter.h:582
MegaBlitter()
Definition: blitter.h:323
SourcePixelSelector_DirectFlip(int flip)
Definition: blitter.h:1560
bool isOpaque(PixelType src)
Definition: blitter.h:734
SourcePixelSelector_Rotation(int degreesToRotate)
Definition: blitter.h:1099
int skipTarget(int x, int y)
Definition: blitter.h:89
PixelType getPixel(int x, int y)
Definition: blitter.h:142
void setTranslationTable(const Uint8 *translationTable)
Definition: blitter.h:553
TargetPixelType convert(SourcePixelType sp)
Definition: blitter.h:288
void assign(PixelType src, PixelType *dest) const
Definition: blitter.h:1029
NullParamType nullParam
Definition: blitter.cpp:30
ColorTransform_None(NullParamType npt)
Definition: blitter.h:522
SourcePixelSelector_Zoom(NullParamType npt=nullParam)
Definition: blitter.h:1335
void initSource(const Surface &src)
Definition: blitter.h:343
void setSrcRectangle(const SDLmm::SRect &rect)
Definition: blitter.h:1726
static const Uint32 opaque
Definition: surface.h:66
PixelType nextPixel()
Definition: blitter.h:1515
PixelSize2Type< BytesPerTargetPixel >::PixelType TargetPixelType
Definition: blitter.h:196
void init(const Surface &srf)
Definition: blitter.h:868
void setAngle(int degrees)
Definition: blitter.h:1091
PixelType transform(PixelType col)
Definition: blitter.h:514
ColorTransform_XLAT(const Uint8 *t)
Definition: blitter.h:562
PixelType getPixel(int x, int y)
Definition: blitter.h:1278
PixelType getPixel(int x, int y)
Definition: blitter.h:1594
ColorMerger_Brightness(float brightness)
Definition: blitter.h:1015
ColorMerger_ColoredOverwrite(DI_Color color)
Definition: blitter.h:641
static int xsize
Definition: blitter.h:1120
SDLmm::Color Color
Definition: blitter.h:35
ColorMerger_Alpha_XLAT_TableShifter(const Uint8 *translationTable)
Definition: blitter.h:992
void init(const Surface &srv, const SPoint &position, int xrange, int yrange)
Definition: blitter.h:1766
ColorConverter(const Surface &sourceSurface, Surface &targetSurface)
Definition: blitter.h:201
ColorMerger_AlphaShadow(const Uint8 *translationTable)
Definition: blitter.h:884
void init(const Surface &srv)
Definition: blitter.h:1055
SourcePixelSelector_CacheRotation(NullParamType npt=nullParam)
Definition: blitter.h:1242
ColorMerger_PlainOverwrite(NullParamType npt)
Definition: blitter.h:617
void assign(PixelType src, PixelType *dest)
Definition: blitter.h:941
SDLmm::SPoint SPoint
Definition: surface.h:27
const int ColorMerger_Alpha_XLAT_Table_shadings[8]
Definition: blitter.cpp:43
int skipTarget(int x, int y)
Definition: blitter.h:1744
void init(const Surface &src)
Definition: blitter.h:540
void init(const Surface &srv)
Definition: blitter.h:134
PixelSize2Type< BytesPerTargetPixel >::PixelType SourcePixelType
Definition: blitter.h:195
static ZoomMap zoomCache
Definition: blitter.h:1355
TargetPixelSelector_Valid(NullParamType npt=nullParam)
Definition: blitter.h:110
void assign(PixelType src, PixelType *dest) const
Definition: blitter.h:633
SourcePixelSelector_Flip(NullParamType npt=nullParam)
Definition: blitter.h:1543
void setZoom(float factorX, float factorY)
Definition: blitter.h:1310
ColorTransform_XLAT(NullParamType npt)
Definition: blitter.h:558
void assign(PixelType src, PixelType *dest)
Definition: blitter.h:975
ColorMerger_AlphaMerge(NullParamType npt=nullParam)
Definition: blitter.h:825
void setAngle(const Surface &srv, int degrees)
Definition: blitter.h:1214
void skipPixels(int pixNum)
Definition: blitter.h:1398
PixelSize2Type< 1 >::PixelType TargetPixelType
Definition: blitter.h:217
ColorMerger_AlphaShadow(const Uint8 *translationTable)
Definition: blitter.h:857
SourcePixelSelector_Rotation(NullParamType npt=nullParam)
Definition: blitter.h:1096
MegaBlitter(const SourceColorTransform< BytesPerSourcePixel > &scm, const ColorMerger< BytesPerTargetPixel > &cm, const SourcePixelSelector< BytesPerSourcePixel > &sps, const TargetPixelSelector &tps)
Definition: blitter.h:326
void setNeutralTranslationTable(const Uint8 *translationTable)
Definition: blitter.h:984
SourcePixelSelector_CacheRotation(pair< const Surface *, int > p)
Definition: blitter.h:1251
ColorMerger_AlphaShadow(NullParamType npt=nullParam)
Definition: blitter.h:854
void init(const Surface &srv, const SPoint &pos, int xrange, int yrange)
Definition: blitter.h:74
ColorMerger_AlphaOverwrite(NullParamType npt=nullParam)
Definition: blitter.h:758
void assign(PixelType src, PixelType *dest)
Definition: blitter.h:789
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
SourcePixelSelector_DirectRotation(int degreesToRotate)
Definition: blitter.h:1109
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
PixelType nextPixel()
Definition: blitter.h:150
void skipPixels(int pixNum)
Definition: blitter.h:1074
int skipTarget(int x, int y)
Definition: blitter.h:70
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
void megaBlitter(const Surface &src, Surface &dst, const SPoint &pos, const SourceColorTransformParameter &scmp=nullParam, const ColorMergerParameter &cmp=nullParam, const SourcePixelSelectorParameter spsp=nullParam, const TargetPixelSelectorParameter tpsp=nullParam)
Definition: blitter.h:410
ColorMerger_Set(SDLmm::Color color)
Definition: blitter.h:1035
PixelType getPixel(int x, int y)
Definition: blitter.h:1510
static map< int, int * > cache
Definition: blitter.h:1119
PixelSize2Type< 4 >::PixelType TargetPixelType
Definition: blitter.h:259
void init(const Surface &srv, const SPoint &pos, int xrange, int yrange)
Definition: blitter.h:102
TargetPixelType convert(SourcePixelType sp)
Definition: blitter.h:204
ColorMerger_Alpha_XLAT_TableShifter(NullParamType npt=nullParam)
Definition: blitter.h:961
void init(const Surface &srv)
Definition: blitter.h:1139
SourcePixelSelector_DirectZoom(NullParamType npt=nullParam)
Definition: blitter.h:1345
SPoint getPixelRotationLocation(SPoint pos, int width, int height, int degrees)
transforms the coordinate for an image rotation
Definition: basegfx.cpp:1999
void setSrcRectangle(SPoint pos, int width, int height)
Definition: blitter.h:1626
void setFlipping(bool horizontal, bool vertical)
Definition: blitter.h:1537
void assign(PixelType src, PixelType *dest)
Definition: blitter.h:874
SourcePixelSelector_Flip(int flip)
Definition: blitter.h:1547
SDLmm::Color lighten_Color(SDLmm::Color color, int factor16)
Definition: lighten.h:37
void setSrcRectangle(SPoint pos, int width, int height)
Definition: blitter.h:1719
void init(const Surface &dst) const
Definition: blitter.h:629
void init(const Surface &srf)
Definition: blitter.h:717
void setSize(int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool forceSquare=true)
Definition: blitter.h:1325
void setSrcRectangle(const SDLmm::SRect &rect)
Definition: blitter.h:1633
SourcePixelSelector_Rectangle(const SDLmm::SRect &rect)
Definition: blitter.h:1578