├── Base.h
├── BaseMesh.h
├── DiskIO.cpp
├── DiskIO.h
├── Error.cpp
├── Error.h
├── ID_APP.ico
├── MD3View.sln
├── MD3View.vcproj
├── README
├── Script.cpp
├── Script.h
├── TEXT.CPP
├── TEXT.H
├── Targa.h
├── animation.cpp
├── animation.h
├── bmp.cpp
├── bmp.h
├── clipboard.cpp
├── clipboard.h
├── drag.cpp
├── g2export.cpp
├── g2export.h
├── jpeg6
├── jcomapi.c
├── jconfig.h
├── jdapimin.c
├── jdapistd.c
├── jdatasrc.c
├── jdcoefct.c
├── jdcolor.c
├── jdct.h
├── jddctmgr.c
├── jdhuff.c
├── jdhuff.h
├── jdinput.c
├── jdmainct.c
├── jdmarker.c
├── jdmaster.c
├── jdpostct.c
├── jdsample.c
├── jdtrans.c
├── jerror.c
├── jerror.h
├── jidctflt.c
├── jinclude.h
├── jmemmgr.c
├── jmemnobs.c
├── jmemsys.h
├── jmorecfg.h
├── jpegint.h
├── jpeglib.h
├── jutils.c
└── jversion.h
├── jpeg_interface.cpp
├── jpeg_interface.h
├── matcomp.c
├── matcomp.h
├── matrix4.cpp
├── matrix4.h
├── md3IO.cpp
├── md3gl.cpp
├── md3gl.h
├── md3view.cpp
├── md3view.h
├── md3view.rc
├── mdr.h
├── mdx_format.h
├── ndictionary.h
├── nodedictionary.cpp
├── nodesequence.cpp
├── nsequence.h
├── oddbits.cpp
├── oddbits.h
├── png
├── png.cpp
└── png.h
├── resource.h
├── stdafx.h
├── system.h
├── targa.cpp
├── texture_res.cpp
├── vect3.cpp
├── vect3.h
├── widgets.cpp
├── win32_driver.cpp
├── win32_msg.cpp
├── win32_treeview.cpp
└── zlib
├── adler32.c
├── crc32.cpp
├── deflate.c
├── deflate.h
├── infblock.c
├── infblock.h
├── infcodes.c
├── infcodes.h
├── inffast.c
├── inffast.h
├── inffixed.h
├── inflate.c
├── inftrees.c
├── inftrees.h
├── infutil.c
├── infutil.h
├── trees.c
├── trees.h
├── zconf.h
├── zlib.h
├── zutil.c
└── zutil.h
/Base.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 |
20 | #ifndef _BASE_H_
21 | #define _BASE_H_
22 |
23 | #define INT32 int
24 | #define INT16 short
25 | #define INT8 char
26 |
27 | #define UINT32 unsigned int
28 | #define UINT16 unsigned short
29 | #define UINT8 unsigned char
30 |
31 | #define SINT32 signed int
32 | #define SINT16 signed short
33 | #define SINT8 signed char
34 |
35 | typedef float Vec3[3];
36 | typedef float Vec2[2];
37 | typedef Vec3 Mat3x3[3];
38 |
39 | typedef INT32 TriVec[3]; //vertex 1,2,3 of TriVec
40 | typedef Vec2 TexVec; //Texture U/V coordinates of vertex
41 |
42 | #endif
--------------------------------------------------------------------------------
/BaseMesh.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 |
20 | #ifndef _BASEMESH_H_
21 | #define _BASEMESH_H_
22 |
23 | #include "mdr.h" // for MAX_QPATH
24 |
25 | /**START OLD STRUCTURES**/
26 |
27 | //These structures are exactly the same in the md3 file structure.
28 | //It is very likely that these structures will be replaced with a
29 | //very different internal structure.
30 | /*
31 | typedef struct
32 | {
33 | //start guess
34 | float Mins[3];
35 | float Maxs[3];
36 | float Position[3];
37 | float Scale;
38 | //end guess
39 | char Creator[16]; //i think this is the "creator" name..
40 | //but i'm only guessing.
41 | } BoneFrame_t;
42 | */
43 | typedef struct
44 | {
45 | vec3_t bounds[2];
46 | vec3_t localOrigin;
47 | float radius;
48 | char name[16]; // creator
49 | } md3BoundFrame_t;
50 |
51 |
52 |
53 | // as with everything else in this source, this is a mess. I've replaced the original guesswork name/unknown stuff,
54 | // but couldn't be arsed converting either the original MD3 code, or the new MDR code to use the other's labels, so...
55 | //
56 | typedef struct
57 | {
58 | /* char Name[12]; //name of 'tag' as it's usually called in the md3 files
59 | //try to see it as a sub-mesh/seperate mesh-part
60 | char unknown[52]; //normally filled with zeros, but there is an exception
61 | //where it's filled with other numbers...
62 | //it would be logical if it was part of name, because
63 | //then name would have 64 chars.
64 | */
65 | union
66 | {
67 | char Name[MAX_QPATH];
68 | char name[MAX_QPATH]; // tag name
69 | };
70 |
71 | union
72 | {
73 | //unverified:
74 | Vec3 Position; //relative position of tag
75 | vec3_t origin;
76 | };
77 |
78 | union
79 | {
80 | Mat3x3 Matrix; //3x3 rotation matrix
81 | vec3_t axis[3];
82 | };
83 |
84 | } Tag;
85 | typedef Tag* TagFrame;
86 | /**END OLD STRUCTURES**/
87 |
88 | typedef Tag md3Tag_t;
89 |
90 |
91 | #endif
--------------------------------------------------------------------------------
/DiskIO.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #include "system.h"
20 | #include "diskio.h"
21 |
22 | void putLittle16 ( INT16 num , FILE *f )
23 | {
24 | union
25 | {
26 | struct
27 | {
28 | UINT8 b1, b2;
29 | };
30 | UINT16 i1;
31 | } u;
32 |
33 | u.i1 = num;
34 |
35 | fputc( u.b1, f );
36 | fputc( u.b2, f );
37 | }
38 |
39 | INT16 getLittle16 (FILE *f)
40 | {
41 | union
42 | {
43 | struct
44 | {
45 | UINT8 b1, b2;
46 | };
47 | UINT16 i1;
48 | } u;
49 |
50 | u.b1 = fgetc(f);
51 | u.b2 = fgetc(f);
52 |
53 | return u.i1;
54 | }
55 |
56 | void putLittle32 ( INT32 num , FILE *f )
57 | {
58 | union
59 | {
60 | struct
61 | {
62 | UINT8 b1, b2, b3, b4;
63 | };
64 | UINT32 i1;
65 | } u;
66 |
67 | u.i1 = num;
68 |
69 | fputc( u.b1, f );
70 | fputc( u.b2, f );
71 | fputc( u.b3, f );
72 | fputc( u.b4, f );
73 | }
74 |
75 | INT32 getLittle32 (FILE *f)
76 | {
77 | union
78 | {
79 | struct
80 | {
81 | UINT8 b1, b2, b3, b4;
82 | };
83 | UINT32 i1;
84 | } u;
85 |
86 | u.b1 = fgetc(f);
87 | u.b2 = fgetc(f);
88 | u.b3 = fgetc(f);
89 | u.b4 = fgetc(f);
90 |
91 | return u.i1;
92 | }
93 |
94 | void putLittleFloat( float num , FILE *f )//32bit floating point number
95 | {
96 | union
97 | {
98 | struct
99 | {
100 | UINT8 b1, b2, b3, b4;
101 | };
102 | float f1;
103 | } u;
104 |
105 | u.f1 = num;
106 |
107 | fputc( u.b1, f );
108 | fputc( u.b2, f );
109 | fputc( u.b3, f );
110 | fputc( u.b4, f );
111 | }
112 |
113 | float getLittleFloat (FILE *f) //32bit floating point number
114 | {
115 | union
116 | {
117 | struct
118 | {
119 | UINT8 b1, b2, b3, b4;
120 | };
121 | float f1;
122 | } u;
123 |
124 | u.b1 = fgetc(f);
125 | u.b2 = fgetc(f);
126 | u.b3 = fgetc(f);
127 | u.b4 = fgetc(f);
128 |
129 | return u.f1;
130 | }
131 |
132 | void putBig16 ( INT16 num , FILE *f )
133 | {
134 | union
135 | {
136 | struct
137 | {
138 | UINT8 b1, b2, b3, b4;
139 | };
140 | INT16 i1;
141 | } u;
142 |
143 | u.i1 = num;
144 |
145 | fputc( u.b2, f );
146 | fputc( u.b1, f );
147 | }
148 |
149 | INT16 getBig16 (FILE *f)
150 | {
151 | union
152 | {
153 | struct
154 | {
155 | UINT8 b1, b2;
156 | };
157 | UINT16 i1;
158 | } u;
159 |
160 | u.b2 = fgetc(f);
161 | u.b1 = fgetc(f);
162 |
163 | return u.i1;
164 | }
165 |
166 | void putBig32 ( INT32 num , FILE *f )
167 | {
168 | union
169 | {
170 | struct
171 | {
172 | UINT8 b1, b2, b3, b4;
173 | };
174 | INT32 i1;
175 | } u;
176 |
177 | u.i1 = num;
178 |
179 | fputc( u.b4, f );
180 | fputc( u.b3, f );
181 | fputc( u.b2, f );
182 | fputc( u.b1, f );
183 | }
184 |
185 | INT32 getBig32 (FILE *f)
186 | {
187 | union
188 | {
189 | struct
190 | {
191 | UINT8 b1, b2, b3, b4;
192 | };
193 | UINT32 i1;
194 | } u;
195 |
196 | u.b4 = fgetc(f);
197 | u.b3 = fgetc(f);
198 | u.b2 = fgetc(f);
199 | u.b1 = fgetc(f);
200 |
201 | return u.i1;
202 | }
203 |
204 | void putBigFloat ( float num , FILE *f ) //32bit floating point number
205 | {
206 | union
207 | {
208 | struct
209 | {
210 | UINT8 b1, b2, b3, b4;
211 | };
212 | float f1;
213 | } u;
214 |
215 | u.f1 = num;
216 |
217 | fputc( u.b4, f );
218 | fputc( u.b3, f );
219 | fputc( u.b2, f );
220 | fputc( u.b1, f );
221 | }
222 |
223 | float getBigFloat (FILE *f) //32bit floating point number
224 | {
225 | union
226 | {
227 | struct
228 | {
229 | UINT8 b1, b2, b3, b4;
230 | };
231 | float f1;
232 | } u;
233 |
234 | u.b4 = fgetc(f);
235 | u.b3 = fgetc(f);
236 | u.b2 = fgetc(f);
237 | u.b1 = fgetc(f);
238 |
239 | return u.f1;
240 | }
241 |
--------------------------------------------------------------------------------
/DiskIO.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 |
20 | #ifndef _DISKIO_H_
21 | #define _DISKIO_H_
22 |
23 | void putLittle16 ( INT16 num , FILE *f );
24 | INT16 getLittle16 ( FILE *f );
25 | void putLittle32 ( INT32 num , FILE *f );
26 | INT32 getLittle32 ( FILE *f );
27 | void putLittleFloat ( float num , FILE *f ); //32bit floating point number
28 | float getLittleFloat ( FILE *f ); //32bit floating point number
29 | void putBig16 ( INT16 num , FILE *f );
30 | INT16 getBig16 ( FILE *f );
31 | void putBig32 ( INT32 num , FILE *f );
32 | INT32 getBig32 ( FILE *f );
33 | void putBigFloat ( float num , FILE *f ); //32bit floating point number
34 | float getBigFloat ( FILE *f ); //32bit floating point number
35 |
36 | #define get16 getLittle16
37 | #define get32 getLittle32
38 | #define getFloat getLittleFloat
39 | #define put16 putLittle16
40 | #define put32 putLittle32
41 | #define putFloat putLittleFloat
42 |
43 | #endif
--------------------------------------------------------------------------------
/Error.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #include "system.h"
20 |
21 | /*
22 | error handler
23 | */
24 |
25 | void Error (char *error, ...)
26 | {
27 | va_list argptr;
28 | char text[1024];
29 |
30 | va_start (argptr,error);
31 | vsprintf (text, error,argptr);
32 | va_end (argptr);
33 |
34 | MessageBox( NULL, text, "Error", MB_OK );
35 |
36 | exit (1);
37 | }
38 |
39 |
40 | /*
41 | debugging output
42 | */
43 | void Debug (char *error, ...)
44 | {
45 | va_list argptr;
46 | char text[4096];
47 |
48 | va_start (argptr,error);
49 | vsprintf (text, error,argptr);
50 | va_end (argptr);
51 |
52 | MessageBox( NULL, text, "Debug", MB_OK );
53 | }
54 |
--------------------------------------------------------------------------------
/Error.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 |
20 | #ifndef _ERROR_H_
21 | #define _ERROR_H_
22 |
23 | void Error (char *error, ...);
24 | void Debug (char *error, ...);
25 |
26 | #endif
--------------------------------------------------------------------------------
/ID_APP.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/UberGames/MD3View/67f26a577a83489e6f785988158c10b2f1746c52/ID_APP.ico
--------------------------------------------------------------------------------
/MD3View.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 10.00
3 | # Visual Studio 2008
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MD3View", "MD3View.vcproj", "{144114CF-2224-4770-A0C8-E87754FC2ED9}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Release|Win32 = Release|Win32
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {144114CF-2224-4770-A0C8-E87754FC2ED9}.Debug|Win32.ActiveCfg = Debug|Win32
13 | {144114CF-2224-4770-A0C8-E87754FC2ED9}.Debug|Win32.Build.0 = Debug|Win32
14 | {144114CF-2224-4770-A0C8-E87754FC2ED9}.Release|Win32.ActiveCfg = Release|Win32
15 | {144114CF-2224-4770-A0C8-E87754FC2ED9}.Release|Win32.Build.0 = Release|Win32
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | ==============================================
2 |
3 | MD3View
4 | By Sander van Rossen & Matthew Baranowski
5 | Additional Enhancements by Raven Software
6 |
7 | ==============================================
8 |
9 | Copyright (C) 2010-2011 Matthew Baranowski, Sander van Rossen & Raven software.
10 |
11 | This program is free software: you can redistribute it and/or modify
12 | it under the terms of the GNU General Public License as published by
13 | the Free Software Foundation, either version 3 of the License, or
14 | (at your option) any later version.
15 |
16 | This program is distributed in the hope that it will be useful,
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | GNU General Public License for more details.
20 |
21 | You should have received a copy of the GNU General Public License
22 | along with this program. If not, see .
23 |
24 | ==============================================
25 |
26 | This is a mirror of the latest official build of MD3View,
27 | created by Raven Software for the development of JK2/JKA.
28 |
29 | This project is provided as is, with no intended warranty
30 | or support.
31 |
--------------------------------------------------------------------------------
/Script.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifndef _RENDERPASS_H_
20 | #define _RENDERPASS_H_
21 |
22 | enum typeTextureEnum
23 | {
24 | texture_normal, texture_alpha, texture_anim
25 | };
26 |
27 | class RenderPass
28 | {
29 | public:
30 | //tcMod - texcoords
31 | float rp_rotate,rp_scalex,rp_scaley,rp_scrollx,rp_scrolly,
32 | //i don't know what the values a-d are for.
33 | rp_turba,rp_turbb,rp_turbc,rp_turbd,
34 | //i don't know what the values a-d are for.
35 | rp_stretchsina,rp_stretchsinb,rp_stretchsinc,rp_stretchsind;
36 | //various gl functions
37 | GLenum blend_sfactor,blend_dfactor,alpha_func,depth_func;
38 | GLclampf alpha_ref;
39 |
40 | //misc commands
41 | bool rp_detail,rp_depthwrite,rp_clamptexcoords;
42 |
43 | NodeDictionary AnimationFramesNames;
44 | NodeDictionary AnimationFramesBuffers;
45 | int AnimationFramesNum;
46 | char* AlphaName;
47 | GLuint AlphaBuffer;
48 | char* TextureName;
49 | GLuint TextureBuffer;
50 |
51 | typeTextureEnum typeTexture;
52 |
53 | RenderPass();
54 | void AddParam( char* Type, char* Var );
55 | };
56 |
57 | typedef RenderPass* RenderPassPtr;
58 |
59 | enum culltype {cull_normal,cull_none, cull_disable, cull_twosided, cull_backsided, cull_back};
60 |
61 | class Surface
62 | {
63 | public:
64 | //surfaceparam
65 | bool sp_trans ,sp_metalsteps,sp_nolightmap,sp_nodraw ,sp_noimpact,
66 | sp_nonsolid ,sp_nomarks ,sp_nodrop ,sp_nodamage ,sp_playerclip,
67 | sp_structural ,sp_slick ,sp_origin ,sp_areaportal,sp_fog,
68 | sp_lightfilter,sp_water ,sp_slime ,sp_sky ,sp_lava,
69 | sf_light1;
70 | //cull
71 | culltype cull;
72 |
73 | //misc commands
74 | bool sf_portal,sf_fogonly,sf_nomipmaps,sf_polygonOffset,
75 | sf_lightning,sf_backsided,sf_qer_nocarve;
76 | float sf_light,sf_tesssize,sf_sort,sf_qer_trans,sf_q3map_backsplash,
77 | sf_q3map_surfacelight;
78 | char *sf_sky,*sf_q3map_lightimage,*sf_qer_editorimage,
79 | *sf_qer_lightimage;
80 |
81 | NodeDictionary RenderPasses;
82 | UINT32 pass_num;
83 |
84 | Surface();
85 | ~Surface();
86 | void AddParam( char* Type, char* Var );
87 | void AddPass ( RenderPass* Pass );
88 | void LoadTextures();
89 | void DestroyTextures();
90 | };
91 |
92 | typedef Surface* SurfacePtr;
93 |
94 | Surface* LoadSurface( char* filename );
95 | void freeSurface( Surface* );
96 |
97 | #endif //_RENDERPASS_H_
--------------------------------------------------------------------------------
/TEXT.H:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifndef TEXT_H
20 | #define TEXT_H
21 |
22 | #define TEXT_WIDTH 8
23 | #define TEXT_DEPTH 8
24 |
25 | //void Text_Create(void); // called automatically internally
26 | void Text_Destroy(void); // should be called at program shutdown
27 | void Text_Display(LPCSTR psString, Vec3 v3DPos, byte r, byte g, byte b);
28 | int Text_DisplayFlat(LPCSTR psString, int x, int y, byte r, byte g, byte b, bool bResizeStringIfNecessary = false);
29 |
30 | extern int g_iScreenWidth;
31 | extern int g_iScreenHeight;
32 | extern bool gbTextInhibit;
33 |
34 |
35 | #endif // #ifndef TEXT_H
36 |
37 | ////////////////////////// eof ///////////////////////////
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/Targa.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifndef _TARGA_H_
20 | #define _TARGA_H_
21 |
22 | bool loadTGA (char *name, byte **pixels, unsigned int *width, unsigned int *height, unsigned int *format);
23 |
24 | #endif
--------------------------------------------------------------------------------
/animation.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifndef ANIMATION_H
20 | #define ANIMATION_H
21 |
22 |
23 | #include
24 | #include
25 | #include
26 | using namespace std;
27 |
28 |
29 | typedef vector MultiSequenceLock_t;
30 | extern MultiSequenceLock_t MultiSequenceLock_Upper;
31 | extern MultiSequenceLock_t MultiSequenceLock_Lower;
32 |
33 |
34 | typedef struct
35 | {
36 | string sName;
37 | int iTargetFrame;
38 | int iFrameCount;
39 | int iLoopFrame;
40 | int iFrameSpeed;
41 | bool bMultiSeq;
42 | } Sequence_t;
43 |
44 | int GetNextFrame_MultiLocked(gl_model* pModel, int iFrame, int iStepVal);
45 | Sequence_t* GetMultiLockedSequenceFromFrame(int iFrame, bool bIsUpper );
46 | int Model_EnsureCurrentFrameLegal(gl_model* model, int iFrame);
47 | Sequence_t* Animation_GetLowerSequence(int iIndex);
48 | Sequence_t* Animation_GetUpperSequence(int iIndex);
49 | int Animation_GetNumLowerSequences(void);
50 | int Animation_GetNumUpperSequences(void);
51 | Sequence_t* Animation_FromUpperFrame(int iFrame);
52 | Sequence_t* Animation_FromLowerFrame(int iFrame);
53 | void ClearAnimationCFG();
54 | void LoadAnimationCFG(LPCSTR psFullPath, HDC hDC);
55 | extern int iAnimLockNumber_Upper;
56 | extern int iAnimLockNumber_Lower;
57 | extern int iAnimDisplayNumber_Upper;
58 | extern int iAnimDisplayNumber_Lower;
59 | extern int iAnimLockLongestString;
60 | extern gl_model* pModel_Lower;
61 | extern gl_model* pModel_Upper;
62 |
63 |
64 | #endif // #ifndef ANIMATION_H
65 |
66 | //////////////////// eof //////////////////////
67 |
68 |
69 |
--------------------------------------------------------------------------------
/bmp.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | // #include "oddbits.h"
23 | #include "bmp.h"
24 |
25 |
26 | static bool BMP_FlipTrueColour(LPCSTR psFilename);
27 |
28 |
29 | static int iBMP_PixelWriteOffset;
30 | static PMEMORYBMP pBMP = NULL;
31 | static int iBMP_MallocSize;
32 | //
33 | static FILE *fhBMP = 0;
34 |
35 |
36 | bool BMP_GetMemDIB(void *&pvAddress, int &iBytes)
37 | {
38 | if (pBMP)
39 | {
40 | pvAddress = pBMP;
41 | iBytes = iBMP_MallocSize;
42 | return true;
43 | }
44 |
45 | return false;
46 | }
47 |
48 |
49 |
50 | // open 24-bit RGB file either to disk or memory
51 | //
52 | // if psFileName == NULL, open memory file instead
53 | //
54 | bool BMP_Open(LPCSTR psFilename, int iWidth, int iHeight)
55 | {
56 | BITMAPFILEHEADER BMPFileHeader;
57 | BITMAPINFOHEADER BMPInfoHeader;
58 |
59 | int iPadBytes = (4-((iWidth * sizeof(RGBTRIPLE))%4))&3;
60 | int iWidthBytes = (iWidth * sizeof(RGBTRIPLE))+iPadBytes;
61 |
62 | ///////
63 | if (pBMP)
64 | {
65 | free(pBMP);
66 | pBMP = NULL;
67 | }
68 | fhBMP = NULL;
69 | ///////
70 |
71 | if (psFilename)
72 | {
73 | fhBMP = fopen(psFilename,"wb");
74 | if (!(int)fhBMP)
75 | return false;
76 | }
77 | else
78 | {
79 | iBMP_MallocSize = sizeof(BITMAPINFOHEADER) + (iWidthBytes * iHeight);
80 | pBMP = (PMEMORYBMP) malloc ( iBMP_MallocSize );
81 | if (!pBMP)
82 | return false;
83 | }
84 |
85 | memset(&BMPFileHeader, 0, sizeof(BITMAPFILEHEADER));
86 | BMPFileHeader.bfType=(WORD)('B'+256*'M');
87 | // int iPad= ((sizeof(RGBTRIPLE)*iWidth)%3)*iHeight;
88 | // BMPFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+(sizeof(RGBTRIPLE)*iWidth*iHeight);//+iPad;
89 | BMPFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+(iWidthBytes * iHeight);
90 |
91 | BMPFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); // No palette
92 |
93 | if (fhBMP)
94 | {
95 | fwrite (&BMPFileHeader,sizeof(BMPFileHeader),1,fhBMP);
96 | }
97 | else
98 | {
99 | // memory version doesn't use the BITMAPFILEHEADER structure
100 | }
101 |
102 | memset(&BMPInfoHeader, 0, sizeof(BITMAPINFOHEADER));
103 | BMPInfoHeader.biSize=sizeof(BITMAPINFOHEADER);
104 | BMPInfoHeader.biWidth=iWidth;
105 | BMPInfoHeader.biHeight=iHeight;
106 | BMPInfoHeader.biPlanes=1;
107 | BMPInfoHeader.biBitCount=24;
108 | BMPInfoHeader.biCompression=BI_RGB;
109 | BMPInfoHeader.biSizeImage=0;// BMPFileHeader.bfSize - (sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)); // allowed for BI_RGB bitmaps
110 | BMPInfoHeader.biXPelsPerMeter=0; // don't know about these
111 | BMPInfoHeader.biYPelsPerMeter=0;
112 | BMPInfoHeader.biClrUsed=0;
113 | BMPInfoHeader.biClrImportant=0;
114 |
115 | if (fhBMP)
116 | {
117 | fwrite (&BMPInfoHeader,sizeof(BMPInfoHeader),1,fhBMP);
118 | }
119 | else
120 | {
121 | pBMP->BMPInfoHeader = BMPInfoHeader; // struct copy
122 | iBMP_PixelWriteOffset = 0;
123 | }
124 |
125 | return true;
126 | }
127 |
128 | bool BMP_WritePixel(byte Red, byte Green, byte Blue)
129 | {
130 | RGBTRIPLE Trip = {0,0,0};
131 |
132 | Trip.rgbtRed = Red;
133 | Trip.rgbtGreen = Green;
134 | Trip.rgbtBlue = Blue;
135 |
136 | if (fhBMP)
137 | {
138 | fwrite(&Trip, sizeof(RGBTRIPLE), 1, fhBMP);
139 | }
140 | else
141 | {
142 | RGBTRIPLE *pDest = (RGBTRIPLE *) ((byte *)pBMP->RGBData + iBMP_PixelWriteOffset);
143 |
144 | *pDest = Trip;
145 |
146 | iBMP_PixelWriteOffset += sizeof(RGBTRIPLE);
147 | }
148 |
149 | return true;
150 | }
151 |
152 | // BMP files need padding to 4-byte boundarys after writing each scan line... (which sucks, and messes up pixel indexing)
153 | //
154 | bool BMP_WriteLinePadding(int iPixelsPerLine)
155 | {
156 | static char cPad[4]={0};
157 |
158 | int iPadBytes = (4-((iPixelsPerLine * sizeof(RGBTRIPLE))%4))&3;
159 |
160 | if (iPadBytes)
161 | {
162 | if (fhBMP)
163 | {
164 | fwrite( &cPad, iPadBytes, 1, fhBMP);
165 | }
166 | else
167 | {
168 | iBMP_PixelWriteOffset += iPadBytes; // , can't be bothered padding with zeroes
169 | }
170 | }
171 | return true;
172 | }
173 |
174 | // BMP files are stored upside down, but if we're writing this out as a result of doing an OpenGL pixel read, then
175 | // the src buffer will be upside down anyway, so I added this flip-bool -Ste
176 | //
177 | // (psFilename can be NULL for mem files)
178 | //
179 | bool BMP_Close(LPCSTR psFilename, bool bFlipFinal)
180 | {
181 | if (fhBMP)
182 | {
183 | fclose (fhBMP);
184 | }
185 | else
186 | {
187 | #if 1
188 |
189 | int iPadBytes = (4-((pBMP->BMPInfoHeader.biWidth * sizeof(RGBTRIPLE))%4))&3;
190 | int iWidthBytes = (pBMP->BMPInfoHeader.biWidth * sizeof(RGBTRIPLE))+iPadBytes;
191 |
192 | assert(iBMP_PixelWriteOffset == iWidthBytes * pBMP->BMPInfoHeader.biHeight);
193 | assert((iBMP_PixelWriteOffset + (int)sizeof(BITMAPINFOHEADER)) == iBMP_MallocSize);
194 |
195 | #endif
196 | }
197 |
198 | if (bFlipFinal)
199 | {
200 | if (psFilename)
201 | {
202 | if (!BMP_FlipTrueColour(psFilename))
203 | return false;
204 | }
205 | }
206 |
207 | return true;
208 | }
209 |
210 |
211 | static bool BMP_FlipTrueColour(LPCSTR psFilename)
212 | {
213 | BITMAPFILEHEADER BMPFileHeader;
214 | BITMAPINFOHEADER BMPInfoHeader;
215 | RGBTRIPLE *RGBTriples, *tTopLine, *tBottomLine;//, *AfterLastLine;
216 | BYTE *byTopLine, *byBottomLine, *byAfterLastLine;
217 | RGBTRIPLE Trip;
218 | int x,y;
219 | int iPadBytes,iRealWidth;
220 |
221 |
222 | // reopen it to flip it
223 | fhBMP=fopen(psFilename,"rb"); // checked fopen
224 | if (!(int)fhBMP)
225 | return false;
226 |
227 | fread (&BMPFileHeader,sizeof(BMPFileHeader),1,fhBMP);
228 | fread (&BMPInfoHeader,sizeof(BMPInfoHeader),1,fhBMP);
229 | iPadBytes = (4-((BMPInfoHeader.biWidth * sizeof(RGBTRIPLE))%4))&3;
230 | iRealWidth=(sizeof(RGBTRIPLE)*BMPInfoHeader.biWidth)+iPadBytes;
231 |
232 | RGBTriples=(RGBTRIPLE *)malloc(iRealWidth*BMPInfoHeader.biHeight);
233 | fread (RGBTriples,iRealWidth*BMPInfoHeader.biHeight,1,fhBMP);
234 |
235 | fclose (fhBMP);
236 |
237 | byTopLine=(BYTE *)RGBTriples;
238 | byAfterLastLine=byTopLine+iRealWidth*BMPInfoHeader.biHeight;
239 |
240 | // actually flip it
241 | for (y=0; y.
16 |
17 | */
18 |
19 |
20 | #ifndef BMP_H
21 | #define BMP_H
22 |
23 | #ifndef BITMAPINFOHEADER
24 | #include
25 | #endif
26 |
27 |
28 | #include
29 | typedef struct
30 | {
31 | BYTE r,g,b; // R&B different order to windoze's RGBTRIPLE struct
32 | } GLRGBBYTES,*LPGLRGBBYTES;
33 | #include
34 |
35 | typedef struct
36 | {
37 | BITMAPINFOHEADER BMPInfoHeader;
38 | RGBTRIPLE RGBData[1]; // a label just for addressing purposes, the actual array size depends on screen dims
39 | } MEMORYBMP, *PMEMORYBMP;
40 |
41 |
42 | bool BMP_Open (LPCSTR psFilename, int iWidth, int iHeight);
43 | bool BMP_WritePixel (byte Red, byte Green, byte Blue);
44 | bool BMP_WriteLinePadding(int iPixelsPerLine);
45 | bool BMP_Close (LPCSTR psFilename, bool bFlipFinal);
46 | bool BMP_GetMemDIB (void *&pvAddress, int &iBytes);
47 |
48 | #endif // #ifndef BMP_H
49 |
50 | /////////////////// eof ////////////////////
51 |
52 |
--------------------------------------------------------------------------------
/clipboard.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include "oddbits.h"
23 | #include "clipboard.h"
24 |
25 |
26 |
27 | extern HWND mainhWnd;
28 |
29 |
30 |
31 | BOOL ClipBoard_SendDIB(LPVOID pvData, int iBytes)
32 | {
33 | HGLOBAL hXferBuffer = GlobalAlloc((UINT)GMEM_MOVEABLE|GMEM_DDESHARE,(DWORD)iBytes);
34 | if (hXferBuffer)
35 | {
36 | char *psLockedDest = (char*) GlobalLock(hXferBuffer);
37 | memcpy(psLockedDest,pvData,iBytes);
38 | GlobalUnlock(psLockedDest);
39 |
40 | if (OpenClipboard(mainhWnd))
41 | {
42 | EmptyClipboard(); // empty it (all handles to NULL);
43 | if((SetClipboardData((UINT)CF_DIB,hXferBuffer))==NULL)
44 | {
45 | CloseClipboard();
46 | ErrorBox("ClipBoard_SendDIB(): Dammit, some sort of problem writing to the clipboard...");
47 | return FALSE; // hmmmm... Oh well.
48 | }
49 | CloseClipboard();
50 | return TRUE;
51 | }
52 | }
53 |
54 | ErrorBox(va("ClipBoard_SendDIB(): Dammit, I can't allocate %d bytes for some strange reason (reboot, then try again, else tell me - Ste)",iBytes));
55 | return FALSE;
56 | }
57 |
58 |
59 | BOOL Clipboard_SendString(LPCSTR psString)
60 | {
61 | HGLOBAL hXferBuffer = GlobalAlloc((UINT)GMEM_MOVEABLE|GMEM_DDESHARE,(DWORD)strlen(psString)+1);
62 | if (hXferBuffer)
63 | {
64 | char *psLockedDest = (char*) GlobalLock(hXferBuffer);
65 | memcpy(psLockedDest,psString,strlen(psString)+1);
66 | GlobalUnlock(psLockedDest);
67 |
68 | if (OpenClipboard(mainhWnd))
69 | {
70 | EmptyClipboard(); // empty it (all handles to NULL);
71 | if((SetClipboardData((UINT)CF_TEXT,hXferBuffer))==NULL)
72 | {
73 | CloseClipboard();
74 | ErrorBox("Clipboard_SendString(): Dammit, some sort of problem writing to the clipboard...");
75 | return FALSE; // hmmmm... Oh well.
76 | }
77 | CloseClipboard();
78 | return TRUE;
79 | }
80 | }
81 |
82 | ErrorBox(va("Clipboard_SendString(): Dammit, I can't allocate %d bytes for some strange reason (reboot, then try again, else tell me - Ste)",strlen(psString)+1));
83 | return FALSE;
84 | }
85 |
86 |
87 |
88 | //////////////// eof ////////////////
89 |
90 |
--------------------------------------------------------------------------------
/clipboard.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifndef CLIPBOARD_H
20 | #define CLIPBOARD_H
21 |
22 |
23 | BOOL Clipboard_SendString(LPCSTR psString);
24 | BOOL ClipBoard_SendDIB(LPVOID pvData, int iBytes);
25 |
26 |
27 | #endif
28 |
29 | /////////////////// eof //////////////////
30 |
31 |
--------------------------------------------------------------------------------
/g2export.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifndef G2EXPORT_H
20 | #define G2EXPORT_H
21 |
22 |
23 | char *ExportGhoul2FromMD3(LPCSTR psFullPathedFilename, int iNumLODs, int iNumSurfaces, int iNumTags,
24 | LPCSTR *ppsFullPathedNameGLA = NULL
25 | );
26 |
27 |
28 |
29 |
30 |
31 |
32 | #endif // #ifndef G2EXPORT_H
33 |
34 | //////////////// eof ///////////////
35 |
36 |
--------------------------------------------------------------------------------
/jpeg6/jcomapi.c:
--------------------------------------------------------------------------------
1 | /*
2 | * jcomapi.c
3 | *
4 | * Copyright (C) 1994, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This file contains application interface routines that are used for both
9 | * compression and decompression.
10 | */
11 |
12 | #define JPEG_INTERNALS
13 | #include "jinclude.h"
14 | #include "jpeglib.h"
15 |
16 |
17 | /*
18 | * Abort processing of a JPEG compression or decompression operation,
19 | * but don't destroy the object itself.
20 | *
21 | * For this, we merely clean up all the nonpermanent memory pools.
22 | * Note that temp files (virtual arrays) are not allowed to belong to
23 | * the permanent pool, so we will be able to close all temp files here.
24 | * Closing a data source or destination, if necessary, is the application's
25 | * responsibility.
26 | */
27 |
28 | GLOBAL void
29 | jpeg_abort (j_common_ptr cinfo)
30 | {
31 | int pool;
32 |
33 | /* Releasing pools in reverse order might help avoid fragmentation
34 | * with some (brain-damaged) malloc libraries.
35 | */
36 | for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
37 | (*cinfo->mem->free_pool) (cinfo, pool);
38 | }
39 |
40 | /* Reset overall state for possible reuse of object */
41 | cinfo->global_state = (cinfo->is_decompressor ? DSTATE_START : CSTATE_START);
42 | }
43 |
44 |
45 | /*
46 | * Destruction of a JPEG object.
47 | *
48 | * Everything gets deallocated except the master jpeg_compress_struct itself
49 | * and the error manager struct. Both of these are supplied by the application
50 | * and must be freed, if necessary, by the application. (Often they are on
51 | * the stack and so don't need to be freed anyway.)
52 | * Closing a data source or destination, if necessary, is the application's
53 | * responsibility.
54 | */
55 |
56 | GLOBAL void
57 | jpeg_destroy (j_common_ptr cinfo)
58 | {
59 | /* We need only tell the memory manager to release everything. */
60 | /* NB: mem pointer is NULL if memory mgr failed to initialize. */
61 | if (cinfo->mem != NULL)
62 | (*cinfo->mem->self_destruct) (cinfo);
63 | cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
64 | cinfo->global_state = 0; /* mark it destroyed */
65 | }
66 |
67 |
68 | /*
69 | * Convenience routines for allocating quantization and Huffman tables.
70 | * (Would jutils.c be a more reasonable place to put these?)
71 | */
72 |
73 | GLOBAL JQUANT_TBL *
74 | jpeg_alloc_quant_table (j_common_ptr cinfo)
75 | {
76 | JQUANT_TBL *tbl;
77 |
78 | tbl = (JQUANT_TBL *)
79 | (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
80 | tbl->sent_table = FALSE; /* make sure this is false in any new table */
81 | return tbl;
82 | }
83 |
84 |
85 | GLOBAL JHUFF_TBL *
86 | jpeg_alloc_huff_table (j_common_ptr cinfo)
87 | {
88 | JHUFF_TBL *tbl;
89 |
90 | tbl = (JHUFF_TBL *)
91 | (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
92 | tbl->sent_table = FALSE; /* make sure this is false in any new table */
93 | return tbl;
94 | }
95 |
--------------------------------------------------------------------------------
/jpeg6/jconfig.h:
--------------------------------------------------------------------------------
1 | /* jconfig.wat --- jconfig.h for Watcom C/C++ on MS-DOS or OS/2. */
2 | /* see jconfig.doc for explanations */
3 |
4 | #define HAVE_PROTOTYPES
5 | #define HAVE_UNSIGNED_CHAR
6 | #define HAVE_UNSIGNED_SHORT
7 | /* #define void char */
8 | /* #define const */
9 | #define CHAR_IS_UNSIGNED
10 | #define HAVE_STDDEF_H
11 | #define HAVE_STDLIB_H
12 | #undef NEED_BSD_STRINGS
13 | #undef NEED_SYS_TYPES_H
14 | #undef NEED_FAR_POINTERS /* Watcom uses flat 32-bit addressing */
15 | #undef NEED_SHORT_EXTERNAL_NAMES
16 | #undef INCOMPLETE_TYPES_BROKEN
17 |
18 | #define JDCT_DEFAULT JDCT_FLOAT
19 | #define JDCT_FASTEST JDCT_FLOAT
20 |
21 | #ifdef JPEG_INTERNALS
22 |
23 | #undef RIGHT_SHIFT_IS_UNSIGNED
24 |
25 | #endif /* JPEG_INTERNALS */
26 |
27 | #ifdef JPEG_CJPEG_DJPEG
28 |
29 | #define BMP_SUPPORTED /* BMP image file format */
30 | #define GIF_SUPPORTED /* GIF image file format */
31 | #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
32 | #undef RLE_SUPPORTED /* Utah RLE image file format */
33 | #define TARGA_SUPPORTED /* Targa image file format */
34 |
35 | #undef TWO_FILE_COMMANDLINE /* optional */
36 | #define USE_SETMODE /* Needed to make one-file style work in Watcom */
37 | #undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */
38 | #undef DONT_USE_B_MODE
39 | #undef PROGRESS_REPORT /* optional */
40 |
41 | #endif /* JPEG_CJPEG_DJPEG */
42 |
--------------------------------------------------------------------------------
/jpeg6/jdatasrc.c:
--------------------------------------------------------------------------------
1 | /*
2 | * jdatasrc.c
3 | *
4 | * Copyright (C) 1994, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This file contains decompression data source routines for the case of
9 | * reading JPEG data from a file (or any stdio stream). While these routines
10 | * are sufficient for most applications, some will want to use a different
11 | * source manager.
12 | * IMPORTANT: we assume that fread() will correctly transcribe an array of
13 | * JOCTETs from 8-bit-wide elements on external storage. If char is wider
14 | * than 8 bits on your machine, you may need to do some tweaking.
15 | */
16 |
17 |
18 | /* this is not a core library module, so it doesn't define JPEG_INTERNALS */
19 | #include "jinclude.h"
20 | #include "jpeglib.h"
21 | #include "jerror.h"
22 |
23 |
24 | /* Expanded data source object for stdio input */
25 |
26 | typedef struct {
27 | struct jpeg_source_mgr pub; /* public fields */
28 |
29 | unsigned char *infile; /* source stream */
30 | JOCTET * buffer; /* start of buffer */
31 | boolean start_of_file; /* have we gotten any data yet? */
32 | } my_source_mgr;
33 |
34 | typedef my_source_mgr * my_src_ptr;
35 |
36 | // do a search on this if you change it, to catch the one in the file load/alloc code(which can't see this H file)
37 | #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
38 |
39 |
40 | /*
41 | * Initialize source --- called by jpeg_read_header
42 | * before any data is actually read.
43 | */
44 |
45 | METHODDEF void
46 | init_source (j_decompress_ptr cinfo)
47 | {
48 | my_src_ptr src = (my_src_ptr) cinfo->src;
49 |
50 | /* We reset the empty-input-file flag for each image,
51 | * but we don't clear the input buffer.
52 | * This is correct behavior for reading a series of images from one source.
53 | */
54 | src->start_of_file = TRUE;
55 | }
56 |
57 |
58 | /*
59 | * Fill the input buffer --- called whenever buffer is emptied.
60 | *
61 | * In typical applications, this should read fresh data into the buffer
62 | * (ignoring the current state of next_input_byte & bytes_in_buffer),
63 | * reset the pointer & count to the start of the buffer, and return TRUE
64 | * indicating that the buffer has been reloaded. It is not necessary to
65 | * fill the buffer entirely, only to obtain at least one more byte.
66 | *
67 | * There is no such thing as an EOF return. If the end of the file has been
68 | * reached, the routine has a choice of ERREXIT() or inserting fake data into
69 | * the buffer. In most cases, generating a warning message and inserting a
70 | * fake EOI marker is the best course of action --- this will allow the
71 | * decompressor to output however much of the image is there. However,
72 | * the resulting error message is misleading if the real problem is an empty
73 | * input file, so we handle that case specially.
74 | *
75 | * In applications that need to be able to suspend compression due to input
76 | * not being available yet, a FALSE return indicates that no more data can be
77 | * obtained right now, but more may be forthcoming later. In this situation,
78 | * the decompressor will return to its caller (with an indication of the
79 | * number of scanlines it has read, if any). The application should resume
80 | * decompression after it has loaded more data into the input buffer. Note
81 | * that there are substantial restrictions on the use of suspension --- see
82 | * the documentation.
83 | *
84 | * When suspending, the decompressor will back up to a convenient restart point
85 | * (typically the start of the current MCU). next_input_byte & bytes_in_buffer
86 | * indicate where the restart point will be if the current call returns FALSE.
87 | * Data beyond this point must be rescanned after resumption, so move it to
88 | * the front of the buffer rather than discarding it.
89 | */
90 |
91 | METHODDEF boolean
92 | fill_input_buffer (j_decompress_ptr cinfo)
93 | {
94 | my_src_ptr src = (my_src_ptr) cinfo->src;
95 |
96 | memcpy( src->buffer, src->infile, INPUT_BUF_SIZE );
97 |
98 | src->infile += INPUT_BUF_SIZE;
99 |
100 | src->pub.next_input_byte = src->buffer;
101 | src->pub.bytes_in_buffer = INPUT_BUF_SIZE;
102 | src->start_of_file = FALSE;
103 |
104 | return TRUE;
105 | }
106 |
107 |
108 | /*
109 | * Skip data --- used to skip over a potentially large amount of
110 | * uninteresting data (such as an APPn marker).
111 | *
112 | * Writers of suspendable-input applications must note that skip_input_data
113 | * is not granted the right to give a suspension return. If the skip extends
114 | * beyond the data currently in the buffer, the buffer can be marked empty so
115 | * that the next read will cause a fill_input_buffer call that can suspend.
116 | * Arranging for additional bytes to be discarded before reloading the input
117 | * buffer is the application writer's problem.
118 | */
119 |
120 | METHODDEF void
121 | skip_input_data (j_decompress_ptr cinfo, long num_bytes)
122 | {
123 | my_src_ptr src = (my_src_ptr) cinfo->src;
124 |
125 | /* Just a dumb implementation for now. Could use fseek() except
126 | * it doesn't work on pipes. Not clear that being smart is worth
127 | * any trouble anyway --- large skips are infrequent.
128 | */
129 | if (num_bytes > 0) {
130 | while (num_bytes > (long) src->pub.bytes_in_buffer) {
131 | num_bytes -= (long) src->pub.bytes_in_buffer;
132 | (void) fill_input_buffer(cinfo);
133 | /* note we assume that fill_input_buffer will never return FALSE,
134 | * so suspension need not be handled.
135 | */
136 | }
137 | src->pub.next_input_byte += (size_t) num_bytes;
138 | src->pub.bytes_in_buffer -= (size_t) num_bytes;
139 | }
140 | }
141 |
142 |
143 | /*
144 | * An additional method that can be provided by data source modules is the
145 | * resync_to_restart method for error recovery in the presence of RST markers.
146 | * For the moment, this source module just uses the default resync method
147 | * provided by the JPEG library. That method assumes that no backtracking
148 | * is possible.
149 | */
150 |
151 |
152 | /*
153 | * Terminate source --- called by jpeg_finish_decompress
154 | * after all data has been read. Often a no-op.
155 | *
156 | * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
157 | * application must deal with any cleanup that should happen even
158 | * for error exit.
159 | */
160 |
161 | METHODDEF void
162 | term_source (j_decompress_ptr cinfo)
163 | {
164 | /* no work necessary here */
165 | }
166 |
167 |
168 | /*
169 | * Prepare for input from a stdio stream.
170 | * The caller must have already opened the stream, and is responsible
171 | * for closing it after finishing decompression.
172 | */
173 |
174 | GLOBAL void
175 | jpeg_stdio_src (j_decompress_ptr cinfo, unsigned char *infile)
176 | {
177 | my_src_ptr src;
178 |
179 | /* The source object and input buffer are made permanent so that a series
180 | * of JPEG images can be read from the same file by calling jpeg_stdio_src
181 | * only before the first one. (If we discarded the buffer at the end of
182 | * one image, we'd likely lose the start of the next one.)
183 | * This makes it unsafe to use this manager and a different source
184 | * manager serially with the same JPEG object. Caveat programmer.
185 | */
186 | if (cinfo->src == NULL) { /* first time for this JPEG object? */
187 | cinfo->src = (struct jpeg_source_mgr *)
188 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
189 | SIZEOF(my_source_mgr));
190 | src = (my_src_ptr) cinfo->src;
191 | src->buffer = (JOCTET *)
192 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
193 | INPUT_BUF_SIZE * SIZEOF(JOCTET));
194 | }
195 |
196 | src = (my_src_ptr) cinfo->src;
197 | src->pub.init_source = init_source;
198 | src->pub.fill_input_buffer = fill_input_buffer;
199 | src->pub.skip_input_data = skip_input_data;
200 | src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
201 | src->pub.term_source = term_source;
202 | src->infile = infile;
203 | src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
204 | src->pub.next_input_byte = NULL; /* until buffer loaded */
205 | }
206 |
--------------------------------------------------------------------------------
/jpeg6/jdct.h:
--------------------------------------------------------------------------------
1 | /*
2 | * jdct.h
3 | *
4 | * Copyright (C) 1994, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This include file contains common declarations for the forward and
9 | * inverse DCT modules. These declarations are private to the DCT managers
10 | * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.
11 | * The individual DCT algorithms are kept in separate files to ease
12 | * machine-dependent tuning (e.g., assembly coding).
13 | */
14 |
15 |
16 | /*
17 | * A forward DCT routine is given a pointer to a work area of type DCTELEM[];
18 | * the DCT is to be performed in-place in that buffer. Type DCTELEM is int
19 | * for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT
20 | * implementations use an array of type FAST_FLOAT, instead.)
21 | * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
22 | * The DCT outputs are returned scaled up by a factor of 8; they therefore
23 | * have a range of +-8K for 8-bit data, +-128K for 12-bit data. This
24 | * convention improves accuracy in integer implementations and saves some
25 | * work in floating-point ones.
26 | * Quantization of the output coefficients is done by jcdctmgr.c.
27 | */
28 |
29 | #if BITS_IN_JSAMPLE == 8
30 | typedef int DCTELEM; /* 16 or 32 bits is fine */
31 | #else
32 | typedef INT32 DCTELEM; /* must have 32 bits */
33 | #endif
34 |
35 | typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
36 | typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
37 |
38 |
39 | /*
40 | * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer
41 | * to an output sample array. The routine must dequantize the input data as
42 | * well as perform the IDCT; for dequantization, it uses the multiplier table
43 | * pointed to by compptr->dct_table. The output data is to be placed into the
44 | * sample array starting at a specified column. (Any row offset needed will
45 | * be applied to the array pointer before it is passed to the IDCT code.)
46 | * Note that the number of samples emitted by the IDCT routine is
47 | * DCT_scaled_size * DCT_scaled_size.
48 | */
49 |
50 | /* typedef inverse_DCT_method_ptr is declared in jpegint.h */
51 |
52 | /*
53 | * Each IDCT routine has its own ideas about the best dct_table element type.
54 | */
55 |
56 | typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
57 | #if BITS_IN_JSAMPLE == 8
58 | typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
59 | #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
60 | #else
61 | typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
62 | #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
63 | #endif
64 | typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
65 |
66 |
67 | /*
68 | * Each IDCT routine is responsible for range-limiting its results and
69 | * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
70 | * be quite far out of range if the input data is corrupt, so a bulletproof
71 | * range-limiting step is required. We use a mask-and-table-lookup method
72 | * to do the combined operations quickly. See the comments with
73 | * prepare_range_limit_table (in jdmaster.c) for more info.
74 | */
75 |
76 | #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
77 |
78 | #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
79 |
80 |
81 | /* Short forms of external names for systems with brain-damaged linkers. */
82 |
83 | #ifdef NEED_SHORT_EXTERNAL_NAMES
84 | #define jpeg_fdct_islow jFDislow
85 | #define jpeg_fdct_ifast jFDifast
86 | #define jpeg_fdct_float jFDfloat
87 | #define jpeg_idct_islow jRDislow
88 | #define jpeg_idct_ifast jRDifast
89 | #define jpeg_idct_float jRDfloat
90 | #define jpeg_idct_4x4 jRD4x4
91 | #define jpeg_idct_2x2 jRD2x2
92 | #define jpeg_idct_1x1 jRD1x1
93 | #endif /* NEED_SHORT_EXTERNAL_NAMES */
94 |
95 | /* Extern declarations for the forward and inverse DCT routines. */
96 |
97 | EXTERN void jpeg_fdct_islow JPP((DCTELEM * data));
98 | EXTERN void jpeg_fdct_ifast JPP((DCTELEM * data));
99 | EXTERN void jpeg_fdct_float JPP((FAST_FLOAT * data));
100 |
101 | EXTERN void jpeg_idct_islow
102 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
103 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
104 | EXTERN void jpeg_idct_ifast
105 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
106 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
107 | EXTERN void jpeg_idct_float
108 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
109 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
110 | EXTERN void jpeg_idct_4x4
111 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
112 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
113 | EXTERN void jpeg_idct_2x2
114 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
115 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
116 | EXTERN void jpeg_idct_1x1
117 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
118 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
119 |
120 |
121 | /*
122 | * Macros for handling fixed-point arithmetic; these are used by many
123 | * but not all of the DCT/IDCT modules.
124 | *
125 | * All values are expected to be of type INT32.
126 | * Fractional constants are scaled left by CONST_BITS bits.
127 | * CONST_BITS is defined within each module using these macros,
128 | * and may differ from one module to the next.
129 | */
130 |
131 | #define ONE ((INT32) 1)
132 | #define CONST_SCALE (ONE << CONST_BITS)
133 |
134 | /* Convert a positive real constant to an integer scaled by CONST_SCALE.
135 | * Caution: some C compilers fail to reduce "FIX(constant)" at compile time,
136 | * thus causing a lot of useless floating-point operations at run time.
137 | */
138 |
139 | #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
140 |
141 | /* Descale and correctly round an INT32 value that's scaled by N bits.
142 | * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
143 | * the fudge factor is correct for either sign of X.
144 | */
145 |
146 | #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
147 |
148 | /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
149 | * This macro is used only when the two inputs will actually be no more than
150 | * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a
151 | * full 32x32 multiply. This provides a useful speedup on many machines.
152 | * Unfortunately there is no way to specify a 16x16->32 multiply portably
153 | * in C, but some C compilers will do the right thing if you provide the
154 | * correct combination of casts.
155 | */
156 |
157 | #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
158 | #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
159 | #endif
160 | #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
161 | #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
162 | #endif
163 |
164 | #ifndef MULTIPLY16C16 /* default definition */
165 | #define MULTIPLY16C16(var,const) ((var) * (const))
166 | #endif
167 |
168 | /* Same except both inputs are variables. */
169 |
170 | #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
171 | #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
172 | #endif
173 |
174 | #ifndef MULTIPLY16V16 /* default definition */
175 | #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
176 | #endif
177 |
--------------------------------------------------------------------------------
/jpeg6/jdtrans.c:
--------------------------------------------------------------------------------
1 | /*
2 | * jdtrans.c
3 | *
4 | * Copyright (C) 1995, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This file contains library routines for transcoding decompression,
9 | * that is, reading raw DCT coefficient arrays from an input JPEG file.
10 | * The routines in jdapimin.c will also be needed by a transcoder.
11 | */
12 |
13 | #define JPEG_INTERNALS
14 | #include "jinclude.h"
15 | #include "jpeglib.h"
16 |
17 |
18 | /* Forward declarations */
19 | LOCAL void transdecode_master_selection JPP((j_decompress_ptr cinfo));
20 |
21 |
22 | /*
23 | * Read the coefficient arrays from a JPEG file.
24 | * jpeg_read_header must be completed before calling this.
25 | *
26 | * The entire image is read into a set of virtual coefficient-block arrays,
27 | * one per component. The return value is a pointer to the array of
28 | * virtual-array descriptors. These can be manipulated directly via the
29 | * JPEG memory manager, or handed off to jpeg_write_coefficients().
30 | * To release the memory occupied by the virtual arrays, call
31 | * jpeg_finish_decompress() when done with the data.
32 | *
33 | * Returns NULL if suspended. This case need be checked only if
34 | * a suspending data source is used.
35 | */
36 |
37 | GLOBAL jvirt_barray_ptr *
38 | jpeg_read_coefficients (j_decompress_ptr cinfo)
39 | {
40 | if (cinfo->global_state == DSTATE_READY) {
41 | /* First call: initialize active modules */
42 | transdecode_master_selection(cinfo);
43 | cinfo->global_state = DSTATE_RDCOEFS;
44 | } else if (cinfo->global_state != DSTATE_RDCOEFS)
45 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
46 | /* Absorb whole file into the coef buffer */
47 | for (;;) {
48 | int retcode;
49 | /* Call progress monitor hook if present */
50 | if (cinfo->progress != NULL)
51 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
52 | /* Absorb some more input */
53 | retcode = (*cinfo->inputctl->consume_input) (cinfo);
54 | if (retcode == JPEG_SUSPENDED)
55 | return NULL;
56 | if (retcode == JPEG_REACHED_EOI)
57 | break;
58 | /* Advance progress counter if appropriate */
59 | if (cinfo->progress != NULL &&
60 | (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
61 | if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
62 | /* startup underestimated number of scans; ratchet up one scan */
63 | cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
64 | }
65 | }
66 | }
67 | /* Set state so that jpeg_finish_decompress does the right thing */
68 | cinfo->global_state = DSTATE_STOPPING;
69 | return cinfo->coef->coef_arrays;
70 | }
71 |
72 |
73 | /*
74 | * Master selection of decompression modules for transcoding.
75 | * This substitutes for jdmaster.c's initialization of the full decompressor.
76 | */
77 |
78 | LOCAL void
79 | transdecode_master_selection (j_decompress_ptr cinfo)
80 | {
81 | /* Entropy decoding: either Huffman or arithmetic coding. */
82 | if (cinfo->arith_code) {
83 | ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
84 | } else {
85 | if (cinfo->progressive_mode) {
86 | #ifdef D_PROGRESSIVE_SUPPORTED
87 | jinit_phuff_decoder(cinfo);
88 | #else
89 | ERREXIT(cinfo, JERR_NOT_COMPILED);
90 | #endif
91 | } else
92 | jinit_huff_decoder(cinfo);
93 | }
94 |
95 | /* Always get a full-image coefficient buffer. */
96 | jinit_d_coef_controller(cinfo, TRUE);
97 |
98 | /* We can now tell the memory manager to allocate virtual arrays. */
99 | (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
100 |
101 | /* Initialize input side of decompressor to consume first scan. */
102 | (*cinfo->inputctl->start_input_pass) (cinfo);
103 |
104 | /* Initialize progress monitoring. */
105 | if (cinfo->progress != NULL) {
106 | int nscans;
107 | /* Estimate number of scans to set pass_limit. */
108 | if (cinfo->progressive_mode) {
109 | /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
110 | nscans = 2 + 3 * cinfo->num_components;
111 | } else if (cinfo->inputctl->has_multiple_scans) {
112 | /* For a nonprogressive multiscan file, estimate 1 scan per component. */
113 | nscans = cinfo->num_components;
114 | } else {
115 | nscans = 1;
116 | }
117 | cinfo->progress->pass_counter = 0L;
118 | cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
119 | cinfo->progress->completed_passes = 0;
120 | cinfo->progress->total_passes = 1;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/jpeg6/jerror.c:
--------------------------------------------------------------------------------
1 | /*
2 | * jerror.c
3 | *
4 | * Copyright (C) 1991-1994, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This file contains simple error-reporting and trace-message routines.
9 | * These are suitable for Unix-like systems and others where writing to
10 | * stderr is the right thing to do. Many applications will want to replace
11 | * some or all of these routines.
12 | *
13 | * These routines are used by both the compression and decompression code.
14 | */
15 |
16 | /* this is not a core library module, so it doesn't define JPEG_INTERNALS */
17 | #include "jinclude.h"
18 | #include "jpeglib.h"
19 | #include "jversion.h"
20 | #include "jerror.h"
21 |
22 |
23 | #ifndef EXIT_FAILURE /* define exit() codes if not provided */
24 | #define EXIT_FAILURE 1
25 | #endif
26 |
27 |
28 | /*
29 | * Create the message string table.
30 | * We do this from the master message list in jerror.h by re-reading
31 | * jerror.h with a suitable definition for macro JMESSAGE.
32 | * The message table is made an external symbol just in case any applications
33 | * want to refer to it directly.
34 | */
35 |
36 | #ifdef NEED_SHORT_EXTERNAL_NAMES
37 | #define jpeg_std_message_table jMsgTable
38 | #endif
39 |
40 | #define JMESSAGE(code,string) string ,
41 |
42 | const char * const jpeg_std_message_table[] = {
43 | #include "jerror.h"
44 | NULL
45 | };
46 |
47 |
48 | /*
49 | * Error exit handler: must not return to caller.
50 | *
51 | * Applications may override this if they want to get control back after
52 | * an error. Typically one would longjmp somewhere instead of exiting.
53 | * The setjmp buffer can be made a private field within an expanded error
54 | * handler object. Note that the info needed to generate an error message
55 | * is stored in the error object, so you can generate the message now or
56 | * later, at your convenience.
57 | * You should make sure that the JPEG object is cleaned up (with jpeg_abort
58 | * or jpeg_destroy) at some point.
59 | */
60 |
61 | METHODDEF void
62 | error_exit (j_common_ptr cinfo)
63 | {
64 | char buffer[JMSG_LENGTH_MAX];
65 |
66 | /* Create the message */
67 | (*cinfo->err->format_message) (cinfo, buffer);
68 |
69 | /* Let the memory manager delete any temp files before we die */
70 | jpeg_destroy(cinfo);
71 |
72 | // -slc
73 | #if 0
74 | ri.Error( ERR_FATAL, "%s\n", buffer );
75 | #else
76 | ERROR_STRING_NO_RETURN(buffer);
77 | #endif
78 | }
79 |
80 | /*
81 | * Actual output of an error or trace message.
82 | * Applications may override this method to send JPEG messages somewhere
83 | * other than stderr.
84 | */
85 |
86 | METHODDEF void
87 | output_message (j_common_ptr cinfo)
88 | {
89 | char buffer[JMSG_LENGTH_MAX];
90 |
91 | /* Create the message */
92 | (*cinfo->err->format_message) (cinfo, buffer);
93 |
94 | // -slc
95 | #if 0
96 | /* Send it to stderr, adding a newline */
97 | ri.Printf(PRINT_ALL, "%s\n", buffer);
98 | #else
99 | MESSAGE_STRING(buffer);
100 | #endif
101 | }
102 |
103 |
104 | /*
105 | * Decide whether to emit a trace or warning message.
106 | * msg_level is one of:
107 | * -1: recoverable corrupt-data warning, may want to abort.
108 | * 0: important advisory messages (always display to user).
109 | * 1: first level of tracing detail.
110 | * 2,3,...: successively more detailed tracing messages.
111 | * An application might override this method if it wanted to abort on warnings
112 | * or change the policy about which messages to display.
113 | */
114 |
115 | METHODDEF void
116 | emit_message (j_common_ptr cinfo, int msg_level)
117 | {
118 | struct jpeg_error_mgr * err = cinfo->err;
119 |
120 | if (msg_level < 0) {
121 | /* It's a warning message. Since corrupt files may generate many warnings,
122 | * the policy implemented here is to show only the first warning,
123 | * unless trace_level >= 3.
124 | */
125 | if (err->num_warnings == 0 || err->trace_level >= 3)
126 | (*err->output_message) (cinfo);
127 | /* Always count warnings in num_warnings. */
128 | err->num_warnings++;
129 | } else {
130 | /* It's a trace message. Show it if trace_level >= msg_level. */
131 | if (err->trace_level >= msg_level)
132 | (*err->output_message) (cinfo);
133 | }
134 | }
135 |
136 |
137 | /*
138 | * Format a message string for the most recent JPEG error or message.
139 | * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
140 | * characters. Note that no '\n' character is added to the string.
141 | * Few applications should need to override this method.
142 | */
143 |
144 | METHODDEF void
145 | format_message (j_common_ptr cinfo, char * buffer)
146 | {
147 | struct jpeg_error_mgr * err = cinfo->err;
148 | int msg_code = err->msg_code;
149 | const char * msgtext = NULL;
150 | const char * msgptr;
151 | char ch;
152 | boolean isstring;
153 |
154 | /* Look up message string in proper table */
155 | if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
156 | msgtext = err->jpeg_message_table[msg_code];
157 | } else if (err->addon_message_table != NULL &&
158 | msg_code >= err->first_addon_message &&
159 | msg_code <= err->last_addon_message) {
160 | msgtext = err->addon_message_table[msg_code - err->first_addon_message];
161 | }
162 |
163 | /* Defend against bogus message number */
164 | if (msgtext == NULL) {
165 | err->msg_parm.i[0] = msg_code;
166 | msgtext = err->jpeg_message_table[0];
167 | }
168 |
169 | /* Check for string parameter, as indicated by %s in the message text */
170 | isstring = FALSE;
171 | msgptr = msgtext;
172 | while ((ch = *msgptr++) != '\0') {
173 | if (ch == '%') {
174 | if (*msgptr == 's') isstring = TRUE;
175 | break;
176 | }
177 | }
178 |
179 | /* Format the message into the passed buffer */
180 | if (isstring)
181 | sprintf(buffer, msgtext, err->msg_parm.s);
182 | else
183 | sprintf(buffer, msgtext,
184 | err->msg_parm.i[0], err->msg_parm.i[1],
185 | err->msg_parm.i[2], err->msg_parm.i[3],
186 | err->msg_parm.i[4], err->msg_parm.i[5],
187 | err->msg_parm.i[6], err->msg_parm.i[7]);
188 | }
189 |
190 |
191 | /*
192 | * Reset error state variables at start of a new image.
193 | * This is called during compression startup to reset trace/error
194 | * processing to default state, without losing any application-specific
195 | * method pointers. An application might possibly want to override
196 | * this method if it has additional error processing state.
197 | */
198 |
199 | METHODDEF void
200 | reset_error_mgr (j_common_ptr cinfo)
201 | {
202 | cinfo->err->num_warnings = 0;
203 | /* trace_level is not reset since it is an application-supplied parameter */
204 | cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
205 | }
206 |
207 |
208 | /*
209 | * Fill in the standard error-handling methods in a jpeg_error_mgr object.
210 | * Typical call is:
211 | * struct jpeg_compress_struct cinfo;
212 | * struct jpeg_error_mgr err;
213 | *
214 | * cinfo.err = jpeg_std_error(&err);
215 | * after which the application may override some of the methods.
216 | */
217 |
218 | GLOBAL struct jpeg_error_mgr *
219 | jpeg_std_error (struct jpeg_error_mgr * err)
220 | {
221 | err->error_exit = error_exit;
222 | err->emit_message = emit_message;
223 | err->output_message = output_message;
224 | err->format_message = format_message;
225 | err->reset_error_mgr = reset_error_mgr;
226 |
227 | err->trace_level = 0; /* default = no tracing */
228 | err->num_warnings = 0; /* no warnings emitted yet */
229 | err->msg_code = 0; /* may be useful as a flag for "no error" */
230 |
231 | /* Initialize message table pointers */
232 | err->jpeg_message_table = jpeg_std_message_table;
233 | err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
234 |
235 | err->addon_message_table = NULL;
236 | err->first_addon_message = 0; /* for safety */
237 | err->last_addon_message = 0;
238 |
239 | return err;
240 | }
241 |
--------------------------------------------------------------------------------
/jpeg6/jinclude.h:
--------------------------------------------------------------------------------
1 | /*
2 | * jinclude.h
3 | *
4 | * Copyright (C) 1991-1994, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This file exists to provide a single place to fix any problems with
9 | * including the wrong system include files. (Common problems are taken
10 | * care of by the standard jconfig symbols, but on really weird systems
11 | * you may have to edit this file.)
12 | *
13 | * NOTE: this file is NOT intended to be included by applications using the
14 | * JPEG library. Most applications need only include jpeglib.h.
15 | */
16 |
17 |
18 | #ifdef __cplusplus
19 | extern "C"
20 | {
21 | #endif
22 |
23 |
24 |
25 |
26 | /* Include auto-config file to find out which system include files we need. */
27 |
28 | #include "jconfig.h" /* auto configuration options */
29 | #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
30 |
31 | /*
32 | * We need the NULL macro and size_t typedef.
33 | * On an ANSI-conforming system it is sufficient to include .
34 | * Otherwise, we get them from or ; we may have to
35 | * pull in as well.
36 | * Note that the core JPEG library does not require ;
37 | * only the default error handler and data source/destination modules do.
38 | * But we must pull it in because of the references to FILE in jpeglib.h.
39 | * You can remove those references if you want to compile without .
40 | */
41 |
42 | #ifdef HAVE_STDDEF_H
43 | #include
44 | #endif
45 |
46 | #ifdef HAVE_STDLIB_H
47 | #include
48 | #endif
49 |
50 | #ifdef NEED_SYS_TYPES_H
51 | #include
52 | #endif
53 |
54 | #include
55 |
56 | /*
57 | * We need memory copying and zeroing functions, plus strncpy().
58 | * ANSI and System V implementations declare these in .
59 | * BSD doesn't have the mem() functions, but it does have bcopy()/bzero().
60 | * Some systems may declare memset and memcpy in .
61 | *
62 | * NOTE: we assume the size parameters to these functions are of type size_t.
63 | * Change the casts in these macros if not!
64 | */
65 |
66 | #ifdef NEED_BSD_STRINGS
67 |
68 | #include
69 | #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
70 | #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
71 |
72 | #else /* not BSD, assume ANSI/SysV string lib */
73 |
74 | #include
75 | #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
76 | #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
77 |
78 | #endif
79 |
80 | /*
81 | * In ANSI C, and indeed any rational implementation, size_t is also the
82 | * type returned by sizeof(). However, it seems there are some irrational
83 | * implementations out there, in which sizeof() returns an int even though
84 | * size_t is defined as long or unsigned long. To ensure consistent results
85 | * we always use this SIZEOF() macro in place of using sizeof() directly.
86 | */
87 |
88 | #define SIZEOF(object) ((size_t) sizeof(object))
89 |
90 | /*
91 | * The modules that use fread() and fwrite() always invoke them through
92 | * these macros. On some systems you may need to twiddle the argument casts.
93 | * CAUTION: argument order is different from underlying functions!
94 | */
95 |
96 | #define JFREAD(file,buf,sizeofbuf) \
97 | ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
98 | #define JFWRITE(file,buf,sizeofbuf) \
99 | ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
100 |
101 |
102 | #ifdef __cplusplus
103 | };
104 | #endif
105 |
106 |
--------------------------------------------------------------------------------
/jpeg6/jmemnobs.c:
--------------------------------------------------------------------------------
1 | /*
2 | * jmemnobs.c
3 | *
4 | * Copyright (C) 1992-1994, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This file provides a really simple implementation of the system-
9 | * dependent portion of the JPEG memory manager. This implementation
10 | * assumes that no backing-store files are needed: all required space
11 | * can be obtained from ri.Malloc().
12 | * This is very portable in the sense that it'll compile on almost anything,
13 | * but you'd better have lots of main memory (or virtual memory) if you want
14 | * to process big images.
15 | * Note that the max_memory_to_use option is ignored by this implementation.
16 | */
17 |
18 | #define JPEG_INTERNALS
19 | #include "jinclude.h"
20 | #include "jpeglib.h"
21 | #include "jmemsys.h" /* import the system-dependent declarations */
22 |
23 | /*
24 | * Memory allocation and ri.Freeing are controlled by the regular library
25 | * routines ri.Malloc() and ri.Free().
26 | */
27 |
28 | GLOBAL void *
29 | jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
30 | {
31 | // -slc
32 | #if 0
33 | return (void *) ri.Malloc(sizeofobject);
34 | #else
35 | return JPG_Malloc(sizeofobject);
36 | #endif
37 | }
38 |
39 | GLOBAL void
40 | jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
41 | {
42 | // -slc
43 | #if 0
44 | ri.Free(object);
45 | #else
46 | JPG_Free(object);
47 | #endif
48 | }
49 |
50 |
51 | /*
52 | * "Large" objects are treated the same as "small" ones.
53 | * NB: although we include FAR keywords in the routine declarations,
54 | * this file won't actually work in 80x86 small/medium model; at least,
55 | * you probably won't be able to process useful-size images in only 64KB.
56 | */
57 |
58 | GLOBAL void FAR *
59 | jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
60 | {
61 | // -slc
62 | #if 0
63 | return (void FAR *) ri.Malloc(sizeofobject);
64 | #else
65 | return JPG_Malloc(sizeofobject);
66 | #endif
67 | }
68 |
69 | GLOBAL void
70 | jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
71 | {
72 | // -slc
73 | #if 0
74 | ri.Free(object);
75 | #else
76 | JPG_Free(object);
77 | #endif
78 | }
79 |
80 |
81 | /*
82 | * This routine computes the total memory space available for allocation.
83 | * Here we always say, "we got all you want bud!"
84 | */
85 |
86 | GLOBAL long
87 | jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
88 | long max_bytes_needed, long already_allocated)
89 | {
90 | return max_bytes_needed;
91 | }
92 |
93 |
94 | /*
95 | * Backing store (temporary file) management.
96 | * Since jpeg_mem_available always promised the moon,
97 | * this should never be called and we can just error out.
98 | */
99 |
100 | GLOBAL void
101 | jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
102 | long total_bytes_needed)
103 | {
104 | ERREXIT(cinfo, JERR_NO_BACKING_STORE);
105 | }
106 |
107 |
108 | /*
109 | * These routines take care of any system-dependent initialization and
110 | * cleanup required. Here, there isn't any.
111 | */
112 |
113 | GLOBAL long
114 | jpeg_mem_init (j_common_ptr cinfo)
115 | {
116 | return 0; /* just set max_memory_to_use to 0 */
117 | }
118 |
119 | GLOBAL void
120 | jpeg_mem_term (j_common_ptr cinfo)
121 | {
122 | /* no work */
123 | }
124 |
--------------------------------------------------------------------------------
/jpeg6/jmemsys.h:
--------------------------------------------------------------------------------
1 | /*
2 | * jmemsys.h
3 | *
4 | * Copyright (C) 1992-1994, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This include file defines the interface between the system-independent
9 | * and system-dependent portions of the JPEG memory manager. No other
10 | * modules need include it. (The system-independent portion is jmemmgr.c;
11 | * there are several different versions of the system-dependent portion.)
12 | *
13 | * This file works as-is for the system-dependent memory managers supplied
14 | * in the IJG distribution. You may need to modify it if you write a
15 | * custom memory manager. If system-dependent changes are needed in
16 | * this file, the best method is to #ifdef them based on a configuration
17 | * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR.
18 | */
19 |
20 |
21 | /* Short forms of external names for systems with brain-damaged linkers. */
22 |
23 | #ifdef NEED_SHORT_EXTERNAL_NAMES
24 | #define jpeg_get_small jGetSmall
25 | #define jpeg_free_small jFreeSmall
26 | #define jpeg_get_large jGetLarge
27 | #define jpeg_free_large jFreeLarge
28 | #define jpeg_mem_available jMemAvail
29 | #define jpeg_open_backing_store jOpenBackStore
30 | #define jpeg_mem_init jMemInit
31 | #define jpeg_mem_term jMemTerm
32 | #endif /* NEED_SHORT_EXTERNAL_NAMES */
33 |
34 |
35 | /*
36 | * These two functions are used to allocate and release small chunks of
37 | * memory. (Typically the total amount requested through jpeg_get_small is
38 | * no more than 20K or so; this will be requested in chunks of a few K each.)
39 | * Behavior should be the same as for the standard library functions malloc
40 | * and free; in particular, jpeg_get_small must return NULL on failure.
41 | * On most systems, these ARE malloc and free. jpeg_free_small is passed the
42 | * size of the object being freed, just in case it's needed.
43 | * On an 80x86 machine using small-data memory model, these manage near heap.
44 | */
45 |
46 | EXTERN void * jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
47 | EXTERN void jpeg_free_small JPP((j_common_ptr cinfo, void * object,
48 | size_t sizeofobject));
49 |
50 | /*
51 | * These two functions are used to allocate and release large chunks of
52 | * memory (up to the total free space designated by jpeg_mem_available).
53 | * The interface is the same as above, except that on an 80x86 machine,
54 | * far pointers are used. On most other machines these are identical to
55 | * the jpeg_get/free_small routines; but we keep them separate anyway,
56 | * in case a different allocation strategy is desirable for large chunks.
57 | */
58 |
59 | EXTERN void FAR * jpeg_get_large JPP((j_common_ptr cinfo,size_t sizeofobject));
60 | EXTERN void jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
61 | size_t sizeofobject));
62 |
63 | /*
64 | * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
65 | * be requested in a single call to jpeg_get_large (and jpeg_get_small for that
66 | * matter, but that case should never come into play). This macro is needed
67 | * to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
68 | * On those machines, we expect that jconfig.h will provide a proper value.
69 | * On machines with 32-bit flat address spaces, any large constant may be used.
70 | *
71 | * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
72 | * size_t and will be a multiple of sizeof(align_type).
73 | */
74 |
75 | #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
76 | #define MAX_ALLOC_CHUNK 1000000000L
77 | #endif
78 |
79 | /*
80 | * This routine computes the total space still available for allocation by
81 | * jpeg_get_large. If more space than this is needed, backing store will be
82 | * used. NOTE: any memory already allocated must not be counted.
83 | *
84 | * There is a minimum space requirement, corresponding to the minimum
85 | * feasible buffer sizes; jmemmgr.c will request that much space even if
86 | * jpeg_mem_available returns zero. The maximum space needed, enough to hold
87 | * all working storage in memory, is also passed in case it is useful.
88 | * Finally, the total space already allocated is passed. If no better
89 | * method is available, cinfo->mem->max_memory_to_use - already_allocated
90 | * is often a suitable calculation.
91 | *
92 | * It is OK for jpeg_mem_available to underestimate the space available
93 | * (that'll just lead to more backing-store access than is really necessary).
94 | * However, an overestimate will lead to failure. Hence it's wise to subtract
95 | * a slop factor from the true available space. 5% should be enough.
96 | *
97 | * On machines with lots of virtual memory, any large constant may be returned.
98 | * Conversely, zero may be returned to always use the minimum amount of memory.
99 | */
100 |
101 | EXTERN long jpeg_mem_available JPP((j_common_ptr cinfo,
102 | long min_bytes_needed,
103 | long max_bytes_needed,
104 | long already_allocated));
105 |
106 |
107 | /*
108 | * This structure holds whatever state is needed to access a single
109 | * backing-store object. The read/write/close method pointers are called
110 | * by jmemmgr.c to manipulate the backing-store object; all other fields
111 | * are private to the system-dependent backing store routines.
112 | */
113 |
114 | #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
115 |
116 | #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
117 |
118 | typedef unsigned short XMSH; /* type of extended-memory handles */
119 | typedef unsigned short EMSH; /* type of expanded-memory handles */
120 |
121 | typedef union {
122 | short file_handle; /* DOS file handle if it's a temp file */
123 | XMSH xms_handle; /* handle if it's a chunk of XMS */
124 | EMSH ems_handle; /* handle if it's a chunk of EMS */
125 | } handle_union;
126 |
127 | #endif /* USE_MSDOS_MEMMGR */
128 |
129 | typedef struct backing_store_struct * backing_store_ptr;
130 |
131 | typedef struct backing_store_struct {
132 | /* Methods for reading/writing/closing this backing-store object */
133 | JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
134 | backing_store_ptr info,
135 | void FAR * buffer_address,
136 | long file_offset, long byte_count));
137 | JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
138 | backing_store_ptr info,
139 | void FAR * buffer_address,
140 | long file_offset, long byte_count));
141 | JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
142 | backing_store_ptr info));
143 |
144 | /* Private fields for system-dependent backing-store management */
145 | #ifdef USE_MSDOS_MEMMGR
146 | /* For the MS-DOS manager (jmemdos.c), we need: */
147 | handle_union handle; /* reference to backing-store storage object */
148 | char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
149 | #else
150 | /* For a typical implementation with temp files, we need: */
151 | FILE * temp_file; /* stdio reference to temp file */
152 | char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
153 | #endif
154 | } backing_store_info;
155 |
156 | /*
157 | * Initial opening of a backing-store object. This must fill in the
158 | * read/write/close pointers in the object. The read/write routines
159 | * may take an error exit if the specified maximum file size is exceeded.
160 | * (If jpeg_mem_available always returns a large value, this routine can
161 | * just take an error exit.)
162 | */
163 |
164 | EXTERN void jpeg_open_backing_store JPP((j_common_ptr cinfo,
165 | backing_store_ptr info,
166 | long total_bytes_needed));
167 |
168 |
169 | /*
170 | * These routines take care of any system-dependent initialization and
171 | * cleanup required. jpeg_mem_init will be called before anything is
172 | * allocated (and, therefore, nothing in cinfo is of use except the error
173 | * manager pointer). It should return a suitable default value for
174 | * max_memory_to_use; this may subsequently be overridden by the surrounding
175 | * application. (Note that max_memory_to_use is only important if
176 | * jpeg_mem_available chooses to consult it ... no one else will.)
177 | * jpeg_mem_term may assume that all requested memory has been freed and that
178 | * all opened backing-store objects have been closed.
179 | */
180 |
181 | EXTERN long jpeg_mem_init JPP((j_common_ptr cinfo));
182 | EXTERN void jpeg_mem_term JPP((j_common_ptr cinfo));
183 |
--------------------------------------------------------------------------------
/jpeg6/jutils.c:
--------------------------------------------------------------------------------
1 | /*
2 | * jutils.c
3 | *
4 | * Copyright (C) 1991-1995, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This file contains tables and miscellaneous utility routines needed
9 | * for both compression and decompression.
10 | * Note we prefix all global names with "j" to minimize conflicts with
11 | * a surrounding application.
12 | */
13 |
14 | #define JPEG_INTERNALS
15 | #include "jinclude.h"
16 | #include "jpeglib.h"
17 |
18 |
19 | /*
20 | * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element
21 | * of a DCT block read in natural order (left to right, top to bottom).
22 | */
23 |
24 | const int jpeg_zigzag_order[DCTSIZE2] = {
25 | 0, 1, 5, 6, 14, 15, 27, 28,
26 | 2, 4, 7, 13, 16, 26, 29, 42,
27 | 3, 8, 12, 17, 25, 30, 41, 43,
28 | 9, 11, 18, 24, 31, 40, 44, 53,
29 | 10, 19, 23, 32, 39, 45, 52, 54,
30 | 20, 22, 33, 38, 46, 51, 55, 60,
31 | 21, 34, 37, 47, 50, 56, 59, 61,
32 | 35, 36, 48, 49, 57, 58, 62, 63
33 | };
34 |
35 | /*
36 | * jpeg_natural_order[i] is the natural-order position of the i'th element
37 | * of zigzag order.
38 | *
39 | * When reading corrupted data, the Huffman decoders could attempt
40 | * to reference an entry beyond the end of this array (if the decoded
41 | * zero run length reaches past the end of the block). To prevent
42 | * wild stores without adding an inner-loop test, we put some extra
43 | * "63"s after the real entries. This will cause the extra coefficient
44 | * to be stored in location 63 of the block, not somewhere random.
45 | * The worst case would be a run-length of 15, which means we need 16
46 | * fake entries.
47 | */
48 |
49 | const int jpeg_natural_order[DCTSIZE2+16] = {
50 | 0, 1, 8, 16, 9, 2, 3, 10,
51 | 17, 24, 32, 25, 18, 11, 4, 5,
52 | 12, 19, 26, 33, 40, 48, 41, 34,
53 | 27, 20, 13, 6, 7, 14, 21, 28,
54 | 35, 42, 49, 56, 57, 50, 43, 36,
55 | 29, 22, 15, 23, 30, 37, 44, 51,
56 | 58, 59, 52, 45, 38, 31, 39, 46,
57 | 53, 60, 61, 54, 47, 55, 62, 63,
58 | 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
59 | 63, 63, 63, 63, 63, 63, 63, 63
60 | };
61 |
62 |
63 | /*
64 | * Arithmetic utilities
65 | */
66 |
67 | GLOBAL long
68 | jdiv_round_up (long a, long b)
69 | /* Compute a/b rounded up to next integer, ie, ceil(a/b) */
70 | /* Assumes a >= 0, b > 0 */
71 | {
72 | return (a + b - 1L) / b;
73 | }
74 |
75 |
76 | GLOBAL long
77 | jround_up (long a, long b)
78 | /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
79 | /* Assumes a >= 0, b > 0 */
80 | {
81 | a += b - 1L;
82 | return a - (a % b);
83 | }
84 |
85 |
86 | /* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
87 | * and coefficient-block arrays. This won't work on 80x86 because the arrays
88 | * are FAR and we're assuming a small-pointer memory model. However, some
89 | * DOS compilers provide far-pointer versions of memcpy() and memset() even
90 | * in the small-model libraries. These will be used if USE_FMEM is defined.
91 | * Otherwise, the routines below do it the hard way. (The performance cost
92 | * is not all that great, because these routines aren't very heavily used.)
93 | */
94 |
95 | #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
96 | #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
97 | #define FMEMZERO(target,size) MEMZERO(target,size)
98 | #else /* 80x86 case, define if we can */
99 | #ifdef USE_FMEM
100 | #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
101 | #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
102 | #endif
103 | #endif
104 |
105 |
106 | GLOBAL void
107 | jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
108 | JSAMPARRAY output_array, int dest_row,
109 | int num_rows, JDIMENSION num_cols)
110 | /* Copy some rows of samples from one place to another.
111 | * num_rows rows are copied from input_array[source_row++]
112 | * to output_array[dest_row++]; these areas may overlap for duplication.
113 | * The source and destination arrays must be at least as wide as num_cols.
114 | */
115 | {
116 | register JSAMPROW inptr, outptr;
117 | #ifdef FMEMCOPY
118 | register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
119 | #else
120 | register JDIMENSION count;
121 | #endif
122 | register int row;
123 |
124 | input_array += source_row;
125 | output_array += dest_row;
126 |
127 | for (row = num_rows; row > 0; row--) {
128 | inptr = *input_array++;
129 | outptr = *output_array++;
130 | #ifdef FMEMCOPY
131 | FMEMCOPY(outptr, inptr, count);
132 | #else
133 | for (count = num_cols; count > 0; count--)
134 | *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
135 | #endif
136 | }
137 | }
138 |
139 |
140 | GLOBAL void
141 | jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
142 | JDIMENSION num_blocks)
143 | /* Copy a row of coefficient blocks from one place to another. */
144 | {
145 | #ifdef FMEMCOPY
146 | FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
147 | #else
148 | register JCOEFPTR inptr, outptr;
149 | register long count;
150 |
151 | inptr = (JCOEFPTR) input_row;
152 | outptr = (JCOEFPTR) output_row;
153 | for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
154 | *outptr++ = *inptr++;
155 | }
156 | #endif
157 | }
158 |
159 |
160 | GLOBAL void
161 | jzero_far (void FAR * target, size_t bytestozero)
162 | /* Zero out a chunk of FAR memory. */
163 | /* This might be sample-array data, block-array data, or alloc_large data. */
164 | {
165 | #ifdef FMEMZERO
166 | FMEMZERO(target, bytestozero);
167 | #else
168 | register char FAR * ptr = (char FAR *) target;
169 | register size_t count;
170 |
171 | for (count = bytestozero; count > 0; count--) {
172 | *ptr++ = 0;
173 | }
174 | #endif
175 | }
176 |
--------------------------------------------------------------------------------
/jpeg6/jversion.h:
--------------------------------------------------------------------------------
1 | /*
2 | * jversion.h
3 | *
4 | * Copyright (C) 1991-1995, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This file contains software version identification.
9 | */
10 |
11 |
12 | #define JVERSION "6 2-Aug-95"
13 |
14 | #define JCOPYRIGHT "Copyright (C) 1995, Thomas G. Lane"
15 |
--------------------------------------------------------------------------------
/jpeg_interface.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "system.h"
3 | #include "oddbits.h"
4 | //#include "tr_local.h"
5 | #include "jpeg_interface.h"
6 |
7 | #include "jpeg6\jpeglib.h"
8 |
9 | void LoadJPG( const char *filename, unsigned char **pic, int *width, int *height )
10 | {
11 | *pic = NULL;
12 |
13 | // static char sTEMP[]="Q:\\quake\\baseq3\\menu\\common\\cursor.jpg";
14 | // filename = sTEMP;
15 |
16 | /* This struct contains the JPEG decompression parameters and pointers to
17 | * working space (which is allocated as needed by the JPEG library).
18 | */
19 | struct jpeg_decompress_struct cinfo;
20 | /* We use our private extension JPEG error handler.
21 | * Note that this struct must live as long as the main JPEG parameter
22 | * struct, to avoid dangling-pointer problems.
23 | */
24 | /* This struct represents a JPEG error handler. It is declared separately
25 | * because applications often want to supply a specialized error handler
26 | * (see the second half of this file for an example). But here we just
27 | * take the easy way out and use the standard error handler, which will
28 | * print a message on stderr and call exit() if compression fails.
29 | * Note that this struct must live as long as the main JPEG parameter
30 | * struct, to avoid dangling-pointer problems.
31 | */
32 | struct jpeg_error_mgr jerr;
33 | /* More stuff */
34 | JSAMPARRAY buffer; /* Output row buffer */
35 | int row_stride; /* physical row width in output buffer */
36 | unsigned char *out;
37 | byte *fbuffer;
38 | byte *bbuf;
39 |
40 | /* In this example we want to open the input file before doing anything else,
41 | * so that the setjmp() error recovery below can assume the file is open.
42 | * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
43 | * requires it in order to read binary files.
44 | */
45 |
46 | LoadFile (filename, (void **)&fbuffer);
47 | // ri.FS_ReadFile ( ( char * ) filename, (void **)&fbuffer);
48 | if (!fbuffer)
49 | return;
50 |
51 |
52 | try
53 | {
54 |
55 | /* Step 1: allocate and initialize JPEG decompression object */
56 |
57 | /* We have to set up the error handler first, in case the initialization
58 | * step fails. (Unlikely, but it could happen if you are out of memory.)
59 | * This routine fills in the contents of struct jerr, and returns jerr's
60 | * address which we place into the link field in cinfo.
61 | */
62 | cinfo.err = jpeg_std_error(&jerr);
63 |
64 | /* Now we can initialize the JPEG decompression object. */
65 | jpeg_create_decompress(&cinfo);
66 |
67 | /* Step 2: specify data source (eg, a file) */
68 |
69 | jpeg_stdio_src(&cinfo, fbuffer);
70 |
71 | /* Step 3: read file parameters with jpeg_read_header() */
72 |
73 | (void) jpeg_read_header(&cinfo, TRUE);
74 | /* We can ignore the return value from jpeg_read_header since
75 | * (a) suspension is not possible with the stdio data source, and
76 | * (b) we passed TRUE to reject a tables-only JPEG file as an error.
77 | * See libjpeg.doc for more info.
78 | */
79 |
80 | /* Step 4: set parameters for decompression */
81 |
82 | /* In this example, we don't need to change any of the defaults set by
83 | * jpeg_read_header(), so we do nothing here.
84 | */
85 |
86 | /* Step 5: Start decompressor */
87 |
88 | (void) jpeg_start_decompress(&cinfo);
89 | /* We can ignore the return value since suspension is not possible
90 | * with the stdio data source.
91 | */
92 |
93 | /* We may need to do some setup of our own at this point before reading
94 | * the data. After jpeg_start_decompress() we have the correct scaled
95 | * output image dimensions available, as well as the output colormap
96 | * if we asked for color quantization.
97 | * In this example, we need to make an output work buffer of the right size.
98 | */
99 | /* JSAMPLEs per row in output buffer */
100 | row_stride = cinfo.output_width * cinfo.output_components;
101 |
102 | if (cinfo.output_components!=4 && cinfo.output_components!=1 )
103 | {
104 | WarningBox(va("JPG %s is unsupported color depth (%d)", filename, cinfo.output_components));
105 | }
106 |
107 | out = (byte *) malloc(cinfo.output_width*cinfo.output_height*4);
108 |
109 | *pic = out;
110 | *width = cinfo.output_width;
111 | *height = cinfo.output_height;
112 |
113 | /* Step 6: while (scan lines remain to be read) */
114 | /* jpeg_read_scanlines(...); */
115 |
116 | /* Here we use the library's state variable cinfo.output_scanline as the
117 | * loop counter, so that we don't have to keep track ourselves.
118 | */
119 | while (cinfo.output_scanline < cinfo.output_height) {
120 | /* jpeg_read_scanlines expects an array of pointers to scanlines.
121 | * Here the array is only one element long, but you could ask for
122 | * more than one scanline at a time if that's more convenient.
123 | */
124 | bbuf = ((out+(row_stride*cinfo.output_scanline)));
125 | buffer = &bbuf;
126 | (void) jpeg_read_scanlines(&cinfo, buffer, 1);
127 | }
128 |
129 | // if we've just loaded a greyscale, then adjust it from 8-bit to 32bit by stretch-copying it over itself...
130 | // (this also does the alpha stuff as well)
131 | //
132 | if (cinfo.output_components == 1)
133 | {
134 | byte *pbDest = (*pic + (cinfo.output_width * cinfo.output_height * 4))-1;
135 | byte *pbSrc = (*pic + (cinfo.output_width * cinfo.output_height ))-1;
136 | int iPixels = cinfo.output_width * cinfo.output_height;
137 |
138 | for (int i=0; i.
16 |
17 | */
18 |
19 | #ifndef TR_JPEG_INTERFACE_H
20 | #define TR_JPEG_INTERFACE_H
21 |
22 |
23 | #ifdef __cplusplus
24 | extern "C"
25 | {
26 | #endif
27 |
28 |
29 | #ifndef LPCSTR
30 | typedef const char * LPCSTR;
31 | #endif
32 |
33 | void LoadJPG( const char *filename, unsigned char **pic, int *width, int *height );
34 |
35 | void JPG_ErrorThrow(LPCSTR message);
36 | void JPG_MessageOut(LPCSTR message);
37 | #define ERROR_STRING_NO_RETURN(message) JPG_ErrorThrow(message)
38 | #define MESSAGE_STRING(message) JPG_MessageOut(message)
39 |
40 |
41 | void *JPG_Malloc( int iSize );
42 | void JPG_Free( void *pvObject);
43 |
44 |
45 | #ifdef __cplusplus
46 | };
47 | #endif
48 |
49 |
50 |
51 | #endif // #ifndef TR_JPEG_INTERFACE_H
52 |
53 |
54 | ////////////////// eof //////////////////
55 |
56 |
--------------------------------------------------------------------------------
/matcomp.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifdef MODVIEW
20 | #include "stdafx.h"
21 | #endif
22 |
23 | #include
24 | #include
25 | #include
26 | #include // for memcpy
27 | //
28 | #include "MatComp.h"
29 |
30 |
31 | #define MC_MASK_X ((1<<(MC_BITS_X))-1)
32 | #define MC_MASK_Y ((1<<(MC_BITS_Y))-1)
33 | #define MC_MASK_Z ((1<<(MC_BITS_Z))-1)
34 | #define MC_MASK_VECT ((1<<(MC_BITS_VECT))-1)
35 |
36 | #define MC_SCALE_VECT (1.0f/(float)((1<<(MC_BITS_VECT-1))-2))
37 |
38 | #define MC_POS_X (0)
39 | #define MC_SHIFT_X (0)
40 |
41 | #define MC_POS_Y ((((MC_BITS_X))/8))
42 | #define MC_SHIFT_Y ((((MC_BITS_X)%8)))
43 |
44 | #define MC_POS_Z ((((MC_BITS_X+MC_BITS_Y))/8))
45 | #define MC_SHIFT_Z ((((MC_BITS_X+MC_BITS_Y)%8)))
46 |
47 | #define MC_POS_V11 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z))/8))
48 | #define MC_SHIFT_V11 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z)%8)))
49 |
50 | #define MC_POS_V12 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT))/8))
51 | #define MC_SHIFT_V12 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT)%8)))
52 |
53 | #define MC_POS_V13 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*2))/8))
54 | #define MC_SHIFT_V13 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*2)%8)))
55 |
56 | #define MC_POS_V21 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*3))/8))
57 | #define MC_SHIFT_V21 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*3)%8)))
58 |
59 | #define MC_POS_V22 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*4))/8))
60 | #define MC_SHIFT_V22 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*4)%8)))
61 |
62 | #define MC_POS_V23 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*5))/8))
63 | #define MC_SHIFT_V23 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*5)%8)))
64 |
65 | #define MC_POS_V31 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*6))/8))
66 | #define MC_SHIFT_V31 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*6)%8)))
67 |
68 | #define MC_POS_V32 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*7))/8))
69 | #define MC_SHIFT_V32 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*7)%8)))
70 |
71 | #define MC_POS_V33 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*8))/8))
72 | #define MC_SHIFT_V33 ((((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*8)%8)))
73 |
74 | void MC_Compress(const float mat[3][4],unsigned char * _comp)
75 | {
76 | char comp[MC_COMP_BYTES*2];
77 |
78 | int i,val;
79 | for (i=0;i=(1<=(1<=(1<=(1<=(1<=(1<=(1<=(1<=(1<=(1<=(1<=(1<.
16 |
17 | */
18 |
19 | #ifndef __MATCOMP__
20 | #define __MATCOMP__
21 |
22 | #ifdef __cplusplus
23 | extern "C"
24 | {
25 | #endif
26 |
27 |
28 | #if (defined _MODVIEW || defined _CARCASS)
29 | #include "special_defines.h"
30 | #endif
31 |
32 | #pragma optimize( "p", on ) // improve floating-point consistancy (makes release do bone-pooling as good as debug)
33 |
34 |
35 | #define MC_BITS_X (16)
36 | #define MC_BITS_Y (16)
37 | #define MC_BITS_Z (16)
38 | #define MC_BITS_VECT (16)
39 |
40 | #define MC_SCALE_X (1.0f/64)
41 | #define MC_SCALE_Y (1.0f/64)
42 | #define MC_SCALE_Z (1.0f/64)
43 |
44 |
45 | // pre-quat version
46 | //#define MC_COMP_BYTES (((MC_BITS_X+MC_BITS_Y+MC_BITS_Z+MC_BITS_VECT*9)+7)/8)
47 | //
48 | // quat version, this is gay to do this but hard to change
49 | #define MC_COMP_BYTES 14
50 |
51 | void MC_Compress(const float mat[3][4],unsigned char * comp);
52 | void MC_UnCompress(float mat[3][4],const unsigned char * comp);
53 |
54 | #ifdef __cplusplus
55 | }
56 | #endif
57 |
58 | #endif
--------------------------------------------------------------------------------
/matrix4.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #if !defined(MATRIX4_INC)
20 | #define MATRIX4_INC
21 |
22 | #include "vect3.h"
23 | #include
24 | #include
25 |
26 | #pragma warning( disable : 4244)
27 | #pragma optimize( "p", on ) // improve floating-point consistancy (makes release do bone-pooling as good as debug)
28 | extern const float Pi;
29 | extern const float Half_Pi;
30 |
31 |
32 | #define MATFLAG_IDENTITY (1)
33 | class Matrix4
34 | {
35 | float m[4][4];
36 | int flags;
37 | public:
38 | Matrix4() {flags=0;}
39 | Matrix4(const Matrix4 &o);
40 | float* operator[](int i) {return m[i];flags=0;}
41 | const float* operator[](int i) const {return m[i];}
42 | void SetElem(int r,int c,float v) {m[r][c]=v;flags=0;}
43 | const float &Elem(int r,int c) const {return m[r][c];}
44 | void SetFromMem(const float *mem) {memcpy(m,mem,sizeof(float)*16);CalcFlags();}
45 | void GetFromMem(float *mem) const {memcpy(mem,m,sizeof(float)*16);}
46 | void Identity();
47 | void Zero();
48 | bool IsRotationIdentity(void) const;
49 | bool IsRotationIdentityMoreTolerance(void) const;
50 | int CalcFlags();
51 | int GetFlags() const {return flags;}
52 | bool IntegrityCheck() const;
53 | void Translate(const float tx,const float ty,const float tz);
54 | void Translate(const Vect3 &t);
55 | void Rotate(int axis,const float theta);
56 | void Rotate(const float rx,const float ry,const float rz);
57 | void Rotate(const Vect3 v);
58 | void Scale(const float sx,const float sy,const float sz);
59 | void Scale(const float sx);
60 | void Concat(const Matrix4 &m1,const Matrix4 &m2);
61 | void Interp(const Matrix4 &m1,float s1,const Matrix4 &m2,float s2);
62 | void Interp(const Matrix4 &m1,const Matrix4 &m2,float s1);
63 | void XFormPoint(Vect3 &dest,const Vect3 &src) const;
64 | float HXFormPoint(Vect3 &dest,const Vect3 &src) const;
65 | void HXFormPointND(float *dest,const float *src) const;
66 | void XFormVect(Vect3 &dest,const Vect3 &src) const;
67 | void XFormVectTranspose(Vect3 &dest,const Vect3 &src) const;
68 | void SetRow(int i,const Vect3 &t);
69 | void SetColumn(int i,const Vect3 &t);
70 | void SetRow(int i);
71 | void SetColumn(int i);
72 | void SetFromDouble(double *d);
73 | void MultiplyColumn(int i,float f);
74 | float GetColumnLen(int i);
75 | void Inverse(const Matrix4 &old);
76 | void OrthoNormalInverse(const Matrix4 &old);
77 | void FindFromPoints(const Vect3 base1[4],const Vect3 base2[4]);
78 | void MakeEquiscalar();
79 | float Det();
80 | float MaxAbsElement();
81 | void GetRow(int r,Vect3 &v) const {v.x()=m[r][0];v.y()=m[r][1];v.z()=m[r][2];}
82 | void GetColumn(int r,Vect3 &v) const {v.x()=m[0][r];v.y()=m[1][r];v.z()=m[2][r];}
83 | void Transpose();
84 | bool operator== (const Matrix4& t) const;
85 | void From3x4(const float mat[3][4]);
86 | void To3x4(float mat[3][4]) const;
87 | void ClampPrecision(float fNumDecimals);
88 | };
89 |
90 |
91 | int GetTextureSystem(
92 | const Vect3 &p0,const Vect3 &uv0, //vertex 0
93 | const Vect3 &p1,const Vect3 &uv1, //vertex 1
94 | const Vect3 &p2,const Vect3 &uv2, //vertex 2
95 | const Vect3 &n, // normal vector for triangle
96 | Vect3 &M, // returned gradient wrt u
97 | Vect3 &N, // returned gradient wrt v
98 | Vect3 &P); // returned location in world space where u=v=0
99 |
100 |
101 | #endif
--------------------------------------------------------------------------------
/md3gl.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifndef _MD3_GL_H_
20 | #define _MD3_GL_H_
21 |
22 | #include "mdr.h"
23 |
24 | typedef struct
25 | {
26 | unsigned char *Data; // actual texture bitmap
27 | unsigned int Width, Height; // size of TextureData
28 | GLenum _Type; // type of texture ie. (not actually used)
29 | GLuint Bind; // id the texture is bound to
30 | char *File; // allocated string storing path name
31 | int numUsed;
32 | } TextureGL;
33 |
34 | typedef struct
35 | {
36 | GLuint *textureBinds; // array of texture binds, one for each mesh
37 | int topTextureBind;
38 | Vec3 *iterVerts; // arrays of vertices for interpolation, one for each mesh
39 | NodeDictionary textureRes; // map of texture names to TextureGL data, stores texture resources
40 | } MD3GL;
41 |
42 | typedef struct
43 | {
44 | Vec3 *pVerts;
45 | short *pNormalIndexes;
46 | } FMeshFrame;
47 | /*
48 | run time model data structure
49 | */
50 |
51 | struct gl_mesh
52 | {
53 | char sName[64];
54 | unsigned int iNumVertices; // number of vertices in model
55 | unsigned int iNumTriangles; // number of triangles in gl_model
56 | unsigned int iNumMeshFrames; // same as global frame but convenient
57 |
58 | TriVec *triangles; // array of triangle vertex indices of size iNumTriangles
59 | TexVec *textureCoord; // array of float s/t texture coordinates of size iNumVertices
60 | FMeshFrame *meshFrames; // 2d array of size of [iNumFrames][vertexNum] stores mesh frame vertices
61 | Vec3 *iterMesh; // buffer mesh frame used to store interpolated mesh of size vertexNum
62 |
63 | unsigned int iNumSkins; // number of skins this model has
64 | GLuint *bindings; // array of texture bindings of size skinNum;
65 |
66 | char sTextureName[MAX_QPATH]; // only bother storing first one
67 | };
68 |
69 | struct gl_model;
70 | struct gl_model
71 | {
72 | // common to any model format:
73 | //
74 | modelType_t modelType;
75 | unsigned int iNumFrames; // number of frames in gl_model
76 | unsigned int iNumTags; // number of tags in gl_model
77 | unsigned int currentFrame; // current frame being displayed
78 | // tag info is duplicated here, even for MDR types, so rest of code works ok
79 | TagFrame *tags; // 2d array of tags size [iNumFrames][iNumTags]
80 | gl_model **linkedModels; // array of links of size iNumTags, each link corresponds to a tag
81 | gl_model *parent;
82 |
83 | // some stuff for dealing with MD3 LODs (which are actually seperate models)...
84 | //
85 | gl_model *pModel_LOD0; // for the LOD0 (default) model, this will be NULL, for other LODs, this will point at original LOD0 model)
86 | gl_model *pModel_LOD1;
87 | gl_model *pModel_LOD2;
88 |
89 | // other stuff...
90 | //
91 | unsigned int iNumMeshes; // number of meshes in whole model
92 | NodePosition modelListPosition; // link to its mdview.modelList
93 | float CTM_matrix[16]; // object transformation matrix for manipulating mesh
94 |
95 | gl_mesh *pMeshes; // array of meshes of size meshNum
96 | md3BoundFrame_t *pMD3BoundFrames; // array of boundary frames size [iNumFrames]
97 |
98 | // this requires more work once the script parser is done
99 | bool isBlended;
100 | GLenum blendParam1, blendParam2;
101 |
102 | int iRenderedTris;
103 | int iRenderedVerts;
104 |
105 | char sHeadSkinName[32]; // should be enough
106 | char sMD3BaseName[1024];
107 | char sMDXFullPathname[1024];
108 | model_t Q3ModelStuff;
109 | };
110 |
111 |
112 | #define NEAR_GL_PLANE 0.1
113 | #define FAR_GL_PLANE 512
114 |
115 | void initialize_glstate();
116 | bool loadmd3gl( MD3GL &data );
117 | void rendermd3gl( MD3GL &mdl );
118 | void freemd3gl( MD3GL &data );
119 | void renderFrame();
120 |
121 | bool bIsWireFrame(void);
122 | bool bIsTextured(void);
123 |
124 | void oglStateFlatTextured();
125 | void oglStateShadedTexturedAndWireFrame();
126 | void oglStateShadedTextured();
127 | void oglStateShadedFlat();
128 | void oglStateWireframe();
129 |
130 |
131 | /*
132 | damn smart and efficient texture loader,
133 | first searches for an existing teature name is parent directories
134 | then checks if texture has already been loaded,
135 | otherwise it loads it up, enters in textureRes manager and returns the new binding
136 | */
137 | extern bool gbIgnoreTextureLoad;
138 | GLuint loadTexture( LPCSTR texturepath );
139 |
140 | /*
141 | frees a texture resource, called whenever a mesh is being freed. a texture is freed only if nothing is using it anymore
142 | */
143 | void freeTexture( GLuint bind );
144 |
145 | /*
146 | deletes the entire texture resource manager with all its textures, usually called at the end of the program
147 | or when a whole new model is loaded
148 | */
149 | void freeTextureRes();
150 |
151 | /*
152 | reloads all texture resources from disk
153 | */
154 | void refreshTextureRes();
155 |
156 | /*
157 | chooses the specific filter to be applied based on current mode
158 | */
159 | void setTextureToFilter();
160 |
161 | /*
162 | sets texture parameters to the current texMode
163 | */
164 | void setTextureFilter();
165 |
166 | /*
167 | renders the current frame
168 | */
169 | void draw_view();
170 | void draw_viewSkeleton();
171 |
172 |
173 |
174 | typedef unsigned int glIndex_t;
175 | typedef struct shaderCommands_s
176 | {
177 | glIndex_t indexes[SHADER_MAX_INDEXES];
178 | vec4_t xyz[SHADER_MAX_VERTEXES];
179 | vec4_t normal[SHADER_MAX_VERTEXES];
180 | vec2_t texCoords[SHADER_MAX_VERTEXES][2];
181 | /* color4ub_t vertexColors[SHADER_MAX_VERTEXES];
182 | int vertexDlightBits[SHADER_MAX_VERTEXES];
183 |
184 | stageVars_t svars;
185 |
186 | color4ub_t constantColor255[SHADER_MAX_VERTEXES];
187 |
188 | shader_t *shader;
189 | int fogNum;
190 |
191 | int dlightBits; // or together of all vertexDlightBits
192 | */
193 | int numIndexes;
194 |
195 | int numVertexes;
196 | /*
197 | // info extracted from current shader
198 | int numPasses;
199 | void (*currentStageIteratorFunc)( void );
200 | shaderStage_t **xstages;
201 | */
202 | } shaderCommands_t;
203 |
204 |
205 | LPCSTR SkinName_FromPathedModelName(LPCSTR psModelPathName);
206 | bool Model_ApplySkin(gl_model* model, LPCSTR psSkinFilename);
207 | bool ApplyNewSkin(LPCSTR psSkinFullPathName);
208 | gl_model* R_FindModel( gl_model* model, LPCSTR psModelBaseName);
209 | shaderCommands_t* Freeze_Surface( md4Surface_t *surface, int iFrame );
210 |
211 | #endif
212 |
--------------------------------------------------------------------------------
/md3view.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 |
20 | /*!
21 | md3view.h - the header file holding the platform independent viewer interface.
22 | the structure MD3ViewState holds all of the runtime global data needed by the viewer
23 | holds most viewer interaction constants and mode enumerations.
24 | this should be the only file included by system dependent code, but that rule is flexible.
25 | */
26 |
27 | #ifndef _MD3_VIEW_H_
28 | #define _MD3_VIEW_H_
29 |
30 | //this is the caption name & the name in the about box
31 | #define FILENAME "MD3View v1.6"
32 |
33 | /*!
34 | enumeration of various display modes that the ogl rendering engine supports. line refers
35 | to wire frame, fill to flat shaded polygons, and textured is self explanatory.
36 | */
37 | enum DrawMode {
38 | DRAW_LINE,
39 | DRAW_FILL,
40 | DRAW_TEXTURE
41 | };
42 |
43 | /*!
44 | texture modes supported by the engine, translates loosely to TEX_FAST being GL_NEAREST texture
45 | fileter with fastest perspective correction. used mostly but he software driver. unfiltered is GL_NEAREST
46 | with full perspective correction and filtered uses bilinear filetering.
47 | */
48 | enum TextureMode {
49 | TEX_FAST,
50 | TEX_UNFILTERED,
51 | TEX_FILTERED
52 | };
53 |
54 | /*!
55 | MD3ViewState - main global structure that holds all the global variables need by the viewer at runtime.
56 | is used for everythign and everwhere.
57 | */
58 |
59 | typedef struct
60 | {
61 | float xPos, yPos;
62 | float zPos;
63 | float rotAngleX, rotAngleY;
64 | float rotAngleZ;
65 | double animSpeed;
66 | double timeStamp1;
67 | float frameFrac;
68 | bool hasAnimation;
69 | bool interpolate;
70 | bool done;
71 | bool animate;
72 | bool bUseAlpha;
73 | bool bBBox;
74 |
75 | /* MD3GL * glmdl;
76 | MD3 * model;
77 | unsigned int* frames;
78 | */
79 | NodeDictionary textureRes; // map of texture names to TextureGL data, stores texture resources
80 | unsigned int topTextureBind; // simple index to keep track of texture bindings
81 |
82 | NodeSequence modelList; // list of gl_meshes loaded
83 | gl_model *baseModel; // base model of a tag hierarchy
84 |
85 | DrawMode drawMode;
86 | TextureMode texMode;
87 |
88 | GLenum faceSide;
89 |
90 | char basepath[128];
91 |
92 | #ifdef WIN32
93 | HWND hwnd;
94 | HDC hdc;
95 | HGLRC glrc;
96 | #endif
97 |
98 | int iLODLevel;
99 | int iSkinNumber;
100 | bool bAxisView;
101 |
102 | byte _R,_G,_B; // clear colours
103 |
104 | // these 2 just for printing stats info...
105 | //
106 | bool bAnimCFGLoaded;
107 | bool bAnimIsMultiPlayerFormat;
108 |
109 | double dFOV;
110 |
111 | } MDViewState;
112 |
113 | const double ANIM_SLOWER = 1.3;
114 | const double ANIM_FASTER = 0.9;
115 | const float MOUSE_ROT_SCALE = 0.5f;
116 | const float MOUSE_ZPOS_SCALE = 0.1f;
117 | const float MOUSE_XPOS_SCALE = 0.1f;
118 | const float MOUSE_YPOS_SCALE = 0.1f;
119 |
120 |
121 | extern MDViewState mdview;
122 |
123 |
124 | #ifdef WIN32
125 | #include
126 | /*!
127 | platform independent key enumeration to drag functions
128 | */
129 | enum mkey_enum {
130 | KEY_LBUTTON = MK_LBUTTON,
131 | KEY_RBUTTON = MK_RBUTTON,
132 | KEY_MBUTTON = MK_MBUTTON
133 | };
134 | #endif
135 |
136 | /*! initializes the mdview structures, should be called at startup before the gui is created */
137 | void init_mdview(const char*);
138 |
139 | /*! initializes the gl structures should be called immiedietly after opengl context has been created */
140 | bool init_mdview_gl();
141 |
142 | /*! called when window is resized to update gl matrices, actually defined in md3gl.cpp */
143 | void set_windowSize( int x, int y );
144 |
145 | /*! called to render the main viewer screen */
146 | void render_mdview();
147 |
148 | /*! commands to handle mouse dragging, uses key_flags defines above */
149 | void start_drag( mkey_enum keyFlags, int x, int y );
150 | bool drag( mkey_enum keyFlags, int x, int y );
151 | void end_drag( mkey_enum keyFlags, int x, int y );
152 |
153 | /*!
154 | loads a model into the file, called by a file open dialog box
155 | */
156 | bool loadmdl( char *filename );
157 |
158 | /*
159 | writes the current mesh frame to a raw file
160 | */
161 | void write_baseModelToRaw( char *fname );
162 |
163 | /*
164 | frees data for shutdown, call this only as the last thing before exiting or bad thigns will happen
165 | */
166 | void shutdown_mdviewdata();
167 |
168 | /*
169 | frees all mdviewdata, and effectively resets the data state back to init
170 | */
171 | void free_mdviewdata();
172 |
173 |
174 | /*! rewinds the animation, called by menu or key callbacks */
175 | void rewindAnim();
176 |
177 | void FrameAdvanceAnim(int iStep); // frame up or down (I generally call this for the '<' & '>' keys)
178 | void SetLODLevel(int iLOD);
179 | void SetFaceSkin(int iSkin);
180 |
181 | void animation_loop();
182 |
183 | /*
184 | frees a model that has been loaded before by loadmdl_totag into the modelptr slot
185 | */
186 | void freemdl_fromtag( GLMODEL_DBLPTR modelptr );
187 |
188 | /*
189 | loads a model into the slot pointed to by dblptr
190 | */
191 | void loadmdl_totag( char *fullName, GLMODEL_DBLPTR dblptr );
192 |
193 | /*
194 | loads a new costum skin and sets all the models to it
195 | */
196 | void importNewSkin( char *fullName );
197 | bool ParseSequenceLockFile(LPCSTR psFilename);
198 |
199 | #define sRAVEN "\n\n(This version heavily customised by Ste Cork @/4 Raven Software)"
200 |
201 | #define ABOUT_TEXT "\n\n " FILENAME "\t\n\n" \
202 | "A q3test model viewer\t\n\n" \
203 | "started by Sander 'FireStorm' van Rossen\t\n" \
204 | "& Matthew 'pagan' Baranowski\t\n\n" \
205 | "a Mental Vortex production\t\n\n" \
206 | "For more information go to: \t\n" \
207 | "mvwebsite.hypermart.net\t\n\n" \
208 | "SOURCE CODE IS FREELY AVAILABLE!!!\n\n" \
209 | sRAVEN
210 |
211 | extern int giTagMenuSubtractValue_Torso;
212 | extern int giTagMenuSubtractValue_Head;
213 | extern int giTagMenuSubtractValue_Weapon;
214 | extern int giTagMenuSubtractValue_Barrel;
215 | extern int giTagMenuSubtractValue_Barrel2;
216 | extern int giTagMenuSubtractValue_Barrel3;
217 | extern int giTagMenuSubtractValue_Barrel4;
218 | extern gl_model* pLastLoadedModel;
219 |
220 |
221 | #endif
222 |
--------------------------------------------------------------------------------
/mdr.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 | #ifndef MDR_H
19 | #define MDR_H
20 |
21 | // a whole bunch of crap to make a big cut/paste from Trek work...
22 |
23 |
24 | typedef int qboolean;
25 | #define qfalse 0
26 | #define qtrue 1
27 | #define MAX_QPATH 64
28 |
29 | // surface geometry should not exceed these limits
30 | #define SHADER_MAX_VERTEXES 1000
31 | #define SHADER_MAX_INDEXES (6*SHADER_MAX_VERTEXES)
32 |
33 |
34 | #define MD4_IDENT (('5'<<24)+('M'<<16)+('D'<<8)+'R')
35 | #define MD4_VERSION 2
36 | #define MD4_MAX_BONES 128
37 |
38 | typedef float vec_t;
39 | typedef vec_t vec2_t[2];
40 | typedef vec_t vec3_t[3];
41 | typedef vec_t vec4_t[4];
42 | typedef vec_t vec5_t[5];
43 |
44 | #define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0)
45 | #define VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
46 | #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
47 | #define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
48 | #define VectorAdd(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
49 | #define VectorScale(v, s, o) ((o)[0]=(v)[0]*((vec_t)s),(o)[1]=(v)[1]*((vec_t)s),(o)[2]=(v)[2]*((vec_t)s))
50 | #define VectorMA(v, s, b, o) ((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s))
51 |
52 |
53 |
54 | typedef enum {
55 | MODTYPE_BAD,
56 | MODTYPE_MD3,
57 | MODTYPE_MDR,
58 | } modelType_t;
59 |
60 |
61 | typedef enum {
62 | SF_BAD,
63 | SF_SKIP, // ignore
64 | SF_FACE,
65 | SF_GRID,
66 | SF_TRIANGLES,
67 | SF_POLY,
68 | SF_MD3,
69 | SF_MD4,
70 | SF_FLARE,
71 | SF_ENTITY, // beams, rails, lightning, etc that can be determined by entity
72 | SF_DISPLAY_LIST,
73 |
74 | SF_NUM_SURFACE_TYPES,
75 | SF_MAX = 0xffffffff // ensures that sizeof( surfaceType_t ) == sizeof( int )
76 | } surfaceType_t;
77 |
78 | typedef struct {
79 | int boneIndex; // these are indexes into the boneReferences,
80 | float boneWeight; // not the global per-frame bone list
81 | vec3_t offset;
82 | } md4Weight_t;
83 |
84 | typedef struct {
85 | vec3_t normal;
86 | vec2_t texCoords;
87 | int numWeights;
88 | md4Weight_t weights[1]; // variable sized
89 | } md4Vertex_t;
90 |
91 | typedef struct {
92 | int indexes[3];
93 | } md4Triangle_t;
94 |
95 | typedef struct {
96 | int ident;
97 |
98 | char name[MAX_QPATH]; // polyset name
99 | char shader[MAX_QPATH];
100 | int shaderIndex; // for in-game use
101 |
102 | int ofsHeader; // this will be a negative number
103 |
104 | int numVerts;
105 | int ofsVerts;
106 |
107 | int numTriangles;
108 | int ofsTriangles;
109 |
110 | // Bone references are a set of ints representing all the bones
111 | // present in any vertex weights for this surface. This is
112 | // needed because a model may have surfaces that need to be
113 | // drawn at different sort times, and we don't want to have
114 | // to re-interpolate all the bones for each surface.
115 | int numBoneReferences;
116 | int ofsBoneReferences;
117 |
118 | int ofsEnd; // next surface follows
119 | } md4Surface_t;
120 |
121 | typedef struct {
122 | float matrix[3][4];
123 | } md4Bone_t;
124 |
125 | typedef struct {
126 | vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame
127 | vec3_t localOrigin; // midpoint of bounds, used for sphere cull
128 | float radius; // dist from localOrigin to corner
129 | char name[16];
130 | md4Bone_t bones[1]; // [numBones]
131 | } md4Frame_t;
132 |
133 | typedef struct {
134 | unsigned char Comp[24]; // MC_COMP_BYTES is in MatComp.h, but don't want to couple
135 | } md4CompBone_t;
136 |
137 | typedef struct {
138 | vec3_t bounds[2]; // bounds of all surfaces of all LOD's for this frame
139 | vec3_t localOrigin; // midpoint of bounds, used for sphere cull
140 | float radius; // dist from localOrigin to corner
141 | md4CompBone_t bones[1]; // [numBones]
142 | } md4CompFrame_t;
143 |
144 | typedef struct {
145 | int numSurfaces;
146 | int ofsSurfaces; // first surface, others follow
147 | int ofsEnd; // next lod follows
148 | } md4LOD_t;
149 |
150 | typedef struct {
151 | int boneIndex;
152 | char name[32];
153 | } md4Tag_t;
154 |
155 | typedef struct {
156 | int ident;
157 | int version;
158 |
159 | char name[MAX_QPATH]; // model name
160 |
161 | // frames and bones are shared by all levels of detail
162 | int numFrames;
163 | int numBones;
164 | int ofsFrames; // md4Frame_t[numFrames] // this will be -ve for compressed models
165 |
166 | // each level of detail has completely separate sets of surfaces
167 | int numLODs;
168 | int ofsLODs;
169 |
170 | int numTags;
171 | int ofsTags;
172 |
173 | int ofsEnd; // end of file
174 | } md4Header_t;
175 |
176 | typedef struct model_s {
177 | char name[MAX_QPATH];
178 | modelType_t modelType;
179 | int index; // model = tr.models[model->index]
180 |
181 | int dataSize; // just for listing purposes
182 | // bmodel_t *bmodel; // only if type == MOD_BRUSH
183 | // md3Header_t *md3[MD3_MAX_LODS]; // only if type == MOD_MESH
184 | md4Header_t *md4; // only if type == MOD_MD4
185 |
186 | int numLods;
187 | } model_t;
188 |
189 | #define LittleFloat(l) l
190 | #define LittleLong(l) l
191 | #define LL(x) x=LittleLong(x)
192 |
193 |
194 | #endif // #ifndef MDR_H
195 |
196 |
--------------------------------------------------------------------------------
/ndictionary.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifndef _NPDICTIONARY_H_
20 | #define _NPDICTIONARY_H_
21 |
22 | #include "nsequence.h"
23 |
24 | typedef class NodeLocatorInfo * NodeLocator;
25 | typedef class NodeDictionaryInfo * NodeDictionary;
26 | typedef class KeyComparatorInfo * KeyComparator;
27 | typedef class StrKeyComparatorInfo * StrKeyComparator;
28 | typedef class IntKeyComparatorInfo * IntKeyComparator;
29 |
30 | /********************************************************************
31 | * CLASS NAME: KeyComparator
32 | * abstract class defining the interface for KeyComparators
33 | ********************************************************************/
34 |
35 | #ifndef BOOL
36 | #define BOOL int
37 | #endif
38 |
39 | class KeyComparatorInfo
40 | {
41 | public:
42 | virtual BOOL equal( Object key1, Object key2 )=0;
43 | virtual char *printKey( Object key )=0;
44 | };
45 |
46 | /* integer comparator */
47 | class IntKeyComparatorInfo: public KeyComparatorInfo
48 | {
49 | public:
50 | virtual BOOL equal( Object key1, Object key2 ) { return ((int)key1 == (int)key2); }
51 | virtual char *printKey( Object key ) { return NULL; }
52 | };
53 |
54 | /* string comparator */
55 | class StrKeyComparatorInfo: public KeyComparatorInfo
56 | {
57 | public:
58 | virtual BOOL equal( Object key1, Object key2 );
59 | virtual char *printKey( Object key ) { return (char*)key; }
60 | };
61 |
62 |
63 | /********************************************************************
64 | * CLASS NAME: NodeLocator
65 | * extends NodePosition class to include a key for indexing
66 | ********************************************************************/
67 |
68 | class NodeLocatorInfo: public NodePositionInfo {
69 | private:
70 | Object m_key;
71 |
72 | public:
73 | NodeLocatorInfo( NodeSequence container, Object element, Object key ):
74 | NodePositionInfo( container, element)
75 | { m_key = key; };
76 |
77 | void setKey( Object key ) { m_key = key; }
78 | Object key() { return m_key; }
79 | };
80 |
81 | /********************************************************************
82 | * CLASS NAME: NodeDictionary
83 | * stores a series of locators that are acessed using their keys,
84 | * a key comparator class defines how keys are used
85 | ********************************************************************/
86 |
87 | class NodeDictionaryInfo: public NodeSequenceInfo {
88 | private:
89 | KeyComparator m_keyComp;
90 | public:
91 | NodeDictionaryInfo( KeyComparator kC ): NodeSequenceInfo() { m_keyComp = kC; };
92 |
93 | /* appends the key, element pair to the end of the list */
94 | void insert( Object element, Object key );
95 | /* if the key already exists, replaces the returned element, otherwise inserts new pair */
96 | Object insertReplace( Object element, Object key );
97 | /* returns an object mapped to the key */
98 | Object find( Object key );
99 | /* removes the key, element pair and returns the element */
100 | Object remove( Object key );
101 | /* replaces the element mapped to the key */
102 | Object replace( Object element, Object key );
103 | /* debugging dump */
104 | void dumpDictionary();
105 | };
106 |
107 |
108 | #endif
109 |
110 |
--------------------------------------------------------------------------------
/nodedictionary.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #include "ndictionary.h"
20 | #include
21 |
22 | using namespace std;
23 |
24 | void NodeDictionaryInfo::insert( Object element, Object key )
25 | {
26 | NodeLocator nL = new NodeLocatorInfo( this, element, key );
27 | insertLast( nL );
28 | };
29 |
30 |
31 | Object NodeDictionaryInfo::insertReplace( Object element, Object key )
32 | {
33 | Object toReturn;
34 | NodeLocator nL;
35 | for (nL = (NodeLocator)first(); nL != NULL; nL = (NodeLocator)after(nL))
36 | {
37 | if (m_keyComp->equal( nL->key(), key )) {
38 | toReturn = nL->element();
39 | nL->setElement( element );
40 | return toReturn;
41 | }
42 | }
43 |
44 | // found nothing so append
45 | nL = new NodeLocatorInfo( this, element, key );
46 | insertLast( nL );
47 | return NULL;
48 | };
49 |
50 |
51 | Object NodeDictionaryInfo::find(Object key)
52 | {
53 | for (NodeLocator nL = (NodeLocator)first(); nL != NULL; nL = (NodeLocator)after(nL))
54 | {
55 | if (m_keyComp->equal( nL->key(), key )) {
56 | return nL->element();
57 | }
58 | }
59 | return NULL; // found nothing
60 | }
61 |
62 | Object NodeDictionaryInfo::remove( Object key )
63 | {
64 | for (NodeLocator nL = (NodeLocator)first(); nL != NULL; nL = (NodeLocator)after(nL))
65 | {
66 | if (m_keyComp->equal( nL->key(), key )) {
67 | return remove( nL );
68 | }
69 | }
70 | return NULL; // found nothing
71 | }
72 |
73 |
74 | Object NodeDictionaryInfo::replace( Object element, Object key )
75 | {
76 | Object toReturn;
77 | for (NodeLocator nL = (NodeLocator)first(); nL != NULL; nL = (NodeLocator)after(nL))
78 | {
79 | if (m_keyComp->equal( nL->key(), key )) {
80 | toReturn = nL->element();
81 | nL->setElement( element );
82 | return toReturn;
83 | }
84 | }
85 | return NULL; // found nothing
86 | }
87 |
88 |
89 | void NodeDictionaryInfo::dumpDictionary()
90 | {
91 | cout << "Dictionary Dump, size " << size() << endl;
92 | for (NodeLocator nL = (NodeLocator)first(); nL != NULL; nL = (NodeLocator)after(nL))
93 | {
94 | cout << " Position " << nL;
95 | cout << " next " << nL->getNextNode();
96 | cout << " prev " << nL->getPrevNode();
97 | cout << " element " << nL->element();
98 | cout << " key " << (char *)nL->key() << endl;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/nodesequence.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #include "ndictionary.h"
20 | #include
21 | #include
22 |
23 | using namespace std;
24 |
25 | //void DebugToFile (char *msg, ...);
26 |
27 | BOOL StrKeyComparatorInfo::equal( Object key1, Object key2 )
28 | {
29 | return (!strcmp( (char*)key1, (char*)key2 ));
30 | }
31 |
32 |
33 | /*
34 | =======
35 | destructor removes sequence positions, however does nothing for the object pointers
36 | use this if _only_ if don't need to delete position elements
37 | =======
38 | */
39 | NodeSequenceInfo::~NodeSequenceInfo()
40 | {
41 | NodePosition pos, next;
42 | if (!isEmpty()) {
43 | for(pos=first(); pos!=NULL ; pos=next) {
44 | next = after(pos);
45 | remove(pos);
46 | }
47 | }
48 | }
49 |
50 |
51 | Object NodeSequenceInfo::replace(NodePosition position, Object newElement )
52 | {
53 | NodePosition nodePosition = (NodePosition)position;
54 | Object toReturn = nodePosition->element();
55 | nodePosition->setElement( newElement );
56 | return toReturn;
57 | };
58 |
59 | void NodeSequenceInfo::dumpSequence()
60 | {
61 |
62 | cout << "Sequence Dump, size " << size() << endl;
63 | for (NodePosition pos = first(); pos != NULL; pos = after(pos) ) {
64 | cout << " Position " << pos;
65 | cout << " next " << pos->getNextNode();
66 | cout << " prev " << pos->getPrevNode();
67 | cout << " element " << pos->element() << endl;
68 | }
69 |
70 | }
71 |
72 | void NodeSequenceInfo::swap(NodePosition p1,NodePosition p2 )
73 | {
74 | NodePosition nP1 = (NodePosition)p1;
75 | NodePosition nP2 = (NodePosition)p2;
76 | Object element = nP1->element();
77 | nP1->setElement( nP2->element() );
78 | nP2->setElement( element );
79 | };
80 |
81 | NodePosition NodeSequenceInfo::before( NodePosition p )
82 | {
83 | NodePosition nodePosition = (NodePosition)p;
84 | return nodePosition->getPrevNode();
85 | };
86 |
87 | NodePosition NodeSequenceInfo::after( NodePosition p )
88 | {
89 | NodePosition nodePosition = (NodePosition)p;
90 | return nodePosition->getNextNode();
91 | };
92 |
93 | NodePosition NodeSequenceInfo::insertFirst( Object element )
94 | {
95 | NodePosition nP = new NodePositionInfo( this, element );
96 | return insertFirst( nP );
97 | }
98 |
99 | NodePosition NodeSequenceInfo::insertFirst( NodePosition nP )
100 | {
101 | nP->setPrevNode( NULL );
102 | nP->setNextNode( first_ );
103 | if (first_) first_->setPrevNode( nP );
104 | first_ = nP;
105 | if (nP->getNextNode() == NULL) {
106 | last_ = nP;
107 | }
108 |
109 | size_++;
110 | return first_;
111 | }
112 |
113 | NodePosition NodeSequenceInfo::insertLast( Object element )
114 | {
115 | NodePosition nP = new NodePositionInfo( this, element );
116 | return insertLast( nP );
117 | };
118 |
119 |
120 | NodePosition NodeSequenceInfo::insertLast( NodePosition nP )
121 | {
122 | nP->setPrevNode( last_ );
123 | nP->setNextNode( NULL );
124 | if (last_) last_->setNextNode( nP );
125 | last_ = nP;
126 | if (nP->getPrevNode() == NULL) {
127 | first_ = nP;
128 | }
129 | size_++;
130 | return last_;
131 | };
132 |
133 |
134 | NodePosition NodeSequenceInfo::insertAfter(NodePosition p, Object element )
135 | {
136 | NodePosition node = (NodePosition)p;
137 | if (node->getNextNode() == NULL) {
138 | NodePosition result = insertLast(element);
139 | return result;
140 | }
141 |
142 | NodePosition nP = new NodePositionInfo( this, element );
143 | nP->setPrevNode( node );
144 | nP->setNextNode( node->getNextNode() );
145 | node->getNextNode()->setPrevNode( nP );
146 | node->setNextNode( nP );
147 | size_++;
148 | return nP;
149 |
150 | };
151 |
152 | NodePosition NodeSequenceInfo::insertBefore(NodePosition p, Object element )
153 | {
154 | NodePosition node = (NodePosition)p;
155 | if (node->getPrevNode() == NULL) {
156 | return insertFirst( element );
157 | }
158 |
159 | NodePosition nP = new NodePositionInfo( this, element );
160 | nP->setNextNode( node );
161 | nP->setPrevNode( node->getPrevNode() );
162 | NodePosition prevNode = node->getPrevNode();
163 | prevNode->setNextNode( nP );
164 | node->setPrevNode( nP );
165 | size_++;
166 | return nP;
167 | };
168 |
169 | Object NodeSequenceInfo::remove(NodePosition p )
170 | {
171 | NodePosition nP = (NodePosition)p;
172 | Object toReturn = nP->element();
173 |
174 | NodePosition prevNode = nP->getPrevNode();
175 |
176 | if (prevNode == NULL) {
177 | Object result = removeFirst();
178 | return result;
179 | }
180 |
181 | NodePosition nextNode = nP->getNextNode();
182 |
183 | if (nextNode == NULL) {
184 | Object result = removeLast();
185 | return result;
186 |
187 | }
188 |
189 | prevNode->setNextNode( nextNode );
190 | nextNode->setPrevNode( prevNode );
191 | delete nP;
192 | size_--;
193 | return toReturn;
194 | };
195 |
196 | Object NodeSequenceInfo::removeAfter(NodePosition p )
197 | {
198 |
199 | NodePosition nP = (NodePosition)p;
200 |
201 | if (nP->getNextNode() == NULL) {
202 | return NULL;
203 | }
204 | nP = nP->getNextNode();
205 |
206 | Object toReturn = nP->element();
207 |
208 | NodePosition prevNode = nP->getPrevNode();
209 | NodePosition nextNode = nP->getNextNode();
210 |
211 | if (nextNode == NULL) {
212 | return removeLast();
213 | }
214 |
215 | prevNode->setNextNode( nextNode );
216 | nextNode->setPrevNode( prevNode );
217 | delete nP;
218 | size_--;
219 | return toReturn;
220 | };
221 |
222 | Object NodeSequenceInfo::removeBefore(NodePosition p )
223 | {
224 | NodePosition nP = (NodePosition)p;
225 |
226 | if (nP->getPrevNode() == NULL) {
227 | return NULL;
228 | }
229 | nP = nP->getPrevNode();
230 |
231 | Object toReturn = nP->element();
232 |
233 | NodePosition prevNode = nP->getPrevNode();
234 |
235 | if (prevNode == NULL) {
236 | return removeFirst();
237 | }
238 |
239 | NodePosition nextNode = nP->getNextNode();
240 |
241 | prevNode->setNextNode( nextNode );
242 | nextNode->setPrevNode( prevNode );
243 | delete nP;
244 | size_--;
245 | return toReturn;
246 | };
247 |
248 | Object NodeSequenceInfo::removeFirst()
249 | {
250 | NodePosition nP = (NodePosition)first_;
251 | Object toReturn = nP->element();
252 |
253 | NodePosition nextNode = nP->getNextNode();
254 | if (nextNode) nextNode->setPrevNode( NULL );
255 | first_ = nextNode;
256 | if (!first_) last_ = NULL;
257 | delete nP;
258 | size_--;
259 | return toReturn;
260 | };
261 |
262 | Object NodeSequenceInfo::removeLast()
263 | {
264 | NodePosition nP = (NodePosition)last_;
265 | Object toReturn = nP->element();
266 |
267 | NodePosition prevNode = nP->getPrevNode();
268 | if (prevNode) prevNode->setNextNode( NULL );
269 | last_ = prevNode;
270 | if (!last_) first_ = NULL;
271 | delete nP;
272 | size_--;
273 | return toReturn;
274 | };
275 |
--------------------------------------------------------------------------------
/nsequence.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | /*
20 | linked list implementation, by Matthew Baranowski
21 | */
22 |
23 | #ifndef _NPSEQUENCE_H_
24 | #define _NPSEQUENCE_H_
25 |
26 | #define Object void *
27 |
28 | #ifndef NULL
29 | #define NULL 0
30 | #endif
31 |
32 | typedef class NodePositionInfo * NodePosition;
33 | typedef class NodeSequenceInfo * NodeSequence;
34 |
35 | /********************************************************************
36 | * CLASS NAME: NodePosition
37 | * double linked nodeNodePosition implementation
38 | ********************************************************************/
39 |
40 |
41 | class NodePositionInfo {
42 | private:
43 | NodeSequence container_;
44 | Object element_;
45 | NodePosition nextNode_;
46 | NodePosition prevNode_;
47 |
48 | public:
49 | NodePositionInfo( NodeSequence container, Object element )
50 | { container_ = container; element_ = element; };
51 |
52 | void setNextNode( NodePosition nextNode ) { nextNode_ = nextNode; };
53 | void setPrevNode( NodePosition prevNode ) { prevNode_ = prevNode; };
54 | NodePosition getNextNode() { return nextNode_; };
55 | NodePosition getPrevNode() { return prevNode_; };
56 | void setElement( Object element ) { element_ = element; };
57 | NodeSequence container() { return container_; };
58 | Object element() { return element_; };
59 | };
60 |
61 | /********************************************************************
62 | *
63 | * CLASS NAME: NodeSequence
64 | *
65 | * double linked node sequence implementation
66 | *
67 | ********************************************************************/
68 |
69 |
70 | class NodeSequenceInfo {
71 |
72 | private:
73 | NodePosition first_;
74 | NodePosition last_;
75 | int size_;
76 |
77 | public:
78 | NodeSequenceInfo() { size_ = 0; first_ = last_ = NULL; };
79 | ~NodeSequenceInfo();
80 |
81 | void clearSequence() { size_ = 0; first_ = last_ = NULL; };
82 | NodeSequence newContainer() { return new NodeSequenceInfo(); };
83 | int isEmpty() { if (size_ == 0) return 1; else return 0;};
84 | int size() { return size_; };
85 | Object replace(NodePosition, Object newElement );
86 | void swap(NodePosition p1,NodePosition p2 );
87 | NodePosition first() { return first_; };
88 | NodePosition last() { return last_; };
89 | NodePosition before(NodePosition p );
90 | NodePosition after(NodePosition p );
91 | NodePosition insertFirst( Object element );
92 | NodePosition insertLast( Object element );
93 | NodePosition insertFirst( NodePosition nP );
94 | NodePosition insertLast( NodePosition nP );
95 | NodePosition insertBefore(NodePosition p, Object element );
96 | NodePosition insertAfter(NodePosition p, Object element );
97 | Object remove(NodePosition p );
98 | Object removeAfter(NodePosition p );
99 | Object removeBefore(NodePosition p );
100 | Object removeFirst();
101 | Object removeLast();
102 | void dumpSequence();
103 | };
104 |
105 | #endif
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/oddbits.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifndef ODDBITS_H
20 | #define ODDBITS_H
21 |
22 | #include "assert.h"
23 |
24 | #define SAFEFREE(arg) if (arg){free(arg);arg=0;}
25 | #define ZEROMEM(arg) memset(arg, 0, sizeof(arg))
26 | #define ASSERT assert
27 | #ifdef _DEBUG
28 | #define VERIFY(arg) ASSERT(arg)
29 | #else
30 | #define VERIFY(arg) arg
31 | #endif
32 |
33 | char *va(char *format, ...);
34 | bool FileExists (LPCSTR psFilename);
35 |
36 | void ErrorBox(const char *sString);
37 | void InfoBox(const char *sString);
38 | void WarningBox(const char *sString);
39 | #define GetYesNo(psQuery) (!!(MessageBox(mdview.hwnd,psQuery,"Query",MB_YESNO|MB_ICONWARNING|MB_TASKMODAL)==IDYES))
40 |
41 |
42 | char *scGetTempPath(void);
43 | char *InputLoadFileName(char *psInitialLoadName, char *psCaption, const char *psInitialDir, char *psFilter);
44 | long filesize(FILE *handle);
45 | int LoadFile (LPCSTR psPathedFilename, void **bufferptr);
46 | //void Filename_RemoveBASEQ(CString &string);
47 | //void Filename_RemoveFilename(CString &string);
48 | //void Filename_BaseOnly(CString &string);
49 | //void Filename_AccountForLOD(CString &string, int iLODLevel);
50 |
51 | char *Filename_WithoutPath(LPCSTR psFilename);
52 | char *Filename_WithoutExt(LPCSTR psFilename);
53 | char *Filename_PathOnly(LPCSTR psFilename);
54 | char *Filename_ExtOnly(LPCSTR psFilename);
55 | char *String_ToLower(LPCSTR psString);
56 | char *String_ToUpper(LPCSTR psString);
57 | char *String_Neaten(LPCSTR psString);
58 | char *String_NeatenEveryWord(LPCSTR psString);
59 | char *String_Replace(char *psString, char *psFind, char *psReplace, BOOL bCaseInSensitive);
60 | char *String_GetField(char *psString);
61 | char *String_LoseField(char *psString);
62 | char *String_LoseWhitespace(char *psString);
63 | char *String_LoseLeadingWhitespace(char *psString);
64 | char *String_LoseTrailingWhitespace(char *psString);
65 | char *String_EnsureTrailingChar(char *psString, char c);
66 | char *String_LoseTrailingChar(char *psString, char c);
67 | char *String_LoseComment(char *psString);
68 | char *String_LoseNewline(char *psString);
69 | char *String_EnsureMinLength(LPCSTR psString, int iMinLength);
70 | int RunningNT(void);
71 |
72 | #define StartWait() HCURSOR hcurSave = SetCursor(::LoadCursor(NULL, IDC_WAIT))
73 | #define RestoreWait() SetCursor(::LoadCursor(NULL, IDC_WAIT))
74 | #define EndWait() SetCursor(hcurSave)
75 |
76 | #define STL_ITERATE_DECL(iter, dataname) for (dataname##_t::iterator iter = dataname.begin(); iter!=dataname.end(); ++iter)
77 | #define STL_ITERATE(iter, dataname) for (iter = dataname.begin(); iter!=dataname.end(); ++iter)
78 |
79 | void SystemErrorBox(DWORD dwError = GetLastError());
80 |
81 | #endif // #ifndef ODDBITS_H
82 |
83 |
84 | /////////////////// eof ////////////////////
85 |
86 |
87 |
--------------------------------------------------------------------------------
/png/png.h:
--------------------------------------------------------------------------------
1 | // Known chunk types
2 |
3 | #define PNG_IHDR 'IHDR'
4 | #define PNG_IDAT 'IDAT'
5 | #define PNG_IEND 'IEND'
6 | #define PNG_tEXt 'tEXt'
7 |
8 | #define PNG_PLTE 'PLTE'
9 | #define PNG_bKGD 'bKGD'
10 | #define PNG_cHRM 'cHRM'
11 | #define PNG_gAMA 'gAMA'
12 | #define PNG_hIST 'hIST'
13 | #define PNG_iCCP 'iCCP'
14 | #define PNG_iTXt 'iTXt'
15 | #define PNG_oFFs 'oFFs'
16 | #define PNG_pCAL 'pCAL'
17 | #define PNG_sCAL 'sCAL'
18 | #define PNG_pHYs 'pHYs'
19 | #define PNG_sBIT 'sBIT'
20 | #define PNG_sPLT 'sPLT'
21 | #define PNG_sRGB 'sRGB'
22 | #define PNG_tIME 'tIME'
23 | #define PNG_tRNS 'tRNS'
24 | #define PNG_zTXt 'zTXt'
25 |
26 | // Filter values
27 |
28 | #define PNG_FILTER_VALUE_NONE 0
29 | #define PNG_FILTER_VALUE_SUB 1
30 | #define PNG_FILTER_VALUE_UP 2
31 | #define PNG_FILTER_VALUE_AVG 3
32 | #define PNG_FILTER_VALUE_PAETH 4
33 | #define PNG_FILTER_NUM 5
34 |
35 | // Common defines and typedefs
36 |
37 | typedef unsigned char byte;
38 | typedef unsigned short word;
39 | typedef unsigned long ulong;
40 |
41 | #pragma pack(push)
42 | #pragma pack(1)
43 |
44 | typedef struct png_ihdr_s
45 | {
46 | ulong width;
47 | ulong height;
48 | byte bitdepth; // Bits per sample (not per pixel)
49 | byte colortype; // bit 0 - palette; bit 1 - RGB; bit 2 - alpha channel
50 | byte compression; // 0 for zip - error otherwise
51 | byte filter; // 0 for adaptive with the 5 basic types - error otherwise
52 | byte interlace; // 0 for no interlace - 1 for Adam7 interlace
53 | } png_ihdr_t;
54 |
55 | #pragma pack(pop)
56 |
57 | typedef struct png_image_s
58 | {
59 | byte *data;
60 | ulong width;
61 | ulong height;
62 | ulong bytedepth;
63 | } png_image_t;
64 |
65 | bool LoadPNG32 (const char *name, byte **pixels, int *width, int *height, int *bytedepth);
66 |
67 | // end
--------------------------------------------------------------------------------
/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Developer Studio generated include file.
3 | // Used by MD3View.rc
4 | //
5 | #define IDS_FILESTRING 1
6 | #define IDS_RAWFILEFILTER 2
7 | #define TAG_MENU_ID 3
8 | #define IDS_SKINFILEFILTER 3
9 | #define IDS_UPPERANIM 4
10 | #define IDS_MD3FILEFILTER 4
11 | #define IDS_LOWERANIM 5
12 | #define IDS_SEQFILTER 5
13 | #define IDR_MENU1 101
14 | #define IDI_APP 102
15 | #define IDR_ACCELERATOR1 105
16 | #define ID_FILE_EXIT 40002
17 | #define ID_ABOUT 40003
18 | #define ID_VIEW_WIREFRAME 40004
19 | #define ID_VIEW_FLATSHADED 40005
20 | #define ID_VIEW_TEXTURED 40006
21 | #define ID_VIEW_TEXTUREDSHADED 40007
22 | #define ID_VIEW_NEAREST 40008
23 | #define ID_VIEW_UNFILTEREDTEXTURE 40010
24 | #define ID_VIEW_FILTEREDTEXTURE 40011
25 | #define ID_VIEW_FLIPFACESIDES 40012
26 | #define ID_ANIMATION_SLOWER 40013
27 | #define ID_ANIMATION_FASTER 40014
28 | #define ID_ANIMATION_STOP 40015
29 | #define ID_ANIMATION_START 40016
30 | #define ID_ANIMATION_REWIND 40017
31 | #define ID_ANIMATION_INTERPOLATE 40018
32 | #define ID_FILE_EXPORTTORAW 40019
33 | #define ID_FILE_IMPORTSKIN 40020
34 | #define ID_VIEW_REFRESHTEXTURE 40021
35 | #define ID_FRAME_UP 40022
36 | #define ID_FRAME_DW 40023
37 | #define ID_VIEW_LOADEDSTUFF 40024
38 | #define ID_LOD0 40025
39 | #define ID_LOD1 40026
40 | #define ID_LOD2 40027
41 | #define ID_FACE_INCANIM 40028
42 | #define ID_FACE_DECANIM 40029
43 | #define ID_FACE_RESANIM 40030
44 | #define ID_VIEWAXIS 40031
45 | #define ID_VIEWLOWERANIM_INC 40032
46 | #define ID_VIEWLOWERANIM_DEC 40033
47 | #define ID_VIEWLOWERANIM_LOCK 40034
48 | #define ID_VIEWUPPERANIM_INC 40035
49 | #define ID_VIEWUPPERANIM_DEC 40036
50 | #define ID_VIEWUPPERANIM_LOCK 40037
51 | #define ID_FILE_SAVE_MD3 40039
52 | #define ID_FILE_IMPORTMULTISEQ 40040
53 | #define ID_VIEWALPHA 40041
54 | #define ID_SCREENSHOT_CLIPBOARD 40042
55 | #define ID_SCREENSHOT_FILE 40043
56 | #define ID_VIEW_COLOURPICKER 40044
57 | #define ID_VIEW_FOVTOGGLE 40045
58 | #define ID_FILE_SAVE_G2 40046
59 | #define ID_PICMIP0 40047
60 | #define ID_PICMIP1 40048
61 | #define ID_PICMIP2 40049
62 | #define ID_PICMIP3 40050
63 | #define ID_PICMIP4 40051
64 | #define ID_PICMIP5 40052
65 | #define ID_PICMIP6 40053
66 | #define ID_PICMIP7 40054
67 | #define ID_VIEWPOS_RESET 40055
68 | #define ID_VIEW_TEXTUREDWIREFRAME 40056
69 | #define ID_VIEW_BOUNDSTOGGLE 40057
70 | #define ID_FILE_SAVE_G2_PERFECT 40058
71 | #define ID_TAG_START 50000
72 | #define ID_MENUITEMS_UPPERANIMS 60000
73 | #define ID_MENUITEMS_LOWERANIMS 61000
74 | #define ID_MENUITEMS_NEXT 62000
75 |
76 | // Next default values for new objects
77 | //
78 | #ifdef APSTUDIO_INVOKED
79 | #ifndef APSTUDIO_READONLY_SYMBOLS
80 | #define _APS_NEXT_RESOURCE_VALUE 106
81 | #define _APS_NEXT_COMMAND_VALUE 40059
82 | #define _APS_NEXT_CONTROL_VALUE 1000
83 | #define _APS_NEXT_SYMED_VALUE 101
84 | #endif
85 | #endif
86 |
--------------------------------------------------------------------------------
/stdafx.h:
--------------------------------------------------------------------------------
1 | // stdafx.h : include file for standard system include files,
2 | // or project specific include files that are used frequently, but
3 | // are changed infrequently
4 | //
5 |
6 | #if !defined(AFX_STDAFX_H__2CCA5546_2AD3_11D3_82E0_0000C0366FF2__INCLUDED_)
7 | #define AFX_STDAFX_H__2CCA5546_2AD3_11D3_82E0_0000C0366FF2__INCLUDED_
8 |
9 | #if _MSC_VER > 1000
10 | #pragma once
11 | #endif // _MSC_VER > 1000
12 |
13 | #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
14 |
15 | #include // MFC core and standard components
16 | #include // MFC extensions
17 | #include // MFC Automation classes
18 | #include // MFC support for Internet Explorer 4 Common Controls
19 | #include // MFC support for Windows Common Controls
20 | #include
21 |
22 | //{{AFX_INSERT_LOCATION}}
23 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
24 |
25 | #endif // !defined(AFX_STDAFX_H__2CCA5546_2AD3_11D3_82E0_0000C0366FF2__INCLUDED_)
26 |
--------------------------------------------------------------------------------
/system.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifndef _SYSTEM_H_
20 | #define _SYSTEM_H_
21 |
22 | /*
23 | system dependent function exported to the rest of the application
24 | redefine these for each platform being ported
25 | */
26 |
27 | #ifdef WIN32
28 | #define _CRT_SECURE_NO_WARNINGS
29 | #define _CRT_NONSTDC_NO_WARNINGS
30 | #include
31 | #include
32 | #endif
33 |
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 |
42 | double getDoubleTime (void);
43 |
44 | void repaint_main();
45 | void set_cursor( int x, int y );
46 |
47 | bool file_exists( LPCSTR fname );
48 | char *getCmdLine();
49 | void FreeCmdLine();
50 | void swap_buffers();
51 |
52 | typedef int GLMODEL_DBLPTR;
53 | void tagMenu_append( char *name, GLMODEL_DBLPTR model );
54 | void tagMenu_seperatorAppend( char *name );
55 | void tagMenu_remove( GLMODEL_DBLPTR tagid );
56 |
57 | #include "Error.h"
58 | #include "Base.h"
59 | #include "BaseMesh.h"
60 |
61 |
62 |
63 | //
64 | // I did it this way to avoid other modules having to know about HMENUs...
65 | //
66 | void Menu_UpperAnims_Clear(void);
67 | void Menu_LowerAnims_Clear(void);
68 | void Menu_UpperAnims_AddItem(LPCSTR psItem);
69 | void Menu_LowerAnims_AddItem(LPCSTR psItem);
70 |
71 | #ifndef g_iScreenWidth
72 | #include "text.h"
73 | #endif
74 | bool ScreenShot(LPCSTR psFilename = NULL, LPCSTR psCopyrightMessage = NULL, int iWidth = g_iScreenWidth, int iHeight = g_iScreenHeight);
75 |
76 |
77 | #endif
--------------------------------------------------------------------------------
/vect3.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #include "vect3.h"
20 |
21 |
22 | const Vect3 Vect3X(1.f,0.f,0.f);
23 | const Vect3 Vect3Y(0.f,1.f,0.f);
24 | const Vect3 Vect3Z(0.f,0.f,1.f);
25 | const Vect3 Vect3negX(-1.f,0.f,0.f);
26 | const Vect3 Vect3negY(0.f,-1.f,0.f);
27 | const Vect3 Vect3negZ(0.f,0.f,-1.f);
28 | const Vect3 Vect3Zero(0.f,0.f,0.f);
29 |
30 | const Vect3 &Vect3::operator/= (const float d)
31 | {
32 | float inv=1.f/d;
33 | return (*this)*=inv;
34 | }
35 |
36 | void Vect3::Cross(const Vect3& p)
37 | {
38 | Vect3 t=*this;
39 | v[0]=t.v[1]*p.v[2]-t.v[2]*p.v[1];
40 | v[1]=t.v[2]*p.v[0]-t.v[0]*p.v[2];
41 | v[2]=t.v[0]*p.v[1]-t.v[1]*p.v[0];
42 | }
43 |
44 | void Vect3::NegCross(const Vect3& p)
45 | {
46 | Vect3 t=*this;
47 | v[0]=p.v[1]*t.v[2]-p.v[2]*t.v[1];
48 | v[1]=p.v[2]*t.v[0]-p.v[0]*t.v[2];
49 | v[2]=p.v[0]*t.v[1]-p.v[1]*t.v[0];
50 | }
51 |
52 | float Vect3::Dist(const Vect3& p) const
53 | {
54 | Vect3 t=*this;
55 | t-=p;
56 | return t.Len();
57 | }
58 |
59 | float Vect3::Dist2(const Vect3& p) const
60 | {
61 | Vect3 t=*this;
62 | t-=p;
63 | return t^t;
64 | }
65 |
66 | void Vect3::Perp()
67 | {
68 | float rlen,tlen;
69 | Vect3 r,t;
70 | r=*this;
71 | r.Cross(Vect3X);
72 | rlen=r.Len();
73 | t=*this;
74 | t.Cross(Vect3Y);
75 | tlen=t.Len();
76 | if (tlen>rlen)
77 | {
78 | r=t;
79 | rlen=tlen;
80 | }
81 | t=*this;
82 | t.Cross(Vect3Z);
83 | tlen=t.Len();
84 | if (tlen>rlen)
85 | {
86 | r=t;
87 | rlen=tlen;
88 | }
89 | *this=r;
90 | }
91 |
92 | void Vect3::Min(const Vect3& p)
93 | {
94 | if (p.v[0]v[0])
105 | v[0]=p.v[0];
106 | if (p.v[1]>v[1])
107 | v[1]=p.v[1];
108 | if (p.v[2]>v[2])
109 | v[2]=p.v[2];
110 | }
111 |
112 | float Vect3::MaxElement() const
113 | {
114 | return v[MaxElementIndex()];
115 | }
116 |
117 | int Vect3::MaxElementIndex() const
118 | {
119 | if (fabs(v[0])>fabs(v[1])&&fabs(v[0])>fabs(v[2]))
120 | return 0;
121 | if (fabs(v[1])>fabs(v[2]))
122 | return 1;
123 | return 2;
124 | }
125 |
126 |
--------------------------------------------------------------------------------
/vect3.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #if !defined(VECT3_INC)
20 | #define VECT3_INC
21 |
22 | #include
23 | #include
24 |
25 | class Vect3
26 | {
27 | float v[3];
28 | public:
29 | Vect3(const float val) {v[0]=val;v[1]=val;v[2]=val;}
30 | Vect3() {}//never put anything in here! too slow}
31 | Vect3(const float x,const float y,const float z) {v[0]=x;v[1]=y;v[2]=z;}
32 | Vect3(const Vect3& t) {v[0]=t.v[0];v[1]=t.v[1];v[2]=t.v[2];}
33 | Vect3(const float *t) {v[0]=t[0];v[1]=t[1];v[2]=t[2];}
34 | float& operator[](int i) {return v[i];}
35 | float& x() {return v[0];}
36 | float& y() {return v[1];}
37 | float& z() {return v[2];}
38 | const float& operator[](int i) const {return v[i];}
39 | const float& x() const {return v[0];}
40 | const float& y() const {return v[1];}
41 | const float& z() const {return v[2];}
42 | void Set(const float x,const float y,const float z) {v[0]=x;v[1]=y;v[2]=z;}
43 |
44 | float Len() const {return (float)sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);}
45 | float Len2() const {return v[0]*v[0]+v[1]*v[1]+v[2]*v[2];}
46 | void Norm() {(*this)/=this->Len();}
47 | bool ZeroNorm() {float d=this->Len();if (d>1E-10) {(*this)/=d;return true;} (*this)=0.0f; return false;}
48 | void SafeNorm() {assert(this->Len()>1E-10);(*this)/=this->Len();}
49 |
50 | const Vect3 &operator= (const float d) {v[0]=d;v[1]=d;v[2]=d; return *this; }
51 | const Vect3 &operator= (const Vect3& t) {v[0]=t.v[0];v[1]=t.v[1];v[2]=t.v[2]; return *this; }
52 |
53 | const Vect3 &operator+= (const float d) {v[0]+=d;v[1]+=d;v[2]+=d; return *this; }
54 | const Vect3 &operator+= (const Vect3& t) {v[0]+=t.v[0];v[1]+=t.v[1];v[2]+=t.v[2]; return *this; }
55 |
56 | const Vect3 &operator-= (const float d) {v[0]-=d;v[1]-=d;v[2]-=d; return *this; }
57 | const Vect3 &operator-= (const Vect3& t) {v[0]-=t.v[0];v[1]-=t.v[1];v[2]-=t.v[2]; return *this; }
58 |
59 | const Vect3 &operator*= (const float d) {v[0]*=d;v[1]*=d;v[2]*=d; return *this; }
60 | const Vect3 &operator*= (const Vect3& t) {v[0]*=t.v[0];v[1]*=t.v[1];v[2]*=t.v[2]; return *this; }
61 |
62 | const Vect3 &operator/= (const float d);
63 | const Vect3 &operator/= (const Vect3& t) {v[0]/=t.v[0];v[1]/=t.v[1];v[2]/=t.v[2]; return *this; }
64 |
65 | float operator^ (const Vect3& t) const {return v[0]*t.v[0]+v[1]*t.v[1]+v[2]*t.v[2];}
66 |
67 | float Dist(const Vect3&) const;
68 | float Dist2(const Vect3&) const;
69 | void Cross(const Vect3&);
70 | void NegCross(const Vect3&);
71 | void Perp();
72 | void Min(const Vect3&);
73 | void Max(const Vect3&);
74 | float MaxElement() const;
75 | int MaxElementIndex() const;
76 |
77 | void Interp(const Vect3 &v1,const Vect3 &v2,float t) {*this=v1;*this-=v2;*this*=t;*this+=v2;}
78 | // bool operator== (const Vect3& t) const {return v[0]==t.v[0]&&v[1]==t.v[1]&&v[2]==t.v[2];}
79 | bool operator== (const Vect3& t) const {return fabs(v[0]-t.v[0])<.001f&&fabs(v[1]-t.v[1])<.001f&&fabs(v[2]-t.v[2])<.001f;}
80 | bool operator< (const Vect3& t) const {assert(0);return false;}
81 | bool operator!= (const Vect3& t) const {return !(v[0]==t.v[0]&&v[1]==t.v[1]&&v[2]==t.v[2]);}
82 | bool operator> (const Vect3& t) const {assert(0);return false;}
83 |
84 | inline Vect3 operator +(const Vect3 &rhs) const { return Vect3(v[0]+rhs.v[0], v[1]+rhs.v[1], v[2]+rhs.v[2]); }
85 | inline Vect3 operator -(const Vect3 &rhs) const { return Vect3(v[0]-rhs.v[0], v[1]-rhs.v[1], v[2]-rhs.v[2]); }
86 | inline Vect3 operator *(const Vect3 &rhs) const { return Vect3(v[0]*rhs.v[0], v[1]*rhs.v[1], v[2]*rhs.v[2]); }
87 | inline Vect3 operator *(const float scalar) const { return Vect3(v[0]*scalar, v[1]*scalar, v[2]*scalar); }
88 | inline friend Vect3 operator *(const float scalar, const Vect3 &rhs);
89 | inline Vect3 operator /(const Vect3 &rhs) const { return Vect3(v[0]/rhs.v[0], v[1]/rhs.v[1], v[2]/rhs.v[2]); }
90 | inline Vect3 operator /(const float scalar) const { return Vect3(v[0]/scalar, v[1]/scalar, v[2]/scalar); }
91 | };
92 |
93 | inline Vect3 operator *(const float scalar, const Vect3 &rhs)
94 | {
95 | return Vect3(scalar*rhs.v[0], scalar*rhs.v[1], scalar*rhs.v[2]);
96 | }
97 |
98 |
99 | extern const Vect3 Vect3X;
100 | extern const Vect3 Vect3Y;
101 | extern const Vect3 Vect3Z;
102 | extern const Vect3 Vect3negX;
103 | extern const Vect3 Vect3negY;
104 | extern const Vect3 Vect3negZ;
105 | extern const Vect3 Vect3Zero;
106 |
107 |
108 |
109 |
110 | #endif
--------------------------------------------------------------------------------
/widgets.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #include "system.h"
20 | #include "ndictionary.h"
21 | #include "md3gl.h"
22 | #include "md3view.h"
23 |
24 | void setVertex( Vec3 v, float f1, float f2, float f3 )
25 | {
26 | v[0] = f1;
27 | v[1] = f2;
28 | v[2] = f3;
29 | }
30 |
31 | void widget_AxisFaces( Vec3 *v )
32 | {
33 | glBegin( GL_TRIANGLES );
34 |
35 | glVertex3fv( v[0] ); glVertex3fv( v[2] ); glVertex3fv( v[3] );
36 | glVertex3fv( v[3] ); glVertex3fv( v[1] ); glVertex3fv( v[0] );
37 | glVertex3fv( v[4] ); glVertex3fv( v[5] ); glVertex3fv( v[7] );
38 | glVertex3fv( v[7] ); glVertex3fv( v[6] ); glVertex3fv( v[4] );
39 | glVertex3fv( v[0] ); glVertex3fv( v[1] ); glVertex3fv( v[5] );
40 | glVertex3fv( v[5] ); glVertex3fv( v[4] ); glVertex3fv( v[0] );
41 | glVertex3fv( v[1] ); glVertex3fv( v[3] ); glVertex3fv( v[7] );
42 | glVertex3fv( v[7] ); glVertex3fv( v[5] ); glVertex3fv( v[1] );
43 | glVertex3fv( v[3] ); glVertex3fv( v[2] ); glVertex3fv( v[6] );
44 | glVertex3fv( v[6] ); glVertex3fv( v[7] ); glVertex3fv( v[3] );
45 | glVertex3fv( v[2] ); glVertex3fv( v[0] ); glVertex3fv( v[4] );
46 | glVertex3fv( v[4] ); glVertex3fv( v[6] ); glVertex3fv( v[2] );
47 |
48 | glEnd();
49 | }
50 |
51 |
52 | void widget_Axis()
53 | {
54 | Vec3 v[8];
55 |
56 | setVertex( v[0], -1.0000, 1.0000, 0.0000 );
57 | setVertex( v[1], 1.0000, 1.0000, 0.0000 );
58 | setVertex( v[2], -1.0000, 1.0000, 10.0000 );
59 | setVertex( v[3], 1.0000, 1.0000, 10.0000 );
60 | setVertex( v[4], -1.0000, -1.0000, 0.0000 );
61 | setVertex( v[5], 1.0000, -1.0000, 0.0000 );
62 | setVertex( v[6], -1.0000, -1.0000, 10.0000 );
63 | setVertex( v[7], 1.0000, -1.0000, 10.0000 );
64 |
65 | glColor3f( 0, 0, 1 );
66 | widget_AxisFaces( v );
67 |
68 | setVertex( v[0], -1.0000, 0.0000, 1.0000 );
69 | setVertex( v[1], 1.0000, 0.0000, 1.0000 );
70 | setVertex( v[2], -1.0000, 10.0000, 1.0000 );
71 | setVertex( v[3], 1.0000, 10.0000, 1.0000 );
72 | setVertex( v[4], -1.0000, 0.0000, -1.0000 );
73 | setVertex( v[5], 1.0000, 0.0000, -1.0000 );
74 | setVertex( v[6], -1.0000, 10.0000, -1.0000 );
75 | setVertex( v[7], 1.0000, 10.0000, -1.0000 );
76 |
77 | glColor3f( 0, 1, 0 );
78 | widget_AxisFaces( v );
79 |
80 | setVertex( v[0], 0.0000, -1.0000, 1.0000 );
81 | setVertex( v[1], 0.0000, 1.0000, 1.0000 );
82 | setVertex( v[2], 10.0000, -1.0000, 1.0000 );
83 | setVertex( v[3], 10.0000, 1.0000, 1.0000 );
84 | setVertex( v[4], 0.0000, -1.0000, -1.0000 );
85 | setVertex( v[5], 0.0000, 1.0000, -1.0000 );
86 | setVertex( v[6], 10.0000, -1.0000, -1.0000 );
87 | setVertex( v[7], 10.0000, 1.0000, -1.0000 );
88 |
89 | glColor3f( 1, 0, 0 );
90 | widget_AxisFaces( v );
91 | }
92 |
--------------------------------------------------------------------------------
/win32_treeview.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | This program is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this program. If not, see .
16 |
17 | */
18 |
19 | #ifdef WIN32
20 | #include
21 | #endif
22 |
23 | class Core
24 | {
25 | public:
26 | Core( int argc, char **argv );
27 |
28 | void exec();
29 | private:
30 | };
31 |
32 | class Event;
33 |
34 | class Window
35 | {
36 | public:
37 | Window( Window *parent=NULL, int style=0, const char *label=NULL );
38 | virtual ~Window();
39 |
40 | void setGeometry( int x, int y, int w, int h );
41 |
42 | virtual void repaint();
43 | virtual void event( Event *evt );
44 |
45 | private:
46 |
47 | #ifdef WIN32
48 | HWND g_hwnd;
49 | HDC g_hdc;
50 | #endif
51 |
52 | };
53 |
54 | class WindowTreeView
55 | {
56 | public:
57 | private:
58 | };
--------------------------------------------------------------------------------
/zlib/adler32.c:
--------------------------------------------------------------------------------
1 | /* adler32.c -- compute the Adler-32 checksum of a data stream
2 | * Copyright (C) 1995-1998 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id$ */
7 |
8 | #include "../zlib/zlib.h"
9 |
10 | #define BASE 65521L /* largest prime smaller than 65536 */
11 | #define NMAX 5552
12 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
13 |
14 | #define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
15 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
16 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
17 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
18 | #define DO16(buf) DO8(buf,0); DO8(buf,8);
19 |
20 | /* ========================================================================= */
21 | uLong ZEXPORT adler32(adler, buf, len)
22 | uLong adler;
23 | const Bytef *buf;
24 | uInt len;
25 | {
26 | unsigned long s1 = adler & 0xffff;
27 | unsigned long s2 = (adler >> 16) & 0xffff;
28 | int k;
29 |
30 | if (buf == Z_NULL) return 1L;
31 |
32 | while (len > 0) {
33 | k = len < NMAX ? len : NMAX;
34 | len -= k;
35 | while (k >= 16) {
36 | DO16(buf);
37 | buf += 16;
38 | k -= 16;
39 | }
40 | if (k != 0) do {
41 | s1 += *buf++;
42 | s2 += s1;
43 | } while (--k);
44 | s1 %= BASE;
45 | s2 %= BASE;
46 | }
47 | return (s2 << 16) | s1;
48 | }
49 |
--------------------------------------------------------------------------------
/zlib/crc32.cpp:
--------------------------------------------------------------------------------
1 | /* crc32.c -- compute the CRC-32 of a data stream
2 | * Copyright (C) 1995-1998 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id: unzip.c,v 1.2 1999/09/07 20:51:25 zoid Exp $ */
7 |
8 | /* ========================================================================
9 | * Table of CRC-32's of all single-byte values (made by make_crc_table)
10 | */
11 | #include "../zlib/zlib.h"
12 |
13 | static const uLong crc_table[256] = {
14 | 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
15 | 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
16 | 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
17 | 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
18 | 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
19 | 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
20 | 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
21 | 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
22 | 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
23 | 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
24 | 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
25 | 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
26 | 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
27 | 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
28 | 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
29 | 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
30 | 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
31 | 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
32 | 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
33 | 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
34 | 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
35 | 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
36 | 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
37 | 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
38 | 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
39 | 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
40 | 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
41 | 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
42 | 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
43 | 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
44 | 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
45 | 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
46 | 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
47 | 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
48 | 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
49 | 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
50 | 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
51 | 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
52 | 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
53 | 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
54 | 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
55 | 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
56 | 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
57 | 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
58 | 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
59 | 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
60 | 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
61 | 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
62 | 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
63 | 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
64 | 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
65 | 0x2d02ef8dL
66 | };
67 |
68 | /* =========================================================================
69 | * This function can be used by asm versions of crc32()
70 | */
71 | const uLong * get_crc_table()
72 | {
73 | return (const uLong *)crc_table;
74 | }
75 |
76 | /* ========================================================================= */
77 | #define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
78 | #define DO2(buf) DO1(buf); DO1(buf);
79 | #define DO4(buf) DO2(buf); DO2(buf);
80 | #define DO8(buf) DO4(buf); DO4(buf);
81 |
82 | /* ========================================================================= */
83 | uLong crc32(uLong crc, const Byte *buf, uInt len)
84 | {
85 | if (buf == Z_NULL) return 0L;
86 | crc = crc ^ 0xffffffffL;
87 | while (len >= 8)
88 | {
89 | DO8(buf);
90 | len -= 8;
91 | }
92 | if (len) do {
93 | DO1(buf);
94 | } while (--len);
95 | return crc ^ 0xffffffffL;
96 | }
97 |
98 | // end
--------------------------------------------------------------------------------
/zlib/infblock.h:
--------------------------------------------------------------------------------
1 | /* infblock.h -- header to use infblock.c
2 | * Copyright (C) 1995-1998 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | struct inflate_blocks_state;
12 | typedef struct inflate_blocks_state FAR inflate_blocks_statef;
13 |
14 | extern inflate_blocks_statef * inflate_blocks_new OF((
15 | z_streamp z,
16 | check_func c, /* check function */
17 | uInt w)); /* window size */
18 |
19 | extern int inflate_blocks OF((
20 | inflate_blocks_statef *,
21 | z_streamp ,
22 | int)); /* initial return code */
23 |
24 | extern void inflate_blocks_reset OF((
25 | inflate_blocks_statef *,
26 | z_streamp ,
27 | uLongf *)); /* check value on output */
28 |
29 | extern int inflate_blocks_free OF((
30 | inflate_blocks_statef *,
31 | z_streamp));
32 |
33 | extern void inflate_set_dictionary OF((
34 | inflate_blocks_statef *s,
35 | const Bytef *d, /* dictionary */
36 | uInt n)); /* dictionary length */
37 |
38 | extern int inflate_blocks_sync_point OF((
39 | inflate_blocks_statef *s));
40 |
--------------------------------------------------------------------------------
/zlib/infcodes.h:
--------------------------------------------------------------------------------
1 | /* infcodes.h -- header to use infcodes.c
2 | * Copyright (C) 1995-1998 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | struct inflate_codes_state;
12 | typedef struct inflate_codes_state FAR inflate_codes_statef;
13 |
14 | extern inflate_codes_statef *inflate_codes_new OF((
15 | uInt, uInt,
16 | inflate_huft *, inflate_huft *,
17 | z_streamp ));
18 |
19 | extern int inflate_codes OF((
20 | inflate_blocks_statef *,
21 | z_streamp ,
22 | int));
23 |
24 | extern void inflate_codes_free OF((
25 | inflate_codes_statef *,
26 | z_streamp ));
27 |
28 |
--------------------------------------------------------------------------------
/zlib/inffast.c:
--------------------------------------------------------------------------------
1 | /* inffast.c -- process literals and length/distance pairs fast
2 | * Copyright (C) 1995-1998 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | #include "zutil.h"
7 | #include "inftrees.h"
8 | #include "infblock.h"
9 | #include "infcodes.h"
10 | #include "infutil.h"
11 | #include "inffast.h"
12 |
13 | struct inflate_codes_state {int dummy;}; /* for buggy compilers */
14 |
15 | /* simplify the use of the inflate_huft type with some defines */
16 | #define exop word.what.Exop
17 | #define bits word.what.Bits
18 |
19 | /* macros for bit input with no checking and for returning unused bytes */
20 | #define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<avail_in-n;c=(k>>3)>3:c;n+=c;p-=c;k-=c<<3;}
22 |
23 | /* Called with number of bytes left to write in window at least 258
24 | (the maximum string length) and number of input bytes available
25 | at least ten. The ten bytes are six bytes for the longest length/
26 | distance pair plus four bytes for overloading the bit buffer. */
27 |
28 | int inflate_fast(bl, bd, tl, td, s, z)
29 | uInt bl, bd;
30 | inflate_huft *tl;
31 | inflate_huft *td; /* need separate declaration for Borland C++ */
32 | inflate_blocks_statef *s;
33 | z_streamp z;
34 | {
35 | inflate_huft *t; /* temporary pointer */
36 | uInt e; /* extra bits or operation */
37 | uLong b; /* bit buffer */
38 | uInt k; /* bits in bit buffer */
39 | Bytef *p; /* input data pointer */
40 | uInt n; /* bytes available there */
41 | Bytef *q; /* output window write pointer */
42 | uInt m; /* bytes to end of window or read pointer */
43 | uInt ml; /* mask for literal/length tree */
44 | uInt md; /* mask for distance tree */
45 | uInt c; /* bytes to copy */
46 | uInt d; /* distance back to copy from */
47 | Bytef *r; /* copy source pointer */
48 |
49 | /* load input, output, bit values */
50 | LOAD
51 |
52 | /* initialize masks */
53 | ml = inflate_mask[bl];
54 | md = inflate_mask[bd];
55 |
56 | /* do until not enough input or output space for fast loop */
57 | do { /* assume called with m >= 258 && n >= 10 */
58 | /* get literal/length code */
59 | GRABBITS(20) /* max bits for literal/length code */
60 | if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
61 | {
62 | DUMPBITS(t->bits)
63 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
64 | "inflate: * literal '%c'\n" :
65 | "inflate: * literal 0x%02x\n", t->base));
66 | *q++ = (Byte)t->base;
67 | m--;
68 | continue;
69 | }
70 | do {
71 | DUMPBITS(t->bits)
72 | if (e & 16)
73 | {
74 | /* get extra bits for length */
75 | e &= 15;
76 | c = t->base + ((uInt)b & inflate_mask[e]);
77 | DUMPBITS(e)
78 | Tracevv((stderr, "inflate: * length %u\n", c));
79 |
80 | /* decode distance base of block to copy */
81 | GRABBITS(15); /* max bits for distance code */
82 | e = (t = td + ((uInt)b & md))->exop;
83 | do {
84 | DUMPBITS(t->bits)
85 | if (e & 16)
86 | {
87 | /* get extra bits to add to distance base */
88 | e &= 15;
89 | GRABBITS(e) /* get extra bits (up to 13) */
90 | d = t->base + ((uInt)b & inflate_mask[e]);
91 | DUMPBITS(e)
92 | Tracevv((stderr, "inflate: * distance %u\n", d));
93 |
94 | /* do the copy */
95 | m -= c;
96 | if ((uInt)(q - s->window) >= d) /* offset before dest */
97 | { /* just copy */
98 | r = q - d;
99 | *q++ = *r++; c--; /* minimum count is three, */
100 | *q++ = *r++; c--; /* so unroll loop a little */
101 | }
102 | else /* else offset after destination */
103 | {
104 | e = d - (uInt)(q - s->window); /* bytes from offset to end */
105 | r = s->end - e; /* pointer to offset */
106 | if (c > e) /* if source crosses, */
107 | {
108 | c -= e; /* copy to end of window */
109 | do {
110 | *q++ = *r++;
111 | } while (--e);
112 | r = s->window; /* copy rest from start of window */
113 | }
114 | }
115 | do { /* copy all or what's left */
116 | *q++ = *r++;
117 | } while (--c);
118 | break;
119 | }
120 | else if ((e & 64) == 0)
121 | {
122 | t += t->base;
123 | e = (t += ((uInt)b & inflate_mask[e]))->exop;
124 | }
125 | else
126 | {
127 | z->msg = (char*)"invalid distance code";
128 | UNGRAB
129 | UPDATE
130 | return Z_DATA_ERROR;
131 | }
132 | } while (1);
133 | break;
134 | }
135 | if ((e & 64) == 0)
136 | {
137 | t += t->base;
138 | if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)
139 | {
140 | DUMPBITS(t->bits)
141 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
142 | "inflate: * literal '%c'\n" :
143 | "inflate: * literal 0x%02x\n", t->base));
144 | *q++ = (Byte)t->base;
145 | m--;
146 | break;
147 | }
148 | }
149 | else if (e & 32)
150 | {
151 | Tracevv((stderr, "inflate: * end of block\n"));
152 | UNGRAB
153 | UPDATE
154 | return Z_STREAM_END;
155 | }
156 | else
157 | {
158 | z->msg = (char*)"invalid literal/length code";
159 | UNGRAB
160 | UPDATE
161 | return Z_DATA_ERROR;
162 | }
163 | } while (1);
164 | } while (m >= 258 && n >= 10);
165 |
166 | /* not enough input or output--restore pointers and return */
167 | UNGRAB
168 | UPDATE
169 | return Z_OK;
170 | }
171 |
--------------------------------------------------------------------------------
/zlib/inffast.h:
--------------------------------------------------------------------------------
1 | /* inffast.h -- header to use inffast.c
2 | * Copyright (C) 1995-1998 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | extern int inflate_fast OF((
12 | uInt,
13 | uInt,
14 | inflate_huft *,
15 | inflate_huft *,
16 | inflate_blocks_statef *,
17 | z_streamp ));
18 |
--------------------------------------------------------------------------------
/zlib/inftrees.h:
--------------------------------------------------------------------------------
1 | /* inftrees.h -- header to use inftrees.c
2 | * Copyright (C) 1995-1998 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | /* Huffman code lookup table entry--this entry is four bytes for machines
12 | that have 16-bit pointers (e.g. PC's in the small or medium model). */
13 |
14 | typedef struct inflate_huft_s FAR inflate_huft;
15 |
16 | struct inflate_huft_s {
17 | union {
18 | struct {
19 | Byte Exop; /* number of extra bits or operation */
20 | Byte Bits; /* number of bits in this code or subcode */
21 | } what;
22 | uInt pad; /* pad structure to a power of 2 (4 bytes for */
23 | } word; /* 16-bit, 8 bytes for 32-bit int's) */
24 | uInt base; /* literal, length base, distance base,
25 | or table offset */
26 | };
27 |
28 | /* Maximum size of dynamic tree. The maximum found in a long but non-
29 | exhaustive search was 1004 huft structures (850 for length/literals
30 | and 154 for distances, the latter actually the result of an
31 | exhaustive search). The actual maximum is not known, but the
32 | value below is more than safe. */
33 | #define MANY 1440
34 |
35 | extern int inflate_trees_bits OF((
36 | uIntf *, /* 19 code lengths */
37 | uIntf *, /* bits tree desired/actual depth */
38 | inflate_huft * FAR *, /* bits tree result */
39 | inflate_huft *, /* space for trees */
40 | z_streamp)); /* for messages */
41 |
42 | extern int inflate_trees_dynamic OF((
43 | uInt, /* number of literal/length codes */
44 | uInt, /* number of distance codes */
45 | uIntf *, /* that many (total) code lengths */
46 | uIntf *, /* literal desired/actual bit depth */
47 | uIntf *, /* distance desired/actual bit depth */
48 | inflate_huft * FAR *, /* literal/length tree result */
49 | inflate_huft * FAR *, /* distance tree result */
50 | inflate_huft *, /* space for trees */
51 | z_streamp)); /* for messages */
52 |
53 | extern int inflate_trees_fixed OF((
54 | uIntf *, /* literal desired/actual bit depth */
55 | uIntf *, /* distance desired/actual bit depth */
56 | inflate_huft * FAR *, /* literal/length tree result */
57 | inflate_huft * FAR *, /* distance tree result */
58 | z_streamp)); /* for memory allocation */
59 |
--------------------------------------------------------------------------------
/zlib/infutil.c:
--------------------------------------------------------------------------------
1 | /* inflate_util.c -- data and routines common to blocks and codes
2 | * Copyright (C) 1995-1998 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | #include "zutil.h"
7 | #include "infblock.h"
8 | #include "inftrees.h"
9 | #include "infcodes.h"
10 | #include "infutil.h"
11 |
12 | struct inflate_codes_state {int dummy;}; /* for buggy compilers */
13 |
14 | /* And'ing with mask[n] masks the lower n bits */
15 | uInt inflate_mask[17] = {
16 | 0x0000,
17 | 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
18 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
19 | };
20 |
21 |
22 | /* copy as much as possible from the sliding window to the output area */
23 | int inflate_flush(s, z, r)
24 | inflate_blocks_statef *s;
25 | z_streamp z;
26 | int r;
27 | {
28 | uInt n;
29 | Bytef *p;
30 | Bytef *q;
31 |
32 | /* local copies of source and destination pointers */
33 | p = z->next_out;
34 | q = s->read;
35 |
36 | /* compute number of bytes to copy as far as end of window */
37 | n = (uInt)((q <= s->write ? s->write : s->end) - q);
38 | if (n > z->avail_out) n = z->avail_out;
39 | if (n && r == Z_BUF_ERROR) r = Z_OK;
40 |
41 | /* update counters */
42 | z->avail_out -= n;
43 | z->total_out += n;
44 |
45 | /* update check information */
46 | if (s->checkfn != Z_NULL)
47 | z->adler = s->check = (*s->checkfn)(s->check, q, n);
48 |
49 | /* copy as far as end of window */
50 | zmemcpy(p, q, n);
51 | p += n;
52 | q += n;
53 |
54 | /* see if more to copy at beginning of window */
55 | if (q == s->end)
56 | {
57 | /* wrap pointers */
58 | q = s->window;
59 | if (s->write == s->end)
60 | s->write = s->window;
61 |
62 | /* compute bytes to copy */
63 | n = (uInt)(s->write - q);
64 | if (n > z->avail_out) n = z->avail_out;
65 | if (n && r == Z_BUF_ERROR) r = Z_OK;
66 |
67 | /* update counters */
68 | z->avail_out -= n;
69 | z->total_out += n;
70 |
71 | /* update check information */
72 | if (s->checkfn != Z_NULL)
73 | z->adler = s->check = (*s->checkfn)(s->check, q, n);
74 |
75 | /* copy */
76 | zmemcpy(p, q, n);
77 | p += n;
78 | q += n;
79 | }
80 |
81 | /* update pointers */
82 | z->next_out = p;
83 | s->read = q;
84 |
85 | /* done */
86 | return r;
87 | }
88 |
--------------------------------------------------------------------------------
/zlib/infutil.h:
--------------------------------------------------------------------------------
1 | /* infutil.h -- types and macros common to blocks and codes
2 | * Copyright (C) 1995-1998 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | #ifndef _INFUTIL_H
12 | #define _INFUTIL_H
13 |
14 | typedef enum {
15 | TYPE, /* get type bits (3, including end bit) */
16 | LENS, /* get lengths for stored */
17 | STORED, /* processing stored block */
18 | TABLE, /* get table lengths */
19 | BTREE, /* get bit lengths tree for a dynamic block */
20 | DTREE, /* get length, distance trees for a dynamic block */
21 | CODES, /* processing fixed or dynamic block */
22 | DRY, /* output remaining window bytes */
23 | DONE, /* finished last block, done */
24 | BAD} /* got a data error--stuck here */
25 | inflate_block_mode;
26 |
27 | /* inflate blocks semi-private state */
28 | struct inflate_blocks_state {
29 |
30 | /* mode */
31 | inflate_block_mode mode; /* current inflate_block mode */
32 |
33 | /* mode dependent information */
34 | union {
35 | uInt left; /* if STORED, bytes left to copy */
36 | struct {
37 | uInt table; /* table lengths (14 bits) */
38 | uInt index; /* index into blens (or border) */
39 | uIntf *blens; /* bit lengths of codes */
40 | uInt bb; /* bit length tree depth */
41 | inflate_huft *tb; /* bit length decoding tree */
42 | } trees; /* if DTREE, decoding info for trees */
43 | struct {
44 | inflate_codes_statef
45 | *codes;
46 | } decode; /* if CODES, current state */
47 | } sub; /* submode */
48 | uInt last; /* true if this block is the last block */
49 |
50 | /* mode independent information */
51 | uInt bitk; /* bits in bit buffer */
52 | uLong bitb; /* bit buffer */
53 | inflate_huft *hufts; /* single malloc for tree space */
54 | Bytef *window; /* sliding window */
55 | Bytef *end; /* one byte after sliding window */
56 | Bytef *read; /* window read pointer */
57 | Bytef *write; /* window write pointer */
58 | check_func checkfn; /* check function */
59 | uLong check; /* check on output */
60 |
61 | };
62 |
63 |
64 | /* defines for inflate input/output */
65 | /* update pointers and return */
66 | #define UPDBITS {s->bitb=b;s->bitk=k;}
67 | #define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
68 | #define UPDOUT {s->write=q;}
69 | #define UPDATE {UPDBITS UPDIN UPDOUT}
70 | #define LEAVE {UPDATE return inflate_flush(s,z,r);}
71 | /* get bytes and bits */
72 | #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
73 | #define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
74 | #define NEXTBYTE (n--,*p++)
75 | #define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<>=(j);k-=(j);}
77 | /* output bytes */
78 | #define WAVAIL (uInt)(qread?s->read-q-1:s->end-q)
79 | #define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
80 | #define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
81 | #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
82 | #define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
83 | #define OUTBYTE(a) {*q++=(Byte)(a);m--;}
84 | /* load local pointers */
85 | #define LOAD {LOADIN LOADOUT}
86 |
87 | /* masks for lower bits (size given to avoid silly warnings with Visual C++) */
88 | extern uInt inflate_mask[17];
89 |
90 | /* copy as much as possible from the sliding window to the output area */
91 | extern int inflate_flush OF((
92 | inflate_blocks_statef *,
93 | z_streamp ,
94 | int));
95 |
96 | struct internal_state {int dummy;}; /* for buggy compilers */
97 |
98 | #endif
99 |
--------------------------------------------------------------------------------
/zlib/zutil.c:
--------------------------------------------------------------------------------
1 | /* zutil.c -- target dependent utility functions for the compression library
2 | * Copyright (C) 1995-1998 Jean-loup Gailly.
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id$ */
7 |
8 | #include "zutil.h"
9 |
10 | struct internal_state {int dummy;}; /* for buggy compilers */
11 |
12 | #ifndef STDC
13 | extern void exit OF((int));
14 | #endif
15 |
16 | const char *z_errmsg[10] = {
17 | "need dictionary", /* Z_NEED_DICT 2 */
18 | "stream end", /* Z_STREAM_END 1 */
19 | "", /* Z_OK 0 */
20 | "file error", /* Z_ERRNO (-1) */
21 | "stream error", /* Z_STREAM_ERROR (-2) */
22 | "data error", /* Z_DATA_ERROR (-3) */
23 | "insufficient memory", /* Z_MEM_ERROR (-4) */
24 | "buffer error", /* Z_BUF_ERROR (-5) */
25 | "incompatible version",/* Z_VERSION_ERROR (-6) */
26 | ""};
27 |
28 |
29 | const char * ZEXPORT zlibVersion()
30 | {
31 | return ZLIB_VERSION;
32 | }
33 |
34 | #ifdef DEBUG
35 |
36 | # ifndef verbose
37 | # define verbose 0
38 | # endif
39 | int z_verbose = verbose;
40 |
41 | void z_error (m)
42 | char *m;
43 | {
44 | fprintf(stderr, "%s\n", m);
45 | exit(1);
46 | }
47 | #endif
48 |
49 | /* exported to allow conversion of error code to string for compress() and
50 | * uncompress()
51 | */
52 | const char * ZEXPORT zError(err)
53 | int err;
54 | {
55 | return ERR_MSG(err);
56 | }
57 |
58 |
59 | #ifndef HAVE_MEMCPY
60 |
61 | void zmemcpy(dest, source, len)
62 | Bytef* dest;
63 | const Bytef* source;
64 | uInt len;
65 | {
66 | if (len == 0) return;
67 | do {
68 | *dest++ = *source++; /* ??? to be unrolled */
69 | } while (--len != 0);
70 | }
71 |
72 | int zmemcmp(s1, s2, len)
73 | const Bytef* s1;
74 | const Bytef* s2;
75 | uInt len;
76 | {
77 | uInt j;
78 |
79 | for (j = 0; j < len; j++) {
80 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
81 | }
82 | return 0;
83 | }
84 |
85 | void zmemzero(dest, len)
86 | Bytef* dest;
87 | uInt len;
88 | {
89 | if (len == 0) return;
90 | do {
91 | *dest++ = 0; /* ??? to be unrolled */
92 | } while (--len != 0);
93 | }
94 | #endif
95 |
96 | #ifdef __TURBOC__
97 | #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
98 | /* Small and medium model in Turbo C are for now limited to near allocation
99 | * with reduced MAX_WBITS and MAX_MEM_LEVEL
100 | */
101 | # define MY_ZCALLOC
102 |
103 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
104 | * and farmalloc(64K) returns a pointer with an offset of 8, so we
105 | * must fix the pointer. Warning: the pointer must be put back to its
106 | * original form in order to free it, use zcfree().
107 | */
108 |
109 | #define MAX_PTR 10
110 | /* 10*64K = 640K */
111 |
112 | local int next_ptr = 0;
113 |
114 | typedef struct ptr_table_s {
115 | voidpf org_ptr;
116 | voidpf new_ptr;
117 | } ptr_table;
118 |
119 | local ptr_table table[MAX_PTR];
120 | /* This table is used to remember the original form of pointers
121 | * to large buffers (64K). Such pointers are normalized with a zero offset.
122 | * Since MSDOS is not a preemptive multitasking OS, this table is not
123 | * protected from concurrent access. This hack doesn't work anyway on
124 | * a protected system like OS/2. Use Microsoft C instead.
125 | */
126 |
127 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
128 | {
129 | voidpf buf = opaque; /* just to make some compilers happy */
130 | ulg bsize = (ulg)items*size;
131 |
132 | /* If we allocate less than 65520 bytes, we assume that farmalloc
133 | * will return a usable pointer which doesn't have to be normalized.
134 | */
135 | if (bsize < 65520L) {
136 | buf = farmalloc(bsize);
137 | if (*(ush*)&buf != 0) return buf;
138 | } else {
139 | buf = farmalloc(bsize + 16L);
140 | }
141 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
142 | table[next_ptr].org_ptr = buf;
143 |
144 | /* Normalize the pointer to seg:0 */
145 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
146 | *(ush*)&buf = 0;
147 | table[next_ptr++].new_ptr = buf;
148 | return buf;
149 | }
150 |
151 | void zcfree (voidpf opaque, voidpf ptr)
152 | {
153 | int n;
154 | if (*(ush*)&ptr != 0) { /* object < 64K */
155 | farfree(ptr);
156 | return;
157 | }
158 | /* Find the original pointer */
159 | for (n = 0; n < next_ptr; n++) {
160 | if (ptr != table[n].new_ptr) continue;
161 |
162 | farfree(table[n].org_ptr);
163 | while (++n < next_ptr) {
164 | table[n-1] = table[n];
165 | }
166 | next_ptr--;
167 | return;
168 | }
169 | ptr = opaque; /* just to make some compilers happy */
170 | Assert(0, "zcfree: ptr not found");
171 | }
172 | #endif
173 | #endif /* __TURBOC__ */
174 |
175 |
176 | #if defined(M_I86) && !defined(__32BIT__)
177 | /* Microsoft C in 16-bit mode */
178 |
179 | # define MY_ZCALLOC
180 |
181 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
182 | # define _halloc halloc
183 | # define _hfree hfree
184 | #endif
185 |
186 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
187 | {
188 | if (opaque) opaque = 0; /* to make compiler happy */
189 | return _halloc((long)items, size);
190 | }
191 |
192 | void zcfree (voidpf opaque, voidpf ptr)
193 | {
194 | if (opaque) opaque = 0; /* to make compiler happy */
195 | _hfree(ptr);
196 | }
197 |
198 | #endif /* MSC */
199 |
200 |
201 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */
202 |
203 | #ifndef STDC
204 | extern voidp calloc OF((uInt items, uInt size));
205 | extern void free OF((voidpf ptr));
206 | #endif
207 |
208 | voidpf zcalloc (opaque, items, size)
209 | voidpf opaque;
210 | unsigned items;
211 | unsigned size;
212 | {
213 | if (opaque) items += size - size; /* make compiler happy */
214 | return (voidpf)calloc(items, size);
215 | }
216 |
217 | void zcfree (opaque, ptr)
218 | voidpf opaque;
219 | voidpf ptr;
220 | {
221 | free(ptr);
222 | if (opaque) return; /* make compiler happy */
223 | }
224 |
225 | #endif /* MY_ZCALLOC */
226 |
--------------------------------------------------------------------------------
/zlib/zutil.h:
--------------------------------------------------------------------------------
1 | /* zutil.h -- internal interface and configuration of the compression library
2 | * Copyright (C) 1995-1998 Jean-loup Gailly.
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | /* @(#) $Id$ */
12 |
13 | #ifndef _Z_UTIL_H
14 | #define _Z_UTIL_H
15 |
16 | #include "zlib.h"
17 |
18 | #ifdef STDC
19 | # include
20 | # include
21 | # include
22 | #endif
23 | #ifdef NO_ERRNO_H
24 | extern int errno;
25 | #else
26 | # include
27 | #endif
28 |
29 | #ifndef local
30 | # define local static
31 | #endif
32 | /* compile with -Dlocal if your debugger can't find static symbols */
33 |
34 | typedef unsigned char uch;
35 | typedef uch FAR uchf;
36 | typedef unsigned short ush;
37 | typedef ush FAR ushf;
38 | typedef unsigned long ulg;
39 |
40 | extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
41 | /* (size given to avoid silly warnings with Visual C++) */
42 |
43 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
44 |
45 | #define ERR_RETURN(strm,err) \
46 | return (strm->msg = (char*)ERR_MSG(err), (err))
47 | /* To be used only when the state is known to be valid */
48 |
49 | /* common constants */
50 |
51 | #ifndef DEF_WBITS
52 | # define DEF_WBITS MAX_WBITS
53 | #endif
54 | /* default windowBits for decompression. MAX_WBITS is for compression only */
55 |
56 | #if MAX_MEM_LEVEL >= 8
57 | # define DEF_MEM_LEVEL 8
58 | #else
59 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL
60 | #endif
61 | /* default memLevel */
62 |
63 | #define STORED_BLOCK 0
64 | #define STATIC_TREES 1
65 | #define DYN_TREES 2
66 | /* The three kinds of block type */
67 |
68 | #define MIN_MATCH 3
69 | #define MAX_MATCH 258
70 | /* The minimum and maximum match lengths */
71 |
72 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
73 |
74 | /* target dependencies */
75 |
76 | #ifdef MSDOS
77 | # define OS_CODE 0x00
78 | # if defined(__TURBOC__) || defined(__BORLANDC__)
79 | # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
80 | /* Allow compilation with ANSI keywords only enabled */
81 | void _Cdecl farfree( void *block );
82 | void *_Cdecl farmalloc( unsigned long nbytes );
83 | # else
84 | # include
85 | # endif
86 | # else /* MSC or DJGPP */
87 | # include
88 | # endif
89 | #endif
90 |
91 | #ifdef OS2
92 | # define OS_CODE 0x06
93 | #endif
94 |
95 | #ifdef WIN32 /* Window 95 & Windows NT */
96 | # define OS_CODE 0x0b
97 | #endif
98 |
99 | #if defined(VAXC) || defined(VMS)
100 | # define OS_CODE 0x02
101 | # define F_OPEN(name, mode) \
102 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
103 | #endif
104 |
105 | #ifdef AMIGA
106 | # define OS_CODE 0x01
107 | #endif
108 |
109 | #if defined(ATARI) || defined(atarist)
110 | # define OS_CODE 0x05
111 | #endif
112 |
113 | #if defined(MACOS) || defined(TARGET_OS_MAC)
114 | # define OS_CODE 0x07
115 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
116 | # include /* for fdopen */
117 | # else
118 | # ifndef fdopen
119 | # define fdopen(fd,mode) NULL /* No fdopen() */
120 | # endif
121 | # endif
122 | #endif
123 |
124 | #ifdef __50SERIES /* Prime/PRIMOS */
125 | # define OS_CODE 0x0F
126 | #endif
127 |
128 | #ifdef TOPS20
129 | # define OS_CODE 0x0a
130 | #endif
131 |
132 | #if defined(_BEOS_) || defined(RISCOS)
133 | # define fdopen(fd,mode) NULL /* No fdopen() */
134 | #endif
135 |
136 | #if (defined(_MSC_VER) && (_MSC_VER > 600))
137 | # define fdopen(fd,type) _fdopen(fd,type)
138 | #endif
139 |
140 |
141 | /* Common defaults */
142 |
143 | #ifndef OS_CODE
144 | # define OS_CODE 0x03 /* assume Unix */
145 | #endif
146 |
147 | #ifndef F_OPEN
148 | # define F_OPEN(name, mode) fopen((name), (mode))
149 | #endif
150 |
151 | /* functions */
152 |
153 | #ifdef HAVE_STRERROR
154 | extern char *strerror OF((int));
155 | # define zstrerror(errnum) strerror(errnum)
156 | #else
157 | # define zstrerror(errnum) ""
158 | #endif
159 |
160 | #if defined(pyr)
161 | # define NO_MEMCPY
162 | #endif
163 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
164 | /* Use our own functions for small and medium model with MSC <= 5.0.
165 | * You may have to use the same strategy for Borland C (untested).
166 | * The __SC__ check is for Symantec.
167 | */
168 | # define NO_MEMCPY
169 | #endif
170 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
171 | # define HAVE_MEMCPY
172 | #endif
173 | #ifdef HAVE_MEMCPY
174 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
175 | # define zmemcpy _fmemcpy
176 | # define zmemcmp _fmemcmp
177 | # define zmemzero(dest, len) _fmemset(dest, 0, len)
178 | # else
179 | # define zmemcpy memcpy
180 | # define zmemcmp memcmp
181 | # define zmemzero(dest, len) memset(dest, 0, len)
182 | # endif
183 | #else
184 | extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
185 | extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
186 | extern void zmemzero OF((Bytef* dest, uInt len));
187 | #endif
188 |
189 | /* Diagnostic functions */
190 | #ifdef DEBUG
191 | # include
192 | extern int z_verbose;
193 | extern void z_error OF((char *m));
194 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
195 | # define Trace(x) {if (z_verbose>=0) fprintf x ;}
196 | # define Tracev(x) {if (z_verbose>0) fprintf x ;}
197 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
198 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
199 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
200 | #else
201 | # define Assert(cond,msg)
202 | # define Trace(x)
203 | # define Tracev(x)
204 | # define Tracevv(x)
205 | # define Tracec(c,x)
206 | # define Tracecv(c,x)
207 | #endif
208 |
209 |
210 | typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
211 | uInt len));
212 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
213 | void zcfree OF((voidpf opaque, voidpf ptr));
214 |
215 | #define ZALLOC(strm, items, size) \
216 | (*((strm)->zalloc))((strm)->opaque, (items), (size))
217 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
218 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
219 |
220 | #endif /* _Z_UTIL_H */
221 |
--------------------------------------------------------------------------------