Mercurial > hg > orthanc
annotate Core/Images/ImageProcessing.cpp @ 4116:975f1f20995b Orthanc-1.4.2-fix-build
closing Orthanc-1.4.2-fix-build
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 13:12:40 +0200 |
parents | 65699fcb4e99 |
children | f4c232bba1eb |
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 |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2423
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
853 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeaders.h" | |
35 #include "ImageProcessing.h" | |
36 | |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
37 #include "PixelTraits.h" |
853 | 38 |
863 | 39 #include <boost/math/special_functions/round.hpp> |
40 | |
853 | 41 #include <cassert> |
42 #include <string.h> | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
43 #include <limits> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
44 #include <stdint.h> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
45 |
853 | 46 namespace Orthanc |
47 { | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
48 template <typename TargetType, typename SourceType> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
49 static void ConvertInternal(ImageAccessor& target, |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
50 const ImageAccessor& source) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
51 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
52 const TargetType minValue = std::numeric_limits<TargetType>::min(); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
53 const TargetType maxValue = std::numeric_limits<TargetType>::max(); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
54 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
55 for (unsigned int y = 0; y < source.GetHeight(); y++) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
56 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
57 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
58 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
59 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
60 for (unsigned int x = 0; x < source.GetWidth(); x++, t++, s++) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
61 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
62 if (static_cast<int32_t>(*s) < static_cast<int32_t>(minValue)) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
63 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
64 *t = minValue; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
65 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
66 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
|
67 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
68 *t = maxValue; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
69 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
70 else |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
71 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
72 *t = static_cast<TargetType>(*s); |
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 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
78 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
79 template <typename SourceType> |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
80 static void ConvertGrayscaleToFloat(ImageAccessor& target, |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
81 const ImageAccessor& source) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
82 { |
1994
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
83 assert(sizeof(float) == 4); |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
84 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
85 for (unsigned int y = 0; y < source.GetHeight(); y++) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
86 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
87 float* t = reinterpret_cast<float*>(target.GetRow(y)); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
88 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
89 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
90 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
|
91 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
92 *t = static_cast<float>(*s); |
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 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
97 |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
98 template <typename TargetType> |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
99 static void ConvertColorToGrayscale(ImageAccessor& target, |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
100 const ImageAccessor& source) |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
101 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
102 assert(source.GetFormat() == PixelFormat_RGB24); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
103 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
104 const TargetType minValue = std::numeric_limits<TargetType>::min(); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
105 const TargetType maxValue = std::numeric_limits<TargetType>::max(); |
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 for (unsigned int y = 0; y < source.GetHeight(); y++) |
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 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
110 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
|
111 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
112 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
|
113 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
114 // 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
|
115 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
|
116 7152 * static_cast<int32_t>(s[1]) + |
2491
a9459c7d4bc2
fix color-to-grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2490
diff
changeset
|
117 0722 * static_cast<int32_t>(s[2])) / 10000; |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
118 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
119 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
|
120 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
121 *t = minValue; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
122 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
123 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
|
124 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
125 *t = maxValue; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
126 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
127 else |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
128 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
129 *t = static_cast<TargetType>(v); |
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 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
135 |
863 | 136 template <typename PixelType> |
137 static void SetInternal(ImageAccessor& image, | |
138 int64_t constant) | |
139 { | |
140 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
141 { | |
142 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
143 | |
144 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
145 { | |
146 *p = static_cast<PixelType>(constant); | |
147 } | |
148 } | |
149 } | |
150 | |
151 | |
152 template <typename PixelType> | |
153 static void GetMinMaxValueInternal(PixelType& minValue, | |
154 PixelType& maxValue, | |
155 const ImageAccessor& source) | |
156 { | |
157 // Deal with the special case of empty image | |
158 if (source.GetWidth() == 0 || | |
159 source.GetHeight() == 0) | |
160 { | |
161 minValue = 0; | |
162 maxValue = 0; | |
163 return; | |
164 } | |
165 | |
166 minValue = std::numeric_limits<PixelType>::max(); | |
167 maxValue = std::numeric_limits<PixelType>::min(); | |
168 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
169 const unsigned int width = source.GetWidth(); |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
170 |
863 | 171 for (unsigned int y = 0; y < source.GetHeight(); y++) |
172 { | |
173 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); | |
174 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
175 for (unsigned int x = 0; x < width; x++, p++) |
863 | 176 { |
177 if (*p < minValue) | |
178 { | |
179 minValue = *p; | |
180 } | |
181 | |
182 if (*p > maxValue) | |
183 { | |
184 maxValue = *p; | |
185 } | |
186 } | |
187 } | |
188 } | |
189 | |
190 | |
191 | |
192 template <typename PixelType> | |
193 static void AddConstantInternal(ImageAccessor& image, | |
194 int64_t constant) | |
195 { | |
196 if (constant == 0) | |
197 { | |
198 return; | |
199 } | |
200 | |
201 const int64_t minValue = std::numeric_limits<PixelType>::min(); | |
202 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
203 | |
204 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
205 { | |
206 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
207 | |
208 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | |
209 { | |
210 int64_t v = static_cast<int64_t>(*p) + constant; | |
211 | |
212 if (v > maxValue) | |
213 { | |
876 | 214 *p = std::numeric_limits<PixelType>::max(); |
863 | 215 } |
216 else if (v < minValue) | |
217 { | |
876 | 218 *p = std::numeric_limits<PixelType>::min(); |
863 | 219 } |
220 else | |
221 { | |
222 *p = static_cast<PixelType>(v); | |
223 } | |
224 } | |
225 } | |
226 } | |
227 | |
228 | |
229 | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
230 template <typename PixelType, |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
231 bool UseRound> |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
232 static void MultiplyConstantInternal(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
233 float factor) |
863 | 234 { |
1334 | 235 if (std::abs(factor - 1.0f) <= std::numeric_limits<float>::epsilon()) |
863 | 236 { |
237 return; | |
238 } | |
239 | |
240 const int64_t minValue = std::numeric_limits<PixelType>::min(); | |
241 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
242 const unsigned int width = image.GetWidth(); |
863 | 243 |
244 for (unsigned int y = 0; y < image.GetHeight(); y++) | |
245 { | |
246 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
247 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
248 for (unsigned int x = 0; x < width; x++, p++) |
863 | 249 { |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
250 int64_t v; |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
251 if (UseRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
252 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
253 // The "round" operation is very costly |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
254 v = boost::math::llround(static_cast<float>(*p) * factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
255 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
256 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
257 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
258 v = static_cast<int64_t>(static_cast<float>(*p) * factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
259 } |
863 | 260 |
261 if (v > maxValue) | |
262 { | |
876 | 263 *p = std::numeric_limits<PixelType>::max(); |
863 | 264 } |
265 else if (v < minValue) | |
266 { | |
876 | 267 *p = std::numeric_limits<PixelType>::min(); |
863 | 268 } |
269 else | |
270 { | |
271 *p = static_cast<PixelType>(v); | |
272 } | |
273 } | |
274 } | |
275 } | |
276 | |
277 | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
278 template <typename PixelType, |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
279 bool UseRound> |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
280 static void ShiftScaleInternal(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
281 float offset, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
282 float scaling) |
863 | 283 { |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
284 const float minFloatValue = static_cast<float>(std::numeric_limits<PixelType>::min()); |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
285 const float maxFloatValue = static_cast<float>(std::numeric_limits<PixelType>::max()); |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
286 const PixelType minPixelValue = std::numeric_limits<PixelType>::min(); |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
287 const PixelType maxPixelValue = std::numeric_limits<PixelType>::max(); |
863 | 288 |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
289 const unsigned int height = image.GetHeight(); |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
290 const unsigned int width = image.GetWidth(); |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
291 |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
292 for (unsigned int y = 0; y < height; y++) |
863 | 293 { |
294 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
295 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
296 for (unsigned int x = 0; x < width; x++, p++) |
863 | 297 { |
298 float v = (static_cast<float>(*p) + offset) * scaling; | |
299 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
300 if (v > maxFloatValue) |
863 | 301 { |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
302 *p = maxPixelValue; |
863 | 303 } |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
304 else if (v < minFloatValue) |
863 | 305 { |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
306 *p = minPixelValue; |
863 | 307 } |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
308 else if (UseRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
309 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
310 // The "round" operation is very costly |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
311 *p = static_cast<PixelType>(boost::math::iround(v)); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
312 } |
863 | 313 else |
314 { | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
315 *p = static_cast<PixelType>(v); |
863 | 316 } |
317 } | |
318 } | |
319 } | |
320 | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
321 |
853 | 322 void ImageProcessing::Copy(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 (target.GetFormat() != source.GetFormat()) | |
332 { | |
333 throw OrthancException(ErrorCode_IncompatibleImageFormat); | |
334 } | |
335 | |
336 unsigned int lineSize = GetBytesPerPixel(source.GetFormat()) * source.GetWidth(); | |
337 | |
338 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize); | |
339 | |
340 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
341 { | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
342 memcpy(target.GetRow(y), source.GetConstRow(y), lineSize); |
853 | 343 } |
344 } | |
345 | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
346 |
853 | 347 void ImageProcessing::Convert(ImageAccessor& target, |
348 const ImageAccessor& source) | |
349 { | |
350 if (target.GetWidth() != source.GetWidth() || | |
351 target.GetHeight() != source.GetHeight()) | |
352 { | |
353 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
354 } | |
355 | |
356 if (source.GetFormat() == target.GetFormat()) | |
357 { | |
358 Copy(target, source); | |
359 return; | |
360 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
361 |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
362 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
363 source.GetFormat() == PixelFormat_Grayscale8) |
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 ConvertInternal<uint16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
366 return; |
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 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
369 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
370 source.GetFormat() == PixelFormat_Grayscale8) |
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 ConvertInternal<int16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
373 return; |
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 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
376 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
377 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
378 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
379 ConvertInternal<uint8_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
380 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
381 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
382 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
383 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
384 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
385 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
386 ConvertInternal<int16_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
387 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
388 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
389 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
390 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
391 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
392 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
393 ConvertInternal<uint8_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
394 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
395 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
396 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
397 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
398 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
399 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
400 ConvertInternal<uint16_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
401 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
402 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
403 |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
404 if (target.GetFormat() == PixelFormat_Grayscale8 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
405 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
406 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
407 ConvertColorToGrayscale<uint8_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
408 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
409 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
410 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
411 if (target.GetFormat() == PixelFormat_Grayscale16 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
412 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
413 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
414 ConvertColorToGrayscale<uint16_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
415 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
416 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
417 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
418 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
419 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
420 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
421 ConvertColorToGrayscale<int16_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
422 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
423 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
424 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
425 if (target.GetFormat() == PixelFormat_Float32 && |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
426 source.GetFormat() == PixelFormat_Grayscale8) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
427 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
428 ConvertGrayscaleToFloat<uint8_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
429 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
430 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
431 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
432 if (target.GetFormat() == PixelFormat_Float32 && |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
433 source.GetFormat() == PixelFormat_Grayscale16) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
434 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
435 ConvertGrayscaleToFloat<uint16_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
436 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
437 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
438 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
439 if (target.GetFormat() == PixelFormat_Float32 && |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
440 source.GetFormat() == PixelFormat_Grayscale32) |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
441 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
442 ConvertGrayscaleToFloat<uint32_t>(target, source); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
443 return; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
444 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
445 |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
446 if (target.GetFormat() == PixelFormat_Float32 && |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
447 source.GetFormat() == PixelFormat_SignedGrayscale16) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
448 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
449 ConvertGrayscaleToFloat<int16_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
450 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
451 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
452 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
453 if (target.GetFormat() == PixelFormat_Grayscale8 && |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
454 source.GetFormat() == PixelFormat_RGBA32) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
455 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
456 for (unsigned int y = 0; y < source.GetHeight(); y++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
457 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
458 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
|
459 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
|
460 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
|
461 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
462 *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
|
463 7152 * static_cast<uint32_t>(p[1]) + |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
464 0722 * static_cast<uint32_t>(p[2])) / 10000); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
465 p += 4; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
466 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
467 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
468 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
469 return; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
470 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
471 |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
472 if (target.GetFormat() == PixelFormat_RGB24 && |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
473 source.GetFormat() == PixelFormat_RGBA32) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
474 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
475 for (unsigned int y = 0; y < source.GetHeight(); y++) |
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 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
478 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
479 for (unsigned int x = 0; x < source.GetWidth(); x++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
480 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
481 q[0] = p[0]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
482 q[1] = p[1]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
483 q[2] = p[2]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
484 p += 4; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
485 q += 3; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
486 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
487 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
488 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
489 return; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
490 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
491 |
2252
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
492 if (target.GetFormat() == PixelFormat_RGB24 && |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
493 source.GetFormat() == PixelFormat_BGRA32) |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
494 { |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
495 for (unsigned int y = 0; y < source.GetHeight(); y++) |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
496 { |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
497 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
498 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
499 for (unsigned int x = 0; x < source.GetWidth(); x++) |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
500 { |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
501 q[0] = p[2]; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
502 q[1] = p[1]; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
503 q[2] = p[0]; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
504 p += 4; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
505 q += 3; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
506 } |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
507 } |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
508 |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
509 return; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
510 } |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
511 |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
512 if (target.GetFormat() == PixelFormat_RGBA32 && |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
513 source.GetFormat() == PixelFormat_RGB24) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
514 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
515 for (unsigned int y = 0; y < source.GetHeight(); y++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
516 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
517 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
518 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
519 for (unsigned int x = 0; x < source.GetWidth(); x++) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
520 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
521 q[0] = p[0]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
522 q[1] = p[1]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
523 q[2] = p[2]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
524 q[3] = 255; // Set the alpha channel to full opacity |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
525 p += 3; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
526 q += 4; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
527 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
528 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
529 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
530 return; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
531 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
532 |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
533 if (target.GetFormat() == PixelFormat_RGB24 && |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
534 source.GetFormat() == PixelFormat_Grayscale8) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
535 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
536 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
|
537 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
538 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
|
539 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
|
540 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
|
541 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
542 q[0] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
543 q[1] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
544 q[2] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
545 p += 1; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
546 q += 3; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
547 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
548 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
549 |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
550 return; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
551 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
552 |
2650 | 553 if ((target.GetFormat() == PixelFormat_RGBA32 || |
554 target.GetFormat() == PixelFormat_BGRA32) && | |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
555 source.GetFormat() == PixelFormat_Grayscale8) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
556 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
557 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
|
558 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
559 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
|
560 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
|
561 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
|
562 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
563 q[0] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
564 q[1] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
565 q[2] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
566 q[3] = 255; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
567 p += 1; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
568 q += 4; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
569 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
570 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
571 |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
572 return; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
573 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
574 |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
575 if (target.GetFormat() == PixelFormat_BGRA32 && |
2495
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
576 source.GetFormat() == PixelFormat_Grayscale16) |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
577 { |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
578 for (unsigned int y = 0; y < source.GetHeight(); y++) |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
579 { |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
580 const uint16_t* p = reinterpret_cast<const uint16_t*>(source.GetConstRow(y)); |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
581 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
582 for (unsigned int x = 0; x < source.GetWidth(); x++) |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
583 { |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
584 uint8_t value = (*p < 256 ? *p : 255); |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
585 q[0] = value; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
586 q[1] = value; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
587 q[2] = value; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
588 q[3] = 255; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
589 p += 1; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
590 q += 4; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
591 } |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
592 } |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
593 |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
594 return; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
595 } |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
596 |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
597 if (target.GetFormat() == PixelFormat_BGRA32 && |
2496
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
598 source.GetFormat() == PixelFormat_SignedGrayscale16) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
599 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
600 for (unsigned int y = 0; y < source.GetHeight(); y++) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
601 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
602 const int16_t* p = reinterpret_cast<const int16_t*>(source.GetConstRow(y)); |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
603 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
604 for (unsigned int x = 0; x < source.GetWidth(); x++) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
605 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
606 uint8_t value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
607 if (*p < 0) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
608 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
609 value = 0; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
610 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
611 else if (*p > 255) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
612 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
613 value = 255; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
614 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
615 else |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
616 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
617 value = static_cast<uint8_t>(*p); |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
618 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
619 |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
620 q[0] = value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
621 q[1] = value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
622 q[2] = value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
623 q[3] = 255; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
624 p += 1; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
625 q += 4; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
626 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
627 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
628 |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
629 return; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
630 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
631 |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
632 if (target.GetFormat() == PixelFormat_BGRA32 && |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
633 source.GetFormat() == PixelFormat_RGB24) |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
634 { |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
635 for (unsigned int y = 0; y < source.GetHeight(); y++) |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
636 { |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
637 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
|
638 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
|
639 for (unsigned int x = 0; x < source.GetWidth(); x++) |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
640 { |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
641 q[0] = p[2]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
642 q[1] = p[1]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
643 q[2] = p[0]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
644 q[3] = 255; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
645 p += 3; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
646 q += 4; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
647 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
648 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
649 |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
650 return; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
651 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
652 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
653 if (target.GetFormat() == PixelFormat_RGB24 && |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
654 source.GetFormat() == PixelFormat_RGB48) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
655 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
656 for (unsigned int y = 0; y < source.GetHeight(); y++) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
657 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
658 const uint16_t* p = reinterpret_cast<const uint16_t*>(source.GetConstRow(y)); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
659 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
660 for (unsigned int x = 0; x < source.GetWidth(); x++) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
661 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
662 q[0] = p[0] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
663 q[1] = p[1] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
664 q[2] = p[2] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
665 p += 3; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
666 q += 3; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
667 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
668 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
669 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
670 return; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
671 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
672 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
673 throw OrthancException(ErrorCode_NotImplemented); |
853 | 674 } |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
675 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
676 |
863 | 677 |
678 void ImageProcessing::Set(ImageAccessor& image, | |
679 int64_t value) | |
680 { | |
681 switch (image.GetFormat()) | |
682 { | |
683 case PixelFormat_Grayscale8: | |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2482
diff
changeset
|
684 memset(image.GetBuffer(), static_cast<uint8_t>(value), image.GetPitch() * image.GetHeight()); |
863 | 685 return; |
686 | |
687 case PixelFormat_Grayscale16: | |
2490
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
688 if (value == 0) |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
689 { |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
690 memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
691 } |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
692 else |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
693 { |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
694 SetInternal<uint16_t>(image, value); |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
695 } |
863 | 696 return; |
697 | |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
698 case PixelFormat_Grayscale32: |
2490
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
699 if (value == 0) |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
700 { |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
701 memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
702 } |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
703 else |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
704 { |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
705 SetInternal<uint32_t>(image, value); |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
706 } |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
707 return; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
708 |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
709 case PixelFormat_Grayscale64: |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
710 if (value == 0) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
711 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
712 memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
713 } |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
714 else |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
715 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
716 SetInternal<uint64_t>(image, value); |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
717 } |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
718 return; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
719 |
863 | 720 case PixelFormat_SignedGrayscale16: |
2490
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
721 if (value == 0) |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
722 { |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
723 memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
724 } |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
725 else |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
726 { |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
727 SetInternal<int16_t>(image, value); |
0cacb38297a9
speed up ImageProcessing::Set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
728 } |
863 | 729 return; |
730 | |
1994
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
731 case PixelFormat_Float32: |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
732 assert(sizeof(float) == 4); |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
733 SetInternal<float>(image, value); |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
734 return; |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
735 |
863 | 736 default: |
737 throw OrthancException(ErrorCode_NotImplemented); | |
738 } | |
739 } | |
740 | |
741 | |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
742 void ImageProcessing::Set(ImageAccessor& image, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
743 uint8_t red, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
744 uint8_t green, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
745 uint8_t blue, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
746 uint8_t alpha) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
747 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
748 uint8_t p[4]; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
749 unsigned int size; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
750 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
751 switch (image.GetFormat()) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
752 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
753 case PixelFormat_RGBA32: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
754 p[0] = red; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
755 p[1] = green; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
756 p[2] = blue; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
757 p[3] = alpha; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
758 size = 4; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
759 break; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
760 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
761 case PixelFormat_BGRA32: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
762 p[0] = blue; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
763 p[1] = green; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
764 p[2] = red; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
765 p[3] = alpha; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
766 size = 4; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
767 break; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
768 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
769 case PixelFormat_RGB24: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
770 p[0] = red; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
771 p[1] = green; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
772 p[2] = blue; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
773 size = 3; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
774 break; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
775 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
776 default: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
777 throw OrthancException(ErrorCode_NotImplemented); |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
778 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
779 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
780 for (unsigned int y = 0; y < image.GetHeight(); y++) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
781 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
782 uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y)); |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
783 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
784 for (unsigned int x = 0; x < image.GetWidth(); x++) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
785 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
786 for (unsigned int i = 0; i < size; i++) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
787 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
788 q[i] = p[i]; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
789 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
790 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
791 q += size; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
792 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
793 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
794 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
795 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
796 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
797 void ImageProcessing::ShiftRight(ImageAccessor& image, |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
798 unsigned int shift) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
799 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
800 if (image.GetWidth() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
801 image.GetHeight() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
802 shift == 0) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
803 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
804 // Nothing to do |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
805 return; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
806 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
807 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
808 throw OrthancException(ErrorCode_NotImplemented); |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
809 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
810 |
863 | 811 |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
812 void ImageProcessing::GetMinMaxIntegerValue(int64_t& minValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
813 int64_t& maxValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
814 const ImageAccessor& image) |
863 | 815 { |
816 switch (image.GetFormat()) | |
817 { | |
818 case PixelFormat_Grayscale8: | |
819 { | |
820 uint8_t a, b; | |
821 GetMinMaxValueInternal<uint8_t>(a, b, image); | |
822 minValue = a; | |
823 maxValue = b; | |
824 break; | |
825 } | |
826 | |
827 case PixelFormat_Grayscale16: | |
828 { | |
829 uint16_t a, b; | |
830 GetMinMaxValueInternal<uint16_t>(a, b, image); | |
831 minValue = a; | |
832 maxValue = b; | |
833 break; | |
834 } | |
835 | |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
836 case PixelFormat_Grayscale32: |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
837 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
838 uint32_t a, b; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
839 GetMinMaxValueInternal<uint32_t>(a, b, image); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
840 minValue = a; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
841 maxValue = b; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
842 break; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
843 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
844 |
863 | 845 case PixelFormat_SignedGrayscale16: |
846 { | |
847 int16_t a, b; | |
848 GetMinMaxValueInternal<int16_t>(a, b, image); | |
849 minValue = a; | |
850 maxValue = b; | |
851 break; | |
852 } | |
853 | |
854 default: | |
855 throw OrthancException(ErrorCode_NotImplemented); | |
856 } | |
857 } | |
858 | |
859 | |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
860 void ImageProcessing::GetMinMaxFloatValue(float& minValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
861 float& maxValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
862 const ImageAccessor& image) |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
863 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
864 switch (image.GetFormat()) |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
865 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
866 case PixelFormat_Float32: |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
867 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
868 assert(sizeof(float) == 32); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
869 float a, b; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
870 GetMinMaxValueInternal<float>(a, b, image); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
871 minValue = a; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
872 maxValue = b; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
873 break; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
874 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
875 |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
876 default: |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
877 throw OrthancException(ErrorCode_NotImplemented); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
878 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
879 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
880 |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
881 |
863 | 882 |
883 void ImageProcessing::AddConstant(ImageAccessor& image, | |
884 int64_t value) | |
885 { | |
886 switch (image.GetFormat()) | |
887 { | |
888 case PixelFormat_Grayscale8: | |
889 AddConstantInternal<uint8_t>(image, value); | |
890 return; | |
891 | |
892 case PixelFormat_Grayscale16: | |
893 AddConstantInternal<uint16_t>(image, value); | |
894 return; | |
895 | |
896 case PixelFormat_SignedGrayscale16: | |
897 AddConstantInternal<int16_t>(image, value); | |
898 return; | |
899 | |
900 default: | |
901 throw OrthancException(ErrorCode_NotImplemented); | |
902 } | |
903 } | |
904 | |
905 | |
906 void ImageProcessing::MultiplyConstant(ImageAccessor& image, | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
907 float factor, |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
908 bool useRound) |
863 | 909 { |
910 switch (image.GetFormat()) | |
911 { | |
912 case PixelFormat_Grayscale8: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
913 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
914 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
915 MultiplyConstantInternal<uint8_t, true>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
916 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
917 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
918 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
919 MultiplyConstantInternal<uint8_t, false>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
920 } |
863 | 921 return; |
922 | |
923 case PixelFormat_Grayscale16: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
924 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
925 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
926 MultiplyConstantInternal<uint16_t, true>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
927 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
928 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
929 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
930 MultiplyConstantInternal<uint16_t, false>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
931 } |
863 | 932 return; |
933 | |
934 case PixelFormat_SignedGrayscale16: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
935 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
936 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
937 MultiplyConstantInternal<int16_t, true>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
938 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
939 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
940 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
941 MultiplyConstantInternal<int16_t, false>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
942 } |
863 | 943 return; |
944 | |
945 default: | |
946 throw OrthancException(ErrorCode_NotImplemented); | |
947 } | |
948 } | |
949 | |
950 | |
951 void ImageProcessing::ShiftScale(ImageAccessor& image, | |
952 float offset, | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
953 float scaling, |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
954 bool useRound) |
863 | 955 { |
956 switch (image.GetFormat()) | |
957 { | |
958 case PixelFormat_Grayscale8: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
959 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
960 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
961 ShiftScaleInternal<uint8_t, true>(image, offset, scaling); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
962 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
963 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
964 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
965 ShiftScaleInternal<uint8_t, false>(image, offset, scaling); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
966 } |
863 | 967 return; |
968 | |
969 case PixelFormat_Grayscale16: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
970 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
971 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
972 ShiftScaleInternal<uint16_t, true>(image, offset, scaling); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
973 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
974 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
975 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
976 ShiftScaleInternal<uint16_t, false>(image, offset, scaling); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
977 } |
863 | 978 return; |
979 | |
980 case PixelFormat_SignedGrayscale16: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
981 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
982 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
983 ShiftScaleInternal<int16_t, true>(image, offset, scaling); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
984 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
985 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
986 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
987 ShiftScaleInternal<int16_t, false>(image, offset, scaling); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
988 } |
863 | 989 return; |
990 | |
991 default: | |
992 throw OrthancException(ErrorCode_NotImplemented); | |
993 } | |
994 } | |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
995 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
996 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
997 void ImageProcessing::Invert(ImageAccessor& image) |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
998 { |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
999 switch (image.GetFormat()) |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1000 { |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1001 case PixelFormat_Grayscale8: |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1002 { |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1003 for (unsigned int y = 0; y < image.GetHeight(); y++) |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1004 { |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1005 uint8_t* p = reinterpret_cast<uint8_t*>(image.GetRow(y)); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1006 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1007 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1008 { |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1009 *p = 255 - (*p); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1010 } |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1011 } |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1012 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1013 return; |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1014 } |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1015 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1016 default: |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1017 throw OrthancException(ErrorCode_NotImplemented); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1018 } |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1019 } |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1020 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1021 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1022 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1023 namespace |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1024 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1025 template <Orthanc::PixelFormat Format> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1026 class BresenhamPixelWriter |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1027 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1028 private: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1029 typedef typename PixelTraits<Format>::PixelType PixelType; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1030 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1031 Orthanc::ImageAccessor& image_; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1032 PixelType value_; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1033 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1034 void PlotLineLow(int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1035 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1036 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1037 int y1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1038 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1039 int dx = x1 - x0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1040 int dy = y1 - y0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1041 int yi = 1; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1042 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1043 if (dy < 0) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1044 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1045 yi = -1; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1046 dy = -dy; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1047 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1048 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1049 int d = 2 * dy - dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1050 int y = y0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1051 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1052 for (int x = x0; x <= x1; x++) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1053 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1054 Write(x, y); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1055 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1056 if (d > 0) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1057 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1058 y = y + yi; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1059 d = d - 2 * dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1060 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1061 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1062 d = d + 2*dy; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1063 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1064 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1065 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1066 void PlotLineHigh(int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1067 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1068 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1069 int y1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1070 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1071 int dx = x1 - x0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1072 int dy = y1 - y0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1073 int xi = 1; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1074 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1075 if (dx < 0) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1076 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1077 xi = -1; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1078 dx = -dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1079 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1080 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1081 int d = 2 * dx - dy; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1082 int x = x0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1083 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1084 for (int y = y0; y <= y1; y++) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1085 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1086 Write(x, y); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1087 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1088 if (d > 0) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1089 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1090 x = x + xi; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1091 d = d - 2 * dy; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1092 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1093 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1094 d = d + 2 * dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1095 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1096 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1097 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1098 public: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1099 BresenhamPixelWriter(Orthanc::ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1100 int64_t value) : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1101 image_(image), |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1102 value_(PixelTraits<Format>::IntegerToPixel(value)) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1103 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1104 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1105 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1106 BresenhamPixelWriter(Orthanc::ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1107 const PixelType& value) : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1108 image_(image), |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1109 value_(value) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1110 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1111 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1112 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1113 void Write(int x, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1114 int y) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1115 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1116 if (x >= 0 && |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1117 y >= 0 && |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1118 static_cast<unsigned int>(x) < image_.GetWidth() && |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1119 static_cast<unsigned int>(y) < image_.GetHeight()) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1120 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1121 PixelType* p = reinterpret_cast<PixelType*>(image_.GetRow(y)); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1122 p[x] = value_; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1123 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1124 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1125 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1126 void DrawSegment(int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1127 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1128 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1129 int y1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1130 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1131 // This is an implementation of Bresenham's line algorithm |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1132 // https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#All_cases |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1133 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1134 if (abs(y1 - y0) < abs(x1 - x0)) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1135 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1136 if (x0 > x1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1137 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1138 PlotLineLow(x1, y1, x0, y0); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1139 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1140 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1141 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1142 PlotLineLow(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1143 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1144 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1145 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1146 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1147 if (y0 > y1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1148 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1149 PlotLineHigh(x1, y1, x0, y0); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1150 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1151 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1152 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1153 PlotLineHigh(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1154 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1155 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1156 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1157 }; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1158 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1159 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1160 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1161 void ImageProcessing::DrawLineSegment(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1162 int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1163 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1164 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1165 int y1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1166 int64_t value) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1167 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1168 switch (image.GetFormat()) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1169 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1170 case Orthanc::PixelFormat_Grayscale8: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1171 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1172 BresenhamPixelWriter<Orthanc::PixelFormat_Grayscale8> writer(image, value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1173 writer.DrawSegment(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1174 break; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1175 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1176 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1177 case Orthanc::PixelFormat_Grayscale16: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1178 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1179 BresenhamPixelWriter<Orthanc::PixelFormat_Grayscale16> writer(image, value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1180 writer.DrawSegment(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1181 break; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1182 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1183 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1184 case Orthanc::PixelFormat_SignedGrayscale16: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1185 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1186 BresenhamPixelWriter<Orthanc::PixelFormat_SignedGrayscale16> writer(image, value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1187 writer.DrawSegment(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1188 break; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1189 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1190 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1191 default: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1192 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1193 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1194 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1195 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1196 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1197 void ImageProcessing::DrawLineSegment(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1198 int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1199 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1200 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1201 int y1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1202 uint8_t red, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1203 uint8_t green, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1204 uint8_t blue, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1205 uint8_t alpha) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1206 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1207 switch (image.GetFormat()) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1208 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1209 case Orthanc::PixelFormat_BGRA32: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1210 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1211 PixelTraits<Orthanc::PixelFormat_BGRA32>::PixelType pixel; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1212 pixel.red_ = red; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1213 pixel.green_ = green; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1214 pixel.blue_ = blue; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1215 pixel.alpha_ = alpha; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1216 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1217 BresenhamPixelWriter<Orthanc::PixelFormat_BGRA32> writer(image, pixel); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1218 writer.DrawSegment(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1219 break; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1220 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1221 |
2783
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1222 case Orthanc::PixelFormat_RGBA32: |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1223 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1224 PixelTraits<Orthanc::PixelFormat_RGBA32>::PixelType pixel; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1225 pixel.red_ = red; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1226 pixel.green_ = green; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1227 pixel.blue_ = blue; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1228 pixel.alpha_ = alpha; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1229 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1230 BresenhamPixelWriter<Orthanc::PixelFormat_RGBA32> writer(image, pixel); |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1231 writer.DrawSegment(x0, y0, x1, y1); |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1232 break; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1233 } |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1234 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1235 case Orthanc::PixelFormat_RGB24: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1236 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1237 PixelTraits<Orthanc::PixelFormat_RGB24>::PixelType pixel; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1238 pixel.red_ = red; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1239 pixel.green_ = green; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1240 pixel.blue_ = blue; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1241 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1242 BresenhamPixelWriter<Orthanc::PixelFormat_RGB24> writer(image, pixel); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1243 writer.DrawSegment(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1244 break; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1245 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1246 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1247 default: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1248 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1249 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1250 } |
853 | 1251 } |