ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkBMPImageIO.h
Go to the documentation of this file.
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 itkBMPImageIO_h
19 #define itkBMPImageIO_h
20 #include "ITKIOBMPExport.h"
21 
22 
23 #include <fstream>
24 #include "itkImageIOBase.h"
25 #include <cstdio>
26 #include "itkRGBPixel.h"
27 
28 namespace itk
29 {
38 class ITKIOBMP_EXPORT BMPImageIO:public ImageIOBase
39 {
40 public:
42  typedef BMPImageIO Self;
46 
48  itkNewMacro(Self);
49 
51  itkTypeMacro(BMPImageIO, Superclass);
52 
54  itkGetConstMacro(FileLowerLeft, bool);
55 
57  itkGetConstMacro(BMPCompression, long);
58 
59  /*-------- This part of the interfaces deals with reading data. ----- */
60 
63  virtual bool CanReadFile(const char *) ITK_OVERRIDE;
64 
66  virtual void ReadImageInformation() ITK_OVERRIDE;
67 
69  virtual void Read(void *buffer) ITK_OVERRIDE;
70 
71  /*-------- This part of the interfaces deals with writing data. ----- */
72 
75  virtual bool CanWriteFile(const char *) ITK_OVERRIDE;
76 
78  virtual void WriteImageInformation() ITK_OVERRIDE;
79 
82  virtual void Write(const void *buffer) ITK_OVERRIDE;
83 
84  BMPImageIO();
85  ~BMPImageIO();
86  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
87 
88 private:
89  BMPImageIO(const Self &); //purposely not implemented
90  void operator=(const Self &); //purposely not implemented
91 
92  void SwapBytesIfNecessary(void *buffer, SizeValueType numberOfPixels);
93 
95  void Write32BitsInteger(unsigned int value);
96 
97  void Write16BitsInteger(unsigned short value);
98 
99  RGBPixelType GetColorPaletteEntry(const unsigned char entry) const;
100 
101  std::ifstream m_Ifstream;
102  std::ofstream m_Ofstream;
103  long m_BitMapOffset;
104  bool m_FileLowerLeft;
105  short m_Depth;
106  bool m_Allow8BitBMP;
107  unsigned short m_NumberOfColors;
108  unsigned int m_ColorTableSize;
109  long m_BMPCompression;
110  unsigned long m_BMPDataSize;
111  std::vector< RGBPixelType > m_ColorPalette;
112 };
113 } // end namespace itk
114 
115 #endif // itkBMPImageIO_h
Light weight base class for most itk classes.
Read BMPImage file format.
Definition: itkBMPImageIO.h:38
BMPImageIO Self
Definition: itkBMPImageIO.h:42
Abstract superclass defines image IO interface.
ImageIOBase Superclass
Definition: itkBMPImageIO.h:43
RGBPixel< unsigned char > RGBPixelType
Definition: itkBMPImageIO.h:45
::itk::SizeValueType SizeValueType
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:58
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:57
SmartPointer< Self > Pointer
Definition: itkBMPImageIO.h:44