[Ffmpeg-devel] [RFC] rtjpeg decoding functions

Justin Schoeman justin
Wed Jan 18 09:07:12 CET 2006


;-) Nice to see rtjpeg is still around, although I can't for the life of 
me see why.  When I first wrote it, it was in the days of Pentium 166's, 
and was specifically designed to allow real time encoding on these 
platforms. (That is the reason for the 8-bit aligned codes - 
bitstreaming simply cost to much on x86 class machines back then.)

However, there are now much better encoders that can be used on even the 
slowest machines currently available, so I don't really see the need to 
keep it going? Not that I mind - it is actually a bit flattering 
(although some credits would be nice).

-justin

Reimar D?ffinger wrote:
> Hi,
> the attached patch constains (untested) rtjpeg decoding functions. These
> are _not_ in a decoder module, since I do not know of any pure rtjpeg
> codec, and nuv must select between different codings on a per-frame
> basis.
> Any comments or a "testbed" are welcome.
> 
> Greetings,
> Reimar D?ffinger
> 
> 
> ------------------------------------------------------------------------
> 
> Index: libavcodec/Makefile
> ===================================================================
> RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/Makefile,v
> retrieving revision 1.226
> diff -u -r1.226 Makefile
> --- libavcodec/Makefile	15 Jan 2006 00:28:35 -0000	1.226
> +++ libavcodec/Makefile	17 Jan 2006 19:54:48 -0000
> @@ -18,7 +18,7 @@
>        fft.o mdct.o raw.o golomb.o cabac.o\
>        dpcm.o adx.o faandct.o parser.o g726.o \
>        vp3dsp.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o \
> -      opt.o
> +      opt.o rtjpeg.o
>  
>  ifeq ($(CONFIG_AASC_DECODER),yes)
>      OBJS+= aasc.o
> Index: libavcodec/rtjpeg.c
> ===================================================================
> RCS file: libavcodec/rtjpeg.c
> diff -N libavcodec/rtjpeg.c
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ libavcodec/rtjpeg.c	17 Jan 2006 19:54:50 -0000
> @@ -0,0 +1,121 @@
> +/*
> + * RTJpeg decoding functions
> + * Copyright (c) 2006 Reimar Doeffinger
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +#include "common.h"
> +#include "bitstream.h"
> +#include "dsputil.h"
> +#include "rtjpeg.h"
> +
> +#define PUT_COEFF(c) \
> +    i = scan[coeff--]; \
> +    block[i] = c * quant[i];
> +
> +static inline int get_block(GetBitContext *gb, DCTELEM *block, uint8_t *scan,
> +                            uint32_t *quant) {
> +    int coeff, i;
> +    int8_t ac;
> +    uint8_t dc = get_bits(gb, 8);
> +
> +    // block not coded
> +    if (dc == 255)
> +       return 0;
> +
> +    // number of non-zero coefficients
> +    coeff = get_bits(gb, 6);
> +    memset(&block[coeff + 1], 0, 63 - coeff);
> +
> +    // 2 bits per coefficient
> +    while (coeff) {
> +        ac = get_sbits(gb, 2);
> +        if (ac == -2)
> +            break; // continue with more bits
> +        PUT_COEFF(ac);
> +    }
> +
> +    // 4 bits per coefficient
> +    align_get_bits_to(gb, 4);
> +    while (coeff) {
> +        ac = get_sbits(gb, 4);
> +        if (ac == -8)
> +            break; // continue with more bits
> +        PUT_COEFF(ac);
> +    }
> +
> +    // 8 bits per coefficient
> +    align_get_bits_to(gb, 8);
> +    while (coeff) {
> +        ac = get_sbits(gb, 8);
> +        PUT_COEFF(ac);
> +    }
> +
> +    PUT_COEFF(dc);
> +    return 1;
> +}
> +
> +void rtjpeg_decode_frame_yuv420(RTJpegContext *c, AVFrame *f,
> +                                uint8_t *buf, int buf_size) {
> +    GetBitContext gb;
> +    int w = c->w / 16, h = c->h / 16;
> +    int x, y;
> +    void *y1 = f->data[0], *y2 = f->data[0] + 8 * f->linesize[0];
> +    void *u = f->data[1], *v = f->data[2];
> +    init_get_bits(&gb, buf, buf_size * 8);
> +    for (y = 0; y < h; y++) {
> +        for (x = 0; x < w; x++) {
> +            if (get_block(&gb, c->block, c->scan, c->lquant))
> +                c->dsp->idct_put(y1, f->linesize[0], c->block);
> +            y1 += 8;
> +            if (get_block(&gb, c->block, c->scan, c->lquant))
> +                c->dsp->idct_put(y1, f->linesize[0], c->block);
> +            y1 += 8;
> +            if (get_block(&gb, c->block, c->scan, c->lquant))
> +                c->dsp->idct_put(y2, f->linesize[0], c->block);
> +            y2 += 8;
> +            if (get_block(&gb, c->block, c->scan, c->lquant))
> +                c->dsp->idct_put(y2, f->linesize[0], c->block);
> +            y2 += 8;
> +            if (get_block(&gb, c->block, c->scan, c->lquant))
> +                c->dsp->idct_put(u, f->linesize[1], c->block);
> +            u += 8;
> +            if (get_block(&gb, c->block, c->scan, c->lquant))
> +                c->dsp->idct_put(u, f->linesize[2], c->block);
> +            v += 8;
> +        }
> +        y1 += 16 * f->linesize[0] - 16 * w;
> +        y2 += 16 * f->linesize[0] - 16 * w;
> +        u += 8 * f->linesize[1] - 8 * w;
> +        v += 8 * f->linesize[2] - 8 * w;
> +    }
> +}
> +
> +void rtjpeg_decode_init(RTJpegContext *c, DSPContext *dsp,
> +                        int width, int height,
> +                        uint32_t *lquant, uint32_t *cquant) {
> +    int i;
> +    c->dsp = dsp;
> +    for (i = 0; i < 64; i++) {
> +        int z = ff_zigzag_direct[i];
> +        int p = c->dsp->idct_permutation[i];
> +        z = ((z << 3) | (z >> 3)) & 63; // rtjpeg uses a transposed variant
> +        c->scan[i] = c->dsp->idct_permutation[z];
> +        c->lquant[p] = lquant[i];
> +        c->cquant[p] = cquant[i];
> +    }
> +    c->w = width;
> +    c->h = height;
> +}
> Index: libavcodec/rtjpeg.h
> ===================================================================
> RCS file: libavcodec/rtjpeg.h
> diff -N libavcodec/rtjpeg.h
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ libavcodec/rtjpeg.h	17 Jan 2006 19:54:50 -0000
> @@ -0,0 +1,13 @@
> +#ifndef RTJPEG_H
> +#define RTJPEG_H
> +
> +typedef struct {
> +    int w, h;
> +    DSPContext *dsp;
> +    DCTELEM block[64];
> +    uint8_t scan[64];
> +    uint32_t lquant[64];
> +    uint32_t cquant[64];
> +} RTJpegContext;
> +
> +#endif
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> http://mplayerhq.hu/mailman/listinfo/ffmpeg-devel





More information about the ffmpeg-devel mailing list