⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libmng_read.c

📁 Linux下的基于X11的图形开发环境。
💻 C
📖 第 1 页 / 共 2 页
字号:
  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;}/* ************************************************************************** */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; }        case 9 : { iRetcode = process_display_magn2 (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;}/* ************************************************************************** */mng_retcode read_graphic (mng_datap pData){  mng_uint32  iBuflen;                 /* number of bytes requested */  mng_uint32  iRead;                   /* number of bytes read */  mng_retcode iRetcode;                /* temporary error-code */#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_GRAPHIC, MNG_LC_START)#endif  if (!pData->pReadbuf)                /* buffer allocated ? */  {    pData->iReadbufsize = 4200;        /* allocate a default read buffer */    MNG_ALLOC (pData, pData->pReadbuf, pData->iReadbufsize)  }                                       /* haven't processed the signature ? */  if ((!pData->bHavesig) || (pData->iSuspendpoint == 1))  {    iBuflen = 2 * sizeof (mng_uint32); /* read signature */    iRetcode = read_databuffer (pData, pData->pReadbuf, iBuflen, &iRead);    if (iRetcode)      return iRetcode;    if (pData->bSuspended)             /* input suspension ? */      pData->iSuspendpoint = 1;    else    {      if (iRead != iBuflen)            /* full signature received ? */        MNG_ERROR (pData, MNG_UNEXPECTEDEOF);                                       /* is it a valid signature ? */      if (mng_get_uint32 (pData->pReadbuf) == PNG_SIG)        pData->eSigtype = mng_it_png;      else      if (mng_get_uint32 (pData->pReadbuf) == JNG_SIG)        pData->eSigtype = mng_it_jng;      else      if (mng_get_uint32 (pData->pReadbuf) == MNG_SIG)        pData->eSigtype = mng_it_mng;      else        MNG_ERROR (pData, MNG_INVALIDSIG);                                       /* all of it ? */      if (mng_get_uint32 (pData->pReadbuf+4) != POST_SIG)        MNG_ERROR (pData, MNG_INVALIDSIG);      pData->bHavesig = MNG_TRUE;    }  }  if (!pData->bSuspended)              /* still going ? */  {    do    {      iRetcode = read_chunk (pData);   /* process a chunk */      if (iRetcode)                    /* on error bail out */        return iRetcode;    }#ifdef MNG_SUPPORT_DISPLAY             /* until EOF or a break-request */    while (((!pData->bEOF) || (pData->pCurraniobj)) && (!pData->bSuspended) &&           (!pData->bTimerset) && (!pData->bSectionwait));#else    while ((!pData->bEOF) && (!pData->bSuspended));#endif  }#ifdef MNG_SUPPORT_TRACE  MNG_TRACE (pData, MNG_FN_READ_GRAPHIC, MNG_LC_END)#endif  return MNG_NOERROR;}/* ************************************************************************** */#endif /* MNG_INCLUDE_READ_PROCS *//* ************************************************************************** *//* * end of file                                                            * *//* ************************************************************************** */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -