vil_bmp.h
Go to the documentation of this file.
1 // This is core/vil/file_formats/vil_bmp.h
2 #ifndef vil_bmp_file_format_h_
3 #define vil_bmp_file_format_h_
4 //:
5 // \file
6 // \author Don Hamilton, Peter Tu
7 // \date 17 Feb 2000
8 //
9 //\verbatim
10 // Modifications
11 // 27 May 2000 fsm Numerous endianness and structure-packing bugs fixed.
12 // 3 October 2001 Peter Vanroose - Implemented get_property("top_row_first")
13 // 13 November 2011 Gehua Yang - Allow read and write 32bpp image. Default to have the first plane as alpha channel
14 // See a good reference at http://en.wikipedia.org/wiki/BMP_file_format
15 //\endverbatim
16 
17 class vil_stream;
18 
19 //=============================================================================
20 
21 // Due to padding, you cannot expect to read/write the header
22 // structures as raw sequences of bytes and still get a valid
23 // BMP header. The compiler will probably place shorts on 4-byte
24 // boundaries, which means it will place two bytes of padding
25 // afterwards (little-endian) or before (bigendian).
26 //
27 // Use the read() and write() methods instead.
28 
29 //--------------------------------------------------------------------------------
30 
31 #include <vil/vil_file_format.h>
32 #include <vil/vil_image_resource.h>
33 #include <vil/vil_stream.h>
34 #include "vil_bmp_file_header.h"
35 #include "vil_bmp_core_header.h"
36 #include "vil_bmp_info_header.h"
38 
39 
40 //: Loader for BMP files
42 {
43  public:
44  char const* tag() const override;
47  unsigned nx,
48  unsigned ny,
49  unsigned nplanes,
50  vil_pixel_format format) override;
51 };
52 
53 //: Generic image implementation for BMP files
55 {
56  public:
57  vil_bmp_image(vil_stream* is, unsigned ni,
58  unsigned nj, unsigned nplanes, vil_pixel_format format);
60  ~vil_bmp_image() override;
61 
62  //: Dimensions: planes x width x height x components
63  unsigned nplanes() const override;
64  unsigned ni() const override;
65  unsigned nj() const override;
66 
67  enum vil_pixel_format pixel_format() const override {return VIL_PIXEL_FORMAT_BYTE; }
68 
69  //: Create a read/write view of a copy of this data.
70  // \return 0 if unable to get view of correct size.
71  vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
72  unsigned j0, unsigned nj) const override;
73 
74  //: Put the data in this view back into the image source.
75  bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0) override;
76 
77  char const* file_format() const override;
78  bool get_property(char const *tag, void *prop = nullptr) const override;
79  private:
81 
82  bool read_header();
83  bool write_header();
84 
85  friend class vil_bmp_file_format;
86 
90  vil_streampos bit_map_start; // position in file of bitmap raw data.
91 #if 0
92  uchar **freds_colormap;
93 
94  xBITMAPINFOHEADER header;
95  xBITMAPFILEHEADER fbmp;
96  int pixsize;
97  int** local_color_map_;
98 #endif // 0
99 };
100 
101 
102 #endif // vil_bmp_file_format_h_
vil_stream * is_
Definition: vil_bmp.h:80
unsigned nj() const override
Dimensions: Planes x ni x nj.
Definition: vil_bmp.cxx:152
vil_bmp_image(vil_stream *is, unsigned ni, unsigned nj, unsigned nplanes, vil_pixel_format format)
Definition: vil_bmp.cxx:83
Stream interface for VIL image loaders.
An abstract base class of smart pointers to actual image data in memory.
vil_pixel_format
Describes the type of the concrete data.
char const * file_format() const override
Return a string describing the file format.
Definition: vil_bmp.cxx:53
vil_image_resource_sptr make_input_image(vil_stream *vs) override
Attempt to make a generic_image which will read from vil_stream vs.
Definition: vil_bmp.cxx:22
unsigned nplanes() const override
Dimensions: planes x width x height x components.
Definition: vil_bmp.cxx:142
bool put_view(const vil_image_view_base &im, unsigned i0, unsigned j0) override
Put the data in this view back into the image source.
Definition: vil_bmp.cxx:481
bool read_header()
Definition: vil_bmp.cxx:157
Base class for image formats.
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
bool write_header()
Definition: vil_bmp.cxx:303
char const * tag() const override
Return a character string which uniquely identifies this format.
Definition: vil_bmp.cxx:46
vil_streampos bit_map_start
Definition: vil_bmp.h:90
Generic image implementation for BMP files.
Definition: vil_bmp.h:54
~vil_bmp_image() override
Definition: vil_bmp.cxx:116
Abstract representation of an image source or image destination.
bool get_property(char const *tag, void *prop=nullptr) const override
Extra property information.
Definition: vil_bmp.cxx:71
enum vil_pixel_format pixel_format() const override
Pixel Format.
Definition: vil_bmp.h:67
vil_image_view_base_sptr get_copy_view() const
Create a read/write view of a copy of all the data.
unsigned ni() const override
Dimensions: Planes x ni x nj.
Definition: vil_bmp.cxx:147
Loader for BMP files.
Definition: vil_bmp.h:41
vxl_int_32 vil_streampos
Definition: vil_stream.h:16
Representation of a generic image source or destination.
Base class for image formats.
vil_bmp_info_header info_hdr
Definition: vil_bmp.h:89
vil_image_resource_sptr make_output_image(vil_stream *vs, unsigned nx, unsigned ny, unsigned nplanes, vil_pixel_format format) override
Definition: vil_bmp.cxx:35
vil_bmp_file_header file_hdr
Definition: vil_bmp.h:87
vil_bmp_core_header core_hdr
Definition: vil_bmp.h:88