HGImgFmt_SaveImageToGifWriter增加失败处理
This commit is contained in:
parent
d36cfc24db
commit
a4e55d294d
|
@ -954,21 +954,33 @@ HGResult HGAPI HGImgFmt_SaveImageToGifWriter(HGGifWriter writer, HGUInt interval
|
|||
}
|
||||
}
|
||||
|
||||
SavedImage* gifImage = GifMakeSavedImage(gifFile, NULL);
|
||||
|
||||
int mapSize = (1 << gifFile->SColorResolution);
|
||||
if ((gifImage->ImageDesc.ColorMap = GifMakeMapObject(mapSize, NULL)) == NULL)
|
||||
ColorMapObject* colorMap = GifMakeMapObject(mapSize, NULL);
|
||||
if (NULL == colorMap)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
gifImage->RasterBits = (GifPixelType*)malloc(sizeof(GifPixelType) * gifWidth * gifHeight);
|
||||
//5.2.0 GifQuantizeBuffer函数已移除
|
||||
//但是自己去做rgb转256色太麻烦,所以我又加上了
|
||||
//mapSize调用后会被修改为实际值
|
||||
if (GifQuantizeBuffer(gifWidth, gifHeight, &mapSize, redBuffer, greenBuffer, blueBuffer,
|
||||
gifImage->RasterBits, gifImage->ImageDesc.ColorMap->Colors) == GIF_ERROR)
|
||||
GifByteType* rasterBits = (GifPixelType*)malloc(sizeof(GifPixelType) * gifWidth * gifHeight);
|
||||
if (NULL == rasterBits)
|
||||
{
|
||||
GifFreeMapObject(colorMap);
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (GifQuantizeBuffer(gifWidth, gifHeight, &mapSize, redBuffer, greenBuffer, blueBuffer,
|
||||
rasterBits, colorMap->Colors) == GIF_ERROR)
|
||||
{
|
||||
free(rasterBits);
|
||||
GifFreeMapObject(colorMap);
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
SavedImage* gifImage = GifMakeSavedImage(gifFile, NULL);
|
||||
if (NULL == gifImage)
|
||||
{
|
||||
free(rasterBits);
|
||||
GifFreeMapObject(colorMap);
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
|
@ -977,6 +989,8 @@ HGResult HGAPI HGImgFmt_SaveImageToGifWriter(HGGifWriter writer, HGUInt interval
|
|||
gifImage->ImageDesc.Width = gifWidth;
|
||||
gifImage->ImageDesc.Height = gifHeight;
|
||||
gifImage->ImageDesc.Interlace = false;
|
||||
gifImage->ImageDesc.ColorMap = colorMap;
|
||||
gifImage->RasterBits = rasterBits;
|
||||
|
||||
GraphicsControlBlock gcb;
|
||||
gcb.DisposalMode = DISPOSAL_UNSPECIFIED;
|
||||
|
@ -988,18 +1002,13 @@ HGResult HGAPI HGImgFmt_SaveImageToGifWriter(HGGifWriter writer, HGUInt interval
|
|||
//把循环次数写到第一帧对应的扩展块
|
||||
if (0 == gifWriterImpl->m_curIndex)
|
||||
{
|
||||
unsigned char params[3] = { 1, 0, 0 };
|
||||
//Create a Netscape 2.0 loop block
|
||||
if (GifAddExtensionBlock(&gifImage->ExtensionBlockCount, &gifImage->ExtensionBlocks, APPLICATION_EXT_FUNC_CODE,
|
||||
11, (unsigned char*)"NETSCAPE2.0") == GIF_ERROR)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
GifAddExtensionBlock(&gifImage->ExtensionBlockCount, &gifImage->ExtensionBlocks,
|
||||
APPLICATION_EXT_FUNC_CODE, 11, (unsigned char*)"NETSCAPE2.0");
|
||||
|
||||
if (GifAddExtensionBlock(&gifImage->ExtensionBlockCount, &gifImage->ExtensionBlocks, 0, sizeof(params), params) == GIF_ERROR)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
unsigned char params[3] = { 1, 0, 0 };
|
||||
GifAddExtensionBlock(&gifImage->ExtensionBlockCount, &gifImage->ExtensionBlocks,
|
||||
CONTINUE_EXT_FUNC_CODE, sizeof(params), params);
|
||||
}
|
||||
|
||||
++gifWriterImpl->m_curIndex;
|
||||
|
|
Loading…
Reference in New Issue