Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbfb6af8

Browse files
committed
moduzlib: Import uzlib v1.1.
https://github.com/pfalcon/uzlib
1 parent3416287 commitbfb6af8

File tree

4 files changed

+792
-0
lines changed

4 files changed

+792
-0
lines changed

‎extmod/uzlib/adler32.c‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Adler-32 checksum
3+
*
4+
* Copyright (c) 2003 by Joergen Ibsen / Jibz
5+
* All Rights Reserved
6+
*
7+
* http://www.ibsensoftware.com/
8+
*
9+
* This software is provided 'as-is', without any express
10+
* or implied warranty. In no event will the authors be
11+
* held liable for any damages arising from the use of
12+
* this software.
13+
*
14+
* Permission is granted to anyone to use this software
15+
* for any purpose, including commercial applications,
16+
* and to alter it and redistribute it freely, subject to
17+
* the following restrictions:
18+
*
19+
* 1. The origin of this software must not be
20+
* misrepresented; you must not claim that you
21+
* wrote the original software. If you use this
22+
* software in a product, an acknowledgment in
23+
* the product documentation would be appreciated
24+
* but is not required.
25+
*
26+
* 2. Altered source versions must be plainly marked
27+
* as such, and must not be misrepresented as
28+
* being the original software.
29+
*
30+
* 3. This notice may not be removed or altered from
31+
* any source distribution.
32+
*/
33+
34+
/*
35+
* Adler-32 algorithm taken from the zlib source, which is
36+
* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
37+
*/
38+
39+
#include"tinf.h"
40+
41+
#defineA32_BASE 65521
42+
#defineA32_NMAX 5552
43+
44+
unsignedinttinf_adler32(constvoid*data,unsignedintlength)
45+
{
46+
constunsignedchar*buf= (constunsignedchar*)data;
47+
48+
unsignedints1=1;
49+
unsignedints2=0;
50+
51+
while (length>0)
52+
{
53+
intk=length<A32_NMAX ?length :A32_NMAX;
54+
inti;
55+
56+
for (i=k /16;i;--i,buf+=16)
57+
{
58+
s1+=buf[0];s2+=s1;s1+=buf[1];s2+=s1;
59+
s1+=buf[2];s2+=s1;s1+=buf[3];s2+=s1;
60+
s1+=buf[4];s2+=s1;s1+=buf[5];s2+=s1;
61+
s1+=buf[6];s2+=s1;s1+=buf[7];s2+=s1;
62+
63+
s1+=buf[8];s2+=s1;s1+=buf[9];s2+=s1;
64+
s1+=buf[10];s2+=s1;s1+=buf[11];s2+=s1;
65+
s1+=buf[12];s2+=s1;s1+=buf[13];s2+=s1;
66+
s1+=buf[14];s2+=s1;s1+=buf[15];s2+=s1;
67+
}
68+
69+
for (i=k %16;i;--i) {s1+=*buf++;s2+=s1; }
70+
71+
s1 %=A32_BASE;
72+
s2 %=A32_BASE;
73+
74+
length-=k;
75+
}
76+
77+
return (s2 <<16) |s1;
78+
}

‎extmod/uzlib/tinf.h‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
3+
*
4+
* Copyright (c) 2003 by Joergen Ibsen / Jibz
5+
* All Rights Reserved
6+
* http://www.ibsensoftware.com/
7+
*
8+
* Copyright (c) 2014 by Paul Sokolovsky
9+
*/
10+
11+
#ifndefTINF_H_INCLUDED
12+
#defineTINF_H_INCLUDED
13+
14+
#include<stdint.h>
15+
16+
/* calling convention */
17+
#ifndefTINFCC
18+
#ifdef__WATCOMC__
19+
#defineTINFCC __cdecl
20+
#else
21+
#defineTINFCC
22+
#endif
23+
#endif
24+
25+
#ifdef__cplusplus
26+
extern"C" {
27+
#endif
28+
29+
#defineTINF_OK 0
30+
#defineTINF_DATA_ERROR (-3)
31+
#defineTINF_DEST_OVERFLOW (-4)
32+
33+
/* data structures */
34+
35+
typedefstruct {
36+
unsigned shorttable[16];/* table of code length counts */
37+
unsigned shorttrans[288];/* code -> symbol translation table */
38+
}TINF_TREE;
39+
40+
structTINF_DATA;
41+
typedefstructTINF_DATA {
42+
constunsignedchar*source;
43+
unsignedinttag;
44+
unsignedintbitcount;
45+
46+
/* Buffer start */
47+
unsignedchar*destStart;
48+
/* Buffer total size */
49+
unsignedintdestSize;
50+
/* Current pointer in buffer */
51+
unsignedchar*dest;
52+
/* Remaining bytes in buffer */
53+
unsignedintdestRemaining;
54+
/* Argument is the allocation size which didn't fit into buffer. Note that
55+
exact mimumum size to grow buffer by is lastAlloc - destRemaining. But
56+
growing by this exact size is ineficient, as the next allocation will
57+
fail again. */
58+
int (*destGrow)(structTINF_DATA*data,unsignedintlastAlloc);
59+
60+
TINF_TREEltree;/* dynamic length/symbol tree */
61+
TINF_TREEdtree;/* dynamic distance tree */
62+
}TINF_DATA;
63+
64+
65+
/* low-level API */
66+
67+
/* Step 1: Allocate TINF_DATA structure */
68+
/* Step 2: Set destStart, destSize, and destGrow fields */
69+
/* Step 3: Set source field */
70+
/* Step 4: Call tinf_uncompress_dyn() */
71+
/* Step 5: In response to destGrow callback, update destStart and destSize fields */
72+
/* Step 6: When tinf_uncompress_dyn() returns, buf.dest points to a byte past last uncompressed byte */
73+
74+
intTINFCCtinf_uncompress_dyn(TINF_DATA*d);
75+
intTINFCCtinf_zlib_uncompress_dyn(TINF_DATA*d,unsignedintsourceLen);
76+
77+
/* high-level API */
78+
79+
voidTINFCCtinf_init();
80+
81+
intTINFCCtinf_uncompress(void*dest,unsignedint*destLen,
82+
constvoid*source,unsignedintsourceLen);
83+
84+
intTINFCCtinf_gzip_uncompress(void*dest,unsignedint*destLen,
85+
constvoid*source,unsignedintsourceLen);
86+
87+
intTINFCCtinf_zlib_uncompress(void*dest,unsignedint*destLen,
88+
constvoid*source,unsignedintsourceLen);
89+
90+
unsignedintTINFCCtinf_adler32(constvoid*data,unsignedintlength);
91+
92+
unsignedintTINFCCtinf_crc32(constvoid*data,unsignedintlength);
93+
94+
/* compression API */
95+
96+
voidTINFCCtinf_compress(void*data,constuint8_t*src,unsignedslen);
97+
98+
#ifdef__cplusplus
99+
}/* extern "C" */
100+
#endif
101+
102+
#endif/* TINF_H_INCLUDED */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp