PCL
ICCProfile.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/ICCProfile.h - Released 2024-06-18T15:48:54Z
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_ICCProfile_h
53 #define __PCL_ICCProfile_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/ByteArray.h>
60 #include <pcl/Flags.h>
61 #include <pcl/StringList.h>
62 
63 namespace pcl
64 {
65 
66 // ----------------------------------------------------------------------------
67 
89 namespace ICCProfileClass
90 {
91  enum mask_type
92  {
93  Unknown = 0x80000000,
94  Any = 0x00000000,
95  InputDevice = 0x00000001,
96  DisplayDevice = 0x00000002,
97  OutputDevice = 0x00000004,
98  DeviceLink = 0x00000008,
99  ColorSpaceConversion = 0x00000010,
100  AbstractProfile = 0x00000020,
101  NamedColorProfile = 0x00000040
102  };
103 }
104 
110 using ICCProfileClasses = Flags<ICCProfileClass::mask_type>;
111 
112 // ----------------------------------------------------------------------------
113 
139 namespace ICCColorSpace
140 {
141  enum mask_type
142  {
143  Unknown = 0x80000000,
144  Any = 0x00000000,
145  XYZ = 0x00000001,
146  Lab = 0x00000002,
147  Luv = 0x00000004,
148  YCbCr = 0x00000008,
149  Yxy = 0x00000010,
150  RGB = 0x00000020,
151  Gray = 0x00000040,
152  HSV = 0x00000080,
153  HLS = 0x00000100,
154  CMYK = 0x00000200,
155  CMY = 0x00000400,
156  LuvK = 0x00000800
157  };
158 }
159 
165 using ICCColorSpaces = Flags<ICCColorSpace::mask_type>;
166 
167 // ----------------------------------------------------------------------------
168 
181 namespace ICCRenderingIntent
182 {
183  enum value_type
184  {
185  Perceptual,
186  Saturation,
187  RelativeColorimetric,
188  AbsoluteColorimetric
189  };
190 }
191 
192 // ----------------------------------------------------------------------------
193 
205 namespace ICCRenderingDirection
206 {
207  enum value_type
208  {
209  Input,
210  Output,
211  Proofing
212  };
213 }
214 
215 // ----------------------------------------------------------------------------
216 
234 class PCL_CLASS ICCProfile
235 {
236 public:
237 
241  using handle = void*;
242 
246  using profile_class = ICCProfileClass::mask_type;
247 
251  using color_space = ICCColorSpace::mask_type;
252 
256  using rendering_intent = ICCRenderingIntent::value_type;
257 
261  using rendering_direction = ICCRenderingDirection::value_type;
262 
267  ICCProfile() = default;
268 
272  ICCProfile( const ICCProfile& ) = default;
273 
277  ICCProfile( ICCProfile&& ) = default;
278 
287  ICCProfile( const String& profilePath )
288  {
289  Load( profilePath );
290  }
291 
297  ICCProfile( const ByteArray& rawData )
298  {
299  Set( rawData );
300  }
301 
307  ICCProfile( const void* rawData )
308  {
309  Set( rawData );
310  }
311 
316  virtual ~ICCProfile()
317  {
318  }
319 
323  ICCProfile& operator =( const ICCProfile& ) = default;
324 
328  ICCProfile& operator =( ICCProfile&& ) = default;
329 
333  bool IsProfile() const
334  {
335  return !m_data.IsEmpty();
336  }
337 
341  operator bool() const
342  {
343  return IsProfile();
344  }
345 
351  bool IsDiskProfile() const
352  {
353  return !m_path.IsEmpty();
354  }
355 
363  bool IsSameProfile( const ICCProfile& other ) const;
364 
370  const ByteArray& ProfileData() const
371  {
372  return m_data;
373  }
374 
380 
386  String FilePath() const
387  {
388  return m_path;
389  }
390 
408  String Description( const char* language = "en", const char* country = "US" ) const;
409 
416  String Manufacturer( const char* language = "en", const char* country = "US" ) const;
417 
424  String Model( const char* language = "en", const char* country = "US" ) const;
425 
432  String Copyright( const char* language = "en", const char* country = "US" ) const;
433 
445  void GetInformation( String& description, String& manufacturer, String& model, String& copyright,
446  const char* language = "en", const char* country = "US" ) const;
447 
455  profile_class Class() const;
456 
464  color_space ColorSpace() const;
465 
469  bool IsRGB() const
470  {
471  return ColorSpace() == ICCColorSpace::RGB;
472  }
473 
477  bool IsGrayscale() const
478  {
479  return ColorSpace() == ICCColorSpace::Gray;
480  }
481 
488  bool SupportsRenderingIntent( rendering_intent intent, rendering_direction direction ) const;
489 
496  bool IsEmbedded() const;
497 
506  void SetEmbeddedFlag( bool on = true );
507 
516  {
517  SetEmbeddedFlag( false );
518  }
519 
531  void Load( const String& profilePath );
532 
542  void Set( const ByteArray& profile );
543 
552  void Set( const void* rawData );
553 
560  void Clear()
561  {
562  m_data.Clear();
563  m_path.Clear();
564  }
565 
577  handle Open() const
578  {
579  return Open( m_data );
580  }
581 
585  friend void Swap( ICCProfile& x1, ICCProfile& x2 )
586  {
587  pcl::Swap( x1.m_data, x2.m_data );
588  pcl::Swap( x1.m_path, x2.m_path );
589  }
590 
599  static handle Open( const String& profilePath );
600 
608  static handle Open( const void* rawData );
609 
617  static handle Open( const ByteArray& icc )
618  {
619  return Open( icc.Begin() );
620  }
621 
625  static void Close( handle h );
626 
631  static bool IsValidHandle( handle h );
632 
638  static bool IsValidFile( const String& profilePath );
639 
645  static bool IsValid( const void* rawdata );
646 
652  static bool IsValid( const ByteArray& icc )
653  {
654  return IsValid( icc.Begin() );
655  }
656 
676  static String Description( handle h, const char* language = "en", const char* country = "US" );
677 
684  static String Manufacturer( handle h, const char* language = "en", const char* country = "US" );
685 
692  static String Model( handle h, const char* language = "en", const char* country = "US" );
693 
700  static String Copyright( handle h, const char* language = "en", const char* country = "US" );
701 
706  static profile_class Class( handle h );
707 
712  static color_space ColorSpace( handle h );
713 
720  static bool SupportsRenderingIntent( handle h, rendering_intent intent, rendering_direction direction );
721 
752 
771  static StringList FindProfiles( const String& dirPath = String() );
772 
795  static String FindInstalledProfile( const String& description, bool exactMatch = true );
796 
814  static void ExtractProfileList( StringList& selectedDescriptionsList,
815  StringList& selectedPathsList,
816  const StringList& pathList,
817  ICCColorSpaces spaces = ICCColorSpace::Any,
818  ICCProfileClasses classes = ICCProfileClass::Any );
819 
820  // -------------------------------------------------------------------------
821 
830  struct Info
831  {
834 
838  Info( const String& a_description, const String& a_path = String() )
839  : description( a_description )
840  , path( a_path )
841  {
842  }
843 
848  bool operator ==( const Info& x ) const
849  {
850  return description == x.description;
851  }
852 
857  bool operator <( const Info& x ) const
858  {
859  return description < x.description;
860  }
861  };
862 
867 
886 
890  static void ThrowErrorWithCMSInfo( const String& message );
891 
892 private:
893 
894  ByteArray m_data; // ICC profile data
895  String m_path; // empty if this is an embedded or newly created profile
896 };
897 
898 // ----------------------------------------------------------------------------
899 
900 } // pcl
901 
902 #endif // __PCL_ICCProfile_h
903 
904 // ----------------------------------------------------------------------------
905 // EOF pcl/ICCProfile.h - Released 2024-06-18T15:48:54Z
iterator Begin()
Definition: Array.h:426
A type-safe collection of enumerated flags.
Definition: Flags.h:85
A combination of ICCColorSpace values.
A combination of ICCProfileClass values.
A high-level interface to ICC color profiles.
Definition: ICCProfile.h:235
size_type ProfileSize() const
static handle Open(const ByteArray &icc)
Definition: ICCProfile.h:617
void Set(const ByteArray &profile)
bool IsDiskProfile() const
Definition: ICCProfile.h:351
static bool IsValidFile(const String &profilePath)
static profile_class Class(handle h)
String FilePath() const
Definition: ICCProfile.h:386
static String Description(handle h, const char *language="en", const char *country="US")
ICCProfile(ICCProfile &&)=default
static handle Open(const String &profilePath)
void Set(const void *rawData)
static profile_list FindProfilesByColorSpace(ICCColorSpaces spaces)
virtual ~ICCProfile()
Definition: ICCProfile.h:316
ICCProfile(const String &profilePath)
Definition: ICCProfile.h:287
static StringList FindProfiles(const String &dirPath=String())
String Description(const char *language="en", const char *country="US") const
static StringList ProfileDirectories()
void GetInformation(String &description, String &manufacturer, String &model, String &copyright, const char *language="en", const char *country="US") const
static void Close(handle h)
static bool IsValidHandle(handle h)
bool IsProfile() const
Definition: ICCProfile.h:333
handle Open() const
Definition: ICCProfile.h:577
bool IsGrayscale() const
Definition: ICCProfile.h:477
ICCProfile(const void *rawData)
Definition: ICCProfile.h:307
String Manufacturer(const char *language="en", const char *country="US") const
static bool IsValid(const ByteArray &icc)
Definition: ICCProfile.h:652
static handle Open(const void *rawData)
bool IsSameProfile(const ICCProfile &other) const
bool SupportsRenderingIntent(rendering_intent intent, rendering_direction direction) const
String Copyright(const char *language="en", const char *country="US") const
ICCProfile(const ByteArray &rawData)
Definition: ICCProfile.h:297
const ByteArray & ProfileData() const
Definition: ICCProfile.h:370
void ClearEmbeddedFlag()
Definition: ICCProfile.h:515
bool IsEmbedded() const
static void ExtractProfileList(StringList &selectedDescriptionsList, StringList &selectedPathsList, const StringList &pathList, ICCColorSpaces spaces=ICCColorSpace::Any, ICCProfileClasses classes=ICCProfileClass::Any)
ICCProfile(const ICCProfile &)=default
String Model(const char *language="en", const char *country="US") const
static String Manufacturer(handle h, const char *language="en", const char *country="US")
static bool IsValid(const void *rawdata)
static String Model(handle h, const char *language="en", const char *country="US")
static String FindInstalledProfile(const String &description, bool exactMatch=true)
color_space ColorSpace() const
bool IsRGB() const
Definition: ICCProfile.h:469
friend void Swap(ICCProfile &x1, ICCProfile &x2)
Definition: ICCProfile.h:585
static String Copyright(handle h, const char *language="en", const char *country="US")
void SetEmbeddedFlag(bool on=true)
static bool SupportsRenderingIntent(handle h, rendering_intent intent, rendering_direction direction)
static color_space ColorSpace(handle h)
profile_class Class() const
ICCProfile()=default
void Load(const String &profilePath)
Generic dynamic sorted array.
Definition: SortedArray.h:83
Unicode (UTF-16) string.
Definition: String.h:8113
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2267
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2278
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2) noexcept
Definition: Point.h:1459
size_t size_type
Definition: Defs.h:609
PCL root namespace.
Definition: AbstractImage.h:77
A structure to hold descriptive data about ICC profiles.
Definition: ICCProfile.h:831
String path
Full path to an ICC profile disk file.
Definition: ICCProfile.h:833
Info(const String &a_description, const String &a_path=String())
Definition: ICCProfile.h:838
String description
Description of an ICC profile.
Definition: ICCProfile.h:832