The spica renderer
image.h
1 #ifdef _MSC_VER
2 #pragma once
3 #endif
4 
5 #ifndef SPICA_IMAGE_H
6 #define SPICA_IMAGE_H
7 
8 #include <string>
9 #include <memory>
10 
11 #include "spectrum.h"
12 
13 namespace spica {
14 
18 class SPICA_EXPORTS Image {
19 public:
20  Image();
21  Image(int width, int height);
22  Image(const Image& image);
23  Image(Image&& image);
24 
25  virtual ~Image();
26 
27  Image& operator=(const Image& image);
28  Image& operator=(Image&& image);
29 
30  static Image fromFile(const std::string& filename);
31 
32  const RGBSpectrum& operator()(int x, int y) const;
33  RGBSpectrum& pixel(int x, int y);
34 
35  void resize(const int width, const int height);
36  void fill(const RGBSpectrum& color);
37 
38  void load(const std::string& filename);
39  void save(const std::string& filename) const;
40 
41  inline int width() const { return width_; }
42  inline int height() const { return height_; }
43 
44 protected:
51  virtual void postSaveEvent() const {}
52 
53 private:
54  void swap(Image &image);
55  static double toReal(uint8_t b);
56  static uint8_t toByte(double d);
57 
58  void loadBmp(const std::string& filename);
59  void saveBmp(const std::string& filename) const;
60 
61  void loadHdr(const std::string& filename);
62  void saveHdr(const std::string& filename) const;
63 
64  void loadPng(const std::string& filename);
65  void savePng(const std::string& filename) const;
66 
67 private:
68  int width_ = 0;
69  int height_ = 0;
70  std::unique_ptr<RGBSpectrum[]> pixels_ = nullptr;
71 };
72 
73 } // namespace spica
74 
75 #endif // SPICA_IMAGE_H
RGB spectrum.
Definition: spectrum.h:18
virtual void postSaveEvent() const
Post save event.
Definition: image.h:51
Image class.
Definition: image.h:18