ADTF Display Toolbox
color.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <adtf_base.h>
12 
13 namespace adtf
14 {
15 
16 namespace disptb
17 {
18 
19 namespace graphicslib
20 {
21 
22 namespace dengar
23 {
24 
30 class cColor : public tColor, public IColor
31 {
32 public:
37  {
38  this->nRed = 0;
39  this->nGreen = 0;
40  this->nBlue = 0;
41  this->nAlpha = 0;
42  }
43 
49  cColor(const IColor* pColor)
50  {
51  this->nRed = pColor->GetRed();
52  this->nGreen = pColor->GetGreen();
53  this->nBlue = pColor->GetBlue();
54  this->nAlpha = pColor->GetAlpha();
55  }
56 
62  cColor(const tColor& oColor)
63  {
64  this->nRed = oColor.nRed;
65  this->nGreen = oColor.nGreen;
66  this->nBlue = oColor.nBlue;
67  this->nAlpha = oColor.nAlpha;
68  }
69 
77  cColor(tInt nRedLocal, tInt nGreenLocal, tInt nBlueLocal, tInt nAlphaLocal =255)
78  {
79  this->nRed = (tUInt8) nRedLocal;
80  this->nGreen = (tUInt8) nGreenLocal;
81  this->nBlue = (tUInt8) nBlueLocal;
82  this->nAlpha = (tUInt8) nAlphaLocal;
83  }
84 
92  cColor(tUInt8 nRed, tUInt8 nGreen, tUInt8 nBlue, tUInt8 nAlpha = 255)
93  {
94  this->nRed = (tUInt8) nRed;
95  this->nGreen = (tUInt8) nGreen;
96  this->nBlue = (tUInt8) nBlue;
97  this->nAlpha = (tUInt8) nAlpha;
98  }
99 
107  cColor(tFloat32 fRed, tFloat32 fGreen, tFloat32 fBlue, tFloat32 fAlpha = 1.0f)
108  {
109  this->nRed = (tUInt8) (fRed * 255.0f);
110  this->nGreen = (tUInt8) (fGreen * 255.0f);
111  this->nBlue = (tUInt8) (fBlue * 255.0f);
112  this->nAlpha = (tUInt8) (fAlpha * 255.0f);
113  }
114 
121  cColor(tUInt32 nRGBA)
122  {
123  SetRGBA(nRGBA);
124  }
125 
132  cColor(tUInt32 nRGBA, tInt oPixelFormat)
133  {
134  SetRGBA(nRGBA, oPixelFormat);
135  }
136 
140  tVoid Release();
141 
154  tVoid Set(tInt nRedLocal, tInt nGreenLocal, tInt nBlueLocal, tInt nAlphaLocal = 255)
155  {
156  this->nRed = (tUInt8) nRedLocal;
157  this->nGreen = (tUInt8) nGreenLocal;
158  this->nBlue = (tUInt8) nBlueLocal;
159  this->nAlpha = (tUInt8) nAlphaLocal;
160  }
161 
174  tVoid Set(tUInt8 nRedLocal, tUInt8 nGreenLocal, tUInt8 nBlueLocal, tUInt8 nAlphaLocal = 255)
175  {
176  this->nRed = nRedLocal;
177  this->nGreen = nGreenLocal;
178  this->nBlue = nBlueLocal;
179  this->nAlpha = nAlphaLocal;
180  }
181 
192  tVoid Set(tFloat32 fRed, tFloat32 fGreen, tFloat32 fBlue, tFloat32 fAlpha = 1.0f)
193  {
194  this->nRed = (tUInt8) (fRed * 255.0f);
195  this->nGreen = (tUInt8) (fGreen * 255.0f);
196  this->nBlue = (tUInt8) (fBlue * 255.0f);
197  this->nAlpha = (tUInt8) (fAlpha * 255.0f);
198  }
199 
206  tVoid SetRGBA(tUInt32 nRGBA)
207  {
209  }
210 
220  tVoid SetRGBA(tUInt32 nRGBA, tInt oPixelFormat);
221 
230  tUInt32 GetRGBA() const
231  {
233  }
234 
242  tUInt32 GetRGBA(tInt oPixelFormat) const;
243 
251  operator tUInt32()
252  {
254  }
255 
263  tVoid SetRed(tUInt8 nRedValue)
264  {
265  this->nRed = nRedValue;
266  }
267 
275  tUInt8 GetRed() const
276  {
277  return nRed;
278  }
279 
287  tVoid SetGreen(tUInt8 nGreenValue)
288  {
289  this->nGreen = nGreenValue;
290  }
291 
299  tUInt8 GetGreen() const
300  {
301  return nGreen;
302  }
303 
311  tVoid SetBlue(tUInt8 nBlueValue)
312  {
313  this->nBlue = nBlueValue;
314  }
315 
323  tUInt8 GetBlue() const
324  {
325  return nBlue;
326  }
327 
335  tVoid SetAlpha(tUInt8 nAlphaValue)
336  {
337  this->nAlpha = nAlphaValue;
338  }
339 
347  tUInt8 GetAlpha() const
348  {
349  return nAlpha;
350  }
351 
359  tUInt8 GetBrightness() const
360  {
361  return (tUInt8) ((116 * nRed + 602 * nGreen + 306 * nBlue) >> 10);
362  }
363 
364 public:
372  static cColor Scale(const cColor& c, tInt nAlpha)
373  {
374  return cColor(c.nRed * nAlpha / 255,
375  c.nGreen * nAlpha / 255,
376  c.nBlue * nAlpha / 255);
377  }
378 
386  static cColor Scale(const cColor& c, tFloat32 fAlpha)
387  {
388  return cColor(c.nRed * fAlpha, c.nGreen * fAlpha, c.nBlue * fAlpha);
389  }
390 
399  static cColor Blend(const cColor& c1, const cColor& c2, tInt nAlpha)
400  {
401  tUInt8 nInvAlpha = (tUInt8) (255 - nAlpha);
402 
403  return cColor((c1.nRed * nAlpha + c2.nRed * nInvAlpha) / 255,
404  (c1.nGreen * nAlpha + c2.nGreen * nInvAlpha) / 255,
405  (c1.nBlue * nAlpha + c2.nBlue * nInvAlpha) / 255);
406  }
407 
416  static cColor Blend(const cColor& c1, const cColor& c2, tFloat32 fAlpha)
417  {
418  tUInt8 nAlpha = (tUInt8) (fAlpha * 255.0f);
419  tUInt8 nInvAlpha = (tUInt8) (255 - nAlpha);
420 
421  return cColor((c1.nRed * nAlpha + c2.nRed * nInvAlpha) / 255,
422  (c1.nGreen * nAlpha + c2.nGreen * nInvAlpha) / 255,
423  (c1.nBlue * nAlpha + c2.nBlue * nInvAlpha) / 255);
424  }
425 
437  static tResult ColorFromString(const tChar* strColor, cColor& oColor);
438 
444  explicit operator IColor*()
445  {
446  return static_cast<IColor*>(this);
447  }
448 
454  explicit operator const IColor*() const
455  {
456  return static_cast<const IColor*>(this);
457  }
458 
459 public:
460  static const cColor Black;
461  static const cColor White;
462  static const cColor Red;
463  static const cColor Green;
464  static const cColor Blue;
465  static const cColor Yellow;
466  static const cColor Cyan;
467  static const cColor Purple;
468 };
469 
470 }
471 
472 using dengar::cColor;
473 }
474 
475 }
476 
477 }
478 
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:416
tVoid SetAlpha(tUInt8 nAlphaValue)
Sets the value of the alpha channel.
Definition: color.h:335
tVoid SetBlue(tUInt8 nBlueValue)
Sets the value of the blue channel.
Definition: color.h:311
static const cColor Yellow
definition of color yellow
Definition: color.h:465
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:462
tVoid Release()
Releases this color.
cColor(tFloat32 fRed, tFloat32 fGreen, tFloat32 fBlue, tFloat32 fAlpha=1.0f)
constructor with several init parameters.
Definition: color.h:107
tUInt8 GetBlue() const
Returns the value for the green channel.
Definition: color.h:323
tUInt8 GetRed() const
Returns the value for the red channel.
Definition: color.h:275
tUInt8 GetBrightness() const
This function returns the brightness value.
Definition: color.h:359
cColor(const IColor *pColor)
constructor from IColor
Definition: color.h:49
static const cColor Purple
definition of color purple
Definition: color.h:467
static const cColor White
definition of color white
Definition: color.h:461
tVoid SetGreen(tUInt8 nGreenValue)
Sets the value of the green channel.
Definition: color.h:287
tUInt8 GetAlpha() const
This function returns the value for the alpha channel.
Definition: color.h:347
tVoid Set(tInt nRedLocal, tInt nGreenLocal, tInt nBlueLocal, tInt nAlphaLocal=255)
Method to set color and transparency information.
Definition: color.h:154
static cColor Scale(const cColor &c, tFloat32 fAlpha)
scales a color with an alpha channel
Definition: color.h:386
tVoid SetRGBA(tUInt32 nRGBA)
method to set color and transparency with a combined parameter (3 color channels and the alphachannel...
Definition: color.h:206
cColor(const tColor &oColor)
Constructor.
Definition: color.h:62
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:263
tVoid Set(tFloat32 fRed, tFloat32 fGreen, tFloat32 fBlue, tFloat32 fAlpha=1.0f)
Method to set color and transparency information.
Definition: color.h:192
static cColor Scale(const cColor &c, tInt nAlpha)
scales a color with an alpha channel
Definition: color.h:372
cColor(tUInt8 nRed, tUInt8 nGreen, tUInt8 nBlue, tUInt8 nAlpha=255)
constructor with several init parameters.
Definition: color.h:92
static cColor Blend(const cColor &c1, const cColor &c2, tInt nAlpha)
blends two colors with an alpha channel
Definition: color.h:399
static const cColor Black
definition of color black
Definition: color.h:460
static const cColor Blue
definition of color blue
Definition: color.h:464
cColor(tUInt32 nRGBA)
Constructor with a bitfield containing the encoded rgba-values.
Definition: color.h:121
static const cColor Cyan
definition of color cyan
Definition: color.h:466
tVoid Set(tUInt8 nRedLocal, tUInt8 nGreenLocal, tUInt8 nBlueLocal, tUInt8 nAlphaLocal=255)
Method to set color and transparency information.
Definition: color.h:174
tUInt32 GetRGBA() const
Gets a four Byte value containing the 3 color channels and the alphachannel.
Definition: color.h:230
cColor(tUInt32 nRGBA, tInt oPixelFormat)
Constructor with a bitfield containing the encoded rgba-values and another parameter which describes ...
Definition: color.h:132
cColor(tInt nRedLocal, tInt nGreenLocal, tInt nBlueLocal, tInt nAlphaLocal=255)
constructor with several init parameters.
Definition: color.h:77
static const cColor Green
definition of color green
Definition: color.h:463
tUInt8 GetGreen() const
Returns the value for the green channel.
Definition: color.h:299
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.