core/vil/file_formats/vil_bmp.h

Go to the documentation of this file.
00001 // This is core/vil/file_formats/vil_bmp.h
00002 #ifndef vil_bmp_file_format_h_
00003 #define vil_bmp_file_format_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Don Hamilton, Peter Tu
00010 // \date 17 Feb 2000
00011 //
00012 //\verbatim
00013 //  Modifications
00014 // 27 May 2000 fsm Numerous endianness and structure-packing bugs fixed.
00015 //  3 October 2001 Peter Vanroose - Implemented get_property("top_row_first")
00016 //\endverbatim
00017 
00018 class vil_stream;
00019 
00020 //=============================================================================
00021 
00022 // Due to padding, you cannot expect to read/write the header
00023 // structures as raw sequences of bytes and still get a valid
00024 // BMP header. The compiler will probably place shorts on 4-byte
00025 // boundaries, which means it will place two bytes of padding
00026 // afterwards (little-endian) or before (bigendian).
00027 //
00028 // Use the read() and write() methods instead.
00029 
00030 //--------------------------------------------------------------------------------
00031 
00032 #include <vil/vil_file_format.h>
00033 #include <vil/vil_image_resource.h>
00034 #include <vil/vil_stream.h>
00035 #include "vil_bmp_file_header.h"
00036 #include "vil_bmp_core_header.h"
00037 #include "vil_bmp_info_header.h"
00038 class vil_image_view_base;
00039 
00040 
00041 //: Loader for BMP files
00042 class vil_bmp_file_format : public vil_file_format
00043 {
00044  public:
00045   virtual char const* tag() const;
00046   virtual vil_image_resource_sptr make_input_image(vil_stream* vs);
00047   virtual vil_image_resource_sptr make_output_image(vil_stream* vs,
00048                                                     unsigned nx,
00049                                                     unsigned ny,
00050                                                     unsigned nplanes,
00051                                                     vil_pixel_format format);
00052 };
00053 
00054 //: Generic image implementation for BMP files
00055 class vil_bmp_image : public vil_image_resource
00056 {
00057  public:
00058   vil_bmp_image(vil_stream* is, unsigned ni,
00059                 unsigned nj, unsigned nplanes, vil_pixel_format format);
00060   vil_bmp_image(vil_stream* is);
00061   ~vil_bmp_image();
00062 
00063   //: Dimensions:  planes x width x height x components
00064   virtual unsigned nplanes() const {
00065     return (core_hdr.bitsperpixel<24)?1:core_hdr.bitsperpixel/8; }  // FIXME
00066   virtual unsigned ni() const { return core_hdr.width; }
00067   virtual unsigned nj() const { return core_hdr.height; }
00068 
00069   virtual enum vil_pixel_format pixel_format() const {return VIL_PIXEL_FORMAT_BYTE; }
00070 
00071   //: Create a read/write view of a copy of this data.
00072   // \return 0 if unable to get view of correct size.
00073   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00074                                                  unsigned j0, unsigned nj) const;
00075 
00076   //: Put the data in this view back into the image source.
00077   virtual bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0);
00078 
00079   char const* file_format() const;
00080   bool get_property(char const *tag, void *prop = 0) const;
00081  private:
00082   vil_stream* is_;
00083 
00084   bool read_header();
00085   bool write_header();
00086 
00087   friend class vil_bmp_file_format;
00088 
00089   vil_bmp_file_header file_hdr;
00090   vil_bmp_core_header core_hdr;
00091   vil_bmp_info_header info_hdr;
00092   vil_streampos bit_map_start; // position in file of bitmap raw data.
00093 #if 0
00094   uchar **freds_colormap;
00095 
00096   xBITMAPINFOHEADER header;
00097   xBITMAPFILEHEADER fbmp;
00098   int pixsize;
00099   int** local_color_map_;
00100 #endif // 0
00101 };
00102 
00103 
00104 #endif // vil_bmp_file_format_h_

Generated on Sat Nov 22 05:07:51 2008 for core/vil by  doxygen 1.5.1