{MNG_UINT_MAGN, init_magn, free_magn, read_magn, write_magn, 0, 0},
mng_retcode process_raw_chunk (mng_datap  pData,                               mng_uint8p pBuf,                               mng_uint32 iBuflen){  /* the table-idea & binary search code was adapted from     libpng 1.1.0 (pngread.c) */  /* NOTE1: the table must remain sorted by chunkname, otherwise the binary     search will break !!! */  /* NOTE2: the layout must remain equal to the header part of all the     chunk-structures (yes, that means even the pNext and pPrev fields;     it's wasting a bit of space, but hey, the code is a lot easier) */  mng_chunk_header chunk_unknown = {MNG_UINT_HUH, init_unknown, free_unknown,                                    read_unknown, write_unknown, 0, 0};  mng_chunk_header chunk_table [] =  {    {MNG_UINT_BACK, init_back, free_back, read_back, write_back, 0, 0},    {MNG_UINT_BASI, init_basi, free_basi, read_basi, write_basi, 0, 0},    {MNG_UINT_CLIP, init_clip, free_clip, read_clip, write_clip, 0, 0},    {MNG_UINT_CLON, init_clon, free_clon, read_clon, write_clon, 0, 0},    {MNG_UINT_DBYK, init_dbyk, free_dbyk, read_dbyk, write_dbyk, 0, 0},    {MNG_UINT_DEFI, init_defi, free_defi, read_defi, write_defi, 0, 0},    {MNG_UINT_DHDR, init_dhdr, free_dhdr, read_dhdr, write_dhdr, 0, 0},    {MNG_UINT_DISC, init_disc, free_disc, read_disc, write_disc, 0, 0},    {MNG_UINT_DROP, init_drop, free_drop, read_drop, write_drop, 0, 0},    {MNG_UINT_ENDL, init_endl, free_endl, read_endl, write_endl, 0, 0},    {MNG_UINT_FRAM, init_fram, free_fram, read_fram, write_fram, 0, 0},    {MNG_UINT_IDAT, init_idat, free_idat, read_idat, write_idat, 0, 0},  /* 12-th element! */    {MNG_UINT_IEND, init_iend, free_iend, read_iend, write_iend, 0, 0},    {MNG_UINT_IHDR, init_ihdr, free_ihdr, read_ihdr, write_ihdr, 0, 0},    {MNG_UINT_IJNG, init_ijng, free_ijng, read_ijng, write_ijng, 0, 0},    {MNG_UINT_IPNG, init_ipng, free_ipng, read_ipng, write_ipng, 0, 0},#ifdef MNG_INCLUDE_JNG    {MNG_UINT_JDAT, init_jdat, free_jdat, read_jdat, write_jdat, 0, 0},    {MNG_UINT_JHDR, init_jhdr, free_jhdr, read_jhdr, write_jhdr, 0, 0},    {MNG_UINT_JSEP, init_jsep, free_jsep, read_jsep, write_jsep, 0, 0},#endif    {MNG_UINT_LOOP, init_loop, free_loop, read_loop, write_loop, 0, 0},    {MNG_UINT_MEND, init_mend, free_mend, read_mend, write_mend, 0, 0},    {MNG_UINT_MHDR, init_mhdr, free_mhdr, read_mhdr, write_mhdr, 0, 0},    {MNG_UINT_MOVE, init_move, free_move, read_move, write_move, 0, 0},    {MNG_UINT_ORDR, init_ordr, free_ordr, read_ordr, write_ordr, 0, 0},    {MNG_UINT_PAST, init_past, free_past, read_past, write_past, 0, 0},    {MNG_UINT_PLTE, init_plte, free_plte, read_plte, write_plte, 0, 0},    {MNG_UINT_PPLT, init_pplt, free_pplt, read_pplt, write_pplt, 0, 0},    {MNG_UINT_PROM, init_prom, free_prom, read_prom, write_prom, 0, 0},    {MNG_UINT_SAVE, init_save, free_save, read_save, write_save, 0, 0},    {MNG_UINT_SEEK, init_seek, free_seek, read_seek, write_seek, 0, 0},    {MNG_UINT_SHOW, init_show, free_show, read_show, write_show, 0, 0},    {MNG_UINT_TERM, init_term, free_term, read_term, write_term, 0, 0},    {MNG_UINT_bKGD, init_bkgd, free_bkgd, read_bkgd, write_bkgd, 0, 0},    {MNG_UINT_cHRM, init_chrm, free_chrm, read_chrm, write_chrm, 0, 0},    {MNG_UINT_eXPI, init_expi, free_expi, read_expi, write_expi, 0, 0},    {MNG_UINT_fPRI, init_fpri, free_fpri, read_fpri, write_fpri, 0, 0},    {MNG_UINT_gAMA, init_gama, free_gama, read_gama, write_gama, 0, 0},    {MNG_UINT_hIST, init_hist, free_hist, read_hist, write_hist, 0, 0},    {MNG_UINT_iCCP, init_iccp, free_iccp, read_iccp, write_iccp, 0, 0},    {MNG_UINT_iTXt, init_itxt, free_itxt, read_itxt, write_itxt, 0, 0},    {MNG_UINT_nEED, init_need, free_need, read_need, write_need, 0, 0},/* TODO:     {MNG_UINT_oFFs, 0, 0, 0, 0, 0, 0},  *//* TODO:     {MNG_UINT_pCAL, 0, 0, 0, 0, 0, 0},  */    {MNG_UINT_pHYg, init_phyg, free_phyg, read_phyg, write_phyg, 0, 0},    {MNG_UINT_pHYs, init_phys, free_phys, read_phys, write_phys, 0, 0},    {MNG_UINT_sBIT, init_sbit, free_sbit, read_sbit, write_sbit, 0, 0},/* TODO:     {MNG_UINT_sCAL, 0, 0, 0, 0, 0, 0},  */    {MNG_UINT_sPLT, init_splt, free_splt, read_splt, write_splt, 0, 0},    {MNG_UINT_sRGB, init_srgb, free_srgb, read_srgb, write_srgb, 0, 0},    {MNG_UINT_tEXt, init_text, free_text, read_text, write_text, 0, 0},    {MNG_UINT_tIME, init_time, free_time, read_time, write_time, 0, 0},    {MNG_UINT_tRNS, init_trns, free_trns, read_trns, write_trns, 0, 0},    {MNG_UINT_zTXt, init_ztxt, free_ztxt, read_ztxt, write_ztxt, 0, 0},  };                                       /* binary search variables */  mng_int32         iTop, iLower, iUpper, iMiddle;  mng_chunk_headerp pEntry;            /* pointer to found entry */  mng_chunkid       iChunkname;        /* the chunk's tag */  mng_chunkp        pChunk;            /* chunk structure (if #define MNG_STORE_CHUNKS) */  mng_retcode       iRetcode;          /* temporary error-code */#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_PROCESS_RAW_CHUNK, MNG_LC_START)#endif                                       /* get the chunkname */  iChunkname = (mng_chunkid)(mng_get_uint32 (pBuf));  pBuf += sizeof (mng_chunkid);        /* adjust the buffer */  iBuflen -= sizeof (mng_chunkid);                                       /* determine max index of table */  iTop = (sizeof (chunk_table) / sizeof (chunk_table [0])) - 1;  /* binary search; with 52 chunks, worst-case is 7 comparisons */  iLower  = 0;  iMiddle = 11;                        /* start with the IDAT entry */  iUpper  = iTop;  pEntry  = 0;                         /* no goods yet! */  pChunk  = 0;  do                                   /* the binary search itself */    {      if (chunk_table [iMiddle].iChunkname < iChunkname)        iLower = iMiddle + 1;      else if (chunk_table [iMiddle].iChunkname > iChunkname)        iUpper = iMiddle - 1;      else      {        pEntry = &chunk_table [iMiddle];        break;      }      iMiddle = (iLower + iUpper) >> 1;    }  while (iLower <= iUpper);  if (!pEntry)                         /* unknown chunk ? */    pEntry = &chunk_unknown;           /* make it so! */  pData->iChunkname = iChunkname;      /* keep track of where we are */  pData->iChunkseq++;  if (pEntry->fRead)                   /* read-callback available ? */  {    iRetcode = pEntry->fRead (pData, pEntry, iBuflen, (mng_ptr)pBuf, &pChunk);    if (!iRetcode)                     /* everything oke ? */    {                                  /* remember unknown chunk's id */      if ((pChunk) && (pEntry == &chunk_unknown))        ((mng_chunk_headerp)pChunk)->iChunkname = iChunkname;    }  }  else    iRetcode = MNG_NOERROR;  if (pChunk)                          /* store this chunk ? */    add_chunk (pData, pChunk);         /* do it */#ifdef MNG_INCLUDE_JNG                 /* implicit EOF ? */  if ((!pData->bHasMHDR) && (!pData->bHasIHDR) && (!pData->bHasJHDR))#else  if ((!pData->bHasMHDR) && (!pData->bHasIHDR))#endif    iRetcode = process_eof (pData);    /* then do some EOF processing */  if (iRetcode)                        /* on error bail out */    return iRetcode;#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_PROCESS_RAW_CHUNK, MNG_LC_END)#endif  return MNG_NOERROR;}