ITK  4.13.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;
45 
46  typedef RGBPixel< unsigned char > RGBPixelType; //Palette is only unsigned char in BMP files
47  typedef std::vector< RGBPixelType > PaletteType;
48 
50  itkNewMacro(Self);
51 
53  itkTypeMacro(BMPImageIO, Superclass);
54 
56  itkGetConstMacro(FileLowerLeft, bool);
57 
59  itkGetConstMacro(BMPCompression, long);
60 
62  itkGetConstReferenceMacro(ColorPalette, PaletteType);
63 
64  /*-------- This part of the interfaces deals with reading data. ----- */
65 
68  virtual bool CanReadFile(const char *) ITK_OVERRIDE;
69 
71  virtual void ReadImageInformation() ITK_OVERRIDE;
72 
74  virtual void Read(void *buffer) ITK_OVERRIDE;
75 
76  /*-------- This part of the interfaces deals with writing data. ----- */
77 
80  virtual bool CanWriteFile(const char *) ITK_OVERRIDE;
81 
83  virtual void WriteImageInformation() ITK_OVERRIDE;
84 
87  virtual void Write(const void *buffer) ITK_OVERRIDE;
88 
89  BMPImageIO();
90  ~BMPImageIO() ITK_OVERRIDE;
91  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
92 
93 private:
94  ITK_DISALLOW_COPY_AND_ASSIGN(BMPImageIO);
95 
96  void SwapBytesIfNecessary(void *buffer, SizeValueType numberOfPixels);
97 
99  void Write32BitsInteger(unsigned int value);
100 
101  void Write16BitsInteger(unsigned short value);
102 
103  RGBPixelType GetColorPaletteEntry(const unsigned char entry) const;
104 
105  std::ifstream m_Ifstream;
106  std::ofstream m_Ofstream;
107  long m_BitMapOffset;
108  bool m_FileLowerLeft;
109  short m_Depth;
110  unsigned short m_NumberOfColors;
111  unsigned int m_ColorPaletteSize;
112  long m_BMPCompression;
113  unsigned long m_BMPDataSize;
114  PaletteType m_ColorPalette;
115 };
116 } // end namespace itk
117 
118 #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.
std::vector< RGBPixelType > PaletteType
Definition: itkBMPImageIO.h:47
ImageIOBase Superclass
Definition: itkBMPImageIO.h:43
RGBPixel< unsigned char > RGBPixelType
Definition: itkBMPImageIO.h:46
::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:59
SmartPointer< Self > Pointer
Definition: itkBMPImageIO.h:44