annotate adler32.c @ 101:dc973a8c90fd libavutil

cleanup PixelFormat a little
author michael
date Sun, 20 Aug 2006 13:04:19 +0000
parents 95f290a7ad74
children f731186c3562
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
1 /* adler32.c -- compute the Adler-32 checksum of a data stream
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
2 * Copyright (C) 1995 Mark Adler
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
3 * For conditions of distribution and use, see copyright notice in zlib.h
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
4 */
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
5
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
6 #include "common.h"
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
7 #include "adler32.h"
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
8
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
9 #define BASE 65521L /* largest prime smaller than 65536 */
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
10
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
11 #define DO1(buf) {s1 += *buf++; s2 += s1;}
83
4d16d6abcf65 simplify
michael
parents: 68
diff changeset
12 #define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf);
4d16d6abcf65 simplify
michael
parents: 68
diff changeset
13 #define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf);
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
14
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
15 unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len)
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
16 {
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
17 unsigned long s1 = adler & 0xffff;
85
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
18 unsigned long s2 = adler >> 16;
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
19
85
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
20 while (len>0) {
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
21 #ifdef CONFIG_SMALL
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
22 while(len>4 && s2 < (1U<<31)){
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
23 DO4(buf); len-=4;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
24 #else
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
25 while(len>16 && s2 < (1U<<31)){
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
26 DO16(buf); len-=16;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
27 #endif
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
28 }
85
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
29 DO1(buf); len--;
67
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
30 s1 %= BASE;
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
31 s2 %= BASE;
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
32 }
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
33 return (s2 << 16) | s1;
0dbb7828d014 move adler32 to libavutil
mru
parents:
diff changeset
34 }
85
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
35
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
36 #ifdef TEST
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
37 #include "log.h"
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
38 #define LEN 7001
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
39 volatile int checksum;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
40 int main(){
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
41 int i;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
42 char data[LEN];
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
43 av_log_level = AV_LOG_DEBUG;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
44 for(i=0; i<LEN; i++)
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
45 data[i]= ((i*i)>>3) + 123*i;
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
46 for(i=0; i<1000; i++){
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
47 START_TIMER
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
48 checksum= av_adler32_update(1, data, LEN);
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
49 STOP_TIMER("adler")
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
50 }
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
51 av_log(NULL, AV_LOG_DEBUG, "%X == 50E6E508\n", checksum);
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
52 }
95f290a7ad74 simpler, smaller and faster
michael
parents: 83
diff changeset
53 #endif