ITK  6.0.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
28namespace itk
29{
39class ITKIOBMP_EXPORT BMPImageIO : public ImageIOBase
40{
41public:
42 ITK_DISALLOW_COPY_AND_MOVE(BMPImageIO);
43
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
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
92
95 void
96 Write(const void * buffer) override;
97
99 ~BMPImageIO() override;
100 void
101 PrintSelf(std::ostream & os, Indent indent) const override;
102
103private:
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
Read BMPImage file format.
Definition: itkBMPImageIO.h:40
void Write32BitsInteger(unsigned int value)
RGBPixelType GetColorPaletteEntry(const unsigned char entry) const
void SwapBytesIfNecessary(void *buffer, SizeValueType numberOfPixels)
void ReadImageInformation() override
~BMPImageIO() override
void Write16BitsInteger(unsigned short value)
void Read(void *buffer) override
bool CanReadFile(const char *) override
void WriteImageInformation() override
void Write(const void *buffer) override
bool CanWriteFile(const char *) override
void PrintSelf(std::ostream &os, Indent indent) const override
std::vector< RGBPixelType > PaletteType
Definition: itkBMPImageIO.h:50
Abstract superclass defines image IO interface.
itk::SizeValueType SizeValueType
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Base class for most ITK classes.
Definition: itkObject.h:62
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:59
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....