[FFmpeg-devel] [PATCH] avcodec: add Apple Pixlet decoder
James Almer
jamrial at gmail.com
Mon Dec 19 19:59:06 EET 2016
On 12/19/2016 11:18 AM, Paul B Mahol wrote:
> +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);
escape = av_mod_uintp2(16383, nbits);
> + 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;
> + }
> + }
> +
> + if (i + rlen > size)
> + return AVERROR_INVALIDDATA;
> +
> + for (j = 0; j < rlen; j++)
> + dst[i++] = 0;
> +
> + rparam = 0;
> + flag = rlen < 0xFFFF ? 1 : 0;
> + }
> +
> + align_get_bits(b);
> + return get_bits_count(b) >> 3;
> +}
More information about the ffmpeg-devel
mailing list