mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-02 00:15:06 +01:00
camera: refactor (add qt_camera_base)
This commit is contained in:
parent
5ebd466869
commit
6e410dcef5
@ -13,8 +13,8 @@ add_executable(citra-qt
|
||||
camera/camera_util.h
|
||||
camera/still_image_camera.cpp
|
||||
camera/still_image_camera.h
|
||||
camera/qt_camera_factory.cpp
|
||||
camera/qt_camera_factory.h
|
||||
camera/qt_camera_base.cpp
|
||||
camera/qt_camera_base.h
|
||||
camera/qt_multimedia_camera.cpp
|
||||
camera/qt_multimedia_camera.h
|
||||
citra-qt.rc
|
||||
|
57
src/citra_qt/camera/qt_camera_base.cpp
Normal file
57
src/citra_qt/camera/qt_camera_base.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright 2018 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <QMessageBox>
|
||||
#include "citra_qt/camera/camera_util.h"
|
||||
#include "citra_qt/camera/qt_camera_base.h"
|
||||
|
||||
namespace Camera {
|
||||
|
||||
QtCameraInterface::QtCameraInterface(const Service::CAM::Flip& flip) {
|
||||
using namespace Service::CAM;
|
||||
flip_horizontal = basic_flip_horizontal = (flip == Flip::Horizontal) || (flip == Flip::Reverse);
|
||||
flip_vertical = basic_flip_vertical = (flip == Flip::Vertical) || (flip == Flip::Reverse);
|
||||
}
|
||||
|
||||
void QtCameraInterface::SetFormat(Service::CAM::OutputFormat output_format) {
|
||||
output_rgb = output_format == Service::CAM::OutputFormat::RGB565;
|
||||
}
|
||||
|
||||
void QtCameraInterface::SetResolution(const Service::CAM::Resolution& resolution) {
|
||||
width = resolution.width;
|
||||
height = resolution.height;
|
||||
}
|
||||
|
||||
void QtCameraInterface::SetFlip(Service::CAM::Flip flip) {
|
||||
using namespace Service::CAM;
|
||||
flip_horizontal = basic_flip_horizontal ^ (flip == Flip::Horizontal || flip == Flip::Reverse);
|
||||
flip_vertical = basic_flip_vertical ^ (flip == Flip::Vertical || flip == Flip::Reverse);
|
||||
}
|
||||
|
||||
void QtCameraInterface::SetEffect(Service::CAM::Effect effect) {
|
||||
if (effect != Service::CAM::Effect::None) {
|
||||
NGLOG_ERROR(Service_CAM, "Unimplemented effect {}", static_cast<int>(effect));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<u16> QtCameraInterface::ReceiveFrame() {
|
||||
return CameraUtil::ProcessImage(QtReceiveFrame(), width, height, output_rgb, flip_horizontal,
|
||||
flip_vertical);
|
||||
}
|
||||
|
||||
std::unique_ptr<CameraInterface> QtCameraFactory::CreatePreview(
|
||||
const std::string& config, int width, int height, const Service::CAM::Flip& flip) const {
|
||||
std::unique_ptr<CameraInterface> camera = Create(config, flip);
|
||||
|
||||
if (camera->IsPreviewAvailable()) {
|
||||
return camera;
|
||||
}
|
||||
QMessageBox::critical(
|
||||
nullptr, QObject::tr("Error"),
|
||||
(config.empty() ? QObject::tr("Couldn't load the camera")
|
||||
: QObject::tr("Couldn't load %1").arg(QString::fromStdString(config))));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace Camera
|
36
src/citra_qt/camera/qt_camera_base.h
Normal file
36
src/citra_qt/camera/qt_camera_base.h
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright 2018 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "core/frontend/camera/factory.h"
|
||||
|
||||
namespace Camera {
|
||||
|
||||
// Base class for camera interfaces of citra_qt
|
||||
class QtCameraInterface : public CameraInterface {
|
||||
public:
|
||||
QtCameraInterface(const Service::CAM::Flip& flip);
|
||||
void SetResolution(const Service::CAM::Resolution&) override;
|
||||
void SetFlip(Service::CAM::Flip) override;
|
||||
void SetEffect(Service::CAM::Effect) override;
|
||||
void SetFormat(Service::CAM::OutputFormat) override;
|
||||
std::vector<u16> ReceiveFrame() override;
|
||||
virtual QImage QtReceiveFrame() = 0;
|
||||
|
||||
private:
|
||||
int width, height;
|
||||
bool output_rgb;
|
||||
bool flip_horizontal, flip_vertical;
|
||||
bool basic_flip_horizontal, basic_flip_vertical;
|
||||
};
|
||||
|
||||
// Base class for camera factories of citra_qt
|
||||
class QtCameraFactory : public CameraFactory {
|
||||
std::unique_ptr<CameraInterface> CreatePreview(const std::string& config, int width, int height,
|
||||
const Service::CAM::Flip& flip) const override;
|
||||
};
|
||||
|
||||
} // namespace Camera
|
@ -1,24 +0,0 @@
|
||||
// Copyright 2018 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <QMessageBox>
|
||||
#include "citra_qt/camera/qt_camera_factory.h"
|
||||
|
||||
namespace Camera {
|
||||
|
||||
std::unique_ptr<CameraInterface> QtCameraFactory::CreatePreview(
|
||||
const std::string& config, int width, int height, const Service::CAM::Flip& flip) const {
|
||||
std::unique_ptr<CameraInterface> camera = Create(config, flip);
|
||||
|
||||
if (camera->IsPreviewAvailable()) {
|
||||
return camera;
|
||||
}
|
||||
QMessageBox::critical(
|
||||
nullptr, QObject::tr("Error"),
|
||||
(config.empty() ? QObject::tr("Couldn't load the camera")
|
||||
: QObject::tr("Couldn't load %1").arg(QString::fromStdString(config))));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace Camera
|
@ -1,18 +0,0 @@
|
||||
// Copyright 2018 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "core/frontend/camera/factory.h"
|
||||
|
||||
namespace Camera {
|
||||
|
||||
// Base class for camera factories of citra_qt
|
||||
class QtCameraFactory : public CameraFactory {
|
||||
std::unique_ptr<CameraInterface> CreatePreview(const std::string& config, int width, int height,
|
||||
const Service::CAM::Flip& flip) const override;
|
||||
};
|
||||
|
||||
} // namespace Camera
|
@ -48,16 +48,13 @@ bool QtCameraSurface::present(const QVideoFrame& frame) {
|
||||
|
||||
QtMultimediaCamera::QtMultimediaCamera(const std::string& camera_name,
|
||||
const Service::CAM::Flip& flip)
|
||||
: handler(QtMultimediaCameraHandler::GetHandler()) {
|
||||
: QtCameraInterface(flip), handler(QtMultimediaCameraHandler::GetHandler()) {
|
||||
if (handler->thread() == QThread::currentThread()) {
|
||||
handler->CreateCamera(camera_name);
|
||||
} else {
|
||||
QMetaObject::invokeMethod(handler.get(), "CreateCamera", Qt::BlockingQueuedConnection,
|
||||
Q_ARG(const std::string&, camera_name));
|
||||
}
|
||||
using namespace Service::CAM;
|
||||
flip_horizontal = basic_flip_horizontal = (flip == Flip::Horizontal) || (flip == Flip::Reverse);
|
||||
flip_vertical = basic_flip_vertical = (flip == Flip::Vertical) || (flip == Flip::Reverse);
|
||||
}
|
||||
|
||||
QtMultimediaCamera::~QtMultimediaCamera() {
|
||||
@ -77,10 +74,6 @@ void QtMultimediaCamera::StopCapture() {
|
||||
handler->StopCamera();
|
||||
}
|
||||
|
||||
void QtMultimediaCamera::SetFormat(Service::CAM::OutputFormat output_format) {
|
||||
output_rgb = output_format == Service::CAM::OutputFormat::RGB565;
|
||||
}
|
||||
|
||||
void QtMultimediaCamera::SetFrameRate(Service::CAM::FrameRate frame_rate) {
|
||||
const std::array<QCamera::FrameRateRange, 13> FrameRateList = {
|
||||
/* Rate_15 */ QCamera::FrameRateRange(15, 15),
|
||||
@ -104,27 +97,9 @@ void QtMultimediaCamera::SetFrameRate(Service::CAM::FrameRate frame_rate) {
|
||||
handler->settings.setMinimumFrameRate(framerate.maximumFrameRate);
|
||||
}
|
||||
|
||||
void QtMultimediaCamera::SetResolution(const Service::CAM::Resolution& resolution) {
|
||||
width = resolution.width;
|
||||
height = resolution.height;
|
||||
}
|
||||
|
||||
void QtMultimediaCamera::SetFlip(Service::CAM::Flip flip) {
|
||||
using namespace Service::CAM;
|
||||
flip_horizontal = basic_flip_horizontal ^ (flip == Flip::Horizontal || flip == Flip::Reverse);
|
||||
flip_vertical = basic_flip_vertical ^ (flip == Flip::Vertical || flip == Flip::Reverse);
|
||||
}
|
||||
|
||||
void QtMultimediaCamera::SetEffect(Service::CAM::Effect effect) {
|
||||
if (effect != Service::CAM::Effect::None) {
|
||||
NGLOG_ERROR(Service_CAM, "Unimplemented effect {}", static_cast<int>(effect));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<u16> QtMultimediaCamera::ReceiveFrame() {
|
||||
QImage QtMultimediaCamera::QtReceiveFrame() {
|
||||
QMutexLocker locker(&handler->camera_surface.mutex);
|
||||
return CameraUtil::ProcessImage(handler->camera_surface.current_frame, width, height,
|
||||
output_rgb, flip_horizontal, flip_vertical);
|
||||
return handler->camera_surface.current_frame;
|
||||
}
|
||||
|
||||
bool QtMultimediaCamera::IsPreviewAvailable() {
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <QImage>
|
||||
#include <QMutex>
|
||||
#include "citra_qt/camera/camera_util.h"
|
||||
#include "citra_qt/camera/qt_camera_factory.h"
|
||||
#include "citra_qt/camera/qt_camera_base.h"
|
||||
#include "core/frontend/camera/interface.h"
|
||||
|
||||
class GMainWindow;
|
||||
@ -36,26 +36,18 @@ private:
|
||||
class QtMultimediaCameraHandler;
|
||||
|
||||
/// This class is only an interface. It just calls QtMultimediaCameraHandler.
|
||||
class QtMultimediaCamera final : public CameraInterface {
|
||||
class QtMultimediaCamera final : public QtCameraInterface {
|
||||
public:
|
||||
QtMultimediaCamera(const std::string& camera_name, const Service::CAM::Flip& flip);
|
||||
~QtMultimediaCamera();
|
||||
void StartCapture() override;
|
||||
void StopCapture() override;
|
||||
void SetResolution(const Service::CAM::Resolution&) override;
|
||||
void SetFlip(Service::CAM::Flip) override;
|
||||
void SetEffect(Service::CAM::Effect) override;
|
||||
void SetFormat(Service::CAM::OutputFormat) override;
|
||||
void SetFrameRate(Service::CAM::FrameRate frame_rate) override;
|
||||
std::vector<u16> ReceiveFrame() override;
|
||||
QImage QtReceiveFrame() override;
|
||||
bool IsPreviewAvailable() override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<QtMultimediaCameraHandler> handler;
|
||||
int width, height;
|
||||
bool output_rgb;
|
||||
bool flip_horizontal, flip_vertical;
|
||||
bool basic_flip_horizontal, basic_flip_vertical;
|
||||
};
|
||||
|
||||
class QtMultimediaCameraFactory final : public QtCameraFactory {
|
||||
|
@ -10,40 +10,14 @@
|
||||
namespace Camera {
|
||||
|
||||
StillImageCamera::StillImageCamera(QImage image_, const Service::CAM::Flip& flip)
|
||||
: image(std::move(image_)) {
|
||||
using namespace Service::CAM;
|
||||
flip_horizontal = basic_flip_horizontal = (flip == Flip::Horizontal) || (flip == Flip::Reverse);
|
||||
flip_vertical = basic_flip_vertical = (flip == Flip::Vertical) || (flip == Flip::Reverse);
|
||||
}
|
||||
: QtCameraInterface(flip), image(std::move(image_)) {}
|
||||
|
||||
void StillImageCamera::StartCapture() {}
|
||||
|
||||
void StillImageCamera::StopCapture() {}
|
||||
|
||||
void StillImageCamera::SetFormat(Service::CAM::OutputFormat output_format) {
|
||||
output_rgb = output_format == Service::CAM::OutputFormat::RGB565;
|
||||
}
|
||||
|
||||
void StillImageCamera::SetResolution(const Service::CAM::Resolution& resolution) {
|
||||
width = resolution.width;
|
||||
height = resolution.height;
|
||||
}
|
||||
|
||||
void StillImageCamera::SetFlip(Service::CAM::Flip flip) {
|
||||
using namespace Service::CAM;
|
||||
flip_horizontal = basic_flip_horizontal ^ (flip == Flip::Horizontal || flip == Flip::Reverse);
|
||||
flip_vertical = basic_flip_vertical ^ (flip == Flip::Vertical || flip == Flip::Reverse);
|
||||
}
|
||||
|
||||
void StillImageCamera::SetEffect(Service::CAM::Effect effect) {
|
||||
if (effect != Service::CAM::Effect::None) {
|
||||
NGLOG_ERROR(Service_CAM, "Unimplemented effect {}", static_cast<int>(effect));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<u16> StillImageCamera::ReceiveFrame() {
|
||||
return CameraUtil::ProcessImage(image, width, height, output_rgb, flip_horizontal,
|
||||
flip_vertical);
|
||||
QImage StillImageCamera::QtReceiveFrame() {
|
||||
return image;
|
||||
}
|
||||
|
||||
bool StillImageCamera::IsPreviewAvailable() {
|
||||
|
@ -7,30 +7,22 @@
|
||||
#include <vector>
|
||||
#include <QImage>
|
||||
#include "citra_qt/camera/camera_util.h"
|
||||
#include "citra_qt/camera/qt_camera_factory.h"
|
||||
#include "citra_qt/camera/qt_camera_base.h"
|
||||
#include "core/frontend/camera/interface.h"
|
||||
|
||||
namespace Camera {
|
||||
|
||||
class StillImageCamera final : public CameraInterface {
|
||||
class StillImageCamera final : public QtCameraInterface {
|
||||
public:
|
||||
StillImageCamera(QImage image, const Service::CAM::Flip& flip);
|
||||
void StartCapture() override;
|
||||
void StopCapture() override;
|
||||
void SetResolution(const Service::CAM::Resolution&) override;
|
||||
void SetFlip(Service::CAM::Flip) override;
|
||||
void SetEffect(Service::CAM::Effect) override;
|
||||
void SetFormat(Service::CAM::OutputFormat) override;
|
||||
void SetFrameRate(Service::CAM::FrameRate frame_rate) override {}
|
||||
std::vector<u16> ReceiveFrame() override;
|
||||
QImage QtReceiveFrame() override;
|
||||
bool IsPreviewAvailable() override;
|
||||
|
||||
private:
|
||||
QImage image;
|
||||
int width, height;
|
||||
bool output_rgb;
|
||||
bool flip_horizontal, flip_vertical;
|
||||
bool basic_flip_horizontal, basic_flip_vertical;
|
||||
};
|
||||
|
||||
class StillImageCameraFactory final : public QtCameraFactory {
|
||||
|
Loading…
Reference in New Issue
Block a user