All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Image.hh
Go to the documentation of this file.
1 /*
2  * Copyright 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 BOOL
26 #undef BOOL
27 #endif
28 #include <FreeImage.h>
29 #include <string>
30 
31 #include "common/CommonTypes.hh"
32 #include "common/Color.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 
68  class Image
69  {
71  public: enum PixelFormat
72  {
93  };
94 
95 
100  const std::string &_format);
101 
104  public: explicit Image(const std::string &_filename="");
105 
107  public: virtual ~Image();
108 
111  public: int Load(const std::string &_filename);
112 
115  public: void SavePNG(const std::string &_filename);
116 
122  public: void SetFromData(const unsigned char *_data,
123  unsigned int _width,
124  unsigned int _height,
125  Image::PixelFormat _format);
126 
130  public: void GetData(unsigned char **_data,
131  unsigned int &_count) const;
132 
137  public: void GetRGBData(unsigned char **_data,
138  unsigned int &_count) const;
139 
142  public: unsigned int GetWidth() const;
143 
146  public: unsigned int GetHeight() const;
147 
150  public: unsigned int GetBPP() const;
151 
152  // \brief Get the size of a row of pixel
154  public: int GetPitch() const;
155 
158  public: std::string GetFilename() const;
159 
162  public: PixelFormat GetPixelFormat() const;
163 
167  public: Color GetPixel(unsigned int _x, unsigned int _y);
168 
171  public: Color GetAvgColor();
172 
175  public: Color GetMaxColor();
176 
180  public: void Rescale(int _width, int _height);
181 
184  public: bool Valid() const;
185 
187  private: void GetDataImpl(unsigned char **_data, unsigned int &_count,
188  FIBITMAP *_img) const;
189 
192  private: static int count;
193 
195  private: FIBITMAP *bitmap;
196 
198  private: std::string fullName;
199  };
201  }
202 }
203 #endif