~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Source/LibMNG/libmng_chunk_io.c

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-07-20 13:42:15 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720134215-xt1454zaedv3b604
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
/* ************************************************************************** */
5
5
/* *                                                                        * */
6
6
/* * project   : libmng                                                     * */
7
 
/* * file      : libmng_chunk_io.c         copyright (c) 2000-2004 G.Juyn   * */
8
 
/* * version   : 1.0.9                                                      * */
 
7
/* * file      : libmng_chunk_io.c         copyright (c) 2000-2007 G.Juyn   * */
 
8
/* * version   : 1.0.10                                                     * */
9
9
/* *                                                                        * */
10
10
/* * purpose   : Chunk I/O routines (implementation)                        * */
11
11
/* *                                                                        * */
225
225
/* *             1.0.9 - 01/17/2005 - G.Juyn                                * */
226
226
/* *             - fixed problem with global PLTE/tRNS                      * */
227
227
/* *                                                                        * */
 
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      * */
 
233
/* *               available.                                               * */
 
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      * */
 
240
/* *                                                                        * */
228
241
/* ************************************************************************** */
229
242
 
230
243
#include "libmng.h"
420
433
 
421
434
/* ************************************************************************** */
422
435
 
423
 
#if !defined(MNG_SKIPCHUNK_iCCP) || !defined(MNG_SKIPCHUNK_zTXt) || !defined(MNG_SKIPCHUNK_iTXt)
 
436
#if !defined(MNG_SKIPCHUNK_iCCP) || !defined(MNG_SKIPCHUNK_zTXt) || \
 
437
    !defined(MNG_SKIPCHUNK_iTXt) || defined(MNG_INCLUDE_MPNG_PROPOSAL) || \
 
438
    defined(MNG_INCLUDE_ANG_PROPOSAL)
424
439
mng_retcode mng_inflate_buffer (mng_datap  pData,
425
440
                                mng_uint8p pInbuf,
426
441
                                mng_uint32 iInsize,
458
473
      if (iRetcode == MNG_BUFOVERFLOW) /* not enough space ? */
459
474
      {                                /* then get some more */
460
475
        MNG_FREEX (pData, *pOutbuf, *iOutsize);
461
 
        *iOutsize = *iOutsize + iInsize;
 
476
        *iOutsize = *iOutsize + *iOutsize;
462
477
        MNG_ALLOC (pData, *pOutbuf, *iOutsize);
463
478
      }
464
479
    }                                  /* repeat if we didn't have enough space */
465
480
    while ((iRetcode == MNG_BUFOVERFLOW) &&
466
 
           (*iOutsize < 20 * iInsize));
 
481
           (*iOutsize < 200 * iInsize));
467
482
 
468
483
    if (!iRetcode)                     /* if oke ? */
469
484
      *((*pOutbuf) + *iRealsize) = 0;  /* then put terminator zero */
773
788
 
774
789
              if ((pTempfield->iLengthmax) && (iDatalen > pTempfield->iLengthmax))
775
790
                MNG_ERROR (pData, MNG_INVALIDLENGTH);
 
791
#if !defined(MNG_SKIPCHUNK_iCCP) || !defined(MNG_SKIPCHUNK_zTXt) || \
 
792
    !defined(MNG_SKIPCHUNK_iTXt) || defined(MNG_INCLUDE_MPNG_PROPOSAL) || \
 
793
    defined(MNG_INCLUDE_ANG_PROPOSAL)
776
794
                                       /* needs decompression ? */
777
795
              if (pTempfield->iFlags & MNG_FIELD_DEFLATED)
778
796
              {
795
813
                {
796
814
                  if (iRetcode)
797
815
                    return iRetcode;
 
816
 
 
817
#if defined(MNG_INCLUDE_MPNG_PROPOSAL) || defined(MNG_INCLUDE_ANG_PROPOSAL)
 
818
                  if ( (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_mpNG) ||
 
819
                       (((mng_chunk_headerp)pHeader)->iChunkname == MNG_UINT_adAT)    )
 
820
                  {
 
821
                    MNG_ALLOC (pData, pWork, iRealsize);
 
822
                  }
 
823
                  else
 
824
                  {
 
825
#endif
798
826
                                       /* don't forget to generate null terminator */
799
 
                  MNG_ALLOC (pData, pWork, iRealsize+1);
 
827
                    MNG_ALLOC (pData, pWork, iRealsize+1);
 
828
#if defined(MNG_INCLUDE_MPNG_PROPOSAL) || defined(MNG_INCLUDE_ANG_PROPOSAL)
 
829
                  }
 
830
#endif
800
831
                  MNG_COPY (pWork, pBuf, iRealsize);
801
832
 
802
833
                  *((mng_ptr *)(pChunkdata+pTempfield->iOffsetchunk))      = pWork;
806
837
                if (pBuf)              /* free the temporary buffer */
807
838
                  MNG_FREEX (pData, pBuf, iBufsize);
808
839
 
809
 
              } else {                 /* no decompression, so just copy */
 
840
              } else
 
841
#endif
 
842
                     {                 /* no decompression, so just copy */
810
843
 
811
844
                mng_ptr pWork;
812
845
                                       /* don't forget to generate null terminator */
876
909
 
877
910
READ_CHUNK (mng_read_general)
878
911
{
 
912
  mng_retcode     iRetcode = MNG_NOERROR;
879
913
  mng_chunk_descp pDescr   = ((mng_chunk_headerp)pHeader)->pChunkdescr;
880
 
  mng_field_descp pField   = pDescr->pFielddesc;
881
 
  mng_uint16      iFields  = pDescr->iFielddesc;
882
 
  mng_retcode     iRetcode = MNG_NOERROR;
 
914
  mng_field_descp pField;
 
915
  mng_uint16      iFields;
883
916
 
884
917
  if (!pDescr)                         /* this is a bad booboo !!! */
885
918
    MNG_ERROR (pData, MNG_INTERNALERROR);
 
919
 
 
920
  pField  = pDescr->pFielddesc;
 
921
  iFields = pDescr->iFielddesc;
886
922
                                       /* check chunk against signature */
887
923
  if ((pDescr->eImgtype == mng_it_mng) && (pData->eSigtype != mng_it_mng))
888
924
    MNG_ERROR (pData, MNG_CHUNKNOTALLOWED);
1194
1230
    if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight))
1195
1231
      MNG_WARNING (pData, MNG_IMAGETOOLARGE);
1196
1232
 
 
1233
#if !defined(MNG_INCLUDE_MPNG_PROPOSAL) || !defined(MNG_SUPPORT_DISPLAY)
1197
1234
    if (pData->fProcessheader)         /* inform the app ? */
1198
1235
      if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight))
1199
1236
        MNG_ERROR (pData, MNG_APPMISCERROR);
 
1237
#endif        
1200
1238
  }
1201
1239
 
1202
1240
  if (!pData->bHasDHDR)
2376
2414
                                       /* allocate a buffer & copy it */
2377
2415
        MNG_ALLOC (pData, pImage->pImgbuf->pProfile, iProfilesize);
2378
2416
        MNG_COPY  (pImage->pImgbuf->pProfile, pBuf, iProfilesize);
2379
 
                                       /* store it's length as well */
 
2417
                                       /* store its length as well */
2380
2418
        pImage->pImgbuf->iProfilesize = iProfilesize;
2381
2419
        pImage->pImgbuf->bHasICCP     = MNG_TRUE;
2382
2420
      }
2393
2431
                                       /* allocate a buffer & copy it */
2394
2432
        MNG_ALLOC (pData, pImage->pImgbuf->pProfile, iProfilesize);
2395
2433
        MNG_COPY  (pImage->pImgbuf->pProfile, pBuf, iProfilesize);
2396
 
                                       /* store it's length as well */
 
2434
                                       /* store its length as well */
2397
2435
        pImage->pImgbuf->iProfilesize = iProfilesize;
2398
2436
        pImage->pImgbuf->bHasICCP     = MNG_TRUE;
2399
2437
      }
2412
2450
      {                                /* allocate a global buffer & copy it */
2413
2451
        MNG_ALLOC (pData, pData->pGlobalProfile, iProfilesize);
2414
2452
        MNG_COPY  (pData->pGlobalProfile, pBuf, iProfilesize);
2415
 
                                       /* store it's length as well */
 
2453
                                       /* store its length as well */
2416
2454
        pData->iGlobalProfilesize = iProfilesize;
2417
2455
      }
2418
2456
 
3913
3951
      if (iRetcode)                    /* on error bail out */
3914
3952
        return iRetcode;
3915
3953
 
3916
 
      {                                /* process it */
 
3954
/*      {
3917
3955
        mng_ani_endlp pENDL = (mng_ani_endlp)pData->pLastaniobj;
3918
3956
 
3919
3957
        iRetcode = pENDL->sHeader.fProcess (pData, pENDL);
3920
3958
 
3921
 
        if (iRetcode)                  /* on error bail out */
 
3959
        if (iRetcode)
3922
3960
          return iRetcode;
3923
 
      }
 
3961
      } */
3924
3962
    }
3925
3963
    else
3926
3964
      MNG_ERROR (pData, MNG_NOMATCHINGLOOP);
4235
4273
    iRetcode = mng_create_ani_basi (pData, iRed, iGreen, iBlue,
4236
4274
                                    bHasalpha, iAlpha, iViewable);
4237
4275
 
4238
 
    if (!iRetcode)                     /* display-processing... */
 
4276
/*    if (!iRetcode)
4239
4277
      iRetcode = mng_process_display_basi (pData, iRed, iGreen, iBlue,
4240
 
                                           bHasalpha, iAlpha, iViewable);
 
4278
                                           bHasalpha, iAlpha, iViewable); */
4241
4279
 
4242
4280
    if (iRetcode)                      /* on error bail out */
4243
4281
      return iRetcode;
4355
4393
                                    bHasdonotshow, iDonotshow, iConcrete,
4356
4394
                                    bHasloca, iLocationtype, iLocationx, iLocationy);
4357
4395
 
4358
 
    if (!iRetcode)                     /* do display processing */
 
4396
/*    if (!iRetcode)
4359
4397
      iRetcode = mng_process_display_clon (pData, iSourceid, iCloneid, iClonetype,
4360
4398
                                           bHasdonotshow, iDonotshow, iConcrete,
4361
4399
                                           bHasloca, iLocationtype, iLocationx,
4362
 
                                           iLocationy);
 
4400
                                           iLocationy); */
4363
4401
 
4364
4402
    if (iRetcode)                      /* on error bail out */
4365
4403
      return iRetcode;
4485
4523
    iRetcode = mng_create_ani_past (pData, iTargetid, iTargettype, iTargetx,
4486
4524
                                    iTargety, iCount, pSources);
4487
4525
 
4488
 
    if (!iRetcode)                     /* do display processing */
 
4526
/*    if (!iRetcode)
4489
4527
      iRetcode = mng_process_display_past (pData, iTargetid, iTargettype, iTargetx,
4490
 
                                           iTargety, iCount, pSources);
 
4528
                                           iTargety, iCount, pSources); */
4491
4529
 
4492
4530
    if (iRetcode)                      /* on error bail out */
4493
4531
    {
4591
4629
  {                                    /* create playback object */
4592
4630
    iRetcode = mng_create_ani_disc (pData, iCount, pIds);
4593
4631
 
4594
 
    if (iRetcode)                      /* on error bail out */
4595
 
      return iRetcode;
4596
 
                                       /* now process it */
4597
 
    iRetcode = mng_process_display_disc (pData, iCount, pIds);
 
4632
/*    if (!iRetcode)
 
4633
      iRetcode = mng_process_display_disc (pData, iCount, pIds); */
4598
4634
 
4599
4635
    if (iRetcode)                      /* on error bail out */
4600
4636
      return iRetcode;
4870
4906
                                    iChangeclipping, iCliptype,
4871
4907
                                    iClipl, iClipr, iClipt, iClipb);
4872
4908
 
4873
 
    if (!iRetcode)                     /* now go and do something */
 
4909
/*    if (!iRetcode)
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); */
4878
4914
 
4879
4915
    if (iRetcode)                      /* on error bail out */
4880
4916
      return iRetcode;
5024
5060
                                           mng_get_int32 (pRawdata+5),
5025
5061
                                           mng_get_int32 (pRawdata+9));
5026
5062
 
5027
 
    if (!iRetcode)                     /* process the move */
 
5063
/*    if (!iRetcode)
5028
5064
      iRetcode = mng_process_display_move (pData,
5029
5065
                                           mng_get_uint16 (pRawdata),
5030
5066
                                           mng_get_uint16 (pRawdata+2),
5031
5067
                                           *(pRawdata+4),
5032
5068
                                           mng_get_int32 (pRawdata+5),
5033
 
                                           mng_get_int32 (pRawdata+9));
 
5069
                                           mng_get_int32 (pRawdata+9)); */
5034
5070
 
5035
5071
    if (iRetcode)                      /* on error bail out */
5036
5072
      return iRetcode;
5098
5134
                                           mng_get_int32 (pRawdata+13),
5099
5135
                                           mng_get_int32 (pRawdata+17));
5100
5136
 
5101
 
    if (!iRetcode)                     /* process the clipping */
 
5137
/*    if (!iRetcode)
5102
5138
      iRetcode = mng_process_display_clip (pData,
5103
5139
                                           mng_get_uint16 (pRawdata),
5104
5140
                                           mng_get_uint16 (pRawdata+2),
5106
5142
                                           mng_get_int32 (pRawdata+5),
5107
5143
                                           mng_get_int32 (pRawdata+9),
5108
5144
                                           mng_get_int32 (pRawdata+13),
5109
 
                                           mng_get_int32 (pRawdata+17));
 
5145
                                           mng_get_int32 (pRawdata+17)); */
5110
5146
 
5111
5147
    if (iRetcode)                      /* on error bail out */
5112
5148
      return iRetcode;
5192
5228
    iRetcode = mng_create_ani_show (pData, pData->iSHOWfromid,
5193
5229
                                    pData->iSHOWtoid, pData->iSHOWmode);
5194
5230
 
5195
 
    if (!iRetcode)                     /* go and do it! */
 
5231
    if (!iRetcode)
5196
5232
      iRetcode = mng_process_display_show (pData);
5197
5233
 
5198
5234
    if (iRetcode)                      /* on error bail out */
5369
5405
 
5370
5406
                                       /* create a SAVE animation object */
5371
5407
    iRetcode = mng_create_ani_save (pData);
5372
 
                   
5373
 
    if (!iRetcode)                     /* process it */
 
5408
 
 
5409
    if (!iRetcode)
5374
5410
      iRetcode = mng_process_display_save (pData);
5375
5411
 
5376
5412
    if (iRetcode)                      /* on error bail out */
5804
5840
    MNG_UINT_SEEK,
5805
5841
    MNG_UINT_SHOW,
5806
5842
    MNG_UINT_TERM,
 
5843
#ifdef MNG_INCLUDE_ANG_PROPOSAL
 
5844
    MNG_UINT_adAT,
 
5845
    MNG_UINT_ahDR,
 
5846
#endif
5807
5847
    MNG_UINT_bKGD,
5808
5848
    MNG_UINT_cHRM,
5809
5849
/* TODO:    MNG_UINT_eXPI,  */
5813
5853
/* TODO:    MNG_UINT_hIST,  */
5814
5854
    MNG_UINT_iCCP,
5815
5855
    MNG_UINT_iTXt,
 
5856
#ifdef MNG_INCLUDE_MPNG_PROPOSAL
 
5857
    MNG_UINT_mpNG,
 
5858
#endif
5816
5859
    MNG_UINT_nEED,
5817
5860
/* TODO:    MNG_UINT_oFFs,  */
5818
5861
/* TODO:    MNG_UINT_pCAL,  */
6486
6529
    iRetcode = mng_create_ani_dhdr (pData, iObjectid, iImagetype, iDeltatype,
6487
6530
                                    iBlockwidth, iBlockheight, iBlockx, iBlocky);
6488
6531
 
6489
 
    if (!iRetcode)                     /* display processing ? */
 
6532
/*    if (!iRetcode)
6490
6533
      iRetcode = mng_process_display_dhdr (pData, iObjectid, iImagetype, iDeltatype,
6491
 
                                           iBlockwidth, iBlockheight, iBlockx, iBlocky);
 
6534
                                           iBlockwidth, iBlockheight, iBlockx, iBlocky); */
6492
6535
 
6493
6536
    if (iRetcode)                      /* on error bail out */
6494
6537
      return iRetcode;
6585
6628
  {
6586
6629
    mng_retcode iRetcode = mng_create_ani_prom (pData, iSampledepth,
6587
6630
                                                iColortype, iFilltype);
6588
 
                               
6589
 
    if (!iRetcode)                     /* display processing ? */
 
6631
 
 
6632
/*    if (!iRetcode)
6590
6633
      iRetcode = mng_process_display_prom (pData, iSampledepth,
6591
 
                                           iColortype, iFilltype);
 
6634
                                           iColortype, iFilltype); */
 
6635
                                           
6592
6636
    if (iRetcode)                      /* on error bail out */
6593
6637
      return iRetcode;
6594
6638
  }
6636
6680
#ifdef MNG_SUPPORT_DISPLAY
6637
6681
  {
6638
6682
    mng_retcode iRetcode = mng_create_ani_ipng (pData);
6639
 
                               
6640
 
    if (!iRetcode)                     /* process it */
 
6683
 
 
6684
    if (!iRetcode)
6641
6685
      iRetcode = mng_process_display_ipng (pData);
6642
6686
 
6643
6687
    if (iRetcode)                      /* on error bail out */
6810
6854
                                                aIndexentries, aAlphaentries,
6811
6855
                                                aUsedentries);
6812
6856
 
6813
 
    if (!iRetcode)                     /* execute it now ? */
 
6857
/*    if (!iRetcode)
6814
6858
      iRetcode = mng_process_display_pplt (pData, iDeltatype, iMax, aIndexentries,
6815
 
                                           aAlphaentries, aUsedentries);
 
6859
                                           aAlphaentries, aUsedentries); */
6816
6860
 
6817
6861
    if (iRetcode)                      /* on error bail out */
6818
6862
      return iRetcode;
6871
6915
#ifdef MNG_SUPPORT_DISPLAY
6872
6916
  {
6873
6917
    mng_retcode iRetcode = mng_create_ani_ijng (pData);
6874
 
                               
6875
 
    if (!iRetcode)                     /* process it */
 
6918
 
 
6919
    if (!iRetcode)
6876
6920
      iRetcode = mng_process_display_ijng (pData);
6877
6921
 
6878
6922
    if (iRetcode)                      /* on error bail out */
7252
7296
    iRetcode = mng_create_ani_magn (pData, iFirstid, iLastid, iMethodX,
7253
7297
                                    iMX, iMY, iML, iMR, iMT, iMB, iMethodY);
7254
7298
 
7255
 
    if (!iRetcode)                     /* display processing ? */
 
7299
/*    if (!iRetcode)
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); */
7258
7302
 
7259
7303
    if (iRetcode)                      /* on error bail out */
7260
7304
      return iRetcode;
7295
7339
/* ************************************************************************** */
7296
7340
 
7297
7341
#ifndef MNG_OPTIMIZE_CHUNKREADER
 
7342
#ifdef MNG_INCLUDE_MPNG_PROPOSAL
 
7343
READ_CHUNK (mng_read_mpng)
 
7344
{
 
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;
 
7355
#endif
 
7356
 
 
7357
#ifdef MNG_SUPPORT_TRACE
 
7358
  MNG_TRACE (pData, MNG_FN_READ_MPNG, MNG_LC_START);
 
7359
#endif
 
7360
                                       /* sequence checks */
 
7361
  if (!pData->bHasIHDR)
 
7362
    MNG_ERROR (pData, MNG_SEQUENCEERROR);
 
7363
 
 
7364
  if (iRawlen < 41)                    /* length must be at least 41 */
 
7365
    MNG_ERROR (pData, MNG_INVALIDLENGTH);
 
7366
 
 
7367
  iFramewidth     = mng_get_int32 (pRawdata);
 
7368
  if (iFramewidth == 0)                /* frame_width must not be zero */
 
7369
    MNG_ERROR (pData, MNG_INVALIDWIDTH);
 
7370
 
 
7371
  iFrameheight    = mng_get_int32 (pRawdata+4);
 
7372
  if (iFrameheight == 0)               /* frame_height must not be zero */
 
7373
    MNG_ERROR (pData, MNG_INVALIDHEIGHT);
 
7374
 
 
7375
  iTickspersec    = mng_get_uint16 (pRawdata+10);
 
7376
  if (iTickspersec == 0)               /* delay_den must not be zero */
 
7377
    MNG_ERROR (pData, MNG_INVALIDFIELDVAL);
 
7378
 
 
7379
  if (*(pRawdata+12) != 0)             /* only deflate compression-method allowed */
 
7380
    MNG_ERROR (pData, MNG_INVALIDCOMPRESS);
 
7381
 
 
7382
#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS)
 
7383
  iNumplays       = mng_get_uint16 (pRawdata+8);
 
7384
  iCompressedsize = (mng_uint32)(iRawlen - 13);
 
7385
#endif
 
7386
 
 
7387
#ifdef MNG_SUPPORT_DISPLAY
 
7388
  {
 
7389
    iRetcode = mng_inflate_buffer (pData, pRawdata+13, iCompressedsize,
 
7390
                                   &pBuf, &iBufsize, &iFramessize);
 
7391
    if (iRetcode)                    /* on error bail out */
 
7392
    {
 
7393
      MNG_FREEX (pData, pBuf, iBufsize);
 
7394
      return iRetcode;
 
7395
    }
 
7396
 
 
7397
    if (iFramessize % 26)
 
7398
    {
 
7399
      MNG_FREEX (pData, pBuf, iBufsize);
 
7400
      MNG_ERROR (pData, MNG_INVALIDLENGTH);
 
7401
    }
 
7402
 
 
7403
    iRetcode = mng_create_mpng_obj (pData, iFramewidth, iFrameheight, iNumplays,
 
7404
                                    iTickspersec, iFramessize, pBuf);
 
7405
    if (iRetcode)                      /* on error bail out */
 
7406
    {
 
7407
      MNG_FREEX (pData, pBuf, iBufsize);
 
7408
      return iRetcode;
 
7409
    }
 
7410
  }
 
7411
#endif /* MNG_SUPPORT_DISPLAY */
 
7412
 
 
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 */
 
7418
      return iRetcode;
 
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);
 
7425
 
 
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 */
 
7430
    {
 
7431
      MNG_FREEX (pData, pBuf, iBufsize);
 
7432
      return iRetcode;
 
7433
    }
 
7434
 
 
7435
    if (iFramessize % 26)
 
7436
    {
 
7437
      MNG_FREEX (pData, pBuf, iBufsize);
 
7438
      MNG_ERROR (pData, MNG_INVALIDLENGTH);
 
7439
    }
 
7440
#endif
 
7441
 
 
7442
    if (iFramessize)
 
7443
    {
 
7444
      MNG_ALLOCX (pData, ((mng_mpngp)*ppChunk)->pFrames, iFramessize);
 
7445
      if (((mng_mpngp)*ppChunk)->pFrames == 0)
 
7446
      {
 
7447
        MNG_FREEX (pData, pBuf, iBufsize);
 
7448
        MNG_ERROR (pData, MNG_OUTOFMEMORY);
 
7449
      }
 
7450
 
 
7451
      ((mng_mpngp)*ppChunk)->iFramessize = iFramessize;
 
7452
      MNG_COPY (((mng_mpngp)*ppChunk)->pFrames, pBuf, iFramessize);
 
7453
    }
 
7454
  }
 
7455
#endif /* MNG_STORE_CHUNKS */
 
7456
 
 
7457
#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS)
 
7458
  MNG_FREEX (pData, pBuf, iBufsize);
 
7459
#endif
 
7460
 
 
7461
#ifdef MNG_SUPPORT_TRACE
 
7462
  MNG_TRACE (pData, MNG_FN_READ_MPNG, MNG_LC_END);
 
7463
#endif
 
7464
 
 
7465
  return MNG_NOERROR;                  /* done */
 
7466
}
 
7467
#endif
 
7468
#endif
 
7469
 
 
7470
/* ************************************************************************** */
 
7471
 
 
7472
#ifndef MNG_OPTIMIZE_CHUNKREADER
7298
7473
#ifndef MNG_SKIPCHUNK_evNT
7299
7474
READ_CHUNK (mng_read_evnt)
7300
7475
{
10310
10485
 
10311
10486
/* ************************************************************************** */
10312
10487
 
 
10488
#ifdef MNG_INCLUDE_MPNG_PROPOSAL
 
10489
WRITE_CHUNK (mng_write_mpng)
 
10490
{
 
10491
  mng_mpngp   pMPNG;
 
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;
 
10498
 
 
10499
#ifdef MNG_SUPPORT_TRACE
 
10500
  MNG_TRACE (pData, MNG_FN_WRITE_MPNG, MNG_LC_START);
 
10501
#endif
 
10502
 
 
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);
 
10507
 
 
10508
  if (!iRetcode)                       /* all ok ? */
 
10509
  {
 
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;
 
10521
 
 
10522
    if (iReallen)
 
10523
      MNG_COPY (pRawdata+13, pBuf, iReallen);
 
10524
                                       /* and write it */
 
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);
 
10530
  }
 
10531
 
 
10532
  MNG_FREEX (pData, pBuf, iBuflen);    /* always drop the compression buffer */
 
10533
 
 
10534
#ifdef MNG_SUPPORT_TRACE
 
10535
  MNG_TRACE (pData, MNG_FN_WRITE_MPNG, MNG_LC_END);
 
10536
#endif
 
10537
 
 
10538
  return iRetcode;
 
10539
}
 
10540
#endif
 
10541
 
 
10542
/* ************************************************************************** */
 
10543
 
 
10544
#ifdef MNG_INCLUDE_ANG_PROPOSAL
 
10545
WRITE_CHUNK (mng_write_ahdr)
 
10546
{
 
10547
  mng_ahdrp   pAHDR;
 
10548
  mng_uint8p  pRawdata;
 
10549
  mng_uint32  iRawlen;
 
10550
  mng_retcode iRetcode;
 
10551
 
 
10552
#ifdef MNG_SUPPORT_TRACE
 
10553
  MNG_TRACE (pData, MNG_FN_WRITE_AHDR, MNG_LC_START);
 
10554
#endif
 
10555
 
 
10556
  pAHDR    = (mng_ahdrp)pChunk;        /* address the proper chunk */
 
10557
  pRawdata = pData->pWritebuf+8;       /* init output buffer & size */
 
10558
  iRawlen  = 22;
 
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;
 
10567
                                       /* and write it */
 
10568
  iRetcode = write_raw_chunk (pData, pAHDR->sHeader.iChunkname,
 
10569
                              iRawlen, pRawdata);
 
10570
 
 
10571
#ifdef MNG_SUPPORT_TRACE
 
10572
  MNG_TRACE (pData, MNG_FN_WRITE_AHDR, MNG_LC_END);
 
10573
#endif
 
10574
 
 
10575
  return iRetcode;
 
10576
}
 
10577
#endif
 
10578
 
 
10579
/* ************************************************************************** */
 
10580
 
 
10581
#ifdef MNG_INCLUDE_ANG_PROPOSAL
 
10582
WRITE_CHUNK (mng_write_adat)
 
10583
{
 
10584
 
 
10585
  /* TODO: something */
 
10586
 
 
10587
  return MNG_NOERROR;
 
10588
}
 
10589
#endif
 
10590
 
 
10591
/* ************************************************************************** */
 
10592
 
10313
10593
#ifndef MNG_SKIPCHUNK_evNT
10314
10594
WRITE_CHUNK (mng_write_evnt)
10315
10595
{