huffyuv.c
Go to the documentation of this file.
1 /*
2  * huffyuv codec for libavcodec
3  *
4  * Copyright (c) 2002-2003 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * see http://www.pcisys.net/~melanson/codecs/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/mem.h"
34 
35 #include "avcodec.h"
36 #include "huffyuv.h"
37 
38 int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table)
39 {
40  int len, index;
41  uint32_t bits = 0;
42 
43  for (len = 32; len > 0; len--) {
44  for (index = 0; index < 256; index++) {
45  if (len_table[index] == len)
46  dst[index] = bits++;
47  }
48  if (bits & 1) {
49  av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
50  return -1;
51  }
52  bits >>= 1;
53  }
54  return 0;
55 }
56 
58 {
59  int i;
60 
61  if (s->bitstream_bpp<24) {
62  for (i=0; i<3; i++) {
63  s->temp[i]= av_malloc(s->width + 16);
64  if (!s->temp[i])
65  return AVERROR(ENOMEM);
66  }
67  } else {
68  s->temp[0]= av_mallocz(4*s->width + 16);
69  if (!s->temp[0])
70  return AVERROR(ENOMEM);
71  }
72  return 0;
73 }
74 
76 {
77  HYuvContext *s = avctx->priv_data;
78 
79  s->avctx = avctx;
80  s->flags = avctx->flags;
81 
82  ff_dsputil_init(&s->dsp, avctx);
83 
84  s->width = avctx->width;
85  s->height = avctx->height;
86 
87  av_assert1(s->width > 0 && s->height > 0);
88 }
89 
91 {
92  int i;
93 
94  for(i = 0; i < 3; i++) {
95  av_freep(&s->temp[i]);
96  }
97 }
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
Definition: dsputil.c:2675
const char * s
Definition: avisynth_c.h:668
int bitstream_bpp
Definition: huffyuv.h:66
memory handling functions
int height
Definition: huffyuv.h:70
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
uint8_t bits
Definition: crc.c:216
uint8_t
#define av_cold
Definition: attributes.h:78
av_cold int ff_huffyuv_alloc_temp(HYuvContext *s)
Definition: huffyuv.c:57
av_cold void ff_huffyuv_common_end(HYuvContext *s)
Definition: huffyuv.c:90
int flags
Definition: huffyuv.h:71
int flags
CODEC_FLAG_*.
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
external API header
huffyuv codec for libavcodec.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
int width
Definition: huffyuv.h:70
int width
picture width / height.
uint8_t * temp[3]
Definition: huffyuv.h:75
NULL
Definition: eval.c:55
main external API structure.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
AVCodecContext * avctx
Definition: huffyuv.h:60
av_cold void ff_huffyuv_common_init(AVCodecContext *avctx)
Definition: huffyuv.c:75
int len
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
DSPContext dsp
Definition: huffyuv.h:84
int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table)
Definition: huffyuv.c:38