Image.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /* Desc: Image class
18  * Author: Nate Koenig
19  * Date: 14 July 2008
20  */
21 
22 #ifndef _IMAGE_HH_
23 #define _IMAGE_HH_
24 
25 #ifdef _WIN32
26  // Ensure that Winsock2.h is included before Windows.h, which can get
27  // pulled in by anybody (e.g., Boost).
28  #include <Winsock2.h>
29 #endif
30 
31 #ifdef BOOL
32 #undef BOOL
33 #endif
34 #include <FreeImage.h>
35 #include <string>
36 #include <ignition/math/Color.hh>
37 
38 #include "gazebo/common/Color.hh"
39 #include "gazebo/util/system.hh"
40 
41 namespace gazebo
42 {
43  namespace common
44  {
47 
50  static std::string PixelFormatNames[] =
51  {
52  "UNKNOWN_PIXEL_FORMAT",
53  "L_INT8",
54  "L_INT16",
55  "RGB_INT8",
56  "RGBA_INT8",
57  "BGRA_INT8",
58  "RGB_INT16",
59  "RGB_INT32",
60  "BGR_INT8",
61  "BGR_INT16",
62  "BGR_INT32",
63  "R_FLOAT16",
64  "RGB_FLOAT16",
65  "R_FLOAT32",
66  "RGB_FLOAT32",
67  "BAYER_RGGB8",
68  "BAYER_RGGR8",
69  "BAYER_GBRG8",
70  "BAYER_GRBG8"
71  };
72 
75  class GZ_COMMON_VISIBLE Image
76  {
78  public: enum PixelFormat
79  {
80  UNKNOWN_PIXEL_FORMAT = 0,
99  PIXEL_FORMAT_COUNT
100  };
101 
102 
106  public: static Image::PixelFormat ConvertPixelFormat(
107  const std::string &_format);
108 
111  public: explicit Image(const std::string &_filename="");
112 
114  public: virtual ~Image();
115 
119  public: int Load(const std::string &_filename);
120 
123  public: void SavePNG(const std::string &_filename);
124 
130  public: void SetFromData(const unsigned char *_data,
131  unsigned int _width,
132  unsigned int _height,
133  Image::PixelFormat _format);
134 
138  public: void GetData(unsigned char **_data,
139  unsigned int &_count) const;
140 
145  public: void GetRGBData(unsigned char **_data,
146  unsigned int &_count) const;
147 
150  public: unsigned int GetWidth() const;
151 
154  public: unsigned int GetHeight() const;
155 
158  public: unsigned int GetBPP() const;
159 
160  // \brief Get the size of a row of pixel
162  public: int GetPitch() const;
163 
166  public: std::string GetFilename() const;
167 
170  public: PixelFormat GetPixelFormat() const;
171 
177  public: Color GetPixel(unsigned int _x, unsigned int _y) const
178  GAZEBO_DEPRECATED(9.0);
179 
184  public: ignition::math::Color Pixel(const unsigned int _x,
185  const unsigned int _y) const;
186 
190  public: Color GetAvgColor() GAZEBO_DEPRECATED(9.0);
191 
194  public: ignition::math::Color AvgColor();
195 
199  public: Color GetMaxColor() const GAZEBO_DEPRECATED(9.0);
200 
203  public: ignition::math::Color MaxColor() const;
204 
208  public: void Rescale(int _width, int _height);
209 
212  public: bool Valid() const;
213 
215  private: void GetDataImpl(unsigned char **_data, unsigned int &_count,
216  FIBITMAP *_img) const;
217 
220  private: static int count;
221 
223  private: FIBITMAP *bitmap;
224 
226  private: std::string fullName;
227  };
229  }
230 }
231 #endif
Definition: Image.hh:81
Definition: Image.hh:96
Definition: Image.hh:95
Definition: Image.hh:88
Definition: Image.hh:98
Definition: Image.hh:82
Definition: Image.hh:90
PixelFormat
Pixel formats enumeration.
Definition: Image.hh:78
Definition: Image.hh:94
Definition: Image.hh:83
Definition: Image.hh:84
Definition: Image.hh:89
Definition: Image.hh:87
Definition: Image.hh:91
Definition: Image.hh:93
Defines a color.
Definition: Color.hh:36
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:50
Definition: Image.hh:92
Definition: Image.hh:86
Encapsulates an image.
Definition: Image.hh:75
Definition: Image.hh:97
Definition: Image.hh:85