[FFmpeg-devel] [PATCH] Simplify codebook allocation for Escape 124
Benoit Fouet
benoit.fouet
Wed Apr 2 09:27:21 CEST 2008
Hi,
Eli Friedman wrote:
> Index: libavcodec/escape124.c
> ===================================================================
> --- libavcodec/escape124.c (revision 12665)
> +++ libavcodec/escape124.c (working copy)
> @@ -83,23 +83,27 @@
> return 0;
> }
>
> -static CodeBook unpack_codebook(GetBitContext* gb, unsigned depth,
> - unsigned size)
> +static void unpack_codebook(GetBitContext* gb, unsigned depth,
> + unsigned size, CodeBook* cb)
> {
> unsigned i, j;
> - CodeBook cb = { 0 };
>
> + cb->depth = depth;
> + cb->size = 0;
> + av_free(cb->blocks);
> + cb->blocks = NULL;
> +
> if (!can_safely_read(gb, size * 34))
> - return cb;
> + return;
>
> if (size >= INT_MAX / sizeof(MacroBlock))
> - return cb;
> - cb.blocks = av_malloc(size ? size * sizeof(MacroBlock) : 1);
> - if (!cb.blocks)
> - return cb;
> + return;
> + cb->blocks = av_malloc(size * sizeof(MacroBlock));
> + if (!cb->blocks)
> + return;
>
> - cb.depth = depth;
> - cb.size = size;
> + cb->size = size;
> +
> for (i = 0; i < size; i++) {
> unsigned mask_bits = get_bits(gb, 4);
> unsigned color0 = get_bits(gb, 15);
> @@ -107,12 +111,12 @@
>
> for (j = 0; j < 4; j++) {
> if (mask_bits & (1 << j))
> - cb.blocks[i].pixels[j] = color1;
> + cb->blocks[i].pixels[j] = color1;
> else
> - cb.blocks[i].pixels[j] = color0;
> + cb->blocks[i].pixels[j] = color0;
> }
> }
> - return cb;
> + return;
> }
>
> static unsigned decode_skip_count(GetBitContext* gb)
> @@ -265,10 +269,7 @@
> cb_size = s->num_superblocks << cb_depth;
> }
> }
> - av_free(s->codebooks[i].blocks);
> - s->codebooks[i] = unpack_codebook(&gb, cb_depth, cb_size);
> - if (!s->codebooks[i].blocks)
> - return -1;
>
why does this check is removed ?
> + unpack_codebook(&gb, cb_depth, cb_size, &s->codebooks[i]);
> }
> }
>
--
Benoit Fouet
Purple Labs S.A.
www.purplelabs.com
More information about the ffmpeg-devel
mailing list