diff options
Diffstat (limited to 'contrib/testzlib')
-rw-r--r-- | contrib/testzlib/testzlib.c | 298 | ||||
-rw-r--r-- | contrib/testzlib/testzlib.vcproj | 6 |
2 files changed, 152 insertions, 152 deletions
diff --git a/contrib/testzlib/testzlib.c b/contrib/testzlib/testzlib.c index caae4ef..fdabc5c 100644 --- a/contrib/testzlib/testzlib.c +++ b/contrib/testzlib/testzlib.c | |||
@@ -1,149 +1,149 @@ | |||
1 | 1 | ||
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <windows.h> | 4 | #include <windows.h> |
5 | #include "zlib.h" | 5 | #include "zlib.h" |
6 | 6 | ||
7 | int ReadFileMemory(const char* filename,long* plFileSize,void** pFilePtr) | 7 | int ReadFileMemory(const char* filename,long* plFileSize,void** pFilePtr) |
8 | { | 8 | { |
9 | FILE* stream; | 9 | FILE* stream; |
10 | void* ptr; | 10 | void* ptr; |
11 | int retVal=1; | 11 | int retVal=1; |
12 | stream=fopen(filename, "rb"); | 12 | stream=fopen(filename, "rb"); |
13 | if (stream==NULL) | 13 | if (stream==NULL) |
14 | return 0; | 14 | return 0; |
15 | 15 | ||
16 | fseek(stream,0,SEEK_END); | 16 | fseek(stream,0,SEEK_END); |
17 | 17 | ||
18 | *plFileSize=ftell(stream); | 18 | *plFileSize=ftell(stream); |
19 | fseek(stream,0,SEEK_SET); | 19 | fseek(stream,0,SEEK_SET); |
20 | ptr=malloc((*plFileSize)+1); | 20 | ptr=malloc((*plFileSize)+1); |
21 | if (ptr==NULL) | 21 | if (ptr==NULL) |
22 | retVal=0; | 22 | retVal=0; |
23 | else | 23 | else |
24 | { | 24 | { |
25 | if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize)) | 25 | if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize)) |
26 | retVal=0; | 26 | retVal=0; |
27 | } | 27 | } |
28 | fclose(stream); | 28 | fclose(stream); |
29 | *pFilePtr=ptr; | 29 | *pFilePtr=ptr; |
30 | return retVal; | 30 | return retVal; |
31 | } | 31 | } |
32 | 32 | ||
33 | int main(int argc, char *argv[]) | 33 | int main(int argc, char *argv[]) |
34 | { | 34 | { |
35 | int BlockSizeCompress=0x8000; | 35 | int BlockSizeCompress=0x8000; |
36 | int BlockSizeUncompress=0x8000; | 36 | int BlockSizeUncompress=0x8000; |
37 | int cprLevel=Z_DEFAULT_COMPRESSION ; | 37 | int cprLevel=Z_DEFAULT_COMPRESSION ; |
38 | long lFileSize; | 38 | long lFileSize; |
39 | unsigned char* FilePtr; | 39 | unsigned char* FilePtr; |
40 | long lBufferSizeCpr; | 40 | long lBufferSizeCpr; |
41 | long lBufferSizeUncpr; | 41 | long lBufferSizeUncpr; |
42 | long lCompressedSize=0; | 42 | long lCompressedSize=0; |
43 | unsigned char* CprPtr; | 43 | unsigned char* CprPtr; |
44 | unsigned char* UncprPtr; | 44 | unsigned char* UncprPtr; |
45 | long lSizeCpr,lSizeUncpr; | 45 | long lSizeCpr,lSizeUncpr; |
46 | DWORD dwGetTick; | 46 | DWORD dwGetTick; |
47 | 47 | ||
48 | if (argc<=1) | 48 | if (argc<=1) |
49 | { | 49 | { |
50 | printf("run TestZlib <File> [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n"); | 50 | printf("run TestZlib <File> [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n"); |
51 | return 0; | 51 | return 0; |
52 | } | 52 | } |
53 | 53 | ||
54 | if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0) | 54 | if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0) |
55 | { | 55 | { |
56 | printf("error reading %s\n",argv[1]); | 56 | printf("error reading %s\n",argv[1]); |
57 | return 1; | 57 | return 1; |
58 | } | 58 | } |
59 | else printf("file %s read, %u bytes\n",argv[1],lFileSize); | 59 | else printf("file %s read, %u bytes\n",argv[1],lFileSize); |
60 | 60 | ||
61 | if (argc>=3) | 61 | if (argc>=3) |
62 | BlockSizeCompress=atol(argv[2]); | 62 | BlockSizeCompress=atol(argv[2]); |
63 | 63 | ||
64 | if (argc>=4) | 64 | if (argc>=4) |
65 | BlockSizeUncompress=atol(argv[3]); | 65 | BlockSizeUncompress=atol(argv[3]); |
66 | 66 | ||
67 | if (argc>=5) | 67 | if (argc>=5) |
68 | cprLevel=(int)atol(argv[4]); | 68 | cprLevel=(int)atol(argv[4]); |
69 | 69 | ||
70 | lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200; | 70 | lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200; |
71 | lBufferSizeUncpr = lBufferSizeCpr; | 71 | lBufferSizeUncpr = lBufferSizeCpr; |
72 | 72 | ||
73 | CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress); | 73 | CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress); |
74 | UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress); | 74 | UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress); |
75 | 75 | ||
76 | dwGetTick=GetTickCount(); | 76 | dwGetTick=GetTickCount(); |
77 | { | 77 | { |
78 | z_stream zcpr; | 78 | z_stream zcpr; |
79 | int ret=Z_OK; | 79 | int ret=Z_OK; |
80 | long lOrigToDo = lFileSize; | 80 | long lOrigToDo = lFileSize; |
81 | long lOrigDone = 0; | 81 | long lOrigDone = 0; |
82 | int step=0; | 82 | int step=0; |
83 | memset(&zcpr,0,sizeof(z_stream)); | 83 | memset(&zcpr,0,sizeof(z_stream)); |
84 | deflateInit(&zcpr,cprLevel); | 84 | deflateInit(&zcpr,cprLevel); |
85 | 85 | ||
86 | zcpr.next_in = FilePtr; | 86 | zcpr.next_in = FilePtr; |
87 | zcpr.next_out = CprPtr; | 87 | zcpr.next_out = CprPtr; |
88 | 88 | ||
89 | 89 | ||
90 | do | 90 | do |
91 | { | 91 | { |
92 | long all_read_before = zcpr.total_in; | 92 | long all_read_before = zcpr.total_in; |
93 | zcpr.avail_in = min(lOrigToDo,BlockSizeCompress); | 93 | zcpr.avail_in = min(lOrigToDo,BlockSizeCompress); |
94 | zcpr.avail_out = BlockSizeCompress; | 94 | zcpr.avail_out = BlockSizeCompress; |
95 | ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH); | 95 | ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH); |
96 | lOrigDone += (zcpr.total_in-all_read_before); | 96 | lOrigDone += (zcpr.total_in-all_read_before); |
97 | lOrigToDo -= (zcpr.total_in-all_read_before); | 97 | lOrigToDo -= (zcpr.total_in-all_read_before); |
98 | step++; | 98 | step++; |
99 | } while (ret==Z_OK); | 99 | } while (ret==Z_OK); |
100 | 100 | ||
101 | lSizeCpr=zcpr.total_out; | 101 | lSizeCpr=zcpr.total_out; |
102 | deflateEnd(&zcpr); | 102 | deflateEnd(&zcpr); |
103 | dwGetTick=GetTickCount()-dwGetTick; | 103 | dwGetTick=GetTickCount()-dwGetTick; |
104 | printf("total compress size = %u, in %u step\n",lSizeCpr,step); | 104 | printf("total compress size = %u, in %u step\n",lSizeCpr,step); |
105 | printf("time = %u msec = %f sec\n\n",dwGetTick,dwGetTick/(double)1000.); | 105 | printf("time = %u msec = %f sec\n\n",dwGetTick,dwGetTick/(double)1000.); |
106 | } | 106 | } |
107 | 107 | ||
108 | dwGetTick=GetTickCount(); | 108 | dwGetTick=GetTickCount(); |
109 | { | 109 | { |
110 | z_stream zcpr; | 110 | z_stream zcpr; |
111 | int ret=Z_OK; | 111 | int ret=Z_OK; |
112 | long lOrigToDo = lSizeCpr; | 112 | long lOrigToDo = lSizeCpr; |
113 | long lOrigDone = 0; | 113 | long lOrigDone = 0; |
114 | int step=0; | 114 | int step=0; |
115 | memset(&zcpr,0,sizeof(z_stream)); | 115 | memset(&zcpr,0,sizeof(z_stream)); |
116 | inflateInit(&zcpr); | 116 | inflateInit(&zcpr); |
117 | 117 | ||
118 | zcpr.next_in = CprPtr; | 118 | zcpr.next_in = CprPtr; |
119 | zcpr.next_out = UncprPtr; | 119 | zcpr.next_out = UncprPtr; |
120 | 120 | ||
121 | 121 | ||
122 | do | 122 | do |
123 | { | 123 | { |
124 | long all_read_before = zcpr.total_in; | 124 | long all_read_before = zcpr.total_in; |
125 | zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress); | 125 | zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress); |
126 | zcpr.avail_out = BlockSizeUncompress; | 126 | zcpr.avail_out = BlockSizeUncompress; |
127 | ret=inflate(&zcpr,Z_SYNC_FLUSH); | 127 | ret=inflate(&zcpr,Z_SYNC_FLUSH); |
128 | lOrigDone += (zcpr.total_in-all_read_before); | 128 | lOrigDone += (zcpr.total_in-all_read_before); |
129 | lOrigToDo -= (zcpr.total_in-all_read_before); | 129 | lOrigToDo -= (zcpr.total_in-all_read_before); |
130 | step++; | 130 | step++; |
131 | } while (ret==Z_OK); | 131 | } while (ret==Z_OK); |
132 | 132 | ||
133 | lSizeUncpr=zcpr.total_out; | 133 | lSizeUncpr=zcpr.total_out; |
134 | inflateEnd(&zcpr); | 134 | inflateEnd(&zcpr); |
135 | dwGetTick=GetTickCount()-dwGetTick; | 135 | dwGetTick=GetTickCount()-dwGetTick; |
136 | printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step); | 136 | printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step); |
137 | printf("time = %u msec = %f sec\n\n",dwGetTick,dwGetTick/(double)1000.); | 137 | printf("time = %u msec = %f sec\n\n",dwGetTick,dwGetTick/(double)1000.); |
138 | } | 138 | } |
139 | 139 | ||
140 | if (lSizeUncpr==lFileSize) | 140 | if (lSizeUncpr==lFileSize) |
141 | { | 141 | { |
142 | if (memcmp(FilePtr,UncprPtr,lFileSize)==0) | 142 | if (memcmp(FilePtr,UncprPtr,lFileSize)==0) |
143 | printf("compare ok\n"); | 143 | printf("compare ok\n"); |
144 | 144 | ||
145 | } | 145 | } |
146 | 146 | ||
147 | return 0; | 147 | return 0; |
148 | 148 | ||
149 | } | 149 | } |
diff --git a/contrib/testzlib/testzlib.vcproj b/contrib/testzlib/testzlib.vcproj index 5165301..bd9b39b 100644 --- a/contrib/testzlib/testzlib.vcproj +++ b/contrib/testzlib/testzlib.vcproj | |||
@@ -19,7 +19,7 @@ | |||
19 | <Tool | 19 | <Tool |
20 | Name="VCCLCompilerTool" | 20 | Name="VCCLCompilerTool" |
21 | Optimization="0" | 21 | Optimization="0" |
22 | PreprocessorDefinitions="WIN32;ZLIB_DLL;_DEBUG;_CONSOLE" | 22 | PreprocessorDefinitions="WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE" |
23 | MinimalRebuild="TRUE" | 23 | MinimalRebuild="TRUE" |
24 | BasicRuntimeChecks="3" | 24 | BasicRuntimeChecks="3" |
25 | RuntimeLibrary="5" | 25 | RuntimeLibrary="5" |
@@ -63,7 +63,7 @@ | |||
63 | Optimization="2" | 63 | Optimization="2" |
64 | InlineFunctionExpansion="1" | 64 | InlineFunctionExpansion="1" |
65 | OmitFramePointers="TRUE" | 65 | OmitFramePointers="TRUE" |
66 | PreprocessorDefinitions="WIN32;ZLIB_DLL;NDEBUG;_CONSOLE" | 66 | PreprocessorDefinitions="WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE" |
67 | StringPooling="TRUE" | 67 | StringPooling="TRUE" |
68 | RuntimeLibrary="4" | 68 | RuntimeLibrary="4" |
69 | EnableFunctionLevelLinking="TRUE" | 69 | EnableFunctionLevelLinking="TRUE" |
@@ -116,7 +116,7 @@ | |||
116 | Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"> | 116 | Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"> |
117 | </Filter> | 117 | </Filter> |
118 | <File | 118 | <File |
119 | RelativePath="zlib.lib"> | 119 | RelativePath="zlibwapi.lib"> |
120 | </File> | 120 | </File> |
121 | </Files> | 121 | </Files> |
122 | <Globals> | 122 | <Globals> |