1 | /* ************************************************************************** */
|
---|
2 | /* * For conditions of distribution and use, * */
|
---|
3 | /* * see copyright notice in libmng.h * */
|
---|
4 | /* ************************************************************************** */
|
---|
5 | /* * * */
|
---|
6 | /* * project : libmng * */
|
---|
7 | /* * file : libmng_error.c copyright (c) 2000 G.Juyn * */
|
---|
8 | /* * version : 1.0.2 * */
|
---|
9 | /* * * */
|
---|
10 | /* * purpose : Error routines (implementation) * */
|
---|
11 | /* * * */
|
---|
12 | /* * author : G.Juyn * */
|
---|
13 | /* * web : http://www.3-t.com * */
|
---|
14 | /* * email : mailto:info@3-t.com * */
|
---|
15 | /* * * */
|
---|
16 | /* * comment : implementation of the general error handling routines * */
|
---|
17 | /* * * */
|
---|
18 | /* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */
|
---|
19 | /* * - changed strict-ANSI stuff * */
|
---|
20 | /* * * */
|
---|
21 | /* * 0.5.2 - 05/23/2000 - G.Juyn * */
|
---|
22 | /* * - added error telltaling * */
|
---|
23 | /* * 0.5.2 - 05/30/2000 - G.Juyn * */
|
---|
24 | /* * - added errorstrings for delta-image processing * */
|
---|
25 | /* * 0.5.2 - 05/31/2000 - G.Juyn * */
|
---|
26 | /* * - fixed up punctuation (contributed by Tim Rowley) * */
|
---|
27 | /* * 0.5.2 - 06/06/2000 - G.Juyn * */
|
---|
28 | /* * - added errorstring for delayed buffer-processing * */
|
---|
29 | /* * * */
|
---|
30 | /* * 0.9.1 - 07/06/2000 - G.Juyn * */
|
---|
31 | /* * - added MNG_NEEDTIMERWAIT errorstring * */
|
---|
32 | /* * 0.9.1 - 07/15/2000 - G.Juyn * */
|
---|
33 | /* * - added NEEDSECTIONWAIT errorstring * */
|
---|
34 | /* * - added macro + routine to set returncode without * */
|
---|
35 | /* * calling error callback * */
|
---|
36 | /* * 0.9.1 - 07/19/2000 - G.Juyn * */
|
---|
37 | /* * - added errorstring for updatemngheader if not a MNG * */
|
---|
38 | /* * * */
|
---|
39 | /* * 0.9.2 - 08/05/2000 - G.Juyn * */
|
---|
40 | /* * - changed file-prefixes * */
|
---|
41 | /* * * */
|
---|
42 | /* * 0.9.3 - 08/09/2000 - G.Juyn * */
|
---|
43 | /* * - added check for simplicity-bits in MHDR * */
|
---|
44 | /* * 0.9.3 - 10/11/2000 - G.Juyn * */
|
---|
45 | /* * - fixed processing of unknown critical chunks * */
|
---|
46 | /* * - added support for nEED * */
|
---|
47 | /* * 0.9.3 - 10/20/2000 - G.Juyn * */
|
---|
48 | /* * - added errorcode for delayed delta-processing * */
|
---|
49 | /* * * */
|
---|
50 | /* * 0.9.4 - 1/18/2001 - G.Juyn * */
|
---|
51 | /* * - added errorcode for MAGN methods * */
|
---|
52 | /* * * */
|
---|
53 | /* * 1.0.2 - 06/23/2001 - G.Juyn * */
|
---|
54 | /* * - added optimization option for MNG-video playback * */
|
---|
55 | /* * * */
|
---|
56 | /* ************************************************************************** */
|
---|
57 |
|
---|
58 | #include "libmng.h"
|
---|
59 | #include "libmng_data.h"
|
---|
60 | #include "libmng_error.h"
|
---|
61 | #include "libmng_trace.h"
|
---|
62 | #ifdef __BORLANDC__
|
---|
63 | #pragma hdrstop
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | #if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)
|
---|
67 | #pragma option -A /* force ANSI-C */
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | /* ************************************************************************** */
|
---|
71 |
|
---|
72 | #ifdef MNG_INCLUDE_ERROR_STRINGS
|
---|
73 | mng_error_entry error_table [] =
|
---|
74 | {
|
---|
75 | {MNG_NOERROR, "No error"},
|
---|
76 | {MNG_OUTOFMEMORY, "Out of memory"},
|
---|
77 | {MNG_INVALIDHANDLE, "The handle is invalid"},
|
---|
78 | {MNG_NOCALLBACK, "A required callback is not defined"},
|
---|
79 | {MNG_UNEXPECTEDEOF, "Encountered unexpected end-of-file"},
|
---|
80 | {MNG_ZLIBERROR, "zlib encountered an error"},
|
---|
81 | {MNG_JPEGERROR, "ijgsrc6b encountered an error"},
|
---|
82 | {MNG_LCMSERROR, "lcms encountered an error"},
|
---|
83 | {MNG_NOOUTPUTPROFILE, "No output-profile defined for CMS"},
|
---|
84 | {MNG_NOSRGBPROFILE, "No sRGB-profile defined for CMS"},
|
---|
85 | {MNG_BUFOVERFLOW, "Internal buffer-overflow"},
|
---|
86 | {MNG_FUNCTIONINVALID, "Function is invalid at this point"},
|
---|
87 | {MNG_OUTPUTERROR, "Writing was unsuccessful; disk full?"},
|
---|
88 | {MNG_JPEGBUFTOOSMALL, "Internal buffer for JPEG processing too small"},
|
---|
89 | {MNG_NEEDMOREDATA, "Reading suspended; waiting for I/O to catch up"},
|
---|
90 | {MNG_NEEDTIMERWAIT, "Timer suspension; normal animation delay"},
|
---|
91 | {MNG_NEEDSECTIONWAIT, "SEEK suspension; application decides"},
|
---|
92 | {MNG_LOOPWITHCACHEOFF, "LOOP encountered when playback cache is turned off"},
|
---|
93 |
|
---|
94 | {MNG_APPIOERROR, "Application signalled I/O error"},
|
---|
95 | {MNG_APPTIMERERROR, "Application signalled timing error"},
|
---|
96 | {MNG_APPCMSERROR, "Application signalled CMS error"},
|
---|
97 | {MNG_APPMISCERROR, "Application signalled an error"},
|
---|
98 | {MNG_APPTRACEABORT, "Application signalled error during trace-callback"},
|
---|
99 |
|
---|
100 | {MNG_INTERNALERROR, "Internal error in libmng"},
|
---|
101 |
|
---|
102 | {MNG_INVALIDSIG, "The signature is invalid"},
|
---|
103 | {MNG_INVALIDCRC, "The CRC for this chunk is invalid"},
|
---|
104 | {MNG_INVALIDLENGTH, "Chunk-length is invalid"},
|
---|
105 | {MNG_SEQUENCEERROR, "Chunk out of sequence"},
|
---|
106 | {MNG_CHUNKNOTALLOWED, "Chunk not allowed at this point"},
|
---|
107 | {MNG_MULTIPLEERROR, "Chunk cannot occur multiple times"},
|
---|
108 | {MNG_PLTEMISSING, "Missing PLTE chunk"},
|
---|
109 | {MNG_IDATMISSING, "Missing IDAT chunk(s)"},
|
---|
110 | {MNG_CANNOTBEEMPTY, "Chunk cannot be empty"},
|
---|
111 | {MNG_GLOBALLENGTHERR, "Global data length invalid"},
|
---|
112 | {MNG_INVALIDBITDEPTH, "The bit_depth is invalid"},
|
---|
113 | {MNG_INVALIDCOLORTYPE, "The color_type is invalid"},
|
---|
114 | {MNG_INVALIDCOMPRESS, "The compression_method is invalid"},
|
---|
115 | {MNG_INVALIDFILTER, "The filter_method or filter_type is invalid"},
|
---|
116 | {MNG_INVALIDINTERLACE, "The interlace_method is invalid"},
|
---|
117 | {MNG_NOTENOUGHIDAT, "There is not enough data in the IDAT chunk(s)"},
|
---|
118 | {MNG_PLTEINDEXERROR, "Palette-index out of bounds"},
|
---|
119 | {MNG_NULLNOTFOUND, "NULL separator not found"},
|
---|
120 | {MNG_KEYWORDNULL, "Keyword cannot be zero-length"},
|
---|
121 | {MNG_OBJECTUNKNOWN, "Object does not exist"},
|
---|
122 | {MNG_OBJECTEXISTS, "Object already exists"},
|
---|
123 | {MNG_TOOMUCHIDAT, "Too much data in IDAT chunk(s)"},
|
---|
124 | {MNG_INVSAMPLEDEPTH, "The sample_depth is invalid"},
|
---|
125 | {MNG_INVOFFSETSIZE, "The offset_type is invalid"},
|
---|
126 | {MNG_INVENTRYTYPE, "The entry_type is invalid"},
|
---|
127 | {MNG_ENDWITHNULL, "Chunk must not end with NULL byte"},
|
---|
128 | {MNG_INVIMAGETYPE, "The image_type is invalid"},
|
---|
129 | {MNG_INVDELTATYPE, "The delta_type is invalid"},
|
---|
130 | {MNG_INVALIDINDEX, "Index-value out of bounds"},
|
---|
131 | {MNG_TOOMUCHJDAT, "Too much data in JDAT chunk(s)"},
|
---|
132 | {MNG_JPEGPARMSERR, "JHDR parameters & JFIF-data do not match"},
|
---|
133 | {MNG_INVFILLMETHOD, "The fill_method is invalid"},
|
---|
134 | {MNG_OBJNOTCONCRETE, "Target object for DHDR must be concrete"},
|
---|
135 | {MNG_TARGETNOALPHA, "Target object must have alpha-channel"},
|
---|
136 | {MNG_MNGTOOCOMPLEX, "MHDR simplicity indicates unsupported feature(s)"},
|
---|
137 | {MNG_UNKNOWNCRITICAL, "Unknown critical chunk encountered"},
|
---|
138 | {MNG_UNSUPPORTEDNEED, "Requested nEED resources are not supported"},
|
---|
139 | {MNG_INVALIDDELTA, "The delta operation is invalid (mismatched color_types?)"},
|
---|
140 | {MNG_INVALIDMETHOD, "Method is invalid"},
|
---|
141 |
|
---|
142 | {MNG_INVALIDCNVSTYLE, "Canvas_style is invalid"},
|
---|
143 | {MNG_WRONGCHUNK, "Attempt to access the wrong chunk"},
|
---|
144 | {MNG_INVALIDENTRYIX, "Attempt to access an non-existing entry"},
|
---|
145 | {MNG_NOHEADER, "No valid header-chunk"},
|
---|
146 | {MNG_NOCORRCHUNK, "Parent chunk not found"},
|
---|
147 | {MNG_NOMHDR, "No MNG header (MHDR) found"},
|
---|
148 |
|
---|
149 | {MNG_IMAGETOOLARGE, "Image is larger than defined maximum"},
|
---|
150 | {MNG_NOTANANIMATION, "Image is not an animation"},
|
---|
151 | {MNG_FRAMENRTOOHIGH, "Framenr out of bounds"},
|
---|
152 | {MNG_LAYERNRTOOHIGH, "Layernr out of bounds"},
|
---|
153 | {MNG_PLAYTIMETOOHIGH, "Playtime out of bounds"},
|
---|
154 | {MNG_FNNOTIMPLEMENTED, "Function not yet implemented"},
|
---|
155 | {MNG_IMAGEFROZEN, "Image is frozen"},
|
---|
156 |
|
---|
157 | {MNG_LCMS_NOHANDLE, "Handle could not be initialized"},
|
---|
158 | {MNG_LCMS_NOMEM, "No memory for gamma-table(s)"},
|
---|
159 | {MNG_LCMS_NOTRANS, "Transformation could not be initialized"},
|
---|
160 | };
|
---|
161 | #endif /* MNG_INCLUDE_ERROR_STRINGS */
|
---|
162 |
|
---|
163 | /* ************************************************************************** */
|
---|
164 |
|
---|
165 | mng_bool mng_store_error (mng_datap pData,
|
---|
166 | mng_retcode iError,
|
---|
167 | mng_retcode iExtra1,
|
---|
168 | mng_retcode iExtra2)
|
---|
169 | {
|
---|
170 | #ifdef MNG_SUPPORT_TRACE
|
---|
171 | MNG_TRACEB (pData, MNG_FN_STORE_ERROR, MNG_LC_START)
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | if (pData != 0)
|
---|
175 | {
|
---|
176 | pData->iErrorcode = iError; /* save also for getlasterror */
|
---|
177 | pData->iErrorx1 = iExtra1;
|
---|
178 | pData->iErrorx2 = iExtra2;
|
---|
179 |
|
---|
180 | #ifdef MNG_INCLUDE_ERROR_STRINGS
|
---|
181 | { /* binary search variables */
|
---|
182 | mng_int32 iTop, iLower, iUpper, iMiddle;
|
---|
183 | mng_error_entryp pEntry; /* pointer to found entry */
|
---|
184 | /* determine max index of table */
|
---|
185 | iTop = (sizeof (error_table) / sizeof (error_table [0])) - 1;
|
---|
186 |
|
---|
187 | iLower = 0; /* initialize binary search */
|
---|
188 | iMiddle = iTop >> 1; /* start in the middle */
|
---|
189 | iUpper = iTop;
|
---|
190 | pEntry = 0; /* no goods yet! */
|
---|
191 |
|
---|
192 | do /* the binary search itself */
|
---|
193 | {
|
---|
194 | if (error_table [iMiddle].iError < iError)
|
---|
195 | iLower = iMiddle + 1;
|
---|
196 | else if (error_table [iMiddle].iError > iError)
|
---|
197 | iUpper = iMiddle - 1;
|
---|
198 | else
|
---|
199 | {
|
---|
200 | pEntry = &error_table [iMiddle];
|
---|
201 | break;
|
---|
202 | }
|
---|
203 |
|
---|
204 | iMiddle = (iLower + iUpper) >> 1;
|
---|
205 | }
|
---|
206 | while (iLower <= iUpper);
|
---|
207 |
|
---|
208 | if (pEntry) /* found it ? */
|
---|
209 | pData->zErrortext = pEntry->zErrortext;
|
---|
210 | else
|
---|
211 | pData->zErrortext = "Unknown error";
|
---|
212 | }
|
---|
213 | #else
|
---|
214 | pData->zErrortext = 0;
|
---|
215 | #endif /* mng_error_telltale */
|
---|
216 |
|
---|
217 | if (iError == 0) /* no error is not severe ! */
|
---|
218 | {
|
---|
219 | pData->iSeverity = 0;
|
---|
220 | }
|
---|
221 | else
|
---|
222 | {
|
---|
223 | switch (iError&0x3C00) /* determine the severity */
|
---|
224 | {
|
---|
225 | case 0x0800 : { pData->iSeverity = 5; break; }
|
---|
226 | case 0x1000 : { pData->iSeverity = 2; break; }
|
---|
227 | case 0x2000 : { pData->iSeverity = 1; break; }
|
---|
228 | default : { pData->iSeverity = 9; }
|
---|
229 | }
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 | #ifdef MNG_SUPPORT_TRACE
|
---|
234 | MNG_TRACEB (pData, MNG_FN_STORE_ERROR, MNG_LC_END)
|
---|
235 | #endif
|
---|
236 |
|
---|
237 | return MNG_TRUE;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /* ************************************************************************** */
|
---|
241 |
|
---|
242 | mng_bool mng_process_error (mng_datap pData,
|
---|
243 | mng_retcode iError,
|
---|
244 | mng_retcode iExtra1,
|
---|
245 | mng_retcode iExtra2)
|
---|
246 | {
|
---|
247 | #ifdef MNG_SUPPORT_TRACE
|
---|
248 | MNG_TRACEB (pData, MNG_FN_PROCESS_ERROR, MNG_LC_START)
|
---|
249 | #endif
|
---|
250 |
|
---|
251 | mng_store_error (pData, iError, iExtra1, iExtra2);
|
---|
252 |
|
---|
253 | if (pData != 0)
|
---|
254 | {
|
---|
255 | if (pData->fErrorproc) /* callback defined ? */
|
---|
256 | return pData->fErrorproc (((mng_handle)pData), iError, pData->iSeverity,
|
---|
257 | pData->iChunkname, pData->iChunkseq,
|
---|
258 | pData->iErrorx1, pData->iErrorx2, pData->zErrortext);
|
---|
259 | }
|
---|
260 |
|
---|
261 | #ifdef MNG_SUPPORT_TRACE
|
---|
262 | MNG_TRACEB (pData, MNG_FN_PROCESS_ERROR, MNG_LC_END)
|
---|
263 | #endif
|
---|
264 |
|
---|
265 | return MNG_FALSE; /* automatic failure */
|
---|
266 | }
|
---|
267 |
|
---|
268 | /* ************************************************************************** */
|
---|
269 | /* * end of file * */
|
---|
270 | /* ************************************************************************** */
|
---|
271 |
|
---|