Mercurial > hg > orthanc
annotate Core/Images/ImageProcessing.cpp @ 3120:a323b75e5b08 db-changes
Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 14 Jan 2019 13:13:12 +0100 |
parents | 4e43e67f8ecf |
children | 53bb1f4b3844 |
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 |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2918
diff
changeset
|
5 * Copyright (C) 2017-2019 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" |
2895 | 38 #include "../OrthancException.h" |
853 | 39 |
863 | 40 #include <boost/math/special_functions/round.hpp> |
41 | |
853 | 42 #include <cassert> |
43 #include <string.h> | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
44 #include <limits> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
45 #include <stdint.h> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
46 |
853 | 47 namespace Orthanc |
48 { | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
49 template <typename TargetType, typename SourceType> |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
50 static void ConvertInternal(ImageAccessor& target, |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
51 const ImageAccessor& source) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
52 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
53 const TargetType minValue = std::numeric_limits<TargetType>::min(); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
54 const TargetType maxValue = std::numeric_limits<TargetType>::max(); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
55 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
56 const unsigned int width = source.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
57 const unsigned int height = source.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
58 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
59 for (unsigned int y = 0; y < height; y++) |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
60 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
61 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
62 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
63 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
64 for (unsigned int x = 0; x < width; x++, t++, s++) |
859
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 if (static_cast<int32_t>(*s) < static_cast<int32_t>(minValue)) |
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 = minValue; |
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 if (static_cast<int32_t>(*s) > static_cast<int32_t>(maxValue)) |
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 = maxValue; |
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 else |
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 *t = static_cast<TargetType>(*s); |
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 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
79 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
80 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
81 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
82 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
83 template <typename SourceType> |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
84 static void ConvertGrayscaleToFloat(ImageAccessor& target, |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
85 const ImageAccessor& source) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
86 { |
1994
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
87 assert(sizeof(float) == 4); |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
88 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
89 const unsigned int width = source.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
90 const unsigned int height = source.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
91 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
92 for (unsigned int y = 0; y < height; y++) |
1993
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 float* t = reinterpret_cast<float*>(target.GetRow(y)); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
95 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y)); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
96 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
97 for (unsigned int x = 0; x < width; x++, t++, s++) |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
98 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
99 *t = static_cast<float>(*s); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
100 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
101 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
102 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
103 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
104 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
105 template <PixelFormat TargetFormat> |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
106 static void ConvertFloatToGrayscale(ImageAccessor& target, |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
107 const ImageAccessor& source) |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
108 { |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
109 typedef typename PixelTraits<TargetFormat>::PixelType TargetType; |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
110 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
111 assert(sizeof(float) == 4); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
112 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
113 const unsigned int width = source.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
114 const unsigned int height = source.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
115 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
116 for (unsigned int y = 0; y < height; y++) |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
117 { |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
118 TargetType* q = reinterpret_cast<TargetType*>(target.GetRow(y)); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
119 const float* p = reinterpret_cast<const float*>(source.GetConstRow(y)); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
120 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
121 for (unsigned int x = 0; x < width; x++, p++, q++) |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
122 { |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
123 PixelTraits<TargetFormat>::FloatToPixel(*q, *p); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
124 } |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
125 } |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
126 } |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
127 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
128 |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
129 template <typename TargetType> |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
130 static void ConvertColorToGrayscale(ImageAccessor& target, |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
131 const ImageAccessor& source) |
993
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 assert(source.GetFormat() == PixelFormat_RGB24); |
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 const TargetType minValue = std::numeric_limits<TargetType>::min(); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
136 const TargetType maxValue = std::numeric_limits<TargetType>::max(); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
137 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
138 const unsigned int width = source.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
139 const unsigned int height = source.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
140 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
141 for (unsigned int y = 0; y < height; y++) |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
142 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
143 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y)); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
144 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
|
145 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
146 for (unsigned int x = 0; x < width; x++, t++, s += 3) |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
147 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
148 // 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
|
149 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
|
150 7152 * static_cast<int32_t>(s[1]) + |
2491
a9459c7d4bc2
fix color-to-grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2490
diff
changeset
|
151 0722 * static_cast<int32_t>(s[2])) / 10000; |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
152 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
153 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
|
154 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
155 *t = minValue; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
156 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
157 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
|
158 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
159 *t = maxValue; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
160 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
161 else |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
162 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
163 *t = static_cast<TargetType>(v); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
164 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
165 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
166 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
167 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
168 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
169 |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
170 static void MemsetZeroInternal(ImageAccessor& image) |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
171 { |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
172 const unsigned int height = image.GetHeight(); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
173 const size_t lineSize = image.GetBytesPerPixel() * image.GetWidth(); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
174 const size_t pitch = image.GetPitch(); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
175 |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
176 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetBuffer()); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
177 |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
178 for (unsigned int y = 0; y < height; y++) |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
179 { |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
180 memset(p, 0, lineSize); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
181 p += pitch; |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
182 } |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
183 } |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
184 |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
185 |
863 | 186 template <typename PixelType> |
187 static void SetInternal(ImageAccessor& image, | |
188 int64_t constant) | |
189 { | |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
190 if (constant == 0 && |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
191 (image.GetFormat() == PixelFormat_Grayscale8 || |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
192 image.GetFormat() == PixelFormat_Grayscale16 || |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
193 image.GetFormat() == PixelFormat_Grayscale32 || |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
194 image.GetFormat() == PixelFormat_Grayscale64 || |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
195 image.GetFormat() == PixelFormat_SignedGrayscale16)) |
863 | 196 { |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
197 MemsetZeroInternal(image); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
198 } |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
199 else |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
200 { |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
201 const unsigned int width = image.GetWidth(); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
202 const unsigned int height = image.GetHeight(); |
863 | 203 |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
204 for (unsigned int y = 0; y < height; y++) |
863 | 205 { |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
206 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
207 |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
208 for (unsigned int x = 0; x < width; x++, p++) |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
209 { |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
210 *p = static_cast<PixelType>(constant); |
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
211 } |
863 | 212 } |
213 } | |
214 } | |
215 | |
216 | |
217 template <typename PixelType> | |
218 static void GetMinMaxValueInternal(PixelType& minValue, | |
219 PixelType& maxValue, | |
220 const ImageAccessor& source) | |
221 { | |
222 // Deal with the special case of empty image | |
223 if (source.GetWidth() == 0 || | |
224 source.GetHeight() == 0) | |
225 { | |
226 minValue = 0; | |
227 maxValue = 0; | |
228 return; | |
229 } | |
230 | |
231 minValue = std::numeric_limits<PixelType>::max(); | |
232 maxValue = std::numeric_limits<PixelType>::min(); | |
233 | |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
234 const unsigned int height = source.GetHeight(); |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
235 const unsigned int width = source.GetWidth(); |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
236 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
237 for (unsigned int y = 0; y < height; y++) |
863 | 238 { |
239 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); | |
240 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
241 for (unsigned int x = 0; x < width; x++, p++) |
863 | 242 { |
243 if (*p < minValue) | |
244 { | |
245 minValue = *p; | |
246 } | |
247 | |
248 if (*p > maxValue) | |
249 { | |
250 maxValue = *p; | |
251 } | |
252 } | |
253 } | |
254 } | |
255 | |
256 | |
257 | |
258 template <typename PixelType> | |
259 static void AddConstantInternal(ImageAccessor& image, | |
260 int64_t constant) | |
261 { | |
262 if (constant == 0) | |
263 { | |
264 return; | |
265 } | |
266 | |
267 const int64_t minValue = std::numeric_limits<PixelType>::min(); | |
268 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
269 | |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
270 const unsigned int width = image.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
271 const unsigned int height = image.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
272 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
273 for (unsigned int y = 0; y < height; y++) |
863 | 274 { |
275 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
276 | |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
277 for (unsigned int x = 0; x < width; x++, p++) |
863 | 278 { |
279 int64_t v = static_cast<int64_t>(*p) + constant; | |
280 | |
281 if (v > maxValue) | |
282 { | |
876 | 283 *p = std::numeric_limits<PixelType>::max(); |
863 | 284 } |
285 else if (v < minValue) | |
286 { | |
876 | 287 *p = std::numeric_limits<PixelType>::min(); |
863 | 288 } |
289 else | |
290 { | |
291 *p = static_cast<PixelType>(v); | |
292 } | |
293 } | |
294 } | |
295 } | |
296 | |
297 | |
298 | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
299 template <typename PixelType, |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
300 bool UseRound> |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
301 static void MultiplyConstantInternal(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
302 float factor) |
863 | 303 { |
1334 | 304 if (std::abs(factor - 1.0f) <= std::numeric_limits<float>::epsilon()) |
863 | 305 { |
306 return; | |
307 } | |
308 | |
309 const int64_t minValue = std::numeric_limits<PixelType>::min(); | |
310 const int64_t maxValue = std::numeric_limits<PixelType>::max(); | |
311 | |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
312 const unsigned int width = image.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
313 const unsigned int height = image.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
314 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
315 for (unsigned int y = 0; y < height; y++) |
863 | 316 { |
317 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
318 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
319 for (unsigned int x = 0; x < width; x++, p++) |
863 | 320 { |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
321 int64_t v; |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
322 if (UseRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
323 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
324 // The "round" operation is very costly |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
325 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
|
326 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
327 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
328 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
329 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
|
330 } |
863 | 331 |
332 if (v > maxValue) | |
333 { | |
876 | 334 *p = std::numeric_limits<PixelType>::max(); |
863 | 335 } |
336 else if (v < minValue) | |
337 { | |
876 | 338 *p = std::numeric_limits<PixelType>::min(); |
863 | 339 } |
340 else | |
341 { | |
342 *p = static_cast<PixelType>(v); | |
343 } | |
344 } | |
345 } | |
346 } | |
347 | |
348 | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
349 template <typename PixelType, |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
350 bool UseRound> |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
351 static void ShiftScaleInternal(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
352 float offset, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
353 float scaling) |
863 | 354 { |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
355 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
|
356 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
|
357 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
|
358 const PixelType maxPixelValue = std::numeric_limits<PixelType>::max(); |
863 | 359 |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
360 const unsigned int height = image.GetHeight(); |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
361 const unsigned int width = image.GetWidth(); |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
362 |
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
363 for (unsigned int y = 0; y < height; y++) |
863 | 364 { |
365 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
366 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
367 for (unsigned int x = 0; x < width; x++, p++) |
863 | 368 { |
369 float v = (static_cast<float>(*p) + offset) * scaling; | |
370 | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
371 if (v > maxFloatValue) |
863 | 372 { |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
373 *p = maxPixelValue; |
863 | 374 } |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
375 else if (v < minFloatValue) |
863 | 376 { |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
377 *p = minPixelValue; |
863 | 378 } |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
379 else if (UseRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
380 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
381 // The "round" operation is very costly |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
382 *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
|
383 } |
863 | 384 else |
385 { | |
2482
509041cb57db
speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
386 *p = static_cast<PixelType>(v); |
863 | 387 } |
388 } | |
389 } | |
390 } | |
391 | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
392 |
853 | 393 void ImageProcessing::Copy(ImageAccessor& target, |
394 const ImageAccessor& source) | |
395 { | |
396 if (target.GetWidth() != source.GetWidth() || | |
397 target.GetHeight() != source.GetHeight()) | |
398 { | |
399 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
400 } | |
401 | |
402 if (target.GetFormat() != source.GetFormat()) | |
403 { | |
404 throw OrthancException(ErrorCode_IncompatibleImageFormat); | |
405 } | |
406 | |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
407 unsigned int lineSize = source.GetBytesPerPixel() * source.GetWidth(); |
853 | 408 |
409 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize); | |
410 | |
411 for (unsigned int y = 0; y < source.GetHeight(); y++) | |
412 { | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
413 memcpy(target.GetRow(y), source.GetConstRow(y), lineSize); |
853 | 414 } |
415 } | |
416 | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
417 |
853 | 418 void ImageProcessing::Convert(ImageAccessor& target, |
419 const ImageAccessor& source) | |
420 { | |
421 if (target.GetWidth() != source.GetWidth() || | |
422 target.GetHeight() != source.GetHeight()) | |
423 { | |
424 throw OrthancException(ErrorCode_IncompatibleImageSize); | |
425 } | |
426 | |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
427 const unsigned int width = source.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
428 const unsigned int height = source.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
429 |
853 | 430 if (source.GetFormat() == target.GetFormat()) |
431 { | |
432 Copy(target, source); | |
433 return; | |
434 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
435 |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
436 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
437 source.GetFormat() == PixelFormat_Grayscale8) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
438 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
439 ConvertInternal<uint16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
440 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
441 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
442 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
443 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
444 source.GetFormat() == PixelFormat_Grayscale8) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
445 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
446 ConvertInternal<int16_t, uint8_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
447 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
448 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
449 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
450 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
451 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
452 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
453 ConvertInternal<uint8_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
454 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
455 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
456 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
457 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
458 source.GetFormat() == PixelFormat_Grayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
459 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
460 ConvertInternal<int16_t, uint16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
461 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
462 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
463 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
464 if (target.GetFormat() == PixelFormat_Grayscale8 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
465 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
466 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
467 ConvertInternal<uint8_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
468 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
469 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
470 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
471 if (target.GetFormat() == PixelFormat_Grayscale16 && |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
472 source.GetFormat() == PixelFormat_SignedGrayscale16) |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
473 { |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
474 ConvertInternal<uint16_t, int16_t>(target, source); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
475 return; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
476 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
854
diff
changeset
|
477 |
993
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
478 if (target.GetFormat() == PixelFormat_Grayscale8 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
479 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
480 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
481 ConvertColorToGrayscale<uint8_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
482 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
483 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
484 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
485 if (target.GetFormat() == PixelFormat_Grayscale16 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
486 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
487 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
488 ConvertColorToGrayscale<uint16_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
489 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
490 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
491 |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
492 if (target.GetFormat() == PixelFormat_SignedGrayscale16 && |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
493 source.GetFormat() == PixelFormat_RGB24) |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
494 { |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
495 ConvertColorToGrayscale<int16_t>(target, source); |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
496 return; |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
497 } |
501880d76474
improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
498 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
499 if (target.GetFormat() == PixelFormat_Float32 && |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
500 source.GetFormat() == PixelFormat_Grayscale8) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
501 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
502 ConvertGrayscaleToFloat<uint8_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
503 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
504 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
505 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
506 if (target.GetFormat() == PixelFormat_Float32 && |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
507 source.GetFormat() == PixelFormat_Grayscale16) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
508 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
509 ConvertGrayscaleToFloat<uint16_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
510 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
511 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
512 |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
513 if (target.GetFormat() == PixelFormat_Float32 && |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
514 source.GetFormat() == PixelFormat_Grayscale32) |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
515 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
516 ConvertGrayscaleToFloat<uint32_t>(target, source); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
517 return; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
518 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
519 |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
520 if (target.GetFormat() == PixelFormat_Float32 && |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
521 source.GetFormat() == PixelFormat_SignedGrayscale16) |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
522 { |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
523 ConvertGrayscaleToFloat<int16_t>(target, source); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
524 return; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
525 } |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1992
diff
changeset
|
526 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
527 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
528 if (target.GetFormat() == PixelFormat_Grayscale8 && |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
529 source.GetFormat() == PixelFormat_RGBA32) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
530 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
531 for (unsigned int y = 0; y < height; y++) |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
532 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
533 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
|
534 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
535 for (unsigned int x = 0; x < width; x++, q++) |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
536 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
537 *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
|
538 7152 * static_cast<uint32_t>(p[1]) + |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
539 0722 * static_cast<uint32_t>(p[2])) / 10000); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
540 p += 4; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
541 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
542 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
543 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
544 return; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
545 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
546 |
2840
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
547 if (target.GetFormat() == PixelFormat_Grayscale8 && |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
548 source.GetFormat() == PixelFormat_BGRA32) |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
549 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
550 for (unsigned int y = 0; y < height; y++) |
2840
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
551 { |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
552 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
553 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
554 for (unsigned int x = 0; x < width; x++, q++) |
2840
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
555 { |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
556 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[2]) + |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
557 7152 * static_cast<uint32_t>(p[1]) + |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
558 0722 * static_cast<uint32_t>(p[0])) / 10000); |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
559 p += 4; |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
560 } |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
561 } |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
562 |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
563 return; |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
564 } |
f4c232bba1eb
bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2783
diff
changeset
|
565 |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
566 if (target.GetFormat() == PixelFormat_RGB24 && |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
567 source.GetFormat() == PixelFormat_RGBA32) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
568 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
569 for (unsigned int y = 0; y < height; y++) |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
570 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
571 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
572 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
573 for (unsigned int x = 0; x < width; x++) |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
574 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
575 q[0] = p[0]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
576 q[1] = p[1]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
577 q[2] = p[2]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
578 p += 4; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
579 q += 3; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
580 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
581 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
582 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
583 return; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
584 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
585 |
2252
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
586 if (target.GetFormat() == PixelFormat_RGB24 && |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
587 source.GetFormat() == PixelFormat_BGRA32) |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
588 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
589 for (unsigned int y = 0; y < height; y++) |
2252
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
590 { |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
591 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
|
592 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
593 for (unsigned int x = 0; x < width; x++) |
2252
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
594 { |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
595 q[0] = p[2]; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
596 q[1] = p[1]; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
597 q[2] = p[0]; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
598 p += 4; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
599 q += 3; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
600 } |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
601 } |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
602 |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
603 return; |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
604 } |
002b94046c69
colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
605 |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
606 if (target.GetFormat() == PixelFormat_RGBA32 && |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
607 source.GetFormat() == PixelFormat_RGB24) |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
608 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
609 for (unsigned int y = 0; y < height; y++) |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
610 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
611 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
612 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
613 for (unsigned int x = 0; x < width; x++) |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
614 { |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
615 q[0] = p[0]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
616 q[1] = p[1]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
617 q[2] = p[2]; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
618 q[3] = 255; // Set the alpha channel to full opacity |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
619 p += 3; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
620 q += 4; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
621 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
622 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
623 |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
624 return; |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
625 } |
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1334
diff
changeset
|
626 |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
627 if (target.GetFormat() == PixelFormat_RGB24 && |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
628 source.GetFormat() == PixelFormat_Grayscale8) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
629 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
630 for (unsigned int y = 0; y < height; y++) |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
631 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
632 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
|
633 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
634 for (unsigned int x = 0; x < width; x++) |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
635 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
636 q[0] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
637 q[1] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
638 q[2] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
639 p += 1; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
640 q += 3; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
641 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
642 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
643 |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
644 return; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
645 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
646 |
2650 | 647 if ((target.GetFormat() == PixelFormat_RGBA32 || |
648 target.GetFormat() == PixelFormat_BGRA32) && | |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
649 source.GetFormat() == PixelFormat_Grayscale8) |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
650 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
651 for (unsigned int y = 0; y < height; y++) |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
652 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
653 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
|
654 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
655 for (unsigned int x = 0; x < width; x++) |
1992
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
656 { |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
657 q[0] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
658 q[1] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
659 q[2] = *p; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
660 q[3] = 255; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
661 p += 1; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
662 q += 4; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
663 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
664 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
665 |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
666 return; |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
667 } |
9161e3ef0d17
new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
668 |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
669 if (target.GetFormat() == PixelFormat_BGRA32 && |
2495
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
670 source.GetFormat() == PixelFormat_Grayscale16) |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
671 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
672 for (unsigned int y = 0; y < height; y++) |
2495
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
673 { |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
674 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
|
675 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
676 for (unsigned int x = 0; x < width; x++) |
2495
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
677 { |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
678 uint8_t value = (*p < 256 ? *p : 255); |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
679 q[0] = value; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
680 q[1] = value; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
681 q[2] = value; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
682 q[3] = 255; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
683 p += 1; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
684 q += 4; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
685 } |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
686 } |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
687 |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
688 return; |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
689 } |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
690 |
cd7b854dbc05
convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2491
diff
changeset
|
691 if (target.GetFormat() == PixelFormat_BGRA32 && |
2496
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
692 source.GetFormat() == PixelFormat_SignedGrayscale16) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
693 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
694 for (unsigned int y = 0; y < height; y++) |
2496
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
695 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
696 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
|
697 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
698 for (unsigned int x = 0; x < width; x++) |
2496
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
699 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
700 uint8_t value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
701 if (*p < 0) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
702 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
703 value = 0; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
704 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
705 else if (*p > 255) |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
706 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
707 value = 255; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
708 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
709 else |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
710 { |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
711 value = static_cast<uint8_t>(*p); |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
712 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
713 |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
714 q[0] = value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
715 q[1] = value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
716 q[2] = value; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
717 q[3] = 255; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
718 p += 1; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
719 q += 4; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
720 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
721 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
722 |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
723 return; |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
724 } |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
725 |
3d65adee289a
int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2495
diff
changeset
|
726 if (target.GetFormat() == PixelFormat_BGRA32 && |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
727 source.GetFormat() == PixelFormat_RGB24) |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
728 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
729 for (unsigned int y = 0; y < height; y++) |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
730 { |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
731 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
|
732 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
733 for (unsigned int x = 0; x < width; x++) |
2100
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
734 { |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
735 q[0] = p[2]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
736 q[1] = p[1]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
737 q[2] = p[0]; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
738 q[3] = 255; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
739 p += 3; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
740 q += 4; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
741 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
742 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
743 |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
744 return; |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
745 } |
1554fc153a93
conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2089
diff
changeset
|
746 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
747 if (target.GetFormat() == PixelFormat_RGB24 && |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
748 source.GetFormat() == PixelFormat_RGB48) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
749 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
750 for (unsigned int y = 0; y < height; y++) |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
751 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
752 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
|
753 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
754 for (unsigned int x = 0; x < width; x++) |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
755 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
756 q[0] = p[0] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
757 q[1] = p[1] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
758 q[2] = p[2] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
759 p += 3; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
760 q += 3; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
761 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
762 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
763 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
764 return; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
765 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
766 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
767 if (target.GetFormat() == PixelFormat_Grayscale16 && |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
768 source.GetFormat() == PixelFormat_Float32) |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
769 { |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
770 ConvertFloatToGrayscale<PixelFormat_Grayscale16>(target, source); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
771 return; |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
772 } |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
773 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
774 if (target.GetFormat() == PixelFormat_Grayscale8 && |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
775 source.GetFormat() == PixelFormat_Float32) |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
776 { |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
777 ConvertFloatToGrayscale<PixelFormat_Grayscale8>(target, source); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
778 return; |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
779 } |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
780 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
781 throw OrthancException(ErrorCode_NotImplemented); |
853 | 782 } |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
783 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
784 |
863 | 785 |
786 void ImageProcessing::Set(ImageAccessor& image, | |
787 int64_t value) | |
788 { | |
789 switch (image.GetFormat()) | |
790 { | |
791 case PixelFormat_Grayscale8: | |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
792 SetInternal<uint8_t>(image, value); |
863 | 793 return; |
794 | |
795 case PixelFormat_Grayscale16: | |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
796 SetInternal<uint16_t>(image, value); |
863 | 797 return; |
798 | |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
799 case PixelFormat_Grayscale32: |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
800 SetInternal<uint32_t>(image, value); |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
801 return; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
802 |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
803 case PixelFormat_Grayscale64: |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
804 SetInternal<uint64_t>(image, value); |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
805 return; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2496
diff
changeset
|
806 |
863 | 807 case PixelFormat_SignedGrayscale16: |
2902
e80b38fb22c6
fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
808 SetInternal<int16_t>(image, value); |
863 | 809 return; |
810 | |
1994
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
811 case PixelFormat_Float32: |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
812 assert(sizeof(float) == 4); |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
813 SetInternal<float>(image, value); |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
814 return; |
4d099fee5eca
ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
815 |
863 | 816 default: |
817 throw OrthancException(ErrorCode_NotImplemented); | |
818 } | |
819 } | |
820 | |
821 | |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
822 void ImageProcessing::Set(ImageAccessor& image, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
823 uint8_t red, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
824 uint8_t green, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
825 uint8_t blue, |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
826 uint8_t alpha) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
827 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
828 uint8_t p[4]; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
829 unsigned int size; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
830 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
831 switch (image.GetFormat()) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
832 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
833 case PixelFormat_RGBA32: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
834 p[0] = red; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
835 p[1] = green; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
836 p[2] = blue; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
837 p[3] = alpha; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
838 size = 4; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
839 break; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
840 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
841 case PixelFormat_BGRA32: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
842 p[0] = blue; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
843 p[1] = green; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
844 p[2] = red; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
845 p[3] = alpha; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
846 size = 4; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
847 break; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
848 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
849 case PixelFormat_RGB24: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
850 p[0] = red; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
851 p[1] = green; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
852 p[2] = blue; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
853 size = 3; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
854 break; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
855 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
856 default: |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
857 throw OrthancException(ErrorCode_NotImplemented); |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
858 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
859 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
860 const unsigned int width = image.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
861 const unsigned int height = image.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
862 |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
863 for (unsigned int y = 0; y < height; y++) |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
864 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
865 uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y)); |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
866 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
867 for (unsigned int x = 0; x < width; x++) |
2089
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
868 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
869 for (unsigned int i = 0; i < size; i++) |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
870 { |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
871 q[i] = p[i]; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
872 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
873 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
874 q += size; |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
875 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
876 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
877 } |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
878 |
7a969f235adf
PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1994
diff
changeset
|
879 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
880 void ImageProcessing::ShiftRight(ImageAccessor& image, |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
881 unsigned int shift) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
882 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
883 if (image.GetWidth() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
884 image.GetHeight() == 0 || |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
885 shift == 0) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
886 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
887 // Nothing to do |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
888 return; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
889 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
890 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
891 throw OrthancException(ErrorCode_NotImplemented); |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
892 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
893 |
863 | 894 |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
895 void ImageProcessing::GetMinMaxIntegerValue(int64_t& minValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
896 int64_t& maxValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
897 const ImageAccessor& image) |
863 | 898 { |
899 switch (image.GetFormat()) | |
900 { | |
901 case PixelFormat_Grayscale8: | |
902 { | |
903 uint8_t a, b; | |
904 GetMinMaxValueInternal<uint8_t>(a, b, image); | |
905 minValue = a; | |
906 maxValue = b; | |
907 break; | |
908 } | |
909 | |
910 case PixelFormat_Grayscale16: | |
911 { | |
912 uint16_t a, b; | |
913 GetMinMaxValueInternal<uint16_t>(a, b, image); | |
914 minValue = a; | |
915 maxValue = b; | |
916 break; | |
917 } | |
918 | |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
919 case PixelFormat_Grayscale32: |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
920 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
921 uint32_t a, b; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
922 GetMinMaxValueInternal<uint32_t>(a, b, image); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
923 minValue = a; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
924 maxValue = b; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
925 break; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
926 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
927 |
863 | 928 case PixelFormat_SignedGrayscale16: |
929 { | |
930 int16_t a, b; | |
931 GetMinMaxValueInternal<int16_t>(a, b, image); | |
932 minValue = a; | |
933 maxValue = b; | |
934 break; | |
935 } | |
936 | |
937 default: | |
938 throw OrthancException(ErrorCode_NotImplemented); | |
939 } | |
940 } | |
941 | |
942 | |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
943 void ImageProcessing::GetMinMaxFloatValue(float& minValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
944 float& maxValue, |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
945 const ImageAccessor& image) |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
946 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
947 switch (image.GetFormat()) |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
948 { |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
949 case PixelFormat_Float32: |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
950 { |
2918 | 951 assert(sizeof(float) == 4); |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
952 float a, b; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
953 GetMinMaxValueInternal<float>(a, b, image); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
954 minValue = a; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
955 maxValue = b; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
956 break; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
957 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
958 |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
959 default: |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
960 throw OrthancException(ErrorCode_NotImplemented); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
961 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
962 } |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
963 |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
964 |
863 | 965 |
966 void ImageProcessing::AddConstant(ImageAccessor& image, | |
967 int64_t value) | |
968 { | |
969 switch (image.GetFormat()) | |
970 { | |
971 case PixelFormat_Grayscale8: | |
972 AddConstantInternal<uint8_t>(image, value); | |
973 return; | |
974 | |
975 case PixelFormat_Grayscale16: | |
976 AddConstantInternal<uint16_t>(image, value); | |
977 return; | |
978 | |
979 case PixelFormat_SignedGrayscale16: | |
980 AddConstantInternal<int16_t>(image, value); | |
981 return; | |
982 | |
983 default: | |
984 throw OrthancException(ErrorCode_NotImplemented); | |
985 } | |
986 } | |
987 | |
988 | |
989 void ImageProcessing::MultiplyConstant(ImageAccessor& image, | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
990 float factor, |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
991 bool useRound) |
863 | 992 { |
993 switch (image.GetFormat()) | |
994 { | |
995 case PixelFormat_Grayscale8: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
996 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
997 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
998 MultiplyConstantInternal<uint8_t, true>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
999 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1000 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1001 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1002 MultiplyConstantInternal<uint8_t, false>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1003 } |
863 | 1004 return; |
1005 | |
1006 case PixelFormat_Grayscale16: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1007 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1008 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1009 MultiplyConstantInternal<uint16_t, true>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1010 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1011 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1012 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1013 MultiplyConstantInternal<uint16_t, false>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1014 } |
863 | 1015 return; |
1016 | |
1017 case PixelFormat_SignedGrayscale16: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1018 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1019 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1020 MultiplyConstantInternal<int16_t, true>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1021 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1022 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1023 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1024 MultiplyConstantInternal<int16_t, false>(image, factor); |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1025 } |
863 | 1026 return; |
1027 | |
1028 default: | |
1029 throw OrthancException(ErrorCode_NotImplemented); | |
1030 } | |
1031 } | |
1032 | |
1033 | |
1034 void ImageProcessing::ShiftScale(ImageAccessor& image, | |
1035 float offset, | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1036 float scaling, |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1037 bool useRound) |
863 | 1038 { |
1039 switch (image.GetFormat()) | |
1040 { | |
1041 case PixelFormat_Grayscale8: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1042 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1043 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1044 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
|
1045 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1046 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1047 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1048 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
|
1049 } |
863 | 1050 return; |
1051 | |
1052 case PixelFormat_Grayscale16: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1053 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1054 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1055 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
|
1056 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1057 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1058 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1059 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
|
1060 } |
863 | 1061 return; |
1062 | |
1063 case PixelFormat_SignedGrayscale16: | |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1064 if (useRound) |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1065 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1066 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
|
1067 } |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1068 else |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1069 { |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
1070 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
|
1071 } |
863 | 1072 return; |
1073 | |
1074 default: | |
1075 throw OrthancException(ErrorCode_NotImplemented); | |
1076 } | |
1077 } | |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1078 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1079 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1080 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
|
1081 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1082 const unsigned int width = image.GetWidth(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1083 const unsigned int height = image.GetHeight(); |
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1084 |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1085 switch (image.GetFormat()) |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1086 { |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1087 case PixelFormat_Grayscale8: |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1088 { |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1089 for (unsigned int y = 0; y < height; y++) |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1090 { |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1091 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
|
1092 |
2904
0dd54ee073db
float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2902
diff
changeset
|
1093 for (unsigned int x = 0; x < width; x++, p++) |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1094 { |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1095 *p = 255 - (*p); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1096 } |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1097 } |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1098 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1099 return; |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1100 } |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1101 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1102 default: |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1103 throw OrthancException(ErrorCode_NotImplemented); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1104 } |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2252
diff
changeset
|
1105 } |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1106 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1107 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1108 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1109 namespace |
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 template <Orthanc::PixelFormat Format> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1112 class BresenhamPixelWriter |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1113 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1114 private: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1115 typedef typename PixelTraits<Format>::PixelType PixelType; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1116 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1117 Orthanc::ImageAccessor& image_; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1118 PixelType value_; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1119 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1120 void PlotLineLow(int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1121 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1122 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1123 int y1) |
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 int dx = x1 - x0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1126 int dy = y1 - y0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1127 int yi = 1; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1128 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1129 if (dy < 0) |
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 yi = -1; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1132 dy = -dy; |
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 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1135 int d = 2 * dy - dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1136 int y = y0; |
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 for (int x = x0; x <= x1; x++) |
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 Write(x, y); |
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 if (d > 0) |
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 y = y + yi; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1145 d = d - 2 * dx; |
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 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1148 d = d + 2*dy; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1149 } |
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 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1152 void PlotLineHigh(int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1153 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1154 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1155 int y1) |
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 int dx = x1 - x0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1158 int dy = y1 - y0; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1159 int xi = 1; |
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 if (dx < 0) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1162 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1163 xi = -1; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1164 dx = -dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1165 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1166 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1167 int d = 2 * dx - dy; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1168 int x = x0; |
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 for (int y = y0; y <= y1; y++) |
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 Write(x, y); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1173 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1174 if (d > 0) |
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 x = x + xi; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1177 d = d - 2 * dy; |
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 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1180 d = d + 2 * dx; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1181 } |
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 public: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1185 BresenhamPixelWriter(Orthanc::ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1186 int64_t value) : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1187 image_(image), |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1188 value_(PixelTraits<Format>::IntegerToPixel(value)) |
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 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1192 BresenhamPixelWriter(Orthanc::ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1193 const PixelType& value) : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1194 image_(image), |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1195 value_(value) |
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 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1198 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1199 void Write(int x, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1200 int y) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1201 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1202 if (x >= 0 && |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1203 y >= 0 && |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1204 static_cast<unsigned int>(x) < image_.GetWidth() && |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1205 static_cast<unsigned int>(y) < image_.GetHeight()) |
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 PixelType* p = reinterpret_cast<PixelType*>(image_.GetRow(y)); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1208 p[x] = value_; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1209 } |
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 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1212 void DrawSegment(int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1213 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1214 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1215 int y1) |
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 // This is an implementation of Bresenham's line algorithm |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1218 // 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
|
1219 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1220 if (abs(y1 - y0) < abs(x1 - x0)) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1221 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1222 if (x0 > x1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1223 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1224 PlotLineLow(x1, y1, x0, y0); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1225 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1226 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1227 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1228 PlotLineLow(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1229 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1230 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1231 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1232 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1233 if (y0 > y1) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1234 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1235 PlotLineHigh(x1, y1, x0, y0); |
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 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1238 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1239 PlotLineHigh(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1240 } |
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 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1243 }; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1244 } |
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 void ImageProcessing::DrawLineSegment(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1248 int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1249 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1250 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1251 int y1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1252 int64_t value) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1253 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1254 switch (image.GetFormat()) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1255 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1256 case Orthanc::PixelFormat_Grayscale8: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1257 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1258 BresenhamPixelWriter<Orthanc::PixelFormat_Grayscale8> writer(image, value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1259 writer.DrawSegment(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1260 break; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1261 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1262 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1263 case Orthanc::PixelFormat_Grayscale16: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1264 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1265 BresenhamPixelWriter<Orthanc::PixelFormat_Grayscale16> writer(image, value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1266 writer.DrawSegment(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1267 break; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1268 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1269 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1270 case Orthanc::PixelFormat_SignedGrayscale16: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1271 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1272 BresenhamPixelWriter<Orthanc::PixelFormat_SignedGrayscale16> writer(image, value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1273 writer.DrawSegment(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1274 break; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1275 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1276 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1277 default: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1278 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1279 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1280 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1281 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1282 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1283 void ImageProcessing::DrawLineSegment(ImageAccessor& image, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1284 int x0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1285 int y0, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1286 int x1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1287 int y1, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1288 uint8_t red, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1289 uint8_t green, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1290 uint8_t blue, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1291 uint8_t alpha) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1292 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1293 switch (image.GetFormat()) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1294 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1295 case Orthanc::PixelFormat_BGRA32: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1296 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1297 PixelTraits<Orthanc::PixelFormat_BGRA32>::PixelType pixel; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1298 pixel.red_ = red; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1299 pixel.green_ = green; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1300 pixel.blue_ = blue; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1301 pixel.alpha_ = alpha; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1302 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1303 BresenhamPixelWriter<Orthanc::PixelFormat_BGRA32> writer(image, pixel); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1304 writer.DrawSegment(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1305 break; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1306 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1307 |
2783
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1308 case Orthanc::PixelFormat_RGBA32: |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1309 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1310 PixelTraits<Orthanc::PixelFormat_RGBA32>::PixelType pixel; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1311 pixel.red_ = red; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1312 pixel.green_ = green; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1313 pixel.blue_ = blue; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1314 pixel.alpha_ = alpha; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1315 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1316 BresenhamPixelWriter<Orthanc::PixelFormat_RGBA32> writer(image, pixel); |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1317 writer.DrawSegment(x0, y0, x1, y1); |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1318 break; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1319 } |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2650
diff
changeset
|
1320 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1321 case Orthanc::PixelFormat_RGB24: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1322 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1323 PixelTraits<Orthanc::PixelFormat_RGB24>::PixelType pixel; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1324 pixel.red_ = red; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1325 pixel.green_ = green; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1326 pixel.blue_ = blue; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1327 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1328 BresenhamPixelWriter<Orthanc::PixelFormat_RGB24> writer(image, pixel); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1329 writer.DrawSegment(x0, y0, x1, y1); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1330 break; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1331 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1332 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1333 default: |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1334 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1335 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2488
diff
changeset
|
1336 } |
853 | 1337 } |