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_Types.h>
16 #include <SYS/SYS_Math.h>
17 
18 class UT_Color;
19 
20 namespace
21 {
22  // Inline helpers to do unit-value conversions between different
23  // scalar types.
24 
25  template<typename S, typename D>
26  static inline D unitConvert(S s); // Intentionally left blank
27 
28  template<>
29  inline uint8 unitConvert(uint16 s) { return uint8(s >> 8); }
30 
31  template<>
32  inline uint16 unitConvert(uint8 s) { return uint16((s << 8) | s); }
33 
34  template<>
35  inline uint8 unitConvert(fpreal32 s)
36  {
37  return (uint8)(SYSrint(SYSclamp(s, 0.f, 1.f) * SYS_UINT8_MAX));
38  }
39 
40  template<>
41  inline fpreal32 unitConvert(uint8 s)
42  {
43  return s / (fpreal32)SYS_UINT8_MAX;
44  }
45 
46  template<>
47  inline uint16 unitConvert(fpreal32 s)
48  {
49  return (uint16)(SYSrint(SYSclamp(s, 0.f, 1.f) * SYS_UINT16_MAX));
50  }
51 
52  template<>
53  inline fpreal32 unitConvert(uint16 s)
54  {
55  return s / (fpreal32)SYS_UINT16_MAX;
56  }
57 
58  template<>
59  inline fpreal32 unitConvert(fpreal64 s) { return fpreal32(s); }
60 }
61 
62 
63 template<typename T>
64 struct UT_RGBAT
65 {
67 
68  UT_RGBAT() = default; // deliberately left uninitialized
69 
70  UT_RGBAT(ZeroInitType) { r = g = b = a = T(0); }
71  explicit UT_RGBAT(T r, T g, T b, T a) : r(r), g(g), b(b), a(a) {}
72 
73  template<typename U>
74  UT_RGBAT(U r, U g, U b, U a)
75  : r(unitConvert<U,T>(r)), g(unitConvert<U,T>(g)),
76  b(unitConvert<U,T>(b)), a(unitConvert<U,T>(a))
77  {}
78 
79  UT_RGBAT(const UT_RGBAT &s) = default;
80 
81  template<typename U>
83  {
84  *this = s;
85  }
86 
87  UT_RGBAT &operator=(const UT_RGBAT &s) = default;
88 
89  template<typename U>
91  {
92  r = unitConvert<U,T>(s.r);
93  g = unitConvert<U,T>(s.g);
94  b = unitConvert<U,T>(s.b);
95  a = unitConvert<U,T>(s.a);
96  return *this;
97  }
98 
99  T r, g, b, a;
100 };
101 
102 // Specializations that alias on the old type names.
106 
107 
108 
110 public:
111  UT_HSVA() {}
112  UT_HSVA(unsigned short ch, unsigned short cs, char cv, char ca)
113  { h = (short)ch; s = (short)cs;
114  v = (unsigned short)((cv << 8) | cv);
115  a = (unsigned short)((ca << 8) | cv); }
116 
117  UT_HSVA(unsigned short ch, unsigned short cs,
118  unsigned short cv, unsigned short ca)
119  { h = (short)ch; s = (short)cs; v = cv; a = ca; }
120 
121  UT_HSVA(const UT_RGBA &rgba) { *this = rgba; }
122  UT_HSVA(const UT_BIG_RGBA &rgba) { *this = rgba; }
123  UT_HSVA(const UT_HSVA &hsva) { *this = hsva; }
124 
125  UT_HSVA &operator=(const UT_RGBA &rgba);
126  UT_HSVA &operator=(const UT_BIG_RGBA &rgba);
127  UT_HSVA &operator=(const UT_HSVA &hsva);
128  UT_HSVA &operator=(const UT_Color &c);
129 
130  operator UT_RGBA() const;
131  operator UT_BIG_RGBA() const;
132 
133  // Returns previous value:
134  static int enableAlphaDivide(int state);
135  static int getAlphaDivide() { return hsvDoAlphaDivide; }
136 
137  short h, s;
138  unsigned short v, a;
139 
140 private:
141  static char hsvDoAlphaDivide;
142 };
143 
145 public:
146  UT_BUMP() {}
147  UT_BUMP(short u, short v) { du = u; dv = v; }
148 
149  short du, dv;
150 };
151 
153 public:
155  UT_BIG_BUMP(long u, long v) { du = (int)u; dv = (int)v; }
156 
157  int du, dv;
158 };
159 
160 #endif
UT_BIG_BUMP(long u, long v)
Definition: UT_Pixel.h:155
UT_HSVA(const UT_BIG_RGBA &rgba)
Definition: UT_Pixel.h:122
UT_RGBAT(ZeroInitType)
Definition: UT_Pixel.h:70
#define SYS_UINT8_MAX
Definition: SYS_Types.h:153
UT_RGBAT(U r, U g, U b, U a)
Definition: UT_Pixel.h:74
const GLdouble * v
Definition: glcorearb.h:836
GLboolean GLboolean g
Definition: glcorearb.h:1221
UT_RGBAT & operator=(const UT_RGBAT &s)=default
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
short s
Definition: UT_Pixel.h:137
#define SYS_UINT16_MAX
Definition: SYS_Types.h:158
#define UT_API
Definition: UT_API.h:13
UT_BUMP()
Definition: UT_Pixel.h:146
UT_RGBAT()=default
UT_HSVA(unsigned short ch, unsigned short cs, char cv, char ca)
Definition: UT_Pixel.h:112
GLfloat f
Definition: glcorearb.h:1925
UT_HSVA(const UT_RGBA &rgba)
Definition: UT_Pixel.h:121
short dv
Definition: UT_Pixel.h:149
double fpreal64
Definition: SYS_Types.h:192
unsigned short v
Definition: UT_Pixel.h:138
UT_RGBAT(const UT_RGBAT< U > &s)
Definition: UT_Pixel.h:82
UT_RGBAT< uint8 > UT_RGBA
Definition: UT_Pixel.h:103
UT_RGBAT< uint16 > UT_BIG_RGBA
Definition: UT_Pixel.h:104
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
fpreal32 SYSrint(fpreal32 val)
Definition: SYS_Floor.h:163
UT_RGBAT(T r, T g, T b, T a)
Definition: UT_Pixel.h:71
UT_BUMP(short u, short v)
Definition: UT_Pixel.h:147
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
unsigned short uint16
Definition: SYS_Types.h:34
typedef int
Definition: png.h:1175
UT_HSVA(unsigned short ch, unsigned short cs, unsigned short cv, unsigned short ca)
Definition: UT_Pixel.h:117
unsigned char uint8
Definition: SYS_Types.h:32
ZeroInitType
Definition: UT_Pixel.h:66
UT_HSVA()
Definition: UT_Pixel.h:111
UT_RGBAT< fpreal32 > UT_FRGBA
Definition: UT_Pixel.h:105
UT_RGBAT< T > & operator=(const UT_RGBAT< U > &s)
Definition: UT_Pixel.h:90
GLboolean r
Definition: glcorearb.h:1221
static int getAlphaDivide()
Definition: UT_Pixel.h:135
UT_HSVA(const UT_HSVA &hsva)
Definition: UT_Pixel.h:123
float fpreal32
Definition: SYS_Types.h:191