mng_retcode iRetcode;
READ_CHUNK (read_iccp){#if defined(MNG_SUPPORT_DISPLAY) || defined(MNG_STORE_CHUNKS)  mng_uint8p  pTemp;  mng_uint32  iCompressedsize;  mng_uint32  iProfilesize;  mng_uint32  iBufsize = 0;  mng_retcode iRetcode;#endif  mng_uint8p  pBuf = 0;#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_ICCP, MNG_LC_START)#endif                                       /* sequence checks */#ifdef MNG_INCLUDE_JNG  if ((!pData->bHasMHDR) && (!pData->bHasIHDR) &&      (!pData->bHasBASI) && (!pData->bHasDHDR) && (!pData->bHasJHDR))#else  if ((!pData->bHasMHDR) && (!pData->bHasIHDR) &&      (!pData->bHasBASI) && (!pData->bHasDHDR)    )#endif    MNG_ERROR (pData, MNG_SEQUENCEERROR)#ifdef MNG_INCLUDE_JNG  if ((pData->bHasIDAT) || (pData->bHasPLTE) || (pData->bHasJDAT))#else  if ((pData->bHasIDAT) || (pData->bHasPLTE))#endif    MNG_ERROR (pData, MNG_SEQUENCEERROR)#ifdef MNG_INCLUDE_JNG  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR))#else  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR))#endif  {                                    /* length must be at least 2 */    if (iRawlen < 2)      MNG_ERROR (pData, MNG_INVALIDLENGTH)  }  else  {                                    /* length must be empty or at least 2 */    if ((iRawlen != 0) && (iRawlen < 2))      MNG_ERROR (pData, MNG_INVALIDLENGTH)  }#ifdef MNG_INCLUDE_JNG  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR))#else  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR))#endif    pData->bHasICCP = MNG_TRUE;        /* indicate we've got it */  else    pData->bHasglobalICCP = (mng_bool)(iRawlen != 0);#ifdef MNG_SUPPORT_DISPLAY  pTemp = find_null (pRawdata);        /* find null-separator */                                       /* not found inside input-data ? */  if ((pTemp - pRawdata) > (mng_int32)iRawlen)    MNG_ERROR (pData, MNG_NULLNOTFOUND)                                       /* determine size of compressed profile */  iCompressedsize = (mng_uint32)(iRawlen - (pTemp - pRawdata) - 2);                                       /* decompress the profile */  iRetcode = inflate_buffer (pData, pTemp+2, iCompressedsize,                             &pBuf, &iBufsize, &iProfilesize);  if (iRetcode)                        /* on error bail out */  {    MNG_FREE (pData, pBuf, iBufsize)   /* don't forget to drop the temp buffer */    return iRetcode;  }#ifdef MNG_INCLUDE_JNG  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR) || (pData->bHasJHDR))#else  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasDHDR))#endif  {    mng_imagep pImage;    if (pData->bHasDHDR)               /* update delta image ? */    {                                  /* store in object 0 ! */      pImage = (mng_imagep)pData->pObjzero;      if (pImage->pImgbuf->pProfile)   /* profile existed ? */        MNG_FREEX (pData, pImage->pImgbuf->pProfile, pImage->pImgbuf->iProfilesize)                                       /* allocate a buffer & copy it */      MNG_ALLOC (pData, pImage->pImgbuf->pProfile, iProfilesize)      MNG_COPY  (pImage->pImgbuf->pProfile, pBuf, iProfilesize)                                       /* store it's length as well */      pImage->pImgbuf->iProfilesize = iProfilesize;      pImage->pImgbuf->bHasICCP     = MNG_TRUE;    }    else    {      pImage = (mng_imagep)pData->pCurrentobj;      if (!pImage)                     /* no object then dump it in obj 0 */        pImage = (mng_imagep)pData->pObjzero;      if (pImage->pImgbuf->pProfile)   /* profile existed ? */        MNG_FREEX (pData, pImage->pImgbuf->pProfile, pImage->pImgbuf->iProfilesize)                                       /* allocate a buffer & copy it */      MNG_ALLOC (pData, pImage->pImgbuf->pProfile, iProfilesize)      MNG_COPY  (pImage->pImgbuf->pProfile, pBuf, iProfilesize)                                       /* store it's length as well */      pImage->pImgbuf->iProfilesize = iProfilesize;      pImage->pImgbuf->bHasICCP     = MNG_TRUE;    }  }  else  {                                    /* store as global */    if (iRawlen == 0)                  /* empty chunk ? */    {      if (pData->pGlobalProfile)       /* did we have a global profile ? */        MNG_FREEX (pData, pData->pGlobalProfile, pData->iGlobalProfilesize)      pData->iGlobalProfilesize = 0;   /* reset to null */      pData->pGlobalProfile     = MNG_NULL;     }    else    {                                  /* allocate a global buffer & copy it */      MNG_ALLOC (pData, pData->pGlobalProfile, iProfilesize)      MNG_COPY  (pData->pGlobalProfile, pBuf, iProfilesize)                                       /* store it's length as well */      pData->iGlobalProfilesize = iProfilesize;    }                                       /* create an animation object */    iRetcode = create_ani_iccp (pData, (mng_bool)(iRawlen == 0),                                pData->iGlobalProfilesize,                                pData->pGlobalProfile);    if (iRetcode)                      /* on error bail out */      return iRetcode;  }#endif /* MNG_SUPPORT_DISPLAY */  #ifdef MNG_STORE_CHUNKS  if (pData->bStorechunks)  {                                    /* initialize storage */    iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk);    if (iRetcode)                      /* on error bail out */    {      MNG_FREE (pData, pBuf, iBufsize) /* don't forget to drop the temp buffer */      return iRetcode;    }                                       /* store the fields */    ((mng_iccpp)*ppChunk)->bEmpty = (mng_bool)(iRawlen == 0);    if (iRawlen)                       /* not empty ? */    {      if (!pBuf)                       /* hasn't been unpuzzled it yet ? */      {        pTemp = find_null (pRawdata);  /* find null-separator */                                       /* not found inside input-data ? */        if ((pTemp - pRawdata) > (mng_int32)iRawlen)          MNG_ERROR (pData, MNG_NULLNOTFOUND)                                       /* determine size of compressed profile */        iCompressedsize = iRawlen - (pTemp - pRawdata) - 2;                                       /* decompress the profile */        iRetcode = inflate_buffer (pData, pTemp+2, iCompressedsize,                                   &pBuf, &iBufsize, &iProfilesize);        if (iRetcode)                  /* on error bail out */        {                              /* don't forget to drop the temp buffer */          MNG_FREE (pData, pBuf, iBufsize)          return iRetcode;        }      }      ((mng_iccpp)*ppChunk)->iNamesize = (mng_uint32)(pTemp - pRawdata);      if (((mng_iccpp)*ppChunk)->iNamesize)      {        MNG_ALLOC (pData, ((mng_iccpp)*ppChunk)->zName,                          ((mng_iccpp)*ppChunk)->iNamesize + 1)        MNG_COPY  (((mng_iccpp)*ppChunk)->zName, pRawdata,                   ((mng_iccpp)*ppChunk)->iNamesize)      }      ((mng_iccpp)*ppChunk)->iCompression = *(pTemp+1);      ((mng_iccpp)*ppChunk)->iProfilesize = iProfilesize;      MNG_ALLOC (pData, ((mng_iccpp)*ppChunk)->pProfile, iProfilesize)      MNG_COPY  (((mng_iccpp)*ppChunk)->pProfile, pBuf, iProfilesize)    }  }#endif /* MNG_STORE_CHUNKS */  if (pBuf)    MNG_FREE (pData, pBuf, iBufsize)   /* free the temporary buffer */#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_ICCP, MNG_LC_END)#endif  return MNG_NOERROR;                  /* done */}