PCL
FileFormatImplementation.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.11
6 // ----------------------------------------------------------------------------
7 // pcl/FileFormatImplementation.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_FileFormat_h
53 #define __PCL_FileFormat_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/AutoPointer.h>
62 #include <pcl/ColorFilterArray.h>
63 #include <pcl/DisplayFunction.h>
64 #include <pcl/FITSHeaderKeyword.h>
65 #include <pcl/ICCProfile.h>
66 #include <pcl/ImageDescription.h>
67 #include <pcl/ImageVariant.h>
68 #include <pcl/MetaFileFormat.h>
70 #include <pcl/RGBColorSystem.h>
71 
72 namespace pcl
73 {
74 
75 struct FileFormatImplementationPrivate;
76 
77 // ----------------------------------------------------------------------------
78 
97 class PCL_CLASS FileFormatImplementation
98 {
99 public:
100 
108 
112  virtual ~FileFormatImplementation() noexcept( false );
113 
114  /*
115  * FileFormatImplementation instances (e.g., image files) are unique.
116  */
117 
123 
128  FileFormatImplementation& operator =( const FileFormatImplementation& ) = delete;
129 
135  const MetaFileFormat* Meta() const
136  {
137  return meta;
138  }
139 
143  virtual void Close();
144 
148  virtual bool IsOpen() const;
149 
155  virtual String FilePath() const;
156 
157  // Reader functionality
158 
192  virtual ImageDescriptionArray Open( const String& filePath, const IsoString& hints );
193 
202  virtual void SelectImage( int index );
203 
212  virtual int SelectedImageIndex() const;
213 
221  virtual void* FormatSpecificData() const;
222 
234  virtual String ImageFormatInfo() const
235  {
236  return String();
237  }
238 
249 
260 
272 
283 
290 
297 
314 
329  virtual Variant ReadProperty( const IsoString& property );
330 
344 
356  virtual Variant ReadImageProperty( const IsoString& property );
357 
361  virtual void ReadImage( pcl::Image& image );
362 
366  virtual void ReadImage( pcl::DImage& image );
367 
371  virtual void ReadImage( UInt8Image& image );
372 
376  virtual void ReadImage( UInt16Image& image );
377 
381  virtual void ReadImage( UInt32Image& image );
382 
393  virtual bool CanReadIncrementally() const
394  {
395  return true; // allow incremental reads if the format supports them
396  }
397 
419  virtual void ReadSamples( pcl::Image::sample* buffer, int startRow, int rowCount, int channel );
420 
427  virtual void ReadSamples( pcl::DImage::sample* buffer, int startRow, int rowCount, int channel );
428 
435  virtual void ReadSamples( UInt8Image::sample* buffer, int startRow, int rowCount, int channel );
436 
443  virtual void ReadSamples( UInt16Image::sample* buffer, int startRow, int rowCount, int channel );
444 
451  virtual void ReadSamples( UInt32Image::sample* buffer, int startRow, int rowCount, int channel );
452 
465  virtual bool WasInexactRead() const
466  {
467  return false; // exact read operations assumed by default
468  }
469 
470  // Writer functionality
471 
506  virtual bool QueryOptions( Array<ImageOptions>& options, Array<void*>& formatOptions )
507  {
508  return true;
509  }
510 
554  virtual void Create( const String& filePath, int numberOfImages, const IsoString& hints );
555 
563  virtual void SetId( const IsoString& id )
564  {
565  }
566 
574  virtual void SetOptions( const ImageOptions& options )
575  {
576  }
577 
605  virtual void SetFormatSpecificData( const void* data );
606 
611  virtual void WriteICCProfile( const ICCProfile& icc );
612 
617  virtual void WriteRGBWorkingSpace( const RGBColorSystem& rgbws );
618 
623  virtual void WriteDisplayFunction( const DisplayFunction& df );
624 
629  virtual void WriteColorFilterArray( const ColorFilterArray& cfa );
630 
635  virtual void WriteThumbnail( const pcl::UInt8Image& image );
636 
641  virtual void WriteFITSKeywords( const FITSKeywordArray& keywords );
642 
657  virtual void WriteProperty( const IsoString& property, const Variant& value );
658 
671  virtual void WriteImageProperty( const IsoString& property, const Variant& value );
672 
676  virtual void WriteImage( const pcl::Image& image );
677 
681  virtual void WriteImage( const pcl::DImage& image );
682 
686  virtual void WriteImage( const UInt8Image& image );
687 
691  virtual void WriteImage( const UInt16Image& image );
692 
696  virtual void WriteImage( const UInt32Image& image );
697 
710  virtual void CreateImage( const ImageInfo& info );
711 
719  virtual void CloseImage();
720 
731  virtual bool CanWriteIncrementally() const
732  {
733  return true; // allow incremental writes if the format supports them
734  }
735 
757  virtual void WriteSamples( const pcl::Image::sample* buffer, int startRow, int rowCount, int channel );
758 
765  virtual void WriteSamples( const pcl::DImage::sample* buffer, int startRow, int rowCount, int channel );
766 
773  virtual void WriteSamples( const UInt8Image::sample* buffer, int startRow, int rowCount, int channel );
774 
781  virtual void WriteSamples( const UInt16Image::sample* buffer, int startRow, int rowCount, int channel );
782 
789  virtual void WriteSamples( const UInt32Image::sample* buffer, int startRow, int rowCount, int channel );
790 
803  virtual bool WasLossyWrite() const
804  {
805  return false; // lossless write operations assumed by default
806  }
807 
808 protected:
809 
810  /*
811  * The file format to which this instance belongs.
812  */
813  const MetaFileFormat* meta = nullptr;
814 
815 private:
816 
817  /*
818  * Internal stuff to automate low-level C API communication.
819  */
821 
822  ImageDescriptionArray m_description; // used exclusively by FileFormatDispatcher
823 
824  void BeginPrivate();
825 
826  void BeginICCProfileExtraction();
827  const ICCProfile& GetICCProfile() const;
828  void EndICCProfileExtraction();
829 
830  void BeginRGBWSExtraction();
831  const RGBColorSystem& GetRGBWS() const;
832  void EndRGBWSExtraction();
833 
834  void BeginDisplayFunctionExtraction();
835  const DisplayFunction& GetDisplayFunction() const;
836  void EndDisplayFunctionExtraction();
837 
838  void BeginColorFilterArrayExtraction();
839  const ColorFilterArray& GetColorFilterArray() const;
840  void EndColorFilterArrayExtraction();
841 
842  void BeginThumbnailExtraction();
843  const UInt8Image& GetThumbnail() const;
844  void EndThumbnailExtraction();
845 
846  void BeginKeywordExtraction();
847  size_type NumberOfKeywords() const;
848  bool GetNextKeyword( FITSHeaderKeyword& ) const;
849  void EndKeywordExtraction();
850 
851  void BeginPropertyExtraction();
852  const Variant& GetProperty( const IsoString& );
853  void EndPropertyExtraction();
854 
855  void BeginImagePropertyExtraction();
856  const Variant& GetImageProperty( const IsoString& );
857  void EndImagePropertyExtraction();
858 
859  void BeginICCProfileEmbedding();
860  void SetICCProfile( const ICCProfile& );
861  void EndICCProfileEmbedding();
862 
863  void BeginRGBWSEmbedding();
864  void SetRGBWS( const RGBColorSystem& );
865  void EndRGBWSEmbedding();
866 
867  void BeginDisplayFunctionEmbedding();
868  void SetDisplayFunction( const DisplayFunction& );
869  void EndDisplayFunctionEmbedding();
870 
871  void BeginColorFilterArrayEmbedding();
872  void SetColorFilterArray( const ColorFilterArray& );
873  void EndColorFilterArrayEmbedding();
874 
875  void BeginThumbnailEmbedding();
876  void SetThumbnail( const UInt8Image& );
877  void EndThumbnailEmbedding();
878 
879  void BeginKeywordEmbedding();
880  void AddKeyword( const FITSHeaderKeyword& );
881  void EndKeywordEmbedding();
882 
883  void BeginPropertyEmbedding();
884  void SetProperty( const IsoString&, const Variant& );
885  void EndPropertyEmbedding();
886 
887  void BeginImagePropertyEmbedding();
888  void SetImageProperty( const IsoString&, const Variant& );
889  void EndImagePropertyEmbedding();
890 
891  friend class FileFormatDispatcher;
892 };
893 
894 // ----------------------------------------------------------------------------
895 
896 } // pcl
897 
898 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
899 
900 #endif // __PCL_FileFormat_h
901 
902 // ----------------------------------------------------------------------------
903 // EOF pcl/FileFormatImplementation.h - Released 2024-05-07T15:27:32Z
Color filter array (CFA) structure.
Adaptive histogram transformations for image visualization.
FITS header keyword
Implementation of a PixInsight file format instance.
virtual void WriteColorFilterArray(const ColorFilterArray &cfa)
virtual RGBColorSystem ReadRGBWorkingSpace()
virtual PropertyDescriptionArray PropertyDescriptions()
virtual void WriteImage(const pcl::Image &image)
virtual FITSKeywordArray ReadFITSKeywords()
virtual void WriteThumbnail(const pcl::UInt8Image &image)
virtual void ReadSamples(UInt32Image::sample *buffer, int startRow, int rowCount, int channel)
virtual void ReadImage(UInt32Image &image)
virtual void Create(const String &filePath, int numberOfImages, const IsoString &hints)
virtual void WriteImage(const UInt8Image &image)
virtual void WriteSamples(const UInt8Image::sample *buffer, int startRow, int rowCount, int channel)
virtual void ReadImage(UInt16Image &image)
virtual void WriteImage(const pcl::DImage &image)
virtual void WriteSamples(const UInt16Image::sample *buffer, int startRow, int rowCount, int channel)
virtual void WriteImageProperty(const IsoString &property, const Variant &value)
virtual void WriteImage(const UInt32Image &image)
virtual void ReadSamples(UInt16Image::sample *buffer, int startRow, int rowCount, int channel)
virtual void WriteDisplayFunction(const DisplayFunction &df)
virtual void WriteICCProfile(const ICCProfile &icc)
virtual void WriteImage(const UInt16Image &image)
virtual void WriteProperty(const IsoString &property, const Variant &value)
virtual String FilePath() const
virtual bool IsOpen() const
virtual PropertyDescriptionArray ImagePropertyDescriptions()
virtual ImageDescriptionArray Open(const String &filePath, const IsoString &hints)
virtual void ReadImage(pcl::DImage &image)
virtual ~FileFormatImplementation() noexcept(false)
virtual void ReadSamples(UInt8Image::sample *buffer, int startRow, int rowCount, int channel)
virtual void SetFormatSpecificData(const void *data)
virtual void WriteFITSKeywords(const FITSKeywordArray &keywords)
virtual void ReadImage(UInt8Image &image)
virtual void WriteSamples(const pcl::Image::sample *buffer, int startRow, int rowCount, int channel)
virtual Variant ReadImageProperty(const IsoString &property)
virtual void * FormatSpecificData() const
virtual UInt8Image ReadThumbnail()
FileFormatImplementation(const MetaFileFormat *m)
virtual void ReadSamples(pcl::DImage::sample *buffer, int startRow, int rowCount, int channel)
virtual Variant ReadProperty(const IsoString &property)
virtual void SetId(const IsoString &id)
virtual void WriteSamples(const pcl::DImage::sample *buffer, int startRow, int rowCount, int channel)
virtual bool QueryOptions(Array< ImageOptions > &options, Array< void * > &formatOptions)
virtual void WriteSamples(const UInt32Image::sample *buffer, int startRow, int rowCount, int channel)
virtual int SelectedImageIndex() const
virtual void ReadSamples(pcl::Image::sample *buffer, int startRow, int rowCount, int channel)
virtual void SetOptions(const ImageOptions &options)
virtual ColorFilterArray ReadColorFilterArray()
virtual void WriteRGBWorkingSpace(const RGBColorSystem &rgbws)
virtual DisplayFunction ReadDisplayFunction()
virtual void ReadImage(pcl::Image &image)
virtual void SelectImage(int index)
virtual void CreateImage(const ImageInfo &info)
virtual ICCProfile ReadICCProfile()
typename pixel_traits::sample sample
Definition: Image.h:305
A high-level interface to ICC color profiles.
Definition: ICCProfile.h:235
A simple structure to hold basic information about images.
Definition: ImageInfo.h:72
Format-independent, fundamental image stream options.
Definition: ImageOptions.h:98
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5425
A formal description of an image file format in PixInsight.
Colorimetrically defined RGB working color space.
Unicode (UTF-16) string.
Definition: String.h:8113
Acts like a union to store instances of different data types.
Definition: Variant.h:332
size_t size_type
Definition: Defs.h:609
PCL root namespace.
Definition: AbstractImage.h:77