Ignition Common

API Reference

3.0.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 <ignition/math/Color.hh>
23 #include <ignition/common/graphics/Export.hh>
25 
26 namespace ignition
27 {
28  namespace common
29  {
31  class ImagePrivate;
32 
36  {
37  "UNKNOWN_PIXEL_FORMAT",
38  "L_INT8",
39  "L_INT16",
40  "RGB_INT8",
41  "RGBA_INT8",
42  "BGRA_INT8",
43  "RGB_INT16",
44  "RGB_INT32",
45  "BGR_INT8",
46  "BGR_INT16",
47  "BGR_INT32",
48  "R_FLOAT16",
49  "RGB_FLOAT16",
50  "R_FLOAT32",
51  "RGB_FLOAT32",
52  "BAYER_RGGB8",
53  "BAYER_RGGR8",
54  "BAYER_GBRG8",
55  "BAYER_GRBG8"
56  };
57 
60  class IGNITION_COMMON_GRAPHICS_VISIBLE Image
61  {
63  public: enum PixelFormatType
64  {
65  UNKNOWN_PIXEL_FORMAT = 0,
84  PIXEL_FORMAT_COUNT
85  };
86 
87 
91  public: static Image::PixelFormatType ConvertPixelFormat(
92  const std::string &_format);
93 
96  public: explicit Image(const std::string &_filename = "");
97 
99  public: virtual ~Image();
100 
104  public: int Load(const std::string &_filename);
105 
108  public: void SavePNG(const std::string &_filename);
109 
115  public: void SetFromData(const unsigned char *_data,
116  unsigned int _width,
117  unsigned int _height,
118  Image::PixelFormatType _format);
119 
123  public: void Data(unsigned char **_data,
124  unsigned int &_count) const;
125 
130  public: void RGBData(unsigned char **_data,
131  unsigned int &_count) const;
132 
135  public: unsigned int Width() const;
136 
139  public: unsigned int Height() const;
140 
143  public: unsigned int BPP() const;
144 
145  // \brief Get the size of a row of pixel
147  public: int Pitch() const;
148 
151  public: std::string Filename() const;
152 
155  public: PixelFormatType PixelFormat() const;
156 
161  public: math::Color Pixel(const unsigned int _x,
162  const unsigned int _y) const;
163 
166  public: math::Color AvgColor();
167 
170  public: math::Color MaxColor() const;
171 
175  public: void Rescale(const int _width, const int _height);
176 
179  public: bool Valid() const;
180 
183  private: std::unique_ptr<ImagePrivate> dataPtr;
185  };
186  }
187 }
188 #endif
Definition: Image.hh:72
Definition: Image.hh:71
Definition: Image.hh:67
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: SuppressWarning.hh:67
Definition: Image.hh:66
STL class.
PixelFormatType
Pixel formats enumeration.
Definition: Image.hh:63
Definition: Image.hh:78
Definition: Image.hh:76
Definition: Image.hh:68
Definition: Image.hh:69
Definition: Image.hh:74
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:35
Forward declarations for the common classes.
Definition: Image.hh:73
Definition: Image.hh:75
Encapsulates an image.
Definition: Image.hh:60
Definition: Image.hh:70
#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