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/common/Color.hh"
29 #include "gazebo/util/system.hh"
30 
31 struct FIBITMAP;
32 namespace gazebo
33 {
34  namespace common
35  {
38 
41  static std::string PixelFormatNames[] =
42  {
43  "UNKNOWN_PIXEL_FORMAT",
44  "L_INT8",
45  "L_INT16",
46  "RGB_INT8",
47  "RGBA_INT8",
48  "BGRA_INT8",
49  "RGB_INT16",
50  "RGB_INT32",
51  "BGR_INT8",
52  "BGR_INT16",
53  "BGR_INT32",
54  "R_FLOAT16",
55  "RGB_FLOAT16",
56  "R_FLOAT32",
57  "RGB_FLOAT32",
58  "BAYER_RGGB8",
59  "BAYER_RGGR8",
60  "BAYER_GBRG8",
61  "BAYER_GRBG8"
62  };
63 
66  class GZ_COMMON_VISIBLE Image
67  {
69  public: enum PixelFormat
70  {
71  UNKNOWN_PIXEL_FORMAT = 0,
90  PIXEL_FORMAT_COUNT
91  };
92 
93 
97  public: static Image::PixelFormat ConvertPixelFormat(
98  const std::string &_format);
99 
102  public: explicit Image(const std::string &_filename="");
103 
105  public: virtual ~Image();
106 
110  public: int Load(const std::string &_filename);
111 
114  public: void SavePNG(const std::string &_filename);
115 
121  public: void SetFromData(const unsigned char *_data,
122  unsigned int _width,
123  unsigned int _height,
124  Image::PixelFormat _format);
125 
129  public: void GetData(unsigned char **_data,
130  unsigned int &_count) const;
131 
136  public: void GetRGBData(unsigned char **_data,
137  unsigned int &_count) const;
138 
141  public: unsigned int GetWidth() const;
142 
145  public: unsigned int GetHeight() const;
146 
149  public: unsigned int GetBPP() const;
150 
151  // \brief Get the size of a row of pixel
153  public: int GetPitch() const;
154 
157  public: std::string GetFilename() const;
158 
161  public: PixelFormat GetPixelFormat() const;
162 
168  public: Color GetPixel(unsigned int _x, unsigned int _y) const
169  GAZEBO_DEPRECATED(9.0);
170 
175  public: ignition::math::Color Pixel(const unsigned int _x,
176  const unsigned int _y) const;
177 
181  public: Color GetAvgColor() GAZEBO_DEPRECATED(9.0);
182 
185  public: ignition::math::Color AvgColor();
186 
190  public: Color GetMaxColor() const GAZEBO_DEPRECATED(9.0);
191 
194  public: ignition::math::Color MaxColor() const;
195 
199  public: void Rescale(int _width, int _height);
200 
203  public: bool Valid() const;
204 
206  private: void GetDataImpl(unsigned char **_data, unsigned int &_count,
207  FIBITMAP *_img) const;
208 
211  private: static int count;
212 
214  private: FIBITMAP *bitmap;
215 
217  private: std::string fullName;
218  };
220  }
221 }
222 #endif
ignition::math::Color AvgColor()
Get the average color.
unsigned int GetBPP() const
Get the size of one pixel in bits.
Color GetAvgColor() GAZEBO_DEPRECATED(9.0)
Get the average color.
bool Valid() const
Returns whether this is a valid image.
Definition: Model.hh:40
Forward declarations for the common classes.
Definition: Animation.hh:26
Color GetPixel(unsigned int _x, unsigned int _y) const GAZEBO_DEPRECATED(9.0)
Get a pixel color value.
Definition: Image.hh:84
void GetRGBData(unsigned char **_data, unsigned int &_count) const
Get only the RGB data from the image.
Image(const std::string &_filename="")
Constructor.
Definition: Image.hh:75
Definition: Image.hh:80
common
Definition: FuelModelDatabase.hh:37
void Rescale(int _width, int _height)
Rescale the image.
Definition: Image.hh:90
void GetData(unsigned char **_data, unsigned int &_count) const
Get the image as a data array.
Definition: Image.hh:78
Definition: Image.hh:82
Encapsulates an image.
Definition: Image.hh:66
static Image::PixelFormat ConvertPixelFormat(const std::string &_format)
Convert a string to a Image::PixelFormat.
Definition: Image.hh:77
PixelFormat
Pixel formats enumeration.
Definition: Image.hh:69
Definition: Image.hh:83
Definition: Image.hh:88
Color GetMaxColor() const GAZEBO_DEPRECATED(9.0)
Get the max color.
Definition: Image.hh:76
PixelFormat GetPixelFormat() const
Get the pixel format.
std::string GetFilename() const
Get the full filename of the image.
Definition: Image.hh:72
Definition: Image.hh:87
void SavePNG(const std::string &_filename)
Save the image in PNG format.
Definition: Image.hh:73
Definition: Image.hh:81
virtual ~Image()
Destructor.
Definition: Image.hh:86
Definition: Image.hh:89
Definition: Image.hh:79
Definition: Image.hh:71
Defines a color.
Definition: Color.hh:36
unsigned int GetWidth() const
Get the width.
ignition::math::Color Pixel(const unsigned int _x, const unsigned int _y) const
Get a pixel color value.
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
unsigned int GetHeight() const
Get the height.
int GetPitch() const
void SetFromData(const unsigned char *_data, unsigned int _width, unsigned int _height, Image::PixelFormat _format)
Set the image from raw data.
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:41
int Load(const std::string &_filename)
Load an image.
ignition::math::Color MaxColor() const
Get the max color.
Definition: Image.hh:85
Definition: Image.hh:74