My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
 
uchar * m_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.

References hsl2rgb(), m_data, m_hasAlpha, m_height, and m_width.

{
m_hasAlpha = alphaLevels!=0;
m_width = width;
m_height = height;
m_data = (uchar*)malloc(width*height*4);
int i;
for (i=0;i<width*height;i++)
{
uchar r,g,b,a;
double red,green,blue;
hsl2rgb(hue/360.0, // hue
saturation/255.0, // saturation
pow(greyLevels[i]/255.0,gamma/100.0), // luma (gamma corrected)
&red,&green,&blue);
r = (int)(red *255.0);
g = (int)(green*255.0);
b = (int)(blue *255.0);
a = alphaLevels ? alphaLevels[i] : 255;
m_data[i*4+0]=r;
m_data[i*4+1]=g;
m_data[i*4+2]=b;
m_data[i*4+3]=a;
}
}
ColoredImage::~ColoredImage ( )

Definition at line 520 of file image.cpp.

References m_data.

{
free(m_data);
}

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.

Referenced by ColoredImage(), Image::Image(), and replaceColorMarkers().

{
double v;
double r,g,b;
r = l; // default to gray
g = l;
b = l;
v = (l <= 0.5) ? (l * (1.0 + s)) : (l + s - l * s);
if (v > 0)
{
double m;
double sv;
int sextant;
double fract, vsf, mid1, mid2;
m = l + l - v;
sv = (v - m ) / v;
h *= 6.0;
sextant = (int)h;
fract = h - sextant;
vsf = v * sv * fract;
mid1 = m + vsf;
mid2 = v - vsf;
switch (sextant)
{
case 0:
r = v;
g = mid1;
b = m;
break;
case 1:
r = mid2;
g = v;
b = m;
break;
case 2:
r = m;
g = v;
b = mid1;
break;
case 3:
r = m;
g = mid2;
b = v;
break;
case 4:
r = mid1;
g = m;
b = v;
break;
case 5:
r = v;
g = m;
b = mid2;
break;
}
}
*pRed = r;
*pGreen = g;
*pBlue = b;
}
bool ColoredImage::save ( const char *  fileName)

Definition at line 525 of file image.cpp.

References LodePNG_InfoPng::color, LodePNG_InfoRaw::color, LodePNG_InfoColor::colorType, LodePNG_Encoder::infoPng, LodePNG_Encoder::infoRaw, LodePNG_encode(), LodePNG_Encoder_cleanup(), LodePNG_Encoder_init(), LodePNG_saveFile(), m_data, m_hasAlpha, m_height, and m_width.

Referenced by writeColoredImgData().

{
uchar *buffer;
size_t bufferSize;
LodePNG_Encoder encoder;
encoder.infoPng.color.colorType = m_hasAlpha ? 6 : 2; // 2=RGB 24 bit, 6=RGBA 32 bit
encoder.infoRaw.color.colorType = 6; // 6=RGBA 32 bit
LodePNG_encode(&encoder, &buffer, &bufferSize, m_data, m_width, m_height);
LodePNG_saveFile(buffer, bufferSize, fileName);
free(buffer);
return TRUE;
}

Member Data Documentation

uchar* ColoredImage::m_data
private

Definition at line 67 of file image.h.

Referenced by ColoredImage(), save(), and ~ColoredImage().

bool ColoredImage::m_hasAlpha
private

Definition at line 68 of file image.h.

Referenced by ColoredImage(), and save().

int ColoredImage::m_height
private

Definition at line 66 of file image.h.

Referenced by ColoredImage(), and save().

int ColoredImage::m_width
private

Definition at line 65 of file image.h.

Referenced by ColoredImage(), and save().


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