You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Keyframe::IsIncreasing(): Search over points, not values
Searching over the keyframe points is considerably faster than calculating interpolating values and searching over them.
This commit is contained in:
@@ -282,13 +282,23 @@ bool Keyframe::IsIncreasing(int index) const
|
||||
if (index < 1 || (index + 1) >= GetLength()) {
|
||||
return true;
|
||||
}
|
||||
int64_t const current = GetLong(index);
|
||||
// TODO: skip over constant sections.
|
||||
std::vector<Point>::const_iterator candidate =
|
||||
std::lower_bound(begin(Points), end(Points), static_cast<double>(index), IsPointBeforeX);
|
||||
if (candidate == end(Points)) {
|
||||
return false; // After the last point, thus constant.
|
||||
}
|
||||
if ((candidate->co.X == index) || (candidate == begin(Points))) {
|
||||
++candidate;
|
||||
}
|
||||
int64_t const value = GetLong(index);
|
||||
do {
|
||||
int64_t const next = GetLong(++index);
|
||||
if (next > current) return true;
|
||||
if (next < current) return false;
|
||||
} while (index < GetLength());
|
||||
if (value < round(candidate->co.Y)) {
|
||||
return true;
|
||||
} else if (value > round(candidate->co.Y)) {
|
||||
return false;
|
||||
}
|
||||
++candidate;
|
||||
} while (candidate != end(Points));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user