PCL
ICCProfileTransformation.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/ICCProfileTransformation.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_ICCProfileTransformation_h
53 #define __PCL_ICCProfileTransformation_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/Array.h>
60 #include <pcl/Color.h>
61 #include <pcl/ICCProfile.h>
63 #include <pcl/ParallelProcess.h>
64 
65 // ----------------------------------------------------------------------------
66 
67 #ifdef __PCL_BUILDING_PIXINSIGHT_APPLICATION
68 namespace pi
69 {
70  class ImageWindow;
71 } // pi
72 #endif
73 
74 namespace pcl
75 {
76 
77 // ----------------------------------------------------------------------------
78 
95 {
96 public:
97 
101  using rendering_intent = ICCRenderingIntent::value_type;
102 
106  using transformation_handle = void*;
107 
112 
117 
122  : ImageTransformation( x )
123  , ParallelProcess( x )
124  , m_transformation( x.m_transformation )
125  , m_profiles( std::move( x.m_profiles ) )
126  , m_intent( x.m_intent )
127  , m_proofingIntent( x.m_proofingIntent )
128  , m_blackPointCompensation( x.m_blackPointCompensation )
129  , m_forceFloatingPoint( x.m_forceFloatingPoint )
130  , m_highResolutionCLUT( x.m_highResolutionCLUT )
131  , m_lowResolutionCLUT( x.m_lowResolutionCLUT )
132  , m_proofingTransformation( x.m_proofingTransformation )
133  , m_gamutCheck( x.m_gamutCheck )
134  , m_srcRGB( x.m_srcRGB )
135  , m_dstRGB( x.m_dstRGB )
136  , m_floatingPoint( x.m_floatingPoint )
137  {
138  x.m_transformation = nullptr;
139  }
140 
145  {
146  (void)ImageTransformation::operator =( x );
147  (void)ParallelProcess::operator =( x );
148  m_transformation = x.m_transformation;
149  m_profiles = std::move( x.m_profiles );
150  m_intent = x.m_intent;
151  m_proofingIntent = x.m_proofingIntent;
152  m_blackPointCompensation = x.m_blackPointCompensation;
153  m_forceFloatingPoint = x.m_forceFloatingPoint;
154  m_highResolutionCLUT = x.m_highResolutionCLUT;
155  m_lowResolutionCLUT = x.m_lowResolutionCLUT;
156  m_proofingTransformation = x.m_proofingTransformation;
157  m_gamutCheck = x.m_gamutCheck;
158  m_srcRGB = x.m_srcRGB;
159  m_dstRGB = x.m_dstRGB;
160  m_floatingPoint = x.m_floatingPoint;
161  x.m_transformation = nullptr;
162  return *this;
163  }
164 
170 
175  ICCProfileTransformation& operator =( const ICCProfileTransformation& ) = delete;
176 
181  {
182  Clear();
183  }
184 
189  void Add( const String& profilePath );
190 
194  void Add( const ICCProfile& profile );
195 
200  void Add( const ICCProfile::handle profileHandle );
201 
211  bool IsValid() const
212  {
213  return m_transformation != nullptr;
214  }
215 
220  const profile_list& Profiles() const
221  {
222  return m_profiles;
223  }
224 
228  rendering_intent RenderingIntent() const
229  {
230  return m_intent;
231  }
232 
239  void SetRenderingIntent( rendering_intent i )
240  {
241  CloseTransformation();
242  m_intent = i;
243  }
244 
250  {
251  return m_blackPointCompensation;
252  }
253 
261  void EnableBlackPointCompensation( bool enable = true )
262  {
263  CloseTransformation();
264  m_blackPointCompensation = enable;
265  }
266 
274  void DisableBlackPointCompensation( bool disable = true )
275  {
276  EnableBlackPointCompensation( !disable );
277  }
278 
290  {
291  return m_forceFloatingPoint;
292  }
293 
298  void ForceFloatingPointTransformation( bool force = true )
299  {
300  CloseTransformation();
301  m_forceFloatingPoint = force;
302  }
303 
311  void RelaxFloatingPointTransformation( bool relax = true )
312  {
313  ForceFloatingPointTransformation( !relax );
314  }
315 
326  {
327  return m_highResolutionCLUT;
328  }
329 
334  void EnableHighResolutionCLUT( bool enable = true )
335  {
336  CloseTransformation();
337  if ( (m_highResolutionCLUT = enable) == true )
338  m_lowResolutionCLUT = false;
339  }
340 
348  void DisableHighResolutionCLUT( bool disable = true )
349  {
350  EnableHighResolutionCLUT( !disable );
351  }
352 
363  {
364  return m_lowResolutionCLUT;
365  }
366 
371  void EnableLowResolutionCLUT( bool enable = true )
372  {
373  CloseTransformation();
374  if ( (m_lowResolutionCLUT = enable) == true )
375  m_highResolutionCLUT = false;
376  }
377 
385  void DisableLowResolutionCLUT( bool disable = true )
386  {
387  EnableLowResolutionCLUT( !disable );
388  }
389 
394  {
395  return m_proofingTransformation;
396  }
397 
406  void Create()
407  {
408  CreateTransformation( m_forceFloatingPoint );
409  }
410 
419  transformation_handle Handle() const
420  {
421  return m_transformation;
422  }
423 
430  void Clear();
431 
436  bool IsSourceRGBProfile() const
437  {
438  return m_srcRGB;
439  }
440 
445  bool IsTargetRGBProfile() const
446  {
447  return m_dstRGB;
448  }
449 
450 protected:
451 
452  /*
453  * Opaque handle to the profile transformation.
454  */
455  mutable transformation_handle m_transformation = nullptr;
456 
457  /*
458  * The ICC profiles, rendering intents and operating parameters that define
459  * this color transformation.
460  */
461  profile_list m_profiles;
462  rendering_intent m_intent = ICCRenderingIntent::Perceptual;
463  rendering_intent m_proofingIntent = ICCRenderingIntent::AbsoluteColorimetric;
464  bool m_blackPointCompensation = false;
465  bool m_forceFloatingPoint = false;
466  bool m_highResolutionCLUT = true;
467  bool m_lowResolutionCLUT = false;
468  bool m_proofingTransformation = false;
469  bool m_gamutCheck = false;
470 
471  /*
472  * Flags indicating source and destination color spaces.
473  * ### NB: These refer to the color spaces of the source and target pixel
474  * buffers, *not* to the color spaces of the profiles involved in the
475  * transformation.
476  */
477  mutable bool m_srcRGB = false;
478  mutable bool m_dstRGB = false;
479 
480  /*
481  * Flag indicating whether the current transformation (if any) has been
482  * created forcing floating point arithmetics.
483  */
484  mutable bool m_floatingPoint = false;
485 
486  void AddAt( size_type, const String& );
487  void AddAt( size_type, const ICCProfile& );
488  void AddAt( size_type, const ICCProfile::handle );
489  void AddOrReplaceAt( size_type i, const ICCProfile::handle );
490 
491  void CreateTransformation( bool ) const;
492  void CloseTransformation() const;
493 
494  // Inherited from ImageTransformation
495  void Apply( pcl::Image& ) const override;
496  void Apply( pcl::DImage& ) const override;
497  void Apply( pcl::UInt8Image& ) const override;
498  void Apply( pcl::UInt16Image& ) const override;
499  void Apply( pcl::UInt32Image& ) const override;
500 };
501 
502 // ----------------------------------------------------------------------------
503 
531 {
532 public:
533 
538  {
539  m_proofingTransformation = true;
540  m_profiles.Add( static_cast<ICCProfile::handle>( nullptr ), 3 );
541  }
542 
547 
552  {
553  }
554 
559 
564  void SetSourceProfile( const String& profilePath );
565 
570  void SetSourceProfile( const ICCProfile& profile );
571 
576  void SetSourceProfile( const ICCProfile::handle profileHandle );
577 
582  void SetProofingProfile( const String& profilePath );
583 
588  void SetProofingProfile( const ICCProfile& profile );
589 
594  void SetProofingProfile( const ICCProfile::handle profileHandle );
595 
601  void SetTargetProfile( const String& profilePath );
602 
607  void SetTargetProfile( const ICCProfile& profile );
608 
613  void SetTargetProfile( const ICCProfile::handle profileHandle );
614 
619  rendering_intent ProofingIntent() const
620  {
621  return m_intent;
622  }
623 
629  void SetProofingIntent( rendering_intent i )
630  {
631  CloseTransformation();
632  m_proofingIntent = i;
633  }
634 
641  bool IsGamutCheckEnabled() const
642  {
643  return m_gamutCheck;
644  }
645 
649  void EnableGamutCheck( bool enable = true )
650  {
651  CloseTransformation();
652  m_gamutCheck = enable;
653  }
654 
658  void DisableGamutCheck( bool disable = true )
659  {
660  EnableGamutCheck( !disable );
661  }
662 
669 
681  static void SetGamutWarningColor( RGBA color );
682 };
683 
684 // ----------------------------------------------------------------------------
685 
686 } // pcl
687 
688 #endif // __PCL_ICCProfileTransformation_h
689 
690 // ----------------------------------------------------------------------------
691 // EOF pcl/ICCProfileTransformation.h - Released 2024-06-18T15:48:54Z
Implements a generic, two-dimensional, shared or local image.
Definition: Image.h:278
Conversion of pixel values between ICC profile color spaces.
void EnableBlackPointCompensation(bool enable=true)
void Apply(pcl::UInt16Image &) const override
void DisableLowResolutionCLUT(bool disable=true)
void Add(const String &profilePath)
void Apply(pcl::Image &) const override
void Apply(pcl::DImage &) const override
void RelaxFloatingPointTransformation(bool relax=true)
void SetRenderingIntent(rendering_intent i)
ICCProfileTransformation(const ICCProfileTransformation &)=delete
void EnableLowResolutionCLUT(bool enable=true)
void Apply(pcl::UInt8Image &) const override
void Add(const ICCProfile &profile)
void Add(const ICCProfile::handle profileHandle)
ICCProfileTransformation(ICCProfileTransformation &&x)
const profile_list & Profiles() const
rendering_intent RenderingIntent() const
void Apply(pcl::UInt32Image &) const override
void EnableHighResolutionCLUT(bool enable=true)
void DisableHighResolutionCLUT(bool disable=true)
void DisableBlackPointCompensation(bool disable=true)
void ForceFloatingPointTransformation(bool force=true)
A high-level interface to ICC color profiles.
Definition: ICCProfile.h:235
A soft proofing ICC profile transformation.
void SetSourceProfile(const String &profilePath)
void SetTargetProfile(const String &profilePath)
void SetProofingProfile(const ICCProfile &profile)
void SetSourceProfile(const ICCProfile &profile)
void SetTargetProfile(const ICCProfile &profile)
void SetTargetProfile(const ICCProfile::handle profileHandle)
rendering_intent ProofingIntent() const
void DisableGamutCheck(bool disable=true)
void SetProofingIntent(rendering_intent i)
void SetProofingProfile(const ICCProfile::handle profileHandle)
static void SetGamutWarningColor(RGBA color)
void SetSourceProfile(const ICCProfile::handle profileHandle)
ICCProofingTransformation(ICCProofingTransformation &&)=default
void SetProofingProfile(const String &profilePath)
Root base class of all PCL image transformations.
A process using multiple concurrent execution threads.
Unicode (UTF-16) string.
Definition: String.h:8113
uint32 RGBA
Definition: Color.h:92
size_t size_type
Definition: Defs.h:609
PCL root namespace.
Definition: AbstractImage.h:77