pData->iLayerseq++;
if (pData->bRunning) pData->iLayerseq++;
mng_retcode next_layer (mng_datap pData){  mng_imagep  pImage;  mng_retcode iRetcode = MNG_NOERROR;#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_START)#endif  if (!pData->iBreakpoint)             /* no previous break here ? */  {    if ((pData->iLayerseq) &&          /* interframe delay required ? */        ((pData->iFramemode == 1) || (pData->iFramemode == 3)))      iRetcode = interframe_delay (pData);    else      pData->iFramedelay = pData->iNextdelay;    if (iRetcode)                      /* on error bail out */      return iRetcode;  }  if (!pData->bTimerset)               /* timer still off ? */  {    if (!pData->iLayerseq)             /* restore background for the very first layer ? */    {      iRetcode = load_bkgdlayer (pData);      pData->iLayerseq++;              /* and it counts as a layer then ! */    }    else    if (pData->iFramemode == 3)        /* restore background for each layer ? */      iRetcode = load_bkgdlayer (pData);    if (iRetcode)                      /* on error bail out */      return iRetcode;    if (pData->bHasDHDR)               /* processing a delta-image ? */      pImage = (mng_imagep)pData->pDeltaImage;    else      pImage = (mng_imagep)pData->pCurrentobj;    if (!pImage)                       /* not an active object ? */      pImage = (mng_imagep)pData->pObjzero;                                       /* determine display rectangle */    pData->iDestl   = MAX_COORD ((mng_int32)0,   pImage->iPosx);    pData->iDestt   = MAX_COORD ((mng_int32)0,   pImage->iPosy);                                       /* is it a valid buffer ? */    if ((pImage->pImgbuf->iWidth) && (pImage->pImgbuf->iHeight))    {      pData->iDestr = MIN_COORD ((mng_int32)pData->iWidth,                                 pImage->iPosx + (mng_int32)pImage->pImgbuf->iWidth );      pData->iDestb = MIN_COORD ((mng_int32)pData->iHeight,                                 pImage->iPosy + (mng_int32)pImage->pImgbuf->iHeight);    }    else                               /* it's a single image ! */    {      pData->iDestr = MIN_COORD ((mng_int32)pData->iWidth,                                 (mng_int32)pData->iDatawidth );      pData->iDestb = MIN_COORD ((mng_int32)pData->iHeight,                                 (mng_int32)pData->iDataheight);    }    if (pData->bFrameclipping)         /* frame clipping specified ? */    {      pData->iDestl = MAX_COORD (pData->iDestl,  pData->iFrameclipl);      pData->iDestt = MAX_COORD (pData->iDestt,  pData->iFrameclipt);      pData->iDestr = MIN_COORD (pData->iDestr,  pData->iFrameclipr);      pData->iDestb = MIN_COORD (pData->iDestb,  pData->iFrameclipb);    }    if (pImage->bClipped)              /* is the image clipped itself ? */    {      pData->iDestl = MAX_COORD (pData->iDestl,  pImage->iClipl);      pData->iDestt = MAX_COORD (pData->iDestt,  pImage->iClipt);      pData->iDestr = MIN_COORD (pData->iDestr,  pImage->iClipr);      pData->iDestb = MIN_COORD (pData->iDestb,  pImage->iClipb);    }                                       /* determine source starting point */    pData->iSourcel = MAX_COORD ((mng_int32)0,   pData->iDestl - pImage->iPosx);    pData->iSourcet = MAX_COORD ((mng_int32)0,   pData->iDestt - pImage->iPosy);    if ((pImage->pImgbuf->iWidth) && (pImage->pImgbuf->iHeight))    {                                  /* and maximum size  */      pData->iSourcer = MIN_COORD ((mng_int32)pImage->pImgbuf->iWidth,                                   pData->iSourcel + pData->iDestr - pData->iDestl);      pData->iSourceb = MIN_COORD ((mng_int32)pImage->pImgbuf->iHeight,                                   pData->iSourcet + pData->iDestb - pData->iDestt);    }    else                               /* it's a single image ! */    {      pData->iSourcer = pData->iSourcel + pData->iDestr - pData->iDestl;      pData->iSourceb = pData->iSourcet + pData->iDestb - pData->iDestt;    }    pData->iLayerseq++;                /* count the layer ! */  }#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_NEXT_LAYER, MNG_LC_END)#endif  return MNG_NOERROR;}