Image.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 
37 #include "gazebo/common/Color.hh"
38 #include "gazebo/util/system.hh"
39 
40 namespace gazebo
41 {
42  namespace common
43  {
46 
49  static std::string PixelFormatNames[] =
50  {
51  "UNKNOWN_PIXEL_FORMAT",
52  "L_INT8",
53  "L_INT16",
54  "RGB_INT8",
55  "RGBA_INT8",
56  "BGRA_INT8",
57  "RGB_INT16",
58  "RGB_INT32",
59  "BGR_INT8",
60  "BGR_INT16",
61  "BGR_INT32",
62  "R_FLOAT16",
63  "RGB_FLOAT16",
64  "R_FLOAT32",
65  "RGB_FLOAT32",
66  "BAYER_RGGB8",
67  "BAYER_RGGR8",
68  "BAYER_GBRG8",
69  "BAYER_GRBG8"
70  };
71 
74  class GZ_COMMON_VISIBLE Image
75  {
77  public: enum PixelFormat
78  {
79  UNKNOWN_PIXEL_FORMAT = 0,
98  PIXEL_FORMAT_COUNT
99  };
100 
101 
105  public: static Image::PixelFormat ConvertPixelFormat(
106  const std::string &_format);
107 
110  public: explicit Image(const std::string &_filename="");
111 
113  public: virtual ~Image();
114 
118  public: int Load(const std::string &_filename);
119 
122  public: void SavePNG(const std::string &_filename);
123 
129  public: void SetFromData(const unsigned char *_data,
130  unsigned int _width,
131  unsigned int _height,
132  Image::PixelFormat _format);
133 
137  public: void GetData(unsigned char **_data,
138  unsigned int &_count) const;
139 
144  public: void GetRGBData(unsigned char **_data,
145  unsigned int &_count) const;
146 
149  public: unsigned int GetWidth() const;
150 
153  public: unsigned int GetHeight() const;
154 
157  public: unsigned int GetBPP() const;
158 
159  // \brief Get the size of a row of pixel
161  public: int GetPitch() const;
162 
165  public: std::string GetFilename() const;
166 
169  public: PixelFormat GetPixelFormat() const;
170 
175  public: Color GetPixel(unsigned int _x, unsigned int _y) const;
176 
179  public: Color GetAvgColor();
180 
183  public: Color GetMaxColor() const;
184 
188  public: void Rescale(int _width, int _height);
189 
192  public: bool Valid() const;
193 
195  private: void GetDataImpl(unsigned char **_data, unsigned int &_count,
196  FIBITMAP *_img) const;
197 
200  private: static int count;
201 
203  private: FIBITMAP *bitmap;
204 
206  private: std::string fullName;
207  };
209  }
210 }
211 #endif
Definition: Image.hh:80
Definition: Image.hh:95
Definition: Image.hh:94
Definition: Image.hh:87
Definition: Image.hh:97
Definition: Image.hh:81
Definition: Image.hh:89
PixelFormat
Pixel formats enumeration.
Definition: Image.hh:77
Definition: Image.hh:93
Definition: Image.hh:82
Definition: Image.hh:83
Definition: Image.hh:88
Definition: Image.hh:86
Definition: Image.hh:90
Definition: Image.hh:92
Defines a color.
Definition: Color.hh:36
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:49
Definition: Image.hh:91
Definition: Image.hh:85
Encapsulates an image.
Definition: Image.hh:74
Definition: Image.hh:96
Definition: Image.hh:84