Libav
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 Libav.
10  *
11  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24  */
25 
31 #include <stdint.h>
32 
33 #include "libavutil/mem.h"
34 
35 #include "avcodec.h"
36 #include "bswapdsp.h"
37 #include "huffyuv.h"
38 
39 int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table)
40 {
41  int len, index;
42  uint32_t bits = 0;
43 
44  for (len = 32; len > 0; len--) {
45  for (index = 0; index < 256; index++) {
46  if (len_table[index] == len)
47  dst[index] = bits++;
48  }
49  if (bits & 1) {
50  av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
51  return -1;
52  }
53  bits >>= 1;
54  }
55  return 0;
56 }
57 
59 {
60  int i;
61 
62  if (s->bitstream_bpp<24) {
63  for (i=0; i<3; i++) {
64  s->temp[i]= av_malloc(s->width + 16);
65  if (!s->temp[i])
66  return AVERROR(ENOMEM);
67  }
68  } else {
69  s->temp[0]= av_mallocz(4*s->width + 16);
70  if (!s->temp[0])
71  return AVERROR(ENOMEM);
72  }
73  return 0;
74 }
75 
77 {
78  HYuvContext *s = avctx->priv_data;
79 
80  s->avctx = avctx;
81  s->flags = avctx->flags;
82 
84 
85  s->width = avctx->width;
86  s->height = avctx->height;
87  assert(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_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
int bitstream_bpp
Definition: huffyuv.h:68
memory handling functions
void ff_huffyuv_common_end(HYuvContext *s)
Definition: huffyuv.c:90
int height
Definition: huffyuv.h:72
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:251
uint8_t
#define av_cold
Definition: attributes.h:66
av_cold int ff_huffyuv_alloc_temp(HYuvContext *s)
Definition: huffyuv.c:58
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
#define AVERROR(e)
Definition: error.h:43
int flags
Definition: huffyuv.h:73
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1144
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
huffyuv codec for libavcodec.
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
int width
Definition: huffyuv.h:72
int width
picture width / height.
Definition: avcodec.h:1224
uint8_t * temp[3]
Definition: huffyuv.h:77
NULL
Definition: eval.c:55
Libavcodec external API header.
main external API structure.
Definition: avcodec.h:1050
int index
Definition: gxfenc.c:72
AVCodecContext * avctx
Definition: huffyuv.h:62
av_cold void ff_huffyuv_common_init(AVCodecContext *avctx)
Definition: huffyuv.c:76
void * priv_data
Definition: avcodec.h:1092
int len
BswapDSPContext bdsp
Definition: huffyuv.h:85
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
int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table)
Definition: huffyuv.c:39