Mercurial > hg > orthanc
annotate Core/Images/ImageProcessing.cpp @ 1767:b268756c2cb9
fix msvc 2013 build
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Nov 2015 09:34:18 +0100 |
parents | 96582230ddcb |
children | b1291df2f780 |
rev | line source |
---|---|
853 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
993
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
993
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
853 | 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 |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
78 template <typename TargetType> |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
79 static void ConvertColorToGrayscale(ImageAccessor& target, |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
80 const ImageAccessor& source) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
81 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
82 assert(source.GetFormat() == PixelFormat_RGB24); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
83 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
84 const TargetType minValue = std::numeric_limits<TargetType>::min(); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
85 const TargetType maxValue = std::numeric_limits<TargetType>::max(); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
86 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
87 for (unsigned int y = 0; y < source.GetHeight(); y++) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
88 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
89 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
90 const uint8_t* s = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
91 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
92 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s += 3) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
93 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
94 // Y = 0.2126 R + 0.7152 G + 0.0722 B |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
95 int32_t v = (2126 * static_cast<int32_t>(s[0]) + |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
96 7152 * static_cast<int32_t>(s[1]) + |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
97 0722 * static_cast<int32_t>(s[2])) / 1000; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
98 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
99 if (static_cast<int32_t>(v) < static_cast<int32_t>(minValue)) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
100 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
101 *t = minValue; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
102 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
103 else if (static_cast<int32_t>(v) > static_cast<int32_t>(maxValue)) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
104 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
105 *t = maxValue; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
106 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
107 else |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
108 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
109 *t = static_cast<TargetType>(v); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
110 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
111 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
112 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
113 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
114 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
115 |
863 | 116 template <typename PixelType> |
117 static void SetInternal(ImageAccessor& image, | |
118 int64_t constant) | |
119 { | |
120 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
121 { | |
122 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
123 | |
124 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
125 { | |
126 *p = static_cast<PixelType>(constant); | |
127 } | |
128 } | |
129 } | |
130 | |
131 | |
132 template <typename PixelType> | |
133 static void GetMinMaxValueInternal(PixelType& minValue, | |
134 PixelType& maxValue, | |
135 const ImageAccessor& source) | |
136 { | |
137 // Deal with the special case of empty image | |
138 if (source.GetWidth() == 0 || | |
139 source.GetHeight() == 0) | |
140 { | |
141 minValue = 0; | |
142 maxValue = 0; | |
143 return; | |
144 } | |
145 | |
146 minValue = std::numeric_limits<PixelType>::max(); | |
147 maxValue = std::numeric_limits<PixelType>::min(); | |
148 | |
149 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
150 { | |
151 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); | |
152 | |
153 for (unsigned int x = 0; x < source.GetWidth(); x++, p++) | |
154 { | |
155 if (*p < minValue) | |
156 { | |
157 minValue = *p; | |
158 } | |
159 | |
160 if (*p > maxValue) | |
161 { | |
162 maxValue = *p; | |
163 } | |
164 } | |
165 } | |
166 } | |
167 | |
168 | |
169 | |
170 template <typename PixelType> | |
171 static void AddConstantInternal(ImageAccessor& image, | |
172 int64_t constant) | |
173 { | |
174 if (constant == 0) | |
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 = static_cast<int64_t>(*p) + constant; | |
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 | |
208 template <typename PixelType> | |
209 void MultiplyConstantInternal(ImageAccessor& image, | |
210 float factor) | |
211 { | |
1334 | 212 if (std::abs(factor - 1.0f) <= std::numeric_limits<float>::epsilon()) |
863 | 213 { |
214 return; | |
215 } | |
216 | |
217 const int64_t minValue = std::numeric_limits<PixelType>::min(); | |
218 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
219 | |
220 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
221 { | |
222 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
223 | |
224 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
225 { | |
226 int64_t v = boost::math::llround(static_cast<float>(*p) * factor); | |
227 | |
228 if (v > maxValue) | |
229 { | |
876 | 230 *p = std::numeric_limits<PixelType>::max(); |
863 | 231 } |
232 else if (v < minValue) | |
233 { | |
876 | 234 *p = std::numeric_limits<PixelType>::min(); |
863 | 235 } |
236 else | |
237 { | |
238 *p = static_cast<PixelType>(v); | |
239 } | |
240 } | |
241 } | |
242 } | |
243 | |
244 | |
245 template <typename PixelType> | |
246 void ShiftScaleInternal(ImageAccessor& image, | |
247 float offset, | |
248 float scaling) | |
249 { | |
250 const float minValue = static_cast<float>(std::numeric_limits<PixelType>::min()); | |
251 const float maxValue = static_cast<float>(std::numeric_limits<PixelType>::max()); | |
252 | |
253 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
254 { | |
255 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
256 | |
257 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
258 { | |
259 float v = (static_cast<float>(*p) + offset) * scaling; | |
260 | |
261 if (v > maxValue) | |
262 { | |
263 *p = std::numeric_limits<PixelType>::max(); | |
264 } | |
265 else if (v < minValue) | |
266 { | |
267 *p = std::numeric_limits<PixelType>::min(); | |
268 } | |
269 else | |
270 { | |
271 *p = static_cast<PixelType>(boost::math::iround(v)); | |
272 } | |
273 } | |
274 } | |
275 } | |
276 | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
277 |
853 | 278 void ImageProcessing::Copy(ImageAccessor& target, |
279 const ImageAccessor& source) | |
280 { | |
281 if (target.GetWidth() != source.GetWidth() || | |
282 target.GetHeight() != source.GetHeight()) | |
283 { | |
284 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
285 } | |
286 | |
287 if (target.GetFormat() != source.GetFormat()) | |
288 { | |
289 throw OrthancException(ErrorCode_IncompatibleImageFormat); | |
290 } | |
291 | |
292 unsigned int lineSize = GetBytesPerPixel(source.GetFormat()) * source.GetWidth(); | |
293 | |
294 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize); | |
295 | |
296 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
297 { | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
298 memcpy(target.GetRow(y), source.GetConstRow(y), lineSize); |
853 | 299 } |
300 } | |
301 | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
302 |
853 | 303 void ImageProcessing::Convert(ImageAccessor& target, |
304 const ImageAccessor& source) | |
305 { | |
306 if (target.GetWidth() != source.GetWidth() || | |
307 target.GetHeight() != source.GetHeight()) | |
308 { | |
309 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
310 } | |
311 | |
312 if (source.GetFormat() == target.GetFormat()) | |
313 { | |
314 Copy(target, source); | |
315 return; | |
316 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
317 |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
318 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
319 source.GetFormat() == PixelFormat_Grayscale8) |
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 ConvertInternal<uint16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
322 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
323 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
324 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
325 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
326 source.GetFormat() == PixelFormat_Grayscale8) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
327 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
328 ConvertInternal<int16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
329 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
330 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
331 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
332 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
333 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
334 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
335 ConvertInternal<uint8_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
336 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
337 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
338 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
339 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
340 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
341 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
342 ConvertInternal<int16_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
343 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
344 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
345 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
346 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
347 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
348 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
349 ConvertInternal<uint8_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
350 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
351 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
352 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
353 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
354 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
355 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
356 ConvertInternal<uint16_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
357 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
358 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
359 |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
360 if (target.GetFormat() == PixelFormat_Grayscale8 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
361 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
362 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
363 ConvertColorToGrayscale<uint8_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
364 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
365 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
366 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
367 if (target.GetFormat() == PixelFormat_Grayscale16 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
368 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
369 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
370 ConvertColorToGrayscale<uint16_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
371 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
372 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
373 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
374 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
375 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
376 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
377 ConvertColorToGrayscale<int16_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
378 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
379 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
380 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
381 if (target.GetFormat() == PixelFormat_Grayscale8 && |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
382 source.GetFormat() == PixelFormat_RGBA32) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
383 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
384 for (unsigned int y = 0; y < source.GetHeight(); y++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
385 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
386 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
387 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
388 for (unsigned int x = 0; x < source.GetWidth(); x++, q++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
389 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
390 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[0]) + |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
391 7152 * static_cast<uint32_t>(p[1]) + |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
392 0722 * static_cast<uint32_t>(p[2])) / 10000); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
393 p += 4; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
394 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
395 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
396 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
397 return; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
398 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
399 |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
400 if (target.GetFormat() == PixelFormat_RGB24 && |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
401 source.GetFormat() == PixelFormat_RGBA32) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
402 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
403 for (unsigned int y = 0; y < source.GetHeight(); y++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
404 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
405 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
406 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
407 for (unsigned int x = 0; x < source.GetWidth(); x++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
408 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
409 q[0] = p[0]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
410 q[1] = p[1]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
411 q[2] = p[2]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
412 p += 4; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
413 q += 3; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
414 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
415 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
416 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
417 return; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
418 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
419 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
420 if (target.GetFormat() == PixelFormat_RGBA32 && |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
421 source.GetFormat() == PixelFormat_RGB24) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
422 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
423 for (unsigned int y = 0; y < source.GetHeight(); y++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
424 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
425 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
426 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
427 for (unsigned int x = 0; x < source.GetWidth(); x++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
428 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
429 q[0] = p[0]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
430 q[1] = p[1]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
431 q[2] = p[2]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
432 q[3] = 255; // Set the alpha channel to full opacity |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
433 p += 3; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
434 q += 4; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
435 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
436 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
437 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
438 return; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
439 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
440 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
441 throw OrthancException(ErrorCode_NotImplemented); |
853 | 442 } |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
443 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
444 |
863 | 445 |
446 void ImageProcessing::Set(ImageAccessor& image, | |
447 int64_t value) | |
448 { | |
449 switch (image.GetFormat()) | |
450 { | |
451 case PixelFormat_Grayscale8: | |
452 SetInternal<uint8_t>(image, value); | |
453 return; | |
454 | |
455 case PixelFormat_Grayscale16: | |
456 SetInternal<uint16_t>(image, value); | |
457 return; | |
458 | |
459 case PixelFormat_SignedGrayscale16: | |
460 SetInternal<int16_t>(image, value); | |
461 return; | |
462 | |
463 default: | |
464 throw OrthancException(ErrorCode_NotImplemented); | |
465 } | |
466 } | |
467 | |
468 | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
469 void ImageProcessing::ShiftRight(ImageAccessor& image, |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
470 unsigned int shift) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
471 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
472 if (image.GetWidth() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
473 image.GetHeight() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
474 shift == 0) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
475 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
476 // Nothing to do |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
477 return; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
478 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
479 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
480 throw OrthancException(ErrorCode_NotImplemented); |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
481 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
482 |
863 | 483 |
484 void ImageProcessing::GetMinMaxValue(int64_t& minValue, | |
485 int64_t& maxValue, | |
486 const ImageAccessor& image) | |
487 { | |
488 switch (image.GetFormat()) | |
489 { | |
490 case PixelFormat_Grayscale8: | |
491 { | |
492 uint8_t a, b; | |
493 GetMinMaxValueInternal<uint8_t>(a, b, image); | |
494 minValue = a; | |
495 maxValue = b; | |
496 break; | |
497 } | |
498 | |
499 case PixelFormat_Grayscale16: | |
500 { | |
501 uint16_t a, b; | |
502 GetMinMaxValueInternal<uint16_t>(a, b, image); | |
503 minValue = a; | |
504 maxValue = b; | |
505 break; | |
506 } | |
507 | |
508 case PixelFormat_SignedGrayscale16: | |
509 { | |
510 int16_t a, b; | |
511 GetMinMaxValueInternal<int16_t>(a, b, image); | |
512 minValue = a; | |
513 maxValue = b; | |
514 break; | |
515 } | |
516 | |
517 default: | |
518 throw OrthancException(ErrorCode_NotImplemented); | |
519 } | |
520 } | |
521 | |
522 | |
523 | |
524 void ImageProcessing::AddConstant(ImageAccessor& image, | |
525 int64_t value) | |
526 { | |
527 switch (image.GetFormat()) | |
528 { | |
529 case PixelFormat_Grayscale8: | |
530 AddConstantInternal<uint8_t>(image, value); | |
531 return; | |
532 | |
533 case PixelFormat_Grayscale16: | |
534 AddConstantInternal<uint16_t>(image, value); | |
535 return; | |
536 | |
537 case PixelFormat_SignedGrayscale16: | |
538 AddConstantInternal<int16_t>(image, value); | |
539 return; | |
540 | |
541 default: | |
542 throw OrthancException(ErrorCode_NotImplemented); | |
543 } | |
544 } | |
545 | |
546 | |
547 void ImageProcessing::MultiplyConstant(ImageAccessor& image, | |
548 float factor) | |
549 { | |
550 switch (image.GetFormat()) | |
551 { | |
552 case PixelFormat_Grayscale8: | |
553 MultiplyConstantInternal<uint8_t>(image, factor); | |
554 return; | |
555 | |
556 case PixelFormat_Grayscale16: | |
557 MultiplyConstantInternal<uint16_t>(image, factor); | |
558 return; | |
559 | |
560 case PixelFormat_SignedGrayscale16: | |
561 MultiplyConstantInternal<int16_t>(image, factor); | |
562 return; | |
563 | |
564 default: | |
565 throw OrthancException(ErrorCode_NotImplemented); | |
566 } | |
567 } | |
568 | |
569 | |
570 void ImageProcessing::ShiftScale(ImageAccessor& image, | |
571 float offset, | |
572 float scaling) | |
573 { | |
574 switch (image.GetFormat()) | |
575 { | |
576 case PixelFormat_Grayscale8: | |
577 ShiftScaleInternal<uint8_t>(image, offset, scaling); | |
578 return; | |
579 | |
580 case PixelFormat_Grayscale16: | |
581 ShiftScaleInternal<uint16_t>(image, offset, scaling); | |
582 return; | |
583 | |
584 case PixelFormat_SignedGrayscale16: | |
585 ShiftScaleInternal<int16_t>(image, offset, scaling); | |
586 return; | |
587 | |
588 default: | |
589 throw OrthancException(ErrorCode_NotImplemented); | |
590 } | |
591 } | |
853 | 592 } |