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";
377 auto colorSpace =
format.colorSpace();
379 if (
format.frameHeight() > 576)
386 switch (colorSpace) {
389 1.0f, 0.000f, 1.402f, -0.701f,
390 1.0f, -0.344f, -0.714f, 0.529f,
391 1.0f, 1.772f, 0.000f, -0.886f,
392 0.0f, 0.000f, 0.000f, 1.000f
398 1.0f, 0.0f, 1.5748f, -0.790488f,
399 1.0f, -0.187324f, -0.468124f, 0.329010f,
400 1.0f, 1.855600f, 0.0f, -0.931439f,
401 0.0f, 0.0f, 0.0f, 1.0f
404 1.1644f, 0.0000f, 1.7927f, -0.9729f,
405 1.1644f, -0.2132f, -0.5329f, 0.3015f,
406 1.1644f, 2.1124f, 0.0000f, -1.1334f,
407 0.0000f, 0.0000f, 0.0000f, 1.0000f
412 1.f, 0.0000f, 1.4746f, -0.7402f,
413 1.f, -0.1646f, -0.5714f, 0.3694f,
414 1.f, 1.8814f, 0.000f, -0.9445f,
415 0.0f, 0.0000f, 0.000f, 1.0000f
418 1.1644f, 0.000f, 1.6787f, -0.9157f,
419 1.1644f, -0.1874f, -0.6504f, 0.3475f,
420 1.1644f, 2.1418f, 0.0000f, -1.1483f,
421 0.0000f, 0.0000f, 0.0000f, 1.0000f
428 1.f, 0.000f, 1.772f, -0.886f,
429 1.f, -0.1646f, -0.57135f, 0.36795f,
430 1.f, 1.42f, 0.000f, -0.71f,
431 0.0f, 0.000f, 0.000f, 1.0000f
434 1.164f, 0.000f, 1.596f, -0.8708f,
435 1.164f, -0.392f, -0.813f, 0.5296f,
436 1.164f, 2.017f, 0.000f, -1.0810f,
437 0.000f, 0.000f, 0.000f, 1.0000f
447 const float m1 = 1305.f/8192.f;
448 const float m2 = 2523.f/32.f;
449 const float c1 = 107.f/128.f;
450 const float c2 = 2413.f/128.f;
451 const float c3 = 2392.f/128.f;
453 const float SDR_LEVEL = 100.f;
454 sig *= SDR_LEVEL/10000.f;
455 float psig = powf(sig, m1);
456 float num = c1 +
c2*psig;
457 float den = 1 + c3*psig;
458 return powf(
num/den, m2);
463 const float a = 0.17883277f;
464 const float b = 0.28466892f;
465 const float c = 0.55991073f;
468 return sqrtf(3.f*sig);
469 return a*logf(12.f*sig -
b) +
c;
484 switch (
format.pixelFormat()) {
523 cmat =
frame.videoBuffer()->externalTextureMatrix();
541 switch (
format.colorTransfer()) {
556 memcpy(ud->transformMatrix,
transform.constData(),
sizeof(ud->transformMatrix));
557 memcpy(ud->colorMatrix, cmat.constData(),
sizeof(ud->transformMatrix));
558 ud->opacity = opacity;
559 ud->width = float(
format.frameWidth());
560 ud->masteringWhite = fromLinear(
float(
format.maxLuminance())/100.f);
561 ud->maxLum = fromLinear(
float(maxNits)/100.f);
572 std::unique_ptr<QRhiTexture> &tex)
581 QSize planeSize(
size.width()/texDesc.sizeScale[plane].x,
size.height()/texDesc.sizeScale[plane].y);
583 bool needsRebuild = !tex || tex->pixelSize() != planeSize || tex->format() != texDesc.textureFormat[plane];
585 tex.reset(rhi->
newTexture(texDesc.textureFormat[plane], planeSize, 1, {}));
587 qWarning(
"Failed to create new texture (size %dx%d)", planeSize.width(), planeSize.height());
593 tex->setFormat(texDesc.textureFormat[plane]);
594 tex->setPixelSize(planeSize);
595 if (!tex->create()) {
596 qWarning(
"Failed to create texture (size %dx%d)", planeSize.width(), planeSize.height());
618 reinterpret_cast<const char *
>(
frame.bits(plane)),
frame.mappedBytes(plane)));
625 rub->uploadTexture(tex.get(), desc);
637 QSize planeSize(
size.width()/texDesc.sizeScale[plane].x,
size.height()/texDesc.sizeScale[plane].y);
639 QRhiTexture::Flags textureFlags = {};
654 std::unique_ptr<QRhiTexture> tex(rhi->
newTexture(texDesc.textureFormat[plane], planeSize, 1, textureFlags));
655 if (tex->createFrom({handle, 0}))
658 qWarning(
"Failed to initialize QRhiTexture wrapper for native texture object %llu",
handle);
668 : m_textures(
std::move(
textures)), m_mappedFrame(
std::move(mappedFrame))
682 return plane < std::size(m_textures) ? m_textures[plane].get() :
nullptr;
697 for (
quint8 plane = 0; plane < texDesc.nplanes; ++plane) {
702 return std::make_unique<QVideoFrameTexturesArray>(std::move(
textures));
716 qWarning() <<
"Cannot map a video frame in ReadOnly mode!";
722 bool shouldKeepMapping =
false;
723 for (
quint8 plane = 0; plane < texDesc.nplanes; ++plane) {
729 shouldKeepMapping =
true;
733 return std::make_unique<QVideoFrameTexturesArray>(
743 if (
auto vft = vf->mapTextures(rhi))
776 int leading =
metrics.leading();
788 line.setLineWidth(lineWidth);
792 textWidth =
qMax(textWidth,
line.naturalTextWidth());
The QAbstractVideoBuffer class is an abstraction for video data. \inmodule QtMultimedia.
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.
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.
Format
Describes the swapchain format.
void setDataStride(quint32 stride)
Sets the data stride in bytes.
void setData(const QByteArray &data)
Sets data.
void setImage(const QImage &image)
Sets image.
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Implementation backend() const
QRhiTexture * newTexture(QRhiTexture::Format format, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
void scale(int w, int h, Qt::AspectRatioMode mode) noexcept
Scales the size to a rectangle with the given width and height, according to the specified mode:
\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...
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
qsizetype size() const noexcept
Returns the number of characters in this string.
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.
void setUseDesignMetrics(bool b)
If enable is true then the layout will use design metrics; otherwise it will use the metrics of the p...
The QVideoFrame class represents a frame of video data.
void unmap()
Releases the memory mapped by the map() function.
bool isReadable() const
Identifies if the mapped contents of a video frame were read from the frame when it was mapped.
bool isValid() const
Identifies whether a video frame is valid.
std::array< std::unique_ptr< QRhiTexture >, TextureDescription::maxPlanes > TextureArray
QVideoFrameTexturesArray(TextureArray &&textures, QVideoFrame mappedFrame={})
QRhiTexture * texture(uint plane) const override
TextureArray takeTextures()
~QVideoFrameTexturesArray()
Combined button and popup list for selecting options.
float convertHLGFromLinear(float sig)
QString vertexShaderFileName(const QVideoFrameFormat &format)
static QMatrix4x4 colorMatrix(const QVideoFrameFormat &format)
static float convertPQFromLinear(float sig)
static UpdateTextureWithMapResult updateTextureWithMap(const QVideoFrame &frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, int plane, std::unique_ptr< QRhiTexture > &tex)
static float convertSDRFromLinear(float sig)
QString fragmentShaderFileName(const QVideoFrameFormat &format, QRhiSwapChain::Format surfaceFormat)
static const TextureDescription descriptions[QVideoFrameFormat::NPixelFormats]
UpdateTextureWithMapResult
@ UpdatedWithDataReference
const TextureDescription * textureDescription(QVideoFrameFormat::PixelFormat format)
static std::unique_ptr< QRhiTexture > createTextureFromHandle(const QVideoFrame &frame, QRhi *rhi, int plane)
static std::unique_ptr< QVideoFrameTextures > createTexturesFromMemory(QVideoFrame frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, QVideoFrameTextures *old)
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)
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
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
static constexpr int maxPlanes