Pixel.h
1/* Copyright (C) 2015 Marc Boris Duerner
2
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License as published by the Free Software Foundation; either
6 version 2.1 of the License, or (at your option) any later version.
7
8 As a special exception, you may use this file as part of a free
9 software library without restriction. Specifically, if other files
10 instantiate templates or use macros or inline functions from this
11 file, or you compile this file and link it with other files to
12 produce an executable, this file does not by itself cause the
13 resulting executable to be covered by the GNU General Public
14 License. This exception does not however invalidate any other
15 reasons why the executable file might be covered by the GNU Library
16 General Public License.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 MA 02110-1301 USA
27*/
28
29#ifndef PT_GFX_PIXEL_H
30#define PT_GFX_PIXEL_H
31
32#include <Pt/Gfx/Api.h>
33#include <Pt/Gfx/ViewBase.h>
34#include <Pt/Types.h>
35
36#ifdef __cpp_concepts
37#include <concepts>
38#endif
39
40namespace Pt {
41
42namespace Gfx {
43
44#ifdef __cpp_concepts
45
57template <typename P>
58concept PixelLike = std::destructible<P> && requires {
59 typename P::FormatType;
60 typename P::ColorType;
61} && requires(P p, const P cp,
62 const typename P::ColorType& color,
63 typename P::ColorType* colors,
64 ViewBase& view,
65 Pt::ssize_t n, std::size_t len)
66{
67 P(cp);
68 P(view, n, n);
69
70 { p = color } -> std::same_as<P&>;
71
72 p.reset(cp);
73 p.reset(view, n, n);
74
75 { cp.view() } -> std::same_as<const ViewBase&>;
76 { cp.base() } -> std::same_as<const Pt::uint8_t*>;
77 { p.base() } -> std::same_as<Pt::uint8_t*>;
78
79 p.advance();
80 p.advance(n);
81 p.skipPadding();
82 p.advanceLines(n);
83
84 { cp.getColor() } -> std::same_as<typename P::ColorType>;
85 cp.getColors(colors, len);
86
87 p.assign(cp);
88 p.assign(cp, len);
89 p.assign(colors, len);
90
91 p.fill(len, color);
92
93 { cp.equals(cp) } -> std::same_as<bool>;
94};
95
105template <typename P>
106concept ConstPixelLike = std::destructible<P> && requires {
107 typename P::FormatType;
108 typename P::ColorType;
109} && requires(P p, const P cp,
110 typename P::ColorType* colors,
111 const ViewBase& cview, ViewBase& view,
112 Pt::ssize_t n, std::size_t len)
113{
114 P(cp);
115 P(cview, n, n);
116 P(view, n, n);
117
118 p.reset(cp);
119 p.reset(cview, n, n);
120 p.reset(view, n, n);
121
122 { cp.view() } -> std::same_as<const ViewBase&>;
123 { cp.base() } -> std::same_as<const Pt::uint8_t*>;
124
125 p.advance();
126 p.advance(n);
127 p.skipPadding();
128 p.advanceLines(n);
129
130 { cp.getColor() } -> std::same_as<typename P::ColorType>;
131 cp.getColors(colors, len);
132
133 { cp.equals(cp) } -> std::same_as<bool>;
134};
135
136#endif // __cpp_concepts
137
138
139template <typename T>
140typename T::Traits::Pixel pixel(T& source,
141 Pt::ssize_t x, Pt::ssize_t y)
142{
143 return typename T::Traits::Pixel(source, x, y);
144}
145
146
147template <typename T>
148typename T::Traits::ConstPixel pixel(const T& source,
149 Pt::ssize_t x, Pt::ssize_t y)
150{
151 return typename T::Traits::ConstPixel(source, x, y);
152}
153
154
155template <typename T>
156Pixel<ColorF> pixelF(T& source,
157 Pt::ssize_t x, Pt::ssize_t y)
158{
159 return Pixel<ColorF>(source, x, y);
160}
161
162
163template <typename T>
164ConstPixel<ColorF> pixelF(const T& source,
165 Pt::ssize_t x, Pt::ssize_t y)
166{
167 return ConstPixel<ColorF>(source, x, y);
168}
169
170} // namespace
171
172} // namespace
173
174#endif
Read-only cursor to one pixel.
Definition ImageFormat.h:345
Cursor to one pixel.
Definition ImageFormat.h:219
Width, height and stride of an image or view.
Definition ViewBase.h:50
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33