00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef PLANCK_TGA_IMAGE_H
00035 #define PLANCK_TGA_IMAGE_H
00036
00037 #include <string>
00038 #include <vector>
00039 #include <algorithm>
00040 #include "arr.h"
00041
00042
00043
00044
00045
00046 class Colour
00047 {
00048 public:
00049 float r,
00050 g,
00051 b;
00052
00053
00054 Colour() {}
00055
00056 Colour (float R, float G, float B) : r(R), g(G), b(B) {}
00057
00058 const Colour &operator*= (float fact)
00059 { r*=fact; g*=fact; b*=fact; return *this; }
00060
00061 const Colour operator+ (const Colour &c2) const
00062 { return Colour(r+c2.r, g+c2.g, b+c2.b); }
00063
00064 const Colour operator* (double f) const
00065 { return Colour(r*f, g*f, b*f); }
00066 };
00067
00068
00069 class Palette
00070 {
00071 private:
00072 std::vector<Colour> cv;
00073 std::vector<float> fv;
00074
00075 public:
00076
00077
00078 void add (float f, const Colour &c)
00079 {
00080 fv.push_back(f);
00081 cv.push_back(c);
00082 }
00083
00084 void setPredefined(int num);
00085
00086
00087 Colour Get_Colour (float f) const
00088 {
00089 if (f<=fv[0]) return cv[0];
00090 if (f>=fv[fv.size()-1]) return cv[cv.size()-1];
00091 int i=0;
00092 while (f>fv[i]) ++i;
00093 return cv[i-1]*((fv[i]-f)/(fv[i]-fv[i-1]))
00094 + cv[i]*((f-fv[i-1])/(fv[i]-fv[i-1]));
00095 }
00096 };
00097
00098 class Colour8
00099 {
00100 private:
00101 void import (const Colour &col)
00102 {
00103 using namespace std;
00104 r = max(0,min(255,int(col.r*256)));
00105 g = max(0,min(255,int(col.g*256)));
00106 b = max(0,min(255,int(col.b*256)));
00107 }
00108
00109 public:
00110 char r,g,b;
00111
00112 Colour8() {}
00113 Colour8 (unsigned char R, unsigned char G, unsigned char B)
00114 : r(R), g(G), b(B) {}
00115 Colour8 (const Colour &col)
00116 { import (col); }
00117 const Colour8 &operator= (const Colour &col)
00118 { import (col); return *this; }
00119 };
00120
00121 class Font
00122 {
00123 public:
00124 int offset, num_chars, xpix, ypix;
00125 const char *data;
00126 };
00127
00128 extern const Font medium_bold_font;
00129 extern const Font giant_font;
00130
00131
00132 class TGA_Image
00133 {
00134 private:
00135 Font font;
00136 arr2<Colour8> pixel;
00137
00138 void write_char (int xpos, int ypos, const Colour &col, char c,
00139 int scale=1);
00140
00141 public:
00142
00143 TGA_Image ();
00144
00145 TGA_Image (int xres, int yres);
00146
00147 ~TGA_Image () {}
00148
00149
00150 void fill (const Colour &col) { pixel.fill(col); }
00151
00152 void set_font (const Font &fnt);
00153
00154
00155
00156 void annotate (int xpos, int ypos, const Colour &col,
00157 const std::string &text, int scale=1);
00158
00159
00160 void annotate_centered (int xpos, int ypos, const Colour &col,
00161 const std::string &text, int scale=1);
00162
00163 void put_pixel (int i, int j, const Colour &col)
00164 {
00165 if ((i>=0) && (i<pixel.size1()) && (j>=0) && (j<pixel.size2()))
00166 pixel[i][j] = col;
00167 }
00168
00169
00170 void write (const std::string &file) const;
00171 };
00172
00173
00174
00175 #endif