70 QList<QColor> colors = { Qt::red, Qt::green, Qt::blue, Qt::yellow };
71 const int width = image.width();
72 const int height = image.height();
74 for (
int j = 0; j < height; ++j) {
75 for (
int i = 0; i < width; ++i) {
76 const int colorX = i < width / 2 ? 0 : 1;
77 const int colorY = j < height / 2 ? 0 : 1;
78 const int colorIndex = colorX + 2 * colorY;
79 image.setPixel(i, j, colors[colorIndex].rgb());
87 QBuffer buffer(&jpegData);
88 if (!buffer.open(QIODevice::WriteOnly))
92 if (!image.save(&buffer,
"JPG", 100))
96 auto videoBuffer = std::make_unique<QMemoryVideoBuffer>(std::move(jpegData), -1);
97 return QVideoFramePrivate::createFrame(std::move(videoBuffer),
98 QVideoFrameFormat(size, QVideoFrameFormat::Format_Jpeg));
103 using namespace std::chrono;
105 QImage image(m_size, QImage::Format_ARGB32);
107 case ImagePattern::SingleColor:
108 image.fill(m_colors[m_frameIndex % m_colors.size()]);
110 case ImagePattern::ColoredSquares:
111 fillColoredSquares(image);
116 if (m_pixelFormat == QVideoFrameFormat::Format_Jpeg) {
117 frame = createJpegFrame(image, m_size);
119 QVideoFrame rgbFrame(image);
120 QVideoFrameFormat outputFormat{ m_size, m_pixelFormat };
121 frame = QPlatformMediaIntegration::instance()->convertVideoFrame(rgbFrame, outputFormat);
125 frame.setStreamFrameRate(*m_frameRate);
128 frame.setStartTime(m_period->count() * m_frameIndex);
129 if (m_endTimeIsReported)
130 frame.setEndTime(m_period->count() * (m_frameIndex + 1));
133 if (m_presentationRotation)
134 frame.setRotation(*m_presentationRotation);
136 if (m_presentationMirrored)
137 frame.setMirrored(*m_presentationMirrored);