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