1 /*========================================================================= 2 * 3 * Copyright Insight Software Consortium 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0.txt 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *=========================================================================*/ 18 #ifndef itkPNGImageIO_h 19 #define itkPNGImageIO_h 20 #include "ITKIOPNGExport.h" 21 22 23 #include "itkImageIOBase.h" 24 25 namespace itk 26 { 27 /** \class PNGImageIO 28 * 29 * \brief ImageIO object for reading and writing PNG images 30 * 31 * Compression is support with only the default compressor. The 32 * compression level option is supported in the range 0-9. 33 * 34 * \ingroup IOFilters 35 * 36 * \ingroup ITKIOPNG 37 */ 38 class ITKIOPNG_EXPORT PNGImageIO:public ImageIOBase 39 { 40 public: 41 ITK_DISALLOW_COPY_AND_ASSIGN(PNGImageIO); 42 43 /** Standard class type aliases. */ 44 using Self = PNGImageIO; 45 using Superclass = ImageIOBase; 46 using Pointer = SmartPointer< Self >; 47 48 using RGBPixelType = RGBPixel< unsigned char >; 49 using PaletteType = std::vector< RGBPixelType >; 50 51 /** Method for creation through the object factory. */ 52 itkNewMacro(Self); 53 54 /** Run-time type information (and related methods). */ 55 itkTypeMacro(PNGImageIO, ImageIOBase); 56 57 /** Get a const ref to the palette of the image. In the case of non palette 58 * image or ExpandRGBPalette set to true, a vector of size 59 * 0 is returned */ 60 itkGetConstReferenceMacro(ColorPalette, PaletteType); 61 62 /*-------- This part of the interface deals with reading data. ------ */ 63 64 /** Determine the file type. Returns true if this ImageIO can read the 65 * file specified. */ 66 bool CanReadFile(const char *) override; 67 68 /** Set the spacing and dimension information for the set filename. */ 69 void ReadImageInformation() override; 70 71 /** Reads the data from disk into the memory buffer provided. */ 72 void Read(void *buffer) override; 73 74 /** Reads 3D data from multiple files assuming one slice per file. */ 75 virtual void ReadVolume(void *buffer); 76 77 /*-------- This part of the interfaces deals with writing data. ----- */ 78 79 /** Determine the file type. Returns true if this ImageIO can write the 80 * file specified. */ 81 bool CanWriteFile(const char *) override; 82 83 /** Writes the spacing and dimensions of the image. 84 * Assumes SetFileName has been called with a valid file name. */ 85 void WriteImageInformation() override; 86 87 /** Writes the data to disk from the memory buffer provided. Make sure 88 * that the IORegion has been set properly. */ 89 void Write(const void *buffer) override; 90 91 protected: 92 PNGImageIO(); 93 ~PNGImageIO() override; 94 void PrintSelf(std::ostream & os, Indent indent) const override; 95 96 void WriteSlice(const std::string & fileName, const void *buffer); 97 98 99 PaletteType m_ColorPalette; 100 }; 101 } // end namespace itk 102 103 #endif // itkPNGImageIO_h 104