mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-21 05:09:46 -06:00
port camera stuff
This commit is contained in:
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
using namespace melonDS;
|
using namespace melonDS;
|
||||||
|
|
||||||
|
const char* kCamConfigPath[] = {"DSi.Camera0", "DSi.Camera1"};
|
||||||
|
|
||||||
#if QT_VERSION >= 0x060000
|
#if QT_VERSION >= 0x060000
|
||||||
|
|
||||||
CameraFrameDumper::CameraFrameDumper(QObject* parent) : QVideoSink(parent)
|
CameraFrameDumper::CameraFrameDumper(QObject* parent) : QVideoSink(parent)
|
||||||
@ -116,10 +118,11 @@ QList<QVideoFrame::PixelFormat> CameraFrameDumper::supportedPixelFormats(QAbstra
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
CameraManager::CameraManager(int num, int width, int height, bool yuv) : QObject()
|
CameraManager::CameraManager(int num, int width, int height, bool yuv)
|
||||||
|
: QObject(),
|
||||||
|
num(num),
|
||||||
|
config(Config::GetGlobalTable().GetTable(kCamConfigPath[num]))
|
||||||
{
|
{
|
||||||
this->num = num;
|
|
||||||
|
|
||||||
startNum = 0;
|
startNum = 0;
|
||||||
|
|
||||||
// QCamera needs to be controlled from the UI thread, hence this
|
// QCamera needs to be controlled from the UI thread, hence this
|
||||||
@ -136,7 +139,7 @@ CameraManager::CameraManager(int num, int width, int height, bool yuv) : QObject
|
|||||||
tempFrameBuffer = new u32[fbsize];
|
tempFrameBuffer = new u32[fbsize];
|
||||||
|
|
||||||
inputType = -1;
|
inputType = -1;
|
||||||
xFlip = false;
|
xFlip = config.GetBool("XFlip");
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,9 +160,9 @@ void CameraManager::init()
|
|||||||
|
|
||||||
startNum = 0;
|
startNum = 0;
|
||||||
|
|
||||||
inputType = Config::Camera[num].InputType;
|
inputType = config.GetInt("InputType");
|
||||||
imagePath = QString::fromStdString(Config::Camera[num].ImagePath);
|
imagePath = config.GetQString("ImagePath");
|
||||||
camDeviceName = QString::fromStdString(Config::Camera[num].CamDeviceName);
|
camDeviceName = config.GetQString("DeviceName");
|
||||||
|
|
||||||
camDevice = nullptr;
|
camDevice = nullptr;
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
class CameraManager;
|
class CameraManager;
|
||||||
|
|
||||||
@ -80,6 +81,8 @@ public:
|
|||||||
CameraManager(int num, int width, int height, bool yuv);
|
CameraManager(int num, int width, int height, bool yuv);
|
||||||
~CameraManager();
|
~CameraManager();
|
||||||
|
|
||||||
|
Config::Table& getConfig() { return config; }
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void deInit();
|
void deInit();
|
||||||
|
|
||||||
@ -106,6 +109,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
int num;
|
int num;
|
||||||
|
|
||||||
|
Config::Table config;
|
||||||
|
|
||||||
int startNum;
|
int startNum;
|
||||||
|
|
||||||
int inputType;
|
int inputType;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#include "CameraSettingsDialog.h"
|
#include "CameraSettingsDialog.h"
|
||||||
#include "ui_CameraSettingsDialog.h"
|
#include "ui_CameraSettingsDialog.h"
|
||||||
@ -71,9 +72,16 @@ CameraSettingsDialog::CameraSettingsDialog(QWidget* parent) : QDialog(parent), u
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
emuInstance = ((MainWindow*)parent)->getEmuInstance();
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
oldCamSettings[i] = Config::Camera[i];
|
auto& cfg = camManager[i]->getConfig();
|
||||||
|
|
||||||
|
oldCamSettings[i].InputType = cfg.GetInt("InputType");
|
||||||
|
oldCamSettings[i].ImagePath = cfg.GetString("ImagePath");
|
||||||
|
oldCamSettings[i].CamDeviceName = cfg.GetString("DeviceName");
|
||||||
|
oldCamSettings[i].XFlip = cfg.GetBool("XFlip");
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->cbCameraSel->addItem("DSi outer camera");
|
ui->cbCameraSel->addItem("DSi outer camera");
|
||||||
@ -161,7 +169,13 @@ void CameraSettingsDialog::on_CameraSettingsDialog_rejected()
|
|||||||
{
|
{
|
||||||
camManager[i]->stop();
|
camManager[i]->stop();
|
||||||
camManager[i]->deInit();
|
camManager[i]->deInit();
|
||||||
Config::Camera[i] = oldCamSettings[i];
|
|
||||||
|
auto& cfg = camManager[i]->getConfig();
|
||||||
|
cfg.SetInt("InputType", oldCamSettings[i].InputType);
|
||||||
|
cfg.SetString("ImagePath", oldCamSettings[i].ImagePath);
|
||||||
|
cfg.SetString("DeviceName", oldCamSettings[i].CamDeviceName);
|
||||||
|
cfg.SetBool("XFlip", oldCamSettings[i].XFlip);
|
||||||
|
|
||||||
camManager[i]->init();
|
camManager[i]->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +192,7 @@ void CameraSettingsDialog::on_cbCameraSel_currentIndexChanged(int id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentId = id;
|
currentId = id;
|
||||||
currentCfg = &Config::Camera[id];
|
currentCfg = &camManager[id]->getConfig();
|
||||||
//currentCam = camManager[id];
|
//currentCam = camManager[id];
|
||||||
currentCam = nullptr;
|
currentCam = nullptr;
|
||||||
populateCamControls(id);
|
populateCamControls(id);
|
||||||
@ -198,16 +212,16 @@ void CameraSettingsDialog::onChangeInputType(int type)
|
|||||||
currentCam->deInit();
|
currentCam->deInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
currentCfg->InputType = type;
|
currentCfg->SetInt("InputType", type);
|
||||||
|
|
||||||
ui->txtSrcImagePath->setEnabled(type == 1);
|
ui->txtSrcImagePath->setEnabled(type == 1);
|
||||||
ui->btnSrcImageBrowse->setEnabled(type == 1);
|
ui->btnSrcImageBrowse->setEnabled(type == 1);
|
||||||
ui->cbPhysicalCamera->setEnabled((type == 2) && (ui->cbPhysicalCamera->count()>0));
|
ui->cbPhysicalCamera->setEnabled((type == 2) && (ui->cbPhysicalCamera->count()>0));
|
||||||
|
|
||||||
currentCfg->ImagePath = ui->txtSrcImagePath->text().toStdString();
|
currentCfg->SetQString("ImagePath", ui->txtSrcImagePath->text());
|
||||||
|
|
||||||
if (ui->cbPhysicalCamera->count() > 0)
|
if (ui->cbPhysicalCamera->count() > 0)
|
||||||
currentCfg->CamDeviceName = ui->cbPhysicalCamera->currentData().toString().toStdString();
|
currentCfg->SetQString("DeviceName", ui->cbPhysicalCamera->currentData().toString());
|
||||||
|
|
||||||
if (currentCam)
|
if (currentCam)
|
||||||
{
|
{
|
||||||
@ -226,7 +240,7 @@ void CameraSettingsDialog::on_txtSrcImagePath_textChanged()
|
|||||||
currentCam->deInit();
|
currentCam->deInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
currentCfg->ImagePath = ui->txtSrcImagePath->text().toStdString();
|
currentCfg->SetQString("ImagePath", ui->txtSrcImagePath->text());
|
||||||
|
|
||||||
if (currentCam)
|
if (currentCam)
|
||||||
{
|
{
|
||||||
@ -257,7 +271,7 @@ void CameraSettingsDialog::on_cbPhysicalCamera_currentIndexChanged(int id)
|
|||||||
currentCam->deInit();
|
currentCam->deInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
currentCfg->CamDeviceName = ui->cbPhysicalCamera->itemData(id).toString().toStdString();
|
currentCfg->SetQString("DeviceName", ui->cbPhysicalCamera->itemData(id).toString());
|
||||||
|
|
||||||
if (currentCam)
|
if (currentCam)
|
||||||
{
|
{
|
||||||
@ -268,16 +282,16 @@ void CameraSettingsDialog::on_cbPhysicalCamera_currentIndexChanged(int id)
|
|||||||
|
|
||||||
void CameraSettingsDialog::populateCamControls(int id)
|
void CameraSettingsDialog::populateCamControls(int id)
|
||||||
{
|
{
|
||||||
Config::CameraConfig& cfg = Config::Camera[id];
|
Config::Table& cfg = camManager[id]->getConfig();
|
||||||
|
|
||||||
int type = cfg.InputType;
|
int type = cfg.GetInt("InputType");
|
||||||
if (type < 0 || type >= grpInputType->buttons().count()) type = 0;
|
if (type < 0 || type >= grpInputType->buttons().count()) type = 0;
|
||||||
grpInputType->button(type)->setChecked(true);
|
grpInputType->button(type)->setChecked(true);
|
||||||
|
|
||||||
ui->txtSrcImagePath->setText(QString::fromStdString(cfg.ImagePath));
|
ui->txtSrcImagePath->setText(cfg.GetQString("ImagePath"));
|
||||||
|
|
||||||
bool deviceset = false;
|
bool deviceset = false;
|
||||||
QString device = QString::fromStdString(cfg.CamDeviceName);
|
QString device = cfg.GetQString("DeviceName");
|
||||||
for (int i = 0; i < ui->cbPhysicalCamera->count(); i++)
|
for (int i = 0; i < ui->cbPhysicalCamera->count(); i++)
|
||||||
{
|
{
|
||||||
QString itemdev = ui->cbPhysicalCamera->itemData(i).toString();
|
QString itemdev = ui->cbPhysicalCamera->itemData(i).toString();
|
||||||
@ -293,13 +307,14 @@ void CameraSettingsDialog::populateCamControls(int id)
|
|||||||
|
|
||||||
onChangeInputType(type);
|
onChangeInputType(type);
|
||||||
|
|
||||||
ui->chkFlipPicture->setChecked(cfg.XFlip);
|
ui->chkFlipPicture->setChecked(cfg.GetBool("XFlip"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraSettingsDialog::on_chkFlipPicture_clicked()
|
void CameraSettingsDialog::on_chkFlipPicture_clicked()
|
||||||
{
|
{
|
||||||
if (!currentCfg) return;
|
if (!currentCfg) return;
|
||||||
|
|
||||||
currentCfg->XFlip = ui->chkFlipPicture->isChecked();
|
bool xflip = ui->chkFlipPicture->isChecked();
|
||||||
if (currentCam) currentCam->setXFlip(currentCfg->XFlip);
|
currentCfg->SetBool("XFlip", xflip);
|
||||||
|
if (currentCam) currentCam->setXFlip(xflip);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
namespace Ui { class CameraSettingsDialog; }
|
namespace Ui { class CameraSettingsDialog; }
|
||||||
class CameraSettingsDialog;
|
class CameraSettingsDialog;
|
||||||
|
|
||||||
|
class EmuInstance;
|
||||||
|
|
||||||
class CameraPreviewPanel : public QWidget
|
class CameraPreviewPanel : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -92,15 +94,22 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CameraSettingsDialog* ui;
|
Ui::CameraSettingsDialog* ui;
|
||||||
|
EmuInstance* emuInstance;
|
||||||
|
|
||||||
QButtonGroup* grpInputType;
|
QButtonGroup* grpInputType;
|
||||||
CameraPreviewPanel* previewPanel;
|
CameraPreviewPanel* previewPanel;
|
||||||
|
|
||||||
int currentId;
|
int currentId;
|
||||||
Config::CameraConfig* currentCfg;
|
Config::Table* currentCfg;
|
||||||
CameraManager* currentCam;
|
CameraManager* currentCam;
|
||||||
|
|
||||||
Config::CameraConfig oldCamSettings[2];
|
struct
|
||||||
|
{
|
||||||
|
int InputType; // 0=blank 1=image 2=camera
|
||||||
|
std::string ImagePath;
|
||||||
|
std::string CamDeviceName;
|
||||||
|
bool XFlip;
|
||||||
|
} oldCamSettings[2];
|
||||||
|
|
||||||
void populateCamControls(int id);
|
void populateCamControls(int id);
|
||||||
};
|
};
|
||||||
|
@ -48,8 +48,6 @@ int GL_ScaleFactor;
|
|||||||
bool GL_BetterPolygons;
|
bool GL_BetterPolygons;
|
||||||
bool GL_HiresCoordinates;
|
bool GL_HiresCoordinates;
|
||||||
|
|
||||||
CameraConfig Camera[2];
|
|
||||||
|
|
||||||
|
|
||||||
const char* kConfigFile = "melonDS.toml";
|
const char* kConfigFile = "melonDS.toml";
|
||||||
|
|
||||||
|
@ -25,9 +25,6 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
//#define TOML_HEADER_ONLY 0
|
|
||||||
//#include "toml/toml.hpp"
|
|
||||||
|
|
||||||
#ifndef TOML11_VALUE_HPP
|
#ifndef TOML11_VALUE_HPP
|
||||||
namespace toml
|
namespace toml
|
||||||
{
|
{
|
||||||
@ -46,23 +43,6 @@ struct LegacyEntry
|
|||||||
bool InstanceUnique; // whether the setting can exist individually for each instance in multiplayer
|
bool InstanceUnique; // whether the setting can exist individually for each instance in multiplayer
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ConfigEntry
|
|
||||||
{
|
|
||||||
char Name[32];
|
|
||||||
int Type; // 0=int 1=bool 2=string 3=64bit int
|
|
||||||
void* Value; // pointer to the value variable
|
|
||||||
std::variant<int, bool, std::string, int64_t> Default;
|
|
||||||
bool InstanceUnique; // whether the setting can exist individually for each instance in multiplayer
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CameraConfig
|
|
||||||
{
|
|
||||||
int InputType; // 0=blank 1=image 2=camera
|
|
||||||
std::string ImagePath;
|
|
||||||
std::string CamDeviceName;
|
|
||||||
bool XFlip;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using DefaultList = std::unordered_map<std::string, T>;
|
using DefaultList = std::unordered_map<std::string, T>;
|
||||||
|
|
||||||
@ -162,8 +142,6 @@ extern int GL_ScaleFactor;
|
|||||||
extern bool GL_BetterPolygons;
|
extern bool GL_BetterPolygons;
|
||||||
extern bool GL_HiresCoordinates;
|
extern bool GL_HiresCoordinates;
|
||||||
|
|
||||||
extern CameraConfig Camera[2];
|
|
||||||
|
|
||||||
|
|
||||||
bool Load();
|
bool Load();
|
||||||
void Save();
|
void Save();
|
||||||
|
@ -324,8 +324,6 @@ int main(int argc, char** argv)
|
|||||||
camStarted[1] = false;
|
camStarted[1] = false;
|
||||||
camManager[0] = new CameraManager(0, 640, 480, true);
|
camManager[0] = new CameraManager(0, 640, 480, true);
|
||||||
camManager[1] = new CameraManager(1, 640, 480, true);
|
camManager[1] = new CameraManager(1, 640, 480, true);
|
||||||
camManager[0]->setXFlip(Config::Camera[0].XFlip);
|
|
||||||
camManager[1]->setXFlip(Config::Camera[1].XFlip);
|
|
||||||
|
|
||||||
systemThemeName = new QString(QApplication::style()->objectName());
|
systemThemeName = new QString(QApplication::style()->objectName());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user