PhotoPNG.h (3483B)
1 // File : PhotoPNG.h 2 // Date : Tue Apr 26 14:46:18 2016 3 // Author : Fabian Wermelinger 4 // Description: PNG Photos 5 // Copyright 2016 ETH Zurich. All Rights Reserved. 6 #ifndef PHOTOPNG_H_7DZT9TLW 7 #define PHOTOPNG_H_7DZT9TLW 8 9 #include "Polaroid.h" 10 #include "PhotoPaper.h" 11 #include "pngwriter.h" 12 13 class PNG_HSV : public PhotoPaper 14 { 15 protected: 16 bool m_open; 17 pngwriter* m_png; 18 double m_saturation, m_value, m_background; 19 std::string m_title, m_author, m_software; 20 21 // helper 22 inline void _default_info() 23 { 24 m_title = "Portable Network Graphics"; 25 m_author = "Walt Disney"; 26 m_software = "Polaroid++"; 27 } 28 inline void _dispose() { delete m_png; m_png=nullptr; } 29 30 public: 31 32 PNG_HSV(const std::string filename="hsv", const double saturation=1.0, const double value=1.0, const double bg=1.0) : 33 PhotoPaper(0,0,filename), m_open(false), m_png(nullptr), m_saturation(saturation), m_value(value), m_background(bg) 34 { 35 m_description = "PNG HSV colorscheme"; 36 _default_info(); 37 } 38 PNG_HSV(const Polaroid& cam, const std::string filename="hsv", const double saturation=1.0, const double value=1.0, const double bg=1.0) : 39 PhotoPaper(0,0,filename), m_open(false), m_png(nullptr), m_saturation(saturation), m_value(value), m_background(bg) 40 { 41 m_description = "PNG HSV colorscheme"; 42 _default_info(); 43 resize(cam.width(), cam.height()); 44 } 45 PNG_HSV(const int width, const int height, const std::string filename="hsv", const double saturation=1.0, const double value=1.0, const double bg=1.0) : 46 PhotoPaper(0,0,filename), m_open(false), m_png(nullptr), m_saturation(saturation), m_value(value), m_background(bg) 47 { 48 m_description = "PNG HSV colorscheme"; 49 _default_info(); 50 resize(width, height); 51 } 52 53 virtual ~PNG_HSV() 54 { 55 if (m_open) 56 { 57 m_png->close(); 58 _dispose(); 59 } 60 } 61 62 virtual void make_new(const std::string name, const int width, const int height); 63 virtual void resize(const int width, const int height); 64 virtual void write(); 65 virtual void set_pixel(const double phi, const int x, const int y); 66 virtual std::string suffix() const { return std::string(".png"); } 67 }; 68 69 class PNG_MONO : public PNG_HSV 70 { 71 public: 72 PNG_MONO(const std::string filename="mono") : PNG_HSV(filename) { m_description = "PNG MONO colorscheme"; } 73 PNG_MONO(const Polaroid& cam, const std::string filename="mono") : PNG_HSV(cam, filename) { m_description = "PNG MONO colorscheme"; } 74 PNG_MONO(const int width, const int height, const std::string filename="mono") : PNG_HSV(width, height, filename) { m_description = "PNG MONO colorscheme"; } 75 76 virtual void set_pixel(const double phi, const int x, const int y); 77 }; 78 79 class PNG_RGB : public PNG_HSV 80 { 81 PNG_RGB(const std::string filename="rgb") : PNG_HSV(filename) { m_description = "PNG RGB colorscheme"; } 82 PNG_RGB(const Polaroid& cam, const std::string filename="rgb") : PNG_HSV(cam, filename) { m_description = "PNG RGB colorscheme"; } 83 PNG_RGB(const int width, const int height, const std::string filename="rgb") : PNG_HSV(width, height, filename) { m_description = "PNG RGB colorscheme"; } 84 85 inline void set_pixel(const int x, const int y, const double R, const double G, const double B) 86 { 87 if (m_open) 88 m_png->plot(x+1, y+1, R, G, B); 89 } 90 }; 91 92 #endif /* PHOTOPNG_H_7DZT9TLW */