2002-11-14 19:20:04 +00: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 19:20:04 +00:00
|
|
|
*
|
2022-10-02 16:38:53 +02:00
|
|
|
* see https://multimedia.cx/huffyuv.txt for a description of
|
2007-07-05 10:37:29 +00:00
|
|
|
* the algorithm used
|
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-11-14 19:20:04 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2002-11-14 19:20:04 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2002-11-14 19:20:04 +00: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 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-11-14 19:20:04 +00:00
|
|
|
*/
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2003-03-06 11:32:04 +00:00
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2003-03-06 11:32:04 +00:00
|
|
|
* huffyuv codec for libavcodec.
|
|
|
|
*/
|
2002-11-14 19:20:04 +00:00
|
|
|
|
2012-12-06 14:06:46 +01:00
|
|
|
#include <stdint.h>
|
2011-11-28 15:07:48 +01:00
|
|
|
|
2022-10-01 23:36:09 +02:00
|
|
|
#include "libavutil/attributes.h"
|
|
|
|
#include "libavutil/error.h"
|
|
|
|
#include "libavutil/log.h"
|
2012-12-06 14:06:46 +01:00
|
|
|
#include "libavutil/mem.h"
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2012-12-06 14:06:46 +01:00
|
|
|
#include "huffyuv.h"
|
2002-11-14 19:20:04 +00: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
|
|
|
{
|
2022-10-02 00:46:11 +02:00
|
|
|
int lens[33] = { 0 };
|
|
|
|
uint32_t codes[33];
|
2002-11-14 19:20:04 +00:00
|
|
|
|
2022-10-02 00:46:11 +02:00
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
lens[len_table[i]]++;
|
|
|
|
|
|
|
|
codes[32] = 0;
|
|
|
|
for (int i = FF_ARRAY_ELEMS(lens) - 1; i > 0; i--) {
|
|
|
|
if ((lens[i] + codes[i]) & 1) {
|
2003-11-03 13:26:22 +00:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
|
2003-05-23 12:58:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2022-10-02 00:46:11 +02:00
|
|
|
codes[i - 1] = (lens[i] + codes[i]) >> 1;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
if (len_table[i])
|
|
|
|
dst[i] = codes[len_table[i]]++;
|
2002-11-14 19:20:04 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-01 23:36:09 +02:00
|
|
|
av_cold int ff_huffyuv_alloc_temp(uint8_t *temp[3], uint16_t *temp16[3], int width)
|
2012-08-27 12:30:13 +02:00
|
|
|
{
|
2005-02-17 19:00:42 +00:00
|
|
|
int i;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2014-02-19 20:19:38 +01:00
|
|
|
for (i=0; i<3; i++) {
|
2022-10-01 23:36:09 +02:00
|
|
|
temp[i] = av_malloc(4 * width + 16);
|
|
|
|
if (!temp[i])
|
2012-12-06 16:44:43 +00:00
|
|
|
return AVERROR(ENOMEM);
|
2022-10-01 23:36:09 +02:00
|
|
|
temp16[i] = (uint16_t*)temp[i];
|
2005-02-17 19:00:42 +00:00
|
|
|
}
|
2012-12-06 16:44:43 +00:00
|
|
|
return 0;
|
2005-02-17 19:00:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-01 23:36:09 +02:00
|
|
|
av_cold void ff_huffyuv_common_end(uint8_t *temp[3], uint16_t *temp16[3])
|
2012-12-06 16:44:43 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < 3; i++) {
|
2022-10-01 23:36:09 +02:00
|
|
|
av_freep(&temp[i]);
|
|
|
|
temp16[i] = NULL;
|
2012-12-06 16:44:43 +00:00
|
|
|
}
|
2002-11-15 11:05:14 +00:00
|
|
|
}
|