Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtGui/qpixelformat.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QPIXELFORMAT_H
0005 #define QPIXELFORMAT_H
0006 
0007 #include <QtGui/qtguiglobal.h>
0008 
0009 QT_BEGIN_NAMESPACE
0010 
0011 class QPixelFormat
0012 {
0013     // QPixelFormat basically is a glorified quint64, split into several fields.
0014     // We could use bit-fields, but GCC at least generates horrible, horrible code for them,
0015     // so we do the bit-twiddling ourselves.
0016     enum FieldWidth {
0017         ModelFieldWidth = 4,
0018         FirstFieldWidth = 6,
0019         SecondFieldWidth = FirstFieldWidth,
0020         ThirdFieldWidth = FirstFieldWidth,
0021         FourthFieldWidth = FirstFieldWidth,
0022         FifthFieldWidth = FirstFieldWidth,
0023         AlphaFieldWidth = FirstFieldWidth,
0024         AlphaUsageFieldWidth = 1,
0025         AlphaPositionFieldWidth = 1,
0026         PremulFieldWidth = 1,
0027         TypeInterpretationFieldWidth = 4,
0028         ByteOrderFieldWidth = 2,
0029         SubEnumFieldWidth = 6,
0030         UnusedFieldWidth = 9,
0031 
0032         TotalFieldWidthByWidths = ModelFieldWidth + FirstFieldWidth + SecondFieldWidth + ThirdFieldWidth +
0033                                   FourthFieldWidth + FifthFieldWidth + AlphaFieldWidth + AlphaUsageFieldWidth +
0034                                   AlphaPositionFieldWidth + PremulFieldWidth + TypeInterpretationFieldWidth +
0035                                   ByteOrderFieldWidth + SubEnumFieldWidth + UnusedFieldWidth
0036     };
0037 
0038     enum Field {
0039         ModelField = 0,
0040         // work around bug in old clang versions: when building webkit
0041         // with XCode 4.6 and older this fails compilation, thus cast to int
0042         FirstField = ModelField + int(ModelFieldWidth),
0043         SecondField = FirstField + int(FirstFieldWidth),
0044         ThirdField = SecondField + int(SecondFieldWidth),
0045         FourthField = ThirdField + int(ThirdFieldWidth),
0046         FifthField = FourthField + int(FourthFieldWidth),
0047         AlphaField = FifthField + int(FifthFieldWidth),
0048         AlphaUsageField = AlphaField + int(AlphaFieldWidth),
0049         AlphaPositionField = AlphaUsageField + int(AlphaUsageFieldWidth),
0050         PremulField = AlphaPositionField + int(AlphaPositionFieldWidth),
0051         TypeInterpretationField = PremulField + int(PremulFieldWidth),
0052         ByteOrderField = TypeInterpretationField + int(TypeInterpretationFieldWidth),
0053         SubEnumField = ByteOrderField + int(ByteOrderFieldWidth),
0054         UnusedField = SubEnumField + int(SubEnumFieldWidth),
0055 
0056         TotalFieldWidthByOffsets = UnusedField + int(UnusedFieldWidth)
0057     };
0058 
0059     static_assert(uint(TotalFieldWidthByWidths) == uint(TotalFieldWidthByOffsets));
0060     static_assert(uint(TotalFieldWidthByWidths) == 8 * sizeof(quint64));
0061 
0062     constexpr inline uchar get(Field offset, FieldWidth width) const noexcept
0063     { return uchar((data >> uint(offset)) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))); }
0064     constexpr static inline quint64 set(Field offset, FieldWidth width, uchar value)
0065     { return (quint64(value) & ((Q_UINT64_C(1) << uint(width)) - Q_UINT64_C(1))) << uint(offset); }
0066 
0067 public:
0068     enum ColorModel {
0069         RGB,
0070         BGR,
0071         Indexed,
0072         Grayscale,
0073         CMYK,
0074         HSL,
0075         HSV,
0076         YUV,
0077         Alpha
0078     };
0079 
0080     enum AlphaUsage {
0081         UsesAlpha,
0082         IgnoresAlpha
0083     };
0084 
0085     enum AlphaPosition {
0086         AtBeginning,
0087         AtEnd
0088     };
0089 
0090     enum AlphaPremultiplied {
0091         NotPremultiplied,
0092         Premultiplied
0093     };
0094 
0095     enum TypeInterpretation {
0096         UnsignedInteger,
0097         UnsignedShort,
0098         UnsignedByte,
0099         FloatingPoint
0100     };
0101 
0102     enum YUVLayout {
0103         YUV444,
0104         YUV422,
0105         YUV411,
0106         YUV420P,
0107         YUV420SP,
0108         YV12,
0109         UYVY,
0110         YUYV,
0111         NV12,
0112         NV21,
0113         IMC1,
0114         IMC2,
0115         IMC3,
0116         IMC4,
0117         Y8,
0118         Y16
0119     };
0120 
0121     enum ByteOrder {
0122         LittleEndian,
0123         BigEndian,
0124         CurrentSystemEndian
0125     };
0126 
0127     constexpr inline QPixelFormat() noexcept : data(0) {}
0128     constexpr inline QPixelFormat(ColorModel colorModel,
0129                                            uchar firstSize,
0130                                            uchar secondSize,
0131                                            uchar thirdSize,
0132                                            uchar fourthSize,
0133                                            uchar fifthSize,
0134                                            uchar alphaSize,
0135                                            AlphaUsage alphaUsage,
0136                                            AlphaPosition alphaPosition,
0137                                            AlphaPremultiplied premultiplied,
0138                                            TypeInterpretation typeInterpretation,
0139                                            ByteOrder byteOrder = CurrentSystemEndian,
0140                                            uchar subEnum = 0) noexcept;
0141 
0142     constexpr inline ColorModel colorModel() const  noexcept { return ColorModel(get(ModelField, ModelFieldWidth)); }
0143     constexpr inline uchar channelCount() const noexcept { return (get(FirstField, FirstFieldWidth) > 0) +
0144                                                                                  (get(SecondField, SecondFieldWidth) > 0) +
0145                                                                                  (get(ThirdField, ThirdFieldWidth) > 0) +
0146                                                                                  (get(FourthField, FourthFieldWidth) > 0) +
0147                                                                                  (get(FifthField, FifthFieldWidth) > 0) +
0148                                                                                  (get(AlphaField, AlphaFieldWidth) > 0); }
0149 
0150     constexpr inline uchar redSize() const noexcept { return get(FirstField, FirstFieldWidth); }
0151     constexpr inline uchar greenSize() const noexcept { return get(SecondField, SecondFieldWidth); }
0152     constexpr inline uchar blueSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
0153 
0154     constexpr inline uchar cyanSize() const noexcept { return get(FirstField, FirstFieldWidth); }
0155     constexpr inline uchar magentaSize() const noexcept { return get(SecondField, SecondFieldWidth); }
0156     constexpr inline uchar yellowSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
0157     constexpr inline uchar blackSize() const noexcept { return get(FourthField, FourthFieldWidth); }
0158 
0159     constexpr inline uchar hueSize() const noexcept { return get(FirstField, FirstFieldWidth); }
0160     constexpr inline uchar saturationSize() const noexcept { return get(SecondField, SecondFieldWidth); }
0161     constexpr inline uchar lightnessSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
0162     constexpr inline uchar brightnessSize() const noexcept { return get(ThirdField, ThirdFieldWidth); }
0163 
0164     constexpr inline uchar alphaSize() const noexcept { return get(AlphaField, AlphaFieldWidth); }
0165 
0166     constexpr inline uchar bitsPerPixel() const noexcept { return get(FirstField, FirstFieldWidth) +
0167                                                                                  get(SecondField, SecondFieldWidth) +
0168                                                                                  get(ThirdField, ThirdFieldWidth) +
0169                                                                                  get(FourthField, FourthFieldWidth) +
0170                                                                                  get(FifthField, FifthFieldWidth) +
0171                                                                                  get(AlphaField, AlphaFieldWidth); }
0172 
0173     constexpr inline AlphaUsage alphaUsage() const noexcept { return AlphaUsage(get(AlphaUsageField, AlphaUsageFieldWidth)); }
0174     constexpr inline AlphaPosition alphaPosition() const noexcept { return AlphaPosition(get(AlphaPositionField, AlphaPositionFieldWidth)); }
0175     constexpr inline AlphaPremultiplied premultiplied() const noexcept { return AlphaPremultiplied(get(PremulField, PremulFieldWidth)); }
0176     constexpr inline TypeInterpretation typeInterpretation() const noexcept { return TypeInterpretation(get(TypeInterpretationField, TypeInterpretationFieldWidth)); }
0177     constexpr inline ByteOrder byteOrder() const noexcept { return ByteOrder(get(ByteOrderField, ByteOrderFieldWidth)); }
0178 
0179     constexpr inline YUVLayout yuvLayout() const noexcept { return YUVLayout(get(SubEnumField, SubEnumFieldWidth)); }
0180     constexpr inline uchar subEnum() const noexcept { return get(SubEnumField, SubEnumFieldWidth); }
0181 
0182 private:
0183     constexpr static inline ByteOrder resolveByteOrder(ByteOrder bo)
0184     { return bo == CurrentSystemEndian ? Q_BYTE_ORDER == Q_LITTLE_ENDIAN ? LittleEndian : BigEndian : bo ; }
0185 
0186 private:
0187     quint64 data;
0188 
0189     friend Q_DECL_CONST_FUNCTION constexpr inline bool operator==(QPixelFormat fmt1, QPixelFormat fmt2)
0190     { return fmt1.data == fmt2.data; }
0191 
0192     friend Q_DECL_CONST_FUNCTION constexpr inline bool operator!=(QPixelFormat fmt1, QPixelFormat fmt2)
0193     { return !(fmt1 == fmt2); }
0194 };
0195 static_assert(sizeof(QPixelFormat) == sizeof(quint64));
0196 Q_DECLARE_TYPEINFO(QPixelFormat, Q_PRIMITIVE_TYPE);
0197 
0198 
0199 namespace QtPrivate {
0200     QPixelFormat Q_GUI_EXPORT QPixelFormat_createYUV(QPixelFormat::YUVLayout yuvLayout,
0201                                                      uchar alphaSize,
0202                                                      QPixelFormat::AlphaUsage alphaUsage,
0203                                                      QPixelFormat::AlphaPosition alphaPosition,
0204                                                      QPixelFormat::AlphaPremultiplied premultiplied,
0205                                                      QPixelFormat::TypeInterpretation typeInterpretation,
0206                                                      QPixelFormat::ByteOrder byteOrder);
0207 }
0208 
0209 constexpr QPixelFormat::QPixelFormat(ColorModel mdl,
0210                                      uchar firstSize,
0211                                      uchar secondSize,
0212                                      uchar thirdSize,
0213                                      uchar fourthSize,
0214                                      uchar fifthSize,
0215                                      uchar alfa,
0216                                      AlphaUsage usage,
0217                                      AlphaPosition position,
0218                                      AlphaPremultiplied premult,
0219                                      TypeInterpretation typeInterp,
0220                                      ByteOrder b_order,
0221                                      uchar s_enum) noexcept
0222     : data(set(ModelField, ModelFieldWidth, uchar(mdl)) |
0223            set(FirstField, FirstFieldWidth, firstSize) |
0224            set(SecondField, SecondFieldWidth, secondSize) |
0225            set(ThirdField, ThirdFieldWidth, thirdSize) |
0226            set(FourthField, FourthFieldWidth, fourthSize) |
0227            set(FifthField, FifthFieldWidth, fifthSize) |
0228            set(AlphaField, AlphaFieldWidth, alfa) |
0229            set(AlphaUsageField, AlphaUsageFieldWidth, uchar(usage)) |
0230            set(AlphaPositionField, AlphaPositionFieldWidth, uchar(position)) |
0231            set(PremulField, PremulFieldWidth, uchar(premult)) |
0232            set(TypeInterpretationField, TypeInterpretationFieldWidth, uchar(typeInterp)) |
0233            set(ByteOrderField, ByteOrderFieldWidth, uchar(resolveByteOrder(b_order))) |
0234            set(SubEnumField, SubEnumFieldWidth, s_enum) |
0235            set(UnusedField, UnusedFieldWidth, 0))
0236 {
0237 }
0238 
0239 constexpr inline QPixelFormat qPixelFormatRgba(uchar red,
0240                                                uchar green,
0241                                                uchar blue,
0242                                                uchar alfa,
0243                                                QPixelFormat::AlphaUsage usage,
0244                                                QPixelFormat::AlphaPosition position,
0245                                                QPixelFormat::AlphaPremultiplied pmul=QPixelFormat::NotPremultiplied,
0246                                                QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
0247 {
0248     return QPixelFormat(QPixelFormat::RGB,
0249                         red,
0250                         green,
0251                         blue,
0252                         0,
0253                         0,
0254                         alfa,
0255                         usage,
0256                         position,
0257                         pmul,
0258                         typeInt);
0259 }
0260 
0261 constexpr inline QPixelFormat qPixelFormatGrayscale(uchar channelSize,
0262                                                     QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
0263 {
0264     return QPixelFormat(QPixelFormat::Grayscale,
0265                         channelSize,
0266                         0,
0267                         0,
0268                         0,
0269                         0,
0270                         0,
0271                         QPixelFormat::IgnoresAlpha,
0272                         QPixelFormat::AtBeginning,
0273                         QPixelFormat::NotPremultiplied,
0274                         typeInt);
0275 }
0276 
0277 constexpr inline QPixelFormat qPixelFormatAlpha(uchar channelSize,
0278                                                 QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
0279 {
0280     return QPixelFormat(QPixelFormat::Alpha,
0281                         0,
0282                         0,
0283                         0,
0284                         0,
0285                         0,
0286                         channelSize,
0287                         QPixelFormat::UsesAlpha,
0288                         QPixelFormat::AtBeginning,
0289                         QPixelFormat::NotPremultiplied,
0290                         typeInt);
0291 }
0292 
0293 constexpr inline QPixelFormat qPixelFormatCmyk(uchar channelSize,
0294                                                uchar alfa=0,
0295                                                QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha,
0296                                                QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning,
0297                                                QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedInteger) noexcept
0298 {
0299     return QPixelFormat(QPixelFormat::CMYK,
0300                         channelSize,
0301                         channelSize,
0302                         channelSize,
0303                         channelSize,
0304                         0,
0305                         alfa,
0306                         usage,
0307                         position,
0308                         QPixelFormat::NotPremultiplied,
0309                         typeInt);
0310 }
0311 
0312 constexpr inline QPixelFormat qPixelFormatHsl(uchar channelSize,
0313                                               uchar alfa=0,
0314                                               QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha,
0315                                               QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning,
0316                                               QPixelFormat::TypeInterpretation typeInt=QPixelFormat::FloatingPoint) noexcept
0317 {
0318     return QPixelFormat(QPixelFormat::HSL,
0319                         channelSize,
0320                         channelSize,
0321                         channelSize,
0322                         0,
0323                         0,
0324                         alfa,
0325                         usage,
0326                         position,
0327                         QPixelFormat::NotPremultiplied,
0328                         typeInt);
0329 }
0330 
0331 constexpr inline QPixelFormat qPixelFormatHsv(uchar channelSize,
0332                                               uchar alfa=0,
0333                                               QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha,
0334                                               QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning,
0335                                               QPixelFormat::TypeInterpretation typeInt=QPixelFormat::FloatingPoint) noexcept
0336 {
0337     return QPixelFormat(QPixelFormat::HSV,
0338                         channelSize,
0339                         channelSize,
0340                         channelSize,
0341                         0,
0342                         0,
0343                         alfa,
0344                         usage,
0345                         position,
0346                         QPixelFormat::NotPremultiplied,
0347                         typeInt);
0348 }
0349 
0350 inline QPixelFormat qPixelFormatYuv(QPixelFormat::YUVLayout layout,
0351                                     uchar alfa=0,
0352                                     QPixelFormat::AlphaUsage usage=QPixelFormat::IgnoresAlpha,
0353                                     QPixelFormat::AlphaPosition position=QPixelFormat::AtBeginning,
0354                                     QPixelFormat::AlphaPremultiplied p_mul=QPixelFormat::NotPremultiplied,
0355                                     QPixelFormat::TypeInterpretation typeInt=QPixelFormat::UnsignedByte,
0356                                     QPixelFormat::ByteOrder b_order=QPixelFormat::LittleEndian)
0357 {
0358     return QtPrivate::QPixelFormat_createYUV(layout,
0359                                              alfa,
0360                                              usage,
0361                                              position,
0362                                              p_mul,
0363                                              typeInt,
0364                                              b_order);
0365 }
0366 
0367 QT_END_NAMESPACE
0368 
0369 #endif //QPIXELFORMAT_H