src/platform/qt/VideoDumper.cpp (view raw)
1/* Copyright (c) 2013-2017 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "VideoDumper.h"
7
8#include <QImage>
9
10using namespace QGBA;
11
12VideoDumper::VideoDumper(QObject* parent)
13 : QAbstractVideoSurface(parent)
14{
15}
16
17bool VideoDumper::present(const QVideoFrame& frame) {
18 QVideoFrame mappedFrame(frame);
19 if (!mappedFrame.map(QAbstractVideoBuffer::ReadOnly)) {
20 return false;
21 }
22 QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(mappedFrame.pixelFormat());
23 const uchar* bits = mappedFrame.bits();
24 QImage image(bits, mappedFrame.width(), mappedFrame.height(), mappedFrame.bytesPerLine(),
25 format);
26 image = std::move(image.copy()); // Create a deep copy of the bits
27 emit imageAvailable(image);
28 mappedFrame.unmap();
29 return true;
30}
31
32QList<QVideoFrame::PixelFormat> VideoDumper::supportedPixelFormats(QAbstractVideoBuffer::HandleType) const {
33 QList<QVideoFrame::PixelFormat> list;
34 list.append(QVideoFrame::Format_ARGB32);
35 list.append(QVideoFrame::Format_ARGB32_Premultiplied);
36 list.append(QVideoFrame::Format_RGB32);
37 list.append(QVideoFrame::Format_RGB24);
38 list.append(QVideoFrame::Format_RGB565);
39 list.append(QVideoFrame::Format_RGB555);
40 return list;
41}