Doxygen
image.cpp
浏览该文件的文档.
1 /******************************************************************************
2  *
3  *
4  *
5  *
6  * Copyright (C) 1997-2015 by Dimitri van Heesch.
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation under the terms of the GNU General Public License is hereby
10  * granted. No representations are made about the suitability of this software
11  * for any purpose. It is provided "as is" without express or implied warranty.
12  * See the GNU General Public License for more details.
13  *
14  * Documents produced by Doxygen are derivative works derived from the
15  * input used in their production; they are not affected by this license.
16  *
17  */
18 
19 #include "image.h"
20 #include <math.h>
21 #include "lodepng.h"
22 #include "config.h"
23 
24 typedef unsigned char Byte;
25 
26 /** Helper struct representing a RGBA color */
27 struct Color
28 {
33 };
34 
35 const int charSetWidth=80;
36 const int charHeight=12;
37 const int numChars=96;
38 
39 unsigned short charPos[numChars] =
40  {
41  0, 5, 8, 13, 20, 27, 38, 47,
42  50, 54, 58, 65, 72, 76, 83, 87,
43  91, 98,105,112,119,126,133,140,
44  147,154,161,164,167,174,181,188,
45  195,207,216,224,233,242,250,258,
46  267,276,279,286,294,301,312,321,
47  331,339,349,357,365,372,380,389,
48  400,409,418,427,430,434,437,443,
49  450,453,460,467,474,481,488,492,
50  499,506,509,512,518,521,530,537,
51  544,551,557,562,568,571,578,585,
52  594,600,607,613,617,620,624,631
53  };
54 
55 unsigned char charWidth[numChars] =
56  {
57  5, 3, 5, 7, 7,11, 9, 3,
58  4, 4, 7, 7, 4, 7, 4, 4,
59 
60  7, 7, 7, 7, 7, 7, 7, 7,
61  7, 7, 3, 3, 7, 7, 7, 7,
62  12, 9, 8, 9, 9, 8, 8, 9,
63  9, 3, 7, 8, 7,11, 9,10,
64  8,10, 8, 8, 7, 8, 9,11,
65  9, 9, 9, 3, 4, 3, 6, 7,
66  3, 7, 7, 7, 7, 7, 4, 7,
67  7, 3, 3, 6, 3, 9, 7, 7,
68  7, 6, 5, 6, 3, 7, 7, 9,
69  6, 7, 6, 4, 3, 4, 7, 5
70  };
71 
72 unsigned char fontRaw[charSetWidth*charHeight] = {
73  0x02, 0x50, 0x01, 0x06, 0x20, 0x60, 0xc6, 0x04, 0x00, 0x00, 0x00, 0x27,
74  0x04, 0x1c, 0x38, 0x11, 0xf1, 0xc7, 0xc7, 0x0e, 0x00, 0x00, 0x00, 0x03,
75  0x81, 0xf0, 0x10, 0x7c, 0x1e, 0x3e, 0x1f, 0x9f, 0x87, 0x88, 0x24, 0x09,
76  0x09, 0x02, 0x02, 0x41, 0x0f, 0x0f, 0x83, 0xc3, 0xe1, 0xe7, 0xf4, 0x24,
77  0x12, 0x22, 0x41, 0x20, 0x9f, 0xce, 0x30, 0x00, 0x10, 0x04, 0x00, 0x01,
78  0x00, 0x30, 0x08, 0x12, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
79  0x00, 0x00, 0x00, 0x00, 0x01, 0xac, 0x00, 0x00, 0x02, 0x51, 0x43, 0x89,
80  0x40, 0x90, 0x49, 0x15, 0x00, 0x00, 0x00, 0x28, 0x9c, 0x22, 0x44, 0x31,
81  0x02, 0x20, 0x48, 0x91, 0x00, 0x00, 0x00, 0x04, 0x46, 0x08, 0x28, 0x42,
82  0x21, 0x21, 0x10, 0x10, 0x08, 0x48, 0x24, 0x09, 0x11, 0x03, 0x06, 0x61,
83  0x10, 0x88, 0x44, 0x22, 0x12, 0x10, 0x84, 0x24, 0x12, 0x22, 0x22, 0x20,
84  0x80, 0x4a, 0x11, 0x00, 0x20, 0x04, 0x00, 0x01, 0x00, 0x40, 0x08, 0x00,
85  0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00,
86  0x02, 0x22, 0x00, 0x00, 0x02, 0x51, 0x45, 0x49, 0x40, 0x90, 0x89, 0x0a,
87  0x00, 0x00, 0x00, 0x48, 0x84, 0x02, 0x04, 0x51, 0x02, 0x00, 0x88, 0x91,
88  0x00, 0x00, 0x00, 0x04, 0x44, 0xd4, 0x28, 0x42, 0x40, 0x20, 0x90, 0x10,
89  0x10, 0x08, 0x24, 0x09, 0x21, 0x03, 0x06, 0x51, 0x20, 0x48, 0x48, 0x12,
90  0x12, 0x00, 0x84, 0x22, 0x22, 0x22, 0x22, 0x11, 0x00, 0x89, 0x12, 0x80,
91  0x31, 0xc5, 0x87, 0x0d, 0x1c, 0xe3, 0x4b, 0x12, 0x49, 0x29, 0x16, 0x1c,
92  0x58, 0x69, 0x4c, 0xe8, 0x91, 0x44, 0x61, 0x44, 0xf2, 0x22, 0x00, 0x00,
93  0x02, 0x07, 0xe5, 0x06, 0x80, 0x60, 0x10, 0x95, 0x08, 0x00, 0x00, 0x48,
94  0x84, 0x04, 0x18, 0x51, 0xe2, 0xc0, 0x87, 0x11, 0x24, 0x18, 0x03, 0x00,
95  0x89, 0x24, 0x44, 0x42, 0x40, 0x20, 0x90, 0x10, 0x10, 0x08, 0x24, 0x09,
96  0x41, 0x02, 0x8a, 0x51, 0x20, 0x48, 0x48, 0x12, 0x11, 0x80, 0x84, 0x22,
97  0x21, 0x24, 0x14, 0x11, 0x01, 0x09, 0x14, 0x40, 0x02, 0x26, 0x48, 0x93,
98  0x22, 0x44, 0xcc, 0x92, 0x51, 0x36, 0x99, 0x22, 0x64, 0x99, 0x92, 0x48,
99  0x91, 0x44, 0x52, 0x44, 0x12, 0x22, 0x00, 0x00, 0x02, 0x01, 0x43, 0x80,
100  0x80, 0xa0, 0x10, 0x84, 0x08, 0x00, 0x00, 0x88, 0x84, 0x08, 0x04, 0x90,
101  0x13, 0x21, 0x08, 0x8f, 0x00, 0x61, 0xf0, 0xc0, 0x8a, 0x24, 0x44, 0x7c,
102  0x40, 0x20, 0x9f, 0x9f, 0x11, 0xcf, 0xe4, 0x09, 0xc1, 0x02, 0x8a, 0x49,
103  0x20, 0x4f, 0x88, 0x13, 0xe0, 0x60, 0x84, 0x22, 0x21, 0x54, 0x08, 0x0a,
104  0x02, 0x08, 0x90, 0x00, 0x00, 0x24, 0x48, 0x11, 0x22, 0x44, 0x48, 0x92,
105  0x61, 0x24, 0x91, 0x22, 0x44, 0x89, 0x10, 0x48, 0x91, 0x24, 0x8c, 0x44,
106  0x22, 0x22, 0x64, 0x00, 0x02, 0x07, 0xe1, 0x41, 0x31, 0x14, 0x10, 0x80,
107  0x3e, 0x07, 0xc0, 0x88, 0x84, 0x10, 0x05, 0x10, 0x12, 0x21, 0x08, 0x81,
108  0x01, 0x80, 0x00, 0x31, 0x0a, 0x24, 0x7c, 0x42, 0x40, 0x20, 0x90, 0x10,
109  0x10, 0x48, 0x24, 0x09, 0x21, 0x02, 0x52, 0x45, 0x20, 0x48, 0x08, 0x92,
110  0x20, 0x10, 0x84, 0x21, 0x41, 0x54, 0x14, 0x04, 0x04, 0x08, 0x90, 0x00,
111  0x01, 0xe4, 0x48, 0x11, 0x3e, 0x44, 0x48, 0x92, 0x61, 0x24, 0x91, 0x22,
112  0x44, 0x89, 0x0c, 0x48, 0x8a, 0x24, 0x8c, 0x48, 0x44, 0x21, 0x98, 0x00,
113  0x02, 0x02, 0x85, 0x41, 0x49, 0x08, 0x10, 0x80, 0x08, 0x00, 0x00, 0x88,
114  0x84, 0x20, 0x45, 0xf9, 0x12, 0x21, 0x08, 0x81, 0x00, 0x61, 0xf0, 0xc1,
115  0x0a, 0x68, 0x82, 0x42, 0x40, 0x20, 0x90, 0x10, 0x10, 0x48, 0x24, 0x89,
116  0x11, 0x02, 0x52, 0x45, 0x20, 0x48, 0x08, 0x52, 0x12, 0x10, 0x84, 0x21,
117  0x40, 0x88, 0x22, 0x04, 0x08, 0x08, 0x90, 0x00, 0x02, 0x24, 0x48, 0x11,
118  0x20, 0x44, 0x48, 0x92, 0x51, 0x24, 0x91, 0x22, 0x44, 0x89, 0x02, 0x48,
119  0x8a, 0x2a, 0x92, 0x28, 0x42, 0x22, 0x00, 0x00, 0x00, 0x02, 0x85, 0x41,
120  0x49, 0x18, 0x10, 0x80, 0x08, 0x00, 0x01, 0x08, 0x84, 0x20, 0x44, 0x11,
121  0x12, 0x22, 0x08, 0x91, 0x00, 0x18, 0x03, 0x00, 0x09, 0xb0, 0x82, 0x42,
122  0x21, 0x21, 0x10, 0x10, 0x08, 0xc8, 0x24, 0x89, 0x09, 0x02, 0x22, 0x43,
123  0x10, 0x88, 0x04, 0x22, 0x12, 0x10, 0x84, 0x20, 0x80, 0x88, 0x22, 0x04,
124  0x10, 0x08, 0x50, 0x00, 0x02, 0x26, 0x48, 0x93, 0x22, 0x44, 0xc8, 0x92,
125  0x49, 0x24, 0x91, 0x22, 0x64, 0x99, 0x12, 0x49, 0x84, 0x11, 0x21, 0x28,
126  0x82, 0x22, 0x00, 0x00, 0x02, 0x02, 0x83, 0x82, 0x30, 0xe4, 0x10, 0x80,
127  0x00, 0x20, 0x05, 0x07, 0x04, 0x3e, 0x38, 0x10, 0xe1, 0xc2, 0x07, 0x0e,
128  0x24, 0x00, 0x00, 0x01, 0x04, 0x00, 0x82, 0x7c, 0x1e, 0x3e, 0x1f, 0x90,
129  0x07, 0x48, 0x24, 0x71, 0x05, 0xf2, 0x22, 0x41, 0x0f, 0x08, 0x03, 0xd2,
130  0x11, 0xe0, 0x83, 0xc0, 0x80, 0x88, 0x41, 0x04, 0x1f, 0xc8, 0x50, 0x00,
131  0x01, 0xd5, 0x87, 0x0d, 0x1c, 0x43, 0x48, 0x92, 0x45, 0x24, 0x91, 0x1c,
132  0x58, 0x69, 0x0c, 0x66, 0x84, 0x11, 0x21, 0x10, 0xf2, 0x22, 0x00, 0x00,
133  0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x20, 0x00, 0x00,
134  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
135  0x03, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137  0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
138  0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, 0x08, 0x00, 0x00,
139  0x00, 0x00, 0x00, 0x10, 0x02, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140  0x00, 0x00, 0x09, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141  0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144  0x00, 0x08, 0x10, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x02,
145  0x00, 0x00, 0x00, 0x00, 0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
146  0x02, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
147  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x00,
151  0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x00, 0x00,
152  0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0xac, 0x00, 0x00
153 };
154 
155 static Color palette[] =
156 {
157  { 0xff, 0xff, 0xff, 0x00 },
158  { 0x00, 0x00, 0x00, 0xff },
159  { 0xff, 0xff, 0xc0, 0xff },
160  { 0x9f, 0x9f, 0x60, 0xff },
161  { 0x90, 0x00, 0x00, 0xff },
162  { 0x00, 0x90, 0x00, 0xff },
163  { 0x00, 0x00, 0x90, 0xff },
164  { 0xc0, 0xc0, 0xc0, 0xff }
165 };
166 
167 // for alpha we use x^(1/1.3)
168 static Color palette2[] =
169 {
170  { 0x00, 0x00, 0x00, 0x00 },
171  { 0x00, 0x00, 0x00, 0x2e },
172  { 0x00, 0x00, 0x00, 0x48 },
173  { 0x00, 0x00, 0x00, 0x5d },
174  { 0x00, 0x00, 0x00, 0x6f },
175  { 0x00, 0x00, 0x00, 0x80 },
176  { 0x00, 0x00, 0x00, 0x8f },
177  { 0x00, 0x00, 0x00, 0x9e },
178  { 0x00, 0x00, 0x00, 0xac },
179  { 0x00, 0x00, 0x00, 0xb9 },
180  { 0x00, 0x00, 0x00, 0xc5 },
181  { 0x00, 0x00, 0x00, 0xd2 },
182  { 0x00, 0x00, 0x00, 0xdd },
183  { 0x00, 0x00, 0x00, 0xe9 },
184  { 0x00, 0x00, 0x00, 0xf4 },
185  { 0x00, 0x00, 0x00, 0xff }
186 };
187 
188 static Color palette3[] =
189 {
190  { 0xff, 0xff, 0xff, 0xff },
191  { 0xe0, 0xe0, 0xe0, 0xff },
192  { 0xd0, 0xd0, 0xd0, 0xff },
193  { 0xc0, 0xc0, 0xc0, 0xff },
194  { 0xb0, 0xb0, 0xb0, 0xff },
195  { 0xa0, 0xa0, 0xa0, 0xff },
196  { 0x90, 0x90, 0x90, 0xff },
197  { 0x80, 0x80, 0x80, 0xff },
198  { 0x70, 0x70, 0x70, 0xff },
199  { 0x60, 0x60, 0x60, 0xff },
200  { 0x50, 0x50, 0x50, 0xff },
201  { 0x40, 0x40, 0x40, 0xff },
202  { 0x30, 0x30, 0x30, 0xff },
203  { 0x20, 0x20, 0x20, 0xff },
204  { 0x10, 0x10, 0x10, 0xff },
205  { 0x00, 0x00, 0x00, 0xff }
206 };
207 
208 
210 {
211  static int hue = Config_getInt(HTML_COLORSTYLE_HUE);
212  static int sat = Config_getInt(HTML_COLORSTYLE_SAT);
213  static int gamma = Config_getInt(HTML_COLORSTYLE_GAMMA);
214 
215  double red1,green1,blue1;
216  double red2,green2,blue2;
217 
218  ColoredImage::hsl2rgb(hue/360.0, // hue
219  sat/255.0, // saturation
220  pow(235/255.0,gamma/100.0), // luma (gamma corrected)
221  &red1,&green1,&blue1
222  );
223 
224  ColoredImage::hsl2rgb(hue/360.0, // hue
225  sat/255.0, // saturation
226  pow(138/255.0,gamma/100.0), // luma (gamma corrected)
227  &red2,&green2,&blue2
228  );
229 
230  palette[2].red = (int)(red1 * 255.0);
231  palette[2].green = (int)(green1 * 255.0);
232  palette[2].blue = (int)(blue1 * 255.0);
233 
234  palette[3].red = (int)(red2 * 255.0);
235  palette[3].green = (int)(green2 * 255.0);
236  palette[3].blue = (int)(blue2 * 255.0);
237 
238  m_data = new uchar[w*h];
239  memset(m_data,0,w*h);
240  m_width = w;
241  m_height = h;
242 }
243 
245 {
246  delete[] m_data;
247 }
248 
250 {
251  if (x<m_width && y<m_height)
252  m_data[y*m_width+x] = val;
253 }
254 
256 {
257  if (x<m_width && y<m_height)
258  return m_data[y*m_width+x];
259  else
260  return 0;
261 }
262 
263 void Image::writeChar(uint x,uint y,char c,uchar fg)
264 {
265  if (c>=' ')
266  {
267  uint xf,yf,ci=c-' ';
268  uint rowOffset=0;
269  uint cw = charWidth[ci];
270  uint cp = charPos[ci];
271  for (yf=0;yf<charHeight;yf++)
272  {
273  unsigned short bitPattern=0;
274  uint bitsLeft=cw;
275  uint byteOffset = rowOffset+(cp>>3);
276  uint bitOffset = cp&7;
277  // get the bit pattern for row yf of the character from the font data
278  while (bitsLeft>0)
279  {
280  uint bits=8-bitOffset;
281  if (bits>bitsLeft) bits=bitsLeft;
282  bitPattern<<=bits;
283  bitPattern|=((fontRaw[byteOffset]<<bitOffset)&0xff)>>(8-bits);
284  bitsLeft-=bits;
285  bitOffset=0;
286  byteOffset++;
287  }
288  uint mask=1<<(cw-1);
289  // draw character row yf
290  for (xf=0;xf<cw;xf++)
291  {
292  setPixel(x+xf,y+yf,(bitPattern&mask) ? fg : getPixel(x+xf,y+yf));
293  mask>>=1;
294  }
295  rowOffset+=charSetWidth;
296  }
297  }
298 }
299 
301 {
302  if (!s.isEmpty())
303  {
304  const char *p = s.data();
305  char c;
306  while ((c=*p++))
307  {
308  writeChar(x,y,c,fg);
309  x+=charWidth[c-' '];
310  }
311  }
312 }
313 
315 {
316  uint w=0;
317  if (!s.isEmpty())
318  {
319  const char *p = s.data();
320  char c;
321  while ((c=*p++)) w+=charWidth[c-' '];
322  }
323  return w;
324 }
325 
326 void Image::drawHorzLine(uint y,uint xs,uint xe,uchar colIndex,uint mask)
327 {
328  uint x,i=0,j=0;
329  for (x=xs;x<=xe;x++,j++)
330  {
331  if (j&1) i++;
332  if (mask&(1<<(i&0x1f))) setPixel(x,y,colIndex);
333  }
334 }
335 
336 void Image::drawHorzArrow(uint y,uint xs,uint xe,uchar colIndex,uint mask)
337 {
338  drawHorzLine(y,xs,xe,colIndex,mask);
339  uint i;
340  for (i=0;i<6;i++)
341  {
342  uint h=i>>1;
343  drawVertLine(xe-i,y-h,y+h,colIndex,0xffffffff);
344  }
345 }
346 
347 void Image::drawVertLine(uint x,uint ys,uint ye,uchar colIndex,uint mask)
348 {
349  uint y,i=0;
350  for (y=ys;y<=ye;y++,i++)
351  {
352  if (mask&(1<<(i&0x1f))) setPixel(x,y,colIndex);
353  }
354 }
355 
356 void Image::drawVertArrow(uint x,uint ys,uint ye,uchar colIndex,uint mask)
357 {
358  drawVertLine(x,ys,ye,colIndex,mask);
359  uint i;
360  for (i=0;i<6;i++)
361  {
362  uint h=i>>1;
363  drawHorzLine(ys+i,x-h,x+h,colIndex,0xffffffff);
364  }
365 }
366 
367 void Image::drawRect(uint x,uint y,uint w,uint h,uchar colIndex,uint mask)
368 {
369  drawHorzLine(y,x,x+w-1,colIndex,mask);
370  drawHorzLine(y+h-1,x,x+w-1,colIndex,mask);
371  drawVertLine(x,y,y+h-1,colIndex,mask);
372  drawVertLine(x+w-1,y,y+h-1,colIndex,mask);
373 }
374 
375 void Image::fillRect(uint x,uint y,uint width,uint height,uchar colIndex,uint mask)
376 {
377  uint xp,yp,xi,yi;
378  for (yp=y,yi=0;yp<y+height;yp++,yi++)
379  for (xp=x,xi=0;xp<x+width;xp++,xi++)
380  if (mask&(1<<((xi+yi)&0x1f)))
381  setPixel(xp,yp,colIndex);
382 }
383 
384 bool Image::save(const QCString &fileName,int mode)
385 {
386  static bool useTransparency = Config_getBool(FORMULA_TRANSPARENT);
387  uchar* buffer;
388  size_t bufferSize;
389  LodePNG_Encoder encoder;
390  LodePNG_Encoder_init(&encoder);
391  uint numCols = mode==0 ? 8 : 16;
392  Color *pPal = mode==0 ? palette :
393  useTransparency ? palette2 :
394  palette3 ;
395  uint i;
396  for (i=0;i<numCols;i++,pPal++)
397  {
398  LodePNG_InfoColor_addPalette(&encoder.infoPng.color,
399  pPal->red,pPal->green,pPal->blue,pPal->alpha);
400  }
401  encoder.infoPng.color.colorType = 3;
402  encoder.infoRaw.color.colorType = 3;
403  LodePNG_encode(&encoder, &buffer, &bufferSize, m_data, m_width, m_height);
404  LodePNG_saveFile(buffer, bufferSize, fileName.data());
405  free(buffer);
406  LodePNG_Encoder_cleanup(&encoder);
407  return TRUE;
408 }
409 
410 //----------------------------------------------------------------
411 
412 void ColoredImage::hsl2rgb(double h,double s,double l,
413  double *pRed,double *pGreen,double *pBlue)
414 {
415  double v;
416  double r,g,b;
417 
418  r = l; // default to gray
419  g = l;
420  b = l;
421  v = (l <= 0.5) ? (l * (1.0 + s)) : (l + s - l * s);
422  if (v > 0)
423  {
424  double m;
425  double sv;
426  int sextant;
427  double fract, vsf, mid1, mid2;
428 
429  m = l + l - v;
430  sv = (v - m ) / v;
431  h *= 6.0;
432  sextant = (int)h;
433  fract = h - sextant;
434  vsf = v * sv * fract;
435  mid1 = m + vsf;
436  mid2 = v - vsf;
437  switch (sextant)
438  {
439  case 0:
440  r = v;
441  g = mid1;
442  b = m;
443  break;
444  case 1:
445  r = mid2;
446  g = v;
447  b = m;
448  break;
449  case 2:
450  r = m;
451  g = v;
452  b = mid1;
453  break;
454  case 3:
455  r = m;
456  g = mid2;
457  b = v;
458  break;
459  case 4:
460  r = mid1;
461  g = m;
462  b = v;
463  break;
464  case 5:
465  r = v;
466  g = m;
467  b = mid2;
468  break;
469  }
470  }
471  *pRed = r;
472  *pGreen = g;
473  *pBlue = b;
474 }
475 
477  const uchar *greyLevels,const uchar *alphaLevels,
478  int saturation,int hue,int gamma)
479 {
480  m_hasAlpha = alphaLevels!=0;
481  m_width = width;
482  m_height = height;
483  m_data = (uchar*)malloc(width*height*4);
484  uint i;
485  for (i=0;i<width*height;i++)
486  {
487  uchar r,g,b,a;
488  double red,green,blue;
489  hsl2rgb(hue/360.0, // hue
490  saturation/255.0, // saturation
491  pow(greyLevels[i]/255.0,gamma/100.0), // luma (gamma corrected)
492  &red,&green,&blue);
493  r = (int)(red *255.0);
494  g = (int)(green*255.0);
495  b = (int)(blue *255.0);
496  a = alphaLevels ? alphaLevels[i] : 255;
497  m_data[i*4+0]=r;
498  m_data[i*4+1]=g;
499  m_data[i*4+2]=b;
500  m_data[i*4+3]=a;
501  }
502 }
503 
505 {
506  free(m_data);
507 }
508 
509 bool ColoredImage::save(const QCString &fileName)
510 {
511  uchar *buffer;
512  size_t bufferSize;
513  LodePNG_Encoder encoder;
514  LodePNG_Encoder_init(&encoder);
515  encoder.infoPng.color.colorType = m_hasAlpha ? 6 : 2; // 2=RGB 24 bit, 6=RGBA 32 bit
516  encoder.infoRaw.color.colorType = 6; // 6=RGBA 32 bit
517  LodePNG_encode(&encoder, &buffer, &bufferSize, m_data, m_width, m_height);
518  LodePNG_saveFile(buffer, bufferSize, fileName.data());
519  LodePNG_Encoder_cleanup(&encoder);
520  free(buffer);
521  return TRUE;
522 }
523 
524 
ColoredImage::ColoredImage
ColoredImage(uint width, uint height, const uchar *greyLevels, const uchar *alphaLevels, int saturation, int hue, int gamma)
Definition: image.cpp:476
ColoredImage::hsl2rgb
static void hsl2rgb(double h, double s, double l, double *pRed, double *pGreen, double *pBlue)
Definition: image.cpp:412
ColoredImage::m_width
uint m_width
Definition: image.h:67
Image::writeString
void writeString(uint x, uint y, const QCString &s, uchar fg)
Definition: image.cpp:300
Image::m_height
uint m_height
Definition: image.h:67
ColoredImage::m_height
uint m_height
Definition: image.h:68
Color::alpha
Byte alpha
Definition: image.cpp:32
charPos
unsigned short charPos[numChars]
Definition: image.cpp:39
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty
Definition: qcstring.h:144
fontRaw
unsigned char fontRaw[charSetWidth *charHeight]
Definition: image.cpp:72
numChars
const int numChars
Definition: image.cpp:37
ColoredImage::~ColoredImage
~ColoredImage()
Definition: image.cpp:504
Image::drawRect
void drawRect(uint x, uint y, uint width, uint height, uchar colIndex, uint mask)
Definition: image.cpp:367
Image::stringLength
friend uint stringLength(const QCString &s)
Definition: image.cpp:314
Image::m_width
uint m_width
Definition: image.h:66
Image::drawVertLine
void drawVertLine(uint x, uint ys, uint ye, uchar colIndex, uint mask)
Definition: image.cpp:347
Image::fillRect
void fillRect(uint x, uint y, uint width, uint height, uchar colIndex, uint mask)
Definition: image.cpp:375
ColoredImage::m_hasAlpha
bool m_hasAlpha
Definition: image.h:70
Image::m_data
uchar * m_data
Definition: image.h:68
Image::~Image
~Image()
Definition: image.cpp:244
Color::red
Byte red
Definition: image.cpp:29
Image::getPixel
uchar getPixel(uint x, uint y) const
Definition: image.cpp:255
Byte
unsigned char Byte
Definition: image.cpp:24
charWidth
unsigned char charWidth[numChars]
Definition: image.cpp:55
uint
unsigned uint
Definition: qcstring.h:40
Image::height
uint height() const
Definition: image.h:61
palette2
static Color palette2[]
Definition: image.cpp:168
Config_getInt
#define Config_getInt(name)
Definition: config.h:34
charHeight
const int charHeight
Definition: image.cpp:36
uchar
unsigned char uchar
Definition: qcstring.h:38
Image::save
bool save(const QCString &fileName, int mode=0)
Definition: image.cpp:384
Image::drawHorzLine
void drawHorzLine(uint y, uint xs, uint xe, uchar colIndex, uint mask)
Definition: image.cpp:326
Image::Image
Image(uint w, uint h)
Definition: image.cpp:209
Image::writeChar
void writeChar(uint x, uint y, char c, uchar fg)
Definition: image.cpp:263
ColoredImage::m_data
uchar * m_data
Definition: image.h:69
image.h
TRUE
#define TRUE
Definition: qcstring.h:36
Image::drawVertArrow
void drawVertArrow(uint x, uint ys, uint ye, uchar colIndex, uint mask)
Definition: image.cpp:356
palette
static Color palette[]
Definition: image.cpp:155
palette3
static Color palette3[]
Definition: image.cpp:188
charSetWidth
const int charSetWidth
Definition: image.cpp:35
Image::width
uint width() const
Definition: image.h:60
Config_getBool
#define Config_getBool(name)
Definition: config.h:33
ColoredImage::save
bool save(const QCString &fileName)
Definition: image.cpp:509
Color
Helper struct representing a RGBA color
Definition: image.cpp:27
config.h
QCString::data
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string
Definition: qcstring.h:153
Color::blue
Byte blue
Definition: image.cpp:31
Color::green
Byte green
Definition: image.cpp:30
Image::drawHorzArrow
void drawHorzArrow(uint y, uint xs, uint xe, uchar colIndex, uint mask)
Definition: image.cpp:336
Image::setPixel
void setPixel(uint x, uint y, uchar val)
Definition: image.cpp:249
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108