Mercurial > hg > orthanc
annotate Core/Images/ImageProcessing.cpp @ 2764:60f09c16c1e5 Orthanc-1.2.0
close old branch
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 09:42:14 +0200 |
parents | 1554fc153a93 |
children | a3a65de1840f |
rev | line source |
---|---|
853 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
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 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
78 template <typename SourceType> |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
79 static void ConvertGrayscaleToFloat(ImageAccessor& target, |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
80 const ImageAccessor& source) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
81 { |
1994
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
82 assert(sizeof(float) == 4); |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
83 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
84 for (unsigned int y = 0; y < source.GetHeight(); y++) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
85 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
86 float* t = reinterpret_cast<float*>(target.GetRow(y)); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
87 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
88 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
89 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
90 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
91 *t = static_cast<float>(*s); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
92 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
93 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
94 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
95 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
96 |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
97 template <typename TargetType> |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
98 static void ConvertColorToGrayscale(ImageAccessor& target, |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
99 const ImageAccessor& source) |
993
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 assert(source.GetFormat() == PixelFormat_RGB24); |
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 const TargetType minValue = std::numeric_limits<TargetType>::min(); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
104 const TargetType maxValue = std::numeric_limits<TargetType>::max(); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
105 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
106 for (unsigned int y = 0; y < source.GetHeight(); y++) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
107 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
108 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
109 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
|
110 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
111 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
|
112 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
113 // 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
|
114 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
|
115 7152 * static_cast<int32_t>(s[1]) + |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
116 0722 * static_cast<int32_t>(s[2])) / 1000; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
117 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
118 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
|
119 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
120 *t = minValue; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
121 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
122 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
|
123 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
124 *t = maxValue; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
125 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
126 else |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
127 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
128 *t = static_cast<TargetType>(v); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
129 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
130 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
131 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
132 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
133 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
134 |
863 | 135 template <typename PixelType> |
136 static void SetInternal(ImageAccessor& image, | |
137 int64_t constant) | |
138 { | |
139 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
140 { | |
141 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
142 | |
143 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
144 { | |
145 *p = static_cast<PixelType>(constant); | |
146 } | |
147 } | |
148 } | |
149 | |
150 | |
151 template <typename PixelType> | |
152 static void GetMinMaxValueInternal(PixelType& minValue, | |
153 PixelType& maxValue, | |
154 const ImageAccessor& source) | |
155 { | |
156 // Deal with the special case of empty image | |
157 if (source.GetWidth() == 0 || | |
158 source.GetHeight() == 0) | |
159 { | |
160 minValue = 0; | |
161 maxValue = 0; | |
162 return; | |
163 } | |
164 | |
165 minValue = std::numeric_limits<PixelType>::max(); | |
166 maxValue = std::numeric_limits<PixelType>::min(); | |
167 | |
168 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
169 { | |
170 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); | |
171 | |
172 for (unsigned int x = 0; x < source.GetWidth(); x++, p++) | |
173 { | |
174 if (*p < minValue) | |
175 { | |
176 minValue = *p; | |
177 } | |
178 | |
179 if (*p > maxValue) | |
180 { | |
181 maxValue = *p; | |
182 } | |
183 } | |
184 } | |
185 } | |
186 | |
187 | |
188 | |
189 template <typename PixelType> | |
190 static void AddConstantInternal(ImageAccessor& image, | |
191 int64_t constant) | |
192 { | |
193 if (constant == 0) | |
194 { | |
195 return; | |
196 } | |
197 | |
198 const int64_t minValue = std::numeric_limits<PixelType>::min(); | |
199 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
200 | |
201 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
202 { | |
203 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
204 | |
205 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
206 { | |
207 int64_t v = static_cast<int64_t>(*p) + constant; | |
208 | |
209 if (v > maxValue) | |
210 { | |
876 | 211 *p = std::numeric_limits<PixelType>::max(); |
863 | 212 } |
213 else if (v < minValue) | |
214 { | |
876 | 215 *p = std::numeric_limits<PixelType>::min(); |
863 | 216 } |
217 else | |
218 { | |
219 *p = static_cast<PixelType>(v); | |
220 } | |
221 } | |
222 } | |
223 } | |
224 | |
225 | |
226 | |
227 template <typename PixelType> | |
228 void MultiplyConstantInternal(ImageAccessor& image, | |
229 float factor) | |
230 { | |
1334 | 231 if (std::abs(factor - 1.0f) <= std::numeric_limits<float>::epsilon()) |
863 | 232 { |
233 return; | |
234 } | |
235 | |
236 const int64_t minValue = std::numeric_limits<PixelType>::min(); | |
237 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
238 | |
239 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
240 { | |
241 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
242 | |
243 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
244 { | |
245 int64_t v = boost::math::llround(static_cast<float>(*p) * factor); | |
246 | |
247 if (v > maxValue) | |
248 { | |
876 | 249 *p = std::numeric_limits<PixelType>::max(); |
863 | 250 } |
251 else if (v < minValue) | |
252 { | |
876 | 253 *p = std::numeric_limits<PixelType>::min(); |
863 | 254 } |
255 else | |
256 { | |
257 *p = static_cast<PixelType>(v); | |
258 } | |
259 } | |
260 } | |
261 } | |
262 | |
263 | |
264 template <typename PixelType> | |
265 void ShiftScaleInternal(ImageAccessor& image, | |
266 float offset, | |
267 float scaling) | |
268 { | |
269 const float minValue = static_cast<float>(std::numeric_limits<PixelType>::min()); | |
270 const float maxValue = static_cast<float>(std::numeric_limits<PixelType>::max()); | |
271 | |
272 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
273 { | |
274 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
275 | |
276 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
277 { | |
278 float v = (static_cast<float>(*p) + offset) * scaling; | |
279 | |
280 if (v > maxValue) | |
281 { | |
282 *p = std::numeric_limits<PixelType>::max(); | |
283 } | |
284 else if (v < minValue) | |
285 { | |
286 *p = std::numeric_limits<PixelType>::min(); | |
287 } | |
288 else | |
289 { | |
290 *p = static_cast<PixelType>(boost::math::iround(v)); | |
291 } | |
292 } | |
293 } | |
294 } | |
295 | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
296 |
853 | 297 void ImageProcessing::Copy(ImageAccessor& target, |
298 const ImageAccessor& source) | |
299 { | |
300 if (target.GetWidth() != source.GetWidth() || | |
301 target.GetHeight() != source.GetHeight()) | |
302 { | |
303 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
304 } | |
305 | |
306 if (target.GetFormat() != source.GetFormat()) | |
307 { | |
308 throw OrthancException(ErrorCode_IncompatibleImageFormat); | |
309 } | |
310 | |
311 unsigned int lineSize = GetBytesPerPixel(source.GetFormat()) * source.GetWidth(); | |
312 | |
313 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize); | |
314 | |
315 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
316 { | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
317 memcpy(target.GetRow(y), source.GetConstRow(y), lineSize); |
853 | 318 } |
319 } | |
320 | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
321 |
853 | 322 void ImageProcessing::Convert(ImageAccessor& target, |
323 const ImageAccessor& source) | |
324 { | |
325 if (target.GetWidth() != source.GetWidth() || | |
326 target.GetHeight() != source.GetHeight()) | |
327 { | |
328 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
329 } | |
330 | |
331 if (source.GetFormat() == target.GetFormat()) | |
332 { | |
333 Copy(target, source); | |
334 return; | |
335 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
336 |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
337 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
338 source.GetFormat() == PixelFormat_Grayscale8) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
339 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
340 ConvertInternal<uint16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
341 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
342 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
343 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
344 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
345 source.GetFormat() == PixelFormat_Grayscale8) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
346 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
347 ConvertInternal<int16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
348 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
349 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
350 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
351 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
352 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
353 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
354 ConvertInternal<uint8_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
355 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
356 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
357 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
358 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
359 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
360 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
361 ConvertInternal<int16_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
362 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
363 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
364 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
365 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
366 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
367 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
368 ConvertInternal<uint8_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
369 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
370 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
371 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
372 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
373 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
374 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
375 ConvertInternal<uint16_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
376 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
377 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
378 |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
379 if (target.GetFormat() == PixelFormat_Grayscale8 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
380 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
381 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
382 ConvertColorToGrayscale<uint8_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
383 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
384 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
385 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
386 if (target.GetFormat() == PixelFormat_Grayscale16 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
387 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
388 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
389 ConvertColorToGrayscale<uint16_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
390 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
391 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
392 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
393 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
394 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
395 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
396 ConvertColorToGrayscale<int16_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
397 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
398 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
399 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
400 if (target.GetFormat() == PixelFormat_Float32 && |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
401 source.GetFormat() == PixelFormat_Grayscale8) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
402 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
403 ConvertGrayscaleToFloat<uint8_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
404 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
405 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
406 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
407 if (target.GetFormat() == PixelFormat_Float32 && |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
408 source.GetFormat() == PixelFormat_Grayscale16) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
409 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
410 ConvertGrayscaleToFloat<uint16_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
411 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
412 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
413 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
414 if (target.GetFormat() == PixelFormat_Float32 && |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
415 source.GetFormat() == PixelFormat_SignedGrayscale16) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
416 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
417 ConvertGrayscaleToFloat<int16_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
418 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
419 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
420 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
421 if (target.GetFormat() == PixelFormat_Grayscale8 && |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
422 source.GetFormat() == PixelFormat_RGBA32) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
423 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
424 for (unsigned int y = 0; y < source.GetHeight(); y++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
425 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
426 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
|
427 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
|
428 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
|
429 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
430 *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
|
431 7152 * static_cast<uint32_t>(p[1]) + |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
432 0722 * static_cast<uint32_t>(p[2])) / 10000); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
433 p += 4; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
434 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
435 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
436 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
437 return; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
438 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
439 |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
440 if (target.GetFormat() == PixelFormat_RGB24 && |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
441 source.GetFormat() == PixelFormat_RGBA32) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
442 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
443 for (unsigned int y = 0; y < source.GetHeight(); y++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
444 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
445 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
446 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
447 for (unsigned int x = 0; x < source.GetWidth(); x++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
448 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
449 q[0] = p[0]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
450 q[1] = p[1]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
451 q[2] = p[2]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
452 p += 4; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
453 q += 3; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
454 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
455 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
456 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
457 return; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
458 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
459 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
460 if (target.GetFormat() == PixelFormat_RGBA32 && |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
461 source.GetFormat() == PixelFormat_RGB24) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
462 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
463 for (unsigned int y = 0; y < source.GetHeight(); y++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
464 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
465 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
466 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
467 for (unsigned int x = 0; x < source.GetWidth(); x++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
468 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
469 q[0] = p[0]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
470 q[1] = p[1]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
471 q[2] = p[2]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
472 q[3] = 255; // Set the alpha channel to full opacity |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
473 p += 3; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
474 q += 4; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
475 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
476 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
477 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
478 return; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
479 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
480 |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
481 if (target.GetFormat() == PixelFormat_RGB24 && |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
482 source.GetFormat() == PixelFormat_Grayscale8) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
483 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
484 for (unsigned int y = 0; y < source.GetHeight(); y++) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
485 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
486 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
487 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
488 for (unsigned int x = 0; x < source.GetWidth(); x++) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
489 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
490 q[0] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
491 q[1] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
492 q[2] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
493 p += 1; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
494 q += 3; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
495 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
496 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
497 |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
498 return; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
499 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
500 |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
501 if (target.GetFormat() == PixelFormat_RGBA32 && |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
502 source.GetFormat() == PixelFormat_Grayscale8) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
503 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
504 for (unsigned int y = 0; y < source.GetHeight(); y++) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
505 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
506 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
507 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
508 for (unsigned int x = 0; x < source.GetWidth(); x++) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
509 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
510 q[0] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
511 q[1] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
512 q[2] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
513 q[3] = 255; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
514 p += 1; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
515 q += 4; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
516 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
517 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
518 |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
519 return; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
520 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
521 |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
522 if (target.GetFormat() == PixelFormat_BGRA32 && |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
523 source.GetFormat() == PixelFormat_RGB24) |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
524 { |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
525 for (unsigned int y = 0; y < source.GetHeight(); y++) |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
526 { |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
527 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
528 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
529 for (unsigned int x = 0; x < source.GetWidth(); x++) |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
530 { |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
531 q[0] = p[2]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
532 q[1] = p[1]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
533 q[2] = p[0]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
534 q[3] = 255; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
535 p += 3; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
536 q += 4; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
537 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
538 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
539 |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
540 return; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
541 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
542 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
543 throw OrthancException(ErrorCode_NotImplemented); |
853 | 544 } |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
545 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
546 |
863 | 547 |
548 void ImageProcessing::Set(ImageAccessor& image, | |
549 int64_t value) | |
550 { | |
551 switch (image.GetFormat()) | |
552 { | |
553 case PixelFormat_Grayscale8: | |
554 SetInternal<uint8_t>(image, value); | |
555 return; | |
556 | |
557 case PixelFormat_Grayscale16: | |
558 SetInternal<uint16_t>(image, value); | |
559 return; | |
560 | |
561 case PixelFormat_SignedGrayscale16: | |
562 SetInternal<int16_t>(image, value); | |
563 return; | |
564 | |
1994
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
565 case PixelFormat_Float32: |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
566 assert(sizeof(float) == 4); |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
567 SetInternal<float>(image, value); |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
568 return; |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
569 |
863 | 570 default: |
571 throw OrthancException(ErrorCode_NotImplemented); | |
572 } | |
573 } | |
574 | |
575 | |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
576 void ImageProcessing::Set(ImageAccessor& image, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
577 uint8_t red, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
578 uint8_t green, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
579 uint8_t blue, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
580 uint8_t alpha) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
581 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
582 uint8_t p[4]; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
583 unsigned int size; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
584 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
585 switch (image.GetFormat()) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
586 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
587 case PixelFormat_RGBA32: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
588 p[0] = red; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
589 p[1] = green; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
590 p[2] = blue; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
591 p[3] = alpha; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
592 size = 4; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
593 break; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
594 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
595 case PixelFormat_BGRA32: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
596 p[0] = blue; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
597 p[1] = green; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
598 p[2] = red; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
599 p[3] = alpha; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
600 size = 4; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
601 break; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
602 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
603 case PixelFormat_RGB24: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
604 p[0] = red; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
605 p[1] = green; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
606 p[2] = blue; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
607 size = 3; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
608 break; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
609 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
610 default: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
611 throw OrthancException(ErrorCode_NotImplemented); |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
612 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
613 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
614 for (unsigned int y = 0; y < image.GetHeight(); y++) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
615 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
616 uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y)); |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
617 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
618 for (unsigned int x = 0; x < image.GetWidth(); x++) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
619 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
620 for (unsigned int i = 0; i < size; i++) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
621 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
622 q[i] = p[i]; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
623 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
624 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
625 q += size; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
626 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
627 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
628 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
629 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
630 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
631 void ImageProcessing::ShiftRight(ImageAccessor& image, |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
632 unsigned int shift) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
633 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
634 if (image.GetWidth() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
635 image.GetHeight() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
636 shift == 0) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
637 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
638 // Nothing to do |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
639 return; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
640 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
641 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
642 throw OrthancException(ErrorCode_NotImplemented); |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
643 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
644 |
863 | 645 |
646 void ImageProcessing::GetMinMaxValue(int64_t& minValue, | |
647 int64_t& maxValue, | |
648 const ImageAccessor& image) | |
649 { | |
650 switch (image.GetFormat()) | |
651 { | |
652 case PixelFormat_Grayscale8: | |
653 { | |
654 uint8_t a, b; | |
655 GetMinMaxValueInternal<uint8_t>(a, b, image); | |
656 minValue = a; | |
657 maxValue = b; | |
658 break; | |
659 } | |
660 | |
661 case PixelFormat_Grayscale16: | |
662 { | |
663 uint16_t a, b; | |
664 GetMinMaxValueInternal<uint16_t>(a, b, image); | |
665 minValue = a; | |
666 maxValue = b; | |
667 break; | |
668 } | |
669 | |
670 case PixelFormat_SignedGrayscale16: | |
671 { | |
672 int16_t a, b; | |
673 GetMinMaxValueInternal<int16_t>(a, b, image); | |
674 minValue = a; | |
675 maxValue = b; | |
676 break; | |
677 } | |
678 | |
679 default: | |
680 throw OrthancException(ErrorCode_NotImplemented); | |
681 } | |
682 } | |
683 | |
684 | |
685 | |
686 void ImageProcessing::AddConstant(ImageAccessor& image, | |
687 int64_t value) | |
688 { | |
689 switch (image.GetFormat()) | |
690 { | |
691 case PixelFormat_Grayscale8: | |
692 AddConstantInternal<uint8_t>(image, value); | |
693 return; | |
694 | |
695 case PixelFormat_Grayscale16: | |
696 AddConstantInternal<uint16_t>(image, value); | |
697 return; | |
698 | |
699 case PixelFormat_SignedGrayscale16: | |
700 AddConstantInternal<int16_t>(image, value); | |
701 return; | |
702 | |
703 default: | |
704 throw OrthancException(ErrorCode_NotImplemented); | |
705 } | |
706 } | |
707 | |
708 | |
709 void ImageProcessing::MultiplyConstant(ImageAccessor& image, | |
710 float factor) | |
711 { | |
712 switch (image.GetFormat()) | |
713 { | |
714 case PixelFormat_Grayscale8: | |
715 MultiplyConstantInternal<uint8_t>(image, factor); | |
716 return; | |
717 | |
718 case PixelFormat_Grayscale16: | |
719 MultiplyConstantInternal<uint16_t>(image, factor); | |
720 return; | |
721 | |
722 case PixelFormat_SignedGrayscale16: | |
723 MultiplyConstantInternal<int16_t>(image, factor); | |
724 return; | |
725 | |
726 default: | |
727 throw OrthancException(ErrorCode_NotImplemented); | |
728 } | |
729 } | |
730 | |
731 | |
732 void ImageProcessing::ShiftScale(ImageAccessor& image, | |
733 float offset, | |
734 float scaling) | |
735 { | |
736 switch (image.GetFormat()) | |
737 { | |
738 case PixelFormat_Grayscale8: | |
739 ShiftScaleInternal<uint8_t>(image, offset, scaling); | |
740 return; | |
741 | |
742 case PixelFormat_Grayscale16: | |
743 ShiftScaleInternal<uint16_t>(image, offset, scaling); | |
744 return; | |
745 | |
746 case PixelFormat_SignedGrayscale16: | |
747 ShiftScaleInternal<int16_t>(image, offset, scaling); | |
748 return; | |
749 | |
750 default: | |
751 throw OrthancException(ErrorCode_NotImplemented); | |
752 } | |
753 } | |
853 | 754 } |