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 Nate Koenig
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  class Image
44  {
46  public: enum PixelFormat {
66  };
67 
70  public: Image(const std::string &_filename="");
71 
73  public: virtual ~Image();
74 
77  public: int Load(const std::string &_filename);
78 
81  public: void SavePNG(const std::string &_filename);
82 
88  public: void SetFromData(const unsigned char *_data,
89  unsigned int _width,
90  unsigned int _height,
91  Image::PixelFormat _format);
92 
96  public: void GetData(unsigned char **_data,
97  unsigned int &_count) const;
98 
103  public: void GetRGBData(unsigned char **_data,
104  unsigned int &_count) const;
105 
108  public: unsigned int GetWidth() const;
109 
112  public: unsigned int GetHeight() const;
113 
116  public: unsigned int GetBPP() const;
117 
118  // \brief Get the size of a row of pixel
120  public: int GetPitch() const;
121 
124  public: std::string GetFilename() const;
125 
128  public: PixelFormat GetPixelFormat() const;
129 
133  public: Color GetPixel(unsigned int _x, unsigned int _y);
134 
137  public: Color GetAvgColor();
138 
141  public: Color GetMaxColor();
142 
146  public: void Rescale(int _width, int _height);
147 
150  public: bool Valid() const;
151 
153  private: void GetDataImpl(unsigned char **_data, unsigned int &_count,
154  FIBITMAP *_img) const;
155 
158  private: static int count;
159 
161  private: FIBITMAP *bitmap;
162 
164  private: std::string fullName;
165  };
167  }
168 }
169 #endif