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 #include <string>
26 #include <ignition/math/Color.hh>
27 
28 #include "gazebo/util/system.hh"
29 
30 struct FIBITMAP;
31 namespace gazebo
32 {
33  namespace common
34  {
37 
40  static std::string PixelFormatNames[] =
41  {
42  "UNKNOWN_PIXEL_FORMAT",
43  "L_INT8",
44  "L_INT16",
45  "RGB_INT8",
46  "RGBA_INT8",
47  "BGRA_INT8",
48  "RGB_INT16",
49  "RGB_INT32",
50  "BGR_INT8",
51  "BGR_INT16",
52  "BGR_INT32",
53  "R_FLOAT16",
54  "RGB_FLOAT16",
55  "R_FLOAT32",
56  "RGB_FLOAT32",
57  "BAYER_RGGB8",
58  "BAYER_BGGR8",
59  "BAYER_GBRG8",
60  "BAYER_GRBG8"
61  };
62 
65  class GZ_COMMON_VISIBLE Image
66  {
68  public: enum PixelFormat
69  {
70  UNKNOWN_PIXEL_FORMAT = 0,
89  PIXEL_FORMAT_COUNT
90  };
91 
92 
96  public: static Image::PixelFormat ConvertPixelFormat(
97  const std::string &_format);
98 
101  public: explicit Image(const std::string &_filename="");
102 
104  public: virtual ~Image();
105 
109  public: int Load(const std::string &_filename);
110 
113  public: void SavePNG(const std::string &_filename);
114 
120  public: void SetFromData(const unsigned char *_data,
121  unsigned int _width,
122  unsigned int _height,
123  Image::PixelFormat _format);
124 
128  public: void GetData(unsigned char **_data,
129  unsigned int &_count) const;
130 
135  public: void GetRGBData(unsigned char **_data,
136  unsigned int &_count) const;
137 
140  public: unsigned int GetWidth() const;
141 
144  public: unsigned int GetHeight() const;
145 
148  public: unsigned int GetBPP() const;
149 
150  // \brief Get the size of a row of pixel
152  public: int GetPitch() const;
153 
156  public: std::string GetFilename() const;
157 
160  public: PixelFormat GetPixelFormat() const;
161 
166  public: ignition::math::Color Pixel(const unsigned int _x,
167  const unsigned int _y) const;
168 
171  public: ignition::math::Color AvgColor();
172 
175  public: ignition::math::Color MaxColor() const;
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
Definition: Image.hh:71
Forward declarations for the common classes.
Definition: Animation.hh:26
Definition: Image.hh:85
Definition: Image.hh:78
Definition: Image.hh:88
Definition: Image.hh:72
Definition: Image.hh:80
PixelFormat
Pixel formats enumeration.
Definition: Image.hh:68
Definition: Image.hh:84
Definition: Image.hh:73
Definition: Image.hh:74
Definition: Image.hh:79
Definition: Image.hh:86
Definition: Image.hh:77
Definition: Image.hh:81
Definition: Image.hh:83
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:40
Definition: Image.hh:82
Definition: Image.hh:76
Encapsulates an image.
Definition: Image.hh:65
Definition: Image.hh:87
common
Definition: FuelModelDatabase.hh:37
Definition: Image.hh:75