Mercurial > hg > orthanc
annotate Core/Images/PixelTraits.h @ 3349:ef18ea68a362
merge
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 18 Apr 2019 15:52:56 +0200 |
parents | f58553a98204 |
children | 94f4a18a79cc |
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 |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2895
diff
changeset
|
5 * Copyright (C) 2017-2019 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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
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 * In addition, as a special exception, the copyright holders of this |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
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 * 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
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 **/ |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #pragma once |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 #include "../Enumerations.h" |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
38 #include <limits> |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 namespace Orthanc |
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 template <PixelFormat format, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
43 typename _PixelType> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
44 struct IntegerPixelTraits |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
46 typedef _PixelType PixelType; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 static PixelFormat GetPixelFormat() |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
51 return format; |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
52 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
53 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
54 ORTHANC_FORCE_INLINE |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
55 static PixelType IntegerToPixel(int64_t value) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
56 { |
2895 | 57 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
|
58 { |
2895 | 59 return std::numeric_limits<PixelType>::min(); |
60 } | |
61 else if (value > static_cast<int64_t>(std::numeric_limits<PixelType>::max())) | |
62 { | |
63 return std::numeric_limits<PixelType>::max(); | |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
64 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
65 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
66 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
67 return static_cast<PixelType>(value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
68 } |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 static void SetZero(PixelType& target) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 target = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 ORTHANC_FORCE_INLINE |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
78 static void SetMinValue(PixelType& target) |
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 target = std::numeric_limits<PixelType>::min(); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
81 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
82 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
83 ORTHANC_FORCE_INLINE |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
84 static void SetMaxValue(PixelType& target) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
85 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
86 target = std::numeric_limits<PixelType>::max(); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
87 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
88 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
89 ORTHANC_FORCE_INLINE |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 static void Copy(PixelType& target, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 const PixelType& source) |
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 target = source; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 static float PixelToFloat(const PixelType& source) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 return static_cast<float>(source); |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 static void FloatToPixel(PixelType& target, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 float value) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 { |
3263 | 106 value += 0.5f; |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
107 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
|
108 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
109 target = std::numeric_limits<PixelType>::min(); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
110 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
111 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
|
112 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
113 target = std::numeric_limits<PixelType>::max(); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
114 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
115 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
116 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
117 target = static_cast<PixelType>(value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
118 } |
2487
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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 static bool IsEqual(const PixelType& a, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 const PixelType& b) |
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 return a == b; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 }; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 |
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 template <PixelFormat Format> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
131 struct PixelTraits; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 template <> |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
135 struct PixelTraits<PixelFormat_Grayscale8> : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
136 public IntegerPixelTraits<PixelFormat_Grayscale8, uint8_t> |
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 }; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
140 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
141 template <> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
142 struct PixelTraits<PixelFormat_Grayscale16> : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
143 public IntegerPixelTraits<PixelFormat_Grayscale16, uint16_t> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
144 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
145 }; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
147 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
148 template <> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
149 struct PixelTraits<PixelFormat_SignedGrayscale16> : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
150 public IntegerPixelTraits<PixelFormat_SignedGrayscale16, int16_t> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
151 { |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 }; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 template <> |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
156 struct PixelTraits<PixelFormat_Grayscale32> : |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
157 public IntegerPixelTraits<PixelFormat_Grayscale32, uint32_t> |
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 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
161 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
162 template <> |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
163 struct PixelTraits<PixelFormat_Grayscale64> : |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
164 public IntegerPixelTraits<PixelFormat_Grayscale64, uint64_t> |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
165 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
166 }; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
167 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
168 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
169 template <> |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 struct PixelTraits<PixelFormat_RGB24> |
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 struct PixelType |
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 uint8_t red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 uint8_t green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 uint8_t blue_; |
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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 static PixelFormat GetPixelFormat() |
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 return PixelFormat_RGB24; |
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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 static void SetZero(PixelType& target) |
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_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 target.green_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 target.blue_ = 0; |
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 void Copy(PixelType& target, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 const PixelType& source) |
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 target.red_ = source.red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 target.green_ = source.green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 target.blue_ = source.blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 static bool IsEqual(const PixelType& a, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 const PixelType& b) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 return (a.red_ == b.red_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 a.green_ == b.green_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 a.blue_ == b.blue_); |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 } |
2493
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
210 |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
211 ORTHANC_FORCE_INLINE |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
212 static void FloatToPixel(PixelType& target, |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
213 float value) |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
214 { |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
215 uint8_t v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
216 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value); |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
217 |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
218 target.red_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
219 target.green_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
220 target.blue_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
221 } |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 }; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 |
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 template <> |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 struct PixelTraits<PixelFormat_BGRA32> |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 struct PixelType |
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 uint8_t blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 uint8_t green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 uint8_t red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 uint8_t alpha_; |
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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 static PixelFormat GetPixelFormat() |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 return PixelFormat_BGRA32; |
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 SetZero(PixelType& target) |
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_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 target.green_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 target.red_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 target.alpha_ = 0; |
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 void Copy(PixelType& target, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 const PixelType& source) |
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 target.blue_ = source.blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 target.green_ = source.green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 target.red_ = source.red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 target.alpha_ = source.alpha_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 static bool IsEqual(const PixelType& a, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 const PixelType& b) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 return (a.blue_ == b.blue_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 a.green_ == b.green_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 a.red_ == b.red_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 a.alpha_ == b.alpha_); |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 } |
2493
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
270 |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
271 ORTHANC_FORCE_INLINE |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
272 static void FloatToPixel(PixelType& target, |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
273 float value) |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
274 { |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
275 uint8_t v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
276 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value); |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
277 |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
278 target.blue_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
279 target.green_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
280 target.red_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
281 target.alpha_ = 255; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
282 } |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 }; |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
284 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
285 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
286 template <> |
2783
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
287 struct PixelTraits<PixelFormat_RGBA32> |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
288 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
289 struct PixelType |
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 uint8_t red_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
292 uint8_t green_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
293 uint8_t blue_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
294 uint8_t alpha_; |
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 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
297 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
298 static PixelFormat GetPixelFormat() |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
299 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
300 return PixelFormat_RGBA32; |
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 SetZero(PixelType& target) |
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_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
307 target.green_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
308 target.blue_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
309 target.alpha_ = 0; |
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 void Copy(PixelType& target, |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
314 const PixelType& source) |
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 target.red_ = source.red_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
317 target.green_ = source.green_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
318 target.blue_ = source.blue_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
319 target.alpha_ = source.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 bool IsEqual(const PixelType& a, |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
324 const PixelType& b) |
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 return (a.red_ == b.red_ && |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
327 a.green_ == b.green_ && |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
328 a.blue_ == b.blue_ && |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
329 a.alpha_ == b.alpha_); |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
330 } |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
331 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
332 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
333 static void FloatToPixel(PixelType& target, |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
334 float value) |
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 uint8_t v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
337 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value); |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
338 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
339 target.red_ = v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
340 target.green_ = v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
341 target.blue_ = v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
342 target.alpha_ = 255; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
343 } |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
344 }; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
345 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
346 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
347 template <> |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
348 struct PixelTraits<PixelFormat_Float32> |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
349 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
350 typedef float PixelType; |
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 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
353 static PixelFormat GetPixelFormat() |
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 return PixelFormat_Float32; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
356 } |
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 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
359 static void SetZero(PixelType& target) |
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 target = 0.0f; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
362 } |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
363 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
364 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
365 static void Copy(PixelType& target, |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
366 const PixelType& source) |
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 target = source; |
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 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
371 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
372 static bool IsEqual(const PixelType& a, |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
373 const PixelType& b) |
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 float tmp = (a - b); |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
376 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
377 if (tmp < 0) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
378 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
379 tmp = -tmp; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
380 } |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
381 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
382 return tmp <= std::numeric_limits<float>::epsilon(); |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
383 } |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
384 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
385 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
386 static void FloatToPixel(PixelType& target, |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
387 float value) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
388 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
389 target = value; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
390 } |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
391 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
392 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
393 static float PixelToFloat(const PixelType& source) |
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 return source; |
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 }; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
398 } |