ls_image.h
Go to the documentation of this file.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 #ifndef PLANCK_LS_IMAGE_H
00033 #define PLANCK_LS_IMAGE_H
00034
00035 #include <string>
00036 #include <vector>
00037 #include <iostream>
00038 #include <algorithm>
00039 #include "arr.h"
00040 #include "datatypes.h"
00041 #include "colour.h"
00042 #include "linear_map.h"
00043
00044
00045
00046
00047
00048 class Palette: public linearMap<Colour>
00049 {
00050 public:
00051
00052
00053 void add (float f, const Colour &c)
00054 { addVal (f, c); }
00055 void addb (uint8 f, uint8 r,uint8 g, uint8 b)
00056 { addVal (f, Colour(r/255.,g/255.,b/255.)); }
00057
00058 void setPredefined(int num);
00059
00060
00061 Colour Get_Colour (float f) const
00062 { return getVal_const(f); }
00063 };
00064
00065 class Colour8
00066 {
00067 private:
00068 void import (const Colour &col)
00069 {
00070 using namespace std;
00071 r = uint8(max(0,min(255,int(col.r*256))));
00072 g = uint8(max(0,min(255,int(col.g*256))));
00073 b = uint8(max(0,min(255,int(col.b*256))));
00074 }
00075
00076 public:
00077 uint8 r,g,b;
00078
00079 Colour8() {}
00080 Colour8 (uint8 R, uint8 G, uint8 B)
00081 : r(R), g(G), b(B) {}
00082 Colour8 (const Colour &col)
00083 { import (col); }
00084 const Colour8 &operator= (const Colour &col)
00085 { import (col); return *this; }
00086 bool operator== (const Colour8 &that)
00087 { return (r == that.r) && (g == that.g) && (b == that.b); }
00088 bool operator!= (const Colour8 &that)
00089 { return (r != that.r) || (g != that.g) || (b != that.b); }
00090 };
00091
00092 class MP_Font
00093 {
00094 public:
00095 int offset, num_chars, xpix, ypix;
00096 const char *data;
00097 };
00098
00099 extern const MP_Font medium_bold_font;
00100 extern const MP_Font giant_font;
00101
00102
00103 class LS_Image
00104 {
00105 private:
00106 MP_Font font;
00107 arr2<Colour8> pixel;
00108
00109 void write_char (int xpos, int ypos, const Colour &col, char c,
00110 int scale=1);
00111
00112 public:
00113
00114 LS_Image ();
00115
00116 LS_Image (int xres, int yres);
00117
00118 ~LS_Image () {}
00119
00120
00121 void fill (const Colour &col) { pixel.fill(col); }
00122
00123 void set_font (const MP_Font &fnt);
00124
00125
00126
00127 void annotate (int xpos, int ypos, const Colour &col,
00128 const std::string &text, int scale=1);
00129
00130
00131 void annotate_centered (int xpos, int ypos, const Colour &col,
00132 const std::string &text, int scale=1);
00133
00134 void put_pixel (tsize i, tsize j, const Colour &col)
00135 {
00136 if ((i<pixel.size1()) && (j<pixel.size2()))
00137 pixel[i][j] = col;
00138 }
00139
00140
00141 Colour8 get_pixel (tsize i, tsize j)
00142 {
00143 return ((i<pixel.size1()) && (j<pixel.size2())) ?
00144 pixel[i][j] : Colour8(0, 0, 0);
00145 }
00146
00147
00148 void write_TGA (const std::string &file) const;
00149
00150
00151 void write_TGA_rle (const std::string &file) const;
00152
00153
00154 void write_PPM (const std::string &file) const;
00155 };
00156
00157
00158
00159 #endif