ITK  5.4.0
Insight Toolkit
itkBMPImageIO.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 {
39 class ITKIOBMP_EXPORT BMPImageIO : public ImageIOBase
40 {
41 public:
42  ITK_DISALLOW_COPY_AND_MOVE(BMPImageIO);
43 
45  using Self = BMPImageIO;
48 
49  using RGBPixelType = RGBPixel<unsigned char>; // Palette is only unsigned char in BMP files
50  using PaletteType = std::vector<RGBPixelType>;
51 
53  itkNewMacro(Self);
54 
56  itkOverrideGetNameOfClassMacro(BMPImageIO);
57 
59  itkGetConstMacro(FileLowerLeft, bool);
60 
62  itkGetConstMacro(BMPCompression, long);
63 
65  itkGetConstReferenceMacro(ColorPalette, PaletteType);
66 
67  /*-------- This part of the interfaces deals with reading data. ----- */
68 
71  bool
72  CanReadFile(const char *) override;
73 
75  void
76  ReadImageInformation() override;
77 
79  void
80  Read(void * buffer) override;
81 
82  /*-------- This part of the interfaces deals with writing data. ----- */
83 
86  bool
87  CanWriteFile(const char *) override;
88 
90  void
91  WriteImageInformation() override;
92 
95  void
96  Write(const void * buffer) override;
97 
98  BMPImageIO();
99  ~BMPImageIO() override;
100  void
101  PrintSelf(std::ostream & os, Indent indent) const override;
102 
103 private:
104  void
105  SwapBytesIfNecessary(void * buffer, SizeValueType numberOfPixels);
106 
108  void
109  Write32BitsInteger(unsigned int value);
110 
111  void
112  Write16BitsInteger(unsigned short value);
113 
115  GetColorPaletteEntry(const unsigned char entry) const;
116 
117  std::ifstream m_Ifstream{};
118  std::ofstream m_Ofstream{};
119  long m_BitMapOffset{ 0 };
120  bool m_FileLowerLeft{ false };
121  short m_Depth{ 8 };
122  unsigned short m_NumberOfColors{ 0 };
123  unsigned int m_ColorPaletteSize{ 0 };
124  long m_BMPCompression{ 0 };
125  unsigned long m_BMPDataSize{ 0 };
126  PaletteType m_ColorPalette{};
127 };
128 } // end namespace itk
129 
130 #endif // itkBMPImageIO_h
itk::ImageIOBase
Abstract superclass defines image IO interface.
Definition: itkImageIOBase.h:77
itk::ImageIOBase::SizeValueType
itk::SizeValueType SizeValueType
Definition: itkImageIOBase.h:98
itk::RGBPixel
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:58
itkRGBPixel.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::BMPImageIO
Read BMPImage file format.
Definition: itkBMPImageIO.h:39
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkImageIOBase.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::BMPImageIO::PaletteType
std::vector< RGBPixelType > PaletteType
Definition: itkBMPImageIO.h:50