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
|
|
|
*
|
2022-10-02 16:38:53 +02:00
|
|
|
* see https://multimedia.cx/huffyuv.txt for a description of
|
2007-07-05 13:37:29 +03:00
|
|
|
* 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
|
|
|
|
2024-04-04 05:53:09 +02:00
|
|
|
#include <stddef.h>
|
2012-12-06 16:06:46 +03:00
|
|
|
#include <stdint.h>
|
2011-11-28 17:07:48 +03:00
|
|
|
|
2024-04-04 06:09:31 +02:00
|
|
|
#include "libavutil/error.h"
|
2022-10-01 23:36:09 +02:00
|
|
|
#include "libavutil/log.h"
|
2024-04-04 05:53:09 +02:00
|
|
|
#include "libavutil/macros.h"
|
2005-12-17 20:14:38 +02:00
|
|
|
|
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
|
|
|
{
|
2022-10-02 00:46:11 +02:00
|
|
|
int lens[33] = { 0 };
|
|
|
|
uint32_t codes[33];
|
2002-11-14 21:20:04 +02: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 15:26:22 +02:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
|
2024-04-04 06:09:31 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2003-05-23 15:58:46 +03:00
|
|
|
}
|
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 21:20:04 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|