/work/prefix/include/QtGui/qpixelformat.h
Line | Count | Source (jump to first uncovered line) |
1 | | /**************************************************************************** |
2 | | ** |
3 | | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | | ** Contact: https://www.qt.io/licensing/ |
5 | | ** |
6 | | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | | ** |
8 | | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | | ** Commercial License Usage |
10 | | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | | ** accordance with the commercial license agreement provided with the |
12 | | ** Software or, alternatively, in accordance with the terms contained in |
13 | | ** a written agreement between you and The Qt Company. For licensing terms |
14 | | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | | ** information use the contact form at https://www.qt.io/contact-us. |
16 | | ** |
17 | | ** GNU Lesser General Public License Usage |
18 | | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | | ** General Public License version 3 as published by the Free Software |
20 | | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | | ** packaging of this file. Please review the following information to |
22 | | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | | ** |
25 | | ** GNU General Public License Usage |
26 | | ** Alternatively, this file may be used under the terms of the GNU |
27 | | ** General Public License version 2.0 or (at your option) the GNU General |
28 | | ** Public license version 3 or any later version approved by the KDE Free |
29 | | ** Qt Foundation. The licenses are as published by the Free Software |
30 | | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | | ** included in the packaging of this file. Please review the following |
32 | | ** information to ensure the GNU General Public License requirements will |
33 | | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | | ** |
36 | | ** $QT_END_LICENSE$ |
37 | | ** |
38 | | ****************************************************************************/ |
39 | | |
40 | | #ifndef QPIXELFORMAT_H |
41 | | #define QPIXELFORMAT_H |
42 | | |
43 | | #include <QtGui/qtguiglobal.h> |
44 | | |
45 | | QT_BEGIN_NAMESPACE |
46 | | |
47 | | class QPixelFormat |
48 | | { |
49 | | // QPixelFormat basically is a glorified quint64, split into several fields. |
50 | | // We could use bit-fields, but GCC at least generates horrible, horrible code for them, |
51 | | // so we do the bit-twiddling ourselves. |
52 | | enum FieldWidth { |
53 | | ModelFieldWidth = 4, |
54 | | FirstFieldWidth = 6, |
55 | | SecondFieldWidth = FirstFieldWidth, |
56 | | ThirdFieldWidth = FirstFieldWidth, |
57 | | FourthFieldWidth = FirstFieldWidth, |
58 | | FifthFieldWidth = FirstFieldWidth, |
59 | | AlphaFieldWidth = FirstFieldWidth, |
60 | | AlphaUsageFieldWidth = 1, |
61 | | AlphaPositionFieldWidth = 1, |
62 | | PremulFieldWidth = 1, |
63 | | TypeInterpretationFieldWidth = 4, |
64 | | ByteOrderFieldWidth = 2, |
65 | | SubEnumFieldWidth = 6, |
66 | | UnusedFieldWidth = 9, |
67 | | |
68 | | TotalFieldWidthByWidths = ModelFieldWidth + FirstFieldWidth + SecondFieldWidth + ThirdFieldWidth + |
69 | | FourthFieldWidth + FifthFieldWidth + AlphaFieldWidth + AlphaUsageFieldWidth + |
70 | | AlphaPositionFieldWidth + PremulFieldWidth + TypeInterpretationFieldWidth + |
71 | | ByteOrderFieldWidth + SubEnumFieldWidth + UnusedFieldWidth |
72 | | }; |
73 | | |
74 | | enum Field { |
75 | | ModelField = 0, |
76 | | // work around bug in old clang versions: when building webkit |
77 | | // with XCode 4.6 and older this fails compilation, thus cast to int |
78 | | FirstField = ModelField + int(ModelFieldWidth), |
79 | | SecondField = FirstField + int(FirstFieldWidth), |
80 | | ThirdField = SecondField + int(SecondFieldWidth), |
81 | | FourthField = ThirdField + int(ThirdFieldWidth), |
82 | | FifthField = FourthField + int(FourthFieldWidth), |
83 | | AlphaField = FifthField + int(FifthFieldWidth), |
84 | | AlphaUsageField = AlphaField + int(AlphaFieldWidth), |
85 | | AlphaPositionField = AlphaUsageField + int(AlphaUsageFieldWidth), |
86 | | PremulField = AlphaPositionField + int(AlphaPositionFieldWidth), |
87 | | TypeInterpretationField = PremulField + int(PremulFieldWidth), |
88 | | ByteOrderField = TypeInterpretationField + int(TypeInterpretationFieldWidth), |
89 | | SubEnumField = ByteOrderField + int(ByteOrderFieldWidth), |
90 | | UnusedField = SubEnumField + int(SubEnumFieldWidth), |
91 | | |
92 | | TotalFieldWidthByOffsets = UnusedField + int(UnusedFieldWidth) |
93 | | }; |
94 | | |
95 | | Q_STATIC_ASSERT(uint(TotalFieldWidthByWidths) == uint(TotalFieldWidthByOffsets)); |
96 | | Q_STATIC_ASSERT(uint(TotalFieldWidthByWidths) == 8 * sizeof(quint64)); |
97 | | |
98 | | Q_DECL_CONSTEXPR inline uchar get(Field offset, FieldWidth width) const noexcept |
99 | | { return uchar((data >> uint(offset)) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))); } |
100 | | Q_DECL_CONSTEXPR static inline quint64 set(Field offset, FieldWidth width, uchar value) |
101 | 0 | { return (quint64(value) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))) << uint(offset); } |
102 | | |
103 | | public: |
104 | | enum ColorModel { |
105 | | RGB, |
106 | | BGR, |
107 | | Indexed, |
108 | | Grayscale, |
109 | | CMYK, |
110 | | HSL, |
111 | | HSV, |
112 | | YUV, |
113 | | Alpha |
114 | | }; |
115 | | |
116 | | enum AlphaUsage { |
117 | | UsesAlpha, |
118 | | IgnoresAlpha |
119 | | }; |
120 | | |
121 | | enum AlphaPosition { |
122 | | AtBeginning, |
123 | | AtEnd |
124 | | }; |
125 | | |
126 | | enum AlphaPremultiplied { |
127 | | NotPremultiplied, |
128 | | Premultiplied |
129 | | }; |
130 | | |
131 | | enum TypeInterpretation { |
132 | | UnsignedInteger, |
133 | | UnsignedShort, |
134 | | UnsignedByte, |
135 | | FloatingPoint |
136 | | }; |
137 | | |
138 | | enum YUVLayout { |
139 | | YUV444, |
140 | | YUV422, |
141 | | YUV411, |
142 | | YUV420P, |
143 | | YUV420SP, |
144 | | YV12, |
145 | | UYVY, |
146 | | YUYV, |
147 | | NV12, |
148 | | NV21, |
149 | | IMC1, |
150 | | IMC2, |
151 | | IMC3, |
152 | | IMC4, |
153 | | Y8, |
154 | | Y16 |
155 | | }; |
156 | | |
157 | | enum ByteOrder { |
158 | | LittleEndian, |
159 | | BigEndian, |
160 | | CurrentSystemEndian |
161 | | }; |
162 | | |
163 | 0 | Q_DECL_CONSTEXPR inline QPixelFormat() noexcept : data(0) {} |
164 | | Q_DECL_CONSTEXPR inline QPixelFormat(ColorModel colorModel, |
165 | | uchar firstSize, |
166 | | uchar secondSize, |
167 | | uchar thirdSize, |
168 | | uchar fourthSize, |
169 | | uchar fifthSize, |
170 | | uchar alphaSize, |
171 | | AlphaUsage alphaUsage, |
172 | | AlphaPosition alphaPosition, |
173 | | AlphaPremultiplied premultiplied, |
174 | | TypeInterpretation typeInterpretation, |
175 | | ByteOrder byteOrder = CurrentSystemEndian, |
176 | | uchar subEnum = 0) noexcept; |
177 | | |
178 | | Q_DECL_CONSTEXPR inline ColorModel colorModel() const noexcept { return ColorModel(get(ModelField, ModelFieldWidth)); } |
179 | 0 | Q_DECL_CONSTEXPR inline uchar channelCount() const noexcept { return (get(FirstField, FirstFieldWidth) > 0) + |
180 | 0 | (get(SecondField, SecondFieldWidth) > 0) + |
181 | 0 | (get(ThirdField, ThirdFieldWidth) > 0) + |
182 | 0 | (get(FourthField, FourthFieldWidth) > 0) + |
183 | 0 | (get(FifthField, FifthFieldWidth) > 0) + |
184 | 0 | (get(AlphaField, AlphaFieldWidth) > 0); } |
185 | | |
186 | 0 | Q_DECL_CONSTEXPR inline uchar redSize() const noexcept { return get(FirstField, FirstFieldWidth); } |
187 | 0 | Q_DECL_CONSTEXPR inline uchar greenSize() const noexcept { return get(SecondField, SecondFieldWidth); } |
188 | 0 | Q_DECL_CONSTEXPR inline uchar blueSize() const noexcept { return get(ThirdField, ThirdFieldWidth); } |
189 | | |
190 | 0 | Q_DECL_CONSTEXPR inline uchar cyanSize() const noexcept { return get(FirstField, FirstFieldWidth); } |
191 | 0 | Q_DECL_CONSTEXPR inline uchar magentaSize() const noexcept { return get(SecondField, SecondFieldWidth); } |
192 | 0 | Q_DECL_CONSTEXPR inline uchar yellowSize() const noexcept { return get(ThirdField, ThirdFieldWidth); } |
193 | 0 | Q_DECL_CONSTEXPR inline uchar blackSize() const noexcept { return get(FourthField, FourthFieldWidth); } |
194 | | |
195 | 0 | Q_DECL_CONSTEXPR inline uchar hueSize() const noexcept { return get(FirstField, FirstFieldWidth); } |
196 | 0 | Q_DECL_CONSTEXPR inline uchar saturationSize() const noexcept { return get(SecondField, SecondFieldWidth); } |
197 | 0 | Q_DECL_CONSTEXPR inline uchar lightnessSize() const noexcept { return get(ThirdField, ThirdFieldWidth); } |
198 | 0 | Q_DECL_CONSTEXPR inline uchar brightnessSize() const noexcept { return get(ThirdField, ThirdFieldWidth); } |
199 | | |
200 | 0 | Q_DECL_CONSTEXPR inline uchar alphaSize() const noexcept { return get(AlphaField, AlphaFieldWidth); } |
201 | | |
202 | 0 | Q_DECL_CONSTEXPR inline uchar bitsPerPixel() const noexcept { return get(FirstField, FirstFieldWidth) + |
203 | 0 | get(SecondField, SecondFieldWidth) + |
204 | 0 | get(ThirdField, ThirdFieldWidth) + |
205 | 0 | get(FourthField, FourthFieldWidth) + |
206 | 0 | get(FifthField, FifthFieldWidth) + |
207 | 0 | get(AlphaField, AlphaFieldWidth); } |
208 | | |
209 | | Q_DECL_CONSTEXPR inline AlphaUsage alphaUsage() const noexcept { return AlphaUsage(get(AlphaUsageField, AlphaUsageFieldWidth)); } |
210 | 0 | Q_DECL_CONSTEXPR inline AlphaPosition alphaPosition() const noexcept { return AlphaPosition(get(AlphaPositionField, AlphaPositionFieldWidth)); } |
211 | 0 | Q_DECL_CONSTEXPR inline AlphaPremultiplied premultiplied() const noexcept { return AlphaPremultiplied(get(PremulField, PremulFieldWidth)); } |
212 | 0 | Q_DECL_CONSTEXPR inline TypeInterpretation typeInterpretation() const noexcept { return TypeInterpretation(get(TypeInterpretationField, TypeInterpretationFieldWidth)); } |
213 | 0 | Q_DECL_CONSTEXPR inline ByteOrder byteOrder() const noexcept { return ByteOrder(get(ByteOrderField, ByteOrderFieldWidth)); } |
214 | | |
215 | 0 | Q_DECL_CONSTEXPR inline YUVLayout yuvLayout() const noexcept { return YUVLayout(get(SubEnumField, SubEnumFieldWidth)); } |
216 | 0 | Q_DECL_CONSTEXPR inline uchar subEnum() const noexcept { return get(SubEnumField, SubEnumFieldWidth); } |
217 | | |
218 | | private: |
219 | | Q_DECL_CONSTEXPR static inline ByteOrder resolveByteOrder(ByteOrder bo) |
220 | 0 | { return bo == CurrentSystemEndian ? Q_BYTE_ORDER == Q_LITTLE_ENDIAN ? LittleEndian : BigEndian : bo ; } |
221 | | |
222 | | private: |
223 | | quint64 data; |
224 | | |
225 | | friend Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline bool operator==(QPixelFormat fmt1, QPixelFormat fmt2) |
226 | | { return fmt1.data == fmt2.data; } |
227 | | |
228 | | friend Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline bool operator!=(QPixelFormat fmt1, QPixelFormat fmt2) |
229 | 0 | { return !(fmt1 == fmt2); } |
230 | | }; |
231 | | Q_STATIC_ASSERT(sizeof(QPixelFormat) == sizeof(quint64)); |
232 | | Q_DECLARE_TYPEINFO(QPixelFormat, Q_PRIMITIVE_TYPE); |
233 | | |
234 | | |
235 | | namespace QtPrivate { |
236 | | QPixelFormat Q_GUI_EXPORT QPixelFormat_createYUV(QPixelFormat::YUVLayout yuvLayout, |
237 | | uchar alphaSize, |
238 | | QPixelFormat::AlphaUsage alphaUsage, |
239 | | QPixelFormat::AlphaPosition alphaPosition, |
240 | | QPixelFormat::AlphaPremultiplied premultiplied, |
241 | | QPixelFormat::TypeInterpretation typeInterpretation, |
242 | | QPixelFormat::ByteOrder byteOrder); |
243 | | } |
244 | | |
245 | | Q_DECL_CONSTEXPR |
246 | | QPixelFormat::QPixelFormat(ColorModel mdl, |
247 | | uchar firstSize, |
248 | | uchar secondSize, |
249 | | uchar thirdSize, |
250 | | uchar fourthSize, |
251 | | uchar fifthSize, |
252 | | uchar alfa, |
253 | | AlphaUsage usage, |
254 | | AlphaPosition position, |
255 | | AlphaPremultiplied premult, |
256 | | TypeInterpretation typeInterp, |
257 | | ByteOrder b_order, |
258 | | uchar s_enum) noexcept |
259 | | : data(set(ModelField, ModelFieldWidth, uchar(mdl)) | |
260 | | set(FirstField, FirstFieldWidth, firstSize) | |
261 | | set(SecondField, SecondFieldWidth, secondSize) | |
262 | | set(ThirdField, ThirdFieldWidth, thirdSize) | |
263 | | set(FourthField, FourthFieldWidth, fourthSize) | |
264 | | set(FifthField, FifthFieldWidth, fifthSize) | |
265 | | set(AlphaField, AlphaFieldWidth, alfa) | |
266 | | set(AlphaUsageField, AlphaUsageFieldWidth, uchar(usage)) | |
267 | | set(AlphaPositionField, AlphaPositionFieldWidth, uchar(position)) | |
268 | | set(PremulField, PremulFieldWidth, uchar(premult)) | |
269 | | set(TypeInterpretationField, TypeInterpretationFieldWidth, uchar(typeInterp)) | |
270 | | set(ByteOrderField, ByteOrderFieldWidth, uchar(resolveByteOrder(b_order))) | |
271 | | set(SubEnumField, SubEnumFieldWidth, s_enum) | |
272 | | set(UnusedField, UnusedFieldWidth, 0)) |
273 | | { |
274 | | } |
275 | | |
276 | | Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatRgba(uchar red, |
277 | | uchar green, |
278 | | uchar blue, |
279 | | uchar alfa, |
280 | | QPixelFormat::AlphaUsage usage, |
281 | | QPixelFormat::AlphaPosition position, |
282 | | QPixelFormat::AlphaPremultiplied pmul=QPixelFormat::NotPremultiplied, |
283 | | QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept |
284 | 0 | { |
285 | 0 | return QPixelFormat(QPixelFormat::RGB, |
286 | 0 | red, |
287 | 0 | green, |
288 | 0 | blue, |
289 | 0 | 0, |
290 | 0 | 0, |
291 | 0 | alfa, |
292 | 0 | usage, |
293 | 0 | position, |
294 | 0 | pmul, |
295 | 0 | typeInt); |
296 | 0 | } |
297 | | |
298 | | Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatGrayscale(uchar channelSize, |
299 | | QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept |
300 | 0 | { |
301 | 0 | return QPixelFormat(QPixelFormat::Grayscale, |
302 | 0 | channelSize, |
303 | 0 | 0, |
304 | 0 | 0, |
305 | 0 | 0, |
306 | 0 | 0, |
307 | 0 | 0, |
308 | 0 | QPixelFormat::IgnoresAlpha, |
309 | 0 | QPixelFormat::AtBeginning, |
310 | 0 | QPixelFormat::NotPremultiplied, |
311 | 0 | typeInt); |
312 | 0 | } |
313 | | |
314 | | Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatAlpha(uchar channelSize, |
315 | | QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept |
316 | 0 | { |
317 | 0 | return QPixelFormat(QPixelFormat::Alpha, |
318 | 0 | 0, |
319 | 0 | 0, |
320 | 0 | 0, |
321 | 0 | 0, |
322 | 0 | 0, |
323 | 0 | channelSize, |
324 | 0 | QPixelFormat::UsesAlpha, |
325 | 0 | QPixelFormat::AtBeginning, |
326 | 0 | QPixelFormat::NotPremultiplied, |
327 | 0 | typeInt); |
328 | 0 | } |
329 | | |
330 | | Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatCmyk(uchar channelSize, |
331 | | uchar alfa=0, |
332 | | QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha, |
333 | | QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning, |
334 | | QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept |
335 | 0 | { |
336 | 0 | return QPixelFormat(QPixelFormat::CMYK, |
337 | 0 | channelSize, |
338 | 0 | channelSize, |
339 | 0 | channelSize, |
340 | 0 | channelSize, |
341 | 0 | 0, |
342 | 0 | alfa, |
343 | 0 | usage, |
344 | 0 | position, |
345 | 0 | QPixelFormat::NotPremultiplied, |
346 | 0 | typeInt); |
347 | 0 | } |
348 | | |
349 | | Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatHsl(uchar channelSize, |
350 | | uchar alfa=0, |
351 | | QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha, |
352 | | QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning, |
353 | | QPixelFormat::TypeInterpretation typeInt=QPixelFormat::FloatingPoint) noexcept |
354 | 0 | { |
355 | 0 | return QPixelFormat(QPixelFormat::HSL, |
356 | 0 | channelSize, |
357 | 0 | channelSize, |
358 | 0 | channelSize, |
359 | 0 | 0, |
360 | 0 | 0, |
361 | 0 | alfa, |
362 | 0 | usage, |
363 | 0 | position, |
364 | 0 | QPixelFormat::NotPremultiplied, |
365 | 0 | typeInt); |
366 | 0 | } |
367 | | |
368 | | Q_DECL_CONSTEXPR inline QPixelFormat qPixelFormatHsv(uchar channelSize, |
369 | | uchar alfa=0, |
370 | | QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha, |
371 | | QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning, |
372 | | QPixelFormat::TypeInterpretation typeInt=QPixelFormat::FloatingPoint) noexcept |
373 | 0 | { |
374 | 0 | return QPixelFormat(QPixelFormat::HSV, |
375 | 0 | channelSize, |
376 | 0 | channelSize, |
377 | 0 | channelSize, |
378 | 0 | 0, |
379 | 0 | 0, |
380 | 0 | alfa, |
381 | 0 | usage, |
382 | 0 | position, |
383 | 0 | QPixelFormat::NotPremultiplied, |
384 | 0 | typeInt); |
385 | 0 | } |
386 | | |
387 | | inline QPixelFormat qPixelFormatYuv(QPixelFormat::YUVLayout layout, |
388 | | uchar alfa=0, |
389 | | QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha, |
390 | | QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning, |
391 | | QPixelFormat::AlphaPremultiplied p_mul=QPixelFormat::NotPremultiplied, |
392 | | QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedByte, |
393 | | QPixelFormat::ByteOrder b_order=QPixelFormat::LittleEndian) |
394 | 0 | { |
395 | 0 | return QtPrivate::QPixelFormat_createYUV(layout, |
396 | 0 | alfa, |
397 | 0 | usage, |
398 | 0 | position, |
399 | 0 | p_mul, |
400 | 0 | typeInt, |
401 | 0 | b_order); |
402 | 0 | } |
403 | | |
404 | | QT_END_NAMESPACE |
405 | | |
406 | | #endif //QPIXELFORMAT_H |