Mercurial > hg > orthanc
annotate Core/Images/PixelTraits.h @ 2971:62b07b30e3db
error details
author | amazy |
---|---|
date | Thu, 06 Dec 2018 10:10:57 +0100 |
parents | da43ef7ff32a |
children | 4e43e67f8ecf |
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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
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 { |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
106 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
|
107 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
108 target = std::numeric_limits<PixelType>::min(); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
109 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
110 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
|
111 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
112 target = std::numeric_limits<PixelType>::max(); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
113 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
114 else |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
115 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
116 target = static_cast<PixelType>(value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
117 } |
2487
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 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 static bool IsEqual(const PixelType& a, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 const PixelType& b) |
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 return a == b; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 } |
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 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
129 template <PixelFormat Format> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
130 struct PixelTraits; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 |
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 template <> |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
134 struct PixelTraits<PixelFormat_Grayscale8> : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
135 public IntegerPixelTraits<PixelFormat_Grayscale8, uint8_t> |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 { |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
137 }; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
139 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
140 template <> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
141 struct PixelTraits<PixelFormat_Grayscale16> : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
142 public IntegerPixelTraits<PixelFormat_Grayscale16, uint16_t> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
143 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
144 }; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
146 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
147 template <> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
148 struct PixelTraits<PixelFormat_SignedGrayscale16> : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
149 public IntegerPixelTraits<PixelFormat_SignedGrayscale16, int16_t> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
150 { |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 }; |
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 template <> |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
155 struct PixelTraits<PixelFormat_Grayscale32> : |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
156 public IntegerPixelTraits<PixelFormat_Grayscale32, uint32_t> |
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 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
161 template <> |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
162 struct PixelTraits<PixelFormat_Grayscale64> : |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
163 public IntegerPixelTraits<PixelFormat_Grayscale64, uint64_t> |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
164 { |
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 template <> |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 struct PixelTraits<PixelFormat_RGB24> |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 struct PixelType |
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 uint8_t red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 uint8_t green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 uint8_t blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 }; |
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 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 static PixelFormat GetPixelFormat() |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 return PixelFormat_RGB24; |
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 SetZero(PixelType& target) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 target.red_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 target.green_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 target.blue_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 static void Copy(PixelType& target, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 const PixelType& source) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 target.red_ = source.red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 target.green_ = source.green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 target.blue_ = source.blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 } |
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 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 static bool IsEqual(const PixelType& a, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 const PixelType& b) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 return (a.red_ == b.red_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 a.green_ == b.green_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 a.blue_ == b.blue_); |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 } |
2493
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
209 |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
210 ORTHANC_FORCE_INLINE |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
211 static void FloatToPixel(PixelType& target, |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
212 float value) |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
213 { |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
214 uint8_t v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
215 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value); |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
216 |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
217 target.red_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
218 target.green_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
219 target.blue_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
220 } |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 }; |
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 template <> |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 struct PixelTraits<PixelFormat_BGRA32> |
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 struct PixelType |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 uint8_t blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 uint8_t green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 uint8_t red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 uint8_t alpha_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 }; |
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 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 static PixelFormat GetPixelFormat() |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 return PixelFormat_BGRA32; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 static void SetZero(PixelType& target) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 target.blue_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 target.green_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 target.red_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 target.alpha_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 } |
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 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 static void Copy(PixelType& target, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 const PixelType& source) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 target.blue_ = source.blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 target.green_ = source.green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 target.red_ = source.red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 target.alpha_ = source.alpha_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 } |
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 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 static bool IsEqual(const PixelType& a, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 const PixelType& b) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 return (a.blue_ == b.blue_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 a.green_ == b.green_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 a.red_ == b.red_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 a.alpha_ == b.alpha_); |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 } |
2493
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
269 |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
270 ORTHANC_FORCE_INLINE |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
271 static void FloatToPixel(PixelType& target, |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
272 float value) |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
273 { |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
274 uint8_t v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
275 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value); |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
276 |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
277 target.blue_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
278 target.green_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
279 target.red_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
280 target.alpha_ = 255; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
281 } |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 }; |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
283 |
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 template <> |
2783
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
286 struct PixelTraits<PixelFormat_RGBA32> |
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 struct PixelType |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
289 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
290 uint8_t red_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
291 uint8_t green_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
292 uint8_t blue_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
293 uint8_t alpha_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
294 }; |
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 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
297 static PixelFormat GetPixelFormat() |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
298 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
299 return PixelFormat_RGBA32; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
300 } |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
301 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
302 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
303 static void SetZero(PixelType& target) |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
304 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
305 target.red_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
306 target.green_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
307 target.blue_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
308 target.alpha_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
309 } |
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 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
312 static void Copy(PixelType& target, |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
313 const PixelType& source) |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
314 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
315 target.red_ = source.red_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
316 target.green_ = source.green_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
317 target.blue_ = source.blue_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
318 target.alpha_ = source.alpha_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
319 } |
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 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
322 static bool IsEqual(const PixelType& a, |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
323 const PixelType& b) |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
324 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
325 return (a.red_ == b.red_ && |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
326 a.green_ == b.green_ && |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
327 a.blue_ == b.blue_ && |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
328 a.alpha_ == b.alpha_); |
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 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
331 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
332 static void FloatToPixel(PixelType& target, |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
333 float value) |
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 uint8_t v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
336 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, value); |
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 target.red_ = v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
339 target.green_ = v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
340 target.blue_ = v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
341 target.alpha_ = 255; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
342 } |
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 template <> |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
347 struct PixelTraits<PixelFormat_Float32> |
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 typedef float PixelType; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
350 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
351 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
352 static PixelFormat GetPixelFormat() |
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 return PixelFormat_Float32; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
355 } |
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 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
358 static void SetZero(PixelType& target) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
359 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
360 target = 0.0f; |
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 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
363 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
364 static void Copy(PixelType& target, |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
365 const PixelType& source) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
366 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
367 target = source; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
368 } |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
369 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
370 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
371 static bool IsEqual(const PixelType& a, |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
372 const PixelType& b) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
373 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
374 float tmp = (a - b); |
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 if (tmp < 0) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
377 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
378 tmp = -tmp; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
379 } |
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 return tmp <= std::numeric_limits<float>::epsilon(); |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
382 } |
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 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
385 static void FloatToPixel(PixelType& target, |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
386 float value) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
387 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
388 target = value; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
389 } |
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 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
392 static float PixelToFloat(const PixelType& source) |
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 return source; |
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 }; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 } |