FFmpeg
Loading...
Searching...
No Matches
huffyuv.c
Go to the documentation of this file.
1/*
2 * huffyuv codec for libavcodec
3 *
4 * Copyright (c) 2002-2014 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * see https://multimedia.cx/huffyuv.txt for a description of
7 * the algorithm used
8 *
9 * This file is part of FFmpeg.
10 *
11 * FFmpeg is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * FFmpeg is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with FFmpeg; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26/**
27 * @file
28 * huffyuv codec for libavcodec.
29 */
30
31#include <stddef.h>
32#include <stdint.h>
33
34#include "libavutil/error.h"
35#include "libavutil/log.h"
36#include "libavutil/macros.h"
37
38#include "huffyuv.h"
39
40int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n)
41{
42 int lens[33] = { 0 };
43 uint32_t codes[33];
44
45 for (int i = 0; i < n; i++)
46 lens[len_table[i]]++;
47
48 codes[32] = 0;
49 for (int i = FF_ARRAY_ELEMS(lens) - 1; i > 0; i--) {
50 if ((lens[i] + codes[i]) & 1) {
51 av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
53 }
54 codes[i - 1] = (lens[i] + codes[i]) >> 1;
55 }
56 for (int i = 0; i < n; i++) {
57 if (len_table[i])
58 dst[i] = codes[len_table[i]]++;
59 }
60 return 0;
61}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
error code definitions
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n)
Definition huffyuv.c:40
huffyuv codec for libavcodec.
Utility Preprocessor macros.
#define FF_ARRAY_ELEMS(a)
#define av_log(a,...)