19 [](int, int) {
return 0; },
21 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
27 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
33 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
39 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
45 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
51 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
57 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
63 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
69 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
75 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
81 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
87 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
93 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
99 { { 1, 1 }, { 2, 2 }, { 2, 2 } }
105 { { 1, 1 }, { 2, 1 }, { 2, 1 } }
111 { { 1, 1 }, { 2, 2 }, { 2, 2 } }
117 { { 2, 1 }, { 1, 1 }, { 1, 1 } }
123 { { 2, 1 }, { 1, 1 }, { 1, 1 } }
129 { { 1, 1 }, { 2, 2 }, { 1, 1 } }
135 { { 1, 1 }, { 2, 2 }, { 1, 1 } }
142 h += 2*(((
h/2) + 15) & ~15);
146 { { 1, 1 }, { 2, 2 }, { 2, 2 } }
152 { { 1, 1 }, { 1, 2 }, { 1, 1 } }
159 h += 2*(((
h/2) + 15) & ~15);
163 { { 1, 1 }, { 2, 2 }, { 2, 2 } }
169 { { 1, 1 }, { 1, 2 }, { 1, 1 } }
175 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
181 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
187 { { 1, 1 }, { 2, 2 }, { 1, 1 } }
193 { { 1, 1 }, { 2, 2 }, { 1, 1 } }
198 [](int, int) {
return 0; },
200 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
206 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
211 [](int, int) {
return 0; },
213 { { 1, 1 }, { 1, 1 }, { 1, 1 } }
219 { { 1, 1 }, { 2, 2 }, { 2, 2 } }
235 return QStringLiteral(
":/qt-project.org/multimedia/shaders/externalsampler.vert.qsb");
239 return QStringLiteral(
":/qt-project.org/multimedia/shaders/rectsampler.vert.qsb");
242 return QStringLiteral(
":/qt-project.org/multimedia/shaders/vertex.vert.qsb");
247 const char *
shader =
nullptr;
248 switch (
format.pixelFormat()) {
282 shader =
"yuv_triplanar_p10";
304 shader =
"nv12_bt2020_pq";
308 shader =
"nv12_bt2020_hlg";
321 shader =
"externalsampler";
326 shader =
"rectsampler_bgra";
375 auto colorSpace =
format.colorSpace();
377 if (
format.frameHeight() > 576)
384 switch (colorSpace) {
387 1.0f, 0.000f, 1.402f, -0.701f,
388 1.0f, -0.344f, -0.714f, 0.529f,
389 1.0f, 1.772f, 0.000f, -0.886f,
390 0.0f, 0.000f, 0.000f, 1.0000f);
395 1.f, 0.000f, 1.5748f, -0.8774f,
396 1.f, -0.187324f, -0.468124f, 0.327724f,
397 1.f, 1.8556f, 0.000f, -0.9278f,
398 0.0f, 0.000f, 0.000f, 1.0000f);
400 1.1644f, 0.000f, 1.7928f, -0.9731f,
401 1.1644f, -0.2132f, -0.5329f, 0.3015f,
402 1.1644f, 2.1124f, 0.000f, -1.1335f,
403 0.0f, 0.000f, 0.000f, 1.0000f);
407 1.f, 0.000f, 1.4746f, -0.7373f,
408 1.f, -0.2801f, -0.91666f, 0.5984f,
409 1.f, 1.8814f, 0.000f, -0.9407f,
410 0.0f, 0.000f, 0.000f, 1.0000f);
412 1.1644f, 0.000f, 1.6787f, -0.9158f,
413 1.1644f, -0.1874f, -0.6511f, 0.3478f,
414 1.1644f, 2.1418f, 0.000f, -1.1483f,
415 0.0f, 0.000f, 0.000f, 1.0000f);
421 1.f, 0.000f, 1.772f, -0.886f,
422 1.f, -0.1646f, -0.57135f, 0.36795f,
423 1.f, 1.42f, 0.000f, -0.71f,
424 0.0f, 0.000f, 0.000f, 1.0000f);
426 1.164f, 0.000f, 1.596f, -0.8708f,
427 1.164f, -0.392f, -0.813f, 0.5296f,
428 1.164f, 2.017f, 0.000f, -1.081f,
429 0.0f, 0.000f, 0.000f, 1.0000f);
434static QMatrix4x4 yuvColorCorrectionMatrix(
float brightness,
float contrast,
float hue,
float saturation)
458 float chcs = cos(hue)*contrast*saturation;
459 float shcs = sin(hue)*contrast*saturation;
460 return QMatrix4x4(contrast, 0, 0, .0625*(1 - contrast) + brightness,
461 0, chcs, shcs, .5*(1 - chcs - shcs),
462 0, -shcs, chcs, .5*(1 + shcs - chcs),
471 const float m1 = 1305.f/8192.f;
472 const float m2 = 2523.f/32.f;
473 const float c1 = 107.f/128.f;
474 const float c2 = 2413.f/128.f;
475 const float c3 = 2392.f/128.f;
477 const float SDR_LEVEL = 100.f;
478 sig *= SDR_LEVEL/10000.f;
479 float psig = powf(sig, m1);
480 float num = c1 +
c2*psig;
481 float den = 1 + c3*psig;
482 return powf(
num/den, m2);
487 const float a = 0.17883277f;
488 const float b = 0.28466892f;
489 const float c = 0.55991073f;
492 return sqrtf(3.f*sig);
493 return a*logf(12.f*sig -
b) +
c;
508 switch (
format.pixelFormat()) {
547 cmat =
frame.videoBuffer()->externalTextureMatrix();
565 switch (
format.colorTransfer()) {
580 memcpy(ud->transformMatrix,
transform.constData(),
sizeof(ud->transformMatrix));
581 memcpy(ud->colorMatrix, cmat.
constData(),
sizeof(ud->transformMatrix));
582 ud->opacity = opacity;
583 ud->width = float(
format.frameWidth());
584 ud->masteringWhite = fromLinear(
float(
format.maxLuminance())/100.f);
585 ud->maxLum = fromLinear(
float(maxNits)/100.f);
591 qWarning() <<
"could not map data of QVideoFrame for upload";
602 bool needsRebuild = !tex || tex->pixelSize() != planeSize || tex->format() != texDesc.
textureFormat[plane];
606 qWarning(
"Failed to create new texture (size %dx%d)", planeSize.
width(), planeSize.
height());
613 tex->setPixelSize(planeSize);
614 if (!tex->create()) {
648 QRhiTexture::Flags textureFlags = {};
664 if (tex->createFrom({handle, 0}))
667 qWarning(
"Failed to initialize QRhiTexture wrapper for native texture object %llu",
handle);
682 return plane < std::size(m_textures) ? m_textures[plane].get() :
nullptr;
701 return std::make_unique<QVideoFrameTexturesArray>(std::move(
textures));
719 return std::make_unique<QVideoFrameTexturesArray>(std::move(
textures));
758 option.setUseDesignMetrics(
true);
763 int leading =
metrics.leading();
775 line.setLineWidth(lineWidth);
779 textWidth =
qMax(textWidth,
line.naturalTextWidth());
The QAbstractVideoBuffer class is an abstraction for video data. \inmodule QtMultimedia.
virtual std::unique_ptr< QVideoFrameTextures > mapTextures(QRhi *)
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
The QColor class provides colors based on RGB, HSV or CMYK values.
void setAlpha(int alpha)
Sets the alpha of this color to alpha.
\reentrant \inmodule QtGui
void setPointSize(int)
Sets the point size to pointSize.
@ Format_RGBA8888_Premultiplied
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
void scale(const QVector3D &vector)
Multiplies this matrix by another that scales coordinates by the components of vector.
const float * constData() const
Returns a constant pointer to the raw data of this matrix.
The QPainter class performs low-level painting on widgets and other paint devices.
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void restore()
Restores the current painter state (pops a saved state off the stack).
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void save()
Saves the current painter state (pushes the state onto a stack).
void setBrush(const QBrush &brush)
Sets the painter's brush to the given brush.
@ CompositionMode_SourceOver
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr QPointF topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
constexpr QSizeF size() const noexcept
Returns the size of the rectangle.
void uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc)
Enqueues uploading the image data for one or more mip levels in one or more layers of the texture tex...
Format
Describes the swapchain format.
void setDataStride(quint32 stride)
Sets the data stride in bytes.
void setData(const QByteArray &data)
Sets data.
Implementation backend() const
QRhiTexture * newTexture(QRhiTexture::Format format, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & replace(qsizetype i, qsizetype len, QChar after)
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void setFont(const QFont &f)
Sets the layout's font to the given font.
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
void beginLayout()
Begins the layout process.
void setPosition(const QPointF &p)
Moves the text layout to point p.
void setText(const QString &string)
Sets the layout's text to the given string.
QString text() const
Returns the layout's text.
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
void draw(QPainter *p, const QPointF &pos, const QList< FormatRange > &selections=QList< FormatRange >(), const QRectF &clip=QRectF()) const
Draws the whole layout on the painter p at the position specified by pos.
void endLayout()
Ends the layout process.
The QVideoFrame class represents a frame of video data.
std::array< std::unique_ptr< QRhiTexture >, TextureDescription::maxPlanes > TextureArray
QRhiTexture * texture(uint plane) const override
TextureArray takeTextures()
QVideoFrameTexturesArray(TextureArray &&textures)
Combined button and popup list for selecting options.
float convertHLGFromLinear(float sig)
static bool updateTextureWithMap(QVideoFrame frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, int plane, std::unique_ptr< QRhiTexture > &tex)
QString vertexShaderFileName(const QVideoFrameFormat &format)
static QMatrix4x4 colorMatrix(const QVideoFrameFormat &format)
static float convertPQFromLinear(float sig)
std::unique_ptr< QVideoFrameTextures > createTexturesFromMemory(const QVideoFrame &frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, QVideoFrameTextures *old)
static float convertSDRFromLinear(float sig)
QString fragmentShaderFileName(const QVideoFrameFormat &format, QRhiSwapChain::Format surfaceFormat)
static const TextureDescription descriptions[QVideoFrameFormat::NPixelFormats]
const TextureDescription * textureDescription(QVideoFrameFormat::PixelFormat format)
static std::unique_ptr< QRhiTexture > createTextureFromHandle(const QVideoFrame &frame, QRhi *rhi, int plane)
std::unique_ptr< QVideoFrameTextures > createTextures(QVideoFrame &frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, std::unique_ptr< QVideoFrameTextures > &&oldTextures)
void updateUniformData(QByteArray *dst, const QVideoFrameFormat &format, const QVideoFrame &frame, const QMatrix4x4 &transform, float opacity, float maxNits)
static std::unique_ptr< QVideoFrameTextures > createTexturesFromHandles(const QVideoFrame &frame, QRhi *rhi)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLuint64 GLenum void * handle
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint const GLuint GLuint const GLuint * textures
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
const void GLsizei GLsizei stride
GLenum GLsizeiptr fontSize
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLuint GLenum GLenum transform
static constexpr QSize frameSize(const T &frame)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
unsigned long long quint64
QVideoFrameFormat::PixelFormat fmt
static bool translate(xcb_connection_t *connection, xcb_window_t child, xcb_window_t parent, int *x, int *y)
\inmodule QtCore \reentrant
bool update(const QSize &frameSize, QString text)
void draw(QPainter *painter, const QPointF &translate) const
QRhiTexture::Format textureFormat[maxPlanes]
static constexpr int maxPlanes
SizeScale sizeScale[maxPlanes]