?? libmng_jpeg.c
字號:
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_JPEG_DESTROY_DECOMPRESS)
#endif
jpeg_destroy_decompress (pData->pJPEGdinfo);
pData->bJPEGdecompress = MNG_FALSE; /* indicate it's done */
#endif /* MNG_INCLUDE_IJG6B */
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_END)
#endif
return MNG_NOERROR;
}
#endif /* MNG_INCLUDE_JNG_READ */
/* ************************************************************************** */
/* * * */
/* * JPEG decompression routines (JDAA) * */
/* * * */
/* ************************************************************************** */
#ifdef MNG_INCLUDE_JNG_READ
mng_retcode mngjpeg_decompressinit2 (mng_datap pData)
{
#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP)
mng_retcode iRetcode;
#endif
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_START)
#endif
#ifdef MNG_INCLUDE_IJG6B
/* allocate and initialize a JPEG decompression object */
pData->pJPEGdinfo2->err = jpeg_std_error (pData->pJPEGderr2);
#ifdef MNG_USE_SETJMP /* setup local JPEG error-routines */
pData->pJPEGderr2->error_exit = mng_error_exit;
pData->pJPEGderr2->output_message = mng_output_message;
iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */
if (iRetcode != 0) /* got here from longjmp ? */
MNG_ERRORJ (pData, iRetcode) /* then IJG-lib issued an error */
#endif /* MNG_USE_SETJMP */
/* allocate and initialize a JPEG decompression object (continued) */
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_JPEG_CREATE_DECOMPRESS)
#endif
jpeg_create_decompress (pData->pJPEGdinfo2);
pData->bJPEGdecompress2 = MNG_TRUE; /* indicate it's initialized */
/* specify the source of the compressed data (eg, a file) */
/* no, not a file; we have buffered input */
pData->pJPEGdinfo2->src = pData->pJPEGdsrc2;
/* use the default handler */
pData->pJPEGdinfo2->src->resync_to_restart = jpeg_resync_to_restart;
/* setup local source routine & parms */
pData->pJPEGdinfo2->src->init_source = mng_init_source;
pData->pJPEGdinfo2->src->fill_input_buffer = mng_fill_input_buffer;
pData->pJPEGdinfo2->src->skip_input_data = mng_skip_input_data2;
pData->pJPEGdinfo2->src->term_source = mng_term_source;
pData->pJPEGdinfo2->src->next_input_byte = pData->pJPEGcurrent2;
pData->pJPEGdinfo2->src->bytes_in_buffer = pData->iJPEGbufremain2;
#endif /* MNG_INCLUDE_IJG6B */
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSINIT, MNG_LC_END)
#endif
return MNG_NOERROR;
}
#endif /* MNG_INCLUDE_JNG_READ */
/* ************************************************************************** */
#ifdef MNG_INCLUDE_JNG_READ
mng_retcode mngjpeg_decompressdata2 (mng_datap pData,
mng_uint32 iRawsize,
mng_uint8p pRawdata)
{
mng_retcode iRetcode;
mng_uint32 iRemain;
mng_uint8p pWork;
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_START)
#endif
#if defined (MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP)
iRetcode = setjmp (pData->sErrorbuf);/* initialize local JPEG error-recovery */
if (iRetcode != 0) /* got here from longjmp ? */
MNG_ERRORJ (pData, iRetcode) /* then IJG-lib issued an error */
#endif
pWork = pRawdata;
iRemain = iRawsize;
if (pData->iJPEGtoskip2) /* JPEG-lib told us to skip some more data ? */
{
if (iRemain > pData->iJPEGtoskip2) /* enough data in this buffer ? */
{
iRemain -= pData->iJPEGtoskip2; /* skip enough to access the next byte */
pWork += pData->iJPEGtoskip2;
pData->iJPEGtoskip2 = 0; /* no more to skip then */
}
else
{
pData->iJPEGtoskip2 -= iRemain; /* skip all data in the buffer */
iRemain = 0; /* and indicate this accordingly */
}
/* the skip set current-pointer to NULL ! */
pData->pJPEGcurrent2 = pData->pJPEGbuf2;
}
while (iRemain) /* repeat until no more input-bytes */
{ /* need to shift anything ? */
if ((pData->pJPEGcurrent2 > pData->pJPEGbuf2) &&
(pData->pJPEGcurrent2 - pData->pJPEGbuf2 + pData->iJPEGbufremain2 + iRemain > pData->iJPEGbufmax2))
{
if (pData->iJPEGbufremain2 > 0) /* then do so */
MNG_COPY (pData->pJPEGbuf2, pData->pJPEGcurrent2, pData->iJPEGbufremain2)
pData->pJPEGcurrent2 = pData->pJPEGbuf2;
}
/* does the remaining input fit into the buffer ? */
if (pData->iJPEGbufremain2 + iRemain <= pData->iJPEGbufmax2)
{ /* move the lot */
MNG_COPY ((pData->pJPEGcurrent2 + pData->iJPEGbufremain2), pWork, iRemain)
/* adjust remaining_bytes counter */
pData->iJPEGbufremain2 += iRemain;
iRemain = 0; /* and indicate there's no input left */
}
else
{ /* calculate what does fit */
mng_uint32 iFits = pData->iJPEGbufmax2 - pData->iJPEGbufremain2;
if (iFits <= 0) /* no space is just bugger 'm all */
MNG_ERROR (pData, MNG_JPEGBUFTOOSMALL)
/* move that */
MNG_COPY ((pData->pJPEGcurrent2 + pData->iJPEGbufremain2), pWork, iFits)
pData->iJPEGbufremain2 += iFits; /* adjust remain_bytes counter */
iRemain -= iFits; /* and the input-parms */
pWork += iFits;
}
#ifdef MNG_INCLUDE_IJG6B
pData->pJPEGdinfo2->src->next_input_byte = pData->pJPEGcurrent2;
pData->pJPEGdinfo2->src->bytes_in_buffer = pData->iJPEGbufremain2;
if (!pData->bJPEGhasheader2) /* haven't got the header yet ? */
{
/* call jpeg_read_header() to obtain image info */
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_HEADER)
#endif
if (jpeg_read_header (pData->pJPEGdinfo2, TRUE) != JPEG_SUSPENDED)
{ /* indicate the header's oke */
pData->bJPEGhasheader2 = MNG_TRUE;
/* let's do some sanity checks ! */
if ((pData->pJPEGdinfo2->image_width != pData->iDatawidth ) ||
(pData->pJPEGdinfo2->image_height != pData->iDataheight) )
MNG_ERROR (pData, MNG_JPEGPARMSERR)
if (pData->pJPEGdinfo2->jpeg_color_space != JCS_GRAYSCALE)
MNG_ERROR (pData, MNG_JPEGPARMSERR)
/* indicate whether or not it's progressive */
pData->bJPEGprogressive2 = (mng_bool)jpeg_has_multiple_scans (pData->pJPEGdinfo2);
if (pData->bJPEGprogressive2) /* progressive alphachannel not allowed !!! */
MNG_ERROR (pData, MNG_JPEGPARMSERR)
/* allocate a row of JPEG-samples */
if (pData->pJPEGdinfo2->jpeg_color_space == JCS_YCbCr)
pData->iJPEGrowlen2 = pData->pJPEGdinfo2->image_width * RGB_PIXELSIZE;
else
pData->iJPEGrowlen2 = pData->pJPEGdinfo2->image_width;
MNG_ALLOC (pData, pData->pJPEGrow2, pData->iJPEGrowlen2)
pData->iJPEGalpharow = 0; /* quite empty up to now */
}
pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte;
pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer;
}
/* decompress not started ? */
if ((pData->bJPEGhasheader2) && (!pData->bJPEGdecostarted2))
{
/* set parameters for decompression */
if (pData->bJPEGprogressive2) /* progressive display ? */
pData->pJPEGdinfo2->buffered_image = TRUE;
/* jpeg_start_decompress(...); */
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_START_DECOMPRESS)
#endif
if (jpeg_start_decompress (pData->pJPEGdinfo2) == TRUE)
/* indicate it started */
pData->bJPEGdecostarted2 = MNG_TRUE;
pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte;
pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer;
}
/* process some scanlines ? */
if ((pData->bJPEGhasheader2) && (pData->bJPEGdecostarted2) &&
((!jpeg_input_complete (pData->pJPEGdinfo2)) ||
(pData->pJPEGdinfo2->output_scanline < pData->pJPEGdinfo2->output_height)))
{
mng_int32 iLines;
/* for (each output pass) */
do
{ /* address the row output buffer */
JSAMPROW pRow = (JSAMPROW)pData->pJPEGrow2;
/* init new pass ? */
if ((pData->bJPEGprogressive2) &&
((!pData->bJPEGscanstarted2) ||
(pData->pJPEGdinfo2->output_scanline >= pData->pJPEGdinfo2->output_height)))
{
pData->bJPEGscanstarted2 = MNG_TRUE;
/* adjust output decompression parameters if required */
/* nop */
/* start a new output pass */
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_START_OUTPUT)
#endif
jpeg_start_output (pData->pJPEGdinfo2, pData->pJPEGdinfo2->input_scan_number);
pData->iJPEGrow = 0; /* start at row 0 in the image again */
}
/* while (scan lines remain to be read) */
do
{
/* jpeg_read_scanlines(...); */
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_READ_SCANLINES)
#endif
iLines = jpeg_read_scanlines (pData->pJPEGdinfo2, (JSAMPARRAY)&pRow, 1);
pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte;
pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer;
if (iLines > 0) /* got something ? */
{
if (pData->fStorerow3) /* store in object ? */
{
iRetcode = ((mng_storerow)pData->fStorerow3) (pData);
if (iRetcode) /* on error bail out */
return iRetcode;
}
}
}
while ((pData->pJPEGdinfo2->output_scanline < pData->pJPEGdinfo2->output_height) &&
(iLines > 0)); /* until end-of-image or not enough input-data */
/* terminate output pass */
if ((pData->bJPEGprogressive2) &&
(pData->pJPEGdinfo2->output_scanline >= pData->pJPEGdinfo2->output_height))
{
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_FINISH_OUTPUT)
#endif
if (jpeg_finish_output (pData->pJPEGdinfo2) == JPEG_SUSPENDED)
jpeg_finish_output (pData->pJPEGdinfo2);
/* this scan has ended */
pData->bJPEGscanstarted2 = MNG_FALSE;
}
}
while ((!jpeg_input_complete (pData->pJPEGdinfo2)) && (iLines > 0));
}
/* end of image ? */
if ((pData->bJPEGhasheader2) && (pData->bJPEGdecostarted2) &&
(jpeg_input_complete (pData->pJPEGdinfo2)) &&
(pData->pJPEGdinfo2->input_scan_number == pData->pJPEGdinfo2->output_scan_number))
{
/* jpeg_finish_decompress(...); */
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_JPEG_FINISH_DECOMPRESS)
#endif
if (jpeg_finish_decompress (pData->pJPEGdinfo2) == TRUE)
{ /* indicate it's done */
pData->bJPEGhasheader2 = MNG_FALSE;
pData->bJPEGdecostarted2 = MNG_FALSE;
pData->pJPEGcurrent2 = (mng_uint8p)pData->pJPEGdinfo2->src->next_input_byte;
pData->iJPEGbufremain2 = (mng_uint32)pData->pJPEGdinfo2->src->bytes_in_buffer;
/* remaining fluff is an error ! */
if ((pData->iJPEGbufremain2 > 0) || (iRemain > 0))
MNG_ERROR (pData, MNG_TOOMUCHJDAT)
}
}
#endif /* MNG_INCLUDE_IJG6B */
}
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSDATA, MNG_LC_END)
#endif
return MNG_NOERROR;
}
#endif /* MNG_INCLUDE_JNG_READ */
/* ************************************************************************** */
#ifdef MNG_INCLUDE_JNG_READ
mng_retcode mngjpeg_decompressfree2 (mng_datap pData)
{
#if defined(MNG_INCLUDE_IJG6B) && defined(MNG_USE_SETJMP)
mng_retcode iRetcode;
#endif
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_START)
#endif
#ifdef MNG_INCLUDE_IJG6B
#ifdef MNG_USE_SETJMP
iRetcode = setjmp (pData->sErrorbuf);/* setup local JPEG error-recovery */
if (iRetcode != 0) /* got here from longjmp ? */
MNG_ERRORJ (pData, iRetcode) /* then IJG-lib issued an error */
#endif
/* free the row of JPEG-samples*/
MNG_FREE (pData, pData->pJPEGrow2, pData->iJPEGrowlen2)
/* release the JPEG decompression object */
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_JPEG_DESTROY_DECOMPRESS)
#endif
jpeg_destroy_decompress (pData->pJPEGdinfo2);
pData->bJPEGdecompress2 = MNG_FALSE; /* indicate it's done */
#endif /* MNG_INCLUDE_IJG6B */
#ifdef MNG_SUPPORT_TRACE
MNG_TRACE (pData, MNG_FN_JPEG_DECOMPRESSFREE, MNG_LC_END)
#endif
return MNG_NOERROR;
}
#endif /* MNG_INCLUDE_JNG_READ */
/* ************************************************************************** */
#endif /* MNG_INCLUDE_JNG && MNG_INCLUDE_DISPLAY_PROCS */
/* ************************************************************************** */
/* * end of file * */
/* ************************************************************************** */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -