1 /*
2  *
3  *  Iter Vehemens ad Necem (IVAN)
4  *  Copyright (C) Timo Kiviluoto
5  *  Released under the GNU General
6  *  Public License
7  *
8  *  See LICENSING which should be included
9  *  along with this file for more details
10  *
11  */
12 
13 #ifndef __COLORBIT_H__
14 #define __COLORBIT_H__
15 
16 #include <map>
17 #include <vector>
18 
19 #include "v2.h"
20 
21 class outputfile;
22 class inputfile;
23 class bitmap;
24 class cachedfont;
25 class festring;
26 
27 typedef std::map<col16, std::pair<cachedfont*, cachedfont*>> fontcache;
28 
29 class rawbitmap
30 {
31  public:
32   friend class bitmap;
33   rawbitmap(cfestring&);
34   rawbitmap(v2);
35   ~rawbitmap();
36   void Save(cfestring&);
37   void MaskedBlit(bitmap*, v2, v2,
38                   v2, packcol16*) const;
39   void MaskedBlit(bitmap*, packcol16*) const;
40 
41   void LIKE_PRINTF(5, 6) Printf(bitmap*, v2, packcol16,
42                                 cchar*, ...) const;
43   void LIKE_PRINTF(5, 6) PrintfUnshaded(bitmap*, v2, packcol16,
44                                         cchar*, ...) const;
45   cachedfont* Colorize(cpackcol16*, alpha = 255,
46                        cpackalpha* = 0) const;
47   bitmap* Colorize(v2, v2, v2,
48                    cpackcol16*, alpha = 255,
49                    cpackalpha* = 0,
50                    cuchar* = 0, cuchar* = 0, truth = true) const;
GetSize()51   v2 GetSize() const { return Size; }
52 
53   void AlterGradient(v2, v2, int, int, truth);
54   void SwapColors(v2, v2, int, int);
55   void Roll(v2, v2, v2, paletteindex*);
56 
57   void CreateFontCache(packcol16);
IsMaterialColor(int Color)58   static truth IsMaterialColor(int Color) { return Color >= 192; }
GetMaterialColorIndex(int Color)59   static int GetMaterialColorIndex(int Color) { return (Color - 192) >> 4; }
GetMaterialColorIndex(int X,int Y)60   int GetMaterialColorIndex(int X, int Y) const
61   { return (PaletteBuffer[Y][X] - 192) >> 4; }
62   truth IsTransparent(v2) const;
63   truth IsMaterialColor1(v2) const;
64   v2 RandomizeSparklePos(cv2*, v2*, v2, v2, int, int) const;
65   void CopyPaletteFrom(rawbitmap*);
PutPixel(v2 Pos,paletteindex Color)66   void PutPixel(v2 Pos, paletteindex Color)
67   { PaletteBuffer[Pos.Y][Pos.X] = Color; }
GetPixel(v2 Pos)68   paletteindex GetPixel(v2 Pos) const
69   { return PaletteBuffer[Pos.Y][Pos.X]; }
70   void Clear();
71   void NormalBlit(rawbitmap*, v2, v2, v2, int = 0) const;
72  protected:
73   v2 Size;
74   uchar* Palette;
75   paletteindex** PaletteBuffer;
76   fontcache FontCache;
77 };
78 
79 #endif
80