Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qpixelformat.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPIXELFORMAT_H
5#define QPIXELFORMAT_H
6
7#include <QtGui/qtguiglobal.h>
8
10
12{
13 // QPixelFormat basically is a glorified quint64, split into several fields.
14 // We could use bit-fields, but GCC at least generates horrible, horrible code for them,
15 // so we do the bit-twiddling ourselves.
16 enum FieldWidth {
17 ModelFieldWidth = 4,
18 FirstFieldWidth = 6,
19 SecondFieldWidth = FirstFieldWidth,
20 ThirdFieldWidth = FirstFieldWidth,
21 FourthFieldWidth = FirstFieldWidth,
22 FifthFieldWidth = FirstFieldWidth,
23 AlphaFieldWidth = FirstFieldWidth,
24 AlphaUsageFieldWidth = 1,
25 AlphaPositionFieldWidth = 1,
26 PremulFieldWidth = 1,
27 TypeInterpretationFieldWidth = 4,
28 ByteOrderFieldWidth = 2,
29 SubEnumFieldWidth = 6,
30 UnusedFieldWidth = 9,
31
32 TotalFieldWidthByWidths = ModelFieldWidth + FirstFieldWidth + SecondFieldWidth + ThirdFieldWidth +
33 FourthFieldWidth + FifthFieldWidth + AlphaFieldWidth + AlphaUsageFieldWidth +
34 AlphaPositionFieldWidth + PremulFieldWidth + TypeInterpretationFieldWidth +
35 ByteOrderFieldWidth + SubEnumFieldWidth + UnusedFieldWidth
36 };
37
38 enum Field {
39 ModelField = 0,
40 // work around bug in old clang versions: when building webkit
41 // with XCode 4.6 and older this fails compilation, thus cast to int
42 FirstField = ModelField + int(ModelFieldWidth),
43 SecondField = FirstField + int(FirstFieldWidth),
44 ThirdField = SecondField + int(SecondFieldWidth),
45 FourthField = ThirdField + int(ThirdFieldWidth),
46 FifthField = FourthField + int(FourthFieldWidth),
47 AlphaField = FifthField + int(FifthFieldWidth),
48 AlphaUsageField = AlphaField + int(AlphaFieldWidth),
49 AlphaPositionField = AlphaUsageField + int(AlphaUsageFieldWidth),
50 PremulField = AlphaPositionField + int(AlphaPositionFieldWidth),
51 TypeInterpretationField = PremulField + int(PremulFieldWidth),
52 ByteOrderField = TypeInterpretationField + int(TypeInterpretationFieldWidth),
53 SubEnumField = ByteOrderField + int(ByteOrderFieldWidth),
54 UnusedField = SubEnumField + int(SubEnumFieldWidth),
55
56 TotalFieldWidthByOffsets = UnusedField + int(UnusedFieldWidth)
57 };
58
59 static_assert(uint(TotalFieldWidthByWidths) == uint(TotalFieldWidthByOffsets));
60 static_assert(uint(TotalFieldWidthByWidths) == 8 * sizeof(quint64));
61
62 constexpr inline uchar get(Field offset, FieldWidth width) const noexcept
63 { return uchar((data >> uint(offset)) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))); }
64 constexpr static inline quint64 set(Field offset, FieldWidth width, uchar value)
65 { return (quint64(value) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))) << uint(offset); }
66
67public:
79
84
89
94
101
120
126
127 constexpr inline QPixelFormat() noexcept : data(0) {}
128 constexpr inline QPixelFormat(ColorModel colorModel,
129 uchar firstSize,
130 uchar secondSize,
131 uchar thirdSize,
132 uchar fourthSize,
133 uchar fifthSize,
140 uchar subEnum = 0) noexcept;
141
142 constexpr inline ColorModel colorModel() const noexcept { return ColorModel(get(ModelField, ModelFieldWidth)); }
143 constexpr inline uchar channelCount() const noexcept { return (get(FirstField, FirstFieldWidth) > 0) +
144 (get(SecondField, SecondFieldWidth) > 0) +
145 (get(ThirdField, ThirdFieldWidth) > 0) +
146 (get(FourthField, FourthFieldWidth) > 0) +
147 (get(FifthField, FifthFieldWidth) > 0) +
148 (get(AlphaField, AlphaFieldWidth) > 0); }
149
150 constexpr inline uchar redSize() const noexcept { return get(FirstField, FirstFieldWidth); }
151 constexpr inline uchar greenSize() const noexcept { return get(SecondField, SecondFieldWidth); }
152 constexpr inline uchar blueSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
153
154 constexpr inline uchar cyanSize() const noexcept { return get(FirstField, FirstFieldWidth); }
155 constexpr inline uchar magentaSize() const noexcept { return get(SecondField, SecondFieldWidth); }
156 constexpr inline uchar yellowSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
157 constexpr inline uchar blackSize() const noexcept { return get(FourthField, FourthFieldWidth); }
158
159 constexpr inline uchar hueSize() const noexcept { return get(FirstField, FirstFieldWidth); }
160 constexpr inline uchar saturationSize() const noexcept { return get(SecondField, SecondFieldWidth); }
161 constexpr inline uchar lightnessSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
162 constexpr inline uchar brightnessSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
163
164 constexpr inline uchar alphaSize() const noexcept { return get(AlphaField, AlphaFieldWidth); }
165
166 constexpr inline uchar bitsPerPixel() const noexcept { return get(FirstField, FirstFieldWidth) +
167 get(SecondField, SecondFieldWidth) +
168 get(ThirdField, ThirdFieldWidth) +
169 get(FourthField, FourthFieldWidth) +
170 get(FifthField, FifthFieldWidth) +
171 get(AlphaField, AlphaFieldWidth); }
172
173 constexpr inline AlphaUsage alphaUsage() const noexcept { return AlphaUsage(get(AlphaUsageField, AlphaUsageFieldWidth)); }
174 constexpr inline AlphaPosition alphaPosition() const noexcept { return AlphaPosition(get(AlphaPositionField, AlphaPositionFieldWidth)); }
175 constexpr inline AlphaPremultiplied premultiplied() const noexcept { return AlphaPremultiplied(get(PremulField, PremulFieldWidth)); }
176 constexpr inline TypeInterpretation typeInterpretation() const noexcept { return TypeInterpretation(get(TypeInterpretationField, TypeInterpretationFieldWidth)); }
177 constexpr inline ByteOrder byteOrder() const noexcept { return ByteOrder(get(ByteOrderField, ByteOrderFieldWidth)); }
178
179 constexpr inline YUVLayout yuvLayout() const noexcept { return YUVLayout(get(SubEnumField, SubEnumFieldWidth)); }
180 constexpr inline uchar subEnum() const noexcept { return get(SubEnumField, SubEnumFieldWidth); }
181
182private:
183 constexpr static inline ByteOrder resolveByteOrder(ByteOrder bo)
184 { return bo == CurrentSystemEndian ? Q_BYTE_ORDER == Q_LITTLE_ENDIAN ? LittleEndian : BigEndian : bo ; }
185
186private:
188
189 friend Q_DECL_CONST_FUNCTION constexpr inline bool operator==(QPixelFormat fmt1, QPixelFormat fmt2)
190 { return fmt1.data == fmt2.data; }
191
192 friend Q_DECL_CONST_FUNCTION constexpr inline bool operator!=(QPixelFormat fmt1, QPixelFormat fmt2)
193 { return !(fmt1 == fmt2); }
194};
195static_assert(sizeof(QPixelFormat) == sizeof(quint64));
197
198
199namespace QtPrivate {
201 uchar alphaSize,
202 QPixelFormat::AlphaUsage alphaUsage,
203 QPixelFormat::AlphaPosition alphaPosition,
205 QPixelFormat::TypeInterpretation typeInterpretation,
206 QPixelFormat::ByteOrder byteOrder);
207}
208
210 uchar firstSize,
211 uchar secondSize,
212 uchar thirdSize,
213 uchar fourthSize,
214 uchar fifthSize,
215 uchar alfa,
218 AlphaPremultiplied premult,
219 TypeInterpretation typeInterp,
220 ByteOrder b_order,
221 uchar s_enum) noexcept
222 : data(set(ModelField, ModelFieldWidth, uchar(mdl)) |
223 set(FirstField, FirstFieldWidth, firstSize) |
224 set(SecondField, SecondFieldWidth, secondSize) |
225 set(ThirdField, ThirdFieldWidth, thirdSize) |
226 set(FourthField, FourthFieldWidth, fourthSize) |
227 set(FifthField, FifthFieldWidth, fifthSize) |
228 set(AlphaField, AlphaFieldWidth, alfa) |
229 set(AlphaUsageField, AlphaUsageFieldWidth, uchar(usage)) |
230 set(AlphaPositionField, AlphaPositionFieldWidth, uchar(position)) |
231 set(PremulField, PremulFieldWidth, uchar(premult)) |
232 set(TypeInterpretationField, TypeInterpretationFieldWidth, uchar(typeInterp)) |
233 set(ByteOrderField, ByteOrderFieldWidth, uchar(resolveByteOrder(b_order))) |
234 set(SubEnumField, SubEnumFieldWidth, s_enum) |
235 set(UnusedField, UnusedFieldWidth, 0))
236{
237}
238
260
261constexpr inline QPixelFormat qPixelFormatGrayscale(uchar channelSize,
263{
265 channelSize,
266 0,
267 0,
268 0,
269 0,
270 0,
274 typeInt);
275}
276
277constexpr inline QPixelFormat qPixelFormatAlpha(uchar channelSize,
279{
281 0,
282 0,
283 0,
284 0,
285 0,
286 channelSize,
290 typeInt);
291}
292
293constexpr inline QPixelFormat qPixelFormatCmyk(uchar channelSize,
294 uchar alfa=0,
298{
300 channelSize,
301 channelSize,
302 channelSize,
303 channelSize,
304 0,
305 alfa,
306 usage,
307 position,
309 typeInt);
310}
311
312constexpr inline QPixelFormat qPixelFormatHsl(uchar channelSize,
313 uchar alfa=0,
317{
319 channelSize,
320 channelSize,
321 channelSize,
322 0,
323 0,
324 alfa,
325 usage,
326 position,
328 typeInt);
329}
330
331constexpr inline QPixelFormat qPixelFormatHsv(uchar channelSize,
332 uchar alfa=0,
336{
338 channelSize,
339 channelSize,
340 channelSize,
341 0,
342 0,
343 alfa,
344 usage,
345 position,
347 typeInt);
348}
349
366
368
369#endif //QPIXELFORMAT_H
\inmodule QtGui
constexpr uchar greenSize() const noexcept
Accessor function for the size of the green color channel.
constexpr AlphaPosition alphaPosition() const noexcept
Accessor function for alphaPosition.
constexpr uchar hueSize() const noexcept
Accessor function for the hue channel size.
ByteOrder
This enum describes the ByteOrder of the pixel format.
constexpr uchar yellowSize() const noexcept
Accessor function for the yellow color channel.
constexpr TypeInterpretation typeInterpretation() const noexcept
Accessor function for the type representation of a color channel or a pixel.
constexpr AlphaUsage alphaUsage() const noexcept
Accessor function for alphaUsage.
AlphaPosition
This enum type is used to describe the alpha channels position relative to the color channels.
AlphaPremultiplied
This enum type describes the boolean state if the alpha channel is multiplied into the color channels...
friend Q_DECL_CONST_FUNCTION constexpr bool operator==(QPixelFormat fmt1, QPixelFormat fmt2)
TypeInterpretation
This enum describes how each pixel is interpreted.
constexpr uchar lightnessSize() const noexcept
Accessor function for the lightness channel size.
constexpr uchar blueSize() const noexcept
Accessor function for the size of the blue color channel.
constexpr uchar alphaSize() const noexcept
Accessor function for the alpha channel size.
constexpr uchar bitsPerPixel() const noexcept
Accessor function for the bits used per pixel.
constexpr AlphaPremultiplied premultiplied() const noexcept
Accessor function for the AlphaPremultiplied enum.
constexpr uchar saturationSize() const noexcept
Accessor function for the saturation channel size.
friend Q_DECL_CONST_FUNCTION constexpr bool operator!=(QPixelFormat fmt1, QPixelFormat fmt2)
constexpr uchar channelCount() const noexcept
Accessor function for getting the channelCount.
constexpr QPixelFormat() noexcept
Creates a null pixelformat.
constexpr YUVLayout yuvLayout() const noexcept
Accessor function for the YUVLayout.
constexpr uchar blackSize() const noexcept
Accessor function for the black/key color channel.
constexpr uchar cyanSize() const noexcept
Accessor function for the cyan color channel.
YUVLayout
YUV is not represented by describing the size of the color channels.
constexpr uchar magentaSize() const noexcept
Accessor function for the megenta color channel.
constexpr uchar brightnessSize() const noexcept
Accessor function for the brightness channel size.
constexpr ColorModel colorModel() const noexcept
Accessor function for getting the colorModel.
constexpr ByteOrder byteOrder() const noexcept
The byte order is almost always set the byte order of the current system.
AlphaUsage
This enum describes if the alpha channel is used or not.
ColorModel
This enum type is used to describe the color model of the pixelformat.
constexpr uchar subEnum() const noexcept
Accessor for the datapart which contains subEnums This is the same as the yuvLayout() function.
constexpr uchar redSize() const noexcept
Accessor function for the size of the red color channel.
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
QPixelFormat QPixelFormat_createYUV(QPixelFormat::YUVLayout yuvLayout, uchar alphaSize, QPixelFormat::AlphaUsage alphaUsage, QPixelFormat::AlphaPosition alphaPosition, QPixelFormat::AlphaPremultiplied premultiplied, QPixelFormat::TypeInterpretation typeInterpretation, QPixelFormat::ByteOrder byteOrder)
#define Q_DECL_CONST_FUNCTION
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei width
GLenum GLuint GLintptr offset
GLbyte GLbyte blue
Definition qopenglext.h:385
GLbyte green
Definition qopenglext.h:385
GLsizeiptr const void GLenum usage
Definition qopenglext.h:543
constexpr QPixelFormat qPixelFormatHsv(uchar channelSize, uchar alfa=0, QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning, QPixelFormat::TypeInterpretation typeInt=QPixelFormat::FloatingPoint) noexcept
constexpr QPixelFormat qPixelFormatCmyk(uchar channelSize, uchar alfa=0, QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning, QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
constexpr QPixelFormat qPixelFormatRgba(uchar red, uchar green, uchar blue, uchar alfa, QPixelFormat::AlphaUsage usage, QPixelFormat::AlphaPosition position, QPixelFormat::AlphaPremultiplied pmul=QPixelFormat::NotPremultiplied, QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
constexpr QPixelFormat qPixelFormatHsl(uchar channelSize, uchar alfa=0, QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning, QPixelFormat::TypeInterpretation typeInt=QPixelFormat::FloatingPoint) noexcept
constexpr QPixelFormat qPixelFormatGrayscale(uchar channelSize, QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
constexpr QPixelFormat qPixelFormatAlpha(uchar channelSize, QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
QPixelFormat qPixelFormatYuv(QPixelFormat::YUVLayout layout, uchar alfa=0, QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha, QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning, QPixelFormat::AlphaPremultiplied p_mul=QPixelFormat::NotPremultiplied, QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedByte, QPixelFormat::ByteOrder b_order=QPixelFormat::LittleEndian)
#define Q_LITTLE_ENDIAN
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:157
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
#define Q_UINT64_C(c)
Definition qtypes.h:58
unsigned char uchar
Definition qtypes.h:32
unsigned long long quint64
Definition qtypes.h:61
unsigned int uint
Definition qtypes.h:34
QFuture< QSet< QChar > > set
[10]
QVBoxLayout * layout
QGraphicsSvgItem * red