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

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

#include <src/image.h>

Classes

struct  Private
 

Public Member Functions

 ColoredImage (uint32_t width, uint32_t height, const uint8_t *greyLevels, const uint8_t *alphaLevels, int saturation, int hue, int gamma)
 
 ~ColoredImage ()
 
bool save (const QCString &fileName)
 

Static Public Member Functions

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

Private Attributes

std::unique_ptr< Privatep
 

Detailed Description

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

Definition at line 55 of file image.h.

Constructor & Destructor Documentation

◆ ColoredImage()

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

Definition at line 432 of file image.cpp.

434 : 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}
static void hsl2rgb(double h, double s, double l, double *pRed, double *pGreen, double *pBlue)
Definition image.cpp:368
std::unique_ptr< Private > p
Definition image.h:69
unsigned char Byte
Definition image.cpp:23

References hsl2rgb(), and p.

Referenced by ~ColoredImage().

◆ ~ColoredImage()

ColoredImage::~ColoredImage ( )
default

References ColoredImage().

Member Function Documentation

◆ hsl2rgb()

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

Definition at line 368 of file image.cpp.

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().

◆ save()

bool ColoredImage::save ( const QCString & fileName)

Definition at line 460 of file image.cpp.

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}
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:159
#define TRUE
Definition qcstring.h:37

References QCString::data(), p, and TRUE.

Referenced by writeColoredImgData().

Member Data Documentation

◆ p

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

Definition at line 69 of file image.h.

Referenced by ColoredImage(), and save().


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