Initial revision
[libav.git] / libav / common.h
1 #ifndef COMMON_H
2 #define COMMON_H
3
4 typedef unsigned char UINT8;
5 typedef unsigned short UINT16;
6 typedef unsigned int UINT32;
7 typedef signed char INT8;
8 typedef signed short INT16;
9 typedef signed int INT32;
10
11 /* bit I/O */
12
13 struct PutBitContext;
14
15 typedef void (*WriteDataFunc)(void *, UINT8 *, int);
16
17 typedef struct PutBitContext {
18 UINT8 *buf, *buf_ptr, *buf_end;
19 int bit_cnt;
20 UINT32 bit_buf;
21 long long data_out_size; /* in bytes */
22 void *opaque;
23 WriteDataFunc write_data;
24 } PutBitContext;
25
26 void init_put_bits(PutBitContext *s,
27 UINT8 *buffer, int buffer_size,
28 void *opaque,
29 void (*write_data)(void *, UINT8 *, int));
30 void put_bits(PutBitContext *s, int n, unsigned int value);
31 long long get_bit_count(PutBitContext *s);
32 void align_put_bits(PutBitContext *s);
33 void flush_put_bits(PutBitContext *s);
34
35 /* jpeg specific put_bits */
36 void jput_bits(PutBitContext *s, int n, unsigned int value);
37 void jflush_put_bits(PutBitContext *s);
38
39 /* misc math functions */
40
41 extern inline int log2(unsigned int v)
42 {
43 int n;
44
45 n = 0;
46 if (v & 0xffff0000) {
47 v >>= 16;
48 n += 16;
49 }
50 if (v & 0xff00) {
51 v >>= 8;
52 n += 8;
53 }
54 if (v & 0xf0) {
55 v >>= 4;
56 n += 4;
57 }
58 if (v & 0xc) {
59 v >>= 2;
60 n += 2;
61 }
62 if (v & 0x2) {
63 n++;
64 }
65 return n;
66 }
67
68 #endif