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 uchar* bits = mappedFrame.bits();
24 QImage image(bits, mappedFrame.width(), mappedFrame.height(), mappedFrame.bytesPerLine(), format);
25 image = image.copy(); // Create a deep copy of the bits
26 mappedFrame.unmap();
27 emit imageAvailable(image);
28 return true;
29}
30
31QList<QVideoFrame::PixelFormat> VideoDumper::supportedPixelFormats(QAbstractVideoBuffer::HandleType) const {
32 QList<QVideoFrame::PixelFormat> list;
33 list.append(QVideoFrame::Format_RGB32);
34 list.append(QVideoFrame::Format_ARGB32);
35 list.append(QVideoFrame::Format_RGB24);
36 list.append(QVideoFrame::Format_ARGB32_Premultiplied);
37 list.append(QVideoFrame::Format_RGB565);
38 list.append(QVideoFrame::Format_RGB555);
39 return list;
40}