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 2011 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 
42  class Image
43  {
45  public: enum PixelFormat {
65  };
66 
69  public: Image(const std::string &_filename="");
70 
72  public: virtual ~Image();
73 
76  public: int Load(const std::string &_filename);
77 
80  public: void SavePNG(const std::string &_filename);
81 
87  public: void SetFromData(const unsigned char *_data,
88  unsigned int _width,
89  unsigned int _height,
90  Image::PixelFormat _format);
91 
95  public: void GetData(unsigned char **_data,
96  unsigned int &_count) const;
97 
102  public: void GetRGBData(unsigned char **_data,
103  unsigned int &_count) const;
104 
107  public: unsigned int GetWidth() const;
108 
111  public: unsigned int GetHeight() const;
112 
115  public: unsigned int GetBPP() const;
116 
117  // \brief Get the size of a row of pixel
119  public: int GetPitch() const;
120 
123  public: std::string GetFilename() const;
124 
127  public: PixelFormat GetPixelFormat() const;
128 
132  public: Color GetPixel(unsigned int _x, unsigned int _y);
133 
136  public: Color GetAvgColor();
137 
140  public: Color GetMaxColor();
141 
145  public: void Rescale(int _width, int _height);
146 
149  public: bool Valid() const;
150 
152  private: void GetDataImpl(unsigned char **_data, unsigned int &_count,
153  FIBITMAP *_img) const;
154 
157  private: static int count;
158 
160  private: FIBITMAP *bitmap;
161 
163  private: std::string fullName;
164  };
166  }
167 }
168 #endif