OFFIS DCMTK  Version 3.6.0
util.h
1 //
2 // (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use.
3 //
4 
5 
6 #ifndef CHARLS_UTIL
7 #define CHARLS_UTIL
8 
9 #include "pubtypes.h"
10 
11 #ifndef MAX
12 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
13 #endif
14 
15 #ifndef MIN
16 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
17 #endif
18 
19 #ifndef ABS
20 #define ABS(a) (((a) > 0) ? (a) : -(a))
21 #endif
22 
23 
24 const LONG BASIC_RESET = 64;
25 
26 inline LONG log_2(LONG n)
27 {
28  LONG x = 0;
29  while (n > (LONG(1) << x))
30  {
31  ++x;
32  }
33  return x;
34 
35 }
36 
37 struct Size
38 {
39  Size(LONG width, LONG height) :
40  cx(width),
41  cy(height)
42  {}
43  LONG cx;
44  LONG cy;
45 };
46 
47 
48 
49 inline LONG Sign(LONG n)
50  { return (n >> (LONG_BITCOUNT-1)) | 1;}
51 
52 inline LONG BitWiseSign(LONG i)
53  { return i >> (LONG_BITCOUNT-1); }
54 
55 
56 template<class SAMPLE>
57 struct Triplet
58 {
59  Triplet() :
60  v1(0),
61  v2(0),
62  v3(0)
63  {}
64 
65  Triplet(LONG x1, LONG x2, LONG x3) :
66  v1((SAMPLE)x1),
67  v2((SAMPLE)x2),
68  v3((SAMPLE)x3)
69  {}
70 
71  union
72  {
73  SAMPLE v1;
74  SAMPLE R;
75  };
76  union
77  {
78  SAMPLE v2;
79  SAMPLE G;
80  };
81  union
82  {
83  SAMPLE v3;
84  SAMPLE B;
85  };
86 };
87 
88 inline bool operator==(const Triplet<BYTE>& lhs, const Triplet<BYTE>& rhs)
89  { return lhs.v1 == rhs.v1 && lhs.v2 == rhs.v2 && lhs.v3 == rhs.v3; }
90 
91 inline bool operator!=(const Triplet<BYTE>& lhs, const Triplet<BYTE>& rhs)
92  { return !(lhs == rhs); }
93 
94 
95 template<class sample>
96 struct Quad : public Triplet<sample>
97 {
98  Quad() :
99  v4(0)
100  {}
101 
102  Quad(Triplet<sample> triplet, LONG alpha) : Triplet<sample>(triplet), A((sample)alpha)
103  {}
104 
105  union
106  {
107  sample v4;
108  sample A;
109  };
110 };
111 
112 
113 
114 template<typename T>
116 {
117  inlinehint static T Read(BYTE* pbyte)
118  {
119  T ret = pbyte[0];
120  for (unsigned int i = 1; i < sizeof(T); i++)
121  {
122  ret <<= 8;
123  ret |= pbyte[i];
124  }
125  return ret;
126  }
127 };
128 
129 
131 {
132 public:
133  JlsException(JLS_ERROR error) : _error(error)
134  { }
135 
136  JLS_ERROR _error;
137 };
138 
139 
140 #endif


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2