comparison Framework/ColorSpaces.h @ 330:c42083d50ddf

Added support for DICOM tag "Recommended Absent Pixel CIELab" (0048,0015)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Oct 2024 13:08:55 +0200
parents
children cf828b381bc9
comparison
equal deleted inserted replaced
329:ae2d769215d2 330:c42083d50ddf
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
8 *
9 * This program is free software: you can redistribute it and/or
10 * modify it under the terms of the GNU Affero General Public License
11 * as published by the Free Software Foundation, either version 3 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 **/
22
23
24 #pragma once
25
26 #include <stdint.h>
27 #include <string>
28
29
30 namespace OrthancWSI
31 {
32 class sRGBColor;
33 class XYZColor;
34 class LABColor;
35
36
37 class RGBColor
38 {
39 private:
40 uint8_t r_;
41 uint8_t g_;
42 uint8_t b_;
43
44 public:
45 RGBColor(uint8_t r,
46 uint8_t g,
47 uint8_t b) :
48 r_(r),
49 g_(g),
50 b_(b)
51 {
52 }
53
54 RGBColor(const sRGBColor& srgb);
55
56 uint8_t GetR() const
57 {
58 return r_;
59 }
60
61 uint8_t GetG() const
62 {
63 return g_;
64 }
65
66 uint8_t GetB() const
67 {
68 return b_;
69 }
70 };
71
72
73 // Those correspond to Standard Illuminant D65
74 // https://en.wikipedia.org/wiki/SRGB#From_CIE_XYZ_to_sRGB
75 class sRGBColor
76 {
77 private:
78 float r_;
79 float g_;
80 float b_;
81
82 public:
83 sRGBColor(float r,
84 float g,
85 float b) :
86 r_(r),
87 g_(g),
88 b_(b)
89 {
90 }
91
92 sRGBColor(const RGBColor& rgb);
93
94 sRGBColor(const XYZColor& xyz);
95
96 float GetR() const
97 {
98 return r_;
99 }
100
101 float GetG() const
102 {
103 return g_;
104 }
105
106 float GetB() const
107 {
108 return b_;
109 }
110 };
111
112
113 class XYZColor
114 {
115 private:
116 float x_;
117 float y_;
118 float z_;
119
120 public:
121 XYZColor(const sRGBColor& srgb);
122
123 XYZColor(const LABColor& lab);
124
125 float GetX() const
126 {
127 return x_;
128 }
129
130 float GetY() const
131 {
132 return y_;
133 }
134
135 float GetZ() const
136 {
137 return z_;
138 }
139 };
140
141
142 class LABColor
143 {
144 private:
145 float l_;
146 float a_;
147 float b_;
148
149 public:
150 LABColor() :
151 l_(0),
152 a_(0),
153 b_(0)
154 {
155 }
156
157 LABColor(float l,
158 float a,
159 float b) :
160 l_(l),
161 a_(a),
162 b_(b)
163 {
164 }
165
166 LABColor(const XYZColor& xyz);
167
168 float GetL() const
169 {
170 return l_;
171 }
172
173 float GetA() const
174 {
175 return a_;
176 }
177
178 float GetB() const
179 {
180 return b_;
181 }
182
183 void EncodeDicomRecommendedAbsentPixelCIELab(uint16_t target[3]) const;
184
185 static LABColor DecodeDicomRecommendedAbsentPixelCIELab(uint16_t l,
186 uint16_t a,
187 uint16_t b);
188
189 static bool DecodeDicomRecommendedAbsentPixelCIELab(LABColor& target,
190 const std::string& tag);
191 };
192 }