On 02/19/2012 09:44 AM, Anton Khirnov wrote:

> ---
>  libavcodec/sgienc.c |   38 ++++++++++++++++++++++++--------------
>  1 files changed, 24 insertions(+), 14 deletions(-)
> 
> diff --git a/libavcodec/sgienc.c b/libavcodec/sgienc.c
> index 9d02eea..2fb5bd3 100644
> --- a/libavcodec/sgienc.c
> +++ b/libavcodec/sgienc.c
> @@ -21,6 +21,7 @@
>  
>  #include "avcodec.h"
>  #include "bytestream.h"
> +#include "internal.h"
>  #include "sgi.h"
>  #include "rle.h"
>  
> @@ -41,17 +42,17 @@ static av_cold int encode_init(AVCodecContext *avctx)
>      return 0;
>  }
>  
> -static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
> -                        int buf_size, void *data)
> +static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
> +                        const AVFrame *frame, int *got_packet)
>  {
>      SgiContext *s = avctx->priv_data;
>      AVFrame * const p = &s->picture;
> -    uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf;
> -    int x, y, z, length, tablesize;
> +    uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf, *buf;
> +    int x, y, z, length = SGI_HEADER_SIZE, tablesize, ret;


the 'length' assignment kind of gets lost in there. i would prefer if
it's moved down to the section before it's incremented.

>      unsigned int width, height, depth, dimension;
> -    unsigned char *orig_buf = buf, *end_buf = buf + buf_size;
> +    unsigned char *end_buf;
>  
> -    *p = *(AVFrame*)data;
> +    *p = *frame;
>      p->pict_type = AV_PICTURE_TYPE_I;
>      p->key_frame = 1;
>  
> @@ -76,12 +77,17 @@ static int encode_frame(AVCodecContext *avctx, unsigned 
> char *buf,
>      }
>  
>      tablesize = depth * height * 4;
> -    length = tablesize * 2 + SGI_HEADER_SIZE;
> -
> -    if (buf_size < length) {
> -        av_log(avctx, AV_LOG_ERROR, "buf_size too small(need %d, got %d)\n", 
> length, buf_size);
> -        return -1;
> +    if (avctx->coder_type == FF_CODER_TYPE_RAW)
> +        length += depth*height*width;
> +    else // assume ff_rl_encode() produces at most 2x size of input
> +        length += tablesize*2 + depth*height*(2*width + 1);


give those operators some room to breathe.

the rest looks fine.

-Justin

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to