[FFmpeg-devel] [PATCH] Add DPX decoder rev-8

Michael Niedermayer michaelni
Fri May 15 03:51:29 CEST 2009


On Mon, May 11, 2009 at 11:31:25AM +0200, Jimmy Christensen wrote:
[...]
> +typedef struct DPXContext {
> +    AVFrame picture;
> +    int width;
> +    int height;

> +    int bpp;

useless


> +    int color_type;
> +    int compression_type;
> +} DPXContext;
> +
> +static unsigned int read32(const uint8_t *ptr, int is_big)
> +{
> +    return is_big ? AV_RB32(ptr) : AV_RL32(ptr);
> +}
> +
> +static int decode_frame(AVCodecContext *avctx,
> +                        void *data,
> +                        int *data_size,
> +                        AVPacket *avpkt)
> +{
> +    const uint8_t *headerBuffer = avpkt->data;
> +    const uint8_t *buf          = avpkt->data;
> +    int buf_size                = avpkt->size;
> +    DPXContext *const s = avctx->priv_data;
> +    AVFrame *picture  = data;
> +    AVFrame *const p = &s->picture;
> +    uint8_t *ptr;
> +    struct RGB10Field rgb10Field;
> +    struct RGB16Field rgb16Field;
> +
> +    int magic_num, offset;
> +    char version[8];
> +    int x, y;
> +    int w, h, orientation, stride, dstBpp;
> +
> +    unsigned int rgbBuffer;
> +    int endian = 0;
> +
> +    magic_num = AV_RB32(headerBuffer);
> +
> +    headerBuffer += 4;
> +
> +    /* Check if the files "magic number" is "SDPX" which means it uses
> +     * big-endian or XPDS which is for little-endian files */
> +    if (magic_num == MKTAG('S', 'D', 'P', 'X'))
> +        endian = 0;
> +    else if (magic_num == MKTAG('X', 'P', 'D', 'S'))
> +        endian = 1;
> +    else {
> +        av_log(avctx, AV_LOG_ERROR, "DPX marker not found");
> +        return -1;
> +    }
> +
> +    offset = read32(headerBuffer, endian);
> +    headerBuffer += 4;
> +    bytestream_get_buffer(&headerBuffer, version, 8);
> +    headerBuffer += 8;
> +    // Jump in extra 744 bytes to end at address 744 + 4 + 4 + 8 = 760 = 0x2f8
> +    headerBuffer += 744;
> +    orientation = read32(headerBuffer, endian);
> +    headerBuffer += 4;
> +    w = read32(headerBuffer, endian);
> +    headerBuffer += 4;
> +    h = read32(headerBuffer, endian);
> +    headerBuffer += 4;

your read32() function could add 4 to headerBuffer


[...]
> +    for (x = 0; x < s->height; x++) {
> +        uint8_t *dst = ptr;
> +        for (y = 0; y < s->width; y++) {

> +            rgbBuffer = AV_RB32(buf);
> +            memcpy(&rgb10Field, &rgbBuffer, 4);
> +            rgb16Field.R = rgb10Field.R * 64; // 10-bit > 16-bit
> +            rgb16Field.G = rgb10Field.G * 64; // 10-bit > 16-bit
> +            rgb16Field.B = rgb10Field.B * 64; // 10-bit > 16-bit
> +            memcpy(dst, &rgb16Field, dstBpp);

not portable


> +            dst += dstBpp;
> +            buf += 4;
> +        }
> +        ptr += stride;
> +    }
> +
> +    *picture   = s->picture;
> +    *data_size = sizeof(AVPicture);
> +
> +    return buf_size;
> +}
> +

> +static av_cold int dpx_init(AVCodecContext *avctx)
> +{
> +    DPXContext *s = avctx->priv_data;
> +    avcodec_get_frame_defaults((AVFrame*) &s->picture);
> +    avctx->coded_frame = (AVFrame*) &s->picture;
> +    return 0;
> +}

useless casts

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

No snowflake in an avalanche ever feels responsible. -- Voltaire
-------------- 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/20090515/9c370b2d/attachment.pgp>



More information about the ffmpeg-devel mailing list