annotate OrthancFramework/Sources/Images/PixelTraits.h @ 5095:b52fe770aec0

more logs in HttpClient
author Alain Mazy <am@osimis.io>
date Wed, 12 Oct 2022 09:22:08 +0200
parents 43e613a7756b
children 0ea402b4d901
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
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * the License, or (at your option) any later version.
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * 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
16 * Lesser General Public License for more details.
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
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
18 * 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
19 * 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
20 * <http://www.gnu.org/licenses/>.
2487
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #pragma once
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
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
26 #include "../Compatibility.h" // For ORTHANC_FORCE_INLINE
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../Enumerations.h"
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
29 #include <limits>
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace Orthanc
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
33 template <PixelFormat format,
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
34 typename _PixelType>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
35 struct IntegerPixelTraits
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
37 typedef _PixelType PixelType;
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 static PixelFormat GetPixelFormat()
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
42 return format;
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
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
45 ORTHANC_FORCE_INLINE
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
46 static PixelType IntegerToPixel(int64_t value)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
47 {
2895
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
48 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
49 {
2895
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
50 return std::numeric_limits<PixelType>::min();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
51 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
52 else if (value > static_cast<int64_t>(std::numeric_limits<PixelType>::max()))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
53 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2783
diff changeset
54 return std::numeric_limits<PixelType>::max();
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
55 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
56 else
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
57 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
58 return static_cast<PixelType>(value);
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
59 }
2487
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 static void SetZero(PixelType& target)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 target = 0;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 ORTHANC_FORCE_INLINE
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
69 static void SetMinValue(PixelType& target)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
70 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
71 target = std::numeric_limits<PixelType>::min();
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
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
74 ORTHANC_FORCE_INLINE
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
75 static void SetMaxValue(PixelType& target)
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
76 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
77 target = std::numeric_limits<PixelType>::max();
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
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
80 ORTHANC_FORCE_INLINE
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 static void Copy(PixelType& target,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 const PixelType& source)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 target = source;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 static float PixelToFloat(const PixelType& source)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 return static_cast<float>(source);
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 static void FloatToPixel(PixelType& target,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 float value)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
3263
f58553a98204 fix rounding
am@osimis.io
parents: 3060
diff changeset
97 value += 0.5f;
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
98 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
99 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
100 target = std::numeric_limits<PixelType>::min();
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
101 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
102 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
103 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
104 target = std::numeric_limits<PixelType>::max();
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
105 }
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
106 else
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
107 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
108 target = static_cast<PixelType>(value);
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
109 }
2487
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 static bool IsEqual(const PixelType& a,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 const PixelType& b)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return a == b;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
121 template <PixelFormat Format>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
122 struct PixelTraits;
2487
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 template <>
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
126 struct PixelTraits<PixelFormat_Grayscale8> :
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
127 public IntegerPixelTraits<PixelFormat_Grayscale8, uint8_t>
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
129 };
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
131
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
132 template <>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
133 struct PixelTraits<PixelFormat_Grayscale16> :
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
134 public IntegerPixelTraits<PixelFormat_Grayscale16, uint16_t>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
135 {
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
136 };
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
2489
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
138
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
139 template <>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
140 struct PixelTraits<PixelFormat_SignedGrayscale16> :
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
141 public IntegerPixelTraits<PixelFormat_SignedGrayscale16, int16_t>
e91bab2d8c75 Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2487
diff changeset
142 {
2487
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 template <>
2645
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
147 struct PixelTraits<PixelFormat_Grayscale32> :
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
148 public IntegerPixelTraits<PixelFormat_Grayscale32, uint32_t>
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
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
153 template <>
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
154 struct PixelTraits<PixelFormat_Grayscale64> :
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
155 public IntegerPixelTraits<PixelFormat_Grayscale64, uint64_t>
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
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
160 template <>
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 struct PixelTraits<PixelFormat_RGB24>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 struct PixelType
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 uint8_t red_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 uint8_t green_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 uint8_t blue_;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 static PixelFormat GetPixelFormat()
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 return PixelFormat_RGB24;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 static void SetZero(PixelType& target)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 target.red_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 target.green_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 target.blue_ = 0;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 static void Copy(PixelType& target,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 const PixelType& source)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 target.red_ = source.red_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 target.green_ = source.green_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 target.blue_ = source.blue_;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 static bool IsEqual(const PixelType& a,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 const PixelType& b)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 return (a.red_ == b.red_ &&
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 a.green_ == b.green_ &&
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 a.blue_ == b.blue_);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
2493
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
201
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
202 ORTHANC_FORCE_INLINE
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
203 static void FloatToPixel(PixelType& target,
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
204 float value)
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
205 {
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
206 uint8_t v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
207 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value);
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
208
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
209 target.red_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
210 target.green_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
211 target.blue_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
212 }
2487
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 template <>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 struct PixelTraits<PixelFormat_BGRA32>
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 struct PixelType
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 uint8_t blue_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 uint8_t green_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 uint8_t red_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 uint8_t alpha_;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 static PixelFormat GetPixelFormat()
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 return PixelFormat_BGRA32;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 static void SetZero(PixelType& target)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 target.blue_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 target.green_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 target.red_ = 0;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 target.alpha_ = 0;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 static void Copy(PixelType& target,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 const PixelType& source)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 target.blue_ = source.blue_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 target.green_ = source.green_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 target.red_ = source.red_;
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 target.alpha_ = source.alpha_;
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
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 ORTHANC_FORCE_INLINE
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 static bool IsEqual(const PixelType& a,
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 const PixelType& b)
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 {
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 return (a.blue_ == b.blue_ &&
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 a.green_ == b.green_ &&
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 a.red_ == b.red_ &&
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 a.alpha_ == b.alpha_);
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
2493
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
261
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
262 ORTHANC_FORCE_INLINE
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
263 static void FloatToPixel(PixelType& target,
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
264 float value)
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
265 {
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
266 uint8_t v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
267 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value);
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
268
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
269 target.blue_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
270 target.green_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
271 target.red_ = v;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
272 target.alpha_ = 255;
5aa787a03e7d PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2489
diff changeset
273 }
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 };
2645
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
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
277 template <>
2783
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
278 struct PixelTraits<PixelFormat_RGBA32>
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
279 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
280 struct PixelType
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
281 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
282 uint8_t red_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
283 uint8_t green_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
284 uint8_t blue_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
285 uint8_t alpha_;
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
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
288 ORTHANC_FORCE_INLINE
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
289 static PixelFormat GetPixelFormat()
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
290 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
291 return PixelFormat_RGBA32;
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
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
294 ORTHANC_FORCE_INLINE
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
295 static void SetZero(PixelType& target)
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
296 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
297 target.red_ = 0;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
298 target.green_ = 0;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
299 target.blue_ = 0;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
300 target.alpha_ = 0;
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
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
303 ORTHANC_FORCE_INLINE
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
304 static void Copy(PixelType& target,
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
305 const PixelType& source)
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
306 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
307 target.red_ = source.red_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
308 target.green_ = source.green_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
309 target.blue_ = source.blue_;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
310 target.alpha_ = source.alpha_;
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
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
313 ORTHANC_FORCE_INLINE
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
314 static bool IsEqual(const PixelType& a,
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
315 const PixelType& b)
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
316 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
317 return (a.red_ == b.red_ &&
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
318 a.green_ == b.green_ &&
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
319 a.blue_ == b.blue_ &&
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
320 a.alpha_ == b.alpha_);
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
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
323 ORTHANC_FORCE_INLINE
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
324 static void FloatToPixel(PixelType& target,
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
325 float value)
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
326 {
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
327 uint8_t v;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
328 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value);
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
329
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
330 target.red_ = v;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
331 target.green_ = v;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
332 target.blue_ = v;
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
333 target.alpha_ = 255;
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
65699fcb4e99 PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2645
diff changeset
338 template <>
2645
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
339 struct PixelTraits<PixelFormat_Float32>
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
340 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
341 typedef float PixelType;
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
342
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
343 ORTHANC_FORCE_INLINE
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
344 static PixelFormat GetPixelFormat()
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
345 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
346 return PixelFormat_Float32;
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
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
349 ORTHANC_FORCE_INLINE
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
350 static void SetZero(PixelType& target)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
351 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
352 target = 0.0f;
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
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
355 ORTHANC_FORCE_INLINE
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
356 static void Copy(PixelType& target,
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
357 const PixelType& source)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
358 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
359 target = source;
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
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
362 ORTHANC_FORCE_INLINE
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
363 static bool IsEqual(const PixelType& a,
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
364 const PixelType& b)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
365 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
366 float tmp = (a - b);
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
367
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
368 if (tmp < 0)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
369 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
370 tmp = -tmp;
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
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
373 return tmp <= std::numeric_limits<float>::epsilon();
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
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
376 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
377 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
378 {
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
379 // 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
380 // 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
381 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
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
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
384 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
385 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
386 {
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
387 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
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
3c4269229566 Added functions to retrieve min and max possible values for floating-point pixels
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
390 ORTHANC_FORCE_INLINE
2645
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
391 static void FloatToPixel(PixelType& target,
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
392 float value)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
393 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
394 target = value;
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
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
397 ORTHANC_FORCE_INLINE
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
398 static float PixelToFloat(const PixelType& source)
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
399 {
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
400 return source;
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
401 }
89b789366596 Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2493
diff changeset
402 };
2487
be1dbb1dcdd6 PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 }