Mercurial > hg > orthanc
annotate Core/Images/PixelTraits.h @ 2790:c7313e1f7644
MongooseServer::SetRealm()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 26 Jul 2018 20:43:03 +0200 |
parents | 65699fcb4e99 |
children | da43ef7ff32a |
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" |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
37 #include "../OrthancException.h" |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
39 #include <limits> |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 namespace Orthanc |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
43 template <PixelFormat format, |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
44 typename _PixelType> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
45 struct IntegerPixelTraits |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 { |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
47 typedef _PixelType PixelType; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 static PixelFormat GetPixelFormat() |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 { |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
52 return format; |
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 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
55 ORTHANC_FORCE_INLINE |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
56 static PixelType IntegerToPixel(int64_t value) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
57 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
58 if (value < static_cast<int64_t>(std::numeric_limits<PixelType>::min()) || |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
59 value > static_cast<int64_t>(std::numeric_limits<PixelType>::max())) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
60 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
61 throw OrthancException(ErrorCode_ParameterOutOfRange); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
62 } |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
63 else |
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 return static_cast<PixelType>(value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
66 } |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 static void SetZero(PixelType& target) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 target = 0; |
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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 ORTHANC_FORCE_INLINE |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
76 static void SetMinValue(PixelType& target) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
77 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
78 target = std::numeric_limits<PixelType>::min(); |
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 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
81 ORTHANC_FORCE_INLINE |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
82 static void SetMaxValue(PixelType& target) |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
83 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
84 target = std::numeric_limits<PixelType>::max(); |
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 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
87 ORTHANC_FORCE_INLINE |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 static void Copy(PixelType& target, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 const PixelType& source) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 target = 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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 static float PixelToFloat(const PixelType& source) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 return static_cast<float>(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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 static void FloatToPixel(PixelType& target, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 float value) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 { |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
104 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
|
105 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
106 target = 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 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
|
109 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
110 target = 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 else |
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 target = static_cast<PixelType>(value); |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
115 } |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 static bool IsEqual(const PixelType& a, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 const PixelType& b) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 return a == 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 }; |
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 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
127 template <PixelFormat Format> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
128 struct PixelTraits; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 template <> |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
132 struct PixelTraits<PixelFormat_Grayscale8> : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
133 public IntegerPixelTraits<PixelFormat_Grayscale8, uint8_t> |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 { |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
135 }; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 |
2489
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
137 |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
138 template <> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
139 struct PixelTraits<PixelFormat_Grayscale16> : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
140 public IntegerPixelTraits<PixelFormat_Grayscale16, uint16_t> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
141 { |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
142 }; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 |
2489
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 template <> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
146 struct PixelTraits<PixelFormat_SignedGrayscale16> : |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
147 public IntegerPixelTraits<PixelFormat_SignedGrayscale16, int16_t> |
e91bab2d8c75
Bresenham's line algorithm
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2487
diff
changeset
|
148 { |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 }; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 |
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 template <> |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
153 struct PixelTraits<PixelFormat_Grayscale32> : |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
154 public IntegerPixelTraits<PixelFormat_Grayscale32, uint32_t> |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
155 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
156 }; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
157 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
158 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
159 template <> |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
160 struct PixelTraits<PixelFormat_Grayscale64> : |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
161 public IntegerPixelTraits<PixelFormat_Grayscale64, uint64_t> |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
162 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
163 }; |
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 template <> |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 struct PixelTraits<PixelFormat_RGB24> |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 struct PixelType |
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 uint8_t red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 uint8_t green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 uint8_t blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 }; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 static PixelFormat GetPixelFormat() |
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 return PixelFormat_RGB24; |
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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 static void SetZero(PixelType& target) |
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 target.red_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 target.green_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 target.blue_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 static void Copy(PixelType& target, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 const PixelType& source) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 target.red_ = source.red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 target.green_ = source.green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 target.blue_ = source.blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 static bool IsEqual(const PixelType& a, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 const PixelType& b) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 return (a.red_ == b.red_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 a.green_ == b.green_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 a.blue_ == b.blue_); |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 } |
2493
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
207 |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
208 ORTHANC_FORCE_INLINE |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
209 static void FloatToPixel(PixelType& target, |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
210 float value) |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
211 { |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
212 uint8_t v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
213 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, 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 target.red_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
216 target.green_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
217 target.blue_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
218 } |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 }; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 |
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 template <> |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 struct PixelTraits<PixelFormat_BGRA32> |
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 struct PixelType |
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 uint8_t blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 uint8_t green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 uint8_t red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 uint8_t alpha_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 }; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 static PixelFormat GetPixelFormat() |
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 return PixelFormat_BGRA32; |
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 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 static void SetZero(PixelType& target) |
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 target.blue_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 target.green_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 target.red_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 target.alpha_ = 0; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 static void Copy(PixelType& target, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 const PixelType& source) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 target.blue_ = source.blue_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 target.green_ = source.green_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 target.red_ = source.red_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 target.alpha_ = source.alpha_; |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 } |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 ORTHANC_FORCE_INLINE |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 static bool IsEqual(const PixelType& a, |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 const PixelType& b) |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 { |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 return (a.blue_ == b.blue_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 a.green_ == b.green_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 a.red_ == b.red_ && |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 a.alpha_ == b.alpha_); |
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 } |
2493
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
267 |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
268 ORTHANC_FORCE_INLINE |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
269 static void FloatToPixel(PixelType& target, |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
270 float value) |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
271 { |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
272 uint8_t v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
273 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, 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 target.blue_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
276 target.green_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
277 target.red_ = v; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
278 target.alpha_ = 255; |
5aa787a03e7d
PixelTraits::FloatToPixel for color formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2489
diff
changeset
|
279 } |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 }; |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
281 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
282 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
283 template <> |
2783
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
284 struct PixelTraits<PixelFormat_RGBA32> |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
285 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
286 struct PixelType |
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 uint8_t red_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
289 uint8_t green_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
290 uint8_t blue_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
291 uint8_t alpha_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
292 }; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
293 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
294 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
295 static PixelFormat GetPixelFormat() |
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 return PixelFormat_RGBA32; |
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 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
300 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
301 static void SetZero(PixelType& target) |
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 target.red_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
304 target.green_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
305 target.blue_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
306 target.alpha_ = 0; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
307 } |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
308 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
309 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
310 static void Copy(PixelType& target, |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
311 const PixelType& source) |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
312 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
313 target.red_ = source.red_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
314 target.green_ = source.green_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
315 target.blue_ = source.blue_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
316 target.alpha_ = source.alpha_; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
317 } |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
318 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
319 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
320 static bool IsEqual(const PixelType& a, |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
321 const PixelType& b) |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
322 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
323 return (a.red_ == b.red_ && |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
324 a.green_ == b.green_ && |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
325 a.blue_ == b.blue_ && |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
326 a.alpha_ == b.alpha_); |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
327 } |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
328 |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
329 ORTHANC_FORCE_INLINE |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
330 static void FloatToPixel(PixelType& target, |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
331 float value) |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
332 { |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
333 uint8_t v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
334 PixelTraits<PixelFormat_Grayscale8>::FloatToPixel(v, 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 target.red_ = v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
337 target.green_ = v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
338 target.blue_ = v; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
339 target.alpha_ = 255; |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
340 } |
65699fcb4e99
PixelTraits<PixelFormat_RGBA32>
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
341 }; |
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 template <> |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
345 struct PixelTraits<PixelFormat_Float32> |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
346 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
347 typedef float PixelType; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
348 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
349 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
350 static PixelFormat GetPixelFormat() |
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 return PixelFormat_Float32; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
353 } |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
354 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
355 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
356 static void SetZero(PixelType& target) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
357 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
358 target = 0.0f; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
359 } |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
360 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
361 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
362 static void Copy(PixelType& target, |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
363 const PixelType& source) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
364 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
365 target = 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 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
368 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
369 static bool IsEqual(const PixelType& a, |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
370 const PixelType& b) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
371 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
372 float tmp = (a - 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 if (tmp < 0) |
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 tmp = -tmp; |
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 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
379 return tmp <= std::numeric_limits<float>::epsilon(); |
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 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
383 static void FloatToPixel(PixelType& target, |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
384 float value) |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
385 { |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
386 target = 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 |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
389 ORTHANC_FORCE_INLINE |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2493
diff
changeset
|
390 static float PixelToFloat(const PixelType& source) |
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 return 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 }; |
2487
be1dbb1dcdd6
PixelTraits and ImageTraits
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
395 } |