Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qvideoframeformat.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qvideoframeformat.h"
6
7#include <qdebug.h>
8#include <qlist.h>
9#include <qmetatype.h>
10#include <qpair.h>
11#include <qvariant.h>
12#include <qmatrix4x4.h>
13
14static void initResource() {
16}
17
19
21{
22public:
24
26 const QSize &size,
30 , viewport(QPoint(0, 0), size)
31 {
32 }
33
35 {
36 if (pixelFormat == other.pixelFormat
37 && scanLineDirection == other.scanLineDirection
38 && frameSize == other.frameSize
39 && viewport == other.viewport
40 && frameRatesEqual(frameRate, other.frameRate)
41 && colorSpace == other.colorSpace
42 && mirrored == other.mirrored)
43 return true;
44
45 return false;
46 }
47
48 inline static bool frameRatesEqual(qreal r1, qreal r2)
49 {
50 return qAbs(r1 - r2) <= 0.00001 * qMin(qAbs(r1), qAbs(r2));
51 }
52
60 float frameRate = 0.0;
61 float maxLuminance = -1.;
62 bool mirrored = false;
63};
64
66
350{
351 initResource();
352}
353
360{
361}
362
367
384
395
402{
403 return d->pixelFormat != Format_Invalid && d->frameSize.isValid();
404}
405
410{
411 return d == other.d || *d == *other.d;
412}
413
418{
419 return d != other.d && !(*d == *other.d);
420}
421
426{
427 d.detach();
428}
429
434{
435 return d->pixelFormat;
436}
437
444{
445 return d->frameSize;
446}
447
454{
455 return d->frameSize.width();
456}
457
462{
463 return d->frameSize.height();
464}
465
473{
475}
476
483{
484 detach();
485 d->frameSize = size;
486 d->viewport = QRect(QPoint(0, 0), size);
487}
488
497{
498 detach();
500 d->viewport = QRect(0, 0, width, height);
501}
502
511{
512 return d->viewport;
513}
514
519{
520 detach();
521 d->viewport = viewport;
522}
523
528{
529 return d->scanLineDirection;
530}
531
536{
537 detach();
539}
540
545{
546 return d->frameRate;
547}
548
553{
554 detach();
555 d->frameRate = rate;
556}
557
558#if QT_DEPRECATED_SINCE(6, 4)
564QVideoFrameFormat::YCbCrColorSpace QVideoFrameFormat::yCbCrColorSpace() const
565{
566 return YCbCrColorSpace(d->colorSpace);
567}
568
575void QVideoFrameFormat::setYCbCrColorSpace(QVideoFrameFormat::YCbCrColorSpace space)
576{
577 detach();
578 d->colorSpace = ColorSpace(space);
579}
580#endif // QT_DEPRECATED_SINCE(6, 4)
581
586{
587 return d->colorSpace;
588}
589
594{
595 detach();
597}
598
604{
605 return d->colorTransfer;
606}
607
613{
614 detach();
616}
617
623{
624 return d->colorRange;
625}
626
632{
633 detach();
634 d->colorRange = range;
635}
636
647{
648 return d->mirrored;
649}
650
662{
663 detach();
664 d->mirrored = mirrored;
665}
666
671{
673}
674
679{
681}
682
687{
689}
690
698{
699 if (d->maxLuminance <= 0) {
701 return 10000.; // ST2084 can encode up to 10000 nits
703 return 1500.; // SRD_B67 can encode up to 1200 nits, use a bit more for some headroom
704 return 100; // SDR
705 }
706 return d->maxLuminance;
707}
712{
713 detach();
714 d->maxLuminance = lum;
715}
716
717
726{
727 switch (format) {
728#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
735#else
742#endif
753 default:
755 }
756}
757
766{
767 switch (format) {
768#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
779#else
790#endif
822 }
824}
825
830{
831 switch (pixelFormat) {
833 return QStringLiteral("Invalid");
835 return QStringLiteral("ARGB8888");
837 return QStringLiteral("ARGB8888 Premultiplied");
839 return QStringLiteral("XRGB8888");
841 return QStringLiteral("BGRA8888");
843 return QStringLiteral("BGRX8888");
845 return QStringLiteral("BGRA8888 Premultiplied");
847 return QStringLiteral("RGBA8888");
849 return QStringLiteral("RGBX8888");
851 return QStringLiteral("ABGR8888");
853 return QStringLiteral("XBGR8888");
855 return QStringLiteral("AYUV");
857 return QStringLiteral("AYUV Premultiplied");
859 return QStringLiteral("YUV420P");
861 return QStringLiteral("YUV420P10");
863 return QStringLiteral("YUV422P");
865 return QStringLiteral("YV12");
867 return QStringLiteral("UYVY");
869 return QStringLiteral("YUYV");
871 return QStringLiteral("NV12");
873 return QStringLiteral("NV21");
875 return QStringLiteral("IMC1");
877 return QStringLiteral("IMC2");
879 return QStringLiteral("IMC3");
881 return QStringLiteral("IMC4");
883 return QStringLiteral("Y8");
885 return QStringLiteral("Y16");
887 return QStringLiteral("P010");
889 return QStringLiteral("P016");
891 return QStringLiteral("SamplerExternalOES");
893 return QStringLiteral("Jpeg");
895 return QStringLiteral("SamplerRect");
896 }
897
898 return QStringLiteral("");
899}
900
901#ifndef QT_NO_DEBUG_STREAM
902# if QT_DEPRECATED_SINCE(6, 4)
903QDebug operator<<(QDebug dbg, QVideoFrameFormat::YCbCrColorSpace cs)
904{
905 QDebugStateSaver saver(dbg);
906 dbg.nospace();
907 switch (cs) {
908 case QVideoFrameFormat::YCbCr_BT601:
909 dbg << "YCbCr_BT601";
910 break;
911 case QVideoFrameFormat::YCbCr_BT709:
912 dbg << "YCbCr_BT709";
913 break;
914 case QVideoFrameFormat::YCbCr_JPEG:
915 dbg << "YCbCr_JPEG";
916 break;
917 case QVideoFrameFormat::YCbCr_xvYCC601:
918 dbg << "YCbCr_xvYCC601";
919 break;
920 case QVideoFrameFormat::YCbCr_xvYCC709:
921 dbg << "YCbCr_xvYCC709";
922 break;
923 case QVideoFrameFormat::YCbCr_BT2020:
924 dbg << "YCbCr_BT2020";
925 break;
926 default:
927 dbg << "YCbCr_Undefined";
928 break;
929 }
930 return dbg;
931}
932# endif // QT_DEPRECATED_SINCE(6, 4)
933
935{
936 QDebugStateSaver saver(dbg);
937 dbg.nospace();
938 switch (cs) {
940 dbg << "ColorSpace_BT601";
941 break;
943 dbg << "ColorSpace_BT709";
944 break;
946 dbg << "ColorSpace_AdobeRgb";
947 break;
949 dbg << "ColorSpace_BT2020";
950 break;
951 default:
952 dbg << "ColorSpace_Undefined";
953 break;
954 }
955 return dbg;
956}
957
959{
960 QDebugStateSaver saver(dbg);
961 dbg.nospace();
962 switch (dir) {
964 dbg << "BottomToTop";
965 break;
967 dbg << "TopToBottom";
968 break;
969 }
970 return dbg;
971}
972
974{
975 QDebugStateSaver saver(dbg);
976 dbg.nospace();
977 dbg << "QVideoFrameFormat(" << f.pixelFormat() << ", " << f.frameSize()
978 << ", viewport=" << f.viewport()
979 << ", colorSpace=" << f.colorSpace()
980 << ')'
981 << "\n pixel format=" << f.pixelFormat()
982 << "\n frame size=" << f.frameSize()
983 << "\n viewport=" << f.viewport()
984 << "\n colorSpace=" << f.colorSpace()
985 << "\n frameRate=" << f.frameRate()
986 << "\n mirrored=" << f.isMirrored();
987
988 return dbg;
989}
990
992{
993 QDebugStateSaver saver(dbg);
994 dbg.nospace();
995
997 if (format.isEmpty())
998 return dbg;
999
1000 dbg.noquote() << QStringLiteral("Format_") << format;
1001 return dbg;
1002}
1003#endif
1004
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
\inmodule QtCore
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_Grayscale16
Definition qimage.h:70
@ Format_RGBA8888
Definition qimage.h:59
@ Format_RGB32
Definition qimage.h:46
@ Format_Invalid
Definition qimage.h:42
@ Format_RGBA8888_Premultiplied
Definition qimage.h:60
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
@ Format_ARGB32
Definition qimage.h:47
@ Format_RGBX8888
Definition qimage.h:58
@ Format_Grayscale8
Definition qimage.h:66
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qshareddata.h:19
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:126
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QVideoFrameFormatPrivate(const QSize &size, QVideoFrameFormat::PixelFormat format)
QVideoFrameFormat::ColorSpace colorSpace
QVideoFrameFormat::Direction scanLineDirection
QVideoFrameFormat::PixelFormat pixelFormat
QVideoFrameFormat::ColorRange colorRange
static bool frameRatesEqual(qreal r1, qreal r2)
bool operator==(const QVideoFrameFormatPrivate &other) const
QVideoFrameFormatPrivate()=default
QVideoFrameFormat::ColorTransfer colorTransfer
The QVideoFrameFormat class specifies the stream format of a video presentation surface.
ColorRange colorRange() const
Returns the color range that should be used to render the video stream.
void setViewport(const QRect &viewport)
Sets the viewport of a video stream to viewport.
bool isValid() const
Identifies if a video surface format has a valid pixel format and frame size.
bool isMirrored() const
Returns true if the surface is mirrored around its vertical axis.
ColorSpace
Enumerates the color space of video frames.
void setMaxLuminance(float lum)
Sets the maximum luminance to the given value, lum.
void setColorRange(ColorRange range)
Sets the color transfer range that should be used to render the video stream to range.
ColorTransfer
\value ColorTransfer_Unknown The color transfer function is unknown.
PixelFormat
Enumerates video data types.
void setScanLineDirection(Direction direction)
Sets the direction of scan lines.
bool operator!=(const QVideoFrameFormat &format) const
Returns true if other is different to this video format, and false if they are the same.
void setFrameSize(const QSize &size)
Sets the size of frames in a video stream to size.
void setColorSpace(ColorSpace colorSpace)
Sets the colorSpace of a video stream.
QRect viewport() const
Returns the viewport of a video stream.
Direction scanLineDirection() const
Returns the direction of scan lines.
int planeCount() const
Returns the number of planes used.
void setColorTransfer(ColorTransfer colorTransfer)
Sets the color transfer function that should be used to render the video stream to colorTransfer.
static QString pixelFormatToString(QVideoFrameFormat::PixelFormat pixelFormat)
Returns a string representation of the given pixelFormat.
bool operator==(const QVideoFrameFormat &format) const
Returns true if other is the same as this video format, and false if they are different.
QVideoFrameFormat::PixelFormat pixelFormat() const
Returns the pixel format of frames in a video stream.
static QImage::Format imageFormatFromPixelFormat(PixelFormat format)
Returns an image format equivalent to a video frame pixel format.
int frameWidth() const
Returns the width of frames in a video stream.
void setFrameRate(qreal rate)
Sets the frame rate of a video stream in frames per second.
qreal frameRate() const
Returns the frame rate of a video stream in frames per second.
Direction
Enumerates the layout direction of video scan lines.
ColorTransfer colorTransfer() const
Returns the color transfer function that should be used to render the video stream.
void updateUniformData(QByteArray *dst, const QVideoFrame &frame, const QMatrix4x4 &transform, float opacity) const
QVideoFrameFormat & operator=(const QVideoFrameFormat &format)
Assigns the values of other to this object.
~QVideoFrameFormat()
Destroys a video stream description.
int frameHeight() const
Returns the height of frame in a video stream.
void setMirrored(bool mirrored)
Sets if the surface is mirrored around its vertical axis.
QVideoFrameFormat()
Constructs a null video stream format.
QSize frameSize() const
Returns the dimensions of frames in a video stream.
QString fragmentShaderFileName() const
static PixelFormat pixelFormatFromImageFormat(QImage::Format format)
Returns a video pixel format equivalent to an image format.
ColorRange
Describes the color range used by the video data.
ColorSpace colorSpace() const
Returns the color space of a video stream.
QString vertexShaderFileName() const
The QVideoFrame class represents a frame of video data.
Definition qvideoframe.h:26
direction
Combined button and popup list for selecting options.
QString vertexShaderFileName(const QVideoFrameFormat &format)
QString fragmentShaderFileName(const QVideoFrameFormat &format, QRhiSwapChain::Format surfaceFormat)
const TextureDescription * textureDescription(QVideoFrameFormat::PixelFormat format)
void updateUniformData(QByteArray *dst, const QVideoFrameFormat &format, const QVideoFrame &frame, const QMatrix4x4 &transform, float opacity, float maxNits)
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLfloat GLfloat f
GLsizei range
GLint GLsizei width
GLenum GLenum dst
GLint GLsizei GLsizei GLenum format
GLuint GLenum GLenum transform
GLuint GLenum * rate
GLsizei GLsizei GLuint * shaders
Definition qopenglext.h:677
#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class)
#define QStringLiteral(str)
#define Q_INIT_RESOURCE(name)
Definition qtresource.h:14
double qreal
Definition qtypes.h:92
QDebug operator<<(QDebug dbg, QVideoFrameFormat::ColorSpace cs)
static void initResource()
QRect r1(100, 200, 11, 16)
[0]
QRect r2(QPoint(100, 200), QSize(11, 16))
QSharedPointer< T > other(t)
[5]
QString dir
[11]
view viewport() -> scroll(dx, dy, deviceRect)
QFrame frame
[0]