/src/3rdparty/libmng/libmng_hlapi.c

https://bitbucket.org/ultra_iter/qt-vtl · C · 3001 lines · 2259 code · 420 blank · 322 comment · 207 complexity · 9a8a578c20fc316cbfe619debea91761 MD5 · raw file

  1. /* ************************************************************************** */
  2. /* * For conditions of distribution and use, * */
  3. /* * see copyright notice in libmng.h * */
  4. /* ************************************************************************** */
  5. /* * * */
  6. /* * project : libmng * */
  7. /* * file : libmng_hlapi.c copyright (c) 2000-2007 G.Juyn * */
  8. /* * version : 1.0.10 * */
  9. /* * * */
  10. /* * purpose : high-level application API (implementation) * */
  11. /* * * */
  12. /* * author : G.Juyn * */
  13. /* * * */
  14. /* * comment : implementation of the high-level function interface * */
  15. /* * for applications. * */
  16. /* * * */
  17. /* * changes : 0.5.1 - 05/06/2000 - G.Juyn * */
  18. /* * - added init of iPLTEcount * */
  19. /* * 0.5.1 - 05/08/2000 - G.Juyn * */
  20. /* * - changed calling-convention definition * */
  21. /* * - changed status-handling of display-routines * */
  22. /* * - added versioning-control routines * */
  23. /* * - filled the write routine * */
  24. /* * - changed strict-ANSI stuff * */
  25. /* * 0.5.1 - 05/11/2000 - G.Juyn * */
  26. /* * - added callback error-reporting support * */
  27. /* * 0.5.1 - 05/12/2000 - G.Juyn * */
  28. /* * - changed trace to macro for callback error-reporting * */
  29. /* * 0.5.1 - 05/13/2000 - G.Juyn * */
  30. /* * - added eMNGma hack (will be removed in 1.0.0 !!!) * */
  31. /* * - added TERM animation object pointer (easier reference) * */
  32. /* * 0.5.1 - 05/14/2000 - G.Juyn * */
  33. /* * - added cleanup of saved-data (SAVE/SEEK processing) * */
  34. /* * 0.5.1 - 05/16/2000 - G.Juyn * */
  35. /* * - moved the actual write_graphic functionality from here * */
  36. /* * to its appropriate function in the mng_write module * */
  37. /* * * */
  38. /* * 0.5.2 - 05/19/2000 - G.Juyn * */
  39. /* * - cleaned up some code regarding mixed support * */
  40. /* * - added JNG support * */
  41. /* * 0.5.2 - 05/24/2000 - G.Juyn * */
  42. /* * - moved init of default zlib parms here from "mng_zlib.c" * */
  43. /* * - added init of default IJG parms * */
  44. /* * 0.5.2 - 05/29/2000 - G.Juyn * */
  45. /* * - fixed inconsistancy with freeing global iCCP profile * */
  46. /* * 0.5.2 - 05/30/2000 - G.Juyn * */
  47. /* * - added delta-image field initialization * */
  48. /* * 0.5.2 - 06/06/2000 - G.Juyn * */
  49. /* * - added initialization of the buffer-suspend parameter * */
  50. /* * * */
  51. /* * 0.5.3 - 06/16/2000 - G.Juyn * */
  52. /* * - added initialization of update-region for refresh * */
  53. /* * - added initialization of Needrefresh parameter * */
  54. /* * 0.5.3 - 06/17/2000 - G.Juyn * */
  55. /* * - added initialization of Deltaimmediate * */
  56. /* * 0.5.3 - 06/21/2000 - G.Juyn * */
  57. /* * - added initialization of Speed * */
  58. /* * - added initialization of Imagelevel * */
  59. /* * 0.5.3 - 06/26/2000 - G.Juyn * */
  60. /* * - changed userdata variable to mng_ptr * */
  61. /* * 0.5.3 - 06/29/2000 - G.Juyn * */
  62. /* * - fixed initialization routine for new mng_handle type * */
  63. /* * * */
  64. /* * 0.9.1 - 07/06/2000 - G.Juyn * */
  65. /* * - changed mng_display_resume to allow to be called after * */
  66. /* * a suspension return with MNG_NEEDMOREDATA * */
  67. /* * - added returncode MNG_NEEDTIMERWAIT for timer breaks * */
  68. /* * 0.9.1 - 07/07/2000 - G.Juyn * */
  69. /* * - implemented support for freeze/reset/resume & go_xxxx * */
  70. /* * 0.9.1 - 07/08/2000 - G.Juyn * */
  71. /* * - added support for improved timing * */
  72. /* * - added support for improved I/O-suspension * */
  73. /* * 0.9.1 - 07/14/2000 - G.Juyn * */
  74. /* * - changed EOF processing behavior * */
  75. /* * 0.9.1 - 07/15/2000 - G.Juyn * */
  76. /* * - added callbacks for SAVE/SEEK processing * */
  77. /* * - added variable for NEEDSECTIONWAIT breaks * */
  78. /* * - added variable for freeze & reset processing * */
  79. /* * 0.9.1 - 07/17/2000 - G.Juyn * */
  80. /* * - added error cleanup processing * */
  81. /* * - fixed support for mng_display_reset() * */
  82. /* * - fixed suspension-buffering for 32K+ chunks * */
  83. /* * * */
  84. /* * 0.9.2 - 07/29/2000 - G.Juyn * */
  85. /* * - fixed small bugs in display processing * */
  86. /* * 0.9.2 - 07/31/2000 - G.Juyn * */
  87. /* * - fixed wrapping of suspension parameters * */
  88. /* * 0.9.2 - 08/04/2000 - G.Juyn * */
  89. /* * - B111096 - fixed large-buffer read-suspension * */
  90. /* * 0.9.2 - 08/05/2000 - G.Juyn * */
  91. /* * - changed file-prefixes * */
  92. /* * * */
  93. /* * 0.9.3 - 09/07/2000 - G.Juyn * */
  94. /* * - added support for new filter_types * */
  95. /* * 0.9.3 - 09/10/2000 - G.Juyn * */
  96. /* * - fixed DEFI behavior * */
  97. /* * 0.9.3 - 10/11/2000 - G.Juyn * */
  98. /* * - added support for nEED * */
  99. /* * 0.9.3 - 10/16/2000 - G.Juyn * */
  100. /* * - added optional support for bKGD for PNG images * */
  101. /* * - raised initial maximum canvas size * */
  102. /* * - added support for JDAA * */
  103. /* * 0.9.3 - 10/17/2000 - G.Juyn * */
  104. /* * - added callback to process non-critical unknown chunks * */
  105. /* * - fixed support for delta-images during read() / display() * */
  106. /* * 0.9.3 - 10/18/2000 - G.Juyn * */
  107. /* * - added closestream() processing for mng_cleanup() * */
  108. /* * 0.9.3 - 10/27/2000 - G.Juyn * */
  109. /* * - fixed separate read() & display() processing * */
  110. /* * * */
  111. /* * 0.9.4 - 11/20/2000 - G.Juyn * */
  112. /* * - fixed unwanted repetition in mng_readdisplay() * */
  113. /* * 0.9.4 - 11/24/2000 - G.Juyn * */
  114. /* * - moved restore of object 0 to libmng_display * */
  115. /* * * */
  116. /* * 1.0.1 - 02/08/2001 - G.Juyn * */
  117. /* * - added MEND processing callback * */
  118. /* * 1.0.1 - 02/13/2001 - G.Juyn * */
  119. /* * - fixed first FRAM_MODE=4 timing problem * */
  120. /* * 1.0.1 - 04/21/2001 - G.Juyn * */
  121. /* * - fixed bug with display_reset/display_resume (Thanks G!) * */
  122. /* * 1.0.1 - 04/22/2001 - G.Juyn * */
  123. /* * - fixed memory-leak (Thanks Gregg!) * */
  124. /* * 1.0.1 - 04/23/2001 - G.Juyn * */
  125. /* * - fixed reset_rundata to drop all objects * */
  126. /* * 1.0.1 - 04/25/2001 - G.Juyn * */
  127. /* * - moved mng_clear_cms to libmng_cms * */
  128. /* * * */
  129. /* * 1.0.2 - 06/23/2001 - G.Juyn * */
  130. /* * - added optimization option for MNG-video playback * */
  131. /* * - added processterm callback * */
  132. /* * 1.0.2 - 06/25/2001 - G.Juyn * */
  133. /* * - added option to turn off progressive refresh * */
  134. /* * * */
  135. /* * 1.0.5 - 07/08/2002 - G.Juyn * */
  136. /* * - B578572 - removed eMNGma hack (thanks Dimitri!) * */
  137. /* * 1.0.5 - 07/16/2002 - G.Juyn * */
  138. /* * - B581625 - large chunks fail with suspension reads * */
  139. /* * 1.0.5 - 08/19/2002 - G.Juyn * */
  140. /* * - B597134 - libmng pollutes the linker namespace * */
  141. /* * 1.0.5 - 09/15/2002 - G.Juyn * */
  142. /* * - fixed LOOP iteration=0 special case * */
  143. /* * 1.0.5 - 10/07/2002 - G.Juyn * */
  144. /* * - added another fix for misplaced TERM chunk * */
  145. /* * - completed support for condition=2 in TERM chunk * */
  146. /* * - added beta version function & constant * */
  147. /* * 1.0.5 - 10/11/2002 - G.Juyn * */
  148. /* * - added mng_status_dynamic to supports function * */
  149. /* * 1.0.5 - 11/04/2002 - G.Juyn * */
  150. /* * - changed FRAMECOUNT/LAYERCOUNT/PLAYTIME error to warning * */
  151. /* * 1.0.5 - 11/07/2002 - G.Juyn * */
  152. /* * - added support to get totals after mng_read() * */
  153. /* * 1.0.5 - 11/29/2002 - G.Juyn * */
  154. /* * - fixed goxxxxx() support for zero values * */
  155. /* * * */
  156. /* * 1.0.6 - 05/25/2003 - G.R-P * */
  157. /* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */
  158. /* * 1.0.6 - 07/11/2003 - G.R-P * */
  159. /* * - added conditionals zlib and jpeg property accessors * */
  160. /* * 1.0.6 - 07/14/2003 - G.R-P * */
  161. /* * - added conditionals around "mng_display_go*" and other * */
  162. /* * unused functions * */
  163. /* * 1.0.6 - 07/29/2003 - G.R-P * */
  164. /* * - added conditionals around PAST chunk support * */
  165. /* * * */
  166. /* * 1.0.7 - 03/07/2004 - G. Randers-Pehrson * */
  167. /* * - put gamma, cms-related declarations inside #ifdef * */
  168. /* * 1.0.7 - 03/10/2004 - G.R-P * */
  169. /* * - added conditionals around openstream/closestream * */
  170. /* * 1.0.7 - 03/24/2004 - G.R-P * */
  171. /* * - fixed zTXT -> zTXt typo * */
  172. /* * * */
  173. /* * 1.0.8 - 04/02/2004 - G.Juyn * */
  174. /* * - added CRC existence & checking flags * */
  175. /* * 1.0.8 - 04/10/2004 - G.Juyn * */
  176. /* * - added data-push mechanisms for specialized decoders * */
  177. /* * 1.0.8 - 07/06/2004 - G.R-P * */
  178. /* * - defend against using undefined openstream function * */
  179. /* * 1.0.8 - 08/02/2004 - G.Juyn * */
  180. /* * - added conditional to allow easier writing of large MNG's * */
  181. /* * * */
  182. /* * 1.0.9 - 08/17/2004 - G.R-P * */
  183. /* * - added more SKIPCHUNK conditionals * */
  184. /* * 1.0.9 - 09/25/2004 - G.Juyn * */
  185. /* * - replaced MNG_TWEAK_LARGE_FILES with permanent solution * */
  186. /* * 1.0.9 - 10/03/2004 - G.Juyn * */
  187. /* * - added function to retrieve current FRAM delay * */
  188. /* * 1.0.9 - 12/20/2004 - G.Juyn * */
  189. /* * - cleaned up macro-invocations (thanks to D. Airlie) * */
  190. /* * * */
  191. /* * 1.0.10 - 07/06/2005 - G.R-P * */
  192. /* * - added more SKIPCHUNK conditionals * */
  193. /* * 1.0.10 - 04/08/2007 - G.Juyn * */
  194. /* * - added support for mPNG proposal * */
  195. /* * 1.0.10 - 04/12/2007 - G.Juyn * */
  196. /* * - added support for ANG proposal * */
  197. /* * 1.0.10 - 07/06/2007 - G.R-P bugfix by Lucas Quintana * */
  198. /* * * */
  199. /* ************************************************************************** */
  200. #include "libmng.h"
  201. #include "libmng_data.h"
  202. #include "libmng_error.h"
  203. #include "libmng_trace.h"
  204. #ifdef __BORLANDC__
  205. #pragma hdrstop
  206. #endif
  207. #include "libmng_objects.h"
  208. #include "libmng_object_prc.h"
  209. #include "libmng_chunks.h"
  210. #include "libmng_memory.h"
  211. #include "libmng_read.h"
  212. #include "libmng_write.h"
  213. #include "libmng_display.h"
  214. #include "libmng_zlib.h"
  215. #include "libmng_jpeg.h"
  216. #include "libmng_cms.h"
  217. #include "libmng_pixels.h"
  218. #if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)
  219. #pragma option -A /* force ANSI-C */
  220. #endif
  221. /* ************************************************************************** */
  222. /* * * */
  223. /* * local routines * */
  224. /* * * */
  225. /* ************************************************************************** */
  226. #ifdef MNG_SUPPORT_DISPLAY
  227. MNG_LOCAL mng_retcode mng_drop_objects (mng_datap pData,
  228. mng_bool bDropaniobj)
  229. {
  230. mng_objectp pObject;
  231. mng_objectp pNext;
  232. mng_cleanupobject fCleanup;
  233. #ifdef MNG_SUPPORT_TRACE
  234. MNG_TRACE (pData, MNG_FN_DROP_OBJECTS, MNG_LC_START);
  235. #endif
  236. pObject = pData->pFirstimgobj; /* get first stored image-object (if any) */
  237. while (pObject) /* more objects to discard ? */
  238. {
  239. pNext = ((mng_object_headerp)pObject)->pNext;
  240. /* call appropriate cleanup */
  241. fCleanup = ((mng_object_headerp)pObject)->fCleanup;
  242. fCleanup (pData, pObject);
  243. pObject = pNext; /* neeeext */
  244. }
  245. pData->pFirstimgobj = MNG_NULL; /* clean this up!!! */
  246. pData->pLastimgobj = MNG_NULL;
  247. if (bDropaniobj) /* drop animation objects ? */
  248. {
  249. pObject = pData->pFirstaniobj; /* get first stored animation-object (if any) */
  250. while (pObject) /* more objects to discard ? */
  251. {
  252. pNext = ((mng_object_headerp)pObject)->pNext;
  253. /* call appropriate cleanup */
  254. fCleanup = ((mng_object_headerp)pObject)->fCleanup;
  255. fCleanup (pData, pObject);
  256. pObject = pNext; /* neeeext */
  257. }
  258. pData->pFirstaniobj = MNG_NULL; /* clean this up!!! */
  259. pData->pLastaniobj = MNG_NULL;
  260. #ifdef MNG_SUPPORT_DYNAMICMNG
  261. pObject = pData->pFirstevent; /* get first event-object (if any) */
  262. while (pObject) /* more objects to discard ? */
  263. {
  264. pNext = ((mng_object_headerp)pObject)->pNext;
  265. /* call appropriate cleanup */
  266. fCleanup = ((mng_object_headerp)pObject)->fCleanup;
  267. fCleanup (pData, pObject);
  268. pObject = pNext; /* neeeext */
  269. }
  270. pData->pFirstevent = MNG_NULL; /* clean this up!!! */
  271. pData->pLastevent = MNG_NULL;
  272. #endif
  273. }
  274. #ifdef MNG_INCLUDE_MPNG_PROPOSAL
  275. if (pData->pMPNG) /* drop MPNG data (if any) */
  276. {
  277. fCleanup = ((mng_object_headerp)pData->pMPNG)->fCleanup;
  278. fCleanup (pData, pData->pMPNG);
  279. pData->pMPNG = MNG_NULL;
  280. }
  281. #endif
  282. #ifdef MNG_INCLUDE_ANG_PROPOSAL
  283. if (pData->pANG) /* drop ANG data (if any) */
  284. {
  285. fCleanup = ((mng_object_headerp)pData->pANG)->fCleanup;
  286. fCleanup (pData, pData->pANG);
  287. pData->pANG = MNG_NULL;
  288. }
  289. #endif
  290. #ifdef MNG_SUPPORT_TRACE
  291. MNG_TRACE (pData, MNG_FN_DROP_OBJECTS, MNG_LC_END);
  292. #endif
  293. return MNG_NOERROR;
  294. }
  295. #endif /* MNG_SUPPORT_DISPLAY */
  296. /* ************************************************************************** */
  297. #ifdef MNG_SUPPORT_DISPLAY
  298. #ifndef MNG_SKIPCHUNK_SAVE
  299. MNG_LOCAL mng_retcode mng_drop_savedata (mng_datap pData)
  300. {
  301. #ifdef MNG_SUPPORT_TRACE
  302. MNG_TRACE (pData, MNG_FN_DROP_SAVEDATA, MNG_LC_START);
  303. #endif
  304. if (pData->pSavedata) /* sanity check */
  305. { /* address it more directly */
  306. mng_savedatap pSave = pData->pSavedata;
  307. if (pSave->iGlobalProfilesize) /* cleanup the profile ? */
  308. MNG_FREEX (pData, pSave->pGlobalProfile, pSave->iGlobalProfilesize);
  309. /* cleanup the save structure */
  310. MNG_FREE (pData, pData->pSavedata, sizeof (mng_savedata));
  311. }
  312. #ifdef MNG_SUPPORT_TRACE
  313. MNG_TRACE (pData, MNG_FN_DROP_SAVEDATA, MNG_LC_END);
  314. #endif
  315. return MNG_NOERROR;
  316. }
  317. #endif
  318. #endif /* MNG_SUPPORT_DISPLAY */
  319. /* ************************************************************************** */
  320. #ifdef MNG_SUPPORT_DISPLAY
  321. MNG_LOCAL mng_retcode mng_reset_rundata (mng_datap pData)
  322. {
  323. mng_drop_invalid_objects (pData); /* drop invalidly stored objects */
  324. #ifndef MNG_SKIPCHUNK_SAVE
  325. mng_drop_savedata (pData); /* drop stored savedata */
  326. #endif
  327. mng_reset_objzero (pData); /* reset object 0 */
  328. /* drop stored objects (if any) */
  329. mng_drop_objects (pData, MNG_FALSE);
  330. pData->bFramedone = MNG_FALSE;
  331. pData->iFrameseq = 0; /* reset counters & stuff */
  332. pData->iLayerseq = 0;
  333. pData->iFrametime = 0;
  334. pData->bSkipping = MNG_FALSE;
  335. #ifdef MNG_SUPPORT_DYNAMICMNG
  336. pData->bRunningevent = MNG_FALSE;
  337. pData->bStopafterseek = MNG_FALSE;
  338. pData->iEventx = 0;
  339. pData->iEventy = 0;
  340. pData->pLastmousemove = MNG_NULL;
  341. #endif
  342. pData->iRequestframe = 0;
  343. pData->iRequestlayer = 0;
  344. pData->iRequesttime = 0;
  345. pData->bSearching = MNG_FALSE;
  346. pData->iRuntime = 0;
  347. pData->iSynctime = 0;
  348. pData->iStarttime = 0;
  349. pData->iEndtime = 0;
  350. pData->bRunning = MNG_FALSE;
  351. pData->bTimerset = MNG_FALSE;
  352. pData->iBreakpoint = 0;
  353. pData->bSectionwait = MNG_FALSE;
  354. pData->bFreezing = MNG_FALSE;
  355. pData->bResetting = MNG_FALSE;
  356. pData->bNeedrefresh = MNG_FALSE;
  357. pData->bOnlyfirstframe = MNG_FALSE;
  358. pData->iFramesafterTERM = 0;
  359. pData->iIterations = 0;
  360. /* start of animation objects! */
  361. pData->pCurraniobj = MNG_NULL;
  362. pData->iUpdateleft = 0; /* reset region */
  363. pData->iUpdateright = 0;
  364. pData->iUpdatetop = 0;
  365. pData->iUpdatebottom = 0;
  366. pData->iPLTEcount = 0; /* reset PLTE data */
  367. #ifndef MNG_SKIPCHUNK_DEFI
  368. pData->iDEFIobjectid = 0; /* reset DEFI data */
  369. pData->bDEFIhasdonotshow = MNG_FALSE;
  370. pData->iDEFIdonotshow = 0;
  371. pData->bDEFIhasconcrete = MNG_FALSE;
  372. pData->iDEFIconcrete = 0;
  373. pData->bDEFIhasloca = MNG_FALSE;
  374. pData->iDEFIlocax = 0;
  375. pData->iDEFIlocay = 0;
  376. pData->bDEFIhasclip = MNG_FALSE;
  377. pData->iDEFIclipl = 0;
  378. pData->iDEFIclipr = 0;
  379. pData->iDEFIclipt = 0;
  380. pData->iDEFIclipb = 0;
  381. #endif
  382. #ifndef MNG_SKIPCHUNK_BACK
  383. pData->iBACKred = 0; /* reset BACK data */
  384. pData->iBACKgreen = 0;
  385. pData->iBACKblue = 0;
  386. pData->iBACKmandatory = 0;
  387. pData->iBACKimageid = 0;
  388. pData->iBACKtile = 0;
  389. #endif
  390. #ifndef MNG_SKIPCHUNK_FRAM
  391. pData->iFRAMmode = 1; /* default global FRAM variables */
  392. pData->iFRAMdelay = 1;
  393. pData->iFRAMtimeout = 0x7fffffffl;
  394. pData->bFRAMclipping = MNG_FALSE;
  395. pData->iFRAMclipl = 0;
  396. pData->iFRAMclipr = 0;
  397. pData->iFRAMclipt = 0;
  398. pData->iFRAMclipb = 0;
  399. pData->iFramemode = 1; /* again for the current frame */
  400. pData->iFramedelay = 1;
  401. pData->iFrametimeout = 0x7fffffffl;
  402. pData->bFrameclipping = MNG_FALSE;
  403. pData->iFrameclipl = 0;
  404. pData->iFrameclipr = 0;
  405. pData->iFrameclipt = 0;
  406. pData->iFrameclipb = 0;
  407. pData->iNextdelay = 1;
  408. pData->bForcedelay = MNG_FALSE;
  409. pData->iAccumdelay = 0;
  410. #endif
  411. #ifndef MNG_SKIPCHUNK_SHOW
  412. pData->iSHOWmode = 0; /* reset SHOW data */
  413. pData->iSHOWfromid = 0;
  414. pData->iSHOWtoid = 0;
  415. pData->iSHOWnextid = 0;
  416. pData->iSHOWskip = 0;
  417. #endif
  418. pData->iGlobalPLTEcount = 0; /* reset global PLTE data */
  419. pData->iGlobalTRNSrawlen = 0; /* reset global tRNS data */
  420. pData->iGlobalGamma = 0; /* reset global gAMA data */
  421. #ifndef MNG_SKIPCHUNK_cHRM
  422. pData->iGlobalWhitepointx = 0; /* reset global cHRM data */
  423. pData->iGlobalWhitepointy = 0;
  424. pData->iGlobalPrimaryredx = 0;
  425. pData->iGlobalPrimaryredy = 0;
  426. pData->iGlobalPrimarygreenx = 0;
  427. pData->iGlobalPrimarygreeny = 0;
  428. pData->iGlobalPrimarybluex = 0;
  429. pData->iGlobalPrimarybluey = 0;
  430. #endif
  431. #ifndef MNG_SKIPCHUNK_sRGB
  432. pData->iGlobalRendintent = 0; /* reset global sRGB data */
  433. #endif
  434. #ifndef MNG_SKIPCHUNK_iCCP
  435. if (pData->iGlobalProfilesize) /* drop global profile (if any) */
  436. MNG_FREE (pData, pData->pGlobalProfile, pData->iGlobalProfilesize);
  437. pData->iGlobalProfilesize = 0;
  438. #endif
  439. #ifndef MNG_SKIPCHUNK_bKGD
  440. pData->iGlobalBKGDred = 0; /* reset global bKGD data */
  441. pData->iGlobalBKGDgreen = 0;
  442. pData->iGlobalBKGDblue = 0;
  443. #endif
  444. #ifndef MNG_NO_DELTA_PNG
  445. /* reset delta-image */
  446. pData->pDeltaImage = MNG_NULL;
  447. pData->iDeltaImagetype = 0;
  448. pData->iDeltatype = 0;
  449. pData->iDeltaBlockwidth = 0;
  450. pData->iDeltaBlockheight = 0;
  451. pData->iDeltaBlockx = 0;
  452. pData->iDeltaBlocky = 0;
  453. pData->bDeltaimmediate = MNG_FALSE;
  454. pData->fDeltagetrow = MNG_NULL;
  455. pData->fDeltaaddrow = MNG_NULL;
  456. pData->fDeltareplacerow = MNG_NULL;
  457. pData->fDeltaputrow = MNG_NULL;
  458. pData->fPromoterow = MNG_NULL;
  459. pData->fPromBitdepth = MNG_NULL;
  460. pData->pPromBuf = MNG_NULL;
  461. pData->iPromColortype = 0;
  462. pData->iPromBitdepth = 0;
  463. pData->iPromFilltype = 0;
  464. pData->iPromWidth = 0;
  465. pData->pPromSrc = MNG_NULL;
  466. pData->pPromDst = MNG_NULL;
  467. #endif
  468. #ifndef MNG_SKIPCHUNK_MAGN
  469. pData->iMAGNfromid = 0;
  470. pData->iMAGNtoid = 0;
  471. #endif
  472. #ifndef MNG_SKIPCHUNK_PAST
  473. pData->iPastx = 0;
  474. pData->iPasty = 0;
  475. #endif
  476. pData->pLastseek = MNG_NULL;
  477. return MNG_NOERROR;
  478. }
  479. #endif /* MNG_SUPPORT_DISPLAY */
  480. /* ************************************************************************** */
  481. MNG_LOCAL void cleanup_errors (mng_datap pData)
  482. {
  483. pData->iErrorcode = MNG_NOERROR;
  484. pData->iSeverity = 0;
  485. pData->iErrorx1 = 0;
  486. pData->iErrorx2 = 0;
  487. pData->zErrortext = MNG_NULL;
  488. return;
  489. }
  490. /* ************************************************************************** */
  491. #ifdef MNG_SUPPORT_READ
  492. MNG_LOCAL mng_retcode make_pushbuffer (mng_datap pData,
  493. mng_ptr pPushdata,
  494. mng_size_t iLength,
  495. mng_bool bTakeownership,
  496. mng_pushdatap * pPush)
  497. {
  498. mng_pushdatap pTemp;
  499. MNG_ALLOC (pData, pTemp, sizeof(mng_pushdata));
  500. pTemp->pNext = MNG_NULL;
  501. if (bTakeownership) /* are we going to own the buffer? */
  502. { /* then just copy the pointer */
  503. pTemp->pData = (mng_uint8p)pPushdata;
  504. }
  505. else
  506. { /* otherwise create new buffer */
  507. MNG_ALLOCX (pData, pTemp->pData, iLength);
  508. if (!pTemp->pData) /* succeeded? */
  509. {
  510. MNG_FREEX (pData, pTemp, sizeof(mng_pushdata));
  511. MNG_ERROR (pData, MNG_OUTOFMEMORY);
  512. }
  513. /* and copy the bytes across */
  514. MNG_COPY (pTemp->pData, pPushdata, iLength);
  515. }
  516. pTemp->iLength = iLength;
  517. pTemp->bOwned = bTakeownership;
  518. pTemp->pDatanext = pTemp->pData;
  519. pTemp->iRemaining = iLength;
  520. *pPush = pTemp; /* return it */
  521. return MNG_NOERROR; /* and all's well */
  522. }
  523. #endif
  524. #ifdef MNG_VERSION_QUERY_SUPPORT
  525. /* ************************************************************************** */
  526. /* * * */
  527. /* * Versioning control * */
  528. /* * * */
  529. /* ************************************************************************** */
  530. mng_pchar MNG_DECL mng_version_text (void)
  531. {
  532. return MNG_VERSION_TEXT;
  533. }
  534. /* ************************************************************************** */
  535. mng_uint8 MNG_DECL mng_version_so (void)
  536. {
  537. return MNG_VERSION_SO;
  538. }
  539. /* ************************************************************************** */
  540. mng_uint8 MNG_DECL mng_version_dll (void)
  541. {
  542. return MNG_VERSION_DLL;
  543. }
  544. /* ************************************************************************** */
  545. mng_uint8 MNG_DECL mng_version_major (void)
  546. {
  547. return MNG_VERSION_MAJOR;
  548. }
  549. /* ************************************************************************** */
  550. mng_uint8 MNG_DECL mng_version_minor (void)
  551. {
  552. return MNG_VERSION_MINOR;
  553. }
  554. /* ************************************************************************** */
  555. mng_uint8 MNG_DECL mng_version_release (void)
  556. {
  557. return MNG_VERSION_RELEASE;
  558. }
  559. /* ************************************************************************** */
  560. mng_bool MNG_DECL mng_version_beta (void)
  561. {
  562. return MNG_VERSION_BETA;
  563. }
  564. #endif
  565. /* ************************************************************************** */
  566. /* * * */
  567. /* * 'supports' function * */
  568. /* * * */
  569. /* ************************************************************************** */
  570. #ifdef MNG_SUPPORT_FUNCQUERY
  571. typedef struct {
  572. mng_pchar zFunction;
  573. mng_uint8 iMajor; /* Major == 0 means not implemented ! */
  574. mng_uint8 iMinor;
  575. mng_uint8 iRelease;
  576. } mng_func_entry;
  577. typedef mng_func_entry const * mng_func_entryp;
  578. MNG_LOCAL mng_func_entry const func_table [] =
  579. { /* keep it alphabetically sorted !!!!! */
  580. {"mng_cleanup", 1, 0, 0},
  581. {"mng_copy_chunk", 1, 0, 5},
  582. {"mng_create", 1, 0, 0},
  583. {"mng_display", 1, 0, 0},
  584. {"mng_display_freeze", 1, 0, 0},
  585. #ifndef MNG_NO_DISPLAY_GO_SUPPORTED
  586. {"mng_display_goframe", 1, 0, 0},
  587. {"mng_display_golayer", 1, 0, 0},
  588. {"mng_display_gotime", 1, 0, 0},
  589. #endif
  590. {"mng_display_reset", 1, 0, 0},
  591. {"mng_display_resume", 1, 0, 0},
  592. {"mng_get_alphabitdepth", 1, 0, 0},
  593. {"mng_get_alphacompression", 1, 0, 0},
  594. {"mng_get_alphadepth", 1, 0, 0},
  595. {"mng_get_alphafilter", 1, 0, 0},
  596. {"mng_get_alphainterlace", 1, 0, 0},
  597. {"mng_get_bgcolor", 1, 0, 0},
  598. {"mng_get_bitdepth", 1, 0, 0},
  599. {"mng_get_bkgdstyle", 1, 0, 0},
  600. {"mng_get_cacheplayback", 1, 0, 2},
  601. {"mng_get_canvasstyle", 1, 0, 0},
  602. {"mng_get_colortype", 1, 0, 0},
  603. {"mng_get_compression", 1, 0, 0},
  604. #ifndef MNG_NO_CURRENT_INFO
  605. {"mng_get_currentframe", 1, 0, 0},
  606. {"mng_get_currentlayer", 1, 0, 0},
  607. {"mng_get_currentplaytime", 1, 0, 0},
  608. #endif
  609. {"mng_get_currframdelay", 1, 0, 9},
  610. #ifndef MNG_NO_DFLT_INFO
  611. {"mng_get_dfltimggamma", 1, 0, 0},
  612. {"mng_get_dfltimggammaint", 1, 0, 0},
  613. #endif
  614. {"mng_get_displaygamma", 1, 0, 0},
  615. {"mng_get_displaygammaint", 1, 0, 0},
  616. {"mng_get_doprogressive", 1, 0, 2},
  617. {"mng_get_filter", 1, 0, 0},
  618. {"mng_get_framecount", 1, 0, 0},
  619. {"mng_get_imageheight", 1, 0, 0},
  620. {"mng_get_imagelevel", 1, 0, 0},
  621. {"mng_get_imagetype", 1, 0, 0},
  622. {"mng_get_imagewidth", 1, 0, 0},
  623. {"mng_get_interlace", 1, 0, 0},
  624. #ifdef MNG_ACCESS_JPEG
  625. {"mng_get_jpeg_dctmethod", 1, 0, 0},
  626. {"mng_get_jpeg_maxjdat", 1, 0, 0},
  627. {"mng_get_jpeg_optimized", 1, 0, 0},
  628. {"mng_get_jpeg_progressive", 1, 0, 0},
  629. {"mng_get_jpeg_quality", 1, 0, 0},
  630. {"mng_get_jpeg_smoothing", 1, 0, 0},
  631. #endif
  632. {"mng_get_lastbackchunk", 1, 0, 3},
  633. {"mng_get_lastseekname", 1, 0, 5},
  634. {"mng_get_layercount", 1, 0, 0},
  635. #ifndef MNG_SKIP_MAXCANVAS
  636. {"mng_get_maxcanvasheight", 1, 0, 0},
  637. {"mng_get_maxcanvaswidth", 1, 0, 0},
  638. #endif
  639. {"mng_get_playtime", 1, 0, 0},
  640. {"mng_get_refreshpass", 1, 0, 0},
  641. {"mng_get_runtime", 1, 0, 0},
  642. {"mng_get_sectionbreaks", 1, 0, 0},
  643. {"mng_get_sigtype", 1, 0, 0},
  644. {"mng_get_simplicity", 1, 0, 0},
  645. {"mng_get_speed", 1, 0, 0},
  646. {"mng_get_srgb", 1, 0, 0},
  647. {"mng_get_starttime", 1, 0, 0},
  648. {"mng_get_storechunks", 1, 0, 0},
  649. {"mng_get_suspensionmode", 1, 0, 0},
  650. {"mng_get_ticks", 1, 0, 0},
  651. #ifndef MNG_NO_CURRENT_INFO
  652. {"mng_get_totalframes", 1, 0, 5},
  653. {"mng_get_totallayers", 1, 0, 5},
  654. {"mng_get_totalplaytime", 1, 0, 5},
  655. #endif
  656. {"mng_get_usebkgd", 1, 0, 0},
  657. {"mng_get_userdata", 1, 0, 0},
  658. #if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS)
  659. {"mng_get_viewgamma", 1, 0, 0},
  660. {"mng_get_viewgammaint", 1, 0, 0},
  661. #endif
  662. #ifdef MNG_ACCESS_ZLIB
  663. {"mng_get_zlib_level", 1, 0, 0},
  664. {"mng_get_zlib_maxidat", 1, 0, 0},
  665. {"mng_get_zlib_memlevel", 1, 0, 0},
  666. {"mng_get_zlib_method", 1, 0, 0},
  667. {"mng_get_zlib_strategy", 1, 0, 0},
  668. {"mng_get_zlib_windowbits", 1, 0, 0},
  669. #endif
  670. #ifndef MNG_NO_OPEN_CLOSE_STREAM
  671. {"mng_getcb_closestream", 1, 0, 0},
  672. #endif
  673. {"mng_getcb_errorproc", 1, 0, 0},
  674. {"mng_getcb_getalphaline", 1, 0, 0},
  675. {"mng_getcb_getbkgdline", 1, 0, 0},
  676. {"mng_getcb_getcanvasline", 1, 0, 0},
  677. {"mng_getcb_gettickcount", 1, 0, 0},
  678. {"mng_getcb_memalloc", 1, 0, 0},
  679. {"mng_getcb_memfree", 1, 0, 0},
  680. #ifndef MNG_NO_OPEN_CLOSE_STREAM
  681. {"mng_getcb_openstream", 1, 0, 0},
  682. #endif
  683. {"mng_getcb_processarow", 1, 0, 0},
  684. {"mng_getcb_processchroma", 1, 0, 0},
  685. {"mng_getcb_processgamma", 1, 0, 0},
  686. {"mng_getcb_processheader", 1, 0, 0},
  687. {"mng_getcb_processiccp", 1, 0, 0},
  688. {"mng_getcb_processmend", 1, 0, 1},
  689. {"mng_getcb_processneed", 1, 0, 0},
  690. {"mng_getcb_processsave", 1, 0, 0},
  691. {"mng_getcb_processseek", 1, 0, 0},
  692. {"mng_getcb_processsrgb", 1, 0, 0},
  693. {"mng_getcb_processterm", 1, 0, 2},
  694. {"mng_getcb_processtext", 1, 0, 0},
  695. {"mng_getcb_processunknown", 1, 0, 0},
  696. {"mng_getcb_readdata", 1, 0, 0},
  697. {"mng_getcb_refresh", 1, 0, 0},
  698. {"mng_getcb_releasedata", 1, 0, 8},
  699. {"mng_getcb_settimer", 1, 0, 0},
  700. {"mng_getcb_traceproc", 1, 0, 0},
  701. {"mng_getcb_writedata", 1, 0, 0},
  702. {"mng_getchunk_back", 1, 0, 0},
  703. {"mng_getchunk_basi", 1, 0, 0},
  704. #ifndef MNG_SKIPCHUNK_bKGD
  705. {"mng_getchunk_bkgd", 1, 0, 0},
  706. #endif
  707. #ifndef MNG_SKIPCHUNK_cHRM
  708. {"mng_getchunk_chrm", 1, 0, 0},
  709. #endif
  710. {"mng_getchunk_clip", 1, 0, 0},
  711. {"mng_getchunk_clon", 1, 0, 0},
  712. #ifndef MNG_NO_DELTA_PNG
  713. #ifndef MNG_SKIPCHUNK_dBYK
  714. {"mng_getchunk_dbyk", 1, 0, 0},
  715. #endif
  716. #endif
  717. {"mng_getchunk_defi", 1, 0, 0},
  718. #ifndef MNG_NO_DELTA_PNG
  719. {"mng_getchunk_dhdr", 1, 0, 0},
  720. #endif
  721. {"mng_getchunk_disc", 1, 0, 0},
  722. #ifndef MNG_NO_DELTA_PNG
  723. {"mng_getchunk_drop", 1, 0, 0},
  724. #endif
  725. {"mng_getchunk_endl", 1, 0, 0},
  726. #ifdef MNG_INCLUDE_MPNG_PROPOSAL
  727. {"mng_getchunk_mpng", 1, 0, 10},
  728. {"mng_getchunk_mpng_frame", 1, 0, 10},
  729. #endif
  730. #ifndef MNG_SKIPCHUNK_evNT
  731. {"mng_getchunk_evnt", 1, 0, 5},
  732. {"mng_getchunk_evnt_entry", 1, 0, 5},
  733. #endif
  734. #ifndef MNG_SKIPCHUNK_eXPI
  735. {"mng_getchunk_expi", 1, 0, 0},
  736. #endif
  737. #ifndef MNG_SKIPCHUNK_fPRI
  738. {"mng_getchunk_fpri", 1, 0, 0},
  739. #endif
  740. {"mng_getchunk_fram", 1, 0, 0},
  741. {"mng_getchunk_gama", 1, 0, 0},
  742. #ifndef MNG_SKIPCHUNK_hIST
  743. {"mng_getchunk_hist", 1, 0, 0},
  744. #endif
  745. #ifndef MNG_SKIPCHUNK_iCCP
  746. {"mng_getchunk_iccp", 1, 0, 0},
  747. #endif
  748. {"mng_getchunk_idat", 1, 0, 0},
  749. {"mng_getchunk_iend", 1, 0, 0},
  750. {"mng_getchunk_ihdr", 1, 0, 0},
  751. #ifndef MNG_NO_DELTA_PNG
  752. #ifdef MNG_INCLUDE_JNG
  753. {"mng_getchunk_ijng", 1, 0, 0},
  754. #endif
  755. {"mng_getchunk_ipng", 1, 0, 0},
  756. #endif
  757. #ifndef MNG_SKIPCHUNK_iTXt
  758. {"mng_getchunk_itxt", 1, 0, 0},
  759. #endif
  760. #ifdef MNG_INCLUDE_JNG
  761. {"mng_getchunk_jdaa", 1, 0, 0},
  762. {"mng_getchunk_jdat", 1, 0, 0},
  763. {"mng_getchunk_jhdr", 1, 0, 0},
  764. {"mng_getchunk_jsep", 1, 0, 0},
  765. #endif
  766. {"mng_getchunk_loop", 1, 0, 0},
  767. #ifndef MNG_SKIPCHUNK_MAGN
  768. {"mng_getchunk_magn", 1, 0, 0},
  769. #endif
  770. {"mng_getchunk_mend", 1, 0, 0},
  771. {"mng_getchunk_mhdr", 1, 0, 0},
  772. {"mng_getchunk_move", 1, 0, 0},
  773. #ifndef MNG_SKIPCHUNK_nEED
  774. {"mng_getchunk_need", 1, 0, 0},
  775. #endif
  776. #ifndef MNG_SKIPCHUNK_ORDR
  777. #ifndef MNG_NO_DELTA_PNG
  778. {"mng_getchunk_ordr", 1, 0, 0},
  779. {"mng_getchunk_ordr_entry", 1, 0, 0},
  780. #endif
  781. #endif
  782. #ifndef MNG_SKIPCHUNK_PAST
  783. {"mng_getchunk_past", 1, 0, 0},
  784. {"mng_getchunk_past_src", 1, 0, 0},
  785. #endif
  786. #ifndef MNG_SKIPCHUNK_pHYg
  787. {"mng_getchunk_phyg", 1, 0, 0},
  788. #endif
  789. #ifndef MNG_SKIPCHUNK_pHYs
  790. {"mng_getchunk_phys", 1, 0, 0},
  791. #endif
  792. #ifndef MNG_NO_DELTA_PNG
  793. {"mng_getchunk_plte", 1, 0, 0},
  794. {"mng_getchunk_pplt", 1, 0, 0},
  795. {"mng_getchunk_pplt_entry", 1, 0, 0},
  796. {"mng_getchunk_prom", 1, 0, 0},
  797. #endif
  798. #ifndef MNG_SKIPCHUNK_SAVE
  799. {"mng_getchunk_save", 1, 0, 0},
  800. {"mng_getchunk_save_entry", 1, 0, 0},
  801. #endif
  802. #ifndef MNG_SKIPCHUNK_sBIT
  803. {"mng_getchunk_sbit", 1, 0, 0},
  804. #endif
  805. #ifndef MNG_SKIPCHUNK_SEEK
  806. {"mng_getchunk_seek", 1, 0, 0},
  807. #endif
  808. {"mng_getchunk_show", 1, 0, 0},
  809. #ifndef MNG_SKIPCHUNK_sPLT
  810. {"mng_getchunk_splt", 1, 0, 0},
  811. #endif
  812. #ifndef MNG_SKIPCHUNK_sRGB
  813. {"mng_getchunk_srgb", 1, 0, 0},
  814. #endif
  815. {"mng_getchunk_term", 1, 0, 0},
  816. #ifndef MNG_SKIPCHUNK_tEXt
  817. {"mng_getchunk_text", 1, 0, 0},
  818. #endif
  819. #ifndef MNG_SKIPCHUNK_tIME
  820. {"mng_getchunk_time", 1, 0, 0},
  821. #endif
  822. {"mng_getchunk_trns", 1, 0, 0},
  823. {"mng_getchunk_unkown", 1, 0, 0},
  824. #ifndef MNG_SKIPCHUNK_zTXt
  825. {"mng_getchunk_ztxt", 1, 0, 0},
  826. #endif
  827. {"mng_getimgdata_chunk", 0, 0, 0},
  828. {"mng_getimgdata_chunkseq", 0, 0, 0},
  829. {"mng_getimgdata_seq", 0, 0, 0},
  830. {"mng_getlasterror", 1, 0, 0},
  831. {"mng_initialize", 1, 0, 0},
  832. {"mng_iterate_chunks", 1, 0, 0},
  833. {"mng_putchunk_back", 1, 0, 0},
  834. #ifndef MNG_SKIPCHUNK_BASI
  835. {"mng_putchunk_basi", 1, 0, 0},
  836. #endif
  837. #ifndef MNG_SKIPCHUNK_bKGD
  838. {"mng_putchunk_bkgd", 1, 0, 0},
  839. #endif
  840. #ifndef MNG_SKIPCHUNK_cHRM
  841. {"mng_putchunk_chrm", 1, 0, 0},
  842. #endif
  843. {"mng_putchunk_clip", 1, 0, 0},
  844. {"mng_putchunk_clon", 1, 0, 0},
  845. #ifndef MNG_NO_DELTA_PNG
  846. #ifndef MNG_SKIPCHUNK_DBYK
  847. {"mng_putchunk_dbyk", 1, 0, 0},
  848. #endif
  849. #endif
  850. {"mng_putchunk_defi", 1, 0, 0},
  851. #ifndef MNG_NO_DELTA_PNG
  852. {"mng_putchunk_dhdr", 1, 0, 0},
  853. #endif
  854. {"mng_putchunk_disc", 1, 0, 0},
  855. #ifndef MNG_NO_DELTA_PNG
  856. {"mng_putchunk_drop", 1, 0, 0},
  857. #endif
  858. {"mng_putchunk_endl", 1, 0, 0},
  859. #ifdef MNG_INCLUDE_MPNG_PROPOSAL
  860. {"mng_putchunk_mpng", 1, 0, 10},
  861. {"mng_putchunk_mpng_frame", 1, 0, 10},
  862. #endif
  863. #ifndef MNG_SKIPCHUNK_evNT
  864. {"mng_putchunk_evnt", 1, 0, 5},
  865. {"mng_putchunk_evnt_entry", 1, 0, 5},
  866. #endif
  867. #ifndef MNG_SKIPCHUNK_eXPI
  868. {"mng_putchunk_expi", 1, 0, 0},
  869. #endif
  870. #ifndef MNG_SKIPCHUNK_fPRI
  871. {"mng_putchunk_fpri", 1, 0, 0},
  872. #endif
  873. #ifndef MNG_SKIPCHUNK_FRAM
  874. {"mng_putchunk_fram", 1, 0, 0},
  875. #endif
  876. {"mng_putchunk_gama", 1, 0, 0},
  877. #ifndef MNG_SKIPCHUNK_hIST
  878. {"mng_putchunk_hist", 1, 0, 0},
  879. #endif
  880. #ifndef MNG_SKIPCHUNK_iCCP
  881. {"mng_putchunk_iccp", 1, 0, 0},
  882. #endif
  883. {"mng_putchunk_idat", 1, 0, 0},
  884. {"mng_putchunk_iend", 1, 0, 0},
  885. {"mng_putchunk_ihdr", 1, 0, 0},
  886. #ifndef MNG_NO_DELTA_PNG
  887. #ifdef MNG_INCLUDE_JNG
  888. {"mng_putchunk_ijng", 1, 0, 0},
  889. #endif
  890. {"mng_putchunk_ipng", 1, 0, 0},
  891. #endif
  892. #ifndef MNG_SKIPCHUNK_iTXt
  893. {"mng_putchunk_itxt", 1, 0, 0},
  894. #endif
  895. #ifdef MNG_INCLUDE_JNG
  896. {"mng_putchunk_jdaa", 1, 0, 0},
  897. {"mng_putchunk_jdat", 1, 0, 0},
  898. {"mng_putchunk_jhdr", 1, 0, 0},
  899. {"mng_putchunk_jsep", 1, 0, 0},
  900. #endif
  901. {"mng_putchunk_loop", 1, 0, 0},
  902. #ifndef MNG_SKIPCHUNK_MAGN
  903. {"mng_putchunk_magn", 1, 0, 0},
  904. #endif
  905. {"mng_putchunk_mend", 1, 0, 0},
  906. {"mng_putchunk_mhdr", 1, 0, 0},
  907. {"mng_putchunk_move", 1, 0, 0},
  908. #ifndef MNG_SKIPCHUNK_nEED
  909. {"mng_putchunk_need", 1, 0, 0},
  910. #endif
  911. #ifndef MNG_NO_DELTA_PNG
  912. #ifndef MNG_SKIPCHUNK_ORDR
  913. {"mng_putchunk_ordr", 1, 0, 0},
  914. {"mng_putchunk_ordr_entry", 1, 0, 0},
  915. #endif
  916. #endif
  917. #ifndef MNG_SKIPCHUNK_PAST
  918. {"mng_putchunk_past", 1, 0, 0},
  919. {"mng_putchunk_past_src", 1, 0, 0},
  920. #endif
  921. #ifndef MNG_SKIPCHUNK_pHYg
  922. {"mng_putchunk_phyg", 1, 0, 0},
  923. #endif
  924. #ifndef MNG_SKIPCHUNK_pHYs
  925. {"mng_putchunk_phys", 1, 0, 0},
  926. #endif
  927. #ifndef MNG_NO_DELTA_PNG
  928. {"mng_putchunk_plte", 1, 0, 0},
  929. {"mng_putchunk_pplt", 1, 0, 0},
  930. {"mng_putchunk_pplt_entry", 1, 0, 0},
  931. {"mng_putchunk_prom", 1, 0, 0},
  932. #endif
  933. #ifndef MNG_SKIPCHUNK_SAVE
  934. {"mng_putchunk_save", 1, 0, 0},
  935. {"mng_putchunk_save_entry", 1, 0, 0},
  936. #endif
  937. #ifndef MNG_SKIPCHUNK_sBIT
  938. {"mng_putchunk_sbit", 1, 0, 0},
  939. #endif
  940. #ifndef MNG_SKIPCHUNK_SEEK
  941. {"mng_putchunk_seek", 1, 0, 0},
  942. #endif
  943. {"mng_putchunk_show", 1, 0, 0},
  944. #ifndef MNG_SKIPCHUNK_sPLT
  945. {"mng_putchunk_splt", 1, 0, 0},
  946. #endif
  947. #ifndef MNG_SKIPCHUNK_sRGB
  948. {"mng_putchunk_srgb", 1, 0, 0},
  949. #endif
  950. {"mng_putchunk_term", 1, 0, 0},
  951. #ifndef MNG_SKIPCHUNK_tEXt
  952. {"mng_putchunk_text", 1, 0, 0},
  953. #endif
  954. #ifndef MNG_SKIPCHUNK_tIME
  955. {"mng_putchunk_time", 1, 0, 0},
  956. #endif
  957. {"mng_putchunk_trns", 1, 0, 0},
  958. {"mng_putchunk_unkown", 1, 0, 0},
  959. #ifndef MNG_SKIPCHUNK_zTXt
  960. {"mng_putchunk_ztxt", 1, 0, 0},
  961. #endif
  962. {"mng_putimgdata_ihdr", 0, 0, 0},
  963. {"mng_putimgdata_jhdr", 0, 0, 0},
  964. {"mng_reset", 1, 0, 0},
  965. {"mng_read", 1, 0, 0},
  966. {"mng_read_pushchunk", 1, 0, 8},
  967. {"mng_read_pushdata", 1, 0, 8},
  968. {"mng_read_pushsig", 1, 0, 8},
  969. {"mng_read_resume", 1, 0, 0},
  970. {"mng_readdisplay", 1, 0, 0},
  971. {"mng_set_bgcolor", 1, 0, 0},
  972. {"mng_set_bkgdstyle", 1, 0, 0},
  973. {"mng_set_cacheplayback", 1, 0, 2},
  974. {"mng_set_canvasstyle", 1, 0, 0},
  975. {"mng_set_dfltimggamma", 1, 0, 0},
  976. #ifndef MNG_NO_DFLT_INFO
  977. {"mng_set_dfltimggammaint", 1, 0, 0},
  978. #endif
  979. {"mng_set_displaygamma", 1, 0, 0},
  980. {"mng_set_displaygammaint", 1, 0, 0},
  981. {"mng_set_doprogressive", 1, 0, 2},
  982. #ifdef MNG_ACCESS_JPEG
  983. {"mng_set_jpeg_dctmethod", 1, 0, 0},
  984. {"mng_set_jpeg_maxjdat", 1, 0, 0},
  985. {"mng_set_jpeg_optimized", 1, 0, 0},
  986. {"mng_set_jpeg_progressive", 1, 0, 0},
  987. {"mng_set_jpeg_quality", 1, 0, 0},
  988. {"mng_set_jpeg_smoothing", 1, 0, 0},
  989. #endif
  990. #ifndef MNG_SKIP_MAXCANVAS
  991. {"mng_set_maxcanvasheight", 1, 0, 0},
  992. {"mng_set_maxcanvassize", 1, 0, 0},
  993. {"mng_set_maxcanvaswidth", 1, 0, 0},
  994. #endif
  995. {"mng_set_outputprofile", 1, 0, 0},
  996. {"mng_set_outputprofile2", 1, 0, 0},
  997. {"mng_set_outputsrgb", 1, 0, 1},
  998. {"mng_set_sectionbreaks", 1, 0, 0},
  999. {"mng_set_speed", 1, 0, 0},
  1000. {"mng_set_srgb", 1, 0, 0},
  1001. {"mng_set_srgbimplicit", 1, 0, 1},
  1002. {"mng_set_srgbprofile", 1, 0, 0},
  1003. {"mng_set_srgbprofile2", 1, 0, 0},
  1004. {"mng_set_storechunks", 1, 0, 0},
  1005. {"mng_set_suspensionmode", 1, 0, 0},
  1006. {"mng_set_usebkgd", 1, 0, 0},
  1007. {"mng_set_userdata", 1, 0, 0},
  1008. #if defined(MNG_FULL_CMS) || defined(MNG_GAMMA_ONLY) || defined(MNG_APP_CMS)
  1009. {"mng_set_viewgamma", 1, 0, 0},
  1010. {"mng_set_viewgammaint", 1, 0, 0},
  1011. #endif
  1012. #ifdef MNG_ACCESS_ZLIB
  1013. {"mng_set_zlib_level", 1, 0, 0},
  1014. {"mng_set_zlib_maxidat", 1, 0, 0},
  1015. {"mng_set_zlib_memlevel", 1, 0, 0},
  1016. {"mng_set_zlib_method", 1, 0, 0},
  1017. {"mng_set_zlib_strategy", 1, 0, 0},
  1018. {"mng_set_zlib_windowbits", 1, 0, 0},
  1019. #endif
  1020. #ifndef MNG_NO_OPEN_CLOSE_STREAM
  1021. {"mng_setcb_closestream", 1, 0, 0},
  1022. #endif
  1023. {"mng_setcb_errorproc", 1, 0, 0},
  1024. {"mng_setcb_getalphaline", 1, 0, 0},
  1025. {"mng_setcb_getbkgdline", 1, 0, 0},
  1026. {"mng_setcb_getcanvasline", 1, 0, 0},
  1027. {"mng_setcb_gettickcount", 1, 0, 0},
  1028. {"mng_setcb_memalloc", 1, 0, 0},
  1029. {"mng_setcb_memfree", 1, 0, 0},
  1030. #ifndef MNG_NO_OPEN_CLOSE_STREAM
  1031. {"mng_setcb_openstream", 1, 0, 0},
  1032. #endif
  1033. {"mng_setcb_processarow", 1, 0, 0},
  1034. {"mng_setcb_processchroma", 1, 0, 0},
  1035. {"mng_setcb_processgamma", 1, 0, 0},
  1036. {"mng_setcb_processheader", 1, 0, 0},
  1037. {"mng_setcb_processiccp", 1, 0, 0},
  1038. {"mng_setcb_processmend", 1, 0, 1},
  1039. {"mng_setcb_processneed", 1, 0, 0},
  1040. {"mng_setcb_processsave", 1, 0, 0},
  1041. {"mng_setcb_processseek", 1, 0, 0},
  1042. {"mng_setcb_processsrgb", 1, 0, 0},
  1043. {"mng_setcb_processterm", 1, 0, 2},
  1044. {"mng_setcb_processtext", 1, 0, 0},
  1045. {"mng_setcb_processunknown", 1, 0, 0},
  1046. {"mng_setcb_readdata", 1, 0, 0},
  1047. {"mng_setcb_refresh", 1, 0, 0},
  1048. {"mng_setcb_releasedata", 1, 0, 8},
  1049. {"mng_setcb_settimer", 1, 0, 0},
  1050. {"mng_setcb_traceproc", 1, 0, 0},
  1051. {"mng_setcb_writedata", 1, 0, 0},
  1052. {"mng_status_creating", 1, 0, 0},
  1053. {"mng_status_displaying", 1, 0, 0},
  1054. {"mng_status_dynamic", 1, 0, 5},
  1055. {"mng_status_error", 1, 0, 0},
  1056. {"mng_status_reading", 1, 0, 0},
  1057. {"mng_status_running", 1, 0, 0},
  1058. {"mng_status_runningevent", 1, 0, 5},
  1059. {"mng_status_suspendbreak", 1, 0, 0},
  1060. {"mng_status_timerbreak", 1, 0, 0},
  1061. {"mng_status_writing", 1, 0, 0},
  1062. {"mng_supports_func", 1, 0, 5},
  1063. {"mng_trapevent", 1, 0, 5},
  1064. {"mng_updatemngheader", 1, 0, 0},
  1065. {"mng_updatemngsimplicity", 1, 0, 0},
  1066. {"mng_version_beta", 1, 0, 5},
  1067. {"mng_version_dll", 1, 0, 0},
  1068. {"mng_version_major", 1, 0, 0},
  1069. {"mng_version_minor", 1, 0, 0},
  1070. {"mng_version_release", 1, 0, 0},
  1071. {"mng_version_so", 1, 0, 0},
  1072. {"mng_version_text", 1, 0, 0},
  1073. {"mng_write", 1, 0, 0},
  1074. };
  1075. mng_bool MNG_DECL mng_supports_func (mng_pchar zFunction,
  1076. mng_uint8* iMajor,
  1077. mng_uint8* iMinor,
  1078. mng_uint8* iRelease)
  1079. {
  1080. mng_int32 iTop, iLower, iUpper, iMiddle;
  1081. mng_func_entryp pEntry; /* pointer to found entry */
  1082. /* determine max index of table */
  1083. iTop = (sizeof (func_table) / sizeof (func_table [0])) - 1;
  1084. iLower = 0; /* initialize binary search */
  1085. iMiddle = iTop >> 1; /* start in the middle */
  1086. iUpper = iTop;
  1087. pEntry = 0; /* no goods yet! */
  1088. do /* the binary search itself */
  1089. {
  1090. mng_int32 iRslt = strcmp(func_table [iMiddle].zFunction, zFunction);
  1091. if (iRslt < 0)
  1092. iLower = iMiddle + 1;
  1093. else if (iRslt > 0)
  1094. iUpper = iMiddle - 1;
  1095. else
  1096. {
  1097. pEntry = &func_table [iMiddle];
  1098. break;
  1099. };
  1100. iMiddle = (iLower + iUpper) >> 1;
  1101. }
  1102. while (iLower <= iUpper);
  1103. if (pEntry) /* found it ? */
  1104. {
  1105. *iMajor = pEntry->iMajor;
  1106. *iMinor = pEntry->iMinor;
  1107. *iRelease = pEntry->iRelease;
  1108. return MNG_TRUE;
  1109. }
  1110. else
  1111. {
  1112. *iMajor = 0;
  1113. *iMinor = 0;
  1114. *iRelease = 0;
  1115. return MNG_FALSE;
  1116. }
  1117. }
  1118. #endif
  1119. /* ************************************************************************** */
  1120. /* * * */
  1121. /* * HLAPI routines * */
  1122. /* * * */
  1123. /* ************************************************************************** */
  1124. mng_handle MNG_DECL mng_initialize (mng_ptr pUserdata,
  1125. mng_memalloc fMemalloc,
  1126. mng_memfree fMemfree,
  1127. mng_traceproc fTraceproc)
  1128. {
  1129. mng_datap pData;
  1130. #ifdef MNG_SUPPORT_DISPLAY
  1131. mng_retcode iRetcode;
  1132. mng_imagep pImage;
  1133. #endif
  1134. #ifdef MNG_INTERNAL_MEMMNGMT /* allocate the main datastruc */
  1135. pData = (mng_datap)calloc (1, sizeof (mng_data));
  1136. #else
  1137. pData = (mng_datap)fMemalloc (sizeof (mng_data));
  1138. #endif
  1139. if (!pData)
  1140. return MNG_NULL; /* error: out of memory?? */
  1141. /* validate the structure */
  1142. pData->iMagic = MNG_MAGIC;
  1143. /* save userdata field */
  1144. pData->pUserdata = pUserdata;
  1145. /* remember trace callback */
  1146. pData->fTraceproc = fTraceproc;
  1147. #ifdef MNG_SUPPORT_TRACE
  1148. if (mng_trace (pData, MNG_FN_INITIALIZE, MNG_LC_INITIALIZE))
  1149. {
  1150. MNG_FREEX (pData, pData, sizeof (mng_data));
  1151. return MNG_NULL;
  1152. }
  1153. #endif
  1154. /* default canvas styles are 8-bit RGB */
  1155. pData->iCanvasstyle = MNG_CANVAS_RGB8;
  1156. pData->iBkgdstyle = MNG_CANVAS_RGB8;
  1157. pData->iBGred = 0; /* black */
  1158. pData->iBGgreen = 0;
  1159. pData->iBGblue = 0;
  1160. pData->bUseBKGD = MNG_TRUE;
  1161. #ifdef MNG_FULL_CMS
  1162. pData->bIssRGB = MNG_TRUE;
  1163. pData->hProf1 = 0; /* no profiles yet */
  1164. pData->hProf2 = 0;
  1165. pData->hProf3 = 0;
  1166. pData->hTrans = 0;
  1167. #endif
  1168. pData->dViewgamma = 1.0;
  1169. pData->dDisplaygamma = 2.2;
  1170. pData->dDfltimggamma = 0.45455;
  1171. /* initially remember chunks */
  1172. pData->bStorechunks = MNG_TRUE;
  1173. /* no breaks at section-borders */
  1174. pData->bSectionbreaks = MNG_FALSE;
  1175. /* initially cache playback info */
  1176. pData->bCacheplayback = MNG_TRUE;
  1177. /* progressive refresh for large images */
  1178. pData->bDoProgressive = MNG_TRUE;
  1179. /* crc exists; should check; error for
  1180. critical chunks; warning for ancillery;
  1181. generate crc for output */
  1182. pData->iCrcmode = MNG_CRC_DEFAULT;
  1183. /* normal animation-speed ! */
  1184. pData->iSpeed = mng_st_normal;
  1185. /* initial image limits */
  1186. pData->iMaxwidth = 10000;
  1187. pData->iMaxheight = 10000;
  1188. #ifdef MNG_INTERNAL_MEMMNGMT /* internal management */
  1189. pData->fMemalloc = MNG_NULL;
  1190. pData->fMemfree = MNG_NULL;
  1191. #else /* keep callbacks */
  1192. pData->fMemalloc = fMemalloc;
  1193. pData->fMemfree = fMemfree;
  1194. #endif
  1195. /* no value (yet) */
  1196. pData->fReleasedata = MNG_NULL;
  1197. #ifndef MNG_NO_OPEN_CLOSE_STREAM
  1198. pData->fOpenstream = MNG_NULL;
  1199. pData->fClosestream = MNG_NULL;
  1200. #endif
  1201. pData->fReaddata = MNG_NULL;
  1202. pData->fWritedata = MNG_NULL;
  1203. pData->fErrorproc = MNG_NULL;
  1204. pData->fProcessheader = MNG_NULL;
  1205. pData->fProcesstext = MNG_NULL;
  1206. pData->fProcesssave = MNG_NULL;
  1207. pData->fProcessseek = MNG_NULL;
  1208. pData->fProcessneed = MNG_NULL;
  1209. pData->fProcessmend = MNG_NULL;
  1210. pData->fProcessunknown = MNG_NULL;
  1211. pData->fProcessterm = MNG_NULL;
  1212. pData->fGetcanvasline = MNG_NULL;
  1213. pData->fGetbkgdline = MNG_NULL;
  1214. pData->fGetalphaline = MNG_NULL;
  1215. pData->fRefresh = MNG_NULL;
  1216. pData->fGettickcount = MNG_NULL;
  1217. pData->fSettimer = MNG_NULL;
  1218. pData->fProcessgamma = MNG_NULL;
  1219. pData->fProcesschroma = MNG_NULL;
  1220. pData->fProcesssrgb = MNG_NULL;
  1221. pData->fProcessiccp = MNG_NULL;
  1222. pData->fProcessarow = MNG_NULL;
  1223. #if defined(MNG_SUPPORT_DISPLAY) && (defined(MNG_GAMMA_ONLY) || defined(MNG_FULL_CMS))
  1224. pData->dLastgamma = 0; /* lookup table needs first-time calc */
  1225. #endif
  1226. #ifdef MNG_SUPPORT_DISPLAY /* create object 0 */
  1227. iRetcode = mng_create_imageobject (pData, 0, MNG_TRUE, MNG_TRUE, MNG_TRUE,
  1228. 0, 0, 0, 0, 0, 0, 0, 0, 0, MNG_FALSE,
  1229. 0, 0, 0, 0, &pImage);
  1230. if (iRetcode) /* on error drop out */
  1231. {
  1232. MNG_FREEX (pData, pData, sizeof (mng_data));
  1233. return MNG_NULL;
  1234. }
  1235. pData->pObjzero = pImage;
  1236. #endif
  1237. #if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_INCLUDE_LCMS)
  1238. mnglcms_initlibrary (); /* init lcms particulars */
  1239. #endif
  1240. #ifdef MNG_SUPPORT_READ
  1241. pData->bSuspensionmode = MNG_FALSE;
  1242. pData->iSuspendbufsize = 0;
  1243. pData->pSuspendbuf = MNG_NULL;
  1244. pData->pSuspendbufnext = MNG_NULL;
  1245. pData->iSuspendbufleft = 0;
  1246. pData->iChunklen = 0;
  1247. pData->pReadbufnext = MNG_NULL;
  1248. pData->pLargebufnext = MNG_NULL;
  1249. pData->pFirstpushchunk = MNG_NULL;
  1250. pData->pLastpushchunk = MNG_NULL;
  1251. pData->pFirstpushdata = MNG_NULL;
  1252. pData->pLastpushdata = MNG_NULL;
  1253. #endif
  1254. #ifdef MNG_INCLUDE_ZLIB
  1255. mngzlib_initialize (pData); /* initialize zlib structures and such */
  1256. /* default zlib compression parameters */
  1257. pData->iZlevel = MNG_ZLIB_LEVEL;
  1258. pData->iZmethod = MNG_ZLIB_METHOD;
  1259. pData->iZwindowbits = MNG_ZLIB_WINDOWBITS;
  1260. pData->iZmemlevel = MNG_ZLIB_MEMLEVEL;
  1261. pData->iZstrategy = MNG_ZLIB_STRATEGY;
  1262. /* default maximum IDAT data size */
  1263. pData->iMaxIDAT = MNG_MAX_IDAT_SIZE;
  1264. #endif
  1265. #ifdef MNG_INCLUDE_JNG /* default IJG compression parameters */
  1266. pData->eJPEGdctmethod = MNG_JPEG_DCT;
  1267. pData->iJPEGquality = MNG_JPEG_QUALITY;
  1268. pData->iJPEGsmoothing = MNG_JPEG_SMOOTHING;
  1269. pData->bJPEGcompressprogr = MNG_JPEG_PROGRESSIVE;
  1270. pData->bJPEGcompressopt = MNG_JPEG_OPTIMIZED;
  1271. /* default maximum JDAT data size */
  1272. pData->iMaxJDAT = MNG_MAX_JDAT_SIZE;
  1273. #endif
  1274. mng_reset ((mng_handle)pData);
  1275. #ifdef MNG_SUPPORT_TRACE
  1276. if (mng_trace (pData, MNG_FN_INITIALIZE, MNG_LC_END))
  1277. {
  1278. MNG_FREEX (pData, pData, sizeof (mng_data));
  1279. return MNG_NULL;
  1280. }
  1281. #endif
  1282. return (mng_handle)pData; /* if we get here, we're in business */
  1283. }
  1284. /* ************************************************************************** */
  1285. mng_retcode MNG_DECL mng_reset (mng_handle hHandle)
  1286. {
  1287. mng_datap pData;
  1288. #ifdef MNG_SUPPORT_TRACE
  1289. MNG_TRACE (((mng_datap)hHandle), MNG_FN_RESET, MNG_LC_START);
  1290. #endif
  1291. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  1292. pData = ((mng_datap)(hHandle)); /* address main structure */
  1293. #ifdef MNG_SUPPORT_DISPLAY
  1294. #ifndef MNG_SKIPCHUNK_SAVE
  1295. mng_drop_savedata (pData); /* cleanup saved-data from SAVE/SEEK */
  1296. #endif
  1297. #endif
  1298. #if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_FULL_CMS)
  1299. mng_clear_cms (pData); /* cleanup left-over cms stuff if any */
  1300. #endif
  1301. #if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_INCLUDE_JNG)
  1302. mngjpeg_cleanup (pData); /* cleanup jpeg stuff */
  1303. #endif
  1304. #ifdef MNG_INCLUDE_ZLIB
  1305. if (pData->bInflating) /* if we've been inflating */
  1306. {
  1307. #ifdef MNG_INCLUDE_DISPLAY_PROCS
  1308. mng_cleanup_rowproc (pData); /* cleanup row-processing, */
  1309. #endif
  1310. mngzlib_inflatefree (pData); /* cleanup inflate! */
  1311. }
  1312. #endif /* MNG_INCLUDE_ZLIB */
  1313. #ifdef MNG_SUPPORT_READ
  1314. if ((pData->bReading) && (!pData->bEOF))
  1315. mng_process_eof (pData); /* cleanup app streaming */
  1316. /* cleanup default read buffers */
  1317. MNG_FREE (pData, pData->pReadbuf, pData->iReadbufsize);
  1318. MNG_FREE (pData, pData->pLargebuf, pData->iLargebufsize);
  1319. MNG_FREE (pData, pData->pSuspendbuf, pData->iSuspendbufsize);
  1320. while (pData->pFirstpushdata) /* release any pushed data & chunks */
  1321. mng_release_pushdata (pData);
  1322. while (pData->pFirstpushchunk)
  1323. mng_release_pushchunk (pData);
  1324. #endif
  1325. #ifdef MNG_SUPPORT_WRITE /* cleanup default write buffer */
  1326. MNG_FREE (pData, pData->pWritebuf, pData->iWritebufsize);
  1327. #endif
  1328. #if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE)
  1329. mng_drop_chunks (pData); /* drop stored chunks (if any) */
  1330. #endif
  1331. #ifdef MNG_SUPPORT_DISPLAY
  1332. mng_drop_objects (pData, MNG_TRUE); /* drop stored objects (if any) */
  1333. #ifndef MNG_SKIPCHUNK_iCCP
  1334. if (pData->iGlobalProfilesize) /* drop global profile (if any) */
  1335. MNG_FREEX (pData, pData->pGlobalProfile, pData->iGlobalProfilesize);
  1336. #endif
  1337. #endif
  1338. pData->eSigtype = mng_it_unknown;
  1339. pData->eImagetype = mng_it_unknown;
  1340. pData->iWidth = 0; /* these are unknown yet */
  1341. pData->iHeight = 0;
  1342. pData->iTicks = 0;
  1343. pData->iLayercount = 0;
  1344. pData->iFramecount = 0;
  1345. pData->iPlaytime = 0;
  1346. pData->iSimplicity = 0;
  1347. pData->iAlphadepth = 16; /* assume the worst! */
  1348. pData->iImagelevel = 0; /* no image encountered */
  1349. pData->iMagnify = 0; /* 1-to-1 display */
  1350. pData->iOffsetx = 0; /* no offsets */
  1351. pData->iOffsety = 0;
  1352. pData->iCanvaswidth = 0; /* let the app decide during processheader */
  1353. pData->iCanvasheight = 0;
  1354. /* so far, so good */
  1355. pData->iErrorcode = MNG_NOERROR;
  1356. pData->iSeverity = 0;
  1357. pData->iErrorx1 = 0;
  1358. pData->iErrorx2 = 0;
  1359. pData->zErrortext = MNG_NULL;
  1360. #if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE)
  1361. /* let's assume the best scenario */
  1362. #ifndef MNG_NO_OLD_VERSIONS
  1363. pData->bPreDraft48 = MNG_FALSE;
  1364. #endif
  1365. /* the unknown chunk */
  1366. pData->iChunkname = MNG_UINT_HUH;
  1367. pData->iChunkseq = 0;
  1368. pData->pFirstchunk = MNG_NULL;
  1369. pData->pLastchunk = MNG_NULL;
  1370. /* nothing processed yet */
  1371. pData->bHasheader = MNG_FALSE;
  1372. pData->bHasMHDR = MNG_FALSE;
  1373. pData->bHasIHDR = MNG_FALSE;
  1374. pData->bHasBASI = MNG_FALSE;
  1375. pData->bHasDHDR = MNG_FALSE;
  1376. #ifdef MNG_INCLUDE_JNG
  1377. pData->bHasJHDR = MNG_FALSE;
  1378. pData->bHasJSEP = MNG_FALSE;
  1379. pData->bHasJDAA = MNG_FALSE;
  1380. pData->bHasJDAT = MNG_FALSE;
  1381. #endif
  1382. pData->bHasPLTE = MNG_FALSE;
  1383. pData->bHasTRNS = MNG_FALSE;
  1384. pData->bHasGAMA = MNG_FALSE;
  1385. pData->bHasCHRM = MNG_FALSE;
  1386. pData->bHasSRGB = MNG_FALSE;
  1387. pData->bHasICCP = MNG_FALSE;
  1388. pData->bHasBKGD = MNG_FALSE;
  1389. pData->bHasIDAT = MNG_FALSE;
  1390. pData->bHasSAVE = MNG_FALSE;
  1391. pData->bHasBACK = MNG_FALSE;
  1392. pData->bHasFRAM = MNG_FALSE;
  1393. pData->bHasTERM = MNG_FALSE;
  1394. pData->bHasLOOP = MNG_FALSE;
  1395. /* there's no global stuff yet either */
  1396. pData->bHasglobalPLTE = MNG_FALSE;
  1397. pData->bHasglobalTRNS = MNG_FALSE;
  1398. pData->bHasglobalGAMA = MNG_FALSE;
  1399. pData->bHasglobalCHRM = MNG_FALSE;
  1400. pData->bHasglobalSRGB = MNG_FALSE;
  1401. pData->bHasglobalICCP = MNG_FALSE;
  1402. pData->iDatawidth = 0; /* no IHDR/BASI/DHDR done yet */
  1403. pData->iDataheight = 0;
  1404. pData->iBitdepth = 0;
  1405. pData->iColortype = 0;
  1406. pData->iCompression = 0;
  1407. pData->iFilter = 0;
  1408. pData->iInterlace = 0;
  1409. #ifdef MNG_INCLUDE_JNG
  1410. pData->iJHDRcolortype = 0; /* no JHDR data */
  1411. pData->iJHDRimgbitdepth = 0;
  1412. pData->iJHDRimgcompression = 0;
  1413. pData->iJHDRimginterlace = 0;
  1414. pData->iJHDRalphabitdepth = 0;
  1415. pData->iJHDRalphacompression = 0;
  1416. pData->iJHDRalphafilter = 0;
  1417. pData->iJHDRalphainterlace = 0;
  1418. #endif
  1419. #endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */
  1420. #ifdef MNG_SUPPORT_READ /* no reading done */
  1421. pData->bReading = MNG_FALSE;
  1422. pData->bHavesig = MNG_FALSE;
  1423. pData->bEOF = MNG_FALSE;
  1424. pData->iReadbufsize = 0;
  1425. pData->pReadbuf = MNG_NULL;
  1426. pData->iLargebufsize = 0;
  1427. pData->pLargebuf = MNG_NULL;
  1428. pData->iSuspendtime = 0;
  1429. pData->bSuspended = MNG_FALSE;
  1430. pData->iSuspendpoint = 0;
  1431. pData->pSuspendbufnext = pData->pSuspendbuf;
  1432. pData->iSuspendbufleft = 0;
  1433. #endif /* MNG_SUPPORT_READ */
  1434. #ifdef MNG_SUPPORT_WRITE /* no creating/writing done */
  1435. pData->bCreating = MNG_FALSE;
  1436. pData->bWriting = MNG_FALSE;
  1437. pData->iFirstchunkadded = 0;
  1438. pData->iWritebufsize = 0;
  1439. pData->pWritebuf = MNG_NULL;
  1440. #endif /* MNG_SUPPORT_WRITE */
  1441. #ifdef MNG_SUPPORT_DISPLAY /* done nuttin' yet */
  1442. pData->bDisplaying = MNG_FALSE;
  1443. pData->iFrameseq = 0;
  1444. pData->iLayerseq = 0;
  1445. pData->iFrametime = 0;
  1446. pData->iTotallayers = 0;
  1447. pData->iTotalframes = 0;
  1448. pData->iTotalplaytime = 0;
  1449. pData->bSkipping = MNG_FALSE;
  1450. #ifdef MNG_SUPPORT_DYNAMICMNG
  1451. pData->bDynamic = MNG_FALSE;
  1452. pData->bRunningevent = MNG_FALSE;
  1453. pData->bStopafterseek = MNG_FALSE;
  1454. pData->iEventx = 0;
  1455. pData->iEventy = 0;
  1456. pData->pLastmousemove = MNG_NULL;
  1457. #endif
  1458. pData->iRequestframe = 0;
  1459. pData->iRequestlayer = 0;
  1460. pData->iRequesttime = 0;
  1461. pData->bSearching = MNG_FALSE;
  1462. pData->bRestorebkgd = MNG_FALSE;
  1463. pData->iRuntime = 0;
  1464. pData->iSynctime = 0;
  1465. pData->iStarttime = 0;
  1466. pData->iEndtime = 0;
  1467. pData->bRunning = MNG_FALSE;
  1468. pData->bTimerset = MNG_FALSE;
  1469. pData->iBreakpoint = 0;
  1470. pData->bSectionwait = MNG_FALSE;
  1471. pData->bFreezing = MNG_FALSE;
  1472. pData->bResetting = MNG_FALSE;
  1473. pData->bNeedrefresh = MNG_FALSE;
  1474. pData->bMisplacedTERM = MNG_FALSE;
  1475. pData->bOnlyfirstframe = MNG_FALSE;
  1476. pData->iFramesafterTERM = 0;
  1477. /* these don't exist yet */
  1478. pData->pCurrentobj = MNG_NULL;
  1479. pData->pCurraniobj = MNG_NULL;
  1480. pData->pTermaniobj = MNG_NULL;
  1481. pData->pLastclone = MNG_NULL;
  1482. pData->pStoreobj = MNG_NULL;
  1483. pData->pStorebuf = MNG_NULL;
  1484. pData->pRetrieveobj = MNG_NULL;
  1485. /* no saved data ! */
  1486. pData->pSavedata = MNG_NULL;
  1487. pData->iUpdateleft = 0; /* no region updated yet */
  1488. pData->iUpdateright = 0;
  1489. pData->iUpdatetop = 0;
  1490. pData->iUpdatebottom = 0;
  1491. pData->iPass = -1; /* interlacing stuff and temp buffers */
  1492. pData->iRow = 0;
  1493. pData->iRowinc = 1;
  1494. pData->iCol = 0;
  1495. pData->iColinc = 1;
  1496. pData->iRowsamples = 0;
  1497. pData->iSamplemul = 0;
  1498. pData->iSampleofs = 0;
  1499. pData->iSamplediv = 0;
  1500. pData->iRowsize = 0;
  1501. pData->iRowmax = 0;
  1502. pData->iFilterofs = 0;
  1503. pData->iPixelofs = 1;
  1504. pData->iLevel0 = 0;
  1505. pData->iLevel1 = 0;
  1506. pData->iLevel2 = 0;
  1507. pData->iLevel3 = 0;
  1508. pData->pWorkrow = MNG_NULL;
  1509. pData->pPrevrow = MNG_NULL;
  1510. pData->pRGBArow = MNG_NULL;
  1511. pData->bIsRGBA16 = MNG_TRUE;
  1512. pData->bIsOpaque = MNG_TRUE;
  1513. pData->iFilterbpp = 1;
  1514. pData->iSourcel = 0; /* always initialized just before */
  1515. pData->iSourcer = 0; /* compositing the next layer */
  1516. pData->iSourcet = 0;
  1517. pData->iSourceb = 0;
  1518. pData->iDestl = 0;
  1519. pData->iDestr = 0;
  1520. pData->iDestt = 0;
  1521. pData->iDestb = 0;
  1522. /* lists are empty */
  1523. pData->pFirstimgobj = MNG_NULL;
  1524. pData->pLastimgobj = MNG_NULL;
  1525. pData->pFirstaniobj = MNG_NULL;
  1526. pData->pLastaniobj = MNG_NULL;
  1527. #ifdef MNG_SUPPORT_DYNAMICMNG
  1528. pData->pFirstevent = MNG_NULL;
  1529. pData->pLastevent = MNG_NULL;
  1530. #endif
  1531. /* no processing callbacks */
  1532. pData->fDisplayrow = MNG_NULL;
  1533. pData->fRestbkgdrow = MNG_NULL;
  1534. pData->fCorrectrow = MNG_NULL;
  1535. pData->fRetrieverow = MNG_NULL;
  1536. pData->fStorerow = MNG_NULL;
  1537. pData->fProcessrow = MNG_NULL;
  1538. pData->fDifferrow = MNG_NULL;
  1539. pData->fScalerow = MNG_NULL;
  1540. pData->fDeltarow = MNG_NULL;
  1541. #ifndef MNG_SKIPCHUNK_PAST
  1542. pData->fFliprow = MNG_NULL;
  1543. pData->fTilerow = MNG_NULL;
  1544. #endif
  1545. pData->fInitrowproc = MNG_NULL;
  1546. pData->iPLTEcount = 0; /* no PLTE data */
  1547. #ifndef MNG_SKIPCHUNK_DEFI
  1548. pData->iDEFIobjectid = 0; /* no DEFI data */
  1549. pData->bDEFIhasdonotshow = MNG_FALSE;
  1550. pData->iDEFIdonotshow = 0;
  1551. pData->bDEFIhasconcrete = MNG_FALSE;
  1552. pData->iDEFIconcrete = 0;
  1553. pData->bDEFIhasloca = MNG_FALSE;
  1554. pData->iDEFIlocax = 0;
  1555. pData->iDEFIlocay = 0;
  1556. pData->bDEFIhasclip = MNG_FALSE;
  1557. pData->iDEFIclipl = 0;
  1558. pData->iDEFIclipr = 0;
  1559. pData->iDEFIclipt = 0;
  1560. pData->iDEFIclipb = 0;
  1561. #endif
  1562. #ifndef MNG_SKIPCHUNK_BACK
  1563. pData->iBACKred = 0; /* no BACK data */
  1564. pData->iBACKgreen = 0;
  1565. pData->iBACKblue = 0;
  1566. pData->iBACKmandatory = 0;
  1567. pData->iBACKimageid = 0;
  1568. pData->iBACKtile = 0;
  1569. #endif
  1570. #ifndef MNG_SKIPCHUNK_FRAM
  1571. pData->iFRAMmode = 1; /* default global FRAM variables */
  1572. pData->iFRAMdelay = 1;
  1573. pData->iFRAMtimeout = 0x7fffffffl;
  1574. pData->bFRAMclipping = MNG_FALSE;
  1575. pData->iFRAMclipl = 0;
  1576. pData->iFRAMclipr = 0;
  1577. pData->iFRAMclipt = 0;
  1578. pData->iFRAMclipb = 0;
  1579. pData->iFramemode = 1; /* again for the current frame */
  1580. pData->iFramedelay = 1;
  1581. pData->iFrametimeout = 0x7fffffffl;
  1582. pData->bFrameclipping = MNG_FALSE;
  1583. pData->iFrameclipl = 0;
  1584. pData->iFrameclipr = 0;
  1585. pData->iFrameclipt = 0;
  1586. pData->iFrameclipb = 0;
  1587. pData->iNextdelay = 1;
  1588. pData->bForcedelay = MNG_FALSE;
  1589. pData->iAccumdelay = 0;
  1590. #endif
  1591. #ifndef MNG_SKIPCHUNK_SHOW
  1592. pData->iSHOWmode = 0; /* no SHOW data */
  1593. pData->iSHOWfromid = 0;
  1594. pData->iSHOWtoid = 0;
  1595. pData->iSHOWnextid = 0;
  1596. pData->iSHOWskip = 0;
  1597. #endif
  1598. pData->iGlobalPLTEcount = 0; /* no global PLTE data */
  1599. pData->iGlobalTRNSrawlen = 0; /* no global tRNS data */
  1600. pData->iGlobalGamma = 0; /* no global gAMA data */
  1601. #ifndef MNG_SKIPCHUNK_cHRM
  1602. pData->iGlobalWhitepointx = 0; /* no global cHRM data */
  1603. pData->iGlobalWhitepointy = 0;
  1604. pData->iGlobalPrimaryredx = 0;
  1605. pData->iGlobalPrimaryredy = 0;
  1606. pData->iGlobalPrimarygreenx = 0;
  1607. pData->iGlobalPrimarygreeny = 0;
  1608. pData->iGlobalPrimarybluex = 0;
  1609. pData->iGlobalPrimarybluey = 0;
  1610. #endif
  1611. pData->iGlobalRendintent = 0; /* no global sRGB data */
  1612. #ifndef MNG_SKIPCHUNK_iCCP
  1613. pData->iGlobalProfilesize = 0; /* no global iCCP data */
  1614. pData->pGlobalProfile = MNG_NULL;
  1615. #endif
  1616. #ifndef MNG_SKIPCHUNK_bKGD
  1617. pData->iGlobalBKGDred = 0; /* no global bKGD data */
  1618. pData->iGlobalBKGDgreen = 0;
  1619. pData->iGlobalBKGDblue = 0;
  1620. #endif
  1621. /* no delta-image */
  1622. #ifndef MNG_NO_DELTA_PNG
  1623. pData->pDeltaImage = MNG_NULL;
  1624. pData->iDeltaImagetype = 0;
  1625. pData->iDeltatype = 0;
  1626. pData->iDeltaBlockwidth = 0;
  1627. pData->iDeltaBlockheight = 0;
  1628. pData->iDeltaBlockx = 0;
  1629. pData->iDeltaBlocky = 0;
  1630. pData->bDeltaimmediate = MNG_FALSE;
  1631. pData->fDeltagetrow = MNG_NULL;
  1632. pData->fDeltaaddrow = MNG_NULL;
  1633. pData->fDeltareplacerow = MNG_NULL;
  1634. pData->fDeltaputrow = MNG_NULL;
  1635. pData->fPromoterow = MNG_NULL;
  1636. pData->fPromBitdepth = MNG_NULL;
  1637. pData->pPromBuf = MNG_NULL;
  1638. pData->iPromColortype = 0;
  1639. pData->iPromBitdepth = 0;
  1640. pData->iPromFilltype = 0;
  1641. pData->iPromWidth = 0;
  1642. pData->pPromSrc = MNG_NULL;
  1643. pData->pPromDst = MNG_NULL;
  1644. #endif
  1645. #ifndef MNG_SKIPCHUNK_MAGN
  1646. pData->iMAGNfromid = 0;
  1647. pData->iMAGNtoid = 0;
  1648. #endif
  1649. #ifndef MNG_SKIPCHUNK_PAST
  1650. pData->iPastx = 0;
  1651. pData->iPasty = 0;
  1652. #endif
  1653. pData->pLastseek = MNG_NULL;
  1654. #endif
  1655. #ifdef MNG_INCLUDE_ZLIB
  1656. pData->bInflating = 0; /* no inflating or deflating */
  1657. pData->bDeflating = 0; /* going on at the moment */
  1658. #endif
  1659. #ifdef MNG_SUPPORT_DISPLAY /* reset object 0 */
  1660. mng_reset_objzero (pData);
  1661. #endif
  1662. #ifdef MNG_SUPPORT_TRACE
  1663. MNG_TRACE (((mng_datap)hHandle), MNG_FN_RESET, MNG_LC_END);
  1664. #endif
  1665. return MNG_NOERROR;
  1666. }
  1667. /* ************************************************************************** */
  1668. mng_retcode MNG_DECL mng_cleanup (mng_handle* hHandle)
  1669. {
  1670. mng_datap pData; /* local vars */
  1671. #ifndef MNG_INTERNAL_MEMMNGMT
  1672. mng_memfree fFree;
  1673. #endif
  1674. #ifdef MNG_SUPPORT_TRACE
  1675. MNG_TRACE (((mng_datap)*hHandle), MNG_FN_CLEANUP, MNG_LC_START);
  1676. #endif
  1677. MNG_VALIDHANDLE (*hHandle) /* check validity handle */
  1678. pData = ((mng_datap)(*hHandle)); /* and address main structure */
  1679. mng_reset (*hHandle); /* do an implicit reset to cleanup most stuff */
  1680. #ifdef MNG_SUPPORT_DISPLAY /* drop object 0 */
  1681. mng_free_imageobject (pData, (mng_imagep)pData->pObjzero);
  1682. #endif
  1683. #if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_FULL_CMS)
  1684. if (pData->hProf2) /* output profile defined ? */
  1685. mnglcms_freeprofile (pData->hProf2);
  1686. if (pData->hProf3) /* sRGB profile defined ? */
  1687. mnglcms_freeprofile (pData->hProf3);
  1688. #endif
  1689. #ifdef MNG_INCLUDE_ZLIB
  1690. mngzlib_cleanup (pData); /* cleanup zlib stuff */
  1691. #endif
  1692. #ifdef MNG_SUPPORT_TRACE
  1693. MNG_TRACE (((mng_datap)*hHandle), MNG_FN_CLEANUP, MNG_LC_CLEANUP)
  1694. #endif
  1695. pData->iMagic = 0; /* invalidate the actual memory */
  1696. #ifdef MNG_INTERNAL_MEMMNGMT
  1697. free ((void *)*hHandle); /* cleanup the data-structure */
  1698. #else
  1699. fFree = ((mng_datap)*hHandle)->fMemfree;
  1700. fFree ((mng_ptr)*hHandle, sizeof (mng_data));
  1701. #endif
  1702. *hHandle = 0; /* wipe pointer to inhibit future use */
  1703. return MNG_NOERROR; /* and we're done */
  1704. }
  1705. /* ************************************************************************** */
  1706. #ifdef MNG_SUPPORT_READ
  1707. mng_retcode MNG_DECL mng_read (mng_handle hHandle)
  1708. {
  1709. mng_datap pData; /* local vars */
  1710. mng_retcode iRetcode;
  1711. #ifdef MNG_SUPPORT_TRACE
  1712. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ, MNG_LC_START);
  1713. #endif
  1714. MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */
  1715. pData = ((mng_datap)hHandle); /* and make it addressable */
  1716. #ifndef MNG_INTERNAL_MEMMNGMT
  1717. MNG_VALIDCB (hHandle, fMemalloc)
  1718. MNG_VALIDCB (hHandle, fMemfree)
  1719. #endif
  1720. #ifndef MNG_NO_OPEN_CLOSE_STREAM
  1721. MNG_VALIDCB (hHandle, fOpenstream)
  1722. MNG_VALIDCB (hHandle, fClosestream)
  1723. #endif
  1724. MNG_VALIDCB (hHandle, fReaddata)
  1725. #ifdef MNG_SUPPORT_DISPLAY /* valid at this point ? */
  1726. if ((pData->bReading) || (pData->bDisplaying))
  1727. #else
  1728. if (pData->bReading)
  1729. #endif
  1730. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  1731. #ifdef MNG_SUPPORT_WRITE
  1732. if ((pData->bWriting) || (pData->bCreating))
  1733. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  1734. #endif
  1735. if (!pData->bCacheplayback) /* must store playback info to work!! */
  1736. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  1737. cleanup_errors (pData); /* cleanup previous errors */
  1738. pData->bReading = MNG_TRUE; /* read only! */
  1739. #ifndef MNG_NO_OPEN_CLOSE_STREAM
  1740. if (pData->fOpenstream && !pData->fOpenstream (hHandle))
  1741. /* open it and start reading */
  1742. iRetcode = MNG_APPIOERROR;
  1743. else
  1744. #endif
  1745. iRetcode = mng_read_graphic (pData);
  1746. if (pData->bEOF) /* already at EOF ? */
  1747. {
  1748. pData->bReading = MNG_FALSE; /* then we're no longer reading */
  1749. #ifdef MNG_SUPPORT_DISPLAY
  1750. mng_reset_rundata (pData); /* reset rundata */
  1751. #endif
  1752. }
  1753. if (iRetcode) /* on error bail out */
  1754. return iRetcode;
  1755. if (pData->bSuspended) /* read suspension ? */
  1756. {
  1757. iRetcode = MNG_NEEDMOREDATA;
  1758. pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData);
  1759. }
  1760. #ifdef MNG_SUPPORT_TRACE
  1761. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ, MNG_LC_END);
  1762. #endif
  1763. return iRetcode;
  1764. }
  1765. #endif /* MNG_SUPPORT_READ */
  1766. /* ************************************************************************** */
  1767. #ifdef MNG_SUPPORT_READ
  1768. mng_retcode MNG_DECL mng_read_pushdata (mng_handle hHandle,
  1769. mng_ptr pData,
  1770. mng_size_t iLength,
  1771. mng_bool bTakeownership)
  1772. {
  1773. mng_datap pMyData; /* local vars */
  1774. mng_pushdatap pPush;
  1775. mng_retcode iRetcode;
  1776. #ifdef MNG_SUPPORT_TRACE
  1777. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHDATA, MNG_LC_START);
  1778. #endif
  1779. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  1780. pMyData = ((mng_datap)hHandle); /* and make it addressable */
  1781. /* create a containing buffer */
  1782. iRetcode = make_pushbuffer (pMyData, pData, iLength, bTakeownership, &pPush);
  1783. if (iRetcode)
  1784. return iRetcode;
  1785. if (pMyData->pLastpushdata) /* and update the buffer chain */
  1786. pMyData->pLastpushdata->pNext = pPush;
  1787. else
  1788. pMyData->pFirstpushdata = pPush;
  1789. pMyData->pLastpushdata = pPush;
  1790. #ifdef MNG_SUPPORT_TRACE
  1791. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHDATA, MNG_LC_END);
  1792. #endif
  1793. return MNG_NOERROR;
  1794. }
  1795. #endif /* MNG_SUPPORT_READ */
  1796. /* ************************************************************************** */
  1797. #ifdef MNG_SUPPORT_READ
  1798. mng_retcode MNG_DECL mng_read_pushsig (mng_handle hHandle,
  1799. mng_imgtype eSigtype)
  1800. {
  1801. mng_datap pData; /* local vars */
  1802. #ifdef MNG_SUPPORT_TRACE
  1803. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHSIG, MNG_LC_START);
  1804. #endif
  1805. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  1806. pData = ((mng_datap)hHandle); /* and make it addressable */
  1807. if (pData->bHavesig) /* can we expect this call ? */
  1808. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  1809. pData->eSigtype = eSigtype;
  1810. pData->bHavesig = MNG_TRUE;
  1811. #ifdef MNG_SUPPORT_TRACE
  1812. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHSIG, MNG_LC_END);
  1813. #endif
  1814. return MNG_NOERROR;
  1815. }
  1816. #endif /* MNG_SUPPORT_READ */
  1817. /* ************************************************************************** */
  1818. #ifdef MNG_SUPPORT_READ
  1819. mng_retcode MNG_DECL mng_read_pushchunk (mng_handle hHandle,
  1820. mng_ptr pChunk,
  1821. mng_size_t iLength,
  1822. mng_bool bTakeownership)
  1823. {
  1824. mng_datap pMyData; /* local vars */
  1825. mng_pushdatap pPush;
  1826. mng_retcode iRetcode;
  1827. #ifdef MNG_SUPPORT_TRACE
  1828. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHCHUNK, MNG_LC_START);
  1829. #endif
  1830. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  1831. pMyData = ((mng_datap)hHandle); /* and make it addressable */
  1832. /* create a containing buffer */
  1833. iRetcode = make_pushbuffer (pMyData, pChunk, iLength, bTakeownership, &pPush);
  1834. if (iRetcode)
  1835. return iRetcode;
  1836. if (pMyData->pLastpushchunk) /* and update the buffer chain */
  1837. pMyData->pLastpushchunk->pNext = pPush;
  1838. else
  1839. pMyData->pFirstpushchunk = pPush;
  1840. pMyData->pLastpushchunk = pPush;
  1841. #ifdef MNG_SUPPORT_TRACE
  1842. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_PUSHCHUNK, MNG_LC_END);
  1843. #endif
  1844. return MNG_NOERROR;
  1845. }
  1846. #endif /* MNG_SUPPORT_READ */
  1847. /* ************************************************************************** */
  1848. #ifdef MNG_SUPPORT_READ
  1849. mng_retcode MNG_DECL mng_read_resume (mng_handle hHandle)
  1850. {
  1851. mng_datap pData; /* local vars */
  1852. mng_retcode iRetcode;
  1853. #ifdef MNG_SUPPORT_TRACE
  1854. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_RESUME, MNG_LC_START);
  1855. #endif
  1856. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  1857. pData = ((mng_datap)hHandle); /* and make it addressable */
  1858. /* can we expect this call ? */
  1859. if ((!pData->bReading) || (!pData->bSuspended))
  1860. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  1861. cleanup_errors (pData); /* cleanup previous errors */
  1862. pData->bSuspended = MNG_FALSE; /* reset the flag */
  1863. #ifdef MNG_SUPPORT_DISPLAY /* re-synchronize ? */
  1864. if ((pData->bDisplaying) && (pData->bRunning))
  1865. pData->iSynctime = pData->iSynctime - pData->iSuspendtime +
  1866. pData->fGettickcount (hHandle);
  1867. #endif
  1868. iRetcode = mng_read_graphic (pData); /* continue reading now */
  1869. if (pData->bEOF) /* at EOF ? */
  1870. {
  1871. pData->bReading = MNG_FALSE; /* then we're no longer reading */
  1872. #ifdef MNG_SUPPORT_DISPLAY
  1873. mng_reset_rundata (pData); /* reset rundata */
  1874. #endif
  1875. }
  1876. if (iRetcode) /* on error bail out */
  1877. return iRetcode;
  1878. if (pData->bSuspended) /* read suspension ? */
  1879. {
  1880. iRetcode = MNG_NEEDMOREDATA;
  1881. pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData);
  1882. }
  1883. #ifdef MNG_SUPPORT_TRACE
  1884. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READ_RESUME, MNG_LC_END);
  1885. #endif
  1886. return iRetcode;
  1887. }
  1888. #endif /* MNG_SUPPORT_READ */
  1889. /* ************************************************************************** */
  1890. #ifdef MNG_SUPPORT_WRITE
  1891. mng_retcode MNG_DECL mng_write (mng_handle hHandle)
  1892. {
  1893. mng_datap pData;
  1894. mng_retcode iRetcode;
  1895. #ifdef MNG_SUPPORT_TRACE
  1896. MNG_TRACE (((mng_datap)hHandle), MNG_FN_WRITE, MNG_LC_START);
  1897. #endif
  1898. MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */
  1899. pData = ((mng_datap)hHandle); /* and make it addressable */
  1900. #ifndef MNG_INTERNAL_MEMMNGMT
  1901. MNG_VALIDCB (hHandle, fMemalloc)
  1902. MNG_VALIDCB (hHandle, fMemfree)
  1903. #endif
  1904. #ifndef MNG_NO_OPEN_CLOSE_STREAM
  1905. MNG_VALIDCB (hHandle, fOpenstream)
  1906. MNG_VALIDCB (hHandle, fClosestream)
  1907. #endif
  1908. MNG_VALIDCB (hHandle, fWritedata)
  1909. #ifdef MNG_SUPPORT_READ
  1910. if (pData->bReading) /* valid at this point ? */
  1911. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  1912. #endif
  1913. cleanup_errors (pData); /* cleanup previous errors */
  1914. iRetcode = mng_write_graphic (pData);/* do the write */
  1915. if (iRetcode) /* on error bail out */
  1916. return iRetcode;
  1917. #ifdef MNG_SUPPORT_TRACE
  1918. MNG_TRACE (((mng_datap)hHandle), MNG_FN_WRITE, MNG_LC_END);
  1919. #endif
  1920. return MNG_NOERROR;
  1921. }
  1922. #endif /* MNG_SUPPORT_WRITE */
  1923. /* ************************************************************************** */
  1924. #ifdef MNG_SUPPORT_WRITE
  1925. mng_retcode MNG_DECL mng_create (mng_handle hHandle)
  1926. {
  1927. mng_datap pData;
  1928. mng_retcode iRetcode;
  1929. #ifdef MNG_SUPPORT_TRACE
  1930. MNG_TRACE (((mng_datap)hHandle), MNG_FN_CREATE, MNG_LC_START);
  1931. #endif
  1932. MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */
  1933. pData = ((mng_datap)hHandle); /* and make it addressable */
  1934. #ifndef MNG_INTERNAL_MEMMNGMT
  1935. MNG_VALIDCB (hHandle, fMemalloc)
  1936. MNG_VALIDCB (hHandle, fMemfree)
  1937. #endif
  1938. #ifdef MNG_SUPPORT_READ
  1939. if (pData->bReading) /* valid at this point ? */
  1940. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  1941. #endif
  1942. if ((pData->bWriting) || (pData->bCreating))
  1943. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  1944. cleanup_errors (pData); /* cleanup previous errors */
  1945. iRetcode = mng_reset (hHandle); /* clear any previous stuff */
  1946. if (iRetcode) /* on error bail out */
  1947. return iRetcode;
  1948. pData->bCreating = MNG_TRUE; /* indicate we're creating a new file */
  1949. #ifdef MNG_SUPPORT_TRACE
  1950. MNG_TRACE (((mng_datap)hHandle), MNG_FN_CREATE, MNG_LC_END);
  1951. #endif
  1952. return MNG_NOERROR;
  1953. }
  1954. #endif /* MNG_SUPPORT_WRITE */
  1955. /* ************************************************************************** */
  1956. #if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_READ)
  1957. mng_retcode MNG_DECL mng_readdisplay (mng_handle hHandle)
  1958. {
  1959. mng_datap pData; /* local vars */
  1960. mng_retcode iRetcode;
  1961. #ifdef MNG_SUPPORT_TRACE
  1962. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READDISPLAY, MNG_LC_START);
  1963. #endif
  1964. MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */
  1965. pData = ((mng_datap)hHandle); /* and make it addressable */
  1966. #ifndef MNG_INTERNAL_MEMMNGMT
  1967. MNG_VALIDCB (hHandle, fMemalloc)
  1968. MNG_VALIDCB (hHandle, fMemfree)
  1969. #endif
  1970. MNG_VALIDCB (hHandle, fReaddata)
  1971. MNG_VALIDCB (hHandle, fGetcanvasline)
  1972. MNG_VALIDCB (hHandle, fRefresh)
  1973. MNG_VALIDCB (hHandle, fGettickcount)
  1974. MNG_VALIDCB (hHandle, fSettimer)
  1975. /* valid at this point ? */
  1976. if ((pData->bReading) || (pData->bDisplaying))
  1977. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  1978. #ifdef MNG_SUPPORT_WRITE
  1979. if ((pData->bWriting) || (pData->bCreating))
  1980. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  1981. #endif
  1982. cleanup_errors (pData); /* cleanup previous errors */
  1983. pData->bReading = MNG_TRUE; /* read & display! */
  1984. pData->bDisplaying = MNG_TRUE;
  1985. pData->bRunning = MNG_TRUE;
  1986. pData->iFrameseq = 0;
  1987. pData->iLayerseq = 0;
  1988. pData->iFrametime = 0;
  1989. pData->iRequestframe = 0;
  1990. pData->iRequestlayer = 0;
  1991. pData->iRequesttime = 0;
  1992. pData->bSearching = MNG_FALSE;
  1993. pData->iRuntime = 0;
  1994. pData->iSynctime = pData->fGettickcount (hHandle);
  1995. pData->iSuspendtime = 0;
  1996. pData->iStarttime = pData->iSynctime;
  1997. pData->iEndtime = 0;
  1998. #ifndef MNG_NO_OPEN_CLOSE_STREAM
  1999. if (pData->fOpenstream && !pData->fOpenstream (hHandle))
  2000. /* open it and start reading */
  2001. iRetcode = MNG_APPIOERROR;
  2002. else
  2003. #endif
  2004. iRetcode = mng_read_graphic (pData);
  2005. if (pData->bEOF) /* already at EOF ? */
  2006. {
  2007. pData->bReading = MNG_FALSE; /* then we're no longer reading */
  2008. mng_drop_invalid_objects (pData); /* drop invalidly stored objects */
  2009. }
  2010. if (iRetcode) /* on error bail out */
  2011. return iRetcode;
  2012. if (pData->bSuspended) /* read suspension ? */
  2013. {
  2014. iRetcode = MNG_NEEDMOREDATA;
  2015. pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData);
  2016. }
  2017. else
  2018. if (pData->bTimerset) /* indicate timer break ? */
  2019. iRetcode = MNG_NEEDTIMERWAIT;
  2020. else
  2021. if (pData->bSectionwait) /* indicate section break ? */
  2022. iRetcode = MNG_NEEDSECTIONWAIT;
  2023. else
  2024. { /* no breaks = end of run */
  2025. pData->bRunning = MNG_FALSE;
  2026. if (pData->bFreezing) /* dynamic MNG reached SEEK ? */
  2027. pData->bFreezing = MNG_FALSE; /* reset it ! */
  2028. }
  2029. #ifdef MNG_SUPPORT_TRACE
  2030. MNG_TRACE (((mng_datap)hHandle), MNG_FN_READDISPLAY, MNG_LC_END);
  2031. #endif
  2032. return iRetcode;
  2033. }
  2034. #endif /* MNG_SUPPORT_DISPLAY && MNG_SUPPORT_READ */
  2035. /* ************************************************************************** */
  2036. #ifdef MNG_SUPPORT_DISPLAY
  2037. mng_retcode MNG_DECL mng_display (mng_handle hHandle)
  2038. {
  2039. mng_datap pData; /* local vars */
  2040. mng_retcode iRetcode;
  2041. #ifdef MNG_SUPPORT_TRACE
  2042. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY, MNG_LC_START);
  2043. #endif
  2044. MNG_VALIDHANDLE (hHandle) /* check validity handle and callbacks */
  2045. pData = ((mng_datap)hHandle); /* and make it addressable */
  2046. #ifndef MNG_INTERNAL_MEMMNGMT
  2047. MNG_VALIDCB (hHandle, fMemalloc)
  2048. MNG_VALIDCB (hHandle, fMemfree)
  2049. #endif
  2050. MNG_VALIDCB (hHandle, fGetcanvasline)
  2051. MNG_VALIDCB (hHandle, fRefresh)
  2052. MNG_VALIDCB (hHandle, fGettickcount)
  2053. MNG_VALIDCB (hHandle, fSettimer)
  2054. if (pData->bDisplaying) /* valid at this point ? */
  2055. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2056. #ifdef MNG_SUPPORT_READ
  2057. if (pData->bReading)
  2058. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2059. #endif
  2060. #ifdef MNG_SUPPORT_WRITE
  2061. if ((pData->bWriting) || (pData->bCreating))
  2062. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2063. #endif
  2064. cleanup_errors (pData); /* cleanup previous errors */
  2065. pData->bDisplaying = MNG_TRUE; /* display! */
  2066. pData->bRunning = MNG_TRUE;
  2067. pData->iFrameseq = 0;
  2068. pData->iLayerseq = 0;
  2069. pData->iFrametime = 0;
  2070. pData->iRequestframe = 0;
  2071. pData->iRequestlayer = 0;
  2072. pData->iRequesttime = 0;
  2073. pData->bSearching = MNG_FALSE;
  2074. pData->iRuntime = 0;
  2075. pData->iSynctime = pData->fGettickcount (hHandle);
  2076. #ifdef MNG_SUPPORT_READ
  2077. pData->iSuspendtime = 0;
  2078. #endif
  2079. pData->iStarttime = pData->iSynctime;
  2080. pData->iEndtime = 0;
  2081. pData->pCurraniobj = pData->pFirstaniobj;
  2082. /* go do it */
  2083. iRetcode = mng_process_display (pData);
  2084. if (iRetcode) /* on error bail out */
  2085. return iRetcode;
  2086. if (pData->bTimerset) /* indicate timer break ? */
  2087. iRetcode = MNG_NEEDTIMERWAIT;
  2088. else
  2089. { /* no breaks = end of run */
  2090. pData->bRunning = MNG_FALSE;
  2091. if (pData->bFreezing) /* dynamic MNG reached SEEK ? */
  2092. pData->bFreezing = MNG_FALSE; /* reset it ! */
  2093. }
  2094. #ifdef MNG_SUPPORT_TRACE
  2095. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY, MNG_LC_END);
  2096. #endif
  2097. return iRetcode;
  2098. }
  2099. #endif /* MNG_SUPPORT_DISPLAY */
  2100. /* ************************************************************************** */
  2101. #ifdef MNG_SUPPORT_DISPLAY
  2102. mng_retcode MNG_DECL mng_display_resume (mng_handle hHandle)
  2103. {
  2104. mng_datap pData; /* local vars */
  2105. mng_retcode iRetcode;
  2106. #ifdef MNG_SUPPORT_TRACE
  2107. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESUME, MNG_LC_START);
  2108. #endif
  2109. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  2110. pData = ((mng_datap)hHandle); /* and make it addressable */
  2111. if (!pData->bDisplaying) /* can we expect this call ? */
  2112. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2113. cleanup_errors (pData); /* cleanup previous errors */
  2114. /* was it running ? */
  2115. if ((pData->bRunning) || (pData->bReading))
  2116. { /* are we expecting this call ? */
  2117. if ((pData->bTimerset) || (pData->bSuspended) || (pData->bSectionwait))
  2118. {
  2119. pData->bTimerset = MNG_FALSE; /* reset the flags */
  2120. pData->bSectionwait = MNG_FALSE;
  2121. #ifdef MNG_SUPPORT_READ
  2122. if (pData->bReading) /* set during read&display ? */
  2123. {
  2124. if (pData->bSuspended) /* calculate proper synchronization */
  2125. pData->iSynctime = pData->iSynctime - pData->iSuspendtime +
  2126. pData->fGettickcount (hHandle);
  2127. else
  2128. pData->iSynctime = pData->fGettickcount (hHandle);
  2129. pData->bSuspended = MNG_FALSE; /* now reset this flag */
  2130. /* and continue reading */
  2131. iRetcode = mng_read_graphic (pData);
  2132. if (pData->bEOF) /* already at EOF ? */
  2133. {
  2134. pData->bReading = MNG_FALSE; /* then we're no longer reading */
  2135. /* drop invalidly stored objects */
  2136. mng_drop_invalid_objects (pData);
  2137. }
  2138. }
  2139. else
  2140. #endif /* MNG_SUPPORT_READ */
  2141. { /* synchronize timing */
  2142. pData->iSynctime = pData->fGettickcount (hHandle);
  2143. /* resume display processing */
  2144. iRetcode = mng_process_display (pData);
  2145. }
  2146. }
  2147. else
  2148. {
  2149. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2150. }
  2151. }
  2152. else
  2153. { /* synchronize timing */
  2154. pData->iSynctime = pData->fGettickcount (hHandle);
  2155. pData->bRunning = MNG_TRUE; /* it's restarted again ! */
  2156. /* resume display processing */
  2157. iRetcode = mng_process_display (pData);
  2158. }
  2159. if (iRetcode) /* on error bail out */
  2160. return iRetcode;
  2161. if (pData->bSuspended) /* read suspension ? */
  2162. {
  2163. iRetcode = MNG_NEEDMOREDATA;
  2164. pData->iSuspendtime = pData->fGettickcount ((mng_handle)pData);
  2165. }
  2166. else
  2167. if (pData->bTimerset) /* indicate timer break ? */
  2168. iRetcode = MNG_NEEDTIMERWAIT;
  2169. else
  2170. if (pData->bSectionwait) /* indicate section break ? */
  2171. iRetcode = MNG_NEEDSECTIONWAIT;
  2172. else
  2173. { /* no breaks = end of run */
  2174. pData->bRunning = MNG_FALSE;
  2175. if (pData->bFreezing) /* trying to freeze ? */
  2176. pData->bFreezing = MNG_FALSE; /* then we're there */
  2177. if (pData->bResetting) /* trying to reset as well ? */
  2178. { /* full stop!!! */
  2179. pData->bDisplaying = MNG_FALSE;
  2180. iRetcode = mng_reset_rundata (pData);
  2181. if (iRetcode) /* on error bail out */
  2182. return iRetcode;
  2183. }
  2184. }
  2185. #ifdef MNG_SUPPORT_TRACE
  2186. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESUME, MNG_LC_END);
  2187. #endif
  2188. return iRetcode;
  2189. }
  2190. #endif /* MNG_SUPPORT_DISPLAY */
  2191. /* ************************************************************************** */
  2192. #ifdef MNG_SUPPORT_DISPLAY
  2193. mng_retcode MNG_DECL mng_display_freeze (mng_handle hHandle)
  2194. {
  2195. mng_datap pData;
  2196. #ifdef MNG_SUPPORT_TRACE
  2197. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_FREEZE, MNG_LC_START);
  2198. #endif
  2199. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  2200. pData = ((mng_datap)hHandle); /* and make it addressable */
  2201. /* can we expect this call ? */
  2202. if ((!pData->bDisplaying) || (pData->bReading))
  2203. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2204. cleanup_errors (pData); /* cleanup previous errors */
  2205. if (pData->bRunning) /* is it running ? */
  2206. {
  2207. mng_retcode iRetcode;
  2208. pData->bFreezing = MNG_TRUE; /* indicate we need to freeze */
  2209. /* continue "normal" processing */
  2210. iRetcode = mng_display_resume (hHandle);
  2211. if (iRetcode) /* on error bail out */
  2212. return iRetcode;
  2213. }
  2214. #ifdef MNG_SUPPORT_TRACE
  2215. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_FREEZE, MNG_LC_END);
  2216. #endif
  2217. return MNG_NOERROR;
  2218. }
  2219. #endif /* MNG_SUPPORT_DISPLAY */
  2220. /* ************************************************************************** */
  2221. #ifdef MNG_SUPPORT_DISPLAY
  2222. mng_retcode MNG_DECL mng_display_reset (mng_handle hHandle)
  2223. {
  2224. mng_datap pData;
  2225. mng_retcode iRetcode;
  2226. #ifdef MNG_SUPPORT_TRACE
  2227. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESET, MNG_LC_START);
  2228. #endif
  2229. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  2230. pData = ((mng_datap)hHandle); /* and make it addressable */
  2231. /* can we expect this call ? */
  2232. if ((!pData->bDisplaying) || (pData->bReading))
  2233. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2234. if (!pData->bCacheplayback) /* must store playback info to work!! */
  2235. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2236. cleanup_errors (pData); /* cleanup previous errors */
  2237. if (pData->bRunning) /* is it running ? */
  2238. {
  2239. pData->bFreezing = MNG_TRUE; /* indicate we need to freeze */
  2240. pData->bResetting = MNG_TRUE; /* indicate we're about to reset too */
  2241. /* continue normal processing ? */
  2242. iRetcode = mng_display_resume (hHandle);
  2243. if (iRetcode) /* on error bail out */
  2244. return iRetcode;
  2245. }
  2246. else
  2247. { /* full stop!!! */
  2248. pData->bDisplaying = MNG_FALSE;
  2249. iRetcode = mng_reset_rundata (pData);
  2250. if (iRetcode) /* on error bail out */
  2251. return iRetcode;
  2252. }
  2253. #ifdef MNG_SUPPORT_TRACE
  2254. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_RESET, MNG_LC_END);
  2255. #endif
  2256. return MNG_NOERROR;
  2257. }
  2258. #endif /* MNG_SUPPORT_DISPLAY */
  2259. /* ************************************************************************** */
  2260. #ifdef MNG_SUPPORT_DISPLAY
  2261. #ifndef MNG_NO_DISPLAY_GO_SUPPORTED
  2262. mng_retcode MNG_DECL mng_display_goframe (mng_handle hHandle,
  2263. mng_uint32 iFramenr)
  2264. {
  2265. mng_datap pData;
  2266. mng_retcode iRetcode;
  2267. #ifdef MNG_SUPPORT_TRACE
  2268. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOFRAME, MNG_LC_START);
  2269. #endif
  2270. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  2271. pData = ((mng_datap)hHandle); /* and make it addressable */
  2272. if (pData->eImagetype != mng_it_mng) /* is it an animation ? */
  2273. MNG_ERROR (pData, MNG_NOTANANIMATION);
  2274. /* can we expect this call ? */
  2275. if ((!pData->bDisplaying) || (pData->bRunning))
  2276. MNG_ERROR ((mng_datap)hHandle, MNG_FUNCTIONINVALID);
  2277. if (!pData->bCacheplayback) /* must store playback info to work!! */
  2278. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2279. if (iFramenr > pData->iTotalframes) /* is the parameter within bounds ? */
  2280. MNG_ERROR (pData, MNG_FRAMENRTOOHIGH);
  2281. /* within MHDR bounds ? */
  2282. if ((pData->iFramecount) && (iFramenr > pData->iFramecount))
  2283. MNG_WARNING (pData, MNG_FRAMENRTOOHIGH);
  2284. cleanup_errors (pData); /* cleanup previous errors */
  2285. if (pData->iFrameseq > iFramenr) /* search from current or go back to start ? */
  2286. {
  2287. iRetcode = mng_reset_rundata (pData);
  2288. if (iRetcode) /* on error bail out */
  2289. return iRetcode;
  2290. }
  2291. if (iFramenr)
  2292. {
  2293. pData->iRequestframe = iFramenr; /* go find the requested frame then */
  2294. iRetcode = mng_process_display (pData);
  2295. if (iRetcode) /* on error bail out */
  2296. return iRetcode;
  2297. pData->bTimerset = MNG_FALSE; /* reset just to be safe */
  2298. }
  2299. #ifdef MNG_SUPPORT_TRACE
  2300. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOFRAME, MNG_LC_END);
  2301. #endif
  2302. return MNG_NOERROR;
  2303. }
  2304. #endif
  2305. #endif /* MNG_SUPPORT_DISPLAY */
  2306. /* ************************************************************************** */
  2307. #ifdef MNG_SUPPORT_DISPLAY
  2308. #ifndef MNG_NO_DISPLAY_GO_SUPPORTED
  2309. mng_retcode MNG_DECL mng_display_golayer (mng_handle hHandle,
  2310. mng_uint32 iLayernr)
  2311. {
  2312. mng_datap pData;
  2313. mng_retcode iRetcode;
  2314. #ifdef MNG_SUPPORT_TRACE
  2315. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOLAYER, MNG_LC_START);
  2316. #endif
  2317. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  2318. pData = ((mng_datap)hHandle); /* and make it addressable */
  2319. if (pData->eImagetype != mng_it_mng) /* is it an animation ? */
  2320. MNG_ERROR (pData, MNG_NOTANANIMATION);
  2321. /* can we expect this call ? */
  2322. if ((!pData->bDisplaying) || (pData->bRunning))
  2323. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2324. if (!pData->bCacheplayback) /* must store playback info to work!! */
  2325. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2326. if (iLayernr > pData->iTotallayers) /* is the parameter within bounds ? */
  2327. MNG_ERROR (pData, MNG_LAYERNRTOOHIGH);
  2328. /* within MHDR bounds ? */
  2329. if ((pData->iLayercount) && (iLayernr > pData->iLayercount))
  2330. MNG_WARNING (pData, MNG_LAYERNRTOOHIGH);
  2331. cleanup_errors (pData); /* cleanup previous errors */
  2332. if (pData->iLayerseq > iLayernr) /* search from current or go back to start ? */
  2333. {
  2334. iRetcode = mng_reset_rundata (pData);
  2335. if (iRetcode) /* on error bail out */
  2336. return iRetcode;
  2337. }
  2338. if (iLayernr)
  2339. {
  2340. pData->iRequestlayer = iLayernr; /* go find the requested layer then */
  2341. iRetcode = mng_process_display (pData);
  2342. if (iRetcode) /* on error bail out */
  2343. return iRetcode;
  2344. pData->bTimerset = MNG_FALSE; /* reset just to be safe */
  2345. }
  2346. #ifdef MNG_SUPPORT_TRACE
  2347. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOLAYER, MNG_LC_END);
  2348. #endif
  2349. return MNG_NOERROR;
  2350. }
  2351. #endif
  2352. #endif /* MNG_SUPPORT_DISPLAY */
  2353. /* ************************************************************************** */
  2354. #ifdef MNG_SUPPORT_DISPLAY
  2355. #ifndef MNG_NO_DISPLAY_GO_SUPPORTED
  2356. mng_retcode MNG_DECL mng_display_gotime (mng_handle hHandle,
  2357. mng_uint32 iPlaytime)
  2358. {
  2359. mng_datap pData;
  2360. mng_retcode iRetcode;
  2361. #ifdef MNG_SUPPORT_TRACE
  2362. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOTIME, MNG_LC_START);
  2363. #endif
  2364. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  2365. pData = ((mng_datap)hHandle); /* and make it addressable */
  2366. if (pData->eImagetype != mng_it_mng) /* is it an animation ? */
  2367. MNG_ERROR (pData, MNG_NOTANANIMATION);
  2368. /* can we expect this call ? */
  2369. if ((!pData->bDisplaying) || (pData->bRunning))
  2370. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2371. if (!pData->bCacheplayback) /* must store playback info to work!! */
  2372. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2373. /* is the parameter within bounds ? */
  2374. if (iPlaytime > pData->iTotalplaytime)
  2375. MNG_ERROR (pData, MNG_PLAYTIMETOOHIGH);
  2376. /* within MHDR bounds ? */
  2377. if ((pData->iPlaytime) && (iPlaytime > pData->iPlaytime))
  2378. MNG_WARNING (pData, MNG_PLAYTIMETOOHIGH);
  2379. cleanup_errors (pData); /* cleanup previous errors */
  2380. if (pData->iFrametime > iPlaytime) /* search from current or go back to start ? */
  2381. {
  2382. iRetcode = mng_reset_rundata (pData);
  2383. if (iRetcode) /* on error bail out */
  2384. return iRetcode;
  2385. }
  2386. if (iPlaytime)
  2387. {
  2388. pData->iRequesttime = iPlaytime; /* go find the requested playtime then */
  2389. iRetcode = mng_process_display (pData);
  2390. if (iRetcode) /* on error bail out */
  2391. return iRetcode;
  2392. pData->bTimerset = MNG_FALSE; /* reset just to be safe */
  2393. }
  2394. #ifdef MNG_SUPPORT_TRACE
  2395. MNG_TRACE (((mng_datap)hHandle), MNG_FN_DISPLAY_GOTIME, MNG_LC_END);
  2396. #endif
  2397. return MNG_NOERROR;
  2398. }
  2399. #endif
  2400. #endif /* MNG_SUPPORT_DISPLAY */
  2401. /* ************************************************************************** */
  2402. #if defined(MNG_SUPPORT_DISPLAY) && defined(MNG_SUPPORT_DYNAMICMNG)
  2403. mng_retcode MNG_DECL mng_trapevent (mng_handle hHandle,
  2404. mng_uint8 iEventtype,
  2405. mng_int32 iX,
  2406. mng_int32 iY)
  2407. {
  2408. mng_datap pData;
  2409. mng_eventp pEvent;
  2410. mng_bool bFound = MNG_FALSE;
  2411. mng_retcode iRetcode;
  2412. mng_imagep pImage;
  2413. mng_uint8p pPixel;
  2414. #ifdef MNG_SUPPORT_TRACE
  2415. MNG_TRACE (((mng_datap)hHandle), MNG_FN_TRAPEVENT, MNG_LC_START);
  2416. #endif
  2417. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  2418. pData = ((mng_datap)hHandle); /* and make it addressable */
  2419. if (pData->eImagetype != mng_it_mng) /* is it an animation ? */
  2420. MNG_ERROR (pData, MNG_NOTANANIMATION);
  2421. if (!pData->bDisplaying) /* can we expect this call ? */
  2422. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2423. if (!pData->bCacheplayback) /* must store playback info to work!! */
  2424. MNG_ERROR (pData, MNG_FUNCTIONINVALID);
  2425. /* let's find a matching event object */
  2426. pEvent = (mng_eventp)pData->pFirstevent;
  2427. while ((pEvent) && (!bFound))
  2428. { /* matching eventtype ? */
  2429. if (pEvent->iEventtype == iEventtype)
  2430. {
  2431. switch (pEvent->iMasktype) /* check X/Y on basis of masktype */
  2432. {
  2433. case MNG_MASK_NONE : /* no mask is easy */
  2434. {
  2435. bFound = MNG_TRUE;
  2436. break;
  2437. }
  2438. case MNG_MASK_BOX : /* inside the given box ? */
  2439. { /* right- and bottom-border don't count ! */
  2440. if ((iX >= pEvent->iLeft) && (iX < pEvent->iRight) &&
  2441. (iY >= pEvent->iTop) && (iY < pEvent->iBottom))
  2442. bFound = MNG_TRUE;
  2443. break;
  2444. }
  2445. case MNG_MASK_OBJECT : /* non-zero pixel in the image object ? */
  2446. {
  2447. pImage = mng_find_imageobject (pData, pEvent->iObjectid);
  2448. /* valid image ? */
  2449. if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) &&
  2450. ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) &&
  2451. ((mng_int32)pImage->pImgbuf->iWidth > iX) &&
  2452. ((mng_int32)pImage->pImgbuf->iHeight > iY))
  2453. {
  2454. pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iY) + iX);
  2455. if (*pPixel) /* non-zero ? */
  2456. bFound = MNG_TRUE;
  2457. }
  2458. break;
  2459. }
  2460. case MNG_MASK_OBJECTIX : /* pixel in the image object matches index ? */
  2461. {
  2462. pImage = mng_find_imageobject (pData, pEvent->iObjectid);
  2463. /* valid image ? */
  2464. if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) &&
  2465. ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) &&
  2466. ((mng_int32)pImage->pImgbuf->iWidth > iX) && (iX >= 0) &&
  2467. ((mng_int32)pImage->pImgbuf->iHeight > iY) && (iY >= 0))
  2468. {
  2469. pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iY) + iX);
  2470. /* matching index ? */
  2471. if (*pPixel == pEvent->iIndex)
  2472. bFound = MNG_TRUE;
  2473. }
  2474. break;
  2475. }
  2476. case MNG_MASK_BOXOBJECT : /* non-zero pixel in the image object ? */
  2477. {
  2478. mng_int32 iTempx = iX - pEvent->iLeft;
  2479. mng_int32 iTempy = iY - pEvent->iTop;
  2480. pImage = mng_find_imageobject (pData, pEvent->iObjectid);
  2481. /* valid image ? */
  2482. if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) &&
  2483. ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) &&
  2484. (iTempx < (mng_int32)pImage->pImgbuf->iWidth) &&
  2485. (iTempx >= 0) && (iX < pEvent->iRight) &&
  2486. (iTempy < (mng_int32)pImage->pImgbuf->iHeight) &&
  2487. (iTempy >= 0) && (iY < pEvent->iBottom))
  2488. {
  2489. pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iTempy) + iTempx);
  2490. if (*pPixel) /* non-zero ? */
  2491. bFound = MNG_TRUE;
  2492. }
  2493. break;
  2494. }
  2495. case MNG_MASK_BOXOBJECTIX : /* pixel in the image object matches index ? */
  2496. {
  2497. mng_int32 iTempx = iX - pEvent->iLeft;
  2498. mng_int32 iTempy = iY - pEvent->iTop;
  2499. pImage = mng_find_imageobject (pData, pEvent->iObjectid);
  2500. /* valid image ? */
  2501. if ((pImage) && (pImage->pImgbuf->iBitdepth <= 8) &&
  2502. ((pImage->pImgbuf->iColortype == 0) || (pImage->pImgbuf->iColortype == 3)) &&
  2503. (iTempx < (mng_int32)pImage->pImgbuf->iWidth) &&
  2504. (iTempx >= 0) && (iX < pEvent->iRight) &&
  2505. (iTempy < (mng_int32)pImage->pImgbuf->iHeight) &&
  2506. (iTempy >= 0) && (iY < pEvent->iBottom))
  2507. {
  2508. pPixel = pImage->pImgbuf->pImgdata + ((pImage->pImgbuf->iWidth * iTempy) + iTempx);
  2509. /* matching index ? */
  2510. if (*pPixel == pEvent->iIndex)
  2511. bFound = MNG_TRUE;
  2512. }
  2513. break;
  2514. }
  2515. }
  2516. }
  2517. if (!bFound) /* try the next one */
  2518. pEvent = (mng_eventp)pEvent->sHeader.pNext;
  2519. }
  2520. /* found one that's not the last mousemove ? */
  2521. if ((pEvent) && ((mng_objectp)pEvent != pData->pLastmousemove))
  2522. { /* can we start an event process now ? */
  2523. if ((!pData->bReading) && (!pData->bRunning))
  2524. {
  2525. pData->iEventx = iX; /* save coordinates */
  2526. pData->iEventy = iY;
  2527. /* do it then ! */
  2528. iRetcode = pEvent->sHeader.fProcess (pData, pEvent);
  2529. if (iRetcode) /* on error bail out */
  2530. return iRetcode;
  2531. /* remember last mousemove event */
  2532. if (pEvent->iEventtype == MNG_EVENT_MOUSEMOVE)
  2533. pData->pLastmousemove = (mng_objectp)pEvent;
  2534. else
  2535. pData->pLastmousemove = MNG_NULL;
  2536. }
  2537. else
  2538. {
  2539. /* TODO: store unprocessed events or not ??? */
  2540. }
  2541. }
  2542. #ifdef MNG_SUPPORT_TRACE
  2543. MNG_TRACE (((mng_datap)hHandle), MNG_FN_TRAPEVENT, MNG_LC_END);
  2544. #endif
  2545. return MNG_NOERROR;
  2546. }
  2547. #endif
  2548. /* ************************************************************************** */
  2549. mng_retcode MNG_DECL mng_getlasterror (mng_handle hHandle,
  2550. mng_int8* iSeverity,
  2551. mng_chunkid* iChunkname,
  2552. mng_uint32* iChunkseq,
  2553. mng_int32* iExtra1,
  2554. mng_int32* iExtra2,
  2555. mng_pchar* zErrortext)
  2556. {
  2557. mng_datap pData; /* local vars */
  2558. #ifdef MNG_SUPPORT_TRACE
  2559. MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETLASTERROR, MNG_LC_START);
  2560. #endif
  2561. MNG_VALIDHANDLE (hHandle) /* check validity handle */
  2562. pData = ((mng_datap)hHandle); /* and make it addressable */
  2563. *iSeverity = pData->iSeverity; /* return the appropriate fields */
  2564. #if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE)
  2565. *iChunkname = pData->iChunkname;
  2566. *iChunkseq = pData->iChunkseq;
  2567. #else
  2568. *iChunkname = MNG_UINT_HUH;
  2569. *iChunkseq = 0;
  2570. #endif
  2571. *iExtra1 = pData->iErrorx1;
  2572. *iExtra2 = pData->iErrorx2;
  2573. *zErrortext = pData->zErrortext;
  2574. #ifdef MNG_SUPPORT_TRACE
  2575. MNG_TRACE (((mng_datap)hHandle), MNG_FN_GETLASTERROR, MNG_LC_END);
  2576. #endif
  2577. return pData->iErrorcode; /* and the errorcode */
  2578. }
  2579. /* ************************************************************************** */
  2580. /* * end of file * */
  2581. /* ************************************************************************** */