Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
ColoredImage Class Reference

#include <image.h>

Public Member Functions

 ColoredImage (int width, int height, const uchar *greyLevels, const uchar *alphaLevels, int saturation, int hue, int gamma)
 
 ~ColoredImage ()
 
bool save (const char *fileName)
 

Static Public Member Functions

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

Private Attributes

int m_width
 
int m_height
 
ucharm_data
 
bool m_hasAlpha
 

Detailed Description

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

Definition at line 54 of file image.h.

Constructor & Destructor Documentation

ColoredImage::ColoredImage ( int  width,
int  height,
const uchar greyLevels,
const uchar alphaLevels,
int  saturation,
int  hue,
int  gamma 
)

Definition at line 492 of file image.cpp.

495 {
496  m_hasAlpha = alphaLevels!=0;
497  m_width = width;
498  m_height = height;
499  m_data = (uchar*)malloc(width*height*4);
500  int i;
501  for (i=0;i<width*height;i++)
502  {
503  uchar r,g,b,a;
504  double red,green,blue;
505  hsl2rgb(hue/360.0, // hue
506  saturation/255.0, // saturation
507  pow(greyLevels[i]/255.0,gamma/100.0), // luma (gamma corrected)
508  &red,&green,&blue);
509  r = (int)(red *255.0);
510  g = (int)(green*255.0);
511  b = (int)(blue *255.0);
512  a = alphaLevels ? alphaLevels[i] : 255;
513  m_data[i*4+0]=r;
514  m_data[i*4+1]=g;
515  m_data[i*4+2]=b;
516  m_data[i*4+3]=a;
517  }
518 }
static constexpr double g
Definition: Units.h:144
constexpr T pow(T x)
Definition: pow.h:72
bool m_hasAlpha
Definition: image.h:68
static void hsl2rgb(double h, double s, double l, double *pRed, double *pGreen, double *pBlue)
Definition: image.cpp:428
unsigned char uchar
Definition: nybbler.cc:11
const double a
double gamma(double KE, const simb::MCParticle *part)
uchar * m_data
Definition: image.h:67
int m_width
Definition: image.h:65
static bool * b
Definition: config.cpp:1043
int m_height
Definition: image.h:66
ColoredImage::~ColoredImage ( )

Definition at line 520 of file image.cpp.

521 {
522  free(m_data);
523 }
uchar * m_data
Definition: image.h:67

Member Function Documentation

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

Definition at line 428 of file image.cpp.

430 {
431  double v;
432  double r,g,b;
433 
434  r = l; // default to gray
435  g = l;
436  b = l;
437  v = (l <= 0.5) ? (l * (1.0 + s)) : (l + s - l * s);
438  if (v > 0)
439  {
440  double m;
441  double sv;
442  int sextant;
443  double fract, vsf, mid1, mid2;
444 
445  m = l + l - v;
446  sv = (v - m ) / v;
447  h *= 6.0;
448  sextant = (int)h;
449  fract = h - sextant;
450  vsf = v * sv * fract;
451  mid1 = m + vsf;
452  mid2 = v - vsf;
453  switch (sextant)
454  {
455  case 0:
456  r = v;
457  g = mid1;
458  b = m;
459  break;
460  case 1:
461  r = mid2;
462  g = v;
463  b = m;
464  break;
465  case 2:
466  r = m;
467  g = v;
468  b = mid1;
469  break;
470  case 3:
471  r = m;
472  g = mid2;
473  b = v;
474  break;
475  case 4:
476  r = mid1;
477  g = m;
478  b = v;
479  break;
480  case 5:
481  r = v;
482  g = m;
483  b = mid2;
484  break;
485  }
486  }
487  *pRed = r;
488  *pGreen = g;
489  *pBlue = b;
490 }
static constexpr double g
Definition: Units.h:144
static QStrList * l
Definition: config.cpp:1044
static bool * b
Definition: config.cpp:1043
static QCString * s
Definition: config.cpp:1042
bool ColoredImage::save ( const char *  fileName)

Definition at line 525 of file image.cpp.

526 {
527  uchar *buffer;
528  size_t bufferSize;
530  LodePNG_Encoder_init(&encoder);
531  encoder.infoPng.color.colorType = m_hasAlpha ? 6 : 2; // 2=RGB 24 bit, 6=RGBA 32 bit
532  encoder.infoRaw.color.colorType = 6; // 6=RGBA 32 bit
533  LodePNG_encode(&encoder, &buffer, &bufferSize, m_data, m_width, m_height);
534  LodePNG_saveFile(buffer, bufferSize, fileName);
535  LodePNG_Encoder_cleanup(&encoder);
536  free(buffer);
537  return TRUE;
538 }
unsigned colorType
Definition: lodepng.h:127
LodePNG_InfoRaw infoRaw
Definition: lodepng.h:342
LodePNG_InfoColor color
Definition: lodepng.h:225
bool m_hasAlpha
Definition: image.h:68
void LodePNG_Encoder_init(LodePNG_Encoder *encoder)
Definition: lodepng.cpp:4076
void LodePNG_encode(LodePNG_Encoder *encoder, unsigned char **out, size_t *outsize, const unsigned char *image, unsigned w, unsigned h)
Definition: lodepng.cpp:3910
unsigned char uchar
Definition: nybbler.cc:11
fileName
Definition: dumpTree.py:9
void LodePNG_Encoder_cleanup(LodePNG_Encoder *encoder)
Definition: lodepng.cpp:4084
LodePNG_InfoColor color
Definition: lodepng.h:266
unsigned LodePNG_saveFile(const unsigned char *buffer, size_t buffersize, const char *filename)
Definition: lodepng.cpp:4141
LodePNG_InfoPng infoPng
Definition: lodepng.h:341
uchar * m_data
Definition: image.h:67
int m_width
Definition: image.h:65
static QFile::EncoderFn encoder
Definition: qfile.cpp:470
const bool TRUE
Definition: qglobal.h:371
int m_height
Definition: image.h:66

Member Data Documentation

uchar* ColoredImage::m_data
private

Definition at line 67 of file image.h.

bool ColoredImage::m_hasAlpha
private

Definition at line 68 of file image.h.

int ColoredImage::m_height
private

Definition at line 66 of file image.h.

int ColoredImage::m_width
private

Definition at line 65 of file image.h.


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