本文整理匯總了C++中GifFreeMapObject函數的典型用法代碼示例。如果您正苦於以下問題:C++ GifFreeMapObject函數的具體用法?C++ GifFreeMapObject怎麽用?C++ GifFreeMapObject使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GifFreeMapObject函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: DGifGetScreenDesc
/******************************************************************************
This routine should be called before any other DGif calls. Note that
this routine is called automatically from DGif file open routines.
******************************************************************************/
int
DGifGetScreenDesc(GifFileType *GifFile)
{
int BitsPerPixel;
bool SortFlag;
GifByteType Buf[3];
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */
GifFile->Error = D_GIF_ERR_NOT_READABLE;
return GIF_ERROR;
}
/* Put the screen descriptor into the file: */
if (DGifGetWord(GifFile, &GifFile->SWidth) == GIF_ERROR ||
DGifGetWord(GifFile, &GifFile->SHeight) == GIF_ERROR)
return GIF_ERROR;
if (READ(GifFile, Buf, 3) != 3) {
GifFile->Error = D_GIF_ERR_READ_FAILED;
GifFreeMapObject(GifFile->SColorMap);
GifFile->SColorMap = NULL;
return GIF_ERROR;
}
GifFile->SColorResolution = (((Buf[0] & 0x70) + 1) >> 4) + 1;
SortFlag = (Buf[0] & 0x08) != 0;
BitsPerPixel = (Buf[0] & 0x07) + 1;
GifFile->SBackGroundColor = Buf[1];
GifFile->AspectByte = Buf[2];
if (Buf[0] & 0x80) { /* Do we have global color map? */
int i;
GifFile->SColorMap = GifMakeMapObject(1 << BitsPerPixel, NULL);
if (GifFile->SColorMap == NULL) {
GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return GIF_ERROR;
}
/* Get the global color map: */
GifFile->SColorMap->SortFlag = SortFlag;
for (i = 0; i < GifFile->SColorMap->ColorCount; i++) {
/* coverity[check_return] */
if (READ(GifFile, Buf, 3) != 3) {
GifFreeMapObject(GifFile->SColorMap);
GifFile->SColorMap = NULL;
GifFile->Error = D_GIF_ERR_READ_FAILED;
return GIF_ERROR;
}
GifFile->SColorMap->Colors[i].Red = Buf[0];
GifFile->SColorMap->Colors[i].Green = Buf[1];
GifFile->SColorMap->Colors[i].Blue = Buf[2];
}
} else {
GifFile->SColorMap = NULL;
}
return GIF_OK;
}
示例2: EGifCloseFile
/******************************************************************************
This routine should be called last, to close the GIF file.
******************************************************************************/
int
EGifCloseFile(GifFileType *GifFile)
{
GifByteType Buf;
GifFilePrivateType *Private;
FILE *File;
if (GifFile == NULL)
return GIF_ERROR;
Private = (GifFilePrivateType *) GifFile->Private;
if (Private == NULL)
return GIF_ERROR;
if (!IS_WRITEABLE(Private)) {
/* This file was NOT open for writing: */
GifFile->Error = E_GIF_ERR_NOT_WRITEABLE;
return GIF_ERROR;
}
File = Private->File;
Buf = TERMINATOR_INTRODUCER;
InternalWrite(GifFile, &Buf, 1);
if (GifFile->Image.ColorMap) {
GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Image.ColorMap = NULL;
}
if (GifFile->SColorMap) {
GifFreeMapObject(GifFile->SColorMap);
GifFile->SColorMap = NULL;
}
if (Private) {
if (Private->HashTable) {
free((char *) Private->HashTable);
}
free((char *) Private);
}
if (File && fclose(File) != 0) {
GifFile->Error = E_GIF_ERR_CLOSE_FAILED;
return GIF_ERROR;
}
/*
* Without the #ifndef, we get spurious warnings because Coverity mistakenly
* thinks the GIF structure is freed on an error return.
*/
#ifndef __COVERITY__
free(GifFile);
#endif /* __COVERITY__ */
return GIF_OK;
}
示例3: DGifCloseFile
/******************************************************************************
This routine should be called last, to close the GIF file.
******************************************************************************/
int
DGifCloseFile(GifFileType *GifFile, int *ErrorCode)
{
GifFilePrivateType *Private;
if (GifFile == NULL || GifFile->Private == NULL)
return GIF_ERROR;
if (GifFile->Image.ColorMap) {
GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Image.ColorMap = NULL;
}
if (GifFile->SColorMap) {
GifFreeMapObject(GifFile->SColorMap);
GifFile->SColorMap = NULL;
}
if (GifFile->SavedImages) {
GifFreeSavedImages(GifFile);
GifFile->SavedImages = NULL;
}
GifFreeExtensions(&GifFile->ExtensionBlockCount, &GifFile->ExtensionBlocks);
Private = (GifFilePrivateType *) GifFile->Private;
if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */
if (ErrorCode != NULL)
*ErrorCode = D_GIF_ERR_NOT_READABLE;
free((char *)GifFile->Private);
free(GifFile);
return GIF_ERROR;
}
if (Private->File && (fclose(Private->File) != 0)) {
if (ErrorCode != NULL)
*ErrorCode = D_GIF_ERR_CLOSE_FAILED;
free((char *)GifFile->Private);
free(GifFile);
return GIF_ERROR;
}
free((char *)GifFile->Private);
free(GifFile);
if (ErrorCode != NULL)
*ErrorCode = D_GIF_SUCCEEDED;
return GIF_OK;
}
示例4: DGifCloseFile
/******************************************************************************
This routine should be called last, to close the GIF file.
******************************************************************************/
int
DGifCloseFile(GifFileType *GifFile)
{
GifFilePrivateType *Private;
if (GifFile == NULL || GifFile->Private == NULL)
return GIF_ERROR;
if (GifFile->Image.ColorMap) {
GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Image.ColorMap = NULL;
}
if (GifFile->SColorMap) {
GifFreeMapObject(GifFile->SColorMap);
GifFile->SColorMap = NULL;
}
if (GifFile->SavedImages) {
GifFreeSavedImages(GifFile);
GifFile->SavedImages = NULL;
}
GifFreeExtensions(&GifFile->ExtensionBlockCount, &GifFile->ExtensionBlocks);
Private = (GifFilePrivateType *) GifFile->Private;
if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */
GifFile->Error = D_GIF_ERR_NOT_READABLE;
return GIF_ERROR;
}
if (Private->File && (fclose(Private->File) != 0)) {
GifFile->Error = D_GIF_ERR_CLOSE_FAILED;
return GIF_ERROR;
}
free((char *)GifFile->Private);
/*
* Without the #ifndef, we get spurious warnings because Coverity mistakenly
* thinks the GIF structure is freed on an error return.
*/
#ifndef __COVERITY__
free(GifFile);
#endif /* __COVERITY__ */
return GIF_OK;
}
示例5: FreeLastSavedImage
/* Private Function:
* Frees the last image in the GifFile->SavedImages array
*/
void
FreeLastSavedImage(GifFileType *GifFile)
{
SavedImage *sp;
if ((GifFile == NULL) || (GifFile->SavedImages == NULL))
return;
/* Remove one SavedImage from the GifFile */
GifFile->ImageCount--;
sp = &GifFile->SavedImages[GifFile->ImageCount];
/* Deallocate its Colormap */
if (sp->ImageDesc.ColorMap != NULL) {
GifFreeMapObject(sp->ImageDesc.ColorMap);
sp->ImageDesc.ColorMap = NULL;
}
/* Deallocate the image data */
if (sp->RasterBits != NULL)
free((char *)sp->RasterBits);
/* Deallocate any extensions */
GifFreeExtensions(&sp->ExtensionBlockCount, &sp->ExtensionBlocks);
/*** FIXME: We could realloc the GifFile->SavedImages structure but is
* there a point to it? Saves some memory but we'd have to do it every
* time. If this is used in GifFreeSavedImages then it would be inefficient
* (The whole array is going to be deallocated.) If we just use it when
* we want to free the last Image it's convenient to do it here.
*/
}
示例6: cleanUp
static void cleanUp(GifInfo* info) {
free(info->backupPtr);
info->backupPtr = NULL;
free(info->infos);
info->infos = NULL;
free(info->rasterBits);
info->rasterBits = NULL;
free(info->comment);
info->comment = NULL;
GifFileType* GifFile = info->gifFilePtr;
if (GifFile->SavedImages != NULL) {
SavedImage *sp;
for (sp = GifFile->SavedImages;
sp < GifFile->SavedImages + GifFile->ImageCount; sp++) {
if (sp->ImageDesc.ColorMap != NULL) {
GifFreeMapObject(sp->ImageDesc.ColorMap);
sp->ImageDesc.ColorMap = NULL;
}
}
free(GifFile->SavedImages);
GifFile->SavedImages = NULL;
}
DGifCloseFile(GifFile);
free(info);
}
示例7: free
void
AnimatedGifEncoder::end_encoding() {
free(gif_buf);
gif_buf = NULL;
if (output_color_map) {
GifFreeMapObject(output_color_map);
output_color_map = NULL;
}
if (gif_file) {
EGifCloseFile(gif_file);
gif_file = NULL;
}
}
示例8: GifFreeSavedImages
void
GifFreeSavedImages(GifFileType *GifFile) {
SavedImage *sp;
if ((GifFile == NULL) || (GifFile->SavedImages == NULL)) {
return;
}
for (sp = GifFile->SavedImages;
sp < GifFile->SavedImages + GifFile->ImageCount; sp++) {
if (sp->ImageDesc.ColorMap != NULL) {
GifFreeMapObject(sp->ImageDesc.ColorMap);
sp->ImageDesc.ColorMap = NULL;
}
// if (sp->RasterBits != NULL)
// free((char *)sp->RasterBits);
//
// GifFreeExtensions(&sp->ExtensionBlockCount, &sp->ExtensionBlocks);
}
free((char *) GifFile->SavedImages);
GifFile->SavedImages = NULL;
}
示例9: GifUnionColorMap
/*******************************************************************************
Compute the union of two given color maps and return it. If result can't
fit into 256 colors, NULL is returned, the allocated union otherwise.
ColorIn1 is copied as is to ColorUnion, while colors from ColorIn2 are
copied iff they didn't exist before. ColorTransIn2 maps the old
ColorIn2 into the ColorUnion color map table./
*******************************************************************************/
ColorMapObject *
GifUnionColorMap(const ColorMapObject *ColorIn1,
const ColorMapObject *ColorIn2,
GifPixelType ColorTransIn2[])
{
int i, j, CrntSlot, RoundUpTo, NewGifBitSize;
ColorMapObject *ColorUnion;
/*
* We don't worry about duplicates within either color map; if
* the caller wants to resolve those, he can perform unions
* with an empty color map.
*/
/* Allocate table which will hold the result for sure. */
ColorUnion = GifMakeMapObject(MAX(ColorIn1->ColorCount,
ColorIn2->ColorCount) * 2, NULL);
if (ColorUnion == NULL)
return (NULL);
/*
* Copy ColorIn1 to ColorUnion.
*/
for (i = 0; i < ColorIn1->ColorCount; i++)
ColorUnion->Colors[i] = ColorIn1->Colors[i];
CrntSlot = ColorIn1->ColorCount;
/*
* Potentially obnoxious hack:
*
* Back CrntSlot down past all contiguous {0, 0, 0} slots at the end
* of table 1. This is very useful if your display is limited to
* 16 colors.
*/
while (ColorIn1->Colors[CrntSlot - 1].Red == 0
&& ColorIn1->Colors[CrntSlot - 1].Green == 0
&& ColorIn1->Colors[CrntSlot - 1].Blue == 0)
CrntSlot--;
/* Copy ColorIn2 to ColorUnion (use old colors if they exist): */
for (i = 0; i < ColorIn2->ColorCount && CrntSlot <= 256; i++) {
/* Let's see if this color already exists: */
for (j = 0; j < ColorIn1->ColorCount; j++)
if (memcmp (&ColorIn1->Colors[j], &ColorIn2->Colors[i],
sizeof(GifColorType)) == 0)
break;
if (j < ColorIn1->ColorCount)
ColorTransIn2[i] = j; /* color exists in Color1 */
else {
/* Color is new - copy it to a new slot: */
ColorUnion->Colors[CrntSlot] = ColorIn2->Colors[i];
ColorTransIn2[i] = CrntSlot++;
}
}
if (CrntSlot > 256) {
GifFreeMapObject(ColorUnion);
return ((ColorMapObject *) NULL);
}
NewGifBitSize = GifBitSize(CrntSlot);
RoundUpTo = (1 << NewGifBitSize);
if (RoundUpTo != ColorUnion->ColorCount) {
register GifColorType *Map = ColorUnion->Colors;
/*
* Zero out slots up to next power of 2.
* We know these slots exist because of the way ColorUnion's
* start dimension was computed.
*/
for (j = CrntSlot; j < RoundUpTo; j++)
Map[j].Red = Map[j].Green = Map[j].Blue = 0;
/* perhaps we can shrink the map? */
if (RoundUpTo < ColorUnion->ColorCount) {
GifColorType *new_map = (GifColorType *)realloc(Map,
sizeof(GifColorType) * RoundUpTo);
if( new_map == NULL ) {
GifFreeMapObject(ColorUnion);
return ((ColorMapObject *) NULL);
}
ColorUnion->Colors = new_map;
}
}
ColorUnion->ColorCount = RoundUpTo;
ColorUnion->BitsPerPixel = NewGifBitSize;
return (ColorUnion);
}
示例10: pixToGif
/*!
* \brief pixToGif()
*
* \param[in] pix 1, 2, 4, 8, 16 or 32 bpp
* \param[in] gif opened gif stream
* \return 0 if OK, 1 on error
*
* <pre>
* Notes:
* (1) This encodes the pix to the gif stream. The stream is not
* closes by this function.
* (2) It is static to make this function private.
* </pre>
*/
static l_int32
pixToGif(PIX *pix, GifFileType *gif)
{
char *text;
l_int32 wpl, i, j, w, h, d, ncolor, rval, gval, bval;
l_int32 gif_ncolor = 0;
l_uint32 *data, *line;
PIX *pixd;
PIXCMAP *cmap;
ColorMapObject *gif_cmap;
GifByteType *gif_line;
#if (GIFLIB_MAJOR == 5 && GIFLIB_MINOR >= 1) || GIFLIB_MAJOR > 5
int giferr;
#endif /* 5.1 and beyond */
PROCNAME("pixToGif");
if (!pix)
return ERROR_INT("pix not defined", procName, 1);
if (!gif)
return ERROR_INT("gif not defined", procName, 1);
d = pixGetDepth(pix);
if (d == 32) {
pixd = pixConvertRGBToColormap(pix, 1);
} else if (d > 1) {
pixd = pixConvertTo8(pix, TRUE);
} else { /* d == 1; make sure there's a colormap */
pixd = pixClone(pix);
if (!pixGetColormap(pixd)) {
cmap = pixcmapCreate(1);
pixcmapAddColor(cmap, 255, 255, 255);
pixcmapAddColor(cmap, 0, 0, 0);
pixSetColormap(pixd, cmap);
}
}
if (!pixd)
return ERROR_INT("failed to convert image to indexed", procName, 1);
d = pixGetDepth(pixd);
if ((cmap = pixGetColormap(pixd)) == NULL) {
pixDestroy(&pixd);
return ERROR_INT("cmap is missing", procName, 1);
}
/* 'Round' the number of gif colors up to a power of 2 */
ncolor = pixcmapGetCount(cmap);
for (i = 0; i <= 8; i++) {
if ((1 << i) >= ncolor) {
gif_ncolor = (1 << i);
break;
}
}
if (gif_ncolor < 1) {
pixDestroy(&pixd);
return ERROR_INT("number of colors is invalid", procName, 1);
}
/* Save the cmap colors in a gif_cmap */
if ((gif_cmap = GifMakeMapObject(gif_ncolor, NULL)) == NULL) {
pixDestroy(&pixd);
return ERROR_INT("failed to create GIF color map", procName, 1);
}
for (i = 0; i < gif_ncolor; i++) {
rval = gval = bval = 0;
if (ncolor > 0) {
if (pixcmapGetColor(cmap, i, &rval, &gval, &bval) != 0) {
pixDestroy(&pixd);
GifFreeMapObject(gif_cmap);
return ERROR_INT("failed to get color from color map",
procName, 1);
}
ncolor--;
}
gif_cmap->Colors[i].Red = rval;
gif_cmap->Colors[i].Green = gval;
gif_cmap->Colors[i].Blue = bval;
}
pixGetDimensions(pixd, &w, &h, NULL);
if (EGifPutScreenDesc(gif, w, h, gif_cmap->BitsPerPixel, 0, gif_cmap)
!= GIF_OK) {
pixDestroy(&pixd);
GifFreeMapObject(gif_cmap);
return ERROR_INT("failed to write screen description", procName, 1);
//.........這裏部分代碼省略.........
示例11: DGifGetImageDesc
/******************************************************************************
This routine should be called before any attempt to read an image.
Note it is assumed the Image desc. header has been read.
******************************************************************************/
int
DGifGetImageDesc(GifFileType *GifFile)
{
unsigned int BitsPerPixel;
GifByteType Buf[3];
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
SavedImage *sp;
if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */
GifFile->Error = D_GIF_ERR_NOT_READABLE;
return GIF_ERROR;
}
if (DGifGetWord(GifFile, &GifFile->Image.Left) == GIF_ERROR ||
DGifGetWord(GifFile, &GifFile->Image.Top) == GIF_ERROR ||
DGifGetWord(GifFile, &GifFile->Image.Width) == GIF_ERROR ||
DGifGetWord(GifFile, &GifFile->Image.Height) == GIF_ERROR)
return GIF_ERROR;
if (READ(GifFile, Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED;
GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Image.ColorMap = NULL;
return GIF_ERROR;
}
BitsPerPixel = (Buf[0] & 0x07) + 1;
GifFile->Image.Interlace = (Buf[0] & 0x40) ? giftrue : giffalse;
/* Setup the colormap */
if (GifFile->Image.ColorMap) {
GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Image.ColorMap = NULL;
}
/* Does this image have local color map? */
if (Buf[0] & 0x80) {
unsigned int i;
GifFile->Image.ColorMap = GifMakeMapObject(1 << BitsPerPixel, NULL);
if (GifFile->Image.ColorMap == NULL) {
GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return GIF_ERROR;
}
/* Get the image local color map: */
for (i = 0; i < GifFile->Image.ColorMap->ColorCount; i++) {
if (READ(GifFile, Buf, 3) != 3) {
GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Error = D_GIF_ERR_READ_FAILED;
GifFile->Image.ColorMap = NULL;
return GIF_ERROR;
}
GifFile->Image.ColorMap->Colors[i].Red = Buf[0];
GifFile->Image.ColorMap->Colors[i].Green = Buf[1];
GifFile->Image.ColorMap->Colors[i].Blue = Buf[2];
}
}
if (GifFile->SavedImages) {
if ((GifFile->SavedImages = (SavedImage *)realloc(GifFile->SavedImages,
sizeof(SavedImage) *
(GifFile->ImageCount + 1))) == NULL) {
GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return GIF_ERROR;
}
} else {
if ((GifFile->SavedImages =
(SavedImage *) malloc(sizeof(SavedImage))) == NULL) {
GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return GIF_ERROR;
}
}
sp = &GifFile->SavedImages[GifFile->ImageCount];
memcpy(&sp->ImageDesc, &GifFile->Image, sizeof(GifImageDesc));
if (GifFile->Image.ColorMap != NULL) {
sp->ImageDesc.ColorMap = GifMakeMapObject(
GifFile->Image.ColorMap->ColorCount,
GifFile->Image.ColorMap->Colors);
if (sp->ImageDesc.ColorMap == NULL) {
GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return GIF_ERROR;
}
}
sp->RasterBits = (unsigned char *)NULL;
sp->ExtensionBlockCount = 0;
sp->ExtensionBlocks = (ExtensionBlock *) NULL;
GifFile->ImageCount++;
Private->PixelCount = (long)GifFile->Image.Width *
(long)GifFile->Image.Height;
/* Reset decompress algorithm parameters. */
(void)DGifSetupDecompress(GifFile);
return GIF_OK;
//.........這裏部分代碼省略.........
示例12: SetErrorMessage
void EncodeToGifBufferWorker::Execute () {
GifByteType
* redBuff = (GifByteType *) _pixbuf,
* greenBuff = (GifByteType *) _pixbuf + _width * _height,
* blueBuff = (GifByteType *) _pixbuf + 2 * _width * _height,
* alphaBuff = (GifByteType *) _pixbuf + 3 * _width * _height,
* gifimgbuf = (GifByteType *) malloc(_width * _height * sizeof(GifByteType)); // the indexed image
ColorMapObject *cmap;
SavedImage * simg;
if (NULL == gifimgbuf){
SetErrorMessage("Out of memory");
return;
}
cmap = GifMakeMapObject(_cmapSize, NULL);
if (NULL == cmap){
free(gifimgbuf);
SetErrorMessage("Out of memory");
return;
}
if (GIF_ERROR == GifQuantizeBuffer(
_width, _height, &_colors,
redBuff, greenBuff, blueBuff,
gifimgbuf, cmap->Colors
)){
free(gifimgbuf);
GifFreeMapObject(cmap);
SetErrorMessage("Unable to quantize image");
return;
}
int errcode;
gifWriteCbData buffinf = {NULL, 0};
GifFileType * gif;
gif = EGifOpen((void *) &buffinf, gifWriteCB, &errcode);
if (NULL == gif){
free(gifimgbuf);
GifFreeMapObject(cmap);
SetErrorMessage(GifErrorString(errcode));
return;
}
gif->SWidth = _width;
gif->SHeight = _height;
gif->SColorResolution = _cmapSize;
simg = GifMakeSavedImage(gif, NULL);
if (NULL == simg){
free(gifimgbuf);
EGifCloseFile(gif, &errcode); // will also free cmap
SetErrorMessage("Out of memory");
return;
}
simg->ImageDesc.Left = 0;
simg->ImageDesc.Top = 0;
simg->ImageDesc.Width = _width;
simg->ImageDesc.Height = _height;
simg->ImageDesc.Interlace = _interlaced;
simg->ImageDesc.ColorMap = cmap;
simg->RasterBits = gifimgbuf;
// for some reason giflib sometimes creates an invalid file if the global
// color table is not set as well
gif->SColorMap = cmap;
if (_trans){
ExtensionBlock ext;
// 1. assign transparent color index in color table
GraphicsControlBlock gcb = {0, false, 0, _colors++};
// 2. replace transparent pixels above threshold with this color
remapTransparentPixels(gifimgbuf, alphaBuff, _width, _height, gcb.TransparentColor, _threshold);
// 3. create a control block
size_t extlen = EGifGCBToExtension(&gcb, (GifByteType *) &ext);
if (GIF_ERROR == GifAddExtensionBlock(
&(simg->ExtensionBlockCount),
&(simg->ExtensionBlocks),
GRAPHICS_EXT_FUNC_CODE,
extlen,
(unsigned char *) &ext)
) {
EGifCloseFile(gif, &errcode);
SetErrorMessage("Out of memory");
return;
}
}
if (GIF_ERROR == EGifSpew(gif)){
EGifCloseFile(gif, &errcode);
SetErrorMessage(GifErrorString(gif->Error));
return;
}
//.........這裏部分代碼省略.........
示例13: DGifGetImageDesc
//讀取單個幀的圖片信息(圖片的上下左右坐標,幀的局部顏色空間等)
int
DGifGetImageDesc(GifFileType *GifFile)
{
unsigned int BitsPerPixel;
GifByteType Buf[3];
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
SavedImage *sp;
if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */
GifFile->Error = D_GIF_ERR_NOT_READABLE;
return GIF_ERROR;
}
//讀取當前幀的上下左右坐標
if (DGifGetWord(GifFile, &GifFile->Image.Left) == GIF_ERROR ||
DGifGetWord(GifFile, &GifFile->Image.Top) == GIF_ERROR ||
DGifGetWord(GifFile, &GifFile->Image.Width) == GIF_ERROR ||
DGifGetWord(GifFile, &GifFile->Image.Height) == GIF_ERROR)
return GIF_ERROR;
//讀取長度1字節的信息(即當前幀的Packed Field)
if (READ(GifFile, Buf, 1) != 1) {
GifFile->Error = D_GIF_ERR_READ_FAILED;
GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Image.ColorMap = NULL;
return GIF_ERROR;
}
//局部顏色空間的大小
BitsPerPixel = (Buf[0] & 0x07) + 1;
//判斷當前幀是否交錯模式
GifFile->Image.Interlace = (Buf[0] & 0x40) ? true : false;
/* Setup the colormap */
if (GifFile->Image.ColorMap) {
GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Image.ColorMap = NULL;
}
//判斷當前幀是否使用局部的顏色空間
if (Buf[0] & 0x80) {
unsigned int i;
GifFile->Image.ColorMap = GifMakeMapObject(1 << BitsPerPixel, NULL);
if (GifFile->Image.ColorMap == NULL) {
GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return GIF_ERROR;
}
//獲取局部顏色空間 並儲存到臨時的幀描述內
for (i = 0; i < GifFile->Image.ColorMap->ColorCount; i++) {
/* coverity[check_return] */
if (READ(GifFile, Buf, 3) != 3) {
GifFreeMapObject(GifFile->Image.ColorMap);
GifFile->Error = D_GIF_ERR_READ_FAILED;
GifFile->Image.ColorMap = NULL;
return GIF_ERROR;
}
GifFile->Image.ColorMap->Colors[i].Red = Buf[0];
GifFile->Image.ColorMap->Colors[i].Green = Buf[1];
GifFile->Image.ColorMap->Colors[i].Blue = Buf[2];
}
}
//判斷之前是否已經有儲存幀圖像
if (GifFile->SavedImages) {
//如果有已經儲存的幀圖像 需要重新分配空間
SavedImage* new_saved_images =
(SavedImage *)realloc(GifFile->SavedImages,
sizeof(SavedImage) * (GifFile->ImageCount + 1));
if (new_saved_images == NULL) {
GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return GIF_ERROR;
}
GifFile->SavedImages = new_saved_images;
} else {
if ((GifFile->SavedImages =
(SavedImage *) malloc(sizeof(SavedImage))) == NULL) {
GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return GIF_ERROR;
}
}
//指向新的SavedImage
sp = &GifFile->SavedImages[GifFile->ImageCount];
//寫入之前獲取的幀圖像描述
memcpy(&sp->ImageDesc, &GifFile->Image, sizeof(GifImageDesc));
//寫入局部顏色空間
if (GifFile->Image.ColorMap != NULL) {
sp->ImageDesc.ColorMap = GifMakeMapObject(
GifFile->Image.ColorMap->ColorCount,
GifFile->Image.ColorMap->Colors);
if (sp->ImageDesc.ColorMap == NULL) {
GifFile->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return GIF_ERROR;
}
}
//.........這裏部分代碼省略.........
示例14: CSLFetchBoolean
//.........這裏部分代碼省略.........
}
else
{
GDALColorTable *poCT = poBand->GetColorTable();
int nFullCount = 1;
while( nFullCount < poCT->GetColorEntryCount() )
nFullCount = nFullCount * 2;
psGifCT = GifMakeMapObject( nFullCount, NULL );
for( iColor = 0; iColor < poCT->GetColorEntryCount(); iColor++ )
{
GDALColorEntry sEntry;
poCT->GetColorEntryAsRGB( iColor, &sEntry );
psGifCT->Colors[iColor].Red = (GifByteType) sEntry.c1;
psGifCT->Colors[iColor].Green = (GifByteType) sEntry.c2;
psGifCT->Colors[iColor].Blue = (GifByteType) sEntry.c3;
}
for( ; iColor < nFullCount; iColor++ )
{
psGifCT->Colors[iColor].Red = 0;
psGifCT->Colors[iColor].Green = 0;
psGifCT->Colors[iColor].Blue = 0;
}
}
/* -------------------------------------------------------------------- */
/* Setup parameters. */
/* -------------------------------------------------------------------- */
if (EGifPutScreenDesc(hGifFile, nXSize, nYSize,
psGifCT->ColorCount, 255, psGifCT) == GIF_ERROR)
{
GifFreeMapObject(psGifCT);
GDALPrintGifError(hGifFile, "Error writing gif file.");
GIFAbstractDataset::myEGifCloseFile(hGifFile);
VSIFCloseL( fp );
return NULL;
}
GifFreeMapObject(psGifCT);
psGifCT = NULL;
/* Support for transparency */
int bNoDataValue;
double noDataValue = poBand->GetNoDataValue(&bNoDataValue);
if (bNoDataValue && noDataValue >= 0 && noDataValue <= 255)
{
unsigned char extensionData[4];
extensionData[0] = 1; /* Transparent Color Flag */
extensionData[1] = 0;
extensionData[2] = 0;
extensionData[3] = (unsigned char)noDataValue;
EGifPutExtension(hGifFile, 0xf9, 4, extensionData);
}
if (EGifPutImageDesc(hGifFile, 0, 0, nXSize, nYSize, bInterlace, NULL) == GIF_ERROR )
{
GDALPrintGifError(hGifFile, "Error writing gif file.");
GIFAbstractDataset::myEGifCloseFile(hGifFile);
VSIFCloseL( fp );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Loop over image, copying image data. */
示例15: gif_encode
void *
gif_encode(Image *image, int single, int *size)
{
int width = image->columns;
int height = image->rows;
int total = width * height;
GifByteType red[total];
GifByteType green[total];
GifByteType blue[total];
// Quantize the images using IM/GM first, to reduce
// their number of colors to 256.
int count = GetImageListLength(image);
QuantizeInfo info;
GetQuantizeInfo(&info);
info.dither = 0;
info.number_colors = NCOLORS;
QuantizeImage(&info, image);
if (count > 1) {
#ifdef _MAGICK_USES_IM
RemapImages(&info, image->next, image);
#else
MapImages(image->next, image, 0);
#endif
}
if (!acquire_image_pixels(image, red, green, blue)) {
return NULL;
}
size_t frame_size = sizeof(Frame) + total;
Frame *frames = malloc(frame_size * count);
ColorMapObject *palette = GifMakeMapObject(NCOLORS, NULL);
int palette_size = NCOLORS;
// Quantize again using giflib, since it yields a palette which produces
// better compression, reducing the file size by 20%. Note that this second
// quantization is very fast, because the image already has 256 colors, so
// its effect on performance is negligible.
if (GifQuantizeBuffer(width, height, &palette_size, red, green, blue, frames->data, palette->Colors) == GIF_ERROR) {
GifFreeMapObject(palette);
free(frames);
return NULL;
}
frames->width = width;
frames->height = height;
frames->duration = image->delay;
GifColorType *colors = palette->Colors;
Image *cur = image->next;
PixelCache *cache = pixel_cache_new();
unsigned char *p = (unsigned char*)frames;
int ii;
for (ii = 1; ii < count; ii++, cur = cur->next) {
p += frame_size;
Frame *frame = (Frame*)p;
frame->width = width;
frame->height = height;
frame->duration = cur->delay;
GifPixelType *data = frame->data;
if (!aprox_image_pixels(cur, colors, palette_size, cache, data)) {
GifFreeMapObject(palette);
free(frames);
pixel_cache_free(cache);
return NULL;
}
}
pixel_cache_free(cache);
void *ret = gif_save(image, palette, frames, count, frame_size, size);
GifFreeMapObject(palette);
free(frames);
return ret;
}