comparison Core/FileFormats/PngReader.h @ 797:37adac56017a

ImageAccessor abstraction
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 06 May 2014 12:47:26 +0200
parents c87a1d529e13
children e1d27ee2114a
comparison
equal deleted inserted replaced
796:e7b1ca0f1e04 797:37adac56017a
38 #include <stdint.h> 38 #include <stdint.h>
39 #include <boost/shared_ptr.hpp> 39 #include <boost/shared_ptr.hpp>
40 40
41 namespace Orthanc 41 namespace Orthanc
42 { 42 {
43 class PngReader 43 class ImageAccessor
44 { 44 {
45 private: 45 private:
46 struct PngRabi; 46 bool readOnly_;
47
48 PixelFormat format_; 47 PixelFormat format_;
49 unsigned int width_; 48 unsigned int width_;
50 unsigned int height_; 49 unsigned int height_;
51 unsigned int pitch_; 50 unsigned int pitch_;
52 std::vector<uint8_t> buffer_; 51 void *buffer_;
53
54 void CheckHeader(const void* header);
55
56 void Read(PngRabi& rabi);
57 52
58 public: 53 public:
59 PngReader(); 54 ImageAccessor()
55 {
56 AssignEmpty(PixelFormat_Grayscale8);
57 }
58
59 bool IsReadOnly() const
60 {
61 return readOnly_;
62 }
60 63
61 PixelFormat GetFormat() const 64 PixelFormat GetFormat() const
62 { 65 {
63 return format_; 66 return format_;
64 } 67 }
76 unsigned int GetPitch() const 79 unsigned int GetPitch() const
77 { 80 {
78 return pitch_; 81 return pitch_;
79 } 82 }
80 83
81 const void* GetBuffer() const 84 const void* GetConstBuffer() const
82 { 85 {
83 if (buffer_.size() > 0) 86 return buffer_;
84 return &buffer_[0];
85 else
86 return NULL;
87 } 87 }
88 88
89 const void* GetBuffer(unsigned int y) const 89 void* GetBuffer();
90 { 90
91 if (buffer_.size() > 0) 91 const void* GetConstRow(unsigned int y) const;
92 return &buffer_[y * pitch_]; 92
93 else 93 void* GetRow(unsigned int y);
94 return NULL; 94
95 } 95 void AssignEmpty(PixelFormat format);
96
97 void AssignReadOnly(PixelFormat format,
98 unsigned int width,
99 unsigned int height,
100 unsigned int pitch,
101 const void *buffer);
102
103 void AssignWritable(PixelFormat format,
104 unsigned int width,
105 unsigned int height,
106 unsigned int pitch,
107 void *buffer);
108 };
109
110
111 class PngReader : public ImageAccessor
112 {
113 private:
114 struct PngRabi;
115
116 std::vector<uint8_t> data_;
117
118 void CheckHeader(const void* header);
119
120 void Read(PngRabi& rabi);
121
122 public:
123 PngReader();
96 124
97 void ReadFromFile(const char* filename); 125 void ReadFromFile(const char* filename);
98 126
99 void ReadFromFile(const std::string& filename) 127 void ReadFromFile(const std::string& filename)
100 { 128 {