本文整理汇总了C++中DGifGetExtension函数的典型用法代码示例。如果您正苦于以下问题:C++ DGifGetExtension函数的具体用法?C++ DGifGetExtension怎么用?C++ DGifGetExtension使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DGifGetExtension函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
GifRecordType GIFAbstractDataset::FindFirstImage( GifFileType* hGifFile )
{
GifRecordType RecordType = TERMINATE_RECORD_TYPE;
while( DGifGetRecordType(hGifFile, &RecordType) != GIF_ERROR
&& RecordType != TERMINATE_RECORD_TYPE
&& RecordType != IMAGE_DESC_RECORD_TYPE )
{
/* Skip extension records found before IMAGE_DESC_RECORD_TYPE */
if (RecordType == EXTENSION_RECORD_TYPE)
{
int nFunction;
GifByteType *pExtData = nullptr;
if (DGifGetExtension(hGifFile, &nFunction, &pExtData) == GIF_ERROR)
break;
while (pExtData != nullptr)
{
if (DGifGetExtensionNext(hGifFile, &pExtData) == GIF_ERROR)
break;
}
}
}
return RecordType;
}
示例2: dGifGetExtension
value dGifGetExtension( value hdl )
{
CAMLparam1(hdl);
CAMLlocal3(ext,exts,res);
CAMLlocal1(newres);
GifFileType *GifFile = (GifFileType*) hdl;
int func;
GifByteType *extData;
exts = Val_int(0);
if (DGifGetExtension(GifFile,&func, &extData) == GIF_ERROR){
failwith("DGifGetExtension");
}
while( extData != NULL ){
ext= alloc_string(extData[0]);
memcpy(String_val(ext), &extData[1], extData[0]);
newres = alloc_small(2,0);
caml_modify_field(newres, 0, ext);
caml_modify_field(newres, 1, exts);
exts= newres;
DGifGetExtensionNext(GifFile, &extData);
}
res = alloc_small(2,0);
caml_modify_field(res,0, Val_int(func));
caml_modify_field(res,1, exts);
CAMLreturn(res);
}
示例3: gif_fileread
static GifRecordType
gif_fileread(struct gif_state *h)
{
GifRecordType RecordType;
GifByteType *Extension;
int ExtCode, rc;
const char *type;
for (;;) {
if (GIF_ERROR == DGifGetRecordType(h->gif,&RecordType)) {
if (FbiStuff::fim_filereading_debug())
FIM_FBI_PRINTF("gif: DGifGetRecordType failed\n");
PrintGifError();
return (GifRecordType)-1;
}
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
if (FbiStuff::fim_filereading_debug())
FIM_FBI_PRINTF("gif: IMAGE_DESC_RECORD_TYPE found\n");
return RecordType;
case EXTENSION_RECORD_TYPE:
if (FbiStuff::fim_filereading_debug())
FIM_FBI_PRINTF("gif: EXTENSION_RECORD_TYPE found\n");
for (rc = DGifGetExtension(h->gif,&ExtCode,&Extension);
NULL != Extension;
rc = DGifGetExtensionNext(h->gif,&Extension)) {
if (rc == GIF_ERROR) {
if (FbiStuff::fim_filereading_debug())
FIM_FBI_PRINTF("gif: DGifGetExtension failed\n");
PrintGifError();
return (GifRecordType)-1;
}
if (FbiStuff::fim_filereading_debug()) {
switch (ExtCode) {
case COMMENT_EXT_FUNC_CODE: type="comment"; break;
case GRAPHICS_EXT_FUNC_CODE: type="graphics"; break;
case PLAINTEXT_EXT_FUNC_CODE: type="plaintext"; break;
case APPLICATION_EXT_FUNC_CODE: type="appl"; break;
default: type="???"; break;
}
FIM_FBI_PRINTF("gif: extcode=0x%x [%s]\n",ExtCode,type);
}
}
break;
case TERMINATE_RECORD_TYPE:
if (FbiStuff::fim_filereading_debug())
FIM_FBI_PRINTF("gif: TERMINATE_RECORD_TYPE found\n");
return RecordType;
default:
if (FbiStuff::fim_filereading_debug())
FIM_FBI_PRINTF("gif: unknown record type [%d]\n",RecordType);
return (GifRecordType)-1;
}
}
}
示例4: fh_gif_getsize
int fh_gif_getsize(const char *name,int *x,int *y, int /*wanted_width*/, int /*wanted_height*/)
{
int px,py;
GifFileType *gft;
GifByteType *extension;
int extcode;
GifRecordType rt;
#if GIFLIB_MAJOR >= 5
int error;
gft=DGifOpenFileName(name, &error);
#else
gft=DGifOpenFileName(name);
#endif
if(gft==NULL) gflush;
do
{
if(DGifGetRecordType(gft,&rt) == GIF_ERROR) grflush;
switch(rt)
{
case IMAGE_DESC_RECORD_TYPE:
if(DGifGetImageDesc(gft)==GIF_ERROR) grflush;
px=gft->Image.Width;
py=gft->Image.Height;
*x=px; *y=py;
DGIFCLOSEFILE(gft);
return(FH_ERROR_OK);
break;
case EXTENSION_RECORD_TYPE:
if(DGifGetExtension(gft,&extcode,&extension)==GIF_ERROR) grflush;
while(extension!=NULL)
if(DGifGetExtensionNext(gft,&extension)==GIF_ERROR) grflush;
break;
default:
break;
}
}
while( rt!= TERMINATE_RECORD_TYPE );
DGIFCLOSEFILE(gft);
return(FH_ERROR_FORMAT);
}
示例5: fh_gif_getsize
int fh_gif_getsize(char *name,int *x,int *y)
{
int px,py;
GifFileType *gft;
GifByteType *extension;
int extcode;
GifRecordType rt;
gft=DGifOpenFileName(name);
if(gft==NULL) gflush;
do
{
if(DGifGetRecordType(gft,&rt) == GIF_ERROR) grflush;
switch(rt)
{
case IMAGE_DESC_RECORD_TYPE:
if(DGifGetImageDesc(gft)==GIF_ERROR) grflush;
px=gft->Image.Width;
py=gft->Image.Height;
*x=px; *y=py;
DGifCloseFile(gft);
return(FH_ERROR_OK);
break;
case EXTENSION_RECORD_TYPE:
if(DGifGetExtension(gft,&extcode,&extension)==GIF_ERROR) grflush;
while(extension!=NULL)
if(DGifGetExtensionNext(gft,&extension)==GIF_ERROR) grflush;
break;
default:
break;
}
}
while( rt!= TERMINATE_RECORD_TYPE );
DGifCloseFile(gft);
return(FH_ERROR_FORMAT);
}
示例6: img_load_gif
bool img_load_gif(img_t *img, const fileinfo_t *file)
{
GifFileType *gif;
GifRowType *rows = NULL;
GifRecordType rec;
ColorMapObject *cmap;
DATA32 bgpixel, *data, *ptr;
DATA32 *prev_frame = NULL;
Imlib_Image im;
int i, j, bg, r, g, b;
int x, y, w, h, sw, sh;
int px, py, pw, ph;
int intoffset[] = { 0, 4, 2, 1 };
int intjump[] = { 8, 8, 4, 2 };
int transp = -1;
unsigned int disposal = 0, prev_disposal = 0;
unsigned int delay = 0;
bool err = false;
if (img->multi.cap == 0) {
img->multi.cap = 8;
img->multi.frames = (img_frame_t*)
s_malloc(sizeof(img_frame_t) * img->multi.cap);
}
img->multi.cnt = img->multi.sel = 0;
img->multi.length = img->multi.repeat = 0;
#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
gif = DGifOpenFileName(file->path, NULL);
#else
gif = DGifOpenFileName(file->path);
#endif
if (gif == NULL) {
warn("could not open gif file: %s", file->name);
return false;
}
bg = gif->SBackGroundColor;
sw = gif->SWidth;
sh = gif->SHeight;
px = py = pw = ph = 0;
do {
if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
err = true;
break;
}
if (rec == EXTENSION_RECORD_TYPE) {
int ext_code;
GifByteType *ext = NULL;
DGifGetExtension(gif, &ext_code, &ext);
while (ext) {
if (ext_code == GRAPHICS_EXT_FUNC_CODE) {
if (ext[1] & 1)
transp = (int) ext[4];
else
transp = -1;
delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]);
if (delay)
delay = MAX(delay, MIN_GIF_DELAY);
disposal = (unsigned int) ext[1] >> 2 & 0x7;
} else if (ext_code == APPLICATION_EXT_FUNC_CODE) {
if (ext[0] == 11 && memcmp(ext+1, "NETSCAPE2.0", 11) == 0) {
DGifGetExtensionNext(gif, &ext);
if (ext && ext[0] == 3 && ext[1] == 1)
img->multi.repeat = ((int) ext[3] << 8 | (int) ext[2]) - 1;
}
}
ext = NULL;
DGifGetExtensionNext(gif, &ext);
}
} else if (rec == IMAGE_DESC_RECORD_TYPE) {
示例7: img_load_gif
bool img_load_gif(img_t *img, const fileinfo_t *file)
{
GifFileType *gif;
GifRowType *rows = NULL;
GifRecordType rec;
ColorMapObject *cmap;
DATA32 bgpixel, *data, *ptr;
DATA32 *prev_frame = NULL;
Imlib_Image im;
int i, j, bg, r, g, b;
int x, y, w, h, sw, sh;
int px, py, pw, ph;
int intoffset[] = { 0, 4, 2, 1 };
int intjump[] = { 8, 8, 4, 2 };
int transp = -1;
unsigned int disposal = 0, prev_disposal = 0;
unsigned int delay = 0;
bool err = false;
if (img->multi.cap == 0) {
img->multi.cap = 8;
img->multi.frames = (img_frame_t*)
s_malloc(sizeof(img_frame_t) * img->multi.cap);
}
img->multi.cnt = img->multi.sel = 0;
img->multi.length = 0;
#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
gif = DGifOpenFileName(file->path, NULL);
#else
gif = DGifOpenFileName(file->path);
#endif
if (gif == NULL) {
warn("could not open gif file: %s", file->name);
return false;
}
bg = gif->SBackGroundColor;
sw = gif->SWidth;
sh = gif->SHeight;
px = py = pw = ph = 0;
do {
if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
err = true;
break;
}
if (rec == EXTENSION_RECORD_TYPE) {
int ext_code;
GifByteType *ext = NULL;
DGifGetExtension(gif, &ext_code, &ext);
while (ext) {
if (ext_code == GRAPHICS_EXT_FUNC_CODE) {
if (ext[1] & 1)
transp = (int) ext[4];
else
transp = -1;
delay = 10 * ((unsigned int) ext[3] << 8 | (unsigned int) ext[2]);
disposal = (unsigned int) ext[1] >> 2 & 0x7;
}
ext = NULL;
DGifGetExtensionNext(gif, &ext);
}
} else if (rec == IMAGE_DESC_RECORD_TYPE) {
if (DGifGetImageDesc(gif) == GIF_ERROR) {
err = true;
break;
}
x = gif->Image.Left;
y = gif->Image.Top;
w = gif->Image.Width;
h = gif->Image.Height;
rows = (GifRowType*) s_malloc(h * sizeof(GifRowType));
for (i = 0; i < h; i++)
rows[i] = (GifRowType) s_malloc(w * sizeof(GifPixelType));
if (gif->Image.Interlace) {
for (i = 0; i < 4; i++) {
for (j = intoffset[i]; j < h; j += intjump[i])
DGifGetLine(gif, rows[j], w);
}
} else {
for (i = 0; i < h; i++)
DGifGetLine(gif, rows[i], w);
}
ptr = data = (DATA32*) s_malloc(sizeof(DATA32) * sw * sh);
cmap = gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap;
r = cmap->Colors[bg].Red;
g = cmap->Colors[bg].Green;
b = cmap->Colors[bg].Blue;
bgpixel = 0x00ffffff & (r << 16 | g << 8 | b);
for (i = 0; i < sh; i++) {
for (j = 0; j < sw; j++) {
if (i < y || i >= y + h || j < x || j >= x + w ||
rows[i-y][j-x] == transp)
{
if (prev_frame != NULL && (prev_disposal != 2 ||
//.........这里部分代码省略.........
示例8: loader_gif
unsigned char *
loader_gif(FILE *f, int *w, int *h, int *t)
{
unsigned char *data, *ptr;
GifFileType *gif;
GifRowType *rows;
GifRecordType rec;
ColorMapObject *cmap;
int i, j, done, bg, csize, r, g, b;
int intoffset[] = {0, 4, 2, 1};
int intjump[] = {8, 8, 4, 2};
int istransp, transp;
int fd;
done = 0;
istransp = 0;
fd = fileno(f);
/* Apparently rewind(f) isn't sufficient */
lseek(fd, (long) 0, 0);
gif = DGifOpenFileHandle(fd);
transp = -1;
data = NULL;
rows = NULL;
if (!gif)
return NULL;
do
{
if (DGifGetRecordType(gif, &rec) == GIF_ERROR)
{
PrintGifError();
rec = TERMINATE_RECORD_TYPE;
}
if ((rec == IMAGE_DESC_RECORD_TYPE) && (!done))
{
if (DGifGetImageDesc(gif) == GIF_ERROR)
{
PrintGifError();
rec = TERMINATE_RECORD_TYPE;
}
*w = gif->Image.Width;
*h = gif->Image.Height;
if(*h > 32767 || *w > 32767)
{
return NULL;
}
rows = malloc(*h * sizeof(GifRowType *));
if (!rows)
{
DGifCloseFile(gif);
return NULL;
}
data = _gdk_malloc_image(*w, *h);
if (!data)
{
DGifCloseFile(gif);
free(rows);
return NULL;
}
for (i = 0; i < *h; i++)
rows[i] = NULL;
for (i = 0; i < *h; i++)
{
rows[i] = malloc(*w * sizeof(GifPixelType));
if (!rows[i])
{
DGifCloseFile(gif);
for (i = 0; i < *h; i++)
if (rows[i])
free(rows[i]);
free(rows);
free(data);
return NULL;
}
}
if (gif->Image.Interlace)
{
for (i = 0; i < 4; i++)
{
for (j = intoffset[i]; j < *h; j += intjump[i])
DGifGetLine(gif, rows[j], *w);
}
}
else
{
for (i = 0; i < *h; i++)
DGifGetLine(gif, rows[i], *w);
}
done = 1;
}
else if (rec == EXTENSION_RECORD_TYPE)
{
int ext_code;
GifByteType *ext;
ext = NULL;
DGifGetExtension(gif, &ext_code, &ext);
//.........这里部分代码省略.........
示例9: Gif2Icon
//.........这里部分代码省略.........
exit(EXIT_FAILURE);
}
printf("image # %d\nimage left %d\nimage top %d\n",
ImageNum++,
GifFile->Image.Left, GifFile->Image.Top);
if (GifFile->Image.Interlace)
printf("interlaced\n");
if (GifFile->Image.ColorMap)
{
if (GifFile->Image.ColorMap->ColorCount >= (int)strlen(NameTable))
{
(void) fprintf(stderr,
"%s: global color map has unprintable pixels\n",
FileName);
exit(EXIT_FAILURE);
}
printf("image map\n");
for (i = 0; i < GifFile->Image.ColorMap->ColorCount; i++)
printf("\trgb %03d %03d %03d is %c\n",
GifFile->Image.ColorMap ->Colors[i].Red,
GifFile->Image.ColorMap ->Colors[i].Green,
GifFile->Image.ColorMap ->Colors[i].Blue,
NameTable[i]);
printf("end\n\n");
}
printf("image bits %d by %d\n",
GifFile->Image.Width, GifFile->Image.Height);
Line = (GifPixelType *) malloc(GifFile->Image.Width *
sizeof(GifPixelType));
for (i = 0; i < GifFile->Image.Height; i++) {
if (DGifGetLine(GifFile, Line, GifFile->Image.Width)
== GIF_ERROR) {
PrintGifError();
exit(EXIT_FAILURE);
}
for (cp = Line; cp < Line + GifFile->Image.Width; cp++)
putchar(NameTable[*cp]);
putchar('\n');
}
free((char *) Line);
putchar('\n');
break;
case EXTENSION_RECORD_TYPE:
if (DGifGetExtension(GifFile, &ExtCode, &Extension) == GIF_ERROR) {
PrintGifError();
exit(EXIT_FAILURE);
}
if (ExtCode == COMMENT_EXT_FUNC_CODE)
printf("comment\n");
else if (ExtCode == PLAINTEXT_EXT_FUNC_CODE)
printf("plaintext\n");
else if (isalpha(ExtCode))
printf("extension %02x # %c\n", ExtCode, ExtCode);
else
printf("extension %02x\n", ExtCode);
while (Extension != NULL) {
VisibleDumpBuffer((char *)(Extension + 1), Extension[0]);
putchar('\n');
if (DGifGetExtensionNext(GifFile, &Extension) == GIF_ERROR) {
PrintGifError();
exit(EXIT_FAILURE);
}
}
printf("end\n\n");
break;
case TERMINATE_RECORD_TYPE:
break;
default: /* Should be traps by DGifGetRecordType */
break;
}
}
while
(RecordType != TERMINATE_RECORD_TYPE);
/* Tell EMACS this is a picture... */
printf("# The following sets edit modes for GNU EMACS\n");
printf("# Local "); /* ...break this up, so that EMACS doesn't */
printf("Variables:\n"); /* get confused when visiting *this* file! */
printf("# mode:picture\n");
printf("# truncate-lines:t\n");
printf("# End:\n");
if (fdin == -1)
(void) printf("# End of %s dump\n", FileName);
if (DGifCloseFile(GifFile) == GIF_ERROR) {
PrintGifError();
exit(EXIT_FAILURE);
}
}
示例10: main
/******************************************************************************
Main sequence
******************************************************************************/
int main(int argc, char **argv)
{
GifFileType *GifFileIn = NULL, *GifFileOut = NULL;
GifRecordType RecordType;
int CodeSize, ExtCode, ErrorCode;
GifByteType *CodeBlock, *Extension;
/*
* Command-line processing goes here.
*/
/* Use stdin as input (note this also read screen descriptor in: */
if ((GifFileIn = DGifOpenFileHandle(0, &ErrorCode)) == NULL) {
PrintGifError(ErrorCode);
exit(EXIT_FAILURE);
}
/* Use the stdout as output: */
if ((GifFileOut = EGifOpenFileHandle(1, &ErrorCode)) == NULL) {
PrintGifError(ErrorCode);
exit(EXIT_FAILURE);
}
/* And dump out its screen information: */
if (EGifPutScreenDesc(GifFileOut,
GifFileIn->SWidth, GifFileIn->SHeight,
GifFileIn->SColorResolution, GifFileIn->SBackGroundColor,
GifFileIn->SColorMap) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* Scan the content of the input GIF file and load the image(s) in: */
do {
if (DGifGetRecordType(GifFileIn, &RecordType) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
if (DGifGetImageDesc(GifFileIn) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* Put image descriptor to out file: */
if (EGifPutImageDesc(GifFileOut,
GifFileIn->Image.Left, GifFileIn->Image.Top,
GifFileIn->Image.Width, GifFileIn->Image.Height,
GifFileIn->Image.Interlace,
GifFileIn->Image.ColorMap) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* Now read image itself in decoded form as we dont really */
/* care what we have there, and this is much faster. */
if (DGifGetCode(GifFileIn, &CodeSize, &CodeBlock) == GIF_ERROR ||
EGifPutCode(GifFileOut, CodeSize, CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
while (CodeBlock != NULL) {
if (DGifGetCodeNext(GifFileIn, &CodeBlock) == GIF_ERROR ||
EGifPutCodeNext(GifFileOut, CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
break;
case EXTENSION_RECORD_TYPE:
/* pass through extension records */
if (DGifGetExtension(GifFileIn, &ExtCode, &Extension) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (EGifPutExtensionLeader(GifFileOut, ExtCode) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (EGifPutExtensionBlock(GifFileOut,
Extension[0],
Extension + 1) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
while (Extension != NULL) {
if (DGifGetExtensionNext(GifFileIn, &Extension)==GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (Extension != NULL)
if (EGifPutExtensionBlock(GifFileOut,
Extension[0],
Extension + 1) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
if (EGifPutExtensionTrailer(GifFileOut) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
break;
case TERMINATE_RECORD_TYPE:
break;
default: /* Should be trapped by DGifGetRecordType */
break;
}
}
while (RecordType != TERMINATE_RECORD_TYPE);
if (DGifCloseFile(GifFileIn, &ErrorCode) == GIF_ERROR)
{
PrintGifError(ErrorCode);
if (GifFileIn != NULL) {
EGifCloseFile(GifFileIn, NULL);
}
exit(EXIT_FAILURE);
}
if (EGifCloseFile(GifFileOut, &ErrorCode) == GIF_ERROR)
//.........这里部分代码省略.........
示例11: CPLError
GDALDataset *GIFDataset::Open( GDALOpenInfo * poOpenInfo )
{
if( !Identify( poOpenInfo ) )
return NULL;
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The GIF driver does not support update access to existing"
" files.\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Open the file and ingest. */
/* -------------------------------------------------------------------- */
GifFileType *hGifFile;
VSILFILE *fp;
int nGifErr;
fp = VSIFOpenL( poOpenInfo->pszFilename, "r" );
if( fp == NULL )
return NULL;
hGifFile = GIFAbstractDataset::myDGifOpen( fp, VSIGIFReadFunc );
if( hGifFile == NULL )
{
VSIFCloseL( fp );
CPLError( CE_Failure, CPLE_OpenFailed,
"DGifOpen() failed for %s.\n"
"Perhaps the gif file is corrupt?\n",
poOpenInfo->pszFilename );
return NULL;
}
/* The following code enables us to detect GIF datasets eligible */
/* for BIGGIF driver even with an unpatched giflib */
/* -------------------------------------------------------------------- */
/* Find the first image record. */
/* -------------------------------------------------------------------- */
GifRecordType RecordType = TERMINATE_RECORD_TYPE;
while( DGifGetRecordType(hGifFile, &RecordType) != GIF_ERROR
&& RecordType != TERMINATE_RECORD_TYPE
&& RecordType != IMAGE_DESC_RECORD_TYPE )
{
/* Skip extension records found before IMAGE_DESC_RECORD_TYPE */
if (RecordType == EXTENSION_RECORD_TYPE)
{
int nFunction;
GifByteType *pExtData;
if (DGifGetExtension(hGifFile, &nFunction, &pExtData) == GIF_ERROR)
break;
while (pExtData != NULL)
{
if (DGifGetExtensionNext(hGifFile, &pExtData) == GIF_ERROR)
break;
}
}
}
if( RecordType == IMAGE_DESC_RECORD_TYPE &&
DGifGetImageDesc(hGifFile) != GIF_ERROR)
{
int width = hGifFile->SavedImages[0].ImageDesc.Width;
int height = hGifFile->SavedImages[0].ImageDesc.Height;
if ((double) width * (double) height > 100000000.0 )
{
CPLDebug( "GIF",
"Due to limitations of the GDAL GIF driver we deliberately avoid\n"
"opening large GIF files (larger than 100 megapixels).");
GIFAbstractDataset::myDGifCloseFile( hGifFile );
VSIFCloseL( fp );
return NULL;
}
}
GIFAbstractDataset::myDGifCloseFile( hGifFile );
VSIFSeekL( fp, 0, SEEK_SET);
hGifFile = GIFAbstractDataset::myDGifOpen( fp, VSIGIFReadFunc );
if( hGifFile == NULL )
{
VSIFCloseL( fp );
CPLError( CE_Failure, CPLE_OpenFailed,
"DGifOpen() failed for %s.\n"
"Perhaps the gif file is corrupt?\n",
poOpenInfo->pszFilename );
return NULL;
}
nGifErr = DGifSlurp( hGifFile );
if( nGifErr != GIF_OK || hGifFile->SavedImages == NULL )
{
//.........这里部分代码省略.........
示例12: DGifCloseFile
CPLErr BIGGIFDataset::ReOpen()
{
/* -------------------------------------------------------------------- */
/* If the file is already open, close it so we can restart. */
/* -------------------------------------------------------------------- */
if( hGifFile != NULL )
DGifCloseFile( hGifFile );
/* -------------------------------------------------------------------- */
/* If we are actually reopening, then we assume that access to */
/* the image data is not strictly once through sequential, and */
/* we will try to create a working database in a temporary */
/* directory to hold the image as we read through it the second */
/* time. */
/* -------------------------------------------------------------------- */
if( hGifFile != NULL )
{
GDALDriver *poGTiffDriver = (GDALDriver*) GDALGetDriverByName("GTiff");
if( poGTiffDriver != NULL )
{
/* Create as a sparse file to avoid filling up the whole file */
/* while closing and then destroying this temporary dataset */
const char* apszOptions[] = { "COMPRESS=LZW", "SPARSE_OK=YES", NULL };
CPLString osTempFilename = CPLGenerateTempFilename("biggif");
osTempFilename += ".tif";
poWorkDS = poGTiffDriver->Create( osTempFilename,
nRasterXSize, nRasterYSize, 1,
GDT_Byte, const_cast<char**>(apszOptions));
}
}
/* -------------------------------------------------------------------- */
/* Open */
/* -------------------------------------------------------------------- */
VSIFSeekL( fp, 0, SEEK_SET );
nLastLineRead = -1;
#if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
int nError;
hGifFile = DGifOpen( fp, VSIGIFReadFunc, &nError );
#else
hGifFile = DGifOpen( fp, VSIGIFReadFunc );
#endif
if( hGifFile == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"DGifOpen() failed. Perhaps the gif file is corrupt?\n" );
return CE_Failure;
}
/* -------------------------------------------------------------------- */
/* Find the first image record. */
/* -------------------------------------------------------------------- */
GifRecordType RecordType = TERMINATE_RECORD_TYPE;
while( DGifGetRecordType(hGifFile, &RecordType) != GIF_ERROR
&& RecordType != TERMINATE_RECORD_TYPE
&& RecordType != IMAGE_DESC_RECORD_TYPE )
{
/* Skip extension records found before IMAGE_DESC_RECORD_TYPE */
if (RecordType == EXTENSION_RECORD_TYPE)
{
int nFunction;
GifByteType *pExtData;
if (DGifGetExtension(hGifFile, &nFunction, &pExtData) == GIF_ERROR)
break;
while (pExtData != NULL)
{
if (DGifGetExtensionNext(hGifFile, &pExtData) == GIF_ERROR)
break;
}
}
}
if( RecordType != IMAGE_DESC_RECORD_TYPE )
{
DGifCloseFile( hGifFile );
hGifFile = NULL;
CPLError( CE_Failure, CPLE_OpenFailed,
"Failed to find image description record in GIF file." );
return CE_Failure;
}
if (DGifGetImageDesc(hGifFile) == GIF_ERROR)
{
DGifCloseFile( hGifFile );
hGifFile = NULL;
CPLError( CE_Failure, CPLE_OpenFailed,
"Image description reading failed in GIF file." );
return CE_Failure;
}
return CE_None;
//.........这里部分代码省略.........
示例13: DDGifSlurp
void DDGifSlurp(GifInfo *info, bool shouldDecode) {
GifRecordType RecordType;
GifByteType *ExtData;
int codeSize;
int ExtFunction;
do {
if (DGifGetRecordType(info->gifFilePtr, &RecordType) == GIF_ERROR)
return;
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
if (DGifGetImageDesc(info->gifFilePtr, !shouldDecode) == GIF_ERROR)
return;
const uint_fast16_t requiredScreenWidth = info->gifFilePtr->Image.Left + info->gifFilePtr->Image.Width;
const uint_fast16_t requiredScreenHeight = info->gifFilePtr->Image.Top + info->gifFilePtr->Image.Height;
if (requiredScreenWidth > info->gifFilePtr->SWidth || requiredScreenHeight > info->gifFilePtr->SHeight) {
if (shouldDecode) {
void *tmpRasterBits = realloc(info->rasterBits,
requiredScreenWidth * requiredScreenHeight * sizeof(GifPixelType));
if (tmpRasterBits == NULL) {
info->gifFilePtr->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return;
}
info->rasterBits = tmpRasterBits;
}
else {
info->gifFilePtr->SWidth = requiredScreenWidth;
info->gifFilePtr->SHeight = requiredScreenHeight;
}
}
if (shouldDecode) {
if (info->gifFilePtr->Image.Interlace) {
uint_fast16_t i, j;
/*
* The way an interlaced image should be read -
* offsets and jumps...
*/
uint_fast8_t InterlacedOffset[] = {0, 4, 2, 1};
uint_fast8_t InterlacedJumps[] = {8, 8, 4, 2};
/* Need to perform 4 passes on the image */
for (i = 0; i < 4; i++)
for (j = InterlacedOffset[i]; j < info->gifFilePtr->Image.Height; j += InterlacedJumps[i]) {
if (DGifGetLine(info->gifFilePtr, info->rasterBits + j * info->gifFilePtr->Image.Width,
info->gifFilePtr->Image.Width) == GIF_ERROR)
return;
}
}
else {
if (DGifGetLine(
info->gifFilePtr, info->rasterBits,
info->gifFilePtr->Image.Width * info->gifFilePtr->Image.Height) == GIF_ERROR)
return;
}
return;
}
else {
if (DGifGetCode(info->gifFilePtr, &codeSize, &ExtData) == GIF_ERROR)
return;
while (ExtData != NULL) {
if (DGifGetCodeNext(info->gifFilePtr, &ExtData) == GIF_ERROR)
return;
}
}
break;
case EXTENSION_RECORD_TYPE:
if (DGifGetExtension(info->gifFilePtr, &ExtFunction, &ExtData) == GIF_ERROR)
return;
if (!shouldDecode) {
GraphicsControlBlock *tmpInfos = realloc(info->controlBlock,
(info->gifFilePtr->ImageCount + 1) *
sizeof(GraphicsControlBlock));
if (tmpInfos == NULL) {
info->gifFilePtr->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return;
}
info->controlBlock = tmpInfos;
info->controlBlock[info->gifFilePtr->ImageCount].DelayTime = DEFAULT_FRAME_DURATION_MS;
if (readExtensions(ExtFunction, ExtData, info) == GIF_ERROR)
return;
}
while (ExtData != NULL) {
if (DGifGetExtensionNext(info->gifFilePtr, &ExtData,
&ExtFunction) == GIF_ERROR)
return;
if (!shouldDecode) {
if (readExtensions(ExtFunction, ExtData, info) == GIF_ERROR)
return;
}
}
break;
case TERMINATE_RECORD_TYPE:
break;
default: /* Should be trapped by DGifGetRecordType */
break;
//.........这里部分代码省略.........
示例14: DGifOpen
bool CxImageGIF::Decode(CxFile *fp)
{
if (fp == NULL) return false;
GifFileType *GifFile = NULL;
GifRecordType RecordType;
GifByteType *Extension;
GifColorType *ColorMap;
int i, j, Count, Row, Col, Width, Height, ExtCode, ColorMapSize;
static int InterlacedOffset[] = { 0, 4, 2, 1 }, /* The way Interlaced image should. */
InterlacedJumps[] = { 8, 8, 4, 2 }; /* be read - offsets and jumps... */
try
{
GifFile = DGifOpen(fp, readCxFile);
if (!Create(GifFile->SWidth,GifFile->SHeight,8,CXIMAGE_FORMAT_GIF))
throw "Can't allocate memory";
do
{
DGifGetRecordType(GifFile, &RecordType);
switch (RecordType)
{
case IMAGE_DESC_RECORD_TYPE:
DGifGetImageDesc(GifFile);
Row = GifFile->Image.Top; /* Image Position relative to Screen. */
Col = GifFile->Image.Left;
Width = GifFile->Image.Width;
Height = GifFile->Image.Height;
if (GifFile->Image.Left + GifFile->Image.Width > GifFile->SWidth ||
GifFile->Image.Top + GifFile->Image.Height > GifFile->SHeight)
throw "Image is not confined to screen dimension, aborted.\n";
if (GifFile->Image.Interlace)
{
/* Need to perform 4 passes on the images: */
for (Count = i = 0; i < 4; i++)
for (j = Row + InterlacedOffset[i]; j < Row + Height; j += InterlacedJumps[i])
DGifGetLine(GifFile, GetBits(GifFile->SHeight - j - 1) + Col, Width);
}
else {
for (i = 0; i < Height; i++)
DGifGetLine(GifFile,GetBits(GifFile->SHeight - Row++ - 1) + Col,Width);
}
break;
case EXTENSION_RECORD_TYPE:
/* Skip any extension blocks in file: */
DGifGetExtension(GifFile, &ExtCode, &Extension);
while (Extension != NULL)
DGifGetExtensionNext(GifFile, &Extension);
break;
default:
break;
}
}while (RecordType != TERMINATE_RECORD_TYPE);
ColorMap = (GifFile->Image.ColorMap ? GifFile->Image.ColorMap->Colors : GifFile->SColorMap->Colors);
ColorMapSize = GifFile->Image.ColorMap ? GifFile->Image.ColorMap->ColorCount : GifFile->SColorMap->ColorCount;
if(ColorMap && ColorMapSize)
{
RGBQUAD* ppal=GetPalette();
for (i=0; i < ColorMapSize; i++) {
ppal[i].rgbRed = ColorMap[i].Red;
ppal[i].rgbGreen = ColorMap[i].Green;
ppal[i].rgbBlue = ColorMap[i].Blue;
}
head.biClrUsed = ColorMapSize;
if(GifFile->SBackGroundColor)
{
info.nBkgndIndex = GifFile->SBackGroundColor;
info.nBkgndColor.rgbRed = ColorMap[info.nBkgndIndex].Red;
info.nBkgndColor.rgbGreen = ColorMap[info.nBkgndIndex].Green;
info.nBkgndColor.rgbBlue = ColorMap[info.nBkgndIndex].Blue;
}
}
DGifCloseFile(GifFile);
GifFile = NULL;
} catch (int errid) {
strncpy(info.szLastError,GifGetErrorMessage(errid),255);
if(GifFile != NULL) DGifCloseFile(GifFile);
return false;
} catch (char *message) {
strncpy(info.szLastError,message,255);
if(GifFile != NULL) DGifCloseFile(GifFile);
return false;
}
return true;
}
示例15: DoDisassemblyNum
/******************************************************************************
* Perform the disassembly operation - take one input files into few output. *
******************************************************************************/
static int DoDisassemblyNum(const char *InFileName, char *OutFileName, int FileNum)
{
int ExtCode, CodeSize, FileEmpty;
GifRecordType RecordType;
char CrntFileName[80], *p;
GifByteType *Extension, *CodeBlock;
GifFileType *GifFileIn = NULL, *GifFileOut = NULL;
int ErrorCode;
/* If name has type postfix, strip it out, and make sure name is less */
/* or equal to 6 chars, so we will have 2 chars in name for numbers. */
//strupr(OutFileName); /* Make sure all is upper case */
#if 0
printf("OutFileName : %s\n", OutFileName);
if ((p = strrchr(OutFileName, '.')) != NULL && strlen(p) <= 4) p[0] = 0;
if ((p = strrchr(OutFileName, '/')) != NULL ||
(p = strrchr(OutFileName, '\\')) != NULL ||
(p = strrchr(OutFileName, ':')) != NULL) {
if (strlen(p) > 7) p[7] = 0; /* p includes the '/', '\\', ':' char */
}
else {
/* Only name is given for current directory: */
//if (strlen(OutFileName) > 6) OutFileName[6] = 0;
}
printf("OutFileName : %s\n", OutFileName);
#endif
/* Open input file: */
if (InFileName != NULL) {
if ((GifFileIn = DGifOpenFileName(InFileName, &ErrorCode)) == NULL)
return QuitGifError(GifFileIn, GifFileOut);
}
else {
/* Use the stdin instead: */
if ((GifFileIn = DGifOpenFileHandle(0, &ErrorCode)) == NULL)
return QuitGifError(GifFileIn, GifFileOut);
}
/* Scan the content of GIF file and dump image(s) to seperate file(s): */
//sprintf(CrntFileName, "%s_%02d.gif", OutFileName, FileNum);
sprintf(CrntFileName, "%s", OutFileName);
if ((GifFileOut = EGifOpenFileName(CrntFileName, TRUE, &ErrorCode)) == NULL)
return QuitGifError(GifFileIn, GifFileOut);
FileEmpty = TRUE;
/* And dump out its exactly same screen information: */
if (EGifPutScreenDesc(GifFileOut,
GifFileIn->SWidth, GifFileIn->SHeight,
GifFileIn->SColorResolution, GifFileIn->SBackGroundColor,
GifFileIn->SColorMap) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
do {
if (DGifGetRecordType(GifFileIn, &RecordType) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
FileEmpty = FALSE;
if (DGifGetImageDesc(GifFileIn) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
/* Put same image descriptor to out file: */
if (EGifPutImageDesc(GifFileOut,
GifFileIn->Image.Left, GifFileIn->Image.Top,
GifFileIn->Image.Width, GifFileIn->Image.Height,
GifFileIn->Image.Interlace,
GifFileIn->Image.ColorMap) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
/* Now read image itself in decoded form as we dont */
/* really care what is there, and this is much faster. */
if (DGifGetCode(GifFileIn, &CodeSize, &CodeBlock) == GIF_ERROR
|| EGifPutCode(GifFileOut, CodeSize, CodeBlock) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
while (CodeBlock != NULL)
if (DGifGetCodeNext(GifFileIn, &CodeBlock) == GIF_ERROR ||
EGifPutCodeNext(GifFileOut, CodeBlock) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
break;
case EXTENSION_RECORD_TYPE:
FileEmpty = FALSE;
/* Skip any extension blocks in file: */
if (DGifGetExtension(GifFileIn, &ExtCode, &Extension)
== GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
if (EGifPutExtension(GifFileOut, ExtCode, Extension[0],
Extension) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
/* No support to more than one extension blocks, discard */
while (Extension != NULL)
if (DGifGetExtensionNext(GifFileIn, &Extension)
== GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
break;
case TERMINATE_RECORD_TYPE:
break;
//.........这里部分代码省略.........