19 int integral =
int(floor(value));
20 value -= qreal(integral);
24 const int dMax = 1000;
25 int n1 = 0, d1 = 1, n2 = 1, d2 = 1;
27 while (d1 <= dMax && d2 <= dMax) {
28 mid = qreal(n1 + n2) / (d1 + d2);
30 if (qAbs(value - mid) < 0.000001) {
32 }
else if (value > mid) {
42 return {n1 + n2 + integral * (d1 + d2), d1 + d2};
44 return { n2 + integral * d2, d2 };
46 return { n1 + integral * d1, d1 };
106qNormalizedSurfaceTransformation(
const QVideoFrameFormat &format)
108 VideoTransformation result;
109 result.mirrorVertically(format.scanLineDirection() == QVideoFrameFormat::BottomToTop);
110 result.rotate(format.rotation());
111 result.mirrorHorizontally(format.isMirrored());
116 VideoTransformation videoOutputTransformation)
118 VideoTransformation result = qNormalizedSurfaceTransformation(frame.surfaceFormat());
119 result.rotate(frame.rotation());
120 result.mirrorHorizontally(frame.mirrored());
121 result.rotate(videoOutputTransformation.rotation);
122 result.mirrorHorizontally(videoOutputTransformation.mirroredHorizontallyAfterRotation);
146 const qreal absScaleX =
std::hypot(matrix.m11(), matrix.m12());
147 const qreal absScaleY =
std::hypot(matrix.m21(), matrix.m22());
149 if (qFuzzyIsNull(absScaleX) || qFuzzyIsNull(absScaleY))
152 qreal cos1 = matrix.m11() / absScaleX;
153 qreal sin1 = matrix.m12() / absScaleX;
156 const qreal sin2 = -matrix.m21() / absScaleY;
157 const qreal cos2 = matrix.m22() / absScaleY;
159 VideoTransformation result;
163 if (std::abs(cos1) + std::abs(cos2) > std::abs(sin1) + std::abs(sin2))
164 result.mirroredHorizontallyAfterRotation = std::signbit(cos1) != std::signbit(cos2);
166 result.mirroredHorizontallyAfterRotation = std::signbit(sin1) != std::signbit(sin2);
168 if (result.mirroredHorizontallyAfterRotation) {
173 const qreal maxDiscrepancy = 0.2;
175 if (
std::abs(cos1 - cos2) > maxDiscrepancy ||
std::abs(sin1 - sin2) > maxDiscrepancy)
178 const qreal angle = atan2(sin1 + sin2, cos1 + cos2);
179 Q_ASSERT(!
std::isnan(angle));
181 result.rotation = qVideoRotationFromDegrees(qRound(angle /
M_PI_2) * 90);