Mercurial > hg > orthanc
comparison Core/Images/PixelTraits.h @ 2487:be1dbb1dcdd6
PixelTraits and ImageTraits
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 13 Mar 2018 16:29:20 +0100 |
parents | |
children | e91bab2d8c75 |
comparison
equal
deleted
inserted
replaced
2486:ad8f30fc28d1 | 2487:be1dbb1dcdd6 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #pragma once | |
35 | |
36 #include "../Enumerations.h" | |
37 | |
38 | |
39 namespace Orthanc | |
40 { | |
41 template <PixelFormat Format> | |
42 struct PixelTraits; | |
43 | |
44 | |
45 template <> | |
46 struct PixelTraits<PixelFormat_Grayscale8> | |
47 { | |
48 typedef uint8_t PixelType; | |
49 | |
50 ORTHANC_FORCE_INLINE | |
51 static PixelFormat GetPixelFormat() | |
52 { | |
53 return PixelFormat_Grayscale8; | |
54 } | |
55 | |
56 ORTHANC_FORCE_INLINE | |
57 static void SetZero(PixelType& target) | |
58 { | |
59 target = 0; | |
60 } | |
61 | |
62 ORTHANC_FORCE_INLINE | |
63 static void Copy(PixelType& target, | |
64 const PixelType& source) | |
65 { | |
66 target = source; | |
67 } | |
68 | |
69 ORTHANC_FORCE_INLINE | |
70 static float PixelToFloat(const PixelType& source) | |
71 { | |
72 return static_cast<float>(source); | |
73 } | |
74 | |
75 ORTHANC_FORCE_INLINE | |
76 static void FloatToPixel(PixelType& target, | |
77 float value) | |
78 { | |
79 target = static_cast<uint8_t>(value); | |
80 } | |
81 | |
82 ORTHANC_FORCE_INLINE | |
83 static bool IsEqual(const PixelType& a, | |
84 const PixelType& b) | |
85 { | |
86 return a == b; | |
87 } | |
88 }; | |
89 | |
90 | |
91 template <> | |
92 struct PixelTraits<PixelFormat_Grayscale16> | |
93 { | |
94 typedef uint16_t PixelType; | |
95 | |
96 ORTHANC_FORCE_INLINE | |
97 static PixelFormat GetPixelFormat() | |
98 { | |
99 return PixelFormat_Grayscale16; | |
100 } | |
101 | |
102 ORTHANC_FORCE_INLINE | |
103 static void SetZero(PixelType& target) | |
104 { | |
105 target = 0; | |
106 } | |
107 | |
108 ORTHANC_FORCE_INLINE | |
109 static void Copy(PixelType& target, | |
110 const PixelType& source) | |
111 { | |
112 target = source; | |
113 } | |
114 | |
115 ORTHANC_FORCE_INLINE | |
116 static float PixelToFloat(const PixelType& source) | |
117 { | |
118 return static_cast<float>(source); | |
119 } | |
120 | |
121 ORTHANC_FORCE_INLINE | |
122 static void FloatToPixel(PixelType& target, | |
123 float value) | |
124 { | |
125 target = static_cast<uint16_t>(value); | |
126 } | |
127 | |
128 ORTHANC_FORCE_INLINE | |
129 static bool IsEqual(const PixelType& a, | |
130 const PixelType& b) | |
131 { | |
132 return a == b; | |
133 } | |
134 }; | |
135 | |
136 | |
137 template <> | |
138 struct PixelTraits<PixelFormat_SignedGrayscale16> | |
139 { | |
140 typedef int16_t PixelType; | |
141 | |
142 ORTHANC_FORCE_INLINE | |
143 static PixelFormat GetPixelFormat() | |
144 { | |
145 return PixelFormat_SignedGrayscale16; | |
146 } | |
147 | |
148 ORTHANC_FORCE_INLINE | |
149 static void SetZero(PixelType& target) | |
150 { | |
151 target = 0; | |
152 } | |
153 | |
154 ORTHANC_FORCE_INLINE | |
155 static void Copy(PixelType& target, | |
156 const PixelType& source) | |
157 { | |
158 target = source; | |
159 } | |
160 | |
161 ORTHANC_FORCE_INLINE | |
162 static float PixelToFloat(const PixelType& source) | |
163 { | |
164 return static_cast<float>(source); | |
165 } | |
166 | |
167 ORTHANC_FORCE_INLINE | |
168 static void FloatToPixel(PixelType& target, | |
169 float value) | |
170 { | |
171 target = static_cast<int16_t>(value); | |
172 } | |
173 | |
174 ORTHANC_FORCE_INLINE | |
175 static bool IsEqual(const PixelType& a, | |
176 const PixelType& b) | |
177 { | |
178 return a == b; | |
179 } | |
180 }; | |
181 | |
182 | |
183 template <> | |
184 struct PixelTraits<PixelFormat_RGB24> | |
185 { | |
186 struct PixelType | |
187 { | |
188 uint8_t red_; | |
189 uint8_t green_; | |
190 uint8_t blue_; | |
191 }; | |
192 | |
193 ORTHANC_FORCE_INLINE | |
194 static PixelFormat GetPixelFormat() | |
195 { | |
196 return PixelFormat_RGB24; | |
197 } | |
198 | |
199 ORTHANC_FORCE_INLINE | |
200 static void SetZero(PixelType& target) | |
201 { | |
202 target.red_ = 0; | |
203 target.green_ = 0; | |
204 target.blue_ = 0; | |
205 } | |
206 | |
207 ORTHANC_FORCE_INLINE | |
208 static void Copy(PixelType& target, | |
209 const PixelType& source) | |
210 { | |
211 target.red_ = source.red_; | |
212 target.green_ = source.green_; | |
213 target.blue_ = source.blue_; | |
214 } | |
215 | |
216 ORTHANC_FORCE_INLINE | |
217 static bool IsEqual(const PixelType& a, | |
218 const PixelType& b) | |
219 { | |
220 return (a.red_ == b.red_ && | |
221 a.green_ == b.green_ && | |
222 a.blue_ == b.blue_); | |
223 } | |
224 }; | |
225 | |
226 | |
227 template <> | |
228 struct PixelTraits<PixelFormat_BGRA32> | |
229 { | |
230 struct PixelType | |
231 { | |
232 uint8_t blue_; | |
233 uint8_t green_; | |
234 uint8_t red_; | |
235 uint8_t alpha_; | |
236 }; | |
237 | |
238 ORTHANC_FORCE_INLINE | |
239 static PixelFormat GetPixelFormat() | |
240 { | |
241 return PixelFormat_BGRA32; | |
242 } | |
243 | |
244 ORTHANC_FORCE_INLINE | |
245 static void SetZero(PixelType& target) | |
246 { | |
247 target.blue_ = 0; | |
248 target.green_ = 0; | |
249 target.red_ = 0; | |
250 target.alpha_ = 0; | |
251 } | |
252 | |
253 ORTHANC_FORCE_INLINE | |
254 static void Copy(PixelType& target, | |
255 const PixelType& source) | |
256 { | |
257 target.blue_ = source.blue_; | |
258 target.green_ = source.green_; | |
259 target.red_ = source.red_; | |
260 target.alpha_ = source.alpha_; | |
261 } | |
262 | |
263 ORTHANC_FORCE_INLINE | |
264 static bool IsEqual(const PixelType& a, | |
265 const PixelType& b) | |
266 { | |
267 return (a.blue_ == b.blue_ && | |
268 a.green_ == b.green_ && | |
269 a.red_ == b.red_ && | |
270 a.alpha_ == b.alpha_); | |
271 } | |
272 }; | |
273 } |