14 Q_GADGET_EXPORT(Q_GUI_EXPORT)
22 SecondFieldWidth = FirstFieldWidth,
23 ThirdFieldWidth = FirstFieldWidth,
24 FourthFieldWidth = FirstFieldWidth,
25 FifthFieldWidth = FirstFieldWidth,
26 AlphaFieldWidth = FirstFieldWidth,
27 AlphaUsageFieldWidth = 1,
28 AlphaPositionFieldWidth = 1,
30 TypeInterpretationFieldWidth = 4,
31 ByteOrderFieldWidth = 2,
32 SubEnumFieldWidth = 6,
35 TotalFieldWidthByWidths = ModelFieldWidth + FirstFieldWidth + SecondFieldWidth + ThirdFieldWidth +
36 FourthFieldWidth + FifthFieldWidth + AlphaFieldWidth + AlphaUsageFieldWidth +
37 AlphaPositionFieldWidth + PremulFieldWidth + TypeInterpretationFieldWidth +
38 ByteOrderFieldWidth + SubEnumFieldWidth + UnusedFieldWidth
45 FirstField = ModelField +
int(ModelFieldWidth),
46 SecondField = FirstField +
int(FirstFieldWidth),
47 ThirdField = SecondField +
int(SecondFieldWidth),
48 FourthField = ThirdField +
int(ThirdFieldWidth),
49 FifthField = FourthField +
int(FourthFieldWidth),
50 AlphaField = FifthField +
int(FifthFieldWidth),
51 AlphaUsageField = AlphaField +
int(AlphaFieldWidth),
52 AlphaPositionField = AlphaUsageField +
int(AlphaUsageFieldWidth),
53 PremulField = AlphaPositionField +
int(AlphaPositionFieldWidth),
54 TypeInterpretationField = PremulField +
int(PremulFieldWidth),
55 ByteOrderField = TypeInterpretationField +
int(TypeInterpretationFieldWidth),
56 SubEnumField = ByteOrderField +
int(ByteOrderFieldWidth),
57 UnusedField = SubEnumField +
int(SubEnumFieldWidth),
59 TotalFieldWidthByOffsets = UnusedField +
int(UnusedFieldWidth)
62 static_assert(uint(TotalFieldWidthByWidths) == uint(TotalFieldWidthByOffsets));
63 static_assert(uint(TotalFieldWidthByWidths) == 8 *
sizeof(quint64));
65 constexpr inline uchar get(Field offset, FieldWidth width)
const noexcept
66 {
return uchar((data >> uint(offset)) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))); }
67 constexpr static inline quint64 set(Field offset, FieldWidth width, uchar value)
68 {
return (quint64(value) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))) << uint(offset); }
96 enum AlphaPremultiplied {
100 Q_ENUM(AlphaPremultiplied)
102 enum TypeInterpretation {
108 Q_ENUM(TypeInterpretation)
137 constexpr inline QPixelFormat()
noexcept : data(0) {}
138 constexpr inline QPixelFormat(ColorModel colorModel,
145 AlphaUsage alphaUsage,
146 AlphaPosition alphaPosition,
147 AlphaPremultiplied premultiplied,
148 TypeInterpretation typeInterpretation,
149 ByteOrder byteOrder = CurrentSystemEndian,
150 uchar subEnum = 0)
noexcept;
152 constexpr inline ColorModel colorModel()
const noexcept {
return ColorModel(get(ModelField, ModelFieldWidth)); }
153 constexpr inline uchar channelCount()
const noexcept {
return (get(FirstField, FirstFieldWidth) > 0) +
154 (get(SecondField, SecondFieldWidth) > 0) +
155 (get(ThirdField, ThirdFieldWidth) > 0) +
156 (get(FourthField, FourthFieldWidth) > 0) +
157 (get(FifthField, FifthFieldWidth) > 0) +
158 (get(AlphaField, AlphaFieldWidth) > 0); }
160 constexpr inline uchar redSize()
const noexcept {
return get(FirstField, FirstFieldWidth); }
161 constexpr inline uchar greenSize()
const noexcept {
return get(SecondField, SecondFieldWidth); }
162 constexpr inline uchar blueSize()
const noexcept {
return get(ThirdField, ThirdFieldWidth); }
164 constexpr inline uchar cyanSize()
const noexcept {
return get(FirstField, FirstFieldWidth); }
165 constexpr inline uchar magentaSize()
const noexcept {
return get(SecondField, SecondFieldWidth); }
166 constexpr inline uchar yellowSize()
const noexcept {
return get(ThirdField, ThirdFieldWidth); }
167 constexpr inline uchar blackSize()
const noexcept {
return get(FourthField, FourthFieldWidth); }
169 constexpr inline uchar hueSize()
const noexcept {
return get(FirstField, FirstFieldWidth); }
170 constexpr inline uchar saturationSize()
const noexcept {
return get(SecondField, SecondFieldWidth); }
171 constexpr inline uchar lightnessSize()
const noexcept {
return get(ThirdField, ThirdFieldWidth); }
172 constexpr inline uchar brightnessSize()
const noexcept {
return get(ThirdField, ThirdFieldWidth); }
174 constexpr inline uchar alphaSize()
const noexcept {
return get(AlphaField, AlphaFieldWidth); }
176 constexpr inline uchar bitsPerPixel()
const noexcept {
return get(FirstField, FirstFieldWidth) +
177 get(SecondField, SecondFieldWidth) +
178 get(ThirdField, ThirdFieldWidth) +
179 get(FourthField, FourthFieldWidth) +
180 get(FifthField, FifthFieldWidth) +
181 get(AlphaField, AlphaFieldWidth); }
183 constexpr inline AlphaUsage alphaUsage()
const noexcept {
return AlphaUsage(get(AlphaUsageField, AlphaUsageFieldWidth)); }
184 constexpr inline AlphaPosition alphaPosition()
const noexcept {
return AlphaPosition(get(AlphaPositionField, AlphaPositionFieldWidth)); }
185 constexpr inline AlphaPremultiplied premultiplied()
const noexcept {
return AlphaPremultiplied(get(PremulField, PremulFieldWidth)); }
186 constexpr inline TypeInterpretation typeInterpretation()
const noexcept {
return TypeInterpretation(get(TypeInterpretationField, TypeInterpretationFieldWidth)); }
187 constexpr inline ByteOrder byteOrder()
const noexcept {
return ByteOrder(get(ByteOrderField, ByteOrderFieldWidth)); }
189 constexpr inline YUVLayout yuvLayout()
const noexcept {
return YUVLayout(get(SubEnumField, SubEnumFieldWidth)); }
190 constexpr inline uchar subEnum()
const noexcept {
return get(SubEnumField, SubEnumFieldWidth); }
193 constexpr static inline ByteOrder resolveByteOrder(ByteOrder bo) {
return resolveByteOrder(bo, UnsignedInteger ); }
194 constexpr static inline ByteOrder resolveByteOrder(ByteOrder bo, TypeInterpretation ti)
195 {
return bo == CurrentSystemEndian ? ti == UnsignedByte || Q_BYTE_ORDER == Q_BIG_ENDIAN ? BigEndian : LittleEndian : bo ; }
200 friend Q_DECL_CONST_FUNCTION
constexpr inline bool operator==(QPixelFormat fmt1, QPixelFormat fmt2)
201 {
return fmt1.data == fmt2.data; }
203 friend Q_DECL_CONST_FUNCTION
constexpr inline bool operator!=(QPixelFormat fmt1, QPixelFormat fmt2)
204 {
return !(fmt1 == fmt2); }
206#ifndef QT_NO_DEBUG_STREAM
207 friend Q_GUI_EXPORT QDebug operator<<(QDebug debug,
const QPixelFormat &format);
224constexpr QPixelFormat::QPixelFormat(ColorModel mdl,
232 AlphaPosition position,
233 AlphaPremultiplied premult,
234 TypeInterpretation typeInterp,
236 uchar s_enum)
noexcept
237 : data(set(ModelField, ModelFieldWidth, uchar(mdl)) |
238 set(FirstField, FirstFieldWidth, firstSize) |
239 set(SecondField, SecondFieldWidth, secondSize) |
240 set(ThirdField, ThirdFieldWidth, thirdSize) |
241 set(FourthField, FourthFieldWidth, fourthSize) |
242 set(FifthField, FifthFieldWidth, fifthSize) |
243 set(AlphaField, AlphaFieldWidth, alfa) |
244 set(AlphaUsageField, AlphaUsageFieldWidth, uchar(usage)) |
245 set(AlphaPositionField, AlphaPositionFieldWidth, uchar(position)) |
246 set(PremulField, PremulFieldWidth, uchar(premult)) |
247 set(TypeInterpretationField, TypeInterpretationFieldWidth, uchar(typeInterp)) |
248 set(ByteOrderField, ByteOrderFieldWidth, uchar(resolveByteOrder(b_order, typeInterp))) |
249 set(SubEnumField, SubEnumFieldWidth, s_enum) |
250 set(UnusedField, UnusedFieldWidth, 0))