Doxygen
Loading...
Searching...
No Matches
Image Class Reference

Class representing a bitmap image generated by doxygen. More...

#include <src/image.h>

Classes

struct  Private

Public Member Functions

 Image (uint32_t w, uint32_t h)
 ~Image ()
void setPixel (uint32_t x, uint32_t y, uint8_t val)
uint8_t getPixel (uint32_t x, uint32_t y) const
void writeChar (uint32_t x, uint32_t y, char c, uint8_t fg)
void writeString (uint32_t x, uint32_t y, const DString &s, uint8_t fg)
void drawHorzLine (uint32_t y, uint32_t xs, uint32_t xe, uint8_t colIndex, uint32_t mask)
void drawHorzArrow (uint32_t y, uint32_t xs, uint32_t xe, uint8_t colIndex, uint32_t mask)
void drawVertLine (uint32_t x, uint32_t ys, uint32_t ye, uint8_t colIndex, uint32_t mask)
void drawVertArrow (uint32_t x, uint32_t ys, uint32_t ye, uint8_t colIndex, uint32_t mask)
void drawRect (uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint8_t colIndex, uint32_t mask)
void fillRect (uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint8_t colIndex, uint32_t mask)
bool save (const DString &fileName)
uint32_t width () const
uint32_t height () const

Static Public Member Functions

static uint32_t stringLength (const DString &s)

Private Attributes

std::unique_ptr< Privatep

Friends

uint32_t stringLength (const DString &s)

Detailed Description

Class representing a bitmap image generated by doxygen.

Definition at line 28 of file image.h.

Constructor & Destructor Documentation

◆ Image()

Image::Image ( uint32_t w,
uint32_t h )

Definition at line 179 of file image.cpp.

179 : p(std::make_unique<Private>())
180{
181 int hue = Config_getInt(HTML_COLORSTYLE_HUE);
182 int sat = Config_getInt(HTML_COLORSTYLE_SAT);
183 int gamma = Config_getInt(HTML_COLORSTYLE_GAMMA);
184
185 double red1=0.0 ,green1=0.0 ,blue1=0.0;
186 double red2=0.0, green2=0.0, blue2=0.0;
187
188 ColoredImage::hsl2rgb(hue/360.0, // hue
189 sat/255.0, // saturation
190 pow(235/255.0,gamma/100.0), // luma (gamma corrected)
191 &red1,&green1,&blue1
192 );
193
194 ColoredImage::hsl2rgb(hue/360.0, // hue
195 sat/255.0, // saturation
196 pow(138/255.0,gamma/100.0), // luma (gamma corrected)
197 &red2,&green2,&blue2
198 );
199
200 p->palette[2].red = static_cast<Byte>(red1 * 255.0);
201 p->palette[2].green = static_cast<Byte>(green1 * 255.0);
202 p->palette[2].blue = static_cast<Byte>(blue1 * 255.0);
203
204 p->palette[3].red = static_cast<Byte>(red2 * 255.0);
205 p->palette[3].green = static_cast<Byte>(green2 * 255.0);
206 p->palette[3].blue = static_cast<Byte>(blue2 * 255.0);
207
208 p->data.resize(w*h);
209 p->width = w;
210 p->height = h;
211}
static void hsl2rgb(double h, double s, double l, double *pRed, double *pGreen, double *pBlue)
Definition image.cpp:373
std::unique_ptr< Private > p
Definition image.h:53
#define Config_getInt(name)
Definition config.h:34
unsigned char Byte
Definition image.cpp:28

References Config_getInt, ColoredImage::hsl2rgb(), and p.

Referenced by ~Image().

◆ ~Image()

Image::~Image ( )
default

References height(), Image(), and width().

Member Function Documentation

◆ drawHorzArrow()

void Image::drawHorzArrow ( uint32_t y,
uint32_t xs,
uint32_t xe,
uint8_t colIndex,
uint32_t mask )

Definition at line 304 of file image.cpp.

305{
306 drawHorzLine(y,xs,xe,colIndex,mask);
307 for (uint32_t i=0;i<6;i++)
308 {
309 uint32_t h=i>>1;
310 drawVertLine(xe-i,y-h,y+h,colIndex,0xffffffff);
311 }
312}
void drawVertLine(uint32_t x, uint32_t ys, uint32_t ye, uint8_t colIndex, uint32_t mask)
Definition image.cpp:314
void drawHorzLine(uint32_t y, uint32_t xs, uint32_t xe, uint8_t colIndex, uint32_t mask)
Definition image.cpp:294

References drawHorzLine(), and drawVertLine().

Referenced by TreeDiagram::drawConnectors().

◆ drawHorzLine()

void Image::drawHorzLine ( uint32_t y,
uint32_t xs,
uint32_t xe,
uint8_t colIndex,
uint32_t mask )

Definition at line 294 of file image.cpp.

295{
296 uint32_t i=0,j=0;
297 for (uint32_t x=xs;x<=xe;x++,j++)
298 {
299 if (j&1) i++;
300 if (mask&(1<<(i&0x1f))) setPixel(x,y,colIndex);
301 }
302}
void setPixel(uint32_t x, uint32_t y, uint8_t val)
Definition image.cpp:218

References setPixel().

Referenced by TreeDiagram::drawConnectors(), drawHorzArrow(), drawRect(), drawVertArrow(), and writeBitmapBox().

◆ drawRect()

void Image::drawRect ( uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height,
uint8_t colIndex,
uint32_t mask )

Definition at line 333 of file image.cpp.

334{
335 drawHorzLine(y,x,x+w-1,colIndex,mask);
336 drawHorzLine(y+h-1,x,x+w-1,colIndex,mask);
337 drawVertLine(x,y,y+h-1,colIndex,mask);
338 drawVertLine(x+w-1,y,y+h-1,colIndex,mask);
339}

References drawHorzLine(), and drawVertLine().

Referenced by writeBitmapBox().

◆ drawVertArrow()

void Image::drawVertArrow ( uint32_t x,
uint32_t ys,
uint32_t ye,
uint8_t colIndex,
uint32_t mask )

Definition at line 323 of file image.cpp.

324{
325 drawVertLine(x,ys,ye,colIndex,mask);
326 for (uint32_t i=0;i<6;i++)
327 {
328 uint32_t h=i>>1;
329 drawHorzLine(ys+i,x-h,x+h,colIndex,0xffffffff);
330 }
331}

References drawHorzLine(), and drawVertLine().

Referenced by TreeDiagram::drawConnectors().

◆ drawVertLine()

void Image::drawVertLine ( uint32_t x,
uint32_t ys,
uint32_t ye,
uint8_t colIndex,
uint32_t mask )

Definition at line 314 of file image.cpp.

315{
316 uint32_t i=0;
317 for (uint32_t y=ys;y<=ye;y++,i++)
318 {
319 if (mask&(1<<(i&0x1f))) setPixel(x,y,colIndex);
320 }
321}

References setPixel().

Referenced by TreeDiagram::drawConnectors(), drawHorzArrow(), drawRect(), and drawVertArrow().

◆ fillRect()

void Image::fillRect ( uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height,
uint8_t colIndex,
uint32_t mask )

Definition at line 341 of file image.cpp.

342{
343 for (uint32_t yp=y,yi=0;yp<y+height;yp++,yi++)
344 for (uint32_t xp=x,xi=0;xp<x+width;xp++,xi++)
345 if (mask&(1<<((xi+yi)&0x1f)))
346 setPixel(xp,yp,colIndex);
347 else
348 setPixel(xp,yp,8);
349}
uint32_t width() const
Definition image.cpp:213
uint32_t height() const
Definition image.cpp:214

References height(), setPixel(), and width().

Referenced by writeBitmapBox().

◆ getPixel()

uint8_t Image::getPixel ( uint32_t x,
uint32_t y ) const

Definition at line 223 of file image.cpp.

224{
225 return (x<p->width && y<p->height) ? p->data[y*p->width+x] : 0;
226}

References height(), p, and width().

Referenced by writeChar().

◆ height()

uint32_t Image::height ( ) const

Definition at line 214 of file image.cpp.

214{ return p->height; }

References p.

Referenced by TreeDiagram::drawBoxes(), TreeDiagram::drawConnectors(), fillRect(), getPixel(), setPixel(), and ~Image().

◆ save()

bool Image::save ( const DString & fileName)

Definition at line 351 of file image.cpp.

352{
353 uint8_t* buffer = nullptr;
354 size_t bufferSize = 0;
355 LodePNG_Encoder encoder;
356 LodePNG_Encoder_init(&encoder);
357 for (const auto &col : p->palette)
358 {
359 LodePNG_InfoColor_addPalette(&encoder.infoPng.color,
360 col.red,col.green,col.blue,col.alpha);
361 }
362 encoder.infoPng.color.colorType = 3;
363 encoder.infoRaw.color.colorType = 3;
364 LodePNG_encode(&encoder, &buffer, &bufferSize, &p->data[0], p->width, p->height);
365 LodePNG_saveFile(buffer, bufferSize, fileName.data());
366 free(buffer);
367 LodePNG_Encoder_cleanup(&encoder);
368 return true;
369}
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157

References DString::data(), and p.

◆ setPixel()

void Image::setPixel ( uint32_t x,
uint32_t y,
uint8_t val )

Definition at line 218 of file image.cpp.

219{
220 if (x<p->width && y<p->height) p->data[y*p->width+x] = val;
221}

References height(), p, and width().

Referenced by drawHorzLine(), drawVertLine(), fillRect(), and writeChar().

◆ stringLength()

uint32_t Image::stringLength ( const DString & s)
static

◆ width()

uint32_t Image::width ( ) const

Definition at line 213 of file image.cpp.

213{ return p->width; }

References p.

Referenced by fillRect(), getPixel(), setPixel(), and ~Image().

◆ writeChar()

void Image::writeChar ( uint32_t x,
uint32_t y,
char c,
uint8_t fg )

Definition at line 228 of file image.cpp.

229{
230 if (c>=' ')
231 {
232 uint32_t ci=c-' ';
233 uint32_t rowOffset=0;
234 uint32_t cw = charWidth[ci];
235 uint32_t cp = charPos[ci];
236 for (uint32_t yf=0;yf<charHeight;yf++)
237 {
238 unsigned short bitPattern=0;
239 uint32_t bitsLeft=cw;
240 uint32_t byteOffset = rowOffset+(cp>>3);
241 uint32_t bitOffset = cp&7;
242 // get the bit pattern for row yf of the character from the font data
243 while (bitsLeft>0)
244 {
245 uint32_t bits=8-bitOffset;
246 if (bits>bitsLeft) bits=bitsLeft;
247 bitPattern<<=bits;
248 bitPattern|=((fontRaw[byteOffset]<<bitOffset)&0xff)>>(8-bits);
249 bitsLeft-=bits;
250 bitOffset=0;
251 byteOffset++;
252 }
253 if (cw>0 && cw<32)
254 {
255 uint32_t mask=(uint32_t)1<<(cw-1);
256 // draw character row yf
257 for (uint32_t xf=0;xf<cw;xf++)
258 {
259 setPixel(x+xf,y+yf,(bitPattern&mask) ? fg : getPixel(x+xf,y+yf));
260 mask>>=1;
261 }
262 rowOffset+=charSetWidth;
263 }
264 }
265 }
266}
uint8_t getPixel(uint32_t x, uint32_t y) const
Definition image.cpp:223
const unsigned short charPos[numChars]
Definition image.cpp:43
const unsigned char charWidth[numChars]
Definition image.cpp:59
const unsigned char fontRaw[charSetWidth *charHeight]
Definition image.cpp:76
const int charHeight
Definition image.cpp:40
const int charSetWidth
Definition image.cpp:39

References charHeight, charPos, charSetWidth, charWidth, fontRaw, getPixel(), and setPixel().

Referenced by writeString().

◆ writeString()

void Image::writeString ( uint32_t x,
uint32_t y,
const DString & s,
uint8_t fg )

Definition at line 268 of file image.cpp.

269{
270 if (!s.empty())
271 {
272 const char *ps = s.data();
273 char c = 0;
274 while ((c=*ps++))
275 {
276 writeChar(x,y,c,fg);
277 x+=charWidth[c-' '];
278 }
279 }
280}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
void writeChar(uint32_t x, uint32_t y, char c, uint8_t fg)
Definition image.cpp:228

References charWidth, DString::data(), DString::empty(), and writeChar().

Referenced by writeBitmapBox().

◆ stringLength

uint32_t Image::stringLength ( const DString & s)
friend

Definition at line 282 of file image.cpp.

283{
284 uint32_t w=0;
285 if (!s.empty())
286 {
287 const char *ps = s.data();
288 char c = 0;
289 while ((c=*ps++)) w+=charWidth[c-' '];
290 }
291 return w;
292}

References charWidth, DString::data(), and DString::empty().

Referenced by TreeDiagram::computeExtremes(), and writeBitmapBox().

Member Data Documentation

◆ p

std::unique_ptr<Private> Image::p
private

Definition at line 53 of file image.h.

Referenced by getPixel(), height(), Image(), save(), setPixel(), and width().


The documentation for this class was generated from the following files: