Проведи ревью кода: #include "cameramodel.h" #include <QMediaDevices> #include…
- User
Проведи ревью кода: #include "cameramodel.h"
#include #include
#include "common/dataformat.h"
#include "interfaces/iphotosconfigure.h"
namespace {
constexpr auto NULL_RANGE_DIFF(-1); constexpr auto RESOLUTION_ASPECT(4.0/3.0);
}
CameraModel::CameraModel(QObject *parent) : QObject(parent) { }
void CameraModel::setupResolution(bool ready) { if (ready) { m_imageCapture->setResolution(resolveResolution()); } }
QSize CameraModel::maxSupportedResolution() const { const QList resolutions = supportedResolutions();
QSize res = *std::max_element(resolutions.constBegin(), resolutions.constEnd(), [](const QSize &ls, const QSize &rs) -> bool { return ls.width() < rs.width(); }); return res;}
QSize CameraModel::resolveResolution() const { int sideLength = photosConfigure()->maxPhotoSize(); if (sideLength == 0) { return maxSupportedResolution(); }
QSize res; int minRangeDiff = NULL_RANGE_DIFF; const QList<QSize> resolutions = supportedResolutions(); for (const QSize &resolution : resolutions) { int maxResolutionSize = std::max(resolution.width(), resolution.height()); int rangeDiff = std::abs(maxResolutionSize - sideLength); if (minRangeDiff == NULL_RANGE_DIFF) { minRangeDiff = rangeDiff; } if (rangeDiff <= minRangeDiff) { minRangeDiff = rangeDiff; res = resolution; } } return res;}
QList CameraModel::supportedResolutions() const { QList res;
const QList<QSize> allResolutions = QMediaDevices::defaultVideoInput().photoResolutions(); for (const QSize &resolution : allResolutions) { double aspect = static_cast<double>(resolution.width()) / static_cast<double>(resolution.height()); if (DataFormat::doubleEqual(aspect, RESOLUTION_ASPECT)) { res << resolution; } } return res.isEmpty() ? allResolutions : res;}
QImageCapture *CameraModel::imageCapture() const { return m_imageCapture; }
void CameraModel::setImageCapture(QImageCapture *newImageCapture) { if (m_imageCapture == newImageCapture) { return; }
disconnect(m_imageCapture, &QImageCapture::readyForCaptureChanged, this, &CameraModel::setupResolution); m_imageCapture = newImageCapture; connect(m_imageCapture, &QImageCapture::readyForCaptureChanged, this, &CameraModel::setupResolution); emit imageCaptureChanged();}
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.