implement xflip in the UI
This commit is contained in:
parent
7c9e37b156
commit
308ea6289a
|
@ -22,7 +22,7 @@
|
|||
|
||||
CameraFrameDumper::CameraFrameDumper(QObject* parent) : QAbstractVideoSurface(parent)
|
||||
{
|
||||
camList.append((CameraManager*)parent);
|
||||
cam = (CameraManager*)parent;
|
||||
}
|
||||
|
||||
bool CameraFrameDumper::present(const QVideoFrame& _frame)
|
||||
|
@ -33,8 +33,7 @@ bool CameraFrameDumper::present(const QVideoFrame& _frame)
|
|||
if (!frame.isReadable())
|
||||
return false;
|
||||
|
||||
for (CameraManager* cam : camList)
|
||||
cam->feedFrame((u32*)frame.bits(), frame.width(), frame.height(), frame.pixelFormat() == QVideoFrame::Format_YUYV);
|
||||
cam->feedFrame((u32*)frame.bits(), frame.width(), frame.height(), frame.pixelFormat() == QVideoFrame::Format_YUYV);
|
||||
|
||||
frame.unmap();
|
||||
|
||||
|
@ -71,6 +70,7 @@ CameraManager::CameraManager(int num, int width, int height, bool yuv) : QObject
|
|||
frameBuffer = new u32[fbsize];
|
||||
|
||||
inputType = -1;
|
||||
xFlip = false;
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -120,13 +120,14 @@ void CameraManager::init()
|
|||
if (frameFormatYUV)
|
||||
{
|
||||
copyFrame_RGBtoYUV((u32*)img.bits(), img.width(), img.height(),
|
||||
frameBuffer, frameWidth, frameHeight);
|
||||
frameBuffer, frameWidth, frameHeight,
|
||||
false);
|
||||
}
|
||||
else
|
||||
{
|
||||
copyFrame_Straight((u32*)img.bits(), img.width(), img.height(),
|
||||
frameBuffer, frameWidth, frameHeight,
|
||||
false);
|
||||
false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -205,11 +206,19 @@ void CameraManager::camStop()
|
|||
camDevice->stop();
|
||||
}
|
||||
|
||||
void CameraManager::setXFlip(bool flip)
|
||||
{
|
||||
xFlip = flip;
|
||||
}
|
||||
|
||||
void CameraManager::captureFrame(u32* frame, int width, int height, bool yuv)
|
||||
{
|
||||
frameMutex.lock();
|
||||
|
||||
if (width == frameWidth && height == frameHeight && yuv == frameFormatYUV)
|
||||
if ((width == frameWidth) &&
|
||||
(height == frameHeight) &&
|
||||
(yuv == frameFormatYUV) &&
|
||||
(!xFlip))
|
||||
{
|
||||
int len = width * height;
|
||||
if (yuv) len /= 2;
|
||||
|
@ -221,17 +230,19 @@ void CameraManager::captureFrame(u32* frame, int width, int height, bool yuv)
|
|||
{
|
||||
copyFrame_Straight(frameBuffer, frameWidth, frameHeight,
|
||||
frame, width, height,
|
||||
yuv);
|
||||
xFlip, yuv);
|
||||
}
|
||||
else if (yuv)
|
||||
{
|
||||
copyFrame_RGBtoYUV(frameBuffer, frameWidth, frameHeight,
|
||||
frame, width, height);
|
||||
frame, width, height,
|
||||
xFlip);
|
||||
}
|
||||
else
|
||||
{
|
||||
copyFrame_YUVtoRGB(frameBuffer, frameWidth, frameHeight,
|
||||
frame, width, height);
|
||||
frame, width, height,
|
||||
xFlip);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,24 +265,26 @@ void CameraManager::feedFrame(u32* frame, int width, int height, bool yuv)
|
|||
{
|
||||
copyFrame_Straight(frame, width, height,
|
||||
frameBuffer, frameWidth, frameHeight,
|
||||
yuv);
|
||||
false, yuv);
|
||||
}
|
||||
else if (yuv)
|
||||
{
|
||||
copyFrame_RGBtoYUV(frame, width, height,
|
||||
frameBuffer, frameWidth, frameHeight);
|
||||
frameBuffer, frameWidth, frameHeight,
|
||||
false);
|
||||
}
|
||||
else
|
||||
{
|
||||
copyFrame_YUVtoRGB(frame, width, height,
|
||||
frameBuffer, frameWidth, frameHeight);
|
||||
frameBuffer, frameWidth, frameHeight,
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
frameMutex.unlock();
|
||||
}
|
||||
|
||||
void CameraManager::copyFrame_Straight(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight, bool yuv)
|
||||
void CameraManager::copyFrame_Straight(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight, bool xflip, bool yuv)
|
||||
{
|
||||
if (yuv)
|
||||
{
|
||||
|
@ -286,13 +299,14 @@ void CameraManager::copyFrame_Straight(u32* src, int swidth, int sheight, u32* d
|
|||
for (int dx = 0; dx < dwidth; dx++)
|
||||
{
|
||||
int sx = (dx * swidth) / dwidth;
|
||||
if (xflip) sx = swidth-1 - sx;
|
||||
|
||||
dst[(dy * dwidth) + dx] = src[(sy * swidth) + sx];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CameraManager::copyFrame_RGBtoYUV(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight)
|
||||
void CameraManager::copyFrame_RGBtoYUV(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight, bool xflip)
|
||||
{
|
||||
for (int dy = 0; dy < dheight; dy++)
|
||||
{
|
||||
|
@ -303,9 +317,13 @@ void CameraManager::copyFrame_RGBtoYUV(u32* src, int swidth, int sheight, u32* d
|
|||
int sx;
|
||||
|
||||
sx = (dx * swidth) / dwidth;
|
||||
if (xflip) sx = swidth-1 - sx;
|
||||
|
||||
u32 pixel1 = src[sy*swidth + sx];
|
||||
|
||||
sx = ((dx+1) * swidth) / dwidth;
|
||||
if (xflip) sx = swidth-1 - sx;
|
||||
|
||||
u32 pixel2 = src[sy*swidth + sx];
|
||||
|
||||
int r1 = (pixel1 >> 16) & 0xFF;
|
||||
|
@ -339,7 +357,7 @@ void CameraManager::copyFrame_RGBtoYUV(u32* src, int swidth, int sheight, u32* d
|
|||
}
|
||||
}
|
||||
|
||||
void CameraManager::copyFrame_YUVtoRGB(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight)
|
||||
void CameraManager::copyFrame_YUVtoRGB(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight, bool xflip)
|
||||
{
|
||||
for (int dy = 0; dy < dheight; dy++)
|
||||
{
|
||||
|
@ -348,6 +366,8 @@ void CameraManager::copyFrame_YUVtoRGB(u32* src, int swidth, int sheight, u32* d
|
|||
for (int dx = 0; dx < dwidth; dx+=2)
|
||||
{
|
||||
int sx = (dx * swidth) / dwidth;
|
||||
if (xflip) sx = swidth-1 - sx;
|
||||
|
||||
u32 val = src[(sy*swidth + sx) / 2];
|
||||
|
||||
int y1 = val & 0xFF;
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const override;
|
||||
|
||||
private:
|
||||
QList<CameraManager*> camList;
|
||||
CameraManager* cam;
|
||||
};
|
||||
|
||||
class CameraManager : public QObject
|
||||
|
@ -58,6 +58,8 @@ public:
|
|||
void stop();
|
||||
bool isStarted();
|
||||
|
||||
void setXFlip(bool flip);
|
||||
|
||||
void captureFrame(u32* frame, int width, int height, bool yuv);
|
||||
|
||||
void feedFrame(u32* frame, int width, int height, bool yuv);
|
||||
|
@ -87,9 +89,11 @@ private:
|
|||
u32* frameBuffer;
|
||||
QMutex frameMutex;
|
||||
|
||||
void copyFrame_Straight(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight, bool yuv);
|
||||
void copyFrame_RGBtoYUV(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight);
|
||||
void copyFrame_YUVtoRGB(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight);
|
||||
bool xFlip;
|
||||
|
||||
void copyFrame_Straight(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight, bool xflip, bool yuv);
|
||||
void copyFrame_RGBtoYUV(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight, bool xflip);
|
||||
void copyFrame_YUVtoRGB(u32* src, int swidth, int sheight, u32* dst, int dwidth, int dheight, bool xflip);
|
||||
};
|
||||
|
||||
#endif // CAMERAMANAGER_H
|
||||
|
|
|
@ -270,3 +270,11 @@ void CameraSettingsDialog::populateCamControls(int id)
|
|||
|
||||
ui->chkFlipPicture->setChecked(cfg.XFlip);
|
||||
}
|
||||
|
||||
void CameraSettingsDialog::on_chkFlipPicture_clicked()
|
||||
{
|
||||
if (!currentCfg) return;
|
||||
|
||||
currentCfg->XFlip = ui->chkFlipPicture->isChecked();
|
||||
if (currentCam) currentCam->setXFlip(currentCfg->XFlip);
|
||||
}
|
||||
|
|
|
@ -79,9 +79,6 @@ public:
|
|||
currentDlg = nullptr;
|
||||
}
|
||||
|
||||
signals:
|
||||
//
|
||||
|
||||
private slots:
|
||||
void on_CameraSettingsDialog_accepted();
|
||||
void on_CameraSettingsDialog_rejected();
|
||||
|
@ -91,6 +88,7 @@ private slots:
|
|||
void on_txtSrcImagePath_textChanged();
|
||||
void on_btnSrcImageBrowse_clicked();
|
||||
void on_cbPhysicalCamera_currentIndexChanged(int id);
|
||||
void on_chkFlipPicture_clicked();
|
||||
|
||||
private:
|
||||
Ui::CameraSettingsDialog* ui;
|
||||
|
|
|
@ -3233,6 +3233,8 @@ int main(int argc, char** argv)
|
|||
camStarted[1] = false;
|
||||
camManager[0] = new CameraManager(0, 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);
|
||||
|
||||
ROMManager::EnableCheats(Config::EnableCheats != 0);
|
||||
|
||||
|
|
Loading…
Reference in New Issue