Quoting Diego Biurrun (2015-03-31 16:31:33)
> +unsigned ff_els_decode_unsigned(ElsDecCtx *ctx, ElsUnsignedRung *ur)
> +{
> +    int i, n, r, bit;
> +    ElsRungNode *rung_node;
> +
> +    if (ctx->err)
> +        return 0;
> +
> +    /* decode unary prefix */
> +    for (n = 0; n < ELS_EXPGOLOMB_LEN + 1; n++)
> +        if (ff_els_decode_bit(ctx, &ur->prefix_rung[n]))
> +            break;
> +
> +    /* handle the error/overflow case */
> +    if (ctx->err || n >= ELS_EXPGOLOMB_LEN) {
> +        ctx->err = AVERROR(EOVERFLOW);
> +        return 0;
> +    }
> +
> +    /* handle the zero case */
> +    if (!n)
> +        return 0;
> +
> +    /* initialize probability tree */
> +    if (!ur->rem_rung_list) {
> +        ur->rem_rung_list = av_mallocz(RUNG_SPACE);
> +        if (!ur->rem_rung_list) {
> +            ctx->err = AVERROR(ENOMEM); // Probability tree initialization 
> failed
> +            return 0;
> +        }
> +        ur->rung_list_size = RUNG_SPACE;
> +        ur->avail_index    = ELS_EXPGOLOMB_LEN;
> +    }
> +
> +    /* decode the remainder */
> +    for (i = 0, r = 0, bit = 0; i < n; i++) {
> +        if (!i)
> +            rung_node = &ur->rem_rung_list[n];
> +        else {
> +            if (!rung_node->next_index) {
> +                if (ur->rung_list_size <= (ur->avail_index + 2) * 
> sizeof(ElsRungNode)) {
> +                    // remember rung_node position
> +                    ptrdiff_t pos     = rung_node - ur->rem_rung_list;
> +                    ur->rem_rung_list = av_realloc(ur->rem_rung_list,
> +                                                   ur->rung_list_size +
> +                                                   RUNG_SPACE);
> +                    if (!ur->rem_rung_list) {

memleak on failure

> +#define LOAD_NEIGHBOURS(x)      \
> +    W   = curr_row[(x)   - 1];  \
> +    N   = above_row[(x)];       \
> +    WW  = curr_row[(x)   - 2];  \
> +    NW  = above_row[(x)  - 1];  \
> +    NE  = above_row[(x)  + 1];  \
> +    NN  = above2_row[(x)];      \
> +    NNW = above2_row[(x) - 1];  \
> +    NWW = above_row[(x)  - 2];  \
> +    NNE = above2_row[(x) + 1]
> +
> +#define UPDATE_NEIGHBOURS(x)    \
> +    NNW = NN;                   \
> +    NN  = NNE;                  \
> +    NWW = NW;                   \
> +    NW  = N;                    \
> +    N   = NE;                   \
> +    NE  = above_row[(x)  + 1];  \
> +    NNE = above2_row[(x) + 1]
> +
> +#define R_shift 16
> +#define G_shift  8
> +#define B_shift  0
> +
> +static inline int log2_ceil(uint32_t x)
> +{
> +    int c = 0;
> +
> +    for (--x; x > 0; x >>= 1, c++)
> +        ;

Nit: I think this would look better with c++ in the loop body. But maybe
that's just me.

> +static int epic_jb_decode_tile(G2MContext *c, int tile_x, int tile_y,
> +                               const uint8_t *src, size_t src_size,
> +                               AVCodecContext *avctx)
> +{
> +    uint8_t prefix, mask;
> +    int extrabytes, tile_width, tile_height, awidth, aheight;
> +    size_t els_dsize;
> +    uint8_t *dst;
> +
> +    if (!src_size)
> +        return 0;
> +
> +    /* get data size of the ELS partition as unsigned variable-length 
> integer */
> +    prefix = *src++;
> +    for (extrabytes = 0, mask = 0x80; (prefix & mask) && (extrabytes < 7);
> +         mask >>= 1, extrabytes++)
> +        ;

Again, I think mask >>= 1 would look better in the loop body.

> +    if (extrabytes > 3 || --src_size < extrabytes) {

I think it'd be cleaner to decrement src_size immediately after we read
from src above.


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

Reply via email to