HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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() { /* 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  template<typename U>
81  {
82  *this = s;
83  }
84 
85  template<typename U>
87  {
88  r = unitConvert<U,T>(s.r);
89  g = unitConvert<U,T>(s.g);
90  b = unitConvert<U,T>(s.b);
91  a = unitConvert<U,T>(s.a);
92  return *this;
93  }
94 
95  T r, g, b, a;
96 };
97 
98 // Specializations that alias on the old type names.
102 
103 
104 
106 public:
107  UT_HSVA() {}
108  UT_HSVA(unsigned short ch, unsigned short cs, char cv, char ca)
109  { h = (short)ch; s = (short)cs;
110  v = (unsigned short)((cv << 8) | cv);
111  a = (unsigned short)((ca << 8) | cv); }
112 
113  UT_HSVA(unsigned short ch, unsigned short cs,
114  unsigned short cv, unsigned short ca)
115  { h = (short)ch; s = (short)cs; v = cv; a = ca; }
116 
117  UT_HSVA(const UT_RGBA &rgba) { *this = rgba; }
118  UT_HSVA(const UT_BIG_RGBA &rgba) { *this = rgba; }
119  UT_HSVA(const UT_HSVA &hsva) { *this = hsva; }
120 
121  UT_HSVA &operator=(const UT_RGBA &rgba);
122  UT_HSVA &operator=(const UT_BIG_RGBA &rgba);
123  UT_HSVA &operator=(const UT_HSVA &hsva);
124  UT_HSVA &operator=(const UT_Color &c);
125 
126  operator UT_RGBA() const;
127  operator UT_BIG_RGBA() const;
128 
129  // Returns previous value:
130  static int enableAlphaDivide(int state);
131  static int getAlphaDivide() { return hsvDoAlphaDivide; }
132 
133  short h, s;
134  unsigned short v, a;
135 
136 private:
137  static char hsvDoAlphaDivide;
138 };
139 
141 public:
142  UT_BUMP() {}
143  UT_BUMP(short u, short v) { du = u; dv = v; }
144 
145  short du, dv;
146 };
147 
149 public:
151  UT_BIG_BUMP(long u, long v) { du = (int)u; dv = (int)v; }
152 
153  int du, dv;
154 };
155 
156 #endif
UT_BIG_BUMP(long u, long v)
Definition: UT_Pixel.h:151
UT_RGBAT()
Definition: UT_Pixel.h:68
UT_HSVA(const UT_BIG_RGBA &rgba)
Definition: UT_Pixel.h:118
UT_RGBAT(ZeroInitType)
Definition: UT_Pixel.h:70
#define SYS_UINT8_MAX
Definition: SYS_Types.h:146
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
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
short s
Definition: UT_Pixel.h:133
#define SYS_UINT16_MAX
Definition: SYS_Types.h:151
#define UT_API
Definition: UT_API.h:12
UT_BUMP()
Definition: UT_Pixel.h:142
UT_HSVA(unsigned short ch, unsigned short cs, char cv, char ca)
Definition: UT_Pixel.h:108
GLfloat f
Definition: glcorearb.h:1925
UT_HSVA(const UT_RGBA &rgba)
Definition: UT_Pixel.h:117
short dv
Definition: UT_Pixel.h:145
double fpreal64
Definition: SYS_Types.h:185
unsigned short v
Definition: UT_Pixel.h:134
UT_RGBAT(const UT_RGBAT< U > &s)
Definition: UT_Pixel.h:80
UT_RGBAT< uint8 > UT_RGBA
Definition: UT_Pixel.h:99
UT_RGBAT< uint16 > UT_BIG_RGBA
Definition: UT_Pixel.h:100
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:143
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
unsigned short uint16
Definition: SYS_Types.h:27
typedef int
Definition: png.h:1175
UT_HSVA(unsigned short ch, unsigned short cs, unsigned short cv, unsigned short ca)
Definition: UT_Pixel.h:113
unsigned char uint8
Definition: SYS_Types.h:25
ZeroInitType
Definition: UT_Pixel.h:66
UT_HSVA()
Definition: UT_Pixel.h:107
UT_RGBAT< fpreal32 > UT_FRGBA
Definition: UT_Pixel.h:101
UT_RGBAT< T > operator=(UT_RGBAT< U > s)
Definition: UT_Pixel.h:86
GLboolean r
Definition: glcorearb.h:1221
static int getAlphaDivide()
Definition: UT_Pixel.h:131
UT_HSVA(const UT_HSVA &hsva)
Definition: UT_Pixel.h:119
float fpreal32
Definition: SYS_Types.h:184