PCL
ImageColor.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.11
6 // ----------------------------------------------------------------------------
7 // pcl/ImageColor.h - Released 2024-05-07T15:27:32Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_ImageColor_h
53 #define __PCL_ImageColor_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/ColorSpace.h>
60 #include <pcl/Exception.h>
61 #include <pcl/RGBColorSystem.h>
62 #include <pcl/String.h>
63 
64 namespace pcl
65 {
66 
67 // ----------------------------------------------------------------------------
68 
69 #define m_colorSpace m_color->colorSpace
70 #define m_RGBWS m_color->RGBWS
71 
72 // ----------------------------------------------------------------------------
73 
96 class PCL_CLASS ImageColor
97 {
98 public:
99 
105  using color_space = ColorSpace::value_type;
106 
110  const RGBColorSystem& RGBWorkingSpace() const noexcept
111  {
112  return m_RGBWS;
113  }
114 
124  virtual void SetRGBWorkingSpace( const RGBColorSystem& RGBWS )
125  {
126  m_RGBWS = RGBWS;
127  }
128 
137  static const RGBColorSystem& DefaultRGBWorkingSpace() noexcept
138  {
139  return s_defaultRGBWS;
140  }
141 
151  static void SetDefaultRGBWorkingSpace( const RGBColorSystem& RGBWS )
152  {
153  s_defaultRGBWS = RGBWS;
154  }
155 
161  {
162  s_defaultRGBWS = RGBColorSystem::sRGB;
163  }
164 
169  bool IsColor() const noexcept
170  {
171  return m_colorSpace != ColorSpace::Gray;
172  }
173 
178  color_space ColorSpace() const noexcept
179  {
180  return m_colorSpace;
181  }
182 
187  String ChannelId( int c ) const noexcept
188  {
189  return ColorSpace::ChannelId( m_colorSpace, c );
190  }
191 
192 protected:
193 
194  struct Color
195  {
196  color_space colorSpace;
197  RGBColorSystem RGBWS;
198 
199  Color( color_space cs = ColorSpace::Gray )
200  : colorSpace( cs )
201  , RGBWS( s_defaultRGBWS )
202  {
203  }
204 
205  Color( const Color& ) = default;
206 
207  void Assign( const Color& x )
208  {
209  colorSpace = x.colorSpace;
210  RGBWS = x.RGBWS;
211  }
212 
213  void Reset() noexcept
214  {
215  colorSpace = ColorSpace::Gray;
216  }
217  };
218 
219  Color* m_color = nullptr;
220 
221  /*
222  * The default RGB Working Space
223  *
224  * Unless explicitly modified, this corresponds to the sRGB space.
225  *
226  * Note that shared images don't use this default RGBWS, but the global
227  * RGBWS currently selected in the PixInsight core application.
228  */
229  static RGBColorSystem s_defaultRGBWS;
230 
231  ImageColor() = default;
232  ImageColor( const ImageColor& ) = default;
233  ImageColor& operator =( const ImageColor& ) = default;
234 
235  virtual ~ImageColor()
236  {
237  m_color = nullptr;
238  }
239 
240  void Swap( ImageColor& image ) noexcept
241  {
242  pcl::Swap( m_color, image.m_color );
243  }
244 };
245 
246 // ----------------------------------------------------------------------------
247 
248 #undef m_colorSpace
249 #undef m_RGBWS
250 
251 // ----------------------------------------------------------------------------
252 
253 } // pcl
254 
255 #endif // __PCL_ImageColor_h
256 
257 // ----------------------------------------------------------------------------
258 // EOF pcl/ImageColor.h - Released 2024-05-07T15:27:32Z
Implements color space properties of images.
Definition: ImageColor.h:97
const RGBColorSystem & RGBWorkingSpace() const noexcept
Definition: ImageColor.h:110
virtual void SetRGBWorkingSpace(const RGBColorSystem &RGBWS)
Definition: ImageColor.h:124
String ChannelId(int c) const noexcept
Definition: ImageColor.h:187
static void ResetDefaultRGBWorkingSpace()
Definition: ImageColor.h:160
static void SetDefaultRGBWorkingSpace(const RGBColorSystem &RGBWS)
Definition: ImageColor.h:151
color_space ColorSpace() const noexcept
Definition: ImageColor.h:178
bool IsColor() const noexcept
Definition: ImageColor.h:169
static const RGBColorSystem & DefaultRGBWorkingSpace() noexcept
Definition: ImageColor.h:137
Colorimetrically defined RGB working color space.
static const RGBColorSystem sRGB
Unicode (UTF-16) string.
Definition: String.h:8113
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2) noexcept
Definition: Point.h:1459
String ChannelId(int colorSpace, int channel)
PCL root namespace.
Definition: AbstractImage.h:77