diff mbox

[FFmpeg-devel] libavfilter/vf_find_rect: convert the object image to gray8 format instead of failed directly

Message ID 20190606055441.5691-1-lance.lmwang@gmail.com
State Superseded
Headers show

Commit Message

Lance Wang June 6, 2019, 5:54 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/vf_find_rect.c | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)

Comments

Michael Niedermayer June 6, 2019, 10:55 p.m. UTC | #1
On Thu, Jun 06, 2019 at 01:54:41PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavfilter/vf_find_rect.c | 37 ++++++++++++++++++++++++++-----------
>  1 file changed, 26 insertions(+), 11 deletions(-)
> 
> diff --git a/libavfilter/vf_find_rect.c b/libavfilter/vf_find_rect.c
> index d7e6579af7..abf7d89d21 100644
> --- a/libavfilter/vf_find_rect.c
> +++ b/libavfilter/vf_find_rect.c
> @@ -28,6 +28,7 @@
>  #include "internal.h"
>  
>  #include "lavfutils.h"
> +#include "lswsutils.h"
>  
>  #define MAX_MIPMAPS 5
>  

> @@ -244,6 +245,7 @@ static av_cold int init(AVFilterContext *ctx)
>  {
>      FOCContext *foc = ctx->priv;
>      int ret, i;

> +    AVFrame tmp_frame;

AVFrames size cannot be used outside libavutil as it breaks extensibility


[...]
Lance Wang June 7, 2019, 10:42 a.m. UTC | #2
On Fri, Jun 7, 2019 at 6:56 AM Michael Niedermayer <michael@niedermayer.cc>
wrote:

> On Thu, Jun 06, 2019 at 01:54:41PM +0800, lance.lmwang@gmail.com wrote:
> > From: Limin Wang <lance.lmwang@gmail.com>
> >
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavfilter/vf_find_rect.c | 37 ++++++++++++++++++++++++++-----------
> >  1 file changed, 26 insertions(+), 11 deletions(-)
> >
> > diff --git a/libavfilter/vf_find_rect.c b/libavfilter/vf_find_rect.c
> > index d7e6579af7..abf7d89d21 100644
> > --- a/libavfilter/vf_find_rect.c
> > +++ b/libavfilter/vf_find_rect.c
> > @@ -28,6 +28,7 @@
> >  #include "internal.h"
> >
> >  #include "lavfutils.h"
> > +#include "lswsutils.h"
> >
> >  #define MAX_MIPMAPS 5
> >
>
> > @@ -244,6 +245,7 @@ static av_cold int init(AVFilterContext *ctx)
> >  {
> >      FOCContext *foc = ctx->priv;
> >      int ret, i;
>
> > +    AVFrame tmp_frame;
>
> AVFrames size cannot be used outside libavutil as it breaks extensibility
>
>
OK, I have updated the patch for review.


>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> I am the wisest man alive, for I know one thing, and that is that I know
> nothing. -- Socrates
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox

Patch

diff --git a/libavfilter/vf_find_rect.c b/libavfilter/vf_find_rect.c
index d7e6579af7..abf7d89d21 100644
--- a/libavfilter/vf_find_rect.c
+++ b/libavfilter/vf_find_rect.c
@@ -28,6 +28,7 @@ 
 #include "internal.h"
 
 #include "lavfutils.h"
+#include "lswsutils.h"
 
 #define MAX_MIPMAPS 5
 
@@ -244,6 +245,7 @@  static av_cold int init(AVFilterContext *ctx)
 {
     FOCContext *foc = ctx->priv;
     int ret, i;
+    AVFrame tmp_frame;
 
     if (!foc->obj_filename) {
         av_log(ctx, AV_LOG_ERROR, "object filename not set\n");
@@ -254,24 +256,37 @@  static av_cold int init(AVFilterContext *ctx)
     if (!foc->obj_frame)
         return AVERROR(ENOMEM);
 
-    if ((ret = ff_load_image(foc->obj_frame->data, foc->obj_frame->linesize,
-                             &foc->obj_frame->width, &foc->obj_frame->height,
-                             &foc->obj_frame->format, foc->obj_filename, ctx)) < 0)
-        return ret;
-
-    if (foc->obj_frame->format != AV_PIX_FMT_GRAY8) {
-        av_log(ctx, AV_LOG_ERROR, "object image is not a grayscale image\n");
-        return AVERROR(EINVAL);
-    }
+    if ((ret = ff_load_image(&tmp_frame.data, tmp_frame.linesize,
+                             &tmp_frame.width, &tmp_frame.height,
+                             &tmp_frame.format, foc->obj_filename, ctx)) < 0)
+        goto error;
+
+    /* convert object image to gray8 format with same width and height */
+    foc->obj_frame->format = AV_PIX_FMT_GRAY8;
+    foc->obj_frame->width  = tmp_frame.width;
+    foc->obj_frame->height = tmp_frame.height;
+    if ((ret = ff_scale_image(foc->obj_frame->data, foc->obj_frame->linesize, foc->obj_frame->width, foc->obj_frame->height,
+                              foc->obj_frame->format, tmp_frame.data, tmp_frame.linesize, tmp_frame.width, tmp_frame.height,
+                              tmp_frame.format, ctx)) < 0)
+        goto error;
+    av_freep(&tmp_frame.data);
 
     foc->needle_frame[0] = av_frame_clone(foc->obj_frame);
     for (i = 1; i < foc->mipmaps; i++) {
         foc->needle_frame[i] = downscale(foc->needle_frame[i-1]);
-        if (!foc->needle_frame[i])
-            return AVERROR(ENOMEM);
+        if (!foc->needle_frame[i]) {
+            ret = AVERROR(ENOMEM);
+            goto error;
+        }
     }
 
     return 0;
+error:
+    if (foc->obj_frame)
+        av_freep(&foc->obj_frame->data[0]);
+    av_frame_free(&foc->obj_frame);
+    return ret;
+
 }
 
 static const AVFilterPad foc_inputs[] = {