annotate Core/Images/ImageProcessing.cpp @ 2964:6896a7c1cbe2

log
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Dec 2018 12:58:56 +0100
parents 7791eac62572
children 4e43e67f8ecf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 993
diff changeset
4 * Department, University Hospital of Liege, Belgium
2447
878b59270859 upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2423
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../PrecompiledHeaders.h"
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "ImageProcessing.h"
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
37 #include "PixelTraits.h"
2895
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2840
diff changeset
38 #include "../OrthancException.h"
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
40 #include <boost/math/special_functions/round.hpp>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
41
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <cassert>
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 namespace Orthanc
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
186 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
187 static void SetInternal(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
188 int64_t constant)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
212 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
213 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
214 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
215
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
216
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
217 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
218 static void GetMinMaxValueInternal(PixelType& minValue,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
219 PixelType& maxValue,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
220 const ImageAccessor& source)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
221 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
222 // Deal with the special case of empty image
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
223 if (source.GetWidth() == 0 ||
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
224 source.GetHeight() == 0)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
225 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
226 minValue = 0;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
227 maxValue = 0;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
228 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
229 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
230
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
231 minValue = std::numeric_limits<PixelType>::max();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
232 maxValue = std::numeric_limits<PixelType>::min();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
238 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
239 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
242 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
243 if (*p < minValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
244 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
245 minValue = *p;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
246 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
247
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
248 if (*p > maxValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
249 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
250 maxValue = *p;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
251 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
252 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
253 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
254 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
255
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
256
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
257
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
258 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
259 static void AddConstantInternal(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
260 int64_t constant)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
261 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
262 if (constant == 0)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
263 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
264 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
265 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
266
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
267 const int64_t minValue = std::numeric_limits<PixelType>::min();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
268 const int64_t maxValue = std::numeric_limits<PixelType>::max();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
274 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
275 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
278 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
279 int64_t v = static_cast<int64_t>(*p) + constant;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
280
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
281 if (v > maxValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
282 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
283 *p = std::numeric_limits<PixelType>::max();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
284 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
285 else if (v < minValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
286 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
287 *p = std::numeric_limits<PixelType>::min();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
288 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
289 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
290 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
291 *p = static_cast<PixelType>(v);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
292 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
293 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
294 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
295 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
296
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
297
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
303 {
1334
7f0aa3c0f659 code improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
304 if (std::abs(factor - 1.0f) <= std::numeric_limits<float>::epsilon())
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
305 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
306 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
307 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
308
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
309 const int64_t minValue = std::numeric_limits<PixelType>::min();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
310 const int64_t maxValue = std::numeric_limits<PixelType>::max();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
316 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
317 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
331
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
332 if (v > maxValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
333 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
334 *p = std::numeric_limits<PixelType>::max();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
335 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
336 else if (v < minValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
337 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
338 *p = std::numeric_limits<PixelType>::min();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
339 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
340 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
341 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
342 *p = static_cast<PixelType>(v);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
343 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
344 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
345 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
346 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
347
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
364 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
365 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
368 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
369 float v = (static_cast<float>(*p) + offset) * scaling;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
370
2482
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
371 if (v > maxFloatValue)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
372 {
2482
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
373 *p = maxPixelValue;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
376 {
2482
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
377 *p = minPixelValue;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
384 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
387 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
388 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
389 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
390 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
391
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
392
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 void ImageProcessing::Copy(ImageAccessor& target,
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 const ImageAccessor& source)
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 if (target.GetWidth() != source.GetWidth() ||
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 target.GetHeight() != source.GetHeight())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 throw OrthancException(ErrorCode_IncompatibleImageSize);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 if (target.GetFormat() != source.GetFormat())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 throw OrthancException(ErrorCode_IncompatibleImageFormat);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 for (unsigned int y = 0; y < source.GetHeight(); y++)
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
417
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 void ImageProcessing::Convert(ImageAccessor& target,
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 const ImageAccessor& source)
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 if (target.GetWidth() != source.GetWidth() ||
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 target.GetHeight() != source.GetHeight())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 throw OrthancException(ErrorCode_IncompatibleImageSize);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 if (source.GetFormat() == target.GetFormat())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 Copy(target, source);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 return;
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
647 if ((target.GetFormat() == PixelFormat_RGBA32 ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
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
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
785
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
786 void ImageProcessing::Set(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
787 int64_t value)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
788 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
789 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
790 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
793 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
794
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
797 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
809 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
816 default:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
817 throw OrthancException(ErrorCode_NotImplemented);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
818 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
819 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
820
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
898 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
899 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
900 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
901 case PixelFormat_Grayscale8:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
902 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
903 uint8_t a, b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
904 GetMinMaxValueInternal<uint8_t>(a, b, image);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
905 minValue = a;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
906 maxValue = b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
907 break;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
908 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
909
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
910 case PixelFormat_Grayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
911 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
912 uint16_t a, b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
913 GetMinMaxValueInternal<uint16_t>(a, b, image);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
914 minValue = a;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
915 maxValue = b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
916 break;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
917 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
928 case PixelFormat_SignedGrayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
929 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
930 int16_t a, b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
931 GetMinMaxValueInternal<int16_t>(a, b, image);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
932 minValue = a;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
933 maxValue = b;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
934 break;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
935 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
936
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
937 default:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
938 throw OrthancException(ErrorCode_NotImplemented);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
939 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
940 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
941
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2904
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
965
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
966 void ImageProcessing::AddConstant(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
967 int64_t value)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
968 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
969 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
970 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
971 case PixelFormat_Grayscale8:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
972 AddConstantInternal<uint8_t>(image, value);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
973 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
974
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
975 case PixelFormat_Grayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
976 AddConstantInternal<uint16_t>(image, value);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
977 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
978
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
979 case PixelFormat_SignedGrayscale16:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
980 AddConstantInternal<int16_t>(image, value);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
981 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
982
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
983 default:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
984 throw OrthancException(ErrorCode_NotImplemented);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
985 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
986 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
987
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
988
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
992 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
993 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
994 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1004 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1005
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1015 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1016
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1026 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1027
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1028 default:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1029 throw OrthancException(ErrorCode_NotImplemented);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1030 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1031 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1032
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1033
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1034 void ImageProcessing::ShiftScale(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1038 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1039 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1040 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1050 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1051
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1061 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1062
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1072 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1073
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1074 default:
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1075 throw OrthancException(ErrorCode_NotImplemented);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1076 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
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
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337 }