From 971e0ec056e6200064598dbca49c18b8653e08d4 Mon Sep 17 00:00:00 2001
From: tue46wsdgxfjrt <jfbvxt@gmail.com>
Date: Tue, 2 Sep 2014 13:57:45 -0700
Subject: [PATCH] Prevent vf_cropdetect from returning negative rectangle
 sizes.

---
 libavfilter/vf_cropdetect.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index f85a0bb..f554ff8 100644
--- a/libavfilter/vf_cropdetect.c
+++ b/libavfilter/vf_cropdetect.c
@@ -106,8 +106,8 @@ static int config_input(AVFilterLink *inlink)
 
     s->x1 = inlink->w - 1;
     s->y1 = inlink->h - 1;
-    s->x2 = 0;
-    s->y2 = 0;
+    s->x2 = inlink->w - 1;
+    s->y2 = inlink->h - 1;
 
     return 0;
 }
@@ -131,8 +131,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
         if (s->reset_count > 0 && s->frame_nb > s->reset_count) {
             s->x1 = frame->width  - 1;
             s->y1 = frame->height - 1;
-            s->x2 = 0;
-            s->y2 = 0;
+            s->x2 = frame->width  - 1;
+            s->y2 = frame->height - 1;
             s->frame_nb = 1;
         }
 
@@ -143,7 +143,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             }
         }
 
-        for (y = frame->height - 1; y > s->y2; y--) {
+        for (y = frame->height - 1; y >= s->y1; y--) {
             if (checkline(ctx, frame->data[0] + frame->linesize[0] * y, bpp, frame->width, bpp) > s->limit) {
                 s->y2 = y;
                 break;
@@ -157,7 +157,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             }
         }
 
-        for (y = frame->width - 1; y > s->x2; y--) {
+        for (y = frame->width - 1; y >= s->x1; y--) {
             if (checkline(ctx, frame->data[0] + bpp*y, frame->linesize[0], frame->height, bpp) > s->limit) {
                 s->x2 = y;
                 break;
-- 
1.8.5.2 (Apple Git-48)

