Choreonoid  1.8
Image.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_UTIL_IMAGE_H
7 #define CNOID_UTIL_IMAGE_H
8 
9 #include "NullOut.h"
10 #include <string>
11 #include <vector>
12 #include "exportdecl.h"
13 
14 namespace cnoid {
15 
16 class CNOID_EXPORT Image
17 {
18 public:
19  Image();
20  Image(const Image& org);
21  virtual ~Image();
22 
23  Image& operator=(const Image& rhs);
24 
25  void reset();
26  bool empty() const { return pixels_.empty(); }
27 
28  unsigned char* pixels() { return &pixels_.front(); }
29  const unsigned char* pixels() const { return &pixels_.front(); }
30 
31  int width() const { return width_; }
32  int height() const { return height_; }
33  int numComponents() const { return numComponents_; }
34  bool hasAlphaComponent() const { return (numComponents() % 2) == 0; }
35 
36  void setSize(int width, int height, int nComponents);
37  void setSize(int width, int height);
38 
39  void clear();
40  void applyVerticalFlip();
41 
42  bool load(const std::string& filename, std::ostream& os = nullout());
43  bool save(const std::string& filename, std::ostream& os = nullout()) const;
44 
45 private:
46  std::vector<unsigned char> pixels_;
47  int width_;
48  int height_;
49  int numComponents_;
50 };
51 
52 }
53 
54 #endif
NullOut.h
cnoid::Image::pixels
unsigned char * pixels()
Definition: Image.h:28
cnoid::nullout
std::ostream & nullout()
Definition: NullOut.cpp:26
cnoid::Image::numComponents
int numComponents() const
Definition: Image.h:33
cnoid::Image::width
int width() const
Definition: Image.h:31
cnoid::Image::height
int height() const
Definition: Image.h:32
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::Image::empty
bool empty() const
Definition: Image.h:26
cnoid::Image
Definition: Image.h:16
cnoid::Image::pixels
const unsigned char * pixels() const
Definition: Image.h:29
cnoid::Image::hasAlphaComponent
bool hasAlphaComponent() const
Definition: Image.h:34