if (pData->iFilter != MNG_FILTER_ADAPTIVE)
if ((pData->eSigtype == mng_it_png) && (pData->iFilter)) MNG_ERROR (pData, MNG_INVALIDFILTER) else if (pData->iFilter & (~MNG_FILTER_MASK))
READ_CHUNK (read_ihdr){#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_IHDR, MNG_LC_START)#endif  if (iRawlen != 13)                   /* length oke ? */    MNG_ERROR (pData, MNG_INVALIDLENGTH)                                       /* only allowed inside PNG or MNG */  if ((pData->eSigtype != mng_it_png) && (pData->eSigtype != mng_it_mng))    MNG_ERROR (pData, MNG_CHUNKNOTALLOWED)                                       /* sequence checks */  if ((pData->eSigtype == mng_it_png) && (pData->iChunkseq > 1))    MNG_ERROR (pData, MNG_SEQUENCEERROR)#ifdef MNG_INCLUDE_JNG  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasIDAT) || (pData->bHasJHDR))#else  if ((pData->bHasIHDR) || (pData->bHasBASI) || (pData->bHasIDAT))#endif    MNG_ERROR (pData, MNG_SEQUENCEERROR)  pData->bHasIHDR      = MNG_TRUE;     /* indicate IHDR is present */                                       /* and store interesting fields */  if ((!pData->bHasDHDR) || (pData->iDeltatype == MNG_DELTATYPE_NOCHANGE))  {    pData->iDatawidth  = mng_get_uint32 (pRawdata);    pData->iDataheight = mng_get_uint32 (pRawdata+4);  }    pData->iBitdepth     = *(pRawdata+8);  pData->iColortype    = *(pRawdata+9);  pData->iCompression  = *(pRawdata+10);  pData->iFilter       = *(pRawdata+11);  pData->iInterlace    = *(pRawdata+12);  if ((pData->iBitdepth !=  1) &&      /* parameter validity checks */      (pData->iBitdepth !=  2) &&      (pData->iBitdepth !=  4) &&      (pData->iBitdepth !=  8) &&      (pData->iBitdepth != 16)    )    MNG_ERROR (pData, MNG_INVALIDBITDEPTH)  if ((pData->iColortype != MNG_COLORTYPE_GRAY   ) &&      (pData->iColortype != MNG_COLORTYPE_RGB    ) &&      (pData->iColortype != MNG_COLORTYPE_INDEXED) &&      (pData->iColortype != MNG_COLORTYPE_GRAYA  ) &&      (pData->iColortype != MNG_COLORTYPE_RGBA   )    )    MNG_ERROR (pData, MNG_INVALIDCOLORTYPE)  if ((pData->iColortype == MNG_COLORTYPE_INDEXED) && (pData->iBitdepth > 8))    MNG_ERROR (pData, MNG_INVALIDBITDEPTH)  if (((pData->iColortype == MNG_COLORTYPE_RGB    ) ||       (pData->iColortype == MNG_COLORTYPE_GRAYA  ) ||       (pData->iColortype == MNG_COLORTYPE_RGBA   )    ) &&      (pData->iBitdepth < 8                            )    )    MNG_ERROR (pData, MNG_INVALIDBITDEPTH)  if (pData->iCompression != MNG_COMPRESSION_DEFLATE)    MNG_ERROR (pData, MNG_INVALIDCOMPRESS)  if (pData->iFilter != MNG_FILTER_ADAPTIVE)    MNG_ERROR (pData, MNG_INVALIDFILTER)  if ((pData->iInterlace != MNG_INTERLACE_NONE ) &&      (pData->iInterlace != MNG_INTERLACE_ADAM7)    )    MNG_ERROR (pData, MNG_INVALIDINTERLACE)  if (pData->bHasDHDR)                 /* check the colortype for delta-images ! */  {    mng_imagedatap pBuf = ((mng_imagep)pData->pObjzero)->pImgbuf;    if (pData->iColortype != pBuf->iColortype)    {      if ( ( (pData->iColortype != MNG_COLORTYPE_INDEXED) ||             (pBuf->iColortype  == MNG_COLORTYPE_GRAY   )    ) &&           ( (pData->iColortype != MNG_COLORTYPE_GRAY   ) ||             (pBuf->iColortype  == MNG_COLORTYPE_INDEXED)    )    )        MNG_ERROR (pData, MNG_INVALIDCOLORTYPE)    }  }  if (!pData->bHasheader)              /* first chunk ? */  {    pData->bHasheader = MNG_TRUE;      /* we've got a header */    pData->eImagetype = mng_it_png;    /* then this must be a PNG */    pData->iWidth     = pData->iDatawidth;    pData->iHeight    = pData->iDataheight;                                       /* fits on maximum canvas ? */    if ((pData->iWidth > pData->iMaxwidth) || (pData->iHeight > pData->iMaxheight))      MNG_WARNING (pData, MNG_IMAGETOOLARGE)    if (pData->fProcessheader)         /* inform the app ? */      if (!pData->fProcessheader (((mng_handle)pData), pData->iWidth, pData->iHeight))        MNG_ERROR (pData, MNG_APPMISCERROR)          }  if (!pData->bHasDHDR)    pData->iImagelevel++;              /* one level deeper */#ifdef MNG_SUPPORT_DISPLAY  {    mng_retcode iRetcode = process_display_ihdr (pData);    if (iRetcode)                      /* on error bail out */      return iRetcode;  }#endif /* MNG_SUPPORT_DISPLAY */#ifdef MNG_STORE_CHUNKS  if (pData->bStorechunks)  {                                    /* initialize storage */    mng_retcode iRetcode = ((mng_chunk_headerp)pHeader)->fCreate (pData, pHeader, ppChunk);    if (iRetcode)                      /* on error bail out */      return iRetcode;                                       /* fill the fields */    ((mng_ihdrp)*ppChunk)->iWidth       = mng_get_uint32 (pRawdata);    ((mng_ihdrp)*ppChunk)->iHeight      = mng_get_uint32 (pRawdata+4);    ((mng_ihdrp)*ppChunk)->iBitdepth    = pData->iBitdepth;    ((mng_ihdrp)*ppChunk)->iColortype   = pData->iColortype;    ((mng_ihdrp)*ppChunk)->iCompression = pData->iCompression;    ((mng_ihdrp)*ppChunk)->iFilter      = pData->iFilter;    ((mng_ihdrp)*ppChunk)->iInterlace   = pData->iInterlace;  }#endif /* MNG_STORE_CHUNKS */#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_IHDR, MNG_LC_END)#endif  return MNG_NOERROR;                  /* done */}