📄 libmng_read.c
字号:
#endif
case 10 : { iRetcode = mng_process_display_mend2 (pData); break; }
#ifndef MNG_SKIPCHUNK_PAST
case 11 : { iRetcode = mng_process_display_past2 (pData); break; }
#endif
}
}
}
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
{
#ifdef MNG_SUPPORT_DISPLAY
/* freezing in progress ? */
if ((pData->bFreezing) && (pData->iSuspendpoint == 0))
pData->bRunning = MNG_FALSE; /* then this is the right moment to do it */
#endif
if (pData->iSuspendpoint <= 2)
{
iBuflen = sizeof (mng_uint32); /* read length */
iRetcode = read_databuffer (pData, pBuf, &pData->pReadbufnext, 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->iChunklen > 0x7ffffff)
return MNG_INVALIDLENGTH;
}
}
if (!pData->bSuspended) /* still going ? */
{ /* previously suspended or not eof ? */
if ((pData->iSuspendpoint > 2) || (iRead == iBuflen))
{ /* determine length chunkname + data (+ crc) */
if (pData->iCrcmode & MNG_CRC_INPUT)
iBuflen = pData->iChunklen + (mng_uint32)(sizeof (mng_chunkid) + sizeof (mng_uint32));
else
iBuflen = pData->iChunklen + (mng_uint32)(sizeof (mng_chunkid));
/* do we have enough data in the current push buffer ? */
if ((pData->pFirstpushdata) && (iBuflen <= pData->pFirstpushdata->iRemaining))
{
mng_pushdatap pPush = pData->pFirstpushdata;
pBuf = pPush->pDatanext;
pPush->pDatanext += iBuflen;
pPush->iRemaining -= iBuflen;
pData->iSuspendpoint = 0; /* safely reset this here ! */
iRetcode = check_chunk_crc (pData, pBuf, iBuflen);
if (iRetcode)
return iRetcode;
if (!pPush->iRemaining) /* buffer depleted? then release it */
iRetcode = mng_release_pushdata (pData);
}
else
{
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, &pData->pReadbufnext, 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 ? */
MNG_ERROR (pData, MNG_UNEXPECTEDEOF)
else
iRetcode = check_chunk_crc (pData, pBuf, iBuflen);
}
}
else
{
if (iBuflen > 16777216) /* is the length incredible? */
MNG_ERROR (pData, MNG_IMPROBABLELENGTH)
if (!pData->iSuspendpoint) /* create additional large buffer ? */
{ /* again reserve space for the last zero-byte */
pData->iLargebufsize = iBuflen + 1;
pData->pLargebufnext = MNG_NULL;
MNG_ALLOC (pData, pData->pLargebuf, pData->iLargebufsize)
}
iRetcode = read_databuffer (pData, pData->pLargebuf, &pData->pLargebufnext, iBuflen, &iRead);
if (iRetcode)
return iRetcode;
if (pData->bSuspended) /* suspended ? */
pData->iSuspendpoint = 4;
else
{
if (iRead != iBuflen) /* did we get all the data ? */
MNG_ERROR (pData, MNG_UNEXPECTEDEOF)
else
iRetcode = check_chunk_crc (pData, pData->pLargebuf, iBuflen);
/* cleanup additional large buffer */
MNG_FREE (pData, pData->pLargebuf, pData->iLargebufsize)
}
}
}
if (iRetcode) /* on error bail out */
return iRetcode;
}
else
{ /* that's final */
iRetcode = mng_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 = mng_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_LOCAL mng_retcode process_pushedchunk (mng_datap pData)
{
mng_retcode iRetcode;
mng_pushdatap pPush = pData->pFirstpushchunk;
iRetcode = process_raw_chunk (pData, pPush->pData, pPush->iLength);
if (iRetcode)
return iRetcode;
return mng_release_pushchunk (pData);
}
/* ************************************************************************** */
mng_retcode mng_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, &pData->pReadbufnext, 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
#ifdef MNG_INCLUDE_JNG
if (mng_get_uint32 (pData->pReadbuf) == JNG_SIG)
pData->eSigtype = mng_it_jng;
else
#endif
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
{ /* reset timer during mng_read() ? */
if ((pData->bReading) && (!pData->bDisplaying))
pData->bTimerset = MNG_FALSE;
if (pData->pFirstpushchunk) /* chunks pushed ? */
iRetcode = process_pushedchunk (pData); /* process the pushed chunk */
else
iRetcode = read_chunk (pData); /* read & 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->bSectionwait) &&
((!pData->bTimerset) || ((pData->bReading) && (!pData->bDisplaying))));
#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 + -