Mercurial > libavutil.hg
comparison crc.c @ 603:880c6441f56a libavutil
Change semantic of CONFIG_*, HAVE_* and ARCH_*.
They are now always defined to either 0 or 1.
author | aurel |
---|---|
date | Tue, 13 Jan 2009 23:44:16 +0000 |
parents | 49da89abe282 |
children | 8c48a1b999a3 |
comparison
equal
deleted
inserted
replaced
602:0b84593767d8 | 603:880c6441f56a |
---|---|
20 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 #include "bswap.h" | 22 #include "bswap.h" |
23 #include "crc.h" | 23 #include "crc.h" |
24 | 24 |
25 #ifdef CONFIG_HARDCODED_TABLES | 25 #if CONFIG_HARDCODED_TABLES |
26 #include "crc_data.h" | 26 #include "crc_data.h" |
27 #else | 27 #else |
28 static struct { | 28 static struct { |
29 uint8_t le; | 29 uint8_t le; |
30 uint8_t bits; | 30 uint8_t bits; |
73 c = (c<<1) ^ ((poly<<(32-bits)) & (((int32_t)c)>>31) ); | 73 c = (c<<1) ^ ((poly<<(32-bits)) & (((int32_t)c)>>31) ); |
74 ctx[i] = bswap_32(c); | 74 ctx[i] = bswap_32(c); |
75 } | 75 } |
76 } | 76 } |
77 ctx[256]=1; | 77 ctx[256]=1; |
78 #ifndef CONFIG_SMALL | 78 #if !CONFIG_SMALL |
79 if(ctx_size >= sizeof(AVCRC)*1024) | 79 if(ctx_size >= sizeof(AVCRC)*1024) |
80 for (i = 0; i < 256; i++) | 80 for (i = 0; i < 256; i++) |
81 for(j=0; j<3; j++) | 81 for(j=0; j<3; j++) |
82 ctx[256*(j+1) + i]= (ctx[256*j + i]>>8) ^ ctx[ ctx[256*j + i]&0xFF ]; | 82 ctx[256*(j+1) + i]= (ctx[256*j + i]>>8) ^ ctx[ ctx[256*j + i]&0xFF ]; |
83 #endif | 83 #endif |
89 * Get an initialized standard CRC table. | 89 * Get an initialized standard CRC table. |
90 * @param crc_id ID of a standard CRC | 90 * @param crc_id ID of a standard CRC |
91 * @return a pointer to the CRC table or NULL on failure | 91 * @return a pointer to the CRC table or NULL on failure |
92 */ | 92 */ |
93 const AVCRC *av_crc_get_table(AVCRCId crc_id){ | 93 const AVCRC *av_crc_get_table(AVCRCId crc_id){ |
94 #ifndef CONFIG_HARDCODED_TABLES | 94 #if !CONFIG_HARDCODED_TABLES |
95 if (!av_crc_table[crc_id][FF_ARRAY_ELEMS(av_crc_table[crc_id])-1]) | 95 if (!av_crc_table[crc_id][FF_ARRAY_ELEMS(av_crc_table[crc_id])-1]) |
96 if (av_crc_init(av_crc_table[crc_id], | 96 if (av_crc_init(av_crc_table[crc_id], |
97 av_crc_table_params[crc_id].le, | 97 av_crc_table_params[crc_id].le, |
98 av_crc_table_params[crc_id].bits, | 98 av_crc_table_params[crc_id].bits, |
99 av_crc_table_params[crc_id].poly, | 99 av_crc_table_params[crc_id].poly, |
111 * @see av_crc_init() "le" parameter | 111 * @see av_crc_init() "le" parameter |
112 */ | 112 */ |
113 uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length){ | 113 uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length){ |
114 const uint8_t *end= buffer+length; | 114 const uint8_t *end= buffer+length; |
115 | 115 |
116 #ifndef CONFIG_SMALL | 116 #if !CONFIG_SMALL |
117 if(!ctx[256]) | 117 if(!ctx[256]) |
118 while(buffer<end-3){ | 118 while(buffer<end-3){ |
119 crc ^= le2me_32(*(const uint32_t*)buffer); buffer+=4; | 119 crc ^= le2me_32(*(const uint32_t*)buffer); buffer+=4; |
120 crc = ctx[3*256 + ( crc &0xFF)] | 120 crc = ctx[3*256 + ( crc &0xFF)] |
121 ^ctx[2*256 + ((crc>>8 )&0xFF)] | 121 ^ctx[2*256 + ((crc>>8 )&0xFF)] |