ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkBMPImageIO.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkBMPImageIO_h
00019 #define __itkBMPImageIO_h
00020 
00021 
00022 #include <fstream>
00023 #include "itkImageIOBase.h"
00024 #include <stdio.h>
00025 #include "itkRGBPixel.h"
00026 
00027 namespace itk
00028 {
00037 class ITK_EXPORT BMPImageIO:public ImageIOBase
00038 {
00039 public:
00041   typedef BMPImageIO                Self;
00042   typedef ImageIOBase               Superclass;
00043   typedef SmartPointer< Self >      Pointer;
00044   typedef RGBPixel< unsigned char > RGBPixelType;
00045 
00047   itkNewMacro(Self);
00048 
00050   itkTypeMacro(BMPImageIO, Superclass);
00051 
00052   /*-------- This part of the interfaces deals with reading data. ----- */
00053 
00056   virtual bool CanReadFile(const char *);
00057 
00059   virtual void ReadImageInformation();
00060 
00062   virtual void Read(void *buffer);
00063 
00064   /*-------- This part of the interfaces deals with writing data. ----- */
00065 
00068   virtual bool CanWriteFile(const char *);
00069 
00071   virtual void WriteImageInformation();
00072 
00075   virtual void Write(const void *buffer);
00076 
00077   BMPImageIO();
00078   ~BMPImageIO();
00079   void PrintSelf(std::ostream & os, Indent indent) const;
00080 
00081 private:
00082   BMPImageIO(const Self &);     //purposely not implemented
00083   void operator=(const Self &); //purposely not implemented
00084 
00085   void SwapBytesIfNecessary(void *buffer, SizeValueType numberOfPixels);
00086 
00088   void Write32BitsInteger(unsigned int value);
00089 
00090   void Write16BitsInteger(unsigned short value);
00091 
00092   std::ifstream               m_Ifstream;
00093   std::ofstream               m_Ofstream;
00094   long                        m_BitMapOffset;
00095   bool                        m_FileLowerLeft;
00096   short                       m_Depth;
00097   bool                        m_Allow8BitBMP;
00098   unsigned short              m_NumberOfColors;
00099   unsigned int                m_ColorTableSize;
00100   long                        m_BMPCompression;
00101   unsigned long               m_BMPDataSize;
00102   std::vector< RGBPixelType > m_ColorPalette;
00103 };
00104 } // end namespace itk
00105 
00106 #endif // __itkBMPImageIO_h
00107