6#include "videoscannerframe_p.h"
12VideoScannerFrame::VideoScannerFrame() =
default;
14VideoScannerFrame::VideoScannerFrame(
const QVideoFrame &frame,
bool isVerticallyFlipped,
Format::BarcodeFormats formats)
17 , m_verticallyFlipped(isVerticallyFlipped)
21VideoScannerFrame::~VideoScannerFrame() =
default;
23int VideoScannerFrame::width()
const
25 return m_frame.width();
28int VideoScannerFrame::height()
const
30 return m_frame.height();
33int VideoScannerFrame::bytesPerLine()
const
35 return m_frame.bytesPerLine(0);
38QVideoFrameFormat::PixelFormat VideoScannerFrame::pixelFormat()
const
40 return m_frame.pixelFormat();
43void VideoScannerFrame::map()
45 if (!m_frameData && m_image.isNull()) {
46 m_frame.map(QVideoFrame::ReadOnly);
50void VideoScannerFrame::unmap()
52 if (m_frame.isMapped()) {
57const uint8_t *VideoScannerFrame::bits()
const
62 if (!m_image.isNull()) {
63 return m_image.bits();
66 Q_ASSERT(m_frame.isMapped());
67 return m_frame.bits(0);
70bool VideoScannerFrame::copyRequired()
const
72 return m_frame.handleType() == QVideoFrame::RhiTextureHandle;
75void VideoScannerFrame::copyFrameData(
QByteArray &buffer)
77 Q_ASSERT(m_frame.isMapped());
79 const auto size = frameDataSize();
80 if (buffer.
size() != size) {
83 std::memcpy(buffer.
data(), m_frame.bits(0), size);
84 m_frameData =
reinterpret_cast<const uint8_t *
>(buffer.
constData());
87int VideoScannerFrame::frameDataSize()
const
89 Q_ASSERT(m_frame.isMapped());
91 switch (m_frame.pixelFormat()) {
92 case QVideoFrameFormat::Format_YUV420P:
93 case QVideoFrameFormat::Format_YUV422P:
94 case QVideoFrameFormat::Format_YV12:
95 case QVideoFrameFormat::Format_NV12:
96 case QVideoFrameFormat::Format_NV21:
97 case QVideoFrameFormat::Format_IMC1:
98 case QVideoFrameFormat::Format_IMC2:
99 case QVideoFrameFormat::Format_IMC3:
100 case QVideoFrameFormat::Format_IMC4:
101 return m_frame.mappedBytes(0) / 2;
103 return m_frame.mappedBytes(0);
107bool VideoScannerFrame::needsConversion()
const
109 switch (m_frame.pixelFormat()) {
110 case QVideoFrameFormat::Format_Jpeg:
111 case QVideoFrameFormat::Format_SamplerExternalOES:
112 case QVideoFrameFormat::Format_SamplerRect:
119void VideoScannerFrame::convertToImage()
121 if (!m_image.isNull()) {
125 Q_ASSERT(m_frame.isMapped());
126 m_image = m_frame.toImage();
129QImage VideoScannerFrame::image()
const
134bool VideoScannerFrame::isVerticallyFlipped()
const
136 return m_verticallyFlipped;
Provides classes and methods for generating barcodes.
const char * constData() const const
void resize(qsizetype newSize, char c)
qsizetype size() const const