case 9 : { iRetcode = process_display_magn2 (pData); break; }
mng_retcode read_chunk (mng_datap  pData){  mng_uint32  iBufmax   = pData->iReadbufsize;  mng_uint8p  pBuf      = pData->pReadbuf;  mng_uint32  iBuflen   = 0;           /* number of bytes requested */  mng_uint32  iRead     = 0;           /* number of bytes read */  mng_uint32  iCrc;                    /* calculated CRC */  mng_retcode iRetcode  = MNG_NOERROR;#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_CHUNK, MNG_LC_START)#endif#ifdef MNG_SUPPORT_DISPLAY  if (pData->pCurraniobj)              /* processing an animation object ? */  {    do                                 /* process it then */    {      iRetcode = ((mng_object_headerp)pData->pCurraniobj)->fProcess (pData, pData->pCurraniobj);                                       /* refresh needed ? *//*      if ((!iRetcode) && (!pData->bTimerset) && (pData->bNeedrefresh))        iRetcode = display_progressive_refresh (pData, 1); */                                       /* can we advance to next object ? */      if ((!iRetcode) && (pData->pCurraniobj) &&          (!pData->bTimerset) && (!pData->bSectionwait))      {        pData->pCurraniobj = ((mng_object_headerp)pData->pCurraniobj)->pNext;                                       /* TERM processing to be done ? */        if ((!pData->pCurraniobj) && (pData->bHasTERM) && (!pData->bHasMHDR))          iRetcode = process_display_mend (pData);      }    }                                  /* until error or a break or no more objects */    while ((!iRetcode) && (pData->pCurraniobj) &&           (!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bFreezing));  }  else  {    if (pData->iBreakpoint)            /* do we need to finish something first ? */    {      switch (pData->iBreakpoint)      /* return to broken display routine */      {        case 1 : { iRetcode = process_display_fram2 (pData); break; }        case 2 : { iRetcode = process_display_ihdr  (pData); break; }        case 3 : ;                     /* same as 4 !!! */        case 4 : { iRetcode = process_display_show  (pData); break; }        case 5 : { iRetcode = process_display_clon2 (pData); break; }#ifdef MNG_INCLUDE_JNG        case 7 : { iRetcode = process_display_jhdr  (pData); break; }#endif        case 6 : ;                     /* same as 8 !!! */        case 8 : { iRetcode = process_display_iend  (pData); break; }      }    }  }  if (iRetcode)                        /* on error bail out */    return iRetcode;#endif /* MNG_SUPPORT_DISPLAY */                                       /* can we continue processing now, or do we */                                       /* need to wait for the timer to finish (again) ? */#ifdef MNG_SUPPORT_DISPLAY  if ((!pData->bTimerset) && (!pData->bSectionwait) && (!pData->bEOF))#else  if (!pData->bEOF)#endif  {                                    /* freezing in progress ? */    if ((pData->bFreezing) && (pData->iSuspendpoint == 0))      pData->bRunning = MNG_FALSE;     /* then this is the right moment to do it */    if (pData->iSuspendpoint <= 2)    {      iBuflen  = sizeof (mng_uint32);  /* read length */      iRetcode = read_databuffer (pData, pBuf, iBuflen, &iRead);      if (iRetcode)                    /* bail on errors */        return iRetcode;      if (pData->bSuspended)           /* suspended ? */        pData->iSuspendpoint = 2;      else                             /* save the length */        pData->iChunklen = mng_get_uint32 (pBuf);    }    if (!pData->bSuspended)            /* still going ? */    {                                  /* previously suspended or not eof ? */      if ((pData->iSuspendpoint > 2) || (iRead == iBuflen))      {                                /* determine length chunkname + data + crc */        iBuflen = pData->iChunklen + (mng_uint32)(sizeof (mng_chunkid) + sizeof (iCrc));        if (iBuflen < iBufmax)         /* does it fit in default buffer ? */        {                              /* note that we don't use the full size                                          so there's always a zero-byte at the                                          very end !!! */          iRetcode = read_databuffer (pData, pBuf, iBuflen, &iRead);          if (iRetcode)                /* bail on errors */            return iRetcode;          if (pData->bSuspended)       /* suspended ? */            pData->iSuspendpoint = 3;          else          {            if (iRead != iBuflen)      /* did we get all the data ? */              iRetcode = MNG_UNEXPECTEDEOF;            else            {              mng_uint32 iL = iBuflen - (mng_uint32)(sizeof (iCrc));                                       /* calculate the crc */              iCrc = crc (pData, pBuf, iL);                                       /* and check it */              if (!(iCrc == mng_get_uint32 (pBuf + iL)))                iRetcode = MNG_INVALIDCRC;              else                iRetcode = process_raw_chunk (pData, pBuf, iL);            }          }        }        else        {          if (!pData->iSuspendpoint)   /* create additional large buffer ? */          {                            /* again reserve space for the last zero-byte */            pData->iLargebufsize = iBuflen + 1;            MNG_ALLOC (pData, pData->pLargebuf, pData->iLargebufsize)          }          iRetcode = read_databuffer (pData, pData->pLargebuf, iBuflen, &iRead);          if (iRetcode)            return iRetcode;          if (pData->bSuspended)       /* suspended ? */            pData->iSuspendpoint = 4;          else          {            if (iRead != iBuflen)      /* did we get all the data ? */              iRetcode = MNG_UNEXPECTEDEOF;            else            {              mng_uint32 iL = iBuflen - (mng_uint32)(sizeof (iCrc));                                       /* calculate the crc */              iCrc = crc (pData, pData->pLargebuf, iL);                                       /* and check it */              if (!(iCrc == mng_get_uint32 (pData->pLargebuf + iL)))                iRetcode = MNG_INVALIDCRC;              else                iRetcode = process_raw_chunk (pData, pData->pLargebuf, iL);            }                                       /* cleanup additional large buffer */            MNG_FREE (pData, pData->pLargebuf, pData->iLargebufsize)          }          }        if (iRetcode)                  /* on error bail out */          return iRetcode;      }      else      {                                /* that's final */        iRetcode = process_eof (pData);        if (iRetcode)                  /* on error bail out */          return iRetcode;        if ((iRead != 0) ||            /* did we get an unexpected eof ? */#ifdef MNG_INCLUDE_JNG            (pData->bHasIHDR || pData->bHasMHDR || pData->bHasJHDR))#else            (pData->bHasIHDR || pData->bHasMHDR))#endif          MNG_ERROR (pData, MNG_UNEXPECTEDEOF);      }     }  }#ifdef MNG_SUPPORT_DISPLAY             /* refresh needed ? */  if ((!pData->bTimerset) && (!pData->bSuspended) && (pData->bNeedrefresh))  {    iRetcode = display_progressive_refresh (pData, 1);    if (iRetcode)                      /* on error bail out */      return iRetcode;  }#endif#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_CHUNK, MNG_LC_END)#endif  return MNG_NOERROR;}