libmng_read.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. /* ************************************************************************** */
  2. /* * For conditions of distribution and use, * */
  3. /* * see copyright notice in libmng.h * */
  4. /* ************************************************************************** */
  5. /* * * */
  6. /* * project : libmng * */
  7. /* * file : libmng_read.c copyright (c) 2000-2007 G.Juyn * */
  8. /* * version : 1.0.10 * */
  9. /* * * */
  10. /* * purpose : Read logic (implementation) * */
  11. /* * * */
  12. /* * author : G.Juyn * */
  13. /* * * */
  14. /* * comment : implementation of the high-level read logic * */
  15. /* * * */
  16. /* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */
  17. /* * - changed strict-ANSI stuff * */
  18. /* * 0.5.1 - 05/11/2000 - G.Juyn * */
  19. /* * - added callback error-reporting support * */
  20. /* * 0.5.1 - 05/12/2000 - G.Juyn * */
  21. /* * - changed trace to macro for callback error-reporting * */
  22. /* * * */
  23. /* * 0.5.2 - 05/19/2000 - G.Juyn * */
  24. /* * - cleaned up some code regarding mixed support * */
  25. /* * 0.5.2 - 05/20/2000 - G.Juyn * */
  26. /* * - added support for JNG * */
  27. /* * 0.5.2 - 05/31/2000 - G.Juyn * */
  28. /* * - fixed up punctuation (contribution by Tim Rowley) * */
  29. /* * * */
  30. /* * 0.5.3 - 06/16/2000 - G.Juyn * */
  31. /* * - changed progressive-display processing * */
  32. /* * * */
  33. /* * 0.9.1 - 07/08/2000 - G.Juyn * */
  34. /* * - changed read-processing for improved I/O-suspension * */
  35. /* * 0.9.1 - 07/14/2000 - G.Juyn * */
  36. /* * - changed EOF processing behavior * */
  37. /* * 0.9.1 - 07/14/2000 - G.Juyn * */
  38. /* * - changed default readbuffer size from 1024 to 4200 * */
  39. /* * * */
  40. /* * 0.9.2 - 07/27/2000 - G.Juyn * */
  41. /* * - B110320 - fixed GCC warning about mix-sized pointer math * */
  42. /* * 0.9.2 - 07/31/2000 - G.Juyn * */
  43. /* * - B110546 - fixed for improperly returning UNEXPECTEDEOF * */
  44. /* * 0.9.2 - 08/04/2000 - G.Juyn * */
  45. /* * - B111096 - fixed large-buffer read-suspension * */
  46. /* * 0.9.2 - 08/05/2000 - G.Juyn * */
  47. /* * - changed file-prefixes * */
  48. /* * * */
  49. /* * 0.9.3 - 08/26/2000 - G.Juyn * */
  50. /* * - added MAGN chunk * */
  51. /* * 0.9.3 - 10/11/2000 - G.Juyn * */
  52. /* * - removed test-MaGN * */
  53. /* * 0.9.3 - 10/16/2000 - G.Juyn * */
  54. /* * - added support for JDAA * */
  55. /* * * */
  56. /* * 0.9.5 - 01/23/2001 - G.Juyn * */
  57. /* * - fixed timing-problem with switching framing_modes * */
  58. /* * * */
  59. /* * 1.0.4 - 06/22/2002 - G.Juyn * */
  60. /* * - B495443 - incorrect suspend check in read_databuffer * */
  61. /* * * */
  62. /* * 1.0.5 - 07/04/2002 - G.Juyn * */
  63. /* * - added errorcode for extreme chunk-sizes * */
  64. /* * 1.0.5 - 07/08/2002 - G.Juyn * */
  65. /* * - B578572 - removed eMNGma hack (thanks Dimitri!) * */
  66. /* * 1.0.5 - 07/16/2002 - G.Juyn * */
  67. /* * - B581625 - large chunks fail with suspension reads * */
  68. /* * 1.0.5 - 08/19/2002 - G.Juyn * */
  69. /* * - B597134 - libmng pollutes the linker namespace * */
  70. /* * - added HLAPI function to copy chunks * */
  71. /* * 1.0.5 - 09/16/2002 - G.Juyn * */
  72. /* * - added event handling for dynamic MNG * */
  73. /* * * */
  74. /* * 1.0.6 - 05/25/2003 - G.R-P * */
  75. /* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */
  76. /* * 1.0.6 - 07/07/2003 - G.R-P * */
  77. /* * - added MNG_NO_DELTA_PNG reduction * */
  78. /* * - skip additional code when MNG_INCLUDE_JNG is not enabled * */
  79. /* * 1.0.6 - 07/29/2003 - G.R-P * */
  80. /* * - added conditionals around PAST chunk support * */
  81. /* * 1.0.6 - 08/17/2003 - G.R-P * */
  82. /* * - added conditionals around non-VLC chunk support * */
  83. /* * * */
  84. /* * 1.0.7 - 03/10/2004 - G.R-P * */
  85. /* * - added conditionals around openstream/closestream * */
  86. /* * * */
  87. /* * 1.0.8 - 04/08/2004 - G.Juyn * */
  88. /* * - added CRC existence & checking flags * */
  89. /* * 1.0.8 - 04/11/2004 - G.Juyn * */
  90. /* * - added data-push mechanisms for specialized decoders * */
  91. /* * 1.0.8 - 07/06/2004 - G.R-P * */
  92. /* * - defend against using undefined closestream function * */
  93. /* * 1.0.8 - 07/28/2004 - G.R-P * */
  94. /* * - added check for extreme chunk-lengths * */
  95. /* * * */
  96. /* * 1.0.9 - 09/16/2004 - G.Juyn * */
  97. /* * - fixed chunk pushing mechanism * */
  98. /* * 1.0.9 - 12/05/2004 - G.Juyn * */
  99. /* * - added conditional MNG_OPTIMIZE_CHUNKINITFREE * */
  100. /* * 1.0.9 - 12/06/2004 - G.Juyn * */
  101. /* * - added conditional MNG_OPTIMIZE_CHUNKASSIGN * */
  102. /* * - added conditional MNG_OPTIMIZE_CHUNKREADER * */
  103. /* * 1.0.9 - 12/20/2004 - G.Juyn * */
  104. /* * - cleaned up macro-invocations (thanks to D. Airlie) * */
  105. /* * 1.0.9 - 12/31/2004 - G.R-P * */
  106. /* * - removed stray characters from #ifdef directive * */
  107. /* * * */
  108. /* * 1.0.10 - 04/08/2007 - G.Juyn * */
  109. /* * - added support for mPNG proposal * */
  110. /* * * */
  111. /* ************************************************************************** */
  112. #include "libmng.h"
  113. #include "libmng_data.h"
  114. #include "libmng_error.h"
  115. #include "libmng_trace.h"
  116. #ifdef __BORLANDC__
  117. #pragma hdrstop
  118. #endif
  119. #include "libmng_memory.h"
  120. #include "libmng_objects.h"
  121. #include "libmng_object_prc.h"
  122. #include "libmng_chunks.h"
  123. #ifdef MNG_OPTIMIZE_CHUNKREADER
  124. #include "libmng_chunk_descr.h"
  125. #endif
  126. #include "libmng_chunk_prc.h"
  127. #include "libmng_chunk_io.h"
  128. #include "libmng_display.h"
  129. #include "libmng_read.h"
  130. #if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)
  131. #pragma option -A /* force ANSI-C */
  132. #endif
  133. /* ************************************************************************** */
  134. #ifdef MNG_INCLUDE_READ_PROCS
  135. /* ************************************************************************** */
  136. mng_retcode mng_process_eof (mng_datap pData)
  137. {
  138. if (!pData->bEOF) /* haven't closed the stream yet ? */
  139. {
  140. pData->bEOF = MNG_TRUE; /* now we do! */
  141. #ifndef MNG_NO_OPEN_CLOSE_STREAM
  142. if (pData->fClosestream && !pData->fClosestream ((mng_handle)pData))
  143. {
  144. MNG_ERROR (pData, MNG_APPIOERROR);
  145. }
  146. #endif
  147. }
  148. return MNG_NOERROR;
  149. }
  150. /* ************************************************************************** */
  151. mng_retcode mng_release_pushdata (mng_datap pData)
  152. {
  153. mng_pushdatap pFirst = pData->pFirstpushdata;
  154. mng_pushdatap pNext = pFirst->pNext;
  155. #ifdef MNG_SUPPORT_TRACE
  156. MNG_TRACE (pData, MNG_FN_RELEASE_PUSHDATA, MNG_LC_START);
  157. #endif
  158. pData->pFirstpushdata = pNext; /* next becomes the first */
  159. if (!pNext) /* no next? => no last! */
  160. pData->pLastpushdata = MNG_NULL;
  161. /* buffer owned and release callback defined? */
  162. if ((pFirst->bOwned) && (pData->fReleasedata))
  163. pData->fReleasedata ((mng_handle)pData, pFirst->pData, pFirst->iLength);
  164. else /* otherwise use internal free mechanism */
  165. MNG_FREEX (pData, pFirst->pData, pFirst->iLength);
  166. /* and free it */
  167. MNG_FREEX (pData, pFirst, sizeof(mng_pushdata));
  168. #ifdef MNG_SUPPORT_TRACE
  169. MNG_TRACE (pData, MNG_FN_RELEASE_PUSHDATA, MNG_LC_END);
  170. #endif
  171. return MNG_NOERROR;
  172. }
  173. /* ************************************************************************** */
  174. mng_retcode mng_release_pushchunk (mng_datap pData)
  175. {
  176. mng_pushdatap pFirst = pData->pFirstpushchunk;
  177. mng_pushdatap pNext = pFirst->pNext;
  178. #ifdef MNG_SUPPORT_TRACE
  179. MNG_TRACE (pData, MNG_FN_RELEASE_PUSHCHUNK, MNG_LC_START);
  180. #endif
  181. pData->pFirstpushchunk = pNext; /* next becomes the first */
  182. if (!pNext) /* no next? => no last! */
  183. pData->pLastpushchunk = MNG_NULL;
  184. /* buffer owned and release callback defined? */
  185. if ((pFirst->bOwned) && (pData->fReleasedata))
  186. pData->fReleasedata ((mng_handle)pData, pFirst->pData, pFirst->iLength);
  187. else /* otherwise use internal free mechanism */
  188. MNG_FREEX (pData, pFirst->pData, pFirst->iLength);
  189. /* and free it */
  190. MNG_FREEX (pData, pFirst, sizeof(mng_pushdata));
  191. #ifdef MNG_SUPPORT_TRACE
  192. MNG_TRACE (pData, MNG_FN_RELEASE_PUSHCHUNK, MNG_LC_END);
  193. #endif
  194. return MNG_NOERROR;
  195. }
  196. /* ************************************************************************** */
  197. MNG_LOCAL mng_retcode read_data (mng_datap pData,
  198. mng_uint8p pBuf,
  199. mng_uint32 iSize,
  200. mng_uint32 * iRead)
  201. {
  202. mng_retcode iRetcode;
  203. mng_uint32 iTempsize = iSize;
  204. mng_uint8p pTempbuf = pBuf;
  205. mng_pushdatap pPush = pData->pFirstpushdata;
  206. mng_uint32 iPushsize = 0;
  207. *iRead = 0; /* nothing yet */
  208. #ifdef MNG_SUPPORT_TRACE
  209. MNG_TRACE (pData, MNG_FN_READ_DATA, MNG_LC_START);
  210. #endif
  211. while (pPush) /* calculate size of pushed data */
  212. {
  213. iPushsize += pPush->iRemaining;
  214. pPush = pPush->pNext;
  215. }
  216. if (iTempsize <= iPushsize) /* got enough push data? */
  217. {
  218. while (iTempsize)
  219. {
  220. pPush = pData->pFirstpushdata;
  221. /* enough data remaining in this buffer? */
  222. if (pPush->iRemaining <= iTempsize)
  223. { /* no: then copy what we've got */
  224. MNG_COPY (pTempbuf, pPush->pDatanext, pPush->iRemaining);
  225. /* move pointers & lengths */
  226. pTempbuf += pPush->iRemaining;
  227. *iRead += pPush->iRemaining;
  228. iTempsize -= pPush->iRemaining;
  229. /* release the depleted buffer */
  230. iRetcode = mng_release_pushdata (pData);
  231. if (iRetcode)
  232. return iRetcode;
  233. }
  234. else
  235. { /* copy the needed bytes */
  236. MNG_COPY (pTempbuf, pPush->pDatanext, iTempsize);
  237. /* move pointers & lengths */
  238. pPush->iRemaining -= iTempsize;
  239. pPush->pDatanext += iTempsize;
  240. pTempbuf += iTempsize;
  241. *iRead += iTempsize;
  242. iTempsize = 0; /* all done!!! */
  243. }
  244. }
  245. }
  246. else
  247. {
  248. mng_uint32 iTempread = 0;
  249. /* get it from the app then */
  250. if (!pData->fReaddata (((mng_handle)pData), pTempbuf, iTempsize, &iTempread))
  251. MNG_ERROR (pData, MNG_APPIOERROR);
  252. *iRead += iTempread;
  253. }
  254. #ifdef MNG_SUPPORT_TRACE
  255. MNG_TRACE (pData, MNG_FN_READ_DATA, MNG_LC_END);
  256. #endif
  257. return MNG_NOERROR;
  258. }
  259. /* ************************************************************************** */
  260. MNG_LOCAL mng_retcode read_databuffer (mng_datap pData,
  261. mng_uint8p pBuf,
  262. mng_uint8p * pBufnext,
  263. mng_uint32 iSize,
  264. mng_uint32 * iRead)
  265. {
  266. mng_retcode iRetcode;
  267. #ifdef MNG_SUPPORT_TRACE
  268. MNG_TRACE (pData, MNG_FN_READ_DATABUFFER, MNG_LC_START);
  269. #endif
  270. if (pData->bSuspensionmode)
  271. {
  272. mng_uint8p pTemp;
  273. mng_uint32 iTemp;
  274. *iRead = 0; /* let's be negative about the outcome */
  275. if (!pData->pSuspendbuf) /* need to create a suspension buffer ? */
  276. {
  277. pData->iSuspendbufsize = MNG_SUSPENDBUFFERSIZE;
  278. /* so, create it */
  279. MNG_ALLOC (pData, pData->pSuspendbuf, pData->iSuspendbufsize);
  280. pData->iSuspendbufleft = 0; /* make sure to fill it first time */
  281. pData->pSuspendbufnext = pData->pSuspendbuf;
  282. }
  283. /* more than our buffer can hold ? */
  284. if (iSize > pData->iSuspendbufsize)
  285. {
  286. mng_uint32 iRemain;
  287. if (!*pBufnext) /* first time ? */
  288. {
  289. if (pData->iSuspendbufleft) /* do we have some data left ? */
  290. { /* then copy it */
  291. MNG_COPY (pBuf, pData->pSuspendbufnext, pData->iSuspendbufleft);
  292. /* fixup variables */
  293. *pBufnext = pBuf + pData->iSuspendbufleft;
  294. pData->pSuspendbufnext = pData->pSuspendbuf;
  295. pData->iSuspendbufleft = 0;
  296. }
  297. else
  298. {
  299. *pBufnext = pBuf;
  300. }
  301. }
  302. /* calculate how much to get */
  303. iRemain = iSize - (mng_uint32)(*pBufnext - pBuf);
  304. /* let's go get it */
  305. iRetcode = read_data (pData, *pBufnext, iRemain, &iTemp);
  306. if (iRetcode)
  307. return iRetcode;
  308. /* first read after suspension return 0 means EOF */
  309. if ((pData->iSuspendpoint) && (iTemp == 0))
  310. { /* that makes it final */
  311. mng_retcode iRetcode = mng_process_eof (pData);
  312. if (iRetcode) /* on error bail out */
  313. return iRetcode;
  314. /* indicate the source is depleted */
  315. *iRead = iSize - iRemain + iTemp;
  316. }
  317. else
  318. {
  319. if (iTemp < iRemain) /* suspension required ? */
  320. {
  321. *pBufnext = *pBufnext + iTemp;
  322. pData->bSuspended = MNG_TRUE;
  323. }
  324. else
  325. {
  326. *iRead = iSize; /* got it all now ! */
  327. }
  328. }
  329. }
  330. else
  331. { /* need to read some more ? */
  332. while ((!pData->bSuspended) && (!pData->bEOF) && (iSize > pData->iSuspendbufleft))
  333. { /* not enough space left in buffer ? */
  334. if (pData->iSuspendbufsize - pData->iSuspendbufleft -
  335. (mng_uint32)(pData->pSuspendbufnext - pData->pSuspendbuf) <
  336. MNG_SUSPENDREQUESTSIZE)
  337. {
  338. if (pData->iSuspendbufleft) /* then lets shift (if there's anything left) */
  339. MNG_COPY (pData->pSuspendbuf, pData->pSuspendbufnext, pData->iSuspendbufleft);
  340. /* adjust running pointer */
  341. pData->pSuspendbufnext = pData->pSuspendbuf;
  342. }
  343. /* still not enough room ? */
  344. if (pData->iSuspendbufsize - pData->iSuspendbufleft < MNG_SUSPENDREQUESTSIZE)
  345. MNG_ERROR (pData, MNG_INTERNALERROR);
  346. /* now read some more data */
  347. pTemp = pData->pSuspendbufnext + pData->iSuspendbufleft;
  348. iRetcode = read_data (pData, pTemp, MNG_SUSPENDREQUESTSIZE, &iTemp);
  349. if (iRetcode)
  350. return iRetcode;
  351. /* adjust fill-counter */
  352. pData->iSuspendbufleft += iTemp;
  353. /* first read after suspension returning 0 means EOF */
  354. if ((pData->iSuspendpoint) && (iTemp == 0))
  355. { /* that makes it final */
  356. mng_retcode iRetcode = mng_process_eof (pData);
  357. if (iRetcode) /* on error bail out */
  358. return iRetcode;
  359. if (pData->iSuspendbufleft) /* return the leftover scraps */
  360. MNG_COPY (pBuf, pData->pSuspendbufnext, pData->iSuspendbufleft);
  361. /* and indicate so */
  362. *iRead = pData->iSuspendbufleft;
  363. pData->pSuspendbufnext = pData->pSuspendbuf;
  364. pData->iSuspendbufleft = 0;
  365. }
  366. else
  367. { /* suspension required ? */
  368. if ((iSize > pData->iSuspendbufleft) && (iTemp < MNG_SUSPENDREQUESTSIZE))
  369. pData->bSuspended = MNG_TRUE;
  370. }
  371. pData->iSuspendpoint = 0; /* reset it here in case we loop back */
  372. }
  373. if ((!pData->bSuspended) && (!pData->bEOF))
  374. { /* return the data ! */
  375. MNG_COPY (pBuf, pData->pSuspendbufnext, iSize);
  376. *iRead = iSize; /* returned it all */
  377. /* adjust suspension-buffer variables */
  378. pData->pSuspendbufnext += iSize;
  379. pData->iSuspendbufleft -= iSize;
  380. }
  381. }
  382. }
  383. else
  384. {
  385. iRetcode = read_data (pData, (mng_ptr)pBuf, iSize, iRead);
  386. if (iRetcode)
  387. return iRetcode;
  388. if (*iRead == 0) /* suspension required ? */
  389. pData->bSuspended = MNG_TRUE;
  390. }
  391. pData->iSuspendpoint = 0; /* safely reset it here ! */
  392. #ifdef MNG_SUPPORT_TRACE
  393. MNG_TRACE (pData, MNG_FN_READ_DATABUFFER, MNG_LC_END);
  394. #endif
  395. return MNG_NOERROR;
  396. }
  397. /* ************************************************************************** */
  398. MNG_LOCAL mng_retcode process_raw_chunk (mng_datap pData,
  399. mng_uint8p pBuf,
  400. mng_uint32 iBuflen)
  401. {
  402. #ifndef MNG_OPTIMIZE_CHUNKREADER
  403. /* the table-idea & binary search code was adapted from
  404. libpng 1.1.0 (pngread.c) */
  405. /* NOTE1: the table must remain sorted by chunkname, otherwise the binary
  406. search will break !!! (ps. watch upper-/lower-case chunknames !!) */
  407. /* NOTE2: the layout must remain equal to the header part of all the
  408. chunk-structures (yes, that means even the pNext and pPrev fields;
  409. it's wasting a bit of space, but hey, the code is a lot easier) */
  410. #ifdef MNG_OPTIMIZE_CHUNKINITFREE
  411. mng_chunk_header mng_chunk_unknown = {MNG_UINT_HUH, mng_init_general, mng_free_unknown,
  412. mng_read_unknown, mng_write_unknown, mng_assign_unknown, 0, 0, sizeof(mng_unknown_chunk)};
  413. #else
  414. mng_chunk_header mng_chunk_unknown = {MNG_UINT_HUH, mng_init_unknown, mng_free_unknown,
  415. mng_read_unknown, mng_write_unknown, mng_assign_unknown, 0, 0};
  416. #endif
  417. #ifdef MNG_OPTIMIZE_CHUNKINITFREE
  418. mng_chunk_header mng_chunk_table [] =
  419. {
  420. #ifndef MNG_SKIPCHUNK_BACK
  421. {MNG_UINT_BACK, mng_init_general, mng_free_general, mng_read_back, mng_write_back, mng_assign_general, 0, 0, sizeof(mng_back)},
  422. #endif
  423. #ifndef MNG_SKIPCHUNK_BASI
  424. {MNG_UINT_BASI, mng_init_general, mng_free_general, mng_read_basi, mng_write_basi, mng_assign_general, 0, 0, sizeof(mng_basi)},
  425. #endif
  426. #ifndef MNG_SKIPCHUNK_CLIP
  427. {MNG_UINT_CLIP, mng_init_general, mng_free_general, mng_read_clip, mng_write_clip, mng_assign_general, 0, 0, sizeof(mng_clip)},
  428. #endif
  429. #ifndef MNG_SKIPCHUNK_CLON
  430. {MNG_UINT_CLON, mng_init_general, mng_free_general, mng_read_clon, mng_write_clon, mng_assign_general, 0, 0, sizeof(mng_clon)},
  431. #endif
  432. #ifndef MNG_NO_DELTA_PNG
  433. #ifndef MNG_SKIPCHUNK_DBYK
  434. {MNG_UINT_DBYK, mng_init_general, mng_free_dbyk, mng_read_dbyk, mng_write_dbyk, mng_assign_dbyk, 0, 0, sizeof(mng_dbyk)},
  435. #endif
  436. #endif
  437. #ifndef MNG_SKIPCHUNK_DEFI
  438. {MNG_UINT_DEFI, mng_init_general, mng_free_general, mng_read_defi, mng_write_defi, mng_assign_general, 0, 0, sizeof(mng_defi)},
  439. #endif
  440. #ifndef MNG_NO_DELTA_PNG
  441. {MNG_UINT_DHDR, mng_init_general, mng_free_general, mng_read_dhdr, mng_write_dhdr, mng_assign_general, 0, 0, sizeof(mng_dhdr)},
  442. #endif
  443. #ifndef MNG_SKIPCHUNK_DISC
  444. {MNG_UINT_DISC, mng_init_general, mng_free_disc, mng_read_disc, mng_write_disc, mng_assign_disc, 0, 0, sizeof(mng_disc)},
  445. #endif
  446. #ifndef MNG_NO_DELTA_PNG
  447. #ifndef MNG_SKIPCHUNK_DROP
  448. {MNG_UINT_DROP, mng_init_general, mng_free_drop, mng_read_drop, mng_write_drop, mng_assign_drop, 0, 0, sizeof(mng_drop)},
  449. #endif
  450. #endif
  451. #ifndef MNG_SKIPCHUNK_LOOP
  452. {MNG_UINT_ENDL, mng_init_general, mng_free_general, mng_read_endl, mng_write_endl, mng_assign_general, 0, 0, sizeof(mng_endl)},
  453. #endif
  454. #ifndef MNG_SKIPCHUNK_FRAM
  455. {MNG_UINT_FRAM, mng_init_general, mng_free_fram, mng_read_fram, mng_write_fram, mng_assign_fram, 0, 0, sizeof(mng_fram)},
  456. #endif
  457. {MNG_UINT_IDAT, mng_init_general, mng_free_idat, mng_read_idat, mng_write_idat, mng_assign_idat, 0, 0, sizeof(mng_idat)}, /* 12-th element! */
  458. {MNG_UINT_IEND, mng_init_general, mng_free_general, mng_read_iend, mng_write_iend, mng_assign_general, 0, 0, sizeof(mng_iend)},
  459. {MNG_UINT_IHDR, mng_init_general, mng_free_general, mng_read_ihdr, mng_write_ihdr, mng_assign_general, 0, 0, sizeof(mng_ihdr)},
  460. #ifndef MNG_NO_DELTA_PNG
  461. #ifdef MNG_INCLUDE_JNG
  462. {MNG_UINT_IJNG, mng_init_general, mng_free_general, mng_read_ijng, mng_write_ijng, mng_assign_general, 0, 0, sizeof(mng_ijng)},
  463. #endif
  464. {MNG_UINT_IPNG, mng_init_general, mng_free_general, mng_read_ipng, mng_write_ipng, mng_assign_general, 0, 0, sizeof(mng_ipng)},
  465. #endif
  466. #ifdef MNG_INCLUDE_JNG
  467. {MNG_UINT_JDAA, mng_init_general, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa)},
  468. {MNG_UINT_JDAT, mng_init_general, mng_free_jdat, mng_read_jdat, mng_write_jdat, mng_assign_jdat, 0, 0, sizeof(mng_jdat)},
  469. {MNG_UINT_JHDR, mng_init_general, mng_free_general, mng_read_jhdr, mng_write_jhdr, mng_assign_general, 0, 0, sizeof(mng_jhdr)},
  470. {MNG_UINT_JSEP, mng_init_general, mng_free_general, mng_read_jsep, mng_write_jsep, mng_assign_general, 0, 0, sizeof(mng_jsep)},
  471. {MNG_UINT_JdAA, mng_init_general, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0, sizeof(mng_jdaa)},
  472. #endif
  473. #ifndef MNG_SKIPCHUNK_LOOP
  474. {MNG_UINT_LOOP, mng_init_general, mng_free_loop, mng_read_loop, mng_write_loop, mng_assign_loop, 0, 0, sizeof(mng_loop)},
  475. #endif
  476. #ifndef MNG_SKIPCHUNK_MAGN
  477. {MNG_UINT_MAGN, mng_init_general, mng_free_general, mng_read_magn, mng_write_magn, mng_assign_general, 0, 0, sizeof(mng_magn)},
  478. #endif
  479. {MNG_UINT_MEND, mng_init_general, mng_free_general, mng_read_mend, mng_write_mend, mng_assign_general, 0, 0, sizeof(mng_mend)},
  480. {MNG_UINT_MHDR, mng_init_general, mng_free_general, mng_read_mhdr, mng_write_mhdr, mng_assign_general, 0, 0, sizeof(mng_mhdr)},
  481. #ifndef MNG_SKIPCHUNK_MOVE
  482. {MNG_UINT_MOVE, mng_init_general, mng_free_general, mng_read_move, mng_write_move, mng_assign_general, 0, 0, sizeof(mng_move)},
  483. #endif
  484. #ifndef MNG_NO_DELTA_PNG
  485. #ifndef MNG_SKIPCHUNK_ORDR
  486. {MNG_UINT_ORDR, mng_init_general, mng_free_ordr, mng_read_ordr, mng_write_ordr, mng_assign_ordr, 0, 0, sizeof(mng_ordr)},
  487. #endif
  488. #endif
  489. #ifndef MNG_SKIPCHUNK_PAST
  490. {MNG_UINT_PAST, mng_init_general, mng_free_past, mng_read_past, mng_write_past, mng_assign_past, 0, 0, sizeof(mng_past)},
  491. #endif
  492. {MNG_UINT_PLTE, mng_init_general, mng_free_general, mng_read_plte, mng_write_plte, mng_assign_general, 0, 0, sizeof(mng_plte)},
  493. #ifndef MNG_NO_DELTA_PNG
  494. {MNG_UINT_PPLT, mng_init_general, mng_free_general, mng_read_pplt, mng_write_pplt, mng_assign_general, 0, 0, sizeof(mng_pplt)},
  495. {MNG_UINT_PROM, mng_init_general, mng_free_general, mng_read_prom, mng_write_prom, mng_assign_general, 0, 0, sizeof(mng_prom)},
  496. #endif
  497. #ifndef MNG_SKIPCHUNK_SAVE
  498. {MNG_UINT_SAVE, mng_init_general, mng_free_save, mng_read_save, mng_write_save, mng_assign_save, 0, 0, sizeof(mng_save)},
  499. #endif
  500. #ifndef MNG_SKIPCHUNK_SEEK
  501. {MNG_UINT_SEEK, mng_init_general, mng_free_seek, mng_read_seek, mng_write_seek, mng_assign_seek, 0, 0, sizeof(mng_seek)},
  502. #endif
  503. #ifndef MNG_SKIPCHUNK_SHOW
  504. {MNG_UINT_SHOW, mng_init_general, mng_free_general, mng_read_show, mng_write_show, mng_assign_general, 0, 0, sizeof(mng_show)},
  505. #endif
  506. #ifndef MNG_SKIPCHUNK_TERM
  507. {MNG_UINT_TERM, mng_init_general, mng_free_general, mng_read_term, mng_write_term, mng_assign_general, 0, 0, sizeof(mng_term)},
  508. #endif
  509. #ifndef MNG_SKIPCHUNK_bKGD
  510. {MNG_UINT_bKGD, mng_init_general, mng_free_general, mng_read_bkgd, mng_write_bkgd, mng_assign_general, 0, 0, sizeof(mng_bkgd)},
  511. #endif
  512. #ifndef MNG_SKIPCHUNK_cHRM
  513. {MNG_UINT_cHRM, mng_init_general, mng_free_general, mng_read_chrm, mng_write_chrm, mng_assign_general, 0, 0, sizeof(mng_chrm)},
  514. #endif
  515. #ifndef MNG_SKIPCHUNK_eXPI
  516. {MNG_UINT_eXPI, mng_init_general, mng_free_expi, mng_read_expi, mng_write_expi, mng_assign_expi, 0, 0, sizeof(mng_expi)},
  517. #endif
  518. #ifndef MNG_SKIPCHUNK_evNT
  519. {MNG_UINT_evNT, mng_init_general, mng_free_evnt, mng_read_evnt, mng_write_evnt, mng_assign_evnt, 0, 0, sizeof(mng_evnt)},
  520. #endif
  521. #ifndef MNG_SKIPCHUNK_fPRI
  522. {MNG_UINT_fPRI, mng_init_general, mng_free_general, mng_read_fpri, mng_write_fpri, mng_assign_general, 0, 0, sizeof(mng_fpri)},
  523. #endif
  524. #ifndef MNG_SKIPCHUNK_gAMA
  525. {MNG_UINT_gAMA, mng_init_general, mng_free_general, mng_read_gama, mng_write_gama, mng_assign_general, 0, 0, sizeof(mng_gama)},
  526. #endif
  527. #ifndef MNG_SKIPCHUNK_hIST
  528. {MNG_UINT_hIST, mng_init_general, mng_free_general, mng_read_hist, mng_write_hist, mng_assign_general, 0, 0, sizeof(mng_hist)},
  529. #endif
  530. #ifndef MNG_SKIPCHUNK_iCCP
  531. {MNG_UINT_iCCP, mng_init_general, mng_free_iccp, mng_read_iccp, mng_write_iccp, mng_assign_iccp, 0, 0, sizeof(mng_iccp)},
  532. #endif
  533. #ifndef MNG_SKIPCHUNK_iTXt
  534. {MNG_UINT_iTXt, mng_init_general, mng_free_itxt, mng_read_itxt, mng_write_itxt, mng_assign_itxt, 0, 0, sizeof(mng_itxt)},
  535. #endif
  536. #ifdef MNG_INCLUDE_MPNG_PROPOSAL
  537. {MNG_UINT_mpNG, mng_init_general, mng_free_mpng, mng_read_mpng, mng_write_mpng, mng_assign_mpng, 0, 0, sizeof(mng_mpng)},
  538. #endif
  539. #ifndef MNG_SKIPCHUNK_nEED
  540. {MNG_UINT_nEED, mng_init_general, mng_free_need, mng_read_need, mng_write_need, mng_assign_need, 0, 0, sizeof(mng_need)},
  541. #endif
  542. /* TODO: {MNG_UINT_oFFs, 0, 0, 0, 0, 0, 0}, */
  543. /* TODO: {MNG_UINT_pCAL, 0, 0, 0, 0, 0, 0}, */
  544. #ifndef MNG_SKIPCHUNK_pHYg
  545. {MNG_UINT_pHYg, mng_init_general, mng_free_general, mng_read_phyg, mng_write_phyg, mng_assign_general, 0, 0, sizeof(mng_phyg)},
  546. #endif
  547. #ifndef MNG_SKIPCHUNK_pHYs
  548. {MNG_UINT_pHYs, mng_init_general, mng_free_general, mng_read_phys, mng_write_phys, mng_assign_general, 0, 0, sizeof(mng_phys)},
  549. #endif
  550. #ifndef MNG_SKIPCHUNK_sBIT
  551. {MNG_UINT_sBIT, mng_init_general, mng_free_general, mng_read_sbit, mng_write_sbit, mng_assign_general, 0, 0, sizeof(mng_sbit)},
  552. #endif
  553. /* TODO: {MNG_UINT_sCAL, 0, 0, 0, 0, 0, 0}, */
  554. #ifndef MNG_SKIPCHUNK_sPLT
  555. {MNG_UINT_sPLT, mng_init_general, mng_free_splt, mng_read_splt, mng_write_splt, mng_assign_splt, 0, 0, sizeof(mng_splt)},
  556. #endif
  557. {MNG_UINT_sRGB, mng_init_general, mng_free_general, mng_read_srgb, mng_write_srgb, mng_assign_general, 0, 0, sizeof(mng_srgb)},
  558. #ifndef MNG_SKIPCHUNK_tEXt
  559. {MNG_UINT_tEXt, mng_init_general, mng_free_text, mng_read_text, mng_write_text, mng_assign_text, 0, 0, sizeof(mng_text)},
  560. #endif
  561. #ifndef MNG_SKIPCHUNK_tIME
  562. {MNG_UINT_tIME, mng_init_general, mng_free_general, mng_read_time, mng_write_time, mng_assign_general, 0, 0, sizeof(mng_time)},
  563. #endif
  564. {MNG_UINT_tRNS, mng_init_general, mng_free_general, mng_read_trns, mng_write_trns, mng_assign_general, 0, 0, sizeof(mng_trns)},
  565. #ifndef MNG_SKIPCHUNK_zTXt
  566. {MNG_UINT_zTXt, mng_init_general, mng_free_ztxt, mng_read_ztxt, mng_write_ztxt, mng_assign_ztxt, 0, 0, sizeof(mng_ztxt)},
  567. #endif
  568. };
  569. #else /* MNG_OPTIMIZE_CHUNKINITFREE */
  570. mng_chunk_header mng_chunk_table [] =
  571. {
  572. #ifndef MNG_SKIPCHUNK_BACK
  573. {MNG_UINT_BACK, mng_init_back, mng_free_back, mng_read_back, mng_write_back, mng_assign_back, 0, 0},
  574. #endif
  575. #ifndef MNG_SKIPCHUNK_BASI
  576. {MNG_UINT_BASI, mng_init_basi, mng_free_basi, mng_read_basi, mng_write_basi, mng_assign_basi, 0, 0},
  577. #endif
  578. #ifndef MNG_SKIPCHUNK_CLIP
  579. {MNG_UINT_CLIP, mng_init_clip, mng_free_clip, mng_read_clip, mng_write_clip, mng_assign_clip, 0, 0},
  580. #endif
  581. #ifndef MNG_SKIPCHUNK_CLON
  582. {MNG_UINT_CLON, mng_init_clon, mng_free_clon, mng_read_clon, mng_write_clon, mng_assign_clon, 0, 0},
  583. #endif
  584. #ifndef MNG_NO_DELTA_PNG
  585. #ifndef MNG_SKIPCHUNK_DBYK
  586. {MNG_UINT_DBYK, mng_init_dbyk, mng_free_dbyk, mng_read_dbyk, mng_write_dbyk, mng_assign_dbyk, 0, 0},
  587. #endif
  588. #endif
  589. #ifndef MNG_SKIPCHUNK_DEFI
  590. {MNG_UINT_DEFI, mng_init_defi, mng_free_defi, mng_read_defi, mng_write_defi, mng_assign_defi, 0, 0},
  591. #endif
  592. #ifndef MNG_NO_DELTA_PNG
  593. {MNG_UINT_DHDR, mng_init_dhdr, mng_free_dhdr, mng_read_dhdr, mng_write_dhdr, mng_assign_dhdr, 0, 0},
  594. #endif
  595. #ifndef MNG_SKIPCHUNK_DISC
  596. {MNG_UINT_DISC, mng_init_disc, mng_free_disc, mng_read_disc, mng_write_disc, mng_assign_disc, 0, 0},
  597. #endif
  598. #ifndef MNG_NO_DELTA_PNG
  599. #ifndef MNG_SKIPCHUNK_DROP
  600. {MNG_UINT_DROP, mng_init_drop, mng_free_drop, mng_read_drop, mng_write_drop, mng_assign_drop, 0, 0},
  601. #endif
  602. #endif
  603. #ifndef MNG_SKIPCHUNK_LOOP
  604. {MNG_UINT_ENDL, mng_init_endl, mng_free_endl, mng_read_endl, mng_write_endl, mng_assign_endl, 0, 0},
  605. #endif
  606. #ifndef MNG_SKIPCHUNK_FRAM
  607. {MNG_UINT_FRAM, mng_init_fram, mng_free_fram, mng_read_fram, mng_write_fram, mng_assign_fram, 0, 0},
  608. #endif
  609. {MNG_UINT_IDAT, mng_init_idat, mng_free_idat, mng_read_idat, mng_write_idat, mng_assign_idat, 0, 0}, /* 12-th element! */
  610. {MNG_UINT_IEND, mng_init_iend, mng_free_iend, mng_read_iend, mng_write_iend, mng_assign_iend, 0, 0},
  611. {MNG_UINT_IHDR, mng_init_ihdr, mng_free_ihdr, mng_read_ihdr, mng_write_ihdr, mng_assign_ihdr, 0, 0},
  612. #ifndef MNG_NO_DELTA_PNG
  613. #ifdef MNG_INCLUDE_JNG
  614. {MNG_UINT_IJNG, mng_init_ijng, mng_free_ijng, mng_read_ijng, mng_write_ijng, mng_assign_ijng, 0, 0},
  615. #endif
  616. {MNG_UINT_IPNG, mng_init_ipng, mng_free_ipng, mng_read_ipng, mng_write_ipng, mng_assign_ipng, 0, 0},
  617. #endif
  618. #ifdef MNG_INCLUDE_JNG
  619. {MNG_UINT_JDAA, mng_init_jdaa, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0},
  620. {MNG_UINT_JDAT, mng_init_jdat, mng_free_jdat, mng_read_jdat, mng_write_jdat, mng_assign_jdat, 0, 0},
  621. {MNG_UINT_JHDR, mng_init_jhdr, mng_free_jhdr, mng_read_jhdr, mng_write_jhdr, mng_assign_jhdr, 0, 0},
  622. {MNG_UINT_JSEP, mng_init_jsep, mng_free_jsep, mng_read_jsep, mng_write_jsep, mng_assign_jsep, 0, 0},
  623. {MNG_UINT_JdAA, mng_init_jdaa, mng_free_jdaa, mng_read_jdaa, mng_write_jdaa, mng_assign_jdaa, 0, 0},
  624. #endif
  625. #ifndef MNG_SKIPCHUNK_LOOP
  626. {MNG_UINT_LOOP, mng_init_loop, mng_free_loop, mng_read_loop, mng_write_loop, mng_assign_loop, 0, 0},
  627. #endif
  628. #ifndef MNG_SKIPCHUNK_MAGN
  629. {MNG_UINT_MAGN, mng_init_magn, mng_free_magn, mng_read_magn, mng_write_magn, mng_assign_magn, 0, 0},
  630. #endif
  631. {MNG_UINT_MEND, mng_init_mend, mng_free_mend, mng_read_mend, mng_write_mend, mng_assign_mend, 0, 0},
  632. {MNG_UINT_MHDR, mng_init_mhdr, mng_free_mhdr, mng_read_mhdr, mng_write_mhdr, mng_assign_mhdr, 0, 0},
  633. #ifndef MNG_SKIPCHUNK_MOVE
  634. {MNG_UINT_MOVE, mng_init_move, mng_free_move, mng_read_move, mng_write_move, mng_assign_move, 0, 0},
  635. #endif
  636. #ifndef MNG_NO_DELTA_PNG
  637. #ifndef MNG_SKIPCHUNK_ORDR
  638. {MNG_UINT_ORDR, mng_init_ordr, mng_free_ordr, mng_read_ordr, mng_write_ordr, mng_assign_ordr, 0, 0},
  639. #endif
  640. #endif
  641. #ifndef MNG_SKIPCHUNK_PAST
  642. {MNG_UINT_PAST, mng_init_past, mng_free_past, mng_read_past, mng_write_past, mng_assign_past, 0, 0},
  643. #endif
  644. {MNG_UINT_PLTE, mng_init_plte, mng_free_plte, mng_read_plte, mng_write_plte, mng_assign_plte, 0, 0},
  645. #ifndef MNG_NO_DELTA_PNG
  646. {MNG_UINT_PPLT, mng_init_pplt, mng_free_pplt, mng_read_pplt, mng_write_pplt, mng_assign_pplt, 0, 0},
  647. {MNG_UINT_PROM, mng_init_prom, mng_free_prom, mng_read_prom, mng_write_prom, mng_assign_prom, 0, 0},
  648. #endif
  649. #ifndef MNG_SKIPCHUNK_SAVE
  650. {MNG_UINT_SAVE, mng_init_save, mng_free_save, mng_read_save, mng_write_save, mng_assign_save, 0, 0},
  651. #endif
  652. #ifndef MNG_SKIPCHUNK_SEEK
  653. {MNG_UINT_SEEK, mng_init_seek, mng_free_seek, mng_read_seek, mng_write_seek, mng_assign_seek, 0, 0},
  654. #endif
  655. #ifndef MNG_SKIPCHUNK_SHOW
  656. {MNG_UINT_SHOW, mng_init_show, mng_free_show, mng_read_show, mng_write_show, mng_assign_show, 0, 0},
  657. #endif
  658. #ifndef MNG_SKIPCHUNK_TERM
  659. {MNG_UINT_TERM, mng_init_term, mng_free_term, mng_read_term, mng_write_term, mng_assign_term, 0, 0},
  660. #endif
  661. #ifndef MNG_SKIPCHUNK_bKGD
  662. {MNG_UINT_bKGD, mng_init_bkgd, mng_free_bkgd, mng_read_bkgd, mng_write_bkgd, mng_assign_bkgd, 0, 0},
  663. #endif
  664. #ifndef MNG_SKIPCHUNK_cHRM
  665. {MNG_UINT_cHRM, mng_init_chrm, mng_free_chrm, mng_read_chrm, mng_write_chrm, mng_assign_chrm, 0, 0},
  666. #endif
  667. #ifndef MNG_SKIPCHUNK_eXPI
  668. {MNG_UINT_eXPI, mng_init_expi, mng_free_expi, mng_read_expi, mng_write_expi, mng_assign_expi, 0, 0},
  669. #endif
  670. #ifndef MNG_SKIPCHUNK_evNT
  671. {MNG_UINT_evNT, mng_init_evnt, mng_free_evnt, mng_read_evnt, mng_write_evnt, mng_assign_evnt, 0, 0},
  672. #endif
  673. #ifndef MNG_SKIPCHUNK_fPRI
  674. {MNG_UINT_fPRI, mng_init_fpri, mng_free_fpri, mng_read_fpri, mng_write_fpri, mng_assign_fpri, 0, 0},
  675. #endif
  676. #ifndef MNG_SKIPCHUNK_gAMA
  677. {MNG_UINT_gAMA, mng_init_gama, mng_free_gama, mng_read_gama, mng_write_gama, mng_assign_gama, 0, 0},
  678. #endif
  679. #ifndef MNG_SKIPCHUNK_hIST
  680. {MNG_UINT_hIST, mng_init_hist, mng_free_hist, mng_read_hist, mng_write_hist, mng_assign_hist, 0, 0},
  681. #endif
  682. #ifndef MNG_SKIPCHUNK_iCCP
  683. {MNG_UINT_iCCP, mng_init_iccp, mng_free_iccp, mng_read_iccp, mng_write_iccp, mng_assign_iccp, 0, 0},
  684. #endif
  685. #ifndef MNG_SKIPCHUNK_iTXt
  686. {MNG_UINT_iTXt, mng_init_itxt, mng_free_itxt, mng_read_itxt, mng_write_itxt, mng_assign_itxt, 0, 0},
  687. #endif
  688. #ifndef MNG_SKIPCHUNK_nEED
  689. {MNG_UINT_nEED, mng_init_need, mng_free_need, mng_read_need, mng_write_need, mng_assign_need, 0, 0},
  690. #endif
  691. /* TODO: {MNG_UINT_oFFs, 0, 0, 0, 0, 0, 0}, */
  692. /* TODO: {MNG_UINT_pCAL, 0, 0, 0, 0, 0, 0}, */
  693. #ifndef MNG_SKIPCHUNK_pHYg
  694. {MNG_UINT_pHYg, mng_init_phyg, mng_free_phyg, mng_read_phyg, mng_write_phyg, mng_assign_phyg, 0, 0},
  695. #endif
  696. #ifndef MNG_SKIPCHUNK_pHYs
  697. {MNG_UINT_pHYs, mng_init_phys, mng_free_phys, mng_read_phys, mng_write_phys, mng_assign_phys, 0, 0},
  698. #endif
  699. #ifndef MNG_SKIPCHUNK_sBIT
  700. {MNG_UINT_sBIT, mng_init_sbit, mng_free_sbit, mng_read_sbit, mng_write_sbit, mng_assign_sbit, 0, 0},
  701. #endif
  702. /* TODO: {MNG_UINT_sCAL, 0, 0, 0, 0, 0, 0}, */
  703. #ifndef MNG_SKIPCHUNK_sPLT
  704. {MNG_UINT_sPLT, mng_init_splt, mng_free_splt, mng_read_splt, mng_write_splt, mng_assign_splt, 0, 0},
  705. #endif
  706. {MNG_UINT_sRGB, mng_init_srgb, mng_free_srgb, mng_read_srgb, mng_write_srgb, mng_assign_srgb, 0, 0},
  707. #ifndef MNG_SKIPCHUNK_tEXt
  708. {MNG_UINT_tEXt, mng_init_text, mng_free_text, mng_read_text, mng_write_text, mng_assign_text, 0, 0},
  709. #endif
  710. #ifndef MNG_SKIPCHUNK_tIME
  711. {MNG_UINT_tIME, mng_init_time, mng_free_time, mng_read_time, mng_write_time, mng_assign_time, 0, 0},
  712. #endif
  713. {MNG_UINT_tRNS, mng_init_trns, mng_free_trns, mng_read_trns, mng_write_trns, mng_assign_trns, 0, 0},
  714. #ifndef MNG_SKIPCHUNK_zTXt
  715. {MNG_UINT_zTXt, mng_init_ztxt, mng_free_ztxt, mng_read_ztxt, mng_write_ztxt, mng_assign_ztxt, 0, 0},
  716. #endif
  717. };
  718. #endif /* MNG_OPTIMIZE_CHUNKINITFREE */
  719. /* binary search variables */
  720. mng_int32 iTop, iLower, iUpper, iMiddle;
  721. mng_chunk_headerp pEntry; /* pointer to found entry */
  722. #else
  723. mng_chunk_header sEntry; /* temp chunk-header */
  724. #endif /* MNG_OPTIMIZE_CHUNKREADER */
  725. mng_chunkid iChunkname; /* the chunk's tag */
  726. mng_chunkp pChunk; /* chunk structure (if #define MNG_STORE_CHUNKS) */
  727. mng_retcode iRetcode; /* temporary error-code */
  728. #ifdef MNG_SUPPORT_TRACE
  729. MNG_TRACE (pData, MNG_FN_PROCESS_RAW_CHUNK, MNG_LC_START);
  730. #endif
  731. /* reset timer indicator on read-cycle */
  732. if ((pData->bReading) && (!pData->bDisplaying))
  733. pData->bTimerset = MNG_FALSE;
  734. /* get the chunkname */
  735. iChunkname = (mng_chunkid)(mng_get_uint32 (pBuf));
  736. pBuf += sizeof (mng_chunkid); /* adjust the buffer */
  737. iBuflen -= sizeof (mng_chunkid);
  738. pChunk = 0;
  739. #ifndef MNG_OPTIMIZE_CHUNKREADER
  740. /* determine max index of table */
  741. iTop = (sizeof (mng_chunk_table) / sizeof (mng_chunk_table [0])) - 1;
  742. /* binary search; with 54 chunks, worst-case is 7 comparisons */
  743. iLower = 0;
  744. #ifndef MNG_NO_DELTA_PNG
  745. iMiddle = 11; /* start with the IDAT entry */
  746. #else
  747. iMiddle = 8;
  748. #endif
  749. iUpper = iTop;
  750. pEntry = 0; /* no goods yet! */
  751. do /* the binary search itself */
  752. {
  753. if (mng_chunk_table [iMiddle].iChunkname < iChunkname)
  754. iLower = iMiddle + 1;
  755. else if (mng_chunk_table [iMiddle].iChunkname > iChunkname)
  756. iUpper = iMiddle - 1;
  757. else
  758. {
  759. pEntry = &mng_chunk_table [iMiddle];
  760. break;
  761. }
  762. iMiddle = (iLower + iUpper) >> 1;
  763. }
  764. while (iLower <= iUpper);
  765. if (!pEntry) /* unknown chunk ? */
  766. pEntry = &mng_chunk_unknown; /* make it so! */
  767. #else /* MNG_OPTIMIZE_CHUNKREADER */
  768. mng_get_chunkheader (iChunkname, &sEntry);
  769. #endif /* MNG_OPTIMIZE_CHUNKREADER */
  770. pData->iChunkname = iChunkname; /* keep track of where we are */
  771. pData->iChunkseq++;
  772. #ifndef MNG_OPTIMIZE_CHUNKREADER
  773. if (pEntry->fRead) /* read-callback available ? */
  774. {
  775. iRetcode = pEntry->fRead (pData, pEntry, iBuflen, (mng_ptr)pBuf, &pChunk);
  776. if (!iRetcode) /* everything oke ? */
  777. { /* remember unknown chunk's id */
  778. if ((pChunk) && (pEntry->iChunkname == MNG_UINT_HUH))
  779. ((mng_chunk_headerp)pChunk)->iChunkname = iChunkname;
  780. }
  781. }
  782. #else /* MNG_OPTIMIZE_CHUNKREADER */
  783. if (sEntry.fRead) /* read-callback available ? */
  784. {
  785. iRetcode = sEntry.fRead (pData, &sEntry, iBuflen, (mng_ptr)pBuf, &pChunk);
  786. #ifndef MNG_OPTIMIZE_CHUNKREADER
  787. if (!iRetcode) /* everything oke ? */
  788. { /* remember unknown chunk's id */
  789. if ((pChunk) && (sEntry.iChunkname == MNG_UINT_HUH))
  790. ((mng_chunk_headerp)pChunk)->iChunkname = iChunkname;
  791. }
  792. #endif
  793. }
  794. #endif /* MNG_OPTIMIZE_CHUNKREADER */
  795. else
  796. iRetcode = MNG_NOERROR;
  797. if (pChunk) /* store this chunk ? */
  798. mng_add_chunk (pData, pChunk); /* do it */
  799. #ifdef MNG_INCLUDE_JNG /* implicit EOF ? */
  800. if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && (!pData->bHasJHDR))
  801. #else
  802. if ((!pData->bHasMHDR) && (!pData->bHasIHDR))
  803. #endif
  804. iRetcode = mng_process_eof (pData);/* then do some EOF processing */
  805. if (iRetcode) /* on error bail out */
  806. return iRetcode;
  807. #ifdef MNG_SUPPORT_TRACE
  808. MNG_TRACE (pData, MNG_FN_PROCESS_RAW_CHUNK, MNG_LC_END);
  809. #endif
  810. return MNG_NOERROR;
  811. }
  812. /* ************************************************************************** */
  813. MNG_LOCAL mng_retcode check_chunk_crc (mng_datap pData,
  814. mng_uint8p pBuf,
  815. mng_uint32 iBuflen)
  816. {
  817. mng_uint32 iCrc; /* calculated CRC */
  818. mng_bool bDiscard = MNG_FALSE;
  819. mng_retcode iRetcode = MNG_NOERROR;
  820. #ifdef MNG_SUPPORT_TRACE
  821. MNG_TRACE (pData, MNG_FN_READ_CHUNK_CRC, MNG_LC_START);
  822. #endif
  823. if (pData->iCrcmode & MNG_CRC_INPUT) /* crc included ? */
  824. {
  825. mng_bool bCritical = (mng_bool)((*pBuf & 0x20) == 0);
  826. mng_uint32 iL = iBuflen - (mng_uint32)(sizeof (iCrc));
  827. if (((bCritical ) && (pData->iCrcmode & MNG_CRC_CRITICAL )) ||
  828. ((!bCritical) && (pData->iCrcmode & MNG_CRC_ANCILLARY)))
  829. { /* calculate the crc */
  830. iCrc = mng_crc (pData, pBuf, iL);
  831. /* and check it */
  832. if (!(iCrc == mng_get_uint32 (pBuf + iL)))
  833. {
  834. mng_bool bWarning = MNG_FALSE;
  835. mng_bool bError = MNG_FALSE;
  836. if (bCritical)
  837. {
  838. switch (pData->iCrcmode & MNG_CRC_CRITICAL)
  839. {
  840. case MNG_CRC_CRITICAL_WARNING : { bWarning = MNG_TRUE; break; }
  841. case MNG_CRC_CRITICAL_ERROR : { bError = MNG_TRUE; break; }
  842. }
  843. }
  844. else
  845. {
  846. switch (pData->iCrcmode & MNG_CRC_ANCILLARY)
  847. {
  848. case MNG_CRC_ANCILLARY_DISCARD : { bDiscard = MNG_TRUE; break; }
  849. case MNG_CRC_ANCILLARY_WARNING : { bWarning = MNG_TRUE; break; }
  850. case MNG_CRC_ANCILLARY_ERROR : { bError = MNG_TRUE; break; }
  851. }
  852. }
  853. if (bWarning)
  854. MNG_WARNING (pData, MNG_INVALIDCRC);
  855. if (bError)
  856. MNG_ERROR (pData, MNG_INVALIDCRC);
  857. }
  858. }
  859. if (!bDiscard) /* still processing ? */
  860. iRetcode = process_raw_chunk (pData, pBuf, iL);
  861. }
  862. else
  863. { /* no crc => straight onto processing */
  864. iRetcode = process_raw_chunk (pData, pBuf, iBuflen);
  865. }
  866. #ifdef MNG_SUPPORT_TRACE
  867. MNG_TRACE (pData, MNG_FN_READ_CHUNK_CRC, MNG_LC_END);
  868. #endif
  869. return iRetcode;
  870. }
  871. /* ************************************************************************** */
  872. MNG_LOCAL mng_retcode read_chunk (mng_datap pData)
  873. {
  874. mng_uint32 iBufmax = pData->iReadbufsize;
  875. mng_uint8p pBuf = pData->pReadbuf;
  876. mng_uint32 iBuflen = 0; /* number of bytes requested */
  877. mng_uint32 iRead = 0; /* number of bytes read */
  878. mng_retcode iRetcode = MNG_NOERROR;
  879. #ifdef MNG_SUPPORT_TRACE
  880. MNG_TRACE (pData, MNG_FN_READ_CHUNK, MNG_LC_START);
  881. #endif
  882. #ifdef MNG_SUPPORT_DISPLAY
  883. if (pData->pCurraniobj) /* processing an animation object ? */
  884. {
  885. do /* process it then */
  886. {
  887. iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj);
  888. /* refresh needed ? */
  889. /* if ((!iRetcode) && (!pData->bTimerset) && (pData->bNeedrefresh))
  890. iRetcode = display_progressive_refresh (pData, 1); */
  891. /* can we advance to next object ? */
  892. if ((!iRetcode) && (pData->pCurraniobj) &&
  893. (!pData->bTimerset) && (!pData->bSectionwait))
  894. { /* reset timer indicator on read-cycle */
  895. if ((pData->bReading) && (!pData->bDisplaying))
  896. pData->bTimerset = MNG_FALSE;
  897. pData->pCurraniobj = ((mng_object_headerp)pData->pCurraniobj)->pNext;
  898. /* TERM processing to be done ? */
  899. if ((!pData->pCurraniobj) && (pData->bHasTERM) && (!pData->bHasMHDR))
  900. iRetcode = mng_process_display_mend (pData);
  901. }
  902. } /* until error or a break or no more objects */
  903. while ((!iRetcode) && (pData->pCurraniobj) &&
  904. (!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bFreezing));
  905. }
  906. else
  907. {
  908. if (pData->iBreakpoint) /* do we need to finish something first ? */
  909. {
  910. switch (pData->iBreakpoint) /* return to broken display routine */
  911. {
  912. #ifndef MNG_SKIPCHUNK_FRAM
  913. case 1 : { iRetcode = mng_process_display_fram2 (pData); break; }
  914. #endif
  915. case 2 : { iRetcode = mng_process_display_ihdr (pData); break; }
  916. #ifndef MNG_SKIPCHUNK_SHOW
  917. case 3 : ; /* same as 4 !!! */
  918. case 4 : { iRetcode = mng_process_display_show (pData); break; }
  919. #endif
  920. #ifndef MNG_SKIPCHUNK_CLON
  921. case 5 : { iRetcode = mng_process_display_clon2 (pData); break; }
  922. #endif
  923. #ifdef MNG_INCLUDE_JNG
  924. case 7 : { iRetcode = mng_process_display_jhdr (pData); break; }
  925. #endif
  926. case 6 : ; /* same as 8 !!! */
  927. case 8 : { iRetcode = mng_process_display_iend (pData); break; }
  928. #ifndef MNG_SKIPCHUNK_MAGN
  929. case 9 : { iRetcode = mng_process_display_magn2 (pData); break; }
  930. #endif
  931. case 10 : { iRetcode = mng_process_display_mend2 (pData); break; }
  932. #ifndef MNG_SKIPCHUNK_PAST
  933. case 11 : { iRetcode = mng_process_display_past2 (pData); break; }
  934. #endif
  935. }
  936. }
  937. }
  938. if (iRetcode) /* on error bail out */
  939. return iRetcode;
  940. #endif /* MNG_SUPPORT_DISPLAY */
  941. /* can we continue processing now, or do we */
  942. /* need to wait for the timer to finish (again) ? */
  943. #ifdef MNG_SUPPORT_DISPLAY
  944. if ((!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bEOF))
  945. #else
  946. if (!pData->bEOF)
  947. #endif
  948. {
  949. #ifdef MNG_SUPPORT_DISPLAY
  950. /* freezing in progress ? */
  951. if ((pData->bFreezing) && (pData->iSuspendpoint == 0))
  952. pData->bRunning = MNG_FALSE; /* then this is the right moment to do it */
  953. #endif
  954. if (pData->iSuspendpoint <= 2)
  955. {
  956. iBuflen = sizeof (mng_uint32); /* read length */
  957. iRetcode = read_databuffer (pData, pBuf, &pData->pReadbufnext, iBuflen, &iRead);
  958. if (iRetcode) /* bail on errors */
  959. return iRetcode;
  960. if (pData->bSuspended) /* suspended ? */
  961. pData->iSuspendpoint = 2;
  962. else /* save the length */
  963. {
  964. pData->iChunklen = mng_get_uint32 (pBuf);
  965. if (pData->iChunklen > 0x7ffffff)
  966. return MNG_INVALIDLENGTH;
  967. }
  968. }
  969. if (!pData->bSuspended) /* still going ? */
  970. { /* previously suspended or not eof ? */
  971. if ((pData->iSuspendpoint > 2) || (iRead == iBuflen))
  972. { /* determine length chunkname + data (+ crc) */
  973. if (pData->iCrcmode & MNG_CRC_INPUT)
  974. iBuflen = pData->iChunklen + (mng_uint32)(sizeof (mng_chunkid) + sizeof (mng_uint32));
  975. else
  976. iBuflen = pData->iChunklen + (mng_uint32)(sizeof (mng_chunkid));
  977. /* do we have enough data in the current push buffer ? */
  978. if ((pData->pFirstpushdata) && (iBuflen <= pData->pFirstpushdata->iRemaining))
  979. {
  980. mng_pushdatap pPush = pData->pFirstpushdata;
  981. pBuf = pPush->pDatanext;
  982. pPush->pDatanext += iBuflen;
  983. pPush->iRemaining -= iBuflen;
  984. pData->iSuspendpoint = 0; /* safely reset this here ! */
  985. iRetcode = check_chunk_crc (pData, pBuf, iBuflen);
  986. if (iRetcode)
  987. return iRetcode;
  988. if (!pPush->iRemaining) /* buffer depleted? then release it */
  989. iRetcode = mng_release_pushdata (pData);
  990. }
  991. else
  992. {
  993. if (iBuflen < iBufmax) /* does it fit in default buffer ? */
  994. { /* note that we don't use the full size
  995. so there's always a zero-byte at the
  996. very end !!! */
  997. iRetcode = read_databuffer (pData, pBuf, &pData->pReadbufnext, iBuflen, &iRead);
  998. if (iRetcode) /* bail on errors */
  999. return iRetcode;
  1000. if (pData->bSuspended) /* suspended ? */
  1001. pData->iSuspendpoint = 3;
  1002. else
  1003. {
  1004. if (iRead != iBuflen) /* did we get all the data ? */
  1005. MNG_ERROR (pData, MNG_UNEXPECTEDEOF);
  1006. iRetcode = check_chunk_crc (pData, pBuf, iBuflen);
  1007. }
  1008. }
  1009. else
  1010. {
  1011. if (iBuflen > 16777216) /* is the length incredible? */
  1012. MNG_ERROR (pData, MNG_IMPROBABLELENGTH);
  1013. if (!pData->iSuspendpoint) /* create additional large buffer ? */
  1014. { /* again reserve space for the last zero-byte */
  1015. pData->iLargebufsize = iBuflen + 1;
  1016. pData->pLargebufnext = MNG_NULL;
  1017. MNG_ALLOC (pData, pData->pLargebuf, pData->iLargebufsize);
  1018. }
  1019. iRetcode = read_databuffer (pData, pData->pLargebuf, &pData->pLargebufnext, iBuflen, &iRead);
  1020. if (iRetcode)
  1021. return iRetcode;
  1022. if (pData->bSuspended) /* suspended ? */
  1023. pData->iSuspendpoint = 4;
  1024. else
  1025. {
  1026. if (iRead != iBuflen) /* did we get all the data ? */
  1027. MNG_ERROR (pData, MNG_UNEXPECTEDEOF);
  1028. iRetcode = check_chunk_crc (pData, pData->pLargebuf, iBuflen);
  1029. /* cleanup additional large buffer */
  1030. MNG_FREE (pData, pData->pLargebuf, pData->iLargebufsize);
  1031. }
  1032. }
  1033. }
  1034. if (iRetcode) /* on error bail out */
  1035. return iRetcode;
  1036. }
  1037. else
  1038. { /* that's final */
  1039. iRetcode = mng_process_eof (pData);
  1040. if (iRetcode) /* on error bail out */
  1041. return iRetcode;
  1042. if ((iRead != 0) || /* did we get an unexpected eof ? */
  1043. #ifdef MNG_INCLUDE_JNG
  1044. (pData->bHasIHDR || pData->bHasMHDR || pData->bHasJHDR))
  1045. #else
  1046. (pData->bHasIHDR || pData->bHasMHDR))
  1047. #endif
  1048. MNG_ERROR (pData, MNG_UNEXPECTEDEOF);
  1049. }
  1050. }
  1051. }
  1052. #ifdef MNG_SUPPORT_DISPLAY /* refresh needed ? */
  1053. if ((!pData->bTimerset) && (!pData->bSuspended) && (pData->bNeedrefresh))
  1054. {
  1055. iRetcode = mng_display_progressive_refresh (pData, 1);
  1056. if (iRetcode) /* on error bail out */
  1057. return iRetcode;
  1058. }
  1059. #endif
  1060. #ifdef MNG_SUPPORT_TRACE
  1061. MNG_TRACE (pData, MNG_FN_READ_CHUNK, MNG_LC_END);
  1062. #endif
  1063. return MNG_NOERROR;
  1064. }
  1065. /* ************************************************************************** */
  1066. MNG_LOCAL mng_retcode process_pushedchunk (mng_datap pData)
  1067. {
  1068. mng_pushdatap pPush;
  1069. mng_retcode iRetcode = MNG_NOERROR;
  1070. #ifdef MNG_SUPPORT_DISPLAY
  1071. if (pData->pCurraniobj) /* processing an animation object ? */
  1072. {
  1073. do /* process it then */
  1074. {
  1075. iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj);
  1076. /* refresh needed ? */
  1077. /* if ((!iRetcode) && (!pData->bTimerset) && (pData->bNeedrefresh))
  1078. iRetcode = display_progressive_refresh (pData, 1); */
  1079. /* can we advance to next object ? */
  1080. if ((!iRetcode) && (pData->pCurraniobj) &&
  1081. (!pData->bTimerset) && (!pData->bSectionwait))
  1082. { /* reset timer indicator on read-cycle */
  1083. if ((pData->bReading) && (!pData->bDisplaying))
  1084. pData->bTimerset = MNG_FALSE;
  1085. pData->pCurraniobj = ((mng_object_headerp)pData->pCurraniobj)->pNext;
  1086. /* TERM processing to be done ? */
  1087. if ((!pData->pCurraniobj) && (pData->bHasTERM) && (!pData->bHasMHDR))
  1088. iRetcode = mng_process_display_mend (pData);
  1089. }
  1090. } /* until error or a break or no more objects */
  1091. while ((!iRetcode) && (pData->pCurraniobj) &&
  1092. (!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bFreezing));
  1093. }
  1094. else
  1095. {
  1096. if (pData->iBreakpoint) /* do we need to finish something first ? */
  1097. {
  1098. switch (pData->iBreakpoint) /* return to broken display routine */
  1099. {
  1100. #ifndef MNG_SKIPCHUNK_FRAM
  1101. case 1 : { iRetcode = mng_process_display_fram2 (pData); break; }
  1102. #endif
  1103. case 2 : { iRetcode = mng_process_display_ihdr (pData); break; }
  1104. #ifndef MNG_SKIPCHUNK_SHOW
  1105. case 3 : ; /* same as 4 !!! */
  1106. case 4 : { iRetcode = mng_process_display_show (pData); break; }
  1107. #endif
  1108. #ifndef MNG_SKIPCHUNK_CLON
  1109. case 5 : { iRetcode = mng_process_display_clon2 (pData); break; }
  1110. #endif
  1111. #ifdef MNG_INCLUDE_JNG
  1112. case 7 : { iRetcode = mng_process_display_jhdr (pData); break; }
  1113. #endif
  1114. case 6 : ; /* same as 8 !!! */
  1115. case 8 : { iRetcode = mng_process_display_iend (pData); break; }
  1116. #ifndef MNG_SKIPCHUNK_MAGN
  1117. case 9 : { iRetcode = mng_process_display_magn2 (pData); break; }
  1118. #endif
  1119. case 10 : { iRetcode = mng_process_display_mend2 (pData); break; }
  1120. #ifndef MNG_SKIPCHUNK_PAST
  1121. case 11 : { iRetcode = mng_process_display_past2 (pData); break; }
  1122. #endif
  1123. }
  1124. }
  1125. }
  1126. if (iRetcode) /* on error bail out */
  1127. return iRetcode;
  1128. #endif /* MNG_SUPPORT_DISPLAY */
  1129. /* can we continue processing now, or do we */
  1130. /* need to wait for the timer to finish (again) ? */
  1131. #ifdef MNG_SUPPORT_DISPLAY
  1132. if ((!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bEOF))
  1133. #else
  1134. if (!pData->bEOF)
  1135. #endif
  1136. {
  1137. pData->iSuspendpoint = 0; /* safely reset it here ! */
  1138. pPush = pData->pFirstpushchunk;
  1139. iRetcode = process_raw_chunk (pData, pPush->pData, pPush->iLength);
  1140. if (iRetcode)
  1141. return iRetcode;
  1142. #ifdef MNG_SUPPORT_DISPLAY /* refresh needed ? */
  1143. if ((!pData->bTimerset) && (!pData->bSuspended) && (pData->bNeedrefresh))
  1144. {
  1145. iRetcode = mng_display_progressive_refresh (pData, 1);
  1146. if (iRetcode) /* on error bail out */
  1147. return iRetcode;
  1148. }
  1149. #endif
  1150. }
  1151. return mng_release_pushchunk (pData);
  1152. }
  1153. /* ************************************************************************** */
  1154. mng_retcode mng_read_graphic (mng_datap pData)
  1155. {
  1156. mng_uint32 iBuflen; /* number of bytes requested */
  1157. mng_uint32 iRead; /* number of bytes read */
  1158. mng_retcode iRetcode; /* temporary error-code */
  1159. #ifdef MNG_SUPPORT_TRACE
  1160. MNG_TRACE (pData, MNG_FN_READ_GRAPHIC, MNG_LC_START);
  1161. #endif
  1162. if (!pData->pReadbuf) /* buffer allocated ? */
  1163. {
  1164. pData->iReadbufsize = 4200; /* allocate a default read buffer */
  1165. MNG_ALLOC (pData, pData->pReadbuf, pData->iReadbufsize);
  1166. }
  1167. /* haven't processed the signature ? */
  1168. if ((!pData->bHavesig) || (pData->iSuspendpoint == 1))
  1169. {
  1170. iBuflen = 2 * sizeof (mng_uint32); /* read signature */
  1171. iRetcode = read_databuffer (pData, pData->pReadbuf, &pData->pReadbufnext, iBuflen, &iRead);
  1172. if (iRetcode)
  1173. return iRetcode;
  1174. if (pData->bSuspended) /* input suspension ? */
  1175. pData->iSuspendpoint = 1;
  1176. else
  1177. {
  1178. if (iRead != iBuflen) /* full signature received ? */
  1179. MNG_ERROR (pData, MNG_UNEXPECTEDEOF);
  1180. /* is it a valid signature ? */
  1181. if (mng_get_uint32 (pData->pReadbuf) == PNG_SIG)
  1182. pData->eSigtype = mng_it_png;
  1183. else
  1184. #ifdef MNG_INCLUDE_JNG
  1185. if (mng_get_uint32 (pData->pReadbuf) == JNG_SIG)
  1186. pData->eSigtype = mng_it_jng;
  1187. else
  1188. #endif
  1189. if (mng_get_uint32 (pData->pReadbuf) == MNG_SIG)
  1190. pData->eSigtype = mng_it_mng;
  1191. else
  1192. MNG_ERROR (pData, MNG_INVALIDSIG);
  1193. /* all of it ? */
  1194. if (mng_get_uint32 (pData->pReadbuf+4) != POST_SIG)
  1195. MNG_ERROR (pData, MNG_INVALIDSIG);
  1196. pData->bHavesig = MNG_TRUE;
  1197. }
  1198. }
  1199. if (!pData->bSuspended) /* still going ? */
  1200. {
  1201. do
  1202. { /* reset timer during mng_read() ? */
  1203. if ((pData->bReading) && (!pData->bDisplaying))
  1204. pData->bTimerset = MNG_FALSE;
  1205. if (pData->pFirstpushchunk) /* chunks pushed ? */
  1206. iRetcode = process_pushedchunk (pData); /* process the pushed chunk */
  1207. else
  1208. iRetcode = read_chunk (pData); /* read & process a chunk */
  1209. if (iRetcode) /* on error bail out */
  1210. return iRetcode;
  1211. }
  1212. #ifdef MNG_SUPPORT_DISPLAY /* until EOF or a break-request */
  1213. while (((!pData->bEOF) || (pData->pCurraniobj)) &&
  1214. (!pData->bSuspended) && (!pData->bSectionwait) &&
  1215. ((!pData->bTimerset) || ((pData->bReading) && (!pData->bDisplaying))));
  1216. #else
  1217. while ((!pData->bEOF) && (!pData->bSuspended));
  1218. #endif
  1219. }
  1220. #ifdef MNG_SUPPORT_TRACE
  1221. MNG_TRACE (pData, MNG_FN_READ_GRAPHIC, MNG_LC_END);
  1222. #endif
  1223. return MNG_NOERROR;
  1224. }
  1225. /* ************************************************************************** */
  1226. #endif /* MNG_INCLUDE_READ_PROCS */
  1227. /* ************************************************************************** */
  1228. /* * end of file * */
  1229. /* ************************************************************************** */