HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Pixel.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Pixel.h ( UT Library, C++)
7  *
8  * COMMENTS: Contains useful classes for representing pixels in a raster
9  */
10 
11 #ifndef __UT_Pixel__
12 #define __UT_Pixel__
13 
14 #include "UT_API.h"
15 #include <SYS/SYS_Math.h>
16 #include <SYS/SYS_StaticAssert.h>
17 #include <SYS/SYS_Types.h>
18 
19 class UT_Color;
20 
21 namespace
22 {
23  // Inline helpers to do unit-value conversions between different
24  // scalar types.
25 
26  template<typename S, typename D>
27  static inline D unitConvert(S s)
28  {
30  return D(0);
31  }
32 
33  template<>
34  inline uint8 unitConvert(uint16 s) { return uint8(s >> 8); }
35 
36  template<>
37  inline uint16 unitConvert(uint8 s) { return uint16((s << 8) | s); }
38 
39  template<>
40  inline uint8 unitConvert(fpreal32 s)
41  {
42  return (uint8)(SYSrint(SYSclamp(s, 0.f, 1.f) * SYS_UINT8_MAX));
43  }
44 
45  template<>
46  inline fpreal32 unitConvert(uint8 s)
47  {
48  return s / (fpreal32)SYS_UINT8_MAX;
49  }
50 
51  template<>
52  inline uint16 unitConvert(fpreal32 s)
53  {
54  return (uint16)(SYSrint(SYSclamp(s, 0.f, 1.f) * SYS_UINT16_MAX));
55  }
56 
57  template<>
58  inline fpreal32 unitConvert(uint16 s)
59  {
60  return s / (fpreal32)SYS_UINT16_MAX;
61  }
62 
63  template<>
64  inline fpreal32 unitConvert(fpreal64 s) { return fpreal32(s); }
65 
66  template<>
67  inline fpreal64 unitConvert(fpreal32 s) { return fpreal64(s); }
68 }
69 
70 
71 template<typename T>
72 struct UT_RGBAT
73 {
75 
76  UT_RGBAT() = default; // deliberately left uninitialized
77 
78  UT_RGBAT(ZeroInitType) { r = g = b = a = T(0); }
79  explicit UT_RGBAT(T r, T g, T b, T a) : r(r), g(g), b(b), a(a) {}
80 
81  template<typename U>
82  UT_RGBAT(U r, U g, U b, U a)
83  : r(unitConvert<U,T>(r)), g(unitConvert<U,T>(g)),
84  b(unitConvert<U,T>(b)), a(unitConvert<U,T>(a))
85  {}
86 
87  UT_RGBAT(const UT_RGBAT &s) = default;
88 
89  template<typename U>
91  {
92  *this = s;
93  }
94 
95  UT_RGBAT &operator=(const UT_RGBAT &s) = default;
96 
97  template<typename U>
99  {
100  r = unitConvert<U,T>(s.r);
101  g = unitConvert<U,T>(s.g);
102  b = unitConvert<U,T>(s.b);
103  a = unitConvert<U,T>(s.a);
104  return *this;
105  }
106 
107  T r, g, b, a;
108 };
109 
110 // Specializations that alias on the old type names.
114 
115 
116 
118 public:
119  UT_HSVA() {}
120  UT_HSVA(unsigned short ch, unsigned short cs, char cv, char ca)
121  { h = (short)ch; s = (short)cs;
122  v = (unsigned short)((cv << 8) | cv);
123  a = (unsigned short)((ca << 8) | cv); }
124 
125  UT_HSVA(unsigned short ch, unsigned short cs,
126  unsigned short cv, unsigned short ca)
127  { h = (short)ch; s = (short)cs; v = cv; a = ca; }
128 
129  UT_HSVA(const UT_RGBA &rgba) { *this = rgba; }
130  UT_HSVA(const UT_BIG_RGBA &rgba) { *this = rgba; }
131  UT_HSVA(const UT_HSVA &hsva) { *this = hsva; }
132 
133  UT_HSVA &operator=(const UT_RGBA &rgba);
134  UT_HSVA &operator=(const UT_BIG_RGBA &rgba);
135  UT_HSVA &operator=(const UT_HSVA &hsva);
136  UT_HSVA &operator=(const UT_Color &c);
137 
138  operator UT_RGBA() const;
139  operator UT_BIG_RGBA() const;
140 
141  // Returns previous value:
142  static int enableAlphaDivide(int state);
143  static int getAlphaDivide() { return hsvDoAlphaDivide; }
144 
145  short h, s;
146  unsigned short v, a;
147 
148 private:
149  static char hsvDoAlphaDivide;
150 };
151 
153 public:
154  UT_BUMP() {}
155  UT_BUMP(short u, short v) { du = u; dv = v; }
156 
157  short du, dv;
158 };
159 
161 public:
163  UT_BIG_BUMP(long u, long v) { du = (int)u; dv = (int)v; }
164 
165  int du, dv;
166 };
167 
168 #endif
UT_BIG_BUMP(long u, long v)
Definition: UT_Pixel.h:163
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
unsigned short uint16
Definition: SYS_Types.h:38
UT_HSVA(const UT_BIG_RGBA &rgba)
Definition: UT_Pixel.h:130
UT_RGBAT(ZeroInitType)
Definition: UT_Pixel.h:78
#define SYS_UINT8_MAX
Definition: SYS_Types.h:162
UT_RGBAT(U r, U g, U b, U a)
Definition: UT_Pixel.h:82
const GLdouble * v
Definition: glcorearb.h:837
GLboolean GLboolean g
Definition: glcorearb.h:1222
UT_RGBAT & operator=(const UT_RGBAT &s)=default
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
short s
Definition: UT_Pixel.h:145
#define SYS_UINT16_MAX
Definition: SYS_Types.h:167
#define UT_API
Definition: UT_API.h:14
UT_BUMP()
Definition: UT_Pixel.h:154
UT_RGBAT()=default
float fpreal32
Definition: SYS_Types.h:200
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
UT_HSVA(unsigned short ch, unsigned short cs, char cv, char ca)
Definition: UT_Pixel.h:120
GLfloat f
Definition: glcorearb.h:1926
UT_HSVA(const UT_RGBA &rgba)
Definition: UT_Pixel.h:129
short dv
Definition: UT_Pixel.h:157
unsigned short v
Definition: UT_Pixel.h:146
UT_Vector3T< T > SYSclamp(const UT_Vector3T< T > &v, const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
Definition: UT_Vector3.h:1057
UT_RGBAT(const UT_RGBAT< U > &s)
Definition: UT_Pixel.h:90
UT_RGBAT< uint8 > UT_RGBA
Definition: UT_Pixel.h:111
UT_RGBAT< uint16 > UT_BIG_RGBA
Definition: UT_Pixel.h:112
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
fpreal32 SYSrint(fpreal32 val)
Definition: SYS_Floor.h:163
UT_RGBAT(T r, T g, T b, T a)
Definition: UT_Pixel.h:79
UT_BUMP(short u, short v)
Definition: UT_Pixel.h:155
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
UT_HSVA(unsigned short ch, unsigned short cs, unsigned short cv, unsigned short ca)
Definition: UT_Pixel.h:125
ZeroInitType
Definition: UT_Pixel.h:74
UT_HSVA()
Definition: UT_Pixel.h:119
UT_RGBAT< fpreal32 > UT_FRGBA
Definition: UT_Pixel.h:113
UT_RGBAT< T > & operator=(const UT_RGBAT< U > &s)
Definition: UT_Pixel.h:98
#define SYS_UNIMPLEMENTED_TEMPLATE(T)
GLboolean r
Definition: glcorearb.h:1222
static int getAlphaDivide()
Definition: UT_Pixel.h:143
UT_HSVA(const UT_HSVA &hsva)
Definition: UT_Pixel.h:131