36 #include "font_data.inc" 42 const MP_Font medium_bold_font = { 0, 128, 7, 13, medium_bold_font_data };
43 const MP_Font giant_font = { 0, 128, 9, 15, giant_font_data };
56 add(0.4f,Colour(0,0,0.5f));
57 add(0.75f,Colour(0,0.6f,1));
61 add(0,Colour(0,0,.5f));
62 add(0.15f,Colour(0,0,1));
63 add(0.4f,Colour(0,1,1));
64 add(0.7f,Colour(1,1,0));
65 add(0.9f,Colour(1,.33f,0));
66 add(1,Colour(.5f,0,0));
72 addb(127,255,237,217);
79 addb( 13, 10, 20,255);
80 addb( 26, 30,184,255);
81 addb( 38, 80,235,255);
82 addb( 52,191,239,250);
83 addb( 65,228,240,245);
84 addb( 76,241,241,212);
85 addb( 77,241,241,212);
86 addb( 88,245,240,175);
87 addb(101,248,235,130);
88 addb(114,250,204, 38);
89 addb(127,243,153, 13);
91 addb(153,165, 32, 32);
93 addb(179,128,128,153);
94 addb(192,179,179,204);
95 addb(205,204,204,230);
96 addb(218,230,230,242);
97 addb(231,242,242,250);
98 addb(255,252,252,255);
102 addb( 36, 64, 0,128);
104 addb(117, 0,255,255);
106 addb(188,255,255, 0);
108 addb(255,255,255,255);
115 void LS_Image::write_char (
int xpos,
int ypos,
const Colour &col,
char c,
118 planck_assert ((c>=font.offset) && (c<font.offset+font.num_chars),
119 "write_char: character out of range");
120 for (
int i=0; i<font.xpix; ++i)
121 for (
int j=0; j<font.ypix; ++j)
123 int ofs = (c-font.offset)*font.xpix*font.ypix + j*font.xpix + i;
124 if (font.data[ofs]!=
' ')
125 for (
int m=0; m<scale; ++m)
126 for (
int n=0; n<scale; ++n)
127 put_pixel(xpos+scale*i+m,ypos+scale*j+n,col);
131 LS_Image::LS_Image ()
132 : font(medium_bold_font) {}
134 LS_Image::LS_Image (
int xres,
int yres)
135 : font(medium_bold_font), pixel(xres,yres,Colour(0,0,0)) {}
138 const string &text,
int scale)
140 for (
tsize m=0; m<text.length(); ++m)
141 write_char(xpos+m*scale*font.xpix, ypos, col, text[m],scale);
145 const string &text,
int scale)
147 xpos-=(scale*text.length()*font.xpix)/2;
148 ypos-=scale*font.ypix/2;
149 annotate (xpos,ypos,col,text,scale);
157 ofstream out(file.c_str(), ios_base::out | ios_base::binary);
163 const uint8 header[18] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
164 uint8(xres%256), uint8(xres/256), uint8(yres%256), uint8(yres/256), 24, 32};
167 vector <uint8> line(3*xres);
168 for (
tsize j=0; j<yres; ++j)
170 for (
tsize i=0; i<xres; ++i)
172 line[i*3 ]=pixel[i][j].b;
173 line[i*3+1]=pixel[i][j].g;
174 line[i*3+2]=pixel[i][j].r;
176 bo.
put(line.data(),3*xres);
178 planck_assert(out,
"error writing output file '" + file +
"'");
188 while (cm.getNext(cbeg,csz))
190 buf.push_back(uint8(csz-1+128));
191 buf.push_back(px[begin].b);
192 buf.push_back(px[begin].g);
193 buf.push_back(px[begin].r);
201 while (cm.getNext(cbeg,csz))
203 buf.push_back(uint8(csz-1));
204 for (
tsize cnt=begin+cbeg; cnt< begin+cbeg+csz; ++cnt)
206 buf.push_back(px[cnt].b);
207 buf.push_back(px[cnt].g);
208 buf.push_back(px[cnt].r);
217 ofstream out(file.c_str(), ios_base::out | ios_base::binary);
223 const uint8 header[18] = { 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
224 uint8(xres%256), uint8(xres/256), uint8(yres%256), uint8(yres/256), 24, 32};
229 for (
tsize y=0; y<yres; ++y)
232 for (
tsize x=0; x<xres; ++x)
239 write_unequal_range (px,xstart,xstart+1,buf);
244 if (px[xstart+1]==px[xstart])
247 while ((xend<xres) && (px[xend]==px[xstart])) ++xend;
248 write_equal_range (px,xstart,xend,buf);
254 while ((xend<xres) && (px[xend]!=px[xend-1])) ++xend;
255 write_unequal_range (px,xstart,xend,buf);
260 bo.
put(buf.data(), buf.size());
262 planck_assert(out,
"error writing output file '" + file +
"'");
267 ofstream out(file.c_str(), ios_base::out | ios_base::binary);
274 ostringstream header;
275 header <<
"P6" << endl << xres << endl << yres << endl << 255 << endl;
276 string hdrdata = header.str();
277 bo.
put(hdrdata.c_str(),hdrdata.size());
279 vector <uint8> line(3*xres);
280 for (
tsize j=0; j<yres; ++j)
282 for (
tsize i=0; i<xres; ++i)
284 line[i*3 ]=pixel[i][j].r;
285 line[i*3+1]=pixel[i][j].g;
286 line[i*3+2]=pixel[i][j].b;
288 bo.
put(line.data(),3*xres);
290 planck_assert(out,
"error writing output file '" + file +
"'");
void write_TGA_rle(const std::string &file) const
void write_PPM(const std::string &file) const
void annotate(int xpos, int ypos, const Colour &col, const std::string &text, int scale=1)
void annotate_centered(int xpos, int ypos, const Colour &col, const std::string &text, int scale=1)
void write_TGA(const std::string &file) const
bostream & put(const T *data, size_t num)
void set_font(const MP_Font &fnt)
string dataToString(const T &x)
#define planck_assert(testval, msg)
void setPredefined(int num)