libmng_display.c 269 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135
  1. /* ************************************************************************** */
  2. /* * For conditions of distribution and use, * */
  3. /* * see copyright notice in libmng.h * */
  4. /* ************************************************************************** */
  5. /* * * */
  6. /* * project : libmng * */
  7. /* * file : libmng_display.c copyright (c) 2000-2007 G.Juyn * */
  8. /* * version : 1.0.10 * */
  9. /* * * */
  10. /* * purpose : Display management (implementation) * */
  11. /* * * */
  12. /* * author : G.Juyn * */
  13. /* * * */
  14. /* * comment : implementation of the display management routines * */
  15. /* * * */
  16. /* * changes : 0.5.1 - 05/08/2000 - G.Juyn * */
  17. /* * - changed strict-ANSI stuff * */
  18. /* * 0.5.1 - 05/11/2000 - G.Juyn * */
  19. /* * - added callback error-reporting support * */
  20. /* * - fixed frame_delay misalignment * */
  21. /* * 0.5.1 - 05/12/2000 - G.Juyn * */
  22. /* * - added sanity check for frozen status * */
  23. /* * - changed trace to macro for callback error-reporting * */
  24. /* * 0.5.1 - 05/13/2000 - G.Juyn * */
  25. /* * - changed display_mend to reset state to initial or SAVE * */
  26. /* * - added eMNGma hack (will be removed in 1.0.0 !!!) * */
  27. /* * - added TERM animation object pointer (easier reference) * */
  28. /* * - added process_save & process_seek routines * */
  29. /* * 0.5.1 - 05/14/2000 - G.Juyn * */
  30. /* * - added save_state and restore_state for SAVE/SEEK/TERM * */
  31. /* * processing * */
  32. /* * * */
  33. /* * 0.5.2 - 05/20/2000 - G.Juyn * */
  34. /* * - added JNG support (JHDR/JDAT) * */
  35. /* * 0.5.2 - 05/23/2000 - G.Juyn * */
  36. /* * - fixed problem with DEFI clipping * */
  37. /* * 0.5.2 - 05/30/2000 - G.Juyn * */
  38. /* * - added delta-image support (DHDR,PROM,IPNG,IJNG) * */
  39. /* * 0.5.2 - 05/31/2000 - G.Juyn * */
  40. /* * - fixed pointer confusion (contributed by Tim Rowley) * */
  41. /* * 0.5.2 - 06/03/2000 - G.Juyn * */
  42. /* * - fixed makeup for Linux gcc compile * */
  43. /* * 0.5.2 - 06/05/2000 - G.Juyn * */
  44. /* * - added support for RGB8_A8 canvasstyle * */
  45. /* * 0.5.2 - 06/09/2000 - G.Juyn * */
  46. /* * - fixed timer-handling to run with Mozilla (Tim Rowley) * */
  47. /* * 0.5.2 - 06/10/2000 - G.Juyn * */
  48. /* * - fixed some compilation-warnings (contrib Jason Morris) * */
  49. /* * * */
  50. /* * 0.5.3 - 06/12/2000 - G.Juyn * */
  51. /* * - fixed display of stored JNG images * */
  52. /* * 0.5.3 - 06/13/2000 - G.Juyn * */
  53. /* * - fixed problem with BASI-IEND as object 0 * */
  54. /* * 0.5.3 - 06/16/2000 - G.Juyn * */
  55. /* * - changed progressive-display processing * */
  56. /* * 0.5.3 - 06/17/2000 - G.Juyn * */
  57. /* * - changed delta-image processing * */
  58. /* * 0.5.3 - 06/20/2000 - G.Juyn * */
  59. /* * - fixed some minor stuff * */
  60. /* * 0.5.3 - 06/21/2000 - G.Juyn * */
  61. /* * - added speed-modifier to timing routine * */
  62. /* * 0.5.3 - 06/22/2000 - G.Juyn * */
  63. /* * - added support for PPLT chunk processing * */
  64. /* * 0.5.3 - 06/29/2000 - G.Juyn * */
  65. /* * - swapped refresh parameters * */
  66. /* * * */
  67. /* * 0.9.0 - 06/30/2000 - G.Juyn * */
  68. /* * - changed refresh parameters to 'x,y,width,height' * */
  69. /* * * */
  70. /* * 0.9.1 - 07/07/2000 - G.Juyn * */
  71. /* * - implemented support for freeze/reset/resume & go_xxxx * */
  72. /* * 0.9.1 - 07/08/2000 - G.Juyn * */
  73. /* * - added support for improved timing * */
  74. /* * 0.9.1 - 07/14/2000 - G.Juyn * */
  75. /* * - changed EOF processing behavior * */
  76. /* * - fixed TERM delay processing * */
  77. /* * 0.9.1 - 07/15/2000 - G.Juyn * */
  78. /* * - fixed freeze & reset processing * */
  79. /* * 0.9.1 - 07/16/2000 - G.Juyn * */
  80. /* * - fixed storage of images during mng_read() * */
  81. /* * - fixed support for mng_display() after mng_read() * */
  82. /* * 0.9.1 - 07/24/2000 - G.Juyn * */
  83. /* * - fixed reading of still-images * */
  84. /* * * */
  85. /* * 0.9.2 - 08/05/2000 - G.Juyn * */
  86. /* * - changed file-prefixes * */
  87. /* * * */
  88. /* * 0.9.3 - 08/07/2000 - G.Juyn * */
  89. /* * - B111300 - fixup for improved portability * */
  90. /* * 0.9.3 - 08/21/2000 - G.Juyn * */
  91. /* * - fixed TERM processing delay of 0 msecs * */
  92. /* * 0.9.3 - 08/26/2000 - G.Juyn * */
  93. /* * - added MAGN chunk * */
  94. /* * 0.9.3 - 09/10/2000 - G.Juyn * */
  95. /* * - fixed problem with no refresh after TERM * */
  96. /* * - fixed DEFI behavior * */
  97. /* * 0.9.3 - 09/16/2000 - G.Juyn * */
  98. /* * - fixed timing & refresh behavior for single PNG/JNG * */
  99. /* * 0.9.3 - 09/19/2000 - G.Juyn * */
  100. /* * - refixed timing & refresh behavior for single PNG/JNG * */
  101. /* * 0.9.3 - 10/02/2000 - G.Juyn * */
  102. /* * - fixed timing again (this is getting boring...) * */
  103. /* * - refixed problem with no refresh after TERM * */
  104. /* * 0.9.3 - 10/16/2000 - G.Juyn * */
  105. /* * - added JDAA chunk * */
  106. /* * 0.9.3 - 10/17/2000 - G.Juyn * */
  107. /* * - fixed support for bKGD * */
  108. /* * 0.9.3 - 10/18/2000 - G.Juyn * */
  109. /* * - fixed delta-processing behavior * */
  110. /* * 0.9.3 - 10/19/2000 - G.Juyn * */
  111. /* * - added storage for pixel-/alpha-sampledepth for delta's * */
  112. /* * 0.9.3 - 10/27/2000 - G.Juyn * */
  113. /* * - fixed separate read() & display() processing * */
  114. /* * * */
  115. /* * 0.9.4 - 10/31/2000 - G.Juyn * */
  116. /* * - fixed possible loop in display_resume() (Thanks Vova!) * */
  117. /* * 0.9.4 - 11/20/2000 - G.Juyn * */
  118. /* * - fixed unwanted repetition in mng_readdisplay() * */
  119. /* * 0.9.4 - 11/24/2000 - G.Juyn * */
  120. /* * - moved restore of object 0 to libmng_display * */
  121. /* * - added restore of object 0 to TERM processing !!! * */
  122. /* * - fixed TERM delay processing * */
  123. /* * - fixed TERM end processing (count = 0) * */
  124. /* * 0.9.4 - 12/16/2000 - G.Juyn * */
  125. /* * - fixed mixup of data- & function-pointers (thanks Dimitri)* */
  126. /* * 0.9.4 - 1/18/2001 - G.Juyn * */
  127. /* * - removed test filter-methods 1 & 65 * */
  128. /* * - set default level-set for filtertype=64 to all zeroes * */
  129. /* * * */
  130. /* * 0.9.5 - 1/20/2001 - G.Juyn * */
  131. /* * - fixed compiler-warnings Mozilla (thanks Tim) * */
  132. /* * 0.9.5 - 1/23/2001 - G.Juyn * */
  133. /* * - fixed timing-problem with switching framing_modes * */
  134. /* * * */
  135. /* * 1.0.1 - 02/08/2001 - G.Juyn * */
  136. /* * - added MEND processing callback * */
  137. /* * 1.0.1 - 02/13/2001 - G.Juyn * */
  138. /* * - fixed first FRAM_MODE=4 timing problem * */
  139. /* * 1.0.1 - 04/21/2001 - G.Juyn * */
  140. /* * - fixed memory-leak for JNGs with alpha (Thanks Gregg!) * */
  141. /* * - added BGRA8 canvas with premultiplied alpha * */
  142. /* * * */
  143. /* * 1.0.2 - 06/25/2001 - G.Juyn * */
  144. /* * - fixed memory-leak with delta-images (Thanks Michael!) * */
  145. /* * * */
  146. /* * 1.0.5 - 08/15/2002 - G.Juyn * */
  147. /* * - completed PROM support * */
  148. /* * - completed delta-image support * */
  149. /* * 1.0.5 - 08/19/2002 - G.Juyn * */
  150. /* * - B597134 - libmng pollutes the linker namespace * */
  151. /* * 1.0.5 - 09/13/2002 - G.Juyn * */
  152. /* * - fixed read/write of MAGN chunk * */
  153. /* * 1.0.5 - 09/15/2002 - G.Juyn * */
  154. /* * - fixed LOOP iteration=0 special case * */
  155. /* * 1.0.5 - 09/19/2002 - G.Juyn * */
  156. /* * - fixed color-correction for restore-background handling * */
  157. /* * - optimized restore-background for bKGD cases * */
  158. /* * - cleaned up some old stuff * */
  159. /* * 1.0.5 - 09/20/2002 - G.Juyn * */
  160. /* * - finished support for BACK image & tiling * */
  161. /* * - added support for PAST * */
  162. /* * 1.0.5 - 09/22/2002 - G.Juyn * */
  163. /* * - added bgrx8 canvas (filler byte) * */
  164. /* * 1.0.5 - 10/05/2002 - G.Juyn * */
  165. /* * - fixed dropping mix of frozen/unfrozen objects * */
  166. /* * 1.0.5 - 10/07/2002 - G.Juyn * */
  167. /* * - added proposed change in handling of TERM- & if-delay * */
  168. /* * - added another fix for misplaced TERM chunk * */
  169. /* * - completed support for condition=2 in TERM chunk * */
  170. /* * 1.0.5 - 10/18/2002 - G.Juyn * */
  171. /* * - fixed clipping-problem with BACK tiling (Thanks Sakura!) * */
  172. /* * 1.0.5 - 10/20/2002 - G.Juyn * */
  173. /* * - fixed processing for multiple objects in MAGN * */
  174. /* * - fixed display of visible target of PAST operation * */
  175. /* * 1.0.5 - 10/30/2002 - G.Juyn * */
  176. /* * - modified TERM/MEND processing for max(1, TERM_delay, * */
  177. /* * interframe_delay) * */
  178. /* * 1.0.5 - 11/04/2002 - G.Juyn * */
  179. /* * - fixed layer- & frame-counting during read() * */
  180. /* * - fixed goframe/golayer/gotime processing * */
  181. /* * 1.0.5 - 01/19/2003 - G.Juyn * */
  182. /* * - B654627 - fixed SEGV when no gettickcount callback * */
  183. /* * - B664383 - fixed typo * */
  184. /* * - finalized changes in TERM/final_delay to elected proposal* */
  185. /* * * */
  186. /* * 1.0.6 - 05/11/2003 - G. Juyn * */
  187. /* * - added conditionals around canvas update routines * */
  188. /* * 1.0.6 - 05/25/2003 - G.R-P * */
  189. /* * - added MNG_SKIPCHUNK_cHNK footprint optimizations * */
  190. /* * 1.0.6 - 07/07/2003 - G.R-P * */
  191. /* * - added conditionals around some JNG-supporting code * */
  192. /* * - added conditionals around 16-bit supporting code * */
  193. /* * - reversed some loops to use decrementing counter * */
  194. /* * - combined init functions into one function * */
  195. /* * 1.0.6 - 07/10/2003 - G.R-P * */
  196. /* * - replaced nested switches with simple init setup function * */
  197. /* * 1.0.6 - 07/29/2003 - G.R-P * */
  198. /* * - added conditionals around PAST chunk support * */
  199. /* * 1.0.6 - 08/17/2003 - G.R-P * */
  200. /* * - added conditionals around non-VLC chunk support * */
  201. /* * * */
  202. /* * 1.0.7 - 11/27/2003 - R.A * */
  203. /* * - added CANVAS_RGB565 and CANVAS_BGR565 * */
  204. /* * 1.0.7 - 12/06/2003 - R.A * */
  205. /* * - added CANVAS_RGBA565 and CANVAS_BGRA565 * */
  206. /* * 1.0.7 - 01/25/2004 - J.S * */
  207. /* * - added premultiplied alpha canvas' for RGBA, ARGB, ABGR * */
  208. /* * * */
  209. /* * 1.0.8 - 03/31/2004 - G.Juyn * */
  210. /* * - fixed problem with PAST usage where source > dest * */
  211. /* * 1.0.8 - 05/04/2004 - G.R-P. * */
  212. /* * - fixed misplaced 16-bit conditionals * */
  213. /* * * */
  214. /* * 1.0.9 - 09/18/2004 - G.R-P. * */
  215. /* * - revised some SKIPCHUNK conditionals * */
  216. /* * 1.0.9 - 10/10/2004 - G.R-P. * */
  217. /* * - added MNG_NO_1_2_4BIT_SUPPORT * */
  218. /* * 1.0.9 - 10/14/2004 - G.Juyn * */
  219. /* * - added bgr565_a8 canvas-style (thanks to J. Elvander) * */
  220. /* * 1.0.9 - 12/11/2004 - G.Juyn * */
  221. /* * - added conditional MNG_OPTIMIZE_DISPLAYCALLS * */
  222. /* * 1.0.9 - 12/20/2004 - G.Juyn * */
  223. /* * - cleaned up macro-invocations (thanks to D. Airlie) * */
  224. /* * * */
  225. /* * 1.0.10 - 07/06/2005 - G.R-P. * */
  226. /* * - added more SKIPCHUNK conditionals * */
  227. /* * 1.0.10 - 12/28/2005 - G.R-P. * */
  228. /* * - added missing SKIPCHUNK_MAGN conditional * */
  229. /* * 1.0.10 - 03/07/2006 - (thanks to W. Manthey) * */
  230. /* * - added CANVAS_RGB555 and CANVAS_BGR555 * */
  231. /* * 1.0.10 - 04/08/2007 - G.Juyn * */
  232. /* * - fixed several compiler warnings * */
  233. /* * 1.0.10 - 04/08/2007 - G.Juyn * */
  234. /* * - added support for mPNG proposal * */
  235. /* * 1.0.10 - 04/12/2007 - G.Juyn * */
  236. /* * - added support for ANG proposal * */
  237. /* * * */
  238. /* ************************************************************************** */
  239. #include "libmng.h"
  240. #include "libmng_data.h"
  241. #include "libmng_error.h"
  242. #include "libmng_trace.h"
  243. #ifdef __BORLANDC__
  244. #pragma hdrstop
  245. #endif
  246. #include "libmng_chunks.h"
  247. #include "libmng_objects.h"
  248. #include "libmng_object_prc.h"
  249. #include "libmng_memory.h"
  250. #include "libmng_zlib.h"
  251. #include "libmng_jpeg.h"
  252. #include "libmng_cms.h"
  253. #include "libmng_pixels.h"
  254. #include "libmng_display.h"
  255. #if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)
  256. #pragma option -A /* force ANSI-C */
  257. #endif
  258. /* ************************************************************************** */
  259. #ifdef MNG_INCLUDE_DISPLAY_PROCS
  260. /* ************************************************************************** */
  261. MNG_LOCAL mng_retcode set_delay (mng_datap pData,
  262. mng_uint32 iInterval)
  263. {
  264. if (!iInterval) /* at least 1 msec please! */
  265. iInterval = 1;
  266. if (pData->bRunning) /* only when really displaying */
  267. if (!pData->fSettimer ((mng_handle)pData, iInterval))
  268. MNG_ERROR (pData, MNG_APPTIMERERROR);
  269. #ifdef MNG_SUPPORT_DYNAMICMNG
  270. if ((!pData->bDynamic) || (pData->bRunning))
  271. #else
  272. if (pData->bRunning)
  273. #endif
  274. pData->bTimerset = MNG_TRUE; /* and indicate so */
  275. return MNG_NOERROR;
  276. }
  277. /* ************************************************************************** */
  278. MNG_LOCAL mng_uint32 calculate_delay (mng_datap pData,
  279. mng_uint32 iDelay)
  280. {
  281. mng_uint32 iTicks = pData->iTicks;
  282. mng_uint32 iWaitfor = 1; /* default non-MNG delay */
  283. if (!iTicks) /* tick_count not specified ? */
  284. if (pData->eImagetype == mng_it_mng)
  285. iTicks = 1000;
  286. if (iTicks)
  287. {
  288. switch (pData->iSpeed) /* honor speed modifier */
  289. {
  290. case mng_st_fast :
  291. {
  292. iWaitfor = (mng_uint32)(( 500 * iDelay) / iTicks);
  293. break;
  294. }
  295. case mng_st_slow :
  296. {
  297. iWaitfor = (mng_uint32)((3000 * iDelay) / iTicks);
  298. break;
  299. }
  300. case mng_st_slowest :
  301. {
  302. iWaitfor = (mng_uint32)((8000 * iDelay) / iTicks);
  303. break;
  304. }
  305. default :
  306. {
  307. iWaitfor = (mng_uint32)((1000 * iDelay) / iTicks);
  308. }
  309. }
  310. }
  311. return iWaitfor;
  312. }
  313. /* ************************************************************************** */
  314. /* * * */
  315. /* * Progressive display refresh - does the call to the refresh callback * */
  316. /* * and sets the timer to allow the app to perform the actual refresh to * */
  317. /* * the screen (eg. process its main message-loop) * */
  318. /* * * */
  319. /* ************************************************************************** */
  320. mng_retcode mng_display_progressive_refresh (mng_datap pData,
  321. mng_uint32 iInterval)
  322. {
  323. { /* let the app refresh first ? */
  324. if ((pData->bRunning) && (!pData->bSkipping) &&
  325. (pData->iUpdatetop < pData->iUpdatebottom) && (pData->iUpdateleft < pData->iUpdateright))
  326. {
  327. if (!pData->fRefresh (((mng_handle)pData),
  328. pData->iUpdateleft, pData->iUpdatetop,
  329. pData->iUpdateright - pData->iUpdateleft,
  330. pData->iUpdatebottom - pData->iUpdatetop))
  331. MNG_ERROR (pData, MNG_APPMISCERROR);
  332. pData->iUpdateleft = 0; /* reset update-region */
  333. pData->iUpdateright = 0;
  334. pData->iUpdatetop = 0;
  335. pData->iUpdatebottom = 0; /* reset refreshneeded indicator */
  336. pData->bNeedrefresh = MNG_FALSE;
  337. /* interval requested ? */
  338. if ((!pData->bFreezing) && (iInterval))
  339. { /* setup the timer */
  340. mng_retcode iRetcode = set_delay (pData, iInterval);
  341. if (iRetcode) /* on error bail out */
  342. return iRetcode;
  343. }
  344. }
  345. }
  346. return MNG_NOERROR;
  347. }
  348. /* ************************************************************************** */
  349. /* * * */
  350. /* * Generic display routines * */
  351. /* * * */
  352. /* ************************************************************************** */
  353. MNG_LOCAL mng_retcode interframe_delay (mng_datap pData)
  354. {
  355. mng_uint32 iWaitfor = 0;
  356. mng_uint32 iInterval;
  357. mng_uint32 iRuninterval;
  358. mng_retcode iRetcode;
  359. #ifdef MNG_SUPPORT_TRACE
  360. MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_START);
  361. #endif
  362. {
  363. #ifndef MNG_SKIPCHUNK_FRAM
  364. if (pData->iFramedelay > 0) /* real delay ? */
  365. { /* let the app refresh first ? */
  366. if ((pData->bRunning) && (!pData->bSkipping) &&
  367. (pData->iUpdatetop < pData->iUpdatebottom) && (pData->iUpdateleft < pData->iUpdateright))
  368. if (!pData->fRefresh (((mng_handle)pData),
  369. pData->iUpdateleft, pData->iUpdatetop,
  370. pData->iUpdateright - pData->iUpdateleft,
  371. pData->iUpdatebottom - pData->iUpdatetop))
  372. MNG_ERROR (pData, MNG_APPMISCERROR);
  373. pData->iUpdateleft = 0; /* reset update-region */
  374. pData->iUpdateright = 0;
  375. pData->iUpdatetop = 0;
  376. pData->iUpdatebottom = 0; /* reset refreshneeded indicator */
  377. pData->bNeedrefresh = MNG_FALSE;
  378. #ifndef MNG_SKIPCHUNK_TERM
  379. if (pData->bOnlyfirstframe) /* only processing first frame after TERM ? */
  380. {
  381. pData->iFramesafterTERM++;
  382. /* did we do a frame yet ? */
  383. if (pData->iFramesafterTERM > 1)
  384. { /* then that's it; just stop right here ! */
  385. pData->pCurraniobj = MNG_NULL;
  386. pData->bRunning = MNG_FALSE;
  387. return MNG_NOERROR;
  388. }
  389. }
  390. #endif
  391. if (pData->fGettickcount)
  392. { /* get current tickcount */
  393. pData->iRuntime = pData->fGettickcount ((mng_handle)pData);
  394. /* calculate interval since last sync-point */
  395. if (pData->iRuntime < pData->iSynctime)
  396. iRuninterval = pData->iRuntime + ~pData->iSynctime + 1;
  397. else
  398. iRuninterval = pData->iRuntime - pData->iSynctime;
  399. /* calculate actual run-time */
  400. if (pData->iRuntime < pData->iStarttime)
  401. pData->iRuntime = pData->iRuntime + ~pData->iStarttime + 1;
  402. else
  403. pData->iRuntime = pData->iRuntime - pData->iStarttime;
  404. }
  405. else
  406. {
  407. iRuninterval = 0;
  408. }
  409. iWaitfor = calculate_delay (pData, pData->iFramedelay);
  410. if (iWaitfor > iRuninterval) /* delay necessary ? */
  411. iInterval = iWaitfor - iRuninterval;
  412. else
  413. iInterval = 1; /* force app to process messageloop */
  414. /* set the timer ? */
  415. if (((pData->bRunning) || (pData->bSearching) || (pData->bReading)) &&
  416. (!pData->bSkipping))
  417. {
  418. iRetcode = set_delay (pData, iInterval);
  419. if (iRetcode) /* on error bail out */
  420. return iRetcode;
  421. }
  422. }
  423. if (!pData->bSkipping) /* increase frametime in advance */
  424. pData->iFrametime = pData->iFrametime + iWaitfor;
  425. /* setup for next delay */
  426. pData->iFramedelay = pData->iNextdelay;
  427. #endif
  428. }
  429. #ifdef MNG_SUPPORT_TRACE
  430. MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_END);
  431. #endif
  432. return MNG_NOERROR;
  433. }
  434. /* ************************************************************************** */
  435. MNG_LOCAL void set_display_routine (mng_datap pData)
  436. { /* actively running ? */
  437. if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
  438. {
  439. switch (pData->iCanvasstyle) /* determine display routine */
  440. {
  441. #ifndef MNG_SKIPCANVAS_RGB8
  442. case MNG_CANVAS_RGB8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8; break; }
  443. #endif
  444. #ifndef MNG_SKIPCANVAS_RGBA8
  445. case MNG_CANVAS_RGBA8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba8; break; }
  446. #endif
  447. #ifndef MNG_SKIPCANVAS_RGBA8_PM
  448. case MNG_CANVAS_RGBA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_rgba8_pm; break; }
  449. #endif
  450. #ifndef MNG_SKIPCANVAS_ARGB8
  451. case MNG_CANVAS_ARGB8 : { pData->fDisplayrow = (mng_fptr)mng_display_argb8; break; }
  452. #endif
  453. #ifndef MNG_SKIPCANVAS_ARGB8_PM
  454. case MNG_CANVAS_ARGB8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_argb8_pm; break; }
  455. #endif
  456. #ifndef MNG_SKIPCANVAS_RGB8_A8
  457. case MNG_CANVAS_RGB8_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8_a8; break; }
  458. #endif
  459. #ifndef MNG_SKIPCANVAS_BGR8
  460. case MNG_CANVAS_BGR8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr8; break; }
  461. #endif
  462. #ifndef MNG_SKIPCANVAS_BGRX8
  463. case MNG_CANVAS_BGRX8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgrx8; break; }
  464. #endif
  465. #ifndef MNG_SKIPCANVAS_BGRA8
  466. case MNG_CANVAS_BGRA8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra8; break; }
  467. #endif
  468. #ifndef MNG_SKIPCANVAS_BGRA8_PM
  469. case MNG_CANVAS_BGRA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_bgra8_pm; break; }
  470. #endif
  471. #ifndef MNG_SKIPCANVAS_ABGR8
  472. case MNG_CANVAS_ABGR8 : { pData->fDisplayrow = (mng_fptr)mng_display_abgr8; break; }
  473. #endif
  474. #ifndef MNG_SKIPCANVAS_ABGR8_PM
  475. case MNG_CANVAS_ABGR8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_abgr8_pm; break; }
  476. #endif
  477. #ifndef MNG_SKIPCANVAS_RGB565
  478. case MNG_CANVAS_RGB565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb565; break; }
  479. #endif
  480. #ifndef MNG_SKIPCANVAS_RGBA565
  481. case MNG_CANVAS_RGBA565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba565; break; }
  482. #endif
  483. #ifndef MNG_SKIPCANVAS_BGR565
  484. case MNG_CANVAS_BGR565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565; break; }
  485. #endif
  486. #ifndef MNG_SKIPCANVAS_BGRA565
  487. case MNG_CANVAS_BGRA565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra565; break; }
  488. #endif
  489. #ifndef MNG_SKIPCANVAS_BGR565_A8
  490. case MNG_CANVAS_BGR565_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565_a8; break; }
  491. #endif
  492. #ifndef MNG_SKIPCANVAS_RGB555
  493. case MNG_CANVAS_RGB555 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb555; break; }
  494. #endif
  495. #ifndef MNG_SKIPCANVAS_BGR555
  496. case MNG_CANVAS_BGR555 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr555; break; }
  497. #endif
  498. #ifndef MNG_NO_16BIT_SUPPORT
  499. /* case MNG_CANVAS_RGB16 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb16; break; } */
  500. /* case MNG_CANVAS_RGBA16 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba16; break; } */
  501. /* case MNG_CANVAS_ARGB16 : { pData->fDisplayrow = (mng_fptr)mng_display_argb16; break; } */
  502. /* case MNG_CANVAS_BGR16 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr16; break; } */
  503. /* case MNG_CANVAS_BGRA16 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra16; break; } */
  504. /* case MNG_CANVAS_ABGR16 : { pData->fDisplayrow = (mng_fptr)mng_display_abgr16; break; } */
  505. #endif
  506. /* case MNG_CANVAS_INDEX8 : { pData->fDisplayrow = (mng_fptr)mng_display_index8; break; } */
  507. /* case MNG_CANVAS_INDEXA8 : { pData->fDisplayrow = (mng_fptr)mng_display_indexa8; break; } */
  508. /* case MNG_CANVAS_AINDEX8 : { pData->fDisplayrow = (mng_fptr)mng_display_aindex8; break; } */
  509. /* case MNG_CANVAS_GRAY8 : { pData->fDisplayrow = (mng_fptr)mng_display_gray8; break; } */
  510. /* case MNG_CANVAS_AGRAY8 : { pData->fDisplayrow = (mng_fptr)mng_display_agray8; break; } */
  511. /* case MNG_CANVAS_GRAYA8 : { pData->fDisplayrow = (mng_fptr)mng_display_graya8; break; } */
  512. #ifndef MNG_NO_16BIT_SUPPORT
  513. /* case MNG_CANVAS_GRAY16 : { pData->fDisplayrow = (mng_fptr)mng_display_gray16; break; } */
  514. /* case MNG_CANVAS_GRAYA16 : { pData->fDisplayrow = (mng_fptr)mng_display_graya16; break; } */
  515. /* case MNG_CANVAS_AGRAY16 : { pData->fDisplayrow = (mng_fptr)mng_display_agray16; break; } */
  516. #endif
  517. /* case MNG_CANVAS_DX15 : { pData->fDisplayrow = (mng_fptr)mng_display_dx15; break; } */
  518. /* case MNG_CANVAS_DX16 : { pData->fDisplayrow = (mng_fptr)mng_display_dx16; break; } */
  519. }
  520. }
  521. return;
  522. }
  523. /* ************************************************************************** */
  524. MNG_LOCAL mng_retcode load_bkgdlayer (mng_datap pData)
  525. {
  526. #ifdef MNG_SUPPORT_TRACE
  527. MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_START);
  528. #endif
  529. /* actively running ? */
  530. if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
  531. {
  532. mng_int32 iY;
  533. mng_retcode iRetcode;
  534. mng_bool bColorcorr = MNG_FALSE;
  535. /* save values */
  536. mng_int32 iDestl = pData->iDestl;
  537. mng_int32 iDestr = pData->iDestr;
  538. mng_int32 iDestt = pData->iDestt;
  539. mng_int32 iDestb = pData->iDestb;
  540. mng_int32 iSourcel = pData->iSourcel;
  541. mng_int32 iSourcer = pData->iSourcer;
  542. mng_int32 iSourcet = pData->iSourcet;
  543. mng_int32 iSourceb = pData->iSourceb;
  544. mng_int8 iPass = pData->iPass;
  545. mng_int32 iRow = pData->iRow;
  546. mng_int32 iRowinc = pData->iRowinc;
  547. mng_int32 iCol = pData->iCol;
  548. mng_int32 iColinc = pData->iColinc;
  549. mng_int32 iRowsamples = pData->iRowsamples;
  550. mng_int32 iRowsize = pData->iRowsize;
  551. mng_uint8p pPrevrow = pData->pPrevrow;
  552. mng_uint8p pRGBArow = pData->pRGBArow;
  553. mng_bool bIsRGBA16 = pData->bIsRGBA16;
  554. mng_bool bIsOpaque = pData->bIsOpaque;
  555. mng_fptr fCorrectrow = pData->fCorrectrow;
  556. mng_fptr fDisplayrow = pData->fDisplayrow;
  557. mng_fptr fRetrieverow = pData->fRetrieverow;
  558. mng_objectp pCurrentobj = pData->pCurrentobj;
  559. mng_objectp pRetrieveobj = pData->pRetrieveobj;
  560. pData->iDestl = 0; /* determine clipping region */
  561. pData->iDestt = 0;
  562. pData->iDestr = pData->iWidth;
  563. pData->iDestb = pData->iHeight;
  564. #ifndef MNG_SKIPCHUNK_FRAM
  565. if (pData->bFrameclipping) /* frame clipping specified ? */
  566. {
  567. pData->iDestl = MAX_COORD (pData->iDestl, pData->iFrameclipl);
  568. pData->iDestt = MAX_COORD (pData->iDestt, pData->iFrameclipt);
  569. pData->iDestr = MIN_COORD (pData->iDestr, pData->iFrameclipr);
  570. pData->iDestb = MIN_COORD (pData->iDestb, pData->iFrameclipb);
  571. }
  572. #endif
  573. /* anything to clear ? */
  574. if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt))
  575. {
  576. pData->iPass = -1; /* these are the object's dimensions now */
  577. pData->iRow = 0;
  578. pData->iRowinc = 1;
  579. pData->iCol = 0;
  580. pData->iColinc = 1;
  581. pData->iRowsamples = pData->iWidth;
  582. pData->iRowsize = pData->iRowsamples << 2;
  583. pData->bIsRGBA16 = MNG_FALSE; /* let's keep it simple ! */
  584. pData->bIsOpaque = MNG_TRUE;
  585. pData->iSourcel = 0; /* source relative to destination */
  586. pData->iSourcer = pData->iDestr - pData->iDestl;
  587. pData->iSourcet = 0;
  588. pData->iSourceb = pData->iDestb - pData->iDestt;
  589. set_display_routine (pData); /* determine display routine */
  590. /* default restore using preset BG color */
  591. pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgcolor;
  592. #ifndef MNG_SKIPCHUNK_bKGD
  593. if (((pData->eImagetype == mng_it_png) || (pData->eImagetype == mng_it_jng)) &&
  594. (pData->bUseBKGD))
  595. { /* prefer bKGD in PNG/JNG */
  596. if (!pData->pCurrentobj)
  597. pData->pCurrentobj = pData->pObjzero;
  598. if (((mng_imagep)pData->pCurrentobj)->pImgbuf->bHasBKGD)
  599. {
  600. pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bkgd;
  601. bColorcorr = MNG_TRUE;
  602. }
  603. }
  604. #endif
  605. if (pData->fGetbkgdline) /* background-canvas-access callback set ? */
  606. {
  607. switch (pData->iBkgdstyle)
  608. {
  609. #ifndef MNG_SKIPCANVAS_RGB8
  610. case MNG_CANVAS_RGB8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb8; break; }
  611. #endif
  612. #ifndef MNG_SKIPCANVAS_BGR8
  613. case MNG_CANVAS_BGR8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr8; break; }
  614. #endif
  615. #ifndef MNG_SKIPCANVAS_BGRX8
  616. case MNG_CANVAS_BGRX8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgrx8; break; }
  617. #endif
  618. #ifndef MNG_SKIPCANVAS_BGR565
  619. case MNG_CANVAS_BGR565 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr565; break; }
  620. #endif
  621. #ifndef MNG_SKIPCANVAS_RGB565
  622. case MNG_CANVAS_RGB565 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb565; break; }
  623. #endif
  624. #ifndef MNG_NO_16BIT_SUPPORT
  625. /* case MNG_CANVAS_RGB16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb16; break; } */
  626. /* case MNG_CANVAS_BGR16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr16; break; } */
  627. #endif
  628. /* case MNG_CANVAS_INDEX8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_index8; break; } */
  629. /* case MNG_CANVAS_GRAY8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_gray8; break; } */
  630. #ifndef MNG_NO_16BIT_SUPPORT
  631. /* case MNG_CANVAS_GRAY16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_gray16; break; } */
  632. #endif
  633. /* case MNG_CANVAS_DX15 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_dx15; break; } */
  634. /* case MNG_CANVAS_DX16 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_dx16; break; } */
  635. }
  636. }
  637. #ifndef MNG_SKIPCHUNK_BACK
  638. if (pData->bHasBACK)
  639. { /* background image ? */
  640. if ((pData->iBACKmandatory & 0x02) && (pData->iBACKimageid))
  641. {
  642. pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor;
  643. bColorcorr = MNG_TRUE;
  644. }
  645. else /* background color ? */
  646. if (pData->iBACKmandatory & 0x01)
  647. {
  648. pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor;
  649. bColorcorr = MNG_TRUE;
  650. }
  651. }
  652. #endif
  653. pData->fCorrectrow = MNG_NULL; /* default no color-correction */
  654. if (bColorcorr) /* do we have to do color-correction ? */
  655. {
  656. #ifdef MNG_NO_CMS
  657. iRetcode = MNG_NOERROR;
  658. #else
  659. #if defined(MNG_FULL_CMS) /* determine color-management routine */
  660. iRetcode = mng_init_full_cms (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE);
  661. #elif defined(MNG_GAMMA_ONLY)
  662. iRetcode = mng_init_gamma_only (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE);
  663. #elif defined(MNG_APP_CMS)
  664. iRetcode = mng_init_app_cms (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE);
  665. #endif
  666. if (iRetcode) /* on error bail out */
  667. return iRetcode;
  668. #endif /* MNG_NO_CMS */
  669. }
  670. /* get a temporary row-buffer */
  671. MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize);
  672. iY = pData->iDestt; /* this is where we start */
  673. iRetcode = MNG_NOERROR; /* so far, so good */
  674. while ((!iRetcode) && (iY < pData->iDestb))
  675. { /* restore a background row */
  676. iRetcode = ((mng_restbkgdrow)pData->fRestbkgdrow) (pData);
  677. /* color correction ? */
  678. if ((!iRetcode) && (pData->fCorrectrow))
  679. iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData);
  680. if (!iRetcode) /* so... display it */
  681. iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
  682. if (!iRetcode)
  683. iRetcode = mng_next_row (pData);
  684. iY++; /* and next line */
  685. }
  686. /* drop the temporary row-buffer */
  687. MNG_FREE (pData, pData->pRGBArow, pData->iRowsize);
  688. if (iRetcode) /* on error bail out */
  689. return iRetcode;
  690. #if defined(MNG_FULL_CMS) /* cleanup cms stuff */
  691. if (bColorcorr) /* did we do color-correction ? */
  692. {
  693. iRetcode = mng_clear_cms (pData);
  694. if (iRetcode) /* on error bail out */
  695. return iRetcode;
  696. }
  697. #endif
  698. #ifndef MNG_SKIPCHUNK_BACK
  699. /* background image ? */
  700. if ((pData->bHasBACK) && (pData->iBACKmandatory & 0x02) && (pData->iBACKimageid))
  701. {
  702. mng_imagep pImage;
  703. /* let's find that object then */
  704. pData->pRetrieveobj = mng_find_imageobject (pData, pData->iBACKimageid);
  705. pImage = (mng_imagep)pData->pRetrieveobj;
  706. /* exists, viewable and visible ? */
  707. if ((pImage) && (pImage->bViewable) && (pImage->bVisible))
  708. { /* will it fall within the target region ? */
  709. if ((pImage->iPosx < pData->iDestr) && (pImage->iPosy < pData->iDestb) &&
  710. ((pData->iBACKtile) ||
  711. ((pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth >= pData->iDestl) &&
  712. (pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight >= pData->iDestt) )) &&
  713. ((!pImage->bClipped) ||
  714. ((pImage->iClipl <= pImage->iClipr) && (pImage->iClipt <= pImage->iClipb) &&
  715. (pImage->iClipl < pData->iDestr) && (pImage->iClipr >= pData->iDestl) &&
  716. (pImage->iClipt < pData->iDestb) && (pImage->iClipb >= pData->iDestt) )))
  717. { /* right; we've got ourselves something to do */
  718. if (pImage->bClipped) /* clip output region with image's clipping region ? */
  719. {
  720. if (pImage->iClipl > pData->iDestl)
  721. pData->iDestl = pImage->iClipl;
  722. if (pImage->iClipr < pData->iDestr)
  723. pData->iDestr = pImage->iClipr;
  724. if (pImage->iClipt > pData->iDestt)
  725. pData->iDestt = pImage->iClipt;
  726. if (pImage->iClipb < pData->iDestb)
  727. pData->iDestb = pImage->iClipb;
  728. }
  729. /* image offset does some extra clipping too ! */
  730. if (pImage->iPosx > pData->iDestl)
  731. pData->iDestl = pImage->iPosx;
  732. if (pImage->iPosy > pData->iDestt)
  733. pData->iDestt = pImage->iPosy;
  734. if (!pData->iBACKtile) /* without tiling further clipping is needed */
  735. {
  736. if (pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth < pData->iDestr)
  737. pData->iDestr = pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth;
  738. if (pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight < pData->iDestb)
  739. pData->iDestb = pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight;
  740. }
  741. pData->iSourcel = 0; /* source relative to destination */
  742. pData->iSourcer = pData->iDestr - pData->iDestl;
  743. pData->iSourcet = 0;
  744. pData->iSourceb = pData->iDestb - pData->iDestt;
  745. /* 16-bit background ? */
  746. #ifdef MNG_NO_16BIT_SUPPORT
  747. pData->bIsRGBA16 = MNG_FALSE;
  748. #else
  749. pData->bIsRGBA16 = (mng_bool)(pImage->pImgbuf->iBitdepth > 8);
  750. #endif
  751. /* let restore routine know the offsets !!! */
  752. pData->iBackimgoffsx = pImage->iPosx;
  753. pData->iBackimgoffsy = pImage->iPosy;
  754. pData->iBackimgwidth = pImage->pImgbuf->iWidth;
  755. pData->iBackimgheight = pImage->pImgbuf->iHeight;
  756. pData->iRow = 0; /* start at the top again !! */
  757. /* determine background object retrieval routine */
  758. switch (pImage->pImgbuf->iColortype)
  759. {
  760. case 0 : {
  761. #ifndef MNG_NO_16BIT_SUPPORT
  762. if (pImage->pImgbuf->iBitdepth > 8)
  763. pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
  764. else
  765. #endif
  766. pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
  767. pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
  768. break;
  769. }
  770. case 2 : {
  771. #ifndef MNG_NO_16BIT_SUPPORT
  772. if (pImage->pImgbuf->iBitdepth > 8)
  773. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
  774. else
  775. #endif
  776. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
  777. pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
  778. break;
  779. }
  780. case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8;
  781. pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
  782. break;
  783. }
  784. case 4 : {
  785. #ifndef MNG_NO_16BIT_SUPPORT
  786. if (pImage->pImgbuf->iBitdepth > 8)
  787. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
  788. else
  789. #endif
  790. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
  791. pData->bIsOpaque = MNG_FALSE;
  792. break;
  793. }
  794. case 6 : {
  795. #ifndef MNG_NO_16BIT_SUPPORT
  796. if (pImage->pImgbuf->iBitdepth > 8)
  797. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
  798. else
  799. #endif
  800. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
  801. pData->bIsOpaque = MNG_FALSE;
  802. break;
  803. }
  804. case 8 : {
  805. #ifndef MNG_NO_16BIT_SUPPORT
  806. if (pImage->pImgbuf->iBitdepth > 8)
  807. pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
  808. else
  809. #endif
  810. pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
  811. pData->bIsOpaque = MNG_TRUE;
  812. break;
  813. }
  814. case 10 : {
  815. #ifndef MNG_NO_16BIT_SUPPORT
  816. if (pImage->pImgbuf->iBitdepth > 8)
  817. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
  818. else
  819. #endif
  820. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
  821. pData->bIsOpaque = MNG_TRUE;
  822. break;
  823. }
  824. case 12 : {
  825. #ifndef MNG_NO_16BIT_SUPPORT
  826. if (pImage->pImgbuf->iBitdepth > 8)
  827. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
  828. else
  829. #endif
  830. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
  831. pData->bIsOpaque = MNG_FALSE;
  832. break;
  833. }
  834. case 14 : {
  835. #ifndef MNG_NO_16BIT_SUPPORT
  836. if (pImage->pImgbuf->iBitdepth > 8)
  837. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
  838. else
  839. #endif
  840. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
  841. pData->bIsOpaque = MNG_FALSE;
  842. break;
  843. }
  844. }
  845. #ifdef MNG_NO_CMS
  846. iRetcode = MNG_NOERROR;
  847. #else
  848. #if defined(MNG_FULL_CMS) /* determine color-management routine */
  849. iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
  850. #elif defined(MNG_GAMMA_ONLY)
  851. iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
  852. #elif defined(MNG_APP_CMS)
  853. iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
  854. #endif
  855. if (iRetcode) /* on error bail out */
  856. return iRetcode;
  857. #endif /* MNG_NO_CMS */
  858. /* get temporary row-buffers */
  859. MNG_ALLOC (pData, pData->pPrevrow, pData->iRowsize);
  860. MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize);
  861. iY = pData->iDestt; /* this is where we start */
  862. iRetcode = MNG_NOERROR; /* so far, so good */
  863. while ((!iRetcode) && (iY < pData->iDestb))
  864. { /* restore a background row */
  865. iRetcode = mng_restore_bkgd_backimage (pData);
  866. /* color correction ? */
  867. if ((!iRetcode) && (pData->fCorrectrow))
  868. iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData);
  869. if (!iRetcode) /* so... display it */
  870. iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
  871. if (!iRetcode)
  872. iRetcode = mng_next_row (pData);
  873. iY++; /* and next line */
  874. }
  875. /* drop temporary row-buffers */
  876. MNG_FREE (pData, pData->pRGBArow, pData->iRowsize);
  877. MNG_FREE (pData, pData->pPrevrow, pData->iRowsize);
  878. if (iRetcode) /* on error bail out */
  879. return iRetcode;
  880. #if defined(MNG_FULL_CMS) /* cleanup cms stuff */
  881. iRetcode = mng_clear_cms (pData);
  882. if (iRetcode) /* on error bail out */
  883. return iRetcode;
  884. #endif
  885. }
  886. }
  887. }
  888. #endif
  889. }
  890. pData->iDestl = iDestl; /* restore values */
  891. pData->iDestr = iDestr;
  892. pData->iDestt = iDestt;
  893. pData->iDestb = iDestb;
  894. pData->iSourcel = iSourcel;
  895. pData->iSourcer = iSourcer;
  896. pData->iSourcet = iSourcet;
  897. pData->iSourceb = iSourceb;
  898. pData->iPass = iPass;
  899. pData->iRow = iRow;
  900. pData->iRowinc = iRowinc;
  901. pData->iCol = iCol;
  902. pData->iColinc = iColinc;
  903. pData->iRowsamples = iRowsamples;
  904. pData->iRowsize = iRowsize;
  905. pData->pPrevrow = pPrevrow;
  906. pData->pRGBArow = pRGBArow;
  907. pData->bIsRGBA16 = bIsRGBA16;
  908. pData->bIsOpaque = bIsOpaque;
  909. pData->fCorrectrow = fCorrectrow;
  910. pData->fDisplayrow = fDisplayrow;
  911. pData->fRetrieverow = fRetrieverow;
  912. pData->pCurrentobj = pCurrentobj;
  913. pData->pRetrieveobj = pRetrieveobj;
  914. }
  915. #ifdef MNG_SUPPORT_TRACE
  916. MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_END);
  917. #endif
  918. return MNG_NOERROR;
  919. }
  920. /* ************************************************************************** */
  921. MNG_LOCAL mng_retcode clear_canvas (mng_datap pData)
  922. {
  923. mng_int32 iY;
  924. mng_retcode iRetcode;
  925. #ifdef MNG_SUPPORT_TRACE
  926. MNG_TRACE (pData, MNG_FN_CLEAR_CANVAS, MNG_LC_START);
  927. #endif
  928. pData->iDestl = 0; /* clipping region is full canvas! */
  929. pData->iDestt = 0;
  930. pData->iDestr = pData->iWidth;
  931. pData->iDestb = pData->iHeight;
  932. pData->iSourcel = 0; /* source is same as destination */
  933. pData->iSourcer = pData->iWidth;
  934. pData->iSourcet = 0;
  935. pData->iSourceb = pData->iHeight;
  936. pData->iPass = -1; /* these are the object's dimensions now */
  937. pData->iRow = 0;
  938. pData->iRowinc = 1;
  939. pData->iCol = 0;
  940. pData->iColinc = 1;
  941. pData->iRowsamples = pData->iWidth;
  942. pData->iRowsize = pData->iRowsamples << 2;
  943. pData->bIsRGBA16 = MNG_FALSE; /* let's keep it simple ! */
  944. pData->bIsOpaque = MNG_TRUE;
  945. set_display_routine (pData); /* determine display routine */
  946. /* get a temporary row-buffer */
  947. /* it's transparent black by default!! */
  948. MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize);
  949. iY = pData->iDestt; /* this is where we start */
  950. iRetcode = MNG_NOERROR; /* so far, so good */
  951. while ((!iRetcode) && (iY < pData->iDestb))
  952. { /* clear a row then */
  953. iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
  954. if (!iRetcode)
  955. iRetcode = mng_next_row (pData); /* adjust variables for next row */
  956. iY++; /* and next line */
  957. }
  958. /* drop the temporary row-buffer */
  959. MNG_FREE (pData, pData->pRGBArow, pData->iRowsize);
  960. if (iRetcode) /* on error bail out */
  961. return iRetcode;
  962. #ifdef MNG_SUPPORT_TRACE
  963. MNG_TRACE (pData, MNG_FN_CLEAR_CANVAS, MNG_LC_END);
  964. #endif
  965. return MNG_NOERROR;
  966. }
  967. /* ************************************************************************** */
  968. MNG_LOCAL mng_retcode next_frame (mng_datap pData,
  969. mng_uint8 iFramemode,
  970. mng_uint8 iChangedelay,
  971. mng_uint32 iDelay,
  972. mng_uint8 iChangetimeout,
  973. mng_uint32 iTimeout,
  974. mng_uint8 iChangeclipping,
  975. mng_uint8 iCliptype,
  976. mng_int32 iClipl,
  977. mng_int32 iClipr,
  978. mng_int32 iClipt,
  979. mng_int32 iClipb)
  980. {
  981. mng_retcode iRetcode = MNG_NOERROR;
  982. #ifdef MNG_SUPPORT_TRACE
  983. MNG_TRACE (pData, MNG_FN_NEXT_FRAME, MNG_LC_START);
  984. #endif
  985. if (!pData->iBreakpoint) /* no previous break here ? */
  986. {
  987. #ifndef MNG_SKIPCHUNK_FRAM
  988. mng_uint8 iOldmode = pData->iFramemode;
  989. /* interframe delay required ? */
  990. if ((iOldmode == 2) || (iOldmode == 4))
  991. {
  992. if ((pData->iFrameseq) && (iFramemode != 1) && (iFramemode != 3))
  993. iRetcode = interframe_delay (pData);
  994. else
  995. pData->iFramedelay = pData->iNextdelay;
  996. }
  997. else
  998. { /* delay before inserting background layer? */
  999. if ((pData->bFramedone) && (iFramemode == 4))
  1000. iRetcode = interframe_delay (pData);
  1001. }
  1002. if (iRetcode) /* on error bail out */
  1003. return iRetcode;
  1004. /* now we'll assume we're in the next frame! */
  1005. if (iFramemode) /* save the new framing mode ? */
  1006. {
  1007. pData->iFRAMmode = iFramemode;
  1008. pData->iFramemode = iFramemode;
  1009. }
  1010. else /* reload default */
  1011. pData->iFramemode = pData->iFRAMmode;
  1012. if (iChangedelay) /* delay changed ? */
  1013. {
  1014. pData->iNextdelay = iDelay; /* for *after* next subframe */
  1015. if ((iOldmode == 2) || (iOldmode == 4))
  1016. pData->iFramedelay = pData->iFRAMdelay;
  1017. if (iChangedelay == 2) /* also overall ? */
  1018. pData->iFRAMdelay = iDelay;
  1019. }
  1020. else
  1021. { /* reload default */
  1022. pData->iNextdelay = pData->iFRAMdelay;
  1023. }
  1024. if (iChangetimeout) /* timeout changed ? */
  1025. { /* for next subframe */
  1026. pData->iFrametimeout = iTimeout;
  1027. if ((iChangetimeout == 2) || /* also overall ? */
  1028. (iChangetimeout == 4) ||
  1029. (iChangetimeout == 6) ||
  1030. (iChangetimeout == 8))
  1031. pData->iFRAMtimeout = iTimeout;
  1032. }
  1033. else /* reload default */
  1034. pData->iFrametimeout = pData->iFRAMtimeout;
  1035. if (iChangeclipping) /* clipping changed ? */
  1036. {
  1037. pData->bFrameclipping = MNG_TRUE;
  1038. if (!iCliptype) /* absolute ? */
  1039. {
  1040. pData->iFrameclipl = iClipl;
  1041. pData->iFrameclipr = iClipr;
  1042. pData->iFrameclipt = iClipt;
  1043. pData->iFrameclipb = iClipb;
  1044. }
  1045. else /* relative */
  1046. {
  1047. pData->iFrameclipl = pData->iFrameclipl + iClipl;
  1048. pData->iFrameclipr = pData->iFrameclipr + iClipr;
  1049. pData->iFrameclipt = pData->iFrameclipt + iClipt;
  1050. pData->iFrameclipb = pData->iFrameclipb + iClipb;
  1051. }
  1052. if (iChangeclipping == 2) /* also overall ? */
  1053. {
  1054. pData->bFRAMclipping = MNG_TRUE;
  1055. if (!iCliptype) /* absolute ? */
  1056. {
  1057. pData->iFRAMclipl = iClipl;
  1058. pData->iFRAMclipr = iClipr;
  1059. pData->iFRAMclipt = iClipt;
  1060. pData->iFRAMclipb = iClipb;
  1061. }
  1062. else /* relative */
  1063. {
  1064. pData->iFRAMclipl = pData->iFRAMclipl + iClipl;
  1065. pData->iFRAMclipr = pData->iFRAMclipr + iClipr;
  1066. pData->iFRAMclipt = pData->iFRAMclipt + iClipt;
  1067. pData->iFRAMclipb = pData->iFRAMclipb + iClipb;
  1068. }
  1069. }
  1070. }
  1071. else
  1072. { /* reload defaults */
  1073. pData->bFrameclipping = pData->bFRAMclipping;
  1074. pData->iFrameclipl = pData->iFRAMclipl;
  1075. pData->iFrameclipr = pData->iFRAMclipr;
  1076. pData->iFrameclipt = pData->iFRAMclipt;
  1077. pData->iFrameclipb = pData->iFRAMclipb;
  1078. }
  1079. #endif
  1080. }
  1081. if (!pData->bTimerset) /* timer still off ? */
  1082. {
  1083. if (
  1084. #ifndef MNG_SKIPCHUNK_FRAM
  1085. (pData->iFramemode == 4) || /* insert background layer after a new frame */
  1086. #endif
  1087. (!pData->iLayerseq)) /* and certainly before the very first layer */
  1088. iRetcode = load_bkgdlayer (pData);
  1089. if (iRetcode) /* on error bail out */
  1090. return iRetcode;
  1091. pData->iFrameseq++; /* count the frame ! */
  1092. pData->bFramedone = MNG_TRUE; /* and indicate we've done one */
  1093. }
  1094. #ifdef MNG_SUPPORT_TRACE
  1095. MNG_TRACE (pData, MNG_FN_NEXT_FRAME, MNG_LC_END);
  1096. #endif
  1097. return MNG_NOERROR;
  1098. }
  1099. /* ************************************************************************** */
  1100. MNG_LOCAL mng_retcode next_layer (mng_datap pData)
  1101. {
  1102. mng_imagep pImage;
  1103. mng_retcode iRetcode = MNG_NOERROR;
  1104. #ifdef MNG_SUPPORT_TRACE
  1105. MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_START);
  1106. #endif
  1107. #ifndef MNG_SKIPCHUNK_FRAM
  1108. if (!pData->iBreakpoint) /* no previous break here ? */
  1109. { /* interframe delay required ? */
  1110. if ((pData->eImagetype == mng_it_mng) && (pData->iLayerseq) &&
  1111. ((pData->iFramemode == 1) || (pData->iFramemode == 3)))
  1112. iRetcode = interframe_delay (pData);
  1113. else
  1114. pData->iFramedelay = pData->iNextdelay;
  1115. if (iRetcode) /* on error bail out */
  1116. return iRetcode;
  1117. }
  1118. #endif
  1119. if (!pData->bTimerset) /* timer still off ? */
  1120. {
  1121. if (!pData->iLayerseq) /* restore background for the very first layer ? */
  1122. { /* wait till IDAT/JDAT for PNGs & JNGs !!! */
  1123. if ((pData->eImagetype == mng_it_png) || (pData->eImagetype == mng_it_jng))
  1124. pData->bRestorebkgd = MNG_TRUE;
  1125. else
  1126. { /* for MNG we do it right away */
  1127. iRetcode = load_bkgdlayer (pData);
  1128. pData->iLayerseq++; /* and it counts as a layer then ! */
  1129. }
  1130. }
  1131. #ifndef MNG_SKIPCHUNK_FRAM
  1132. else
  1133. if (pData->iFramemode == 3) /* restore background for each layer ? */
  1134. iRetcode = load_bkgdlayer (pData);
  1135. #endif
  1136. if (iRetcode) /* on error bail out */
  1137. return iRetcode;
  1138. #ifndef MNG_NO_DELTA_PNG
  1139. if (pData->bHasDHDR) /* processing a delta-image ? */
  1140. pImage = (mng_imagep)pData->pDeltaImage;
  1141. else
  1142. #endif
  1143. pImage = (mng_imagep)pData->pCurrentobj;
  1144. if (!pImage) /* not an active object ? */
  1145. pImage = (mng_imagep)pData->pObjzero;
  1146. /* determine display rectangle */
  1147. pData->iDestl = MAX_COORD ((mng_int32)0, pImage->iPosx);
  1148. pData->iDestt = MAX_COORD ((mng_int32)0, pImage->iPosy);
  1149. /* is it a valid buffer ? */
  1150. if ((pImage->pImgbuf->iWidth) && (pImage->pImgbuf->iHeight))
  1151. {
  1152. pData->iDestr = MIN_COORD ((mng_int32)pData->iWidth,
  1153. pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth );
  1154. pData->iDestb = MIN_COORD ((mng_int32)pData->iHeight,
  1155. pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight);
  1156. }
  1157. else /* it's a single image ! */
  1158. {
  1159. pData->iDestr = MIN_COORD ((mng_int32)pData->iWidth,
  1160. (mng_int32)pData->iDatawidth );
  1161. pData->iDestb = MIN_COORD ((mng_int32)pData->iHeight,
  1162. (mng_int32)pData->iDataheight);
  1163. }
  1164. #ifndef MNG_SKIPCHUNK_FRAM
  1165. if (pData->bFrameclipping) /* frame clipping specified ? */
  1166. {
  1167. pData->iDestl = MAX_COORD (pData->iDestl, pData->iFrameclipl);
  1168. pData->iDestt = MAX_COORD (pData->iDestt, pData->iFrameclipt);
  1169. pData->iDestr = MIN_COORD (pData->iDestr, pData->iFrameclipr);
  1170. pData->iDestb = MIN_COORD (pData->iDestb, pData->iFrameclipb);
  1171. }
  1172. #endif
  1173. if (pImage->bClipped) /* is the image clipped itself ? */
  1174. {
  1175. pData->iDestl = MAX_COORD (pData->iDestl, pImage->iClipl);
  1176. pData->iDestt = MAX_COORD (pData->iDestt, pImage->iClipt);
  1177. pData->iDestr = MIN_COORD (pData->iDestr, pImage->iClipr);
  1178. pData->iDestb = MIN_COORD (pData->iDestb, pImage->iClipb);
  1179. }
  1180. /* determine source starting point */
  1181. pData->iSourcel = MAX_COORD ((mng_int32)0, pData->iDestl - pImage->iPosx);
  1182. pData->iSourcet = MAX_COORD ((mng_int32)0, pData->iDestt - pImage->iPosy);
  1183. if ((pImage->pImgbuf->iWidth) && (pImage->pImgbuf->iHeight))
  1184. { /* and maximum size */
  1185. pData->iSourcer = MIN_COORD ((mng_int32)pImage->pImgbuf->iWidth,
  1186. pData->iSourcel + pData->iDestr - pData->iDestl);
  1187. pData->iSourceb = MIN_COORD ((mng_int32)pImage->pImgbuf->iHeight,
  1188. pData->iSourcet + pData->iDestb - pData->iDestt);
  1189. }
  1190. else /* it's a single image ! */
  1191. {
  1192. pData->iSourcer = pData->iSourcel + pData->iDestr - pData->iDestl;
  1193. pData->iSourceb = pData->iSourcet + pData->iDestb - pData->iDestt;
  1194. }
  1195. pData->iLayerseq++; /* count the layer ! */
  1196. }
  1197. #ifdef MNG_SUPPORT_TRACE
  1198. MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_END);
  1199. #endif
  1200. return MNG_NOERROR;
  1201. }
  1202. /* ************************************************************************** */
  1203. mng_retcode mng_display_image (mng_datap pData,
  1204. mng_imagep pImage,
  1205. mng_bool bLayeradvanced)
  1206. {
  1207. mng_retcode iRetcode;
  1208. #ifdef MNG_SUPPORT_TRACE
  1209. MNG_TRACE (pData, MNG_FN_DISPLAY_IMAGE, MNG_LC_START);
  1210. #endif
  1211. /* actively running ? */
  1212. #ifndef MNG_SKIPCHUNK_MAGN
  1213. if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
  1214. {
  1215. if ( (!pData->iBreakpoint) && /* needs magnification ? */
  1216. ( (pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY) ) )
  1217. {
  1218. iRetcode = mng_magnify_imageobject (pData, pImage);
  1219. if (iRetcode) /* on error bail out */
  1220. return iRetcode;
  1221. }
  1222. }
  1223. #endif
  1224. pData->pRetrieveobj = pImage; /* so retrieve-row and color-correction can find it */
  1225. if (!bLayeradvanced) /* need to advance the layer ? */
  1226. {
  1227. mng_imagep pSave = pData->pCurrentobj;
  1228. pData->pCurrentobj = pImage;
  1229. next_layer (pData); /* advance to next layer */
  1230. pData->pCurrentobj = pSave;
  1231. }
  1232. /* need to restore the background ? */
  1233. if ((!pData->bTimerset) && (pData->bRestorebkgd))
  1234. {
  1235. mng_imagep pSave = pData->pCurrentobj;
  1236. pData->pCurrentobj = pImage;
  1237. pData->bRestorebkgd = MNG_FALSE;
  1238. iRetcode = load_bkgdlayer (pData);
  1239. pData->pCurrentobj = pSave;
  1240. if (iRetcode) /* on error bail out */
  1241. return iRetcode;
  1242. pData->iLayerseq++; /* and it counts as a layer then ! */
  1243. }
  1244. /* actively running ? */
  1245. if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
  1246. {
  1247. if (!pData->bTimerset) /* all systems still go ? */
  1248. {
  1249. pData->iBreakpoint = 0; /* let's make absolutely sure... */
  1250. /* anything to display ? */
  1251. if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt))
  1252. {
  1253. mng_int32 iY;
  1254. set_display_routine (pData); /* determine display routine */
  1255. /* and image-buffer retrieval routine */
  1256. switch (pImage->pImgbuf->iColortype)
  1257. {
  1258. case 0 : {
  1259. #ifndef MNG_NO_16BIT_SUPPORT
  1260. if (pImage->pImgbuf->iBitdepth > 8)
  1261. pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
  1262. else
  1263. #endif
  1264. pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
  1265. pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
  1266. break;
  1267. }
  1268. case 2 : {
  1269. #ifndef MNG_NO_16BIT_SUPPORT
  1270. if (pImage->pImgbuf->iBitdepth > 8)
  1271. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
  1272. else
  1273. #endif
  1274. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
  1275. pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
  1276. break;
  1277. }
  1278. case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8;
  1279. pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
  1280. break;
  1281. }
  1282. case 4 : {
  1283. #ifndef MNG_NO_16BIT_SUPPORT
  1284. if (pImage->pImgbuf->iBitdepth > 8)
  1285. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
  1286. else
  1287. #endif
  1288. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
  1289. pData->bIsOpaque = MNG_FALSE;
  1290. break;
  1291. }
  1292. case 6 : {
  1293. #ifndef MNG_NO_16BIT_SUPPORT
  1294. if (pImage->pImgbuf->iBitdepth > 8)
  1295. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
  1296. else
  1297. #endif
  1298. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
  1299. pData->bIsOpaque = MNG_FALSE;
  1300. break;
  1301. }
  1302. case 8 : {
  1303. #ifndef MNG_NO_16BIT_SUPPORT
  1304. if (pImage->pImgbuf->iBitdepth > 8)
  1305. pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
  1306. else
  1307. #endif
  1308. pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
  1309. pData->bIsOpaque = MNG_TRUE;
  1310. break;
  1311. }
  1312. case 10 : {
  1313. #ifndef MNG_NO_16BIT_SUPPORT
  1314. if (pImage->pImgbuf->iBitdepth > 8)
  1315. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
  1316. else
  1317. #endif
  1318. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
  1319. pData->bIsOpaque = MNG_TRUE;
  1320. break;
  1321. }
  1322. case 12 : {
  1323. #ifndef MNG_NO_16BIT_SUPPORT
  1324. if (pImage->pImgbuf->iBitdepth > 8)
  1325. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
  1326. else
  1327. #endif
  1328. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
  1329. pData->bIsOpaque = MNG_FALSE;
  1330. break;
  1331. }
  1332. case 14 : {
  1333. #ifndef MNG_NO_16BIT_SUPPORT
  1334. if (pImage->pImgbuf->iBitdepth > 8)
  1335. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
  1336. else
  1337. #endif
  1338. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
  1339. pData->bIsOpaque = MNG_FALSE;
  1340. break;
  1341. }
  1342. }
  1343. pData->iPass = -1; /* these are the object's dimensions now */
  1344. pData->iRow = pData->iSourcet;
  1345. pData->iRowinc = 1;
  1346. pData->iCol = 0;
  1347. pData->iColinc = 1;
  1348. pData->iRowsamples = pImage->pImgbuf->iWidth;
  1349. pData->iRowsize = pData->iRowsamples << 2;
  1350. pData->bIsRGBA16 = MNG_FALSE;
  1351. /* adjust for 16-bit object ? */
  1352. #ifndef MNG_NO_16BIT_SUPPORT
  1353. if (pImage->pImgbuf->iBitdepth > 8)
  1354. {
  1355. pData->bIsRGBA16 = MNG_TRUE;
  1356. pData->iRowsize = pData->iRowsamples << 3;
  1357. }
  1358. #endif
  1359. pData->fCorrectrow = MNG_NULL; /* default no color-correction */
  1360. #ifdef MNG_NO_CMS
  1361. iRetcode = MNG_NOERROR;
  1362. #else
  1363. #if defined(MNG_FULL_CMS) /* determine color-management routine */
  1364. iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
  1365. #elif defined(MNG_GAMMA_ONLY)
  1366. iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
  1367. #elif defined(MNG_APP_CMS)
  1368. iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
  1369. #endif
  1370. if (iRetcode) /* on error bail out */
  1371. return iRetcode;
  1372. #endif /* MNG_NO_CMS */
  1373. /* get a temporary row-buffer */
  1374. MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize);
  1375. iY = pData->iSourcet; /* this is where we start */
  1376. while ((!iRetcode) && (iY < pData->iSourceb))
  1377. { /* get a row */
  1378. iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData);
  1379. /* color correction ? */
  1380. if ((!iRetcode) && (pData->fCorrectrow))
  1381. iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData);
  1382. if (!iRetcode) /* so... display it */
  1383. iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
  1384. if (!iRetcode) /* adjust variables for next row */
  1385. iRetcode = mng_next_row (pData);
  1386. iY++; /* and next line */
  1387. }
  1388. /* drop the temporary row-buffer */
  1389. MNG_FREE (pData, pData->pRGBArow, pData->iRowsize);
  1390. if (iRetcode) /* on error bail out */
  1391. return iRetcode;
  1392. #if defined(MNG_FULL_CMS) /* cleanup cms stuff */
  1393. iRetcode = mng_clear_cms (pData);
  1394. if (iRetcode) /* on error bail out */
  1395. return iRetcode;
  1396. #endif
  1397. }
  1398. }
  1399. }
  1400. #ifdef MNG_SUPPORT_TRACE
  1401. MNG_TRACE (pData, MNG_FN_DISPLAY_IMAGE, MNG_LC_END);
  1402. #endif
  1403. return MNG_NOERROR; /* whehehe, this is good ! */
  1404. }
  1405. /* ************************************************************************** */
  1406. #ifndef MNG_NO_DELTA_PNG
  1407. mng_retcode mng_execute_delta_image (mng_datap pData,
  1408. mng_imagep pTarget,
  1409. mng_imagep pDelta)
  1410. {
  1411. mng_imagedatap pBuftarget = pTarget->pImgbuf;
  1412. mng_imagedatap pBufdelta = pDelta->pImgbuf;
  1413. mng_uint32 iY;
  1414. mng_retcode iRetcode;
  1415. mng_ptr pSaveRGBA;
  1416. #ifdef MNG_SUPPORT_TRACE
  1417. MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_START);
  1418. #endif
  1419. /* actively running ? */
  1420. if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
  1421. {
  1422. if (pBufdelta->bHasPLTE) /* palette in delta ? */
  1423. {
  1424. mng_uint32 iX;
  1425. /* new palette larger than old one ? */
  1426. if ((!pBuftarget->bHasPLTE) || (pBuftarget->iPLTEcount < pBufdelta->iPLTEcount))
  1427. pBuftarget->iPLTEcount = pBufdelta->iPLTEcount;
  1428. /* it's definitely got a PLTE now */
  1429. pBuftarget->bHasPLTE = MNG_TRUE;
  1430. for (iX = 0; iX < pBufdelta->iPLTEcount; iX++)
  1431. {
  1432. pBuftarget->aPLTEentries[iX].iRed = pBufdelta->aPLTEentries[iX].iRed;
  1433. pBuftarget->aPLTEentries[iX].iGreen = pBufdelta->aPLTEentries[iX].iGreen;
  1434. pBuftarget->aPLTEentries[iX].iBlue = pBufdelta->aPLTEentries[iX].iBlue;
  1435. }
  1436. }
  1437. if (pBufdelta->bHasTRNS) /* cheap transparency in delta ? */
  1438. {
  1439. switch (pData->iColortype) /* drop it into the target */
  1440. {
  1441. case 0: { /* gray */
  1442. pBuftarget->iTRNSgray = pBufdelta->iTRNSgray;
  1443. pBuftarget->iTRNSred = 0;
  1444. pBuftarget->iTRNSgreen = 0;
  1445. pBuftarget->iTRNSblue = 0;
  1446. pBuftarget->iTRNScount = 0;
  1447. break;
  1448. }
  1449. case 2: { /* rgb */
  1450. pBuftarget->iTRNSgray = 0;
  1451. pBuftarget->iTRNSred = pBufdelta->iTRNSred;
  1452. pBuftarget->iTRNSgreen = pBufdelta->iTRNSgreen;
  1453. pBuftarget->iTRNSblue = pBufdelta->iTRNSblue;
  1454. pBuftarget->iTRNScount = 0;
  1455. break;
  1456. }
  1457. case 3: { /* indexed */
  1458. pBuftarget->iTRNSgray = 0;
  1459. pBuftarget->iTRNSred = 0;
  1460. pBuftarget->iTRNSgreen = 0;
  1461. pBuftarget->iTRNSblue = 0;
  1462. /* existing range smaller than new one ? */
  1463. if ((!pBuftarget->bHasTRNS) || (pBuftarget->iTRNScount < pBufdelta->iTRNScount))
  1464. pBuftarget->iTRNScount = pBufdelta->iTRNScount;
  1465. MNG_COPY (pBuftarget->aTRNSentries, pBufdelta->aTRNSentries, pBufdelta->iTRNScount);
  1466. break;
  1467. }
  1468. }
  1469. pBuftarget->bHasTRNS = MNG_TRUE; /* tell it it's got a tRNS now */
  1470. }
  1471. #ifndef MNG_SKIPCHUNK_bKGD
  1472. if (pBufdelta->bHasBKGD) /* bkgd in source ? */
  1473. { /* drop it onto the target */
  1474. pBuftarget->bHasBKGD = MNG_TRUE;
  1475. pBuftarget->iBKGDindex = pBufdelta->iBKGDindex;
  1476. pBuftarget->iBKGDgray = pBufdelta->iBKGDgray;
  1477. pBuftarget->iBKGDred = pBufdelta->iBKGDred;
  1478. pBuftarget->iBKGDgreen = pBufdelta->iBKGDgreen;
  1479. pBuftarget->iBKGDblue = pBufdelta->iBKGDblue;
  1480. }
  1481. #endif
  1482. if (pBufdelta->bHasGAMA) /* gamma in source ? */
  1483. {
  1484. pBuftarget->bHasGAMA = MNG_TRUE; /* drop it onto the target */
  1485. pBuftarget->iGamma = pBufdelta->iGamma;
  1486. }
  1487. #ifndef MNG_SKIPCHUNK_cHRM
  1488. if (pBufdelta->bHasCHRM) /* chroma in delta ? */
  1489. { /* drop it onto the target */
  1490. pBuftarget->bHasCHRM = MNG_TRUE;
  1491. pBuftarget->iWhitepointx = pBufdelta->iWhitepointx;
  1492. pBuftarget->iWhitepointy = pBufdelta->iWhitepointy;
  1493. pBuftarget->iPrimaryredx = pBufdelta->iPrimaryredx;
  1494. pBuftarget->iPrimaryredy = pBufdelta->iPrimaryredy;
  1495. pBuftarget->iPrimarygreenx = pBufdelta->iPrimarygreenx;
  1496. pBuftarget->iPrimarygreeny = pBufdelta->iPrimarygreeny;
  1497. pBuftarget->iPrimarybluex = pBufdelta->iPrimarybluex;
  1498. pBuftarget->iPrimarybluey = pBufdelta->iPrimarybluey;
  1499. }
  1500. #endif
  1501. #ifndef MNG_SKIPCHUNK_sRGB
  1502. if (pBufdelta->bHasSRGB) /* sRGB in delta ? */
  1503. { /* drop it onto the target */
  1504. pBuftarget->bHasSRGB = MNG_TRUE;
  1505. pBuftarget->iRenderingintent = pBufdelta->iRenderingintent;
  1506. }
  1507. #endif
  1508. #ifndef MNG_SKIPCHUNK_iCCP
  1509. if (pBufdelta->bHasICCP) /* ICC profile in delta ? */
  1510. {
  1511. pBuftarget->bHasICCP = MNG_TRUE; /* drop it onto the target */
  1512. if (pBuftarget->pProfile) /* profile existed ? */
  1513. MNG_FREEX (pData, pBuftarget->pProfile, pBuftarget->iProfilesize);
  1514. /* allocate a buffer & copy it */
  1515. MNG_ALLOC (pData, pBuftarget->pProfile, pBufdelta->iProfilesize);
  1516. MNG_COPY (pBuftarget->pProfile, pBufdelta->pProfile, pBufdelta->iProfilesize);
  1517. /* store its length as well */
  1518. pBuftarget->iProfilesize = pBufdelta->iProfilesize;
  1519. }
  1520. #endif
  1521. /* need to execute delta pixels ? */
  1522. if ((!pData->bDeltaimmediate) && (pData->iDeltatype != MNG_DELTATYPE_NOCHANGE))
  1523. {
  1524. pData->fScalerow = MNG_NULL; /* not needed by default */
  1525. switch (pBufdelta->iBitdepth) /* determine scaling routine */
  1526. {
  1527. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  1528. case 1 : {
  1529. switch (pBuftarget->iBitdepth)
  1530. {
  1531. case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g2; break; }
  1532. case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g4; break; }
  1533. case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g8; break; }
  1534. #ifndef MNG_NO_16BIT_SUPPORT
  1535. case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g16; break; }
  1536. #endif
  1537. }
  1538. break;
  1539. }
  1540. case 2 : {
  1541. switch (pBuftarget->iBitdepth)
  1542. {
  1543. case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g1; break; }
  1544. case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g4; break; }
  1545. case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g8; break; }
  1546. #ifndef MNG_NO_16BIT_SUPPORT
  1547. case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g2_g16; break; }
  1548. #endif
  1549. }
  1550. break;
  1551. }
  1552. case 4 : {
  1553. switch (pBuftarget->iBitdepth)
  1554. {
  1555. case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g1; break; }
  1556. case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g2; break; }
  1557. case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g8; break; }
  1558. #ifndef MNG_NO_16BIT_SUPPORT
  1559. case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g4_g16; break; }
  1560. #endif
  1561. }
  1562. break;
  1563. }
  1564. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  1565. case 8 : {
  1566. switch (pBufdelta->iColortype)
  1567. {
  1568. case 0 : ;
  1569. case 3 : ;
  1570. case 8 : {
  1571. switch (pBuftarget->iBitdepth)
  1572. {
  1573. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  1574. case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g1; break; }
  1575. case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g2; break; }
  1576. case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g4; break; }
  1577. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  1578. #ifndef MNG_NO_16BIT_SUPPORT
  1579. case 16 : { pData->fScalerow = (mng_fptr)mng_scale_g8_g16; break; }
  1580. #endif
  1581. }
  1582. break;
  1583. }
  1584. case 2 : ;
  1585. case 10 : {
  1586. #ifndef MNG_NO_16BIT_SUPPORT
  1587. if (pBuftarget->iBitdepth == 16)
  1588. pData->fScalerow = (mng_fptr)mng_scale_rgb8_rgb16;
  1589. #endif
  1590. break;
  1591. }
  1592. case 4 : ;
  1593. case 12 : {
  1594. #ifndef MNG_NO_16BIT_SUPPORT
  1595. if (pBuftarget->iBitdepth == 16)
  1596. pData->fScalerow = (mng_fptr)mng_scale_ga8_ga16;
  1597. #endif
  1598. break;
  1599. }
  1600. case 6 : ;
  1601. case 14 : {
  1602. #ifndef MNG_NO_16BIT_SUPPORT
  1603. if (pBuftarget->iBitdepth == 16)
  1604. pData->fScalerow = (mng_fptr)mng_scale_rgba8_rgba16;
  1605. #endif
  1606. break;
  1607. }
  1608. }
  1609. break;
  1610. }
  1611. #ifndef MNG_NO_16BIT_SUPPORT
  1612. case 16 : {
  1613. switch (pBufdelta->iColortype)
  1614. {
  1615. case 0 : ;
  1616. case 3 : ;
  1617. case 8 : {
  1618. switch (pBuftarget->iBitdepth)
  1619. {
  1620. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  1621. case 1 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g1; break; }
  1622. case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g2; break; }
  1623. case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g4; break; }
  1624. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  1625. case 8 : { pData->fScalerow = (mng_fptr)mng_scale_g16_g8; break; }
  1626. }
  1627. break;
  1628. }
  1629. case 2 : ;
  1630. case 10 : {
  1631. if (pBuftarget->iBitdepth == 8)
  1632. pData->fScalerow = (mng_fptr)mng_scale_rgb16_rgb8;
  1633. break;
  1634. }
  1635. case 4 : ;
  1636. case 12 : {
  1637. if (pBuftarget->iBitdepth == 8)
  1638. pData->fScalerow = (mng_fptr)mng_scale_ga16_ga8;
  1639. break;
  1640. }
  1641. case 6 : ;
  1642. case 14 : {
  1643. if (pBuftarget->iBitdepth == 8)
  1644. pData->fScalerow = (mng_fptr)mng_scale_rgba16_rgba8;
  1645. break;
  1646. }
  1647. }
  1648. break;
  1649. }
  1650. #endif
  1651. }
  1652. pData->fDeltarow = MNG_NULL; /* let's assume there's nothing to do */
  1653. switch (pBuftarget->iColortype) /* determine delta processing routine */
  1654. {
  1655. case 0 : ;
  1656. case 8 : { /* gray */
  1657. if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
  1658. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
  1659. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
  1660. {
  1661. if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) ||
  1662. (pBufdelta->iColortype == 8))
  1663. {
  1664. switch (pBuftarget->iBitdepth)
  1665. {
  1666. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  1667. case 1 : { pData->fDeltarow = (mng_fptr)mng_delta_g1_g1; break; }
  1668. case 2 : { pData->fDeltarow = (mng_fptr)mng_delta_g2_g2; break; }
  1669. case 4 : { pData->fDeltarow = (mng_fptr)mng_delta_g4_g4; break; }
  1670. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  1671. case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_g8_g8; break; }
  1672. #ifndef MNG_NO_16BIT_SUPPORT
  1673. case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_g16_g16; break; }
  1674. #endif
  1675. }
  1676. }
  1677. }
  1678. break;
  1679. }
  1680. case 2 : ;
  1681. case 10 : { /* rgb */
  1682. if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
  1683. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
  1684. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
  1685. {
  1686. if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10))
  1687. {
  1688. switch (pBuftarget->iBitdepth)
  1689. {
  1690. case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgb8_rgb8; break; }
  1691. #ifndef MNG_NO_16BIT_SUPPORT
  1692. case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgb16_rgb16; break; }
  1693. #endif
  1694. }
  1695. }
  1696. }
  1697. break;
  1698. }
  1699. case 3 : { /* indexed; abuse gray routines */
  1700. if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
  1701. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
  1702. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
  1703. {
  1704. if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3))
  1705. {
  1706. switch (pBuftarget->iBitdepth)
  1707. {
  1708. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  1709. case 1 : { pData->fDeltarow = (mng_fptr)mng_delta_g1_g1; break; }
  1710. case 2 : { pData->fDeltarow = (mng_fptr)mng_delta_g2_g2; break; }
  1711. case 4 : { pData->fDeltarow = (mng_fptr)mng_delta_g4_g4; break; }
  1712. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  1713. case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_g8_g8; break; }
  1714. }
  1715. }
  1716. }
  1717. break;
  1718. }
  1719. case 4 : ;
  1720. case 12 : { /* gray + alpha */
  1721. if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
  1722. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
  1723. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
  1724. {
  1725. if ((pBufdelta->iColortype == 4) || (pBufdelta->iColortype == 12))
  1726. {
  1727. switch (pBuftarget->iBitdepth)
  1728. {
  1729. case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_ga8_ga8; break; }
  1730. #ifndef MNG_NO_16BIT_SUPPORT
  1731. case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_ga16_ga16; break; }
  1732. #endif
  1733. }
  1734. }
  1735. }
  1736. else
  1737. if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
  1738. (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
  1739. {
  1740. if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) ||
  1741. (pBufdelta->iColortype == 8))
  1742. {
  1743. switch (pBuftarget->iBitdepth)
  1744. {
  1745. case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_ga8_g8; break; }
  1746. #ifndef MNG_NO_16BIT_SUPPORT
  1747. case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_ga16_g16; break; }
  1748. #endif
  1749. }
  1750. }
  1751. }
  1752. else
  1753. if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
  1754. (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
  1755. {
  1756. if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3))
  1757. {
  1758. switch (pBuftarget->iBitdepth)
  1759. {
  1760. case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_ga8_a8; break; }
  1761. #ifndef MNG_NO_16BIT_SUPPORT
  1762. case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_ga16_a16; break; }
  1763. #endif
  1764. }
  1765. }
  1766. }
  1767. break;
  1768. }
  1769. case 6 : ;
  1770. case 14 : { /* rgb + alpha */
  1771. if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
  1772. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
  1773. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
  1774. {
  1775. if ((pBufdelta->iColortype == 6) || (pBufdelta->iColortype == 14))
  1776. {
  1777. switch (pBuftarget->iBitdepth)
  1778. {
  1779. case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgba8; break; }
  1780. #ifndef MNG_NO_16BIT_SUPPORT
  1781. case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgba16; break; }
  1782. #endif
  1783. }
  1784. }
  1785. }
  1786. else
  1787. if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
  1788. (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
  1789. {
  1790. if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10))
  1791. {
  1792. switch (pBuftarget->iBitdepth)
  1793. {
  1794. case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgb8; break; }
  1795. #ifndef MNG_NO_16BIT_SUPPORT
  1796. case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgb16; break; }
  1797. #endif
  1798. }
  1799. }
  1800. }
  1801. else
  1802. if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
  1803. (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
  1804. {
  1805. if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3))
  1806. {
  1807. switch (pBuftarget->iBitdepth)
  1808. {
  1809. case 8 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba8_a8; break; }
  1810. #ifndef MNG_NO_16BIT_SUPPORT
  1811. case 16 : { pData->fDeltarow = (mng_fptr)mng_delta_rgba16_a16; break; }
  1812. #endif
  1813. }
  1814. }
  1815. }
  1816. break;
  1817. }
  1818. }
  1819. if (pData->fDeltarow) /* do we need to take action ? */
  1820. {
  1821. pData->iPass = -1; /* setup row dimensions and stuff */
  1822. pData->iRow = pData->iDeltaBlocky;
  1823. pData->iRowinc = 1;
  1824. pData->iCol = pData->iDeltaBlockx;
  1825. pData->iColinc = 1;
  1826. pData->iRowsamples = pBufdelta->iWidth;
  1827. pData->iRowsize = pBuftarget->iRowsize;
  1828. /* indicate where to retrieve & where to store */
  1829. pData->pRetrieveobj = (mng_objectp)pDelta;
  1830. pData->pStoreobj = (mng_objectp)pTarget;
  1831. pSaveRGBA = pData->pRGBArow; /* save current temp-buffer! */
  1832. /* get a temporary row-buffer */
  1833. MNG_ALLOC (pData, pData->pRGBArow, (pBufdelta->iRowsize << 1));
  1834. iY = 0; /* this is where we start */
  1835. iRetcode = MNG_NOERROR; /* still oke for now */
  1836. while ((!iRetcode) && (iY < pBufdelta->iHeight))
  1837. { /* get a row */
  1838. mng_uint8p pWork = pBufdelta->pImgdata + (iY * pBufdelta->iRowsize);
  1839. MNG_COPY (pData->pRGBArow, pWork, pBufdelta->iRowsize);
  1840. if (pData->fScalerow) /* scale it (if necessary) */
  1841. iRetcode = ((mng_scalerow)pData->fScalerow) (pData);
  1842. if (!iRetcode) /* and... execute it */
  1843. iRetcode = ((mng_deltarow)pData->fDeltarow) (pData);
  1844. if (!iRetcode) /* adjust variables for next row */
  1845. iRetcode = mng_next_row (pData);
  1846. iY++; /* and next line */
  1847. }
  1848. /* drop the temporary row-buffer */
  1849. MNG_FREE (pData, pData->pRGBArow, (pBufdelta->iRowsize << 1));
  1850. pData->pRGBArow = pSaveRGBA; /* restore saved temp-buffer! */
  1851. if (iRetcode) /* on error bail out */
  1852. return iRetcode;
  1853. }
  1854. else
  1855. MNG_ERROR (pData, MNG_INVALIDDELTA);
  1856. }
  1857. }
  1858. #ifdef MNG_SUPPORT_TRACE
  1859. MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_END);
  1860. #endif
  1861. return MNG_NOERROR;
  1862. }
  1863. #endif /* MNG_NO_DELTA_PNG */
  1864. /* ************************************************************************** */
  1865. #ifndef MNG_SKIPCHUNK_SAVE
  1866. MNG_LOCAL mng_retcode save_state (mng_datap pData)
  1867. {
  1868. mng_savedatap pSave;
  1869. mng_imagep pImage;
  1870. #ifdef MNG_SUPPORT_TRACE
  1871. MNG_TRACE (pData, MNG_FN_SAVE_STATE, MNG_LC_START);
  1872. #endif
  1873. if (pData->pSavedata) /* sanity check */
  1874. MNG_ERROR (pData, MNG_INTERNALERROR);
  1875. /* get a buffer for saving */
  1876. MNG_ALLOC (pData, pData->pSavedata, sizeof (mng_savedata));
  1877. pSave = pData->pSavedata; /* address it more directly */
  1878. /* and copy global data from the main struct */
  1879. #if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE)
  1880. pSave->bHasglobalPLTE = pData->bHasglobalPLTE;
  1881. pSave->bHasglobalTRNS = pData->bHasglobalTRNS;
  1882. pSave->bHasglobalGAMA = pData->bHasglobalGAMA;
  1883. pSave->bHasglobalCHRM = pData->bHasglobalCHRM;
  1884. pSave->bHasglobalSRGB = pData->bHasglobalSRGB;
  1885. pSave->bHasglobalICCP = pData->bHasglobalICCP;
  1886. pSave->bHasglobalBKGD = pData->bHasglobalBKGD;
  1887. #endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */
  1888. #ifndef MNG_SKIPCHUNK_BACK
  1889. pSave->iBACKred = pData->iBACKred;
  1890. pSave->iBACKgreen = pData->iBACKgreen;
  1891. pSave->iBACKblue = pData->iBACKblue;
  1892. pSave->iBACKmandatory = pData->iBACKmandatory;
  1893. pSave->iBACKimageid = pData->iBACKimageid;
  1894. pSave->iBACKtile = pData->iBACKtile;
  1895. #endif
  1896. #ifndef MNG_SKIPCHUNK_FRAM
  1897. pSave->iFRAMmode = pData->iFRAMmode;
  1898. pSave->iFRAMdelay = pData->iFRAMdelay;
  1899. pSave->iFRAMtimeout = pData->iFRAMtimeout;
  1900. pSave->bFRAMclipping = pData->bFRAMclipping;
  1901. pSave->iFRAMclipl = pData->iFRAMclipl;
  1902. pSave->iFRAMclipr = pData->iFRAMclipr;
  1903. pSave->iFRAMclipt = pData->iFRAMclipt;
  1904. pSave->iFRAMclipb = pData->iFRAMclipb;
  1905. #endif
  1906. pSave->iGlobalPLTEcount = pData->iGlobalPLTEcount;
  1907. MNG_COPY (pSave->aGlobalPLTEentries, pData->aGlobalPLTEentries, sizeof (mng_rgbpaltab));
  1908. pSave->iGlobalTRNSrawlen = pData->iGlobalTRNSrawlen;
  1909. MNG_COPY (pSave->aGlobalTRNSrawdata, pData->aGlobalTRNSrawdata, 256);
  1910. pSave->iGlobalGamma = pData->iGlobalGamma;
  1911. #ifndef MNG_SKIPCHUNK_cHRM
  1912. pSave->iGlobalWhitepointx = pData->iGlobalWhitepointx;
  1913. pSave->iGlobalWhitepointy = pData->iGlobalWhitepointy;
  1914. pSave->iGlobalPrimaryredx = pData->iGlobalPrimaryredx;
  1915. pSave->iGlobalPrimaryredy = pData->iGlobalPrimaryredy;
  1916. pSave->iGlobalPrimarygreenx = pData->iGlobalPrimarygreenx;
  1917. pSave->iGlobalPrimarygreeny = pData->iGlobalPrimarygreeny;
  1918. pSave->iGlobalPrimarybluex = pData->iGlobalPrimarybluex;
  1919. pSave->iGlobalPrimarybluey = pData->iGlobalPrimarybluey;
  1920. #endif
  1921. #ifndef MNG_SKIPCHUNK_sRGB
  1922. pSave->iGlobalRendintent = pData->iGlobalRendintent;
  1923. #endif
  1924. #ifndef MNG_SKIPCHUNK_iCCP
  1925. pSave->iGlobalProfilesize = pData->iGlobalProfilesize;
  1926. if (pSave->iGlobalProfilesize) /* has a profile ? */
  1927. { /* then copy that ! */
  1928. MNG_ALLOC (pData, pSave->pGlobalProfile, pSave->iGlobalProfilesize);
  1929. MNG_COPY (pSave->pGlobalProfile, pData->pGlobalProfile, pSave->iGlobalProfilesize);
  1930. }
  1931. #endif
  1932. #ifndef MNG_SKIPCHUNK_bKGD
  1933. pSave->iGlobalBKGDred = pData->iGlobalBKGDred;
  1934. pSave->iGlobalBKGDgreen = pData->iGlobalBKGDgreen;
  1935. pSave->iGlobalBKGDblue = pData->iGlobalBKGDblue;
  1936. #endif
  1937. /* freeze current image objects */
  1938. pImage = (mng_imagep)pData->pFirstimgobj;
  1939. while (pImage)
  1940. { /* freeze the object AND its buffer */
  1941. pImage->bFrozen = MNG_TRUE;
  1942. pImage->pImgbuf->bFrozen = MNG_TRUE;
  1943. /* neeeext */
  1944. pImage = (mng_imagep)pImage->sHeader.pNext;
  1945. }
  1946. #ifdef MNG_SUPPORT_TRACE
  1947. MNG_TRACE (pData, MNG_FN_SAVE_STATE, MNG_LC_END);
  1948. #endif
  1949. return MNG_NOERROR;
  1950. }
  1951. #endif
  1952. /* ************************************************************************** */
  1953. mng_retcode mng_reset_objzero (mng_datap pData)
  1954. {
  1955. mng_imagep pImage = (mng_imagep)pData->pObjzero;
  1956. mng_retcode iRetcode = mng_reset_object_details (pData, pImage, 0, 0, 0,
  1957. 0, 0, 0, 0, MNG_TRUE);
  1958. if (iRetcode) /* on error bail out */
  1959. return iRetcode;
  1960. pImage->bVisible = MNG_TRUE;
  1961. pImage->bViewable = MNG_TRUE;
  1962. pImage->iPosx = 0;
  1963. pImage->iPosy = 0;
  1964. pImage->bClipped = MNG_FALSE;
  1965. pImage->iClipl = 0;
  1966. pImage->iClipr = 0;
  1967. pImage->iClipt = 0;
  1968. pImage->iClipb = 0;
  1969. #ifndef MNG_SKIPCHUNK_MAGN
  1970. pImage->iMAGN_MethodX = 0;
  1971. pImage->iMAGN_MethodY = 0;
  1972. pImage->iMAGN_MX = 0;
  1973. pImage->iMAGN_MY = 0;
  1974. pImage->iMAGN_ML = 0;
  1975. pImage->iMAGN_MR = 0;
  1976. pImage->iMAGN_MT = 0;
  1977. pImage->iMAGN_MB = 0;
  1978. #endif
  1979. return MNG_NOERROR;
  1980. }
  1981. /* ************************************************************************** */
  1982. MNG_LOCAL mng_retcode restore_state (mng_datap pData)
  1983. {
  1984. #ifndef MNG_SKIPCHUNK_SAVE
  1985. mng_savedatap pSave;
  1986. #endif
  1987. mng_imagep pImage;
  1988. mng_retcode iRetcode;
  1989. #ifdef MNG_SUPPORT_TRACE
  1990. MNG_TRACE (pData, MNG_FN_RESTORE_STATE, MNG_LC_START);
  1991. #endif
  1992. /* restore object 0 status !!! */
  1993. iRetcode = mng_reset_objzero (pData);
  1994. if (iRetcode) /* on error bail out */
  1995. return iRetcode;
  1996. /* fresh cycle; fake no frames done yet */
  1997. pData->bFramedone = MNG_FALSE;
  1998. #ifndef MNG_SKIPCHUNK_SAVE
  1999. if (pData->pSavedata) /* do we have a saved state ? */
  2000. {
  2001. pSave = pData->pSavedata; /* address it more directly */
  2002. /* and copy it back to the main struct */
  2003. #if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE)
  2004. pData->bHasglobalPLTE = pSave->bHasglobalPLTE;
  2005. pData->bHasglobalTRNS = pSave->bHasglobalTRNS;
  2006. pData->bHasglobalGAMA = pSave->bHasglobalGAMA;
  2007. pData->bHasglobalCHRM = pSave->bHasglobalCHRM;
  2008. pData->bHasglobalSRGB = pSave->bHasglobalSRGB;
  2009. pData->bHasglobalICCP = pSave->bHasglobalICCP;
  2010. pData->bHasglobalBKGD = pSave->bHasglobalBKGD;
  2011. #endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */
  2012. #ifndef MNG_SKIPCHUNK_BACK
  2013. pData->iBACKred = pSave->iBACKred;
  2014. pData->iBACKgreen = pSave->iBACKgreen;
  2015. pData->iBACKblue = pSave->iBACKblue;
  2016. pData->iBACKmandatory = pSave->iBACKmandatory;
  2017. pData->iBACKimageid = pSave->iBACKimageid;
  2018. pData->iBACKtile = pSave->iBACKtile;
  2019. #endif
  2020. #ifndef MNG_SKIPCHUNK_FRAM
  2021. pData->iFRAMmode = pSave->iFRAMmode;
  2022. /* pData->iFRAMdelay = pSave->iFRAMdelay; */
  2023. pData->iFRAMtimeout = pSave->iFRAMtimeout;
  2024. pData->bFRAMclipping = pSave->bFRAMclipping;
  2025. pData->iFRAMclipl = pSave->iFRAMclipl;
  2026. pData->iFRAMclipr = pSave->iFRAMclipr;
  2027. pData->iFRAMclipt = pSave->iFRAMclipt;
  2028. pData->iFRAMclipb = pSave->iFRAMclipb;
  2029. /* NOOOOOOOOOOOO */
  2030. /* pData->iFramemode = pSave->iFRAMmode;
  2031. pData->iFramedelay = pSave->iFRAMdelay;
  2032. pData->iFrametimeout = pSave->iFRAMtimeout;
  2033. pData->bFrameclipping = pSave->bFRAMclipping;
  2034. pData->iFrameclipl = pSave->iFRAMclipl;
  2035. pData->iFrameclipr = pSave->iFRAMclipr;
  2036. pData->iFrameclipt = pSave->iFRAMclipt;
  2037. pData->iFrameclipb = pSave->iFRAMclipb; */
  2038. /* pData->iNextdelay = pSave->iFRAMdelay; */
  2039. pData->iNextdelay = pData->iFramedelay;
  2040. #endif
  2041. pData->iGlobalPLTEcount = pSave->iGlobalPLTEcount;
  2042. MNG_COPY (pData->aGlobalPLTEentries, pSave->aGlobalPLTEentries, sizeof (mng_rgbpaltab));
  2043. pData->iGlobalTRNSrawlen = pSave->iGlobalTRNSrawlen;
  2044. MNG_COPY (pData->aGlobalTRNSrawdata, pSave->aGlobalTRNSrawdata, 256);
  2045. pData->iGlobalGamma = pSave->iGlobalGamma;
  2046. #ifndef MNG_SKIPCHUNK_cHRM
  2047. pData->iGlobalWhitepointx = pSave->iGlobalWhitepointx;
  2048. pData->iGlobalWhitepointy = pSave->iGlobalWhitepointy;
  2049. pData->iGlobalPrimaryredx = pSave->iGlobalPrimaryredx;
  2050. pData->iGlobalPrimaryredy = pSave->iGlobalPrimaryredy;
  2051. pData->iGlobalPrimarygreenx = pSave->iGlobalPrimarygreenx;
  2052. pData->iGlobalPrimarygreeny = pSave->iGlobalPrimarygreeny;
  2053. pData->iGlobalPrimarybluex = pSave->iGlobalPrimarybluex;
  2054. pData->iGlobalPrimarybluey = pSave->iGlobalPrimarybluey;
  2055. #endif
  2056. pData->iGlobalRendintent = pSave->iGlobalRendintent;
  2057. #ifndef MNG_SKIPCHUNK_iCCP
  2058. pData->iGlobalProfilesize = pSave->iGlobalProfilesize;
  2059. if (pData->iGlobalProfilesize) /* has a profile ? */
  2060. { /* then copy that ! */
  2061. MNG_ALLOC (pData, pData->pGlobalProfile, pData->iGlobalProfilesize);
  2062. MNG_COPY (pData->pGlobalProfile, pSave->pGlobalProfile, pData->iGlobalProfilesize);
  2063. }
  2064. #endif
  2065. #ifndef MNG_SKIPCHUNK_bKGD
  2066. pData->iGlobalBKGDred = pSave->iGlobalBKGDred;
  2067. pData->iGlobalBKGDgreen = pSave->iGlobalBKGDgreen;
  2068. pData->iGlobalBKGDblue = pSave->iGlobalBKGDblue;
  2069. #endif
  2070. }
  2071. else /* no saved-data; so reset the lot */
  2072. #endif /* SKIPCHUNK_SAVE */
  2073. {
  2074. #if defined(MNG_SUPPORT_READ) || defined(MNG_SUPPORT_WRITE)
  2075. pData->bHasglobalPLTE = MNG_FALSE;
  2076. pData->bHasglobalTRNS = MNG_FALSE;
  2077. pData->bHasglobalGAMA = MNG_FALSE;
  2078. pData->bHasglobalCHRM = MNG_FALSE;
  2079. pData->bHasglobalSRGB = MNG_FALSE;
  2080. pData->bHasglobalICCP = MNG_FALSE;
  2081. pData->bHasglobalBKGD = MNG_FALSE;
  2082. #endif /* MNG_SUPPORT_READ || MNG_SUPPORT_WRITE */
  2083. #ifndef MNG_SKIPCHUNK_TERM
  2084. if (!pData->bMisplacedTERM) /* backward compatible ugliness !!! */
  2085. {
  2086. pData->iBACKred = 0;
  2087. pData->iBACKgreen = 0;
  2088. pData->iBACKblue = 0;
  2089. pData->iBACKmandatory = 0;
  2090. pData->iBACKimageid = 0;
  2091. pData->iBACKtile = 0;
  2092. }
  2093. #endif
  2094. #ifndef MNG_SKIPCHUNK_FRAM
  2095. pData->iFRAMmode = 1;
  2096. /* pData->iFRAMdelay = 1; */
  2097. pData->iFRAMtimeout = 0x7fffffffl;
  2098. pData->bFRAMclipping = MNG_FALSE;
  2099. pData->iFRAMclipl = 0;
  2100. pData->iFRAMclipr = 0;
  2101. pData->iFRAMclipt = 0;
  2102. pData->iFRAMclipb = 0;
  2103. /* NOOOOOOOOOOOO */
  2104. /* pData->iFramemode = 1;
  2105. pData->iFramedelay = 1;
  2106. pData->iFrametimeout = 0x7fffffffl;
  2107. pData->bFrameclipping = MNG_FALSE;
  2108. pData->iFrameclipl = 0;
  2109. pData->iFrameclipr = 0;
  2110. pData->iFrameclipt = 0;
  2111. pData->iFrameclipb = 0; */
  2112. /* pData->iNextdelay = 1; */
  2113. pData->iNextdelay = pData->iFramedelay;
  2114. #endif
  2115. pData->iGlobalPLTEcount = 0;
  2116. pData->iGlobalTRNSrawlen = 0;
  2117. pData->iGlobalGamma = 0;
  2118. #ifndef MNG_SKIPCHUNK_cHRM
  2119. pData->iGlobalWhitepointx = 0;
  2120. pData->iGlobalWhitepointy = 0;
  2121. pData->iGlobalPrimaryredx = 0;
  2122. pData->iGlobalPrimaryredy = 0;
  2123. pData->iGlobalPrimarygreenx = 0;
  2124. pData->iGlobalPrimarygreeny = 0;
  2125. pData->iGlobalPrimarybluex = 0;
  2126. pData->iGlobalPrimarybluey = 0;
  2127. #endif
  2128. pData->iGlobalRendintent = 0;
  2129. #ifndef MNG_SKIPCHUNK_iCCP
  2130. if (pData->iGlobalProfilesize) /* free a previous profile ? */
  2131. MNG_FREE (pData, pData->pGlobalProfile, pData->iGlobalProfilesize);
  2132. pData->iGlobalProfilesize = 0;
  2133. #endif
  2134. #ifndef MNG_SKIPCHUNK_bKGD
  2135. pData->iGlobalBKGDred = 0;
  2136. pData->iGlobalBKGDgreen = 0;
  2137. pData->iGlobalBKGDblue = 0;
  2138. #endif
  2139. }
  2140. #ifndef MNG_SKIPCHUNK_TERM
  2141. if (!pData->bMisplacedTERM) /* backward compatible ugliness !!! */
  2142. {
  2143. pImage = (mng_imagep)pData->pFirstimgobj;
  2144. /* drop un-frozen image objects */
  2145. while (pImage)
  2146. {
  2147. mng_imagep pNext = (mng_imagep)pImage->sHeader.pNext;
  2148. if (!pImage->bFrozen) /* is it un-frozen ? */
  2149. {
  2150. mng_imagep pPrev = (mng_imagep)pImage->sHeader.pPrev;
  2151. if (pPrev) /* unlink it */
  2152. pPrev->sHeader.pNext = pNext;
  2153. else
  2154. pData->pFirstimgobj = pNext;
  2155. if (pNext)
  2156. pNext->sHeader.pPrev = pPrev;
  2157. else
  2158. pData->pLastimgobj = pPrev;
  2159. if (pImage->pImgbuf->bFrozen) /* buffer frozen ? */
  2160. {
  2161. if (pImage->pImgbuf->iRefcount < 2)
  2162. MNG_ERROR (pData, MNG_INTERNALERROR);
  2163. /* decrease ref counter */
  2164. pImage->pImgbuf->iRefcount--;
  2165. /* just cleanup the object then */
  2166. MNG_FREEX (pData, pImage, sizeof (mng_image));
  2167. }
  2168. else
  2169. { /* free the image buffer */
  2170. iRetcode = mng_free_imagedataobject (pData, pImage->pImgbuf);
  2171. /* and cleanup the object */
  2172. MNG_FREEX (pData, pImage, sizeof (mng_image));
  2173. if (iRetcode) /* on error bail out */
  2174. return iRetcode;
  2175. }
  2176. }
  2177. pImage = pNext; /* neeeext */
  2178. }
  2179. }
  2180. #endif
  2181. #ifdef MNG_SUPPORT_TRACE
  2182. MNG_TRACE (pData, MNG_FN_RESTORE_STATE, MNG_LC_END);
  2183. #endif
  2184. return MNG_NOERROR;
  2185. }
  2186. /* ************************************************************************** */
  2187. /* * * */
  2188. /* * General display processing routine * */
  2189. /* * * */
  2190. /* ************************************************************************** */
  2191. mng_retcode mng_process_display (mng_datap pData)
  2192. {
  2193. mng_retcode iRetcode = MNG_NOERROR;
  2194. #ifdef MNG_SUPPORT_TRACE
  2195. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY, MNG_LC_START);
  2196. #endif
  2197. if (!pData->iBreakpoint) /* not broken previously ? */
  2198. {
  2199. if ((pData->iRequestframe) || (pData->iRequestlayer) || (pData->iRequesttime))
  2200. {
  2201. pData->bSearching = MNG_TRUE; /* indicate we're searching */
  2202. iRetcode = clear_canvas (pData); /* make the canvas virgin black ?!? */
  2203. if (iRetcode) /* on error bail out */
  2204. return iRetcode;
  2205. /* let's start from the top, shall we */
  2206. pData->pCurraniobj = pData->pFirstaniobj;
  2207. }
  2208. }
  2209. do /* process the objects */
  2210. {
  2211. if (pData->bSearching) /* clear timer-flag when searching !!! */
  2212. pData->bTimerset = MNG_FALSE;
  2213. /* do we need to finish something first ? */
  2214. if ((pData->iBreakpoint) && (pData->iBreakpoint < 99))
  2215. {
  2216. switch (pData->iBreakpoint) /* return to broken display routine */
  2217. {
  2218. #ifndef MNG_SKIPCHUNK_FRAM
  2219. case 1 : { iRetcode = mng_process_display_fram2 (pData); break; }
  2220. #endif
  2221. #ifndef MNG_SKIPCHUNK_SHOW
  2222. case 3 : ; /* same as 4 !!! */
  2223. case 4 : { iRetcode = mng_process_display_show (pData); break; }
  2224. #endif
  2225. #ifndef MNG_SKIPCHUNK_CLON
  2226. case 5 : { iRetcode = mng_process_display_clon2 (pData); break; }
  2227. #endif
  2228. #ifndef MNG_SKIPCHUNK_MAGN
  2229. case 9 : { iRetcode = mng_process_display_magn2 (pData); break; }
  2230. case 10 : { iRetcode = mng_process_display_mend2 (pData); break; }
  2231. #endif
  2232. #ifndef MNG_SKIPCHUNK_PAST
  2233. case 11 : { iRetcode = mng_process_display_past2 (pData); break; }
  2234. #endif
  2235. default : MNG_ERROR (pData, MNG_INTERNALERROR);
  2236. }
  2237. }
  2238. else
  2239. {
  2240. if (pData->pCurraniobj)
  2241. iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj);
  2242. }
  2243. if (!pData->bTimerset) /* reset breakpoint flag ? */
  2244. pData->iBreakpoint = 0;
  2245. /* can we advance to next object ? */
  2246. if ((!iRetcode) && (pData->pCurraniobj) &&
  2247. (!pData->bTimerset) && (!pData->bSectionwait))
  2248. {
  2249. pData->pCurraniobj = ((mng_object_headerp)pData->pCurraniobj)->pNext;
  2250. /* MEND processing to be done ? */
  2251. if ((pData->eImagetype == mng_it_mng) && (!pData->pCurraniobj))
  2252. iRetcode = mng_process_display_mend (pData);
  2253. if (!pData->pCurraniobj) /* refresh after last image ? */
  2254. pData->bNeedrefresh = MNG_TRUE;
  2255. }
  2256. if (pData->bSearching) /* are we looking for something ? */
  2257. {
  2258. if ((pData->iRequestframe) && (pData->iRequestframe <= pData->iFrameseq))
  2259. {
  2260. pData->iRequestframe = 0; /* found the frame ! */
  2261. pData->bSearching = MNG_FALSE;
  2262. }
  2263. else
  2264. if ((pData->iRequestlayer) && (pData->iRequestlayer <= pData->iLayerseq))
  2265. {
  2266. pData->iRequestlayer = 0; /* found the layer ! */
  2267. pData->bSearching = MNG_FALSE;
  2268. }
  2269. else
  2270. if ((pData->iRequesttime) && (pData->iRequesttime <= pData->iFrametime))
  2271. {
  2272. pData->iRequesttime = 0; /* found the playtime ! */
  2273. pData->bSearching = MNG_FALSE;
  2274. }
  2275. }
  2276. } /* until error or a break or no more objects */
  2277. while ((!iRetcode) && (pData->pCurraniobj) &&
  2278. (((pData->bRunning) && (!pData->bTimerset)) || (pData->bSearching)) &&
  2279. (!pData->bSectionwait) && (!pData->bFreezing));
  2280. if (iRetcode) /* on error bail out */
  2281. return iRetcode;
  2282. /* refresh needed ? */
  2283. if ((!pData->bTimerset) && (pData->bNeedrefresh))
  2284. {
  2285. iRetcode = mng_display_progressive_refresh (pData, 1);
  2286. if (iRetcode) /* on error bail out */
  2287. return iRetcode;
  2288. }
  2289. /* timer break ? */
  2290. if ((pData->bTimerset) && (!pData->iBreakpoint))
  2291. pData->iBreakpoint = 99;
  2292. else
  2293. if (!pData->bTimerset)
  2294. pData->iBreakpoint = 0; /* reset if no timer break */
  2295. if ((!pData->bTimerset) && (!pData->pCurraniobj))
  2296. pData->bRunning = MNG_FALSE; /* all done now ! */
  2297. #ifdef MNG_SUPPORT_TRACE
  2298. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY, MNG_LC_END);
  2299. #endif
  2300. return MNG_NOERROR;
  2301. }
  2302. /* ************************************************************************** */
  2303. /* * * */
  2304. /* * Chunk display processing routines * */
  2305. /* * * */
  2306. /* ************************************************************************** */
  2307. #ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
  2308. png_imgtype mng_png_imgtype(mng_uint8 colortype, mng_uint8 bitdepth)
  2309. {
  2310. png_imgtype ret;
  2311. switch (bitdepth)
  2312. {
  2313. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  2314. case 1:
  2315. {
  2316. png_imgtype imgtype[]={png_g1,png_none,png_none,png_idx1};
  2317. ret=imgtype[colortype];
  2318. break;
  2319. }
  2320. case 2:
  2321. {
  2322. png_imgtype imgtype[]={png_g2,png_none,png_none,png_idx2};
  2323. ret=imgtype[colortype];
  2324. break;
  2325. }
  2326. case 4:
  2327. {
  2328. png_imgtype imgtype[]={png_g4,png_none,png_none,png_idx4};
  2329. ret=imgtype[colortype];
  2330. break;
  2331. }
  2332. #endif
  2333. case 8:
  2334. {
  2335. png_imgtype imgtype[]={png_g8,png_none,png_rgb8,png_idx8,png_ga8,
  2336. png_none,png_rgba8};
  2337. ret=imgtype[colortype];
  2338. break;
  2339. }
  2340. #ifndef MNG_NO_16BIT_SUPPORT
  2341. case 16:
  2342. {
  2343. png_imgtype imgtype[]={png_g16,png_none,png_rgb16,png_none,png_ga16,
  2344. png_none,png_rgba16};
  2345. ret=imgtype[colortype];
  2346. break;
  2347. }
  2348. #endif
  2349. default:
  2350. ret=png_none;
  2351. break;
  2352. }
  2353. return (ret);
  2354. }
  2355. #endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
  2356. /* ************************************************************************** */
  2357. mng_retcode mng_process_display_ihdr (mng_datap pData)
  2358. { /* address the current "object" if any */
  2359. mng_imagep pImage = (mng_imagep)pData->pCurrentobj;
  2360. #ifdef MNG_SUPPORT_TRACE
  2361. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IHDR, MNG_LC_START);
  2362. #endif
  2363. if (!pData->bHasDHDR)
  2364. {
  2365. pData->fInitrowproc = MNG_NULL; /* do nothing by default */
  2366. pData->fDisplayrow = MNG_NULL;
  2367. pData->fCorrectrow = MNG_NULL;
  2368. pData->fStorerow = MNG_NULL;
  2369. pData->fProcessrow = MNG_NULL;
  2370. pData->fDifferrow = MNG_NULL;
  2371. pData->pStoreobj = MNG_NULL;
  2372. }
  2373. if (!pData->iBreakpoint) /* not previously broken ? */
  2374. {
  2375. mng_retcode iRetcode = MNG_NOERROR;
  2376. #ifndef MNG_NO_DELTA_PNG
  2377. if (pData->bHasDHDR) /* is a delta-image ? */
  2378. {
  2379. if (pData->iDeltatype == MNG_DELTATYPE_REPLACE)
  2380. iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pDeltaImage,
  2381. pData->iDatawidth, pData->iDataheight,
  2382. pData->iBitdepth, pData->iColortype,
  2383. pData->iCompression, pData->iFilter,
  2384. pData->iInterlace, MNG_TRUE);
  2385. else
  2386. if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
  2387. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
  2388. {
  2389. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iBitdepth;
  2390. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iBitdepth;
  2391. }
  2392. else
  2393. if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
  2394. (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
  2395. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iBitdepth;
  2396. else
  2397. if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
  2398. (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
  2399. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iBitdepth;
  2400. if (!iRetcode)
  2401. { /* process immediately if bitdepth & colortype are equal */
  2402. pData->bDeltaimmediate =
  2403. (mng_bool)((pData->iBitdepth == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iBitdepth ) &&
  2404. (pData->iColortype == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iColortype) );
  2405. /* be sure to reset object 0 */
  2406. iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero,
  2407. pData->iDatawidth, pData->iDataheight,
  2408. pData->iBitdepth, pData->iColortype,
  2409. pData->iCompression, pData->iFilter,
  2410. pData->iInterlace, MNG_TRUE);
  2411. }
  2412. }
  2413. else
  2414. #endif
  2415. {
  2416. if (pImage) /* update object buffer ? */
  2417. iRetcode = mng_reset_object_details (pData, pImage,
  2418. pData->iDatawidth, pData->iDataheight,
  2419. pData->iBitdepth, pData->iColortype,
  2420. pData->iCompression, pData->iFilter,
  2421. pData->iInterlace, MNG_TRUE);
  2422. else
  2423. iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero,
  2424. pData->iDatawidth, pData->iDataheight,
  2425. pData->iBitdepth, pData->iColortype,
  2426. pData->iCompression, pData->iFilter,
  2427. pData->iInterlace, MNG_TRUE);
  2428. }
  2429. if (iRetcode) /* on error bail out */
  2430. return iRetcode;
  2431. }
  2432. #ifndef MNG_NO_DELTA_PNG
  2433. if (!pData->bHasDHDR)
  2434. #endif
  2435. {
  2436. if (pImage) /* real object ? */
  2437. pData->pStoreobj = pImage; /* tell the row routines */
  2438. else /* otherwise use object 0 */
  2439. pData->pStoreobj = pData->pObjzero;
  2440. #if !defined(MNG_INCLUDE_MPNG_PROPOSAL) && !defined(MNG_INCLUDE_ANG_PROPOSAL)
  2441. if ( /* display "on-the-fly" ? */
  2442. #ifndef MNG_SKIPCHUNK_MAGN
  2443. (((mng_imagep)pData->pStoreobj)->iMAGN_MethodX == 0) &&
  2444. (((mng_imagep)pData->pStoreobj)->iMAGN_MethodY == 0) &&
  2445. #endif
  2446. ( (pData->eImagetype == mng_it_png ) ||
  2447. (((mng_imagep)pData->pStoreobj)->bVisible) ) )
  2448. {
  2449. next_layer (pData); /* that's a new layer then ! */
  2450. if (pData->bTimerset) /* timer break ? */
  2451. pData->iBreakpoint = 2;
  2452. else
  2453. {
  2454. pData->iBreakpoint = 0;
  2455. /* anything to display ? */
  2456. if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt))
  2457. set_display_routine (pData); /* then determine display routine */
  2458. }
  2459. }
  2460. #endif
  2461. }
  2462. if (!pData->bTimerset) /* no timer break ? */
  2463. {
  2464. #ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
  2465. pData->fInitrowproc = (mng_fptr)mng_init_rowproc;
  2466. pData->ePng_imgtype=mng_png_imgtype(pData->iColortype,pData->iBitdepth);
  2467. #else
  2468. switch (pData->iColortype) /* determine row initialization routine */
  2469. {
  2470. case 0 : { /* gray */
  2471. switch (pData->iBitdepth)
  2472. {
  2473. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  2474. case 1 : {
  2475. if (!pData->iInterlace)
  2476. pData->fInitrowproc = (mng_fptr)mng_init_g1_ni;
  2477. else
  2478. pData->fInitrowproc = (mng_fptr)mng_init_g1_i;
  2479. break;
  2480. }
  2481. case 2 : {
  2482. if (!pData->iInterlace)
  2483. pData->fInitrowproc = (mng_fptr)mng_init_g2_ni;
  2484. else
  2485. pData->fInitrowproc = (mng_fptr)mng_init_g2_i;
  2486. break;
  2487. }
  2488. case 4 : {
  2489. if (!pData->iInterlace)
  2490. pData->fInitrowproc = (mng_fptr)mng_init_g4_ni;
  2491. else
  2492. pData->fInitrowproc = (mng_fptr)mng_init_g4_i;
  2493. break;
  2494. }
  2495. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  2496. case 8 : {
  2497. if (!pData->iInterlace)
  2498. pData->fInitrowproc = (mng_fptr)mng_init_g8_ni;
  2499. else
  2500. pData->fInitrowproc = (mng_fptr)mng_init_g8_i;
  2501. break;
  2502. }
  2503. #ifndef MNG_NO_16BIT_SUPPORT
  2504. case 16 : {
  2505. if (!pData->iInterlace)
  2506. pData->fInitrowproc = (mng_fptr)mng_init_g16_ni;
  2507. else
  2508. pData->fInitrowproc = (mng_fptr)mng_init_g16_i;
  2509. break;
  2510. }
  2511. #endif
  2512. }
  2513. break;
  2514. }
  2515. case 2 : { /* rgb */
  2516. switch (pData->iBitdepth)
  2517. {
  2518. case 8 : {
  2519. if (!pData->iInterlace)
  2520. pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni;
  2521. else
  2522. pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i;
  2523. break;
  2524. }
  2525. #ifndef MNG_NO_16BIT_SUPPORT
  2526. case 16 : {
  2527. if (!pData->iInterlace)
  2528. pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni;
  2529. else
  2530. pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i;
  2531. break;
  2532. }
  2533. #endif
  2534. }
  2535. break;
  2536. }
  2537. case 3 : { /* indexed */
  2538. switch (pData->iBitdepth)
  2539. {
  2540. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  2541. case 1 : {
  2542. if (!pData->iInterlace)
  2543. pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni;
  2544. else
  2545. pData->fInitrowproc = (mng_fptr)mng_init_idx1_i;
  2546. break;
  2547. }
  2548. case 2 : {
  2549. if (!pData->iInterlace)
  2550. pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni;
  2551. else
  2552. pData->fInitrowproc = (mng_fptr)mng_init_idx2_i;
  2553. break;
  2554. }
  2555. case 4 : {
  2556. if (!pData->iInterlace)
  2557. pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni;
  2558. else
  2559. pData->fInitrowproc = (mng_fptr)mng_init_idx4_i;
  2560. break;
  2561. }
  2562. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  2563. case 8 : {
  2564. if (!pData->iInterlace)
  2565. pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni;
  2566. else
  2567. pData->fInitrowproc = (mng_fptr)mng_init_idx8_i;
  2568. break;
  2569. }
  2570. }
  2571. break;
  2572. }
  2573. case 4 : { /* gray+alpha */
  2574. switch (pData->iBitdepth)
  2575. {
  2576. case 8 : {
  2577. if (!pData->iInterlace)
  2578. pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni;
  2579. else
  2580. pData->fInitrowproc = (mng_fptr)mng_init_ga8_i;
  2581. break;
  2582. }
  2583. #ifndef MNG_NO_16BIT_SUPPORT
  2584. case 16 : {
  2585. if (!pData->iInterlace)
  2586. pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni;
  2587. else
  2588. pData->fInitrowproc = (mng_fptr)mng_init_ga16_i;
  2589. break;
  2590. }
  2591. #endif
  2592. }
  2593. break;
  2594. }
  2595. case 6 : { /* rgb+alpha */
  2596. switch (pData->iBitdepth)
  2597. {
  2598. case 8 : {
  2599. if (!pData->iInterlace)
  2600. pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni;
  2601. else
  2602. pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i;
  2603. break;
  2604. }
  2605. #ifndef MNG_NO_16BIT_SUPPORT
  2606. case 16 : {
  2607. if (!pData->iInterlace)
  2608. pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni;
  2609. else
  2610. pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i;
  2611. break;
  2612. }
  2613. #endif
  2614. }
  2615. break;
  2616. }
  2617. }
  2618. #endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
  2619. pData->iFilterofs = 0; /* determine filter characteristics */
  2620. pData->iLevel0 = 0; /* default levels */
  2621. pData->iLevel1 = 0;
  2622. pData->iLevel2 = 0;
  2623. pData->iLevel3 = 0;
  2624. #ifdef FILTER192 /* leveling & differing ? */
  2625. if (pData->iFilter == MNG_FILTER_DIFFERING)
  2626. {
  2627. switch (pData->iColortype)
  2628. {
  2629. case 0 : {
  2630. if (pData->iBitdepth <= 8)
  2631. pData->iFilterofs = 1;
  2632. else
  2633. pData->iFilterofs = 2;
  2634. break;
  2635. }
  2636. case 2 : {
  2637. if (pData->iBitdepth <= 8)
  2638. pData->iFilterofs = 3;
  2639. else
  2640. pData->iFilterofs = 6;
  2641. break;
  2642. }
  2643. case 3 : {
  2644. pData->iFilterofs = 1;
  2645. break;
  2646. }
  2647. case 4 : {
  2648. if (pData->iBitdepth <= 8)
  2649. pData->iFilterofs = 2;
  2650. else
  2651. pData->iFilterofs = 4;
  2652. break;
  2653. }
  2654. case 6 : {
  2655. if (pData->iBitdepth <= 8)
  2656. pData->iFilterofs = 4;
  2657. else
  2658. pData->iFilterofs = 8;
  2659. break;
  2660. }
  2661. }
  2662. }
  2663. #endif
  2664. #ifdef FILTER193 /* no adaptive filtering ? */
  2665. if (pData->iFilter == MNG_FILTER_NOFILTER)
  2666. pData->iPixelofs = pData->iFilterofs;
  2667. else
  2668. #endif
  2669. pData->iPixelofs = pData->iFilterofs + 1;
  2670. }
  2671. #ifdef MNG_SUPPORT_TRACE
  2672. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IHDR, MNG_LC_END);
  2673. #endif
  2674. return MNG_NOERROR;
  2675. }
  2676. /* ************************************************************************** */
  2677. #ifdef MNG_INCLUDE_MPNG_PROPOSAL
  2678. mng_retcode mng_process_display_mpng (mng_datap pData)
  2679. {
  2680. #ifdef MNG_SUPPORT_TRACE
  2681. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MPNG, MNG_LC_START);
  2682. #endif
  2683. pData->iAlphadepth = 8; /* assume transparency !! */
  2684. if (pData->fProcessheader) /* inform the app (creating the output canvas) ? */
  2685. {
  2686. pData->iWidth = ((mng_mpng_objp)pData->pMPNG)->iFramewidth;
  2687. pData->iHeight = ((mng_mpng_objp)pData->pMPNG)->iFrameheight;
  2688. if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight))
  2689. MNG_ERROR (pData, MNG_APPMISCERROR);
  2690. }
  2691. next_layer (pData); /* first mPNG layer then ! */
  2692. pData->bTimerset = MNG_FALSE;
  2693. pData->iBreakpoint = 0;
  2694. if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt))
  2695. set_display_routine (pData); /* then determine display routine */
  2696. #ifdef MNG_SUPPORT_TRACE
  2697. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MPNG, MNG_LC_END);
  2698. #endif
  2699. return MNG_NOERROR;
  2700. }
  2701. #endif
  2702. /* ************************************************************************** */
  2703. #ifdef MNG_INCLUDE_ANG_PROPOSAL
  2704. mng_retcode mng_process_display_ang (mng_datap pData)
  2705. {
  2706. #ifdef MNG_SUPPORT_TRACE
  2707. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_ANG, MNG_LC_START);
  2708. #endif
  2709. if (pData->fProcessheader) /* inform the app (creating the output canvas) ? */
  2710. {
  2711. if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight))
  2712. MNG_ERROR (pData, MNG_APPMISCERROR);
  2713. }
  2714. next_layer (pData); /* first mPNG layer then ! */
  2715. pData->bTimerset = MNG_FALSE;
  2716. pData->iBreakpoint = 0;
  2717. if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt))
  2718. set_display_routine (pData); /* then determine display routine */
  2719. #ifdef MNG_SUPPORT_TRACE
  2720. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_ANG, MNG_LC_END);
  2721. #endif
  2722. return MNG_NOERROR;
  2723. }
  2724. #endif
  2725. /* ************************************************************************** */
  2726. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  2727. mng_retcode mng_process_display_idat (mng_datap pData,
  2728. mng_uint32 iRawlen,
  2729. mng_uint8p pRawdata)
  2730. #else
  2731. mng_retcode mng_process_display_idat (mng_datap pData)
  2732. #endif
  2733. {
  2734. mng_retcode iRetcode = MNG_NOERROR;
  2735. #ifdef MNG_SUPPORT_TRACE
  2736. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IDAT, MNG_LC_START);
  2737. #endif
  2738. #if defined(MNG_INCLUDE_MPNG_PROPOSAL) || defined(MNG_INCLUDE_ANG_PROPOSAL)
  2739. if ((pData->eImagetype == mng_it_png) && (pData->iLayerseq <= 0))
  2740. {
  2741. if (pData->fProcessheader) /* inform the app (creating the output canvas) ? */
  2742. if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight))
  2743. MNG_ERROR (pData, MNG_APPMISCERROR);
  2744. next_layer (pData); /* first regular PNG layer then ! */
  2745. pData->bTimerset = MNG_FALSE;
  2746. pData->iBreakpoint = 0;
  2747. if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt))
  2748. set_display_routine (pData); /* then determine display routine */
  2749. }
  2750. #endif
  2751. if (pData->bRestorebkgd) /* need to restore the background ? */
  2752. {
  2753. pData->bRestorebkgd = MNG_FALSE;
  2754. iRetcode = load_bkgdlayer (pData);
  2755. if (iRetcode) /* on error bail out */
  2756. return iRetcode;
  2757. pData->iLayerseq++; /* and it counts as a layer then ! */
  2758. }
  2759. if (pData->fInitrowproc) /* need to initialize row processing? */
  2760. {
  2761. iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData);
  2762. pData->fInitrowproc = MNG_NULL; /* only call this once !!! */
  2763. }
  2764. if ((!iRetcode) && (!pData->bInflating))
  2765. /* initialize inflate */
  2766. iRetcode = mngzlib_inflateinit (pData);
  2767. if (!iRetcode) /* all ok? then inflate, my man */
  2768. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  2769. iRetcode = mngzlib_inflaterows (pData, iRawlen, pRawdata);
  2770. #else
  2771. iRetcode = mngzlib_inflaterows (pData, pData->iRawlen, pData->pRawdata);
  2772. #endif
  2773. if (iRetcode) /* on error bail out */
  2774. return iRetcode;
  2775. #ifdef MNG_SUPPORT_TRACE
  2776. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IDAT, MNG_LC_END);
  2777. #endif
  2778. return MNG_NOERROR;
  2779. }
  2780. /* ************************************************************************** */
  2781. mng_retcode mng_process_display_iend (mng_datap pData)
  2782. {
  2783. mng_retcode iRetcode, iRetcode2;
  2784. mng_bool bDodisplay = MNG_FALSE;
  2785. mng_bool bMagnify = MNG_FALSE;
  2786. mng_bool bCleanup = (mng_bool)(pData->iBreakpoint != 0);
  2787. #ifdef MNG_SUPPORT_TRACE
  2788. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IEND, MNG_LC_START);
  2789. #endif
  2790. #ifdef MNG_INCLUDE_JNG /* progressive+alpha JNG can be displayed now */
  2791. if ( (pData->bHasJHDR ) &&
  2792. ( (pData->bJPEGprogressive) || (pData->bJPEGprogressive2)) &&
  2793. ( (pData->eImagetype == mng_it_jng ) ||
  2794. (((mng_imagep)pData->pStoreobj)->bVisible) ) &&
  2795. ( (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA ) ||
  2796. (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) ) )
  2797. bDodisplay = MNG_TRUE;
  2798. #endif
  2799. #ifndef MNG_SKIPCHUNK_MAGN
  2800. if ( (pData->pStoreobj) && /* on-the-fly magnification ? */
  2801. ( (((mng_imagep)pData->pStoreobj)->iMAGN_MethodX) ||
  2802. (((mng_imagep)pData->pStoreobj)->iMAGN_MethodY) ) )
  2803. bMagnify = MNG_TRUE;
  2804. #endif
  2805. if ((pData->bHasBASI) || /* was it a BASI stream */
  2806. (bDodisplay) || /* or should we display the JNG */
  2807. #ifndef MNG_SKIPCHUNK_MAGN
  2808. (bMagnify) || /* or should we magnify it */
  2809. #endif
  2810. /* or did we get broken here last time ? */
  2811. ((pData->iBreakpoint) && (pData->iBreakpoint != 8)))
  2812. {
  2813. mng_imagep pImage = (mng_imagep)pData->pCurrentobj;
  2814. if (!pImage) /* or was it object 0 ? */
  2815. pImage = (mng_imagep)pData->pObjzero;
  2816. /* display it now then ? */
  2817. if ((pImage->bVisible) && (pImage->bViewable))
  2818. { /* ok, so do it */
  2819. iRetcode = mng_display_image (pData, pImage, bDodisplay);
  2820. if (iRetcode) /* on error bail out */
  2821. return iRetcode;
  2822. if (pData->bTimerset) /* timer break ? */
  2823. pData->iBreakpoint = 6;
  2824. }
  2825. }
  2826. #ifndef MNG_NO_DELTA_PNG
  2827. else
  2828. if ((pData->bHasDHDR) || /* was it a DHDR stream */
  2829. (pData->iBreakpoint == 8)) /* or did we get broken here last time ? */
  2830. {
  2831. mng_imagep pImage = (mng_imagep)pData->pDeltaImage;
  2832. if (!pData->iBreakpoint)
  2833. { /* perform the delta operations needed */
  2834. iRetcode = mng_execute_delta_image (pData, pImage, (mng_imagep)pData->pObjzero);
  2835. if (iRetcode) /* on error bail out */
  2836. return iRetcode;
  2837. }
  2838. /* display it now then ? */
  2839. if ((pImage->bVisible) && (pImage->bViewable))
  2840. { /* ok, so do it */
  2841. iRetcode = mng_display_image (pData, pImage, MNG_FALSE);
  2842. if (iRetcode) /* on error bail out */
  2843. return iRetcode;
  2844. if (pData->bTimerset) /* timer break ? */
  2845. pData->iBreakpoint = 8;
  2846. }
  2847. }
  2848. #endif
  2849. if (!pData->bTimerset) /* can we continue ? */
  2850. {
  2851. pData->iBreakpoint = 0; /* clear this flag now ! */
  2852. #ifdef MNG_INCLUDE_MPNG_PROPOSAL
  2853. if (pData->eImagetype == mng_it_mpng)
  2854. {
  2855. pData->pCurraniobj = pData->pFirstaniobj;
  2856. } else
  2857. #endif
  2858. #ifdef MNG_INCLUDE_ANG_PROPOSAL
  2859. if (pData->eImagetype == mng_it_ang)
  2860. {
  2861. pData->pCurraniobj = pData->pFirstaniobj;
  2862. } else
  2863. #endif
  2864. { /* cleanup object 0 */
  2865. mng_reset_object_details (pData, (mng_imagep)pData->pObjzero,
  2866. 0, 0, 0, 0, 0, 0, 0, MNG_TRUE);
  2867. }
  2868. if (pData->bInflating) /* if we've been inflating */
  2869. { /* cleanup row-processing, */
  2870. iRetcode = mng_cleanup_rowproc (pData);
  2871. /* also cleanup inflate! */
  2872. iRetcode2 = mngzlib_inflatefree (pData);
  2873. if (iRetcode) /* on error bail out */
  2874. return iRetcode;
  2875. if (iRetcode2)
  2876. return iRetcode2;
  2877. }
  2878. #ifdef MNG_INCLUDE_JNG
  2879. if (pData->bJPEGdecompress) /* if we've been decompressing JDAT */
  2880. { /* cleanup row-processing, */
  2881. iRetcode = mng_cleanup_rowproc (pData);
  2882. /* also cleanup decompress! */
  2883. iRetcode2 = mngjpeg_decompressfree (pData);
  2884. if (iRetcode) /* on error bail out */
  2885. return iRetcode;
  2886. if (iRetcode2)
  2887. return iRetcode2;
  2888. }
  2889. if (pData->bJPEGdecompress2) /* if we've been decompressing JDAA */
  2890. { /* cleanup row-processing, */
  2891. iRetcode = mng_cleanup_rowproc (pData);
  2892. /* also cleanup decompress! */
  2893. iRetcode2 = mngjpeg_decompressfree2 (pData);
  2894. if (iRetcode) /* on error bail out */
  2895. return iRetcode;
  2896. if (iRetcode2)
  2897. return iRetcode2;
  2898. }
  2899. #endif
  2900. if (bCleanup) /* if we got broken last time we need to cleanup */
  2901. {
  2902. pData->bHasIHDR = MNG_FALSE; /* IEND signals the end for most ... */
  2903. pData->bHasBASI = MNG_FALSE;
  2904. pData->bHasDHDR = MNG_FALSE;
  2905. #ifdef MNG_INCLUDE_JNG
  2906. pData->bHasJHDR = MNG_FALSE;
  2907. pData->bHasJSEP = MNG_FALSE;
  2908. pData->bHasJDAA = MNG_FALSE;
  2909. pData->bHasJDAT = MNG_FALSE;
  2910. #endif
  2911. pData->bHasPLTE = MNG_FALSE;
  2912. pData->bHasTRNS = MNG_FALSE;
  2913. pData->bHasGAMA = MNG_FALSE;
  2914. pData->bHasCHRM = MNG_FALSE;
  2915. pData->bHasSRGB = MNG_FALSE;
  2916. pData->bHasICCP = MNG_FALSE;
  2917. pData->bHasBKGD = MNG_FALSE;
  2918. pData->bHasIDAT = MNG_FALSE;
  2919. }
  2920. /* if the image was displayed on the fly, */
  2921. /* we'll have to make the app refresh */
  2922. if ((pData->eImagetype != mng_it_mng) && (pData->fDisplayrow))
  2923. pData->bNeedrefresh = MNG_TRUE;
  2924. }
  2925. #ifdef MNG_SUPPORT_TRACE
  2926. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IEND, MNG_LC_END);
  2927. #endif
  2928. return MNG_NOERROR;
  2929. }
  2930. /* ************************************************************************** */
  2931. /* change in the MNG spec with regards to TERM delay & interframe_delay
  2932. as proposed by Adam M. Costello (option 4) and finalized by official vote
  2933. during december 2002 / check the 'mng-list' archives for more details */
  2934. mng_retcode mng_process_display_mend (mng_datap pData)
  2935. {
  2936. #ifdef MNG_SUPPORT_TRACE
  2937. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_START);
  2938. #endif
  2939. #ifdef MNG_SUPPORT_DYNAMICMNG
  2940. if (pData->bStopafterseek) /* need to stop after this ? */
  2941. {
  2942. pData->bFreezing = MNG_TRUE; /* stop processing on this one */
  2943. pData->bRunningevent = MNG_FALSE;
  2944. pData->bStopafterseek = MNG_FALSE;
  2945. pData->bNeedrefresh = MNG_TRUE; /* make sure the last bit is displayed ! */
  2946. }
  2947. #endif
  2948. #ifndef MNG_SKIPCHUNK_TERM
  2949. /* TERM processed ? */
  2950. if ((pData->bDisplaying) && (pData->bRunning) &&
  2951. (pData->bHasTERM) && (pData->pTermaniobj))
  2952. {
  2953. mng_retcode iRetcode;
  2954. mng_ani_termp pTERM;
  2955. /* get the right animation object ! */
  2956. pTERM = (mng_ani_termp)pData->pTermaniobj;
  2957. pData->iIterations++; /* increase iteration count */
  2958. switch (pTERM->iTermaction) /* determine what to do! */
  2959. {
  2960. case 0 : { /* show last frame indefinitly */
  2961. break; /* piece of cake, that is... */
  2962. }
  2963. case 1 : { /* cease displaying anything */
  2964. /* max(1, TERM delay, interframe_delay) */
  2965. #ifndef MNG_SKIPCHUNK_FRAM
  2966. if (pTERM->iDelay > pData->iFramedelay)
  2967. pData->iFramedelay = pTERM->iDelay;
  2968. if (!pData->iFramedelay)
  2969. pData->iFramedelay = 1;
  2970. #endif
  2971. iRetcode = interframe_delay (pData);
  2972. /* no interframe_delay? then fake it */
  2973. if ((!iRetcode) && (!pData->bTimerset))
  2974. iRetcode = set_delay (pData, 1);
  2975. if (iRetcode)
  2976. return iRetcode;
  2977. pData->iBreakpoint = 10;
  2978. break;
  2979. }
  2980. case 2 : { /* show first image after TERM */
  2981. iRetcode = restore_state (pData);
  2982. if (iRetcode) /* on error bail out */
  2983. return iRetcode;
  2984. /* notify the app ? */
  2985. if (pData->fProcessmend)
  2986. if (!pData->fProcessmend ((mng_handle)pData, pData->iIterations, 0))
  2987. MNG_ERROR (pData, MNG_APPMISCERROR);
  2988. /* show first frame after TERM chunk */
  2989. pData->pCurraniobj = pTERM;
  2990. pData->bOnlyfirstframe = MNG_TRUE;
  2991. pData->iFramesafterTERM = 0;
  2992. /* max(1, TERM delay, interframe_delay) */
  2993. #ifndef MNG_SKIPCHUNK_FRAM
  2994. if (pTERM->iDelay > pData->iFramedelay)
  2995. pData->iFramedelay = pTERM->iDelay;
  2996. if (!pData->iFramedelay)
  2997. pData->iFramedelay = 1;
  2998. #endif
  2999. break;
  3000. }
  3001. case 3 : { /* repeat */
  3002. if ((pTERM->iItermax) && (pTERM->iItermax < 0x7FFFFFFF))
  3003. pTERM->iItermax--;
  3004. if (pTERM->iItermax) /* go back to TERM ? */
  3005. { /* restore to initial or SAVE state */
  3006. iRetcode = restore_state (pData);
  3007. if (iRetcode) /* on error bail out */
  3008. return iRetcode;
  3009. /* notify the app ? */
  3010. if (pData->fProcessmend)
  3011. if (!pData->fProcessmend ((mng_handle)pData,
  3012. pData->iIterations, pTERM->iItermax))
  3013. MNG_ERROR (pData, MNG_APPMISCERROR);
  3014. /* restart from TERM chunk */
  3015. pData->pCurraniobj = pTERM;
  3016. if (pTERM->iDelay) /* set the delay (?) */
  3017. {
  3018. /* max(1, TERM delay, interframe_delay) */
  3019. #ifndef MNG_SKIPCHUNK_FRAM
  3020. if (pTERM->iDelay > pData->iFramedelay)
  3021. pData->iFramedelay = pTERM->iDelay;
  3022. if (!pData->iFramedelay)
  3023. pData->iFramedelay = 1;
  3024. #endif
  3025. pData->bNeedrefresh = MNG_TRUE;
  3026. }
  3027. }
  3028. else
  3029. {
  3030. switch (pTERM->iIteraction)
  3031. {
  3032. case 0 : { /* show last frame indefinitly */
  3033. break; /* piece of cake, that is... */
  3034. }
  3035. case 1 : { /* cease displaying anything */
  3036. /* max(1, TERM delay, interframe_delay) */
  3037. #ifndef MNG_SKIPCHUNK_FRAM
  3038. if (pTERM->iDelay > pData->iFramedelay)
  3039. pData->iFramedelay = pTERM->iDelay;
  3040. if (!pData->iFramedelay)
  3041. pData->iFramedelay = 1;
  3042. #endif
  3043. iRetcode = interframe_delay (pData);
  3044. /* no interframe_delay? then fake it */
  3045. if ((!iRetcode) && (!pData->bTimerset))
  3046. iRetcode = set_delay (pData, 1);
  3047. if (iRetcode)
  3048. return iRetcode;
  3049. pData->iBreakpoint = 10;
  3050. break;
  3051. }
  3052. case 2 : { /* show first image after TERM */
  3053. iRetcode = restore_state (pData);
  3054. /* on error bail out */
  3055. if (iRetcode)
  3056. return iRetcode;
  3057. /* notify the app ? */
  3058. if (pData->fProcessmend)
  3059. if (!pData->fProcessmend ((mng_handle)pData,
  3060. pData->iIterations, 0))
  3061. MNG_ERROR (pData, MNG_APPMISCERROR);
  3062. /* show first frame after TERM chunk */
  3063. pData->pCurraniobj = pTERM;
  3064. pData->bOnlyfirstframe = MNG_TRUE;
  3065. pData->iFramesafterTERM = 0;
  3066. /* max(1, TERM delay, interframe_delay) */
  3067. #ifndef MNG_SKIPCHUNK_FRAM
  3068. if (pTERM->iDelay > pData->iFramedelay)
  3069. pData->iFramedelay = pTERM->iDelay;
  3070. if (!pData->iFramedelay)
  3071. pData->iFramedelay = 1;
  3072. #endif
  3073. break;
  3074. }
  3075. }
  3076. }
  3077. break;
  3078. }
  3079. }
  3080. }
  3081. #endif /* MNG_SKIPCHUNK_TERM */
  3082. /* just reading ? */
  3083. if ((!pData->bDisplaying) && (pData->bReading))
  3084. if (pData->fProcessmend) /* inform the app ? */
  3085. if (!pData->fProcessmend ((mng_handle)pData, 0, 0))
  3086. MNG_ERROR (pData, MNG_APPMISCERROR);
  3087. if (!pData->pCurraniobj) /* always let the app refresh at the end ! */
  3088. pData->bNeedrefresh = MNG_TRUE;
  3089. #ifdef MNG_SUPPORT_TRACE
  3090. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_END);
  3091. #endif
  3092. return MNG_NOERROR;
  3093. }
  3094. /* ************************************************************************** */
  3095. mng_retcode mng_process_display_mend2 (mng_datap pData)
  3096. {
  3097. #ifdef MNG_SUPPORT_TRACE
  3098. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_START);
  3099. #endif
  3100. #ifndef MNG_SKIPCHUNK_FRAM
  3101. pData->bFrameclipping = MNG_FALSE; /* nothing to do but restore the app background */
  3102. #endif
  3103. load_bkgdlayer (pData);
  3104. #ifdef MNG_SUPPORT_TRACE
  3105. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_END);
  3106. #endif
  3107. return MNG_NOERROR;
  3108. }
  3109. /* ************************************************************************** */
  3110. #ifndef MNG_SKIPCHUNK_DEFI
  3111. mng_retcode mng_process_display_defi (mng_datap pData)
  3112. {
  3113. mng_imagep pImage;
  3114. #ifdef MNG_SUPPORT_TRACE
  3115. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DEFI, MNG_LC_START);
  3116. #endif
  3117. if (!pData->iDEFIobjectid) /* object id=0 ? */
  3118. {
  3119. pImage = (mng_imagep)pData->pObjzero;
  3120. if (pData->bDEFIhasdonotshow)
  3121. pImage->bVisible = (mng_bool)(pData->iDEFIdonotshow == 0);
  3122. if (pData->bDEFIhasloca)
  3123. {
  3124. pImage->iPosx = pData->iDEFIlocax;
  3125. pImage->iPosy = pData->iDEFIlocay;
  3126. }
  3127. if (pData->bDEFIhasclip)
  3128. {
  3129. pImage->bClipped = pData->bDEFIhasclip;
  3130. pImage->iClipl = pData->iDEFIclipl;
  3131. pImage->iClipr = pData->iDEFIclipr;
  3132. pImage->iClipt = pData->iDEFIclipt;
  3133. pImage->iClipb = pData->iDEFIclipb;
  3134. }
  3135. pData->pCurrentobj = 0; /* not a real object ! */
  3136. }
  3137. else
  3138. { /* already exists ? */
  3139. pImage = (mng_imagep)mng_find_imageobject (pData, pData->iDEFIobjectid);
  3140. if (!pImage) /* if not; create new */
  3141. {
  3142. mng_retcode iRetcode = mng_create_imageobject (pData, pData->iDEFIobjectid,
  3143. (mng_bool)(pData->iDEFIconcrete == 1),
  3144. (mng_bool)(pData->iDEFIdonotshow == 0),
  3145. MNG_FALSE, 0, 0, 0, 0, 0, 0, 0,
  3146. pData->iDEFIlocax, pData->iDEFIlocay,
  3147. pData->bDEFIhasclip,
  3148. pData->iDEFIclipl, pData->iDEFIclipr,
  3149. pData->iDEFIclipt, pData->iDEFIclipb,
  3150. &pImage);
  3151. if (iRetcode) /* on error bail out */
  3152. return iRetcode;
  3153. }
  3154. else
  3155. { /* exists; then set new info */
  3156. if (pData->bDEFIhasdonotshow)
  3157. pImage->bVisible = (mng_bool)(pData->iDEFIdonotshow == 0);
  3158. pImage->bViewable = MNG_FALSE;
  3159. if (pData->bDEFIhasloca)
  3160. {
  3161. pImage->iPosx = pData->iDEFIlocax;
  3162. pImage->iPosy = pData->iDEFIlocay;
  3163. }
  3164. if (pData->bDEFIhasclip)
  3165. {
  3166. pImage->bClipped = pData->bDEFIhasclip;
  3167. pImage->iClipl = pData->iDEFIclipl;
  3168. pImage->iClipr = pData->iDEFIclipr;
  3169. pImage->iClipt = pData->iDEFIclipt;
  3170. pImage->iClipb = pData->iDEFIclipb;
  3171. }
  3172. if (pData->bDEFIhasconcrete)
  3173. pImage->pImgbuf->bConcrete = (mng_bool)(pData->iDEFIconcrete == 1);
  3174. }
  3175. pData->pCurrentobj = pImage; /* others may want to know this */
  3176. }
  3177. #ifdef MNG_SUPPORT_TRACE
  3178. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DEFI, MNG_LC_END);
  3179. #endif
  3180. return MNG_NOERROR;
  3181. }
  3182. #endif
  3183. /* ************************************************************************** */
  3184. #ifndef MNG_SKIPCHUNK_BASI
  3185. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3186. mng_retcode mng_process_display_basi (mng_datap pData,
  3187. mng_uint16 iRed,
  3188. mng_uint16 iGreen,
  3189. mng_uint16 iBlue,
  3190. mng_bool bHasalpha,
  3191. mng_uint16 iAlpha,
  3192. mng_uint8 iViewable)
  3193. #else
  3194. mng_retcode mng_process_display_basi (mng_datap pData)
  3195. #endif
  3196. { /* address the current "object" if any */
  3197. mng_imagep pImage = (mng_imagep)pData->pCurrentobj;
  3198. mng_uint8p pWork;
  3199. mng_uint32 iX;
  3200. mng_imagedatap pBuf;
  3201. mng_retcode iRetcode;
  3202. #ifdef MNG_SUPPORT_TRACE
  3203. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_BASI, MNG_LC_START);
  3204. #endif
  3205. if (!pImage) /* or is it an "on-the-fly" image ? */
  3206. pImage = (mng_imagep)pData->pObjzero;
  3207. /* address the object-buffer */
  3208. pBuf = pImage->pImgbuf;
  3209. pData->fDisplayrow = MNG_NULL; /* do nothing by default */
  3210. pData->fCorrectrow = MNG_NULL;
  3211. pData->fStorerow = MNG_NULL;
  3212. pData->fProcessrow = MNG_NULL;
  3213. /* set parms now that they're known */
  3214. iRetcode = mng_reset_object_details (pData, pImage, pData->iDatawidth,
  3215. pData->iDataheight, pData->iBitdepth,
  3216. pData->iColortype, pData->iCompression,
  3217. pData->iFilter, pData->iInterlace, MNG_FALSE);
  3218. if (iRetcode) /* on error bail out */
  3219. return iRetcode;
  3220. /* save the viewable flag */
  3221. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3222. pImage->bViewable = (mng_bool)(iViewable == 1);
  3223. #else
  3224. pImage->bViewable = (mng_bool)(pData->iBASIviewable == 1);
  3225. #endif
  3226. pBuf->bViewable = pImage->bViewable;
  3227. pData->pStoreobj = pImage; /* let row-routines know which object */
  3228. pWork = pBuf->pImgdata; /* fill the object-buffer with the specified
  3229. "color" sample */
  3230. switch (pData->iColortype) /* depending on color_type & bit_depth */
  3231. {
  3232. case 0 : { /* gray */
  3233. #ifndef MNG_NO_16BIT_SUPPORT
  3234. if (pData->iBitdepth == 16)
  3235. {
  3236. #ifdef MNG_DECREMENT_LOOPS
  3237. for (iX = pData->iDatawidth * pData->iDataheight;
  3238. iX > 0;iX--)
  3239. #else
  3240. for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
  3241. #endif
  3242. {
  3243. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3244. mng_put_uint16 (pWork, iRed);
  3245. #else
  3246. mng_put_uint16 (pWork, pData->iBASIred);
  3247. #endif
  3248. pWork += 2;
  3249. }
  3250. }
  3251. else
  3252. #endif
  3253. {
  3254. #ifdef MNG_DECREMENT_LOOPS
  3255. for (iX = pData->iDatawidth * pData->iDataheight;
  3256. iX > 0;iX--)
  3257. #else
  3258. for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
  3259. #endif
  3260. {
  3261. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3262. *pWork = (mng_uint8)iRed;
  3263. #else
  3264. *pWork = (mng_uint8)pData->iBASIred;
  3265. #endif
  3266. pWork++;
  3267. }
  3268. }
  3269. /* force tRNS ? */
  3270. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3271. if ((bHasalpha) && (!iAlpha))
  3272. #else
  3273. if ((pData->bBASIhasalpha) && (!pData->iBASIalpha))
  3274. #endif
  3275. {
  3276. pBuf->bHasTRNS = MNG_TRUE;
  3277. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3278. pBuf->iTRNSgray = iRed;
  3279. #else
  3280. pBuf->iTRNSgray = pData->iBASIred;
  3281. #endif
  3282. }
  3283. break;
  3284. }
  3285. case 2 : { /* rgb */
  3286. #ifndef MNG_NO_16BIT_SUPPORT
  3287. if (pData->iBitdepth == 16)
  3288. {
  3289. #ifdef MNG_DECREMENT_LOOPS
  3290. for (iX = pData->iDatawidth * pData->iDataheight;
  3291. iX > 0;iX--)
  3292. #else
  3293. for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
  3294. #endif
  3295. {
  3296. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3297. mng_put_uint16 (pWork, iRed );
  3298. mng_put_uint16 (pWork+2, iGreen);
  3299. mng_put_uint16 (pWork+4, iBlue );
  3300. #else
  3301. mng_put_uint16 (pWork, pData->iBASIred );
  3302. mng_put_uint16 (pWork+2, pData->iBASIgreen);
  3303. mng_put_uint16 (pWork+4, pData->iBASIblue );
  3304. #endif
  3305. pWork += 6;
  3306. }
  3307. }
  3308. else
  3309. #endif
  3310. {
  3311. #ifdef MNG_DECREMENT_LOOPS
  3312. for (iX = pData->iDatawidth * pData->iDataheight;
  3313. iX > 0;iX--)
  3314. #else
  3315. for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
  3316. #endif
  3317. {
  3318. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3319. *pWork = (mng_uint8)iRed;
  3320. *(pWork+1) = (mng_uint8)iGreen;
  3321. *(pWork+2) = (mng_uint8)iBlue;
  3322. #else
  3323. *pWork = (mng_uint8)pData->iBASIred;
  3324. *(pWork+1) = (mng_uint8)pData->iBASIgreen;
  3325. *(pWork+2) = (mng_uint8)pData->iBASIblue;
  3326. #endif
  3327. pWork += 3;
  3328. }
  3329. }
  3330. /* force tRNS ? */
  3331. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3332. if ((bHasalpha) && (!iAlpha))
  3333. #else
  3334. if ((pData->bBASIhasalpha) && (!pData->iBASIalpha))
  3335. #endif
  3336. {
  3337. pBuf->bHasTRNS = MNG_TRUE;
  3338. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3339. pBuf->iTRNSred = iRed;
  3340. pBuf->iTRNSgreen = iGreen;
  3341. pBuf->iTRNSblue = iBlue;
  3342. #else
  3343. pBuf->iTRNSred = pData->iBASIred;
  3344. pBuf->iTRNSgreen = pData->iBASIgreen;
  3345. pBuf->iTRNSblue = pData->iBASIblue;
  3346. #endif
  3347. }
  3348. break;
  3349. }
  3350. case 3 : { /* indexed */
  3351. pBuf->bHasPLTE = MNG_TRUE;
  3352. switch (pData->iBitdepth)
  3353. {
  3354. case 1 : { pBuf->iPLTEcount = 2; break; }
  3355. case 2 : { pBuf->iPLTEcount = 4; break; }
  3356. case 4 : { pBuf->iPLTEcount = 16; break; }
  3357. case 8 : { pBuf->iPLTEcount = 256; break; }
  3358. default : { pBuf->iPLTEcount = 1; break; }
  3359. }
  3360. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3361. pBuf->aPLTEentries [0].iRed = (mng_uint8)iRed;
  3362. pBuf->aPLTEentries [0].iGreen = (mng_uint8)iGreen;
  3363. pBuf->aPLTEentries [0].iBlue = (mng_uint8)iBlue;
  3364. #else
  3365. pBuf->aPLTEentries [0].iRed = (mng_uint8)pData->iBASIred;
  3366. pBuf->aPLTEentries [0].iGreen = (mng_uint8)pData->iBASIgreen;
  3367. pBuf->aPLTEentries [0].iBlue = (mng_uint8)pData->iBASIblue;
  3368. #endif
  3369. for (iX = 1; iX < pBuf->iPLTEcount; iX++)
  3370. {
  3371. pBuf->aPLTEentries [iX].iRed = 0;
  3372. pBuf->aPLTEentries [iX].iGreen = 0;
  3373. pBuf->aPLTEentries [iX].iBlue = 0;
  3374. }
  3375. /* force tRNS ? */
  3376. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3377. if ((bHasalpha) && (iAlpha < 255))
  3378. #else
  3379. if ((pData->bBASIhasalpha) && (pData->iBASIalpha < 255))
  3380. #endif
  3381. {
  3382. pBuf->bHasTRNS = MNG_TRUE;
  3383. pBuf->iTRNScount = 1;
  3384. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3385. pBuf->aTRNSentries [0] = (mng_uint8)iAlpha;
  3386. #else
  3387. pBuf->aTRNSentries [0] = (mng_uint8)pData->iBASIalpha;
  3388. #endif
  3389. }
  3390. break;
  3391. }
  3392. case 4 : { /* gray+alpha */
  3393. #ifndef MNG_NO_16BIT_SUPPORT
  3394. if (pData->iBitdepth == 16)
  3395. {
  3396. #ifdef MNG_DECREMENT_LOOPS
  3397. for (iX = pData->iDatawidth * pData->iDataheight;
  3398. iX > 0;iX--)
  3399. #else
  3400. for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
  3401. #endif
  3402. {
  3403. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3404. mng_put_uint16 (pWork, iRed);
  3405. mng_put_uint16 (pWork+2, iAlpha);
  3406. #else
  3407. mng_put_uint16 (pWork, pData->iBASIred);
  3408. mng_put_uint16 (pWork+2, pData->iBASIalpha);
  3409. #endif
  3410. pWork += 4;
  3411. }
  3412. }
  3413. else
  3414. #endif
  3415. {
  3416. #ifdef MNG_DECREMENT_LOOPS
  3417. for (iX = pData->iDatawidth * pData->iDataheight;
  3418. iX > 0;iX--)
  3419. #else
  3420. for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
  3421. #endif
  3422. {
  3423. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3424. *pWork = (mng_uint8)iRed;
  3425. *(pWork+1) = (mng_uint8)iAlpha;
  3426. #else
  3427. *pWork = (mng_uint8)pData->iBASIred;
  3428. *(pWork+1) = (mng_uint8)pData->iBASIalpha;
  3429. #endif
  3430. pWork += 2;
  3431. }
  3432. }
  3433. break;
  3434. }
  3435. case 6 : { /* rgb+alpha */
  3436. #ifndef MNG_NO_16BIT_SUPPORT
  3437. if (pData->iBitdepth == 16)
  3438. {
  3439. #ifdef MNG_DECREMENT_LOOPS
  3440. for (iX = pData->iDatawidth * pData->iDataheight;
  3441. iX > 0;iX--)
  3442. #else
  3443. for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
  3444. #endif
  3445. {
  3446. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3447. mng_put_uint16 (pWork, iRed);
  3448. mng_put_uint16 (pWork+2, iGreen);
  3449. mng_put_uint16 (pWork+4, iBlue);
  3450. mng_put_uint16 (pWork+6, iAlpha);
  3451. #else
  3452. mng_put_uint16 (pWork, pData->iBASIred);
  3453. mng_put_uint16 (pWork+2, pData->iBASIgreen);
  3454. mng_put_uint16 (pWork+4, pData->iBASIblue);
  3455. mng_put_uint16 (pWork+6, pData->iBASIalpha);
  3456. #endif
  3457. pWork += 8;
  3458. }
  3459. }
  3460. else
  3461. #endif
  3462. {
  3463. #ifdef MNG_DECREMENT_LOOPS
  3464. for (iX = pData->iDatawidth * pData->iDataheight;
  3465. iX > 0;iX--)
  3466. #else
  3467. for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
  3468. #endif
  3469. {
  3470. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3471. *pWork = (mng_uint8)iRed;
  3472. *(pWork+1) = (mng_uint8)iGreen;
  3473. *(pWork+2) = (mng_uint8)iBlue;
  3474. *(pWork+3) = (mng_uint8)iAlpha;
  3475. #else
  3476. *pWork = (mng_uint8)pData->iBASIred;
  3477. *(pWork+1) = (mng_uint8)pData->iBASIgreen;
  3478. *(pWork+2) = (mng_uint8)pData->iBASIblue;
  3479. *(pWork+3) = (mng_uint8)pData->iBASIalpha;
  3480. #endif
  3481. pWork += 4;
  3482. }
  3483. }
  3484. break;
  3485. }
  3486. }
  3487. #ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
  3488. pData->fInitrowproc = (mng_fptr)mng_init_rowproc;
  3489. pData->ePng_imgtype=mng_png_imgtype(pData->iColortype,pData->iBitdepth);
  3490. #else
  3491. switch (pData->iColortype) /* determine row initialization routine */
  3492. { /* just to accomodate IDAT if it arrives */
  3493. case 0 : { /* gray */
  3494. switch (pData->iBitdepth)
  3495. {
  3496. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  3497. case 1 : {
  3498. if (!pData->iInterlace)
  3499. pData->fInitrowproc = (mng_fptr)mng_init_g1_ni;
  3500. else
  3501. pData->fInitrowproc = (mng_fptr)mng_init_g1_i;
  3502. break;
  3503. }
  3504. case 2 : {
  3505. if (!pData->iInterlace)
  3506. pData->fInitrowproc = (mng_fptr)mng_init_g2_ni;
  3507. else
  3508. pData->fInitrowproc = (mng_fptr)mng_init_g2_i;
  3509. break;
  3510. }
  3511. case 4 : {
  3512. if (!pData->iInterlace)
  3513. pData->fInitrowproc = (mng_fptr)mng_init_g4_ni;
  3514. else
  3515. pData->fInitrowproc = (mng_fptr)mng_init_g4_i;
  3516. break;
  3517. }
  3518. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  3519. case 8 : {
  3520. if (!pData->iInterlace)
  3521. pData->fInitrowproc = (mng_fptr)mng_init_g8_ni;
  3522. else
  3523. pData->fInitrowproc = (mng_fptr)mng_init_g8_i;
  3524. break;
  3525. }
  3526. #ifndef MNG_NO_16BIT_SUPPORT
  3527. case 16 : {
  3528. if (!pData->iInterlace)
  3529. pData->fInitrowproc = (mng_fptr)mng_init_g16_ni;
  3530. else
  3531. pData->fInitrowproc = (mng_fptr)mng_init_g16_i;
  3532. break;
  3533. }
  3534. #endif
  3535. }
  3536. break;
  3537. }
  3538. case 2 : { /* rgb */
  3539. switch (pData->iBitdepth)
  3540. {
  3541. case 8 : {
  3542. if (!pData->iInterlace)
  3543. pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni;
  3544. else
  3545. pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i;
  3546. break;
  3547. }
  3548. #ifndef MNG_NO_16BIT_SUPPORT
  3549. case 16 : {
  3550. if (!pData->iInterlace)
  3551. pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni;
  3552. else
  3553. pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i;
  3554. break;
  3555. }
  3556. #endif
  3557. }
  3558. break;
  3559. }
  3560. case 3 : { /* indexed */
  3561. switch (pData->iBitdepth)
  3562. {
  3563. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  3564. case 1 : {
  3565. if (!pData->iInterlace)
  3566. pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni;
  3567. else
  3568. pData->fInitrowproc = (mng_fptr)mng_init_idx1_i;
  3569. break;
  3570. }
  3571. case 2 : {
  3572. if (!pData->iInterlace)
  3573. pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni;
  3574. else
  3575. pData->fInitrowproc = (mng_fptr)mng_init_idx2_i;
  3576. break;
  3577. }
  3578. case 4 : {
  3579. if (!pData->iInterlace)
  3580. pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni;
  3581. else
  3582. pData->fInitrowproc = (mng_fptr)mng_init_idx4_i;
  3583. break;
  3584. }
  3585. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  3586. case 8 : {
  3587. if (!pData->iInterlace)
  3588. pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni;
  3589. else
  3590. pData->fInitrowproc = (mng_fptr)mng_init_idx8_i;
  3591. break;
  3592. }
  3593. }
  3594. break;
  3595. }
  3596. case 4 : { /* gray+alpha */
  3597. switch (pData->iBitdepth)
  3598. {
  3599. case 8 : {
  3600. if (!pData->iInterlace)
  3601. pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni;
  3602. else
  3603. pData->fInitrowproc = (mng_fptr)mng_init_ga8_i;
  3604. break;
  3605. }
  3606. #ifndef MNG_NO_16BIT_SUPPORT
  3607. case 16 : {
  3608. if (!pData->iInterlace)
  3609. pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni;
  3610. else
  3611. pData->fInitrowproc = (mng_fptr)mng_init_ga16_i;
  3612. break;
  3613. }
  3614. #endif
  3615. }
  3616. break;
  3617. }
  3618. case 6 : { /* rgb+alpha */
  3619. switch (pData->iBitdepth)
  3620. {
  3621. case 8 : {
  3622. if (!pData->iInterlace)
  3623. pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni;
  3624. else
  3625. pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i;
  3626. break;
  3627. }
  3628. #ifndef MNG_NO_16BIT_SUPPORT
  3629. case 16 : {
  3630. if (!pData->iInterlace)
  3631. pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni;
  3632. else
  3633. pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i;
  3634. break;
  3635. }
  3636. #endif
  3637. }
  3638. break;
  3639. }
  3640. }
  3641. #endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
  3642. pData->iFilterofs = 0; /* determine filter characteristics */
  3643. pData->iLevel0 = 0; /* default levels */
  3644. pData->iLevel1 = 0;
  3645. pData->iLevel2 = 0;
  3646. pData->iLevel3 = 0;
  3647. #ifdef FILTER192
  3648. if (pData->iFilter == 0xC0) /* leveling & differing ? */
  3649. {
  3650. switch (pData->iColortype)
  3651. {
  3652. case 0 : {
  3653. #ifndef MNG_NO_16BIT_SUPPORT
  3654. if (pData->iBitdepth <= 8)
  3655. #endif
  3656. pData->iFilterofs = 1;
  3657. #ifndef MNG_NO_16BIT_SUPPORT
  3658. else
  3659. pData->iFilterofs = 2;
  3660. #endif
  3661. break;
  3662. }
  3663. case 2 : {
  3664. #ifndef MNG_NO_16BIT_SUPPORT
  3665. if (pData->iBitdepth <= 8)
  3666. #endif
  3667. pData->iFilterofs = 3;
  3668. #ifndef MNG_NO_16BIT_SUPPORT
  3669. else
  3670. pData->iFilterofs = 6;
  3671. #endif
  3672. break;
  3673. }
  3674. case 3 : {
  3675. pData->iFilterofs = 1;
  3676. break;
  3677. }
  3678. case 4 : {
  3679. #ifndef MNG_NO_16BIT_SUPPORT
  3680. if (pData->iBitdepth <= 8)
  3681. #endif
  3682. pData->iFilterofs = 2;
  3683. #ifndef MNG_NO_16BIT_SUPPORT
  3684. else
  3685. pData->iFilterofs = 4;
  3686. #endif
  3687. break;
  3688. }
  3689. case 6 : {
  3690. #ifndef MNG_NO_16BIT_SUPPORT
  3691. if (pData->iBitdepth <= 8)
  3692. #endif
  3693. pData->iFilterofs = 4;
  3694. #ifndef MNG_NO_16BIT_SUPPORT
  3695. else
  3696. pData->iFilterofs = 8;
  3697. #endif
  3698. break;
  3699. }
  3700. }
  3701. }
  3702. #endif
  3703. #ifdef FILTER193
  3704. if (pData->iFilter == 0xC1) /* no adaptive filtering ? */
  3705. pData->iPixelofs = pData->iFilterofs;
  3706. else
  3707. #endif
  3708. pData->iPixelofs = pData->iFilterofs + 1;
  3709. #ifdef MNG_SUPPORT_TRACE
  3710. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_BASI, MNG_LC_END);
  3711. #endif
  3712. return MNG_NOERROR;
  3713. }
  3714. #endif
  3715. /* ************************************************************************** */
  3716. #ifndef MNG_SKIPCHUNK_CLON
  3717. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3718. mng_retcode mng_process_display_clon (mng_datap pData,
  3719. mng_uint16 iSourceid,
  3720. mng_uint16 iCloneid,
  3721. mng_uint8 iClonetype,
  3722. mng_bool bHasdonotshow,
  3723. mng_uint8 iDonotshow,
  3724. mng_uint8 iConcrete,
  3725. mng_bool bHasloca,
  3726. mng_uint8 iLocationtype,
  3727. mng_int32 iLocationx,
  3728. mng_int32 iLocationy)
  3729. #else
  3730. mng_retcode mng_process_display_clon (mng_datap pData)
  3731. #endif
  3732. {
  3733. mng_imagep pSource, pClone;
  3734. mng_bool bVisible, bAbstract;
  3735. mng_retcode iRetcode = MNG_NOERROR;
  3736. #ifdef MNG_SUPPORT_TRACE
  3737. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_START);
  3738. #endif
  3739. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3740. /* locate the source object first */
  3741. pSource = mng_find_imageobject (pData, iSourceid);
  3742. /* check if the clone exists */
  3743. pClone = mng_find_imageobject (pData, iCloneid);
  3744. #else
  3745. /* locate the source object first */
  3746. pSource = mng_find_imageobject (pData, pData->iCLONsourceid);
  3747. /* check if the clone exists */
  3748. pClone = mng_find_imageobject (pData, pData->iCLONcloneid);
  3749. #endif
  3750. if (!pSource) /* source must exist ! */
  3751. MNG_ERROR (pData, MNG_OBJECTUNKNOWN);
  3752. if (pClone) /* clone must not exist ! */
  3753. MNG_ERROR (pData, MNG_OBJECTEXISTS);
  3754. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3755. if (bHasdonotshow) /* DoNotShow flag filled ? */
  3756. bVisible = (mng_bool)(iDonotshow == 0);
  3757. else
  3758. bVisible = pSource->bVisible;
  3759. #else
  3760. if (pData->bCLONhasdonotshow) /* DoNotShow flag filled ? */
  3761. bVisible = (mng_bool)(pData->iCLONdonotshow == 0);
  3762. else
  3763. bVisible = pSource->bVisible;
  3764. #endif
  3765. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3766. bAbstract = (mng_bool)(iConcrete == 1);
  3767. #else
  3768. bAbstract = (mng_bool)(pData->iCLONconcrete == 1);
  3769. #endif
  3770. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3771. switch (iClonetype) /* determine action to take */
  3772. {
  3773. case 0 : { /* full clone */
  3774. iRetcode = mng_clone_imageobject (pData, iCloneid, MNG_FALSE,
  3775. bVisible, bAbstract, bHasloca,
  3776. iLocationtype, iLocationx, iLocationy,
  3777. pSource, &pClone);
  3778. break;
  3779. }
  3780. case 1 : { /* partial clone */
  3781. iRetcode = mng_clone_imageobject (pData, iCloneid, MNG_TRUE,
  3782. bVisible, bAbstract, bHasloca,
  3783. iLocationtype, iLocationx, iLocationy,
  3784. pSource, &pClone);
  3785. break;
  3786. }
  3787. case 2 : { /* renumber object */
  3788. iRetcode = mng_renum_imageobject (pData, pSource, iCloneid,
  3789. bVisible, bAbstract, bHasloca,
  3790. iLocationtype, iLocationx, iLocationy);
  3791. pClone = pSource;
  3792. break;
  3793. }
  3794. }
  3795. #else
  3796. switch (pData->iCLONclonetype) /* determine action to take */
  3797. {
  3798. case 0 : { /* full clone */
  3799. iRetcode = mng_clone_imageobject (pData, pData->iCLONcloneid, MNG_FALSE,
  3800. bVisible, bAbstract,
  3801. pData->bCLONhasloca, pData->iCLONlocationtype,
  3802. pData->iCLONlocationx, pData->iCLONlocationy,
  3803. pSource, &pClone);
  3804. break;
  3805. }
  3806. case 1 : { /* partial clone */
  3807. iRetcode = mng_clone_imageobject (pData, pData->iCLONcloneid, MNG_TRUE,
  3808. bVisible, bAbstract,
  3809. pData->bCLONhasloca, pData->iCLONlocationtype,
  3810. pData->iCLONlocationx, pData->iCLONlocationy,
  3811. pSource, &pClone);
  3812. break;
  3813. }
  3814. case 2 : { /* renumber object */
  3815. iRetcode = mng_renum_imageobject (pData, pSource, pData->iCLONcloneid,
  3816. bVisible, bAbstract,
  3817. pData->bCLONhasloca, pData->iCLONlocationtype,
  3818. pData->iCLONlocationx, pData->iCLONlocationy);
  3819. pClone = pSource;
  3820. break;
  3821. }
  3822. }
  3823. #endif
  3824. if (iRetcode) /* on error bail out */
  3825. return iRetcode;
  3826. /* display on the fly ? */
  3827. if ((pClone->bViewable) && (pClone->bVisible))
  3828. {
  3829. pData->pLastclone = pClone; /* remember in case of timer break ! */
  3830. /* display it */
  3831. mng_display_image (pData, pClone, MNG_FALSE);
  3832. if (pData->bTimerset) /* timer break ? */
  3833. pData->iBreakpoint = 5;
  3834. }
  3835. #ifdef MNG_SUPPORT_TRACE
  3836. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_END);
  3837. #endif
  3838. return MNG_NOERROR;
  3839. }
  3840. /* ************************************************************************** */
  3841. mng_retcode mng_process_display_clon2 (mng_datap pData)
  3842. {
  3843. #ifdef MNG_SUPPORT_TRACE
  3844. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_START);
  3845. #endif
  3846. /* only called after timer break ! */
  3847. mng_display_image (pData, (mng_imagep)pData->pLastclone, MNG_FALSE);
  3848. pData->iBreakpoint = 0;
  3849. #ifdef MNG_SUPPORT_TRACE
  3850. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_END);
  3851. #endif
  3852. return MNG_NOERROR;
  3853. }
  3854. #endif
  3855. /* ************************************************************************** */
  3856. #ifndef MNG_SKIPCHUNK_DISC
  3857. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3858. mng_retcode mng_process_display_disc (mng_datap pData,
  3859. mng_uint32 iCount,
  3860. mng_uint16p pIds)
  3861. #else
  3862. mng_retcode mng_process_display_disc (mng_datap pData)
  3863. #endif
  3864. {
  3865. mng_uint32 iX;
  3866. mng_imagep pImage;
  3867. mng_uint32 iRetcode;
  3868. #ifdef MNG_SUPPORT_TRACE
  3869. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DISC, MNG_LC_START);
  3870. #endif
  3871. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3872. if (iCount) /* specific list ? */
  3873. #else
  3874. if (pData->iDISCcount) /* specific list ? */
  3875. #endif
  3876. {
  3877. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3878. mng_uint16p pWork = pIds;
  3879. #else
  3880. mng_uint16p pWork = pData->pDISCids;
  3881. #endif
  3882. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3883. #ifdef MNG_DECREMENT_LOOPS /* iterate the list */
  3884. for (iX = iCount; iX > 0; iX--)
  3885. #else
  3886. for (iX = 0; iX < iCount; iX++)
  3887. #endif
  3888. #else
  3889. #ifdef MNG_DECREMENT_LOOPS /* iterate the list */
  3890. for (iX = pData->iDISCcount; iX > 0; iX--)
  3891. #else
  3892. for (iX = 0; iX < pData->iDISCcount; iX++)
  3893. #endif
  3894. #endif
  3895. {
  3896. pImage = mng_find_imageobject (pData, *pWork++);
  3897. if (pImage) /* found the object ? */
  3898. { /* then drop it */
  3899. iRetcode = mng_free_imageobject (pData, pImage);
  3900. if (iRetcode) /* on error bail out */
  3901. return iRetcode;
  3902. }
  3903. }
  3904. }
  3905. else /* empty: drop all un-frozen objects */
  3906. {
  3907. mng_imagep pNext = (mng_imagep)pData->pFirstimgobj;
  3908. while (pNext) /* any left ? */
  3909. {
  3910. pImage = pNext;
  3911. pNext = pImage->sHeader.pNext;
  3912. if (!pImage->bFrozen) /* not frozen ? */
  3913. { /* then drop it */
  3914. iRetcode = mng_free_imageobject (pData, pImage);
  3915. if (iRetcode) /* on error bail out */
  3916. return iRetcode;
  3917. }
  3918. }
  3919. }
  3920. #ifdef MNG_SUPPORT_TRACE
  3921. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DISC, MNG_LC_END);
  3922. #endif
  3923. return MNG_NOERROR;
  3924. }
  3925. #endif
  3926. /* ************************************************************************** */
  3927. #ifndef MNG_SKIPCHUNK_FRAM
  3928. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3929. mng_retcode mng_process_display_fram (mng_datap pData,
  3930. mng_uint8 iFramemode,
  3931. mng_uint8 iChangedelay,
  3932. mng_uint32 iDelay,
  3933. mng_uint8 iChangetimeout,
  3934. mng_uint32 iTimeout,
  3935. mng_uint8 iChangeclipping,
  3936. mng_uint8 iCliptype,
  3937. mng_int32 iClipl,
  3938. mng_int32 iClipr,
  3939. mng_int32 iClipt,
  3940. mng_int32 iClipb)
  3941. #else
  3942. mng_retcode mng_process_display_fram (mng_datap pData)
  3943. #endif
  3944. {
  3945. mng_retcode iRetcode;
  3946. #ifdef MNG_SUPPORT_TRACE
  3947. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_START);
  3948. #endif
  3949. /* advance a frame then */
  3950. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3951. iRetcode = next_frame (pData, iFramemode, iChangedelay, iDelay,
  3952. iChangetimeout, iTimeout, iChangeclipping,
  3953. iCliptype, iClipl, iClipr, iClipt, iClipb);
  3954. #else
  3955. iRetcode = next_frame (pData, pData->iTempFramemode, pData->iTempChangedelay,
  3956. pData->iTempDelay, pData->iTempChangetimeout,
  3957. pData->iTempTimeout, pData->iTempChangeclipping,
  3958. pData->iTempCliptype, pData->iTempClipl, pData->iTempClipr,
  3959. pData->iTempClipt, pData->iTempClipb);
  3960. #endif
  3961. if (pData->bTimerset) /* timer break ? */
  3962. pData->iBreakpoint = 1;
  3963. #ifdef MNG_SUPPORT_TRACE
  3964. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_END);
  3965. #endif
  3966. return iRetcode;
  3967. }
  3968. /* ************************************************************************** */
  3969. mng_retcode mng_process_display_fram2 (mng_datap pData)
  3970. {
  3971. mng_retcode iRetcode;
  3972. #ifdef MNG_SUPPORT_TRACE
  3973. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_START);
  3974. #endif
  3975. /* again; after the break */
  3976. iRetcode = next_frame (pData, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  3977. pData->iBreakpoint = 0; /* not again! */
  3978. #ifdef MNG_SUPPORT_TRACE
  3979. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_END);
  3980. #endif
  3981. return iRetcode;
  3982. }
  3983. #endif
  3984. /* ************************************************************************** */
  3985. #ifndef MNG_SKIPCHUNK_MOVE
  3986. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  3987. mng_retcode mng_process_display_move (mng_datap pData,
  3988. mng_uint16 iFromid,
  3989. mng_uint16 iToid,
  3990. mng_uint8 iMovetype,
  3991. mng_int32 iMovex,
  3992. mng_int32 iMovey)
  3993. #else
  3994. mng_retcode mng_process_display_move (mng_datap pData)
  3995. #endif
  3996. {
  3997. mng_uint16 iX;
  3998. mng_imagep pImage;
  3999. #ifdef MNG_SUPPORT_TRACE
  4000. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MOVE, MNG_LC_START);
  4001. #endif
  4002. /* iterate the list */
  4003. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4004. for (iX = iFromid; iX <= iToid; iX++)
  4005. #else
  4006. for (iX = pData->iMOVEfromid; iX <= pData->iMOVEtoid; iX++)
  4007. #endif
  4008. {
  4009. if (!iX) /* object id=0 ? */
  4010. pImage = (mng_imagep)pData->pObjzero;
  4011. else
  4012. pImage = mng_find_imageobject (pData, iX);
  4013. if (pImage) /* object exists ? */
  4014. {
  4015. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4016. switch (iMovetype)
  4017. #else
  4018. switch (pData->iMOVEmovetype)
  4019. #endif
  4020. {
  4021. case 0 : { /* absolute */
  4022. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4023. pImage->iPosx = iMovex;
  4024. pImage->iPosy = iMovey;
  4025. #else
  4026. pImage->iPosx = pData->iMOVEmovex;
  4027. pImage->iPosy = pData->iMOVEmovey;
  4028. #endif
  4029. break;
  4030. }
  4031. case 1 : { /* relative */
  4032. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4033. pImage->iPosx = pImage->iPosx + iMovex;
  4034. pImage->iPosy = pImage->iPosy + iMovey;
  4035. #else
  4036. pImage->iPosx = pImage->iPosx + pData->iMOVEmovex;
  4037. pImage->iPosy = pImage->iPosy + pData->iMOVEmovey;
  4038. #endif
  4039. break;
  4040. }
  4041. }
  4042. }
  4043. }
  4044. #ifdef MNG_SUPPORT_TRACE
  4045. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MOVE, MNG_LC_END);
  4046. #endif
  4047. return MNG_NOERROR;
  4048. }
  4049. #endif
  4050. /* ************************************************************************** */
  4051. #ifndef MNG_SKIPCHUNK_CLIP
  4052. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4053. mng_retcode mng_process_display_clip (mng_datap pData,
  4054. mng_uint16 iFromid,
  4055. mng_uint16 iToid,
  4056. mng_uint8 iCliptype,
  4057. mng_int32 iClipl,
  4058. mng_int32 iClipr,
  4059. mng_int32 iClipt,
  4060. mng_int32 iClipb)
  4061. #else
  4062. mng_retcode mng_process_display_clip (mng_datap pData)
  4063. #endif
  4064. {
  4065. mng_uint16 iX;
  4066. mng_imagep pImage;
  4067. #ifdef MNG_SUPPORT_TRACE
  4068. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLIP, MNG_LC_START);
  4069. #endif
  4070. /* iterate the list */
  4071. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4072. for (iX = iFromid; iX <= iToid; iX++)
  4073. #else
  4074. for (iX = pData->iCLIPfromid; iX <= pData->iCLIPtoid; iX++)
  4075. #endif
  4076. {
  4077. if (!iX) /* object id=0 ? */
  4078. pImage = (mng_imagep)pData->pObjzero;
  4079. else
  4080. pImage = mng_find_imageobject (pData, iX);
  4081. if (pImage) /* object exists ? */
  4082. {
  4083. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4084. switch (iCliptype)
  4085. #else
  4086. switch (pData->iCLIPcliptype)
  4087. #endif
  4088. {
  4089. case 0 : { /* absolute */
  4090. pImage->bClipped = MNG_TRUE;
  4091. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4092. pImage->iClipl = iClipl;
  4093. pImage->iClipr = iClipr;
  4094. pImage->iClipt = iClipt;
  4095. pImage->iClipb = iClipb;
  4096. #else
  4097. pImage->iClipl = pData->iCLIPclipl;
  4098. pImage->iClipr = pData->iCLIPclipr;
  4099. pImage->iClipt = pData->iCLIPclipt;
  4100. pImage->iClipb = pData->iCLIPclipb;
  4101. #endif
  4102. break;
  4103. }
  4104. case 1 : { /* relative */
  4105. pImage->bClipped = MNG_TRUE;
  4106. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4107. pImage->iClipl = pImage->iClipl + iClipl;
  4108. pImage->iClipr = pImage->iClipr + iClipr;
  4109. pImage->iClipt = pImage->iClipt + iClipt;
  4110. pImage->iClipb = pImage->iClipb + iClipb;
  4111. #else
  4112. pImage->iClipl = pImage->iClipl + pData->iCLIPclipl;
  4113. pImage->iClipr = pImage->iClipr + pData->iCLIPclipr;
  4114. pImage->iClipt = pImage->iClipt + pData->iCLIPclipt;
  4115. pImage->iClipb = pImage->iClipb + pData->iCLIPclipb;
  4116. #endif
  4117. break;
  4118. }
  4119. }
  4120. }
  4121. }
  4122. #ifdef MNG_SUPPORT_TRACE
  4123. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLIP, MNG_LC_END);
  4124. #endif
  4125. return MNG_NOERROR;
  4126. }
  4127. #endif
  4128. /* ************************************************************************** */
  4129. #ifndef MNG_SKIPCHUNK_SHOW
  4130. mng_retcode mng_process_display_show (mng_datap pData)
  4131. {
  4132. mng_int16 iX, iS, iFrom, iTo;
  4133. mng_imagep pImage;
  4134. #ifdef MNG_SUPPORT_TRACE
  4135. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SHOW, MNG_LC_START);
  4136. #endif
  4137. /* TODO: optimization for the cases where "abs (iTo - iFrom)" is rather high;
  4138. especially where ((iFrom==1) && (iTo==65535)); eg. an empty SHOW !!! */
  4139. if (pData->iBreakpoint == 3) /* previously broken during cycle-mode ? */
  4140. {
  4141. pImage = mng_find_imageobject (pData, pData->iSHOWnextid);
  4142. if (pImage) /* still there ? */
  4143. mng_display_image (pData, pImage, MNG_FALSE);
  4144. pData->iBreakpoint = 0; /* let's not go through this again! */
  4145. }
  4146. else
  4147. {
  4148. if (pData->iBreakpoint) /* previously broken at other point ? */
  4149. { /* restore last parms */
  4150. iFrom = (mng_int16)pData->iSHOWfromid;
  4151. iTo = (mng_int16)pData->iSHOWtoid;
  4152. iX = (mng_int16)pData->iSHOWnextid;
  4153. iS = (mng_int16)pData->iSHOWskip;
  4154. }
  4155. else
  4156. { /* regular sequence ? */
  4157. if (pData->iSHOWtoid >= pData->iSHOWfromid)
  4158. iS = 1;
  4159. else /* reverse sequence ! */
  4160. iS = -1;
  4161. iFrom = (mng_int16)pData->iSHOWfromid;
  4162. iTo = (mng_int16)pData->iSHOWtoid;
  4163. iX = iFrom;
  4164. pData->iSHOWfromid = (mng_uint16)iFrom;
  4165. pData->iSHOWtoid = (mng_uint16)iTo;
  4166. pData->iSHOWskip = iS;
  4167. }
  4168. /* cycle mode ? */
  4169. if ((pData->iSHOWmode == 6) || (pData->iSHOWmode == 7))
  4170. {
  4171. mng_uint16 iTrigger = 0;
  4172. mng_uint16 iFound = 0;
  4173. mng_uint16 iPass = 0;
  4174. mng_imagep pFound = 0;
  4175. do
  4176. {
  4177. iPass++; /* lets prevent endless loops when there
  4178. are no potential candidates in the list! */
  4179. if (iS > 0) /* forward ? */
  4180. {
  4181. for (iX = iFrom; iX <= iTo; iX += iS)
  4182. {
  4183. pImage = mng_find_imageobject (pData, (mng_uint16)iX);
  4184. if (pImage) /* object exists ? */
  4185. {
  4186. if (iFound) /* already found a candidate ? */
  4187. pImage->bVisible = MNG_FALSE;
  4188. else
  4189. if (iTrigger) /* found the trigger ? */
  4190. {
  4191. pImage->bVisible = MNG_TRUE;
  4192. iFound = iX;
  4193. pFound = pImage;
  4194. }
  4195. else
  4196. if (pImage->bVisible) /* ok, this is the trigger */
  4197. {
  4198. pImage->bVisible = MNG_FALSE;
  4199. iTrigger = iX;
  4200. }
  4201. }
  4202. }
  4203. }
  4204. else
  4205. {
  4206. for (iX = iFrom; iX >= iTo; iX += iS)
  4207. {
  4208. pImage = mng_find_imageobject (pData, (mng_uint16)iX);
  4209. if (pImage) /* object exists ? */
  4210. {
  4211. if (iFound) /* already found a candidate ? */
  4212. pImage->bVisible = MNG_FALSE;
  4213. else
  4214. if (iTrigger) /* found the trigger ? */
  4215. {
  4216. pImage->bVisible = MNG_TRUE;
  4217. iFound = iX;
  4218. pFound = pImage;
  4219. }
  4220. else
  4221. if (pImage->bVisible) /* ok, this is the trigger */
  4222. {
  4223. pImage->bVisible = MNG_FALSE;
  4224. iTrigger = iX;
  4225. }
  4226. }
  4227. }
  4228. }
  4229. if (!iTrigger) /* did not find a trigger ? */
  4230. iTrigger = 1; /* then fake it so the first image
  4231. gets nominated */
  4232. } /* cycle back to beginning ? */
  4233. while ((iPass < 2) && (iTrigger) && (!iFound));
  4234. pData->iBreakpoint = 0; /* just a sanity precaution */
  4235. /* display it ? */
  4236. if ((pData->iSHOWmode == 6) && (pFound))
  4237. {
  4238. mng_display_image (pData, pFound, MNG_FALSE);
  4239. if (pData->bTimerset) /* timer set ? */
  4240. {
  4241. pData->iBreakpoint = 3;
  4242. pData->iSHOWnextid = iFound; /* save it for after the break */
  4243. }
  4244. }
  4245. }
  4246. else
  4247. {
  4248. do
  4249. {
  4250. pImage = mng_find_imageobject (pData, iX);
  4251. if (pImage) /* object exists ? */
  4252. {
  4253. if (pData->iBreakpoint) /* did we get broken last time ? */
  4254. { /* could only happen in the display routine */
  4255. mng_display_image (pData, pImage, MNG_FALSE);
  4256. pData->iBreakpoint = 0; /* only once inside this loop please ! */
  4257. }
  4258. else
  4259. {
  4260. switch (pData->iSHOWmode) /* do what ? */
  4261. {
  4262. case 0 : {
  4263. pImage->bVisible = MNG_TRUE;
  4264. mng_display_image (pData, pImage, MNG_FALSE);
  4265. break;
  4266. }
  4267. case 1 : {
  4268. pImage->bVisible = MNG_FALSE;
  4269. break;
  4270. }
  4271. case 2 : {
  4272. if (pImage->bVisible)
  4273. mng_display_image (pData, pImage, MNG_FALSE);
  4274. break;
  4275. }
  4276. case 3 : {
  4277. pImage->bVisible = MNG_TRUE;
  4278. break;
  4279. }
  4280. case 4 : {
  4281. pImage->bVisible = (mng_bool)(!pImage->bVisible);
  4282. if (pImage->bVisible)
  4283. mng_display_image (pData, pImage, MNG_FALSE);
  4284. break;
  4285. }
  4286. case 5 : {
  4287. pImage->bVisible = (mng_bool)(!pImage->bVisible);
  4288. }
  4289. }
  4290. }
  4291. }
  4292. if (!pData->bTimerset) /* next ? */
  4293. iX += iS;
  4294. } /* continue ? */
  4295. while ((!pData->bTimerset) && (((iS > 0) && (iX <= iTo)) ||
  4296. ((iS < 0) && (iX >= iTo)) ));
  4297. if (pData->bTimerset) /* timer set ? */
  4298. {
  4299. pData->iBreakpoint = 4;
  4300. pData->iSHOWnextid = iX; /* save for next time */
  4301. }
  4302. else
  4303. pData->iBreakpoint = 0;
  4304. }
  4305. }
  4306. #ifdef MNG_SUPPORT_TRACE
  4307. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SHOW, MNG_LC_END);
  4308. #endif
  4309. return MNG_NOERROR;
  4310. }
  4311. #endif
  4312. /* ************************************************************************** */
  4313. #ifndef MNG_SKIPCHUNK_SAVE
  4314. mng_retcode mng_process_display_save (mng_datap pData)
  4315. {
  4316. mng_retcode iRetcode;
  4317. #ifdef MNG_SUPPORT_TRACE
  4318. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SAVE, MNG_LC_START);
  4319. #endif
  4320. iRetcode = save_state (pData); /* save the current state */
  4321. if (iRetcode) /* on error bail out */
  4322. return iRetcode;
  4323. #ifdef MNG_SUPPORT_TRACE
  4324. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SAVE, MNG_LC_END);
  4325. #endif
  4326. return MNG_NOERROR;
  4327. }
  4328. #endif
  4329. /* ************************************************************************** */
  4330. #ifndef MNG_SKIPCHUNK_SEEK
  4331. mng_retcode mng_process_display_seek (mng_datap pData)
  4332. {
  4333. #ifdef MNG_SUPPORT_TRACE
  4334. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SEEK, MNG_LC_START);
  4335. #endif
  4336. #ifdef MNG_SUPPORT_DYNAMICMNG
  4337. if (pData->bStopafterseek) /* need to stop after this SEEK ? */
  4338. {
  4339. pData->bFreezing = MNG_TRUE; /* stop processing on this one */
  4340. pData->bRunningevent = MNG_FALSE;
  4341. pData->bStopafterseek = MNG_FALSE;
  4342. pData->bNeedrefresh = MNG_TRUE; /* make sure the last bit is displayed ! */
  4343. }
  4344. else
  4345. #endif
  4346. { /* restore the initial or SAVE state */
  4347. mng_retcode iRetcode = restore_state (pData);
  4348. if (iRetcode) /* on error bail out */
  4349. return iRetcode;
  4350. #ifdef MNG_SUPPORT_DYNAMICMNG
  4351. /* stop after next SEEK ? */
  4352. if ((pData->bDynamic) || (pData->bRunningevent))
  4353. pData->bStopafterseek = MNG_TRUE;
  4354. #endif
  4355. }
  4356. #ifdef MNG_SUPPORT_TRACE
  4357. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SEEK, MNG_LC_END);
  4358. #endif
  4359. return MNG_NOERROR;
  4360. }
  4361. #endif
  4362. /* ************************************************************************** */
  4363. #ifdef MNG_INCLUDE_JNG
  4364. mng_retcode mng_process_display_jhdr (mng_datap pData)
  4365. { /* address the current "object" if any */
  4366. mng_imagep pImage = (mng_imagep)pData->pCurrentobj;
  4367. mng_retcode iRetcode = MNG_NOERROR;
  4368. #ifdef MNG_SUPPORT_TRACE
  4369. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JHDR, MNG_LC_START);
  4370. #endif
  4371. if (!pData->bHasDHDR)
  4372. {
  4373. pData->fInitrowproc = MNG_NULL; /* do nothing by default */
  4374. pData->fDisplayrow = MNG_NULL;
  4375. pData->fCorrectrow = MNG_NULL;
  4376. pData->fStorerow = MNG_NULL;
  4377. pData->fProcessrow = MNG_NULL;
  4378. pData->fDifferrow = MNG_NULL;
  4379. pData->fStorerow2 = MNG_NULL;
  4380. pData->fStorerow3 = MNG_NULL;
  4381. pData->pStoreobj = MNG_NULL; /* initialize important work-parms */
  4382. pData->iJPEGrow = 0;
  4383. pData->iJPEGalpharow = 0;
  4384. pData->iJPEGrgbrow = 0;
  4385. pData->iRowmax = 0; /* so init_rowproc does the right thing ! */
  4386. }
  4387. if (!pData->iBreakpoint) /* not previously broken ? */
  4388. {
  4389. #ifndef MNG_NO_DELTA_PNG
  4390. if (pData->bHasDHDR) /* delta-image ? */
  4391. {
  4392. if (pData->iDeltatype == MNG_DELTATYPE_REPLACE)
  4393. {
  4394. iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pDeltaImage,
  4395. pData->iDatawidth, pData->iDataheight,
  4396. pData->iJHDRimgbitdepth, pData->iJHDRcolortype,
  4397. pData->iJHDRalphacompression, pData->iJHDRalphafilter,
  4398. pData->iJHDRalphainterlace, MNG_TRUE);
  4399. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth;
  4400. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression;
  4401. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace;
  4402. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
  4403. }
  4404. else
  4405. if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
  4406. (pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
  4407. {
  4408. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iJHDRimgbitdepth;
  4409. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
  4410. }
  4411. else
  4412. if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
  4413. (pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
  4414. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
  4415. else
  4416. if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
  4417. (pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
  4418. ((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iJHDRimgbitdepth;
  4419. }
  4420. else
  4421. #endif /* MNG_NO_DELTA_PNG */
  4422. {
  4423. if (pImage) /* update object buffer ? */
  4424. {
  4425. iRetcode = mng_reset_object_details (pData, pImage,
  4426. pData->iDatawidth, pData->iDataheight,
  4427. pData->iJHDRimgbitdepth, pData->iJHDRcolortype,
  4428. pData->iJHDRalphacompression, pData->iJHDRalphafilter,
  4429. pData->iJHDRalphainterlace, MNG_TRUE);
  4430. pImage->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth;
  4431. pImage->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression;
  4432. pImage->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace;
  4433. pImage->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
  4434. }
  4435. else /* update object 0 */
  4436. {
  4437. iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero,
  4438. pData->iDatawidth, pData->iDataheight,
  4439. pData->iJHDRimgbitdepth, pData->iJHDRcolortype,
  4440. pData->iJHDRalphacompression, pData->iJHDRalphafilter,
  4441. pData->iJHDRalphainterlace, MNG_TRUE);
  4442. ((mng_imagep)pData->pObjzero)->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth;
  4443. ((mng_imagep)pData->pObjzero)->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression;
  4444. ((mng_imagep)pData->pObjzero)->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace;
  4445. ((mng_imagep)pData->pObjzero)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
  4446. }
  4447. }
  4448. if (iRetcode) /* on error bail out */
  4449. return iRetcode;
  4450. }
  4451. if (!pData->bHasDHDR)
  4452. { /* we're always storing a JPEG */
  4453. if (pImage) /* real object ? */
  4454. pData->pStoreobj = pImage; /* tell the row routines */
  4455. else /* otherwise use object 0 */
  4456. pData->pStoreobj = pData->pObjzero;
  4457. /* display "on-the-fly" ? */
  4458. if (
  4459. #ifndef MNG_SKIPCHUNK_MAGN
  4460. ( ((mng_imagep)pData->pStoreobj)->iMAGN_MethodX == 0) &&
  4461. ( ((mng_imagep)pData->pStoreobj)->iMAGN_MethodY == 0) &&
  4462. #endif
  4463. ( (pData->eImagetype == mng_it_jng ) ||
  4464. (((mng_imagep)pData->pStoreobj)->bVisible) ) )
  4465. {
  4466. next_layer (pData); /* that's a new layer then ! */
  4467. pData->iBreakpoint = 0;
  4468. if (pData->bTimerset) /* timer break ? */
  4469. pData->iBreakpoint = 7;
  4470. else
  4471. if (pData->bRunning) /* still running ? */
  4472. { /* anything to display ? */
  4473. if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt))
  4474. {
  4475. set_display_routine (pData); /* then determine display routine */
  4476. /* display from the object we store in */
  4477. pData->pRetrieveobj = pData->pStoreobj;
  4478. }
  4479. }
  4480. }
  4481. }
  4482. if (!pData->bTimerset) /* no timer break ? */
  4483. { /* default row initialization ! */
  4484. #ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
  4485. pData->ePng_imgtype=png_none;
  4486. #endif
  4487. pData->fInitrowproc = (mng_fptr)mng_init_rowproc;
  4488. if ((!pData->bHasDHDR) || (pData->iDeltatype == MNG_DELTATYPE_REPLACE))
  4489. { /* 8-bit JPEG ? */
  4490. if (pData->iJHDRimgbitdepth == 8)
  4491. { /* intermediate row is 8-bit deep */
  4492. pData->bIsRGBA16 = MNG_FALSE;
  4493. pData->iRowsamples = pData->iDatawidth;
  4494. switch (pData->iJHDRcolortype) /* determine pixel processing routines */
  4495. {
  4496. case MNG_COLORTYPE_JPEGGRAY :
  4497. {
  4498. pData->fStorerow2 = (mng_fptr)mng_store_jpeg_g8;
  4499. pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
  4500. pData->bIsOpaque = MNG_TRUE;
  4501. break;
  4502. }
  4503. case MNG_COLORTYPE_JPEGCOLOR :
  4504. {
  4505. pData->fStorerow2 = (mng_fptr)mng_store_jpeg_rgb8;
  4506. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
  4507. pData->bIsOpaque = MNG_TRUE;
  4508. break;
  4509. }
  4510. case MNG_COLORTYPE_JPEGGRAYA :
  4511. {
  4512. pData->fStorerow2 = (mng_fptr)mng_store_jpeg_ga8;
  4513. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
  4514. pData->bIsOpaque = MNG_FALSE;
  4515. break;
  4516. }
  4517. case MNG_COLORTYPE_JPEGCOLORA :
  4518. {
  4519. pData->fStorerow2 = (mng_fptr)mng_store_jpeg_rgba8;
  4520. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
  4521. pData->bIsOpaque = MNG_FALSE;
  4522. break;
  4523. }
  4524. }
  4525. }
  4526. #ifndef MNG_NO_16BIT_SUPPORT
  4527. else
  4528. {
  4529. pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */
  4530. /* TODO: 12-bit JPEG */
  4531. /* TODO: 8- + 12-bit JPEG (eg. type=20) */
  4532. }
  4533. #endif
  4534. /* possible IDAT alpha-channel ? */
  4535. if (pData->iJHDRalphacompression == MNG_COMPRESSION_DEFLATE)
  4536. {
  4537. /* determine alpha processing routine */
  4538. #ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
  4539. pData->fInitrowproc = (mng_fptr)mng_init_rowproc;
  4540. #endif
  4541. switch (pData->iJHDRalphabitdepth)
  4542. {
  4543. #ifndef MNG_OPTIMIZE_FOOTPRINT_INIT
  4544. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  4545. case 1 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a1_ni; break; }
  4546. case 2 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a2_ni; break; }
  4547. case 4 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a4_ni; break; }
  4548. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  4549. case 8 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a8_ni; break; }
  4550. #ifndef MNG_NO_16BIT_SUPPORT
  4551. case 16 : { pData->fInitrowproc = (mng_fptr)mng_init_jpeg_a16_ni; break; }
  4552. #endif
  4553. #else
  4554. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  4555. case 1 : { pData->ePng_imgtype = png_jpeg_a1; break; }
  4556. case 2 : { pData->ePng_imgtype = png_jpeg_a2; break; }
  4557. case 4 : { pData->ePng_imgtype = png_jpeg_a4; break; }
  4558. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  4559. case 8 : { pData->ePng_imgtype = png_jpeg_a8; break; }
  4560. #ifndef MNG_NO_16BIT_SUPPORT
  4561. case 16 : { pData->ePng_imgtype = png_jpeg_a16; break; }
  4562. #endif
  4563. #endif
  4564. }
  4565. }
  4566. else /* possible JDAA alpha-channel ? */
  4567. if (pData->iJHDRalphacompression == MNG_COMPRESSION_BASELINEJPEG)
  4568. { /* 8-bit JPEG ? */
  4569. if (pData->iJHDRimgbitdepth == 8)
  4570. {
  4571. if (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA)
  4572. pData->fStorerow3 = (mng_fptr)mng_store_jpeg_g8_alpha;
  4573. else
  4574. if (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA)
  4575. pData->fStorerow3 = (mng_fptr)mng_store_jpeg_rgb8_alpha;
  4576. }
  4577. else
  4578. {
  4579. /* TODO: 12-bit JPEG with 8-bit JDAA */
  4580. }
  4581. }
  4582. /* initialize JPEG library */
  4583. iRetcode = mngjpeg_initialize (pData);
  4584. if (iRetcode) /* on error bail out */
  4585. return iRetcode;
  4586. }
  4587. else
  4588. { /* must be alpha add/replace !! */
  4589. if ((pData->iDeltatype != MNG_DELTATYPE_BLOCKALPHAADD ) &&
  4590. (pData->iDeltatype != MNG_DELTATYPE_BLOCKALPHAREPLACE) )
  4591. MNG_ERROR (pData, MNG_INVDELTATYPE);
  4592. /* determine alpha processing routine */
  4593. #ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
  4594. pData->fInitrowproc = (mng_fptr)mng_init_rowproc;
  4595. #endif
  4596. switch (pData->iJHDRalphabitdepth)
  4597. {
  4598. #ifndef MNG_OPTIMIZE_FOOTPRINT_INIT
  4599. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  4600. case 1 : { pData->fInitrowproc = (mng_fptr)mng_init_g1_ni; break; }
  4601. case 2 : { pData->fInitrowproc = (mng_fptr)mng_init_g2_ni; break; }
  4602. case 4 : { pData->fInitrowproc = (mng_fptr)mng_init_g4_ni; break; }
  4603. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  4604. case 8 : { pData->fInitrowproc = (mng_fptr)mng_init_g8_ni; break; }
  4605. #ifndef MNG_NO_16BIT_SUPPORT
  4606. case 16 : { pData->fInitrowproc = (mng_fptr)mng_init_g16_ni; break; }
  4607. #endif
  4608. #else
  4609. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  4610. case 1 : { pData->ePng_imgtype = png_jpeg_a1; break; }
  4611. case 2 : { pData->ePng_imgtype = png_jpeg_a2; break; }
  4612. case 4 : { pData->ePng_imgtype = png_jpeg_a4; break; }
  4613. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  4614. case 8 : { pData->ePng_imgtype = png_jpeg_a8; break; }
  4615. #ifndef MNG_NO_16BIT_SUPPORT
  4616. case 16 : { pData->ePng_imgtype = png_jpeg_a16; break; }
  4617. #endif
  4618. #endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
  4619. }
  4620. }
  4621. pData->iFilterofs = 0; /* determine filter characteristics */
  4622. pData->iLevel0 = 0; /* default levels */
  4623. pData->iLevel1 = 0;
  4624. pData->iLevel2 = 0;
  4625. pData->iLevel3 = 0;
  4626. #ifdef FILTER192 /* leveling & differing ? */
  4627. if (pData->iJHDRalphafilter == 0xC0)
  4628. {
  4629. if (pData->iJHDRalphabitdepth <= 8)
  4630. pData->iFilterofs = 1;
  4631. else
  4632. pData->iFilterofs = 2;
  4633. }
  4634. #endif
  4635. #ifdef FILTER193 /* no adaptive filtering ? */
  4636. if (pData->iJHDRalphafilter == 0xC1)
  4637. pData->iPixelofs = pData->iFilterofs;
  4638. else
  4639. #endif
  4640. pData->iPixelofs = pData->iFilterofs + 1;
  4641. }
  4642. #ifdef MNG_SUPPORT_TRACE
  4643. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JHDR, MNG_LC_END);
  4644. #endif
  4645. return MNG_NOERROR;
  4646. }
  4647. #endif /* MNG_INCLUDE_JNG */
  4648. /* ************************************************************************** */
  4649. #ifdef MNG_INCLUDE_JNG
  4650. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4651. mng_retcode mng_process_display_jdaa (mng_datap pData,
  4652. mng_uint32 iRawlen,
  4653. mng_uint8p pRawdata)
  4654. #else
  4655. mng_retcode mng_process_display_jdaa (mng_datap pData)
  4656. #endif
  4657. {
  4658. mng_retcode iRetcode = MNG_NOERROR;
  4659. #ifdef MNG_SUPPORT_TRACE
  4660. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAA, MNG_LC_START);
  4661. #endif
  4662. if (!pData->bJPEGdecompress2) /* if we're not decompressing already */
  4663. {
  4664. if (pData->fInitrowproc) /* initialize row-processing? */
  4665. {
  4666. iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData);
  4667. pData->fInitrowproc = MNG_NULL; /* only call this once !!! */
  4668. }
  4669. if (!iRetcode) /* initialize decompress */
  4670. iRetcode = mngjpeg_decompressinit2 (pData);
  4671. }
  4672. if (!iRetcode) /* all ok? then decompress, my man */
  4673. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4674. iRetcode = mngjpeg_decompressdata2 (pData, iRawlen, pRawdata);
  4675. #else
  4676. iRetcode = mngjpeg_decompressdata2 (pData, pData->iRawlen, pData->pRawdata);
  4677. #endif
  4678. if (iRetcode)
  4679. return iRetcode;
  4680. #ifdef MNG_SUPPORT_TRACE
  4681. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAA, MNG_LC_END);
  4682. #endif
  4683. return MNG_NOERROR;
  4684. }
  4685. #endif /* MNG_INCLUDE_JNG */
  4686. /* ************************************************************************** */
  4687. #ifdef MNG_INCLUDE_JNG
  4688. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4689. mng_retcode mng_process_display_jdat (mng_datap pData,
  4690. mng_uint32 iRawlen,
  4691. mng_uint8p pRawdata)
  4692. #else
  4693. mng_retcode mng_process_display_jdat (mng_datap pData)
  4694. #endif
  4695. {
  4696. mng_retcode iRetcode = MNG_NOERROR;
  4697. #ifdef MNG_SUPPORT_TRACE
  4698. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAT, MNG_LC_START);
  4699. #endif
  4700. if (pData->bRestorebkgd) /* need to restore the background ? */
  4701. {
  4702. pData->bRestorebkgd = MNG_FALSE;
  4703. iRetcode = load_bkgdlayer (pData);
  4704. pData->iLayerseq++; /* and it counts as a layer then ! */
  4705. if (iRetcode) /* on error bail out */
  4706. return iRetcode;
  4707. }
  4708. if (!pData->bJPEGdecompress) /* if we're not decompressing already */
  4709. {
  4710. if (pData->fInitrowproc) /* initialize row-processing? */
  4711. {
  4712. iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData);
  4713. pData->fInitrowproc = MNG_NULL; /* only call this once !!! */
  4714. }
  4715. if (!iRetcode) /* initialize decompress */
  4716. iRetcode = mngjpeg_decompressinit (pData);
  4717. }
  4718. if (!iRetcode) /* all ok? then decompress, my man */
  4719. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4720. iRetcode = mngjpeg_decompressdata (pData, iRawlen, pRawdata);
  4721. #else
  4722. iRetcode = mngjpeg_decompressdata (pData, pData->iRawlen, pData->pRawdata);
  4723. #endif
  4724. if (iRetcode)
  4725. return iRetcode;
  4726. #ifdef MNG_SUPPORT_TRACE
  4727. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAT, MNG_LC_END);
  4728. #endif
  4729. return MNG_NOERROR;
  4730. }
  4731. #endif /* MNG_INCLUDE_JNG */
  4732. /* ************************************************************************** */
  4733. #ifndef MNG_NO_DELTA_PNG
  4734. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4735. mng_retcode mng_process_display_dhdr (mng_datap pData,
  4736. mng_uint16 iObjectid,
  4737. mng_uint8 iImagetype,
  4738. mng_uint8 iDeltatype,
  4739. mng_uint32 iBlockwidth,
  4740. mng_uint32 iBlockheight,
  4741. mng_uint32 iBlockx,
  4742. mng_uint32 iBlocky)
  4743. #else
  4744. mng_retcode mng_process_display_dhdr (mng_datap pData)
  4745. #endif
  4746. {
  4747. mng_imagep pImage;
  4748. mng_retcode iRetcode;
  4749. #ifdef MNG_SUPPORT_TRACE
  4750. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DHDR, MNG_LC_START);
  4751. #endif
  4752. pData->fInitrowproc = MNG_NULL; /* do nothing by default */
  4753. pData->fDisplayrow = MNG_NULL;
  4754. pData->fCorrectrow = MNG_NULL;
  4755. pData->fStorerow = MNG_NULL;
  4756. pData->fProcessrow = MNG_NULL;
  4757. pData->pStoreobj = MNG_NULL;
  4758. pData->fDeltagetrow = MNG_NULL;
  4759. pData->fDeltaaddrow = MNG_NULL;
  4760. pData->fDeltareplacerow = MNG_NULL;
  4761. pData->fDeltaputrow = MNG_NULL;
  4762. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4763. pImage = mng_find_imageobject (pData, iObjectid);
  4764. #else
  4765. pImage = mng_find_imageobject (pData, pData->iDHDRobjectid);
  4766. #endif
  4767. if (pImage) /* object exists ? */
  4768. {
  4769. if (pImage->pImgbuf->bConcrete) /* is it concrete ? */
  4770. { /* previous magnification to be done ? */
  4771. #ifndef MNG_SKIPCHUNK_MAGN
  4772. if ((pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY))
  4773. {
  4774. iRetcode = mng_magnify_imageobject (pData, pImage);
  4775. if (iRetcode) /* on error bail out */
  4776. return iRetcode;
  4777. }
  4778. #endif
  4779. /* save delta fields */
  4780. pData->pDeltaImage = (mng_ptr)pImage;
  4781. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4782. pData->iDeltaImagetype = iImagetype;
  4783. pData->iDeltatype = iDeltatype;
  4784. pData->iDeltaBlockwidth = iBlockwidth;
  4785. pData->iDeltaBlockheight = iBlockheight;
  4786. pData->iDeltaBlockx = iBlockx;
  4787. pData->iDeltaBlocky = iBlocky;
  4788. #else
  4789. pData->iDeltaImagetype = pData->iDHDRimagetype;
  4790. pData->iDeltatype = pData->iDHDRdeltatype;
  4791. pData->iDeltaBlockwidth = pData->iDHDRblockwidth;
  4792. pData->iDeltaBlockheight = pData->iDHDRblockheight;
  4793. pData->iDeltaBlockx = pData->iDHDRblockx;
  4794. pData->iDeltaBlocky = pData->iDHDRblocky;
  4795. #endif
  4796. /* restore target-object fields */
  4797. pData->iDatawidth = pImage->pImgbuf->iWidth;
  4798. pData->iDataheight = pImage->pImgbuf->iHeight;
  4799. pData->iBitdepth = pImage->pImgbuf->iBitdepth;
  4800. pData->iColortype = pImage->pImgbuf->iColortype;
  4801. pData->iCompression = pImage->pImgbuf->iCompression;
  4802. pData->iFilter = pImage->pImgbuf->iFilter;
  4803. pData->iInterlace = pImage->pImgbuf->iInterlace;
  4804. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4805. if ((iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
  4806. (iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
  4807. pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth;
  4808. else
  4809. if ((iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
  4810. (iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
  4811. pData->iBitdepth = pImage->pImgbuf->iAlphasampledepth;
  4812. else
  4813. if ((iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
  4814. (iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
  4815. pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth;
  4816. #else
  4817. if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
  4818. (pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
  4819. pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth;
  4820. else
  4821. if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
  4822. (pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
  4823. pData->iBitdepth = pImage->pImgbuf->iAlphasampledepth;
  4824. else
  4825. if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
  4826. (pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
  4827. pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth;
  4828. #endif
  4829. #ifdef MNG_INCLUDE_JNG
  4830. pData->iJHDRimgbitdepth = pImage->pImgbuf->iBitdepth;
  4831. pData->iJHDRcolortype = pImage->pImgbuf->iColortype;
  4832. pData->iJHDRimgcompression = pImage->pImgbuf->iJHDRcompression;
  4833. pData->iJHDRimginterlace = pImage->pImgbuf->iJHDRinterlace;
  4834. pData->iJHDRalphacompression = pImage->pImgbuf->iCompression;
  4835. pData->iJHDRalphafilter = pImage->pImgbuf->iFilter;
  4836. pData->iJHDRalphainterlace = pImage->pImgbuf->iInterlace;
  4837. pData->iJHDRalphabitdepth = pImage->pImgbuf->iAlphabitdepth;
  4838. #endif
  4839. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4840. /* block size specified ? */
  4841. if (iDeltatype != MNG_DELTATYPE_NOCHANGE)
  4842. { /* block entirely within target ? */
  4843. if (iDeltatype != MNG_DELTATYPE_REPLACE)
  4844. {
  4845. if (((iBlockx + iBlockwidth ) > pData->iDatawidth ) ||
  4846. ((iBlocky + iBlockheight) > pData->iDataheight) )
  4847. MNG_ERROR (pData, MNG_INVALIDBLOCK);
  4848. }
  4849. pData->iDatawidth = iBlockwidth;
  4850. pData->iDataheight = iBlockheight;
  4851. }
  4852. #else
  4853. /* block size specified ? */
  4854. if (pData->iDHDRdeltatype != MNG_DELTATYPE_NOCHANGE)
  4855. { /* block entirely within target ? */
  4856. if (pData->iDHDRdeltatype != MNG_DELTATYPE_REPLACE)
  4857. {
  4858. if (((pData->iDHDRblockx + pData->iDHDRblockwidth ) > pData->iDatawidth ) ||
  4859. ((pData->iDHDRblocky + pData->iDHDRblockheight) > pData->iDataheight) )
  4860. MNG_ERROR (pData, MNG_INVALIDBLOCK);
  4861. }
  4862. pData->iDatawidth = pData->iDHDRblockwidth;
  4863. pData->iDataheight = pData->iDHDRblockheight;
  4864. }
  4865. #endif
  4866. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4867. switch (iDeltatype) /* determine nr of delta-channels */
  4868. #else
  4869. switch (pData->iDHDRdeltatype) /* determine nr of delta-channels */
  4870. #endif
  4871. {
  4872. case MNG_DELTATYPE_BLOCKALPHAADD : ;
  4873. case MNG_DELTATYPE_BLOCKALPHAREPLACE :
  4874. {
  4875. #ifdef MNG_INCLUDE_JNG
  4876. if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) ||
  4877. (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) )
  4878. {
  4879. pData->iColortype = MNG_COLORTYPE_GRAY;
  4880. pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY;
  4881. }
  4882. else
  4883. if ((pData->iColortype == MNG_COLORTYPE_RGBA ) ||
  4884. (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) )
  4885. {
  4886. pData->iColortype = MNG_COLORTYPE_GRAY;
  4887. pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY;
  4888. }
  4889. #else
  4890. if (pData->iColortype == MNG_COLORTYPE_GRAYA)
  4891. pData->iColortype = MNG_COLORTYPE_GRAY;
  4892. else
  4893. if (pData->iColortype == MNG_COLORTYPE_RGBA)
  4894. pData->iColortype = MNG_COLORTYPE_GRAY;
  4895. #endif
  4896. else /* target has no alpha; that sucks! */
  4897. MNG_ERROR (pData, MNG_TARGETNOALPHA);
  4898. break;
  4899. }
  4900. case MNG_DELTATYPE_BLOCKCOLORADD : ;
  4901. case MNG_DELTATYPE_BLOCKCOLORREPLACE :
  4902. {
  4903. #ifdef MNG_INCLUDE_JNG
  4904. if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) ||
  4905. (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) )
  4906. {
  4907. pData->iColortype = MNG_COLORTYPE_GRAY;
  4908. pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY;
  4909. }
  4910. else
  4911. if ((pData->iColortype == MNG_COLORTYPE_RGBA ) ||
  4912. (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) )
  4913. {
  4914. pData->iColortype = MNG_COLORTYPE_RGB;
  4915. pData->iJHDRcolortype = MNG_COLORTYPE_JPEGCOLOR;
  4916. }
  4917. #else
  4918. if (pData->iColortype == MNG_COLORTYPE_GRAYA)
  4919. pData->iColortype = MNG_COLORTYPE_GRAY;
  4920. else
  4921. if (pData->iColortype == MNG_COLORTYPE_RGBA)
  4922. pData->iColortype = MNG_COLORTYPE_RGB;
  4923. #endif
  4924. else /* target has no alpha; that sucks! */
  4925. MNG_ERROR (pData, MNG_TARGETNOALPHA);
  4926. break;
  4927. }
  4928. }
  4929. /* full image replace ? */
  4930. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  4931. if (iDeltatype == MNG_DELTATYPE_REPLACE)
  4932. #else
  4933. if (pData->iDHDRdeltatype == MNG_DELTATYPE_REPLACE)
  4934. #endif
  4935. {
  4936. iRetcode = mng_reset_object_details (pData, pImage,
  4937. pData->iDatawidth, pData->iDataheight,
  4938. pData->iBitdepth, pData->iColortype,
  4939. pData->iCompression, pData->iFilter,
  4940. pData->iInterlace, MNG_FALSE);
  4941. if (iRetcode) /* on error bail out */
  4942. return iRetcode;
  4943. pData->pStoreobj = pImage; /* and store straight into this object */
  4944. }
  4945. else
  4946. {
  4947. mng_imagedatap pBufzero, pBuf;
  4948. /* we store in object 0 and process it later */
  4949. pData->pStoreobj = pData->pObjzero;
  4950. /* make sure to initialize object 0 then */
  4951. iRetcode = mng_reset_object_details (pData, (mng_imagep)pData->pObjzero,
  4952. pData->iDatawidth, pData->iDataheight,
  4953. pData->iBitdepth, pData->iColortype,
  4954. pData->iCompression, pData->iFilter,
  4955. pData->iInterlace, MNG_TRUE);
  4956. if (iRetcode) /* on error bail out */
  4957. return iRetcode;
  4958. pBuf = pImage->pImgbuf; /* copy possible palette & cheap transparency */
  4959. pBufzero = ((mng_imagep)pData->pObjzero)->pImgbuf;
  4960. pBufzero->bHasPLTE = pBuf->bHasPLTE;
  4961. pBufzero->bHasTRNS = pBuf->bHasTRNS;
  4962. if (pBufzero->bHasPLTE) /* copy palette ? */
  4963. {
  4964. mng_uint32 iX;
  4965. pBufzero->iPLTEcount = pBuf->iPLTEcount;
  4966. for (iX = 0; iX < pBuf->iPLTEcount; iX++)
  4967. {
  4968. pBufzero->aPLTEentries [iX].iRed = pBuf->aPLTEentries [iX].iRed;
  4969. pBufzero->aPLTEentries [iX].iGreen = pBuf->aPLTEentries [iX].iGreen;
  4970. pBufzero->aPLTEentries [iX].iBlue = pBuf->aPLTEentries [iX].iBlue;
  4971. }
  4972. }
  4973. if (pBufzero->bHasTRNS) /* copy cheap transparency ? */
  4974. {
  4975. pBufzero->iTRNSgray = pBuf->iTRNSgray;
  4976. pBufzero->iTRNSred = pBuf->iTRNSred;
  4977. pBufzero->iTRNSgreen = pBuf->iTRNSgreen;
  4978. pBufzero->iTRNSblue = pBuf->iTRNSblue;
  4979. pBufzero->iTRNScount = pBuf->iTRNScount;
  4980. MNG_COPY (pBufzero->aTRNSentries, pBuf->aTRNSentries,
  4981. sizeof (pBufzero->aTRNSentries));
  4982. }
  4983. /* process immediately if bitdepth & colortype are equal */
  4984. pData->bDeltaimmediate =
  4985. (mng_bool)((pData->bDisplaying) && (!pData->bSkipping) &&
  4986. ((pData->bRunning) || (pData->bSearching)) &&
  4987. (pData->iBitdepth == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iBitdepth ) &&
  4988. (pData->iColortype == ((mng_imagep)pData->pDeltaImage)->pImgbuf->iColortype) );
  4989. }
  4990. #ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
  4991. pData->fInitrowproc = (mng_fptr)mng_init_rowproc;
  4992. pData->ePng_imgtype = mng_png_imgtype (pData->iColortype, pData->iBitdepth);
  4993. #else
  4994. switch (pData->iColortype) /* determine row initialization routine */
  4995. {
  4996. case 0 : { /* gray */
  4997. switch (pData->iBitdepth)
  4998. {
  4999. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  5000. case 1 : {
  5001. if (!pData->iInterlace)
  5002. pData->fInitrowproc = (mng_fptr)mng_init_g1_ni;
  5003. else
  5004. pData->fInitrowproc = (mng_fptr)mng_init_g1_i;
  5005. break;
  5006. }
  5007. case 2 : {
  5008. if (!pData->iInterlace)
  5009. pData->fInitrowproc = (mng_fptr)mng_init_g2_ni;
  5010. else
  5011. pData->fInitrowproc = (mng_fptr)mng_init_g2_i;
  5012. break;
  5013. }
  5014. case 4 : {
  5015. if (!pData->iInterlace)
  5016. pData->fInitrowproc = (mng_fptr)mng_init_g4_ni;
  5017. else
  5018. pData->fInitrowproc = (mng_fptr)mng_init_g4_i;
  5019. break;
  5020. }
  5021. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  5022. case 8 : {
  5023. if (!pData->iInterlace)
  5024. pData->fInitrowproc = (mng_fptr)mng_init_g8_ni;
  5025. else
  5026. pData->fInitrowproc = (mng_fptr)mng_init_g8_i;
  5027. break;
  5028. }
  5029. #ifndef MNG_NO_16BIT_SUPPORT
  5030. case 16 : {
  5031. if (!pData->iInterlace)
  5032. pData->fInitrowproc = (mng_fptr)mng_init_g16_ni;
  5033. else
  5034. pData->fInitrowproc = (mng_fptr)mng_init_g16_i;
  5035. break;
  5036. }
  5037. #endif
  5038. }
  5039. break;
  5040. }
  5041. case 2 : { /* rgb */
  5042. switch (pData->iBitdepth)
  5043. {
  5044. case 8 : {
  5045. if (!pData->iInterlace)
  5046. pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni;
  5047. else
  5048. pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i;
  5049. break;
  5050. }
  5051. #ifndef MNG_NO_16BIT_SUPPORT
  5052. case 16 : {
  5053. if (!pData->iInterlace)
  5054. pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni;
  5055. else
  5056. pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i;
  5057. break;
  5058. }
  5059. #endif
  5060. }
  5061. break;
  5062. }
  5063. case 3 : { /* indexed */
  5064. switch (pData->iBitdepth)
  5065. {
  5066. #ifndef MNG_NO_1_2_4BIT_SUPPORT
  5067. case 1 : {
  5068. if (!pData->iInterlace)
  5069. pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni;
  5070. else
  5071. pData->fInitrowproc = (mng_fptr)mng_init_idx1_i;
  5072. break;
  5073. }
  5074. case 2 : {
  5075. if (!pData->iInterlace)
  5076. pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni;
  5077. else
  5078. pData->fInitrowproc = (mng_fptr)mng_init_idx2_i;
  5079. break;
  5080. }
  5081. case 4 : {
  5082. if (!pData->iInterlace)
  5083. pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni;
  5084. else
  5085. pData->fInitrowproc = (mng_fptr)mng_init_idx4_i;
  5086. break;
  5087. }
  5088. #endif /* MNG_NO_1_2_4BIT_SUPPORT */
  5089. case 8 : {
  5090. if (!pData->iInterlace)
  5091. pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni;
  5092. else
  5093. pData->fInitrowproc = (mng_fptr)mng_init_idx8_i;
  5094. break;
  5095. }
  5096. }
  5097. break;
  5098. }
  5099. case 4 : { /* gray+alpha */
  5100. switch (pData->iBitdepth)
  5101. {
  5102. case 8 : {
  5103. if (!pData->iInterlace)
  5104. pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni;
  5105. else
  5106. pData->fInitrowproc = (mng_fptr)mng_init_ga8_i;
  5107. break;
  5108. }
  5109. #ifndef MNG_NO_16BIT_SUPPORT
  5110. case 16 : {
  5111. if (!pData->iInterlace)
  5112. pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni;
  5113. else
  5114. pData->fInitrowproc = (mng_fptr)mng_init_ga16_i;
  5115. break;
  5116. }
  5117. #endif
  5118. }
  5119. break;
  5120. }
  5121. case 6 : { /* rgb+alpha */
  5122. switch (pData->iBitdepth)
  5123. {
  5124. case 8 : {
  5125. if (!pData->iInterlace)
  5126. pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni;
  5127. else
  5128. pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i;
  5129. break;
  5130. }
  5131. #ifndef MNG_NO_16BIT_SUPPORT
  5132. case 16 : {
  5133. if (!pData->iInterlace)
  5134. pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni;
  5135. else
  5136. pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i;
  5137. break;
  5138. }
  5139. #endif
  5140. }
  5141. break;
  5142. }
  5143. }
  5144. #endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
  5145. }
  5146. else
  5147. MNG_ERROR (pData, MNG_OBJNOTCONCRETE);
  5148. }
  5149. else
  5150. MNG_ERROR (pData, MNG_OBJECTUNKNOWN);
  5151. #ifdef MNG_SUPPORT_TRACE
  5152. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DHDR, MNG_LC_END);
  5153. #endif
  5154. return MNG_NOERROR;
  5155. }
  5156. #endif
  5157. /* ************************************************************************** */
  5158. #ifndef MNG_NO_DELTA_PNG
  5159. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5160. mng_retcode mng_process_display_prom (mng_datap pData,
  5161. mng_uint8 iBitdepth,
  5162. mng_uint8 iColortype,
  5163. mng_uint8 iFilltype)
  5164. #else
  5165. mng_retcode mng_process_display_prom (mng_datap pData)
  5166. #endif
  5167. {
  5168. mng_imagep pImage;
  5169. mng_imagedatap pBuf;
  5170. mng_retcode iRetcode;
  5171. #ifdef MNG_SUPPORT_TRACE
  5172. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PROM, MNG_LC_START);
  5173. #endif
  5174. if (!pData->pDeltaImage) /* gotta have this now! */
  5175. MNG_ERROR (pData, MNG_INVALIDDELTA);
  5176. pImage = (mng_imagep)pData->pDeltaImage;
  5177. pBuf = pImage->pImgbuf;
  5178. /* can't demote bitdepth! */
  5179. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5180. if (iBitdepth < pBuf->iBitdepth)
  5181. MNG_ERROR (pData, MNG_INVALIDBITDEPTH);
  5182. if ( ((pBuf->iColortype == MNG_COLORTYPE_GRAY ) &&
  5183. (iColortype != MNG_COLORTYPE_GRAY ) &&
  5184. (iColortype != MNG_COLORTYPE_GRAYA ) &&
  5185. (iColortype != MNG_COLORTYPE_RGB ) &&
  5186. (iColortype != MNG_COLORTYPE_RGBA ) ) ||
  5187. ((pBuf->iColortype == MNG_COLORTYPE_GRAYA ) &&
  5188. (iColortype != MNG_COLORTYPE_GRAYA ) &&
  5189. (iColortype != MNG_COLORTYPE_RGBA ) ) ||
  5190. ((pBuf->iColortype == MNG_COLORTYPE_RGB ) &&
  5191. (iColortype != MNG_COLORTYPE_RGB ) &&
  5192. (iColortype != MNG_COLORTYPE_RGBA ) ) ||
  5193. ((pBuf->iColortype == MNG_COLORTYPE_RGBA ) &&
  5194. (iColortype != MNG_COLORTYPE_RGBA ) ) ||
  5195. #ifdef MNG_INCLUDE_JNG
  5196. ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY ) &&
  5197. (iColortype != MNG_COLORTYPE_JPEGGRAY ) &&
  5198. (iColortype != MNG_COLORTYPE_JPEGCOLOR ) &&
  5199. (iColortype != MNG_COLORTYPE_JPEGGRAYA ) &&
  5200. (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) ||
  5201. ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLOR ) &&
  5202. (iColortype != MNG_COLORTYPE_JPEGCOLOR ) &&
  5203. (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) ||
  5204. ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAYA ) &&
  5205. (iColortype != MNG_COLORTYPE_JPEGGRAYA ) &&
  5206. (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) ||
  5207. ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLORA) &&
  5208. (iColortype != MNG_COLORTYPE_JPEGCOLORA) ) ||
  5209. #endif
  5210. ((pBuf->iColortype == MNG_COLORTYPE_INDEXED ) &&
  5211. (iColortype != MNG_COLORTYPE_INDEXED ) &&
  5212. (iColortype != MNG_COLORTYPE_RGB ) &&
  5213. (iColortype != MNG_COLORTYPE_RGBA ) ) )
  5214. MNG_ERROR (pData, MNG_INVALIDCOLORTYPE);
  5215. iRetcode = mng_promote_imageobject (pData, pImage, iBitdepth, iColortype, iFilltype);
  5216. #else
  5217. if (pData->iPROMbitdepth < pBuf->iBitdepth)
  5218. MNG_ERROR (pData, MNG_INVALIDBITDEPTH);
  5219. if ( ((pBuf->iColortype == MNG_COLORTYPE_GRAY ) &&
  5220. (pData->iPROMcolortype != MNG_COLORTYPE_GRAY ) &&
  5221. (pData->iPROMcolortype != MNG_COLORTYPE_GRAYA ) &&
  5222. (pData->iPROMcolortype != MNG_COLORTYPE_RGB ) &&
  5223. (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) ||
  5224. ((pBuf->iColortype == MNG_COLORTYPE_GRAYA ) &&
  5225. (pData->iPROMcolortype != MNG_COLORTYPE_GRAYA ) &&
  5226. (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) ||
  5227. ((pBuf->iColortype == MNG_COLORTYPE_RGB ) &&
  5228. (pData->iPROMcolortype != MNG_COLORTYPE_RGB ) &&
  5229. (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) ||
  5230. ((pBuf->iColortype == MNG_COLORTYPE_RGBA ) &&
  5231. (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) ||
  5232. #ifdef MNG_INCLUDE_JNG
  5233. ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAY ) &&
  5234. (pData->iPROMcolortype != MNG_COLORTYPE_JPEGGRAY ) &&
  5235. (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLOR ) &&
  5236. (pData->iPROMcolortype != MNG_COLORTYPE_JPEGGRAYA ) &&
  5237. (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) ||
  5238. ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLOR ) &&
  5239. (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLOR ) &&
  5240. (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) ||
  5241. ((pBuf->iColortype == MNG_COLORTYPE_JPEGGRAYA ) &&
  5242. (pData->iPROMcolortype != MNG_COLORTYPE_JPEGGRAYA ) &&
  5243. (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) ||
  5244. ((pBuf->iColortype == MNG_COLORTYPE_JPEGCOLORA) &&
  5245. (pData->iPROMcolortype != MNG_COLORTYPE_JPEGCOLORA) ) ||
  5246. #endif
  5247. ((pBuf->iColortype == MNG_COLORTYPE_INDEXED ) &&
  5248. (pData->iPROMcolortype != MNG_COLORTYPE_INDEXED ) &&
  5249. (pData->iPROMcolortype != MNG_COLORTYPE_RGB ) &&
  5250. (pData->iPROMcolortype != MNG_COLORTYPE_RGBA ) ) )
  5251. MNG_ERROR (pData, MNG_INVALIDCOLORTYPE);
  5252. iRetcode = mng_promote_imageobject (pData, pImage, pData->iPROMbitdepth,
  5253. pData->iPROMcolortype, pData->iPROMfilltype);
  5254. #endif
  5255. if (iRetcode) /* on error bail out */
  5256. return iRetcode;
  5257. #ifdef MNG_SUPPORT_TRACE
  5258. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PROM, MNG_LC_END);
  5259. #endif
  5260. return MNG_NOERROR;
  5261. }
  5262. #endif
  5263. /* ************************************************************************** */
  5264. #ifndef MNG_NO_DELTA_PNG
  5265. mng_retcode mng_process_display_ipng (mng_datap pData)
  5266. {
  5267. #ifdef MNG_SUPPORT_TRACE
  5268. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IPNG, MNG_LC_START);
  5269. #endif
  5270. /* indicate it for what it is now */
  5271. pData->iDeltaImagetype = MNG_IMAGETYPE_PNG;
  5272. #ifdef MNG_SUPPORT_TRACE
  5273. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IPNG, MNG_LC_END);
  5274. #endif
  5275. return MNG_NOERROR;
  5276. }
  5277. #endif
  5278. /* ************************************************************************** */
  5279. #ifndef MNG_NO_DELTA_PNG
  5280. #ifdef MNG_INCLUDE_JNG
  5281. mng_retcode mng_process_display_ijng (mng_datap pData)
  5282. {
  5283. #ifdef MNG_SUPPORT_TRACE
  5284. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IJNG, MNG_LC_START);
  5285. #endif
  5286. /* indicate it for what it is now */
  5287. pData->iDeltaImagetype = MNG_IMAGETYPE_JNG;
  5288. #ifdef MNG_SUPPORT_TRACE
  5289. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IJNG, MNG_LC_END);
  5290. #endif
  5291. return MNG_NOERROR;
  5292. }
  5293. #endif
  5294. #endif
  5295. /* ************************************************************************** */
  5296. #ifndef MNG_NO_DELTA_PNG
  5297. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5298. mng_retcode mng_process_display_pplt (mng_datap pData,
  5299. mng_uint8 iType,
  5300. mng_uint32 iCount,
  5301. mng_palette8ep paIndexentries,
  5302. mng_uint8p paAlphaentries,
  5303. mng_uint8p paUsedentries)
  5304. #else
  5305. mng_retcode mng_process_display_pplt (mng_datap pData)
  5306. #endif
  5307. {
  5308. mng_uint32 iX;
  5309. mng_imagep pImage = (mng_imagep)pData->pObjzero;
  5310. mng_imagedatap pBuf = pImage->pImgbuf;
  5311. #ifdef MNG_SUPPORT_TRACE
  5312. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PPLT, MNG_LC_START);
  5313. #endif
  5314. #ifdef MNG_DECREMENT_LOOPS
  5315. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5316. iX = iCount;
  5317. #else
  5318. iX = pData->iPPLTcount;
  5319. #endif
  5320. #endif
  5321. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5322. switch (iType)
  5323. #else
  5324. switch (pData->iPPLTtype)
  5325. #endif
  5326. {
  5327. case MNG_DELTATYPE_REPLACERGB :
  5328. {
  5329. #ifdef MNG_DECREMENT_LOOPS
  5330. for (; iX > 0;iX--)
  5331. #else
  5332. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5333. for (iX = 0; iX < iCount; iX++)
  5334. #else
  5335. for (iX = 0; iX < pData->iPPLTcount; iX++)
  5336. #endif
  5337. #endif
  5338. {
  5339. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5340. if (paUsedentries [iX])
  5341. {
  5342. pBuf->aPLTEentries [iX].iRed = paIndexentries [iX].iRed;
  5343. pBuf->aPLTEentries [iX].iGreen = paIndexentries [iX].iGreen;
  5344. pBuf->aPLTEentries [iX].iBlue = paIndexentries [iX].iBlue;
  5345. }
  5346. #else
  5347. if (pData->paPPLTusedentries [iX])
  5348. {
  5349. pBuf->aPLTEentries [iX].iRed = pData->paPPLTindexentries [iX].iRed;
  5350. pBuf->aPLTEentries [iX].iGreen = pData->paPPLTindexentries [iX].iGreen;
  5351. pBuf->aPLTEentries [iX].iBlue = pData->paPPLTindexentries [iX].iBlue;
  5352. }
  5353. #endif
  5354. }
  5355. break;
  5356. }
  5357. case MNG_DELTATYPE_DELTARGB :
  5358. {
  5359. #ifdef MNG_DECREMENT_LOOPS
  5360. for (; iX > 0;iX--)
  5361. #else
  5362. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5363. for (iX = 0; iX < iCount; iX++)
  5364. #else
  5365. for (iX = 0; iX < pData->iPPLTcount; iX++)
  5366. #endif
  5367. #endif
  5368. {
  5369. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5370. if (paUsedentries [iX])
  5371. {
  5372. pBuf->aPLTEentries [iX].iRed =
  5373. (mng_uint8)(pBuf->aPLTEentries [iX].iRed +
  5374. paIndexentries [iX].iRed );
  5375. pBuf->aPLTEentries [iX].iGreen =
  5376. (mng_uint8)(pBuf->aPLTEentries [iX].iGreen +
  5377. paIndexentries [iX].iGreen);
  5378. pBuf->aPLTEentries [iX].iBlue =
  5379. (mng_uint8)(pBuf->aPLTEentries [iX].iBlue +
  5380. paIndexentries [iX].iBlue );
  5381. }
  5382. #else
  5383. if (pData->paPPLTusedentries [iX])
  5384. {
  5385. pBuf->aPLTEentries [iX].iRed =
  5386. (mng_uint8)(pBuf->aPLTEentries [iX].iRed +
  5387. pData->paPPLTindexentries [iX].iRed );
  5388. pBuf->aPLTEentries [iX].iGreen =
  5389. (mng_uint8)(pBuf->aPLTEentries [iX].iGreen +
  5390. pData->paPPLTindexentries [iX].iGreen);
  5391. pBuf->aPLTEentries [iX].iBlue =
  5392. (mng_uint8)(pBuf->aPLTEentries [iX].iBlue +
  5393. pData->paPPLTindexentries [iX].iBlue );
  5394. }
  5395. #endif
  5396. }
  5397. break;
  5398. }
  5399. case MNG_DELTATYPE_REPLACEALPHA :
  5400. {
  5401. #ifdef MNG_DECREMENT_LOOPS
  5402. for (; iX > 0;iX--)
  5403. #else
  5404. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5405. for (iX = 0; iX < iCount; iX++)
  5406. #else
  5407. for (iX = 0; iX < pData->iPPLTcount; iX++)
  5408. #endif
  5409. #endif
  5410. {
  5411. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5412. if (paUsedentries [iX])
  5413. pBuf->aTRNSentries [iX] = paAlphaentries [iX];
  5414. }
  5415. #else
  5416. if (pData->paPPLTusedentries [iX])
  5417. pBuf->aTRNSentries [iX] = pData->paPPLTalphaentries [iX];
  5418. }
  5419. #endif
  5420. break;
  5421. }
  5422. case MNG_DELTATYPE_DELTAALPHA :
  5423. {
  5424. #ifdef MNG_DECREMENT_LOOPS
  5425. for (; iX > 0;iX--)
  5426. #else
  5427. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5428. for (iX = 0; iX < iCount; iX++)
  5429. #else
  5430. for (iX = 0; iX < pData->iPPLTcount; iX++)
  5431. #endif
  5432. #endif
  5433. {
  5434. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5435. if (paUsedentries [iX])
  5436. pBuf->aTRNSentries [iX] =
  5437. (mng_uint8)(pBuf->aTRNSentries [iX] +
  5438. paAlphaentries [iX]);
  5439. #else
  5440. if (pData->paPPLTusedentries [iX])
  5441. pBuf->aTRNSentries [iX] =
  5442. (mng_uint8)(pBuf->aTRNSentries [iX] +
  5443. pData->paPPLTalphaentries [iX]);
  5444. #endif
  5445. }
  5446. break;
  5447. }
  5448. case MNG_DELTATYPE_REPLACERGBA :
  5449. {
  5450. #ifdef MNG_DECREMENT_LOOPS
  5451. for (; iX > 0;iX--)
  5452. #else
  5453. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5454. for (iX = 0; iX < iCount; iX++)
  5455. #else
  5456. for (iX = 0; iX < pData->iPPLTcount; iX++)
  5457. #endif
  5458. #endif
  5459. {
  5460. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5461. if (paUsedentries [iX])
  5462. {
  5463. pBuf->aPLTEentries [iX].iRed = paIndexentries [iX].iRed;
  5464. pBuf->aPLTEentries [iX].iGreen = paIndexentries [iX].iGreen;
  5465. pBuf->aPLTEentries [iX].iBlue = paIndexentries [iX].iBlue;
  5466. pBuf->aTRNSentries [iX] = paAlphaentries [iX];
  5467. }
  5468. #else
  5469. if (pData->paPPLTusedentries [iX])
  5470. {
  5471. pBuf->aPLTEentries [iX].iRed = pData->paPPLTindexentries [iX].iRed;
  5472. pBuf->aPLTEentries [iX].iGreen = pData->paPPLTindexentries [iX].iGreen;
  5473. pBuf->aPLTEentries [iX].iBlue = pData->paPPLTindexentries [iX].iBlue;
  5474. pBuf->aTRNSentries [iX] = pData->paPPLTalphaentries [iX];
  5475. }
  5476. #endif
  5477. }
  5478. break;
  5479. }
  5480. case MNG_DELTATYPE_DELTARGBA :
  5481. {
  5482. #ifdef MNG_DECREMENT_LOOPS
  5483. for (; iX > 0;iX--)
  5484. #else
  5485. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5486. for (iX = 0; iX < iCount; iX++)
  5487. #else
  5488. for (iX = 0; iX < pData->iPPLTcount; iX++)
  5489. #endif
  5490. #endif
  5491. {
  5492. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5493. if (paUsedentries [iX])
  5494. {
  5495. pBuf->aPLTEentries [iX].iRed =
  5496. (mng_uint8)(pBuf->aPLTEentries [iX].iRed +
  5497. paIndexentries [iX].iRed );
  5498. pBuf->aPLTEentries [iX].iGreen =
  5499. (mng_uint8)(pBuf->aPLTEentries [iX].iGreen +
  5500. paIndexentries [iX].iGreen);
  5501. pBuf->aPLTEentries [iX].iBlue =
  5502. (mng_uint8)(pBuf->aPLTEentries [iX].iBlue +
  5503. paIndexentries [iX].iBlue );
  5504. pBuf->aTRNSentries [iX] =
  5505. (mng_uint8)(pBuf->aTRNSentries [iX] +
  5506. paAlphaentries [iX]);
  5507. }
  5508. #else
  5509. if (pData->paPPLTusedentries [iX])
  5510. {
  5511. pBuf->aPLTEentries [iX].iRed =
  5512. (mng_uint8)(pBuf->aPLTEentries [iX].iRed +
  5513. pData->paPPLTindexentries [iX].iRed );
  5514. pBuf->aPLTEentries [iX].iGreen =
  5515. (mng_uint8)(pBuf->aPLTEentries [iX].iGreen +
  5516. pData->paPPLTindexentries [iX].iGreen);
  5517. pBuf->aPLTEentries [iX].iBlue =
  5518. (mng_uint8)(pBuf->aPLTEentries [iX].iBlue +
  5519. pData->paPPLTindexentries [iX].iBlue );
  5520. pBuf->aTRNSentries [iX] =
  5521. (mng_uint8)(pBuf->aTRNSentries [iX] +
  5522. pData->paPPLTalphaentries [iX]);
  5523. }
  5524. #endif
  5525. }
  5526. break;
  5527. }
  5528. }
  5529. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5530. if ((iType != MNG_DELTATYPE_REPLACERGB) && (iType != MNG_DELTATYPE_DELTARGB))
  5531. #else
  5532. if ((pData->iPPLTtype != MNG_DELTATYPE_REPLACERGB) &&
  5533. (pData->iPPLTtype != MNG_DELTATYPE_DELTARGB ) )
  5534. #endif
  5535. {
  5536. if (pBuf->bHasTRNS)
  5537. {
  5538. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5539. if (iCount > pBuf->iTRNScount)
  5540. pBuf->iTRNScount = iCount;
  5541. #else
  5542. if (pData->iPPLTcount > pBuf->iTRNScount)
  5543. pBuf->iTRNScount = pData->iPPLTcount;
  5544. #endif
  5545. }
  5546. else
  5547. {
  5548. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5549. pBuf->iTRNScount = iCount;
  5550. pBuf->bHasTRNS = MNG_TRUE;
  5551. #else
  5552. pBuf->iTRNScount = pData->iPPLTcount;
  5553. pBuf->bHasTRNS = MNG_TRUE;
  5554. #endif
  5555. }
  5556. }
  5557. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5558. if ((iType != MNG_DELTATYPE_REPLACEALPHA) && (iType != MNG_DELTATYPE_DELTAALPHA))
  5559. #else
  5560. if ((pData->iPPLTtype != MNG_DELTATYPE_REPLACEALPHA) &&
  5561. (pData->iPPLTtype != MNG_DELTATYPE_DELTAALPHA ) )
  5562. #endif
  5563. {
  5564. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5565. if (iCount > pBuf->iPLTEcount)
  5566. pBuf->iPLTEcount = iCount;
  5567. #else
  5568. if (pData->iPPLTcount > pBuf->iPLTEcount)
  5569. pBuf->iPLTEcount = pData->iPPLTcount;
  5570. #endif
  5571. }
  5572. #ifdef MNG_SUPPORT_TRACE
  5573. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PPLT, MNG_LC_END);
  5574. #endif
  5575. return MNG_NOERROR;
  5576. }
  5577. #endif
  5578. /* ************************************************************************** */
  5579. #ifndef MNG_SKIPCHUNK_MAGN
  5580. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5581. mng_retcode mng_process_display_magn (mng_datap pData,
  5582. mng_uint16 iFirstid,
  5583. mng_uint16 iLastid,
  5584. mng_uint8 iMethodX,
  5585. mng_uint16 iMX,
  5586. mng_uint16 iMY,
  5587. mng_uint16 iML,
  5588. mng_uint16 iMR,
  5589. mng_uint16 iMT,
  5590. mng_uint16 iMB,
  5591. mng_uint8 iMethodY)
  5592. #else
  5593. mng_retcode mng_process_display_magn (mng_datap pData)
  5594. #endif
  5595. {
  5596. mng_uint16 iX;
  5597. mng_imagep pImage;
  5598. #ifdef MNG_SUPPORT_TRACE
  5599. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_START);
  5600. #endif
  5601. /* iterate the object-ids */
  5602. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5603. for (iX = iFirstid; iX <= iLastid; iX++)
  5604. #else
  5605. for (iX = pData->iMAGNfirstid; iX <= pData->iMAGNlastid; iX++)
  5606. #endif
  5607. {
  5608. if (iX == 0) /* process object 0 ? */
  5609. {
  5610. pImage = (mng_imagep)pData->pObjzero;
  5611. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5612. pImage->iMAGN_MethodX = iMethodX;
  5613. pImage->iMAGN_MethodY = iMethodY;
  5614. pImage->iMAGN_MX = iMX;
  5615. pImage->iMAGN_MY = iMY;
  5616. pImage->iMAGN_ML = iML;
  5617. pImage->iMAGN_MR = iMR;
  5618. pImage->iMAGN_MT = iMT;
  5619. pImage->iMAGN_MB = iMB;
  5620. #else
  5621. pImage->iMAGN_MethodX = pData->iMAGNmethodX;
  5622. pImage->iMAGN_MethodY = pData->iMAGNmethodY;
  5623. pImage->iMAGN_MX = pData->iMAGNmX;
  5624. pImage->iMAGN_MY = pData->iMAGNmY;
  5625. pImage->iMAGN_ML = pData->iMAGNmL;
  5626. pImage->iMAGN_MR = pData->iMAGNmR;
  5627. pImage->iMAGN_MT = pData->iMAGNmT;
  5628. pImage->iMAGN_MB = pData->iMAGNmB;
  5629. #endif
  5630. }
  5631. else
  5632. {
  5633. pImage = mng_find_imageobject (pData, iX);
  5634. /* object exists & is not frozen ? */
  5635. if ((pImage) && (!pImage->bFrozen))
  5636. { /* previous magnification to be done ? */
  5637. if ((pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY))
  5638. {
  5639. mng_retcode iRetcode = mng_magnify_imageobject (pData, pImage);
  5640. if (iRetcode) /* on error bail out */
  5641. return iRetcode;
  5642. }
  5643. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5644. pImage->iMAGN_MethodX = iMethodX;
  5645. pImage->iMAGN_MethodY = iMethodY;
  5646. pImage->iMAGN_MX = iMX;
  5647. pImage->iMAGN_MY = iMY;
  5648. pImage->iMAGN_ML = iML;
  5649. pImage->iMAGN_MR = iMR;
  5650. pImage->iMAGN_MT = iMT;
  5651. pImage->iMAGN_MB = iMB;
  5652. #else
  5653. pImage->iMAGN_MethodX = pData->iMAGNmethodX;
  5654. pImage->iMAGN_MethodY = pData->iMAGNmethodY;
  5655. pImage->iMAGN_MX = pData->iMAGNmX;
  5656. pImage->iMAGN_MY = pData->iMAGNmY;
  5657. pImage->iMAGN_ML = pData->iMAGNmL;
  5658. pImage->iMAGN_MR = pData->iMAGNmR;
  5659. pImage->iMAGN_MT = pData->iMAGNmT;
  5660. pImage->iMAGN_MB = pData->iMAGNmB;
  5661. #endif
  5662. }
  5663. }
  5664. }
  5665. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5666. pData->iMAGNfromid = iFirstid;
  5667. pData->iMAGNtoid = iLastid;
  5668. iX = iFirstid;
  5669. #else
  5670. pData->iMAGNfromid = pData->iMAGNfirstid;
  5671. pData->iMAGNtoid = pData->iMAGNlastid;
  5672. iX = pData->iMAGNfirstid;
  5673. #endif
  5674. /* iterate again for showing */
  5675. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5676. while ((iX <= iLastid) && (!pData->bTimerset))
  5677. #else
  5678. while ((iX <= pData->iMAGNlastid) && (!pData->bTimerset))
  5679. #endif
  5680. {
  5681. pData->iMAGNcurrentid = iX;
  5682. if (iX) /* only real objects ! */
  5683. {
  5684. pImage = mng_find_imageobject (pData, iX);
  5685. /* object exists & is not frozen &
  5686. is visible & is viewable ? */
  5687. if ((pImage) && (!pImage->bFrozen) &&
  5688. (pImage->bVisible) && (pImage->bViewable))
  5689. {
  5690. mng_retcode iRetcode = mng_display_image (pData, pImage, MNG_FALSE);
  5691. if (iRetcode)
  5692. return iRetcode;
  5693. }
  5694. }
  5695. iX++;
  5696. }
  5697. if (pData->bTimerset) /* broken ? */
  5698. pData->iBreakpoint = 9;
  5699. #ifdef MNG_SUPPORT_TRACE
  5700. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_END);
  5701. #endif
  5702. return MNG_NOERROR;
  5703. }
  5704. /* ************************************************************************** */
  5705. mng_retcode mng_process_display_magn2 (mng_datap pData)
  5706. {
  5707. mng_uint16 iX;
  5708. mng_imagep pImage;
  5709. #ifdef MNG_SUPPORT_TRACE
  5710. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_START);
  5711. #endif
  5712. iX = pData->iMAGNcurrentid;
  5713. /* iterate again for showing */
  5714. while ((iX <= pData->iMAGNtoid) && (!pData->bTimerset))
  5715. {
  5716. pData->iMAGNcurrentid = iX;
  5717. if (iX) /* only real objects ! */
  5718. {
  5719. pImage = mng_find_imageobject (pData, iX);
  5720. /* object exists & is not frozen &
  5721. is visible & is viewable ? */
  5722. if ((pImage) && (!pImage->bFrozen) &&
  5723. (pImage->bVisible) && (pImage->bViewable))
  5724. {
  5725. mng_retcode iRetcode = mng_display_image (pData, pImage, MNG_FALSE);
  5726. if (iRetcode)
  5727. return iRetcode;
  5728. }
  5729. }
  5730. iX++;
  5731. }
  5732. if (pData->bTimerset) /* broken ? */
  5733. pData->iBreakpoint = 9;
  5734. else
  5735. pData->iBreakpoint = 0; /* not again ! */
  5736. #ifdef MNG_SUPPORT_TRACE
  5737. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_END);
  5738. #endif
  5739. return MNG_NOERROR;
  5740. }
  5741. #endif
  5742. /* ************************************************************************** */
  5743. #ifndef MNG_SKIPCHUNK_PAST
  5744. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5745. mng_retcode mng_process_display_past (mng_datap pData,
  5746. mng_uint16 iTargetid,
  5747. mng_uint8 iTargettype,
  5748. mng_int32 iTargetx,
  5749. mng_int32 iTargety,
  5750. mng_uint32 iCount,
  5751. mng_ptr pSources)
  5752. #else
  5753. mng_retcode mng_process_display_past (mng_datap pData)
  5754. #endif
  5755. {
  5756. mng_retcode iRetcode = MNG_NOERROR;
  5757. mng_imagep pTargetimg;
  5758. mng_imagep pSourceimg;
  5759. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5760. mng_past_sourcep pSource = (mng_past_sourcep)pSources;
  5761. #else
  5762. mng_past_sourcep pSource = (mng_past_sourcep)pData->pPASTsources;
  5763. #endif
  5764. mng_uint32 iX = 0;
  5765. #ifdef MNG_SUPPORT_TRACE
  5766. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_START);
  5767. #endif
  5768. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5769. if (iTargetid) /* a real destination object ? */
  5770. #else
  5771. if (pData->iPASTtargetid) /* a real destination object ? */
  5772. #endif
  5773. { /* let's find it then */
  5774. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5775. pTargetimg = (mng_imagep)mng_find_imageobject (pData, iTargetid);
  5776. #else
  5777. pTargetimg = (mng_imagep)mng_find_imageobject (pData, pData->iPASTtargetid);
  5778. #endif
  5779. if (!pTargetimg) /* if it doesn't exists; do a barf */
  5780. MNG_ERROR (pData, MNG_OBJECTUNKNOWN);
  5781. /* it's gotta be abstract !!! */
  5782. if (pTargetimg->pImgbuf->bConcrete)
  5783. MNG_ERROR (pData, MNG_OBJNOTABSTRACT);
  5784. /* we want 32-/64-bit RGBA to play with ! */
  5785. if ((pTargetimg->pImgbuf->iBitdepth <= MNG_BITDEPTH_8) ||
  5786. (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAY) ||
  5787. (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_RGB) ||
  5788. (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_INDEXED) ||
  5789. (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAYA) )
  5790. iRetcode = mng_promote_imageobject (pData, pTargetimg, MNG_BITDEPTH_8,
  5791. MNG_COLORTYPE_RGBA,
  5792. MNG_FILLMETHOD_LEFTBITREPLICATE);
  5793. else
  5794. if ((pTargetimg->pImgbuf->iBitdepth > MNG_BITDEPTH_8) &&
  5795. ((pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAY) ||
  5796. (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_RGB) ||
  5797. (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_GRAYA) ) )
  5798. iRetcode = mng_promote_imageobject (pData, pTargetimg, MNG_BITDEPTH_16,
  5799. MNG_COLORTYPE_RGBA,
  5800. MNG_FILLMETHOD_LEFTBITREPLICATE);
  5801. #ifdef MNG_INCLUDE_JNG
  5802. else
  5803. if ((pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_JPEGGRAY) ||
  5804. (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_JPEGCOLOR) ||
  5805. (pTargetimg->pImgbuf->iColortype == MNG_COLORTYPE_JPEGGRAYA) )
  5806. iRetcode = mng_promote_imageobject (pData, pTargetimg,
  5807. pTargetimg->pImgbuf->iBitdepth,
  5808. MNG_COLORTYPE_JPEGCOLORA,
  5809. MNG_FILLMETHOD_LEFTBITREPLICATE);
  5810. #endif
  5811. if (iRetcode) /* on error bail out */
  5812. return iRetcode;
  5813. /* make it really abstract ? */
  5814. if (!pTargetimg->pImgbuf->bCorrected)
  5815. {
  5816. iRetcode = mng_colorcorrect_object (pData, pTargetimg);
  5817. if (iRetcode) /* on error bail out */
  5818. return iRetcode;
  5819. }
  5820. }
  5821. else
  5822. { /* pasting into object 0 !!! */
  5823. pTargetimg = (mng_imagep)pData->pObjzero;
  5824. /* is it usable ??? */
  5825. if ((pTargetimg->bClipped) &&
  5826. (pTargetimg->iClipr > pTargetimg->iPosx) &&
  5827. (pTargetimg->iClipb > pTargetimg->iPosy))
  5828. {
  5829. /* make it 32-bit RGBA please !!! */
  5830. iRetcode = mng_reset_object_details (pData, pTargetimg,
  5831. pTargetimg->iClipr - pTargetimg->iPosx,
  5832. pTargetimg->iClipb - pTargetimg->iPosy,
  5833. MNG_BITDEPTH_8, MNG_COLORTYPE_RGBA,
  5834. 0, 0, 0, MNG_FALSE);
  5835. if (iRetcode) /* on error bail out */
  5836. return iRetcode;
  5837. }
  5838. else
  5839. pTargetimg = MNG_NULL; /* clipped beyond visibility ! */
  5840. }
  5841. if (pTargetimg) /* usable destination ? */
  5842. {
  5843. mng_int32 iSourceY;
  5844. mng_int32 iSourceYinc;
  5845. mng_int32 iSourcerowsize;
  5846. mng_int32 iSourcesamples;
  5847. mng_bool bSourceRGBA16;
  5848. mng_int32 iTargetY;
  5849. mng_int32 iTargetrowsize;
  5850. mng_int32 iTargetsamples;
  5851. mng_bool bTargetRGBA16 = MNG_FALSE;
  5852. mng_int32 iTemprowsize;
  5853. mng_imagedatap pBuf;
  5854. #ifndef MNG_SKIPCHUNK_MAGN
  5855. /* needs magnification ? */
  5856. if ((pTargetimg->iMAGN_MethodX) || (pTargetimg->iMAGN_MethodY))
  5857. iRetcode = mng_magnify_imageobject (pData, pTargetimg);
  5858. #endif
  5859. if (!iRetcode) /* still ok ? */
  5860. {
  5861. bTargetRGBA16 = (mng_bool)(pTargetimg->pImgbuf->iBitdepth > 8);
  5862. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5863. switch (iTargettype) /* determine target x/y */
  5864. #else
  5865. switch (pData->iPASTtargettype) /* determine target x/y */
  5866. #endif
  5867. {
  5868. case 0 : {
  5869. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5870. pData->iPastx = iTargetx;
  5871. pData->iPasty = iTargety;
  5872. #else
  5873. pData->iPastx = pData->iPASTtargetx;
  5874. pData->iPasty = pData->iPASTtargety;
  5875. #endif
  5876. break;
  5877. }
  5878. case 1 : {
  5879. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5880. pData->iPastx = pTargetimg->iPastx + iTargetx;
  5881. pData->iPasty = pTargetimg->iPasty + iTargety;
  5882. #else
  5883. pData->iPastx = pTargetimg->iPastx + pData->iPASTtargetx;
  5884. pData->iPasty = pTargetimg->iPasty + pData->iPASTtargety;
  5885. #endif
  5886. break;
  5887. }
  5888. case 2 : {
  5889. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5890. pData->iPastx += iTargetx;
  5891. pData->iPasty += iTargety;
  5892. #else
  5893. pData->iPastx += pData->iPASTtargetx;
  5894. pData->iPasty += pData->iPASTtargety;
  5895. #endif
  5896. break;
  5897. }
  5898. }
  5899. /* save for next time ... */
  5900. pTargetimg->iPastx = pData->iPastx;
  5901. pTargetimg->iPasty = pData->iPasty;
  5902. /* address destination for row-routines */
  5903. pData->pStoreobj = (mng_objectp)pTargetimg;
  5904. pData->pStorebuf = (mng_objectp)pTargetimg->pImgbuf;
  5905. }
  5906. /* process the sources one by one */
  5907. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  5908. while ((!iRetcode) && (iX < iCount))
  5909. #else
  5910. while ((!iRetcode) && (iX < pData->iPASTcount))
  5911. #endif
  5912. { /* find the little bastards first */
  5913. pSourceimg = (mng_imagep)mng_find_imageobject (pData, pSource->iSourceid);
  5914. /* exists and viewable? */
  5915. if ((pSourceimg) && (pSourceimg->bViewable))
  5916. { /* needs magnification ? */
  5917. #ifndef MNG_SKIPCHUNK_MAGN
  5918. if ((pSourceimg->iMAGN_MethodX) || (pSourceimg->iMAGN_MethodY))
  5919. iRetcode = mng_magnify_imageobject (pData, pSourceimg);
  5920. #endif
  5921. if (!iRetcode) /* still ok ? */
  5922. {
  5923. pBuf = (mng_imagedatap)pSourceimg->pImgbuf;
  5924. /* address source for row-routines */
  5925. pData->pRetrieveobj = (mng_objectp)pSourceimg;
  5926. pData->iPass = -1; /* init row-processing variables */
  5927. pData->iRowinc = 1;
  5928. pData->iColinc = 1;
  5929. pData->iPixelofs = 0;
  5930. iSourcesamples = (mng_int32)pBuf->iWidth;
  5931. iSourcerowsize = pBuf->iRowsize;
  5932. bSourceRGBA16 = (mng_bool)(pBuf->iBitdepth > 8);
  5933. /* make sure the delta-routines do the right thing */
  5934. pData->iDeltatype = MNG_DELTATYPE_BLOCKPIXELREPLACE;
  5935. switch (pBuf->iColortype)
  5936. {
  5937. case 0 : {
  5938. #ifndef MNG_NO_16BIT_SUPPORT
  5939. if (bSourceRGBA16)
  5940. pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
  5941. else
  5942. #endif
  5943. pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
  5944. pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS);
  5945. break;
  5946. }
  5947. case 2 : {
  5948. #ifndef MNG_NO_16BIT_SUPPORT
  5949. if (bSourceRGBA16)
  5950. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
  5951. else
  5952. #endif
  5953. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
  5954. pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS);
  5955. break;
  5956. }
  5957. case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8;
  5958. pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS);
  5959. break;
  5960. }
  5961. case 4 : {
  5962. #ifndef MNG_NO_16BIT_SUPPORT
  5963. if (bSourceRGBA16)
  5964. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
  5965. else
  5966. #endif
  5967. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
  5968. pData->bIsOpaque = MNG_FALSE;
  5969. break;
  5970. }
  5971. case 6 : {
  5972. #ifndef MNG_NO_16BIT_SUPPORT
  5973. if (bSourceRGBA16)
  5974. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
  5975. else
  5976. #endif
  5977. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
  5978. pData->bIsOpaque = MNG_FALSE;
  5979. break;
  5980. }
  5981. case 8 : {
  5982. #ifndef MNG_NO_16BIT_SUPPORT
  5983. if (bSourceRGBA16)
  5984. pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
  5985. else
  5986. #endif
  5987. pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
  5988. pData->bIsOpaque = MNG_TRUE;
  5989. break;
  5990. }
  5991. case 10 : {
  5992. #ifndef MNG_NO_16BIT_SUPPORT
  5993. if (bSourceRGBA16)
  5994. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
  5995. else
  5996. #endif
  5997. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
  5998. pData->bIsOpaque = MNG_TRUE;
  5999. break;
  6000. }
  6001. case 12 : {
  6002. #ifndef MNG_NO_16BIT_SUPPORT
  6003. if (bSourceRGBA16)
  6004. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
  6005. else
  6006. #endif
  6007. pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
  6008. pData->bIsOpaque = MNG_FALSE;
  6009. break;
  6010. }
  6011. case 14 : {
  6012. #ifndef MNG_NO_16BIT_SUPPORT
  6013. if (bSourceRGBA16)
  6014. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
  6015. else
  6016. #endif
  6017. pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
  6018. pData->bIsOpaque = MNG_FALSE;
  6019. break;
  6020. }
  6021. }
  6022. /* determine scaling */
  6023. #ifndef MNG_NO_16BIT_SUPPORT
  6024. #ifndef MNG_NO_DELTA_PNG
  6025. if ((!bSourceRGBA16) && (bTargetRGBA16))
  6026. pData->fScalerow = (mng_fptr)mng_scale_rgba8_rgba16;
  6027. else
  6028. if ((bSourceRGBA16) && (!bTargetRGBA16))
  6029. pData->fScalerow = (mng_fptr)mng_scale_rgba16_rgba8;
  6030. else
  6031. #endif
  6032. #endif
  6033. pData->fScalerow = MNG_NULL;
  6034. /* default no color-correction */
  6035. pData->fCorrectrow = MNG_NULL;
  6036. #if defined(MNG_FULL_CMS) /* determine color-management routine */
  6037. iRetcode = mng_init_full_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
  6038. #elif defined(MNG_GAMMA_ONLY)
  6039. iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
  6040. #elif defined(MNG_APP_CMS)
  6041. iRetcode = mng_init_app_cms (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
  6042. #endif
  6043. }
  6044. if (!iRetcode) /* still ok ? */
  6045. {
  6046. pData->fFliprow = MNG_NULL; /* no flipping or tiling by default */
  6047. pData->fTilerow = MNG_NULL;
  6048. /* but perhaps we do have to ... */
  6049. switch (pSource->iOrientation)
  6050. {
  6051. case 2 : ;
  6052. case 4 : {
  6053. #ifndef MNG_NO_16BIT_SUPPORT
  6054. if (bTargetRGBA16)
  6055. pData->fFliprow = (mng_fptr)mng_flip_rgba16;
  6056. else
  6057. #endif
  6058. pData->fFliprow = (mng_fptr)mng_flip_rgba8;
  6059. break;
  6060. }
  6061. case 8 : {
  6062. #ifndef MNG_NO_16BIT_SUPPORT
  6063. if (bTargetRGBA16)
  6064. pData->fTilerow = (mng_fptr)mng_tile_rgba16;
  6065. else
  6066. #endif
  6067. pData->fTilerow = (mng_fptr)mng_tile_rgba8;
  6068. break;
  6069. }
  6070. }
  6071. /* determine composition routine */
  6072. /* note that we're abusing the delta-routine setup !!! */
  6073. switch (pSource->iComposition)
  6074. {
  6075. case 0 : { /* composite over */
  6076. #ifndef MNG_NO_16BIT_SUPPORT
  6077. if (bTargetRGBA16)
  6078. pData->fDeltarow = (mng_fptr)mng_composeover_rgba16;
  6079. else
  6080. #endif
  6081. pData->fDeltarow = (mng_fptr)mng_composeover_rgba8;
  6082. break;
  6083. }
  6084. case 1 : { /* replace */
  6085. #ifndef MNG_NO_16BIT_SUPPORT
  6086. if (bTargetRGBA16)
  6087. pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgba16;
  6088. else
  6089. #endif
  6090. pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgba8;
  6091. break;
  6092. }
  6093. case 2 : { /* composite under */
  6094. #ifndef MNG_NO_16BIT_SUPPORT
  6095. if (bTargetRGBA16)
  6096. pData->fDeltarow = (mng_fptr)mng_composeunder_rgba16;
  6097. else
  6098. #endif
  6099. pData->fDeltarow = (mng_fptr)mng_composeunder_rgba8;
  6100. break;
  6101. }
  6102. }
  6103. /* determine offsets & clipping */
  6104. if (pSource->iOffsettype == 1)
  6105. {
  6106. pData->iDestl = pData->iPastx + pSource->iOffsetx;
  6107. pData->iDestt = pData->iPasty + pSource->iOffsety;
  6108. }
  6109. else
  6110. {
  6111. pData->iDestl = pSource->iOffsetx;
  6112. pData->iDestt = pSource->iOffsety;
  6113. }
  6114. pData->iDestr = (mng_int32)pTargetimg->pImgbuf->iWidth;
  6115. pData->iDestb = (mng_int32)pTargetimg->pImgbuf->iHeight;
  6116. /* take the source dimension into account ? */
  6117. if (pSource->iOrientation != 8)
  6118. {
  6119. pData->iDestr = MIN_COORD (pData->iDestr, pData->iDestl + (mng_int32)pBuf->iWidth);
  6120. pData->iDestb = MIN_COORD (pData->iDestb, pData->iDestt + (mng_int32)pBuf->iHeight);
  6121. }
  6122. /* source clipping */
  6123. if (pSource->iBoundarytype == 1)
  6124. {
  6125. if (pData->iDestl < pData->iPastx + pSource->iBoundaryl)
  6126. pData->iSourcel = pData->iPastx + pSource->iBoundaryl - pData->iDestl;
  6127. else
  6128. pData->iSourcel = 0;
  6129. if (pData->iDestt < pData->iPasty + pSource->iBoundaryt)
  6130. pData->iSourcet = pData->iPasty + pSource->iBoundaryt - pData->iDestt;
  6131. else
  6132. pData->iSourcet = 0;
  6133. pData->iDestl = MAX_COORD (pData->iDestl, pData->iPastx + pSource->iBoundaryl);
  6134. pData->iDestt = MAX_COORD (pData->iDestt, pData->iPasty + pSource->iBoundaryt);
  6135. pData->iDestr = MIN_COORD (pData->iDestr, pData->iPastx + pSource->iBoundaryr);
  6136. pData->iDestb = MIN_COORD (pData->iDestb, pData->iPasty + pSource->iBoundaryb);
  6137. }
  6138. else
  6139. {
  6140. if (pData->iDestl < pSource->iBoundaryl)
  6141. pData->iSourcel = pSource->iBoundaryl - pData->iDestl;
  6142. else
  6143. pData->iSourcel = 0;
  6144. if (pData->iDestt < pSource->iBoundaryt)
  6145. pData->iSourcet = pSource->iBoundaryt - pData->iDestt;
  6146. else
  6147. pData->iSourcet = 0;
  6148. pData->iDestl = MAX_COORD (pData->iDestl, pSource->iBoundaryl);
  6149. pData->iDestt = MAX_COORD (pData->iDestt, pSource->iBoundaryt);
  6150. pData->iDestr = MIN_COORD (pData->iDestr, pSource->iBoundaryr);
  6151. pData->iDestb = MIN_COORD (pData->iDestb, pSource->iBoundaryb);
  6152. }
  6153. if (pData->iSourcel) /* indent source ? */
  6154. {
  6155. #ifndef MNG_NO_16BIT_SUPPORT
  6156. if (bTargetRGBA16) /* abuse tiling routine to shift source-pixels */
  6157. pData->fTilerow = (mng_fptr)mng_tile_rgba16;
  6158. else
  6159. #endif
  6160. pData->fTilerow = (mng_fptr)mng_tile_rgba8;
  6161. }
  6162. /* anything to display ? */
  6163. if ((pData->iDestl <= pData->iDestr) && (pData->iDestt <= pData->iDestb))
  6164. { /* init variables for the loop */
  6165. if ((pSource->iOrientation == 2) || (pSource->iOrientation == 6))
  6166. {
  6167. iSourceY = (mng_int32)pBuf->iHeight - 1 - pData->iSourcet;
  6168. iSourceYinc = -1;
  6169. }
  6170. else
  6171. {
  6172. iSourceY = pData->iSourcet;
  6173. iSourceYinc = 1;
  6174. }
  6175. iTargetY = pData->iDestt;
  6176. pData->iCol = pData->iDestl;
  6177. iTargetsamples = pData->iDestr - pData->iDestl;
  6178. #ifndef MNG_NO_16BIT_SUPPORT
  6179. if (bTargetRGBA16)
  6180. iTargetrowsize = (iTargetsamples << 3);
  6181. else
  6182. #endif
  6183. iTargetrowsize = (iTargetsamples << 2);
  6184. /* get temporary work-buffers */
  6185. if (iSourcerowsize > iTargetrowsize)
  6186. iTemprowsize = iSourcerowsize << 1;
  6187. else
  6188. iTemprowsize = iTargetrowsize << 1;
  6189. MNG_ALLOC (pData, pData->pRGBArow, iTemprowsize);
  6190. MNG_ALLOC (pData, pData->pWorkrow, iTemprowsize);
  6191. while ((!iRetcode) && (iTargetY < pData->iDestb))
  6192. { /* get a row */
  6193. pData->iRow = iSourceY;
  6194. pData->iRowsamples = iSourcesamples;
  6195. pData->iRowsize = iSourcerowsize;
  6196. pData->bIsRGBA16 = bSourceRGBA16;
  6197. iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData);
  6198. /* scale it (if necessary) */
  6199. if ((!iRetcode) && (pData->fScalerow))
  6200. iRetcode = ((mng_scalerow)pData->fScalerow) (pData);
  6201. pData->bIsRGBA16 = bTargetRGBA16;
  6202. /* color correction (if necessary) */
  6203. if ((!iRetcode) && (pData->fCorrectrow))
  6204. iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData);
  6205. /* flipping (if necessary) */
  6206. if ((!iRetcode) && (pData->fFliprow))
  6207. iRetcode = ((mng_fliprow)pData->fFliprow) (pData);
  6208. /* tiling (if necessary) */
  6209. if ((!iRetcode) && (pData->fTilerow))
  6210. iRetcode = ((mng_tilerow)pData->fTilerow) (pData);
  6211. if (!iRetcode) /* and paste..... */
  6212. {
  6213. pData->iRow = iTargetY;
  6214. pData->iRowsamples = iTargetsamples;
  6215. pData->iRowsize = iTargetrowsize;
  6216. iRetcode = ((mng_deltarow)pData->fDeltarow) (pData);
  6217. }
  6218. iSourceY += iSourceYinc; /* and next line */
  6219. if (iSourceY < 0)
  6220. iSourceY = (mng_int32)pBuf->iHeight - 1;
  6221. else
  6222. if (iSourceY >= (mng_int32)pBuf->iHeight)
  6223. iSourceY = 0;
  6224. iTargetY++;
  6225. }
  6226. /* drop the temporary row-buffer */
  6227. MNG_FREEX (pData, pData->pWorkrow, iTemprowsize);
  6228. MNG_FREEX (pData, pData->pRGBArow, iTemprowsize);
  6229. }
  6230. #if defined(MNG_FULL_CMS) /* cleanup cms stuff */
  6231. if (!iRetcode)
  6232. iRetcode = mng_clear_cms (pData);
  6233. #endif
  6234. }
  6235. pSource++; /* neeeeext */
  6236. iX++;
  6237. }
  6238. }
  6239. if (iRetcode) /* on error bail out */
  6240. return iRetcode;
  6241. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  6242. if (!iTargetid) /* did we paste into object 0 ? */
  6243. #else
  6244. if (!pData->iPASTtargetid) /* did we paste into object 0 ? */
  6245. #endif
  6246. { /* display it then ! */
  6247. iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE);
  6248. if (iRetcode) /* on error bail out */
  6249. return iRetcode;
  6250. }
  6251. else
  6252. { /* target is visible & viewable ? */
  6253. if ((pTargetimg->bVisible) && (pTargetimg->bViewable))
  6254. {
  6255. iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE);
  6256. if (iRetcode)
  6257. return iRetcode;
  6258. }
  6259. }
  6260. }
  6261. if (pData->bTimerset) /* broken ? */
  6262. {
  6263. #ifndef MNG_OPTIMIZE_DISPLAYCALLS
  6264. pData->iPASTid = iTargetid;
  6265. #else
  6266. pData->iPASTid = pData->iPASTtargetid;
  6267. #endif
  6268. pData->iBreakpoint = 11;
  6269. }
  6270. #ifdef MNG_SUPPORT_TRACE
  6271. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_END);
  6272. #endif
  6273. return MNG_NOERROR;
  6274. }
  6275. #endif /* MNG_SKIPCHUNK_PAST */
  6276. /* ************************************************************************** */
  6277. #ifndef MNG_SKIPCHUNK_PAST
  6278. mng_retcode mng_process_display_past2 (mng_datap pData)
  6279. {
  6280. mng_retcode iRetcode;
  6281. mng_imagep pTargetimg;
  6282. #ifdef MNG_SUPPORT_TRACE
  6283. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_START);
  6284. #endif
  6285. if (pData->iPASTid) /* a real destination object ? */
  6286. pTargetimg = (mng_imagep)mng_find_imageobject (pData, pData->iPASTid);
  6287. else /* otherwise object 0 */
  6288. pTargetimg = (mng_imagep)pData->pObjzero;
  6289. iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE);
  6290. if (iRetcode)
  6291. return iRetcode;
  6292. pData->iBreakpoint = 0; /* only once */
  6293. #ifdef MNG_SUPPORT_TRACE
  6294. MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_END);
  6295. #endif
  6296. return MNG_NOERROR;
  6297. }
  6298. #endif /* MNG_SKIPCHUNK_PAST */
  6299. /* ************************************************************************** */
  6300. #endif /* MNG_INCLUDE_DISPLAY_PROCS */
  6301. /* ************************************************************************** */
  6302. /* * end of file * */
  6303. /* ************************************************************************** */