Ignition Common

API Reference

3.12.0
Image.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 #ifndef IGNITION_COMMON_IMAGE_HH_
18 #define IGNITION_COMMON_IMAGE_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 #include <ignition/math/Color.hh>
24 #include <ignition/common/graphics/Export.hh>
26 
27 namespace ignition
28 {
29  namespace common
30  {
32  class ImagePrivate;
33 
37  {
38  "UNKNOWN_PIXEL_FORMAT",
39  "L_INT8",
40  "L_INT16",
41  "RGB_INT8",
42  "RGBA_INT8",
43  "BGRA_INT8",
44  "RGB_INT16",
45  "RGB_INT32",
46  "BGR_INT8",
47  "BGR_INT16",
48  "BGR_INT32",
49  "R_FLOAT16",
50  "RGB_FLOAT16",
51  "R_FLOAT32",
52  "RGB_FLOAT32",
53  "BAYER_RGGB8",
54  "BAYER_RGGR8",
55  "BAYER_GBRG8",
56  "BAYER_GRBG8",
57  "BAYER_BGGR8"
58  };
59 
62  class IGNITION_COMMON_GRAPHICS_VISIBLE Image
63  {
65  public: enum PixelFormatType
66  {
67  UNKNOWN_PIXEL_FORMAT = 0,
87  BAYER_BGGR8
88  };
89 
90 
94  public: static Image::PixelFormatType ConvertPixelFormat(
95  const std::string &_format);
96 
99  public: explicit Image(const std::string &_filename = "");
100 
102  public: virtual ~Image();
103 
107  public: int Load(const std::string &_filename);
108 
111  public: void SavePNG(const std::string &_filename);
112 
115  public: void SavePNGToBuffer(std::vector<unsigned char> &_buffer);
116 
122  public: void SetFromData(const unsigned char *_data,
123  unsigned int _width,
124  unsigned int _height,
125  Image::PixelFormatType _format);
126 
130  public: void Data(unsigned char **_data,
131  unsigned int &_count) const;
132 
137  public: void RGBData(unsigned char **_data,
138  unsigned int &_count) const;
139 
142  public: unsigned int Width() const;
143 
146  public: unsigned int Height() const;
147 
150  public: unsigned int BPP() const;
151 
152  // \brief Get the size of a row of pixel
154  public: int Pitch() const;
155 
158  public: std::string Filename() const;
159 
162  public: PixelFormatType PixelFormat() const;
163 
168  public: math::Color Pixel(const unsigned int _x,
169  const unsigned int _y) const;
170 
173  public: math::Color AvgColor();
174 
177  public: math::Color MaxColor() const;
178 
182  public: void Rescale(const int _width, const int _height);
183 
186  public: bool Valid() const;
187 
190  private: std::unique_ptr<ImagePrivate> dataPtr;
192  };
193  }
194 }
195 #endif
Definition: Image.hh:74
Definition: Image.hh:73
Definition: Image.hh:69
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: SuppressWarning.hh:67
Definition: Image.hh:68
STL class.
PixelFormatType
Pixel formats enumeration.
Definition: Image.hh:65
Definition: Image.hh:80
Definition: Image.hh:78
Definition: Image.hh:70
Definition: Image.hh:71
STL class.
Definition: Image.hh:76
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:36
Forward declarations for the common classes.
Definition: Image.hh:75
Definition: Image.hh:77
Encapsulates an image.
Definition: Image.hh:62
Definition: Image.hh:72
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: SuppressWarning.hh:64