6#include <QtMultimedia/private/qvideotexturehelper_p.h>
7#include <QtMultimedia/private/qvideotransformation_p.h>
8#include <QtMultimedia/private/qmultimedia_enum_to_string_converter_p.h>
14#include <qmatrix4x4.h>
17 Q_INIT_RESOURCE(qtmultimedia_shaders);
22class QVideoFrameFormatPrivate :
public QSharedData
25 QVideoFrameFormatPrivate() =
default;
27 QVideoFrameFormatPrivate(
29 QVideoFrameFormat::PixelFormat format)
32 , viewport(QPoint(0, 0), size)
36 bool operator ==(
const QVideoFrameFormatPrivate &other)
const
38 if (pixelFormat == other.pixelFormat && scanLineDirection == other.scanLineDirection
39 && frameSize == other.frameSize && viewport == other.viewport
40 && frameRatesEqual(frameRate, other.frameRate) && colorSpace == other.colorSpace
41 && transformation == other.transformation)
47 inline static bool frameRatesEqual(qreal r1, qreal r2)
49 return qAbs(r1 - r2) <= 0.00001 * qMin(qAbs(r1), qAbs(r2));
52 QVideoFrameFormat::PixelFormat pixelFormat = QVideoFrameFormat::Format_Invalid;
53 QVideoFrameFormat::Direction scanLineDirection = QVideoFrameFormat::TopToBottom;
55 QVideoFrameFormat::ColorSpace colorSpace = QVideoFrameFormat::ColorSpace_Undefined;
56 QVideoFrameFormat::ColorTransfer colorTransfer = QVideoFrameFormat::ColorTransfer_Unknown;
57 QVideoFrameFormat::ColorRange colorRange = QVideoFrameFormat::ColorRange_Unknown;
59 float frameRate = 0.0;
60 float maxLuminance = -1.;
61 VideoTransformation transformation;
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
219
220
221
222
223
224
225
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
345
346
347QVideoFrameFormat::QVideoFrameFormat()
348 : d(
new QVideoFrameFormatPrivate)
354
355
356QVideoFrameFormat::QVideoFrameFormat(
357 const QSize& size, QVideoFrameFormat::PixelFormat format)
358 : d(
new QVideoFrameFormatPrivate(size, format))
363
364
365QVideoFrameFormat::QVideoFrameFormat(
const QVideoFrameFormat &other) =
default;
368
369
370
371
374
375
376
377
380
381
382QVideoFrameFormat &QVideoFrameFormat::operator =(
const QVideoFrameFormat &other) =
default;
385
386
387
388
391
392
393QVideoFrameFormat::~QVideoFrameFormat() =
default;
396
397
398
399
400bool QVideoFrameFormat::isValid()
const
402 return d->pixelFormat != Format_Invalid && d->frameSize.isValid();
406
407
408bool QVideoFrameFormat::operator ==(
const QVideoFrameFormat &other)
const
410 return d == other.d || *d == *other.d;
414
415
416bool QVideoFrameFormat::operator !=(
const QVideoFrameFormat &other)
const
418 return d != other.d && !(*d == *other.d);
422
423
424void QVideoFrameFormat::detach()
430
431
432QVideoFrameFormat::PixelFormat QVideoFrameFormat::pixelFormat()
const
434 return d->pixelFormat;
438
439
440
441
442QSize QVideoFrameFormat::frameSize()
const
448
449
450
451
452int QVideoFrameFormat::frameWidth()
const
454 return d->frameSize.width();
458
459
460int QVideoFrameFormat::frameHeight()
const
462 return d->frameSize.height();
466
467
468
469
470
471int QVideoFrameFormat::planeCount()
const
473 return QVideoTextureHelper::textureDescription(d->pixelFormat)->nplanes;
477
478
479
480
481void QVideoFrameFormat::setFrameSize(
const QSize &size)
485 d->viewport = QRect(QPoint(0, 0), size);
489
490
491
492
493
494
495void QVideoFrameFormat::setFrameSize(
int width,
int height)
498 d->frameSize = QSize(width, height);
499 d->viewport = QRect(0, 0, width, height);
503
504
505
506
507
508
509QRect QVideoFrameFormat::viewport()
const
515
516
517void QVideoFrameFormat::setViewport(
const QRect &viewport)
520 d->viewport = viewport;
524
525
526QVideoFrameFormat::Direction QVideoFrameFormat::scanLineDirection()
const
528 return d->scanLineDirection;
532
533
534void QVideoFrameFormat::setScanLineDirection(Direction direction)
537 d->scanLineDirection = direction;
540#if QT_DEPRECATED_SINCE(6
, 8
)
542
543
544qreal QVideoFrameFormat::frameRate()
const
546 return streamFrameRate();
550
551
552void QVideoFrameFormat::setFrameRate(qreal rate)
554 setStreamFrameRate(rate);
559
560
561qreal QVideoFrameFormat::streamFrameRate()
const
567
568
569void QVideoFrameFormat::setStreamFrameRate(qreal rate)
575#if QT_DEPRECATED_SINCE(6
, 4
)
577
578
579
580
581QVideoFrameFormat::YCbCrColorSpace QVideoFrameFormat::yCbCrColorSpace()
const
583 return YCbCrColorSpace(d->colorSpace);
587
588
589
590
591
592void QVideoFrameFormat::setYCbCrColorSpace(QVideoFrameFormat::YCbCrColorSpace space)
595 d->colorSpace = ColorSpace(space);
600
601
602QVideoFrameFormat::ColorSpace QVideoFrameFormat::colorSpace()
const
604 return d->colorSpace;
608
609
610void QVideoFrameFormat::setColorSpace(ColorSpace colorSpace)
613 d->colorSpace = colorSpace;
617
618
619
620QVideoFrameFormat::ColorTransfer QVideoFrameFormat::colorTransfer()
const
622 return d->colorTransfer;
626
627
628
629void QVideoFrameFormat::setColorTransfer(ColorTransfer colorTransfer)
632 d->colorTransfer = colorTransfer;
636
637
638
639QVideoFrameFormat::ColorRange QVideoFrameFormat::colorRange()
const
641 return d->colorRange;
645
646
647
648void QVideoFrameFormat::setColorRange(ColorRange range)
651 d->colorRange = range;
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669bool QVideoFrameFormat::isMirrored()
const
671 return d->transformation.mirroredHorizontallyAfterRotation;
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691void QVideoFrameFormat::setMirrored(
bool mirrored)
694 d->transformation.mirroredHorizontallyAfterRotation = mirrored;
698
699
700
701
702
703
704
705
706
707QtVideo::Rotation QVideoFrameFormat::rotation()
const
709 return d->transformation.rotation;
713
714
715
716
717
718
719
720
721
722
723
724void QVideoFrameFormat::setRotation(QtVideo::Rotation angle)
727 d->transformation.rotation = angle;
731
732
733QString QVideoFrameFormat::vertexShaderFileName()
const
735 return QVideoTextureHelper::vertexShaderFileName(*
this);
739
740
741QString QVideoFrameFormat::fragmentShaderFileName()
const
743 return QVideoTextureHelper::fragmentShaderFileName(*
this,
nullptr);
747
748
749void QVideoFrameFormat::updateUniformData(QByteArray *dst,
const QVideoFrame &frame,
const QMatrix4x4 &transform,
float opacity)
const
751 QVideoTextureHelper::updateUniformData(dst,
nullptr, *
this, frame, transform, opacity);
755
756
757
758
759
760float QVideoFrameFormat::maxLuminance()
const
762 if (d->maxLuminance <= 0) {
763 if (d->colorTransfer == ColorTransfer_ST2084)
765 if (d->colorTransfer == ColorTransfer_STD_B67)
769 return d->maxLuminance;
772
773
774void QVideoFrameFormat::setMaxLuminance(
float lum)
777 d->maxLuminance = lum;
782
783
784
785
786
787
788QVideoFrameFormat::PixelFormat QVideoFrameFormat::pixelFormatFromImageFormat(QImage::Format format)
791#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
792 case QImage::Format_RGB32:
793 return QVideoFrameFormat::Format_BGRX8888;
794 case QImage::Format_ARGB32:
795 return QVideoFrameFormat::Format_BGRA8888;
796 case QImage::Format_ARGB32_Premultiplied:
797 return QVideoFrameFormat::Format_BGRA8888_Premultiplied;
799 case QImage::Format_RGB32:
800 return QVideoFrameFormat::Format_XRGB8888;
801 case QImage::Format_ARGB32:
802 return QVideoFrameFormat::Format_ARGB8888;
803 case QImage::Format_ARGB32_Premultiplied:
804 return QVideoFrameFormat::Format_ARGB8888_Premultiplied;
806 case QImage::Format_RGBA8888:
807 return QVideoFrameFormat::Format_RGBA8888;
808 case QImage::Format_RGBA8888_Premultiplied:
811 return QVideoFrameFormat::Format_RGBX8888;
812 case QImage::Format_RGBX8888:
813 return QVideoFrameFormat::Format_RGBX8888;
814 case QImage::Format_Grayscale8:
815 return QVideoFrameFormat::Format_Y8;
816 case QImage::Format_Grayscale16:
817 return QVideoFrameFormat::Format_Y16;
819 return QVideoFrameFormat::Format_Invalid;
824
825
826
827
828
829
830QImage::Format QVideoFrameFormat::imageFormatFromPixelFormat(QVideoFrameFormat::PixelFormat format)
833#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
834 case QVideoFrameFormat::Format_BGRA8888:
835 return QImage::Format_ARGB32;
836 case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
837 return QImage::Format_ARGB32_Premultiplied;
838 case QVideoFrameFormat::Format_BGRX8888:
839 return QImage::Format_RGB32;
840 case QVideoFrameFormat::Format_ARGB8888:
841 case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
842 case QVideoFrameFormat::Format_XRGB8888:
843 return QImage::Format_Invalid;
845 case QVideoFrameFormat::Format_ARGB8888:
846 return QImage::Format_ARGB32;
847 case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
848 return QImage::Format_ARGB32_Premultiplied;
849 case QVideoFrameFormat::Format_XRGB8888:
850 return QImage::Format_RGB32;
851 case QVideoFrameFormat::Format_BGRA8888:
852 case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
853 case QVideoFrameFormat::Format_BGRX8888:
854 return QImage::Format_Invalid;
856 case QVideoFrameFormat::Format_RGBA8888:
857 return QImage::Format_RGBA8888;
858 case QVideoFrameFormat::Format_RGBX8888:
859 return QImage::Format_RGBX8888;
860 case QVideoFrameFormat::Format_Y8:
861 return QImage::Format_Grayscale8;
862 case QVideoFrameFormat::Format_Y16:
863 return QImage::Format_Grayscale16;
864 case QVideoFrameFormat::Format_ABGR8888:
865 case QVideoFrameFormat::Format_XBGR8888:
866 case QVideoFrameFormat::Format_AYUV:
867 case QVideoFrameFormat::Format_AYUV_Premultiplied:
868 case QVideoFrameFormat::Format_YUV420P:
869 case QVideoFrameFormat::Format_YUV420P10:
870 case QVideoFrameFormat::Format_YUV422P:
871 case QVideoFrameFormat::Format_YV12:
872 case QVideoFrameFormat::Format_UYVY:
873 case QVideoFrameFormat::Format_YUYV:
874 case QVideoFrameFormat::Format_NV12:
875 case QVideoFrameFormat::Format_NV21:
876 case QVideoFrameFormat::Format_IMC1:
877 case QVideoFrameFormat::Format_IMC2:
878 case QVideoFrameFormat::Format_IMC3:
879 case QVideoFrameFormat::Format_IMC4:
880 case QVideoFrameFormat::Format_P010:
881 case QVideoFrameFormat::Format_P016:
882 case QVideoFrameFormat::Format_Jpeg:
883 case QVideoFrameFormat::Format_Invalid:
884 case QVideoFrameFormat::Format_SamplerExternalOES:
885 case QVideoFrameFormat::Format_SamplerRect:
886 return QImage::Format_Invalid;
888 return QImage::Format_Invalid;
893QT_MM_MAKE_STRING_RESOLVER(QVideoFrameFormat::PixelFormat, QtMultimediaPrivate::EnumName,
894 (QVideoFrameFormat::Format_Invalid,
"Invalid")
895 (QVideoFrameFormat::Format_ARGB8888,
"ARGB8888")
896 (QVideoFrameFormat::Format_ARGB8888_Premultiplied,
"ARGB8888 Premultiplied")
897 (QVideoFrameFormat::Format_XRGB8888,
"XRGB8888")
898 (QVideoFrameFormat::Format_BGRA8888,
"BGRA8888")
899 (QVideoFrameFormat::Format_BGRX8888,
"BGRX8888")
900 (QVideoFrameFormat::Format_BGRA8888_Premultiplied,
"BGRA8888 Premultiplied")
901 (QVideoFrameFormat::Format_RGBA8888,
"RGBA8888")
902 (QVideoFrameFormat::Format_RGBX8888,
"RGBX8888")
903 (QVideoFrameFormat::Format_ABGR8888,
"ABGR8888")
904 (QVideoFrameFormat::Format_XBGR8888,
"XBGR8888")
905 (QVideoFrameFormat::Format_AYUV,
"AYUV")
906 (QVideoFrameFormat::Format_AYUV_Premultiplied,
"AYUV Premultiplied")
907 (QVideoFrameFormat::Format_YUV420P,
"YUV420P")
908 (QVideoFrameFormat::Format_YUV420P10,
"YUV420P10")
909 (QVideoFrameFormat::Format_YUV422P,
"YUV422P")
910 (QVideoFrameFormat::Format_YV12,
"YV12")
911 (QVideoFrameFormat::Format_UYVY,
"UYVY")
912 (QVideoFrameFormat::Format_YUYV,
"YUYV")
913 (QVideoFrameFormat::Format_NV12,
"NV12")
914 (QVideoFrameFormat::Format_NV21,
"NV21")
915 (QVideoFrameFormat::Format_IMC1,
"IMC1")
916 (QVideoFrameFormat::Format_IMC2,
"IMC2")
917 (QVideoFrameFormat::Format_IMC3,
"IMC3")
918 (QVideoFrameFormat::Format_IMC4,
"IMC4")
919 (QVideoFrameFormat::Format_Y8,
"Y8")
920 (QVideoFrameFormat::Format_Y16,
"Y16")
921 (QVideoFrameFormat::Format_P010,
"P010")
922 (QVideoFrameFormat::Format_P016,
"P016")
923 (QVideoFrameFormat::Format_SamplerExternalOES,
"SamplerExternalOES")
924 (QVideoFrameFormat::Format_Jpeg,
"Jpeg")
925 (QVideoFrameFormat::Format_SamplerRect,
"SamplerRect")
928#ifndef QT_NO_DEBUG_STREAM
929# if QT_DEPRECATED_SINCE(6
, 4
)
930QT_MM_MAKE_STRING_RESOLVER(QVideoFrameFormat::YCbCrColorSpace, QtMultimediaPrivate::EnumName,
931 (QVideoFrameFormat::YCbCr_Undefined,
"YCbCr_Undefined")
932 (QVideoFrameFormat::YCbCr_BT601,
"YCbCr_BT601")
933 (QVideoFrameFormat::YCbCr_BT709,
"YCbCr_BT709")
934 (QVideoFrameFormat::YCbCr_xvYCC601,
"YCbCr_xvYCC601")
935 (QVideoFrameFormat::YCbCr_xvYCC709,
"YCbCr_xvYCC709")
936 (QVideoFrameFormat::YCbCr_JPEG,
"YCbCr_JPEG")
937 (QVideoFrameFormat::YCbCr_BT2020,
"YCbCr_BT2020")
939QT_MM_DEFINE_QDEBUG_ENUM(QVideoFrameFormat::YCbCrColorSpace);
942QT_MM_MAKE_STRING_RESOLVER(QVideoFrameFormat::ColorSpace, QtMultimediaPrivate::EnumName,
943 (QVideoFrameFormat::ColorSpace_BT601,
"ColorSpace_BT601")
944 (QVideoFrameFormat::ColorSpace_BT709,
"ColorSpace_BT709")
945 (QVideoFrameFormat::ColorSpace_AdobeRgb,
"ColorSpace_AdobeRgb")
946 (QVideoFrameFormat::ColorSpace_BT2020,
"ColorSpace_BT2020")
947 (QVideoFrameFormat::ColorSpace_Undefined,
"ColorSpace_Undefined")
949QT_MM_DEFINE_QDEBUG_ENUM(QVideoFrameFormat::ColorSpace);
951QT_MM_MAKE_STRING_RESOLVER(QVideoFrameFormat::ColorTransfer, QtMultimediaPrivate::EnumName,
952 (QVideoFrameFormat::ColorTransfer_Unknown,
"ColorTransfer_Unknown")
953 (QVideoFrameFormat::ColorTransfer_BT709,
"ColorTransfer_BT709")
954 (QVideoFrameFormat::ColorTransfer_BT601,
"ColorTransfer_BT601")
955 (QVideoFrameFormat::ColorTransfer_Linear,
"ColorTransfer_Linear")
956 (QVideoFrameFormat::ColorTransfer_Gamma22,
"ColorTransfer_Gamma22")
957 (QVideoFrameFormat::ColorTransfer_Gamma28,
"ColorTransfer_Gamma28")
958 (QVideoFrameFormat::ColorTransfer_ST2084,
"ColorTransfer_ST2084")
959 (QVideoFrameFormat::ColorTransfer_STD_B67,
"ColorTransfer_STD_B67")
961QT_MM_DEFINE_QDEBUG_ENUM(QVideoFrameFormat::ColorTransfer);
963QT_MM_MAKE_STRING_RESOLVER(QVideoFrameFormat::ColorRange, QtMultimediaPrivate::EnumName,
964 (QVideoFrameFormat::ColorRange_Unknown,
"ColorRange_Unknown")
965 (QVideoFrameFormat::ColorRange_Video,
"ColorRange_Video")
966 (QVideoFrameFormat::ColorRange_Full,
"ColorRange_Full")
968QT_MM_DEFINE_QDEBUG_ENUM(QVideoFrameFormat::ColorRange);
970QT_MM_MAKE_STRING_RESOLVER(QVideoFrameFormat::Direction, QtMultimediaPrivate::EnumName,
971 (QVideoFrameFormat::TopToBottom,
"TopToBottom")
972 (QVideoFrameFormat::BottomToTop,
"BottomToTop")
974QT_MM_DEFINE_QDEBUG_ENUM(QVideoFrameFormat::Direction);
979
980
982Q_MULTIMEDIA_EXPORT
QString QVideoFrameFormat::pixelFormatToString(QVideoFrameFormat::PixelFormat pixelFormat)
984 auto str = QtMultimediaPrivate::StringResolver<QVideoFrameFormat::PixelFormat>::toQString(pixelFormat);
985 return str.value_or(QString());
988QDebug operator<<(QDebug dbg,
const QVideoFrameFormat &f)
990 QDebugStateSaver saver(dbg);
992 dbg <<
"QVideoFrameFormat(" << f.pixelFormat() <<
", " << f.frameSize()
993 <<
", viewport=" << f.viewport()
994 <<
", colorSpace=" << f.colorSpace()
996 <<
"\n pixel format=" << f.pixelFormat()
997 <<
"\n frame size=" << f.frameSize()
998 <<
"\n viewport=" << f.viewport()
999 <<
"\n colorSpace=" << f.colorSpace()
1000 <<
"\n frameRate=" << f.streamFrameRate()
1001 <<
"\n mirrored=" << f.isMirrored()
1002 <<
"\n range=" << f.colorRange()
1003 <<
"\n colorTransfer=" << f.colorTransfer();
1008QDebug operator<<(QDebug dbg, QVideoFrameFormat::PixelFormat pf)
1010 QDebugStateSaver saver(dbg);
1013 auto format = QVideoFrameFormat::pixelFormatToString(pf);
1014 if (format.isEmpty())
1017 dbg.noquote() << QStringLiteral(
"Format_") << format;