qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
videomode.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2015-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "videomode.h"
21 
37 VideoMode::VideoMode(int width, int height, int x, int y, float FPS)
38  : width(width)
39  , height(height)
40  , x(x)
41  , y(y)
42  , FPS(FPS)
43 {
44 }
45 
47  : width(rect.width())
48  , height(rect.height())
49  , x(rect.x())
50  , y(rect.y())
51 {
52 }
53 
54 QRect VideoMode::toRect() const
55 {
56  return QRect(x, y, width, height);
57 }
58 
59 bool VideoMode::operator==(const VideoMode& other) const
60 {
61  return width == other.width && height == other.height && x == other.x && y == other.y
62  && qFuzzyCompare(FPS, other.FPS) && pixel_format == other.pixel_format;
63 }
64 
65 uint32_t VideoMode::norm(const VideoMode& other) const
66 {
67  return qAbs(this->width - other.width) + qAbs(this->height - other.height);
68 }
69 
70 uint32_t VideoMode::tolerance() const
71 {
72  constexpr uint32_t minTolerance = 300; // keep wider tolerance for low res cameras
73  constexpr uint32_t toleranceFactor = 10; // video mode must be within 10% to be "close enough" to ideal
74  return std::max((width + height)/toleranceFactor, minTolerance);
75 }
76 
80 VideoMode::operator bool() const
81 {
82  return width || height || static_cast<int>(FPS);
83 }
videomode.h
VideoMode::x
int x
Definition: videomode.h:28
VideoMode::tolerance
uint32_t tolerance() const
Definition: videomode.cpp:70
VideoMode::pixel_format
uint32_t pixel_format
Definition: videomode.h:30
VideoMode::height
int height
Displayed video resolution (NOT frame resolution).
Definition: videomode.h:27
VideoMode::norm
uint32_t norm(const VideoMode &other) const
Definition: videomode.cpp:65
VideoMode::operator==
bool operator==(const VideoMode &other) const
Definition: videomode.cpp:59
VideoMode::toRect
QRect toRect() const
Definition: videomode.cpp:54
VideoMode::width
int width
Definition: videomode.h:27
VideoMode::y
int y
Coordinates of upper-left corner.
Definition: videomode.h:28
VideoMode::VideoMode
VideoMode(int width=0, int height=0, int x=0, int y=0, float FPS=-1.0f)
Definition: videomode.cpp:37
VideoMode
Describes a video mode supported by a device.
Definition: videomode.h:25
VideoMode::FPS
float FPS
Frames per second supported by the device at this resolution.
Definition: videomode.h:29