annotate OrthancFramework/Sources/Images/ImageProcessing.cpp @ 5853:4d932683049d get-scu tip

very first implementation of C-Get SCU
author Alain Mazy <am@orthanc.team>
date Tue, 29 Oct 2024 17:25:49 +0100
parents 7aef730c0859
children
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4083
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4083
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4083
diff changeset
12 * the License, or (at your option) any later version.
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
13 *
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4083
diff changeset
17 * Lesser General Public License for more details.
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4083
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4083
diff changeset
20 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4083
diff changeset
21 * <http://www.gnu.org/licenses/>.
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../PrecompiledHeaders.h"
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "ImageProcessing.h"
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
3502
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
28 #include "Image.h"
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
29 #include "ImageTraits.h"
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
30 #include "PixelTraits.h"
2895
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2840
diff changeset
31 #include "../OrthancException.h"
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3585
113a9643e8bb Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3565
diff changeset
33 #ifdef __EMSCRIPTEN__
113a9643e8bb Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3565
diff changeset
34 /*
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
35 Avoid this error:
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
36 -----------------
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
37 .../boost/math/special_functions/round.hpp:118:12: warning: implicit conversion from 'std::__2::numeric_limits<long long>::type' (aka 'long long') to 'float' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-int-float-conversion]
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
38 .../mnt/c/osi/dev/orthanc/Core/Images/ImageProcessing.cpp:333:28: note: in instantiation of function template specialization 'boost::math::llround<float>' requested here
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
39 .../mnt/c/osi/dev/orthanc/Core/Images/ImageProcessing.cpp:1006:9: note: in instantiation of function template specialization 'Orthanc::MultiplyConstantInternal<unsigned char, true>' requested here
3585
113a9643e8bb Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3565
diff changeset
40 */
113a9643e8bb Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3565
diff changeset
41 #pragma GCC diagnostic ignored "-Wimplicit-int-float-conversion"
113a9643e8bb Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3565
diff changeset
42 #endif
113a9643e8bb Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3565
diff changeset
43
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
44 #include <boost/math/special_functions/round.hpp>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
45
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
46 #include <algorithm>
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 #include <cassert>
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
48 #include <limits>
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
49 #include <list>
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
50 #include <map>
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
51 #include <stdint.h>
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
52 #include <string.h>
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
53
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 namespace Orthanc
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
56 ImageProcessing::ImagePoint::ImagePoint(int32_t x,
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
57 int32_t y) :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
58 x_(x),
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
59 y_(y)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
60 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
61 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
62
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
63 int32_t ImageProcessing::ImagePoint::GetX() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
64 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
65 return x_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
66 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
67
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
68 int32_t ImageProcessing::ImagePoint::GetY() const
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
69 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
70 return y_;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
71 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
72
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
73 void ImageProcessing::ImagePoint::Set(int32_t x, int32_t y)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
74 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
75 x_ = x;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
76 y_ = y;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
77 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4297
diff changeset
78
4056
55727d85f419 fix for msvc2008
s.jodogne@gmail.com
parents: 4044
diff changeset
79 void ImageProcessing::ImagePoint::ClipTo(int32_t minX, int32_t maxX, int32_t minY, int32_t maxY)
55727d85f419 fix for msvc2008
s.jodogne@gmail.com
parents: 4044
diff changeset
80 {
55727d85f419 fix for msvc2008
s.jodogne@gmail.com
parents: 4044
diff changeset
81 x_ = std::max(minX, std::min(maxX, x_));
55727d85f419 fix for msvc2008
s.jodogne@gmail.com
parents: 4044
diff changeset
82 y_ = std::max(minY, std::min(maxY, y_));
55727d85f419 fix for msvc2008
s.jodogne@gmail.com
parents: 4044
diff changeset
83 }
55727d85f419 fix for msvc2008
s.jodogne@gmail.com
parents: 4044
diff changeset
84
3265
59a184cbb596 ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents: 3259
diff changeset
85 double ImageProcessing::ImagePoint::GetDistanceTo(const ImagePoint& other) const
59a184cbb596 ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents: 3259
diff changeset
86 {
59a184cbb596 ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents: 3259
diff changeset
87 double dx = (double)(other.GetX() - GetX());
59a184cbb596 ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents: 3259
diff changeset
88 double dy = (double)(other.GetY() - GetY());
59a184cbb596 ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents: 3259
diff changeset
89 return sqrt(dx * dx + dy * dy);
59a184cbb596 ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents: 3259
diff changeset
90 }
59a184cbb596 ImagePoint::Set + GetDistanceTo
Alain Mazy <alain@mazy.be>
parents: 3259
diff changeset
91
3565
2999a6e9456b ImageProcessing::ImagePoint::GetDistanceToLine
Alain Mazy <alain@mazy.be>
parents: 3550
diff changeset
92 double ImageProcessing::ImagePoint::GetDistanceToLine(double a, double b, double c) const // where ax + by + c = 0 is the equation of the line
2999a6e9456b ImageProcessing::ImagePoint::GetDistanceToLine
Alain Mazy <alain@mazy.be>
parents: 3550
diff changeset
93 {
2999a6e9456b ImageProcessing::ImagePoint::GetDistanceToLine
Alain Mazy <alain@mazy.be>
parents: 3550
diff changeset
94 return std::abs(a * static_cast<double>(GetX()) + b * static_cast<double>(GetY()) + c) / pow(a * a + b * b, 0.5);
2999a6e9456b ImageProcessing::ImagePoint::GetDistanceToLine
Alain Mazy <alain@mazy.be>
parents: 3550
diff changeset
95 }
2999a6e9456b ImageProcessing::ImagePoint::GetDistanceToLine
Alain Mazy <alain@mazy.be>
parents: 3550
diff changeset
96
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
97 template <typename TargetType, typename SourceType>
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
98 static void ConvertInternal(ImageAccessor& target,
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
99 const ImageAccessor& source)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
100 {
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
101 // WARNING - "::min()" should be replaced by "::lowest()" if
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
102 // dealing with float or double (which is not the case so far)
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
103 assert(sizeof(TargetType) <= 2); // Safeguard to remember about "float/double"
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
104 const TargetType minValue = std::numeric_limits<TargetType>::min();
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
105 const TargetType maxValue = std::numeric_limits<TargetType>::max();
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
106
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
107 const unsigned int width = source.GetWidth();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
108 const unsigned int height = source.GetHeight();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
109
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
110 for (unsigned int y = 0; y < height; y++)
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
111 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
112 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y));
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
113 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y));
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
114
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
115 for (unsigned int x = 0; x < width; x++, t++, s++)
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
116 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
117 if (static_cast<int32_t>(*s) < static_cast<int32_t>(minValue))
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
118 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
119 *t = minValue;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
120 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
121 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
122 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
123 *t = maxValue;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
124 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
125 else
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
126 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
127 *t = static_cast<TargetType>(*s);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
128 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
129 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
130 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
131 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
132
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
133
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
134 template <typename SourceType>
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
135 static void ConvertGrayscaleToFloat(ImageAccessor& target,
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
136 const ImageAccessor& source)
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
137 {
1994
4d099fee5eca ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
138 assert(sizeof(float) == 4);
4d099fee5eca ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
139
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
140 const unsigned int width = source.GetWidth();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
141 const unsigned int height = source.GetHeight();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
142
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
143 for (unsigned int y = 0; y < height; y++)
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
144 {
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
145 float* t = reinterpret_cast<float*>(target.GetRow(y));
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
146 const SourceType* s = reinterpret_cast<const SourceType*>(source.GetConstRow(y));
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
147
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
148 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
149 {
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
150 *t = static_cast<float>(*s);
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
151 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
152 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
153 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
154
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
155
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
156 template <PixelFormat TargetFormat>
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
157 static void ConvertFloatToGrayscale(ImageAccessor& target,
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
158 const ImageAccessor& source)
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
159 {
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
160 typedef typename PixelTraits<TargetFormat>::PixelType TargetType;
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
161
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
162 assert(sizeof(float) == 4);
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
163
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
164 const unsigned int width = source.GetWidth();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
165 const unsigned int height = source.GetHeight();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
166
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
167 for (unsigned int y = 0; y < height; y++)
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
168 {
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
169 TargetType* q = reinterpret_cast<TargetType*>(target.GetRow(y));
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
170 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
171
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
172 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
173 {
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
174 PixelTraits<TargetFormat>::FloatToPixel(*q, *p);
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
175 }
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
176 }
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
177 }
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
178
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
179
993
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
180 template <typename TargetType>
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
181 static void ConvertColorToGrayscale(ImageAccessor& target,
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
182 const ImageAccessor& source)
993
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
183 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
184 assert(source.GetFormat() == PixelFormat_RGB24);
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
185
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
186 // WARNING - "::min()" should be replaced by "::lowest()" if
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
187 // dealing with float or double (which is not the case so far)
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
188 assert(sizeof(TargetType) <= 2); // Safeguard to remember about "float/double"
993
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
189 const TargetType minValue = std::numeric_limits<TargetType>::min();
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
190 const TargetType maxValue = std::numeric_limits<TargetType>::max();
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
191
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
192 const unsigned int width = source.GetWidth();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
193 const unsigned int height = source.GetHeight();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
194
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
195 for (unsigned int y = 0; y < height; y++)
993
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
196 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
197 TargetType* t = reinterpret_cast<TargetType*>(target.GetRow(y));
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
198 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
199
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
200 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
201 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
202 // 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
203 int32_t v = (2126 * static_cast<int32_t>(s[0]) +
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
204 7152 * static_cast<int32_t>(s[1]) +
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
205 0722 * static_cast<int32_t>(s[2])) / 10000;
993
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
206
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
207 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
208 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
209 *t = minValue;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
210 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
211 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
212 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
213 *t = maxValue;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
214 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
215 else
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
216 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
217 *t = static_cast<TargetType>(v);
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
218 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
219 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
220 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
221 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
222
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
223
2902
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
224 static void MemsetZeroInternal(ImageAccessor& image)
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
225 {
2902
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
226 const unsigned int height = image.GetHeight();
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
227 const size_t lineSize = image.GetBytesPerPixel() * image.GetWidth();
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
228 const size_t pitch = image.GetPitch();
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
229
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
230 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
231
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
232 for (unsigned int y = 0; y < height; y++)
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
233 {
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
234 memset(p, 0, lineSize);
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
235 p += pitch;
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
236 }
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
237 }
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
238
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
239
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
240 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
241 static void SetInternal(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
242 int64_t constant)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
243 {
2902
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
244 if (constant == 0 &&
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
245 (image.GetFormat() == PixelFormat_Grayscale8 ||
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
246 image.GetFormat() == PixelFormat_Grayscale16 ||
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
247 image.GetFormat() == PixelFormat_Grayscale32 ||
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
248 image.GetFormat() == PixelFormat_Grayscale64 ||
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
249 image.GetFormat() == PixelFormat_SignedGrayscale16))
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
250 {
2902
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
251 MemsetZeroInternal(image);
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
252 }
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
253 else
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
254 {
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
255 const unsigned int width = image.GetWidth();
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
256 const unsigned int height = image.GetHeight();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
257
2902
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
258 for (unsigned int y = 0; y < height; y++)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
259 {
2902
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
260 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
261
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
262 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
263 {
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
264 *p = static_cast<PixelType>(constant);
e80b38fb22c6 fix ImageProcessing::Set() for subregions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2895
diff changeset
265 }
863
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 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
268 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
269
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
270
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
271 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
272 static void GetMinMaxValueInternal(PixelType& minValue,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
273 PixelType& maxValue,
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
274 const ImageAccessor& source,
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
275 const PixelType LowestValue = std::numeric_limits<PixelType>::min())
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
276 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
277 // Deal with the special case of empty image
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
278 if (source.GetWidth() == 0 ||
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
279 source.GetHeight() == 0)
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 minValue = 0;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
282 maxValue = 0;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
283 return;
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
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
286 minValue = std::numeric_limits<PixelType>::max();
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
287 maxValue = LowestValue;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
288
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
289 const unsigned int height = source.GetHeight();
2482
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
290 const unsigned int width = source.GetWidth();
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
291
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
292 for (unsigned int y = 0; y < height; y++)
863
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 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
295
2482
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
296 for (unsigned int x = 0; x < width; x++, p++)
863
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 if (*p < minValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
299 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
300 minValue = *p;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
301 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
302
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
303 if (*p > maxValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
304 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
305 maxValue = *p;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
306 }
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 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
310
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
311
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
312
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
313 template <typename PixelType>
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
314 static void AddConstantInternal(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
315 int64_t constant)
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 if (constant == 0)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
318 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
319 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
320 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
321
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
322 // WARNING - "::min()" should be replaced by "::lowest()" if
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
323 // dealing with float or double (which is not the case so far)
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
324 assert(sizeof(PixelType) <= 2); // Safeguard to remember about "float/double"
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
325 const int64_t minValue = std::numeric_limits<PixelType>::min();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
326 const int64_t maxValue = std::numeric_limits<PixelType>::max();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
327
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
328 const unsigned int width = image.GetWidth();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
329 const unsigned int height = image.GetHeight();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
330
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
331 for (unsigned int y = 0; y < height; y++)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
332 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
333 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
334
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
335 for (unsigned int x = 0; x < width; x++, p++)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
336 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
337 int64_t v = static_cast<int64_t>(*p) + constant;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
338
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
339 if (v > maxValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
340 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
341 *p = std::numeric_limits<PixelType>::max();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
342 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
343 else if (v < minValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
344 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
345 *p = std::numeric_limits<PixelType>::min();
863
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 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
348 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
349 *p = static_cast<PixelType>(v);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
350 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
351 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
352 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
353 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
354
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
355
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
356
2488
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
357 template <typename PixelType,
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
358 bool UseRound>
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
359 static void MultiplyConstantInternal(ImageAccessor& image,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
360 float factor)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
361 {
1334
7f0aa3c0f659 code improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
362 if (std::abs(factor - 1.0f) <= std::numeric_limits<float>::epsilon())
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
363 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
364 return;
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
365 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
366
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
367 // WARNING - "::min()" should be replaced by "::lowest()" if
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
368 // dealing with float or double (which is not the case so far)
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
369 assert(sizeof(PixelType) <= 2); // Safeguard to remember about "float/double"
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
370 const int64_t minValue = std::numeric_limits<PixelType>::min();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
371 const int64_t maxValue = std::numeric_limits<PixelType>::max();
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
372
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
373 const unsigned int width = image.GetWidth();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
374 const unsigned int height = image.GetHeight();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
375
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
376 for (unsigned int y = 0; y < height; y++)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
377 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
378 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
379
2482
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
380 for (unsigned int x = 0; x < width; x++, p++)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
381 {
2488
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
382 int64_t v;
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
383 if (UseRound)
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
384 {
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
385 assert(sizeof(long long) == sizeof(int64_t));
2488
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
386 // The "round" operation is very costly
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
387 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
388 }
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
389 else
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
390 {
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
391 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
392 }
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
393
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
394 if (v > maxValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
395 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
396 *p = std::numeric_limits<PixelType>::max();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
397 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
398 else if (v < minValue)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
399 {
876
e21d1a5f5934 fix msvc warnings
jodogne
parents: 863
diff changeset
400 *p = std::numeric_limits<PixelType>::min();
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
401 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
402 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
403 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
404 *p = static_cast<PixelType>(v);
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
405 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
406 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
407 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
408 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
409
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
410
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
411 // Computes "a * x + b" at each pixel => Note that this is not the
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
412 // same convention as in "ShiftScale()", but it is the convention of
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
413 // "ShiftScale2()"
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
414 template <typename TargetType,
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
415 typename SourceType,
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
416 bool UseRound,
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
417 bool Invert>
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
418 static void ShiftScaleIntegerInternal(ImageAccessor& target,
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
419 const ImageAccessor& source,
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
420 float a,
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
421 float b)
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
422 // This function can be applied inplace (source == target)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
423 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
424 assert(target.GetFormat() != PixelFormat_Float32);
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
425
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
426 if (source.GetWidth() != target.GetWidth() ||
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
427 source.GetHeight() != target.GetHeight())
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
428 {
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
429 throw OrthancException(ErrorCode_IncompatibleImageSize);
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
430 }
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
431
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
432 if (&source == &target &&
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
433 source.GetFormat() != target.GetFormat())
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
434 {
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
435 throw OrthancException(ErrorCode_IncompatibleImageFormat);
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
436 }
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
437
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
438 const TargetType minPixelValue = std::numeric_limits<TargetType>::min();
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
439 const TargetType maxPixelValue = std::numeric_limits<TargetType>::max();
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
440 const float minFloatValue = static_cast<float>(minPixelValue);
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
441 const float maxFloatValue = static_cast<float>(maxPixelValue);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
442
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
443 const unsigned int height = target.GetHeight();
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
444 const unsigned int width = target.GetWidth();
2482
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
445
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
446 for (unsigned int y = 0; y < height; y++)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
447 {
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
448 TargetType* p = reinterpret_cast<TargetType*>(target.GetRow(y));
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
449 const SourceType* q = reinterpret_cast<const SourceType*>(source.GetConstRow(y));
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
450
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
451 for (unsigned int x = 0; x < width; x++, p++, q++)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
452 {
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
453 float v = a * static_cast<float>(*q) + b;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
454
3505
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
455 if (v >= maxFloatValue)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
456 {
2482
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
457 *p = maxPixelValue;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
458 }
3505
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
459 else if (v <= minFloatValue)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
460 {
2482
509041cb57db speedup by truncating instead of rounding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
461 *p = minPixelValue;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
462 }
2488
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
463 else if (UseRound)
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
464 {
2488
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
465 // The "round" operation is very costly
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
466 assert(sizeof(TargetType) < sizeof(int));
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
467 *p = static_cast<TargetType>(boost::math::iround(v));
2488
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
468 }
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
469 else
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
470 {
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
471 *p = static_cast<TargetType>(std::floor(v));
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
472 }
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
473
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
474 if (Invert)
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
475 {
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
476 *p = maxPixelValue - *p;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
477 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
478 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
479 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
480 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
481
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
482
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
483 template <typename SourceType>
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
484 static void ShiftScaleFloatInternal(ImageAccessor& target,
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
485 const ImageAccessor& source,
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
486 float a,
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
487 float b)
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
488 // This function can be applied inplace (source == target)
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
489 {
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
490 assert(target.GetFormat() == PixelFormat_Float32);
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
491
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
492 if (source.GetWidth() != target.GetWidth() ||
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
493 source.GetHeight() != target.GetHeight())
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
494 {
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
495 throw OrthancException(ErrorCode_IncompatibleImageSize);
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
496 }
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
497
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
498 if (&source == &target &&
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
499 source.GetFormat() != target.GetFormat())
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
500 {
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
501 throw OrthancException(ErrorCode_IncompatibleImageFormat);
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
502 }
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
503
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
504 const unsigned int height = target.GetHeight();
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
505 const unsigned int width = target.GetWidth();
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
506
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
507 for (unsigned int y = 0; y < height; y++)
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
508 {
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
509 float* p = reinterpret_cast<float*>(target.GetRow(y));
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
510 const SourceType* q = reinterpret_cast<const SourceType*>(source.GetConstRow(y));
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
511
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
512 for (unsigned int x = 0; x < width; x++, p++, q++)
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
513 {
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
514 *p = a * static_cast<float>(*q) + b;
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
515 }
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
516 }
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
517 }
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
518
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
519
3545
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
520 template <typename PixelType>
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
521 static void ShiftRightInternal(ImageAccessor& image,
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
522 unsigned int shift)
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
523 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
524 const unsigned int height = image.GetHeight();
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
525 const unsigned int width = image.GetWidth();
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
526
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
527 for (unsigned int y = 0; y < height; y++)
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
528 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
529 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
530
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
531 for (unsigned int x = 0; x < width; x++, p++)
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
532 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
533 *p = *p >> shift;
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
534 }
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
535 }
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
536 }
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
537
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
538 template <typename PixelType>
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
539 static void ShiftLeftInternal(ImageAccessor& image,
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
540 unsigned int shift)
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
541 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
542 const unsigned int height = image.GetHeight();
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
543 const unsigned int width = image.GetWidth();
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
544
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
545 for (unsigned int y = 0; y < height; y++)
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
546 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
547 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
548
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
549 for (unsigned int x = 0; x < width; x++, p++)
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
550 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
551 *p = *p << shift;
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
552 }
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
553 }
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
554 }
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
555
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 void ImageProcessing::Copy(ImageAccessor& target,
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 const ImageAccessor& source)
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 if (target.GetWidth() != source.GetWidth() ||
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 target.GetHeight() != source.GetHeight())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 throw OrthancException(ErrorCode_IncompatibleImageSize);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 if (target.GetFormat() != source.GetFormat())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 throw OrthancException(ErrorCode_IncompatibleImageFormat);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4201
diff changeset
570 const unsigned int lineSize = source.GetBytesPerPixel() * source.GetWidth();
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572
4278
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4201
diff changeset
573 const unsigned int height = source.GetHeight();
9279de56a405 avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4201
diff changeset
574 for (unsigned int y = 0; y < height; y++)
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 {
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
576 memcpy(target.GetRow(y), source.GetConstRow(y), lineSize);
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
580 template <typename TargetType, typename SourceType>
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
581 static void ApplyWindowingInternal(ImageAccessor& target,
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
582 const ImageAccessor& source,
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
583 float windowCenter,
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
584 float windowWidth,
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
585 float rescaleSlope,
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
586 float rescaleIntercept,
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
587 bool invert)
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
588 {
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
589 assert(sizeof(SourceType) == source.GetBytesPerPixel() &&
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
590 sizeof(TargetType) == target.GetBytesPerPixel());
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
591
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
592 const TargetType maxTargetValue = std::numeric_limits<TargetType>::max();
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
593 const float maxFloatValue = static_cast<float>(maxTargetValue);
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
594
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
595 const float windowIntercept = windowCenter - windowWidth / 2.0f;
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
596 const float windowSlope = (maxFloatValue + 1.0f) / windowWidth;
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
597
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
598 const float a = rescaleSlope * windowSlope;
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
599 const float b = (rescaleIntercept - windowIntercept) * windowSlope;
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
600
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
601 if (invert)
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
602 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
603 ShiftScaleIntegerInternal<TargetType, SourceType, false, true>(target, source, a, b);
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
604 }
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
605 else
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
606 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
607 ShiftScaleIntegerInternal<TargetType, SourceType, false, false>(target, source, a, b);
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
608 }
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
609 }
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
610
3683
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3682
diff changeset
611 void ImageProcessing::ApplyWindowing_Deprecated(ImageAccessor& target,
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3682
diff changeset
612 const ImageAccessor& source,
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3682
diff changeset
613 float windowCenter,
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3682
diff changeset
614 float windowWidth,
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3682
diff changeset
615 float rescaleSlope,
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3682
diff changeset
616 float rescaleIntercept,
12253ddefe5a skeleton for new route: /instances/{id}/rendered
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3682
diff changeset
617 bool invert)
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
618 {
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
619 if (target.GetWidth() != source.GetWidth() ||
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
620 target.GetHeight() != source.GetHeight())
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
621 {
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
622 throw OrthancException(ErrorCode_IncompatibleImageSize);
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
623 }
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
624
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
625 switch (source.GetFormat())
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
626 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
627 case PixelFormat_Float32:
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
628 {
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
629 switch (target.GetFormat())
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
630 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
631 case PixelFormat_Grayscale8:
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
632 ApplyWindowingInternal<uint8_t, float>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert);
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
633 break;
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
634 case PixelFormat_Grayscale16:
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
635 ApplyWindowingInternal<uint16_t, float>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert);
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
636 break;
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
637 default:
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
638 throw OrthancException(ErrorCode_NotImplemented);
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
639 }
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
640 };break;
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
641 case PixelFormat_Grayscale8:
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
642 {
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
643 switch (target.GetFormat())
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
644 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
645 case PixelFormat_Grayscale8:
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
646 ApplyWindowingInternal<uint8_t, uint8_t>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert);
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
647 break;
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
648 case PixelFormat_Grayscale16:
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
649 ApplyWindowingInternal<uint16_t, uint8_t>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert);
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
650 break;
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
651 default:
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
652 throw OrthancException(ErrorCode_NotImplemented);
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
653 }
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
654 };break;
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
655 case PixelFormat_Grayscale16:
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
656 {
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
657 switch (target.GetFormat())
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
658 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
659 case PixelFormat_Grayscale8:
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
660 ApplyWindowingInternal<uint8_t, uint16_t>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert);
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
661 break;
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
662 case PixelFormat_Grayscale16:
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
663 ApplyWindowingInternal<uint16_t, uint16_t>(target, source, windowCenter, windowWidth, rescaleSlope, rescaleIntercept, invert);
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
664 break;
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
665 default:
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
666 throw OrthancException(ErrorCode_NotImplemented);
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
667 }
3600
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
668 };break;
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
669 default:
4066998150ef /instances/{id}/preview route now takes the windowing into account
Alain Mazy <alain@mazy.be>
parents: 3585
diff changeset
670 throw OrthancException(ErrorCode_NotImplemented);
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
671 }
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
672 }
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
673
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
674
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 void ImageProcessing::Convert(ImageAccessor& target,
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 const ImageAccessor& source)
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 if (target.GetWidth() != source.GetWidth() ||
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 target.GetHeight() != source.GetHeight())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 throw OrthancException(ErrorCode_IncompatibleImageSize);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 }
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
684 const unsigned int width = source.GetWidth();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
685 const unsigned int height = source.GetHeight();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
686
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 if (source.GetFormat() == target.GetFormat())
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 {
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 Copy(target, source);
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 return;
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 }
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
692
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
693 if (target.GetFormat() == PixelFormat_Grayscale16 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
694 source.GetFormat() == PixelFormat_Grayscale8)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
695 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
696 ConvertInternal<uint16_t, uint8_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
697 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
698 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
699
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
700 if (target.GetFormat() == PixelFormat_SignedGrayscale16 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
701 source.GetFormat() == PixelFormat_Grayscale8)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
702 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
703 ConvertInternal<int16_t, uint8_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
704 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
705 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
706
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
707 if (target.GetFormat() == PixelFormat_Grayscale8 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
708 source.GetFormat() == PixelFormat_Grayscale16)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
709 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
710 ConvertInternal<uint8_t, uint16_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
711 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
712 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
713
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
714 if (target.GetFormat() == PixelFormat_SignedGrayscale16 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
715 source.GetFormat() == PixelFormat_Grayscale16)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
716 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
717 ConvertInternal<int16_t, uint16_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
718 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
719 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
720
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
721 if (target.GetFormat() == PixelFormat_Grayscale8 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
722 source.GetFormat() == PixelFormat_SignedGrayscale16)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
723 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
724 ConvertInternal<uint8_t, int16_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
725 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
726 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
727
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
728 if (target.GetFormat() == PixelFormat_Grayscale16 &&
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
729 source.GetFormat() == PixelFormat_SignedGrayscale16)
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
730 {
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
731 ConvertInternal<uint16_t, int16_t>(target, source);
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
732 return;
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
733 }
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 854
diff changeset
734
993
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
735 if (target.GetFormat() == PixelFormat_Grayscale8 &&
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
736 source.GetFormat() == PixelFormat_RGB24)
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
737 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
738 ConvertColorToGrayscale<uint8_t>(target, source);
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
739 return;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
740 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
741
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
742 if (target.GetFormat() == PixelFormat_Grayscale16 &&
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
743 source.GetFormat() == PixelFormat_RGB24)
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
744 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
745 ConvertColorToGrayscale<uint16_t>(target, source);
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
746 return;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
747 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
748
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
749 if (target.GetFormat() == PixelFormat_SignedGrayscale16 &&
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
750 source.GetFormat() == PixelFormat_RGB24)
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
751 {
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
752 ConvertColorToGrayscale<int16_t>(target, source);
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
753 return;
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
754 }
501880d76474 improvements to GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 876
diff changeset
755
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
756 if (target.GetFormat() == PixelFormat_Float32 &&
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
757 source.GetFormat() == PixelFormat_Grayscale8)
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
758 {
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
759 ConvertGrayscaleToFloat<uint8_t>(target, source);
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
760 return;
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
761 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
762
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
763 if (target.GetFormat() == PixelFormat_Float32 &&
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
764 source.GetFormat() == PixelFormat_Grayscale16)
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
765 {
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
766 ConvertGrayscaleToFloat<uint16_t>(target, source);
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
767 return;
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
768 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
769
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
770 if (target.GetFormat() == PixelFormat_Float32 &&
2415
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
771 source.GetFormat() == PixelFormat_Grayscale32)
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
772 {
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
773 ConvertGrayscaleToFloat<uint32_t>(target, source);
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
774 return;
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
775 }
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
776
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
777 if (target.GetFormat() == PixelFormat_Float32 &&
1993
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
778 source.GetFormat() == PixelFormat_SignedGrayscale16)
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
779 {
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
780 ConvertGrayscaleToFloat<int16_t>(target, source);
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
781 return;
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
782 }
e2a3ff770b48 introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1992
diff changeset
783
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
784
1610
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
785 if (target.GetFormat() == PixelFormat_Grayscale8 &&
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
786 source.GetFormat() == PixelFormat_RGBA32)
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
787 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
788 for (unsigned int y = 0; y < height; y++)
1610
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
789 {
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
790 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
791 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
792 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
793 {
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
794 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[0]) +
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
795 7152 * static_cast<uint32_t>(p[1]) +
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
796 0722 * static_cast<uint32_t>(p[2])) / 10000);
1610
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
797 p += 4;
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
798 }
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
799 }
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
800
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
801 return;
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
802 }
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
803
2840
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
804 if (target.GetFormat() == PixelFormat_Grayscale8 &&
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
805 source.GetFormat() == PixelFormat_BGRA32)
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
806 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
807 for (unsigned int y = 0; y < height; y++)
2840
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
808 {
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
809 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
810 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
811 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
812 {
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
813 *q = static_cast<uint8_t>((2126 * static_cast<uint32_t>(p[2]) +
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
814 7152 * static_cast<uint32_t>(p[1]) +
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
815 0722 * static_cast<uint32_t>(p[0])) / 10000);
2840
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
816 p += 4;
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
817 }
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
818 }
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
819
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
820 return;
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
821 }
f4c232bba1eb bgra32 to grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
822
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
823 if (target.GetFormat() == PixelFormat_RGB24 &&
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
824 source.GetFormat() == PixelFormat_RGBA32)
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
825 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
826 for (unsigned int y = 0; y < height; y++)
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
827 {
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
828 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
829 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
830 for (unsigned int x = 0; x < width; x++)
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
831 {
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
832 q[0] = p[0];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
833 q[1] = p[1];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
834 q[2] = p[2];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
835 p += 4;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
836 q += 3;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
837 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
838 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
839
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
840 return;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
841 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
842
2252
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
843 if (target.GetFormat() == PixelFormat_RGB24 &&
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
844 source.GetFormat() == PixelFormat_BGRA32)
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
845 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
846 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
847 {
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
848 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
849 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
850 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
851 {
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
852 q[0] = p[2];
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
853 q[1] = p[1];
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
854 q[2] = p[0];
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
855 p += 4;
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
856 q += 3;
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
857 }
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
858 }
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
859
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
860 return;
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
861 }
002b94046c69 colorspace conversion from BGRA32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
862
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
863 if (target.GetFormat() == PixelFormat_RGBA32 &&
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
864 source.GetFormat() == PixelFormat_RGB24)
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
865 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
866 for (unsigned int y = 0; y < height; y++)
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
867 {
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
868 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
869 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
870 for (unsigned int x = 0; x < width; x++)
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
871 {
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
872 q[0] = p[0];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
873 q[1] = p[1];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
874 q[2] = p[2];
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
875 q[3] = 255; // Set the alpha channel to full opacity
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
876 p += 3;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
877 q += 4;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
878 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
879 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
880
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
881 return;
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
882 }
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
883
1992
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
884 if (target.GetFormat() == PixelFormat_RGB24 &&
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
885 source.GetFormat() == PixelFormat_Grayscale8)
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
886 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
887 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
888 {
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
889 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
890 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
891 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
892 {
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
893 q[0] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
894 q[1] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
895 q[2] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
896 p += 1;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
897 q += 3;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
898 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
899 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
900
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
901 return;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
902 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
903
2650
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
904 if ((target.GetFormat() == PixelFormat_RGBA32 ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
905 target.GetFormat() == PixelFormat_BGRA32) &&
1992
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
906 source.GetFormat() == PixelFormat_Grayscale8)
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
907 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
908 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
909 {
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
910 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
911 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
912 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
913 {
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
914 q[0] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
915 q[1] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
916 q[2] = *p;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
917 q[3] = 255;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
918 p += 1;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
919 q += 4;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
920 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
921 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
922
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
923 return;
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
924 }
9161e3ef0d17 new conversions in ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
925
2100
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
926 if (target.GetFormat() == PixelFormat_BGRA32 &&
2495
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
927 source.GetFormat() == PixelFormat_Grayscale16)
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
928 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
929 for (unsigned int y = 0; y < height; y++)
2495
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
930 {
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
931 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
932 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
933 for (unsigned int x = 0; x < width; x++)
2495
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
934 {
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
935 uint8_t value = (*p < 256 ? *p : 255);
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
936 q[0] = value;
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
937 q[1] = value;
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
938 q[2] = value;
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
939 q[3] = 255;
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
940 p += 1;
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
941 q += 4;
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
942 }
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
943 }
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
944
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
945 return;
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
946 }
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
947
cd7b854dbc05 convert grayscale16 to bgra32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2491
diff changeset
948 if (target.GetFormat() == PixelFormat_BGRA32 &&
2496
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
949 source.GetFormat() == PixelFormat_SignedGrayscale16)
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
950 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
951 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
952 {
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
953 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
954 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
955 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
956 {
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
957 uint8_t value;
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
958 if (*p < 0)
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
959 {
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
960 value = 0;
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
961 }
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
962 else if (*p > 255)
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
963 {
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
964 value = 255;
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
965 }
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
966 else
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
967 {
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
968 value = static_cast<uint8_t>(*p);
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
969 }
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
970
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
971 q[0] = value;
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
972 q[1] = value;
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
973 q[2] = value;
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
974 q[3] = 255;
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
975 p += 1;
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
976 q += 4;
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
977 }
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
978 }
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
979
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
980 return;
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
981 }
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
982
3d65adee289a int16_t to rgba32 conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2495
diff changeset
983 if (target.GetFormat() == PixelFormat_BGRA32 &&
2100
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
984 source.GetFormat() == PixelFormat_RGB24)
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
985 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
986 for (unsigned int y = 0; y < height; y++)
2100
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
987 {
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
988 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
989 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
990 for (unsigned int x = 0; x < width; x++)
2100
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
991 {
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
992 q[0] = p[2];
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
993 q[1] = p[1];
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
994 q[2] = p[0];
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
995 q[3] = 255;
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
996 p += 3;
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
997 q += 4;
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
998 }
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
999 }
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
1000
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
1001 return;
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
1002 }
1554fc153a93 conversion RGB24 to BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2089
diff changeset
1003
3547
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1004 if ((target.GetFormat() == PixelFormat_BGRA32 &&
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1005 source.GetFormat() == PixelFormat_RGBA32)
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1006 || (target.GetFormat() == PixelFormat_RGBA32 &&
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1007 source.GetFormat() == PixelFormat_BGRA32))
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1008 {
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1009 for (unsigned int y = 0; y < height; y++)
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1010 {
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1011 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1012 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1013 for (unsigned int x = 0; x < width; x++)
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1014 {
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1015 q[0] = p[2];
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1016 q[1] = p[1];
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1017 q[2] = p[0];
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1018 q[3] = p[3];
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1019 p += 4;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1020 q += 4;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1021 }
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1022 }
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1023
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1024 return;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1025 }
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1026
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1027 if (target.GetFormat() == PixelFormat_RGB24 &&
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1028 source.GetFormat() == PixelFormat_RGB48)
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1029 {
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1030 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
1031 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1032 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
1033 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
1034 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
1035 {
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1036 q[0] = p[0] >> 8;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1037 q[1] = p[1] >> 8;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1038 q[2] = p[2] >> 8;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1039 p += 3;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1040 q += 3;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1041 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1042 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1043
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1044 return;
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1045 }
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2415
diff changeset
1046
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1047 if (target.GetFormat() == PixelFormat_Grayscale16 &&
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1048 source.GetFormat() == PixelFormat_Float32)
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1049 {
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1050 ConvertFloatToGrayscale<PixelFormat_Grayscale16>(target, source);
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1051 return;
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1052 }
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1053
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1054 if (target.GetFormat() == PixelFormat_Grayscale8 &&
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1055 source.GetFormat() == PixelFormat_Float32)
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1056 {
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1057 ConvertFloatToGrayscale<PixelFormat_Grayscale8>(target, source);
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1058 return;
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1059 }
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1060
4664
f9eda86f9045 ImageProcessing::Convert() from Float32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4529
diff changeset
1061 if (target.GetFormat() == PixelFormat_RGB24 &&
f9eda86f9045 ImageProcessing::Convert() from Float32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4529
diff changeset
1062 source.GetFormat() == PixelFormat_Float32)
f9eda86f9045 ImageProcessing::Convert() from Float32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4529
diff changeset
1063 {
f9eda86f9045 ImageProcessing::Convert() from Float32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4529
diff changeset
1064 ConvertFloatToGrayscale<PixelFormat_RGB24>(target, source);
f9eda86f9045 ImageProcessing::Convert() from Float32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4529
diff changeset
1065 return;
f9eda86f9045 ImageProcessing::Convert() from Float32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4529
diff changeset
1066 }
f9eda86f9045 ImageProcessing::Convert() from Float32 to RGB24
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4529
diff changeset
1067
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1068 throw OrthancException(ErrorCode_NotImplemented);
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069 }
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1070
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1071
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1072
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1073 void ImageProcessing::Set(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1074 int64_t value)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1075 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1076 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1077 {
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1078 case PixelFormat_Grayscale8:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1079 SetInternal<uint8_t>(image, value);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1080 return;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1081
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1082 case PixelFormat_Grayscale16:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1083 SetInternal<uint16_t>(image, value);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1084 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1085
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1086 case PixelFormat_Grayscale32:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1087 SetInternal<uint32_t>(image, value);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1088 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1089
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1090 case PixelFormat_Grayscale64:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1091 SetInternal<uint64_t>(image, value);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1092 return;
2415
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1093
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1094 case PixelFormat_SignedGrayscale16:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1095 SetInternal<int16_t>(image, value);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1096 return;
2645
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2496
diff changeset
1097
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1098 case PixelFormat_Float32:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1099 assert(sizeof(float) == 4);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1100 SetInternal<float>(image, value);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1101 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1102
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1103 case PixelFormat_RGBA32:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1104 case PixelFormat_BGRA32:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1105 case PixelFormat_RGB24:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1106 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1107 uint8_t v = static_cast<uint8_t>(value);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1108 Set(image, v, v, v, v); // Use the color version
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1109 return;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1110 }
1994
4d099fee5eca ImageProcessing::Set for float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1993
diff changeset
1111
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1112 default:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1113 throw OrthancException(ErrorCode_NotImplemented);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1114 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1115 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1116
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1117
2089
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1118 void ImageProcessing::Set(ImageAccessor& image,
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1119 uint8_t red,
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1120 uint8_t green,
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1121 uint8_t blue,
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1122 uint8_t alpha)
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1123 {
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1124 uint8_t p[4];
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1125 unsigned int size;
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1126
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1127 switch (image.GetFormat())
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1128 {
4446
19e8540064d8 ImageProcessing::Set(image, r, g, b, a) applicable to grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4443
diff changeset
1129 case PixelFormat_Grayscale8:
19e8540064d8 ImageProcessing::Set(image, r, g, b, a) applicable to grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4443
diff changeset
1130 {
19e8540064d8 ImageProcessing::Set(image, r, g, b, a) applicable to grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4443
diff changeset
1131 // New in Orthanc 1.9.0
19e8540064d8 ImageProcessing::Set(image, r, g, b, a) applicable to grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4443
diff changeset
1132 uint8_t grayscale = (2126 * static_cast<uint16_t>(red) +
19e8540064d8 ImageProcessing::Set(image, r, g, b, a) applicable to grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4443
diff changeset
1133 7152 * static_cast<uint16_t>(green) +
19e8540064d8 ImageProcessing::Set(image, r, g, b, a) applicable to grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4443
diff changeset
1134 0722 * static_cast<uint16_t>(blue)) / 10000;
19e8540064d8 ImageProcessing::Set(image, r, g, b, a) applicable to grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4443
diff changeset
1135 Orthanc::ImageProcessing::Set(image, grayscale);
4447
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4446
diff changeset
1136 return;
4446
19e8540064d8 ImageProcessing::Set(image, r, g, b, a) applicable to grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4443
diff changeset
1137 }
19e8540064d8 ImageProcessing::Set(image, r, g, b, a) applicable to grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4443
diff changeset
1138
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1139 case PixelFormat_RGBA32:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1140 p[0] = red;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1141 p[1] = green;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1142 p[2] = blue;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1143 p[3] = alpha;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1144 size = 4;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1145 break;
2089
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1146
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1147 case PixelFormat_BGRA32:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1148 p[0] = blue;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1149 p[1] = green;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1150 p[2] = red;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1151 p[3] = alpha;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1152 size = 4;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1153 break;
2089
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1154
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1155 case PixelFormat_RGB24:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1156 p[0] = red;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1157 p[1] = green;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1158 p[2] = blue;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1159 size = 3;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1160 break;
2089
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1161
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1162 default:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1163 throw OrthancException(ErrorCode_NotImplemented);
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1164 }
2089
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1165
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1166 const unsigned int width = image.GetWidth();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1167 const unsigned int height = image.GetHeight();
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1168
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1169 for (unsigned int y = 0; y < height; y++)
2089
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1170 {
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1171 uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y));
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1172
2904
0dd54ee073db float to integer grayscale conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2902
diff changeset
1173 for (unsigned int x = 0; x < width; x++)
2089
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1174 {
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1175 for (unsigned int i = 0; i < size; i++)
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1176 {
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1177 q[i] = p[i];
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1178 }
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1179
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1180 q += size;
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1181 }
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1182 }
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1183 }
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1184
3547
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1185 void ImageProcessing::Set(ImageAccessor& image,
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
1186 uint8_t red,
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
1187 uint8_t green,
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
1188 uint8_t blue,
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
1189 ImageAccessor& alpha)
3547
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1190 {
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1191 uint8_t p[4];
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1192
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1193 if (alpha.GetWidth() != image.GetWidth() || alpha.GetHeight() != image.GetHeight())
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1194 {
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1195 throw OrthancException(ErrorCode_IncompatibleImageSize);
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1196 }
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1197
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1198 if (alpha.GetFormat() != PixelFormat_Grayscale8)
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1199 {
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1200 throw OrthancException(ErrorCode_NotImplemented);
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1201 }
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1202
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1203 switch (image.GetFormat())
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1204 {
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1205 case PixelFormat_RGBA32:
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1206 p[0] = red;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1207 p[1] = green;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1208 p[2] = blue;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1209 break;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1210
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1211 case PixelFormat_BGRA32:
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1212 p[0] = blue;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1213 p[1] = green;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1214 p[2] = red;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1215 break;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1216
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1217 default:
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1218 throw OrthancException(ErrorCode_NotImplemented);
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1219 }
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1220
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1221 const unsigned int width = image.GetWidth();
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1222 const unsigned int height = image.GetHeight();
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1223
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1224 for (unsigned int y = 0; y < height; y++)
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1225 {
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1226 uint8_t* q = reinterpret_cast<uint8_t*>(image.GetRow(y));
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1227 uint8_t* a = reinterpret_cast<uint8_t*>(alpha.GetRow(y));
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1228
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1229 for (unsigned int x = 0; x < width; x++)
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1230 {
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1231 for (unsigned int i = 0; i < 3; i++)
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1232 {
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1233 q[i] = p[i];
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1234 }
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1235 q[3] = *a;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1236 q += 4;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1237 ++a;
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1238 }
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1239 }
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1240 }
dabe17e23e23 Copy RGBA to BGRA & Set with alpha
Alain Mazy <alain@mazy.be>
parents: 3545
diff changeset
1241
2089
7a969f235adf PixelFormat_BGRA32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1994
diff changeset
1242
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1243 void ImageProcessing::ShiftRight(ImageAccessor& image,
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1244 unsigned int shift)
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1245 {
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1246 if (image.GetWidth() == 0 ||
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1247 image.GetHeight() == 0 ||
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1248 shift == 0)
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1249 {
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1250 // Nothing to do
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1251 return;
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1252 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1253
3545
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1254 switch (image.GetFormat())
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1255 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1256 case PixelFormat_Grayscale8:
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1257 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1258 ShiftRightInternal<uint8_t>(image, shift);
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1259 break;
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1260 }
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1261
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1262 case PixelFormat_Grayscale16:
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1263 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1264 ShiftRightInternal<uint16_t>(image, shift);
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1265 break;
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1266 }
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1267 default:
3545
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1268 throw OrthancException(ErrorCode_NotImplemented);
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1269 }
854
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1270 }
ff530685e46a fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 853
diff changeset
1271
3545
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1272 void ImageProcessing::ShiftLeft(ImageAccessor& image,
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1273 unsigned int shift)
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1274 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1275 if (image.GetWidth() == 0 ||
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1276 image.GetHeight() == 0 ||
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1277 shift == 0)
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1278 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1279 // Nothing to do
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1280 return;
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1281 }
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1282
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1283 switch (image.GetFormat())
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1284 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1285 case PixelFormat_Grayscale8:
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1286 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1287 ShiftLeftInternal<uint8_t>(image, shift);
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1288 break;
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1289 }
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1290
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1291 case PixelFormat_Grayscale16:
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1292 {
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1293 ShiftLeftInternal<uint16_t>(image, shift);
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1294 break;
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1295 }
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1296 default:
3545
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1297 throw OrthancException(ErrorCode_NotImplemented);
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1298 }
551945086617 ShiftLeft + ShiftRight
Alain Mazy <alain@mazy.be>
parents: 3525
diff changeset
1299 }
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1300
2415
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1301 void ImageProcessing::GetMinMaxIntegerValue(int64_t& minValue,
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1302 int64_t& maxValue,
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1303 const ImageAccessor& image)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1304 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1305 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1306 {
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1307 case PixelFormat_Grayscale8:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1308 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1309 uint8_t a, b;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1310 GetMinMaxValueInternal<uint8_t>(a, b, image);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1311 minValue = a;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1312 maxValue = b;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1313 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1314 }
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1315
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1316 case PixelFormat_Grayscale16:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1317 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1318 uint16_t a, b;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1319 GetMinMaxValueInternal<uint16_t>(a, b, image);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1320 minValue = a;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1321 maxValue = b;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1322 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1323 }
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1324
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1325 case PixelFormat_Grayscale32:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1326 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1327 uint32_t a, b;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1328 GetMinMaxValueInternal<uint32_t>(a, b, image);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1329 minValue = a;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1330 maxValue = b;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1331 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1332 }
2415
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1333
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1334 case PixelFormat_SignedGrayscale16:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1335 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1336 int16_t a, b;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1337 GetMinMaxValueInternal<int16_t>(a, b, image);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1338 minValue = a;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1339 maxValue = b;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1340 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1341 }
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1342
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1343 default:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1344 throw OrthancException(ErrorCode_NotImplemented);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1345 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1346 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1347
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1348
2415
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1349 void ImageProcessing::GetMinMaxFloatValue(float& minValue,
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1350 float& maxValue,
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1351 const ImageAccessor& image)
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1352 {
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1353 switch (image.GetFormat())
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1354 {
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1355 case PixelFormat_Float32:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1356 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1357 assert(sizeof(float) == 4);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1358 float a, b;
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
1359
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
1360 /**
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
1361 * WARNING - On floating-point types, the minimal value is
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
1362 * "-FLT_MAX" (as implemented by "::lowest()"), not "FLT_MIN"
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
1363 * (as implemented by "::min()")
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
1364 * https://en.cppreference.com/w/cpp/types/numeric_limits
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
1365 **/
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
1366 GetMinMaxValueInternal<float>(a, b, image, -std::numeric_limits<float>::max());
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1367 minValue = a;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1368 maxValue = b;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1369 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1370 }
2415
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1371
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1372 default:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1373 throw OrthancException(ErrorCode_NotImplemented);
2415
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1374 }
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1375 }
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1376
7e217a1cc63f PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
1377
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1378
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1379 void ImageProcessing::AddConstant(ImageAccessor& image,
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1380 int64_t value)
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1381 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1382 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1383 {
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1384 case PixelFormat_Grayscale8:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1385 AddConstantInternal<uint8_t>(image, value);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1386 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1387
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1388 case PixelFormat_Grayscale16:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1389 AddConstantInternal<uint16_t>(image, value);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1390 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1391
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1392 case PixelFormat_SignedGrayscale16:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1393 AddConstantInternal<int16_t>(image, value);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1394 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1395
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1396 default:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1397 throw OrthancException(ErrorCode_NotImplemented);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1398 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1399 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1400
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1401
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1402 void ImageProcessing::MultiplyConstant(ImageAccessor& image,
2488
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
1403 float factor,
345725b9350c back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
1404 bool useRound)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1405 {
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1406 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1407 {
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1408 case PixelFormat_Grayscale8:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1409 if (useRound)
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1410 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1411 MultiplyConstantInternal<uint8_t, true>(image, factor);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1412 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1413 else
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1414 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1415 MultiplyConstantInternal<uint8_t, false>(image, factor);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1416 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1417 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1418
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1419 case PixelFormat_Grayscale16:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1420 if (useRound)
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1421 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1422 MultiplyConstantInternal<uint16_t, true>(image, factor);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1423 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1424 else
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1425 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1426 MultiplyConstantInternal<uint16_t, false>(image, factor);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1427 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1428 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1429
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1430 case PixelFormat_SignedGrayscale16:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1431 if (useRound)
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1432 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1433 MultiplyConstantInternal<int16_t, true>(image, factor);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1434 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1435 else
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1436 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1437 MultiplyConstantInternal<int16_t, false>(image, factor);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1438 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1439 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1440
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1441 default:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1442 throw OrthancException(ErrorCode_NotImplemented);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1443 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1444 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1445
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1446
4780
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1447 static bool IsIdentityRescaling(float offset,
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1448 float scaling)
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1449 {
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1450 return (std::abs(offset) <= 10.0f * std::numeric_limits<float>::epsilon() &&
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1451 std::abs(scaling - 1.0f) <= 10.0f * std::numeric_limits<float>::epsilon());
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1452 }
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1453
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1454
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1455 void ImageProcessing::ShiftScale2(ImageAccessor& image,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1456 float offset,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1457 float scaling,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1458 bool useRound)
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1459 {
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1460 // We compute "a * x + b"
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1461 const float a = scaling;
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1462 const float b = offset;
4780
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1463
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1464 if (IsIdentityRescaling(offset, scaling))
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1465 {
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1466 return;
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1467 }
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1468
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1469 switch (image.GetFormat())
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1470 {
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1471 case PixelFormat_Grayscale8:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1472 if (useRound)
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1473 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
1474 ShiftScaleIntegerInternal<uint8_t, uint8_t, true, false>(image, image, a, b);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1475 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1476 else
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1477 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
1478 ShiftScaleIntegerInternal<uint8_t, uint8_t, false, false>(image, image, a, b);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1479 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1480 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1481
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1482 case PixelFormat_Grayscale16:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1483 if (useRound)
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1484 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
1485 ShiftScaleIntegerInternal<uint16_t, uint16_t, true, false>(image, image, a, b);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1486 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1487 else
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1488 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
1489 ShiftScaleIntegerInternal<uint16_t, uint16_t, false, false>(image, image, a, b);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1490 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1491 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1492
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1493 case PixelFormat_SignedGrayscale16:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1494 if (useRound)
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1495 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
1496 ShiftScaleIntegerInternal<int16_t, int16_t, true, false>(image, image, a, b);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1497 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1498 else
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1499 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
1500 ShiftScaleIntegerInternal<int16_t, int16_t, false, false>(image, image, a, b);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1501 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1502 return;
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1503
3505
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
1504 case PixelFormat_Float32:
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
1505 if (useRound)
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
1506 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
1507 ShiftScaleFloatInternal<float>(image, image, a, b);
3505
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
1508 }
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
1509 else
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
1510 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
1511 ShiftScaleFloatInternal<float>(image, image, a, b);
3505
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
1512 }
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
1513 return;
b2d4dd16dae8 removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3504
diff changeset
1514
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1515 default:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1516 throw OrthancException(ErrorCode_NotImplemented);
863
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1517 }
3c0d0836f704 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 862
diff changeset
1518 }
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2252
diff changeset
1519
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2252
diff changeset
1520
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1521 void ImageProcessing::ShiftScale2(ImageAccessor& target,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1522 const ImageAccessor& source,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1523 float offset,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1524 float scaling,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1525 bool useRound)
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1526 {
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1527 // We compute "a * x + b"
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1528 const float a = scaling;
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1529 const float b = offset;
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1530
4780
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1531 if (target.GetFormat() == source.GetFormat() &&
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1532 IsIdentityRescaling(offset, scaling))
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1533 {
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1534 Copy(target, source);
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1535 return;
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1536 }
ebb801d44e06 optimization in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4664
diff changeset
1537
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1538 switch (target.GetFormat())
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1539 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1540 case PixelFormat_Grayscale8:
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1541
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1542 switch (source.GetFormat())
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1543 {
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1544 case PixelFormat_Float32:
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1545 if (useRound)
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1546 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
1547 ShiftScaleIntegerInternal<uint8_t, float, true, false>(target, source, a, b);
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1548 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1549 else
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1550 {
4974
fcdf399f9fc0 fix ImageProcessing::ShiftScale2() on floating-point images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4948
diff changeset
1551 ShiftScaleIntegerInternal<uint8_t, float, false, false>(target, source, a, b);
3690
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1552 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1553 return;
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1554
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1555 default:
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1556 throw OrthancException(ErrorCode_NotImplemented);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1557 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1558
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1559 default:
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1560 throw OrthancException(ErrorCode_NotImplemented);
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1561 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1562 }
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1563
a9ce35d67c3c implementation of "/instances/.../rendered" for grayscale images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3684
diff changeset
1564
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1565 void ImageProcessing::ShiftScale(ImageAccessor& image,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1566 float offset,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1567 float scaling,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1568 bool useRound)
4079
73c22208272f ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1569 {
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1570 // Rewrite "(x + offset) * scaling" as "a * x + b"
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1571
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1572 const float a = scaling;
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1573 const float b = offset * scaling;
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1574 ShiftScale2(image, b, a, useRound);
4079
73c22208272f ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1575 }
73c22208272f ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1576
73c22208272f ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1577
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1578 void ImageProcessing::ShiftScale(ImageAccessor& target,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1579 const ImageAccessor& source,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1580 float offset,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1581 float scaling,
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1582 bool useRound)
4079
73c22208272f ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1583 {
4080
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1584 // Rewrite "(x + offset) * scaling" as "a * x + b"
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1585
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1586 const float a = scaling;
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1587 const float b = offset * scaling;
f18eaade6153 simplification in ImageProcessing::ShiftScale()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4079
diff changeset
1588 ShiftScale2(target, source, b, a, useRound);
4079
73c22208272f ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1589 }
73c22208272f ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1590
73c22208272f ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1591
73c22208272f ImageProcessing::ShiftScale2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1592
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1593 void ImageProcessing::Invert(ImageAccessor& image, int64_t maxValue)
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1594 {
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1595 const unsigned int width = image.GetWidth();
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1596 const unsigned int height = image.GetHeight();
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1597
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1598 switch (image.GetFormat())
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1599 {
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1600 case PixelFormat_Grayscale16:
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1601 {
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1602 uint16_t maxValueUint16 = (uint16_t)(std::min(maxValue, static_cast<int64_t>(std::numeric_limits<uint16_t>::max())));
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1603
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1604 for (unsigned int y = 0; y < height; y++)
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1605 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1606 uint16_t* p = reinterpret_cast<uint16_t*>(image.GetRow(y));
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1607
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1608 for (unsigned int x = 0; x < width; x++, p++)
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1609 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1610 *p = maxValueUint16 - (*p);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1611 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1612 }
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1613
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1614 return;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1615 }
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1616 case PixelFormat_Grayscale8:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1617 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1618 uint8_t maxValueUint8 = (uint8_t)(std::min(maxValue, static_cast<int64_t>(std::numeric_limits<uint8_t>::max())));
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1619
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1620 for (unsigned int y = 0; y < height; y++)
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1621 {
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1622 uint8_t* p = reinterpret_cast<uint8_t*>(image.GetRow(y));
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1623
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1624 for (unsigned int x = 0; x < width; x++, p++)
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1625 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1626 *p = maxValueUint8 - (*p);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1627 }
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1628 }
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1629
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1630 return;
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1631 }
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1632
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1633 default:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1634 throw OrthancException(ErrorCode_NotImplemented);
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1635 }
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1636
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1637 }
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1638
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2252
diff changeset
1639 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
1640 {
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2252
diff changeset
1641 switch (image.GetFormat())
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2252
diff changeset
1642 {
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1643 case PixelFormat_Grayscale8:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1644 return Invert(image, 255);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1645 default:
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1646 throw OrthancException(ErrorCode_NotImplemented); // you should use the Invert(image, maxValue) overload
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1647 }
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2252
diff changeset
1648 }
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1649
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1650
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1651
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1652 namespace
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1653 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1654 template <PixelFormat Format>
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1655 class BresenhamPixelWriter
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1656 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1657 private:
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1658 typedef typename PixelTraits<Format>::PixelType PixelType;
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1659
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1660 ImageAccessor& image_;
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1661 PixelType value_;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1662
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1663 void PlotLineLow(int x0,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1664 int y0,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1665 int x1,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1666 int y1)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1667 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1668 int dx = x1 - x0;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1669 int dy = y1 - y0;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1670 int yi = 1;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1671
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1672 if (dy < 0)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1673 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1674 yi = -1;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1675 dy = -dy;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1676 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1677
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1678 int d = 2 * dy - dx;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1679 int y = y0;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1680
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1681 for (int x = x0; x <= x1; x++)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1682 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1683 Write(x, y);
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1684
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1685 if (d > 0)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1686 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1687 y = y + yi;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1688 d = d - 2 * dx;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1689 }
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1690
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1691 d = d + 2*dy;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1692 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1693 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1694
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1695 void PlotLineHigh(int x0,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1696 int y0,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1697 int x1,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1698 int y1)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1699 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1700 int dx = x1 - x0;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1701 int dy = y1 - y0;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1702 int xi = 1;
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1703
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1704 if (dx < 0)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1705 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1706 xi = -1;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1707 dx = -dx;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1708 }
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1709
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1710 int d = 2 * dx - dy;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1711 int x = x0;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1712
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1713 for (int y = y0; y <= y1; y++)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1714 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1715 Write(x, y);
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1716
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1717 if (d > 0)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1718 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1719 x = x + xi;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1720 d = d - 2 * dy;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1721 }
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1722
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1723 d = d + 2 * dx;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1724 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1725 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1726
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1727 public:
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1728 BresenhamPixelWriter(ImageAccessor& image,
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1729 int64_t value) :
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1730 image_(image),
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1731 value_(PixelTraits<Format>::IntegerToPixel(value))
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1732 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1733 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1734
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1735 BresenhamPixelWriter(ImageAccessor& image,
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1736 const PixelType& value) :
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1737 image_(image),
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1738 value_(value)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1739 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1740 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1741
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1742 void Write(int x,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1743 int y)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1744 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1745 if (x >= 0 &&
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1746 y >= 0 &&
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1747 static_cast<unsigned int>(x) < image_.GetWidth() &&
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1748 static_cast<unsigned int>(y) < image_.GetHeight())
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1749 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1750 PixelType* p = reinterpret_cast<PixelType*>(image_.GetRow(y));
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1751 p[x] = value_;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1752 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1753 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1754
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1755 void DrawSegment(int x0,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1756 int y0,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1757 int x1,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1758 int y1)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1759 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1760 // This is an implementation of Bresenham's line algorithm
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1761 // https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#All_cases
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1762
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1763 if (abs(y1 - y0) < abs(x1 - x0))
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1764 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1765 if (x0 > x1)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1766 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1767 PlotLineLow(x1, y1, x0, y0);
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1768 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1769 else
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1770 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1771 PlotLineLow(x0, y0, x1, y1);
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1772 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1773 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1774 else
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1775 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1776 if (y0 > y1)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1777 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1778 PlotLineHigh(x1, y1, x0, y0);
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1779 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1780 else
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1781 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1782 PlotLineHigh(x0, y0, x1, y1);
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1783 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1784 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1785 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1786 };
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1787 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1788
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1789
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1790 void ImageProcessing::DrawLineSegment(ImageAccessor& image,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1791 int x0,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1792 int y0,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1793 int x1,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1794 int y1,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1795 int64_t value)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1796 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1797 switch (image.GetFormat())
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1798 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1799 case PixelFormat_Grayscale8:
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1800 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1801 BresenhamPixelWriter<PixelFormat_Grayscale8> writer(image, value);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1802 writer.DrawSegment(x0, y0, x1, y1);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1803 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1804 }
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1805
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1806 case PixelFormat_Grayscale16:
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1807 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1808 BresenhamPixelWriter<PixelFormat_Grayscale16> writer(image, value);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1809 writer.DrawSegment(x0, y0, x1, y1);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1810 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1811 }
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1812
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1813 case PixelFormat_SignedGrayscale16:
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1814 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1815 BresenhamPixelWriter<PixelFormat_SignedGrayscale16> writer(image, value);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1816 writer.DrawSegment(x0, y0, x1, y1);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1817 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1818 }
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1819
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1820 default:
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1821 throw OrthancException(ErrorCode_NotImplemented);
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1822 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1823 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1824
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1825
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1826 void ImageProcessing::DrawLineSegment(ImageAccessor& image,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1827 int x0,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1828 int y0,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1829 int x1,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1830 int y1,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1831 uint8_t red,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1832 uint8_t green,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1833 uint8_t blue,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1834 uint8_t alpha)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1835 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1836 switch (image.GetFormat())
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1837 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1838 case PixelFormat_BGRA32:
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1839 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1840 PixelTraits<PixelFormat_BGRA32>::PixelType pixel;
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1841 pixel.red_ = red;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1842 pixel.green_ = green;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1843 pixel.blue_ = blue;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1844 pixel.alpha_ = alpha;
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1845
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1846 BresenhamPixelWriter<PixelFormat_BGRA32> writer(image, pixel);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1847 writer.DrawSegment(x0, y0, x1, y1);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1848 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1849 }
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1850
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1851 case PixelFormat_RGBA32:
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1852 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1853 PixelTraits<PixelFormat_RGBA32>::PixelType pixel;
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1854 pixel.red_ = red;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1855 pixel.green_ = green;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1856 pixel.blue_ = blue;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1857 pixel.alpha_ = alpha;
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1858
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1859 BresenhamPixelWriter<PixelFormat_RGBA32> writer(image, pixel);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1860 writer.DrawSegment(x0, y0, x1, y1);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1861 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1862 }
2783
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2650
diff changeset
1863
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1864 case PixelFormat_RGB24:
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1865 {
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1866 PixelTraits<PixelFormat_RGB24>::PixelType pixel;
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1867 pixel.red_ = red;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1868 pixel.green_ = green;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1869 pixel.blue_ = blue;
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1870
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1871 BresenhamPixelWriter<PixelFormat_RGB24> writer(image, pixel);
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1872 writer.DrawSegment(x0, y0, x1, y1);
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1873 break;
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1874 }
3227
53bb1f4b3844 added Invert for Grayscale16
am@osimis.io
parents: 3060
diff changeset
1875
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
1876 default:
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
1877 throw OrthancException(ErrorCode_NotImplemented);
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1878 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2488
diff changeset
1879 }
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1880
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1881 void ComputePolygonExtent(int32_t& left, int32_t& right, int32_t& top, int32_t& bottom, const std::vector<ImageProcessing::ImagePoint>& points)
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1882 {
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1883 left = std::numeric_limits<int32_t>::max();
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1884 right = std::numeric_limits<int32_t>::min();
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1885 top = std::numeric_limits<int32_t>::max();
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1886 bottom = std::numeric_limits<int32_t>::min();
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1887
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1888 for (size_t i = 0; i < points.size(); i++)
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1889 {
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1890 const ImageProcessing::ImagePoint& p = points[i];
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1891 left = std::min(p.GetX(), left);
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1892 right = std::max(p.GetX(), right);
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1893 bottom = std::max(p.GetY(), bottom);
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1894 top = std::min(p.GetY(), top);
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1895 }
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1896 }
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1897
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1898
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1899 namespace
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1900 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1901 #define USE_POLYGON_FRACTIONS 1
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1902
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1903 class PolygonEdge
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1904 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1905 private:
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1906 int yUpper;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1907
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1908 #if USE_POLYGON_FRACTIONS == 1
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1909 int x;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1910 int xOffset;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1911 int dxPerScanNumerator;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1912 int dxPerScanDenominator;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1913 #else
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1914 float xIntersect;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1915 float dxPerScan;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1916 #endif
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1917
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1918 public:
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1919 PolygonEdge(const ImageProcessing::ImagePoint& lower,
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1920 const ImageProcessing::ImagePoint& upper,
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1921 int yComp)
3365
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3323
diff changeset
1922 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1923 // cf. "makeEdgeRec()" in textbook
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1924
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1925 assert(upper.GetY() != lower.GetY());
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1926
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1927 #if USE_POLYGON_FRACTIONS == 1
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1928 x = lower.GetX();
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1929 xOffset = 0;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1930 dxPerScanNumerator = upper.GetX() - lower.GetX();
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1931 dxPerScanDenominator = upper.GetY() - lower.GetY();
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1932 #else
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1933 dxPerScan = (static_cast<float>(upper.GetX() - lower.GetX()) /
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1934 static_cast<float>(upper.GetY() - lower.GetY()));
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1935 xIntersect = lower.GetX();
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1936 #endif
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1937
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1938 if (upper.GetY() < yComp)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1939 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1940 yUpper = upper.GetY() - 1;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1941 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1942 else
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1943 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1944 yUpper = upper.GetY();
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1945 }
3365
9345710bbf12 check limits in fillpolygon
Alain Mazy <alain@mazy.be>
parents: 3323
diff changeset
1946 }
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1947
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1948 void NextScanLine()
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1949 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1950 #if USE_POLYGON_FRACTIONS == 1
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1951 xOffset += dxPerScanNumerator;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1952
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1953 while (xOffset >= dxPerScanDenominator)
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1954 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1955 x++;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1956 xOffset -= dxPerScanDenominator;
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1957 }
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1958
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1959 while (xOffset < 0)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1960 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1961 x--;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1962 xOffset += dxPerScanDenominator;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1963 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1964
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1965 #else
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1966 xIntersect += dxPerScan;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1967 #endif
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1968 }
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1969
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1970
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1971 int GetEnterX() const
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1972 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1973 #if USE_POLYGON_FRACTIONS == 1
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1974 assert(xOffset >= 0 && xOffset < dxPerScanDenominator);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1975 if (xOffset == 0)
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1976 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1977 return x;
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1978 }
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1979 else
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
1980 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1981 return x + 1;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1982 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1983 #else
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
1984 return static_cast<int>(std::ceil(xIntersect));
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1985 #endif
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1986 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1987
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1988 int GetExitX() const
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1989 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1990 #if USE_POLYGON_FRACTIONS == 1
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1991 assert(xOffset >= 0 && xOffset < dxPerScanDenominator);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1992 return x;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1993 #else
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
1994 return static_cast<int>(std::floor(xIntersect));
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1995 #endif
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1996 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1997
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1998 int GetUpperY() const
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
1999 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2000 return yUpper;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2001 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2002
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2003 bool operator< (const PolygonEdge& other) const
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2004 {
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2005 #if USE_POLYGON_FRACTIONS == 1
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2006 assert(xOffset >= 0 && xOffset < dxPerScanDenominator);
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2007 assert(other.xOffset >= 0 && other.xOffset < other.dxPerScanDenominator);
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2008 return x < other.x;
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2009 #else
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2010 // cf. "insertEdge()" in textbook
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2011 return (xIntersect < other.xIntersect);
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2012 #endif
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2013 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2014 };
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2015 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2016
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2017
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2018 // For an index, return y-coordinate of next nonhorizontal line
4875
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2019 static int GetPolygonNextY(const std::vector<ImageProcessing::ImagePoint>& points,
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2020 size_t k)
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2021 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2022 // cf. "yNext()" in textbook
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2023 size_t j = k;
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2024
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2025 for (;;)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2026 {
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2027 j++;
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2028 if (j == points.size())
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2029 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2030 j = 0;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2031 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2032
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2033 if (points[k].GetY() != points[j].GetY())
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2034 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2035 return points[j].GetY();
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2036 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2037 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2038 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2039
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2040
4875
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2041 static int GetPolygonPreviousY(const std::vector<ImageProcessing::ImagePoint>& points,
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2042 size_t k)
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2043 {
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2044 size_t j = k;
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2045
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2046 for (;;)
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2047 {
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2048 if (j > 0)
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2049 {
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2050 j --;
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2051 }
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2052 else
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2053 {
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2054 j = points.size() - 1;
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2055 }
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2056
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2057 if (points[k].GetY() != points[j].GetY())
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2058 {
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2059 return points[j].GetY();
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2060 }
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2061 }
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2062 }
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2063
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2064
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2065
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2066 void ImageProcessing::FillPolygon(IPolygonFiller& filler,
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2067 const std::vector<ImagePoint>& points)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2068 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2069 /**
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2070 * This implementation is a C++ adaption of Section 3.11 (pages
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2071 * 117-124) of textbook "Computer Graphics - C Version (2nd
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2072 * Edition)" by Hearn and Baker, 1997.
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2073 **/
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2074
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2075 typedef std::map<int, std::list<PolygonEdge> > EdgeTable;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2076
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2077 if (points.size() < 2)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2078 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2079 return;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2080 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2081
4875
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2082 bool onlyHorizontalSegments = true;
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2083 for (size_t i = 1; i < points.size(); i++)
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2084 {
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2085 if (points[0].GetY() != points[i].GetY())
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2086 {
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2087 onlyHorizontalSegments = false;
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2088 break;
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2089 }
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2090 }
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2091
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2092 if (onlyHorizontalSegments)
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2093 {
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2094 // Degenerate case: There are only horizontal lines. If this is
4889
d8c8274d4e41 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4875
diff changeset
2095 // the case, "GetPolygonPreviousY()" would be an infinite loop
4875
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2096 int x1 = points[0].GetX();
4889
d8c8274d4e41 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4875
diff changeset
2097 int x2 = x1;
4875
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2098 for (size_t i = 1; i < points.size(); i++)
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2099 {
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2100 assert(points[i].GetY() == points[0].GetY());
4889
d8c8274d4e41 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4875
diff changeset
2101
d8c8274d4e41 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4875
diff changeset
2102 const int x = points[i].GetX();
d8c8274d4e41 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4875
diff changeset
2103 x1 = std::min(x1, x);
d8c8274d4e41 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4875
diff changeset
2104 x2 = std::max(x2, x);
4875
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2105 }
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2106 filler.Fill(points[0].GetY(), x1, x2);
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2107 return;
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2108 }
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2109
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2110 EdgeTable globalEdgeTable;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2111
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2112 // cf. "buildEdgeList()" in textbook
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2113
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2114 // Error in the textbook: we use "GetPolygonPreviousY()" instead of "points.size() - 2"
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2115 int yPrev = GetPolygonPreviousY(points, points.size() - 1);
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2116 ImagePoint v1(points[points.size() - 1]);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2117
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2118 for (size_t i = 0; i < points.size(); i++)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2119 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2120 ImagePoint v2(points[i]);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2121
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2122 if (v1.GetY() != v2.GetY())
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2123 {
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2124 // Non-horizontal line
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2125 if (v1.GetY() < v2.GetY())
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2126 {
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2127 // Up-going edge
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2128 PolygonEdge edge(v1, v2, GetPolygonNextY(points, i));
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2129 globalEdgeTable[v1.GetY()].push_back(edge);
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2130 }
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2131 else if (v1.GetY() > v2.GetY())
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2132 {
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2133 // Down-going edge
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2134 PolygonEdge edge(v2, v1, yPrev);
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2135 globalEdgeTable[v2.GetY()].push_back(edge);
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2136 }
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2137
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2138 // Error in the textbook: "yPrev" must NOT be updated on horizontal lines
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2139 yPrev = v1.GetY();
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2140 }
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2141
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2142 v1 = v2;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2143 }
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2144
4875
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2145 assert(!globalEdgeTable.empty());
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2146
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2147 std::vector<PolygonEdge> activeEdges;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2148
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2149 for (EdgeTable::const_iterator it = globalEdgeTable.begin(); it != globalEdgeTable.end(); ++it)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2150 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2151 // cf. "buildActiveList()" in textbook
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2152 activeEdges.reserve(activeEdges.size() + it->second.size());
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2153 for (std::list<PolygonEdge>::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2154 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2155 activeEdges.push_back(*it2);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2156 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2157
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2158 assert(!activeEdges.empty());
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2159
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2160 EdgeTable::const_iterator next = it;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2161 ++next;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2162
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2163 int rampEnd;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2164 if (next == globalEdgeTable.end())
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2165 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2166 rampEnd = activeEdges[0].GetUpperY() + 1;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2167
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2168 for (size_t i = 1; i < activeEdges.size(); i++)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2169 {
4873
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4872
diff changeset
2170 rampEnd = std::max(rampEnd, activeEdges[i].GetUpperY() + 1);
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2171 }
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2172 }
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2173 else
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2174 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2175 rampEnd = next->first;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2176 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2177
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2178 for (int y = it->first; y < rampEnd; y++)
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2179 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2180 // cf. "updateActiveList()" in textbook
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2181 std::vector<PolygonEdge> stillActive;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2182 stillActive.reserve(activeEdges.size());
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2183
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2184 for (size_t i = 0; i < activeEdges.size(); i++)
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2185 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2186 if (y <= activeEdges[i].GetUpperY())
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2187 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2188 stillActive.push_back(activeEdges[i]);
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2189 }
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2190 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2191
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2192 activeEdges.swap(stillActive);
4874
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2193
bee6da5155dc fix polygon filling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4873
diff changeset
2194 assert(activeEdges.size() % 2 == 0);
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2195 std::sort(activeEdges.begin(), activeEdges.end());
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2196
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2197 // cf. "fillScan()" in textbook
4875
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2198 for (size_t k = 0; k + 1 < activeEdges.size(); )
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2199 {
4873
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4872
diff changeset
2200 int a = activeEdges[k].GetExitX();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4872
diff changeset
2201 int b = activeEdges[k + 1].GetEnterX();
4875
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2202
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2203 // Fix wrt. the textbook: merge overlapping segments
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2204 k += 2;
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2205 while (k + 1 < activeEdges.size() &&
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2206 activeEdges[k].GetExitX() == b)
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2207 {
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2208 assert(a <= b);
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2209 b = activeEdges[k + 1].GetEnterX();
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2210 k += 2;
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2211 }
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2212
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2213 assert(a <= b);
5dae41084ab7 fix filling polygons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4874
diff changeset
2214 filler.Fill(y, a, b);
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2215 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2216
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2217 // cf. "updateActiveList()" in textbook
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2218 for (size_t k = 0; k < activeEdges.size(); k++)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2219 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2220 activeEdges[k].NextScanLine();
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2221 }
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2222 }
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2223 }
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2224 }
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2225
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2226
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2227 void ImageProcessing::FillPolygon(ImageAccessor& image,
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2228 const std::vector<ImagePoint>& points,
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2229 int64_t value)
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2230 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2231 class Filler : public IPolygonFiller
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2232 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2233 private:
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2234 ImageAccessor& image_;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2235 int64_t value_;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2236
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2237 public:
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2238 Filler(ImageAccessor& image,
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2239 int64_t value) :
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2240 image_(image),
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2241 value_(value)
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
2242 {
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
2243 }
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2244
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2245 virtual void Fill(int y,
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2246 int x1,
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2247 int x2) ORTHANC_OVERRIDE
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
2248 {
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2249 assert(x1 <= x2);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2250
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2251 if (x1 < static_cast<int>(image_.GetWidth()) &&
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2252 x2 >= 0 &&
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2253 y >= 0 &&
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2254 y < static_cast<int>(image_.GetHeight()))
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2255 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2256 unsigned int yy = static_cast<unsigned int>(y);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2257 unsigned int a = static_cast<unsigned int>(std::max(0, x1));
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2258 unsigned int b = static_cast<unsigned int>(std::min(x2, static_cast<int>(image_.GetWidth()) - 1));
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2259
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2260 assert(a <= b);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2261
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2262 ImageAccessor region;
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2263 image_.GetRegion(region, a, yy, b - a + 1, 1);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2264 Set(region, value_);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2265 }
3499
d8f7c3970e25 more tolerance in ImageProcessing::Set()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3431
diff changeset
2266 }
4872
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2267 };
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2268
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2269
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2270 if (image.GetFormat() == PixelFormat_Grayscale8 ||
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2271 image.GetFormat() == PixelFormat_Grayscale16 ||
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2272 image.GetFormat() == PixelFormat_SignedGrayscale16)
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2273 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2274 Filler filler(image, value);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2275 FillPolygon(filler, points);
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2276 }
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2277 else
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2278 {
b1556cefa5c6 reimplementation from scratch of ImageProcessing::FillPolygon()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
2279 throw OrthancException(ErrorCode_NotImplemented);
3258
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2280 }
6f652c7bfc85 ImageProcessing::FillPolygon
Alain Mazy <alain@mazy.be>
parents: 3234
diff changeset
2281 }
3502
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2282
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2283
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2284 template <PixelFormat Format>
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2285 static void ResizeInternal(ImageAccessor& target,
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2286 const ImageAccessor& source)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2287 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2288 assert(target.GetFormat() == source.GetFormat() &&
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2289 target.GetFormat() == Format);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2290
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2291 const unsigned int sourceWidth = source.GetWidth();
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2292 const unsigned int sourceHeight = source.GetHeight();
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2293 const unsigned int targetWidth = target.GetWidth();
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2294 const unsigned int targetHeight = target.GetHeight();
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2295
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2296 if (targetWidth == 0 || targetHeight == 0)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2297 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2298 return;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2299 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2300
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2301 if (sourceWidth == 0 || sourceHeight == 0)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2302 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2303 // Avoids division by zero below
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2304 ImageProcessing::Set(target, 0);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2305 return;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2306 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2307
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2308 const float scaleX = static_cast<float>(sourceWidth) / static_cast<float>(targetWidth);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2309 const float scaleY = static_cast<float>(sourceHeight) / static_cast<float>(targetHeight);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2310
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2311
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2312 /**
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2313 * Create two lookup tables to quickly know the (x,y) position
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2314 * in the source image, given the (x,y) position in the target
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2315 * image.
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2316 **/
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2317
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2318 std::vector<unsigned int> lookupX(targetWidth);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2319
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2320 for (unsigned int x = 0; x < targetWidth; x++)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2321 {
3585
113a9643e8bb Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3565
diff changeset
2322 int sourceX = static_cast<int>(std::floor((static_cast<float>(x) + 0.5f) * scaleX));
3502
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2323 if (sourceX < 0)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2324 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2325 sourceX = 0; // Should never happen
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2326 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2327 else if (sourceX >= static_cast<int>(sourceWidth))
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2328 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2329 sourceX = sourceWidth - 1;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2330 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2331
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2332 lookupX[x] = static_cast<unsigned int>(sourceX);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2333 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2334
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2335 std::vector<unsigned int> lookupY(targetHeight);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2336
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2337 for (unsigned int y = 0; y < targetHeight; y++)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2338 {
3585
113a9643e8bb Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3565
diff changeset
2339 int sourceY = static_cast<int>(std::floor((static_cast<float>(y) + 0.5f) * scaleY));
3502
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2340 if (sourceY < 0)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2341 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2342 sourceY = 0; // Should never happen
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2343 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2344 else if (sourceY >= static_cast<int>(sourceHeight))
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2345 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2346 sourceY = sourceHeight - 1;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2347 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2348
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2349 lookupY[y] = static_cast<unsigned int>(sourceY);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2350 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2351
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2352
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2353 /**
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2354 * Actual resizing
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2355 **/
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2356
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2357 for (unsigned int targetY = 0; targetY < targetHeight; targetY++)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2358 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2359 unsigned int sourceY = lookupY[targetY];
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2360
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2361 for (unsigned int targetX = 0; targetX < targetWidth; targetX++)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2362 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2363 unsigned int sourceX = lookupX[targetX];
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2364
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2365 typename ImageTraits<Format>::PixelType pixel;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2366 ImageTraits<Format>::GetPixel(pixel, source, sourceX, sourceY);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2367 ImageTraits<Format>::SetPixel(target, pixel, targetX, targetY);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2368 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2369 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2370 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2371
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2372
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2373
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2374 void ImageProcessing::Resize(ImageAccessor& target,
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2375 const ImageAccessor& source)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2376 {
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
2377 if (source.GetFormat() != target.GetFormat())
3502
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2378 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2379 throw OrthancException(ErrorCode_IncompatibleImageFormat);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2380 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2381
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2382 if (source.GetWidth() == target.GetWidth() &&
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2383 source.GetHeight() == target.GetHeight())
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2384 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2385 Copy(target, source);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2386 return;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2387 }
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
2388
3502
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2389 switch (source.GetFormat())
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2390 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2391 case PixelFormat_Grayscale8:
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2392 ResizeInternal<PixelFormat_Grayscale8>(target, source);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2393 break;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2394
3548
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
2395 case PixelFormat_Float32:
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
2396 ResizeInternal<PixelFormat_Float32>(target, source);
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
2397 break;
e1ce68692069 ImageProcessing::ApplyWindowing
Alain Mazy <alain@mazy.be>
parents: 3547
diff changeset
2398
3502
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2399 case PixelFormat_RGB24:
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2400 ResizeInternal<PixelFormat_RGB24>(target, source);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2401 break;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2402
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2403 default:
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2404 throw OrthancException(ErrorCode_NotImplemented);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2405 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2406 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2407
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2408
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2409 ImageAccessor* ImageProcessing::Halve(const ImageAccessor& source,
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2410 bool forceMinimalPitch)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2411 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
2412 std::unique_ptr<Image> target(new Image(source.GetFormat(), source.GetWidth() / 2,
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
2413 source.GetHeight() / 2, forceMinimalPitch));
3502
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2414 Resize(*target, source);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2415 return target.release();
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2416 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2417
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2418
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2419 template <PixelFormat Format>
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2420 static void FlipXInternal(ImageAccessor& image)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2421 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2422 const unsigned int height = image.GetHeight();
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2423 const unsigned int width = image.GetWidth();
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2424
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2425 for (unsigned int y = 0; y < height; y++)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2426 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2427 for (unsigned int x1 = 0; x1 < width / 2; x1++)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2428 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2429 unsigned int x2 = width - 1 - x1;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2430
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2431 typename ImageTraits<Format>::PixelType a, b;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2432 ImageTraits<Format>::GetPixel(a, image, x1, y);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2433 ImageTraits<Format>::GetPixel(b, image, x2, y);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2434 ImageTraits<Format>::SetPixel(image, a, x2, y);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2435 ImageTraits<Format>::SetPixel(image, b, x1, y);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2436 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2437 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2438 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2439
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2440
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2441 void ImageProcessing::FlipX(ImageAccessor& image)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2442 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2443 switch (image.GetFormat())
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2444 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2445 case PixelFormat_Grayscale8:
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2446 FlipXInternal<PixelFormat_Grayscale8>(image);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2447 break;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2448
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2449 case PixelFormat_RGB24:
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2450 FlipXInternal<PixelFormat_RGB24>(image);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2451 break;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2452
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2453 default:
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2454 throw OrthancException(ErrorCode_NotImplemented);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2455 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2456 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2457
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2458
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2459 template <PixelFormat Format>
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2460 static void FlipYInternal(ImageAccessor& image)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2461 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2462 const unsigned int height = image.GetHeight();
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2463 const unsigned int width = image.GetWidth();
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2464
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2465 for (unsigned int y1 = 0; y1 < height / 2; y1++)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2466 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2467 unsigned int y2 = height - 1 - y1;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2468
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2469 for (unsigned int x = 0; x < width; x++)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2470 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2471 typename ImageTraits<Format>::PixelType a, b;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2472 ImageTraits<Format>::GetPixel(a, image, x, y1);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2473 ImageTraits<Format>::GetPixel(b, image, x, y2);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2474 ImageTraits<Format>::SetPixel(image, a, x, y2);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2475 ImageTraits<Format>::SetPixel(image, b, x, y1);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2476 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2477 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2478 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2479
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2480
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2481 void ImageProcessing::FlipY(ImageAccessor& image)
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2482 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2483 switch (image.GetFormat())
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2484 {
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2485 case PixelFormat_Grayscale8:
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2486 FlipYInternal<PixelFormat_Grayscale8>(image);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2487 break;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2488
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2489 case PixelFormat_RGB24:
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2490 FlipYInternal<PixelFormat_RGB24>(image);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2491 break;
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2492
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2493 default:
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2494 throw OrthancException(ErrorCode_NotImplemented);
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2495 }
c160eafc42a9 new functions in ImageProcessing toolbox: FlipX/Y(), Resize(), Halve()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3499
diff changeset
2496 }
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2497
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2498
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2499 // This is a slow implementation of horizontal convolution on one
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2500 // individual channel, that checks for out-of-image values
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2501 template <typename RawPixel, unsigned int ChannelsCount>
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4278
diff changeset
2502 static float GetHorizontalConvolutionFloatSecure(const ImageAccessor& source,
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2503 const std::vector<float>& horizontal,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2504 size_t horizontalAnchor,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2505 unsigned int x,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2506 unsigned int y,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2507 float leftBorder,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2508 float rightBorder,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2509 unsigned int channel)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2510 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2511 const RawPixel* row = reinterpret_cast<const RawPixel*>(source.GetConstRow(y)) + channel;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2512
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2513 float p = 0;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2514
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2515 for (unsigned int k = 0; k < horizontal.size(); k++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2516 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2517 float value;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2518
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2519 if (x + k < horizontalAnchor) // Negation of "x - horizontalAnchor + k >= 0"
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2520 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2521 value = leftBorder;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2522 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2523 else if (x + k >= source.GetWidth() + horizontalAnchor) // Negation of "x - horizontalAnchor + k < width"
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2524 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2525 value = rightBorder;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2526 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2527 else
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2528 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2529 // The value lies within the image
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2530 value = row[(x - horizontalAnchor + k) * ChannelsCount];
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2531 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2532
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2533 p += value * horizontal[k];
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2534 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2535
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2536 return p;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2537 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2538
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2539
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2540
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2541 // This is an implementation of separable convolution that uses
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2542 // floating-point arithmetics, and an intermediate Float32
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2543 // image. The out-of-image values are taken as the border
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2544 // value. Further optimization is possible.
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2545 template <typename RawPixel, unsigned int ChannelsCount, bool UseRound>
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2546 static void SeparableConvolutionFloat(ImageAccessor& image /* inplace */,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2547 const std::vector<float>& horizontal,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2548 size_t horizontalAnchor,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2549 const std::vector<float>& vertical,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2550 size_t verticalAnchor,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2551 float normalization)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2552 {
3525
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
2553 // WARNING - "::min()" should be replaced by "::lowest()" if
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
2554 // dealing with float or double (which is not the case so far)
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
2555 assert(sizeof(RawPixel) <= 2); // Safeguard to remember about "float/double"
8c66c9c2257b fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
2556
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2557 const unsigned int width = image.GetWidth();
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2558 const unsigned int height = image.GetHeight();
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2559
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2560
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2561 /**
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2562 * Horizontal convolution
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2563 **/
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2564
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2565 Image tmp(PixelFormat_Float32, ChannelsCount * width, height, false);
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2566
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2567 for (unsigned int y = 0; y < height; y++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2568 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2569 const RawPixel* row = reinterpret_cast<const RawPixel*>(image.GetConstRow(y));
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2570
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2571 float leftBorder[ChannelsCount], rightBorder[ChannelsCount];
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2572
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2573 for (unsigned int c = 0; c < ChannelsCount; c++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2574 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2575 leftBorder[c] = row[c];
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2576 rightBorder[c] = row[ChannelsCount * (width - 1) + c];
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2577 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2578
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2579 float* p = static_cast<float*>(tmp.GetRow(y));
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2580
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2581 if (width < horizontal.size())
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2582 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2583 // It is not possible to have the full kernel within the image, use the direct implementation
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2584 for (unsigned int x = 0; x < width; x++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2585 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2586 for (unsigned int c = 0; c < ChannelsCount; c++, p++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2587 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2588 *p = GetHorizontalConvolutionFloatSecure<RawPixel, ChannelsCount>
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2589 (image, horizontal, horizontalAnchor, x, y, leftBorder[c], rightBorder[c], c);
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2590 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2591 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2592 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2593 else
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2594 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2595 // Deal with the left border
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2596 for (unsigned int x = 0; x < horizontalAnchor; x++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2597 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2598 for (unsigned int c = 0; c < ChannelsCount; c++, p++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2599 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2600 *p = GetHorizontalConvolutionFloatSecure<RawPixel, ChannelsCount>
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2601 (image, horizontal, horizontalAnchor, x, y, leftBorder[c], rightBorder[c], c);
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2602 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2603 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2604
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2605 // Deal with the central portion of the image (all pixel values
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2606 // scanned by the kernel lie inside the image)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2607
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2608 for (unsigned int x = 0; x < width - horizontal.size() + 1; x++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2609 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2610 for (unsigned int c = 0; c < ChannelsCount; c++, p++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2611 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2612 *p = 0;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2613 for (unsigned int k = 0; k < horizontal.size(); k++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2614 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2615 *p += static_cast<float>(row[(x + k) * ChannelsCount + c]) * horizontal[k];
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2616 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2617 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2618 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2619
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2620 // Deal with the right border
3585
113a9643e8bb Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3565
diff changeset
2621 for (unsigned int x = static_cast<unsigned int>(
3682
5f64c866108a merging implementations of ImageProcessing::ShiftScale() and ApplyWindowing()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
2622 horizontalAnchor + width - horizontal.size() + 1); x < width; x++)
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2623 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2624 for (unsigned int c = 0; c < ChannelsCount; c++, p++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2625 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2626 *p = GetHorizontalConvolutionFloatSecure<RawPixel, ChannelsCount>
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2627 (image, horizontal, horizontalAnchor, x, y, leftBorder[c], rightBorder[c], c);
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2628 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2629 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2630 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2631 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2632
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2633
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2634 /**
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2635 * Vertical convolution
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2636 **/
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2637
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2638 std::vector<const float*> rows(vertical.size());
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2639
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2640 for (unsigned int y = 0; y < height; y++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2641 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2642 for (unsigned int k = 0; k < vertical.size(); k++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2643 {
3504
18566f9e1831 unit testing new functions in ImageProcessing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3503
diff changeset
2644 if (y + k < verticalAnchor)
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2645 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2646 rows[k] = reinterpret_cast<const float*>(tmp.GetConstRow(0)); // Use top border
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2647 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2648 else if (y + k >= height + verticalAnchor)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2649 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2650 rows[k] = reinterpret_cast<const float*>(tmp.GetConstRow(height - 1)); // Use bottom border
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2651 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2652 else
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2653 {
3585
113a9643e8bb Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents: 3565
diff changeset
2654 rows[k] = reinterpret_cast<const float*>(tmp.GetConstRow(static_cast<unsigned int>(y + k - verticalAnchor)));
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2655 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2656 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2657
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2658 RawPixel* p = reinterpret_cast<RawPixel*>(image.GetRow(y));
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2659
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2660 for (unsigned int x = 0; x < width; x++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2661 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2662 for (unsigned int c = 0; c < ChannelsCount; c++, p++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2663 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2664 float accumulator = 0;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2665
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2666 for (unsigned int k = 0; k < vertical.size(); k++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2667 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2668 accumulator += rows[k][ChannelsCount * x + c] * vertical[k];
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2669 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2670
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2671 accumulator *= normalization;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2672
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2673 if (accumulator <= static_cast<float>(std::numeric_limits<RawPixel>::min()))
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2674 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2675 *p = std::numeric_limits<RawPixel>::min();
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2676 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2677 else if (accumulator >= static_cast<float>(std::numeric_limits<RawPixel>::max()))
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2678 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2679 *p = std::numeric_limits<RawPixel>::max();
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2680 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2681 else
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2682 {
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2683 if (UseRound)
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2684 {
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2685 assert(sizeof(RawPixel) < sizeof(int));
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2686 *p = static_cast<RawPixel>(boost::math::iround(accumulator));
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2687 }
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2688 else
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2689 {
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2690 *p = static_cast<RawPixel>(accumulator);
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2691 }
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2692 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2693 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2694 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2695 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2696 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2697
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2698
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2699 void ImageProcessing::SeparableConvolution(ImageAccessor& image /* inplace */,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2700 const std::vector<float>& horizontal,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2701 size_t horizontalAnchor,
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2702 const std::vector<float>& vertical,
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2703 size_t verticalAnchor,
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2704 bool useRound)
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2705 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2706 if (horizontal.size() == 0 ||
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2707 vertical.size() == 0 ||
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2708 horizontalAnchor >= horizontal.size() ||
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2709 verticalAnchor >= vertical.size())
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2710 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2711 throw OrthancException(ErrorCode_ParameterOutOfRange);
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2712 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2713
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2714 if (image.GetWidth() == 0 ||
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2715 image.GetHeight() == 0)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2716 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2717 return;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2718 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2719
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2720 /**
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2721 * Compute normalization
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2722 **/
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2723
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2724 float sumHorizontal = 0;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2725 for (size_t i = 0; i < horizontal.size(); i++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2726 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2727 sumHorizontal += horizontal[i];
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2728 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2729
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2730 float sumVertical = 0;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2731 for (size_t i = 0; i < vertical.size(); i++)
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2732 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2733 sumVertical += vertical[i];
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2734 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2735
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2736 if (fabsf(sumHorizontal) <= std::numeric_limits<float>::epsilon() ||
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2737 fabsf(sumVertical) <= std::numeric_limits<float>::epsilon())
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2738 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2739 throw OrthancException(ErrorCode_ParameterOutOfRange, "Singular convolution kernel");
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2740 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2741
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2742 const float normalization = 1.0f / (sumHorizontal * sumVertical);
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2743
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2744 switch (image.GetFormat())
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2745 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2746 case PixelFormat_Grayscale8:
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2747 if (useRound)
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2748 {
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2749 SeparableConvolutionFloat<uint8_t, 1u, true>
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2750 (image, horizontal, horizontalAnchor, vertical, verticalAnchor, normalization);
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2751 }
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2752 else
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2753 {
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2754 SeparableConvolutionFloat<uint8_t, 1u, false>
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2755 (image, horizontal, horizontalAnchor, vertical, verticalAnchor, normalization);
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2756 }
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2757 break;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2758
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2759 case PixelFormat_RGB24:
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2760 if (useRound)
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2761 {
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2762 SeparableConvolutionFloat<uint8_t, 3u, true>
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2763 (image, horizontal, horizontalAnchor, vertical, verticalAnchor, normalization);
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2764 }
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2765 else
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2766 {
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2767 SeparableConvolutionFloat<uint8_t, 3u, false>
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2768 (image, horizontal, horizontalAnchor, vertical, verticalAnchor, normalization);
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2769 }
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2770 break;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2771
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2772 default:
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2773 throw OrthancException(ErrorCode_NotImplemented);
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2774 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2775 }
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2776
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2777
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2778 void ImageProcessing::SmoothGaussian5x5(ImageAccessor& image,
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2779 bool useRound)
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2780 {
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2781 std::vector<float> kernel(5);
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2782 kernel[0] = 1;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2783 kernel[1] = 4;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2784 kernel[2] = 6;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2785 kernel[3] = 4;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2786 kernel[4] = 1;
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2787
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2788 SeparableConvolution(image, kernel, 2, kernel, 2, useRound);
3503
46cf170ba121 ImageProcessing::SeparableConvolution()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3502
diff changeset
2789 }
3549
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2790
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2791
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2792 void ImageProcessing::FitSize(ImageAccessor& target,
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2793 const ImageAccessor& source)
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2794 {
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2795 if (target.GetWidth() == 0 ||
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2796 target.GetHeight() == 0)
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2797 {
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2798 return;
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2799 }
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2800
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2801 if (source.GetWidth() == target.GetWidth() &&
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2802 source.GetHeight() == target.GetHeight())
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2803 {
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2804 Copy(target, source);
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2805 return;
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2806 }
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2807
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2808 Set(target, 0);
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2809
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2810 // Preserve the aspect ratio
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2811 float cw = static_cast<float>(source.GetWidth());
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2812 float ch = static_cast<float>(source.GetHeight());
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2813 float r = std::min(
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2814 static_cast<float>(target.GetWidth()) / cw,
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2815 static_cast<float>(target.GetHeight()) / ch);
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2816
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2817 unsigned int sw = std::min(static_cast<unsigned int>(boost::math::iround(cw * r)), target.GetWidth());
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2818 unsigned int sh = std::min(static_cast<unsigned int>(boost::math::iround(ch * r)), target.GetHeight());
4065
d6362b2c4b61 export dcmdata in shared library, rounding in convolution tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4056
diff changeset
2819
3549
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2820 Image resized(target.GetFormat(), sw, sh, false);
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2821
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2822 //ImageProcessing::SmoothGaussian5x5(source);
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2823 ImageProcessing::Resize(resized, source);
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2824
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2825 assert(target.GetWidth() >= resized.GetWidth() &&
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2826 target.GetHeight() >= resized.GetHeight());
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2827 unsigned int offsetX = (target.GetWidth() - resized.GetWidth()) / 2;
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2828 unsigned int offsetY = (target.GetHeight() - resized.GetHeight()) / 2;
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2829
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2830 ImageAccessor region;
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2831 target.GetRegion(region, offsetX, offsetY, resized.GetWidth(), resized.GetHeight());
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2832 ImageProcessing::Copy(region, resized);
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2833 }
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2834
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2835
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2836 ImageAccessor* ImageProcessing::FitSize(const ImageAccessor& source,
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2837 unsigned int width,
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2838 unsigned int height)
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2839 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3690
diff changeset
2840 std::unique_ptr<ImageAccessor> target(new Image(source.GetFormat(), width, height, false));
3549
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2841 FitSize(*target, source);
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2842 return target.release();
fab5777f4dd4 ImageProcessing::FitSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3547
diff changeset
2843 }
4082
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2844
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2845
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2846 ImageAccessor* ImageProcessing::FitSizeKeepAspectRatio(const ImageAccessor& source,
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2847 unsigned int width,
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2848 unsigned int height)
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2849 {
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2850 std::unique_ptr<ImageAccessor> target(new Image(source.GetFormat(), width, height, false));
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2851 Set(*target, 0);
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2852
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2853 if (width != 0 &&
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2854 height != 0 &&
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2855 source.GetWidth() != 0 &&
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2856 source.GetHeight() != 0)
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2857 {
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2858 float ratio = std::min(static_cast<float>(width) / static_cast<float>(source.GetWidth()),
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2859 static_cast<float>(height) / static_cast<float>(source.GetHeight()));
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2860
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2861 unsigned int resizedWidth = static_cast<unsigned int>(
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2862 boost::math::iround(ratio * static_cast<float>(source.GetWidth())));
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2863
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2864 unsigned int resizedHeight = static_cast<unsigned int>(
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2865 boost::math::iround(ratio * static_cast<float>(source.GetHeight())));
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2866
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2867 std::unique_ptr<ImageAccessor> resized(FitSize(source, resizedWidth, resizedHeight));
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2868
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2869 ImageAccessor region;
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2870 target->GetRegion(region, (width - resizedWidth) / 2,
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2871 (height - resizedHeight) / 2, resizedWidth, resizedHeight);
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2872 Copy(region, *resized);
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2873 }
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2874
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2875 return target.release();
2e1564f57542 ImageProcessing::FitSizeKeepAspectRatio()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4080
diff changeset
2876 }
4443
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2877
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2878
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2879 void ImageProcessing::ConvertJpegYCbCrToRgb(ImageAccessor& image)
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2880 {
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2881 // http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.3.html#sect_C.7.6.3.1.2
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2882 // https://en.wikipedia.org/wiki/YCbCr#JPEG_conversion
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2883
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2884 // TODO - Check out the outcome of Mathieu's discussion about
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2885 // truncation of YCbCr-to-RGB conversion:
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2886 // https://groups.google.com/forum/#!msg/comp.protocols.dicom/JHuGeyWbTz8/ARoTWrJzAQAJ
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2887
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2888 const unsigned int width = image.GetWidth();
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2889 const unsigned int height = image.GetHeight();
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2890 const unsigned int pitch = image.GetPitch();
5839
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5640
diff changeset
2891
4443
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2892 if (image.GetFormat() != PixelFormat_RGB24 ||
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2893 pitch < 3 * width)
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2894 {
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2895 throw OrthancException(ErrorCode_IncompatibleImageFormat);
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2896 }
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2897
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2898 for (unsigned int y = 0; y < height; y++)
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2899 {
5839
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5640
diff changeset
2900 uint8_t* p = reinterpret_cast<uint8_t*>(image.GetRow(y));
4443
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2901
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2902 for (unsigned int x = 0; x < width; x++, p += 3)
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2903 {
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2904 const float Y = p[0];
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2905 const float Cb = p[1];
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2906 const float Cr = p[2];
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2907
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2908 const float result[3] = {
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2909 Y + 1.402f * (Cr - 128.0f),
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2910 Y - 0.344136f * (Cb - 128.0f) - 0.714136f * (Cr - 128.0f),
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2911 Y + 1.772f * (Cb - 128.0f)
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2912 };
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2913
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2914 for (uint8_t i = 0; i < 3 ; i++)
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2915 {
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2916 if (result[i] < 0)
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2917 {
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2918 p[i] = 0;
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2919 }
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2920 else if (result[i] > 255)
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2921 {
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2922 p[i] = 255;
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2923 }
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2924 else
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2925 {
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2926 p[i] = static_cast<uint8_t>(result[i]);
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2927 }
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2928 }
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2929 }
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2930 }
fd958175c5b9 ImageProcessing::ConvertJpegYCbCrToRgb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
2931 }
4529
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2932
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2933
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2934 void ImageProcessing::SwapEndianness(ImageAccessor& image /* inplace */)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2935 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2936 const unsigned int width = image.GetWidth();
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2937 const unsigned int height = image.GetHeight();
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2938
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2939 switch (image.GetFormat())
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2940 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2941 case PixelFormat_Grayscale8:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2942 case PixelFormat_RGB24:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2943 case PixelFormat_RGBA32:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2944 case PixelFormat_BGRA32:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2945 // No swapping required
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2946 break;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2947
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2948 case PixelFormat_Grayscale16:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2949 case PixelFormat_SignedGrayscale16:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2950 for (unsigned int y = 0; y < height; y++)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2951 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2952 uint8_t* t = reinterpret_cast<uint8_t*>(image.GetRow(y));
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2953 for (unsigned int x = 0; x < width; x++)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2954 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2955 uint8_t a = t[0];
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2956 t[0] = t[1];
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2957 t[1] = a;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2958 t += 2;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2959 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2960 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2961 break;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2962
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2963 case PixelFormat_Grayscale32:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2964 case PixelFormat_Float32:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2965 for (unsigned int y = 0; y < height; y++)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2966 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2967 uint8_t* t = reinterpret_cast<uint8_t*>(image.GetRow(y));
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2968 for (unsigned int x = 0; x < width; x++)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2969 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2970 uint8_t a = t[0];
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2971 uint8_t b = t[1];
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2972 t[0] = t[3];
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2973 t[1] = t[2];
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2974 t[2] = b;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2975 t[3] = a;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2976 t += 4;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2977 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2978 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2979 break;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2980
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2981 case PixelFormat_RGB48: // uint16_t per channel
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2982 for (unsigned int y = 0; y < height; y++)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2983 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2984 uint8_t* t = reinterpret_cast<uint8_t*>(image.GetRow(y));
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2985 for (unsigned int x = 0; x < 3 * width; x++)
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2986 {
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2987 uint8_t a = t[0];
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2988 t[0] = t[1];
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2989 t[1] = a;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2990 t += 2;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2991 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2992 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2993 break;
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2994
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2995 default:
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2996 throw OrthancException(ErrorCode_NotImplemented);
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2997 }
5774fe497ff2 fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4447
diff changeset
2998 }
4947
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
2999
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3000
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3001 template <typename PixelType,
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3002 typename Functor>
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3003 static void ApplyImageOntoImage(Functor f,
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3004 ImageAccessor& image /* inout */,
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3005 const ImageAccessor& other)
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3006 {
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3007 const unsigned int width = image.GetWidth();
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3008 const unsigned int height = image.GetHeight();
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3009
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3010 if (width != other.GetWidth() ||
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3011 height != other.GetHeight())
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3012 {
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3013 throw OrthancException(ErrorCode_IncompatibleImageSize);
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3014 }
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3015 else if (image.GetFormat() != other.GetFormat() ||
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3016 GetBytesPerPixel(image.GetFormat()) != sizeof(PixelType))
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3017 {
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3018 throw OrthancException(ErrorCode_IncompatibleImageFormat);
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3019 }
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3020 else
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3021 {
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3022 for (unsigned int y = 0; y < height; y++)
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3023 {
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3024 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y));
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3025 const PixelType* q = reinterpret_cast<const PixelType*>(other.GetConstRow(y));
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3026
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3027 for (unsigned int x = 0; x < width; x++, p++, q++)
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3028 {
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3029 f(*p, *q);
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3030 }
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3031 }
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3032 }
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3033 }
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3034
4948
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3035
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3036 namespace
4947
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3037 {
4948
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3038 // For older version of gcc, templated functors cannot be defined
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3039 // as types internal to functions, hence the anonymous namespace
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3040
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3041 struct MaximumFunctor
4947
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3042 {
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3043 void operator() (uint8_t& a, const uint8_t& b)
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3044 {
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3045 a = std::max(a, b);
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3046 }
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3047
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3048 void operator() (uint16_t& a, const uint16_t& b)
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3049 {
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3050 a = std::max(a, b);
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3051 }
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3052 };
4948
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3053 }
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3054
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3055
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3056 void ImageProcessing::Maximum(ImageAccessor& image,
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3057 const ImageAccessor& other)
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3058 {
4947
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3059 switch (image.GetFormat())
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3060 {
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3061 case PixelFormat_Grayscale8:
4948
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3062 ApplyImageOntoImage<uint8_t, MaximumFunctor>(MaximumFunctor(), image, other);
4947
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3063 return;
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3064
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3065 case PixelFormat_Grayscale16:
4948
5f6b13202e85 fix for older gcc versions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4947
diff changeset
3066 ApplyImageOntoImage<uint16_t, MaximumFunctor>(MaximumFunctor(), image, other);
4947
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3067 return;
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3068
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3069 default:
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3070 throw OrthancException(ErrorCode_NotImplemented);
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3071 }
dfbe764995cf added ParsedDicomFile::DecodeAllOverlays()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4889
diff changeset
3072 }
853
839be3022203 DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3073 }