Image.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27  02110-1301 USA
28 */
29 
30 #ifndef PT_GFX_IMAGE_H
31 #define PT_GFX_IMAGE_H
32 
33 #include <Pt/Gfx/Api.h>
34 #include <Pt/Gfx/ImageView.h>
35 #include <vector>
36 
37 namespace Pt {
38 
39 namespace Gfx {
40 
43 class PT_GFX_API Image
44 {
45  public:
46  typedef ImageView::Pixel Pixel;
48  typedef ImageView::PixelIterator PixelIterator;
49  typedef ImageView::ConstPixelIterator ConstPixelIterator;
50 
51  public:
52  Image();
53 
54  Image(const ImageFormat& format, const Size& size,
55  size_t padding = 0);
56 
57  Image(const ImageFormat& format, Pt::uint8_t* buffer,
58  const Size& size, size_t padding = 0);
59 
60  Image(const Image& image);
61 
62  virtual ~Image();
63 
64  const Image& operator=(const Image& image);
65 
66  void reset(const ImageFormat& format,
67  const Size& size, Pt::ssize_t padding = 0);
68 
69  void reset(const ImageFormat& format, Pt::uint8_t* data,
70  const Size& size, Pt::ssize_t padding = 0);
71 
72  PixelIterator pixel(Pt::ssize_t x, Pt::ssize_t y)
73  { return PixelIterator(view(), x, y); }
74 
75  PixelIterator begin()
76  { return PixelIterator(view(), 0, 0); }
77 
78  PixelIterator end()
79  { return PixelIterator(view(), 0, height()); }
80 
81  ConstPixelIterator pixel(Pt::ssize_t x, Pt::ssize_t y) const
82  { return ConstPixelIterator(view(), x, y); }
83 
84  ConstPixelIterator begin() const
85  { return ConstPixelIterator(view(), 0, 0); }
86 
87  ConstPixelIterator end() const
88  { return ConstPixelIterator(view(), 0, height()); }
89 
92  const ImageView& view() const
93  {
94  return _view;
95  }
96 
100  {
101  return _view;
102  }
103 
106  const ImageFormat& format() const
107  {
108  return _view.format();
109  }
110 
113  const Size& size() const
114  {
115  return _view.size();
116  }
117 
118  Pt::ssize_t width() const
119  {
120  return _view.width();
121  }
122 
123  Pt::ssize_t height() const
124  {
125  return _view.height();
126  }
127 
128  Pt::ssize_t padding() const
129  {
130  return _view.padding();
131  }
132 
133  Pt::uint8_t* data()
134  {
135  return _view.data();
136  }
137 
138  const Pt::uint8_t* data() const
139  {
140  return _view.data();
141  }
142 
143  bool empty() const
144  {
145  return _view.empty();
146  }
147 
148  private:
149  std::vector<Pt::uint8_t> _buffer;
150  ImageView _view;
151 };
152 
153 } // namespace
154 
155 } // namespace
156 
157 #endif
T width() const
Returns the width.
Definition: Size.h:65
ImageView & view()
Returns a view on the image data.
Definition: Image.h:99
View on image data.
Definition: ImageView.h:192
Pixel in an image.
Definition: ImageView.h:48
const Size & size() const
Returns the size of the image.
Definition: Image.h:113
const ImageFormat & format() const
Returns the format of the image.
Definition: Image.h:106
Const pixel in an image.
Definition: ImageView.h:135
Image format.
Definition: ImageFormat.h:49
uint_type uint8_t
Unsigned 8-bit integer type.
Definition: Types.h:18
const ImageView & view() const
Returns a view on the image data.
Definition: Image.h:92
Generic image.
Definition: Image.h:43