16 Q_GADGET_EXPORT(Q_GUI_EXPORT)
24 SecondFieldWidth = FirstFieldWidth,
25 ThirdFieldWidth = FirstFieldWidth,
26 FourthFieldWidth = FirstFieldWidth,
27 FifthFieldWidth = FirstFieldWidth,
28 AlphaFieldWidth = FirstFieldWidth,
29 AlphaUsageFieldWidth = 1,
30 AlphaPositionFieldWidth = 1,
32 TypeInterpretationFieldWidth = 4,
33 ByteOrderFieldWidth = 2,
34 SubEnumFieldWidth = 6,
37 TotalFieldWidthByWidths = ModelFieldWidth + FirstFieldWidth + SecondFieldWidth + ThirdFieldWidth +
38 FourthFieldWidth + FifthFieldWidth + AlphaFieldWidth + AlphaUsageFieldWidth +
39 AlphaPositionFieldWidth + PremulFieldWidth + TypeInterpretationFieldWidth +
40 ByteOrderFieldWidth + SubEnumFieldWidth + UnusedFieldWidth
47 FirstField = ModelField +
int(ModelFieldWidth),
48 SecondField = FirstField +
int(FirstFieldWidth),
49 ThirdField = SecondField +
int(SecondFieldWidth),
50 FourthField = ThirdField +
int(ThirdFieldWidth),
51 FifthField = FourthField +
int(FourthFieldWidth),
52 AlphaField = FifthField +
int(FifthFieldWidth),
53 AlphaUsageField = AlphaField +
int(AlphaFieldWidth),
54 AlphaPositionField = AlphaUsageField +
int(AlphaUsageFieldWidth),
55 PremulField = AlphaPositionField +
int(AlphaPositionFieldWidth),
56 TypeInterpretationField = PremulField +
int(PremulFieldWidth),
57 ByteOrderField = TypeInterpretationField +
int(TypeInterpretationFieldWidth),
58 SubEnumField = ByteOrderField +
int(ByteOrderFieldWidth),
59 UnusedField = SubEnumField +
int(SubEnumFieldWidth),
61 TotalFieldWidthByOffsets = UnusedField +
int(UnusedFieldWidth)
64 static_assert(uint(TotalFieldWidthByWidths) == uint(TotalFieldWidthByOffsets));
65 static_assert(uint(TotalFieldWidthByWidths) == 8 *
sizeof(quint64));
67 constexpr inline uchar get(Field offset, FieldWidth width)
const noexcept
68 {
return uchar((data >> uint(offset)) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))); }
69 constexpr static inline quint64 set(Field offset, FieldWidth width, uchar value)
70 {
return (quint64(value) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))) << uint(offset); }
98 enum AlphaPremultiplied {
102 Q_ENUM(AlphaPremultiplied)
104 enum TypeInterpretation {
110 Q_ENUM(TypeInterpretation)
139 constexpr inline QPixelFormat()
noexcept : data(0) {}
140 constexpr inline QPixelFormat(ColorModel colorModel,
147 AlphaUsage alphaUsage,
148 AlphaPosition alphaPosition,
149 AlphaPremultiplied premultiplied,
150 TypeInterpretation typeInterpretation,
151 ByteOrder byteOrder = CurrentSystemEndian,
152 uchar subEnum = 0)
noexcept;
154 constexpr inline ColorModel colorModel()
const noexcept {
return ColorModel(get(ModelField, ModelFieldWidth)); }
155 constexpr inline uchar channelCount()
const noexcept {
return (get(FirstField, FirstFieldWidth) > 0) +
156 (get(SecondField, SecondFieldWidth) > 0) +
157 (get(ThirdField, ThirdFieldWidth) > 0) +
158 (get(FourthField, FourthFieldWidth) > 0) +
159 (get(FifthField, FifthFieldWidth) > 0) +
160 (get(AlphaField, AlphaFieldWidth) > 0); }
162 constexpr inline uchar redSize()
const noexcept {
return get(FirstField, FirstFieldWidth); }
163 constexpr inline uchar greenSize()
const noexcept {
return get(SecondField, SecondFieldWidth); }
164 constexpr inline uchar blueSize()
const noexcept {
return get(ThirdField, ThirdFieldWidth); }
166 constexpr inline uchar cyanSize()
const noexcept {
return get(FirstField, FirstFieldWidth); }
167 constexpr inline uchar magentaSize()
const noexcept {
return get(SecondField, SecondFieldWidth); }
168 constexpr inline uchar yellowSize()
const noexcept {
return get(ThirdField, ThirdFieldWidth); }
169 constexpr inline uchar blackSize()
const noexcept {
return get(FourthField, FourthFieldWidth); }
171 constexpr inline uchar hueSize()
const noexcept {
return get(FirstField, FirstFieldWidth); }
172 constexpr inline uchar saturationSize()
const noexcept {
return get(SecondField, SecondFieldWidth); }
173 constexpr inline uchar lightnessSize()
const noexcept {
return get(ThirdField, ThirdFieldWidth); }
174 constexpr inline uchar brightnessSize()
const noexcept {
return get(ThirdField, ThirdFieldWidth); }
176 constexpr inline uchar alphaSize()
const noexcept {
return get(AlphaField, AlphaFieldWidth); }
178 constexpr inline uchar bitsPerPixel()
const noexcept {
return get(FirstField, FirstFieldWidth) +
179 get(SecondField, SecondFieldWidth) +
180 get(ThirdField, ThirdFieldWidth) +
181 get(FourthField, FourthFieldWidth) +
182 get(FifthField, FifthFieldWidth) +
183 get(AlphaField, AlphaFieldWidth); }
185 constexpr inline AlphaUsage alphaUsage()
const noexcept {
return AlphaUsage(get(AlphaUsageField, AlphaUsageFieldWidth)); }
186 constexpr inline AlphaPosition alphaPosition()
const noexcept {
return AlphaPosition(get(AlphaPositionField, AlphaPositionFieldWidth)); }
187 constexpr inline AlphaPremultiplied premultiplied()
const noexcept {
return AlphaPremultiplied(get(PremulField, PremulFieldWidth)); }
188 constexpr inline TypeInterpretation typeInterpretation()
const noexcept {
return TypeInterpretation(get(TypeInterpretationField, TypeInterpretationFieldWidth)); }
189 constexpr inline ByteOrder byteOrder()
const noexcept {
return ByteOrder(get(ByteOrderField, ByteOrderFieldWidth)); }
191 constexpr inline YUVLayout yuvLayout()
const noexcept {
return YUVLayout(get(SubEnumField, SubEnumFieldWidth)); }
192 constexpr inline uchar subEnum()
const noexcept {
return get(SubEnumField, SubEnumFieldWidth); }
195 constexpr static inline ByteOrder resolveByteOrder(ByteOrder bo) {
return resolveByteOrder(bo, UnsignedInteger ); }
196 constexpr static inline ByteOrder resolveByteOrder(ByteOrder bo, TypeInterpretation ti)
197 {
return bo == CurrentSystemEndian ? ti == UnsignedByte || Q_BYTE_ORDER == Q_BIG_ENDIAN ? BigEndian : LittleEndian : bo ; }
202 friend Q_DECL_CONST_FUNCTION
constexpr inline bool operator==(QPixelFormat fmt1, QPixelFormat fmt2)
203 {
return fmt1.data == fmt2.data; }
205 friend Q_DECL_CONST_FUNCTION
constexpr inline bool operator!=(QPixelFormat fmt1, QPixelFormat fmt2)
206 {
return !(fmt1 == fmt2); }
208#ifndef QT_NO_DEBUG_STREAM
209 friend Q_GUI_EXPORT QDebug operator<<(QDebug debug,
const QPixelFormat &format);
226constexpr QPixelFormat::QPixelFormat(ColorModel mdl,
234 AlphaPosition position,
235 AlphaPremultiplied premult,
236 TypeInterpretation typeInterp,
238 uchar s_enum)
noexcept
239 : data(set(ModelField, ModelFieldWidth, uchar(mdl)) |
240 set(FirstField, FirstFieldWidth, firstSize) |
241 set(SecondField, SecondFieldWidth, secondSize) |
242 set(ThirdField, ThirdFieldWidth, thirdSize) |
243 set(FourthField, FourthFieldWidth, fourthSize) |
244 set(FifthField, FifthFieldWidth, fifthSize) |
245 set(AlphaField, AlphaFieldWidth, alfa) |
246 set(AlphaUsageField, AlphaUsageFieldWidth, uchar(usage)) |
247 set(AlphaPositionField, AlphaPositionFieldWidth, uchar(position)) |
248 set(PremulField, PremulFieldWidth, uchar(premult)) |
249 set(TypeInterpretationField, TypeInterpretationFieldWidth, uchar(typeInterp)) |
250 set(ByteOrderField, ByteOrderFieldWidth, uchar(resolveByteOrder(b_order, typeInterp))) |
251 set(SubEnumField, SubEnumFieldWidth, s_enum) |
252 set(UnusedField, UnusedFieldWidth, 0))