[FFmpeg-devel] [Toy] Aura 1 and 2 decoder

Michael Niedermayer michaelni
Sun Mar 22 02:38:34 CET 2009


On Mon, Mar 16, 2009 at 09:32:59AM +0200, Kostya wrote:
> $subj - a lazy hack done with a left leg.
> Released before it too rotten.


[...]
> +static int aura_decode_frame(AVCodecContext *avctx,
> +                             void *data, int *data_size,
> +                             const uint8_t *buf, int buf_size)
> +{
> +    AuraDecodeContext *s=avctx->priv_data;
> +
> +    uint8_t *y_plane;
> +    uint8_t *u_plane;
> +    uint8_t *v_plane;
> +    int y_ptr;
> +    int u_ptr;
> +    int v_ptr;
> +
> +    /* prediction error tables (make it clear that they are signed values) */

> +    const int8_t *y_table = (const int8_t*)buf + 16;
> +    const int8_t *c_table = (const int8_t*)buf + 16;

redundant, they both point to the same table


> +
> +    uint8_t y_pred, u_pred, v_pred;
> +    int stream_ptr;
> +    uint8_t cur_byte;
> +    int pixel_groups;
> +

> +    /* sanity check the buffer size: A buffer has 3x16-bytes tables
> +     * followed by (height) lines each with 3 bytes to represent groups
> +     * of 4 pixels. Thus, the total size of the buffer ought to be:
> +     *    (3 * 16) + height * (width * 3 / 4) */
> +    if (buf_size != 48 + s->height * s->width) {
> +      av_log(avctx, AV_LOG_ERROR, "ffmpeg: cyuv: got a buffer with %d bytes when %d were expected\n",
> +        buf_size,
> +        48 + s->height * s->width);
> +      return -1;
> +    }

the indention ...


> +
> +    /* pixel data starts 48 bytes in, after 3x16-byte tables */
> +    stream_ptr = 48;
> +
> +    if(s->frame.data[0])
> +        avctx->release_buffer(avctx, &s->frame);
> +
> +    s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;
> +    s->frame.reference = 0;
> +    if(avctx->get_buffer(avctx, &s->frame) < 0) {
> +        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
> +        return -1;
> +    }
> +
> +    y_plane = s->frame.data[0];
> +    u_plane = s->frame.data[1];
> +    v_plane = s->frame.data[2];
> +

> +    /* iterate through each line in the height */
> +    for (y_ptr = 0, u_ptr = 0, v_ptr = 0;
> +         y_ptr < (s->height * s->frame.linesize[0]);
> +         y_ptr += s->frame.linesize[0] - s->width,
> +         u_ptr += s->frame.linesize[1] - s->width / 2,
> +         v_ptr += s->frame.linesize[2] - s->width / 2) {

this is ugly


> +
> +        /* reset predictors */
> +        cur_byte = buf[stream_ptr++];
> +        u_plane[u_ptr++] = u_pred = cur_byte & 0xF0;

> +        y_plane[y_ptr++] = y_pred = (cur_byte & 0x0F) << 4;

the & is superflous


> +
> +        cur_byte = buf[stream_ptr++];
> +        v_plane[v_ptr++] = v_pred = cur_byte & 0xF0;
> +        y_pred += y_table[cur_byte & 0x0F];
> +        y_plane[y_ptr++] = y_pred;
> +
> +        /* iterate through the remaining pixel groups (4 pixels/group) */
> +        pixel_groups = s->width / 2 - 1;
> +        while (pixel_groups--) {
> +
> +            cur_byte = buf[stream_ptr++];

> +            u_pred += c_table[(cur_byte & 0xF0) >> 4];

useless &


> +            u_plane[u_ptr++] = u_pred;

is there a reason why its not
*u_ptr++ = ... ?

[...]
> Index: libavformat/riff.c
> ===================================================================
> --- libavformat/riff.c	(revision 17586)
> +++ libavformat/riff.c	(working copy)
> @@ -201,6 +201,8 @@
>      { CODEC_ID_RPZA,         MKTAG('R', 'P', 'Z', 'A') },
>      { CODEC_ID_RPZA,         MKTAG('r', 'p', 'z', 'a') },
>      { CODEC_ID_SP5X,         MKTAG('S', 'P', '5', '4') },
> +    { CODEC_ID_AURA,         MKTAG('A', 'U', 'R', 'A') },
> +    { CODEC_ID_AURA2,        MKTAG('A', 'U', 'R', '2') },
>      { CODEC_ID_NONE,         0 }
>  };
>  

hunk ok, also the one adding these to avcodec.h

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090322/fd7ad0da/attachment.pgp>



More information about the ffmpeg-devel mailing list