ADTF_DISPLAY_TOOLBOX  3.8.0 (ADTF 3.14.3)
color.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <adtf_base.h>
12 
13 
14 namespace adtf
15 {
16 
17 namespace disptb
18 {
19 
20 namespace graphicslib
21 {
22 
23 namespace dengar
24 {
25 
31 class cColor : public tColor, public IColor
32 {
33 public:
38  {
39  this->nRed = 0;
40  this->nGreen = 0;
41  this->nBlue = 0;
42  this->nAlpha = 0;
43  }
44 
50  cColor(const IColor* pColor)
51  {
52  this->nRed = pColor->GetRed();
53  this->nGreen = pColor->GetGreen();
54  this->nBlue = pColor->GetBlue();
55  this->nAlpha = pColor->GetAlpha();
56  }
57 
63  cColor(const tColor& oColor)
64  {
65  this->nRed = oColor.nRed;
66  this->nGreen = oColor.nGreen;
67  this->nBlue = oColor.nBlue;
68  this->nAlpha = oColor.nAlpha;
69  }
70 
78  cColor(tInt nRedLocal, tInt nGreenLocal, tInt nBlueLocal, tInt nAlphaLocal =255)
79  {
80  this->nRed = (tUInt8) nRedLocal;
81  this->nGreen = (tUInt8) nGreenLocal;
82  this->nBlue = (tUInt8) nBlueLocal;
83  this->nAlpha = (tUInt8) nAlphaLocal;
84  }
85 
93  cColor(tUInt8 nRed, tUInt8 nGreen, tUInt8 nBlue, tUInt8 nAlpha = 255)
94  {
95  this->nRed = (tUInt8) nRed;
96  this->nGreen = (tUInt8) nGreen;
97  this->nBlue = (tUInt8) nBlue;
98  this->nAlpha = (tUInt8) nAlpha;
99  }
100 
108  cColor(tFloat32 fRed, tFloat32 fGreen, tFloat32 fBlue, tFloat32 fAlpha = 1.0f)
109  {
110  this->nRed = (tUInt8) (fRed * 255.0f);
111  this->nGreen = (tUInt8) (fGreen * 255.0f);
112  this->nBlue = (tUInt8) (fBlue * 255.0f);
113  this->nAlpha = (tUInt8) (fAlpha * 255.0f);
114  }
115 
122  cColor(tUInt32 nRGBA)
123  {
124  SetRGBA(nRGBA);
125  }
126 
133  cColor(tUInt32 nRGBA, tInt oPixelFormat)
134  {
135  SetRGBA(nRGBA, oPixelFormat);
136  }
137 
141  tVoid Release();
142 
155  tVoid Set(tInt nRedLocal, tInt nGreenLocal, tInt nBlueLocal, tInt nAlphaLocal = 255)
156  {
157  this->nRed = (tUInt8) nRedLocal;
158  this->nGreen = (tUInt8) nGreenLocal;
159  this->nBlue = (tUInt8) nBlueLocal;
160  this->nAlpha = (tUInt8) nAlphaLocal;
161  }
162 
175  tVoid Set(tUInt8 nRedLocal, tUInt8 nGreenLocal, tUInt8 nBlueLocal, tUInt8 nAlphaLocal = 255)
176  {
177  this->nRed = nRedLocal;
178  this->nGreen = nGreenLocal;
179  this->nBlue = nBlueLocal;
180  this->nAlpha = nAlphaLocal;
181  }
182 
193  tVoid Set(tFloat32 fRed, tFloat32 fGreen, tFloat32 fBlue, tFloat32 fAlpha = 1.0f)
194  {
195  this->nRed = (tUInt8) (fRed * 255.0f);
196  this->nGreen = (tUInt8) (fGreen * 255.0f);
197  this->nBlue = (tUInt8) (fBlue * 255.0f);
198  this->nAlpha = (tUInt8) (fAlpha * 255.0f);
199  }
200 
207  tVoid SetRGBA(tUInt32 nRGBA)
208  {
210  }
211 
221  tVoid SetRGBA(tUInt32 nRGBA, tInt oPixelFormat);
222 
231  tUInt32 GetRGBA() const
232  {
234  }
235 
243  tUInt32 GetRGBA(tInt oPixelFormat) const;
244 
252  operator tUInt32()
253  {
255  }
256 
264  tVoid SetRed(tUInt8 nRedValue)
265  {
266  this->nRed = nRedValue;
267  }
268 
276  tUInt8 GetRed() const
277  {
278  return nRed;
279  }
280 
288  tVoid SetGreen(tUInt8 nGreenValue)
289  {
290  this->nGreen = nGreenValue;
291  }
292 
300  tUInt8 GetGreen() const
301  {
302  return nGreen;
303  }
304 
312  tVoid SetBlue(tUInt8 nBlueValue)
313  {
314  this->nBlue = nBlueValue;
315  }
316 
324  tUInt8 GetBlue() const
325  {
326  return nBlue;
327  }
328 
336  tVoid SetAlpha(tUInt8 nAlphaValue)
337  {
338  this->nAlpha = nAlphaValue;
339  }
340 
348  tUInt8 GetAlpha() const
349  {
350  return nAlpha;
351  }
352 
360  tUInt8 GetBrightness() const
361  {
362  return (tUInt8) ((116 * nRed + 602 * nGreen + 306 * nBlue) >> 10);
363  }
364 
365 public:
373  static cColor Scale(const cColor& c, tInt nAlpha)
374  {
375  return cColor(c.nRed * nAlpha / 255,
376  c.nGreen * nAlpha / 255,
377  c.nBlue * nAlpha / 255);
378  }
379 
387  static cColor Scale(const cColor& c, tFloat32 fAlpha)
388  {
389  return cColor(c.nRed * fAlpha, c.nGreen * fAlpha, c.nBlue * fAlpha);
390  }
391 
400  static cColor Blend(const cColor& c1, const cColor& c2, tInt nAlpha)
401  {
402  tUInt8 nInvAlpha = (tUInt8) (255 - nAlpha);
403 
404  return cColor((c1.nRed * nAlpha + c2.nRed * nInvAlpha) / 255,
405  (c1.nGreen * nAlpha + c2.nGreen * nInvAlpha) / 255,
406  (c1.nBlue * nAlpha + c2.nBlue * nInvAlpha) / 255);
407  }
408 
417  static cColor Blend(const cColor& c1, const cColor& c2, tFloat32 fAlpha)
418  {
419  tUInt8 nAlpha = (tUInt8) (fAlpha * 255.0f);
420  tUInt8 nInvAlpha = (tUInt8) (255 - nAlpha);
421 
422  return cColor((c1.nRed * nAlpha + c2.nRed * nInvAlpha) / 255,
423  (c1.nGreen * nAlpha + c2.nGreen * nInvAlpha) / 255,
424  (c1.nBlue * nAlpha + c2.nBlue * nInvAlpha) / 255);
425  }
426 
438  static tResult ColorFromString(const tChar* strColor, cColor& oColor);
439 
445  explicit operator IColor*()
446  {
447  return static_cast<IColor*>(this);
448  }
449 
455  explicit operator const IColor*() const
456  {
457  return static_cast<const IColor*>(this);
458  }
459 
460 public:
461  static const cColor Black;
462  static const cColor White;
463  static const cColor Red;
464  static const cColor Green;
465  static const cColor Blue;
466  static const cColor Yellow;
467  static const cColor Cyan;
468  static const cColor Purple;
469 };
470 
471 }
472 
473 using dengar::cColor;
474 }
475 
476 }
477 
478 }
479 
Interface for color representation.
Definition: color_intf.h:27
virtual tUInt8 GetRed() const =0
Returns the value for the red channel.
virtual tUInt8 GetAlpha() const =0
This function returns the value for the alpha channel.
virtual tUInt8 GetBlue() const =0
Returns the value for the blue channel.
virtual tUInt8 GetGreen() const =0
Returns the value for the green channel.
@ PF_RGBA_8888
32 bit RGBA (R: 8 bit, G: 8 bit, B: 8 bit, A: 8 bit) with alpha value - default format for 32 bpp
Definition: image_intf.h:124
@ PF_BGRA_8888
32 bit BGRA (B: 8 bit, G: 8 bit, R: 8 bit, A: 8 bit) with alpha value - inverted RGB + A
Definition: image_intf.h:126
static cColor Blend(const cColor &c1, const cColor &c2, tFloat32 fAlpha)
blends two colors with an alpha channel
Definition: color.h:417
tVoid SetAlpha(tUInt8 nAlphaValue)
Sets the value of the alpha channel.
Definition: color.h:336
tVoid SetBlue(tUInt8 nBlueValue)
Sets the value of the blue channel.
Definition: color.h:312
static const cColor Yellow
definition of color yellow
Definition: color.h:466
tVoid SetRGBA(tUInt32 nRGBA, tInt oPixelFormat)
Method which decodes the rgba-values stored in nRGBA depending on the given pixelformat.
static const cColor Red
definition of color red
Definition: color.h:463
tVoid Release()
Releases this color.
cColor(tFloat32 fRed, tFloat32 fGreen, tFloat32 fBlue, tFloat32 fAlpha=1.0f)
constructor with several init parameters.
Definition: color.h:108
tUInt8 GetBlue() const
Returns the value for the green channel.
Definition: color.h:324
tUInt8 GetRed() const
Returns the value for the red channel.
Definition: color.h:276
tUInt8 GetBrightness() const
This function returns the brightness value.
Definition: color.h:360
cColor(const IColor *pColor)
constructor from IColor
Definition: color.h:50
static const cColor Purple
definition of color purple
Definition: color.h:468
static const cColor White
definition of color white
Definition: color.h:462
tVoid SetGreen(tUInt8 nGreenValue)
Sets the value of the green channel.
Definition: color.h:288
tUInt8 GetAlpha() const
This function returns the value for the alpha channel.
Definition: color.h:348
tVoid Set(tInt nRedLocal, tInt nGreenLocal, tInt nBlueLocal, tInt nAlphaLocal=255)
Method to set color and transparency information.
Definition: color.h:155
static cColor Scale(const cColor &c, tFloat32 fAlpha)
scales a color with an alpha channel
Definition: color.h:387
tVoid SetRGBA(tUInt32 nRGBA)
method to set color and transparency with a combined parameter (3 color channels and the alphachannel...
Definition: color.h:207
cColor(const tColor &oColor)
Constructor.
Definition: color.h:63
tUInt32 GetRGBA(tInt oPixelFormat) const
Gets a four byte balue containing the current rgba-values encoded in the given pixel format.
tVoid SetRed(tUInt8 nRedValue)
Sets the value of the red channel.
Definition: color.h:264
tVoid Set(tFloat32 fRed, tFloat32 fGreen, tFloat32 fBlue, tFloat32 fAlpha=1.0f)
Method to set color and transparency information.
Definition: color.h:193
static cColor Scale(const cColor &c, tInt nAlpha)
scales a color with an alpha channel
Definition: color.h:373
cColor(tUInt8 nRed, tUInt8 nGreen, tUInt8 nBlue, tUInt8 nAlpha=255)
constructor with several init parameters.
Definition: color.h:93
static cColor Blend(const cColor &c1, const cColor &c2, tInt nAlpha)
blends two colors with an alpha channel
Definition: color.h:400
static const cColor Black
definition of color black
Definition: color.h:461
static const cColor Blue
definition of color blue
Definition: color.h:465
cColor(tUInt32 nRGBA)
Constructor with a bitfield containing the encoded rgba-values.
Definition: color.h:122
static const cColor Cyan
definition of color cyan
Definition: color.h:467
tVoid Set(tUInt8 nRedLocal, tUInt8 nGreenLocal, tUInt8 nBlueLocal, tUInt8 nAlphaLocal=255)
Method to set color and transparency information.
Definition: color.h:175
tUInt32 GetRGBA() const
Gets a four Byte value containing the 3 color channels and the alphachannel.
Definition: color.h:231
cColor(tUInt32 nRGBA, tInt oPixelFormat)
Constructor with a bitfield containing the encoded rgba-values and another parameter which describes ...
Definition: color.h:133
cColor(tInt nRedLocal, tInt nGreenLocal, tInt nBlueLocal, tInt nAlphaLocal=255)
constructor with several init parameters.
Definition: color.h:78
static const cColor Green
definition of color green
Definition: color.h:464
tUInt8 GetGreen() const
Returns the value for the green channel.
Definition: color.h:300
static tResult ColorFromString(const tChar *strColor, cColor &oColor)
Converts a hexadecimal color value into a cColor object The input format is like the HTML color defin...
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Main namespace.