📄 giftobmp.cpp.svn-base
字号:
rCode = JC_ERR_MEMORY_ALLOCATION ;
}
return rCode ;
}
/**
* @brief Initializes the structure ST_GIF_ATTRIBUTE
* @param[in] vGifHandle pointer to the ST_GIF_DATA structure
* @param[out] pFilename Pointer to a source gif image
* @retval JC_OK on success
* @retval JC_ERR_INVALID_PARAMETER on error
*/
JC_RETCODE jdi_GifToBmpSetFileContent(JC_HANDLE vGifHandle, JC_CHAR* pFilename)
{
JC_RETCODE rCode = JC_OK ;
ST_GIF_DATA *pstGifData = (ST_GIF_DATA*)JC_NULL;
if(JC_NULL != vGifHandle && JC_NULL != pFilename )
{
pstGifData = (ST_GIF_DATA*)vGifHandle;
rCode = jdi_GifDecodeFile(pFilename, &pstGifData->stGif);
}
else
{
rCode = JC_ERR_INVALID_PARAMETER ;
}
return rCode ;
}
/**
* @brief Deinitializes the structure ST_GIF_DATA
* @param[in] vGifHandle pointer to the ST_GIF_DATA structure
*/
void jdi_GifToBmpDeInit(JC_HANDLE vGifHandle)
{
JC_INT32 iI ;
ST_GIF_DATA *pstGifData ;
JC_HANDLE vFileSysHandle ;
pstGifData = (ST_GIF_DATA*)vGifHandle;
if (JC_NULL != pstGifData)
{
jdd_MemFree(pstGifData->stGif.pucGlobalPalette);
for(iI = 0; iI < pstGifData->stGif.iFrameCount; iI++)
{
jdd_MemFree(pstGifData->stGif.ppstFrameAttribute[iI]->pucFrameRaster);
if (!pstGifData->stGif.ppstFrameAttribute[iI]->bGlobal)
{
jdd_MemFree(pstGifData->stGif.ppstFrameAttribute[iI]->pucFramePalette);
}
}
if (pstGifData->vFile)
{
jdd_FSClose(pstGifData->vFile);
}
if (pstGifData->pmSzFileName)
{
jdd_FSInitialize(&vFileSysHandle) ;
jdd_FSDelete(vFileSysHandle, pstGifData->pmSzFileName);
}
if (pstGifData)
{
jdd_MemFree(pstGifData);
}
}
}
/**
* @brief gives the bmp file(frame) of a gif image depending on the particular frame
* @param[in] vGifHandle pointer to the ST_GIF_DATA structure
* @param[in] pvArg The argument that needs to be passed to the callback
* functions
* @param[out] ppszOutFileName double Pointer (*ppszOutFileName) which is initialised with the output bmp
* file pointer
* @retval JC_OK on success
* @retval JC_ERR_INVALID_PARAMETER on error
* @retval JC_ERR_MEMORY_ALLOCATION on error
*/
JC_RETCODE jdi_GifToBmpGetBmpFile(JC_HANDLE vGifHandle, JC_CHAR** ppszOutFileName, JC_INT32 iFrame)
{
ST_GIF_DATA *pstGifData = (ST_GIF_DATA *)JC_NULL ;
JC_CHAR *pszBmpFileName = (JC_CHAR *)JC_NULL ;
JC_CHAR* pmSzFileName ;
JC_RETCODE rCode = JC_OK ;
if(JC_NULL != vGifHandle && JC_NULL != ppszOutFileName)
{
GENERATEBMPFILENAME(pmSzFileName);
pszBmpFileName = pmSzFileName;
pstGifData = (ST_GIF_DATA*)vGifHandle;
if (JC_NULL != pstGifData)
{
rCode = jdi_BmpCreateFile(&pstGifData->stGif, pszBmpFileName, iFrame);
if (JC_OK != rCode)
{
if (pszBmpFileName)
{
jdd_MemFree(pszBmpFileName);
}
}
}
else
{
rCode = JC_ERR_INVALID_PARAMETER ;
}
}
else
{
rCode = JC_ERR_INVALID_PARAMETER ;
}
*ppszOutFileName = pszBmpFileName;
return rCode;
}
/**
* @brief Gives no of frames in a gif image
* @param[in] vGifHandle pointer to the ST_GIF_DATA structure
* @param[out] pvHandle Pointer to a location that give frame count value in ST_GIF_DATA
* structure
*/
void jdi_GifToBmpGetFrameCount(JC_HANDLE vGifHandle, JC_INT32* piFrameCount)
{
ST_GIF_DATA* pstGifData;
pstGifData = (ST_GIF_DATA*)vGifHandle;
if (JC_NULL != pstGifData)
{
*piFrameCount = pstGifData->stGif.iFrameCount;
}
}
/**
* @brief gives the partial frame(bmp file ) depending upon the structure JC_RECT
* @param[in] vGifHandle pointer to the ST_GIF_DATA structure
* functions
* @param[out] pszOutFile double Pointer which is initialised with the output bmp partial frame
* @retval JC_OK on success
* @retval JC_ERR_INVALID_PARAMETER on error
*/
JC_RETCODE jdi_GifToBmpGetPartialFrameBmpFile(JC_HANDLE vGifHandle, JC_CHAR** pszOutFile, JC_INT32 iFrame, JC_RECT *pstRect)
{
JC_CHAR *pmTempFileName = (JC_CHAR *)JC_NULL ;
JC_CHAR *pmFileName = (JC_CHAR *)JC_NULL ;
JC_RETCODE rCode = JC_OK ;
JDD_FSHANDLE vFsHandle = JC_NULL ;
JC_CHAR* pmSzFileName ;
JC_HANDLE vFileSysHandle ;
if (JC_NULL != vGifHandle && JC_NULL != pszOutFile && iFrame >= 0 && JC_NULL !=pstRect )
{
rCode = jdi_GifToBmpGetBmpFile(vGifHandle, &pmTempFileName, iFrame) ;
if (JC_OK == rCode)
{
GENERATEBMPFILENAME(pmSzFileName);
pmFileName = pmSzFileName;
rCode = jdi_BmpExtractPortion(pmTempFileName, pmFileName, pstRect) ;
if (JC_OK == rCode)
{
jdd_FSInitialize(&vFileSysHandle) ;
jdd_FSDelete(vFileSysHandle, pmTempFileName) ;
if (pmTempFileName)
{
jdd_FSInitialize(&vFileSysHandle) ;
jdd_FSDelete(vFileSysHandle,pmTempFileName);
}
*pszOutFile = pmFileName ;
}
}
}
else
{
rCode = JC_ERR_INVALID_PARAMETER ;
}
return rCode;
}
/**
* @brief Gives the buffer containing the bmp image when size of gif image is less then 4KB
* @param[in] vGifHandle pointer to the ST_GIF_DATA structure
* @param[out] pucBmp double Pointer initialised with pointer containing the bmp image
* @retval JC_OK on success
* @retval JC_ERR_INVALID_PARAMETER on error
*/
JC_RETCODE jdi_GifToBmpGetBmpBuffer(JC_HANDLE vGifHandle, JC_UINT8** pucBmp, JC_INT32 iFrame)
{
JC_RETCODE rCode = JC_ERR_INVALID_PARAMETER ;
ST_GIF_DATA* pstGifData;
pstGifData = (ST_GIF_DATA*)vGifHandle;
if (JC_NULL != pstGifData && JC_NULL != pucBmp)
{
if (E_TRUE == GifToBmpIsBuffer(vGifHandle, iFrame))
{
ST_GIF_ATTRIBUTE *pstGifAttribute = &(pstGifData->stGif) ;
rCode = jdi_BmpCreateBuffer(pstGifAttribute, pstGifData->pucBuf, pstGifData->iLimit, iFrame) ;
*pucBmp = pstGifData->pucBuf;
rCode = JC_OK;
}
}
return rCode;
}
/**
* @brief Gives the format of the source image
* @param[in] pucBmp pucImgBuf containing the first 10 bytes of data of source image
* @param[out] enum E_IMGFORMAT where the format is stored
* @retval JC_OK on success
*/
JC_RETCODE jdi_GifToBmpGetImageFormat(E_IMGFORMAT *eFormat, JC_UINT8 *pucImgBuf)
{
JC_INT8 PNG_SIGNATURE[] = {(JC_INT8)137, (JC_INT8)80, (JC_INT8)78, (JC_INT8)71,
(JC_INT8)13, (JC_INT8)10, (JC_INT8)26, (JC_INT8)10} ;
*eFormat = E_UNKNOWN ;
if((JC_INT8)pucImgBuf[0] == 0)
{
*eFormat = E_WBMP ;
}
else if(0 == jc_strncmp((JC_INT8 *)pucImgBuf, "GIF", 3))
{
*eFormat = E_GIF ;
}
else if(0 == jc_strncmp((JC_INT8 *)pucImgBuf, PNG_SIGNATURE, 8))
{
*eFormat = E_PNG ;
}
else if(0 == jc_strncmp((JC_INT8 *)pucImgBuf, "BM", 2))
{
*eFormat = E_BMP ;
}
else if(0 == jc_strncmp((JC_INT8 *)pucImgBuf + 6, "JFIF", 4)
|| ((JC_UINT8)pucImgBuf[0] == 0xFF && (JC_UINT8)pucImgBuf[1] == 0xD8) )
{
*eFormat = E_JPG ;
}
return JC_OK ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -