Ignition Common

API Reference

3.5.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  "BAYER_BGGR8"
57  };
58 
61  class IGNITION_COMMON_GRAPHICS_VISIBLE Image
62  {
64  public: enum PixelFormatType
65  {
66  UNKNOWN_PIXEL_FORMAT = 0,
86  BAYER_BGGR8
87  };
88 
89 
93  public: static Image::PixelFormatType ConvertPixelFormat(
94  const std::string &_format);
95 
98  public: explicit Image(const std::string &_filename = "");
99 
101  public: virtual ~Image();
102 
106  public: int Load(const std::string &_filename);
107 
110  public: void SavePNG(const std::string &_filename);
111 
117  public: void SetFromData(const unsigned char *_data,
118  unsigned int _width,
119  unsigned int _height,
120  Image::PixelFormatType _format);
121 
125  public: void Data(unsigned char **_data,
126  unsigned int &_count) const;
127 
132  public: void RGBData(unsigned char **_data,
133  unsigned int &_count) const;
134 
137  public: unsigned int Width() const;
138 
141  public: unsigned int Height() const;
142 
145  public: unsigned int BPP() const;
146 
147  // \brief Get the size of a row of pixel
149  public: int Pitch() const;
150 
153  public: std::string Filename() const;
154 
157  public: PixelFormatType PixelFormat() const;
158 
163  public: math::Color Pixel(const unsigned int _x,
164  const unsigned int _y) const;
165 
168  public: math::Color AvgColor();
169 
172  public: math::Color MaxColor() const;
173 
177  public: void Rescale(const int _width, const int _height);
178 
181  public: bool Valid() const;
182 
185  private: std::unique_ptr<ImagePrivate> dataPtr;
187  };
188  }
189 }
190 #endif
Definition: Image.hh:73
Definition: Image.hh:72
Definition: Image.hh:68
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: SuppressWarning.hh:67
Definition: Image.hh:67
STL class.
PixelFormatType
Pixel formats enumeration.
Definition: Image.hh:64
Definition: Image.hh:79
Definition: Image.hh:77
Definition: Image.hh:69
Definition: Image.hh:70
Definition: Image.hh:75
static std::string PixelFormatNames[]
String names for the pixel formats.
Definition: Image.hh:35
Forward declarations for the common classes.
Definition: Image.hh:74
Definition: Image.hh:76
Encapsulates an image.
Definition: Image.hh:61
Definition: Image.hh:71
#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