Mercurial > hg > orthanc
annotate Core/ImageFormats/ImageProcessing.cpp @ 893:f57802f8b4dc plugins
plugins for windows
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Jun 2014 16:14:56 +0200 |
parents | e21d1a5f5934 |
children | 501880d76474 |
rev | line source |
---|---|
853 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, | |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "../PrecompiledHeaders.h" | |
34 #include "ImageProcessing.h" | |
35 | |
36 #include "../OrthancException.h" | |
37 | |
863 | 38 #include <boost/math/special_functions/round.hpp> |
39 | |
853 | 40 #include <cassert> |
41 #include <string.h> | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
42 #include <limits> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
43 #include <stdint.h> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
44 |
853 | 45 namespace Orthanc |
46 { | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
47 template <typename TargetType, typename SourceType> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
48 static void ConvertInternal(ImageAccessor& target, |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
49 const ImageAccessor& source) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
50 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
51 const TargetType minValue = std::numeric_limits<TargetType>::min(); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
52 const TargetType maxValue = std::numeric_limits<TargetType>::max(); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
53 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
54 for (unsigned int y = 0; y < source.GetHeight(); y++) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
55 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
56 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
57 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
58 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
59 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
60 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
61 if (static_cast<int32_t>(*s) < static_cast<int32_t>(minValue)) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
62 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
63 *t = minValue; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
64 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
65 else if (static_cast<int32_t>(*s) > static_cast<int32_t>(maxValue)) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
66 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
67 *t = maxValue; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
68 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
69 else |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
70 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
71 *t = static_cast<TargetType>(*s); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
72 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
73 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
74 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
75 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
76 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
77 |
863 | 78 template <typename PixelType> |
79 static void SetInternal(ImageAccessor& image, | |
80 int64_t constant) | |
81 { | |
82 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
83 { | |
84 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
85 | |
86 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
87 { | |
88 *p = static_cast<PixelType>(constant); | |
89 } | |
90 } | |
91 } | |
92 | |
93 | |
94 template <typename PixelType> | |
95 static void GetMinMaxValueInternal(PixelType& minValue, | |
96 PixelType& maxValue, | |
97 const ImageAccessor& source) | |
98 { | |
99 // Deal with the special case of empty image | |
100 if (source.GetWidth() == 0 || | |
101 source.GetHeight() == 0) | |
102 { | |
103 minValue = 0; | |
104 maxValue = 0; | |
105 return; | |
106 } | |
107 | |
108 minValue = std::numeric_limits<PixelType>::max(); | |
109 maxValue = std::numeric_limits<PixelType>::min(); | |
110 | |
111 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
112 { | |
113 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); | |
114 | |
115 for (unsigned int x = 0; x < source.GetWidth(); x++, p++) | |
116 { | |
117 if (*p < minValue) | |
118 { | |
119 minValue = *p; | |
120 } | |
121 | |
122 if (*p > maxValue) | |
123 { | |
124 maxValue = *p; | |
125 } | |
126 } | |
127 } | |
128 } | |
129 | |
130 | |
131 | |
132 template <typename PixelType> | |
133 static void AddConstantInternal(ImageAccessor& image, | |
134 int64_t constant) | |
135 { | |
136 if (constant == 0) | |
137 { | |
138 return; | |
139 } | |
140 | |
141 const int64_t minValue = std::numeric_limits<PixelType>::min(); | |
142 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
143 | |
144 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
145 { | |
146 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
147 | |
148 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
149 { | |
150 int64_t v = static_cast<int64_t>(*p) + constant; | |
151 | |
152 if (v > maxValue) | |
153 { | |
876 | 154 *p = std::numeric_limits<PixelType>::max(); |
863 | 155 } |
156 else if (v < minValue) | |
157 { | |
876 | 158 *p = std::numeric_limits<PixelType>::min(); |
863 | 159 } |
160 else | |
161 { | |
162 *p = static_cast<PixelType>(v); | |
163 } | |
164 } | |
165 } | |
166 } | |
167 | |
168 | |
169 | |
170 template <typename PixelType> | |
171 void MultiplyConstantInternal(ImageAccessor& image, | |
172 float factor) | |
173 { | |
174 if (abs(factor - 1.0f) <= std::numeric_limits<float>::epsilon()) | |
175 { | |
176 return; | |
177 } | |
178 | |
179 const int64_t minValue = std::numeric_limits<PixelType>::min(); | |
180 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
181 | |
182 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
183 { | |
184 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
185 | |
186 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
187 { | |
188 int64_t v = boost::math::llround(static_cast<float>(*p) * factor); | |
189 | |
190 if (v > maxValue) | |
191 { | |
876 | 192 *p = std::numeric_limits<PixelType>::max(); |
863 | 193 } |
194 else if (v < minValue) | |
195 { | |
876 | 196 *p = std::numeric_limits<PixelType>::min(); |
863 | 197 } |
198 else | |
199 { | |
200 *p = static_cast<PixelType>(v); | |
201 } | |
202 } | |
203 } | |
204 } | |
205 | |
206 | |
207 template <typename PixelType> | |
208 void ShiftScaleInternal(ImageAccessor& image, | |
209 float offset, | |
210 float scaling) | |
211 { | |
212 const float minValue = static_cast<float>(std::numeric_limits<PixelType>::min()); | |
213 const float maxValue = static_cast<float>(std::numeric_limits<PixelType>::max()); | |
214 | |
215 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
216 { | |
217 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
218 | |
219 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
220 { | |
221 float v = (static_cast<float>(*p) + offset) * scaling; | |
222 | |
223 if (v > maxValue) | |
224 { | |
225 *p = std::numeric_limits<PixelType>::max(); | |
226 } | |
227 else if (v < minValue) | |
228 { | |
229 *p = std::numeric_limits<PixelType>::min(); | |
230 } | |
231 else | |
232 { | |
233 *p = static_cast<PixelType>(boost::math::iround(v)); | |
234 } | |
235 } | |
236 } | |
237 } | |
238 | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
239 |
853 | 240 void ImageProcessing::Copy(ImageAccessor& target, |
241 const ImageAccessor& source) | |
242 { | |
243 if (target.GetWidth() != source.GetWidth() || | |
244 target.GetHeight() != source.GetHeight()) | |
245 { | |
246 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
247 } | |
248 | |
249 if (target.GetFormat() != source.GetFormat()) | |
250 { | |
251 throw OrthancException(ErrorCode_IncompatibleImageFormat); | |
252 } | |
253 | |
254 unsigned int lineSize = GetBytesPerPixel(source.GetFormat()) * source.GetWidth(); | |
255 | |
256 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize); | |
257 | |
258 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
259 { | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
260 memcpy(target.GetRow(y), source.GetConstRow(y), lineSize); |
853 | 261 } |
262 } | |
263 | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
264 |
853 | 265 void ImageProcessing::Convert(ImageAccessor& target, |
266 const ImageAccessor& source) | |
267 { | |
268 if (target.GetWidth() != source.GetWidth() || | |
269 target.GetHeight() != source.GetHeight()) | |
270 { | |
271 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
272 } | |
273 | |
274 if (source.GetFormat() == target.GetFormat()) | |
275 { | |
276 Copy(target, source); | |
277 return; | |
278 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
279 |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
280 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
281 source.GetFormat() == PixelFormat_Grayscale8) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
282 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
283 ConvertInternal<uint16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
284 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
285 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
286 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
287 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
288 source.GetFormat() == PixelFormat_Grayscale8) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
289 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
290 ConvertInternal<int16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
291 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
292 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
293 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
294 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
295 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
296 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
297 ConvertInternal<uint8_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
298 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
299 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
300 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
301 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
302 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
303 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
304 ConvertInternal<int16_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
305 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
306 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
307 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
308 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
309 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
310 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
311 ConvertInternal<uint8_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
312 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
313 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
314 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
315 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
316 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
317 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
318 ConvertInternal<uint16_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
319 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
320 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
321 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
322 throw OrthancException(ErrorCode_NotImplemented); |
853 | 323 } |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
324 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
325 |
863 | 326 |
327 void ImageProcessing::Set(ImageAccessor& image, | |
328 int64_t value) | |
329 { | |
330 switch (image.GetFormat()) | |
331 { | |
332 case PixelFormat_Grayscale8: | |
333 SetInternal<uint8_t>(image, value); | |
334 return; | |
335 | |
336 case PixelFormat_Grayscale16: | |
337 SetInternal<uint16_t>(image, value); | |
338 return; | |
339 | |
340 case PixelFormat_SignedGrayscale16: | |
341 SetInternal<int16_t>(image, value); | |
342 return; | |
343 | |
344 default: | |
345 throw OrthancException(ErrorCode_NotImplemented); | |
346 } | |
347 } | |
348 | |
349 | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
350 void ImageProcessing::ShiftRight(ImageAccessor& image, |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
351 unsigned int shift) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
352 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
353 if (image.GetWidth() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
354 image.GetHeight() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
355 shift == 0) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
356 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
357 // Nothing to do |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
358 return; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
359 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
360 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
361 throw OrthancException(ErrorCode_NotImplemented); |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
362 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
363 |
863 | 364 |
365 void ImageProcessing::GetMinMaxValue(int64_t& minValue, | |
366 int64_t& maxValue, | |
367 const ImageAccessor& image) | |
368 { | |
369 switch (image.GetFormat()) | |
370 { | |
371 case PixelFormat_Grayscale8: | |
372 { | |
373 uint8_t a, b; | |
374 GetMinMaxValueInternal<uint8_t>(a, b, image); | |
375 minValue = a; | |
376 maxValue = b; | |
377 break; | |
378 } | |
379 | |
380 case PixelFormat_Grayscale16: | |
381 { | |
382 uint16_t a, b; | |
383 GetMinMaxValueInternal<uint16_t>(a, b, image); | |
384 minValue = a; | |
385 maxValue = b; | |
386 break; | |
387 } | |
388 | |
389 case PixelFormat_SignedGrayscale16: | |
390 { | |
391 int16_t a, b; | |
392 GetMinMaxValueInternal<int16_t>(a, b, image); | |
393 minValue = a; | |
394 maxValue = b; | |
395 break; | |
396 } | |
397 | |
398 default: | |
399 throw OrthancException(ErrorCode_NotImplemented); | |
400 } | |
401 } | |
402 | |
403 | |
404 | |
405 void ImageProcessing::AddConstant(ImageAccessor& image, | |
406 int64_t value) | |
407 { | |
408 switch (image.GetFormat()) | |
409 { | |
410 case PixelFormat_Grayscale8: | |
411 AddConstantInternal<uint8_t>(image, value); | |
412 return; | |
413 | |
414 case PixelFormat_Grayscale16: | |
415 AddConstantInternal<uint16_t>(image, value); | |
416 return; | |
417 | |
418 case PixelFormat_SignedGrayscale16: | |
419 AddConstantInternal<int16_t>(image, value); | |
420 return; | |
421 | |
422 default: | |
423 throw OrthancException(ErrorCode_NotImplemented); | |
424 } | |
425 } | |
426 | |
427 | |
428 void ImageProcessing::MultiplyConstant(ImageAccessor& image, | |
429 float factor) | |
430 { | |
431 switch (image.GetFormat()) | |
432 { | |
433 case PixelFormat_Grayscale8: | |
434 MultiplyConstantInternal<uint8_t>(image, factor); | |
435 return; | |
436 | |
437 case PixelFormat_Grayscale16: | |
438 MultiplyConstantInternal<uint16_t>(image, factor); | |
439 return; | |
440 | |
441 case PixelFormat_SignedGrayscale16: | |
442 MultiplyConstantInternal<int16_t>(image, factor); | |
443 return; | |
444 | |
445 default: | |
446 throw OrthancException(ErrorCode_NotImplemented); | |
447 } | |
448 } | |
449 | |
450 | |
451 void ImageProcessing::ShiftScale(ImageAccessor& image, | |
452 float offset, | |
453 float scaling) | |
454 { | |
455 switch (image.GetFormat()) | |
456 { | |
457 case PixelFormat_Grayscale8: | |
458 ShiftScaleInternal<uint8_t>(image, offset, scaling); | |
459 return; | |
460 | |
461 case PixelFormat_Grayscale16: | |
462 ShiftScaleInternal<uint16_t>(image, offset, scaling); | |
463 return; | |
464 | |
465 case PixelFormat_SignedGrayscale16: | |
466 ShiftScaleInternal<int16_t>(image, offset, scaling); | |
467 return; | |
468 | |
469 default: | |
470 throw OrthancException(ErrorCode_NotImplemented); | |
471 } | |
472 } | |
853 | 473 } |