FFmpeg
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 <stdint.h>
32 
33 #include "libavutil/attributes.h"
34 #include "libavutil/error.h"
35 #include "libavutil/log.h"
36 #include "libavutil/mem.h"
37 
38 #include "huffyuv.h"
39 
40 int 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");
52  return -1;
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 }
62 
63 av_cold int ff_huffyuv_alloc_temp(uint8_t *temp[3], uint16_t *temp16[3], int width)
64 {
65  int i;
66 
67  for (i=0; i<3; i++) {
68  temp[i] = av_malloc(4 * width + 16);
69  if (!temp[i])
70  return AVERROR(ENOMEM);
71  temp16[i] = (uint16_t*)temp[i];
72  }
73  return 0;
74 }
75 
76 av_cold void ff_huffyuv_common_end(uint8_t *temp[3], uint16_t *temp16[3])
77 {
78  int i;
79 
80  for(i = 0; i < 3; i++) {
81  av_freep(&temp[i]);
82  temp16[i] = NULL;
83  }
84 }
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
ff_huffyuv_alloc_temp
av_cold int ff_huffyuv_alloc_temp(uint8_t *temp[3], uint16_t *temp16[3], int width)
Definition: huffyuv.c:63
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
width
#define width
ff_huffyuv_common_end
av_cold void ff_huffyuv_common_end(uint8_t *temp[3], uint16_t *temp16[3])
Definition: huffyuv.c:76
NULL
#define NULL
Definition: coverity.c:32
ff_huffyuv_generate_bits_table
int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n)
Definition: huffyuv.c:40
error.h
attributes.h
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
temp
else temp
Definition: vf_mcdeint.c:248
mem.h
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
huffyuv.h