Add option to mirror the camera image horizontally.

Only for Windows right now - since the PSP expects the image as a JPEG and
the various backends deliver it as such, we have to add
platform-specific code to mirror the image pre-compression.
This commit is contained in:
Henrik Rydgård 2024-04-16 20:33:06 +02:00
parent fa8d8d1121
commit dbd774040e
4 changed files with 27 additions and 2 deletions

View file

@ -603,6 +603,7 @@ static const ConfigSetting graphicsSettings[] = {
ConfigSetting("D3D11Device", &g_Config.sD3D11Device, "", CfgFlag::DEFAULT),
#endif
ConfigSetting("CameraDevice", &g_Config.sCameraDevice, "", CfgFlag::DEFAULT),
ConfigSetting("CameraMirrorHorizontal", &g_Config.bCameraMirrorHorizontal, false, CfgFlag::DEFAULT),
ConfigSetting("AndroidFramerateMode", &g_Config.iDisplayFramerateMode, 1, CfgFlag::DEFAULT),
ConfigSetting("VendorBugChecksEnabled", &g_Config.bVendorBugChecksEnabled, true, CfgFlag::DONT_SAVE),
ConfigSetting("UseGeometryShader", &g_Config.bUseGeometryShader, false, CfgFlag::PER_GAME),

View file

@ -158,6 +158,7 @@ public:
std::string sD3D11Device; // Windows only
std::string sCameraDevice;
std::string sMicDevice;
bool bCameraMirrorHorizontal;
int iDisplayFramerateMode; // enum DisplayFramerateMode. Android-only.
bool bSoftwareRendering;

View file

@ -587,6 +587,9 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings)
graphicsSettings->Add(new ItemHeader(gr->T("Camera")));
PopupMultiChoiceDynamic *cameraChoice = graphicsSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sCameraDevice, gr->T("Camera Device"), cameraList, I18NCat::NONE, screenManager()));
cameraChoice->OnChoice.Handle(this, &GameSettingsScreen::OnCameraDeviceChange);
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
graphicsSettings->Add(new CheckBox(&g_Config.bCameraMirrorHorizontal, gr->T("Mirror camera image")));
#endif
}
graphicsSettings->Add(new ItemHeader(gr->T("Hack Settings", "Hack Settings (these WILL cause glitches)")));

View file

@ -16,6 +16,7 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <shlwapi.h>
#include "Common/Thread/ThreadUtil.h"
#include "CaptureDevice.h"
#include "BufferLock.h"
@ -180,8 +181,8 @@ HRESULT ReaderCallback::OnReadSample(
else
srcPadding = device->deviceParam.default_stride - lStride;
if (SUCCEEDED(hr)) {
#ifdef USE_FFMPEG
if (SUCCEEDED(hr)) {
// Convert image to RGB24
if (lStride > 0) {
imgConvert(
@ -199,6 +200,25 @@ HRESULT ReaderCallback::OnReadSample(
av_free(invertedSrcImg);
}
// Mirror the image in-place if needed.
if (g_Config.bCameraMirrorHorizontal) {
for (int y = 0; y < dstH; y++) {
uint8_t *line = device->imageRGB + y * device->imgRGBLineSizes[0];
for (int x = 0; x < dstW / 2; x++) {
const uint8_t r = line[x * 3];
const uint8_t g = line[x * 3 + 1];
const uint8_t b = line[x * 3 + 1];
const int invX = (dstW - 1 - x);
line[x * 3 + 0] = line[invX * 3 + 0];
line[x * 3 + 1] = line[invX * 3 + 1];
line[x * 3 + 2] = line[invX * 3 + 2];
line[invX * 3 + 0] = r;
line[invX * 3 + 1] = g;
line[invX * 3 + 2] = b;
}
}
}
// Compress image to jpeg from RGB24.
jpge::compress_image_to_jpeg_file_in_memory(
device->imageJpeg, imgJpegSize,
@ -206,8 +226,8 @@ HRESULT ReaderCallback::OnReadSample(
dstH,
3,
device->imageRGB);
#endif
}
#endif
Camera::pushCameraImage(imgJpegSize, device->imageJpeg);
}
// Request the next frame.