moved almost all hardcoded constants to "define.dat"
[k8-i-v-a-n.git] / src / felib / rawbit.h
blobf8c655ae31dfa60f00d6e61cad82292b00772a8d
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 #ifndef __FELIB_COLORBIT_H__
13 #define __FELIB_COLORBIT_H__
15 #include <stdio.h>
17 #include <cstdarg>
18 #include <map>
19 #include <vector>
21 #include "v2.h"
23 class outputfile;
24 class inputfile;
25 class bitmap;
26 class cachedfont;
27 class festring;
30 typedef std::map<col16, std::pair<cachedfont *, cachedfont *> > fontcache;
33 /* actually this is simple 256-color with palette PCX codec */
34 class rawbitmap {
35 public:
36 rawbitmap (cfestring &FileName);
37 rawbitmap (v2);
38 ~rawbitmap ();
39 void Save (cfestring &FileName);
40 void MaskedBlit (bitmap *Bitmap, v2 Src, v2 Dest, v2 Border, packcol16 *Color) const;
41 void MaskedBlit (bitmap *Bitmap, packcol16 *Color) const;
43 void LIKE_PRINTF(5, 6) Printf (bitmap *Bitmap, v2 Pos, packcol16 Color, cchar *Format, ...) const;
44 void LIKE_PRINTF(5, 6) PrintfColored (bitmap *Bitmap, v2 Pos, packcol16 Color, cchar *Format, ...) const;
45 void LIKE_PRINTF(5, 6) PrintfUnshaded (bitmap *Bitmap, v2 Pos, packcol16 Color, cchar *Format, ...) const;
46 void LIKE_PRINTF(5, 6) PrintfUnshadedColored (bitmap *Bitmap, v2 Pos, packcol16 Color, cchar *Format, ...) const;
47 cachedfont *Colorize (cpackcol16 *Color, alpha BaseAlpha=255, cpackalpha *Alpha=0) const;
48 bitmap *Colorize (v2 Pos, v2 Border, v2 Move, cpackcol16 *Color, alpha BaseAlpha=255,
49 cpackalpha *Alpha=0, cuchar *RustData=0, truth AllowReguralColors=true) const;
50 v2 GetSize () const { return Size; }
52 void AlterGradient (v2 Pos, v2 Border, int MColor, int Amount, truth Clip);
53 void SwapColors (v2 Pos, v2 Border, int Color1, int Color2);
54 void Roll (v2 Pos, v2 Border, v2 Move, paletteindex *TempBuffer);
56 void CreateFontCache (packcol16 Color);
57 static truth IsMaterialColor (int Color) { return Color >= 192; }
58 static int GetMaterialColorIndex (int Color) { return (Color-192) >> 4; }
59 int GetMaterialColorIndex (int X, int Y) const { return (PaletteBuffer[Y][X]-192) >> 4; }
60 truth IsTransparent (v2 Pos) const;
61 truth IsMaterialColor1 (v2 Pos) const;
62 v2 RandomizeSparklePos (cv2 *ValidityArray, v2 *PossibleBuffer, v2 Pos, v2 Border, int ValidityArraySize, int SparkleFlags) const;
63 void CopyPaletteFrom (rawbitmap *Bitmap);
64 void PutPixel (v2 Pos, paletteindex Color) { PaletteBuffer[Pos.Y][Pos.X] = Color; }
65 paletteindex GetPixel (v2 Pos) const { return PaletteBuffer[Pos.Y][Pos.X]; }
66 void Clear ();
67 void NormalBlit (rawbitmap *Bitmap, v2 Src, v2 Dest, v2 Border, int Flags=0) const;
69 const uChar *getPalette () const { return Palette; }
70 const uChar *getBuffer () const { return PaletteBuffer[0]; }
72 protected:
73 static truth strHasCtlCodes (cchar *str);
74 void printfColoredVA (bitmap *bmp, v2 pos, packcol16 clr, truth shaded, cchar *fmt, va_list vap) const;
75 void printstrColored (bitmap *bmp, v2 pos, packcol16 clr, truth shaded, cchar *str) const;
77 protected:
78 void loadFromFile (FILE *fl);
79 void loadPCX (FILE *fl);
80 #ifdef HAVE_LIBPNG
81 void loadPNG (FILE *fl);
82 #endif
84 static festring curfile;
85 static unsigned char getb (FILE* fl);
87 protected:
88 v2 Size;
89 uChar *Palette;
90 paletteindex **PaletteBuffer;
91 fontcache FontCache;
95 #endif