int ArraySetDlg::exec() { int w,h; getModeSize( w, h ); ui.mLabTipDis->setText(QString(toChs("当前模式是%1 X %2,建议至少为%3。")).arg(w).arg(h).arg(w+50)); ui.mSpinDis->setValue( w + 50 ); return QDialog::exec(); }
void AVForm::selectBestModes(QVector<VideoMode> &allVideoModes) { // Identify the best resolutions available for the supposed XXXXp resolutions. std::map<int, VideoMode> idealModes; idealModes[120] = VideoMode(160, 120); idealModes[240] = VideoMode(430, 240); idealModes[360] = VideoMode(640, 360); idealModes[480] = VideoMode(854, 480); idealModes[720] = VideoMode(1280, 720); idealModes[1080] = VideoMode(1920, 1080); std::map<int, int> bestModeInds; for (int i = 0; i < allVideoModes.size(); ++i) { VideoMode mode = allVideoModes[i]; // PS3-Cam protection, everything above 60fps makes no sense if (mode.FPS > 60) continue; for (auto iter = idealModes.begin(); iter != idealModes.end(); ++iter) { int res = iter->first; VideoMode idealMode = iter->second; // don't take approximately correct resolutions unless they really // are close if (mode.norm(idealMode) > 300) continue; if (bestModeInds.find(res) == bestModeInds.end()) { bestModeInds[res] = i; continue; } int index = bestModeInds[res]; VideoMode best = allVideoModes[index]; if (mode.norm(idealMode) < best.norm(idealMode)) { bestModeInds[res] = i; continue; } if (mode.norm(idealMode) == best.norm(idealMode)) { // prefer higher FPS and "better" pixel formats if (mode.FPS > best.FPS) { bestModeInds[res] = i; continue; } bool better = CameraDevice::betterPixelFormat(mode.pixel_format, best.pixel_format); if (mode.FPS >= best.FPS && better) bestModeInds[res] = i; } } } QVector<VideoMode> newVideoModes; for (auto it = bestModeInds.rbegin(); it != bestModeInds.rend(); ++it) { VideoMode mode = allVideoModes[it->second]; if (newVideoModes.empty()) { newVideoModes.push_back(mode); } else { int size = getModeSize(mode); auto result = std::find_if(newVideoModes.cbegin(), newVideoModes.cend(), [size](VideoMode mode) { return getModeSize(mode) == size; }); if (result == newVideoModes.end()) newVideoModes.push_back(mode); } } allVideoModes = newVideoModes; }