From eb88aaa3a2aed3235cf837e858f530f6a521349f Mon Sep 17 00:00:00 2001 From: Jorgen Lind Date: Fri, 21 Mar 2014 23:05:33 +0100 Subject: Introducing QPixelFormat Its purpose in life will be to describe pixel formats [ChangeLog][QtGui] Added QPixelFormat class Change-Id: I74d8f974606520efb3935110ff3d6ddb5ea805a8 Reviewed-by: Laszlo Agocs --- src/gui/kernel/kernel.pri | 6 +- src/gui/kernel/qpixelformat.cpp | 630 ++++++++++++++++++++++++++++++++++++++++ src/gui/kernel/qpixelformat.h | 452 ++++++++++++++++++++++++++++ 3 files changed, 1086 insertions(+), 2 deletions(-) create mode 100644 src/gui/kernel/qpixelformat.cpp create mode 100644 src/gui/kernel/qpixelformat.h (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index e9e4a1d818..69568e2f4e 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -68,7 +68,8 @@ HEADERS += \ kernel/qplatformservices.h \ kernel/qplatformscreenpageflipper.h \ kernel/qplatformsystemtrayicon.h \ - kernel/qplatformsessionmanager.h + kernel/qplatformsessionmanager.h \ + kernel/qpixelformat.h SOURCES += \ kernel/qclipboard_qpa.cpp \ @@ -122,7 +123,8 @@ SOURCES += \ kernel/qplatformscreenpageflipper.cpp \ kernel/qplatformsystemtrayicon_qpa.cpp \ kernel/qplatformsessionmanager.cpp \ - kernel/qplatformmenu.cpp + kernel/qplatformmenu.cpp \ + kernel/qpixelformat.cpp contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles2) { HEADERS += \ diff --git a/src/gui/kernel/qpixelformat.cpp b/src/gui/kernel/qpixelformat.cpp new file mode 100644 index 0000000000..436694915f --- /dev/null +++ b/src/gui/kernel/qpixelformat.cpp @@ -0,0 +1,630 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qpixelformat.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QPixelFormat + \inmodule QtGui + \since 5.4 + \brief QPixelFormat is a class for describing different pixel + layouts in graphics buffers + + In Qt there is a often a need to represent the layout of the pixels in a + graphics buffer. Internally QPixelFormat stores everything in a 64 bit + datastructure. This gives performance but also some limitations. + + QPixelFormat can describe 5 color channels and 1 alpha channel, each can use + 6 bits to describe the size of the color channel. + + The position of the alpha channel is described with a separate enum. This is + to make it possible to describe QImage formats like ARGB32, and also + describe typical OpenGL formats like RBGA8888. + + How pixels are suppose to be read is determined by the TypeInterpretation + enum. It describes if color values are suppose to be read byte per byte, + or if a pixel is suppose to be read as a complete int and then masked. + \sa TypeInterpretation + + There is no support for describing YUV's macro pixels. Instead a list of YUV + formats has been made. When a QPixelFormat is describing a YUV format, the + bitsPerPixel value has been deduced by the YUV Layout enum. Also, the color + channels should all be set to zero except the fifth color channel that + should store the bitsPerPixel value. +*/ + +/*! + \enum QPixelFormat::ColorModel + + This enum type is used to describe the color model of the pixelformat. + + \value RGB The color model is RGB. + + \value BGR This is logically the opposite endian version of RGB. However, + for ease of use it has its own model. + + \value Indexed The color model uses a color palette. + + \value GrayScale The color model is GrayScale. + + \value CMYK The color model is CMYK. + + \value HSL The color model is HSL. + + \value HSV The color model is HSV. + + \value YUV The color model is YUV. +*/ + +/*! + \enum QPixelFormat::AlphaUsage + + This enum describes if the alpha channel is used or not. Sometimes the + pixelformat will have a size for the alpha channel, but the pixel format + does actually not use the alpha channel. For example RGB32 is such a + format. The RGB channels are 8 bits each, and there is no alpha channel. + But the complete size for each pixel is 32. Therefore the alpha channel size + is 8, but the alpha channel is ignored. Its important to note that in such + situations the position of the alpha channel is significant. + + \value IgnoresAlpha The alpha channel is not used. + + \value UsesAlpha The alpha channel is used. +*/ + +/*! + \enum QPixelFormat::AlphaPosition + + This enum type is used to describe the alpha channels position relative to the + color channels. + + \value AtBeginning The alpha channel will be put in front of the color + channels . E.g. ARGB. + + \value AtEnd The alpha channel will be put in the back of the color + channels. E.g. RGBA. +*/ + +/*! + \enum QPixelFormat::AlphaPremultiplied + + This enum type describes the boolean state if the alpha channel is multiplied + into the color channels or not. + + \value NotPremultiplied The alpha channel is not multiplied into the color channels. + + \value Premultiplied The alpha channel is multiplied into the color channels. +*/ + +/*! + \enum QPixelFormat::TypeInterpretation + + This enum describes how each pixel is interpreted. If a pixel is read as a + full 32 bit unsigned integer and then each channel is masked out, or if + each byte is read as unsigned char values. Typically QImage formats + interpret one pixel as an unsigned integer and then the color channels are + masked out. OpenGL on the other hand typically interpreted pixels "one byte + after the other", Ie. unsigned byte. + + QImage also have the format Format_RGBA8888 (and its derivatives), where + the pixels are interpreted as unsigned bytes. OpenGL has extensions that makes it + possible to upload pixel buffers in an unsigned integer format. + + \image qpixelformat-argb32buffer.png An unsigned integer ARGB32 pixel. + + The image above shows a ARGB pixel in memory read as an unsigned integer. + However, if this pixel was read byte for byte on a little endian system the + first byte would be the byte containing the B-channel. The next byte would + be the G-channel, then the R-channel and finally the A-channel. This shows + that on little endian systems, how each pixel is interpreted is significant + for integer formats. This is not the case on big endian systems. + + \value UnsignedInteger + \value UnsignedShort + \value UnsignedByte + \value FloatingPoint +*/ + +/*! + \enum QPixelFormat::ByteOrder + + This enum describes the ByteOrder of the pixel format. This enum is mostly + ignored but have some use cases for YUV formats. BGR formats have their own + color model, and should not be described by using the opposite endianness + on an RGB format. + + \value LittleEndian The byte order is little endian. + \value BigEndian The byte order is big endian. + \value CurrentSystemEndian This enum will not be stored, but is converted in + the constructor to the endian enum that matches + the enum of the current system. + +*/ + +/*! + \enum QPixelFormat::YUVLayout + + YUV is not represented by describing the size of the color channels. This is + because YUV often use macro pixels, making the concept of sperate color channels + invalid. Instead the different YUV layouts are described with this enum. + + \value YUV444 + \value YUV422 + \value YUV411 + \value YUV420P + \value YUV420SP + \value YV12 + \value UYVY + \value YUYV + \value NV12 + \value NV21 + \value IMC1 + \value IMC2 + \value IMC3 + \value IMC4 + \value Y8 + \value Y16 +*/ + +/*! + \fn QPixelFormat::QPixelFormat() + + Creates a null pixelformat. This format maps to QImage::Format_Invalid. +*/ + +/*! + \fn QPixelFormat::QPixelFormat(ColorModel colorModel, + uchar firstSize, + uchar secondSize, + uchar thirdSize, + uchar fourthSize, + uchar fifthSize, + uchar alphaSize, + AlphaUsage alphaUsage, + AlphaPosition alphaPosition, + AlphaPremultiplied premultiplied, + TypeInterpretation typeInterpretation, + ByteOrder byteOrder = CurrentSystemEndian, + uchar subEnum = 0) + + Creates a QPixelFormat which assigns its data to the attributes. + \a colorModel will be put into a buffer which is 4 bits long. + + \a firstSize \a secondSize \a thirdSize \a fourthSize \a fifthSize \a + alphaSize are all meant to represent the size of a channel. The channels will + be used for different uses dependent on the \a colorModel. For RGB the + firstSize will represent the Red channel. On CMYK it will represent the + value of the Cyan channel. + + \a alphaUsage represents if the alpha channel is used or not. + + \a alphaPosition is the position of the alpha channel. + + \a premultiplied represents if the alpha channel is already multiplied with + the color channels. + + \a typeInterpretation is how the pixel is interpreted. + + \a byteOrder represents the endianness of the pixelformat. This defaults to + CurrentSystemEndian. + + \a subEnum is used for colorModels that have to store some extra + information with supplying an extra enum. This is used by YUV to store the + YUV type The default value is 0. +*/ + +Q_STATIC_ASSERT(sizeof(QPixelFormatRgb) == sizeof(QPixelFormat)); + +/*! + \class QPixelFormatRgb + \inmodule QtGui + \since 5.4 + \brief QPixelFormatRgb is a helper class for creating pixel formats with + the rgb color model + + The size of QPixelFormatRgb is guaranteed to be the size of QPixelFormat. +*/ + +/*! + \fn QPixelFormatRgb::QPixelFormatRgb(uchar redSize, + uchar greenSize, + uchar blueSize, + uchar alphaSize, + AlphaUsage alphaUsage, + AlphaPosition alphaPosition, + AlphaPremultiplied premultiplied = NotPremultiplied, + TypeInterpretation typeInterpretation = UnsignedInteger) + + Constructor making an RGB pixelformat. \a redSize \a greenSize \a + blueSize represent the size of each color channel. \a alphaSize describes + the alpha channel size and its position is described with \a alphaPosition. + \a alphaUsage is used to determine if the alpha channel is used or not. + Setting the alpha channel size to 8 and alphaUsage to IgnoresAlpha is how + it is possible to create a 32 bit format where the rgb channels only use 24 + bits combined. \a premultiplied \a typeInterpretation are + accessible with accessors with the same name. + + \sa TypeInterpretation +*/ + +Q_STATIC_ASSERT(sizeof(QPixelFormatGrayScale) == sizeof(QPixelFormat)); +/*! + \class QPixelFormatGrayScale + \inmodule QtGui + \since 5.4 + \brief QPixelFormatGrayScale is a helper class for creating pixel formats with + the gray scale color model. + + The size of QPixelFormatGrayScale is guaranteed to be the size of QPixelFormat. +*/ + +/*! + \fn QPixelFormatGrayScale::QPixelFormatGrayScale(uchar channelSize, + TypeInterpretation typeInterpretation = UnsignedInteger) + + Constructor for creating a GrayScale format. Monochrome formats can be + described by passing 1 to \a channelSize. Its also possible to define very + accurate greyscale formats using doubles to describe each pixel by passing 8 + as \a channelSize and FloatingPoint as \a typeInterpretation. + + \sa TypeInterpretation +*/ + +Q_STATIC_ASSERT(sizeof(QPixelFormatCmyk) == sizeof(QPixelFormat)); +/*! + \class QPixelFormatCmyk + \inmodule QtGui + \since 5.4 + \brief QPixelFormatCmyk is a helper class for creating pixel formats with + the CMYK color model + + The size of QPixelFormatCmyk is guaranteed to be the size of QPixelFormat. +*/ + +/*! + \fn QPixelFormatCmyk::QPixelFormatCmyk(uchar channelSize, + uchar alphaSize = 0, + AlphaUsage alphaUsage = IgnoresAlpha, + AlphaPosition alphaPosition = AtBeginning, + TypeInterpretation typeInterpretation = UnsignedInteger) + + Constructor for creating CMYK formats. The channel count will be 4 or + 5 depending on if \a alphaSize is bigger than zero or not. The CMYK color + channels will all be set to the value of \a channelSize. + + \a alphaUsage \a alphaPosition and \a typeInterpretation are all accessible with + the accessors with the same name. + + \sa TypeInterpretation +*/ + +Q_STATIC_ASSERT(sizeof(QPixelFormatHsl) == sizeof(QPixelFormat)); +/*! + \class QPixelFormatHsl + \inmodule QtGui + \since 5.4 + \brief QPixelFormatHsl is a helper class for creating pixel formats with + the HSL color model. + + The size of QPixelFormatHsl is guaranteed to be the size of QPixelFormat. +*/ + +/*! + \fn QPixelFormatHsl::QPixelFormatHsl(uchar channelSize, + uchar alphaSize = 0, + AlphaUsage alphaUsage = IgnoresAlpha, + AlphaPosition alphaPosition = AtBeginning, + TypeInterpretation typeInterpretation = FloatingPoint) + + Constructor for creating HSL formats. The channel count will be 3 or 4 + depending on if \a alphaSize is bigger than 0. + + \a channelSize will set the hueSize saturationSize and lightnessSize to the same value. + + \a alphaUsage \a alphaPosition and \a typeInterpretation are all accessible with + the accessors with the same name. +*/ + +Q_STATIC_ASSERT(sizeof(QPixelFormatHsv) == sizeof(QPixelFormat)); +/*! + \class QPixelFormatHsv + \inmodule QtGui + \since 5.4 + \brief QPixelFormatHsv is a helper class for creating pixel formats with + the HSV color model. + + The size of QPixelFormatHsv is guaranteed to be the size of QPixelFormat. +*/ + +/*! + \fn QPixelFormatHsv::QPixelFormatHsv(uchar channelSize, + uchar alphaSize = 0, + AlphaUsage alphaUsage = IgnoresAlpha, + AlphaPosition alphaPosition = AtBeginning, + TypeInterpretation typeInterpretation = FloatingPoint) + + Constructor for creating HSV formats. The channel count will be 3 or 4 + depending on if \a alphaSize is bigger than 0. + + \a channelSize will set the hueSize saturationSize and brightnessSize to the same value. + + \a alphaUsage \a alphaPosition and \a typeInterpretation are all accessible with + the accessors with the same name. +*/ + +Q_STATIC_ASSERT(sizeof(QPixelFormatYuv) == sizeof(QPixelFormat)); +/*! + \class QPixelFormatYuv + \inmodule QtGui + \since 5.4 + \brief QPixelFormatYuv is a helper class for creating pixel formats with + the YUV color model. + + The size of QPixelFormatYuv is guaranteed to be the size of QPixelFormat. +*/ + +/*! + \fn QPixelFormatYuv::QPixelFormatYuv(YUVLayout yuvLayout, + uchar alphaSize = 0, + AlphaUsage alphaUsage = IgnoresAlpha, + AlphaPosition alphaPosition = AtBeginning, + AlphaPremultiplied premultiplied = NotPremultiplied, + TypeInterpretation typeInterpretation = UnsignedByte, + ByteOrder byteOrder = LittleEndian) + + Constructor for creating a QPixelFormat describing a YUV format with + \a yuvLayout. \a alphaSize describes the size of a potential alpha channel + and is position is described with \a alphaPosition. The "first" "second" .. + "fifth" channels are all set to 0. \a alphaUsage \a premultiplied \a + typeInterpretation and \a byteOrder will work as with other formats. +*/ + +/*! + \fn ColorModel QPixelFormat::colorModel() const + + Accessor function for getting the colorModel. +*/ + +/*! + \fn uchar QPixelFormat::channelCount() const + + Accessor function for getting the channelCount. Channel Count is deduced + by color channels with a size > 0 and if the size of the alpha channel is > 0. +*/ + +/*! + \fn uchar QPixelFormat::redSize() const + + Accessor function for the size of the red color channel. +*/ + +/*! + \fn uchar QPixelFormat::greenSize() const + + Accessor function for the size of the green color channel. +*/ + +/*! + \fn uchar QPixelFormat::blueSize() const + + Accessor function for the size of the blue color channel. +*/ + +/*! + \fn uchar QPixelFormat::cyanSize() const + + Accessor function for the cyan color channel. +*/ + +/*! + \fn uchar QPixelFormat::magentaSize() const + + Accessor function for the megenta color channel. +*/ + +/*! + \fn uchar QPixelFormat::yellowSize() const + + Accessor function for the yellow color channel. +*/ + +/*! + \fn uchar QPixelFormat::blackSize() const + + Accessor function for the black/key color channel. +*/ + +/*! + \fn uchar QPixelFormat::hueSize() const + + Accessor function for the hue channel size. +*/ + +/*! + \fn uchar QPixelFormat::saturationSize() const + + Accessor function for the saturation channel size. +*/ + +/*! + \fn uchar QPixelFormat::lightnessSize() const + + Accessor function for the lightness channel size. +*/ + +/*! + \fn uchar QPixelFormat::brightnessSize() const + + Accessor function for the brightness channel size. +*/ + +/*! + \fn uchar QPixelFormat::alphaSize() const + + Accessor function for the alpha channel size. +*/ + +/*! + \fn uchar QPixelFormat::bitsPerPixel() const + + Accessor function for the bits used per pixel. This function returns the + sum of the color channels + the size of the alpha channel. +*/ + +/*! + \fn AlphaPremultiplied QPixelFormat::premultiplied() const + + Accessor function for the AlphaPremultiplied enum. This indicates if the + alpha channel is multiplied in to the color channels. + +*/ + +/*! + \fn TypeInterpretation QPixelFormat::typeInterpretation() const + + Accessor function for the type representation of a color channel or a pixel. + + \sa TypeInterpretation +*/ + +/*! + \fn ByteOrder QPixelFormat::byteOrder() const + + The byte order is almost always set the the byte order of the current + system. However, it can be useful to describe some YUV formats. This + function should never return QPixelFormat::CurrentSystemEndian as this + value is translated to a endian value in the constructor. +*/ + +/*! + \fn AlphaUsage QPixelFormat::alphaUsage() const + + Accessor function for alphaUsage. +*/ + +/*! + \fn AlphaPosition QPixelFormat::alphaPosition() const + + Accessor function for alphaPosition. +*/ + +/*! + \fn YUVLayout QPixelFormat::yuvLayout() const + + Accessor function for the YUVLayout. It is difficult to describe the color + channels of a YUV pixel format since YUV color model uses macro pixels. + Instead the layout of the pixels are stored as an enum. +*/ + +/*! + \fn uchar QPixelFormat::subEnum() const + + Accessor for the datapart which contains subEnums + This is the same as the yuvLayout() function. + + \sa yuvLayout() + \internal +*/ + +Q_STATIC_ASSERT(sizeof(QPixelFormat) == sizeof(quint64)); + + +namespace QtPrivate { + QPixelFormat QPixelFormat_createYUV(QPixelFormat::YUVLayout yuvLayout, + uchar alphaSize, + QPixelFormat::AlphaUsage alphaUsage, + QPixelFormat::AlphaPosition alphaPosition, + QPixelFormat::AlphaPremultiplied premultiplied, + QPixelFormat::TypeInterpretation typeInterpretation, + QPixelFormat::ByteOrder byteOrder) + { + uchar bits_per_pixel = 0; + switch (yuvLayout) { + case QPixelFormat::YUV444: + bits_per_pixel = 24; + break; + case QPixelFormat::YUV422: + bits_per_pixel = 16; + break; + case QPixelFormat::YUV411: + case QPixelFormat::YUV420P: + case QPixelFormat::YUV420SP: + case QPixelFormat::YV12: + bits_per_pixel = 12; + break; + case QPixelFormat::UYVY: + case QPixelFormat::YUYV: + bits_per_pixel = 16; + break; + case QPixelFormat::NV12: + case QPixelFormat::NV21: + bits_per_pixel = 12; + break; + case QPixelFormat::IMC1: + case QPixelFormat::IMC2: + case QPixelFormat::IMC3: + case QPixelFormat::IMC4: + bits_per_pixel = 12; + break; + case QPixelFormat::Y8: + bits_per_pixel = 8; + break; + case QPixelFormat::Y16: + bits_per_pixel = 16; + break; + } + + return QPixelFormat(QPixelFormat::YUV, + 0, 0, 0, 0, + bits_per_pixel, + alphaSize, + alphaUsage, + alphaPosition, + premultiplied, + typeInterpretation, + byteOrder, + yuvLayout); + } +} + +QT_END_NAMESPACE diff --git a/src/gui/kernel/qpixelformat.h b/src/gui/kernel/qpixelformat.h new file mode 100644 index 0000000000..b020a53e6d --- /dev/null +++ b/src/gui/kernel/qpixelformat.h @@ -0,0 +1,452 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPIXELFORMAT_H +#define QPIXELFORMAT_H + +#include + +QT_BEGIN_NAMESPACE + +class QPixelFormat +{ +public: + enum ColorModel { + RGB, + BGR, + Indexed, + GrayScale, + CMYK, + HSL, + HSV, + YUV + }; + + enum AlphaUsage { + UsesAlpha, + IgnoresAlpha + }; + + enum AlphaPosition { + AtBeginning, + AtEnd + }; + + enum AlphaPremultiplied { + NotPremultiplied, + Premultiplied + }; + + enum TypeInterpretation { + UnsignedInteger, + UnsignedShort, + UnsignedByte, + FloatingPoint + }; + + enum YUVLayout { + YUV444, + YUV422, + YUV411, + YUV420P, + YUV420SP, + YV12, + UYVY, + YUYV, + NV12, + NV21, + IMC1, + IMC2, + IMC3, + IMC4, + Y8, + Y16 + }; + + enum ByteOrder { + LittleEndian, + BigEndian, + CurrentSystemEndian + }; + + Q_DECL_CONSTEXPR inline QPixelFormat() Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR inline QPixelFormat(ColorModel colorModel, + uchar firstSize, + uchar secondSize, + uchar thirdSize, + uchar fourthSize, + uchar fifthSize, + uchar alphaSize, + AlphaUsage alphaUsage, + AlphaPosition alphaPosition, + AlphaPremultiplied premultiplied, + TypeInterpretation typeInterpretation, + ByteOrder byteOrder = CurrentSystemEndian, + uchar subEnum = 0) Q_DECL_NOTHROW; + + Q_DECL_CONSTEXPR inline ColorModel colorModel() const Q_DECL_NOTHROW { return ColorModel(model); } + Q_DECL_CONSTEXPR inline uchar channelCount() const Q_DECL_NOTHROW { return (first > 0) + + (second > 0) + + (third > 0) + + (fourth > 0) + + (fifth > 0) + + (alpha > 0); } + + Q_DECL_CONSTEXPR inline uchar redSize() const Q_DECL_NOTHROW { return first; } + Q_DECL_CONSTEXPR inline uchar greenSize() const Q_DECL_NOTHROW { return second; } + Q_DECL_CONSTEXPR inline uchar blueSize() const Q_DECL_NOTHROW { return third; } + + Q_DECL_CONSTEXPR inline uchar cyanSize() const Q_DECL_NOTHROW { return first; } + Q_DECL_CONSTEXPR inline uchar magentaSize() const Q_DECL_NOTHROW { return second; } + Q_DECL_CONSTEXPR inline uchar yellowSize() const Q_DECL_NOTHROW { return third; } + Q_DECL_CONSTEXPR inline uchar blackSize() const Q_DECL_NOTHROW { return fourth; } + + Q_DECL_CONSTEXPR inline uchar hueSize() const Q_DECL_NOTHROW { return first; } + Q_DECL_CONSTEXPR inline uchar saturationSize() const Q_DECL_NOTHROW { return second; } + Q_DECL_CONSTEXPR inline uchar lightnessSize() const Q_DECL_NOTHROW { return third; } + Q_DECL_CONSTEXPR inline uchar brightnessSize() const Q_DECL_NOTHROW { return third; } + + Q_DECL_CONSTEXPR inline uchar alphaSize() const Q_DECL_NOTHROW { return alpha; } + + Q_DECL_CONSTEXPR inline uchar bitsPerPixel() const Q_DECL_NOTHROW { return first + + second + + third + + fourth + + fifth + + alpha; } + + Q_DECL_CONSTEXPR inline AlphaUsage alphaUsage() const Q_DECL_NOTHROW { return AlphaUsage(alpha_usage); } + Q_DECL_CONSTEXPR inline AlphaPosition alphaPosition() const Q_DECL_NOTHROW { return AlphaPosition(alpha_position); } + Q_DECL_CONSTEXPR inline AlphaPremultiplied premultiplied() const Q_DECL_NOTHROW { return AlphaPremultiplied(premul); } + Q_DECL_CONSTEXPR inline TypeInterpretation typeInterpretation() const Q_DECL_NOTHROW { return TypeInterpretation(type_interpretation); } + Q_DECL_CONSTEXPR inline ByteOrder byteOrder() const Q_DECL_NOTHROW { return ByteOrder(byte_order); } + + Q_DECL_CONSTEXPR inline YUVLayout yuvLayout() const Q_DECL_NOTHROW { return YUVLayout(sub_enum); } + Q_DECL_CONSTEXPR inline uchar subEnum() const Q_DECL_NOTHROW { return sub_enum; } + +protected: + quint64 model : 4; + quint64 first : 6; + quint64 second : 6; + quint64 third : 6; + quint64 fourth : 6; + quint64 fifth : 6; + quint64 alpha : 6; + quint64 alpha_usage : 1; + quint64 alpha_position : 1; + quint64 premul: 1; + quint64 type_interpretation : 4; + quint64 byte_order : 2; + quint64 sub_enum : 6; + quint64 unused : 8; + + friend Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline bool operator==(const QPixelFormat &fmt1, const QPixelFormat &fmt2); + friend Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline bool operator!=(const QPixelFormat &fmt1, const QPixelFormat &fmt2); +}; +Q_DECLARE_TYPEINFO(QPixelFormat, Q_PRIMITIVE_TYPE); + +class QPixelFormatRgb : public QPixelFormat +{ +public: + Q_DECL_CONSTEXPR + inline QPixelFormatRgb(uchar redSize, + uchar greenSize, + uchar blueSize, + uchar alphaSize, + AlphaUsage alphaUsage, + AlphaPosition alphaPosition, + AlphaPremultiplied premultiplied = NotPremultiplied, + TypeInterpretation typeInterpretation = UnsignedInteger) Q_DECL_NOTHROW; +}; + +class QPixelFormatGrayScale : public QPixelFormat +{ +public: + Q_DECL_CONSTEXPR + inline QPixelFormatGrayScale(uchar bufferSize, + TypeInterpretation typeInterpretation = UnsignedInteger) Q_DECL_NOTHROW; +}; + +class QPixelFormatCmyk : public QPixelFormat +{ +public: + Q_DECL_CONSTEXPR + inline QPixelFormatCmyk(uchar channelSize, + uchar alphaSize = 0, + AlphaUsage alphaUsage = IgnoresAlpha, + AlphaPosition alphaPosition = AtBeginning, + TypeInterpretation typeInterpretation = UnsignedInteger) Q_DECL_NOTHROW; +}; + +class QPixelFormatHsl : public QPixelFormat +{ +public: + Q_DECL_CONSTEXPR + inline QPixelFormatHsl(uchar channelSize, + uchar alphaSize = 0, + AlphaUsage alphaUsage = IgnoresAlpha, + AlphaPosition alphaPosition = AtBeginning, + TypeInterpretation typeInterpretation = FloatingPoint) Q_DECL_NOTHROW; +}; + +class QPixelFormatHsv : public QPixelFormat +{ +public: + Q_DECL_CONSTEXPR + inline QPixelFormatHsv(uchar channelSize, + uchar alphaSize = 0, + AlphaUsage alphaUsage = IgnoresAlpha, + AlphaPosition alphaPosition = AtBeginning, + TypeInterpretation typeInterpretation = FloatingPoint) Q_DECL_NOTHROW; +}; + +namespace QtPrivate { + QPixelFormat Q_GUI_EXPORT QPixelFormat_createYUV(QPixelFormat::YUVLayout yuvLayout, + uchar alphaSize, + QPixelFormat::AlphaUsage alphaUsage, + QPixelFormat::AlphaPosition alphaPosition, + QPixelFormat::AlphaPremultiplied premultiplied, + QPixelFormat::TypeInterpretation typeInterpretation, + QPixelFormat::ByteOrder byteOrder); +} + +class QPixelFormatYuv : public QPixelFormat +{ +public: + inline QPixelFormatYuv(YUVLayout yuvLayout, + uchar alphaSize = 0, + AlphaUsage alphaUsage = IgnoresAlpha, + AlphaPosition alphaPosition = AtBeginning, + AlphaPremultiplied premultiplied = NotPremultiplied, + TypeInterpretation typeInterpretation = UnsignedByte, + ByteOrder byteOrder = LittleEndian); +}; + +Q_DECL_CONSTEXPR +QPixelFormat::QPixelFormat() Q_DECL_NOTHROW + : model(0) + , first(0) + , second(0) + , third(0) + , fourth(0) + , fifth(0) + , alpha(0) + , alpha_usage(0) + , alpha_position(0) + , premul(0) + , type_interpretation(0) + , byte_order(0) + , sub_enum(0) + , unused(0) +{ +} + +Q_DECL_CONSTEXPR +QPixelFormat::QPixelFormat(ColorModel mdl, + uchar firstSize, + uchar secondSize, + uchar thirdSize, + uchar fourthSize, + uchar fifthSize, + uchar alfa, + AlphaUsage usage, + AlphaPosition position, + AlphaPremultiplied premult, + TypeInterpretation typeInterp, + ByteOrder b_order, + uchar s_enum) Q_DECL_NOTHROW + : model(mdl) + , first(firstSize) + , second(secondSize) + , third(thirdSize) + , fourth(fourthSize) + , fifth(fifthSize) + , alpha(alfa) + , alpha_usage(usage) + , alpha_position(position) + , premul(premult) + , type_interpretation(typeInterp) +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN + , byte_order(b_order == CurrentSystemEndian ? LittleEndian : b_order) +#else + , byte_order(b_order == CurrentSystemEndian ? BigEndian : b_order) +#endif + , sub_enum(s_enum) + , unused(0) +{ +} + +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline bool operator==(const QPixelFormat &fmt1, const QPixelFormat &fmt2) +{ + return fmt1.model == fmt2.model + && fmt1.first == fmt2.first + && fmt1.second == fmt2.second + && fmt1.third == fmt2.third + && fmt1.fourth == fmt2.fourth + && fmt1.fifth == fmt2.fifth + && fmt1.alpha == fmt2.alpha + && fmt1.alpha_usage == fmt2.alpha_usage + && fmt1.alpha_position == fmt2.alpha_position + && fmt1.premul == fmt2.premul + && fmt1.type_interpretation == fmt2.type_interpretation + && fmt1.byte_order == fmt2.byte_order + && fmt1.sub_enum == fmt2.sub_enum + && fmt1.unused == fmt2.unused; +} + +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline bool operator!=(const QPixelFormat &fmt1, const QPixelFormat &fmt2) +{ return !(fmt1 == fmt2); } + +Q_DECL_CONSTEXPR +QPixelFormatRgb::QPixelFormatRgb(uchar red, + uchar green, + uchar blue, + uchar alfa, + AlphaUsage usage, + AlphaPosition position, + AlphaPremultiplied pmul, + TypeInterpretation typeInt) Q_DECL_NOTHROW + : QPixelFormat(RGB, + red, + green, + blue, + 0, + 0, + alfa, + usage, + position, + pmul, + typeInt) +{ } + +Q_DECL_CONSTEXPR +QPixelFormatGrayScale::QPixelFormatGrayScale(uchar channelSize, + TypeInterpretation typeInt) Q_DECL_NOTHROW + : QPixelFormat(GrayScale, + channelSize, + 0, + 0, + 0, + 0, + 0, + IgnoresAlpha, + AtBeginning, + NotPremultiplied, + typeInt) +{ } + +Q_DECL_CONSTEXPR +QPixelFormatCmyk::QPixelFormatCmyk(uchar channelSize, + uchar alfa, + AlphaUsage usage, + AlphaPosition position, + TypeInterpretation typeInt) Q_DECL_NOTHROW + : QPixelFormat(CMYK, + channelSize, + channelSize, + channelSize, + channelSize, + 0, + alfa, + usage, + position, + NotPremultiplied, + typeInt) +{ } + +Q_DECL_CONSTEXPR +QPixelFormatHsl::QPixelFormatHsl(uchar channelSize, + uchar alfa, + AlphaUsage usage, + AlphaPosition position, + TypeInterpretation typeInt) Q_DECL_NOTHROW + : QPixelFormat(HSL, + channelSize, + channelSize, + channelSize, + 0, + 0, + alfa, + usage, + position, + NotPremultiplied, + typeInt) +{ } + +Q_DECL_CONSTEXPR +QPixelFormatHsv::QPixelFormatHsv(uchar channelSize, + uchar alfa, + AlphaUsage usage, + AlphaPosition position, + TypeInterpretation typeInt) Q_DECL_NOTHROW + : QPixelFormat(HSV, + channelSize, + channelSize, + channelSize, + 0, + 0, + alfa, + usage, + position, + NotPremultiplied, + typeInt) +{ } + +QPixelFormatYuv::QPixelFormatYuv(YUVLayout layout, + uchar alfa, + AlphaUsage usage, + AlphaPosition position, + AlphaPremultiplied p_mul, + TypeInterpretation typeInt, + ByteOrder b_order) + : QPixelFormat(QtPrivate::QPixelFormat_createYUV(layout, + alfa, + usage, + position, + p_mul, + typeInt, + b_order)) + +{ } + +QT_END_NAMESPACE + +#endif //QPIXELFORMAT_H -- cgit v1.2.3