summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/mp_common.c23
-rw-r--r--core/mp_common.h3
2 files changed, 26 insertions, 0 deletions
diff --git a/core/mp_common.c b/core/mp_common.c
index eecd0710cc..c931c29065 100644
--- a/core/mp_common.c
+++ b/core/mp_common.c
@@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <libavutil/common.h>
+
#include "talloc.h"
#include "core/mp_common.h"
@@ -34,3 +36,24 @@ char *mp_format_time(double time, bool fractions)
(int)((time - (int)time) * 1000));
return res;
}
+
+// Set rc to the union of rc and rc2
+void mp_rect_union(struct mp_rect *rc, const struct mp_rect *rc2)
+{
+ rc->x0 = FFMIN(rc->x0, rc2->x0);
+ rc->y0 = FFMIN(rc->y0, rc2->y0);
+ rc->x1 = FFMAX(rc->x1, rc2->x1);
+ rc->y1 = FFMAX(rc->y1, rc2->y1);
+}
+
+// Set rc to the intersection of rc and src.
+// Return false if the result is empty.
+bool mp_rect_intersection(struct mp_rect *rc, const struct mp_rect *rc2)
+{
+ rc->x0 = FFMAX(rc->x0, rc2->x0);
+ rc->y0 = FFMAX(rc->y0, rc2->y0);
+ rc->x1 = FFMIN(rc->x1, rc2->x1);
+ rc->y1 = FFMIN(rc->y1, rc2->y1);
+
+ return rc->x1 > rc->x0 && rc->y1 > rc->y0;
+}
diff --git a/core/mp_common.h b/core/mp_common.h
index 0ee14ab484..6736a08a18 100644
--- a/core/mp_common.h
+++ b/core/mp_common.h
@@ -43,4 +43,7 @@ struct mp_rect {
int x1, y1;
};
+void mp_rect_union(struct mp_rect *rc, const struct mp_rect *src);
+bool mp_rect_intersection(struct mp_rect *rc, const struct mp_rect *rc2);
+
#endif /* MPLAYER_MPCOMMON_H */