Skip to main content

The ColoredImage Class Reference

Class representing a bitmap image colored based on hue/sat/gamma settings. More...

Declaration

class ColoredImage { ... }

Included Headers

#include <src/image.h>

Public Constructors Index

ColoredImage (uint32_t width, uint32_t height, const uint8_t *greyLevels, const uint8_t *alphaLevels, int saturation, int hue, int gamma)

Public Destructor Index

~ColoredImage ()

Public Member Functions Index

boolsave (const QCString &fileName)

Private Member Attributes Index

std::unique_ptr< Private >p

Public Static Functions Index

static voidhsl2rgb (double h, double s, double l, double *pRed, double *pGreen, double *pBlue)

Description

Class representing a bitmap image colored based on hue/sat/gamma settings.

Definition at line 55 of file image.h.

Public Constructors

ColoredImage()

ColoredImage::ColoredImage (uint32_t width, uint32_t height, const uint8_t * greyLevels, const uint8_t * alphaLevels, int saturation, int hue, int gamma)

Declaration at line 58 of file image.h, definition at line 432 of file image.cpp.

432ColoredImage::ColoredImage(uint32_t width,uint32_t height,
433 const uint8_t *greyLevels,const uint8_t *alphaLevels,
434 int saturation,int hue,int gamma) : p(std::make_unique<Private>())
435{
436 p->hasAlpha = alphaLevels!=nullptr;
437 p->width = width;
438 p->height = height;
439 p->data.resize(width*height*4);
440 for (uint32_t i=0;i<width*height;i++)
441 {
442 double red=0.0, green=0.0, blue=0.0;
443 hsl2rgb(hue/360.0, // hue
444 saturation/255.0, // saturation
445 pow(greyLevels[i]/255.0,gamma/100.0), // luma (gamma corrected)
446 &red,&green,&blue);
447 Byte r = static_cast<Byte>(red *255.0);
448 Byte g = static_cast<Byte>(green*255.0);
449 Byte b = static_cast<Byte>(blue *255.0);
450 Byte a = alphaLevels ? alphaLevels[i] : 255;
451 p->data[i*4+0]=r;
452 p->data[i*4+1]=g;
453 p->data[i*4+2]=b;
454 p->data[i*4+3]=a;
455 }
456}

References hsl2rgb and p.

Referenced by ~ColoredImage.

Public Destructor

~ColoredImage()

ColoredImage::~ColoredImage ()

Definition at line 61 of file image.h.

Reference ColoredImage.

Public Member Functions

save()

bool ColoredImage::save (const QCString & fileName)

Declaration at line 64 of file image.h, definition at line 460 of file image.cpp.

460bool ColoredImage::save(const QCString &fileName)
461{
462 uint8_t *buffer = nullptr;
463 size_t bufferSize = 0;
464 LodePNG_Encoder encoder;
465 LodePNG_Encoder_init(&encoder);
466 encoder.infoPng.color.colorType = p->hasAlpha ? 6 : 2; // 2=RGB 24 bit, 6=RGBA 32 bit
467 encoder.infoRaw.color.colorType = 6; // 6=RGBA 32 bit
468 LodePNG_encode(&encoder, &buffer, &bufferSize, &p->data[0], p->width, p->height);
469 LodePNG_saveFile(buffer, bufferSize, fileName.data());
470 LodePNG_Encoder_cleanup(&encoder);
471 free(buffer);
472 return TRUE;
473}

References QCString::data, p and TRUE.

Referenced by writeColoredImgData.

Private Member Attributes

p

std::unique_ptr<Private> ColoredImage::p

Definition at line 69 of file image.h.

69 std::unique_ptr<Private> p;

Referenced by ColoredImage and save.

Public Static Functions

hsl2rgb()

void ColoredImage::hsl2rgb (double h, double s, double l, double * pRed, double * pGreen, double * pBlue)
static

Declaration at line 65 of file image.h, definition at line 368 of file image.cpp.

368void ColoredImage::hsl2rgb(double h,double s,double l,
369 double *pRed,double *pGreen,double *pBlue)
370{
371 double r = l; // default to gray
372 double g = l;
373 double b = l;
374 double v = (l <= 0.5) ? (l * (1.0 + s)) : (l + s - l * s);
375 if (v > 0)
376 {
377 double m = l + l - v;
378 double sv = ( v - m ) / v;
379 h *= 6.0;
380 int sextant = static_cast<int>(h);
381 double fract = h - sextant;
382 double vsf = v * sv * fract;
383 double mid1 = m + vsf;
384 double mid2 = v - vsf;
385 switch (sextant)
386 {
387 case 0:
388 r = v;
389 g = mid1;
390 b = m;
391 break;
392 case 1:
393 r = mid2;
394 g = v;
395 b = m;
396 break;
397 case 2:
398 r = m;
399 g = v;
400 b = mid1;
401 break;
402 case 3:
403 r = m;
404 g = mid2;
405 b = v;
406 break;
407 case 4:
408 r = mid1;
409 g = m;
410 b = v;
411 break;
412 case 5:
413 r = v;
414 g = m;
415 b = mid2;
416 break;
417 }
418 }
419 *pRed = r;
420 *pGreen = g;
421 *pBlue = b;
422}

Referenced by ColoredImage, getDirectoryBackgroundColor, Image::Image and replaceColorMarkers.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.