Mercurial > libavcodec.hg
comparison xan.c @ 9496:2c6a58787aeb libavcodec
Simplify xan_huffman_decode by using get_bits
author | reimar |
---|---|
date | Fri, 17 Apr 2009 19:48:54 +0000 |
parents | 28978a75c865 |
children | cb387dff812d |
comparison
equal
deleted
inserted
replaced
9495:fc15a3b977bf | 9496:2c6a58787aeb |
---|---|
34 #include <unistd.h> | 34 #include <unistd.h> |
35 | 35 |
36 #include "libavutil/intreadwrite.h" | 36 #include "libavutil/intreadwrite.h" |
37 #include "avcodec.h" | 37 #include "avcodec.h" |
38 #include "bytestream.h" | 38 #include "bytestream.h" |
39 #define ALT_BITSTREAM_READER_LE | |
40 #include "get_bits.h" | |
39 // for av_memcpy_backptr | 41 // for av_memcpy_backptr |
40 #include "libavutil/lzo.h" | 42 #include "libavutil/lzo.h" |
41 | 43 |
42 typedef struct XanContext { | 44 typedef struct XanContext { |
43 | 45 |
91 { | 93 { |
92 unsigned char byte = *src++; | 94 unsigned char byte = *src++; |
93 unsigned char ival = byte + 0x16; | 95 unsigned char ival = byte + 0x16; |
94 const unsigned char * ptr = src + byte*2; | 96 const unsigned char * ptr = src + byte*2; |
95 unsigned char val = ival; | 97 unsigned char val = ival; |
96 int counter = 0; | |
97 unsigned char *dest_end = dest + dest_len; | 98 unsigned char *dest_end = dest + dest_len; |
98 | 99 GetBitContext gb; |
99 unsigned char bits = *ptr++; | 100 |
101 init_get_bits(&gb, ptr, 0); // FIXME: no src size available | |
100 | 102 |
101 while ( val != 0x16 ) { | 103 while ( val != 0x16 ) { |
102 if ( (1 << counter) & bits ) | 104 val = src[val - 0x17 + get_bits1(&gb) * byte]; |
103 val = src[byte + val - 0x17]; | |
104 else | |
105 val = src[val - 0x17]; | |
106 | 105 |
107 if ( val < 0x16 ) { | 106 if ( val < 0x16 ) { |
108 if (dest + 1 > dest_end) | 107 if (dest + 1 > dest_end) |
109 return 0; | 108 return 0; |
110 *dest++ = val; | 109 *dest++ = val; |
111 val = ival; | 110 val = ival; |
112 } | |
113 | |
114 if (counter++ == 7) { | |
115 counter = 0; | |
116 bits = *ptr++; | |
117 } | 111 } |
118 } | 112 } |
119 | 113 |
120 return 0; | 114 return 0; |
121 } | 115 } |