2002-11-14 20:20:04 +01:00
|
|
|
/*
|
|
|
|
* huffyuv codec for libavcodec
|
|
|
|
*
|
2014-01-27 01:45:57 +01:00
|
|
|
* Copyright (c) 2002-2014 Michael Niedermayer <michaelni@gmx.at>
|
2002-11-14 20:20:04 +01:00
|
|
|
*
|
2007-07-05 12:37:29 +02:00
|
|
|
* see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
|
|
|
|
* the algorithm used
|
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-11-14 20:20:04 +01:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 17:30:46 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2002-11-14 20:20:04 +01:00
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2002-11-14 20:20:04 +01:00
|
|
|
* 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
|
2006-10-07 17:30:46 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 23:43:26 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-11-14 20:20:04 +01:00
|
|
|
*/
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2003-03-06 12:32:04 +01:00
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2003-03-06 12:32:04 +01:00
|
|
|
* huffyuv codec for libavcodec.
|
|
|
|
*/
|
2002-11-14 20:20:04 +01:00
|
|
|
|
2012-12-06 14:06:46 +01:00
|
|
|
#include <stdint.h>
|
2011-11-28 15:07:48 +01:00
|
|
|
|
2012-12-06 14:06:46 +01:00
|
|
|
#include "libavutil/mem.h"
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2012-12-06 14:06:46 +01:00
|
|
|
#include "avcodec.h"
|
|
|
|
#include "huffyuv.h"
|
2002-11-14 20:20:04 +01:00
|
|
|
|
2014-01-13 01:14:05 +01:00
|
|
|
int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n)
|
2012-08-27 12:30:13 +02:00
|
|
|
{
|
2002-11-14 20:20:04 +01:00
|
|
|
int len, index;
|
2012-08-27 12:30:13 +02:00
|
|
|
uint32_t bits = 0;
|
2002-11-14 20:20:04 +01:00
|
|
|
|
2012-08-27 12:30:13 +02:00
|
|
|
for (len = 32; len > 0; len--) {
|
2014-01-13 01:14:05 +01:00
|
|
|
for (index = 0; index < n; index++) {
|
2012-08-27 12:30:13 +02:00
|
|
|
if (len_table[index] == len)
|
|
|
|
dst[index] = bits++;
|
2002-11-14 20:20:04 +01:00
|
|
|
}
|
2012-08-27 12:30:13 +02:00
|
|
|
if (bits & 1) {
|
2003-11-03 14:26:22 +01:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
|
2003-05-23 14:58:46 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
bits >>= 1;
|
2002-11-14 20:20:04 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-06 14:06:46 +01:00
|
|
|
av_cold int ff_huffyuv_alloc_temp(HYuvContext *s)
|
2012-08-27 12:30:13 +02:00
|
|
|
{
|
2005-02-17 20:00:42 +01:00
|
|
|
int i;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2014-01-28 00:27:57 +01:00
|
|
|
if (s->bitstream_bpp<24 || s->version > 2) {
|
2012-08-27 12:30:13 +02:00
|
|
|
for (i=0; i<3; i++) {
|
2014-01-13 01:14:05 +01:00
|
|
|
s->temp[i]= av_malloc(2*s->width + 16);
|
2012-12-06 17:44:43 +01:00
|
|
|
if (!s->temp[i])
|
|
|
|
return AVERROR(ENOMEM);
|
2014-01-13 01:14:05 +01:00
|
|
|
s->temp16[i] = (uint16_t*)s->temp[i];
|
2005-02-17 20:00:42 +01:00
|
|
|
}
|
2012-08-27 12:30:13 +02:00
|
|
|
} else {
|
2010-01-14 02:32:49 +01:00
|
|
|
s->temp[0]= av_mallocz(4*s->width + 16);
|
2012-12-06 17:44:43 +01:00
|
|
|
if (!s->temp[0])
|
|
|
|
return AVERROR(ENOMEM);
|
2005-02-17 20:00:42 +01:00
|
|
|
}
|
2012-12-06 17:44:43 +01:00
|
|
|
return 0;
|
2005-02-17 20:00:42 +01:00
|
|
|
}
|
|
|
|
|
2012-12-06 14:06:46 +01:00
|
|
|
av_cold void ff_huffyuv_common_init(AVCodecContext *avctx)
|
2012-08-27 12:30:13 +02:00
|
|
|
{
|
2002-11-14 20:20:04 +01:00
|
|
|
HYuvContext *s = avctx->priv_data;
|
|
|
|
|
2012-08-27 12:30:13 +02:00
|
|
|
s->avctx = avctx;
|
|
|
|
s->flags = avctx->flags;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2012-02-15 11:06:44 +01:00
|
|
|
ff_dsputil_init(&s->dsp, avctx);
|
2014-01-23 01:34:56 +01:00
|
|
|
ff_llviddsp_init(&s->llviddsp, avctx);
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2012-08-27 12:30:13 +02:00
|
|
|
s->width = avctx->width;
|
|
|
|
s->height = avctx->height;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2012-12-23 14:36:47 +01:00
|
|
|
av_assert1(s->width > 0 && s->height > 0);
|
2005-01-12 01:16:25 +01:00
|
|
|
}
|
|
|
|
|
2012-12-23 14:36:47 +01:00
|
|
|
av_cold void ff_huffyuv_common_end(HYuvContext *s)
|
2012-12-06 17:44:43 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < 3; i++) {
|
|
|
|
av_freep(&s->temp[i]);
|
2014-01-13 01:14:05 +01:00
|
|
|
s->temp16[i] = NULL;
|
2012-12-06 17:44:43 +01:00
|
|
|
}
|
2002-11-15 12:05:14 +01:00
|
|
|
}
|