1 // Created on: 2012-07-18
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 #ifndef _Image_Color_H__
21 #define _Image_Color_H__
23 #include <Standard.hxx>
25 //! POD structure for packed RGB color value (3 bytes)
29 //! Returns the number of components.
30 static Standard_Integer Length()
35 public: // access methods
37 //! Alias to 1st component (red intensity).
38 Standard_Byte r() const { return v[0]; }
40 //! Alias to 2nd component (green intensity).
41 Standard_Byte g() const { return v[1]; }
43 //! Alias to 3rd component (blue intensity).
44 Standard_Byte b() const { return v[2]; }
46 //! Alias to 1st component (red intensity).
47 Standard_Byte& r() { return v[0]; }
49 //! Alias to 2nd component (green intensity).
50 Standard_Byte& g() { return v[1]; }
52 //! Alias to 3rd component (blue intensity).
53 Standard_Byte& b() { return v[2]; }
61 //! POD structure for packed RGB color value (4 bytes with extra byte for alignment)
62 struct Image_ColorRGB32
65 //! Returns the number of components.
66 static Standard_Integer Length()
71 //! Alias to 1st component (red intensity).
72 Standard_Byte r() const { return v[0]; }
74 //! Alias to 2nd component (green intensity).
75 Standard_Byte g() const { return v[1]; }
77 //! Alias to 3rd component (blue intensity).
78 Standard_Byte b() const { return v[2]; }
80 //! Alias to 4th component (dummy).
81 Standard_Byte a_() const { return v[3]; }
83 //! Alias to 1st component (red intensity).
84 Standard_Byte& r() { return v[0]; }
86 //! Alias to 2nd component (green intensity).
87 Standard_Byte& g() { return v[1]; }
89 //! Alias to 3rd component (blue intensity).
90 Standard_Byte& b() { return v[2]; }
92 //! Alias to 4th component (dummy).
93 Standard_Byte& a_() { return v[3]; }
101 //! POD structure for packed RGBA color value (4 bytes)
102 struct Image_ColorRGBA
105 //! Returns the number of components.
106 static Standard_Integer Length()
111 //! Alias to 1st component (red intensity).
112 Standard_Byte r() const { return v[0]; }
114 //! Alias to 2nd component (green intensity).
115 Standard_Byte g() const { return v[1]; }
117 //! Alias to 3rd component (blue intensity).
118 Standard_Byte b() const { return v[2]; }
120 //! Alias to 4th component (alpha value).
121 Standard_Byte a() const { return v[3]; }
123 //! Alias to 1st component (red intensity).
124 Standard_Byte& r() { return v[0]; }
126 //! Alias to 2nd component (green intensity).
127 Standard_Byte& g() { return v[1]; }
129 //! Alias to 3rd component (blue intensity).
130 Standard_Byte& b() { return v[2]; }
132 //! Alias to 4th component (alpha value).
133 Standard_Byte& a() { return v[3]; }
141 //! POD structure for packed BGR color value (3 bytes)
142 struct Image_ColorBGR
145 //! Returns the number of components.
146 static Standard_Integer Length()
151 //! Alias to 3rd component (red intensity).
152 Standard_Byte r() const { return v[2]; }
154 //! Alias to 2nd component (green intensity).
155 Standard_Byte g() const { return v[1]; }
157 //! Alias to 1st component (blue intensity).
158 Standard_Byte b() const { return v[0]; }
160 //! Alias to 3rd component (red intensity).
161 Standard_Byte& r() { return v[2]; }
163 //! Alias to 2nd component (green intensity).
164 Standard_Byte& g() { return v[1]; }
166 //! Alias to 1st component (blue intensity).
167 Standard_Byte& b() { return v[0]; }
175 //! POD structure for packed BGR color value (4 bytes with extra byte for alignment)
176 struct Image_ColorBGR32
179 //! Returns the number of components.
180 static Standard_Integer Length()
185 //! Alias to 3rd component (red intensity).
186 Standard_Byte r() const { return v[2]; }
188 //! Alias to 2nd component (green intensity).
189 Standard_Byte g() const { return v[1]; }
191 //! Alias to 1st component (blue intensity).
192 Standard_Byte b() const { return v[0]; }
194 //! Alias to 4th component (dummy).
195 Standard_Byte a_() const { return v[3]; }
197 //! Alias to 3rd component (red intensity).
198 Standard_Byte& r() { return v[2]; }
200 //! Alias to 2nd component (green intensity).
201 Standard_Byte& g() { return v[1]; }
203 //! Alias to 1st component (blue intensity).
204 Standard_Byte& b() { return v[0]; }
206 //! Alias to 4th component (dummy).
207 Standard_Byte& a_() { return v[3]; }
215 //! POD structure for packed BGRA color value (4 bytes)
216 struct Image_ColorBGRA
219 //! Returns the number of components.
220 static Standard_Integer Length()
225 //! Alias to 3rd component (red intensity).
226 Standard_Byte r() const { return v[2]; }
228 //! Alias to 2nd component (green intensity).
229 Standard_Byte g() const { return v[1]; }
231 //! Alias to 1st component (blue intensity).
232 Standard_Byte b() const { return v[0]; }
234 //! Alias to 4th component (alpha value).
235 Standard_Byte a() const { return v[3]; }
237 //! Alias to 3rd component (red intensity).
238 Standard_Byte& r() { return v[2]; }
240 //! Alias to 2nd component (green intensity).
241 Standard_Byte& g() { return v[1]; }
243 //! Alias to 1st component (blue intensity).
244 Standard_Byte& b() { return v[0]; }
246 //! Alias to 4th component (alpha value).
247 Standard_Byte& a() { return v[3]; }
255 //! POD structure for packed float RGB color value (3 floats)
256 struct Image_ColorRGBF
259 //! Returns the number of components.
260 static Standard_Integer Length()
265 //! Alias to 1st component (red intensity).
266 Standard_ShortReal r() const { return v[0]; }
268 //! Alias to 2nd component (green intensity).
269 Standard_ShortReal g() const { return v[1]; }
271 //! Alias to 3rd component (blue intensity).
272 Standard_ShortReal b() const { return v[2]; }
274 //! Alias to 1st component (red intensity).
275 Standard_ShortReal& r() { return v[0]; }
277 //! Alias to 2nd component (green intensity).
278 Standard_ShortReal& g() { return v[1]; }
280 //! Alias to 3rd component (blue intensity).
281 Standard_ShortReal& b() { return v[2]; }
285 Standard_ShortReal v[3];
289 //! POD structure for packed BGR float color value (3 floats)
290 struct Image_ColorBGRF
293 //! Returns the number of components.
294 static Standard_Integer Length()
299 //! Alias to 3rd component (red intensity).
300 Standard_ShortReal r() const { return v[2]; }
302 //! Alias to 2nd component (green intensity).
303 Standard_ShortReal g() const { return v[1]; }
305 //! Alias to 1st component (blue intensity).
306 Standard_ShortReal b() const { return v[0]; }
308 //! Alias to 3rd component (red intensity).
309 Standard_ShortReal& r() { return v[2]; }
311 //! Alias to 2nd component (green intensity).
312 Standard_ShortReal& g() { return v[1]; }
314 //! Alias to 1st component (blue intensity).
315 Standard_ShortReal& b() { return v[0]; }
319 Standard_ShortReal v[3];
323 //! POD structure for packed RGBA color value (4 floats)
324 struct Image_ColorRGBAF
327 //! Returns the number of components.
328 static Standard_Integer Length()
333 //! Alias to 1st component (red intensity).
334 Standard_ShortReal r() const { return v[0]; }
336 //! Alias to 2nd component (green intensity).
337 Standard_ShortReal g() const { return v[1]; }
339 //! Alias to 3rd component (blue intensity).
340 Standard_ShortReal b() const { return v[2]; }
342 //! Alias to 4th component (alpha value).
343 Standard_ShortReal a() const { return v[3]; }
345 //! Alias to 1st component (red intensity).
346 Standard_ShortReal& r() { return v[0]; }
348 //! Alias to 2nd component (green intensity).
349 Standard_ShortReal& g() { return v[1]; }
351 //! Alias to 3rd component (blue intensity).
352 Standard_ShortReal& b() { return v[2]; }
354 //! Alias to 4th component (alpha value).
355 Standard_ShortReal& a() { return v[3]; }
359 Standard_ShortReal v[4];
363 //! POD structure for packed float BGRA color value (4 floats)
364 struct Image_ColorBGRAF
367 //! Returns the number of components.
368 static Standard_Integer Length()
373 //! Alias to 3rd component (red intensity).
374 Standard_ShortReal r() const { return v[2]; }
376 //! Alias to 2nd component (green intensity).
377 Standard_ShortReal g() const { return v[1]; }
379 //! Alias to 1st component (blue intensity).
380 Standard_ShortReal b() const { return v[0]; }
382 //! Alias to 4th component (alpha value).
383 Standard_ShortReal a() const { return v[3]; }
385 //! Alias to 3rd component (red intensity).
386 Standard_ShortReal& r() { return v[2]; }
388 //! Alias to 2nd component (green intensity).
389 Standard_ShortReal& g() { return v[1]; }
391 //! Alias to 1st component (blue intensity).
392 Standard_ShortReal& b() { return v[0]; }
394 //! Alias to 4th component (alpha value).
395 Standard_ShortReal& a() { return v[3]; }
399 Standard_ShortReal v[4];
403 //! Addition operator
404 template<typename ColorType_t>
405 inline ColorType_t Image_ColorSumm3 (const ColorType_t& theA, const ColorType_t& theB)
407 ColorType_t aRes = { theA.v[0] + theB.v[0],
408 theA.v[1] + theB.v[1],
409 theA.v[2] + theB.v[2] };
413 inline Image_ColorRGB operator+ (const Image_ColorRGB& theA, const Image_ColorRGB& theB)
415 return Image_ColorSumm3 (theA, theB);
418 inline Image_ColorBGR operator+ (const Image_ColorBGR& theA, const Image_ColorBGR& theB)
420 return Image_ColorSumm3 (theA, theB);
423 inline Image_ColorRGBF operator+ (const Image_ColorRGBF& theA, const Image_ColorRGBF& theB)
425 return Image_ColorSumm3 (theA, theB);
428 inline Image_ColorBGRF operator+ (const Image_ColorBGRF& theA, const Image_ColorBGRF& theB)
430 return Image_ColorSumm3 (theA, theB);
433 template<typename ColorType_t>
434 inline ColorType_t Image_ColorSumm4 (const ColorType_t& theA, const ColorType_t& theB)
436 ColorType_t aRes = { theA.v[0] + theB.v[0],
437 theA.v[1] + theB.v[1],
438 theA.v[2] + theB.v[2],
439 theA.v[3] + theB.v[3] };
443 inline Image_ColorRGBA operator+ (const Image_ColorRGBA& theA, const Image_ColorRGBA& theB)
445 return Image_ColorSumm4 (theA, theB);
448 inline Image_ColorBGRA operator+ (const Image_ColorBGRA& theA, const Image_ColorBGRA& theB)
450 return Image_ColorSumm4 (theA, theB);
453 inline Image_ColorRGB32 operator+ (const Image_ColorRGB32& theA, const Image_ColorRGB32& theB)
455 return Image_ColorSumm4 (theA, theB);
458 inline Image_ColorBGR32 operator+ (const Image_ColorBGR32& theA, const Image_ColorBGR32& theB)
460 return Image_ColorSumm4 (theA, theB);
463 inline Image_ColorRGBAF operator+ (const Image_ColorRGBAF& theA, const Image_ColorRGBAF& theB)
465 return Image_ColorSumm4 (theA, theB);
468 inline Image_ColorBGRAF operator+ (const Image_ColorBGRAF& theA, const Image_ColorBGRAF& theB)
470 return Image_ColorSumm4 (theA, theB);
473 //! Subtraction operator
474 template<typename ColorType_t>
475 inline ColorType_t Image_ColorSub3 (const ColorType_t& theA, const ColorType_t& theB)
477 ColorType_t aRes = { theA.v[0] - theB.v[0],
478 theA.v[1] - theB.v[1],
479 theA.v[2] - theB.v[2] };
483 inline Image_ColorRGB operator- (const Image_ColorRGB& theA, const Image_ColorRGB& theB)
485 return Image_ColorSub3 (theA, theB);
488 inline Image_ColorBGR operator- (const Image_ColorBGR& theA, const Image_ColorBGR& theB)
490 return Image_ColorSub3 (theA, theB);
493 inline Image_ColorRGBF operator- (const Image_ColorRGBF& theA, const Image_ColorRGBF& theB)
495 return Image_ColorSub3 (theA, theB);
498 inline Image_ColorBGRF operator- (const Image_ColorBGRF& theA, const Image_ColorBGRF& theB)
500 return Image_ColorSub3 (theA, theB);
503 template<typename ColorType_t>
504 inline ColorType_t Image_ColorSub4 (const ColorType_t& theA, const ColorType_t& theB)
506 ColorType_t aRes = { theA.v[0] - theB.v[0],
507 theA.v[1] - theB.v[1],
508 theA.v[2] - theB.v[2],
509 theA.v[3] - theB.v[3] };
513 inline Image_ColorRGBA operator- (const Image_ColorRGBA& theA, const Image_ColorRGBA& theB)
515 return Image_ColorSub4 (theA, theB);
518 inline Image_ColorBGRA operator- (const Image_ColorBGRA& theA, const Image_ColorBGRA& theB)
520 return Image_ColorSub4 (theA, theB);
523 inline Image_ColorRGB32 operator- (const Image_ColorRGB32& theA, const Image_ColorRGB32& theB)
525 return Image_ColorSub4 (theA, theB);
528 inline Image_ColorBGR32 operator- (const Image_ColorBGR32& theA, const Image_ColorBGR32& theB)
530 return Image_ColorSub4 (theA, theB);
533 inline Image_ColorRGBAF operator- (const Image_ColorRGBAF& theA, const Image_ColorRGBAF& theB)
535 return Image_ColorSub4 (theA, theB);
538 inline Image_ColorBGRAF operator- (const Image_ColorBGRAF& theA, const Image_ColorBGRAF& theB)
540 return Image_ColorSub4 (theA, theB);
543 #endif // _Image_Color_H__