Image.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 BOOL
26 #undef BOOL
27 #endif
28 #include <FreeImage.h>
29 #include <string>
30 
31 #include "gazebo/common/Color.hh"
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace common
37  {
40 
43  static std::string PixelFormatNames[] =
44  {
45  "UNKNOWN_PIXEL_FORMAT",
46  "L_INT8",
47  "L_INT16",
48  "RGB_INT8",
49  "RGBA_INT8",
50  "BGRA_INT8",
51  "RGB_INT16",
52  "RGB_INT32",
53  "BGR_INT8",
54  "BGR_INT16",
55  "BGR_INT32",
56  "R_FLOAT16",
57  "RGB_FLOAT16",
58  "R_FLOAT32",
59  "RGB_FLOAT32",
60  "BAYER_RGGB8",
61  "BAYER_RGGR8",
62  "BAYER_GBRG8",
63  "BAYER_GRBG8"
64  };
65 
69  {
71  public: enum PixelFormat
72  {
73  UNKNOWN_PIXEL_FORMAT = 0,
92  PIXEL_FORMAT_COUNT
93  };
94 
95 
99  public: static Image::PixelFormat ConvertPixelFormat(
100  const std::string &_format);
101 
104  public: explicit Image(const std::string &_filename="");
105 
107  public: virtual ~Image();
108 
112  public: int Load(const std::string &_filename);
113 
116  public: void SavePNG(const std::string &_filename);
117 
123  public: void SetFromData(const unsigned char *_data,
124  unsigned int _width,
125  unsigned int _height,
126  Image::PixelFormat _format);
127 
131  public: void GetData(unsigned char **_data,
132  unsigned int &_count) const;
133 
138  public: void GetRGBData(unsigned char **_data,
139  unsigned int &_count) const;
140 
143  public: unsigned int GetWidth() const;
144 
147  public: unsigned int GetHeight() const;
148 
151  public: unsigned int GetBPP() const;
152 
153  // \brief Get the size of a row of pixel
155  public: int GetPitch() const;
156 
159  public: std::string GetFilename() const;
160 
163  public: PixelFormat GetPixelFormat() const;
164 
169  public: Color GetPixel(unsigned int _x, unsigned int _y) const;
170 
173  public: Color GetAvgColor();
174 
177  public: Color GetMaxColor() const;
178 
182  public: void Rescale(int _width, int _height);
183 
186  public: bool Valid() const;
187 
189  private: void GetDataImpl(unsigned char **_data, unsigned int &_count,
190  FIBITMAP *_img) const;
191 
194  private: static int count;
195 
197  private: FIBITMAP *bitmap;
198 
200  private: std::string fullName;
201  };
203  }
204 }
205 #endif
Definition: Image.hh:85
Definition: Image.hh:75
Definition: Image.hh:86
Definition: Image.hh:78
Definition: Image.hh:80
#define GZ_COMMON_VISIBLE
Definition: system.hh:91
Definition: Image.hh:91
Definition: Image.hh:79
Definition: Image.hh:88
Definition: Image.hh:89
Definition: Image.hh:81
PixelFormat
Pixel formats enumeration.
Definition: Image.hh:71
Definition: Image.hh:90
Definition: Image.hh:84
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:43
Definition: Image.hh:76
Definition: Image.hh:87
Defines a color.
Definition: Color.hh:36
Definition: Image.hh:83
Encapsulates an image.
Definition: Image.hh:68
Definition: Image.hh:77
Definition: Image.hh:74
Definition: Image.hh:82