ITK  5.0.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:
41  ITK_DISALLOW_COPY_AND_ASSIGN(BMPImageIO);
42 
44  using Self = BMPImageIO;
47 
48  using RGBPixelType = RGBPixel< unsigned char >; //Palette is only unsigned char in BMP files
49  using PaletteType = std::vector< RGBPixelType >;
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(BMPImageIO, Superclass);
56 
58  itkGetConstMacro(FileLowerLeft, bool);
59 
61  itkGetConstMacro(BMPCompression, long);
62 
64  itkGetConstReferenceMacro(ColorPalette, PaletteType);
65 
66  /*-------- This part of the interfaces deals with reading data. ----- */
67 
70  bool CanReadFile(const char *) override;
71 
73  void ReadImageInformation() override;
74 
76  void Read(void *buffer) override;
77 
78  /*-------- This part of the interfaces deals with writing data. ----- */
79 
82  bool CanWriteFile(const char *) override;
83 
85  void WriteImageInformation() override;
86 
89  void Write(const void *buffer) override;
90 
91  BMPImageIO();
92  ~BMPImageIO() override;
93  void PrintSelf(std::ostream & os, Indent indent) const override;
94 
95 private:
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{ 0 };
108  bool m_FileLowerLeft{ false };
109  short m_Depth{ 8 };
110  unsigned short m_NumberOfColors{ 0 };
111  unsigned int m_ColorPaletteSize{ 0 };
112  long m_BMPCompression{ 0 };
113  unsigned long m_BMPDataSize{ 0 };
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
Abstract superclass defines image IO interface.
std::ifstream m_Ifstream
::itk::SizeValueType SizeValueType
std::ofstream m_Ofstream
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:58
PaletteType m_ColorPalette
Control indentation during Print() invocation.
Definition: itkIndent.h:49
std::vector< RGBPixelType > PaletteType
Definition: itkBMPImageIO.h:49
Base class for most ITK classes.
Definition: itkObject.h:60