1 // Created on: 2012-07-18
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Image_Color_H__
17 #define _Image_Color_H__
19 #include <Standard.hxx>
21 //! POD structure for packed RGB color value (3 bytes)
26 typedef Standard_Byte ComponentType_t;
28 //! Returns the number of components.
29 static Standard_Integer Length()
34 public: // access methods
36 //! Alias to 1st component (red intensity).
37 Standard_Byte r() const { return v[0]; }
39 //! Alias to 2nd component (green intensity).
40 Standard_Byte g() const { return v[1]; }
42 //! Alias to 3rd component (blue intensity).
43 Standard_Byte b() const { return v[2]; }
45 //! Alias to 1st component (red intensity).
46 Standard_Byte& r() { return v[0]; }
48 //! Alias to 2nd component (green intensity).
49 Standard_Byte& g() { return v[1]; }
51 //! Alias to 3rd component (blue intensity).
52 Standard_Byte& b() { return v[2]; }
60 //! POD structure for packed RGB color value (4 bytes with extra byte for alignment)
61 struct Image_ColorRGB32
65 typedef Standard_Byte ComponentType_t;
67 //! Returns the number of components.
68 static Standard_Integer Length()
73 //! Alias to 1st component (red intensity).
74 Standard_Byte r() const { return v[0]; }
76 //! Alias to 2nd component (green intensity).
77 Standard_Byte g() const { return v[1]; }
79 //! Alias to 3rd component (blue intensity).
80 Standard_Byte b() const { return v[2]; }
82 //! Alias to 4th component (dummy).
83 Standard_Byte a_() const { return v[3]; }
85 //! Alias to 1st component (red intensity).
86 Standard_Byte& r() { return v[0]; }
88 //! Alias to 2nd component (green intensity).
89 Standard_Byte& g() { return v[1]; }
91 //! Alias to 3rd component (blue intensity).
92 Standard_Byte& b() { return v[2]; }
94 //! Alias to 4th component (dummy).
95 Standard_Byte& a_() { return v[3]; }
103 //! POD structure for packed RGBA color value (4 bytes)
104 struct Image_ColorRGBA
108 typedef Standard_Byte ComponentType_t;
110 //! Returns the number of components.
111 static Standard_Integer Length()
116 //! Alias to 1st component (red intensity).
117 Standard_Byte r() const { return v[0]; }
119 //! Alias to 2nd component (green intensity).
120 Standard_Byte g() const { return v[1]; }
122 //! Alias to 3rd component (blue intensity).
123 Standard_Byte b() const { return v[2]; }
125 //! Alias to 4th component (alpha value).
126 Standard_Byte a() const { return v[3]; }
128 //! Alias to 1st component (red intensity).
129 Standard_Byte& r() { return v[0]; }
131 //! Alias to 2nd component (green intensity).
132 Standard_Byte& g() { return v[1]; }
134 //! Alias to 3rd component (blue intensity).
135 Standard_Byte& b() { return v[2]; }
137 //! Alias to 4th component (alpha value).
138 Standard_Byte& a() { return v[3]; }
146 //! POD structure for packed BGR color value (3 bytes)
147 struct Image_ColorBGR
151 typedef Standard_Byte ComponentType_t;
153 //! Returns the number of components.
154 static Standard_Integer Length()
159 //! Alias to 3rd component (red intensity).
160 Standard_Byte r() const { return v[2]; }
162 //! Alias to 2nd component (green intensity).
163 Standard_Byte g() const { return v[1]; }
165 //! Alias to 1st component (blue intensity).
166 Standard_Byte b() const { return v[0]; }
168 //! Alias to 3rd component (red intensity).
169 Standard_Byte& r() { return v[2]; }
171 //! Alias to 2nd component (green intensity).
172 Standard_Byte& g() { return v[1]; }
174 //! Alias to 1st component (blue intensity).
175 Standard_Byte& b() { return v[0]; }
183 //! POD structure for packed BGR color value (4 bytes with extra byte for alignment)
184 struct Image_ColorBGR32
188 typedef Standard_Byte ComponentType_t;
190 //! Returns the number of components.
191 static Standard_Integer Length()
196 //! Alias to 3rd component (red intensity).
197 Standard_Byte r() const { return v[2]; }
199 //! Alias to 2nd component (green intensity).
200 Standard_Byte g() const { return v[1]; }
202 //! Alias to 1st component (blue intensity).
203 Standard_Byte b() const { return v[0]; }
205 //! Alias to 4th component (dummy).
206 Standard_Byte a_() const { return v[3]; }
208 //! Alias to 3rd component (red intensity).
209 Standard_Byte& r() { return v[2]; }
211 //! Alias to 2nd component (green intensity).
212 Standard_Byte& g() { return v[1]; }
214 //! Alias to 1st component (blue intensity).
215 Standard_Byte& b() { return v[0]; }
217 //! Alias to 4th component (dummy).
218 Standard_Byte& a_() { return v[3]; }
226 //! POD structure for packed BGRA color value (4 bytes)
227 struct Image_ColorBGRA
231 typedef Standard_Byte ComponentType_t;
233 //! Returns the number of components.
234 static Standard_Integer Length()
239 //! Alias to 3rd component (red intensity).
240 Standard_Byte r() const { return v[2]; }
242 //! Alias to 2nd component (green intensity).
243 Standard_Byte g() const { return v[1]; }
245 //! Alias to 1st component (blue intensity).
246 Standard_Byte b() const { return v[0]; }
248 //! Alias to 4th component (alpha value).
249 Standard_Byte a() const { return v[3]; }
251 //! Alias to 3rd component (red intensity).
252 Standard_Byte& r() { return v[2]; }
254 //! Alias to 2nd component (green intensity).
255 Standard_Byte& g() { return v[1]; }
257 //! Alias to 1st component (blue intensity).
258 Standard_Byte& b() { return v[0]; }
260 //! Alias to 4th component (alpha value).
261 Standard_Byte& a() { return v[3]; }
269 //! POD structure for packed float RGB color value (3 floats)
270 struct Image_ColorRGBF
274 typedef Standard_ShortReal ComponentType_t;
276 //! Returns the number of components.
277 static Standard_Integer Length()
282 //! Alias to 1st component (red intensity).
283 Standard_ShortReal r() const { return v[0]; }
285 //! Alias to 2nd component (green intensity).
286 Standard_ShortReal g() const { return v[1]; }
288 //! Alias to 3rd component (blue intensity).
289 Standard_ShortReal b() const { return v[2]; }
291 //! Alias to 1st component (red intensity).
292 Standard_ShortReal& r() { return v[0]; }
294 //! Alias to 2nd component (green intensity).
295 Standard_ShortReal& g() { return v[1]; }
297 //! Alias to 3rd component (blue intensity).
298 Standard_ShortReal& b() { return v[2]; }
302 Standard_ShortReal v[3];
306 //! POD structure for packed BGR float color value (3 floats)
307 struct Image_ColorBGRF
311 typedef Standard_ShortReal ComponentType_t;
313 //! Returns the number of components.
314 static Standard_Integer Length()
319 //! Alias to 3rd component (red intensity).
320 Standard_ShortReal r() const { return v[2]; }
322 //! Alias to 2nd component (green intensity).
323 Standard_ShortReal g() const { return v[1]; }
325 //! Alias to 1st component (blue intensity).
326 Standard_ShortReal b() const { return v[0]; }
328 //! Alias to 3rd component (red intensity).
329 Standard_ShortReal& r() { return v[2]; }
331 //! Alias to 2nd component (green intensity).
332 Standard_ShortReal& g() { return v[1]; }
334 //! Alias to 1st component (blue intensity).
335 Standard_ShortReal& b() { return v[0]; }
339 Standard_ShortReal v[3];
343 //! POD structure for packed RGBA color value (4 floats)
344 struct Image_ColorRGBAF
348 typedef Standard_ShortReal ComponentType_t;
350 //! Returns the number of components.
351 static Standard_Integer Length()
356 //! Alias to 1st component (red intensity).
357 Standard_ShortReal r() const { return v[0]; }
359 //! Alias to 2nd component (green intensity).
360 Standard_ShortReal g() const { return v[1]; }
362 //! Alias to 3rd component (blue intensity).
363 Standard_ShortReal b() const { return v[2]; }
365 //! Alias to 4th component (alpha value).
366 Standard_ShortReal a() const { return v[3]; }
368 //! Alias to 1st component (red intensity).
369 Standard_ShortReal& r() { return v[0]; }
371 //! Alias to 2nd component (green intensity).
372 Standard_ShortReal& g() { return v[1]; }
374 //! Alias to 3rd component (blue intensity).
375 Standard_ShortReal& b() { return v[2]; }
377 //! Alias to 4th component (alpha value).
378 Standard_ShortReal& a() { return v[3]; }
382 Standard_ShortReal v[4];
386 //! POD structure for packed float BGRA color value (4 floats)
387 struct Image_ColorBGRAF
391 typedef Standard_ShortReal ComponentType_t;
393 //! Returns the number of components.
394 static Standard_Integer Length()
399 //! Alias to 3rd component (red intensity).
400 Standard_ShortReal r() const { return v[2]; }
402 //! Alias to 2nd component (green intensity).
403 Standard_ShortReal g() const { return v[1]; }
405 //! Alias to 1st component (blue intensity).
406 Standard_ShortReal b() const { return v[0]; }
408 //! Alias to 4th component (alpha value).
409 Standard_ShortReal a() const { return v[3]; }
411 //! Alias to 3rd component (red intensity).
412 Standard_ShortReal& r() { return v[2]; }
414 //! Alias to 2nd component (green intensity).
415 Standard_ShortReal& g() { return v[1]; }
417 //! Alias to 1st component (blue intensity).
418 Standard_ShortReal& b() { return v[0]; }
420 //! Alias to 4th component (alpha value).
421 Standard_ShortReal& a() { return v[3]; }
425 Standard_ShortReal v[4];
429 //! Addition operator
430 template<typename ColorType_t>
431 inline ColorType_t Image_ColorSumm3 (const ColorType_t& theA, const ColorType_t& theB)
433 ColorType_t aRes = {{typename ColorType_t::ComponentType_t (theA.v[0] + theB.v[0]),
434 typename ColorType_t::ComponentType_t (theA.v[1] + theB.v[1]),
435 typename ColorType_t::ComponentType_t (theA.v[2] + theB.v[2])}};
439 inline Image_ColorRGB operator+ (const Image_ColorRGB& theA, const Image_ColorRGB& theB)
441 return Image_ColorSumm3 (theA, theB);
444 inline Image_ColorBGR operator+ (const Image_ColorBGR& theA, const Image_ColorBGR& theB)
446 return Image_ColorSumm3 (theA, theB);
449 inline Image_ColorRGBF operator+ (const Image_ColorRGBF& theA, const Image_ColorRGBF& theB)
451 return Image_ColorSumm3 (theA, theB);
454 inline Image_ColorBGRF operator+ (const Image_ColorBGRF& theA, const Image_ColorBGRF& theB)
456 return Image_ColorSumm3 (theA, theB);
459 template<typename ColorType_t>
460 inline ColorType_t Image_ColorSumm4 (const ColorType_t& theA, const ColorType_t& theB)
462 ColorType_t aRes = {{typename ColorType_t::ComponentType_t (theA.v[0] + theB.v[0]),
463 typename ColorType_t::ComponentType_t (theA.v[1] + theB.v[1]),
464 typename ColorType_t::ComponentType_t (theA.v[2] + theB.v[2]),
465 typename ColorType_t::ComponentType_t (theA.v[3] + theB.v[3])}};
469 inline Image_ColorRGBA operator+ (const Image_ColorRGBA& theA, const Image_ColorRGBA& theB)
471 return Image_ColorSumm4 (theA, theB);
474 inline Image_ColorBGRA operator+ (const Image_ColorBGRA& theA, const Image_ColorBGRA& theB)
476 return Image_ColorSumm4 (theA, theB);
479 inline Image_ColorRGB32 operator+ (const Image_ColorRGB32& theA, const Image_ColorRGB32& theB)
481 return Image_ColorSumm4 (theA, theB);
484 inline Image_ColorBGR32 operator+ (const Image_ColorBGR32& theA, const Image_ColorBGR32& theB)
486 return Image_ColorSumm4 (theA, theB);
489 inline Image_ColorRGBAF operator+ (const Image_ColorRGBAF& theA, const Image_ColorRGBAF& theB)
491 return Image_ColorSumm4 (theA, theB);
494 inline Image_ColorBGRAF operator+ (const Image_ColorBGRAF& theA, const Image_ColorBGRAF& theB)
496 return Image_ColorSumm4 (theA, theB);
499 //! Subtraction operator
500 template<typename ColorType_t>
501 inline ColorType_t Image_ColorSub3 (const ColorType_t& theA, const ColorType_t& theB)
503 ColorType_t aRes = {{typename ColorType_t::ComponentType_t (theA.v[0] - theB.v[0]),
504 typename ColorType_t::ComponentType_t (theA.v[1] - theB.v[1]),
505 typename ColorType_t::ComponentType_t (theA.v[2] - theB.v[2])}};
509 inline Image_ColorRGB operator- (const Image_ColorRGB& theA, const Image_ColorRGB& theB)
511 return Image_ColorSub3 (theA, theB);
514 inline Image_ColorBGR operator- (const Image_ColorBGR& theA, const Image_ColorBGR& theB)
516 return Image_ColorSub3 (theA, theB);
519 inline Image_ColorRGBF operator- (const Image_ColorRGBF& theA, const Image_ColorRGBF& theB)
521 return Image_ColorSub3 (theA, theB);
524 inline Image_ColorBGRF operator- (const Image_ColorBGRF& theA, const Image_ColorBGRF& theB)
526 return Image_ColorSub3 (theA, theB);
529 template<typename ColorType_t>
530 inline ColorType_t Image_ColorSub4 (const ColorType_t& theA, const ColorType_t& theB)
532 ColorType_t aRes = {{typename ColorType_t::ComponentType_t (theA.v[0] - theB.v[0]),
533 typename ColorType_t::ComponentType_t (theA.v[1] - theB.v[1]),
534 typename ColorType_t::ComponentType_t (theA.v[2] - theB.v[2]),
535 typename ColorType_t::ComponentType_t (theA.v[3] - theB.v[3])}};
539 inline Image_ColorRGBA operator- (const Image_ColorRGBA& theA, const Image_ColorRGBA& theB)
541 return Image_ColorSub4 (theA, theB);
544 inline Image_ColorBGRA operator- (const Image_ColorBGRA& theA, const Image_ColorBGRA& theB)
546 return Image_ColorSub4 (theA, theB);
549 inline Image_ColorRGB32 operator- (const Image_ColorRGB32& theA, const Image_ColorRGB32& theB)
551 return Image_ColorSub4 (theA, theB);
554 inline Image_ColorBGR32 operator- (const Image_ColorBGR32& theA, const Image_ColorBGR32& theB)
556 return Image_ColorSub4 (theA, theB);
559 inline Image_ColorRGBAF operator- (const Image_ColorRGBAF& theA, const Image_ColorRGBAF& theB)
561 return Image_ColorSub4 (theA, theB);
564 inline Image_ColorBGRAF operator- (const Image_ColorBGRAF& theA, const Image_ColorBGRAF& theB)
566 return Image_ColorSub4 (theA, theB);
569 #endif // _Image_Color_H__