annotate OrthancFramework/Sources/Images/PixelTraits.h @ 4437:d9473bd5ed43

upgrade to year 2021
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 06 Jan 2021 17:27:28 +0100
parents 2007ab69ac16
children 7053502fbf97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4202
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * 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: 4044
diff changeset
8 * 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: 4044
diff changeset
9 * 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: 4044
diff changeset
10 * the License, or (at your option) any later version.
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * 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: 4044
diff changeset
15 * Lesser General Public License for more details.
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * 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: 4044
diff changeset
18 * 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: 4044
diff changeset
19 * <http://www.gnu.org/licenses/>.
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #pragma once
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
4202
2007ab69ac16 moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
25 #include "../Compatibility.h" // For ORTHANC_FORCE_INLINE
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../Enumerations.h"
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
28 #include <limits>
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace Orthanc
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
32 template <PixelFormat format,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
33 typename _PixelType>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
34 struct IntegerPixelTraits
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
36 typedef _PixelType PixelType;
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 static PixelFormat GetPixelFormat()
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
41 return format;
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
42 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
43
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
44 ORTHANC_FORCE_INLINE
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
45 static PixelType IntegerToPixel(int64_t value)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
46 {
2895
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
47 if (value < static_cast<int64_t>(std::numeric_limits<PixelType>::min()))
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
48 {
2895
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
49 return std::numeric_limits<PixelType>::min();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
50 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
51 else if (value > static_cast<int64_t>(std::numeric_limits<PixelType>::max()))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
52 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
53 return std::numeric_limits<PixelType>::max();
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
54 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
55 else
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
56 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
57 return static_cast<PixelType>(value);
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
58 }
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 static void SetZero(PixelType& target)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 target = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 ORTHANC_FORCE_INLINE
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
68 static void SetMinValue(PixelType& target)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
69 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
70 target = std::numeric_limits<PixelType>::min();
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
71 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
72
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
73 ORTHANC_FORCE_INLINE
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
74 static void SetMaxValue(PixelType& target)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
75 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
76 target = std::numeric_limits<PixelType>::max();
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
77 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
78
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
79 ORTHANC_FORCE_INLINE
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 static void Copy(PixelType& target,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 const PixelType& source)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 target = source;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 static float PixelToFloat(const PixelType& source)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 return static_cast<float>(source);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 static void FloatToPixel(PixelType& target,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 float value)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
3263
f58553a98204 fix rounding
am@osimis.io
parents: 3060
diff changeset
96 value += 0.5f;
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
97 if (value < static_cast<float>(std::numeric_limits<PixelType>::min()))
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
98 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
99 target = std::numeric_limits<PixelType>::min();
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
100 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
101 else if (value > static_cast<float>(std::numeric_limits<PixelType>::max()))
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
102 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
103 target = std::numeric_limits<PixelType>::max();
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
104 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
105 else
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
106 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
107 target = static_cast<PixelType>(value);
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
108 }
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 static bool IsEqual(const PixelType& a,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 const PixelType& b)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 return a == b;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 };
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
120 template <PixelFormat Format>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
121 struct PixelTraits;
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 template <>
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
125 struct PixelTraits<PixelFormat_Grayscale8> :
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
126 public IntegerPixelTraits<PixelFormat_Grayscale8, uint8_t>
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
128 };
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
130
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
131 template <>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
132 struct PixelTraits<PixelFormat_Grayscale16> :
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
133 public IntegerPixelTraits<PixelFormat_Grayscale16, uint16_t>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
134 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
135 };
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
137
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
138 template <>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
139 struct PixelTraits<PixelFormat_SignedGrayscale16> :
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
140 public IntegerPixelTraits<PixelFormat_SignedGrayscale16, int16_t>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
141 {
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 };
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 template <>
2645
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
146 struct PixelTraits<PixelFormat_Grayscale32> :
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
147 public IntegerPixelTraits<PixelFormat_Grayscale32, uint32_t>
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
148 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
149 };
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
150
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
151
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
152 template <>
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
153 struct PixelTraits<PixelFormat_Grayscale64> :
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
154 public IntegerPixelTraits<PixelFormat_Grayscale64, uint64_t>
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
155 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
156 };
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
157
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
158
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
159 template <>
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 struct PixelTraits<PixelFormat_RGB24>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 struct PixelType
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 uint8_t red_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 uint8_t green_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 uint8_t blue_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 };
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 static PixelFormat GetPixelFormat()
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 return PixelFormat_RGB24;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 static void SetZero(PixelType& target)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 target.red_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 target.green_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 target.blue_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 static void Copy(PixelType& target,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 const PixelType& source)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 target.red_ = source.red_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 target.green_ = source.green_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 target.blue_ = source.blue_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 static bool IsEqual(const PixelType& a,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 const PixelType& b)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 return (a.red_ == b.red_ &&
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 a.green_ == b.green_ &&
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 a.blue_ == b.blue_);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
2493
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
200
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
201 ORTHANC_FORCE_INLINE
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
202 static void FloatToPixel(PixelType& target,
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
203 float value)
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
204 {
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
205 uint8_t v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
206 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value);
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
207
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
208 target.red_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
209 target.green_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
210 target.blue_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
211 }
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 };
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 template <>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 struct PixelTraits<PixelFormat_BGRA32>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 struct PixelType
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 uint8_t blue_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 uint8_t green_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 uint8_t red_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 uint8_t alpha_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 };
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 static PixelFormat GetPixelFormat()
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 return PixelFormat_BGRA32;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 static void SetZero(PixelType& target)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 target.blue_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 target.green_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 target.red_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 target.alpha_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 static void Copy(PixelType& target,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 const PixelType& source)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 target.blue_ = source.blue_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 target.green_ = source.green_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 target.red_ = source.red_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 target.alpha_ = source.alpha_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 static bool IsEqual(const PixelType& a,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 const PixelType& b)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 return (a.blue_ == b.blue_ &&
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 a.green_ == b.green_ &&
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 a.red_ == b.red_ &&
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 a.alpha_ == b.alpha_);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 }
2493
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
260
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
261 ORTHANC_FORCE_INLINE
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
262 static void FloatToPixel(PixelType& target,
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
263 float value)
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
264 {
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
265 uint8_t v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
266 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value);
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
267
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
268 target.blue_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
269 target.green_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
270 target.red_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
271 target.alpha_ = 255;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
272 }
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 };
2645
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
274
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
275
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
276 template <>
2783
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
277 struct PixelTraits<PixelFormat_RGBA32>
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
278 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
279 struct PixelType
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
280 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
281 uint8_t red_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
282 uint8_t green_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
283 uint8_t blue_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
284 uint8_t alpha_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
285 };
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
286
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
287 ORTHANC_FORCE_INLINE
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
288 static PixelFormat GetPixelFormat()
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
289 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
290 return PixelFormat_RGBA32;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
291 }
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
292
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
293 ORTHANC_FORCE_INLINE
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
294 static void SetZero(PixelType& target)
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
295 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
296 target.red_ = 0;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
297 target.green_ = 0;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
298 target.blue_ = 0;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
299 target.alpha_ = 0;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
300 }
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
301
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
302 ORTHANC_FORCE_INLINE
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
303 static void Copy(PixelType& target,
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
304 const PixelType& source)
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
305 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
306 target.red_ = source.red_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
307 target.green_ = source.green_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
308 target.blue_ = source.blue_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
309 target.alpha_ = source.alpha_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
310 }
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
311
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
312 ORTHANC_FORCE_INLINE
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
313 static bool IsEqual(const PixelType& a,
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
314 const PixelType& b)
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
315 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
316 return (a.red_ == b.red_ &&
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
317 a.green_ == b.green_ &&
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
318 a.blue_ == b.blue_ &&
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
319 a.alpha_ == b.alpha_);
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
320 }
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
321
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
322 ORTHANC_FORCE_INLINE
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
323 static void FloatToPixel(PixelType& target,
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
324 float value)
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
325 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
326 uint8_t v;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
327 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value);
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
328
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
329 target.red_ = v;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
330 target.green_ = v;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
331 target.blue_ = v;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
332 target.alpha_ = 255;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
333 }
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
334 };
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
335
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
336
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
337 template <>
2645
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
338 struct PixelTraits<PixelFormat_Float32>
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
339 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
340 typedef float PixelType;
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
341
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
342 ORTHANC_FORCE_INLINE
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
343 static PixelFormat GetPixelFormat()
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
344 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
345 return PixelFormat_Float32;
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
346 }
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
347
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
348 ORTHANC_FORCE_INLINE
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
349 static void SetZero(PixelType& target)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
350 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
351 target = 0.0f;
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
352 }
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
353
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
354 ORTHANC_FORCE_INLINE
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
355 static void Copy(PixelType& target,
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
356 const PixelType& source)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
357 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
358 target = source;
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
359 }
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
360
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
361 ORTHANC_FORCE_INLINE
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
362 static bool IsEqual(const PixelType& a,
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
363 const PixelType& b)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
364 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
365 float tmp = (a - b);
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
366
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
367 if (tmp < 0)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
368 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
369 tmp = -tmp;
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
370 }
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
371
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
372 return tmp <= std::numeric_limits<float>::epsilon();
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
373 }
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
374
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
375 ORTHANC_FORCE_INLINE
3671
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
376 static void SetMinValue(PixelType& target)
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
377 {
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
378 // std::numeric_limits<float>::lowest is not supported on
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
379 // all compilers (for instance, Visual Studio 9.0 2008)
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
380 target = -std::numeric_limits<float>::max();
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
381 }
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
382
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
383 ORTHANC_FORCE_INLINE
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
384 static void SetMaxValue(PixelType& target)
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
385 {
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
386 target = std::numeric_limits<float>::max();
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
387 }
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
388
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
389 ORTHANC_FORCE_INLINE
2645
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
390 static void FloatToPixel(PixelType& target,
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
391 float value)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
392 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
393 target = value;
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
394 }
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
395
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
396 ORTHANC_FORCE_INLINE
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
397 static float PixelToFloat(const PixelType& source)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
398 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
399 return source;
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
400 }
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
401 };
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 }