FaceGen 3 SDKs Reference
Loading...
Searching...
No Matches
fimRgba.hpp
1//
2// Copyright (c) Singular Inversions Inc. 2001.
3//
4// Created: Authors: Change:
5// 12/5/01 ABeatty Create
6//
7// The arithmetic operators are all designed to be compatible with a
8// pre-alpha-weighted approach.
9//
10
11#ifndef FIM_RGBA_H
12#define FIM_RGBA_H
13
14#include "algs.hpp"
15
16namespace Fg {
17
19typedef enum
20{
21 FIMRGBA_R = 0,
22 FIMRGBA_G,
23 FIMRGBA_B,
24 FIMRGBA_A,
25 FIMRGBA_SIZE
26
27} FimRgbaE;
28
33template<class T>
35{
38 T c[FIMRGBA_SIZE];
39
40 typedef T pixel_index_type;
41
42 FimRgbaT() {}
43 explicit FimRgbaT(T v) {c[0]=c[1]=c[2]=c[3]=v; }
44 FimRgbaT(T red,T green,T blue,T alpha)
45 {
46 c[FIMRGBA_R] = red;
47 c[FIMRGBA_G] = green;
48 c[FIMRGBA_B] = blue;
49 c[FIMRGBA_A] = alpha;
50 }
51 FimRgbaT(const FimRgbaT& rhs) = default;
52 FimRgbaT & operator=(FimRgbaT const &) = default;
53
54 // The conversion constructor. Note that this must be explicit for safety and also
55 // requires the CC to be explicitly defined.
56 template<class U>
57 explicit FimRgbaT(const FimRgbaT<U>& v)
58 {for (uint ii=0; ii<FIMRGBA_SIZE; ++ii) futConvert(v.c[ii],c[ii]); }
59
60 const FimRgbaT operator+(const FimRgbaT& v) const
61 {return FimRgbaT<T>(c[0]+v.c[0],c[1]+v.c[1],c[2]+v.c[2],c[3]+v.c[3]); }
62
63 void operator+=(const FimRgbaT& v)
64 {for (uint ii=0; ii<FIMRGBA_SIZE; ++ii) c[ii] = c[ii] + v.c[ii]; }
65
66 const FimRgbaT operator*(T v) const
67 {return FimRgbaT<T>(c[0]*v,c[1]*v,c[2]*v,c[3]*v); }
68
69 FimRgbaT operator/(T v) const
70 {return FimRgbaT(c[0]/v,c[1]/v,c[2]/v,c[3]/v); }
71
72 void operator*=(T v)
73 {c[0] *= v;c[1] *= v;c[2] *= v;c[3] *= v; }
74};
75
76// **************************************************************************
77// **************************************************************************
78
79typedef FimRgbaT<uchar> FimRgbaUbC;
80typedef FimRgbaT<schar> FimRgbaSbC;
81typedef FimRgbaT<ushort> FimRgbaUsC;
82typedef FimRgbaT<short> FimRgbaSsC;
83typedef FimRgbaT<float> FimRgbaFC;
84
85inline FimRgbaFC
86operator*(FimRgbaUbC pix, float v)
87{
88 return FimRgbaFC(float(pix.c[0])*v,
89 float(pix.c[1])*v,
90 float(pix.c[2])*v,
91 float(pix.c[3])*v);
92}
93inline FimRgbaFC
94operator*(FimRgbaSbC pix, float v)
95{
96 return FimRgbaFC(float(pix.c[0])*v,
97 float(pix.c[1])*v,
98 float(pix.c[2])*v,
99 float(pix.c[3])*v);
100}
101inline FimRgbaFC
102operator*(FimRgbaSsC pix, float v)
103{
104 return FimRgbaFC(float(pix.c[0])*v,
105 float(pix.c[1])*v,
106 float(pix.c[2])*v,
107 float(pix.c[3])*v);
108}
109
110template<class T,class U>
111void
112futConvert(const FimRgbaT<T> &a,FimRgbaT<U> &b)
113{
114 for (uint ii=0; ii<FIMRGBA_SIZE; ++ii)
115 futConvert(a.c[ii],b.c[ii]);
116}
117
118}
119
120#endif
T c[FIMRGBA_SIZE]
Definition fimRgba.hpp:38