Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
bitmap.hpp
1 /*
2  Title --- bitmap.hpp
3 
4  Copyright (C) 2013 Giacomo Trudu - wicker25[at]gmail[dot]com
5 
6  This file is part of Rpi-hw.
7 
8  Rpi-hw is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation version 3 of the License.
11 
12  Rpi-hw is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with Rpi-hw. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef _RPI_HW_IMAGE_BITMAP_HPP_
23 #define _RPI_HW_IMAGE_BITMAP_HPP_
24 
25 #include <memory>
26 #include <algorithm>
27 #include <vector>
28 
29 #if USE_MAGICK
30 #include <Magick++.h>
31 #endif
32 
33 #include <rpi-hw/types.hpp>
34 #include <rpi-hw/exception.hpp>
35 
36 #include <rpi-hw/utils.hpp>
37 #include <rpi-hw/utils-inl.hpp>
38 
39 #include <rpi-hw/image/base.hpp>
40 
41 namespace rpihw { // Begin main namespace
42 
43 namespace image { // Begin images namespace
44 
45 #if USE_MAGICK
46 
47  //! Hack to initialize the Magick++ API.
48  struct InitMagick {
49 
50  InitMagick() { Magick::InitializeMagick( NULL ); }
51  };
52 
53  //! Magick++ initializer.
54  static InitMagick magick;
55 
56 #endif
57 
58 
59 /*!
60  @class bitmap
61  @brief Bitmap image.
62 */
63 template < typename T >
64 class bitmap : public image::base< T > {
65 
66 public:
67 
68  /*!
69  @brief Constructor method.
70  @param[in] width The width of the image.
71  @param[in] height The height of the image.
72  @param[in] channels Number of color channel.
73  */
74  bitmap( uint16_t width, uint16_t height, uint8_t channels );
75 
76 
77 #if USE_MAGICK
78 
79  /*!
80  @brief Constructor method.
81  @param[in] path The path to the image file.
82  */
83  bitmap( const std::string &path );
84 
85  /*!
86  @brief Constructor method.
87  @param[in] img An Magick::Image object.
88  */
89  bitmap( Magick::Image &img );
90 
91 #endif /* USE_MAGICK */
92 
93 
94  //! Destructor method.
95  virtual ~bitmap();
96 
97  //! Returns the width of the image.
98  virtual uint16_t getWidth() const;
99 
100  //! Returns the height of the image.
101  virtual uint16_t getHeight() const;
102 
103  //! Returns the number of image channels.
104  virtual uint8_t getSpectrum() const;
105 
106  /*!
107  @brief Sets the color of a pixel.
108  @param[in] x The horizontal position of the pixel.
109  @param[in] y The vertical position of the pixel.
110  @param[in] color A pointer to the color data.
111  */
112  void setData( uint16_t x, uint16_t y, T *color );
113 
114  /*!
115  @brief Sets the channel value of a pixel.
116  @param[in] x The horizontal position of the pixel.
117  @param[in] y The vertical position of the pixel.
118  @param[in] c The color channel.
119  @param[in] value The channel value of the pixel.
120  */
121  void setData( uint16_t x, uint16_t y, uint8_t c, T value );
122 
123  /*!
124  @brief Returns the color of a pixel.
125  @param[in] x The horizontal position of the pixel.
126  @param[in] y The vertical position of the pixel.
127  @return An iterator to the color data.
128  */
129  virtual color_iterator< T > getData( uint16_t x, uint16_t y ) const;
130 
131  /*!
132  @brief Returns the channel value of a pixel.
133  @param[in] x The horizontal position of the pixel.
134  @param[in] y The vertical position of the pixel.
135  @param[in] c The color channel.
136  @return The channel value of the pixel.
137  */
138  virtual T getData( uint16_t x, uint16_t y, uint8_t c ) const;
139 
140 protected:
141 
142  //@{
143  //! Size of the bitmap.
144  uint32_t m_width, m_height;
145  //@}
146 
147  //! Number of color channel.
148  uint8_t m_channels;
149 
150  //! The data buffer.
151  std::vector< T > m_buffer;
152 
153 #if USE_MAGICK
154 
155  /*!
156  @brief Converts Magick::Image object to the bitmap buffer.
157  @param[in] img An Magick::Image object.
158  */
159  void loadMagickObj( Magick::Image &img );
160 
161 #endif
162 };
163 
164 } // End of images namespace
165 
166 } // End of main namespace
167 
168 
169 // Include inline methods
170 #include <rpi-hw/image/bitmap-inl.hpp>
171 
172 #endif /* _RPI_HW_IMAGE_BITMAP_HPP_ */
virtual uint16_t getWidth() const
Returns the width of the image.
Definition: bitmap-inl.hpp:174
uint32_t m_width
Size of the bitmap.
Definition: bitmap.hpp:144
Bitmap image.
Definition: bitmap.hpp:64
virtual uint16_t getHeight() const
Returns the height of the image.
Definition: bitmap-inl.hpp:182
virtual color_iterator< T > getData(uint16_t x, uint16_t y) const
Returns the color of a pixel.
Definition: bitmap-inl.hpp:214
typename std::vector< T >::const_iterator color_iterator
Color iterator.
Definition: types.hpp:45
virtual ~bitmap()
Destructor method.
Definition: bitmap-inl.hpp:168
std::vector< T > m_buffer
The data buffer.
Definition: bitmap.hpp:151
virtual uint8_t getSpectrum() const
Returns the number of image channels.
Definition: bitmap-inl.hpp:190
uint8_t m_channels
Number of color channel.
Definition: bitmap.hpp:148
Generic image.
Definition: base.hpp:44
void setData(uint16_t x, uint16_t y, T *color)
Sets the color of a pixel.
Definition: bitmap-inl.hpp:198
bitmap(uint16_t width, uint16_t height, uint8_t channels)
Constructor method.
Definition: bitmap-inl.hpp:30