Class representing a bitmap image colored based on hue/sat/gamma settings.
More...
#include <src/image.h>
|
| | 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 DString &fileName) |
|
| static void | hsl2rgb (double h, double s, double l, double *pRed, double *pGreen, double *pBlue) |
Class representing a bitmap image colored based on hue/sat/gamma settings.
Definition at line 57 of file image.h.
◆ 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 437 of file image.cpp.
439 :
p(std::make_unique<Private>())
440{
441 p->hasAlpha = alphaLevels!=
nullptr;
444 p->data.resize(width*height*4);
445 for (uint32_t i=0;i<width*height;i++)
446 {
447 double red=0.0, green=0.0, blue=0.0;
449 saturation/255.0,
450 pow(greyLevels[i]/255.0,gamma/100.0),
451 &red,&green,&blue);
452 Byte r =
static_cast<Byte>(red *255.0);
453 Byte g =
static_cast<Byte>(green*255.0);
454 Byte b =
static_cast<Byte>(blue *255.0);
455 Byte a = alphaLevels ? alphaLevels[i] : 255;
460 }
461}
static void hsl2rgb(double h, double s, double l, double *pRed, double *pGreen, double *pBlue)
std::unique_ptr< Private > p
References hsl2rgb(), and p.
Referenced by ~ColoredImage().
◆ ~ColoredImage()
| ColoredImage::~ColoredImage |
( |
| ) |
|
|
default |
◆ hsl2rgb()
| void ColoredImage::hsl2rgb |
( |
double | h, |
|
|
double | s, |
|
|
double | l, |
|
|
double * | pRed, |
|
|
double * | pGreen, |
|
|
double * | pBlue ) |
|
static |
Definition at line 373 of file image.cpp.
375{
376 double r = l;
377 double g = l;
378 double b = l;
379 double v = (l <= 0.5) ? (l * (1.0 + s)) : (l + s - l * s);
380 if (v > 0)
381 {
382 double m = l + l - v;
383 double sv = ( v - m ) / v;
384 h *= 6.0;
385 int sextant = static_cast<int>(h);
386 double fract = h - sextant;
387 double vsf = v * sv * fract;
388 double mid1 = m + vsf;
389 double mid2 = v - vsf;
390 switch (sextant)
391 {
392 case 0:
393 r = v;
394 g = mid1;
395 b = m;
396 break;
397 case 1:
398 r = mid2;
399 g = v;
400 b = m;
401 break;
402 case 2:
403 r = m;
404 g = v;
405 b = mid1;
406 break;
407 case 3:
408 r = m;
409 g = mid2;
410 b = v;
411 break;
412 case 4:
413 r = mid1;
414 g = m;
415 b = v;
416 break;
417 case 5:
418 r = v;
419 g = m;
420 b = mid2;
421 break;
422 }
423 }
424 *pRed = r;
425 *pGreen = g;
426 *pBlue = b;
427}
Referenced by ColoredImage(), getDirectoryBackgroundColor(), Image::Image(), and replaceColorMarkers().
◆ save()
| bool ColoredImage::save |
( |
const DString & | fileName | ) |
|
Definition at line 465 of file image.cpp.
466{
467 uint8_t *buffer = nullptr;
468 size_t bufferSize = 0;
469 LodePNG_Encoder encoder;
470 LodePNG_Encoder_init(&encoder);
471 encoder.infoPng.color.colorType =
p->hasAlpha ? 6 : 2;
472 encoder.infoRaw.color.colorType = 6;
473 LodePNG_encode(&encoder, &buffer, &bufferSize, &
p->data[0],
p->width,
p->height);
474 LodePNG_saveFile(buffer, bufferSize, fileName.
data());
475 LodePNG_Encoder_cleanup(&encoder);
476 free(buffer);
477 return true;
478}
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
References DString::data(), and p.
| std::unique_ptr<Private> ColoredImage::p |
|
private |
The documentation for this class was generated from the following files: