Mercurial > libavutil.hg
annotate crc.c @ 346:e9937dcd0afd libavutil
Clarify comments about PIX_FMT_MONOWHITE/MONOBLACK
Thread: PIX_FMT_MONOWHITE
author | mbardiaux |
---|---|
date | Wed, 20 Jun 2007 08:18:04 +0000 |
parents | 0df19c6b37d0 |
children | b1953daf424e |
rev | line source |
---|---|
108
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
1 /* |
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> |
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
3 * |
116
d76a36742464
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
108
diff
changeset
|
4 * This file is part of FFmpeg. |
d76a36742464
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
108
diff
changeset
|
5 * |
d76a36742464
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
108
diff
changeset
|
6 * FFmpeg is free software; you can redistribute it and/or |
108
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public |
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
8 * License as published by the Free Software Foundation; either |
116
d76a36742464
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
108
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. |
108
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
10 * |
116
d76a36742464
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
108
diff
changeset
|
11 * FFmpeg is distributed in the hope that it will be useful, |
108
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
14 * Lesser General Public License for more details. |
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
15 * |
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public |
116
d76a36742464
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
108
diff
changeset
|
17 * License along with FFmpeg; if not, write to the Free Software |
108
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
19 */ |
11be8e0d1344
Add official LGPL license headers to the files that were missing them.
diego
parents:
61
diff
changeset
|
20 |
30 | 21 #include "common.h" |
22 #include "crc.h" | |
23 | |
317 | 24 #if LIBAVUTIL_VERSION_INT < (50<<16) |
30 | 25 AVCRC *av_crcEDB88320; |
26 AVCRC *av_crc04C11DB7; | |
27 AVCRC *av_crc8005 ; | |
28 AVCRC *av_crc07 ; | |
317 | 29 #else |
30 AVCRC av_crcEDB88320[257]; | |
31 AVCRC av_crc04C11DB7[257]; | |
32 AVCRC av_crc8005 [257]; | |
33 AVCRC av_crc07 [257]; | |
34 #endif | |
30 | 35 |
36 /** | |
37 * Inits a crc table. | |
38 * @param ctx must be an array of sizeof(AVCRC)*257 or sizeof(AVCRC)*1024 | |
39 * @param cts_size size of ctx in bytes | |
40 * @return <0 on failure | |
41 */ | |
42 int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){ | |
43 int i, j; | |
44 uint32_t c; | |
45 | |
46 if (bits < 8 || bits > 32 || poly >= (1LL<<bits)) | |
47 return -1; | |
48 if (ctx_size != sizeof(AVCRC)*257 && ctx_size != sizeof(AVCRC)*1024) | |
49 return -1; | |
50 | |
51 for (i = 0; i < 256; i++) { | |
52 if (le) { | |
53 for (c = i, j = 0; j < 8; j++) | |
54 c = (c>>1)^(poly & (-(c&1))); | |
55 ctx[i] = c; | |
56 } else { | |
57 for (c = i << 24, j = 0; j < 8; j++) | |
58 c = (c<<1) ^ ((poly<<(32-bits)) & (((int32_t)c)>>31) ); | |
59 ctx[i] = bswap_32(c); | |
60 } | |
61 } | |
62 ctx[256]=1; | |
61
f85d07038450
put the code which is specific for the large crc table under #ifndef CONFIG_SMALL
michael
parents:
30
diff
changeset
|
63 #ifndef CONFIG_SMALL |
30 | 64 if(ctx_size >= sizeof(AVCRC)*1024) |
65 for (i = 0; i < 256; i++) | |
66 for(j=0; j<3; j++) | |
67 ctx[256*(j+1) + i]= (ctx[256*j + i]>>8) ^ ctx[ ctx[256*j + i]&0xFF ]; | |
61
f85d07038450
put the code which is specific for the large crc table under #ifndef CONFIG_SMALL
michael
parents:
30
diff
changeset
|
68 #endif |
30 | 69 |
70 return 0; | |
71 } | |
72 | |
73 uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length){ | |
74 const uint8_t *end= buffer+length; | |
75 | |
61
f85d07038450
put the code which is specific for the large crc table under #ifndef CONFIG_SMALL
michael
parents:
30
diff
changeset
|
76 #ifndef CONFIG_SMALL |
30 | 77 if(!ctx[256]) |
78 while(buffer<end-3){ | |
79 crc ^= le2me_32(*(uint32_t*)buffer); buffer+=4; | |
80 crc = ctx[3*256 + ( crc &0xFF)] | |
81 ^ctx[2*256 + ((crc>>8 )&0xFF)] | |
82 ^ctx[1*256 + ((crc>>16)&0xFF)] | |
83 ^ctx[0*256 + ((crc>>24) )]; | |
84 } | |
61
f85d07038450
put the code which is specific for the large crc table under #ifndef CONFIG_SMALL
michael
parents:
30
diff
changeset
|
85 #endif |
30 | 86 while(buffer<end) |
87 crc = ctx[((uint8_t)crc) ^ *buffer++] ^ (crc >> 8); | |
88 | |
89 return crc; | |
90 } | |
91 | |
92 #ifdef TEST | |
93 #undef printf | |
94 main(){ | |
95 uint8_t buf[1999]; | |
96 int i; | |
97 int p[4][4]={{1, 32, 0xedb88320L, 0x3D5CDD04}, | |
98 {0, 32, 0x04c11db7L, 0xC0F5BAE0}, | |
99 {0, 16, 0x8005 , 0x1FBB }, | |
100 {0, 8, 0x07 , 0xE3 },}; | |
101 AVCRC ctx[1 ? 1024:257]; | |
102 | |
103 for(i=0; i<sizeof(buf); i++) | |
104 buf[i]= i+i*i; | |
105 | |
106 for(i=0; i<4; i++){ | |
107 av_crc_init(ctx, p[i][0], p[i][1], p[i][2], sizeof(ctx)); | |
108 printf("crc %08X =%X\n", p[i][2], av_crc(ctx, 0, buf, sizeof(buf))); | |
109 } | |
110 } | |
111 #endif |