~ubuntu-branches/ubuntu/oneiric/libmng/oneiric

« back to all changes in this revision

Viewing changes to libmng_display.c

  • Committer: Bazaar Package Importer
  • Author(s): Shiju p. Nair
  • Date: 2006-04-07 09:49:11 UTC
  • mfrom: (0.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060407094911-ay3179o63gvlh4ll
Tags: 1.0.9-1
* New upstream release. (closes: #303968, #271979)
* Patch from Aurelien Jarno <aurel32@debian.org> to support GNU/kFreeBSD.
  Closes: #314696)
* Patch from Christopher Bodenstein <cb@physicman.net> to support
  hurd-i386. (closes: #361103)
* README.Debian provide information on what options are compiled in to
  libmng.(closes: #174523)

Show diffs side-by-side

added added

removed removed

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