225
225
/* * 1.0.9 - 01/17/2005 - G.Juyn * */
226
226
/* * - fixed problem with global PLTE/tRNS * */
228
/* * 1.0.10 - 02/07/2005 - G.Juyn * */
229
/* * - fixed display routines called twice for FULL_MNG * */
230
/* * support in mozlibmngconf.h * */
231
/* * 1.0.10 - 12/04/2005 - G.R-P. * */
232
/* * - #ifdef out use of mng_inflate_buffer when it is not * */
234
/* * 1.0.10 - 04/08/2007 - G.Juyn * */
235
/* * - added support for mPNG proposal * */
236
/* * 1.0.10 - 04/12/2007 - G.Juyn * */
237
/* * - added support for ANG proposal * */
238
/* * 1.0.10 - 05/02/2007 - G.Juyn * */
239
/* * - fixed inflate_buffer for extreme compression ratios * */
228
241
/* ************************************************************************** */
230
243
#include "libmng.h"
4870
4906
iChangeclipping, iCliptype,
4871
4907
iClipl, iClipr, iClipt, iClipb);
4873
if (!iRetcode) /* now go and do something */
4874
4910
iRetcode = mng_process_display_fram (pData, iFramemode, iChangedelay, iDelay,
4875
4911
iChangetimeout, iTimeout,
4876
4912
iChangeclipping, iCliptype,
4877
iClipl, iClipr, iClipt, iClipb);
4913
iClipl, iClipr, iClipt, iClipb); */
4879
4915
if (iRetcode) /* on error bail out */
4880
4916
return iRetcode;
6486
6529
iRetcode = mng_create_ani_dhdr (pData, iObjectid, iImagetype, iDeltatype,
6487
6530
iBlockwidth, iBlockheight, iBlockx, iBlocky);
6489
if (!iRetcode) /* display processing ? */
6490
6533
iRetcode = mng_process_display_dhdr (pData, iObjectid, iImagetype, iDeltatype,
6491
iBlockwidth, iBlockheight, iBlockx, iBlocky);
6534
iBlockwidth, iBlockheight, iBlockx, iBlocky); */
6493
6536
if (iRetcode) /* on error bail out */
6494
6537
return iRetcode;
7252
7296
iRetcode = mng_create_ani_magn (pData, iFirstid, iLastid, iMethodX,
7253
7297
iMX, iMY, iML, iMR, iMT, iMB, iMethodY);
7255
if (!iRetcode) /* display processing ? */
7256
7300
iRetcode = mng_process_display_magn (pData, iFirstid, iLastid, iMethodX,
7257
iMX, iMY, iML, iMR, iMT, iMB, iMethodY);
7301
iMX, iMY, iML, iMR, iMT, iMB, iMethodY); */
7259
7303
if (iRetcode) /* on error bail out */
7260
7304
return iRetcode;
7295
7339
/* ************************************************************************** */
7297
7341
#ifndef MNG_OPTIMIZE_CHUNKREADER
7342
#ifdef MNG_INCLUDE_MPNG_PROPOSAL
7343
READ_CHUNK (mng_read_mpng)
7345
mng_uint32 iFramewidth;
7346
mng_uint32 iFrameheight;
7347
mng_uint16 iTickspersec;
7348
mng_uint32 iFramessize;
7349
mng_uint32 iCompressedsize;
7350
#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS)
7351
mng_retcode iRetcode;
7352
mng_uint16 iNumplays;
7353
mng_uint32 iBufsize;
7354
mng_uint8p pBuf = 0;
7357
#ifdef MNG_SUPPORT_TRACE
7358
MNG_TRACE (pData, MNG_FN_READ_MPNG, MNG_LC_START);
7360
/* sequence checks */
7361
if (!pData->bHasIHDR)
7362
MNG_ERROR (pData, MNG_SEQUENCEERROR);
7364
if (iRawlen < 41) /* length must be at least 41 */
7365
MNG_ERROR (pData, MNG_INVALIDLENGTH);
7367
iFramewidth = mng_get_int32 (pRawdata);
7368
if (iFramewidth == 0) /* frame_width must not be zero */
7369
MNG_ERROR (pData, MNG_INVALIDWIDTH);
7371
iFrameheight = mng_get_int32 (pRawdata+4);
7372
if (iFrameheight == 0) /* frame_height must not be zero */
7373
MNG_ERROR (pData, MNG_INVALIDHEIGHT);
7375
iTickspersec = mng_get_uint16 (pRawdata+10);
7376
if (iTickspersec == 0) /* delay_den must not be zero */
7377
MNG_ERROR (pData, MNG_INVALIDFIELDVAL);
7379
if (*(pRawdata+12) != 0) /* only deflate compression-method allowed */
7380
MNG_ERROR (pData, MNG_INVALIDCOMPRESS);
7382
#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS)
7383
iNumplays = mng_get_uint16 (pRawdata+8);
7384
iCompressedsize = (mng_uint32)(iRawlen - 13);
7387
#ifdef MNG_SUPPORT_DISPLAY
7389
iRetcode = mng_inflate_buffer (pData, pRawdata+13, iCompressedsize,
7390
&pBuf, &iBufsize, &iFramessize);
7391
if (iRetcode) /* on error bail out */
7393
MNG_FREEX (pData, pBuf, iBufsize);
7397
if (iFramessize % 26)
7399
MNG_FREEX (pData, pBuf, iBufsize);
7400
MNG_ERROR (pData, MNG_INVALIDLENGTH);
7403
iRetcode = mng_create_mpng_obj (pData, iFramewidth, iFrameheight, iNumplays,
7404
iTickspersec, iFramessize, pBuf);
7405
if (iRetcode) /* on error bail out */
7407
MNG_FREEX (pData, pBuf, iBufsize);
7411
#endif /* MNG_SUPPORT_DISPLAY */
7413
#ifdef MNG_STORE_CHUNKS
7414
if (pData->bStorechunks)
7415
{ /* initialize storage */
7416
iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk);
7417
if (iRetcode) /* on error bail out */
7419
/* store the fields */
7420
((mng_mpngp)*ppChunk)->iFramewidth = iFramewidth;
7421
((mng_mpngp)*ppChunk)->iFrameheight = iFrameheight;
7422
((mng_mpngp)*ppChunk)->iNumplays = iNumplays;
7423
((mng_mpngp)*ppChunk)->iTickspersec = iTickspersec;
7424
((mng_mpngp)*ppChunk)->iCompressionmethod = *(pRawdata+14);
7426
#ifndef MNG_SUPPORT_DISPLAY
7427
iRetcode = mng_inflate_buffer (pData, pRawdata+13, iCompressedsize,
7428
&pBuf, &iBufsize, &iFramessize);
7429
if (iRetcode) /* on error bail out */
7431
MNG_FREEX (pData, pBuf, iBufsize);
7435
if (iFramessize % 26)
7437
MNG_FREEX (pData, pBuf, iBufsize);
7438
MNG_ERROR (pData, MNG_INVALIDLENGTH);
7444
MNG_ALLOCX (pData, ((mng_mpngp)*ppChunk)->pFrames, iFramessize);
7445
if (((mng_mpngp)*ppChunk)->pFrames == 0)
7447
MNG_FREEX (pData, pBuf, iBufsize);
7448
MNG_ERROR (pData, MNG_OUTOFMEMORY);
7451
((mng_mpngp)*ppChunk)->iFramessize = iFramessize;
7452
MNG_COPY (((mng_mpngp)*ppChunk)->pFrames, pBuf, iFramessize);
7455
#endif /* MNG_STORE_CHUNKS */
7457
#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS)
7458
MNG_FREEX (pData, pBuf, iBufsize);
7461
#ifdef MNG_SUPPORT_TRACE
7462
MNG_TRACE (pData, MNG_FN_READ_MPNG, MNG_LC_END);
7465
return MNG_NOERROR; /* done */
7470
/* ************************************************************************** */
7472
#ifndef MNG_OPTIMIZE_CHUNKREADER
7298
7473
#ifndef MNG_SKIPCHUNK_evNT
7299
7474
READ_CHUNK (mng_read_evnt)
10311
10486
/* ************************************************************************** */
10488
#ifdef MNG_INCLUDE_MPNG_PROPOSAL
10489
WRITE_CHUNK (mng_write_mpng)
10492
mng_uint8p pRawdata;
10493
mng_uint32 iRawlen;
10494
mng_retcode iRetcode;
10495
mng_uint8p pBuf = 0;
10496
mng_uint32 iBuflen;
10497
mng_uint32 iReallen;
10499
#ifdef MNG_SUPPORT_TRACE
10500
MNG_TRACE (pData, MNG_FN_WRITE_MPNG, MNG_LC_START);
10503
pMPNG = (mng_mpngp)pChunk; /* address the proper chunk */
10504
/* compress the frame structures */
10505
iRetcode = deflate_buffer (pData, (mng_uint8p)pMPNG->pFrames, pMPNG->iFramessize,
10506
&pBuf, &iBuflen, &iReallen);
10508
if (!iRetcode) /* all ok ? */
10510
pRawdata = pData->pWritebuf+8; /* init output buffer & size */
10511
iRawlen = 15 + iReallen;
10512
/* requires large buffer ? */
10513
if (iRawlen > pData->iWritebufsize)
10514
MNG_ALLOC (pData, pRawdata, iRawlen);
10515
/* fill the buffer */
10516
mng_put_uint32 (pRawdata, pMPNG->iFramewidth);
10517
mng_put_uint32 (pRawdata+4, pMPNG->iFrameheight);
10518
mng_put_uint16 (pRawdata+8, pMPNG->iNumplays);
10519
mng_put_uint16 (pRawdata+10, pMPNG->iTickspersec);
10520
*(pRawdata+12) = pMPNG->iCompressionmethod;
10523
MNG_COPY (pRawdata+13, pBuf, iReallen);
10525
iRetcode = write_raw_chunk (pData, pMPNG->sHeader.iChunkname,
10526
iRawlen, pRawdata);
10527
/* drop the temp buffer ? */
10528
if (iRawlen > pData->iWritebufsize)
10529
MNG_FREEX (pData, pRawdata, iRawlen);
10532
MNG_FREEX (pData, pBuf, iBuflen); /* always drop the compression buffer */
10534
#ifdef MNG_SUPPORT_TRACE
10535
MNG_TRACE (pData, MNG_FN_WRITE_MPNG, MNG_LC_END);
10542
/* ************************************************************************** */
10544
#ifdef MNG_INCLUDE_ANG_PROPOSAL
10545
WRITE_CHUNK (mng_write_ahdr)
10548
mng_uint8p pRawdata;
10549
mng_uint32 iRawlen;
10550
mng_retcode iRetcode;
10552
#ifdef MNG_SUPPORT_TRACE
10553
MNG_TRACE (pData, MNG_FN_WRITE_AHDR, MNG_LC_START);
10556
pAHDR = (mng_ahdrp)pChunk; /* address the proper chunk */
10557
pRawdata = pData->pWritebuf+8; /* init output buffer & size */
10559
/* fill the buffer */
10560
mng_put_uint32 (pRawdata, pAHDR->iNumframes);
10561
mng_put_uint32 (pRawdata+4, pAHDR->iTickspersec);
10562
mng_put_uint32 (pRawdata+8, pAHDR->iNumplays);
10563
mng_put_uint32 (pRawdata+12, pAHDR->iTilewidth);
10564
mng_put_uint32 (pRawdata+16, pAHDR->iTileheight);
10565
*(pRawdata+20) = pAHDR->iInterlace;
10566
*(pRawdata+21) = pAHDR->iStillused;
10568
iRetcode = write_raw_chunk (pData, pAHDR->sHeader.iChunkname,
10569
iRawlen, pRawdata);
10571
#ifdef MNG_SUPPORT_TRACE
10572
MNG_TRACE (pData, MNG_FN_WRITE_AHDR, MNG_LC_END);
10579
/* ************************************************************************** */
10581
#ifdef MNG_INCLUDE_ANG_PROPOSAL
10582
WRITE_CHUNK (mng_write_adat)
10585
/* TODO: something */
10587
return MNG_NOERROR;
10591
/* ************************************************************************** */
10313
10593
#ifndef MNG_SKIPCHUNK_evNT
10314
10594
WRITE_CHUNK (mng_write_evnt)