19 SecondFieldWidth = FirstFieldWidth,
20 ThirdFieldWidth = FirstFieldWidth,
21 FourthFieldWidth = FirstFieldWidth,
22 FifthFieldWidth = FirstFieldWidth,
23 AlphaFieldWidth = FirstFieldWidth,
24 AlphaUsageFieldWidth = 1,
25 AlphaPositionFieldWidth = 1,
27 TypeInterpretationFieldWidth = 4,
28 ByteOrderFieldWidth = 2,
29 SubEnumFieldWidth = 6,
32 TotalFieldWidthByWidths = ModelFieldWidth + FirstFieldWidth + SecondFieldWidth + ThirdFieldWidth +
33 FourthFieldWidth + FifthFieldWidth + AlphaFieldWidth + AlphaUsageFieldWidth +
34 AlphaPositionFieldWidth + PremulFieldWidth + TypeInterpretationFieldWidth +
35 ByteOrderFieldWidth + SubEnumFieldWidth + UnusedFieldWidth
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),
56 TotalFieldWidthByOffsets = UnusedField +
int(UnusedFieldWidth)
59 static_assert(uint(TotalFieldWidthByWidths) == uint(TotalFieldWidthByOffsets));
60 static_assert(uint(TotalFieldWidthByWidths) == 8 *
sizeof(quint64));
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); }
90 enum AlphaPremultiplied {
95 enum TypeInterpretation {
127 constexpr inline QPixelFormat()
noexcept : data(0) {}
128 constexpr inline QPixelFormat(ColorModel colorModel,
135 AlphaUsage alphaUsage,
136 AlphaPosition alphaPosition,
137 AlphaPremultiplied premultiplied,
138 TypeInterpretation typeInterpretation,
139 ByteOrder byteOrder = CurrentSystemEndian,
140 uchar subEnum = 0)
noexcept;
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); }
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); }
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); }
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); }
164 constexpr inline uchar alphaSize()
const noexcept {
return get(AlphaField, AlphaFieldWidth); }
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); }
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)); }
179 constexpr inline YUVLayout yuvLayout()
const noexcept {
return YUVLayout(get(SubEnumField, SubEnumFieldWidth)); }
180 constexpr inline uchar subEnum()
const noexcept {
return get(SubEnumField, SubEnumFieldWidth); }
183 constexpr static inline ByteOrder resolveByteOrder(ByteOrder bo)
184 {
return bo == CurrentSystemEndian ? Q_BYTE_ORDER == Q_LITTLE_ENDIAN ? LittleEndian : BigEndian : bo ; }
189 friend Q_DECL_CONST_FUNCTION
constexpr inline bool operator==(QPixelFormat fmt1, QPixelFormat fmt2)
190 {
return fmt1.data == fmt2.data; }
192 friend Q_DECL_CONST_FUNCTION
constexpr inline bool operator!=(QPixelFormat fmt1, QPixelFormat fmt2)
193 {
return !(fmt1 == fmt2); }
209constexpr QPixelFormat::QPixelFormat(ColorModel mdl,
217 AlphaPosition position,
218 AlphaPremultiplied premult,
219 TypeInterpretation typeInterp,
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))