PageRenderTime 69ms CodeModel.GetById 18ms app.highlight 43ms RepoModel.GetById 1ms app.codeStats 0ms

/src/FreeImage/Source/LibMNG/libmng_display.c

https://bitbucket.org/cabalistic/ogredeps/
C | 1418 lines | 951 code | 148 blank | 319 comment | 202 complexity | 0db316acf17863ec734bc3a61aa9cc6c MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  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
240#include "libmng.h"
241#include "libmng_data.h"
242#include "libmng_error.h"
243#include "libmng_trace.h"
244#ifdef __BORLANDC__
245#pragma hdrstop
246#endif
247#include "libmng_chunks.h"
248#include "libmng_objects.h"
249#include "libmng_object_prc.h"
250#include "libmng_memory.h"
251#include "libmng_zlib.h"
252#include "libmng_jpeg.h"
253#include "libmng_cms.h"
254#include "libmng_pixels.h"
255#include "libmng_display.h"
256
257#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)
258#pragma option -A                      /* force ANSI-C */
259#endif
260
261/* ************************************************************************** */
262
263#ifdef MNG_INCLUDE_DISPLAY_PROCS
264
265/* ************************************************************************** */
266
267MNG_LOCAL mng_retcode set_delay (mng_datap  pData,
268                                 mng_uint32 iInterval)
269{
270  if (!iInterval)                      /* at least 1 msec please! */
271    iInterval = 1;
272
273  if (pData->bRunning)                 /* only when really displaying */
274    if (!pData->fSettimer ((mng_handle)pData, iInterval))
275      MNG_ERROR (pData, MNG_APPTIMERERROR);
276
277#ifdef MNG_SUPPORT_DYNAMICMNG
278  if ((!pData->bDynamic) || (pData->bRunning))
279#else
280  if (pData->bRunning)
281#endif
282    pData->bTimerset = MNG_TRUE;       /* and indicate so */
283
284  return MNG_NOERROR;
285}
286
287/* ************************************************************************** */
288
289MNG_LOCAL mng_uint32 calculate_delay (mng_datap  pData,
290                                      mng_uint32 iDelay)
291{
292  mng_uint32 iTicks   = pData->iTicks;
293  mng_uint32 iWaitfor = 1;             /* default non-MNG delay */
294
295  if (!iTicks)                         /* tick_count not specified ? */
296    if (pData->eImagetype == mng_it_mng)
297      iTicks = 1000;
298
299  if (iTicks)
300  {
301    switch (pData->iSpeed)             /* honor speed modifier */
302    {
303      case mng_st_fast :
304        {
305          iWaitfor = (mng_uint32)(( 500 * iDelay) / iTicks);
306          break;
307        }
308      case mng_st_slow :
309        {
310          iWaitfor = (mng_uint32)((3000 * iDelay) / iTicks);
311          break;
312        }
313      case mng_st_slowest :
314        {
315          iWaitfor = (mng_uint32)((8000 * iDelay) / iTicks);
316          break;
317        }
318      default :
319        {
320          iWaitfor = (mng_uint32)((1000 * iDelay) / iTicks);
321        }
322    }
323  }
324
325  return iWaitfor;
326}
327
328/* ************************************************************************** */
329/* *                                                                        * */
330/* * Progressive display refresh - does the call to the refresh callback    * */
331/* * and sets the timer to allow the app to perform the actual refresh to   * */
332/* * the screen (eg. process its main message-loop)                         * */
333/* *                                                                        * */
334/* ************************************************************************** */
335
336mng_retcode mng_display_progressive_refresh (mng_datap  pData,
337                                             mng_uint32 iInterval)
338{
339  {                                    /* let the app refresh first ? */
340    if ((pData->bRunning) && (!pData->bSkipping) &&
341        (pData->iUpdatetop < pData->iUpdatebottom) && (pData->iUpdateleft < pData->iUpdateright))
342    {
343      if (!pData->fRefresh (((mng_handle)pData),
344                            pData->iUpdateleft, pData->iUpdatetop,
345                            pData->iUpdateright  - pData->iUpdateleft,
346                            pData->iUpdatebottom - pData->iUpdatetop))
347        MNG_ERROR (pData, MNG_APPMISCERROR);
348
349      pData->iUpdateleft   = 0;        /* reset update-region */
350      pData->iUpdateright  = 0;
351      pData->iUpdatetop    = 0;
352      pData->iUpdatebottom = 0;        /* reset refreshneeded indicator */
353      pData->bNeedrefresh  = MNG_FALSE;
354                                       /* interval requested ? */
355      if ((!pData->bFreezing) && (iInterval))
356      {                                /* setup the timer */
357        mng_retcode iRetcode = set_delay (pData, iInterval);
358
359        if (iRetcode)                  /* on error bail out */
360          return iRetcode;
361      }
362    }
363  }
364
365  return MNG_NOERROR;
366}
367
368/* ************************************************************************** */
369/* *                                                                        * */
370/* * Generic display routines                                               * */
371/* *                                                                        * */
372/* ************************************************************************** */
373
374MNG_LOCAL mng_retcode interframe_delay (mng_datap pData)
375{
376  mng_uint32  iWaitfor = 0;
377  mng_uint32  iInterval;
378  mng_uint32  iRuninterval;
379  mng_retcode iRetcode;
380
381#ifdef MNG_SUPPORT_TRACE
382  MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_START);
383#endif
384
385  {
386#ifndef MNG_SKIPCHUNK_FRAM
387    if (pData->iFramedelay > 0)        /* real delay ? */
388    {                                  /* let the app refresh first ? */
389      if ((pData->bRunning) && (!pData->bSkipping) &&
390          (pData->iUpdatetop < pData->iUpdatebottom) && (pData->iUpdateleft < pData->iUpdateright))
391        if (!pData->fRefresh (((mng_handle)pData),
392                              pData->iUpdateleft,  pData->iUpdatetop,
393                              pData->iUpdateright - pData->iUpdateleft,
394                              pData->iUpdatebottom - pData->iUpdatetop))
395          MNG_ERROR (pData, MNG_APPMISCERROR);
396
397      pData->iUpdateleft   = 0;        /* reset update-region */
398      pData->iUpdateright  = 0;
399      pData->iUpdatetop    = 0;
400      pData->iUpdatebottom = 0;        /* reset refreshneeded indicator */
401      pData->bNeedrefresh  = MNG_FALSE;
402
403#ifndef MNG_SKIPCHUNK_TERM
404      if (pData->bOnlyfirstframe)      /* only processing first frame after TERM ? */
405      {
406        pData->iFramesafterTERM++;
407                                       /* did we do a frame yet ? */
408        if (pData->iFramesafterTERM > 1)
409        {                              /* then that's it; just stop right here ! */
410          pData->pCurraniobj = MNG_NULL;
411          pData->bRunning    = MNG_FALSE;
412
413          return MNG_NOERROR;
414        }
415      }
416#endif
417
418      if (pData->fGettickcount)
419      {                                /* get current tickcount */
420        pData->iRuntime = pData->fGettickcount ((mng_handle)pData);
421                                       /* calculate interval since last sync-point */
422        if (pData->iRuntime < pData->iSynctime)
423          iRuninterval    = pData->iRuntime + ~pData->iSynctime + 1;
424        else
425          iRuninterval    = pData->iRuntime - pData->iSynctime;
426                                       /* calculate actual run-time */
427        if (pData->iRuntime < pData->iStarttime)
428          pData->iRuntime = pData->iRuntime + ~pData->iStarttime + 1;
429        else
430          pData->iRuntime = pData->iRuntime - pData->iStarttime;
431      }
432      else
433      {
434        iRuninterval = 0;
435      }
436
437      iWaitfor = calculate_delay (pData, pData->iFramedelay);
438
439      if (iWaitfor > iRuninterval)     /* delay necessary ? */
440        iInterval = iWaitfor - iRuninterval;
441      else
442        iInterval = 1;                 /* force app to process messageloop */
443                                       /* set the timer ? */
444      if (((pData->bRunning) || (pData->bSearching) || (pData->bReading)) &&
445          (!pData->bSkipping))
446      {
447        iRetcode = set_delay (pData, iInterval);
448
449        if (iRetcode)                  /* on error bail out */
450          return iRetcode;
451      }
452    }
453
454    if (!pData->bSkipping)             /* increase frametime in advance */
455      pData->iFrametime = pData->iFrametime + iWaitfor;
456                                       /* setup for next delay */
457    pData->iFramedelay = pData->iNextdelay;
458#endif
459  }
460
461#ifdef MNG_SUPPORT_TRACE
462  MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_END);
463#endif
464
465  return MNG_NOERROR;
466}
467
468/* ************************************************************************** */
469
470MNG_LOCAL void set_display_routine (mng_datap pData)
471{                                        /* actively running ? */
472  if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
473  {
474    switch (pData->iCanvasstyle)         /* determine display routine */
475    {
476#ifndef MNG_SKIPCANVAS_RGB8
477      case MNG_CANVAS_RGB8    : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8;     break; }
478#endif
479#ifndef MNG_SKIPCANVAS_RGBA8
480      case MNG_CANVAS_RGBA8   : { pData->fDisplayrow = (mng_fptr)mng_display_rgba8;    break; }
481#endif
482#ifndef MNG_SKIPCANVAS_RGBA8_PM
483      case MNG_CANVAS_RGBA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_rgba8_pm; break; }
484#endif
485#ifndef MNG_SKIPCANVAS_ARGB8
486      case MNG_CANVAS_ARGB8   : { pData->fDisplayrow = (mng_fptr)mng_display_argb8;    break; }
487#endif
488#ifndef MNG_SKIPCANVAS_ARGB8_PM
489      case MNG_CANVAS_ARGB8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_argb8_pm; break; }
490#endif
491#ifndef MNG_SKIPCANVAS_RGB8_A8
492      case MNG_CANVAS_RGB8_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8_a8;  break; }
493#endif
494#ifndef MNG_SKIPCANVAS_BGR8
495      case MNG_CANVAS_BGR8    : { pData->fDisplayrow = (mng_fptr)mng_display_bgr8;     break; }
496#endif
497#ifndef MNG_SKIPCANVAS_BGRX8
498      case MNG_CANVAS_BGRX8   : { pData->fDisplayrow = (mng_fptr)mng_display_bgrx8;    break; }
499#endif
500#ifndef MNG_SKIPCANVAS_BGRA8
501      case MNG_CANVAS_BGRA8   : { pData->fDisplayrow = (mng_fptr)mng_display_bgra8;    break; }
502#endif
503#ifndef MNG_SKIPCANVAS_BGRA8_PM
504      case MNG_CANVAS_BGRA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_bgra8_pm; break; }
505#endif
506#ifndef MNG_SKIPCANVAS_ABGR8
507      case MNG_CANVAS_ABGR8   : { pData->fDisplayrow = (mng_fptr)mng_display_abgr8;    break; }
508#endif
509#ifndef MNG_SKIPCANVAS_ABGR8_PM
510      case MNG_CANVAS_ABGR8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_abgr8_pm; break; }
511#endif
512#ifndef MNG_SKIPCANVAS_RGB565
513      case MNG_CANVAS_RGB565  : { pData->fDisplayrow = (mng_fptr)mng_display_rgb565;   break; }
514#endif
515#ifndef MNG_SKIPCANVAS_RGBA565
516      case MNG_CANVAS_RGBA565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba565;  break; }
517#endif
518#ifndef MNG_SKIPCANVAS_BGR565
519      case MNG_CANVAS_BGR565  : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565;   break; }
520#endif
521#ifndef MNG_SKIPCANVAS_BGRA565
522      case MNG_CANVAS_BGRA565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra565;  break; }
523#endif
524#ifndef MNG_SKIPCANVAS_BGR565_A8
525      case MNG_CANVAS_BGR565_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565_a8;  break; }
526#endif
527#ifndef MNG_SKIPCANVAS_RGB555
528      case MNG_CANVAS_RGB555  : { pData->fDisplayrow = (mng_fptr)mng_display_rgb555;  break; }
529#endif
530#ifndef MNG_SKIPCANVAS_BGR555
531      case MNG_CANVAS_BGR555  : { pData->fDisplayrow = (mng_fptr)mng_display_bgr555;  break; }
532#endif
533
534#ifndef MNG_NO_16BIT_SUPPORT
535/*      case MNG_CANVAS_RGB16   : { pData->fDisplayrow = (mng_fptr)mng_display_rgb16;    break; } */
536/*      case MNG_CANVAS_RGBA16  : { pData->fDisplayrow = (mng_fptr)mng_display_rgba16;   break; } */
537/*      case MNG_CANVAS_ARGB16  : { pData->fDisplayrow = (mng_fptr)mng_display_argb16;   break; } */
538/*      case MNG_CANVAS_BGR16   : { pData->fDisplayrow = (mng_fptr)mng_display_bgr16;    break; } */
539/*      case MNG_CANVAS_BGRA16  : { pData->fDisplayrow = (mng_fptr)mng_display_bgra16;   break; } */
540/*      case MNG_CANVAS_ABGR16  : { pData->fDisplayrow = (mng_fptr)mng_display_abgr16;   break; } */
541#endif
542/*      case MNG_CANVAS_INDEX8  : { pData->fDisplayrow = (mng_fptr)mng_display_index8;   break; } */
543/*      case MNG_CANVAS_INDEXA8 : { pData->fDisplayrow = (mng_fptr)mng_display_indexa8;  break; } */
544/*      case MNG_CANVAS_AINDEX8 : { pData->fDisplayrow = (mng_fptr)mng_display_aindex8;  break; } */
545/*      case MNG_CANVAS_GRAY8   : { pData->fDisplayrow = (mng_fptr)mng_display_gray8;    break; } */
546/*      case MNG_CANVAS_AGRAY8  : { pData->fDisplayrow = (mng_fptr)mng_display_agray8;   break; } */
547/*      case MNG_CANVAS_GRAYA8  : { pData->fDisplayrow = (mng_fptr)mng_display_graya8;   break; } */
548#ifndef MNG_NO_16BIT_SUPPORT
549/*      case MNG_CANVAS_GRAY16  : { pData->fDisplayrow = (mng_fptr)mng_display_gray16;   break; } */
550/*      case MNG_CANVAS_GRAYA16 : { pData->fDisplayrow = (mng_fptr)mng_display_graya16;  break; } */
551/*      case MNG_CANVAS_AGRAY16 : { pData->fDisplayrow = (mng_fptr)mng_display_agray16;  break; } */
552#endif
553/*      case MNG_CANVAS_DX15    : { pData->fDisplayrow = (mng_fptr)mng_display_dx15;     break; } */
554/*      case MNG_CANVAS_DX16    : { pData->fDisplayrow = (mng_fptr)mng_display_dx16;     break; } */
555    }
556  }
557
558  return;
559}
560
561/* ************************************************************************** */
562
563MNG_LOCAL mng_retcode load_bkgdlayer (mng_datap pData)
564{
565#ifdef MNG_SUPPORT_TRACE
566  MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_START);
567#endif
568                                       /* actively running ? */
569  if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
570  {
571    mng_int32   iY;
572    mng_retcode iRetcode;
573    mng_bool    bColorcorr   = MNG_FALSE;
574                                       /* save values */
575    mng_int32   iDestl       = pData->iDestl;
576    mng_int32   iDestr       = pData->iDestr;
577    mng_int32   iDestt       = pData->iDestt;
578    mng_int32   iDestb       = pData->iDestb;
579    mng_int32   iSourcel     = pData->iSourcel;
580    mng_int32   iSourcer     = pData->iSourcer;
581    mng_int32   iSourcet     = pData->iSourcet;
582    mng_int32   iSourceb     = pData->iSourceb;
583    mng_int8    iPass        = pData->iPass;
584    mng_int32   iRow         = pData->iRow;
585    mng_int32   iRowinc      = pData->iRowinc;
586    mng_int32   iCol         = pData->iCol;
587    mng_int32   iColinc      = pData->iColinc;
588    mng_int32   iRowsamples  = pData->iRowsamples;
589    mng_int32   iRowsize     = pData->iRowsize;
590    mng_uint8p  pPrevrow     = pData->pPrevrow;
591    mng_uint8p  pRGBArow     = pData->pRGBArow;
592    mng_bool    bIsRGBA16    = pData->bIsRGBA16;
593    mng_bool    bIsOpaque    = pData->bIsOpaque;
594    mng_fptr    fCorrectrow  = pData->fCorrectrow;
595    mng_fptr    fDisplayrow  = pData->fDisplayrow;
596    mng_fptr    fRetrieverow = pData->fRetrieverow;
597    mng_objectp pCurrentobj  = pData->pCurrentobj;
598    mng_objectp pRetrieveobj = pData->pRetrieveobj;
599
600    pData->iDestl   = 0;               /* determine clipping region */
601    pData->iDestt   = 0;
602    pData->iDestr   = pData->iWidth;
603    pData->iDestb   = pData->iHeight;
604
605#ifndef MNG_SKIPCHUNK_FRAM
606    if (pData->bFrameclipping)         /* frame clipping specified ? */
607    {
608      pData->iDestl = MAX_COORD (pData->iDestl,  pData->iFrameclipl);
609      pData->iDestt = MAX_COORD (pData->iDestt,  pData->iFrameclipt);
610      pData->iDestr = MIN_COORD (pData->iDestr,  pData->iFrameclipr);
611      pData->iDestb = MIN_COORD (pData->iDestb,  pData->iFrameclipb);
612    }
613#endif
614                                       /* anything to clear ? */
615    if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt))
616    {
617      pData->iPass       = -1;         /* these are the object's dimensions now */
618      pData->iRow        = 0;
619      pData->iRowinc     = 1;
620      pData->iCol        = 0;
621      pData->iColinc     = 1;
622      pData->iRowsamples = pData->iWidth;
623      pData->iRowsize    = pData->iRowsamples << 2;
624      pData->bIsRGBA16   = MNG_FALSE;  /* let's keep it simple ! */
625      pData->bIsOpaque   = MNG_TRUE;
626
627      pData->iSourcel    = 0;          /* source relative to destination */
628      pData->iSourcer    = pData->iDestr - pData->iDestl;
629      pData->iSourcet    = 0;
630      pData->iSourceb    = pData->iDestb - pData->iDestt;
631
632      set_display_routine (pData);     /* determine display routine */
633                                       /* default restore using preset BG color */
634      pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgcolor;
635
636#ifndef MNG_SKIPCHUNK_bKGD
637      if (((pData->eImagetype == mng_it_png) || (pData->eImagetype == mng_it_jng)) &&
638          (pData->bUseBKGD))
639      {                                /* prefer bKGD in PNG/JNG */
640        if (!pData->pCurrentobj)
641          pData->pCurrentobj = pData->pObjzero;
642
643        if (((mng_imagep)pData->pCurrentobj)->pImgbuf->bHasBKGD)
644        {
645          pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bkgd;
646          bColorcorr          = MNG_TRUE;
647        }
648      }
649#endif
650
651      if (pData->fGetbkgdline)         /* background-canvas-access callback set ? */
652      {
653        switch (pData->iBkgdstyle)
654        {
655#ifndef MNG_SKIPCANVAS_RGB8
656          case MNG_CANVAS_RGB8    : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb8;    break; }
657#endif
658#ifndef MNG_SKIPCANVAS_BGR8
659          case MNG_CANVAS_BGR8    : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr8;    break; }
660#endif
661#ifndef MNG_SKIPCANVAS_BGRX8
662          case MNG_CANVAS_BGRX8   : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgrx8;   break; }
663#endif
664#ifndef MNG_SKIPCANVAS_BGR565
665          case MNG_CANVAS_BGR565  : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr565;  break; }
666#endif
667#ifndef MNG_SKIPCANVAS_RGB565
668          case MNG_CANVAS_RGB565  : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb565;  break; }
669#endif
670#ifndef MNG_NO_16BIT_SUPPORT
671  /*        case MNG_CANVAS_RGB16   : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb16;   break; } */
672  /*        case MNG_CANVAS_BGR16   : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr16;   break; } */
673#endif
674  /*        case MNG_CANVAS_INDEX8  : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_index8;  break; } */
675  /*        case MNG_CANVAS_GRAY8   : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_gray8;   break; } */
676#ifndef MNG_NO_16BIT_SUPPORT
677  /*        case MNG_CANVAS_GRAY16  : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_gray16;  break; } */
678#endif
679  /*        case MNG_CANVAS_DX15    : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_dx15;    break; } */
680  /*        case MNG_CANVAS_DX16    : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_dx16;    break; } */
681        }
682      }
683
684#ifndef MNG_SKIPCHUNK_BACK
685      if (pData->bHasBACK)
686      {                                /* background image ? */
687        if ((pData->iBACKmandatory & 0x02) && (pData->iBACKimageid))
688        {
689          pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor;
690          bColorcorr          = MNG_TRUE;
691        }
692        else                           /* background color ? */
693        if (pData->iBACKmandatory & 0x01)
694        {
695          pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor;
696          bColorcorr          = MNG_TRUE;
697        }
698      }
699#endif
700
701      pData->fCorrectrow = MNG_NULL;   /* default no color-correction */
702
703      if (bColorcorr)                  /* do we have to do color-correction ? */
704      {
705#ifdef MNG_NO_CMS
706        iRetcode = MNG_NOERROR;
707#else
708#if defined(MNG_FULL_CMS)              /* determine color-management routine */
709        iRetcode = mng_init_full_cms   (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE);
710#elif defined(MNG_GAMMA_ONLY)
711        iRetcode = mng_init_gamma_only (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE);
712#elif defined(MNG_APP_CMS)
713        iRetcode = mng_init_app_cms    (pData, MNG_TRUE, MNG_FALSE, MNG_FALSE);
714#endif
715        if (iRetcode)                  /* on error bail out */
716          return iRetcode;
717#endif /* MNG_NO_CMS */
718      }
719                                       /* get a temporary row-buffer */
720      MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize);
721
722      iY       = pData->iDestt;        /* this is where we start */
723      iRetcode = MNG_NOERROR;          /* so far, so good */
724
725      while ((!iRetcode) && (iY < pData->iDestb))
726      {                                /* restore a background row */
727        iRetcode = ((mng_restbkgdrow)pData->fRestbkgdrow) (pData);
728                                       /* color correction ? */
729        if ((!iRetcode) && (pData->fCorrectrow))
730          iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData);
731
732        if (!iRetcode)                 /* so... display it */
733          iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
734
735        if (!iRetcode)
736          iRetcode = mng_next_row (pData);
737
738        iY++;                          /* and next line */
739      }
740                                       /* drop the temporary row-buffer */
741      MNG_FREE (pData, pData->pRGBArow, pData->iRowsize);
742
743      if (iRetcode)                    /* on error bail out */
744        return iRetcode;
745
746#if defined(MNG_FULL_CMS)              /* cleanup cms stuff */
747      if (bColorcorr)                  /* did we do color-correction ? */
748      {
749        iRetcode = mng_clear_cms (pData);
750
751        if (iRetcode)                  /* on error bail out */
752          return iRetcode;
753      }
754#endif
755#ifndef MNG_SKIPCHUNK_BACK
756                                       /* background image ? */
757      if ((pData->bHasBACK) && (pData->iBACKmandatory & 0x02) && (pData->iBACKimageid))
758      {
759        mng_imagep pImage;
760                                       /* let's find that object then */
761        pData->pRetrieveobj = mng_find_imageobject (pData, pData->iBACKimageid);
762        pImage              = (mng_imagep)pData->pRetrieveobj;
763                                       /* exists, viewable and visible ? */
764        if ((pImage) && (pImage->bViewable) && (pImage->bVisible))
765        {                              /* will it fall within the target region ? */
766          if ((pImage->iPosx < pData->iDestr) && (pImage->iPosy < pData->iDestb)             &&
767              ((pData->iBACKtile) ||
768               ((pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth  >= pData->iDestl) &&
769                (pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight >= pData->iDestt)    )) &&
770              ((!pImage->bClipped) ||
771               ((pImage->iClipl <= pImage->iClipr) && (pImage->iClipt <= pImage->iClipb)     &&
772                (pImage->iClipl < pData->iDestr)   && (pImage->iClipr >= pData->iDestl)      &&
773                (pImage->iClipt < pData->iDestb)   && (pImage->iClipb >= pData->iDestt)         )))
774          {                            /* right; we've got ourselves something to do */
775            if (pImage->bClipped)      /* clip output region with image's clipping region ? */
776            {
777              if (pImage->iClipl > pData->iDestl)
778                pData->iDestl = pImage->iClipl;
779              if (pImage->iClipr < pData->iDestr)
780                pData->iDestr = pImage->iClipr;
781              if (pImage->iClipt > pData->iDestt)
782                pData->iDestt = pImage->iClipt;
783              if (pImage->iClipb < pData->iDestb)
784                pData->iDestb = pImage->iClipb;
785            }
786                                       /* image offset does some extra clipping too ! */
787            if (pImage->iPosx > pData->iDestl)
788              pData->iDestl = pImage->iPosx;
789            if (pImage->iPosy > pData->iDestt)
790              pData->iDestt = pImage->iPosy;
791
792            if (!pData->iBACKtile)     /* without tiling further clipping is needed */
793            {
794              if (pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth  < pData->iDestr)
795                pData->iDestr = pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth;
796              if (pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight < pData->iDestb)
797                pData->iDestb = pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight;
798            }
799            
800            pData->iSourcel    = 0;    /* source relative to destination */
801            pData->iSourcer    = pData->iDestr - pData->iDestl;
802            pData->iSourcet    = 0;
803            pData->iSourceb    = pData->iDestb - pData->iDestt;
804                                       /* 16-bit background ? */
805
806#ifdef MNG_NO_16BIT_SUPPORT
807            pData->bIsRGBA16   = MNG_FALSE;
808#else
809            pData->bIsRGBA16      = (mng_bool)(pImage->pImgbuf->iBitdepth > 8);
810#endif
811                                       /* let restore routine know the offsets !!! */
812            pData->iBackimgoffsx  = pImage->iPosx;
813            pData->iBackimgoffsy  = pImage->iPosy;
814            pData->iBackimgwidth  = pImage->pImgbuf->iWidth;
815            pData->iBackimgheight = pImage->pImgbuf->iHeight;
816            pData->iRow           = 0; /* start at the top again !! */
817                                       /* determine background object retrieval routine */
818            switch (pImage->pImgbuf->iColortype)
819            {
820              case  0 : {
821#ifndef MNG_NO_16BIT_SUPPORT
822                          if (pImage->pImgbuf->iBitdepth > 8)
823                            pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
824                          else
825#endif
826                            pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
827
828                          pData->bIsOpaque      = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
829                          break;
830                        }
831
832              case  2 : {
833#ifndef MNG_NO_16BIT_SUPPORT
834                          if (pImage->pImgbuf->iBitdepth > 8)
835                            pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
836                          else
837#endif
838                            pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
839
840                          pData->bIsOpaque      = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
841                          break;
842                        }
843
844              case  3 : { pData->fRetrieverow   = (mng_fptr)mng_retrieve_idx8;
845                          pData->bIsOpaque      = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
846                          break;
847                        }
848
849              case  4 : { 
850#ifndef MNG_NO_16BIT_SUPPORT
851			if (pImage->pImgbuf->iBitdepth > 8)
852                            pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
853                          else
854#endif
855                            pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
856
857                          pData->bIsOpaque      = MNG_FALSE;
858                          break;
859                        }
860
861              case  6 : {
862#ifndef MNG_NO_16BIT_SUPPORT
863                          if (pImage->pImgbuf->iBitdepth > 8)
864                            pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
865                          else
866#endif
867                            pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
868
869                          pData->bIsOpaque      = MNG_FALSE;
870                          break;
871                        }
872
873              case  8 : {
874#ifndef MNG_NO_16BIT_SUPPORT
875                          if (pImage->pImgbuf->iBitdepth > 8)
876                            pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
877                          else
878#endif
879                            pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
880
881                          pData->bIsOpaque      = MNG_TRUE;
882                          break;
883                        }
884
885              case 10 : {
886#ifndef MNG_NO_16BIT_SUPPORT
887                          if (pImage->pImgbuf->iBitdepth > 8)
888                            pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
889                          else
890#endif
891                            pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
892
893                          pData->bIsOpaque      = MNG_TRUE;
894                          break;
895                        }
896
897              case 12 : {
898#ifndef MNG_NO_16BIT_SUPPORT
899                          if (pImage->pImgbuf->iBitdepth > 8)
900                            pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
901                          else
902#endif
903                            pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
904
905                          pData->bIsOpaque      = MNG_FALSE;
906                          break;
907                        }
908
909              case 14 : {
910#ifndef MNG_NO_16BIT_SUPPORT
911                          if (pImage->pImgbuf->iBitdepth > 8)
912                            pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
913                          else
914#endif
915                            pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
916
917                          pData->bIsOpaque      = MNG_FALSE;
918                          break;
919                        }
920            }
921
922#ifdef MNG_NO_CMS
923            iRetcode = MNG_NOERROR;
924#else
925#if defined(MNG_FULL_CMS)              /* determine color-management routine */
926            iRetcode = mng_init_full_cms   (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
927#elif defined(MNG_GAMMA_ONLY)
928            iRetcode = mng_init_gamma_only (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
929#elif defined(MNG_APP_CMS)
930            iRetcode = mng_init_app_cms    (pData, MNG_FALSE, MNG_FALSE, MNG_TRUE);
931#endif
932            if (iRetcode)              /* on error bail out */
933              return iRetcode;
934#endif /* MNG_NO_CMS */
935                                       /* get temporary row-buffers */
936            MNG_ALLOC (pData, pData->pPrevrow, pData->iRowsize);
937            MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize);
938
939            iY       = pData->iDestt;  /* this is where we start */
940            iRetcode = MNG_NOERROR;    /* so far, so good */
941
942            while ((!iRetcode) && (iY < pData->iDestb))
943            {                          /* restore a background row */
944              iRetcode = mng_restore_bkgd_backimage (pData);
945                                       /* color correction ? */
946              if ((!iRetcode) && (pData->fCorrectrow))
947                iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData);
948
949              if (!iRetcode)           /* so... display it */
950                iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
951
952              if (!iRetcode)
953                iRetcode = mng_next_row (pData);
954
955              iY++;                    /* and next line */
956            }
957                                       /* drop temporary row-buffers */
958            MNG_FREE (pData, pData->pRGBArow, pData->iRowsize);
959            MNG_FREE (pData, pData->pPrevrow, pData->iRowsize);
960
961            if (iRetcode)              /* on error bail out */
962              return iRetcode;
963
964#if defined(MNG_FULL_CMS)              /* cleanup cms stuff */
965            iRetcode = mng_clear_cms (pData);
966
967            if (iRetcode)              /* on error bail out */
968              return iRetcode;
969#endif
970          }
971        }
972      }
973#endif
974    }
975
976    pData->iDestl       = iDestl;      /* restore values */
977    pData->iDestr       = iDestr;
978    pData->iDestt       = iDestt;
979    pData->iDestb       = iDestb;
980    pData->iSourcel     = iSourcel;
981    pData->iSourcer     = iSourcer;
982    pData->iSourcet     = iSourcet;
983    pData->iSourceb     = iSourceb;
984    pData->iPass        = iPass;
985    pData->iRow         = iRow;
986    pData->iRowinc      = iRowinc;
987  

Large files files are truncated, but you can click here to view the full file