PetaVision  Alpha
Image.hpp
1 // Wrapper class for stb_image.h
2 // athresher, Jul 27 2016
3 
4 #ifndef __IMAGE_HPP__
5 #define __IMAGE_HPP__
6 
7 #include "Buffer.hpp"
8 
9 #include <string>
10 #include <vector>
11 
12 namespace PV {
13 
14 class Image : public Buffer<float> {
15  public:
16  Image(std::string filename);
17  Image(const std::vector<float> &data, int width, int height, int channels);
18 
19  void setPixel(int x, int y, float r, float g, float b);
20  void setPixel(int x, int y, float r, float g, float b, float a);
21  float getPixelR(int x, int y);
22  float getPixelG(int x, int y);
23  float getPixelB(int x, int y);
24  float getPixelA(int x, int y);
25  void convertToColor(bool alphaChannel);
26  void convertToGray(bool alphaChannel);
27  void read(std::string filename);
28  void write(std::string filename);
29  static constexpr const float mRToGray = 0.30f;
30  static constexpr const float mGToGray = 0.59f;
31  static constexpr const float mBToGray = 0.11f;
32 
33  protected:
34  // These only line up for RGB and RGBA. Should that change?
35  const int mRPos = 0;
36  const int mGPos = 1;
37  const int mBPos = 2;
38  const int mAPos = 3;
39 };
40 }
41 
42 #endif