📄 giftobmp.cpp.svn-base
字号:
/***************************************************************************
*
* File Name giftobmp.cpp
*
* IMPORTANT NOTICE
*
* Please note that any and all title and/or intellectual property rights
* in and to this Software or any part of this (including without limitation
* any images, photographs, animations, video, audio, music, text and/or
* "applets," incorporated into the Software), herein mentioned to as
* "Software", the accompanying printed materials, and any copies of the
* Software, are owned by Jataayu Software Ltd., Bangalore ("Jataayu")
* or Jataayu's suppliers as the case may be. The Software is protected by
* copyright, including without limitation by applicable copyright laws,
* international treaty provisions, other intellectual property laws and
* applicable laws in the country in which the Software is being used.
* You shall not modify, adapt or translate the Software, without prior
* express written consent from Jataayu. You shall not reverse engineer,
* decompile, disassemble or otherwise alter the Software, except and
* only to the extent that such activity is expressly permitted by
* applicable law notwithstanding this limitation. Unauthorized reproduction
* or redistribution of this program or any portion of it may result in severe
* civil and criminal penalties and will be prosecuted to the maximum extent
* possible under the law. Jataayu reserves all rights not expressly granted.
*
* THIS SOFTWARE IS PROVIDED TO YOU "AS IS" WITHOUT WARRANTY OF ANY
* KIND AND ANY AND ALL REPRESENTATION AND WARRANTIES, EITHER EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY ACCURACY OF INFORMATIONAL CONTENT, AND/OR FITNESS
* FOR A PARTICULAR PURPOSE OR USE, TITLE OR INFRINGEMENT ARE EXPRESSLY
* DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. YOU ASSUME THE
* ENTIRE RISK AS TO THE ACCURACY AND THE USE OF THIS SOFTWARE. JATAAYU
* SHALL NOT BE LIABLE FOR ANY CONSEQUENTIAL, INCIDENTAL, INDIRECT,
* EXEMPLARY, SPECIAL OR PUNITIVE DAMAGES INCLUDING WITHOUT LIMITATION
* ANY LOSS OF DATA, OR; LOSS OF PROFIT, SAVINGS BUSINESS OR GOODWILL
* OR OTHER SIMILAR LOSS RESULTING FROM OR OUT OF THE USE OR INABILITY
* TO USE THIS SOFTWARE, EVEN IF JATAAYU HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE, OR FOR ANY CLAIM BY ANY THIRD PARTY.
***************************************************************************/
/***************************************************************************
* User Include Files
**************************************************************************/
#include "ddl.h"
#include "jcal.h"
#include "gif.h"
#include "giftobmp.h"
#include "bmp.h"
/***************************************************************************
* Macros
**************************************************************************/
#define MAXIMUM_PATH 260
#define BMP_FILEINFOHEADER 40
#define BMP_FILEHEADER 14
#define GENERATEBMPFILENAME(pmSzFileName)\
{\
pmSzFileName = (JC_CHAR*)jdd_MemAlloc(MAXIMUM_PATH, sizeof(JC_CHAR));\
jc_wsprintf(pmSzFileName, MAX_PATH, TEXT("%u.bmp"), jdd_TimerSystemGetTickCount());\
}
#define GENERATEGIFFILENAME(pmSzGifFileName)\
{\
pmSzGifFileName = (JC_CHAR*)jdd_MemAlloc(MAXIMUM_PATH, sizeof(JC_CHAR));\
jc_wsprintf(pmSzGifFileName, MAX_PATH, TEXT("%u.gif"), jdd_TimerSystemGetTickCount());\
}
/***************************************************************************
* Local Function Prototypes
**************************************************************************/
typedef struct gif_data
{
JC_UINT8* pucBuf;
JC_INT32 iLimit;
JDD_FILE vFile;
JC_CHAR* pmSzFileName;
ST_GIF_ATTRIBUTE stGif;
}ST_GIF_DATA;
static JC_BOOLEAN GifToBmpIsBuffer(JC_HANDLE vGifHandle, JC_INT32 iFrame);
static JC_RETCODE GifToBmpGetImageFormat(E_IMGFORMAT *eFormat, JC_UINT8 *pucRaster);
/***************************************************************************
* All Local Function Definitions
**************************************************************************/
JC_BOOLEAN GifToBmpIsBuffer(JC_HANDLE vGifHandle, JC_INT32 iFrame)
{
JC_UINT32 uiFileSize;
JC_INT32 iBitsPerPixel;
ST_GIF_DATA *pstGifData;
pstGifData = (ST_GIF_DATA*)vGifHandle;
iBitsPerPixel = 8;
if((pstGifData->stGif.ppstFrameAttribute[iFrame]->iFrameWidth != pstGifData->stGif.iScreenWidth) || (pstGifData->stGif.ppstFrameAttribute[iFrame]->iFrameHeight != pstGifData->stGif.iScreenHeight))
iBitsPerPixel = 24;
else if(pstGifData->stGif.ppstFrameAttribute[iFrame]->iFrameTransparency)
iBitsPerPixel = 24;
JC_INT32 alignwidth = ((pstGifData->stGif.iScreenWidth * iBitsPerPixel + 31) / 32) * 4;
if(iBitsPerPixel >= 16)
{
uiFileSize = BMP_FILEHEADER + BMP_FILEINFOHEADER + alignwidth * pstGifData->stGif.iScreenHeight-2;
}
else
{
uiFileSize = BMP_FILEHEADER + BMP_FILEINFOHEADER + pstGifData->stGif.ppstFrameAttribute[iFrame]->iNumPalette * 4 + alignwidth * pstGifData->stGif.ppstFrameAttribute[0]->iFrameHeight-2;
}
return (pstGifData->iLimit >= (JC_INT32)uiFileSize) ? E_TRUE: E_FALSE;
}
/***************************************************************************
* All Global Function Definitions
**************************************************************************/
/**
* @brief Gives the properties of the image
* @param[in] vGifHandle pointer to the ST_GIF_DATA structure
* @param[out] pGifInfo Pointer to ST_GIF_INFO that is initialised
* @retval JC_OK on success
* @retval JC_ERR_INVALID_PARAMETER on error
*/
JC_RETCODE jdi_GetInfo(JC_HANDLE vGifHandle, ST_GIF_INFO* pGifInfo)
{
ST_GIF_DATA* pstGifData ;
JC_RETCODE rCode = JC_OK ;
if(JC_NULL != vGifHandle && JC_NULL != pGifInfo)
{
pstGifData = (ST_GIF_DATA*)vGifHandle ;
pGifInfo->iFrameCount= pstGifData->stGif.iFrameCount ;
pGifInfo->iWidth = pstGifData->stGif.iScreenWidth ;
pGifInfo->iHeight = pstGifData->stGif.iScreenHeight ;
pGifInfo->iFrameTransparentColor = pstGifData->stGif.iTransparentColor ;
pGifInfo->bFileOutput = GifToBmpIsBuffer(pstGifData, 0) ;
}
else
{
rCode = JC_ERR_INVALID_PARAMETER ;
}
return rCode ;
}
/**
* @brief Initializes the ST_GIF_DATA structure
* @param[in] iLimit is the limit of the buffer size
* @param[out] pvGifHandle Pointer to a location that receives
* handle to the initialised ST_GIF_DATA
* @retval JC_OK on success
* @retval JC_ERR_DATA_CONN_UNKNOWN on error
* @retval JC_ERR_MEMORY_ALLOCATION on error
* @retval JC_ERR_FILE_OPEN on error
*/
JC_RETCODE jdi_GifToBmpInit(JC_HANDLE *pvGifHandle, JC_INT32 iLimit)
{
JDD_FSHANDLE vFsHandle = JC_NULL ;
JC_RETCODE rCode = JC_OK ;
JC_CHAR* pmSzGifFileName ;
ST_GIF_DATA *pstGifData = (ST_GIF_DATA*)JC_NULL ;
jdd_FSInitialize (&vFsHandle) ;
pstGifData = (ST_GIF_DATA*)jdd_MemAlloc(1, sizeof(ST_GIF_DATA));
if(JC_NULL != pstGifData)
{
pstGifData->iLimit = iLimit ;
GENERATEGIFFILENAME(pmSzGifFileName);
pstGifData->pmSzFileName = pmSzGifFileName;
pstGifData->vFile = jdd_FSOpen(vFsHandle, pstGifData->pmSzFileName,E_CREATE_APPEND_WRITE_READ_MODE) ;
if (JC_NULL != pstGifData->vFile)
{
pstGifData->pucBuf = (JC_UINT8 *)jdd_MemAlloc(iLimit, sizeof(JC_UINT8));
if(JC_NULL != pstGifData->pucBuf)
{
*pvGifHandle = pstGifData;
}
else
{
rCode = JC_ERR_MEMORY_ALLOCATION ;
}
}
else
{
rCode = JC_ERR_FILE_OPEN ;
}
}
else
{
rCode = JC_ERR_MEMORY_ALLOCATION ;
}
return rCode;
}
/**
* @brief sets the contents from the buffer to a file
* @param[in] vGifHandle pointer to the ST_GIF_DATA structure
* @param[in] pucChunk pointer to the buffer containing the image data
* @param[in] iChunkSize size of the buffer
* @param[in] bLastChunk boolean variable true if its the last chunk else false
* @retval JC_OK on success
* @retval JC_ERR_INVALID_PARAMETER on error
* @retval JC_ERR_MEMORY_ALLOCATION on error
*/
JC_RETCODE jdi_GifToBmpSetContent(JC_HANDLE vGifHandle, JC_UINT8* pucChunk, JC_UINT32 iChunkSize, JC_BOOLEAN bLastChunk)
{
JC_RETCODE rCode = JC_OK ;
ST_GIF_DATA *pstGifData ;
E_IMGFORMAT eFormat = E_UNKNOWN ;
JC_UINT8* pucFileType;
pstGifData = (ST_GIF_DATA*)vGifHandle;
pucFileType = (JC_UINT8*) jdd_MemAlloc(sizeof(JC_UINT8), 10);
if(JC_NULL != pucFileType)
{
if(JC_NULL != vGifHandle)
{
if(pucChunk && iChunkSize)
{
jdd_FSWrite(pucChunk, sizeof(JC_UINT8), iChunkSize, pstGifData->vFile) ;
}
if(bLastChunk)
{
if (pstGifData->vFile)
{
jdd_FSClose(pstGifData->vFile);
rCode = jdi_GifDecodeFile(pstGifData->pmSzFileName, &pstGifData->stGif);
}
}
}
else
{
rCode = JC_ERR_INVALID_PARAMETER ;
}
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -