11f18faf |
/*
* huffyuv codec for libavcodec
* |
7cf8918b |
* Copyright (c) 2002-2014 Michael Niedermayer <michaelni@gmx.at> |
11f18faf |
* |
7b94177e |
* see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
* the algorithm used
* |
b78e7197 |
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or |
11f18faf |
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either |
b78e7197 |
* version 2.1 of the License, or (at your option) any later version. |
11f18faf |
* |
b78e7197 |
* FFmpeg is distributed in the hope that it will be useful, |
11f18faf |
* 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 |
b78e7197 |
* License along with FFmpeg; if not, write to the Free Software |
5509bffa |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
11f18faf |
*/ |
115329f1 |
|
983e3246 |
/** |
ba87f080 |
* @file |
983e3246 |
* huffyuv codec for libavcodec.
*/ |
11f18faf |
|
2ca5ca29 |
#include <stdint.h> |
ae5873f1 |
|
2ca5ca29 |
#include "libavutil/mem.h" |
115329f1 |
|
2ca5ca29 |
#include "avcodec.h" |
c67b449b |
#include "bswapdsp.h" |
2ca5ca29 |
#include "huffyuv.h" |
11f18faf |
|
b53aab1a |
int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n) |
e0f7a9f6 |
{ |
11f18faf |
int len, index; |
e0f7a9f6 |
uint32_t bits = 0; |
11f18faf |
|
e0f7a9f6 |
for (len = 32; len > 0; len--) { |
b53aab1a |
for (index = 0; index < n; index++) { |
e0f7a9f6 |
if (len_table[index] == len)
dst[index] = bits++; |
11f18faf |
} |
e0f7a9f6 |
if (bits & 1) { |
9b879566 |
av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n"); |
14b74d38 |
return -1;
}
bits >>= 1; |
11f18faf |
}
return 0;
}
|
2ca5ca29 |
av_cold int ff_huffyuv_alloc_temp(HYuvContext *s) |
e0f7a9f6 |
{ |
ae2f1d46 |
int i; |
115329f1 |
|
4332b01c |
for (i=0; i<3; i++) {
s->temp[i]= av_malloc(4*s->width + 16);
if (!s->temp[i]) |
4a722a5c |
return AVERROR(ENOMEM); |
4332b01c |
s->temp16[i] = (uint16_t*)s->temp[i]; |
ae2f1d46 |
} |
4a722a5c |
return 0; |
ae2f1d46 |
}
|
2ca5ca29 |
av_cold void ff_huffyuv_common_init(AVCodecContext *avctx) |
e0f7a9f6 |
{ |
11f18faf |
HYuvContext *s = avctx->priv_data;
|
e0f7a9f6 |
s->avctx = avctx;
s->flags = avctx->flags; |
115329f1 |
|
c67b449b |
ff_bswapdsp_init(&s->bdsp); |
115329f1 |
|
e0f7a9f6 |
s->width = avctx->width;
s->height = avctx->height; |
115329f1 |
|
def18e54 |
av_assert1(s->width > 0 && s->height > 0); |
0ecca7a4 |
}
|
def18e54 |
av_cold void ff_huffyuv_common_end(HYuvContext *s) |
4a722a5c |
{
int i;
for(i = 0; i < 3; i++) {
av_freep(&s->temp[i]); |
b53aab1a |
s->temp16[i] = NULL; |
4a722a5c |
} |
7c5ab7b8 |
} |