2
0

libmng_hlapi.c 108 KB

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