[MPlayer-dev-eng] [PATCH 2/6] gui: Use new lavc decode API for PNG decode.

Alexander Strasser eclipse7 at gmx.net
Sat Jan 9 02:11:53 EET 2021


On 2020-12-20 18:50 +0100, Reimar Döffinger wrote:
> ---
>  gui/util/bitmap.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/gui/util/bitmap.c b/gui/util/bitmap.c
> index fa0522fcb..ff7cbf4c1 100644
> --- a/gui/util/bitmap.c
> +++ b/gui/util/bitmap.c
> @@ -124,8 +124,6 @@ static int pngRead(const char *fname, guiImage *img, int *pix_fmt)
>          return 6;
>      }
>
> -    avcodec_register_all();
> -
>      if (avcodec_open2(avctx, avcodec_find_decoder(AV_CODEC_ID_PNG), NULL) < 0) {
>          av_free(frame);
>          av_free(avctx);
> @@ -139,7 +137,8 @@ static int pngRead(const char *fname, guiImage *img, int *pix_fmt)
>      /* HACK: Make PNGs decode normally instead of as CorePNG delta frames. */
>      pkt.flags = AV_PKT_FLAG_KEY;
>

> -    avcodec_decode_video2(avctx, frame, &decode_ok, &pkt);
> +    avcodec_send_packet(avctx, &pkt);
> +    decode_ok = avcodec_receive_frame(avctx, frame);

I may be gravely misunderstanding things, but I would argue a

    avcodec_send_packet(avctx, NULL);

once before trying to receive, would better match the protocol
of the send/receive API. It may never make a difference here,
but that's not my point.


>      memset(img, 0, sizeof(*img));
>      memset(palette, 0, sizeof(palette));
> @@ -165,7 +164,7 @@ static int pngRead(const char *fname, guiImage *img, int *pix_fmt)
>          break;
>      }
>
> -    if (decode_ok && img->Bpp) {
> +    if (decode_ok >= 0 && img->Bpp) {
>          img->Width  = avctx->width;
>          img->Height = avctx->height;
>          bpl = img->Width * (img->Bpp / 8);
> @@ -183,7 +182,7 @@ static int pngRead(const char *fname, guiImage *img, int *pix_fmt)
>              if (frame->data[1])
>                  memcpy(palette, frame->data[1], sizeof(palette));
>          } else
> -            decode_ok = False;
> +            decode_ok = -1;
>      }
>
>      avcodec_close(avctx);
> @@ -191,7 +190,7 @@ static int pngRead(const char *fname, guiImage *img, int *pix_fmt)
>      av_free(avctx);
>      av_free(data);
>
> -    return !(decode_ok && img->Bpp);
> +    return !(decode_ok >= 0 && img->Bpp);
>  }
>
>  /**
> --

Otherwise LGTM, but Ingo should decide on this one.


  Alexander


More information about the MPlayer-dev-eng mailing list