ImageFormat.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_IMAGEFORMAT_H
31 #define PT_GFX_IMAGEFORMAT_H
32 
33 #include <Pt/Gfx/Api.h>
34 #include <Pt/Gfx/Color.h>
35 #include <Pt/Gfx/Point.h>
36 #include <Pt/Gfx/Rect.h>
37 #include <Pt/Gfx/CompositionMode.h>
38 
39 namespace Pt {
40 
41 namespace Gfx {
42 
43 class Pixel;
44 class ConstPixel;
45 class ImageView;
46 
50 {
51  public:
52  ImageFormat(size_t pixelStride)
53  : _pixelStride(pixelStride)
54  { }
55 
56  virtual ~ImageFormat()
57  {}
58 
61  std::size_t pixelStride() const
62  {
63  return _pixelStride;
64  }
65 
66  bool operator==(const ImageFormat& a) const
67  {
68  return _pixelStride == a._pixelStride;
69  }
70 
71  bool operator!=(const ImageFormat& a) const
72  {
73  return _pixelStride != a._pixelStride;
74  }
75 
76  PT_GFX_API static const ImageFormat& rgb16();
77 
78  PT_GFX_API static const ImageFormat& rgb32();
79 
80  PT_GFX_API static const ImageFormat& argb32();
81 
82  public:
85  void setPixel(Pixel& to, const Pixel& from,
86  CompositionMode mode) const
87  { onSetPixel(to, from, mode); }
88 
91  void setPixel(Pixel& to, const ConstPixel& from,
92  CompositionMode mode) const
93  { onSetPixel(to, from, mode); }
94 
97  void setPixel(Pixel& to, const Color& c,
98  CompositionMode mode) const
99  { onSetPixel(to, c, mode); }
100 
103  void setPixel(Pixel& to, const Pixel& from,
104  CompositionMode mode, Pt::uint8_t blendingAlpha) const
105  { onSetPixel(to, from, mode, blendingAlpha); }
106 
109  void setPixel(Pixel& to, const ConstPixel& from,
110  CompositionMode mode, Pt::uint8_t blendingAlpha) const
111  { onSetPixel(to, from, mode, blendingAlpha); }
112 
115  void setPixel(Pixel& to, const Color& c,
116  CompositionMode mode, Pt::uint8_t blendingAlpha) const
117  { onSetPixel(to, c, mode, blendingAlpha); }
118 
121  void setPixels(Pixel& to, const Pixel& from, size_t length,
122  CompositionMode mode) const
123  { onSetPixels(to, from, length, mode); }
124 
127  void setPixels(Pixel& to, const ConstPixel& from, size_t length,
128  CompositionMode mode) const
129  { onSetPixels(to, from, length, mode); }
130 
133  void setPixels(Pixel& to, const Color& c, size_t length,
134  CompositionMode mode) const
135  { onSetPixels(to, c, length, mode); }
136 
139  Color getColor(const Pixel& pixel) const
140  { return onGetColor(pixel); }
141 
144  Color getColor(const ConstPixel& pixel) const
145  { return onGetColor(pixel); }
146 
149  void copy(Pixel& dst, const Pixel& src, size_t length,
150  CompositionMode mode) const
151  { onCopy(dst, src, length, mode); }
152 
155  void copy(Pixel& dst, const ConstPixel& src, size_t length,
156  CompositionMode mode) const
157  { onCopy(dst, src, length, mode); }
158 
161  PT_GFX_API void copy(ImageView& to, const Point& toPoint,
162  const ImageView& from, const Rect& fromRect,
163  CompositionMode mode) const;
164 
167  std::size_t imageSize(const Size& size, Pt::ssize_t padding) const
168  { return onImageSize(size, padding); }
169 
170  protected:
171  virtual void onSetPixel(Pixel& to, const Pixel& from,
172  CompositionMode mode) const = 0;
173 
174  virtual void onSetPixel(Pixel& to, const ConstPixel& from,
175  CompositionMode mode) const = 0;
176 
177  virtual void onSetPixel(Pixel& pixel, const Color& c,
178  CompositionMode mode) const = 0;
179 
180  virtual void onSetPixel(Pixel& to, const Pixel& from,
181  CompositionMode mode, Pt::uint8_t blendingAlpha) const = 0;
182 
183  virtual void onSetPixel(Pixel& to, const ConstPixel& from,
184  CompositionMode mode, Pt::uint8_t blendingAlpha) const = 0;
185 
186  virtual void onSetPixel(Pixel& pixel, const Color& c,
187  CompositionMode mode, Pt::uint8_t blendingAlpha) const = 0;
188 
189  virtual void onSetPixels(Pixel& to, const Pixel& from, size_t length,
190  CompositionMode mode) const = 0;
191 
192  virtual void onSetPixels(Pixel& to, const ConstPixel& from, size_t length,
193  CompositionMode mode) const = 0;
194 
195  virtual void onSetPixels(Pixel& pixel, const Color& c, size_t length,
196  CompositionMode mode) const = 0;
197 
198  virtual Color onGetColor(const Pixel& pixel) const = 0;
199 
200  virtual Color onGetColor(const ConstPixel& pixel) const = 0;
201 
202  virtual void onCopy(Pixel& dst, const Pixel& src, size_t length,
203  CompositionMode mode) const = 0;
204 
205  virtual void onCopy(Pixel& dst, const ConstPixel& src, size_t length,
206  CompositionMode mode) const = 0;
207 
208  virtual void onCopy(ImageView& to, const Point& toPos,
209  const ImageView& from, const Rect& fromRect,
210  CompositionMode mode) const = 0;
211 
212  virtual std::size_t onImageSize(const Size& size, Pt::ssize_t padding) const = 0;
213 
214  private:
215  std::size_t _pixelStride;
216 };
217 
218 } // namespace
219 
220 } // namespace
221 
222 #endif
void setPixel(Pixel &to, const Color &c, CompositionMode mode) const
Sets the pixel color.
Definition: ImageFormat.h:97
Point with X ynd X coordinates.
Definition: Point.h:45
void setPixel(Pixel &to, const Pixel &from, CompositionMode mode, Pt::uint8_t blendingAlpha) const
Sets the pixel color with additional blending alhpa.
Definition: ImageFormat.h:103
void setPixels(Pixel &to, const ConstPixel &from, size_t length, CompositionMode mode) const
Sets the pixels color.
Definition: ImageFormat.h:127
void setPixels(Pixel &to, const Color &c, size_t length, CompositionMode mode) const
Sets the pixels color.
Definition: ImageFormat.h:133
std::size_t pixelStride() const
Returns distance in bytes between two pixel base pointers.
Definition: ImageFormat.h:61
Color getColor(const Pixel &pixel) const
Gets the pixel color.
Definition: ImageFormat.h:139
void setPixel(Pixel &to, const ConstPixel &from, CompositionMode mode) const
Sets the pixel color.
Definition: ImageFormat.h:91
View on image data.
Definition: ImageView.h:192
void setPixel(Pixel &to, const Color &c, CompositionMode mode, Pt::uint8_t blendingAlpha) const
Sets the pixel color with additional blending alhpa.
Definition: ImageFormat.h:115
Pixel in an image.
Definition: ImageView.h:48
std::size_t imageSize(const Size &size, Pt::ssize_t padding) const
Returns the size in bytes for a given image size.
Definition: ImageFormat.h:167
void copy(Pixel &dst, const Pixel &src, size_t length, CompositionMode mode) const
Sets the color in a pixel span.
Definition: ImageFormat.h:149
void setPixels(Pixel &to, const Pixel &from, size_t length, CompositionMode mode) const
Sets the pixels color.
Definition: ImageFormat.h:121
Const pixel in an image.
Definition: ImageView.h:135
void setPixel(Pixel &to, const Pixel &from, CompositionMode mode) const
Sets the pixel color.
Definition: ImageFormat.h:85
void copy(Pixel &dst, const ConstPixel &src, size_t length, CompositionMode mode) const
Sets the color in a pixel span.
Definition: ImageFormat.h:155
Image format.
Definition: ImageFormat.h:49
uint_type uint8_t
Unsigned 8-bit integer type.
Definition: Types.h:18
Color getColor(const ConstPixel &pixel) const
Gets the pixel color.
Definition: ImageFormat.h:144
void setPixel(Pixel &to, const ConstPixel &from, CompositionMode mode, Pt::uint8_t blendingAlpha) const
Sets the pixel color with additional blending alhpa.
Definition: ImageFormat.h:109