1
/* ************************************************************************** */
2
/* * For conditions of distribution and use, * */
3
/* * see copyright notice in libmng.h * */
4
/* ************************************************************************** */
6
/* * project : libmng * */
7
/* * file : libmng_display.c copyright (c) 2000-2004 G.Juyn * */
8
/* * version : 1.0.8 * */
10
/* * purpose : Display management (implementation) * */
12
/* * author : G.Juyn * */
14
/* * comment : implementation of the display management routines * */
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 * */
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) * */
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 * */
67
/* * 0.9.0 - 06/30/2000 - G.Juyn * */
68
/* * - changed refresh parameters to 'x,y,width,height' * */
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 * */
85
/* * 0.9.2 - 08/05/2000 - G.Juyn * */
86
/* * - changed file-prefixes * */
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 * */
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 * */
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 * */
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 * */
143
/* * 1.0.2 - 06/25/2001 - G.Juyn * */
144
/* * - fixed memory-leak with delta-images (Thanks Michael!) * */
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* */
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 * */
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 * */
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 * */
214
/* ************************************************************************** */
217
#include "libmng_data.h"
218
#include "libmng_error.h"
219
#include "libmng_trace.h"
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"
233
#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)
234
#pragma option -A /* force ANSI-C */
237
/* ************************************************************************** */
239
#ifdef MNG_INCLUDE_DISPLAY_PROCS
241
/* ************************************************************************** */
243
MNG_LOCAL mng_retcode set_delay (mng_datap pData,
244
mng_uint32 iInterval)
246
if (!iInterval) /* at least 1 msec please! */
249
if (pData->bRunning) /* only when really displaying */
250
if (!pData->fSettimer ((mng_handle)pData, iInterval))
251
MNG_ERROR (pData, MNG_APPTIMERERROR)
253
#ifdef MNG_SUPPORT_DYNAMICMNG
254
if ((!pData->bDynamic) || (pData->bRunning))
258
pData->bTimerset = MNG_TRUE; /* and indicate so */
263
/* ************************************************************************** */
265
MNG_LOCAL mng_uint32 calculate_delay (mng_datap pData,
268
mng_uint32 iTicks = pData->iTicks;
269
mng_uint32 iWaitfor = 1; /* default non-MNG delay */
271
if (!iTicks) /* tick_count not specified ? */
272
if (pData->eImagetype == mng_it_mng)
277
switch (pData->iSpeed) /* honor speed modifier */
281
iWaitfor = (mng_uint32)(( 500 * iDelay) / iTicks);
286
iWaitfor = (mng_uint32)((3000 * iDelay) / iTicks);
289
case mng_st_slowest :
291
iWaitfor = (mng_uint32)((8000 * iDelay) / iTicks);
296
iWaitfor = (mng_uint32)((1000 * iDelay) / iTicks);
304
/* ************************************************************************** */
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) * */
310
/* ************************************************************************** */
312
mng_retcode mng_display_progressive_refresh (mng_datap pData,
313
mng_uint32 iInterval)
315
{ /* let the app refresh first ? */
316
if ((pData->bRunning) && (!pData->bSkipping) &&
317
(pData->iUpdatetop < pData->iUpdatebottom) && (pData->iUpdateleft < pData->iUpdateright))
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)
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);
335
if (iRetcode) /* on error bail out */
344
/* ************************************************************************** */
346
/* * Generic display routines * */
348
/* ************************************************************************** */
350
MNG_LOCAL mng_retcode interframe_delay (mng_datap pData)
352
mng_uint32 iWaitfor = 0;
353
mng_uint32 iInterval;
354
mng_uint32 iRuninterval;
355
mng_retcode iRetcode;
357
#ifdef MNG_SUPPORT_TRACE
358
MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_START)
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)
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;
378
if (pData->bOnlyfirstframe) /* only processing first frame after TERM ? */
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;
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;
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;
403
pData->iRuntime = pData->iRuntime - pData->iStarttime;
410
iWaitfor = calculate_delay (pData, pData->iFramedelay);
412
if (iWaitfor > iRuninterval) /* delay necessary ? */
413
iInterval = iWaitfor - iRuninterval;
415
iInterval = 1; /* force app to process messageloop */
416
/* set the timer ? */
417
if (((pData->bRunning) || (pData->bSearching) || (pData->bReading)) &&
420
iRetcode = set_delay (pData, iInterval);
422
if (iRetcode) /* on error bail out */
427
if (!pData->bSkipping) /* increase frametime in advance */
428
pData->iFrametime = pData->iFrametime + iWaitfor;
429
/* setup for next delay */
430
pData->iFramedelay = pData->iNextdelay;
433
#ifdef MNG_SUPPORT_TRACE
434
MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_END)
440
/* ************************************************************************** */
442
MNG_LOCAL void set_display_routine (mng_datap pData)
443
{ /* actively running ? */
444
if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
446
switch (pData->iCanvasstyle) /* determine display routine */
448
#ifndef MNG_SKIPCANVAS_RGB8
449
case MNG_CANVAS_RGB8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8; break; }
451
#ifndef MNG_SKIPCANVAS_RGBA8
452
case MNG_CANVAS_RGBA8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba8; break; }
454
#ifndef MNG_SKIPCANVAS_RGBA8_PM
455
case MNG_CANVAS_RGBA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_rgba8_pm; break; }
457
#ifndef MNG_SKIPCANVAS_ARGB8
458
case MNG_CANVAS_ARGB8 : { pData->fDisplayrow = (mng_fptr)mng_display_argb8; break; }
460
#ifndef MNG_SKIPCANVAS_ARGB8_PM
461
case MNG_CANVAS_ARGB8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_argb8_pm; break; }
463
#ifndef MNG_SKIPCANVAS_RGB8_A8
464
case MNG_CANVAS_RGB8_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8_a8; break; }
466
#ifndef MNG_SKIPCANVAS_BGR8
467
case MNG_CANVAS_BGR8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr8; break; }
469
#ifndef MNG_SKIPCANVAS_BGRX8
470
case MNG_CANVAS_BGRX8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgrx8; break; }
472
#ifndef MNG_SKIPCANVAS_BGRA8
473
case MNG_CANVAS_BGRA8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra8; break; }
475
#ifndef MNG_SKIPCANVAS_BGRA8_PM
476
case MNG_CANVAS_BGRA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_bgra8_pm; break; }
478
#ifndef MNG_SKIPCANVAS_ABGR8
479
case MNG_CANVAS_ABGR8 : { pData->fDisplayrow = (mng_fptr)mng_display_abgr8; break; }
481
#ifndef MNG_SKIPCANVAS_ABGR8_PM
482
case MNG_CANVAS_ABGR8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_abgr8_pm; break; }
484
#ifndef MNG_SKIPCANVAS_RGB565
485
case MNG_CANVAS_RGB565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb565; break; }
487
#ifndef MNG_SKIPCANVAS_RGBA565
488
case MNG_CANVAS_RGBA565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba565; break; }
490
#ifndef MNG_SKIPCANVAS_BGR565
491
case MNG_CANVAS_BGR565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565; break; }
493
#ifndef MNG_SKIPCANVAS_BGRA565
494
case MNG_CANVAS_BGRA565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra565; break; }
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; } */
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; } */
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; } */
524
/* ************************************************************************** */
526
MNG_LOCAL mng_retcode load_bkgdlayer (mng_datap pData)
528
#ifdef MNG_SUPPORT_TRACE
529
MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_START)
531
/* actively running ? */
532
if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
535
mng_retcode iRetcode;
536
mng_bool bColorcorr = MNG_FALSE;
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;
563
pData->iDestl = 0; /* determine clipping region */
565
pData->iDestr = pData->iWidth;
566
pData->iDestb = pData->iHeight;
568
if (pData->bFrameclipping) /* frame clipping specified ? */
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);
575
/* anything to clear ? */
576
if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt))
578
pData->iPass = -1; /* these are the object's dimensions now */
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;
588
pData->iSourcel = 0; /* source relative to destination */
589
pData->iSourcer = pData->iDestr - pData->iDestl;
591
pData->iSourceb = pData->iDestb - pData->iDestt;
593
set_display_routine (pData); /* determine display routine */
594
/* default restore using preset BG color */
595
pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgcolor;
597
#ifndef MNG_SKIPCHUNK_bKGD
598
if (((pData->eImagetype == mng_it_png) || (pData->eImagetype == mng_it_jng)) &&
600
{ /* prefer bKGD in PNG/JNG */
601
if (!pData->pCurrentobj)
602
pData->pCurrentobj = pData->pObjzero;
604
if (((mng_imagep)pData->pCurrentobj)->pImgbuf->bHasBKGD)
606
pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bkgd;
607
bColorcorr = MNG_TRUE;
612
if (pData->fGetbkgdline) /* background-canvas-access callback set ? */
614
switch (pData->iBkgdstyle)
616
#ifndef MNG_SKIPCANVAS_RGB8
617
case MNG_CANVAS_RGB8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb8; break; }
619
#ifndef MNG_SKIPCANVAS_BGR8
620
case MNG_CANVAS_BGR8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr8; break; }
622
#ifndef MNG_SKIPCANVAS_BGRX8
623
case MNG_CANVAS_BGRX8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgrx8; break; }
625
#ifndef MNG_SKIPCANVAS_BGR565
626
case MNG_CANVAS_BGR565 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr565; break; }
628
#ifndef MNG_SKIPCANVAS_RGB565
629
case MNG_CANVAS_RGB565 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb565; break; }
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; } */
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; } */
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; } */
646
{ /* background image ? */
647
if ((pData->iBACKmandatory & 0x02) && (pData->iBACKimageid))
649
pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor;
650
bColorcorr = MNG_TRUE;
652
else /* background color ? */
653
if (pData->iBACKmandatory & 0x01)
655
pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor;
656
bColorcorr = MNG_TRUE;
660
pData->fCorrectrow = MNG_NULL; /* default no color-correction */
662
if (bColorcorr) /* do we have to do color-correction ? */
665
iRetcode = MNG_NOERROR;
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);
674
if (iRetcode) /* on error bail out */
676
#endif /* MNG_NO_CMS */
678
/* get a temporary row-buffer */
679
MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize)
681
iY = pData->iDestt; /* this is where we start */
682
iRetcode = MNG_NOERROR; /* so far, so good */
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);
691
if (!iRetcode) /* so... display it */
692
iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
695
iRetcode = mng_next_row (pData);
697
iY++; /* and next line */
699
/* drop the temporary row-buffer */
700
MNG_FREE (pData, pData->pRGBArow, pData->iRowsize)
702
if (iRetcode) /* on error bail out */
705
#if defined(MNG_FULL_CMS) /* cleanup cms stuff */
706
if (bColorcorr) /* did we do color-correction ? */
708
iRetcode = mng_clear_cms (pData);
710
if (iRetcode) /* on error bail out */
714
#ifndef MNG_SKIPCHUNK_BACK
715
/* background image ? */
716
if ((pData->bHasBACK) && (pData->iBACKmandatory & 0x02) && (pData->iBACKimageid))
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 ? */
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;
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;
751
if (!pData->iBACKtile) /* without tiling further clipping is needed */
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;
759
pData->iSourcel = 0; /* source relative to destination */
760
pData->iSourcer = pData->iDestr - pData->iDestl;
762
pData->iSourceb = pData->iDestb - pData->iDestt;
763
/* 16-bit background ? */
765
#ifdef MNG_NO_16BIT_SUPPORT
766
pData->bIsRGBA16 = MNG_FALSE;
768
pData->bIsRGBA16 = (mng_bool)(pImage->pImgbuf->iBitdepth > 8);
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)
780
#ifndef MNG_NO_16BIT_SUPPORT
781
if (pImage->pImgbuf->iBitdepth > 8)
782
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
785
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
787
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
792
#ifndef MNG_NO_16BIT_SUPPORT
793
if (pImage->pImgbuf->iBitdepth > 8)
794
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
797
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
799
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
803
case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8;
804
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
809
#ifndef MNG_NO_16BIT_SUPPORT
810
if (pImage->pImgbuf->iBitdepth > 8)
811
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
814
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
816
pData->bIsOpaque = MNG_FALSE;
821
#ifndef MNG_NO_16BIT_SUPPORT
822
if (pImage->pImgbuf->iBitdepth > 8)
823
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
826
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
828
pData->bIsOpaque = MNG_FALSE;
833
#ifndef MNG_NO_16BIT_SUPPORT
834
if (pImage->pImgbuf->iBitdepth > 8)
835
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
838
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
840
pData->bIsOpaque = MNG_TRUE;
845
#ifndef MNG_NO_16BIT_SUPPORT
846
if (pImage->pImgbuf->iBitdepth > 8)
847
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
850
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
852
pData->bIsOpaque = MNG_TRUE;
857
#ifndef MNG_NO_16BIT_SUPPORT
858
if (pImage->pImgbuf->iBitdepth > 8)
859
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
862
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
864
pData->bIsOpaque = MNG_FALSE;
869
#ifndef MNG_NO_16BIT_SUPPORT
870
if (pImage->pImgbuf->iBitdepth > 8)
871
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
874
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
876
pData->bIsOpaque = MNG_FALSE;
882
iRetcode = MNG_NOERROR;
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);
891
if (iRetcode) /* on error bail out */
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)
898
iY = pData->iDestt; /* this is where we start */
899
iRetcode = MNG_NOERROR; /* so far, so good */
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);
908
if (!iRetcode) /* so... display it */
909
iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
912
iRetcode = mng_next_row (pData);
914
iY++; /* and next line */
916
/* drop temporary row-buffers */
917
MNG_FREE (pData, pData->pRGBArow, pData->iRowsize)
918
MNG_FREE (pData, pData->pPrevrow, pData->iRowsize)
920
if (iRetcode) /* on error bail out */
923
#if defined(MNG_FULL_CMS) /* cleanup cms stuff */
924
iRetcode = mng_clear_cms (pData);
926
if (iRetcode) /* on error bail out */
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;
945
pData->iRowinc = iRowinc;
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;
961
#ifdef MNG_SUPPORT_TRACE
962
MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_END)
968
/* ************************************************************************** */
970
MNG_LOCAL mng_retcode clear_canvas (mng_datap pData)
973
mng_retcode iRetcode;
975
#ifdef MNG_SUPPORT_TRACE
976
MNG_TRACE (pData, MNG_FN_CLEAR_CANVAS, MNG_LC_START)
979
pData->iDestl = 0; /* clipping region is full canvas! */
981
pData->iDestr = pData->iWidth;
982
pData->iDestb = pData->iHeight;
984
pData->iSourcel = 0; /* source is same as destination */
985
pData->iSourcer = pData->iWidth;
987
pData->iSourceb = pData->iHeight;
989
pData->iPass = -1; /* these are the object's dimensions now */
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;
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)
1004
iY = pData->iDestt; /* this is where we start */
1005
iRetcode = MNG_NOERROR; /* so far, so good */
1007
while ((!iRetcode) && (iY < pData->iDestb))
1008
{ /* clear a row then */
1009
iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
1012
iRetcode = mng_next_row (pData); /* adjust variables for next row */
1014
iY++; /* and next line */
1016
/* drop the temporary row-buffer */
1017
MNG_FREE (pData, pData->pRGBArow, pData->iRowsize)
1019
if (iRetcode) /* on error bail out */
1022
#ifdef MNG_SUPPORT_TRACE
1023
MNG_TRACE (pData, MNG_FN_CLEAR_CANVAS, MNG_LC_END)
1029
/* ************************************************************************** */
1031
MNG_LOCAL mng_retcode next_frame (mng_datap pData,
1032
mng_uint8 iFramemode,
1033
mng_uint8 iChangedelay,
1035
mng_uint8 iChangetimeout,
1036
mng_uint32 iTimeout,
1037
mng_uint8 iChangeclipping,
1038
mng_uint8 iCliptype,
1044
mng_retcode iRetcode = MNG_NOERROR;
1046
#ifdef MNG_SUPPORT_TRACE
1047
MNG_TRACE (pData, MNG_FN_NEXT_FRAME, MNG_LC_START)
1050
if (!pData->iBreakpoint) /* no previous break here ? */
1052
mng_uint8 iOldmode = pData->iFramemode;
1053
/* interframe delay required ? */
1054
#ifndef MNG_SKIPCHUNK_FRAM
1055
if ((iOldmode == 2) || (iOldmode == 4))
1057
if ((pData->iFrameseq) && (iFramemode != 1) && (iFramemode != 3))
1058
iRetcode = interframe_delay (pData);
1060
pData->iFramedelay = pData->iNextdelay;
1063
{ /* delay before inserting background layer? */
1064
if ((pData->bFramedone) && (iFramemode == 4))
1065
iRetcode = interframe_delay (pData);
1068
if (iRetcode) /* on error bail out */
1070
/* now we'll assume we're in the next frame! */
1071
if (iFramemode) /* save the new framing mode ? */
1073
pData->iFRAMmode = iFramemode;
1074
pData->iFramemode = iFramemode;
1076
else /* reload default */
1077
pData->iFramemode = pData->iFRAMmode;
1079
if (iChangedelay) /* delay changed ? */
1081
pData->iNextdelay = iDelay; /* for *after* next subframe */
1083
if ((iOldmode == 2) || (iOldmode == 4))
1084
pData->iFramedelay = pData->iFRAMdelay;
1086
if (iChangedelay == 2) /* also overall ? */
1087
pData->iFRAMdelay = iDelay;
1090
{ /* reload default */
1091
pData->iNextdelay = pData->iFRAMdelay;
1094
if (iChangetimeout) /* timeout changed ? */
1095
{ /* for next subframe */
1096
pData->iFrametimeout = iTimeout;
1098
if ((iChangetimeout == 2) || /* also overall ? */
1099
(iChangetimeout == 4) ||
1100
(iChangetimeout == 6) ||
1101
(iChangetimeout == 8))
1102
pData->iFRAMtimeout = iTimeout;
1104
else /* reload default */
1105
pData->iFrametimeout = pData->iFRAMtimeout;
1107
if (iChangeclipping) /* clipping changed ? */
1109
pData->bFrameclipping = MNG_TRUE;
1111
if (!iCliptype) /* absolute ? */
1113
pData->iFrameclipl = iClipl;
1114
pData->iFrameclipr = iClipr;
1115
pData->iFrameclipt = iClipt;
1116
pData->iFrameclipb = iClipb;
1120
pData->iFrameclipl = pData->iFrameclipl + iClipl;
1121
pData->iFrameclipr = pData->iFrameclipr + iClipr;
1122
pData->iFrameclipt = pData->iFrameclipt + iClipt;
1123
pData->iFrameclipb = pData->iFrameclipb + iClipb;
1126
if (iChangeclipping == 2) /* also overall ? */
1128
pData->bFRAMclipping = MNG_TRUE;
1130
if (!iCliptype) /* absolute ? */
1132
pData->iFRAMclipl = iClipl;
1133
pData->iFRAMclipr = iClipr;
1134
pData->iFRAMclipt = iClipt;
1135
pData->iFRAMclipb = iClipb;
1139
pData->iFRAMclipl = pData->iFRAMclipl + iClipl;
1140
pData->iFRAMclipr = pData->iFRAMclipr + iClipr;
1141
pData->iFRAMclipt = pData->iFRAMclipt + iClipt;
1142
pData->iFRAMclipb = pData->iFRAMclipb + iClipb;
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;
1157
if (!pData->bTimerset) /* timer still off ? */
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);
1163
if (iRetcode) /* on error bail out */
1166
pData->iFrameseq++; /* count the frame ! */
1167
pData->bFramedone = MNG_TRUE; /* and indicate we've done one */
1170
#ifdef MNG_SUPPORT_TRACE
1171
MNG_TRACE (pData, MNG_FN_NEXT_FRAME, MNG_LC_END)
1177
/* ************************************************************************** */
1179
MNG_LOCAL mng_retcode next_layer (mng_datap pData)
1182
mng_retcode iRetcode = MNG_NOERROR;
1184
#ifdef MNG_SUPPORT_TRACE
1185
MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_START)
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);
1194
pData->iFramedelay = pData->iNextdelay;
1196
if (iRetcode) /* on error bail out */
1200
if (!pData->bTimerset) /* timer still off ? */
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;
1207
{ /* for MNG we do it right away */
1208
iRetcode = load_bkgdlayer (pData);
1209
pData->iLayerseq++; /* and it counts as a layer then ! */
1213
if (pData->iFramemode == 3) /* restore background for each layer ? */
1214
iRetcode = load_bkgdlayer (pData);
1216
if (iRetcode) /* on error bail out */
1219
if (pData->bHasDHDR) /* processing a delta-image ? */
1220
pImage = (mng_imagep)pData->pDeltaImage;
1222
pImage = (mng_imagep)pData->pCurrentobj;
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))
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);
1237
else /* it's a single image ! */
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);
1245
if (pData->bFrameclipping) /* frame clipping specified ? */
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);
1253
if (pImage->bClipped) /* is the image clipped itself ? */
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);
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);
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);
1271
else /* it's a single image ! */
1273
pData->iSourcer = pData->iSourcel + pData->iDestr - pData->iDestl;
1274
pData->iSourceb = pData->iSourcet + pData->iDestb - pData->iDestt;
1277
pData->iLayerseq++; /* count the layer ! */
1280
#ifdef MNG_SUPPORT_TRACE
1281
MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_END)
1287
/* ************************************************************************** */
1289
mng_retcode mng_display_image (mng_datap pData,
1291
mng_bool bLayeradvanced)
1293
mng_retcode iRetcode;
1295
#ifdef MNG_SUPPORT_TRACE
1296
MNG_TRACE (pData, MNG_FN_DISPLAY_IMAGE, MNG_LC_START)
1298
/* actively running ? */
1299
if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
1301
if ( (!pData->iBreakpoint) && /* needs magnification ? */
1302
( (pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY) ) )
1304
iRetcode = mng_magnify_imageobject (pData, pImage);
1306
if (iRetcode) /* on error bail out */
1311
pData->pRetrieveobj = pImage; /* so retrieve-row and color-correction can find it */
1313
if (!bLayeradvanced) /* need to advance the layer ? */
1315
mng_imagep pSave = pData->pCurrentobj;
1316
pData->pCurrentobj = pImage;
1317
next_layer (pData); /* advance to next layer */
1318
pData->pCurrentobj = pSave;
1320
/* need to restore the background ? */
1321
if ((!pData->bTimerset) && (pData->bRestorebkgd))
1323
mng_imagep pSave = pData->pCurrentobj;
1324
pData->pCurrentobj = pImage;
1325
pData->bRestorebkgd = MNG_FALSE;
1326
iRetcode = load_bkgdlayer (pData);
1327
pData->pCurrentobj = pSave;
1329
if (iRetcode) /* on error bail out */
1332
pData->iLayerseq++; /* and it counts as a layer then ! */
1334
/* actively running ? */
1335
if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
1337
if (!pData->bTimerset) /* all systems still go ? */
1339
pData->iBreakpoint = 0; /* let's make absolutely sure... */
1340
/* anything to display ? */
1341
if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt))
1345
set_display_routine (pData); /* determine display routine */
1346
/* and image-buffer retrieval routine */
1347
switch (pImage->pImgbuf->iColortype)
1350
#ifndef MNG_NO_16BIT_SUPPORT
1351
if (pImage->pImgbuf->iBitdepth > 8)
1352
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
1355
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
1357
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
1362
#ifndef MNG_NO_16BIT_SUPPORT
1363
if (pImage->pImgbuf->iBitdepth > 8)
1364
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
1367
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
1369
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
1374
case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8;
1375
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
1381
#ifndef MNG_NO_16BIT_SUPPORT
1382
if (pImage->pImgbuf->iBitdepth > 8)
1383
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
1386
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
1388
pData->bIsOpaque = MNG_FALSE;
1394
#ifndef MNG_NO_16BIT_SUPPORT
1395
if (pImage->pImgbuf->iBitdepth > 8)
1396
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
1399
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
1401
pData->bIsOpaque = MNG_FALSE;
1406
#ifndef MNG_NO_16BIT_SUPPORT
1407
if (pImage->pImgbuf->iBitdepth > 8)
1408
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
1411
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
1413
pData->bIsOpaque = MNG_TRUE;
1418
#ifndef MNG_NO_16BIT_SUPPORT
1419
if (pImage->pImgbuf->iBitdepth > 8)
1420
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
1423
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
1425
pData->bIsOpaque = MNG_TRUE;
1431
#ifndef MNG_NO_16BIT_SUPPORT
1432
if (pImage->pImgbuf->iBitdepth > 8)
1433
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
1436
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
1438
pData->bIsOpaque = MNG_FALSE;
1444
#ifndef MNG_NO_16BIT_SUPPORT
1445
if (pImage->pImgbuf->iBitdepth > 8)
1446
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
1449
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
1451
pData->bIsOpaque = MNG_FALSE;
1457
pData->iPass = -1; /* these are the object's dimensions now */
1458
pData->iRow = pData->iSourcet;
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)
1469
pData->bIsRGBA16 = MNG_TRUE;
1470
pData->iRowsize = pData->iRowsamples << 3;
1474
pData->fCorrectrow = MNG_NULL; /* default no color-correction */
1477
iRetcode = MNG_NOERROR;
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);
1486
if (iRetcode) /* on error bail out */
1488
#endif /* MNG_NO_CMS */
1489
/* get a temporary row-buffer */
1490
MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize)
1492
iY = pData->iSourcet; /* this is where we start */
1494
while ((!iRetcode) && (iY < pData->iSourceb))
1496
iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData);
1497
/* color correction ? */
1498
if ((!iRetcode) && (pData->fCorrectrow))
1499
iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData);
1501
if (!iRetcode) /* so... display it */
1502
iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
1504
if (!iRetcode) /* adjust variables for next row */
1505
iRetcode = mng_next_row (pData);
1507
iY++; /* and next line */
1509
/* drop the temporary row-buffer */
1510
MNG_FREE (pData, pData->pRGBArow, pData->iRowsize)
1512
if (iRetcode) /* on error bail out */
1515
#if defined(MNG_FULL_CMS) /* cleanup cms stuff */
1516
iRetcode = mng_clear_cms (pData);
1518
if (iRetcode) /* on error bail out */
1525
#ifdef MNG_SUPPORT_TRACE
1526
MNG_TRACE (pData, MNG_FN_DISPLAY_IMAGE, MNG_LC_END)
1529
return MNG_NOERROR; /* whehehe, this is good ! */
1532
/* ************************************************************************** */
1534
#ifndef MNG_NO_DELTA_PNG
1535
mng_retcode mng_execute_delta_image (mng_datap pData,
1539
mng_imagedatap pBuftarget = pTarget->pImgbuf;
1540
mng_imagedatap pBufdelta = pDelta->pImgbuf;
1542
mng_retcode iRetcode;
1545
#ifdef MNG_SUPPORT_TRACE
1546
MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_START)
1548
/* actively running ? */
1549
if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
1551
if (pBufdelta->bHasPLTE) /* palette in delta ? */
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;
1560
for (iX = 0; iX < pBufdelta->iPLTEcount; iX++)
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;
1568
if (pBufdelta->bHasTRNS) /* cheap transparency in delta ? */
1570
switch (pData->iColortype) /* drop it into the target */
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;
1581
pBuftarget->iTRNSgray = 0;
1582
pBuftarget->iTRNSred = pBufdelta->iTRNSred;
1583
pBuftarget->iTRNSgreen = pBufdelta->iTRNSgreen;
1584
pBuftarget->iTRNSblue = pBufdelta->iTRNSblue;
1585
pBuftarget->iTRNScount = 0;
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;
1597
MNG_COPY (pBuftarget->aTRNSentries, pBufdelta->aTRNSentries, pBufdelta->iTRNScount)
1602
pBuftarget->bHasTRNS = MNG_TRUE; /* tell it it's got a tRNS now */
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;
1617
if (pBufdelta->bHasGAMA) /* gamma in source ? */
1619
pBuftarget->bHasGAMA = MNG_TRUE; /* drop it onto the target */
1620
pBuftarget->iGamma = pBufdelta->iGamma;
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;
1638
if (pBufdelta->bHasSRGB) /* sRGB in delta ? */
1639
{ /* drop it onto the target */
1640
pBuftarget->bHasSRGB = MNG_TRUE;
1641
pBuftarget->iRenderingintent = pBufdelta->iRenderingintent;
1644
#ifndef MNG_SKIPCHUNK_iCCP
1645
if (pBufdelta->bHasICCP) /* ICC profile in delta ? */
1647
pBuftarget->bHasICCP = MNG_TRUE; /* drop it onto the target */
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;
1658
/* need to execute delta pixels ? */
1659
if ((!pData->bDeltaimmediate) && (pData->iDeltatype != MNG_DELTATYPE_NOCHANGE))
1661
pData->fScalerow = MNG_NULL; /* not needed by default */
1663
switch (pBufdelta->iBitdepth) /* determine scaling routine */
1666
switch (pBuftarget->iBitdepth)
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; }
1679
switch (pBuftarget->iBitdepth)
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; }
1692
switch (pBuftarget->iBitdepth)
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; }
1705
switch (pBufdelta->iColortype)
1710
switch (pBuftarget->iBitdepth)
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; }
1723
#ifndef MNG_NO_16BIT_SUPPORT
1724
if (pBuftarget->iBitdepth == 16)
1725
pData->fScalerow = (mng_fptr)mng_scale_rgb8_rgb16;
1731
#ifndef MNG_NO_16BIT_SUPPORT
1732
if (pBuftarget->iBitdepth == 16)
1733
pData->fScalerow = (mng_fptr)mng_scale_ga8_ga16;
1739
#ifndef MNG_NO_16BIT_SUPPORT
1740
if (pBuftarget->iBitdepth == 16)
1741
pData->fScalerow = (mng_fptr)mng_scale_rgba8_rgba16;
1749
#ifndef MNG_NO_16BIT_SUPPORT
1751
switch (pBufdelta->iColortype)
1756
switch (pBuftarget->iBitdepth)
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; }
1767
if (pBuftarget->iBitdepth == 8)
1768
pData->fScalerow = (mng_fptr)mng_scale_rgb16_rgb8;
1773
if (pBuftarget->iBitdepth == 8)
1774
pData->fScalerow = (mng_fptr)mng_scale_ga16_ga8;
1779
if (pBuftarget->iBitdepth == 8)
1780
pData->fScalerow = (mng_fptr)mng_scale_rgba16_rgba8;
1790
pData->fDeltarow = MNG_NULL; /* let's assume there's nothing to do */
1792
switch (pBuftarget->iColortype) /* determine delta processing routine */
1795
case 8 : { /* gray */
1796
if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
1797
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
1798
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
1800
if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) ||
1801
(pBufdelta->iColortype == 8))
1803
switch (pBuftarget->iBitdepth)
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; }
1820
case 10 : { /* rgb */
1821
if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
1822
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
1823
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
1825
if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10))
1827
switch (pBuftarget->iBitdepth)
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; }
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) )
1845
if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3))
1847
switch (pBuftarget->iBitdepth)
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; }
1861
case 12 : { /* gray + alpha */
1862
if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
1863
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
1864
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
1866
if ((pBufdelta->iColortype == 4) || (pBufdelta->iColortype == 12))
1868
switch (pBuftarget->iBitdepth)
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; }
1878
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
1879
(pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
1881
if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) ||
1882
(pBufdelta->iColortype == 8))
1884
switch (pBuftarget->iBitdepth)
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; }
1894
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
1895
(pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
1897
if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3))
1899
switch (pBuftarget->iBitdepth)
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; }
1913
case 14 : { /* rgb + alpha */
1914
if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
1915
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
1916
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
1918
if ((pBufdelta->iColortype == 6) || (pBufdelta->iColortype == 14))
1920
switch (pBuftarget->iBitdepth)
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; }
1930
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
1931
(pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
1933
if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10))
1935
switch (pBuftarget->iBitdepth)
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; }
1945
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
1946
(pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
1948
if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3))
1950
switch (pBuftarget->iBitdepth)
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; }
1965
if (pData->fDeltarow) /* do we need to take action ? */
1967
pData->iPass = -1; /* setup row dimensions and stuff */
1968
pData->iRow = pData->iDeltaBlocky;
1970
pData->iCol = pData->iDeltaBlockx;
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;
1978
pSaveRGBA = pData->pRGBArow; /* save current temp-buffer! */
1979
/* get a temporary row-buffer */
1980
MNG_ALLOC (pData, pData->pRGBArow, (pBufdelta->iRowsize << 1))
1982
iY = 0; /* this is where we start */
1983
iRetcode = MNG_NOERROR; /* still oke for now */
1985
while ((!iRetcode) && (iY < pBufdelta->iHeight))
1987
mng_uint8p pWork = pBufdelta->pImgdata + (iY * pBufdelta->iRowsize);
1989
MNG_COPY (pData->pRGBArow, pWork, pBufdelta->iRowsize);
1991
if (pData->fScalerow) /* scale it (if necessary) */
1992
iRetcode = ((mng_scalerow)pData->fScalerow) (pData);
1994
if (!iRetcode) /* and... execute it */
1995
iRetcode = ((mng_deltarow)pData->fDeltarow) (pData);
1997
if (!iRetcode) /* adjust variables for next row */
1998
iRetcode = mng_next_row (pData);
2000
iY++; /* and next line */
2002
/* drop the temporary row-buffer */
2003
MNG_FREE (pData, pData->pRGBArow, (pBufdelta->iRowsize << 1))
2004
pData->pRGBArow = pSaveRGBA; /* restore saved temp-buffer! */
2006
if (iRetcode) /* on error bail out */
2011
MNG_ERROR (pData, MNG_INVALIDDELTA)
2016
#ifdef MNG_SUPPORT_TRACE
2017
MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_END)
2022
#endif /* MNG_NO_DELTA_PNG */
2024
/* ************************************************************************** */
2026
#ifndef MNG_SKIPCHUNK_SAVE
2027
MNG_LOCAL mng_retcode save_state (mng_datap pData)
2029
mng_savedatap pSave;
2032
#ifdef MNG_SUPPORT_TRACE
2033
MNG_TRACE (pData, MNG_FN_SAVE_STATE, MNG_LC_START)
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))
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 */
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;
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;
2069
pSave->iGlobalPLTEcount = pData->iGlobalPLTEcount;
2071
MNG_COPY (pSave->aGlobalPLTEentries, pData->aGlobalPLTEentries, sizeof (mng_rgbpaltab))
2073
pSave->iGlobalTRNSrawlen = pData->iGlobalTRNSrawlen;
2074
MNG_COPY (pSave->aGlobalTRNSrawdata, pData->aGlobalTRNSrawdata, 256)
2076
pSave->iGlobalGamma = pData->iGlobalGamma;
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;
2089
pSave->iGlobalRendintent = pData->iGlobalRendintent;
2091
#ifndef MNG_SKIPCHUNK_iCCP
2092
pSave->iGlobalProfilesize = pData->iGlobalProfilesize;
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)
2101
#ifndef MNG_SKIPCHUNK_bKGD
2102
pSave->iGlobalBKGDred = pData->iGlobalBKGDred;
2103
pSave->iGlobalBKGDgreen = pData->iGlobalBKGDgreen;
2104
pSave->iGlobalBKGDblue = pData->iGlobalBKGDblue;
2107
/* freeze current image objects */
2108
pImage = (mng_imagep)pData->pFirstimgobj;
2111
{ /* freeze the object AND it's buffer */
2112
pImage->bFrozen = MNG_TRUE;
2113
pImage->pImgbuf->bFrozen = MNG_TRUE;
2115
pImage = (mng_imagep)pImage->sHeader.pNext;
2118
#ifdef MNG_SUPPORT_TRACE
2119
MNG_TRACE (pData, MNG_FN_SAVE_STATE, MNG_LC_END)
2126
/* ************************************************************************** */
2128
mng_retcode mng_reset_objzero (mng_datap pData)
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);
2134
if (iRetcode) /* on error bail out */
2137
pImage->bVisible = MNG_TRUE;
2138
pImage->bViewable = MNG_TRUE;
2141
pImage->bClipped = MNG_FALSE;
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;
2160
/* ************************************************************************** */
2162
MNG_LOCAL mng_retcode restore_state (mng_datap pData)
2164
#ifndef MNG_SKIPCHUNK_SAVE
2165
mng_savedatap pSave;
2168
mng_retcode iRetcode;
2170
#ifdef MNG_SUPPORT_TRACE
2171
MNG_TRACE (pData, MNG_FN_RESTORE_STATE, MNG_LC_START)
2173
/* restore object 0 status !!! */
2174
iRetcode = mng_reset_objzero (pData);
2176
if (iRetcode) /* on error bail out */
2178
/* fresh cycle; fake no frames done yet */
2179
pData->bFramedone = MNG_FALSE;
2181
#ifndef MNG_SKIPCHUNK_SAVE
2182
if (pData->pSavedata) /* do we have a saved state ? */
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 */
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;
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;
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; */
2221
/* pData->iNextdelay = pSave->iFRAMdelay; */
2222
pData->iNextdelay = pData->iFramedelay;
2224
pData->iGlobalPLTEcount = pSave->iGlobalPLTEcount;
2225
MNG_COPY (pData->aGlobalPLTEentries, pSave->aGlobalPLTEentries, sizeof (mng_rgbpaltab))
2227
pData->iGlobalTRNSrawlen = pSave->iGlobalTRNSrawlen;
2228
MNG_COPY (pData->aGlobalTRNSrawdata, pSave->aGlobalTRNSrawdata, 256)
2230
pData->iGlobalGamma = pSave->iGlobalGamma;
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;
2243
pData->iGlobalRendintent = pSave->iGlobalRendintent;
2245
#ifndef MNG_SKIPCHUNK_iCCP
2246
pData->iGlobalProfilesize = pSave->iGlobalProfilesize;
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)
2255
#ifndef MNG_SKIPCHUNK_bKGD
2256
pData->iGlobalBKGDred = pSave->iGlobalBKGDred;
2257
pData->iGlobalBKGDgreen = pSave->iGlobalBKGDgreen;
2258
pData->iGlobalBKGDblue = pSave->iGlobalBKGDblue;
2261
else /* no saved-data; so reset the lot */
2262
#endif /* SKIPCHUNK_SAVE */
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 */
2274
if (!pData->bMisplacedTERM) /* backward compatible ugliness !!! */
2276
pData->iBACKred = 0;
2277
pData->iBACKgreen = 0;
2278
pData->iBACKblue = 0;
2279
pData->iBACKmandatory = 0;
2280
pData->iBACKimageid = 0;
2281
pData->iBACKtile = 0;
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;
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; */
2302
/* pData->iNextdelay = 1; */
2303
pData->iNextdelay = pData->iFramedelay;
2305
pData->iGlobalPLTEcount = 0;
2307
pData->iGlobalTRNSrawlen = 0;
2309
pData->iGlobalGamma = 0;
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;
2322
pData->iGlobalRendintent = 0;
2324
#ifndef MNG_SKIPCHUNK_iCCP
2325
if (pData->iGlobalProfilesize) /* free a previous profile ? */
2326
MNG_FREE (pData, pData->pGlobalProfile, pData->iGlobalProfilesize)
2328
pData->iGlobalProfilesize = 0;
2331
#ifndef MNG_SKIPCHUNK_bKGD
2332
pData->iGlobalBKGDred = 0;
2333
pData->iGlobalBKGDgreen = 0;
2334
pData->iGlobalBKGDblue = 0;
2338
if (!pData->bMisplacedTERM) /* backward compatible ugliness !!! */
2340
pImage = (mng_imagep)pData->pFirstimgobj;
2341
/* drop un-frozen image objects */
2344
mng_imagep pNext = (mng_imagep)pImage->sHeader.pNext;
2346
if (!pImage->bFrozen) /* is it un-frozen ? */
2348
mng_imagep pPrev = (mng_imagep)pImage->sHeader.pPrev;
2350
if (pPrev) /* unlink it */
2351
pPrev->sHeader.pNext = pNext;
2353
pData->pFirstimgobj = pNext;
2356
pNext->sHeader.pPrev = pPrev;
2358
pData->pLastimgobj = pPrev;
2360
if (pImage->pImgbuf->bFrozen) /* buffer frozen ? */
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))
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))
2375
if (iRetcode) /* on error bail out */
2380
pImage = pNext; /* neeeext */
2384
#ifdef MNG_SUPPORT_TRACE
2385
MNG_TRACE (pData, MNG_FN_RESTORE_STATE, MNG_LC_END)
2391
/* ************************************************************************** */
2393
/* * General display processing routine * */
2395
/* ************************************************************************** */
2397
mng_retcode mng_process_display (mng_datap pData)
2399
mng_retcode iRetcode = MNG_NOERROR;
2401
#ifdef MNG_SUPPORT_TRACE
2402
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY, MNG_LC_START)
2405
if (!pData->iBreakpoint) /* not broken previously ? */
2407
if ((pData->iRequestframe) || (pData->iRequestlayer) || (pData->iRequesttime))
2409
pData->bSearching = MNG_TRUE; /* indicate we're searching */
2411
iRetcode = clear_canvas (pData); /* make the canvas virgin black ?!? */
2413
if (iRetcode) /* on error bail out */
2415
/* let's start from the top, shall we */
2416
pData->pCurraniobj = pData->pFirstaniobj;
2420
do /* process the objects */
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))
2427
switch (pData->iBreakpoint) /* return to broken display routine */
2429
#ifndef MNG_SKIPCHUNK_FRAM
2430
case 1 : { iRetcode = mng_process_display_fram2 (pData); break; }
2432
#ifndef MNG_SKIPCHUNK_SHOW
2433
case 3 : ; /* same as 4 !!! */
2434
case 4 : { iRetcode = mng_process_display_show (pData); break; }
2436
#ifndef MNG_SKIPCHUNK_CLON
2437
case 5 : { iRetcode = mng_process_display_clon2 (pData); break; }
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; }
2443
#ifndef MNG_SKIPCHUNK_PAST
2444
case 11 : { iRetcode = mng_process_display_past2 (pData); break; }
2446
default : MNG_ERROR (pData, MNG_INTERNALERROR)
2451
if (pData->pCurraniobj)
2452
iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj);
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))
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);
2466
if (!pData->pCurraniobj) /* refresh after last image ? */
2467
pData->bNeedrefresh = MNG_TRUE;
2470
if (pData->bSearching) /* are we looking for something ? */
2472
if ((pData->iRequestframe) && (pData->iRequestframe <= pData->iFrameseq))
2474
pData->iRequestframe = 0; /* found the frame ! */
2475
pData->bSearching = MNG_FALSE;
2478
if ((pData->iRequestlayer) && (pData->iRequestlayer <= pData->iLayerseq))
2480
pData->iRequestlayer = 0; /* found the layer ! */
2481
pData->bSearching = MNG_FALSE;
2484
if ((pData->iRequesttime) && (pData->iRequesttime <= pData->iFrametime))
2486
pData->iRequesttime = 0; /* found the playtime ! */
2487
pData->bSearching = MNG_FALSE;
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));
2495
if (iRetcode) /* on error bail out */
2497
/* refresh needed ? */
2498
if ((!pData->bTimerset) && (pData->bNeedrefresh))
2500
iRetcode = mng_display_progressive_refresh (pData, 1);
2502
if (iRetcode) /* on error bail out */
2506
if ((pData->bTimerset) && (!pData->iBreakpoint))
2507
pData->iBreakpoint = 99;
2509
if (!pData->bTimerset)
2510
pData->iBreakpoint = 0; /* reset if no timer break */
2512
if ((!pData->bTimerset) && (!pData->pCurraniobj))
2513
pData->bRunning = MNG_FALSE; /* all done now ! */
2515
#ifdef MNG_SUPPORT_TRACE
2516
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY, MNG_LC_END)
2522
/* ************************************************************************** */
2524
/* * Chunk display processing routines * */
2526
/* ************************************************************************** */
2528
#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
2529
png_imgtype mng_png_imgtype(mng_uint8 colortype, mng_uint8 bitdepth)
2536
png_imgtype imgtype[]={png_g1,png_none,png_none,png_idx1};
2537
ret=imgtype[colortype];
2542
png_imgtype imgtype[]={png_g2,png_none,png_none,png_idx2};
2543
ret=imgtype[colortype];
2548
png_imgtype imgtype[]={png_g4,png_none,png_none,png_idx4};
2549
ret=imgtype[colortype];
2554
png_imgtype imgtype[]={png_g8,png_none,png_rgb8,png_idx8,png_ga8,
2555
png_none,png_rgba8};
2556
ret=imgtype[colortype];
2559
#ifndef MNG_NO_16BIT_SUPPORT
2562
png_imgtype imgtype[]={png_g16,png_none,png_rgb16,png_none,png_ga16,
2563
png_none,png_rgba16};
2564
ret=imgtype[colortype];
2574
#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
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;
2580
#ifdef MNG_SUPPORT_TRACE
2581
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IHDR, MNG_LC_START)
2584
if (!pData->bHasDHDR)
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;
2595
if (!pData->iBreakpoint) /* not previously broken ? */
2597
mng_retcode iRetcode = MNG_NOERROR;
2599
#ifndef MNG_NO_DELTA_PNG
2600
if (pData->bHasDHDR) /* is a delta-image ? */
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);
2609
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
2610
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
2612
((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iBitdepth;
2613
((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iBitdepth;
2616
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
2617
(pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
2618
((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iBitdepth;
2620
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
2621
(pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
2622
((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iBitdepth;
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);
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);
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);
2654
if (iRetcode) /* on error bail out */
2658
if (!pData->bHasDHDR)
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) ) )
2670
next_layer (pData); /* that's a new layer then ! */
2672
if (pData->bTimerset) /* timer break ? */
2673
pData->iBreakpoint = 2;
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 */
2684
if (!pData->bTimerset) /* no timer break ? */
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);
2690
switch (pData->iColortype) /* determine row initialization routine */
2692
case 0 : { /* gray */
2693
switch (pData->iBitdepth)
2696
if (!pData->iInterlace)
2697
pData->fInitrowproc = (mng_fptr)mng_init_g1_ni;
2699
pData->fInitrowproc = (mng_fptr)mng_init_g1_i;
2704
if (!pData->iInterlace)
2705
pData->fInitrowproc = (mng_fptr)mng_init_g2_ni;
2707
pData->fInitrowproc = (mng_fptr)mng_init_g2_i;
2712
if (!pData->iInterlace)
2713
pData->fInitrowproc = (mng_fptr)mng_init_g4_ni;
2715
pData->fInitrowproc = (mng_fptr)mng_init_g4_i;
2719
if (!pData->iInterlace)
2720
pData->fInitrowproc = (mng_fptr)mng_init_g8_ni;
2722
pData->fInitrowproc = (mng_fptr)mng_init_g8_i;
2726
#ifndef MNG_NO_16BIT_SUPPORT
2728
if (!pData->iInterlace)
2729
pData->fInitrowproc = (mng_fptr)mng_init_g16_ni;
2731
pData->fInitrowproc = (mng_fptr)mng_init_g16_i;
2740
case 2 : { /* rgb */
2741
switch (pData->iBitdepth)
2744
if (!pData->iInterlace)
2745
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni;
2747
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i;
2750
#ifndef MNG_NO_16BIT_SUPPORT
2752
if (!pData->iInterlace)
2753
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni;
2755
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i;
2764
case 3 : { /* indexed */
2765
switch (pData->iBitdepth)
2768
if (!pData->iInterlace)
2769
pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni;
2771
pData->fInitrowproc = (mng_fptr)mng_init_idx1_i;
2776
if (!pData->iInterlace)
2777
pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni;
2779
pData->fInitrowproc = (mng_fptr)mng_init_idx2_i;
2784
if (!pData->iInterlace)
2785
pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni;
2787
pData->fInitrowproc = (mng_fptr)mng_init_idx4_i;
2792
if (!pData->iInterlace)
2793
pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni;
2795
pData->fInitrowproc = (mng_fptr)mng_init_idx8_i;
2803
case 4 : { /* gray+alpha */
2804
switch (pData->iBitdepth)
2807
if (!pData->iInterlace)
2808
pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni;
2810
pData->fInitrowproc = (mng_fptr)mng_init_ga8_i;
2814
#ifndef MNG_NO_16BIT_SUPPORT
2816
if (!pData->iInterlace)
2817
pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni;
2819
pData->fInitrowproc = (mng_fptr)mng_init_ga16_i;
2827
case 6 : { /* rgb+alpha */
2828
switch (pData->iBitdepth)
2831
if (!pData->iInterlace)
2832
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni;
2834
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i;
2838
#ifndef MNG_NO_16BIT_SUPPORT
2840
if (!pData->iInterlace)
2841
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni;
2843
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i;
2853
#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
2855
pData->iFilterofs = 0; /* determine filter characteristics */
2856
pData->iLevel0 = 0; /* default levels */
2861
#ifdef FILTER192 /* leveling & differing ? */
2862
if (pData->iFilter == MNG_FILTER_DIFFERING)
2864
switch (pData->iColortype)
2867
if (pData->iBitdepth <= 8)
2868
pData->iFilterofs = 1;
2870
pData->iFilterofs = 2;
2875
if (pData->iBitdepth <= 8)
2876
pData->iFilterofs = 3;
2878
pData->iFilterofs = 6;
2883
pData->iFilterofs = 1;
2887
if (pData->iBitdepth <= 8)
2888
pData->iFilterofs = 2;
2890
pData->iFilterofs = 4;
2895
if (pData->iBitdepth <= 8)
2896
pData->iFilterofs = 4;
2898
pData->iFilterofs = 8;
2906
#ifdef FILTER193 /* no adaptive filtering ? */
2907
if (pData->iFilter == MNG_FILTER_NOFILTER)
2908
pData->iPixelofs = pData->iFilterofs;
2911
pData->iPixelofs = pData->iFilterofs + 1;
2915
#ifdef MNG_SUPPORT_TRACE
2916
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IHDR, MNG_LC_END)
2922
/* ************************************************************************** */
2924
mng_retcode mng_process_display_idat (mng_datap pData,
2926
mng_uint8p pRawdata)
2928
mng_retcode iRetcode = MNG_NOERROR;
2930
#ifdef MNG_SUPPORT_TRACE
2931
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IDAT, MNG_LC_START)
2934
if (pData->bRestorebkgd) /* need to restore the background ? */
2936
pData->bRestorebkgd = MNG_FALSE;
2937
iRetcode = load_bkgdlayer (pData);
2939
if (iRetcode) /* on error bail out */
2942
pData->iLayerseq++; /* and it counts as a layer then ! */
2945
if (pData->fInitrowproc) /* need to initialize row processing? */
2947
iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData);
2948
pData->fInitrowproc = MNG_NULL; /* only call this once !!! */
2951
if ((!iRetcode) && (!pData->bInflating))
2952
/* initialize inflate */
2953
iRetcode = mngzlib_inflateinit (pData);
2955
if (!iRetcode) /* all ok? then inflate, my man */
2956
iRetcode = mngzlib_inflaterows (pData, iRawlen, pRawdata);
2958
if (iRetcode) /* on error bail out */
2961
#ifdef MNG_SUPPORT_TRACE
2962
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IDAT, MNG_LC_END)
2968
/* ************************************************************************** */
2970
mng_retcode mng_process_display_iend (mng_datap pData)
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);
2977
#ifdef MNG_SUPPORT_TRACE
2978
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IEND, MNG_LC_START)
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;
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;
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)))
3002
mng_imagep pImage = (mng_imagep)pData->pCurrentobj;
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);
3011
if (iRetcode) /* on error bail out */
3014
if (pData->bTimerset) /* timer break ? */
3015
pData->iBreakpoint = 6;
3019
if ((pData->bHasDHDR) || /* was it a DHDR stream */
3020
(pData->iBreakpoint == 8)) /* or did we get broken here last time ? */
3022
mng_imagep pImage = (mng_imagep)pData->pDeltaImage;
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);
3029
if (iRetcode) /* on error bail out */
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);
3038
if (iRetcode) /* on error bail out */
3041
if (pData->bTimerset) /* timer break ? */
3042
pData->iBreakpoint = 8;
3046
if (!pData->bTimerset) /* can we continue ? */
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);
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);
3059
if (iRetcode) /* on error bail out */
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);
3072
if (iRetcode) /* on error bail out */
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);
3084
if (iRetcode) /* on error bail out */
3091
if (bCleanup) /* if we got broken last time we need to cleanup */
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;
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;
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;
3118
#ifdef MNG_SUPPORT_TRACE
3119
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IEND, MNG_LC_END)
3125
/* ************************************************************************** */
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 */
3131
mng_retcode mng_process_display_mend (mng_datap pData)
3133
#ifdef MNG_SUPPORT_TRACE
3134
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_START)
3137
#ifdef MNG_SUPPORT_DYNAMICMNG
3138
if (pData->bStopafterseek) /* need to stop after this ? */
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 ! */
3146
/* TERM processed ? */
3147
if ((pData->bDisplaying) && (pData->bRunning) &&
3148
(pData->bHasTERM) && (pData->pTermaniobj))
3150
mng_retcode iRetcode;
3151
mng_ani_termp pTERM;
3152
/* get the right animation object ! */
3153
pTERM = (mng_ani_termp)pData->pTermaniobj;
3155
pData->iIterations++; /* increase iteration count */
3157
switch (pTERM->iTermaction) /* determine what to do! */
3159
case 0 : { /* show last frame indefinitly */
3160
break; /* piece of cake, that is... */
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;
3170
iRetcode = interframe_delay (pData);
3171
/* no interframe_delay? then fake it */
3172
if ((!iRetcode) && (!pData->bTimerset))
3173
iRetcode = set_delay (pData, 1);
3178
pData->iBreakpoint = 10;
3182
case 2 : { /* show first image after TERM */
3183
iRetcode = restore_state (pData);
3185
if (iRetcode) /* on error bail out */
3187
/* notify the app ? */
3188
if (pData->fProcessmend)
3189
if (!pData->fProcessmend ((mng_handle)pData, pData->iIterations, 0))
3190
MNG_ERROR (pData, MNG_APPMISCERROR)
3192
/* show first frame after TERM chunk */
3193
pData->pCurraniobj = pTERM;
3194
pData->bOnlyfirstframe = MNG_TRUE;
3195
pData->iFramesafterTERM = 0;
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;
3206
case 3 : { /* repeat */
3207
if ((pTERM->iItermax) && (pTERM->iItermax < 0x7FFFFFFF))
3210
if (pTERM->iItermax) /* go back to TERM ? */
3211
{ /* restore to initial or SAVE state */
3212
iRetcode = restore_state (pData);
3214
if (iRetcode) /* on error bail out */
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)
3222
/* restart from TERM chunk */
3223
pData->pCurraniobj = pTERM;
3225
if (pTERM->iDelay) /* set the delay (?) */
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;
3233
pData->bNeedrefresh = MNG_TRUE;
3238
switch (pTERM->iIteraction)
3240
case 0 : { /* show last frame indefinitly */
3241
break; /* piece of cake, that is... */
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;
3251
iRetcode = interframe_delay (pData);
3252
/* no interframe_delay? then fake it */
3253
if ((!iRetcode) && (!pData->bTimerset))
3254
iRetcode = set_delay (pData, 1);
3259
pData->iBreakpoint = 10;
3263
case 2 : { /* show first image after TERM */
3264
iRetcode = restore_state (pData);
3265
/* on error bail out */
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)
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;
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)
3299
if (!pData->pCurraniobj) /* always let the app refresh at the end ! */
3300
pData->bNeedrefresh = MNG_TRUE;
3302
#ifdef MNG_SUPPORT_TRACE
3303
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_END)
3309
/* ************************************************************************** */
3311
mng_retcode mng_process_display_mend2 (mng_datap pData)
3313
#ifdef MNG_SUPPORT_TRACE
3314
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_START)
3317
pData->bFrameclipping = MNG_FALSE; /* nothing to do but restore the app background */
3318
load_bkgdlayer (pData);
3320
#ifdef MNG_SUPPORT_TRACE
3321
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_END)
3327
/* ************************************************************************** */
3329
#ifndef MNG_SKIPCHUNK_DEFI
3330
mng_retcode mng_process_display_defi (mng_datap pData)
3334
#ifdef MNG_SUPPORT_TRACE
3335
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DEFI, MNG_LC_START)
3338
if (!pData->iDEFIobjectid) /* object id=0 ? */
3340
pImage = (mng_imagep)pData->pObjzero;
3342
if (pData->bDEFIhasdonotshow)
3343
pImage->bVisible = (mng_bool)(pData->iDEFIdonotshow == 0);
3345
if (pData->bDEFIhasloca)
3347
pImage->iPosx = pData->iDEFIlocax;
3348
pImage->iPosy = pData->iDEFIlocay;
3351
if (pData->bDEFIhasclip)
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;
3360
pData->pCurrentobj = 0; /* not a real object ! */
3363
{ /* already exists ? */
3364
pImage = (mng_imagep)mng_find_imageobject (pData, pData->iDEFIobjectid);
3366
if (!pImage) /* if not; create new */
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,
3378
if (iRetcode) /* on error bail out */
3382
{ /* exists; then set new info */
3383
if (pData->bDEFIhasdonotshow)
3384
pImage->bVisible = (mng_bool)(pData->iDEFIdonotshow == 0);
3386
pImage->bViewable = MNG_FALSE;
3388
if (pData->bDEFIhasloca)
3390
pImage->iPosx = pData->iDEFIlocax;
3391
pImage->iPosy = pData->iDEFIlocay;
3394
if (pData->bDEFIhasclip)
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;
3403
if (pData->bDEFIhasconcrete)
3404
pImage->pImgbuf->bConcrete = (mng_bool)(pData->iDEFIconcrete == 1);
3407
pData->pCurrentobj = pImage; /* others may want to know this */
3410
#ifdef MNG_SUPPORT_TRACE
3411
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DEFI, MNG_LC_END)
3418
/* ************************************************************************** */
3420
#ifndef MNG_SKIPCHUNK_BASI
3421
mng_retcode mng_process_display_basi (mng_datap pData,
3427
mng_uint8 iViewable)
3428
{ /* address the current "object" if any */
3429
mng_imagep pImage = (mng_imagep)pData->pCurrentobj;
3432
mng_imagedatap pBuf;
3433
mng_retcode iRetcode;
3435
#ifdef MNG_SUPPORT_TRACE
3436
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_BASI, MNG_LC_START)
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;
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 */
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 */
3460
pWork = pBuf->pImgdata; /* fill the object-buffer with the specified
3462
switch (pData->iColortype) /* depending on color_type & bit_depth */
3464
case 0 : { /* gray */
3465
#ifndef MNG_NO_16BIT_SUPPORT
3466
if (pData->iBitdepth == 16)
3468
#ifdef MNG_DECREMENT_LOOPS
3469
for (iX = pData->iDatawidth * pData->iDataheight;
3472
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3475
mng_put_uint16 (pWork, iRed);
3482
#ifdef MNG_DECREMENT_LOOPS
3483
for (iX = pData->iDatawidth * pData->iDataheight;
3486
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3489
*pWork = (mng_uint8)iRed;
3494
if ((bHasalpha) && (!iAlpha))
3496
pBuf->bHasTRNS = MNG_TRUE;
3497
pBuf->iTRNSgray = iRed;
3503
case 2 : { /* rgb */
3504
#ifndef MNG_NO_16BIT_SUPPORT
3505
if (pData->iBitdepth == 16)
3507
#ifdef MNG_DECREMENT_LOOPS
3508
for (iX = pData->iDatawidth * pData->iDataheight;
3511
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3514
mng_put_uint16 (pWork, iRed );
3515
mng_put_uint16 (pWork+2, iGreen);
3516
mng_put_uint16 (pWork+4, iBlue );
3523
#ifdef MNG_DECREMENT_LOOPS
3524
for (iX = pData->iDatawidth * pData->iDataheight;
3527
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3530
*pWork = (mng_uint8)iRed;
3531
*(pWork+1) = (mng_uint8)iGreen;
3532
*(pWork+2) = (mng_uint8)iBlue;
3537
if ((bHasalpha) && (!iAlpha))
3539
pBuf->bHasTRNS = MNG_TRUE;
3540
pBuf->iTRNSred = iRed;
3541
pBuf->iTRNSgreen = iGreen;
3542
pBuf->iTRNSblue = iBlue;
3548
case 3 : { /* indexed */
3549
pBuf->bHasPLTE = MNG_TRUE;
3551
switch (pData->iBitdepth)
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; }
3560
pBuf->aPLTEentries [0].iRed = (mng_uint8)iRed;
3561
pBuf->aPLTEentries [0].iGreen = (mng_uint8)iGreen;
3562
pBuf->aPLTEentries [0].iBlue = (mng_uint8)iBlue;
3564
for (iX = 1; iX < pBuf->iPLTEcount; iX++)
3566
pBuf->aPLTEentries [iX].iRed = 0;
3567
pBuf->aPLTEentries [iX].iGreen = 0;
3568
pBuf->aPLTEentries [iX].iBlue = 0;
3571
if ((bHasalpha) && (iAlpha < 255))
3573
pBuf->bHasTRNS = MNG_TRUE;
3574
pBuf->iTRNScount = 1;
3575
pBuf->aTRNSentries [0] = (mng_uint8)iAlpha;
3581
case 4 : { /* gray+alpha */
3582
#ifndef MNG_NO_16BIT_SUPPORT
3583
if (pData->iBitdepth == 16)
3585
#ifdef MNG_DECREMENT_LOOPS
3586
for (iX = pData->iDatawidth * pData->iDataheight;
3589
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3592
mng_put_uint16 (pWork, iRed);
3593
mng_put_uint16 (pWork+2, iAlpha);
3600
#ifdef MNG_DECREMENT_LOOPS
3601
for (iX = pData->iDatawidth * pData->iDataheight;
3604
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3607
*pWork = (mng_uint8)iRed;
3608
*(pWork+1) = (mng_uint8)iAlpha;
3616
case 6 : { /* rgb+alpha */
3617
#ifndef MNG_NO_16BIT_SUPPORT
3618
if (pData->iBitdepth == 16)
3620
#ifdef MNG_DECREMENT_LOOPS
3621
for (iX = pData->iDatawidth * pData->iDataheight;
3624
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
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);
3637
#ifdef MNG_DECREMENT_LOOPS
3638
for (iX = pData->iDatawidth * pData->iDataheight;
3641
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3644
*pWork = (mng_uint8)iRed;
3645
*(pWork+1) = (mng_uint8)iGreen;
3646
*(pWork+2) = (mng_uint8)iBlue;
3647
*(pWork+3) = (mng_uint8)iAlpha;
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);
3661
switch (pData->iColortype) /* determine row initialization routine */
3662
{ /* just to accomodate IDAT if it arrives */
3663
case 0 : { /* gray */
3664
switch (pData->iBitdepth)
3667
if (!pData->iInterlace)
3668
pData->fInitrowproc = (mng_fptr)mng_init_g1_ni;
3670
pData->fInitrowproc = (mng_fptr)mng_init_g1_i;
3675
if (!pData->iInterlace)
3676
pData->fInitrowproc = (mng_fptr)mng_init_g2_ni;
3678
pData->fInitrowproc = (mng_fptr)mng_init_g2_i;
3683
if (!pData->iInterlace)
3684
pData->fInitrowproc = (mng_fptr)mng_init_g4_ni;
3686
pData->fInitrowproc = (mng_fptr)mng_init_g4_i;
3691
if (!pData->iInterlace)
3692
pData->fInitrowproc = (mng_fptr)mng_init_g8_ni;
3694
pData->fInitrowproc = (mng_fptr)mng_init_g8_i;
3698
#ifndef MNG_NO_16BIT_SUPPORT
3700
if (!pData->iInterlace)
3701
pData->fInitrowproc = (mng_fptr)mng_init_g16_ni;
3703
pData->fInitrowproc = (mng_fptr)mng_init_g16_i;
3712
case 2 : { /* rgb */
3713
switch (pData->iBitdepth)
3716
if (!pData->iInterlace)
3717
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni;
3719
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i;
3723
#ifndef MNG_NO_16BIT_SUPPORT
3725
if (!pData->iInterlace)
3726
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni;
3728
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i;
3737
case 3 : { /* indexed */
3738
switch (pData->iBitdepth)
3741
if (!pData->iInterlace)
3742
pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni;
3744
pData->fInitrowproc = (mng_fptr)mng_init_idx1_i;
3749
if (!pData->iInterlace)
3750
pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni;
3752
pData->fInitrowproc = (mng_fptr)mng_init_idx2_i;
3757
if (!pData->iInterlace)
3758
pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni;
3760
pData->fInitrowproc = (mng_fptr)mng_init_idx4_i;
3765
if (!pData->iInterlace)
3766
pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni;
3768
pData->fInitrowproc = (mng_fptr)mng_init_idx8_i;
3776
case 4 : { /* gray+alpha */
3777
switch (pData->iBitdepth)
3780
if (!pData->iInterlace)
3781
pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni;
3783
pData->fInitrowproc = (mng_fptr)mng_init_ga8_i;
3787
#ifndef MNG_NO_16BIT_SUPPORT
3789
if (!pData->iInterlace)
3790
pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni;
3792
pData->fInitrowproc = (mng_fptr)mng_init_ga16_i;
3801
case 6 : { /* rgb+alpha */
3802
switch (pData->iBitdepth)
3805
if (!pData->iInterlace)
3806
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni;
3808
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i;
3812
#ifndef MNG_NO_16BIT_SUPPORT
3814
if (!pData->iInterlace)
3815
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni;
3817
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i;
3827
#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
3829
pData->iFilterofs = 0; /* determine filter characteristics */
3830
pData->iLevel0 = 0; /* default levels */
3836
if (pData->iFilter == 0xC0) /* leveling & differing ? */
3838
switch (pData->iColortype)
3841
#ifndef MNG_NO_16BIT_SUPPORT
3842
if (pData->iBitdepth <= 8)
3844
pData->iFilterofs = 1;
3845
#ifndef MNG_NO_16BIT_SUPPORT
3847
pData->iFilterofs = 2;
3853
#ifndef MNG_NO_16BIT_SUPPORT
3854
if (pData->iBitdepth <= 8)
3856
pData->iFilterofs = 3;
3857
#ifndef MNG_NO_16BIT_SUPPORT
3859
pData->iFilterofs = 6;
3865
pData->iFilterofs = 1;
3869
#ifndef MNG_NO_16BIT_SUPPORT
3870
if (pData->iBitdepth <= 8)
3872
pData->iFilterofs = 2;
3873
#ifndef MNG_NO_16BIT_SUPPORT
3875
pData->iFilterofs = 4;
3881
#ifndef MNG_NO_16BIT_SUPPORT
3882
if (pData->iBitdepth <= 8)
3884
pData->iFilterofs = 4;
3885
#ifndef MNG_NO_16BIT_SUPPORT
3887
pData->iFilterofs = 8;
3897
if (pData->iFilter == 0xC1) /* no adaptive filtering ? */
3898
pData->iPixelofs = pData->iFilterofs;
3901
pData->iPixelofs = pData->iFilterofs + 1;
3903
#ifdef MNG_SUPPORT_TRACE
3904
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_BASI, MNG_LC_END)
3911
/* ************************************************************************** */
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,
3922
mng_uint8 iLocationtype,
3923
mng_int32 iLocationx,
3924
mng_int32 iLocationy)
3926
mng_imagep pSource, pClone;
3927
mng_bool bVisible, bAbstract;
3928
mng_retcode iRetcode = MNG_NOERROR;
3930
#ifdef MNG_SUPPORT_TRACE
3931
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_START)
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);
3938
if (!pSource) /* source must exist ! */
3939
MNG_ERROR (pData, MNG_OBJECTUNKNOWN);
3941
if (pClone) /* clone must not exist ! */
3942
MNG_ERROR (pData, MNG_OBJECTEXISTS);
3944
if (bHasdonotshow) /* DoNotShow flag filled ? */
3945
bVisible = (mng_bool)(iDonotshow == 0);
3947
bVisible = pSource->bVisible;
3949
bAbstract = (mng_bool)(iConcrete == 1);
3951
switch (iClonetype) /* determine action to take */
3953
case 0 : { /* full clone */
3954
iRetcode = mng_clone_imageobject (pData, iCloneid, MNG_FALSE,
3955
bVisible, bAbstract, bHasloca,
3956
iLocationtype, iLocationx, iLocationy,
3961
case 1 : { /* partial clone */
3962
iRetcode = mng_clone_imageobject (pData, iCloneid, MNG_TRUE,
3963
bVisible, bAbstract, bHasloca,
3964
iLocationtype, iLocationx, iLocationy,
3969
case 2 : { /* renumber object */
3970
iRetcode = mng_renum_imageobject (pData, pSource, iCloneid,
3971
bVisible, bAbstract, bHasloca,
3972
iLocationtype, iLocationx, iLocationy);
3979
if (iRetcode) /* on error bail out */
3982
/* display on the fly ? */
3983
if ((pClone->bViewable) && (pClone->bVisible))
3985
pData->pLastclone = pClone; /* remember in case of timer break ! */
3987
mng_display_image (pData, pClone, MNG_FALSE);
3989
if (pData->bTimerset) /* timer break ? */
3990
pData->iBreakpoint = 5;
3993
#ifdef MNG_SUPPORT_TRACE
3994
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_END)
4000
/* ************************************************************************** */
4002
mng_retcode mng_process_display_clon2 (mng_datap pData)
4004
#ifdef MNG_SUPPORT_TRACE
4005
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_START)
4007
/* only called after timer break ! */
4008
mng_display_image (pData, (mng_imagep)pData->pLastclone, MNG_FALSE);
4009
pData->iBreakpoint = 0;
4011
#ifdef MNG_SUPPORT_TRACE
4012
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_END)
4019
/* ************************************************************************** */
4021
#ifndef MNG_SKIPCHUNK_DISC
4022
mng_retcode mng_process_display_disc (mng_datap pData,
4028
mng_uint32 iRetcode;
4029
#ifdef MNG_SUPPORT_TRACE
4030
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DISC, MNG_LC_START)
4033
if (iCount) /* specific list ? */
4035
mng_uint16p pWork = pIds;
4037
#ifdef MNG_DECREMENT_LOOPS
4038
for (iX = iCount; iX > 0;iX--)
4040
for (iX = 0; iX < iCount; iX++) /* iterate the list */
4043
pImage = mng_find_imageobject (pData, *pWork++);
4045
if (pImage) /* found the object ? */
4046
{ /* then drop it */
4047
iRetcode = mng_free_imageobject (pData, pImage);
4049
if (iRetcode) /* on error bail out */
4054
else /* empty: drop all un-frozen objects */
4056
mng_imagep pNext = (mng_imagep)pData->pFirstimgobj;
4058
while (pNext) /* any left ? */
4061
pNext = pImage->sHeader.pNext;
4063
if (!pImage->bFrozen) /* not frozen ? */
4064
{ /* then drop it */
4065
iRetcode = mng_free_imageobject (pData, pImage);
4067
if (iRetcode) /* on error bail out */
4073
#ifdef MNG_SUPPORT_TRACE
4074
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DISC, MNG_LC_END)
4081
/* ************************************************************************** */
4083
#ifndef MNG_SKIPCHUNK_FRAM
4084
mng_retcode mng_process_display_fram (mng_datap pData,
4085
mng_uint8 iFramemode,
4086
mng_uint8 iChangedelay,
4088
mng_uint8 iChangetimeout,
4089
mng_uint32 iTimeout,
4090
mng_uint8 iChangeclipping,
4091
mng_uint8 iCliptype,
4097
mng_retcode iRetcode;
4099
#ifdef MNG_SUPPORT_TRACE
4100
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_START)
4102
/* advance a frame then */
4103
iRetcode = next_frame (pData, iFramemode, iChangedelay, iDelay,
4104
iChangetimeout, iTimeout, iChangeclipping,
4105
iCliptype, iClipl, iClipr, iClipt, iClipb);
4107
if (pData->bTimerset) /* timer break ? */
4108
pData->iBreakpoint = 1;
4110
#ifdef MNG_SUPPORT_TRACE
4111
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_END)
4117
/* ************************************************************************** */
4119
mng_retcode mng_process_display_fram2 (mng_datap pData)
4121
mng_retcode iRetcode;
4123
#ifdef MNG_SUPPORT_TRACE
4124
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_START)
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! */
4130
#ifdef MNG_SUPPORT_TRACE
4131
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_END)
4138
/* ************************************************************************** */
4140
#ifndef MNG_SKIPCHUNK_MOVE
4141
mng_retcode mng_process_display_move (mng_datap pData,
4144
mng_uint8 iMovetype,
4151
#ifdef MNG_SUPPORT_TRACE
4152
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MOVE, MNG_LC_START)
4154
/* iterate the list */
4155
for (iX = iFromid; iX <= iToid; iX++)
4157
if (!iX) /* object id=0 ? */
4158
pImage = (mng_imagep)pData->pObjzero;
4160
pImage = mng_find_imageobject (pData, iX);
4162
if (pImage) /* object exists ? */
4166
case 0 : { /* absolute */
4167
pImage->iPosx = iMovex;
4168
pImage->iPosy = iMovey;
4171
case 1 : { /* relative */
4172
pImage->iPosx = pImage->iPosx + iMovex;
4173
pImage->iPosy = pImage->iPosy + iMovey;
4180
#ifdef MNG_SUPPORT_TRACE
4181
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MOVE, MNG_LC_END)
4188
/* ************************************************************************** */
4190
#ifndef MNG_SKIPCHUNK_CLIP
4191
mng_retcode mng_process_display_clip (mng_datap pData,
4194
mng_uint8 iCliptype,
4203
#ifdef MNG_SUPPORT_TRACE
4204
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLIP, MNG_LC_START)
4206
/* iterate the list */
4207
for (iX = iFromid; iX <= iToid; iX++)
4209
if (!iX) /* object id=0 ? */
4210
pImage = (mng_imagep)pData->pObjzero;
4212
pImage = mng_find_imageobject (pData, iX);
4214
if (pImage) /* object exists ? */
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;
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;
4238
#ifdef MNG_SUPPORT_TRACE
4239
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLIP, MNG_LC_END)
4246
/* ************************************************************************** */
4248
#ifndef MNG_SKIPCHUNK_SHOW
4249
mng_retcode mng_process_display_show (mng_datap pData)
4251
mng_int16 iX, iS, iFrom, iTo;
4254
#ifdef MNG_SUPPORT_TRACE
4255
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SHOW, MNG_LC_START)
4258
/* TODO: optimization for the cases where "abs (iTo - iFrom)" is rather high;
4259
especially where ((iFrom==1) && (iTo==65535)); eg. an empty SHOW !!! */
4261
if (pData->iBreakpoint == 3) /* previously broken during cycle-mode ? */
4263
pImage = mng_find_imageobject (pData, pData->iSHOWnextid);
4265
if (pImage) /* still there ? */
4266
mng_display_image (pData, pImage, MNG_FALSE);
4268
pData->iBreakpoint = 0; /* let's not go through this again! */
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;
4280
{ /* regular sequence ? */
4281
if (pData->iSHOWtoid >= pData->iSHOWfromid)
4283
else /* reverse sequence ! */
4286
iFrom = (mng_int16)pData->iSHOWfromid;
4287
iTo = (mng_int16)pData->iSHOWtoid;
4290
pData->iSHOWfromid = (mng_uint16)iFrom;
4291
pData->iSHOWtoid = (mng_uint16)iTo;
4292
pData->iSHOWskip = iS;
4295
if ((pData->iSHOWmode == 6) || (pData->iSHOWmode == 7))
4297
mng_uint16 iTrigger = 0;
4298
mng_uint16 iFound = 0;
4299
mng_uint16 iPass = 0;
4300
mng_imagep pFound = 0;
4304
iPass++; /* lets prevent endless loops when there
4305
are no potential candidates in the list! */
4307
if (iS > 0) /* forward ? */
4309
for (iX = iFrom; iX <= iTo; iX += iS)
4311
pImage = mng_find_imageobject (pData, (mng_uint16)iX);
4313
if (pImage) /* object exists ? */
4315
if (iFound) /* already found a candidate ? */
4316
pImage->bVisible = MNG_FALSE;
4318
if (iTrigger) /* found the trigger ? */
4320
pImage->bVisible = MNG_TRUE;
4325
if (pImage->bVisible) /* ok, this is the trigger */
4327
pImage->bVisible = MNG_FALSE;
4335
for (iX = iFrom; iX >= iTo; iX += iS)
4337
pImage = mng_find_imageobject (pData, (mng_uint16)iX);
4339
if (pImage) /* object exists ? */
4341
if (iFound) /* already found a candidate ? */
4342
pImage->bVisible = MNG_FALSE;
4344
if (iTrigger) /* found the trigger ? */
4346
pImage->bVisible = MNG_TRUE;
4351
if (pImage->bVisible) /* ok, this is the trigger */
4353
pImage->bVisible = MNG_FALSE;
4360
if (!iTrigger) /* did not find a trigger ? */
4361
iTrigger = 1; /* then fake it so the first image
4363
} /* cycle back to beginning ? */
4364
while ((iPass < 2) && (iTrigger) && (!iFound));
4366
pData->iBreakpoint = 0; /* just a sanity precaution */
4368
if ((pData->iSHOWmode == 6) && (pFound))
4370
mng_display_image (pData, pFound, MNG_FALSE);
4372
if (pData->bTimerset) /* timer set ? */
4374
pData->iBreakpoint = 3;
4375
pData->iSHOWnextid = iFound; /* save it for after the break */
4383
pImage = mng_find_imageobject (pData, iX);
4385
if (pImage) /* object exists ? */
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 ! */
4394
switch (pData->iSHOWmode) /* do what ? */
4397
pImage->bVisible = MNG_TRUE;
4398
mng_display_image (pData, pImage, MNG_FALSE);
4402
pImage->bVisible = MNG_FALSE;
4406
if (pImage->bVisible)
4407
mng_display_image (pData, pImage, MNG_FALSE);
4411
pImage->bVisible = MNG_TRUE;
4415
pImage->bVisible = (mng_bool)(!pImage->bVisible);
4416
if (pImage->bVisible)
4417
mng_display_image (pData, pImage, MNG_FALSE);
4421
pImage->bVisible = (mng_bool)(!pImage->bVisible);
4427
if (!pData->bTimerset) /* next ? */
4431
while ((!pData->bTimerset) && (((iS > 0) && (iX <= iTo)) ||
4432
((iS < 0) && (iX >= iTo)) ));
4434
if (pData->bTimerset) /* timer set ? */
4436
pData->iBreakpoint = 4;
4437
pData->iSHOWnextid = iX; /* save for next time */
4440
pData->iBreakpoint = 0;
4445
#ifdef MNG_SUPPORT_TRACE
4446
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SHOW, MNG_LC_END)
4453
/* ************************************************************************** */
4455
#ifndef MNG_SKIPCHUNK_SAVE
4456
mng_retcode mng_process_display_save (mng_datap pData)
4458
mng_retcode iRetcode;
4460
#ifdef MNG_SUPPORT_TRACE
4461
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SAVE, MNG_LC_START)
4464
iRetcode = save_state (pData); /* save the current state */
4466
if (iRetcode) /* on error bail out */
4469
#ifdef MNG_SUPPORT_TRACE
4470
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SAVE, MNG_LC_END)
4477
/* ************************************************************************** */
4479
#ifndef MNG_SKIPCHUNK_SEEK
4480
mng_retcode mng_process_display_seek (mng_datap pData)
4482
#ifdef MNG_SUPPORT_TRACE
4483
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SEEK, MNG_LC_START)
4486
#ifdef MNG_SUPPORT_DYNAMICMNG
4487
if (pData->bStopafterseek) /* need to stop after this SEEK ? */
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 ! */
4496
{ /* restore the initial or SAVE state */
4497
mng_retcode iRetcode = restore_state (pData);
4499
if (iRetcode) /* on error bail out */
4502
#ifdef MNG_SUPPORT_DYNAMICMNG
4503
/* stop after next SEEK ? */
4504
if ((pData->bDynamic) || (pData->bRunningevent))
4505
pData->bStopafterseek = MNG_TRUE;
4509
#ifdef MNG_SUPPORT_TRACE
4510
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SEEK, MNG_LC_END)
4517
/* ************************************************************************** */
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;
4525
#ifdef MNG_SUPPORT_TRACE
4526
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JHDR, MNG_LC_START)
4529
if (!pData->bHasDHDR)
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;
4540
pData->pStoreobj = MNG_NULL; /* initialize important work-parms */
4542
pData->iJPEGrow = 0;
4543
pData->iJPEGalpharow = 0;
4544
pData->iJPEGrgbrow = 0;
4545
pData->iRowmax = 0; /* so init_rowproc does the right thing ! */
4548
if (!pData->iBreakpoint) /* not previously broken ? */
4550
#ifndef MNG_NO_DELTA_PNG
4551
if (pData->bHasDHDR) /* delta-image ? */
4553
if (pData->iDeltatype == MNG_DELTATYPE_REPLACE)
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);
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;
4567
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
4568
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
4570
((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iJHDRimgbitdepth;
4571
((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
4574
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
4575
(pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
4576
((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
4578
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
4579
(pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
4580
((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iJHDRimgbitdepth;
4584
#endif /* MNG_NO_DELTA_PNG */
4586
if (pImage) /* update object buffer ? */
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);
4594
pImage->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth;
4595
pImage->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression;
4596
pImage->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace;
4597
pImage->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
4599
else /* update object 0 */
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);
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;
4614
if (iRetcode) /* on error bail out */
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) ) )
4630
next_layer (pData); /* that's a new layer then ! */
4632
pData->iBreakpoint = 0;
4634
if (pData->bTimerset) /* timer break ? */
4635
pData->iBreakpoint = 7;
4637
if (pData->bRunning) /* still running ? */
4638
{ /* anything to display ? */
4639
if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt))
4641
set_display_routine (pData); /* then determine display routine */
4642
/* display from the object we store in */
4643
pData->pRetrieveobj = pData->pStoreobj;
4649
if (!pData->bTimerset) /* no timer break ? */
4650
{ /* default row initialization ! */
4651
#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
4652
pData->ePng_imgtype=png_none;
4654
pData->fInitrowproc = (mng_fptr)mng_init_rowproc;
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;
4663
switch (pData->iJHDRcolortype) /* determine pixel processing routines */
4665
case MNG_COLORTYPE_JPEGGRAY :
4667
pData->fStorerow2 = (mng_fptr)mng_store_jpeg_g8;
4668
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
4669
pData->bIsOpaque = MNG_TRUE;
4672
case MNG_COLORTYPE_JPEGCOLOR :
4674
pData->fStorerow2 = (mng_fptr)mng_store_jpeg_rgb8;
4675
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
4676
pData->bIsOpaque = MNG_TRUE;
4679
case MNG_COLORTYPE_JPEGGRAYA :
4681
pData->fStorerow2 = (mng_fptr)mng_store_jpeg_ga8;
4682
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
4683
pData->bIsOpaque = MNG_FALSE;
4686
case MNG_COLORTYPE_JPEGCOLORA :
4688
pData->fStorerow2 = (mng_fptr)mng_store_jpeg_rgba8;
4689
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
4690
pData->bIsOpaque = MNG_FALSE;
4695
#ifndef MNG_NO_16BIT_SUPPORT
4698
pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */
4700
/* TODO: 12-bit JPEG */
4701
/* TODO: 8- + 12-bit JPEG (eg. type=20) */
4705
/* possible IDAT alpha-channel ? */
4706
if (pData->iJHDRalphacompression == MNG_COMPRESSION_DEFLATE)
4708
/* determine alpha processing routine */
4709
#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
4710
pData->fInitrowproc = (mng_fptr)mng_init_rowproc;
4712
switch (pData->iJHDRalphabitdepth)
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; }
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; }
4733
else /* possible JDAA alpha-channel ? */
4734
if (pData->iJHDRalphacompression == MNG_COMPRESSION_BASELINEJPEG)
4735
{ /* 8-bit JPEG ? */
4736
if (pData->iJHDRimgbitdepth == 8)
4738
if (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA)
4739
pData->fStorerow3 = (mng_fptr)mng_store_jpeg_g8_alpha;
4741
if (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA)
4742
pData->fStorerow3 = (mng_fptr)mng_store_jpeg_rgb8_alpha;
4746
/* TODO: 12-bit JPEG with 8-bit JDAA */
4749
/* initialize JPEG library */
4750
iRetcode = mngjpeg_initialize (pData);
4752
if (iRetcode) /* on error bail out */
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;
4764
switch (pData->iJHDRalphabitdepth)
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; }
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; }
4782
#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
4786
pData->iFilterofs = 0; /* determine filter characteristics */
4787
pData->iLevel0 = 0; /* default levels */
4792
#ifdef FILTER192 /* leveling & differing ? */
4793
if (pData->iJHDRalphafilter == 0xC0)
4795
if (pData->iJHDRalphabitdepth <= 8)
4796
pData->iFilterofs = 1;
4798
pData->iFilterofs = 2;
4802
#ifdef FILTER193 /* no adaptive filtering ? */
4803
if (pData->iJHDRalphafilter == 0xC1)
4804
pData->iPixelofs = pData->iFilterofs;
4807
pData->iPixelofs = pData->iFilterofs + 1;
4811
#ifdef MNG_SUPPORT_TRACE
4812
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JHDR, MNG_LC_END)
4817
#endif /* MNG_INCLUDE_JNG */
4819
/* ************************************************************************** */
4821
#ifdef MNG_INCLUDE_JNG
4822
mng_retcode mng_process_display_jdaa (mng_datap pData,
4824
mng_uint8p pRawdata)
4826
mng_retcode iRetcode = MNG_NOERROR;
4828
#ifdef MNG_SUPPORT_TRACE
4829
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAA, MNG_LC_START)
4832
if (!pData->bJPEGdecompress2) /* if we're not decompressing already */
4834
if (pData->fInitrowproc) /* initialize row-processing? */
4836
iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData);
4837
pData->fInitrowproc = MNG_NULL; /* only call this once !!! */
4840
if (!iRetcode) /* initialize decompress */
4841
iRetcode = mngjpeg_decompressinit2 (pData);
4844
if (!iRetcode) /* all ok? then decompress, my man */
4845
iRetcode = mngjpeg_decompressdata2 (pData, iRawlen, pRawdata);
4850
#ifdef MNG_SUPPORT_TRACE
4851
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAA, MNG_LC_END)
4856
#endif /* MNG_INCLUDE_JNG */
4858
/* ************************************************************************** */
4860
#ifdef MNG_INCLUDE_JNG
4861
mng_retcode mng_process_display_jdat (mng_datap pData,
4863
mng_uint8p pRawdata)
4865
mng_retcode iRetcode = MNG_NOERROR;
4867
#ifdef MNG_SUPPORT_TRACE
4868
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAT, MNG_LC_START)
4871
if (pData->bRestorebkgd) /* need to restore the background ? */
4873
pData->bRestorebkgd = MNG_FALSE;
4874
iRetcode = load_bkgdlayer (pData);
4876
pData->iLayerseq++; /* and it counts as a layer then ! */
4878
if (iRetcode) /* on error bail out */
4882
if (!pData->bJPEGdecompress) /* if we're not decompressing already */
4884
if (pData->fInitrowproc) /* initialize row-processing? */
4886
iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData);
4887
pData->fInitrowproc = MNG_NULL; /* only call this once !!! */
4890
if (!iRetcode) /* initialize decompress */
4891
iRetcode = mngjpeg_decompressinit (pData);
4894
if (!iRetcode) /* all ok? then decompress, my man */
4895
iRetcode = mngjpeg_decompressdata (pData, iRawlen, pRawdata);
4900
#ifdef MNG_SUPPORT_TRACE
4901
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAT, MNG_LC_END)
4906
#endif /* MNG_INCLUDE_JNG */
4908
/* ************************************************************************** */
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,
4921
mng_retcode iRetcode;
4923
#ifdef MNG_SUPPORT_TRACE
4924
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DHDR, MNG_LC_START)
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;
4934
pData->fDeltagetrow = MNG_NULL;
4935
pData->fDeltaaddrow = MNG_NULL;
4936
pData->fDeltareplacerow = MNG_NULL;
4937
pData->fDeltaputrow = MNG_NULL;
4939
pImage = mng_find_imageobject (pData, iObjectid);
4941
if (pImage) /* object exists ? */
4943
if (pImage->pImgbuf->bConcrete) /* is it concrete ? */
4944
{ /* previous magnification to be done ? */
4945
if ((pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY))
4947
iRetcode = mng_magnify_imageobject (pData, pImage);
4949
if (iRetcode) /* on error bail out */
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;
4969
if ((iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
4970
(iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
4971
pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth;
4973
if ((iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
4974
(iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
4975
pData->iBitdepth = pImage->pImgbuf->iAlphasampledepth;
4977
if ((iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
4978
(iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
4979
pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth;
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;
4991
/* block size specified ? */
4992
if (iDeltatype != MNG_DELTATYPE_NOCHANGE)
4993
{ /* block entirely within target ? */
4994
if (iDeltatype != MNG_DELTATYPE_REPLACE)
4996
if (((iBlockx + iBlockwidth ) > pData->iDatawidth ) ||
4997
((iBlocky + iBlockheight) > pData->iDataheight) )
4998
MNG_ERROR (pData, MNG_INVALIDBLOCK)
5001
pData->iDatawidth = iBlockwidth;
5002
pData->iDataheight = iBlockheight;
5005
switch (iDeltatype) /* determine nr of delta-channels */
5007
case MNG_DELTATYPE_BLOCKALPHAADD : ;
5008
case MNG_DELTATYPE_BLOCKALPHAREPLACE :
5010
#ifdef MNG_INCLUDE_JNG
5011
if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) ||
5012
(pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) )
5014
pData->iColortype = MNG_COLORTYPE_GRAY;
5015
pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY;
5018
if ((pData->iColortype == MNG_COLORTYPE_RGBA ) ||
5019
(pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) )
5021
pData->iColortype = MNG_COLORTYPE_GRAY;
5022
pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY;
5025
if (pData->iColortype == MNG_COLORTYPE_GRAYA)
5026
pData->iColortype = MNG_COLORTYPE_GRAY;
5028
if (pData->iColortype == MNG_COLORTYPE_RGBA)
5029
pData->iColortype = MNG_COLORTYPE_GRAY;
5031
else /* target has no alpha; that sucks! */
5032
MNG_ERROR (pData, MNG_TARGETNOALPHA)
5037
case MNG_DELTATYPE_BLOCKCOLORADD : ;
5038
case MNG_DELTATYPE_BLOCKCOLORREPLACE :
5040
#ifdef MNG_INCLUDE_JNG
5041
if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) ||
5042
(pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) )
5044
pData->iColortype = MNG_COLORTYPE_GRAY;
5045
pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY;
5048
if ((pData->iColortype == MNG_COLORTYPE_RGBA ) ||
5049
(pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) )
5051
pData->iColortype = MNG_COLORTYPE_RGB;
5052
pData->iJHDRcolortype = MNG_COLORTYPE_JPEGCOLOR;
5055
if (pData->iColortype == MNG_COLORTYPE_GRAYA)
5056
pData->iColortype = MNG_COLORTYPE_GRAY;
5058
if (pData->iColortype == MNG_COLORTYPE_RGBA)
5059
pData->iColortype = MNG_COLORTYPE_RGB;
5061
else /* target has no alpha; that sucks! */
5062
MNG_ERROR (pData, MNG_TARGETNOALPHA)
5068
/* full image replace ? */
5069
if (iDeltatype == MNG_DELTATYPE_REPLACE)
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);
5077
if (iRetcode) /* on error bail out */
5080
pData->pStoreobj = pImage; /* and store straight into this object */
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);
5094
if (iRetcode) /* on error bail out */
5097
pBuf = pImage->pImgbuf; /* copy possible palette & cheap transparency */
5098
pBufzero = ((mng_imagep)pData->pObjzero)->pImgbuf;
5100
pBufzero->bHasPLTE = pBuf->bHasPLTE;
5101
pBufzero->bHasTRNS = pBuf->bHasTRNS;
5103
if (pBufzero->bHasPLTE) /* copy palette ? */
5107
pBufzero->iPLTEcount = pBuf->iPLTEcount;
5109
for (iX = 0; iX < pBuf->iPLTEcount; iX++)
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;
5117
if (pBufzero->bHasTRNS) /* copy cheap transparency ? */
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;
5125
MNG_COPY (pBufzero->aTRNSentries, pBuf->aTRNSentries,
5126
sizeof (pBufzero->aTRNSentries))
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) );
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);
5140
switch (pData->iColortype) /* determine row initialization routine */
5142
case 0 : { /* gray */
5143
switch (pData->iBitdepth)
5146
if (!pData->iInterlace)
5147
pData->fInitrowproc = (mng_fptr)mng_init_g1_ni;
5149
pData->fInitrowproc = (mng_fptr)mng_init_g1_i;
5154
if (!pData->iInterlace)
5155
pData->fInitrowproc = (mng_fptr)mng_init_g2_ni;
5157
pData->fInitrowproc = (mng_fptr)mng_init_g2_i;
5162
if (!pData->iInterlace)
5163
pData->fInitrowproc = (mng_fptr)mng_init_g4_ni;
5165
pData->fInitrowproc = (mng_fptr)mng_init_g4_i;
5170
if (!pData->iInterlace)
5171
pData->fInitrowproc = (mng_fptr)mng_init_g8_ni;
5173
pData->fInitrowproc = (mng_fptr)mng_init_g8_i;
5177
#ifndef MNG_NO_16BIT_SUPPORT
5179
if (!pData->iInterlace)
5180
pData->fInitrowproc = (mng_fptr)mng_init_g16_ni;
5182
pData->fInitrowproc = (mng_fptr)mng_init_g16_i;
5191
case 2 : { /* rgb */
5192
switch (pData->iBitdepth)
5195
if (!pData->iInterlace)
5196
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni;
5198
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i;
5202
#ifndef MNG_NO_16BIT_SUPPORT
5204
if (!pData->iInterlace)
5205
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni;
5207
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i;
5216
case 3 : { /* indexed */
5217
switch (pData->iBitdepth)
5220
if (!pData->iInterlace)
5221
pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni;
5223
pData->fInitrowproc = (mng_fptr)mng_init_idx1_i;
5228
if (!pData->iInterlace)
5229
pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni;
5231
pData->fInitrowproc = (mng_fptr)mng_init_idx2_i;
5236
if (!pData->iInterlace)
5237
pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni;
5239
pData->fInitrowproc = (mng_fptr)mng_init_idx4_i;
5244
if (!pData->iInterlace)
5245
pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni;
5247
pData->fInitrowproc = (mng_fptr)mng_init_idx8_i;
5255
case 4 : { /* gray+alpha */
5256
switch (pData->iBitdepth)
5259
if (!pData->iInterlace)
5260
pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni;
5262
pData->fInitrowproc = (mng_fptr)mng_init_ga8_i;
5266
#ifndef MNG_NO_16BIT_SUPPORT
5268
if (!pData->iInterlace)
5269
pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni;
5271
pData->fInitrowproc = (mng_fptr)mng_init_ga16_i;
5280
case 6 : { /* rgb+alpha */
5281
switch (pData->iBitdepth)
5284
if (!pData->iInterlace)
5285
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni;
5287
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i;
5291
#ifndef MNG_NO_16BIT_SUPPORT
5293
if (!pData->iInterlace)
5294
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni;
5296
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i;
5306
#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
5309
MNG_ERROR (pData, MNG_OBJNOTCONCRETE)
5313
MNG_ERROR (pData, MNG_OBJECTUNKNOWN)
5315
#ifdef MNG_SUPPORT_TRACE
5316
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DHDR, MNG_LC_END)
5323
/* ************************************************************************** */
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)
5332
mng_imagedatap pBuf;
5333
mng_retcode iRetcode;
5335
#ifdef MNG_SUPPORT_TRACE
5336
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PROM, MNG_LC_START)
5339
if (!pData->pDeltaImage) /* gotta have this now! */
5340
MNG_ERROR (pData, MNG_INVALIDDELTA)
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)
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) ) ||
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)
5382
iRetcode = mng_promote_imageobject (pData, pImage, iBitdepth, iColortype, iFilltype);
5384
if (iRetcode) /* on error bail out */
5387
#ifdef MNG_SUPPORT_TRACE
5388
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PROM, MNG_LC_END)
5395
/* ************************************************************************** */
5397
#ifndef MNG_NO_DELTA_PNG
5398
mng_retcode mng_process_display_ipng (mng_datap pData)
5400
#ifdef MNG_SUPPORT_TRACE
5401
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IPNG, MNG_LC_START)
5403
/* indicate it for what it is now */
5404
pData->iDeltaImagetype = MNG_IMAGETYPE_PNG;
5406
#ifdef MNG_SUPPORT_TRACE
5407
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IPNG, MNG_LC_END)
5414
/* ************************************************************************** */
5416
#ifndef MNG_NO_DELTA_PNG
5417
#ifdef MNG_INCLUDE_JNG
5418
mng_retcode mng_process_display_ijng (mng_datap pData)
5420
#ifdef MNG_SUPPORT_TRACE
5421
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IJNG, MNG_LC_START)
5423
/* indicate it for what it is now */
5424
pData->iDeltaImagetype = MNG_IMAGETYPE_JNG;
5426
#ifdef MNG_SUPPORT_TRACE
5427
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IJNG, MNG_LC_END)
5435
/* ************************************************************************** */
5437
#ifndef MNG_NO_DELTA_PNG
5438
mng_retcode mng_process_display_pplt (mng_datap pData,
5441
mng_palette8ep paIndexentries,
5442
mng_uint8p paAlphaentries,
5443
mng_uint8p paUsedentries)
5446
mng_imagep pImage = (mng_imagep)pData->pObjzero;
5447
mng_imagedatap pBuf = pImage->pImgbuf;
5449
#ifdef MNG_SUPPORT_TRACE
5450
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PPLT, MNG_LC_START)
5453
#ifdef MNG_DECREMENT_LOOPS
5459
case MNG_DELTATYPE_REPLACERGB :
5461
#ifdef MNG_DECREMENT_LOOPS
5464
for (iX = 0; iX < iCount; iX++)
5467
if (paUsedentries [iX])
5469
pBuf->aPLTEentries [iX].iRed = paIndexentries [iX].iRed;
5470
pBuf->aPLTEentries [iX].iGreen = paIndexentries [iX].iGreen;
5471
pBuf->aPLTEentries [iX].iBlue = paIndexentries [iX].iBlue;
5477
case MNG_DELTATYPE_DELTARGB :
5479
#ifdef MNG_DECREMENT_LOOPS
5482
for (iX = 0; iX < iCount; iX++)
5485
if (paUsedentries [iX])
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 );
5501
case MNG_DELTATYPE_REPLACEALPHA :
5503
#ifdef MNG_DECREMENT_LOOPS
5506
for (iX = 0; iX < iCount; iX++)
5509
if (paUsedentries [iX])
5510
pBuf->aTRNSentries [iX] = paAlphaentries [iX];
5515
case MNG_DELTATYPE_DELTAALPHA :
5517
#ifdef MNG_DECREMENT_LOOPS
5520
for (iX = 0; iX < iCount; iX++)
5523
if (paUsedentries [iX])
5524
pBuf->aTRNSentries [iX] =
5525
(mng_uint8)(pBuf->aTRNSentries [iX] +
5526
paAlphaentries [iX]);
5531
case MNG_DELTATYPE_REPLACERGBA :
5533
#ifdef MNG_DECREMENT_LOOPS
5536
for (iX = 0; iX < iCount; iX++)
5539
if (paUsedentries [iX])
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];
5550
case MNG_DELTATYPE_DELTARGBA :
5552
#ifdef MNG_DECREMENT_LOOPS
5555
for (iX = 0; iX < iCount; iX++)
5558
if (paUsedentries [iX])
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]);
5579
if ((iType != MNG_DELTATYPE_REPLACERGB) && (iType != MNG_DELTATYPE_DELTARGB))
5583
if (iCount > pBuf->iTRNScount)
5584
pBuf->iTRNScount = iCount;
5588
pBuf->iTRNScount = iCount;
5589
pBuf->bHasTRNS = MNG_TRUE;
5593
if ((iType != MNG_DELTATYPE_REPLACEALPHA) && (iType != MNG_DELTATYPE_DELTAALPHA))
5595
if (iCount > pBuf->iPLTEcount)
5596
pBuf->iPLTEcount = iCount;
5599
#ifdef MNG_SUPPORT_TRACE
5600
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PPLT, MNG_LC_END)
5607
/* ************************************************************************** */
5609
#ifndef MNG_SKIPCHUNK_MAGN
5610
mng_retcode mng_process_display_magn (mng_datap pData,
5611
mng_uint16 iFirstid,
5625
#ifdef MNG_SUPPORT_TRACE
5626
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_START)
5628
/* iterate the object-ids */
5629
for (iX = iFirstid; iX <= iLastid; iX++)
5631
if (iX == 0) /* process object 0 ? */
5633
pImage = (mng_imagep)pData->pObjzero;
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;
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))
5652
mng_retcode iRetcode = mng_magnify_imageobject (pData, pImage);
5653
if (iRetcode) /* on error bail out */
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;
5669
pData->iMAGNfromid = iFirstid;
5670
pData->iMAGNtoid = iLastid;
5672
/* iterate again for showing */
5673
while ((iX <= iLastid) && (!pData->bTimerset))
5675
pData->iMAGNcurrentid = iX;
5677
if (iX) /* only real objects ! */
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))
5685
mng_retcode iRetcode = mng_display_image (pData, pImage, MNG_FALSE);
5694
if (pData->bTimerset) /* broken ? */
5695
pData->iBreakpoint = 9;
5697
#ifdef MNG_SUPPORT_TRACE
5698
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_END)
5704
/* ************************************************************************** */
5706
mng_retcode mng_process_display_magn2 (mng_datap pData)
5711
#ifdef MNG_SUPPORT_TRACE
5712
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_START)
5715
iX = pData->iMAGNcurrentid;
5716
/* iterate again for showing */
5717
while ((iX <= pData->iMAGNtoid) && (!pData->bTimerset))
5719
pData->iMAGNcurrentid = iX;
5721
if (iX) /* only real objects ! */
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))
5729
mng_retcode iRetcode = mng_display_image (pData, pImage, MNG_FALSE);
5738
if (pData->bTimerset) /* broken ? */
5739
pData->iBreakpoint = 9;
5741
pData->iBreakpoint = 0; /* not again ! */
5743
#ifdef MNG_SUPPORT_TRACE
5744
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_END)
5751
/* ************************************************************************** */
5753
#ifndef MNG_SKIPCHUNK_PAST
5754
mng_retcode mng_process_display_past (mng_datap pData,
5755
mng_uint16 iTargetid,
5756
mng_uint8 iTargettype,
5762
mng_retcode iRetcode = MNG_NOERROR;
5763
mng_imagep pTargetimg;
5764
mng_imagep pSourceimg;
5765
mng_past_sourcep pSource = (mng_past_sourcep)pSources;
5768
#ifdef MNG_SUPPORT_TRACE
5769
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_START)
5772
if (iTargetid) /* a real destination object ? */
5773
{ /* let's find it then */
5774
pTargetimg = (mng_imagep)mng_find_imageobject (pData, iTargetid);
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,
5789
MNG_FILLMETHOD_LEFTBITREPLICATE);
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,
5797
MNG_FILLMETHOD_LEFTBITREPLICATE);
5798
#ifdef MNG_INCLUDE_JNG
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);
5809
if (iRetcode) /* on error bail out */
5811
/* make it really abstract ? */
5812
if (!pTargetimg->pImgbuf->bCorrected)
5814
iRetcode = mng_colorcorrect_object (pData, pTargetimg);
5816
if (iRetcode) /* on error bail out */
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))
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);
5835
if (iRetcode) /* on error bail out */
5839
pTargetimg = MNG_NULL; /* clipped beyond visibility ! */
5842
if (pTargetimg) /* usable destination ? */
5845
mng_int32 iSourceYinc;
5846
mng_int32 iSourcerowsize;
5847
mng_int32 iSourcesamples;
5848
mng_bool bSourceRGBA16;
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);
5859
if (!iRetcode) /* still ok ? */
5861
bTargetRGBA16 = (mng_bool)(pTargetimg->pImgbuf->iBitdepth > 8);
5863
switch (iTargettype) /* determine target x/y */
5866
pData->iPastx = iTargetx;
5867
pData->iPasty = iTargety;
5872
pData->iPastx = pTargetimg->iPastx + iTargetx;
5873
pData->iPasty = pTargetimg->iPasty + iTargety;
5878
pData->iPastx += iTargetx;
5879
pData->iPasty += iTargety;
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;
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);
5900
if (!iRetcode) /* still ok ? */
5902
pBuf = (mng_imagedatap)pSourceimg->pImgbuf;
5903
/* address source for row-routines */
5904
pData->pRetrieveobj = (mng_objectp)pSourceimg;
5906
pData->iPass = -1; /* init row-processing variables */
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;
5916
switch (pBuf->iColortype)
5919
#ifndef MNG_NO_16BIT_SUPPORT
5921
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
5924
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
5926
pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS);
5931
#ifndef MNG_NO_16BIT_SUPPORT
5933
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
5936
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
5938
pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS);
5943
case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8;
5944
pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS);
5950
#ifndef MNG_NO_16BIT_SUPPORT
5952
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
5955
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
5957
pData->bIsOpaque = MNG_FALSE;
5963
#ifndef MNG_NO_16BIT_SUPPORT
5965
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
5968
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
5970
pData->bIsOpaque = MNG_FALSE;
5975
#ifndef MNG_NO_16BIT_SUPPORT
5977
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
5980
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
5982
pData->bIsOpaque = MNG_TRUE;
5987
#ifndef MNG_NO_16BIT_SUPPORT
5989
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
5992
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
5994
pData->bIsOpaque = MNG_TRUE;
6000
#ifndef MNG_NO_16BIT_SUPPORT
6002
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
6005
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
6007
pData->bIsOpaque = MNG_FALSE;
6013
#ifndef MNG_NO_16BIT_SUPPORT
6015
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
6018
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
6020
pData->bIsOpaque = MNG_FALSE;
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;
6030
if ((bSourceRGBA16) && (!bTargetRGBA16))
6031
pData->fScalerow = (mng_fptr)mng_scale_rgba16_rgba8;
6035
pData->fScalerow = MNG_NULL;
6037
/* default no color-correction */
6038
pData->fCorrectrow = MNG_NULL;
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);
6049
if (!iRetcode) /* still ok ? */
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)
6058
#ifndef MNG_NO_16BIT_SUPPORT
6060
pData->fFliprow = (mng_fptr)mng_flip_rgba16;
6063
pData->fFliprow = (mng_fptr)mng_flip_rgba8;
6068
#ifndef MNG_NO_16BIT_SUPPORT
6070
pData->fTilerow = (mng_fptr)mng_tile_rgba16;
6073
pData->fTilerow = (mng_fptr)mng_tile_rgba8;
6077
/* determine composition routine */
6078
/* note that we're abusing the delta-routine setup !!! */
6079
switch (pSource->iComposition)
6081
case 0 : { /* composite over */
6082
#ifndef MNG_NO_16BIT_SUPPORT
6084
pData->fDeltarow = (mng_fptr)mng_composeover_rgba16;
6087
pData->fDeltarow = (mng_fptr)mng_composeover_rgba8;
6091
case 1 : { /* replace */
6092
#ifndef MNG_NO_16BIT_SUPPORT
6094
pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgba16;
6097
pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgba8;
6101
case 2 : { /* composite under */
6102
#ifndef MNG_NO_16BIT_SUPPORT
6104
pData->fDeltarow = (mng_fptr)mng_composeunder_rgba16;
6107
pData->fDeltarow = (mng_fptr)mng_composeunder_rgba8;
6111
/* determine offsets & clipping */
6112
if (pSource->iOffsettype == 1)
6114
pData->iDestl = pData->iPastx + pSource->iOffsetx;
6115
pData->iDestt = pData->iPasty + pSource->iOffsety;
6119
pData->iDestl = pSource->iOffsetx;
6120
pData->iDestt = pSource->iOffsety;
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)
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);
6131
/* source clipping */
6132
if (pSource->iBoundarytype == 1)
6134
if (pData->iDestl < pData->iPastx + pSource->iBoundaryl)
6135
pData->iSourcel = pData->iPastx + pSource->iBoundaryl - pData->iDestl;
6137
pData->iSourcel = 0;
6139
if (pData->iDestt < pData->iPasty + pSource->iBoundaryt)
6140
pData->iSourcet = pData->iPasty + pSource->iBoundaryt - pData->iDestt;
6142
pData->iSourcet = 0;
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);
6151
if (pData->iDestl < pSource->iBoundaryl)
6152
pData->iSourcel = pSource->iBoundaryl - pData->iDestl;
6154
pData->iSourcel = 0;
6156
if (pData->iDestt < pSource->iBoundaryt)
6157
pData->iSourcet = pSource->iBoundaryt - pData->iDestt;
6159
pData->iSourcet = 0;
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);
6167
if (pData->iSourcel) /* indent source ? */
6169
#ifndef MNG_NO_16BIT_SUPPORT
6170
if (bTargetRGBA16) /* abuse tiling routine to shift source-pixels */
6171
pData->fTilerow = (mng_fptr)mng_tile_rgba16;
6174
pData->fTilerow = (mng_fptr)mng_tile_rgba8;
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))
6181
iSourceY = (mng_int32)pBuf->iHeight - 1 - pData->iSourcet;
6186
iSourceY = pData->iSourcet;
6190
iTargetY = pData->iDestt;
6191
pData->iCol = pData->iDestl;
6193
iTargetsamples = pData->iDestr - pData->iDestl;
6195
#ifndef MNG_NO_16BIT_SUPPORT
6197
iTargetrowsize = (iTargetsamples << 3);
6200
iTargetrowsize = (iTargetsamples << 2);
6202
/* get temporary work-buffers */
6203
if (iSourcerowsize > iTargetrowsize)
6204
iTemprowsize = iSourcerowsize << 1;
6206
iTemprowsize = iTargetrowsize << 1;
6207
MNG_ALLOC (pData, pData->pRGBArow, iTemprowsize)
6208
MNG_ALLOC (pData, pData->pWorkrow, iTemprowsize)
6210
while ((!iRetcode) && (iTargetY < pData->iDestb))
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);
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);
6232
if (!iRetcode) /* and paste..... */
6234
pData->iRow = iTargetY;
6235
pData->iRowsamples = iTargetsamples;
6236
pData->iRowsize = iTargetrowsize;
6237
iRetcode = ((mng_deltarow)pData->fDeltarow) (pData);
6240
iSourceY += iSourceYinc; /* and next line */
6243
iSourceY = (mng_int32)pBuf->iHeight - 1;
6245
if (iSourceY >= (mng_int32)pBuf->iHeight)
6250
/* drop the temporary row-buffer */
6251
MNG_FREEX (pData, pData->pWorkrow, iTemprowsize)
6252
MNG_FREEX (pData, pData->pRGBArow, iTemprowsize)
6255
#if defined(MNG_FULL_CMS) /* cleanup cms stuff */
6257
iRetcode = mng_clear_cms (pData);
6261
pSource++; /* neeeeext */
6266
if (iRetcode) /* on error bail out */
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 */
6276
{ /* target is visible & viewable ? */
6277
if ((pTargetimg->bVisible) && (pTargetimg->bViewable))
6279
iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE);
6286
if (pData->bTimerset) /* broken ? */
6288
pData->iPASTid = iTargetid;
6289
pData->iBreakpoint = 11;
6292
#ifdef MNG_SUPPORT_TRACE
6293
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_END)
6298
#endif /* MNG_SKIPCHUNK_PAST */
6300
/* ************************************************************************** */
6302
#ifndef MNG_SKIPCHUNK_PAST
6303
mng_retcode mng_process_display_past2 (mng_datap pData)
6305
mng_retcode iRetcode;
6306
mng_imagep pTargetimg;
6308
#ifdef MNG_SUPPORT_TRACE
6309
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_START)
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;
6317
iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE);
6321
pData->iBreakpoint = 0; /* only once */
6323
#ifdef MNG_SUPPORT_TRACE
6324
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_END)
6329
#endif /* MNG_SKIPCHUNK_PAST */
6331
/* ************************************************************************** */
6333
#endif /* MNG_INCLUDE_DISPLAY_PROCS */
6335
/* ************************************************************************** */
6336
/* * end of file * */
6337
/* ************************************************************************** */
1
/* ************************************************************************** */
2
/* * For conditions of distribution and use, * */
3
/* * see copyright notice in libmng.h * */
4
/* ************************************************************************** */
6
/* * project : libmng * */
7
/* * file : libmng_display.c copyright (c) 2000-2004 G.Juyn * */
8
/* * version : 1.0.9 * */
10
/* * purpose : Display management (implementation) * */
12
/* * author : G.Juyn * */
14
/* * comment : implementation of the display management routines * */
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 * */
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) * */
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 * */
67
/* * 0.9.0 - 06/30/2000 - G.Juyn * */
68
/* * - changed refresh parameters to 'x,y,width,height' * */
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 * */
85
/* * 0.9.2 - 08/05/2000 - G.Juyn * */
86
/* * - changed file-prefixes * */
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 * */
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 * */
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 * */
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 * */
143
/* * 1.0.2 - 06/25/2001 - G.Juyn * */
144
/* * - fixed memory-leak with delta-images (Thanks Michael!) * */
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* */
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 * */
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 * */
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 * */
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) * */
225
/* ************************************************************************** */
228
#include "libmng_data.h"
229
#include "libmng_error.h"
230
#include "libmng_trace.h"
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"
244
#if defined(__BORLANDC__) && defined(MNG_STRICT_ANSI)
245
#pragma option -A /* force ANSI-C */
248
/* ************************************************************************** */
250
#ifdef MNG_INCLUDE_DISPLAY_PROCS
252
/* ************************************************************************** */
254
MNG_LOCAL mng_retcode set_delay (mng_datap pData,
255
mng_uint32 iInterval)
257
if (!iInterval) /* at least 1 msec please! */
260
if (pData->bRunning) /* only when really displaying */
261
if (!pData->fSettimer ((mng_handle)pData, iInterval))
262
MNG_ERROR (pData, MNG_APPTIMERERROR);
264
#ifdef MNG_SUPPORT_DYNAMICMNG
265
if ((!pData->bDynamic) || (pData->bRunning))
269
pData->bTimerset = MNG_TRUE; /* and indicate so */
274
/* ************************************************************************** */
276
MNG_LOCAL mng_uint32 calculate_delay (mng_datap pData,
279
mng_uint32 iTicks = pData->iTicks;
280
mng_uint32 iWaitfor = 1; /* default non-MNG delay */
282
if (!iTicks) /* tick_count not specified ? */
283
if (pData->eImagetype == mng_it_mng)
288
switch (pData->iSpeed) /* honor speed modifier */
292
iWaitfor = (mng_uint32)(( 500 * iDelay) / iTicks);
297
iWaitfor = (mng_uint32)((3000 * iDelay) / iTicks);
300
case mng_st_slowest :
302
iWaitfor = (mng_uint32)((8000 * iDelay) / iTicks);
307
iWaitfor = (mng_uint32)((1000 * iDelay) / iTicks);
315
/* ************************************************************************** */
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) * */
321
/* ************************************************************************** */
323
mng_retcode mng_display_progressive_refresh (mng_datap pData,
324
mng_uint32 iInterval)
326
{ /* let the app refresh first ? */
327
if ((pData->bRunning) && (!pData->bSkipping) &&
328
(pData->iUpdatetop < pData->iUpdatebottom) && (pData->iUpdateleft < pData->iUpdateright))
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);
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);
346
if (iRetcode) /* on error bail out */
355
/* ************************************************************************** */
357
/* * Generic display routines * */
359
/* ************************************************************************** */
361
MNG_LOCAL mng_retcode interframe_delay (mng_datap pData)
363
mng_uint32 iWaitfor = 0;
364
mng_uint32 iInterval;
365
mng_uint32 iRuninterval;
366
mng_retcode iRetcode;
368
#ifdef MNG_SUPPORT_TRACE
369
MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_START);
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);
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;
390
#ifndef MNG_SKIPCHUNK_TERM
391
if (pData->bOnlyfirstframe) /* only processing first frame after TERM ? */
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;
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;
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;
417
pData->iRuntime = pData->iRuntime - pData->iStarttime;
424
iWaitfor = calculate_delay (pData, pData->iFramedelay);
426
if (iWaitfor > iRuninterval) /* delay necessary ? */
427
iInterval = iWaitfor - iRuninterval;
429
iInterval = 1; /* force app to process messageloop */
430
/* set the timer ? */
431
if (((pData->bRunning) || (pData->bSearching) || (pData->bReading)) &&
434
iRetcode = set_delay (pData, iInterval);
436
if (iRetcode) /* on error bail out */
441
if (!pData->bSkipping) /* increase frametime in advance */
442
pData->iFrametime = pData->iFrametime + iWaitfor;
443
/* setup for next delay */
444
pData->iFramedelay = pData->iNextdelay;
448
#ifdef MNG_SUPPORT_TRACE
449
MNG_TRACE (pData, MNG_FN_INTERFRAME_DELAY, MNG_LC_END);
455
/* ************************************************************************** */
457
MNG_LOCAL void set_display_routine (mng_datap pData)
458
{ /* actively running ? */
459
if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
461
switch (pData->iCanvasstyle) /* determine display routine */
463
#ifndef MNG_SKIPCANVAS_RGB8
464
case MNG_CANVAS_RGB8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8; break; }
466
#ifndef MNG_SKIPCANVAS_RGBA8
467
case MNG_CANVAS_RGBA8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba8; break; }
469
#ifndef MNG_SKIPCANVAS_RGBA8_PM
470
case MNG_CANVAS_RGBA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_rgba8_pm; break; }
472
#ifndef MNG_SKIPCANVAS_ARGB8
473
case MNG_CANVAS_ARGB8 : { pData->fDisplayrow = (mng_fptr)mng_display_argb8; break; }
475
#ifndef MNG_SKIPCANVAS_ARGB8_PM
476
case MNG_CANVAS_ARGB8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_argb8_pm; break; }
478
#ifndef MNG_SKIPCANVAS_RGB8_A8
479
case MNG_CANVAS_RGB8_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb8_a8; break; }
481
#ifndef MNG_SKIPCANVAS_BGR8
482
case MNG_CANVAS_BGR8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr8; break; }
484
#ifndef MNG_SKIPCANVAS_BGRX8
485
case MNG_CANVAS_BGRX8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgrx8; break; }
487
#ifndef MNG_SKIPCANVAS_BGRA8
488
case MNG_CANVAS_BGRA8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra8; break; }
490
#ifndef MNG_SKIPCANVAS_BGRA8_PM
491
case MNG_CANVAS_BGRA8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_bgra8_pm; break; }
493
#ifndef MNG_SKIPCANVAS_ABGR8
494
case MNG_CANVAS_ABGR8 : { pData->fDisplayrow = (mng_fptr)mng_display_abgr8; break; }
496
#ifndef MNG_SKIPCANVAS_ABGR8_PM
497
case MNG_CANVAS_ABGR8_PM: { pData->fDisplayrow = (mng_fptr)mng_display_abgr8_pm; break; }
499
#ifndef MNG_SKIPCANVAS_RGB565
500
case MNG_CANVAS_RGB565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgb565; break; }
502
#ifndef MNG_SKIPCANVAS_RGBA565
503
case MNG_CANVAS_RGBA565 : { pData->fDisplayrow = (mng_fptr)mng_display_rgba565; break; }
505
#ifndef MNG_SKIPCANVAS_BGR565
506
case MNG_CANVAS_BGR565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565; break; }
508
#ifndef MNG_SKIPCANVAS_BGRA565
509
case MNG_CANVAS_BGRA565 : { pData->fDisplayrow = (mng_fptr)mng_display_bgra565; break; }
511
#ifndef MNG_SKIPCANVAS_BGR565_A8
512
case MNG_CANVAS_BGR565_A8 : { pData->fDisplayrow = (mng_fptr)mng_display_bgr565_a8; break; }
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; } */
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; } */
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; } */
542
/* ************************************************************************** */
544
MNG_LOCAL mng_retcode load_bkgdlayer (mng_datap pData)
546
#ifdef MNG_SUPPORT_TRACE
547
MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_START);
549
/* actively running ? */
550
if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
553
mng_retcode iRetcode;
554
mng_bool bColorcorr = MNG_FALSE;
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;
581
pData->iDestl = 0; /* determine clipping region */
583
pData->iDestr = pData->iWidth;
584
pData->iDestb = pData->iHeight;
586
#ifndef MNG_SKIPCHUNK_FRAM
587
if (pData->bFrameclipping) /* frame clipping specified ? */
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);
595
/* anything to clear ? */
596
if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt))
598
pData->iPass = -1; /* these are the object's dimensions now */
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;
608
pData->iSourcel = 0; /* source relative to destination */
609
pData->iSourcer = pData->iDestr - pData->iDestl;
611
pData->iSourceb = pData->iDestb - pData->iDestt;
613
set_display_routine (pData); /* determine display routine */
614
/* default restore using preset BG color */
615
pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgcolor;
617
#ifndef MNG_SKIPCHUNK_bKGD
618
if (((pData->eImagetype == mng_it_png) || (pData->eImagetype == mng_it_jng)) &&
620
{ /* prefer bKGD in PNG/JNG */
621
if (!pData->pCurrentobj)
622
pData->pCurrentobj = pData->pObjzero;
624
if (((mng_imagep)pData->pCurrentobj)->pImgbuf->bHasBKGD)
626
pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bkgd;
627
bColorcorr = MNG_TRUE;
632
if (pData->fGetbkgdline) /* background-canvas-access callback set ? */
634
switch (pData->iBkgdstyle)
636
#ifndef MNG_SKIPCANVAS_RGB8
637
case MNG_CANVAS_RGB8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb8; break; }
639
#ifndef MNG_SKIPCANVAS_BGR8
640
case MNG_CANVAS_BGR8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr8; break; }
642
#ifndef MNG_SKIPCANVAS_BGRX8
643
case MNG_CANVAS_BGRX8 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgrx8; break; }
645
#ifndef MNG_SKIPCANVAS_BGR565
646
case MNG_CANVAS_BGR565 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_bgr565; break; }
648
#ifndef MNG_SKIPCANVAS_RGB565
649
case MNG_CANVAS_RGB565 : { pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_rgb565; break; }
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; } */
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; } */
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; } */
665
#ifndef MNG_SKIPCHUNK_BACK
667
{ /* background image ? */
668
if ((pData->iBACKmandatory & 0x02) && (pData->iBACKimageid))
670
pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor;
671
bColorcorr = MNG_TRUE;
673
else /* background color ? */
674
if (pData->iBACKmandatory & 0x01)
676
pData->fRestbkgdrow = (mng_fptr)mng_restore_bkgd_backcolor;
677
bColorcorr = MNG_TRUE;
682
pData->fCorrectrow = MNG_NULL; /* default no color-correction */
684
if (bColorcorr) /* do we have to do color-correction ? */
687
iRetcode = MNG_NOERROR;
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);
696
if (iRetcode) /* on error bail out */
698
#endif /* MNG_NO_CMS */
700
/* get a temporary row-buffer */
701
MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize);
703
iY = pData->iDestt; /* this is where we start */
704
iRetcode = MNG_NOERROR; /* so far, so good */
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);
713
if (!iRetcode) /* so... display it */
714
iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
717
iRetcode = mng_next_row (pData);
719
iY++; /* and next line */
721
/* drop the temporary row-buffer */
722
MNG_FREE (pData, pData->pRGBArow, pData->iRowsize);
724
if (iRetcode) /* on error bail out */
727
#if defined(MNG_FULL_CMS) /* cleanup cms stuff */
728
if (bColorcorr) /* did we do color-correction ? */
730
iRetcode = mng_clear_cms (pData);
732
if (iRetcode) /* on error bail out */
736
#ifndef MNG_SKIPCHUNK_BACK
737
/* background image ? */
738
if ((pData->bHasBACK) && (pData->iBACKmandatory & 0x02) && (pData->iBACKimageid))
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 ? */
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;
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;
773
if (!pData->iBACKtile) /* without tiling further clipping is needed */
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;
781
pData->iSourcel = 0; /* source relative to destination */
782
pData->iSourcer = pData->iDestr - pData->iDestl;
784
pData->iSourceb = pData->iDestb - pData->iDestt;
785
/* 16-bit background ? */
787
#ifdef MNG_NO_16BIT_SUPPORT
788
pData->bIsRGBA16 = MNG_FALSE;
790
pData->bIsRGBA16 = (mng_bool)(pImage->pImgbuf->iBitdepth > 8);
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)
802
#ifndef MNG_NO_16BIT_SUPPORT
803
if (pImage->pImgbuf->iBitdepth > 8)
804
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
807
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
809
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
814
#ifndef MNG_NO_16BIT_SUPPORT
815
if (pImage->pImgbuf->iBitdepth > 8)
816
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
819
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
821
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
825
case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8;
826
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
831
#ifndef MNG_NO_16BIT_SUPPORT
832
if (pImage->pImgbuf->iBitdepth > 8)
833
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
836
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
838
pData->bIsOpaque = MNG_FALSE;
843
#ifndef MNG_NO_16BIT_SUPPORT
844
if (pImage->pImgbuf->iBitdepth > 8)
845
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
848
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
850
pData->bIsOpaque = MNG_FALSE;
855
#ifndef MNG_NO_16BIT_SUPPORT
856
if (pImage->pImgbuf->iBitdepth > 8)
857
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
860
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
862
pData->bIsOpaque = MNG_TRUE;
867
#ifndef MNG_NO_16BIT_SUPPORT
868
if (pImage->pImgbuf->iBitdepth > 8)
869
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
872
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
874
pData->bIsOpaque = MNG_TRUE;
879
#ifndef MNG_NO_16BIT_SUPPORT
880
if (pImage->pImgbuf->iBitdepth > 8)
881
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
884
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
886
pData->bIsOpaque = MNG_FALSE;
891
#ifndef MNG_NO_16BIT_SUPPORT
892
if (pImage->pImgbuf->iBitdepth > 8)
893
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
896
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
898
pData->bIsOpaque = MNG_FALSE;
904
iRetcode = MNG_NOERROR;
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);
913
if (iRetcode) /* on error bail out */
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);
920
iY = pData->iDestt; /* this is where we start */
921
iRetcode = MNG_NOERROR; /* so far, so good */
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);
930
if (!iRetcode) /* so... display it */
931
iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
934
iRetcode = mng_next_row (pData);
936
iY++; /* and next line */
938
/* drop temporary row-buffers */
939
MNG_FREE (pData, pData->pRGBArow, pData->iRowsize);
940
MNG_FREE (pData, pData->pPrevrow, pData->iRowsize);
942
if (iRetcode) /* on error bail out */
945
#if defined(MNG_FULL_CMS) /* cleanup cms stuff */
946
iRetcode = mng_clear_cms (pData);
948
if (iRetcode) /* on error bail out */
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;
967
pData->iRowinc = iRowinc;
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;
983
#ifdef MNG_SUPPORT_TRACE
984
MNG_TRACE (pData, MNG_FN_LOAD_BKGDLAYER, MNG_LC_END);
990
/* ************************************************************************** */
992
MNG_LOCAL mng_retcode clear_canvas (mng_datap pData)
995
mng_retcode iRetcode;
997
#ifdef MNG_SUPPORT_TRACE
998
MNG_TRACE (pData, MNG_FN_CLEAR_CANVAS, MNG_LC_START);
1001
pData->iDestl = 0; /* clipping region is full canvas! */
1003
pData->iDestr = pData->iWidth;
1004
pData->iDestb = pData->iHeight;
1006
pData->iSourcel = 0; /* source is same as destination */
1007
pData->iSourcer = pData->iWidth;
1008
pData->iSourcet = 0;
1009
pData->iSourceb = pData->iHeight;
1011
pData->iPass = -1; /* these are the object's dimensions now */
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;
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);
1026
iY = pData->iDestt; /* this is where we start */
1027
iRetcode = MNG_NOERROR; /* so far, so good */
1029
while ((!iRetcode) && (iY < pData->iDestb))
1030
{ /* clear a row then */
1031
iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
1034
iRetcode = mng_next_row (pData); /* adjust variables for next row */
1036
iY++; /* and next line */
1038
/* drop the temporary row-buffer */
1039
MNG_FREE (pData, pData->pRGBArow, pData->iRowsize);
1041
if (iRetcode) /* on error bail out */
1044
#ifdef MNG_SUPPORT_TRACE
1045
MNG_TRACE (pData, MNG_FN_CLEAR_CANVAS, MNG_LC_END);
1051
/* ************************************************************************** */
1053
MNG_LOCAL mng_retcode next_frame (mng_datap pData,
1054
mng_uint8 iFramemode,
1055
mng_uint8 iChangedelay,
1057
mng_uint8 iChangetimeout,
1058
mng_uint32 iTimeout,
1059
mng_uint8 iChangeclipping,
1060
mng_uint8 iCliptype,
1066
mng_retcode iRetcode = MNG_NOERROR;
1068
#ifdef MNG_SUPPORT_TRACE
1069
MNG_TRACE (pData, MNG_FN_NEXT_FRAME, MNG_LC_START);
1072
if (!pData->iBreakpoint) /* no previous break here ? */
1074
#ifndef MNG_SKIPCHUNK_FRAM
1075
mng_uint8 iOldmode = pData->iFramemode;
1076
/* interframe delay required ? */
1077
if ((iOldmode == 2) || (iOldmode == 4))
1079
if ((pData->iFrameseq) && (iFramemode != 1) && (iFramemode != 3))
1080
iRetcode = interframe_delay (pData);
1082
pData->iFramedelay = pData->iNextdelay;
1085
{ /* delay before inserting background layer? */
1086
if ((pData->bFramedone) && (iFramemode == 4))
1087
iRetcode = interframe_delay (pData);
1090
if (iRetcode) /* on error bail out */
1092
/* now we'll assume we're in the next frame! */
1093
if (iFramemode) /* save the new framing mode ? */
1095
pData->iFRAMmode = iFramemode;
1096
pData->iFramemode = iFramemode;
1098
else /* reload default */
1099
pData->iFramemode = pData->iFRAMmode;
1101
if (iChangedelay) /* delay changed ? */
1103
pData->iNextdelay = iDelay; /* for *after* next subframe */
1105
if ((iOldmode == 2) || (iOldmode == 4))
1106
pData->iFramedelay = pData->iFRAMdelay;
1108
if (iChangedelay == 2) /* also overall ? */
1109
pData->iFRAMdelay = iDelay;
1112
{ /* reload default */
1113
pData->iNextdelay = pData->iFRAMdelay;
1116
if (iChangetimeout) /* timeout changed ? */
1117
{ /* for next subframe */
1118
pData->iFrametimeout = iTimeout;
1120
if ((iChangetimeout == 2) || /* also overall ? */
1121
(iChangetimeout == 4) ||
1122
(iChangetimeout == 6) ||
1123
(iChangetimeout == 8))
1124
pData->iFRAMtimeout = iTimeout;
1126
else /* reload default */
1127
pData->iFrametimeout = pData->iFRAMtimeout;
1129
if (iChangeclipping) /* clipping changed ? */
1131
pData->bFrameclipping = MNG_TRUE;
1133
if (!iCliptype) /* absolute ? */
1135
pData->iFrameclipl = iClipl;
1136
pData->iFrameclipr = iClipr;
1137
pData->iFrameclipt = iClipt;
1138
pData->iFrameclipb = iClipb;
1142
pData->iFrameclipl = pData->iFrameclipl + iClipl;
1143
pData->iFrameclipr = pData->iFrameclipr + iClipr;
1144
pData->iFrameclipt = pData->iFrameclipt + iClipt;
1145
pData->iFrameclipb = pData->iFrameclipb + iClipb;
1148
if (iChangeclipping == 2) /* also overall ? */
1150
pData->bFRAMclipping = MNG_TRUE;
1152
if (!iCliptype) /* absolute ? */
1154
pData->iFRAMclipl = iClipl;
1155
pData->iFRAMclipr = iClipr;
1156
pData->iFRAMclipt = iClipt;
1157
pData->iFRAMclipb = iClipb;
1161
pData->iFRAMclipl = pData->iFRAMclipl + iClipl;
1162
pData->iFRAMclipr = pData->iFRAMclipr + iClipr;
1163
pData->iFRAMclipt = pData->iFRAMclipt + iClipt;
1164
pData->iFRAMclipb = pData->iFRAMclipb + iClipb;
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;
1179
if (!pData->bTimerset) /* timer still off ? */
1182
#ifndef MNG_SKIPCHUNK_FRAM
1183
(pData->iFramemode == 4) || /* insert background layer after a new frame */
1185
(!pData->iLayerseq)) /* and certainly before the very first layer */
1186
iRetcode = load_bkgdlayer (pData);
1188
if (iRetcode) /* on error bail out */
1191
pData->iFrameseq++; /* count the frame ! */
1192
pData->bFramedone = MNG_TRUE; /* and indicate we've done one */
1195
#ifdef MNG_SUPPORT_TRACE
1196
MNG_TRACE (pData, MNG_FN_NEXT_FRAME, MNG_LC_END);
1202
/* ************************************************************************** */
1204
MNG_LOCAL mng_retcode next_layer (mng_datap pData)
1207
mng_retcode iRetcode = MNG_NOERROR;
1209
#ifdef MNG_SUPPORT_TRACE
1210
MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_START);
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);
1220
pData->iFramedelay = pData->iNextdelay;
1222
if (iRetcode) /* on error bail out */
1227
if (!pData->bTimerset) /* timer still off ? */
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;
1234
{ /* for MNG we do it right away */
1235
iRetcode = load_bkgdlayer (pData);
1236
pData->iLayerseq++; /* and it counts as a layer then ! */
1239
#ifndef MNG_SKIPCHUNK_FRAM
1241
if (pData->iFramemode == 3) /* restore background for each layer ? */
1242
iRetcode = load_bkgdlayer (pData);
1245
if (iRetcode) /* on error bail out */
1248
#ifndef MNG_NO_DELTA_PNG
1249
if (pData->bHasDHDR) /* processing a delta-image ? */
1250
pImage = (mng_imagep)pData->pDeltaImage;
1253
pImage = (mng_imagep)pData->pCurrentobj;
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))
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);
1268
else /* it's a single image ! */
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);
1276
#ifndef MNG_SKIPCHUNK_FRAM
1277
if (pData->bFrameclipping) /* frame clipping specified ? */
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);
1286
if (pImage->bClipped) /* is the image clipped itself ? */
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);
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);
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);
1304
else /* it's a single image ! */
1306
pData->iSourcer = pData->iSourcel + pData->iDestr - pData->iDestl;
1307
pData->iSourceb = pData->iSourcet + pData->iDestb - pData->iDestt;
1310
pData->iLayerseq++; /* count the layer ! */
1313
#ifdef MNG_SUPPORT_TRACE
1314
MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_END);
1320
/* ************************************************************************** */
1322
mng_retcode mng_display_image (mng_datap pData,
1324
mng_bool bLayeradvanced)
1326
mng_retcode iRetcode;
1328
#ifdef MNG_SUPPORT_TRACE
1329
MNG_TRACE (pData, MNG_FN_DISPLAY_IMAGE, MNG_LC_START);
1331
/* actively running ? */
1332
#ifndef MNG_SKIPCHUNK_MAGN
1333
if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
1335
if ( (!pData->iBreakpoint) && /* needs magnification ? */
1336
( (pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY) ) )
1338
iRetcode = mng_magnify_imageobject (pData, pImage);
1340
if (iRetcode) /* on error bail out */
1346
pData->pRetrieveobj = pImage; /* so retrieve-row and color-correction can find it */
1348
if (!bLayeradvanced) /* need to advance the layer ? */
1350
mng_imagep pSave = pData->pCurrentobj;
1351
pData->pCurrentobj = pImage;
1352
next_layer (pData); /* advance to next layer */
1353
pData->pCurrentobj = pSave;
1355
/* need to restore the background ? */
1356
if ((!pData->bTimerset) && (pData->bRestorebkgd))
1358
mng_imagep pSave = pData->pCurrentobj;
1359
pData->pCurrentobj = pImage;
1360
pData->bRestorebkgd = MNG_FALSE;
1361
iRetcode = load_bkgdlayer (pData);
1362
pData->pCurrentobj = pSave;
1364
if (iRetcode) /* on error bail out */
1367
pData->iLayerseq++; /* and it counts as a layer then ! */
1369
/* actively running ? */
1370
if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
1372
if (!pData->bTimerset) /* all systems still go ? */
1374
pData->iBreakpoint = 0; /* let's make absolutely sure... */
1375
/* anything to display ? */
1376
if ((pData->iDestr >= pData->iDestl) && (pData->iDestb >= pData->iDestt))
1380
set_display_routine (pData); /* determine display routine */
1381
/* and image-buffer retrieval routine */
1382
switch (pImage->pImgbuf->iColortype)
1385
#ifndef MNG_NO_16BIT_SUPPORT
1386
if (pImage->pImgbuf->iBitdepth > 8)
1387
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
1390
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
1392
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
1397
#ifndef MNG_NO_16BIT_SUPPORT
1398
if (pImage->pImgbuf->iBitdepth > 8)
1399
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
1402
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
1404
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
1409
case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8;
1410
pData->bIsOpaque = (mng_bool)(!pImage->pImgbuf->bHasTRNS);
1416
#ifndef MNG_NO_16BIT_SUPPORT
1417
if (pImage->pImgbuf->iBitdepth > 8)
1418
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
1421
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
1423
pData->bIsOpaque = MNG_FALSE;
1429
#ifndef MNG_NO_16BIT_SUPPORT
1430
if (pImage->pImgbuf->iBitdepth > 8)
1431
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
1434
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
1436
pData->bIsOpaque = MNG_FALSE;
1441
#ifndef MNG_NO_16BIT_SUPPORT
1442
if (pImage->pImgbuf->iBitdepth > 8)
1443
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
1446
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
1448
pData->bIsOpaque = MNG_TRUE;
1453
#ifndef MNG_NO_16BIT_SUPPORT
1454
if (pImage->pImgbuf->iBitdepth > 8)
1455
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
1458
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
1460
pData->bIsOpaque = MNG_TRUE;
1466
#ifndef MNG_NO_16BIT_SUPPORT
1467
if (pImage->pImgbuf->iBitdepth > 8)
1468
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
1471
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
1473
pData->bIsOpaque = MNG_FALSE;
1479
#ifndef MNG_NO_16BIT_SUPPORT
1480
if (pImage->pImgbuf->iBitdepth > 8)
1481
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
1484
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
1486
pData->bIsOpaque = MNG_FALSE;
1492
pData->iPass = -1; /* these are the object's dimensions now */
1493
pData->iRow = pData->iSourcet;
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)
1504
pData->bIsRGBA16 = MNG_TRUE;
1505
pData->iRowsize = pData->iRowsamples << 3;
1509
pData->fCorrectrow = MNG_NULL; /* default no color-correction */
1512
iRetcode = MNG_NOERROR;
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);
1521
if (iRetcode) /* on error bail out */
1523
#endif /* MNG_NO_CMS */
1524
/* get a temporary row-buffer */
1525
MNG_ALLOC (pData, pData->pRGBArow, pData->iRowsize);
1527
iY = pData->iSourcet; /* this is where we start */
1529
while ((!iRetcode) && (iY < pData->iSourceb))
1531
iRetcode = ((mng_retrieverow)pData->fRetrieverow) (pData);
1532
/* color correction ? */
1533
if ((!iRetcode) && (pData->fCorrectrow))
1534
iRetcode = ((mng_correctrow)pData->fCorrectrow) (pData);
1536
if (!iRetcode) /* so... display it */
1537
iRetcode = ((mng_displayrow)pData->fDisplayrow) (pData);
1539
if (!iRetcode) /* adjust variables for next row */
1540
iRetcode = mng_next_row (pData);
1542
iY++; /* and next line */
1544
/* drop the temporary row-buffer */
1545
MNG_FREE (pData, pData->pRGBArow, pData->iRowsize);
1547
if (iRetcode) /* on error bail out */
1550
#if defined(MNG_FULL_CMS) /* cleanup cms stuff */
1551
iRetcode = mng_clear_cms (pData);
1553
if (iRetcode) /* on error bail out */
1560
#ifdef MNG_SUPPORT_TRACE
1561
MNG_TRACE (pData, MNG_FN_DISPLAY_IMAGE, MNG_LC_END);
1564
return MNG_NOERROR; /* whehehe, this is good ! */
1567
/* ************************************************************************** */
1569
#ifndef MNG_NO_DELTA_PNG
1570
mng_retcode mng_execute_delta_image (mng_datap pData,
1574
mng_imagedatap pBuftarget = pTarget->pImgbuf;
1575
mng_imagedatap pBufdelta = pDelta->pImgbuf;
1577
mng_retcode iRetcode;
1580
#ifdef MNG_SUPPORT_TRACE
1581
MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_START);
1583
/* actively running ? */
1584
if (((pData->bRunning) || (pData->bSearching)) && (!pData->bSkipping))
1586
if (pBufdelta->bHasPLTE) /* palette in delta ? */
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;
1595
for (iX = 0; iX < pBufdelta->iPLTEcount; iX++)
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;
1603
if (pBufdelta->bHasTRNS) /* cheap transparency in delta ? */
1605
switch (pData->iColortype) /* drop it into the target */
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;
1616
pBuftarget->iTRNSgray = 0;
1617
pBuftarget->iTRNSred = pBufdelta->iTRNSred;
1618
pBuftarget->iTRNSgreen = pBufdelta->iTRNSgreen;
1619
pBuftarget->iTRNSblue = pBufdelta->iTRNSblue;
1620
pBuftarget->iTRNScount = 0;
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;
1632
MNG_COPY (pBuftarget->aTRNSentries, pBufdelta->aTRNSentries, pBufdelta->iTRNScount);
1637
pBuftarget->bHasTRNS = MNG_TRUE; /* tell it it's got a tRNS now */
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;
1652
if (pBufdelta->bHasGAMA) /* gamma in source ? */
1654
pBuftarget->bHasGAMA = MNG_TRUE; /* drop it onto the target */
1655
pBuftarget->iGamma = pBufdelta->iGamma;
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;
1673
if (pBufdelta->bHasSRGB) /* sRGB in delta ? */
1674
{ /* drop it onto the target */
1675
pBuftarget->bHasSRGB = MNG_TRUE;
1676
pBuftarget->iRenderingintent = pBufdelta->iRenderingintent;
1679
#ifndef MNG_SKIPCHUNK_iCCP
1680
if (pBufdelta->bHasICCP) /* ICC profile in delta ? */
1682
pBuftarget->bHasICCP = MNG_TRUE; /* drop it onto the target */
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;
1693
/* need to execute delta pixels ? */
1694
if ((!pData->bDeltaimmediate) && (pData->iDeltatype != MNG_DELTATYPE_NOCHANGE))
1696
pData->fScalerow = MNG_NULL; /* not needed by default */
1698
switch (pBufdelta->iBitdepth) /* determine scaling routine */
1700
#ifndef MNG_NO_1_2_4BIT_SUPPORT
1702
switch (pBuftarget->iBitdepth)
1704
case 2 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g2; break; }
1705
case 4 : { pData->fScalerow = (mng_fptr)mng_scale_g1_g4; break; }
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; }
1716
switch (pBuftarget->iBitdepth)
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; }
1729
switch (pBuftarget->iBitdepth)
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; }
1740
#endif /* MNG_NO_1_2_4BIT_SUPPORT */
1743
switch (pBufdelta->iColortype)
1748
switch (pBuftarget->iBitdepth)
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; }
1763
#ifndef MNG_NO_16BIT_SUPPORT
1764
if (pBuftarget->iBitdepth == 16)
1765
pData->fScalerow = (mng_fptr)mng_scale_rgb8_rgb16;
1771
#ifndef MNG_NO_16BIT_SUPPORT
1772
if (pBuftarget->iBitdepth == 16)
1773
pData->fScalerow = (mng_fptr)mng_scale_ga8_ga16;
1779
#ifndef MNG_NO_16BIT_SUPPORT
1780
if (pBuftarget->iBitdepth == 16)
1781
pData->fScalerow = (mng_fptr)mng_scale_rgba8_rgba16;
1789
#ifndef MNG_NO_16BIT_SUPPORT
1791
switch (pBufdelta->iColortype)
1796
switch (pBuftarget->iBitdepth)
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; }
1809
if (pBuftarget->iBitdepth == 8)
1810
pData->fScalerow = (mng_fptr)mng_scale_rgb16_rgb8;
1815
if (pBuftarget->iBitdepth == 8)
1816
pData->fScalerow = (mng_fptr)mng_scale_ga16_ga8;
1821
if (pBuftarget->iBitdepth == 8)
1822
pData->fScalerow = (mng_fptr)mng_scale_rgba16_rgba8;
1832
pData->fDeltarow = MNG_NULL; /* let's assume there's nothing to do */
1834
switch (pBuftarget->iColortype) /* determine delta processing routine */
1837
case 8 : { /* gray */
1838
if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
1839
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
1840
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
1842
if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) ||
1843
(pBufdelta->iColortype == 8))
1845
switch (pBuftarget->iBitdepth)
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; }
1864
case 10 : { /* rgb */
1865
if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
1866
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
1867
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
1869
if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10))
1871
switch (pBuftarget->iBitdepth)
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; }
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) )
1889
if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3))
1891
switch (pBuftarget->iBitdepth)
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; }
1907
case 12 : { /* gray + alpha */
1908
if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
1909
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
1910
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
1912
if ((pBufdelta->iColortype == 4) || (pBufdelta->iColortype == 12))
1914
switch (pBuftarget->iBitdepth)
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; }
1924
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
1925
(pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
1927
if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3) ||
1928
(pBufdelta->iColortype == 8))
1930
switch (pBuftarget->iBitdepth)
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; }
1940
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
1941
(pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
1943
if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3))
1945
switch (pBuftarget->iBitdepth)
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; }
1959
case 14 : { /* rgb + alpha */
1960
if ((pData->iDeltatype == MNG_DELTATYPE_REPLACE ) ||
1961
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
1962
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
1964
if ((pBufdelta->iColortype == 6) || (pBufdelta->iColortype == 14))
1966
switch (pBuftarget->iBitdepth)
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; }
1976
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
1977
(pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
1979
if ((pBufdelta->iColortype == 2) || (pBufdelta->iColortype == 10))
1981
switch (pBuftarget->iBitdepth)
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; }
1991
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
1992
(pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
1994
if ((pBufdelta->iColortype == 0) || (pBufdelta->iColortype == 3))
1996
switch (pBuftarget->iBitdepth)
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; }
2011
if (pData->fDeltarow) /* do we need to take action ? */
2013
pData->iPass = -1; /* setup row dimensions and stuff */
2014
pData->iRow = pData->iDeltaBlocky;
2016
pData->iCol = pData->iDeltaBlockx;
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;
2024
pSaveRGBA = pData->pRGBArow; /* save current temp-buffer! */
2025
/* get a temporary row-buffer */
2026
MNG_ALLOC (pData, pData->pRGBArow, (pBufdelta->iRowsize << 1));
2028
iY = 0; /* this is where we start */
2029
iRetcode = MNG_NOERROR; /* still oke for now */
2031
while ((!iRetcode) && (iY < pBufdelta->iHeight))
2033
mng_uint8p pWork = pBufdelta->pImgdata + (iY * pBufdelta->iRowsize);
2035
MNG_COPY (pData->pRGBArow, pWork, pBufdelta->iRowsize);
2037
if (pData->fScalerow) /* scale it (if necessary) */
2038
iRetcode = ((mng_scalerow)pData->fScalerow) (pData);
2040
if (!iRetcode) /* and... execute it */
2041
iRetcode = ((mng_deltarow)pData->fDeltarow) (pData);
2043
if (!iRetcode) /* adjust variables for next row */
2044
iRetcode = mng_next_row (pData);
2046
iY++; /* and next line */
2048
/* drop the temporary row-buffer */
2049
MNG_FREE (pData, pData->pRGBArow, (pBufdelta->iRowsize << 1));
2050
pData->pRGBArow = pSaveRGBA; /* restore saved temp-buffer! */
2052
if (iRetcode) /* on error bail out */
2057
MNG_ERROR (pData, MNG_INVALIDDELTA);
2062
#ifdef MNG_SUPPORT_TRACE
2063
MNG_TRACE (pData, MNG_FN_EXECUTE_DELTA_IMAGE, MNG_LC_END);
2068
#endif /* MNG_NO_DELTA_PNG */
2070
/* ************************************************************************** */
2072
#ifndef MNG_SKIPCHUNK_SAVE
2073
MNG_LOCAL mng_retcode save_state (mng_datap pData)
2075
mng_savedatap pSave;
2078
#ifdef MNG_SUPPORT_TRACE
2079
MNG_TRACE (pData, MNG_FN_SAVE_STATE, MNG_LC_START);
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));
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 */
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;
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;
2115
pSave->iGlobalPLTEcount = pData->iGlobalPLTEcount;
2117
MNG_COPY (pSave->aGlobalPLTEentries, pData->aGlobalPLTEentries, sizeof (mng_rgbpaltab));
2119
pSave->iGlobalTRNSrawlen = pData->iGlobalTRNSrawlen;
2120
MNG_COPY (pSave->aGlobalTRNSrawdata, pData->aGlobalTRNSrawdata, 256);
2122
pSave->iGlobalGamma = pData->iGlobalGamma;
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;
2135
pSave->iGlobalRendintent = pData->iGlobalRendintent;
2137
#ifndef MNG_SKIPCHUNK_iCCP
2138
pSave->iGlobalProfilesize = pData->iGlobalProfilesize;
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);
2147
#ifndef MNG_SKIPCHUNK_bKGD
2148
pSave->iGlobalBKGDred = pData->iGlobalBKGDred;
2149
pSave->iGlobalBKGDgreen = pData->iGlobalBKGDgreen;
2150
pSave->iGlobalBKGDblue = pData->iGlobalBKGDblue;
2153
/* freeze current image objects */
2154
pImage = (mng_imagep)pData->pFirstimgobj;
2157
{ /* freeze the object AND it's buffer */
2158
pImage->bFrozen = MNG_TRUE;
2159
pImage->pImgbuf->bFrozen = MNG_TRUE;
2161
pImage = (mng_imagep)pImage->sHeader.pNext;
2164
#ifdef MNG_SUPPORT_TRACE
2165
MNG_TRACE (pData, MNG_FN_SAVE_STATE, MNG_LC_END);
2172
/* ************************************************************************** */
2174
mng_retcode mng_reset_objzero (mng_datap pData)
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);
2180
if (iRetcode) /* on error bail out */
2183
pImage->bVisible = MNG_TRUE;
2184
pImage->bViewable = MNG_TRUE;
2187
pImage->bClipped = MNG_FALSE;
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;
2206
/* ************************************************************************** */
2208
MNG_LOCAL mng_retcode restore_state (mng_datap pData)
2210
#ifndef MNG_SKIPCHUNK_SAVE
2211
mng_savedatap pSave;
2214
mng_retcode iRetcode;
2216
#ifdef MNG_SUPPORT_TRACE
2217
MNG_TRACE (pData, MNG_FN_RESTORE_STATE, MNG_LC_START);
2219
/* restore object 0 status !!! */
2220
iRetcode = mng_reset_objzero (pData);
2222
if (iRetcode) /* on error bail out */
2224
/* fresh cycle; fake no frames done yet */
2225
pData->bFramedone = MNG_FALSE;
2227
#ifndef MNG_SKIPCHUNK_SAVE
2228
if (pData->pSavedata) /* do we have a saved state ? */
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 */
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;
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;
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; */
2267
/* pData->iNextdelay = pSave->iFRAMdelay; */
2268
pData->iNextdelay = pData->iFramedelay;
2270
pData->iGlobalPLTEcount = pSave->iGlobalPLTEcount;
2271
MNG_COPY (pData->aGlobalPLTEentries, pSave->aGlobalPLTEentries, sizeof (mng_rgbpaltab));
2273
pData->iGlobalTRNSrawlen = pSave->iGlobalTRNSrawlen;
2274
MNG_COPY (pData->aGlobalTRNSrawdata, pSave->aGlobalTRNSrawdata, 256);
2276
pData->iGlobalGamma = pSave->iGlobalGamma;
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;
2289
pData->iGlobalRendintent = pSave->iGlobalRendintent;
2291
#ifndef MNG_SKIPCHUNK_iCCP
2292
pData->iGlobalProfilesize = pSave->iGlobalProfilesize;
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);
2301
#ifndef MNG_SKIPCHUNK_bKGD
2302
pData->iGlobalBKGDred = pSave->iGlobalBKGDred;
2303
pData->iGlobalBKGDgreen = pSave->iGlobalBKGDgreen;
2304
pData->iGlobalBKGDblue = pSave->iGlobalBKGDblue;
2307
else /* no saved-data; so reset the lot */
2308
#endif /* SKIPCHUNK_SAVE */
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 */
2320
#ifndef MNG_SKIPCHUNK_TERM
2321
if (!pData->bMisplacedTERM) /* backward compatible ugliness !!! */
2323
pData->iBACKred = 0;
2324
pData->iBACKgreen = 0;
2325
pData->iBACKblue = 0;
2326
pData->iBACKmandatory = 0;
2327
pData->iBACKimageid = 0;
2328
pData->iBACKtile = 0;
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;
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; */
2351
/* pData->iNextdelay = 1; */
2352
pData->iNextdelay = pData->iFramedelay;
2355
pData->iGlobalPLTEcount = 0;
2357
pData->iGlobalTRNSrawlen = 0;
2359
pData->iGlobalGamma = 0;
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;
2372
pData->iGlobalRendintent = 0;
2374
#ifndef MNG_SKIPCHUNK_iCCP
2375
if (pData->iGlobalProfilesize) /* free a previous profile ? */
2376
MNG_FREE (pData, pData->pGlobalProfile, pData->iGlobalProfilesize);
2378
pData->iGlobalProfilesize = 0;
2381
#ifndef MNG_SKIPCHUNK_bKGD
2382
pData->iGlobalBKGDred = 0;
2383
pData->iGlobalBKGDgreen = 0;
2384
pData->iGlobalBKGDblue = 0;
2388
#ifndef MNG_SKIPCHUNK_TERM
2389
if (!pData->bMisplacedTERM) /* backward compatible ugliness !!! */
2391
pImage = (mng_imagep)pData->pFirstimgobj;
2392
/* drop un-frozen image objects */
2395
mng_imagep pNext = (mng_imagep)pImage->sHeader.pNext;
2397
if (!pImage->bFrozen) /* is it un-frozen ? */
2399
mng_imagep pPrev = (mng_imagep)pImage->sHeader.pPrev;
2401
if (pPrev) /* unlink it */
2402
pPrev->sHeader.pNext = pNext;
2404
pData->pFirstimgobj = pNext;
2407
pNext->sHeader.pPrev = pPrev;
2409
pData->pLastimgobj = pPrev;
2411
if (pImage->pImgbuf->bFrozen) /* buffer frozen ? */
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));
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));
2426
if (iRetcode) /* on error bail out */
2431
pImage = pNext; /* neeeext */
2436
#ifdef MNG_SUPPORT_TRACE
2437
MNG_TRACE (pData, MNG_FN_RESTORE_STATE, MNG_LC_END);
2443
/* ************************************************************************** */
2445
/* * General display processing routine * */
2447
/* ************************************************************************** */
2449
mng_retcode mng_process_display (mng_datap pData)
2451
mng_retcode iRetcode = MNG_NOERROR;
2453
#ifdef MNG_SUPPORT_TRACE
2454
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY, MNG_LC_START);
2457
if (!pData->iBreakpoint) /* not broken previously ? */
2459
if ((pData->iRequestframe) || (pData->iRequestlayer) || (pData->iRequesttime))
2461
pData->bSearching = MNG_TRUE; /* indicate we're searching */
2463
iRetcode = clear_canvas (pData); /* make the canvas virgin black ?!? */
2465
if (iRetcode) /* on error bail out */
2467
/* let's start from the top, shall we */
2468
pData->pCurraniobj = pData->pFirstaniobj;
2472
do /* process the objects */
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))
2479
switch (pData->iBreakpoint) /* return to broken display routine */
2481
#ifndef MNG_SKIPCHUNK_FRAM
2482
case 1 : { iRetcode = mng_process_display_fram2 (pData); break; }
2484
#ifndef MNG_SKIPCHUNK_SHOW
2485
case 3 : ; /* same as 4 !!! */
2486
case 4 : { iRetcode = mng_process_display_show (pData); break; }
2488
#ifndef MNG_SKIPCHUNK_CLON
2489
case 5 : { iRetcode = mng_process_display_clon2 (pData); break; }
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; }
2495
#ifndef MNG_SKIPCHUNK_PAST
2496
case 11 : { iRetcode = mng_process_display_past2 (pData); break; }
2498
default : MNG_ERROR (pData, MNG_INTERNALERROR);
2503
if (pData->pCurraniobj)
2504
iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj);
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))
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);
2518
if (!pData->pCurraniobj) /* refresh after last image ? */
2519
pData->bNeedrefresh = MNG_TRUE;
2522
if (pData->bSearching) /* are we looking for something ? */
2524
if ((pData->iRequestframe) && (pData->iRequestframe <= pData->iFrameseq))
2526
pData->iRequestframe = 0; /* found the frame ! */
2527
pData->bSearching = MNG_FALSE;
2530
if ((pData->iRequestlayer) && (pData->iRequestlayer <= pData->iLayerseq))
2532
pData->iRequestlayer = 0; /* found the layer ! */
2533
pData->bSearching = MNG_FALSE;
2536
if ((pData->iRequesttime) && (pData->iRequesttime <= pData->iFrametime))
2538
pData->iRequesttime = 0; /* found the playtime ! */
2539
pData->bSearching = MNG_FALSE;
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));
2547
if (iRetcode) /* on error bail out */
2549
/* refresh needed ? */
2550
if ((!pData->bTimerset) && (pData->bNeedrefresh))
2552
iRetcode = mng_display_progressive_refresh (pData, 1);
2554
if (iRetcode) /* on error bail out */
2558
if ((pData->bTimerset) && (!pData->iBreakpoint))
2559
pData->iBreakpoint = 99;
2561
if (!pData->bTimerset)
2562
pData->iBreakpoint = 0; /* reset if no timer break */
2564
if ((!pData->bTimerset) && (!pData->pCurraniobj))
2565
pData->bRunning = MNG_FALSE; /* all done now ! */
2567
#ifdef MNG_SUPPORT_TRACE
2568
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY, MNG_LC_END);
2574
/* ************************************************************************** */
2576
/* * Chunk display processing routines * */
2578
/* ************************************************************************** */
2580
#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
2581
png_imgtype mng_png_imgtype(mng_uint8 colortype, mng_uint8 bitdepth)
2588
png_imgtype imgtype[]={png_g1,png_none,png_none,png_idx1};
2589
ret=imgtype[colortype];
2594
png_imgtype imgtype[]={png_g2,png_none,png_none,png_idx2};
2595
ret=imgtype[colortype];
2600
png_imgtype imgtype[]={png_g4,png_none,png_none,png_idx4};
2601
ret=imgtype[colortype];
2606
png_imgtype imgtype[]={png_g8,png_none,png_rgb8,png_idx8,png_ga8,
2607
png_none,png_rgba8};
2608
ret=imgtype[colortype];
2611
#ifndef MNG_NO_16BIT_SUPPORT
2614
png_imgtype imgtype[]={png_g16,png_none,png_rgb16,png_none,png_ga16,
2615
png_none,png_rgba16};
2616
ret=imgtype[colortype];
2626
#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
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;
2632
#ifdef MNG_SUPPORT_TRACE
2633
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IHDR, MNG_LC_START);
2636
if (!pData->bHasDHDR)
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;
2647
if (!pData->iBreakpoint) /* not previously broken ? */
2649
mng_retcode iRetcode = MNG_NOERROR;
2651
#ifndef MNG_NO_DELTA_PNG
2652
if (pData->bHasDHDR) /* is a delta-image ? */
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);
2661
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
2662
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
2664
((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iBitdepth;
2665
((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iBitdepth;
2668
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
2669
(pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
2670
((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iBitdepth;
2672
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
2673
(pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
2674
((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iBitdepth;
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);
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);
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);
2706
if (iRetcode) /* on error bail out */
2710
#ifndef MNG_NO_DELTA_PNG
2711
if (!pData->bHasDHDR)
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" ? */
2720
#ifndef MNG_SKIPCHUNK_MAGN
2721
(((mng_imagep)pData->pStoreobj)->iMAGN_MethodX == 0) &&
2722
(((mng_imagep)pData->pStoreobj)->iMAGN_MethodY == 0) &&
2724
( (pData->eImagetype == mng_it_png ) ||
2725
(((mng_imagep)pData->pStoreobj)->bVisible) ) )
2727
next_layer (pData); /* that's a new layer then ! */
2729
if (pData->bTimerset) /* timer break ? */
2730
pData->iBreakpoint = 2;
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 */
2741
if (!pData->bTimerset) /* no timer break ? */
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);
2747
switch (pData->iColortype) /* determine row initialization routine */
2749
case 0 : { /* gray */
2750
switch (pData->iBitdepth)
2752
#ifndef MNG_NO_1_2_4BIT_SUPPORT
2754
if (!pData->iInterlace)
2755
pData->fInitrowproc = (mng_fptr)mng_init_g1_ni;
2757
pData->fInitrowproc = (mng_fptr)mng_init_g1_i;
2762
if (!pData->iInterlace)
2763
pData->fInitrowproc = (mng_fptr)mng_init_g2_ni;
2765
pData->fInitrowproc = (mng_fptr)mng_init_g2_i;
2770
if (!pData->iInterlace)
2771
pData->fInitrowproc = (mng_fptr)mng_init_g4_ni;
2773
pData->fInitrowproc = (mng_fptr)mng_init_g4_i;
2776
#endif /* MNG_NO_1_2_4BIT_SUPPORT */
2778
if (!pData->iInterlace)
2779
pData->fInitrowproc = (mng_fptr)mng_init_g8_ni;
2781
pData->fInitrowproc = (mng_fptr)mng_init_g8_i;
2785
#ifndef MNG_NO_16BIT_SUPPORT
2787
if (!pData->iInterlace)
2788
pData->fInitrowproc = (mng_fptr)mng_init_g16_ni;
2790
pData->fInitrowproc = (mng_fptr)mng_init_g16_i;
2799
case 2 : { /* rgb */
2800
switch (pData->iBitdepth)
2803
if (!pData->iInterlace)
2804
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni;
2806
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i;
2809
#ifndef MNG_NO_16BIT_SUPPORT
2811
if (!pData->iInterlace)
2812
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni;
2814
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i;
2823
case 3 : { /* indexed */
2824
switch (pData->iBitdepth)
2826
#ifndef MNG_NO_1_2_4BIT_SUPPORT
2828
if (!pData->iInterlace)
2829
pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni;
2831
pData->fInitrowproc = (mng_fptr)mng_init_idx1_i;
2836
if (!pData->iInterlace)
2837
pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni;
2839
pData->fInitrowproc = (mng_fptr)mng_init_idx2_i;
2844
if (!pData->iInterlace)
2845
pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni;
2847
pData->fInitrowproc = (mng_fptr)mng_init_idx4_i;
2851
#endif /* MNG_NO_1_2_4BIT_SUPPORT */
2853
if (!pData->iInterlace)
2854
pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni;
2856
pData->fInitrowproc = (mng_fptr)mng_init_idx8_i;
2864
case 4 : { /* gray+alpha */
2865
switch (pData->iBitdepth)
2868
if (!pData->iInterlace)
2869
pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni;
2871
pData->fInitrowproc = (mng_fptr)mng_init_ga8_i;
2875
#ifndef MNG_NO_16BIT_SUPPORT
2877
if (!pData->iInterlace)
2878
pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni;
2880
pData->fInitrowproc = (mng_fptr)mng_init_ga16_i;
2888
case 6 : { /* rgb+alpha */
2889
switch (pData->iBitdepth)
2892
if (!pData->iInterlace)
2893
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni;
2895
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i;
2899
#ifndef MNG_NO_16BIT_SUPPORT
2901
if (!pData->iInterlace)
2902
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni;
2904
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i;
2914
#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
2916
pData->iFilterofs = 0; /* determine filter characteristics */
2917
pData->iLevel0 = 0; /* default levels */
2922
#ifdef FILTER192 /* leveling & differing ? */
2923
if (pData->iFilter == MNG_FILTER_DIFFERING)
2925
switch (pData->iColortype)
2928
if (pData->iBitdepth <= 8)
2929
pData->iFilterofs = 1;
2931
pData->iFilterofs = 2;
2936
if (pData->iBitdepth <= 8)
2937
pData->iFilterofs = 3;
2939
pData->iFilterofs = 6;
2944
pData->iFilterofs = 1;
2948
if (pData->iBitdepth <= 8)
2949
pData->iFilterofs = 2;
2951
pData->iFilterofs = 4;
2956
if (pData->iBitdepth <= 8)
2957
pData->iFilterofs = 4;
2959
pData->iFilterofs = 8;
2967
#ifdef FILTER193 /* no adaptive filtering ? */
2968
if (pData->iFilter == MNG_FILTER_NOFILTER)
2969
pData->iPixelofs = pData->iFilterofs;
2972
pData->iPixelofs = pData->iFilterofs + 1;
2976
#ifdef MNG_SUPPORT_TRACE
2977
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IHDR, MNG_LC_END);
2983
/* ************************************************************************** */
2985
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
2986
mng_retcode mng_process_display_idat (mng_datap pData,
2988
mng_uint8p pRawdata)
2990
mng_retcode mng_process_display_idat (mng_datap pData)
2993
mng_retcode iRetcode = MNG_NOERROR;
2995
#ifdef MNG_SUPPORT_TRACE
2996
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IDAT, MNG_LC_START);
2999
if (pData->bRestorebkgd) /* need to restore the background ? */
3001
pData->bRestorebkgd = MNG_FALSE;
3002
iRetcode = load_bkgdlayer (pData);
3004
if (iRetcode) /* on error bail out */
3007
pData->iLayerseq++; /* and it counts as a layer then ! */
3010
if (pData->fInitrowproc) /* need to initialize row processing? */
3012
iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData);
3013
pData->fInitrowproc = MNG_NULL; /* only call this once !!! */
3016
if ((!iRetcode) && (!pData->bInflating))
3017
/* initialize inflate */
3018
iRetcode = mngzlib_inflateinit (pData);
3020
if (!iRetcode) /* all ok? then inflate, my man */
3021
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3022
iRetcode = mngzlib_inflaterows (pData, iRawlen, pRawdata);
3024
iRetcode = mngzlib_inflaterows (pData, pData->iRawlen, pData->pRawdata);
3027
if (iRetcode) /* on error bail out */
3030
#ifdef MNG_SUPPORT_TRACE
3031
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IDAT, MNG_LC_END);
3037
/* ************************************************************************** */
3039
mng_retcode mng_process_display_iend (mng_datap pData)
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);
3046
#ifdef MNG_SUPPORT_TRACE
3047
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IEND, MNG_LC_START);
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;
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;
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)))
3073
mng_imagep pImage = (mng_imagep)pData->pCurrentobj;
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);
3082
if (iRetcode) /* on error bail out */
3085
if (pData->bTimerset) /* timer break ? */
3086
pData->iBreakpoint = 6;
3089
#ifndef MNG_NO_DELTA_PNG
3091
if ((pData->bHasDHDR) || /* was it a DHDR stream */
3092
(pData->iBreakpoint == 8)) /* or did we get broken here last time ? */
3094
mng_imagep pImage = (mng_imagep)pData->pDeltaImage;
3096
if (!pData->iBreakpoint)
3097
{ /* perform the delta operations needed */
3098
iRetcode = mng_execute_delta_image (pData, pImage, (mng_imagep)pData->pObjzero);
3100
if (iRetcode) /* on error bail out */
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);
3108
if (iRetcode) /* on error bail out */
3111
if (pData->bTimerset) /* timer break ? */
3112
pData->iBreakpoint = 8;
3117
if (!pData->bTimerset) /* can we continue ? */
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);
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);
3130
if (iRetcode) /* on error bail out */
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);
3143
if (iRetcode) /* on error bail out */
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);
3155
if (iRetcode) /* on error bail out */
3162
if (bCleanup) /* if we got broken last time we need to cleanup */
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;
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;
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;
3189
#ifdef MNG_SUPPORT_TRACE
3190
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IEND, MNG_LC_END);
3196
/* ************************************************************************** */
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 */
3202
mng_retcode mng_process_display_mend (mng_datap pData)
3204
#ifdef MNG_SUPPORT_TRACE
3205
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_START);
3208
#ifdef MNG_SUPPORT_DYNAMICMNG
3209
if (pData->bStopafterseek) /* need to stop after this ? */
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 ! */
3218
#ifndef MNG_SKIPCHUNK_TERM
3219
/* TERM processed ? */
3220
if ((pData->bDisplaying) && (pData->bRunning) &&
3221
(pData->bHasTERM) && (pData->pTermaniobj))
3223
mng_retcode iRetcode;
3224
mng_ani_termp pTERM;
3225
/* get the right animation object ! */
3226
pTERM = (mng_ani_termp)pData->pTermaniobj;
3228
pData->iIterations++; /* increase iteration count */
3230
switch (pTERM->iTermaction) /* determine what to do! */
3232
case 0 : { /* show last frame indefinitly */
3233
break; /* piece of cake, that is... */
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;
3245
iRetcode = interframe_delay (pData);
3246
/* no interframe_delay? then fake it */
3247
if ((!iRetcode) && (!pData->bTimerset))
3248
iRetcode = set_delay (pData, 1);
3253
pData->iBreakpoint = 10;
3257
case 2 : { /* show first image after TERM */
3258
iRetcode = restore_state (pData);
3260
if (iRetcode) /* on error bail out */
3262
/* notify the app ? */
3263
if (pData->fProcessmend)
3264
if (!pData->fProcessmend ((mng_handle)pData, pData->iIterations, 0))
3265
MNG_ERROR (pData, MNG_APPMISCERROR);
3267
/* show first frame after TERM chunk */
3268
pData->pCurraniobj = pTERM;
3269
pData->bOnlyfirstframe = MNG_TRUE;
3270
pData->iFramesafterTERM = 0;
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;
3283
case 3 : { /* repeat */
3284
if ((pTERM->iItermax) && (pTERM->iItermax < 0x7FFFFFFF))
3287
if (pTERM->iItermax) /* go back to TERM ? */
3288
{ /* restore to initial or SAVE state */
3289
iRetcode = restore_state (pData);
3291
if (iRetcode) /* on error bail out */
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);
3299
/* restart from TERM chunk */
3300
pData->pCurraniobj = pTERM;
3302
if (pTERM->iDelay) /* set the delay (?) */
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;
3312
pData->bNeedrefresh = MNG_TRUE;
3317
switch (pTERM->iIteraction)
3319
case 0 : { /* show last frame indefinitly */
3320
break; /* piece of cake, that is... */
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;
3332
iRetcode = interframe_delay (pData);
3333
/* no interframe_delay? then fake it */
3334
if ((!iRetcode) && (!pData->bTimerset))
3335
iRetcode = set_delay (pData, 1);
3340
pData->iBreakpoint = 10;
3344
case 2 : { /* show first image after TERM */
3345
iRetcode = restore_state (pData);
3346
/* on error bail out */
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);
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;
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);
3383
if (!pData->pCurraniobj) /* always let the app refresh at the end ! */
3384
pData->bNeedrefresh = MNG_TRUE;
3386
#ifdef MNG_SUPPORT_TRACE
3387
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_END);
3393
/* ************************************************************************** */
3395
mng_retcode mng_process_display_mend2 (mng_datap pData)
3397
#ifdef MNG_SUPPORT_TRACE
3398
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_START);
3401
#ifndef MNG_SKIPCHUNK_FRAM
3402
pData->bFrameclipping = MNG_FALSE; /* nothing to do but restore the app background */
3404
load_bkgdlayer (pData);
3406
#ifdef MNG_SUPPORT_TRACE
3407
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MEND, MNG_LC_END);
3413
/* ************************************************************************** */
3415
#ifndef MNG_SKIPCHUNK_DEFI
3416
mng_retcode mng_process_display_defi (mng_datap pData)
3420
#ifdef MNG_SUPPORT_TRACE
3421
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DEFI, MNG_LC_START);
3424
if (!pData->iDEFIobjectid) /* object id=0 ? */
3426
pImage = (mng_imagep)pData->pObjzero;
3428
if (pData->bDEFIhasdonotshow)
3429
pImage->bVisible = (mng_bool)(pData->iDEFIdonotshow == 0);
3431
if (pData->bDEFIhasloca)
3433
pImage->iPosx = pData->iDEFIlocax;
3434
pImage->iPosy = pData->iDEFIlocay;
3437
if (pData->bDEFIhasclip)
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;
3446
pData->pCurrentobj = 0; /* not a real object ! */
3449
{ /* already exists ? */
3450
pImage = (mng_imagep)mng_find_imageobject (pData, pData->iDEFIobjectid);
3452
if (!pImage) /* if not; create new */
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,
3464
if (iRetcode) /* on error bail out */
3468
{ /* exists; then set new info */
3469
if (pData->bDEFIhasdonotshow)
3470
pImage->bVisible = (mng_bool)(pData->iDEFIdonotshow == 0);
3472
pImage->bViewable = MNG_FALSE;
3474
if (pData->bDEFIhasloca)
3476
pImage->iPosx = pData->iDEFIlocax;
3477
pImage->iPosy = pData->iDEFIlocay;
3480
if (pData->bDEFIhasclip)
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;
3489
if (pData->bDEFIhasconcrete)
3490
pImage->pImgbuf->bConcrete = (mng_bool)(pData->iDEFIconcrete == 1);
3493
pData->pCurrentobj = pImage; /* others may want to know this */
3496
#ifdef MNG_SUPPORT_TRACE
3497
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DEFI, MNG_LC_END);
3504
/* ************************************************************************** */
3506
#ifndef MNG_SKIPCHUNK_BASI
3507
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3508
mng_retcode mng_process_display_basi (mng_datap pData,
3514
mng_uint8 iViewable)
3516
mng_retcode mng_process_display_basi (mng_datap pData)
3518
{ /* address the current "object" if any */
3519
mng_imagep pImage = (mng_imagep)pData->pCurrentobj;
3522
mng_imagedatap pBuf;
3523
mng_retcode iRetcode;
3525
#ifdef MNG_SUPPORT_TRACE
3526
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_BASI, MNG_LC_START);
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;
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 */
3545
/* save the viewable flag */
3546
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3547
pImage->bViewable = (mng_bool)(iViewable == 1);
3549
pImage->bViewable = (mng_bool)(pData->iBASIviewable == 1);
3551
pBuf->bViewable = pImage->bViewable;
3552
pData->pStoreobj = pImage; /* let row-routines know which object */
3554
pWork = pBuf->pImgdata; /* fill the object-buffer with the specified
3556
switch (pData->iColortype) /* depending on color_type & bit_depth */
3558
case 0 : { /* gray */
3559
#ifndef MNG_NO_16BIT_SUPPORT
3560
if (pData->iBitdepth == 16)
3562
#ifdef MNG_DECREMENT_LOOPS
3563
for (iX = pData->iDatawidth * pData->iDataheight;
3566
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3569
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3570
mng_put_uint16 (pWork, iRed);
3572
mng_put_uint16 (pWork, pData->iBASIred);
3580
#ifdef MNG_DECREMENT_LOOPS
3581
for (iX = pData->iDatawidth * pData->iDataheight;
3584
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3587
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3588
*pWork = (mng_uint8)iRed;
3590
*pWork = (mng_uint8)pData->iBASIred;
3596
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3597
if ((bHasalpha) && (!iAlpha))
3599
if ((pData->bBASIhasalpha) && (!pData->iBASIalpha))
3602
pBuf->bHasTRNS = MNG_TRUE;
3603
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3604
pBuf->iTRNSgray = iRed;
3606
pBuf->iTRNSgray = pData->iBASIred;
3613
case 2 : { /* rgb */
3614
#ifndef MNG_NO_16BIT_SUPPORT
3615
if (pData->iBitdepth == 16)
3617
#ifdef MNG_DECREMENT_LOOPS
3618
for (iX = pData->iDatawidth * pData->iDataheight;
3621
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
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 );
3629
mng_put_uint16 (pWork, pData->iBASIred );
3630
mng_put_uint16 (pWork+2, pData->iBASIgreen);
3631
mng_put_uint16 (pWork+4, pData->iBASIblue );
3639
#ifdef MNG_DECREMENT_LOOPS
3640
for (iX = pData->iDatawidth * pData->iDataheight;
3643
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3646
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3647
*pWork = (mng_uint8)iRed;
3648
*(pWork+1) = (mng_uint8)iGreen;
3649
*(pWork+2) = (mng_uint8)iBlue;
3651
*pWork = (mng_uint8)pData->iBASIred;
3652
*(pWork+1) = (mng_uint8)pData->iBASIgreen;
3653
*(pWork+2) = (mng_uint8)pData->iBASIblue;
3659
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3660
if ((bHasalpha) && (!iAlpha))
3662
if ((pData->bBASIhasalpha) && (!pData->iBASIalpha))
3665
pBuf->bHasTRNS = MNG_TRUE;
3666
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3667
pBuf->iTRNSred = iRed;
3668
pBuf->iTRNSgreen = iGreen;
3669
pBuf->iTRNSblue = iBlue;
3671
pBuf->iTRNSred = pData->iBASIred;
3672
pBuf->iTRNSgreen = pData->iBASIgreen;
3673
pBuf->iTRNSblue = pData->iBASIblue;
3680
case 3 : { /* indexed */
3681
pBuf->bHasPLTE = MNG_TRUE;
3683
switch (pData->iBitdepth)
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; }
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;
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;
3702
for (iX = 1; iX < pBuf->iPLTEcount; iX++)
3704
pBuf->aPLTEentries [iX].iRed = 0;
3705
pBuf->aPLTEentries [iX].iGreen = 0;
3706
pBuf->aPLTEentries [iX].iBlue = 0;
3709
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3710
if ((bHasalpha) && (iAlpha < 255))
3712
if ((pData->bBASIhasalpha) && (pData->iBASIalpha < 255))
3715
pBuf->bHasTRNS = MNG_TRUE;
3716
pBuf->iTRNScount = 1;
3717
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3718
pBuf->aTRNSentries [0] = (mng_uint8)iAlpha;
3720
pBuf->aTRNSentries [0] = (mng_uint8)pData->iBASIalpha;
3727
case 4 : { /* gray+alpha */
3728
#ifndef MNG_NO_16BIT_SUPPORT
3729
if (pData->iBitdepth == 16)
3731
#ifdef MNG_DECREMENT_LOOPS
3732
for (iX = pData->iDatawidth * pData->iDataheight;
3735
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3738
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3739
mng_put_uint16 (pWork, iRed);
3740
mng_put_uint16 (pWork+2, iAlpha);
3742
mng_put_uint16 (pWork, pData->iBASIred);
3743
mng_put_uint16 (pWork+2, pData->iBASIalpha);
3751
#ifdef MNG_DECREMENT_LOOPS
3752
for (iX = pData->iDatawidth * pData->iDataheight;
3755
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
3758
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
3759
*pWork = (mng_uint8)iRed;
3760
*(pWork+1) = (mng_uint8)iAlpha;
3762
*pWork = (mng_uint8)pData->iBASIred;
3763
*(pWork+1) = (mng_uint8)pData->iBASIalpha;
3772
case 6 : { /* rgb+alpha */
3773
#ifndef MNG_NO_16BIT_SUPPORT
3774
if (pData->iBitdepth == 16)
3776
#ifdef MNG_DECREMENT_LOOPS
3777
for (iX = pData->iDatawidth * pData->iDataheight;
3780
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
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);
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);
3800
#ifdef MNG_DECREMENT_LOOPS
3801
for (iX = pData->iDatawidth * pData->iDataheight;
3804
for (iX = 0; iX < pData->iDatawidth * pData->iDataheight; iX++)
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;
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;
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);
3831
switch (pData->iColortype) /* determine row initialization routine */
3832
{ /* just to accomodate IDAT if it arrives */
3833
case 0 : { /* gray */
3834
switch (pData->iBitdepth)
3836
#ifndef MNG_NO_1_2_4BIT_SUPPORT
3838
if (!pData->iInterlace)
3839
pData->fInitrowproc = (mng_fptr)mng_init_g1_ni;
3841
pData->fInitrowproc = (mng_fptr)mng_init_g1_i;
3846
if (!pData->iInterlace)
3847
pData->fInitrowproc = (mng_fptr)mng_init_g2_ni;
3849
pData->fInitrowproc = (mng_fptr)mng_init_g2_i;
3854
if (!pData->iInterlace)
3855
pData->fInitrowproc = (mng_fptr)mng_init_g4_ni;
3857
pData->fInitrowproc = (mng_fptr)mng_init_g4_i;
3861
#endif /* MNG_NO_1_2_4BIT_SUPPORT */
3863
if (!pData->iInterlace)
3864
pData->fInitrowproc = (mng_fptr)mng_init_g8_ni;
3866
pData->fInitrowproc = (mng_fptr)mng_init_g8_i;
3870
#ifndef MNG_NO_16BIT_SUPPORT
3872
if (!pData->iInterlace)
3873
pData->fInitrowproc = (mng_fptr)mng_init_g16_ni;
3875
pData->fInitrowproc = (mng_fptr)mng_init_g16_i;
3884
case 2 : { /* rgb */
3885
switch (pData->iBitdepth)
3888
if (!pData->iInterlace)
3889
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni;
3891
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i;
3895
#ifndef MNG_NO_16BIT_SUPPORT
3897
if (!pData->iInterlace)
3898
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni;
3900
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i;
3909
case 3 : { /* indexed */
3910
switch (pData->iBitdepth)
3912
#ifndef MNG_NO_1_2_4BIT_SUPPORT
3914
if (!pData->iInterlace)
3915
pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni;
3917
pData->fInitrowproc = (mng_fptr)mng_init_idx1_i;
3922
if (!pData->iInterlace)
3923
pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni;
3925
pData->fInitrowproc = (mng_fptr)mng_init_idx2_i;
3930
if (!pData->iInterlace)
3931
pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni;
3933
pData->fInitrowproc = (mng_fptr)mng_init_idx4_i;
3937
#endif /* MNG_NO_1_2_4BIT_SUPPORT */
3939
if (!pData->iInterlace)
3940
pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni;
3942
pData->fInitrowproc = (mng_fptr)mng_init_idx8_i;
3950
case 4 : { /* gray+alpha */
3951
switch (pData->iBitdepth)
3954
if (!pData->iInterlace)
3955
pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni;
3957
pData->fInitrowproc = (mng_fptr)mng_init_ga8_i;
3961
#ifndef MNG_NO_16BIT_SUPPORT
3963
if (!pData->iInterlace)
3964
pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni;
3966
pData->fInitrowproc = (mng_fptr)mng_init_ga16_i;
3975
case 6 : { /* rgb+alpha */
3976
switch (pData->iBitdepth)
3979
if (!pData->iInterlace)
3980
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni;
3982
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i;
3986
#ifndef MNG_NO_16BIT_SUPPORT
3988
if (!pData->iInterlace)
3989
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni;
3991
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i;
4001
#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
4003
pData->iFilterofs = 0; /* determine filter characteristics */
4004
pData->iLevel0 = 0; /* default levels */
4010
if (pData->iFilter == 0xC0) /* leveling & differing ? */
4012
switch (pData->iColortype)
4015
#ifndef MNG_NO_16BIT_SUPPORT
4016
if (pData->iBitdepth <= 8)
4018
pData->iFilterofs = 1;
4019
#ifndef MNG_NO_16BIT_SUPPORT
4021
pData->iFilterofs = 2;
4027
#ifndef MNG_NO_16BIT_SUPPORT
4028
if (pData->iBitdepth <= 8)
4030
pData->iFilterofs = 3;
4031
#ifndef MNG_NO_16BIT_SUPPORT
4033
pData->iFilterofs = 6;
4039
pData->iFilterofs = 1;
4043
#ifndef MNG_NO_16BIT_SUPPORT
4044
if (pData->iBitdepth <= 8)
4046
pData->iFilterofs = 2;
4047
#ifndef MNG_NO_16BIT_SUPPORT
4049
pData->iFilterofs = 4;
4055
#ifndef MNG_NO_16BIT_SUPPORT
4056
if (pData->iBitdepth <= 8)
4058
pData->iFilterofs = 4;
4059
#ifndef MNG_NO_16BIT_SUPPORT
4061
pData->iFilterofs = 8;
4071
if (pData->iFilter == 0xC1) /* no adaptive filtering ? */
4072
pData->iPixelofs = pData->iFilterofs;
4075
pData->iPixelofs = pData->iFilterofs + 1;
4077
#ifdef MNG_SUPPORT_TRACE
4078
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_BASI, MNG_LC_END);
4085
/* ************************************************************************** */
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,
4097
mng_uint8 iLocationtype,
4098
mng_int32 iLocationx,
4099
mng_int32 iLocationy)
4101
mng_retcode mng_process_display_clon (mng_datap pData)
4104
mng_imagep pSource, pClone;
4105
mng_bool bVisible, bAbstract;
4106
mng_retcode iRetcode = MNG_NOERROR;
4108
#ifdef MNG_SUPPORT_TRACE
4109
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_START);
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);
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);
4123
if (!pSource) /* source must exist ! */
4124
MNG_ERROR (pData, MNG_OBJECTUNKNOWN);
4126
if (pClone) /* clone must not exist ! */
4127
MNG_ERROR (pData, MNG_OBJECTEXISTS);
4129
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4130
if (bHasdonotshow) /* DoNotShow flag filled ? */
4131
bVisible = (mng_bool)(iDonotshow == 0);
4133
bVisible = pSource->bVisible;
4135
if (pData->bCLONhasdonotshow) /* DoNotShow flag filled ? */
4136
bVisible = (mng_bool)(pData->iCLONdonotshow == 0);
4138
bVisible = pSource->bVisible;
4141
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4142
bAbstract = (mng_bool)(iConcrete == 1);
4144
bAbstract = (mng_bool)(pData->iCLONconcrete == 1);
4147
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4148
switch (iClonetype) /* determine action to take */
4150
case 0 : { /* full clone */
4151
iRetcode = mng_clone_imageobject (pData, iCloneid, MNG_FALSE,
4152
bVisible, bAbstract, bHasloca,
4153
iLocationtype, iLocationx, iLocationy,
4158
case 1 : { /* partial clone */
4159
iRetcode = mng_clone_imageobject (pData, iCloneid, MNG_TRUE,
4160
bVisible, bAbstract, bHasloca,
4161
iLocationtype, iLocationx, iLocationy,
4166
case 2 : { /* renumber object */
4167
iRetcode = mng_renum_imageobject (pData, pSource, iCloneid,
4168
bVisible, bAbstract, bHasloca,
4169
iLocationtype, iLocationx, iLocationy);
4176
switch (pData->iCLONclonetype) /* determine action to take */
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,
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,
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);
4208
if (iRetcode) /* on error bail out */
4211
/* display on the fly ? */
4212
if ((pClone->bViewable) && (pClone->bVisible))
4214
pData->pLastclone = pClone; /* remember in case of timer break ! */
4216
mng_display_image (pData, pClone, MNG_FALSE);
4218
if (pData->bTimerset) /* timer break ? */
4219
pData->iBreakpoint = 5;
4222
#ifdef MNG_SUPPORT_TRACE
4223
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_END);
4229
/* ************************************************************************** */
4231
mng_retcode mng_process_display_clon2 (mng_datap pData)
4233
#ifdef MNG_SUPPORT_TRACE
4234
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_START);
4236
/* only called after timer break ! */
4237
mng_display_image (pData, (mng_imagep)pData->pLastclone, MNG_FALSE);
4238
pData->iBreakpoint = 0;
4240
#ifdef MNG_SUPPORT_TRACE
4241
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLON, MNG_LC_END);
4248
/* ************************************************************************** */
4250
#ifndef MNG_SKIPCHUNK_DISC
4251
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4252
mng_retcode mng_process_display_disc (mng_datap pData,
4256
mng_retcode mng_process_display_disc (mng_datap pData)
4261
mng_uint32 iRetcode;
4262
#ifdef MNG_SUPPORT_TRACE
4263
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DISC, MNG_LC_START);
4266
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4267
if (iCount) /* specific list ? */
4269
if (pData->iDISCcount) /* specific list ? */
4272
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4273
mng_uint16p pWork = pIds;
4275
mng_uint16p pWork = pData->pDISCids;
4278
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4279
#ifdef MNG_DECREMENT_LOOPS /* iterate the list */
4280
for (iX = iCount; iX > 0; iX--)
4282
for (iX = 0; iX < iCount; iX++)
4285
#ifdef MNG_DECREMENT_LOOPS /* iterate the list */
4286
for (iX = pData->iDISCcount; iX > 0; iX--)
4288
for (iX = 0; iX < pData->iDISCcount; iX++)
4292
pImage = mng_find_imageobject (pData, *pWork++);
4294
if (pImage) /* found the object ? */
4295
{ /* then drop it */
4296
iRetcode = mng_free_imageobject (pData, pImage);
4298
if (iRetcode) /* on error bail out */
4303
else /* empty: drop all un-frozen objects */
4305
mng_imagep pNext = (mng_imagep)pData->pFirstimgobj;
4307
while (pNext) /* any left ? */
4310
pNext = pImage->sHeader.pNext;
4312
if (!pImage->bFrozen) /* not frozen ? */
4313
{ /* then drop it */
4314
iRetcode = mng_free_imageobject (pData, pImage);
4316
if (iRetcode) /* on error bail out */
4322
#ifdef MNG_SUPPORT_TRACE
4323
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DISC, MNG_LC_END);
4330
/* ************************************************************************** */
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,
4338
mng_uint8 iChangetimeout,
4339
mng_uint32 iTimeout,
4340
mng_uint8 iChangeclipping,
4341
mng_uint8 iCliptype,
4347
mng_retcode mng_process_display_fram (mng_datap pData)
4350
mng_retcode iRetcode;
4352
#ifdef MNG_SUPPORT_TRACE
4353
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_START);
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);
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);
4368
if (pData->bTimerset) /* timer break ? */
4369
pData->iBreakpoint = 1;
4371
#ifdef MNG_SUPPORT_TRACE
4372
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_END);
4378
/* ************************************************************************** */
4380
mng_retcode mng_process_display_fram2 (mng_datap pData)
4382
mng_retcode iRetcode;
4384
#ifdef MNG_SUPPORT_TRACE
4385
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_START);
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! */
4391
#ifdef MNG_SUPPORT_TRACE
4392
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_FRAM, MNG_LC_END);
4399
/* ************************************************************************** */
4401
#ifndef MNG_SKIPCHUNK_MOVE
4402
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4403
mng_retcode mng_process_display_move (mng_datap pData,
4406
mng_uint8 iMovetype,
4410
mng_retcode mng_process_display_move (mng_datap pData)
4416
#ifdef MNG_SUPPORT_TRACE
4417
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MOVE, MNG_LC_START);
4419
/* iterate the list */
4420
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4421
for (iX = iFromid; iX <= iToid; iX++)
4423
for (iX = pData->iMOVEfromid; iX <= pData->iMOVEtoid; iX++)
4426
if (!iX) /* object id=0 ? */
4427
pImage = (mng_imagep)pData->pObjzero;
4429
pImage = mng_find_imageobject (pData, iX);
4431
if (pImage) /* object exists ? */
4433
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4436
switch (pData->iMOVEmovetype)
4439
case 0 : { /* absolute */
4440
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4441
pImage->iPosx = iMovex;
4442
pImage->iPosy = iMovey;
4444
pImage->iPosx = pData->iMOVEmovex;
4445
pImage->iPosy = pData->iMOVEmovey;
4449
case 1 : { /* relative */
4450
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4451
pImage->iPosx = pImage->iPosx + iMovex;
4452
pImage->iPosy = pImage->iPosy + iMovey;
4454
pImage->iPosx = pImage->iPosx + pData->iMOVEmovex;
4455
pImage->iPosy = pImage->iPosy + pData->iMOVEmovey;
4463
#ifdef MNG_SUPPORT_TRACE
4464
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MOVE, MNG_LC_END);
4471
/* ************************************************************************** */
4473
#ifndef MNG_SKIPCHUNK_CLIP
4474
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4475
mng_retcode mng_process_display_clip (mng_datap pData,
4478
mng_uint8 iCliptype,
4484
mng_retcode mng_process_display_clip (mng_datap pData)
4490
#ifdef MNG_SUPPORT_TRACE
4491
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLIP, MNG_LC_START);
4493
/* iterate the list */
4494
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4495
for (iX = iFromid; iX <= iToid; iX++)
4497
for (iX = pData->iCLIPfromid; iX <= pData->iCLIPtoid; iX++)
4500
if (!iX) /* object id=0 ? */
4501
pImage = (mng_imagep)pData->pObjzero;
4503
pImage = mng_find_imageobject (pData, iX);
4505
if (pImage) /* object exists ? */
4507
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
4510
switch (pData->iCLIPcliptype)
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;
4521
pImage->iClipl = pData->iCLIPclipl;
4522
pImage->iClipr = pData->iCLIPclipr;
4523
pImage->iClipt = pData->iCLIPclipt;
4524
pImage->iClipb = pData->iCLIPclipb;
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;
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;
4547
#ifdef MNG_SUPPORT_TRACE
4548
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_CLIP, MNG_LC_END);
4555
/* ************************************************************************** */
4557
#ifndef MNG_SKIPCHUNK_SHOW
4558
mng_retcode mng_process_display_show (mng_datap pData)
4560
mng_int16 iX, iS, iFrom, iTo;
4563
#ifdef MNG_SUPPORT_TRACE
4564
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SHOW, MNG_LC_START);
4567
/* TODO: optimization for the cases where "abs (iTo - iFrom)" is rather high;
4568
especially where ((iFrom==1) && (iTo==65535)); eg. an empty SHOW !!! */
4570
if (pData->iBreakpoint == 3) /* previously broken during cycle-mode ? */
4572
pImage = mng_find_imageobject (pData, pData->iSHOWnextid);
4574
if (pImage) /* still there ? */
4575
mng_display_image (pData, pImage, MNG_FALSE);
4577
pData->iBreakpoint = 0; /* let's not go through this again! */
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;
4589
{ /* regular sequence ? */
4590
if (pData->iSHOWtoid >= pData->iSHOWfromid)
4592
else /* reverse sequence ! */
4595
iFrom = (mng_int16)pData->iSHOWfromid;
4596
iTo = (mng_int16)pData->iSHOWtoid;
4599
pData->iSHOWfromid = (mng_uint16)iFrom;
4600
pData->iSHOWtoid = (mng_uint16)iTo;
4601
pData->iSHOWskip = iS;
4604
if ((pData->iSHOWmode == 6) || (pData->iSHOWmode == 7))
4606
mng_uint16 iTrigger = 0;
4607
mng_uint16 iFound = 0;
4608
mng_uint16 iPass = 0;
4609
mng_imagep pFound = 0;
4613
iPass++; /* lets prevent endless loops when there
4614
are no potential candidates in the list! */
4616
if (iS > 0) /* forward ? */
4618
for (iX = iFrom; iX <= iTo; iX += iS)
4620
pImage = mng_find_imageobject (pData, (mng_uint16)iX);
4622
if (pImage) /* object exists ? */
4624
if (iFound) /* already found a candidate ? */
4625
pImage->bVisible = MNG_FALSE;
4627
if (iTrigger) /* found the trigger ? */
4629
pImage->bVisible = MNG_TRUE;
4634
if (pImage->bVisible) /* ok, this is the trigger */
4636
pImage->bVisible = MNG_FALSE;
4644
for (iX = iFrom; iX >= iTo; iX += iS)
4646
pImage = mng_find_imageobject (pData, (mng_uint16)iX);
4648
if (pImage) /* object exists ? */
4650
if (iFound) /* already found a candidate ? */
4651
pImage->bVisible = MNG_FALSE;
4653
if (iTrigger) /* found the trigger ? */
4655
pImage->bVisible = MNG_TRUE;
4660
if (pImage->bVisible) /* ok, this is the trigger */
4662
pImage->bVisible = MNG_FALSE;
4669
if (!iTrigger) /* did not find a trigger ? */
4670
iTrigger = 1; /* then fake it so the first image
4672
} /* cycle back to beginning ? */
4673
while ((iPass < 2) && (iTrigger) && (!iFound));
4675
pData->iBreakpoint = 0; /* just a sanity precaution */
4677
if ((pData->iSHOWmode == 6) && (pFound))
4679
mng_display_image (pData, pFound, MNG_FALSE);
4681
if (pData->bTimerset) /* timer set ? */
4683
pData->iBreakpoint = 3;
4684
pData->iSHOWnextid = iFound; /* save it for after the break */
4692
pImage = mng_find_imageobject (pData, iX);
4694
if (pImage) /* object exists ? */
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 ! */
4703
switch (pData->iSHOWmode) /* do what ? */
4706
pImage->bVisible = MNG_TRUE;
4707
mng_display_image (pData, pImage, MNG_FALSE);
4711
pImage->bVisible = MNG_FALSE;
4715
if (pImage->bVisible)
4716
mng_display_image (pData, pImage, MNG_FALSE);
4720
pImage->bVisible = MNG_TRUE;
4724
pImage->bVisible = (mng_bool)(!pImage->bVisible);
4725
if (pImage->bVisible)
4726
mng_display_image (pData, pImage, MNG_FALSE);
4730
pImage->bVisible = (mng_bool)(!pImage->bVisible);
4736
if (!pData->bTimerset) /* next ? */
4740
while ((!pData->bTimerset) && (((iS > 0) && (iX <= iTo)) ||
4741
((iS < 0) && (iX >= iTo)) ));
4743
if (pData->bTimerset) /* timer set ? */
4745
pData->iBreakpoint = 4;
4746
pData->iSHOWnextid = iX; /* save for next time */
4749
pData->iBreakpoint = 0;
4754
#ifdef MNG_SUPPORT_TRACE
4755
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SHOW, MNG_LC_END);
4762
/* ************************************************************************** */
4764
#ifndef MNG_SKIPCHUNK_SAVE
4765
mng_retcode mng_process_display_save (mng_datap pData)
4767
mng_retcode iRetcode;
4769
#ifdef MNG_SUPPORT_TRACE
4770
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SAVE, MNG_LC_START);
4773
iRetcode = save_state (pData); /* save the current state */
4775
if (iRetcode) /* on error bail out */
4778
#ifdef MNG_SUPPORT_TRACE
4779
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SAVE, MNG_LC_END);
4786
/* ************************************************************************** */
4788
#ifndef MNG_SKIPCHUNK_SEEK
4789
mng_retcode mng_process_display_seek (mng_datap pData)
4791
#ifdef MNG_SUPPORT_TRACE
4792
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SEEK, MNG_LC_START);
4795
#ifdef MNG_SUPPORT_DYNAMICMNG
4796
if (pData->bStopafterseek) /* need to stop after this SEEK ? */
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 ! */
4805
{ /* restore the initial or SAVE state */
4806
mng_retcode iRetcode = restore_state (pData);
4808
if (iRetcode) /* on error bail out */
4811
#ifdef MNG_SUPPORT_DYNAMICMNG
4812
/* stop after next SEEK ? */
4813
if ((pData->bDynamic) || (pData->bRunningevent))
4814
pData->bStopafterseek = MNG_TRUE;
4818
#ifdef MNG_SUPPORT_TRACE
4819
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_SEEK, MNG_LC_END);
4826
/* ************************************************************************** */
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;
4834
#ifdef MNG_SUPPORT_TRACE
4835
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JHDR, MNG_LC_START);
4838
if (!pData->bHasDHDR)
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;
4849
pData->pStoreobj = MNG_NULL; /* initialize important work-parms */
4851
pData->iJPEGrow = 0;
4852
pData->iJPEGalpharow = 0;
4853
pData->iJPEGrgbrow = 0;
4854
pData->iRowmax = 0; /* so init_rowproc does the right thing ! */
4857
if (!pData->iBreakpoint) /* not previously broken ? */
4859
#ifndef MNG_NO_DELTA_PNG
4860
if (pData->bHasDHDR) /* delta-image ? */
4862
if (pData->iDeltatype == MNG_DELTATYPE_REPLACE)
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);
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;
4876
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
4877
(pData->iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
4879
((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iJHDRimgbitdepth;
4880
((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
4883
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
4884
(pData->iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
4885
((mng_imagep)pData->pDeltaImage)->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
4887
if ((pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
4888
(pData->iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
4889
((mng_imagep)pData->pDeltaImage)->pImgbuf->iPixelsampledepth = pData->iJHDRimgbitdepth;
4893
#endif /* MNG_NO_DELTA_PNG */
4895
if (pImage) /* update object buffer ? */
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);
4903
pImage->pImgbuf->iAlphabitdepth = pData->iJHDRalphabitdepth;
4904
pImage->pImgbuf->iJHDRcompression = pData->iJHDRimgcompression;
4905
pImage->pImgbuf->iJHDRinterlace = pData->iJHDRimginterlace;
4906
pImage->pImgbuf->iAlphasampledepth = pData->iJHDRalphabitdepth;
4908
else /* update object 0 */
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);
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;
4923
if (iRetcode) /* on error bail out */
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) ) )
4939
next_layer (pData); /* that's a new layer then ! */
4941
pData->iBreakpoint = 0;
4943
if (pData->bTimerset) /* timer break ? */
4944
pData->iBreakpoint = 7;
4946
if (pData->bRunning) /* still running ? */
4947
{ /* anything to display ? */
4948
if ((pData->iDestr > pData->iDestl) && (pData->iDestb > pData->iDestt))
4950
set_display_routine (pData); /* then determine display routine */
4951
/* display from the object we store in */
4952
pData->pRetrieveobj = pData->pStoreobj;
4958
if (!pData->bTimerset) /* no timer break ? */
4959
{ /* default row initialization ! */
4960
#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
4961
pData->ePng_imgtype=png_none;
4963
pData->fInitrowproc = (mng_fptr)mng_init_rowproc;
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;
4972
switch (pData->iJHDRcolortype) /* determine pixel processing routines */
4974
case MNG_COLORTYPE_JPEGGRAY :
4976
pData->fStorerow2 = (mng_fptr)mng_store_jpeg_g8;
4977
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
4978
pData->bIsOpaque = MNG_TRUE;
4981
case MNG_COLORTYPE_JPEGCOLOR :
4983
pData->fStorerow2 = (mng_fptr)mng_store_jpeg_rgb8;
4984
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
4985
pData->bIsOpaque = MNG_TRUE;
4988
case MNG_COLORTYPE_JPEGGRAYA :
4990
pData->fStorerow2 = (mng_fptr)mng_store_jpeg_ga8;
4991
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
4992
pData->bIsOpaque = MNG_FALSE;
4995
case MNG_COLORTYPE_JPEGCOLORA :
4997
pData->fStorerow2 = (mng_fptr)mng_store_jpeg_rgba8;
4998
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
4999
pData->bIsOpaque = MNG_FALSE;
5004
#ifndef MNG_NO_16BIT_SUPPORT
5007
pData->bIsRGBA16 = MNG_TRUE; /* intermediate row is 16-bit deep */
5009
/* TODO: 12-bit JPEG */
5010
/* TODO: 8- + 12-bit JPEG (eg. type=20) */
5014
/* possible IDAT alpha-channel ? */
5015
if (pData->iJHDRalphacompression == MNG_COMPRESSION_DEFLATE)
5017
/* determine alpha processing routine */
5018
#ifdef MNG_OPTIMIZE_FOOTPRINT_INIT
5019
pData->fInitrowproc = (mng_fptr)mng_init_rowproc;
5021
switch (pData->iJHDRalphabitdepth)
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; }
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; }
5046
else /* possible JDAA alpha-channel ? */
5047
if (pData->iJHDRalphacompression == MNG_COMPRESSION_BASELINEJPEG)
5048
{ /* 8-bit JPEG ? */
5049
if (pData->iJHDRimgbitdepth == 8)
5051
if (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA)
5052
pData->fStorerow3 = (mng_fptr)mng_store_jpeg_g8_alpha;
5054
if (pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA)
5055
pData->fStorerow3 = (mng_fptr)mng_store_jpeg_rgb8_alpha;
5059
/* TODO: 12-bit JPEG with 8-bit JDAA */
5062
/* initialize JPEG library */
5063
iRetcode = mngjpeg_initialize (pData);
5065
if (iRetcode) /* on error bail out */
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;
5077
switch (pData->iJHDRalphabitdepth)
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; }
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; }
5099
#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
5103
pData->iFilterofs = 0; /* determine filter characteristics */
5104
pData->iLevel0 = 0; /* default levels */
5109
#ifdef FILTER192 /* leveling & differing ? */
5110
if (pData->iJHDRalphafilter == 0xC0)
5112
if (pData->iJHDRalphabitdepth <= 8)
5113
pData->iFilterofs = 1;
5115
pData->iFilterofs = 2;
5119
#ifdef FILTER193 /* no adaptive filtering ? */
5120
if (pData->iJHDRalphafilter == 0xC1)
5121
pData->iPixelofs = pData->iFilterofs;
5124
pData->iPixelofs = pData->iFilterofs + 1;
5128
#ifdef MNG_SUPPORT_TRACE
5129
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JHDR, MNG_LC_END);
5134
#endif /* MNG_INCLUDE_JNG */
5136
/* ************************************************************************** */
5138
#ifdef MNG_INCLUDE_JNG
5139
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5140
mng_retcode mng_process_display_jdaa (mng_datap pData,
5142
mng_uint8p pRawdata)
5144
mng_retcode mng_process_display_jdaa (mng_datap pData)
5147
mng_retcode iRetcode = MNG_NOERROR;
5149
#ifdef MNG_SUPPORT_TRACE
5150
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAA, MNG_LC_START);
5153
if (!pData->bJPEGdecompress2) /* if we're not decompressing already */
5155
if (pData->fInitrowproc) /* initialize row-processing? */
5157
iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData);
5158
pData->fInitrowproc = MNG_NULL; /* only call this once !!! */
5161
if (!iRetcode) /* initialize decompress */
5162
iRetcode = mngjpeg_decompressinit2 (pData);
5165
if (!iRetcode) /* all ok? then decompress, my man */
5166
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5167
iRetcode = mngjpeg_decompressdata2 (pData, iRawlen, pRawdata);
5169
iRetcode = mngjpeg_decompressdata2 (pData, pData->iRawlen, pData->pRawdata);
5175
#ifdef MNG_SUPPORT_TRACE
5176
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAA, MNG_LC_END);
5181
#endif /* MNG_INCLUDE_JNG */
5183
/* ************************************************************************** */
5185
#ifdef MNG_INCLUDE_JNG
5186
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5187
mng_retcode mng_process_display_jdat (mng_datap pData,
5189
mng_uint8p pRawdata)
5191
mng_retcode mng_process_display_jdat (mng_datap pData)
5194
mng_retcode iRetcode = MNG_NOERROR;
5196
#ifdef MNG_SUPPORT_TRACE
5197
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAT, MNG_LC_START);
5200
if (pData->bRestorebkgd) /* need to restore the background ? */
5202
pData->bRestorebkgd = MNG_FALSE;
5203
iRetcode = load_bkgdlayer (pData);
5205
pData->iLayerseq++; /* and it counts as a layer then ! */
5207
if (iRetcode) /* on error bail out */
5211
if (!pData->bJPEGdecompress) /* if we're not decompressing already */
5213
if (pData->fInitrowproc) /* initialize row-processing? */
5215
iRetcode = ((mng_initrowproc)pData->fInitrowproc) (pData);
5216
pData->fInitrowproc = MNG_NULL; /* only call this once !!! */
5219
if (!iRetcode) /* initialize decompress */
5220
iRetcode = mngjpeg_decompressinit (pData);
5223
if (!iRetcode) /* all ok? then decompress, my man */
5224
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5225
iRetcode = mngjpeg_decompressdata (pData, iRawlen, pRawdata);
5227
iRetcode = mngjpeg_decompressdata (pData, pData->iRawlen, pData->pRawdata);
5233
#ifdef MNG_SUPPORT_TRACE
5234
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_JDAT, MNG_LC_END);
5239
#endif /* MNG_INCLUDE_JNG */
5241
/* ************************************************************************** */
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,
5254
mng_retcode mng_process_display_dhdr (mng_datap pData)
5258
mng_retcode iRetcode;
5260
#ifdef MNG_SUPPORT_TRACE
5261
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DHDR, MNG_LC_START);
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;
5271
pData->fDeltagetrow = MNG_NULL;
5272
pData->fDeltaaddrow = MNG_NULL;
5273
pData->fDeltareplacerow = MNG_NULL;
5274
pData->fDeltaputrow = MNG_NULL;
5276
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5277
pImage = mng_find_imageobject (pData, iObjectid);
5279
pImage = mng_find_imageobject (pData, pData->iDHDRobjectid);
5282
if (pImage) /* object exists ? */
5284
if (pImage->pImgbuf->bConcrete) /* is it concrete ? */
5285
{ /* previous magnification to be done ? */
5286
if ((pImage->iMAGN_MethodX) || (pImage->iMAGN_MethodY))
5288
iRetcode = mng_magnify_imageobject (pData, pImage);
5290
if (iRetcode) /* on error bail out */
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;
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;
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;
5319
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5320
if ((iDeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
5321
(iDeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
5322
pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth;
5324
if ((iDeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
5325
(iDeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
5326
pData->iBitdepth = pImage->pImgbuf->iAlphasampledepth;
5328
if ((iDeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
5329
(iDeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
5330
pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth;
5332
if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKPIXELADD ) ||
5333
(pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKPIXELREPLACE) )
5334
pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth;
5336
if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKALPHAADD ) ||
5337
(pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKALPHAREPLACE) )
5338
pData->iBitdepth = pImage->pImgbuf->iAlphasampledepth;
5340
if ((pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKCOLORADD ) ||
5341
(pData->iDHDRdeltatype == MNG_DELTATYPE_BLOCKCOLORREPLACE) )
5342
pData->iBitdepth = pImage->pImgbuf->iPixelsampledepth;
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;
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)
5362
if (((iBlockx + iBlockwidth ) > pData->iDatawidth ) ||
5363
((iBlocky + iBlockheight) > pData->iDataheight) )
5364
MNG_ERROR (pData, MNG_INVALIDBLOCK);
5367
pData->iDatawidth = iBlockwidth;
5368
pData->iDataheight = iBlockheight;
5371
/* block size specified ? */
5372
if (pData->iDHDRdeltatype != MNG_DELTATYPE_NOCHANGE)
5373
{ /* block entirely within target ? */
5374
if (pData->iDHDRdeltatype != MNG_DELTATYPE_REPLACE)
5376
if (((pData->iDHDRblockx + pData->iDHDRblockwidth ) > pData->iDatawidth ) ||
5377
((pData->iDHDRblocky + pData->iDHDRblockheight) > pData->iDataheight) )
5378
MNG_ERROR (pData, MNG_INVALIDBLOCK);
5381
pData->iDatawidth = pData->iDHDRblockwidth;
5382
pData->iDataheight = pData->iDHDRblockheight;
5386
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5387
switch (iDeltatype) /* determine nr of delta-channels */
5389
switch (pData->iDHDRdeltatype) /* determine nr of delta-channels */
5392
case MNG_DELTATYPE_BLOCKALPHAADD : ;
5393
case MNG_DELTATYPE_BLOCKALPHAREPLACE :
5395
#ifdef MNG_INCLUDE_JNG
5396
if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) ||
5397
(pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) )
5399
pData->iColortype = MNG_COLORTYPE_GRAY;
5400
pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY;
5403
if ((pData->iColortype == MNG_COLORTYPE_RGBA ) ||
5404
(pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) )
5406
pData->iColortype = MNG_COLORTYPE_GRAY;
5407
pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY;
5410
if (pData->iColortype == MNG_COLORTYPE_GRAYA)
5411
pData->iColortype = MNG_COLORTYPE_GRAY;
5413
if (pData->iColortype == MNG_COLORTYPE_RGBA)
5414
pData->iColortype = MNG_COLORTYPE_GRAY;
5416
else /* target has no alpha; that sucks! */
5417
MNG_ERROR (pData, MNG_TARGETNOALPHA);
5422
case MNG_DELTATYPE_BLOCKCOLORADD : ;
5423
case MNG_DELTATYPE_BLOCKCOLORREPLACE :
5425
#ifdef MNG_INCLUDE_JNG
5426
if ((pData->iColortype == MNG_COLORTYPE_GRAYA ) ||
5427
(pData->iJHDRcolortype == MNG_COLORTYPE_JPEGGRAYA) )
5429
pData->iColortype = MNG_COLORTYPE_GRAY;
5430
pData->iJHDRcolortype = MNG_COLORTYPE_JPEGGRAY;
5433
if ((pData->iColortype == MNG_COLORTYPE_RGBA ) ||
5434
(pData->iJHDRcolortype == MNG_COLORTYPE_JPEGCOLORA) )
5436
pData->iColortype = MNG_COLORTYPE_RGB;
5437
pData->iJHDRcolortype = MNG_COLORTYPE_JPEGCOLOR;
5440
if (pData->iColortype == MNG_COLORTYPE_GRAYA)
5441
pData->iColortype = MNG_COLORTYPE_GRAY;
5443
if (pData->iColortype == MNG_COLORTYPE_RGBA)
5444
pData->iColortype = MNG_COLORTYPE_RGB;
5446
else /* target has no alpha; that sucks! */
5447
MNG_ERROR (pData, MNG_TARGETNOALPHA);
5453
/* full image replace ? */
5454
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5455
if (iDeltatype == MNG_DELTATYPE_REPLACE)
5457
if (pData->iDHDRdeltatype == MNG_DELTATYPE_REPLACE)
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);
5466
if (iRetcode) /* on error bail out */
5469
pData->pStoreobj = pImage; /* and store straight into this object */
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);
5483
if (iRetcode) /* on error bail out */
5486
pBuf = pImage->pImgbuf; /* copy possible palette & cheap transparency */
5487
pBufzero = ((mng_imagep)pData->pObjzero)->pImgbuf;
5489
pBufzero->bHasPLTE = pBuf->bHasPLTE;
5490
pBufzero->bHasTRNS = pBuf->bHasTRNS;
5492
if (pBufzero->bHasPLTE) /* copy palette ? */
5496
pBufzero->iPLTEcount = pBuf->iPLTEcount;
5498
for (iX = 0; iX < pBuf->iPLTEcount; iX++)
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;
5506
if (pBufzero->bHasTRNS) /* copy cheap transparency ? */
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;
5514
MNG_COPY (pBufzero->aTRNSentries, pBuf->aTRNSentries,
5515
sizeof (pBufzero->aTRNSentries));
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) );
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);
5529
switch (pData->iColortype) /* determine row initialization routine */
5531
case 0 : { /* gray */
5532
switch (pData->iBitdepth)
5534
#ifndef MNG_NO_1_2_4BIT_SUPPORT
5536
if (!pData->iInterlace)
5537
pData->fInitrowproc = (mng_fptr)mng_init_g1_ni;
5539
pData->fInitrowproc = (mng_fptr)mng_init_g1_i;
5544
if (!pData->iInterlace)
5545
pData->fInitrowproc = (mng_fptr)mng_init_g2_ni;
5547
pData->fInitrowproc = (mng_fptr)mng_init_g2_i;
5552
if (!pData->iInterlace)
5553
pData->fInitrowproc = (mng_fptr)mng_init_g4_ni;
5555
pData->fInitrowproc = (mng_fptr)mng_init_g4_i;
5559
#endif /* MNG_NO_1_2_4BIT_SUPPORT */
5561
if (!pData->iInterlace)
5562
pData->fInitrowproc = (mng_fptr)mng_init_g8_ni;
5564
pData->fInitrowproc = (mng_fptr)mng_init_g8_i;
5568
#ifndef MNG_NO_16BIT_SUPPORT
5570
if (!pData->iInterlace)
5571
pData->fInitrowproc = (mng_fptr)mng_init_g16_ni;
5573
pData->fInitrowproc = (mng_fptr)mng_init_g16_i;
5582
case 2 : { /* rgb */
5583
switch (pData->iBitdepth)
5586
if (!pData->iInterlace)
5587
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_ni;
5589
pData->fInitrowproc = (mng_fptr)mng_init_rgb8_i;
5593
#ifndef MNG_NO_16BIT_SUPPORT
5595
if (!pData->iInterlace)
5596
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_ni;
5598
pData->fInitrowproc = (mng_fptr)mng_init_rgb16_i;
5607
case 3 : { /* indexed */
5608
switch (pData->iBitdepth)
5610
#ifndef MNG_NO_1_2_4BIT_SUPPORT
5612
if (!pData->iInterlace)
5613
pData->fInitrowproc = (mng_fptr)mng_init_idx1_ni;
5615
pData->fInitrowproc = (mng_fptr)mng_init_idx1_i;
5620
if (!pData->iInterlace)
5621
pData->fInitrowproc = (mng_fptr)mng_init_idx2_ni;
5623
pData->fInitrowproc = (mng_fptr)mng_init_idx2_i;
5628
if (!pData->iInterlace)
5629
pData->fInitrowproc = (mng_fptr)mng_init_idx4_ni;
5631
pData->fInitrowproc = (mng_fptr)mng_init_idx4_i;
5635
#endif /* MNG_NO_1_2_4BIT_SUPPORT */
5637
if (!pData->iInterlace)
5638
pData->fInitrowproc = (mng_fptr)mng_init_idx8_ni;
5640
pData->fInitrowproc = (mng_fptr)mng_init_idx8_i;
5648
case 4 : { /* gray+alpha */
5649
switch (pData->iBitdepth)
5652
if (!pData->iInterlace)
5653
pData->fInitrowproc = (mng_fptr)mng_init_ga8_ni;
5655
pData->fInitrowproc = (mng_fptr)mng_init_ga8_i;
5659
#ifndef MNG_NO_16BIT_SUPPORT
5661
if (!pData->iInterlace)
5662
pData->fInitrowproc = (mng_fptr)mng_init_ga16_ni;
5664
pData->fInitrowproc = (mng_fptr)mng_init_ga16_i;
5673
case 6 : { /* rgb+alpha */
5674
switch (pData->iBitdepth)
5677
if (!pData->iInterlace)
5678
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_ni;
5680
pData->fInitrowproc = (mng_fptr)mng_init_rgba8_i;
5684
#ifndef MNG_NO_16BIT_SUPPORT
5686
if (!pData->iInterlace)
5687
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_ni;
5689
pData->fInitrowproc = (mng_fptr)mng_init_rgba16_i;
5699
#endif /* MNG_OPTIMIZE_FOOTPRINT_INIT */
5702
MNG_ERROR (pData, MNG_OBJNOTCONCRETE);
5706
MNG_ERROR (pData, MNG_OBJECTUNKNOWN);
5708
#ifdef MNG_SUPPORT_TRACE
5709
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_DHDR, MNG_LC_END);
5716
/* ************************************************************************** */
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)
5725
mng_retcode mng_process_display_prom (mng_datap pData)
5729
mng_imagedatap pBuf;
5730
mng_retcode iRetcode;
5732
#ifdef MNG_SUPPORT_TRACE
5733
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PROM, MNG_LC_START);
5736
if (!pData->pDeltaImage) /* gotta have this now! */
5737
MNG_ERROR (pData, MNG_INVALIDDELTA);
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);
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) ) ||
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);
5780
iRetcode = mng_promote_imageobject (pData, pImage, iBitdepth, iColortype, iFilltype);
5782
if (pData->iPROMbitdepth < pBuf->iBitdepth)
5783
MNG_ERROR (pData, MNG_INVALIDBITDEPTH);
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) ) ||
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);
5819
iRetcode = mng_promote_imageobject (pData, pImage, pData->iPROMbitdepth,
5820
pData->iPROMcolortype, pData->iPROMfilltype);
5823
if (iRetcode) /* on error bail out */
5826
#ifdef MNG_SUPPORT_TRACE
5827
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PROM, MNG_LC_END);
5834
/* ************************************************************************** */
5836
#ifndef MNG_NO_DELTA_PNG
5837
mng_retcode mng_process_display_ipng (mng_datap pData)
5839
#ifdef MNG_SUPPORT_TRACE
5840
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IPNG, MNG_LC_START);
5842
/* indicate it for what it is now */
5843
pData->iDeltaImagetype = MNG_IMAGETYPE_PNG;
5845
#ifdef MNG_SUPPORT_TRACE
5846
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IPNG, MNG_LC_END);
5853
/* ************************************************************************** */
5855
#ifndef MNG_NO_DELTA_PNG
5856
#ifdef MNG_INCLUDE_JNG
5857
mng_retcode mng_process_display_ijng (mng_datap pData)
5859
#ifdef MNG_SUPPORT_TRACE
5860
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IJNG, MNG_LC_START);
5862
/* indicate it for what it is now */
5863
pData->iDeltaImagetype = MNG_IMAGETYPE_JNG;
5865
#ifdef MNG_SUPPORT_TRACE
5866
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_IJNG, MNG_LC_END);
5874
/* ************************************************************************** */
5876
#ifndef MNG_NO_DELTA_PNG
5877
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5878
mng_retcode mng_process_display_pplt (mng_datap pData,
5881
mng_palette8ep paIndexentries,
5882
mng_uint8p paAlphaentries,
5883
mng_uint8p paUsedentries)
5885
mng_retcode mng_process_display_pplt (mng_datap pData)
5889
mng_imagep pImage = (mng_imagep)pData->pObjzero;
5890
mng_imagedatap pBuf = pImage->pImgbuf;
5892
#ifdef MNG_SUPPORT_TRACE
5893
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PPLT, MNG_LC_START);
5896
#ifdef MNG_DECREMENT_LOOPS
5897
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5900
iX = pData->iPPLTcount;
5904
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5907
switch (pData->iPPLTtype)
5910
case MNG_DELTATYPE_REPLACERGB :
5912
#ifdef MNG_DECREMENT_LOOPS
5915
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5916
for (iX = 0; iX < iCount; iX++)
5918
for (iX = 0; iX < pData->iPPLTcount; iX++)
5922
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5923
if (paUsedentries [iX])
5925
pBuf->aPLTEentries [iX].iRed = paIndexentries [iX].iRed;
5926
pBuf->aPLTEentries [iX].iGreen = paIndexentries [iX].iGreen;
5927
pBuf->aPLTEentries [iX].iBlue = paIndexentries [iX].iBlue;
5930
if (pData->paPPLTusedentries [iX])
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;
5941
case MNG_DELTATYPE_DELTARGB :
5943
#ifdef MNG_DECREMENT_LOOPS
5946
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5947
for (iX = 0; iX < iCount; iX++)
5949
for (iX = 0; iX < pData->iPPLTcount; iX++)
5953
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5954
if (paUsedentries [iX])
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 );
5967
if (pData->paPPLTusedentries [iX])
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 );
5984
case MNG_DELTATYPE_REPLACEALPHA :
5986
#ifdef MNG_DECREMENT_LOOPS
5989
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5990
for (iX = 0; iX < iCount; iX++)
5992
for (iX = 0; iX < pData->iPPLTcount; iX++)
5996
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
5997
if (paUsedentries [iX])
5998
pBuf->aTRNSentries [iX] = paAlphaentries [iX];
6001
if (pData->paPPLTusedentries [iX])
6002
pBuf->aTRNSentries [iX] = pData->paPPLTalphaentries [iX];
6008
case MNG_DELTATYPE_DELTAALPHA :
6010
#ifdef MNG_DECREMENT_LOOPS
6013
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6014
for (iX = 0; iX < iCount; iX++)
6016
for (iX = 0; iX < pData->iPPLTcount; iX++)
6020
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6021
if (paUsedentries [iX])
6022
pBuf->aTRNSentries [iX] =
6023
(mng_uint8)(pBuf->aTRNSentries [iX] +
6024
paAlphaentries [iX]);
6026
if (pData->paPPLTusedentries [iX])
6027
pBuf->aTRNSentries [iX] =
6028
(mng_uint8)(pBuf->aTRNSentries [iX] +
6029
pData->paPPLTalphaentries [iX]);
6035
case MNG_DELTATYPE_REPLACERGBA :
6037
#ifdef MNG_DECREMENT_LOOPS
6040
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6041
for (iX = 0; iX < iCount; iX++)
6043
for (iX = 0; iX < pData->iPPLTcount; iX++)
6047
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6048
if (paUsedentries [iX])
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];
6056
if (pData->paPPLTusedentries [iX])
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];
6068
case MNG_DELTATYPE_DELTARGBA :
6070
#ifdef MNG_DECREMENT_LOOPS
6073
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6074
for (iX = 0; iX < iCount; iX++)
6076
for (iX = 0; iX < pData->iPPLTcount; iX++)
6080
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6081
if (paUsedentries [iX])
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]);
6097
if (pData->paPPLTusedentries [iX])
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]);
6119
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6120
if ((iType != MNG_DELTATYPE_REPLACERGB) && (iType != MNG_DELTATYPE_DELTARGB))
6122
if ((pData->iPPLTtype != MNG_DELTATYPE_REPLACERGB) &&
6123
(pData->iPPLTtype != MNG_DELTATYPE_DELTARGB ) )
6128
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6129
if (iCount > pBuf->iTRNScount)
6130
pBuf->iTRNScount = iCount;
6132
if (pData->iPPLTcount > pBuf->iTRNScount)
6133
pBuf->iTRNScount = pData->iPPLTcount;
6138
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6139
pBuf->iTRNScount = iCount;
6140
pBuf->bHasTRNS = MNG_TRUE;
6142
pBuf->iTRNScount = pData->iPPLTcount;
6143
pBuf->bHasTRNS = MNG_TRUE;
6148
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6149
if ((iType != MNG_DELTATYPE_REPLACEALPHA) && (iType != MNG_DELTATYPE_DELTAALPHA))
6151
if ((pData->iPPLTtype != MNG_DELTATYPE_REPLACEALPHA) &&
6152
(pData->iPPLTtype != MNG_DELTATYPE_DELTAALPHA ) )
6155
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6156
if (iCount > pBuf->iPLTEcount)
6157
pBuf->iPLTEcount = iCount;
6159
if (pData->iPPLTcount > pBuf->iPLTEcount)
6160
pBuf->iPLTEcount = pData->iPPLTcount;
6164
#ifdef MNG_SUPPORT_TRACE
6165
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PPLT, MNG_LC_END);
6172
/* ************************************************************************** */
6174
#ifndef MNG_SKIPCHUNK_MAGN
6175
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6176
mng_retcode mng_process_display_magn (mng_datap pData,
6177
mng_uint16 iFirstid,
6188
mng_retcode mng_process_display_magn (mng_datap pData)
6194
#ifdef MNG_SUPPORT_TRACE
6195
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_START);
6197
/* iterate the object-ids */
6198
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6199
for (iX = iFirstid; iX <= iLastid; iX++)
6201
for (iX = pData->iMAGNfirstid; iX <= pData->iMAGNlastid; iX++)
6204
if (iX == 0) /* process object 0 ? */
6206
pImage = (mng_imagep)pData->pObjzero;
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;
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;
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))
6236
mng_retcode iRetcode = mng_magnify_imageobject (pData, pImage);
6237
if (iRetcode) /* on error bail out */
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;
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;
6264
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6265
pData->iMAGNfromid = iFirstid;
6266
pData->iMAGNtoid = iLastid;
6269
pData->iMAGNfromid = pData->iMAGNfirstid;
6270
pData->iMAGNtoid = pData->iMAGNlastid;
6271
iX = pData->iMAGNfirstid;
6273
/* iterate again for showing */
6274
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6275
while ((iX <= iLastid) && (!pData->bTimerset))
6277
while ((iX <= pData->iMAGNlastid) && (!pData->bTimerset))
6280
pData->iMAGNcurrentid = iX;
6282
if (iX) /* only real objects ! */
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))
6290
mng_retcode iRetcode = mng_display_image (pData, pImage, MNG_FALSE);
6299
if (pData->bTimerset) /* broken ? */
6300
pData->iBreakpoint = 9;
6302
#ifdef MNG_SUPPORT_TRACE
6303
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_END);
6309
/* ************************************************************************** */
6311
mng_retcode mng_process_display_magn2 (mng_datap pData)
6316
#ifdef MNG_SUPPORT_TRACE
6317
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_START);
6320
iX = pData->iMAGNcurrentid;
6321
/* iterate again for showing */
6322
while ((iX <= pData->iMAGNtoid) && (!pData->bTimerset))
6324
pData->iMAGNcurrentid = iX;
6326
if (iX) /* only real objects ! */
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))
6334
mng_retcode iRetcode = mng_display_image (pData, pImage, MNG_FALSE);
6343
if (pData->bTimerset) /* broken ? */
6344
pData->iBreakpoint = 9;
6346
pData->iBreakpoint = 0; /* not again ! */
6348
#ifdef MNG_SUPPORT_TRACE
6349
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_MAGN, MNG_LC_END);
6356
/* ************************************************************************** */
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,
6368
mng_retcode mng_process_display_past (mng_datap pData)
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;
6377
mng_past_sourcep pSource = (mng_past_sourcep)pData->pPASTsources;
6381
#ifdef MNG_SUPPORT_TRACE
6382
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_START);
6385
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6386
if (iTargetid) /* a real destination object ? */
6388
if (pData->iPASTtargetid) /* a real destination object ? */
6390
{ /* let's find it then */
6391
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6392
pTargetimg = (mng_imagep)mng_find_imageobject (pData, iTargetid);
6394
pTargetimg = (mng_imagep)mng_find_imageobject (pData, pData->iPASTtargetid);
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,
6410
MNG_FILLMETHOD_LEFTBITREPLICATE);
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,
6418
MNG_FILLMETHOD_LEFTBITREPLICATE);
6419
#ifdef MNG_INCLUDE_JNG
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);
6430
if (iRetcode) /* on error bail out */
6432
/* make it really abstract ? */
6433
if (!pTargetimg->pImgbuf->bCorrected)
6435
iRetcode = mng_colorcorrect_object (pData, pTargetimg);
6437
if (iRetcode) /* on error bail out */
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))
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);
6456
if (iRetcode) /* on error bail out */
6460
pTargetimg = MNG_NULL; /* clipped beyond visibility ! */
6463
if (pTargetimg) /* usable destination ? */
6466
mng_int32 iSourceYinc;
6467
mng_int32 iSourcerowsize;
6468
mng_int32 iSourcesamples;
6469
mng_bool bSourceRGBA16;
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);
6480
if (!iRetcode) /* still ok ? */
6482
bTargetRGBA16 = (mng_bool)(pTargetimg->pImgbuf->iBitdepth > 8);
6484
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6485
switch (iTargettype) /* determine target x/y */
6487
switch (pData->iPASTtargettype) /* determine target x/y */
6491
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6492
pData->iPastx = iTargetx;
6493
pData->iPasty = iTargety;
6495
pData->iPastx = pData->iPASTtargetx;
6496
pData->iPasty = pData->iPASTtargety;
6502
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6503
pData->iPastx = pTargetimg->iPastx + iTargetx;
6504
pData->iPasty = pTargetimg->iPasty + iTargety;
6506
pData->iPastx = pTargetimg->iPastx + pData->iPASTtargetx;
6507
pData->iPasty = pTargetimg->iPasty + pData->iPASTtargety;
6513
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6514
pData->iPastx += iTargetx;
6515
pData->iPasty += iTargety;
6517
pData->iPastx += pData->iPASTtargetx;
6518
pData->iPasty += pData->iPASTtargety;
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;
6530
/* process the sources one by one */
6531
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6532
while ((!iRetcode) && (iX < iCount))
6534
while ((!iRetcode) && (iX < pData->iPASTcount))
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);
6544
if (!iRetcode) /* still ok ? */
6546
pBuf = (mng_imagedatap)pSourceimg->pImgbuf;
6547
/* address source for row-routines */
6548
pData->pRetrieveobj = (mng_objectp)pSourceimg;
6550
pData->iPass = -1; /* init row-processing variables */
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;
6560
switch (pBuf->iColortype)
6563
#ifndef MNG_NO_16BIT_SUPPORT
6565
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
6568
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
6570
pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS);
6575
#ifndef MNG_NO_16BIT_SUPPORT
6577
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
6580
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
6582
pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS);
6587
case 3 : { pData->fRetrieverow = (mng_fptr)mng_retrieve_idx8;
6588
pData->bIsOpaque = (mng_bool)(!pBuf->bHasTRNS);
6594
#ifndef MNG_NO_16BIT_SUPPORT
6596
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
6599
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
6601
pData->bIsOpaque = MNG_FALSE;
6607
#ifndef MNG_NO_16BIT_SUPPORT
6609
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
6612
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
6614
pData->bIsOpaque = MNG_FALSE;
6619
#ifndef MNG_NO_16BIT_SUPPORT
6621
pData->fRetrieverow = (mng_fptr)mng_retrieve_g16;
6624
pData->fRetrieverow = (mng_fptr)mng_retrieve_g8;
6626
pData->bIsOpaque = MNG_TRUE;
6631
#ifndef MNG_NO_16BIT_SUPPORT
6633
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb16;
6636
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgb8;
6638
pData->bIsOpaque = MNG_TRUE;
6644
#ifndef MNG_NO_16BIT_SUPPORT
6646
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga16;
6649
pData->fRetrieverow = (mng_fptr)mng_retrieve_ga8;
6651
pData->bIsOpaque = MNG_FALSE;
6657
#ifndef MNG_NO_16BIT_SUPPORT
6659
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba16;
6662
pData->fRetrieverow = (mng_fptr)mng_retrieve_rgba8;
6664
pData->bIsOpaque = MNG_FALSE;
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;
6674
if ((bSourceRGBA16) && (!bTargetRGBA16))
6675
pData->fScalerow = (mng_fptr)mng_scale_rgba16_rgba8;
6679
pData->fScalerow = MNG_NULL;
6681
/* default no color-correction */
6682
pData->fCorrectrow = MNG_NULL;
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);
6693
if (!iRetcode) /* still ok ? */
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)
6702
#ifndef MNG_NO_16BIT_SUPPORT
6704
pData->fFliprow = (mng_fptr)mng_flip_rgba16;
6707
pData->fFliprow = (mng_fptr)mng_flip_rgba8;
6712
#ifndef MNG_NO_16BIT_SUPPORT
6714
pData->fTilerow = (mng_fptr)mng_tile_rgba16;
6717
pData->fTilerow = (mng_fptr)mng_tile_rgba8;
6721
/* determine composition routine */
6722
/* note that we're abusing the delta-routine setup !!! */
6723
switch (pSource->iComposition)
6725
case 0 : { /* composite over */
6726
#ifndef MNG_NO_16BIT_SUPPORT
6728
pData->fDeltarow = (mng_fptr)mng_composeover_rgba16;
6731
pData->fDeltarow = (mng_fptr)mng_composeover_rgba8;
6735
case 1 : { /* replace */
6736
#ifndef MNG_NO_16BIT_SUPPORT
6738
pData->fDeltarow = (mng_fptr)mng_delta_rgba16_rgba16;
6741
pData->fDeltarow = (mng_fptr)mng_delta_rgba8_rgba8;
6745
case 2 : { /* composite under */
6746
#ifndef MNG_NO_16BIT_SUPPORT
6748
pData->fDeltarow = (mng_fptr)mng_composeunder_rgba16;
6751
pData->fDeltarow = (mng_fptr)mng_composeunder_rgba8;
6755
/* determine offsets & clipping */
6756
if (pSource->iOffsettype == 1)
6758
pData->iDestl = pData->iPastx + pSource->iOffsetx;
6759
pData->iDestt = pData->iPasty + pSource->iOffsety;
6763
pData->iDestl = pSource->iOffsetx;
6764
pData->iDestt = pSource->iOffsety;
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)
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);
6775
/* source clipping */
6776
if (pSource->iBoundarytype == 1)
6778
if (pData->iDestl < pData->iPastx + pSource->iBoundaryl)
6779
pData->iSourcel = pData->iPastx + pSource->iBoundaryl - pData->iDestl;
6781
pData->iSourcel = 0;
6783
if (pData->iDestt < pData->iPasty + pSource->iBoundaryt)
6784
pData->iSourcet = pData->iPasty + pSource->iBoundaryt - pData->iDestt;
6786
pData->iSourcet = 0;
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);
6795
if (pData->iDestl < pSource->iBoundaryl)
6796
pData->iSourcel = pSource->iBoundaryl - pData->iDestl;
6798
pData->iSourcel = 0;
6800
if (pData->iDestt < pSource->iBoundaryt)
6801
pData->iSourcet = pSource->iBoundaryt - pData->iDestt;
6803
pData->iSourcet = 0;
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);
6811
if (pData->iSourcel) /* indent source ? */
6813
#ifndef MNG_NO_16BIT_SUPPORT
6814
if (bTargetRGBA16) /* abuse tiling routine to shift source-pixels */
6815
pData->fTilerow = (mng_fptr)mng_tile_rgba16;
6818
pData->fTilerow = (mng_fptr)mng_tile_rgba8;
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))
6825
iSourceY = (mng_int32)pBuf->iHeight - 1 - pData->iSourcet;
6830
iSourceY = pData->iSourcet;
6834
iTargetY = pData->iDestt;
6835
pData->iCol = pData->iDestl;
6837
iTargetsamples = pData->iDestr - pData->iDestl;
6839
#ifndef MNG_NO_16BIT_SUPPORT
6841
iTargetrowsize = (iTargetsamples << 3);
6844
iTargetrowsize = (iTargetsamples << 2);
6846
/* get temporary work-buffers */
6847
if (iSourcerowsize > iTargetrowsize)
6848
iTemprowsize = iSourcerowsize << 1;
6850
iTemprowsize = iTargetrowsize << 1;
6851
MNG_ALLOC (pData, pData->pRGBArow, iTemprowsize);
6852
MNG_ALLOC (pData, pData->pWorkrow, iTemprowsize);
6854
while ((!iRetcode) && (iTargetY < pData->iDestb))
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);
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);
6876
if (!iRetcode) /* and paste..... */
6878
pData->iRow = iTargetY;
6879
pData->iRowsamples = iTargetsamples;
6880
pData->iRowsize = iTargetrowsize;
6881
iRetcode = ((mng_deltarow)pData->fDeltarow) (pData);
6884
iSourceY += iSourceYinc; /* and next line */
6887
iSourceY = (mng_int32)pBuf->iHeight - 1;
6889
if (iSourceY >= (mng_int32)pBuf->iHeight)
6894
/* drop the temporary row-buffer */
6895
MNG_FREEX (pData, pData->pWorkrow, iTemprowsize);
6896
MNG_FREEX (pData, pData->pRGBArow, iTemprowsize);
6899
#if defined(MNG_FULL_CMS) /* cleanup cms stuff */
6901
iRetcode = mng_clear_cms (pData);
6905
pSource++; /* neeeeext */
6910
if (iRetcode) /* on error bail out */
6913
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6914
if (!iTargetid) /* did we paste into object 0 ? */
6916
if (!pData->iPASTtargetid) /* did we paste into object 0 ? */
6918
{ /* display it then ! */
6919
iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE);
6920
if (iRetcode) /* on error bail out */
6924
{ /* target is visible & viewable ? */
6925
if ((pTargetimg->bVisible) && (pTargetimg->bViewable))
6927
iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE);
6934
if (pData->bTimerset) /* broken ? */
6936
#ifndef MNG_OPTIMIZE_DISPLAYCALLS
6937
pData->iPASTid = iTargetid;
6939
pData->iPASTid = pData->iPASTtargetid;
6941
pData->iBreakpoint = 11;
6944
#ifdef MNG_SUPPORT_TRACE
6945
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_END);
6950
#endif /* MNG_SKIPCHUNK_PAST */
6952
/* ************************************************************************** */
6954
#ifndef MNG_SKIPCHUNK_PAST
6955
mng_retcode mng_process_display_past2 (mng_datap pData)
6957
mng_retcode iRetcode;
6958
mng_imagep pTargetimg;
6960
#ifdef MNG_SUPPORT_TRACE
6961
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_START);
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;
6969
iRetcode = mng_display_image (pData, pTargetimg, MNG_FALSE);
6973
pData->iBreakpoint = 0; /* only once */
6975
#ifdef MNG_SUPPORT_TRACE
6976
MNG_TRACE (pData, MNG_FN_PROCESS_DISPLAY_PAST, MNG_LC_END);
6981
#endif /* MNG_SKIPCHUNK_PAST */
6983
/* ************************************************************************** */
6985
#endif /* MNG_INCLUDE_DISPLAY_PROCS */
6987
/* ************************************************************************** */
6988
/* * end of file * */
6989
/* ************************************************************************** */