[FFmpeg-devel] [PATCH] avcodec: add Apple Pixlet decoder

Michael Niedermayer michael at niedermayer.cc
Tue Dec 20 17:52:10 EET 2016


On Mon, Dec 19, 2016 at 03:18:00PM +0100, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
>  doc/general.texi        |   1 +
>  libavcodec/Makefile     |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/avcodec.h    |   1 +
>  libavcodec/codec_desc.c |   7 +
>  libavcodec/pixlet.c     | 726 ++++++++++++++++++++++++++++++++++++++++++++++++
>  libavformat/isom.c      |   2 +
>  7 files changed, 739 insertions(+)
>  create mode 100644 libavcodec/pixlet.c
[...]
> +static int read_low_coeffs(AVCodecContext *avctx, int16_t *dst, int size)
> +{
> +    PixletContext *ctx = avctx->priv_data;
> +    GetBitContext *b = &ctx->gbit;
> +    unsigned value, cnt1, nbits, j, i = 0;
> +    int rlen, flag = 0, escape;
> +    int64_t rparam = 3;
> +
> +    while (i < size) {
> +        nbits = FFMIN(ff_clz((rparam >> 8) + 3) ^ 0x1F, 14);
> +

> +        cnt1 = get_unary(b, 0, 8);
> +        if (cnt1 < 8) {
> +            value = show_bits(b, nbits);
> +            if (value <= 1) {
> +                skip_bits(b, nbits - 1);
> +                escape = ((1 << nbits) - 1) * cnt1;
> +            } else {
> +                skip_bits(b, nbits);
> +                escape = value + ((1 << nbits) - 1) * cnt1 - 1;
> +            }
> +        } else {
> +            escape = get_bits(b, 16);
> +        }

> +
> +        rlen = -((escape + flag) & 1) | 1;
> +        dst[i++] = rlen * ((escape + flag + 1) >> 1);
> +        rparam += 120 * (escape + flag) - (120 * rparam >> 8);
> +        flag = 0;
> +
> +        if (rparam * 4 > 0xFF || i >= size)
> +            continue;
> +
> +        nbits = ((rparam + 8) >> 5) + (rparam ? ff_clz(rparam) : 32) - 24;
> +        escape = 16383 & ((1 << nbits) - 1);

> +        cnt1 = get_unary(b, 0, 8);
> +        if (cnt1 > 7) {
> +            rlen = get_bits(b, 16);
> +        } else {
> +            value = show_bits(b, nbits);
> +            if (value > 1) {
> +                skip_bits(b, nbits);
> +                rlen = value + escape * cnt1 - 1;
> +            } else {
> +                if (nbits - 1 > 0)
> +                    skip_bits(b, nbits - 1);
> +                rlen = escape * cnt1;
> +            }
> +        }

this and the previous such block look very similar
so do the ones in read_high_coeffs()
can they be factored or are there subtele differences that make that
annoying ?


[...]
> +static void reconstruction(AVCodecContext *avctx,
> +                           int16_t *dest, unsigned width, unsigned height, size_t stride, int nb_levels,
> +                           float *scaling_H, float *scaling_V, int lowres)
> +{
> +    PixletContext *ctx = avctx->priv_data;
> +    unsigned scaled_width, scaled_height;
> +    float scale_H, scale_V;
> +    int16_t *ptr, *tmp;
> +    int i, j, k;
> +
> +    scaled_height = height >> nb_levels;
> +    scaled_width  = width  >> nb_levels;
> +    tmp = ctx->filter[0];
> +
> +    for (i = 0; i < nb_levels; i++) {
> +        scaled_width  <<= 1;
> +        scaled_height <<= 1;
> +        scale_H = scaling_H[i + lowres];
> +        scale_V = scaling_V[i + lowres];
> +
> +        ptr = dest;
> +        for (j = 0; j < scaled_height; j++) {
> +            filter(ptr, ctx->filter[1], scaled_width, scale_V);
> +            ptr += stride;
> +        }
> +
> +        for (j = 0; j < scaled_width; j++) {
> +            ptr = dest + j;
> +            for (k = 0; k < scaled_height; k++) {
> +                tmp[k] = *ptr;
> +                ptr += stride;
> +            }
> +
> +            filter(tmp, ctx->filter[1], scaled_height, scale_H);
> +
> +            ptr = dest + j;
> +            for (k = 0; k < scaled_height; k++) {
> +                *ptr = tmp[k];
> +                ptr += stride;
> +            }

the whole codec does quite a bit of copying and extra passes
(for example postprocess could be merged into prior steps)
not sure this matters or how important speed for this codec is?


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

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161220/220e9a5d/attachment.sig>


More information about the ffmpeg-devel mailing list