core/vil1/file_formats/vil1_bmp.h

Go to the documentation of this file.
00001 // This is core/vil1/file_formats/vil1_bmp.h
00002 #ifndef vil1_bmp_file_format_h_
00003 #define vil1_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 vil1_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 <vil1/vil1_file_format.h>
00033 #include <vil1/vil1_image_impl.h>
00034 #include "vil1_bmp_file_header.h"
00035 #include "vil1_bmp_core_header.h"
00036 #include "vil1_bmp_info_header.h"
00037 
00038 //: Loader for BMP files
00039 class vil1_bmp_file_format : public vil1_file_format
00040 {
00041  public:
00042   virtual char const* tag() const;
00043   virtual vil1_image_impl* make_input_image(vil1_stream* vs);
00044   virtual vil1_image_impl* make_output_image(vil1_stream* vs, int planes,
00045                                              int width,
00046                                              int height,
00047                                              int components,
00048                                              int bits_per_component,
00049                                              vil1_component_format format);
00050 };
00051 
00052 //: Generic image implementation for BMP files
00053 class vil1_bmp_generic_image : public vil1_image_impl
00054 {
00055  public:
00056 
00057   vil1_bmp_generic_image(vil1_stream* is);
00058   vil1_bmp_generic_image(vil1_stream* is,
00059                          int planes,
00060                          int width,
00061                          int height,
00062                          int components,
00063                          int bits_per_component,
00064                          vil1_component_format format);
00065 
00066   ~vil1_bmp_generic_image();
00067 
00068   //: Dimensions.  Planes x W x H x Components
00069   virtual int planes() const { return 1; } // assume only one for now.
00070   virtual int width() const { return core_hdr.width; }
00071   virtual int height() const { return core_hdr.height; }
00072   virtual int components() const { return (core_hdr.bitsperpixel<24)?1:core_hdr.bitsperpixel/8; } // FIXME
00073   virtual int bits_per_component() const { return (core_hdr.bitsperpixel<24)?core_hdr.bitsperpixel:8; } // FIXME
00074   virtual enum vil1_component_format component_format() const { return VIL1_COMPONENT_FORMAT_UNSIGNED_INT; }
00075 
00076   //: Copy plane PLANE of this to BUF,
00077   virtual bool get_section(void* buf, int x0, int y0, int width, int height) const;
00078   virtual bool put_section(void const* buf, int x0, int y0, int width, int height);
00079 
00080   char const* file_format() const;
00081   bool get_property(char const *tag, void *prop = 0) const;
00082 
00083  private:
00084   vil1_stream* is_;
00085 
00086   bool read_header();
00087   bool write_header();
00088 
00089   friend class vil1_bmp_file_format;
00090 
00091   vil1_bmp_file_header file_hdr;
00092   vil1_bmp_core_header core_hdr;
00093   vil1_bmp_info_header info_hdr;
00094   long bit_map_start; // position in file of bitmap raw data.
00095 #if 0
00096   uchar **freds_colormap;
00097 
00098   xBITMAPINFOHEADER header;
00099   xBITMAPFILEHEADER fbmp;
00100   int pixsize;
00101   int** local_color_map_;
00102 #endif
00103 };
00104 
00105 #endif // vil1_bmp_file_format_h_

Generated on Sat Nov 22 05:08:28 2008 for core/vil1 by  doxygen 1.5.1