PixRectArray::PixRectArray(const StringArray &fileNames, StringArray &errors) {
  USES_CONVERSION;
  m_updateCounter = 0;
  for(size_t i = 0; i < fileNames.size(); i++) {
    const String &name = fileNames[i];
    try {
      if(FileNameSplitter(name).getExtension().equalsIgnoreCase(_T(".gif"))) {
        int error;
        const char *namea = T2A(name.cstr());
        GifFileType *gifFile = DGifOpenFileName(namea, &error);
        if(gifFile == NULL) {
          throwException(_T("%s"), GifErrorString(error));
        }
        if(DGifSlurp(gifFile) != GIF_OK) {
          const String msg = GifErrorString(gifFile->Error);
          DGifCloseFile(gifFile, &error);
          throwException(_T("%s"), msg.cstr());
        }
        const int imageCount   = gifFile->ImageCount;

        for(int k = 0; k < imageCount; k++) {
          add(new GifPixRect(gifFile, k));
        }
        DGifCloseFile(gifFile, &error);
      } else {
        add(GifPixRect::load(name));
      }
    } catch(Exception e) {
      errors.add(e.what());
    }
  }
}
Example #2
0
/*
 * This function cleans up the gif object after the decode completes
 * It is used in a SkAutoTCallIProc template
 */
void SkGifCodec::CloseGif(GifFileType* gif) {
#if GIFLIB_MAJOR < 5 || (GIFLIB_MAJOR == 5 && GIFLIB_MINOR == 0)
    DGifCloseFile(gif);
#else
    DGifCloseFile(gif, nullptr);
#endif
}
Example #3
0
int GIFAbstractDataset::myDGifCloseFile( GifFileType *hGifFile )
{
#if defined(GIFLIB_MAJOR) && ((GIFLIB_MAJOR == 5 && GIFLIB_MINOR >= 1) || GIFLIB_MAJOR > 5)
    int nErrorCode;
    return DGifCloseFile( hGifFile, &nErrorCode );
#else
    return DGifCloseFile( hGifFile );
#endif
}
Example #4
0
bool compress_custom(void* input_data, InputFunc input_func,
    void* output_data, OutputFunc output_func, int sample_size)
{
  GifFileType* input_gif = NULL;
  GifFileType* output_gif = NULL;
  int result = GIF_ERROR;

  // Check sample
  if (sample_size <= 0) {
    return false;
  }

  input_gif = DGifOpen(input_data, input_func, &error_code);
  if (input_gif == NULL) {
    LOGE(EMSG("Can't open input gif"));
    return false;
  }

  DGifSlurp(input_gif);

  if (input_gif->ImageCount == 0) {
    LOGE(EMSG("Gif frame count is 0"));
    DGifCloseFile(input_gif, &error_code);
    return false;
  }

  // Save gif
  output_gif = EGifOpen(output_data, output_func, &error_code);
  if (output_gif == NULL) {
    LOGE(EMSG("Can't open output gif"));
    DGifCloseFile(input_gif, &error_code);
    return false;
  }

  if (do_compress(input_gif, output_gif, sample_size)) {
    result = EGifSpew(output_gif);
  }

  // Free
  GifFreeExtensions(&output_gif->ExtensionBlockCount, &output_gif->ExtensionBlocks);
  if (output_gif->SavedImages) {
    GifFreeSavedImages(output_gif);
    output_gif->SavedImages = NULL;
  }

  // Close gif
  DGifCloseFile(input_gif, &error_code);

  return result == GIF_OK;
}
Example #5
0
value dGifCloseFile( value hdl )
{
  CAMLparam1(hdl);

  /* For the bug libungif/giflib 4.1.0 */
  /* This may add a new memory leak, but it is better than having 
     segmentation faults */
  ((GifFileType *)hdl)->Image.ColorMap = NULL; 

#if (GIFLIB_MAJOR <= 4)
  DGifCloseFile( (GifFileType *) hdl);
#else
  DGifCloseFile( (GifFileType *) hdl, NULL );
#endif
  CAMLreturn0;
}
Image*
readGifFile ( int infile )
{
  Image          *img = 0;

#if defined(INCLUDE_GIF)

  /*
   * we don't use DGifOpenFile because file io might be intercepted
   * (because of threading)
   */
  FileSource     fileSrc;
  GifFileType    *gf;

  fileSrc.fd = infile;

  if ( !(gf = DGifOpen( &fileSrc, readGifFileSource)) )
	return 0;

  img = readGif( gf);

  DGifCloseFile( gf);
#endif

  return img;
}
Example #7
0
/******************************************************************************
* Close both input and output file (if open), and exit.			      *
******************************************************************************/
static void QuitGifError(GifFileType *GifFileIn, GifFileType *GifFileOut)
{
    PrintGifError();
    if (GifFileIn != NULL) DGifCloseFile(GifFileIn);
    if (GifFileOut != NULL) EGifCloseFile(GifFileOut);
    exit(EXIT_FAILURE);
}
Example #8
0
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);
}
Example #9
0
int main(int argc, char **argv) {
  argv++;
  if(!*argv) usage();

  int errorCode;
  GifFileType *gifFile = DGifOpenFileName(*argv, &errorCode);
  if(gifFile == NULL) {
    printf("Error:%s\n", GifErrorString(errorCode));
    exit(-1);
  }
  CHECKGIFOK(DGifSlurp(gifFile));

  _tprintf(_T("GifFile:Size:(%d,%d)\n"), gifFile->SWidth, gifFile->SHeight);
  _tprintf(_T("GifFile:BackgroundColor:%d, AspectByte:%d, ColorResultion:%d\n"), gifFile->SBackGroundColor, gifFile->AspectByte, gifFile->SColorResolution);
  _tprintf(_T("GifFile ")); dumpImageDesc(gifFile->Image);
  _tprintf(_T("GifFile:")); dumpColorMap(gifFile->SColorMap);
  _tprintf(_T("GifFile.ExtentionBlocks:\n"));
  dumpExtensionBlocks(gifFile->ExtensionBlocks, gifFile->ExtensionBlockCount);

  for(int i = 0; i < gifFile->ImageCount; i++) {
    dumpSavedImage(i, gifFile->SavedImages[i]);
  }

  if(DGifCloseFile(gifFile, &errorCode) != GIF_OK) {
    CHECKGIFOK(errorCode);
  }

  return 0;
}
Example #10
0
/******************************************************************************
* Close both input and output file (if open), and exit.			      *
******************************************************************************/
static void QuitGifError(GifFileType *GifFileIn, GifFileType *GifFileOut)
{
    fprintf(stderr, "\nFollowing unrecoverable error occured:");
    PrintGifError();
    if (GifFileIn != NULL) DGifCloseFile(GifFileIn);
    if (GifFileOut != NULL) EGifCloseFile(GifFileOut);
    exit(EXIT_FAILURE);
}
void AnimatedImage::load(CWnd *parent, ByteInputStream &in) {
  int error;
  GifFileType *gifFile = DGifOpen(&in, readGifStreamFunction, &error);
  if(gifFile == NULL) {
    THROWGIFERROR(error);
  }
  try {
    if(DGifSlurp(gifFile) != GIF_OK) {
      THROWGIFERROR(gifFile->Error);
    }
    createFromGifFile(parent, gifFile);
    DGifCloseFile(gifFile, &error);
  } catch(...) {
    DGifCloseFile(gifFile, &error);
    throw;
  }
}
Example #12
0
MCGIFImageLoader::~MCGIFImageLoader()
{
	if (m_gif != nil)
	{
		int t_error_code;
		DGifCloseFile(m_gif, &t_error_code);
		m_gif = nil;
	}
}
Example #13
0
/******************************************************************************
* Close both input and output file (if open), and exit.			      *
******************************************************************************/
static int QuitGifError(GifFileType *GifFileIn, GifFileType *GifFileOut)
{
	int ErrorCode;
//    PrintGifError(ErrorCode);
    if (GifFileIn != NULL) DGifCloseFile(GifFileIn, &ErrorCode);
    if (GifFileOut != NULL) EGifCloseFile(GifFileOut, &ErrorCode);
    //exit(1);
	return -1;
}
Example #14
0
static int DGifCloseMem(GifFileType *gifFile)
{
	if (gifFile->UserData != NULL)
	{
		GifMemoryType *gifMemoryType = (GifMemoryType *) gifFile->UserData;
		gif_free(gifMemoryType);
	}
	return DGifCloseFile(gifFile);
}
Example #15
0
static int decode_gif_pixels(struct gps_map *map,
			     unsigned char *out, int x, int y, int width,
			     int height, int bpp, int row_stride)
{
	struct raster_map *raster_map = map->data;
	GifFileType *gf;
	GifRecordType record_type;
	int r;

	if (bpp != 24)
		return -1;
	gf = DGifOpenFileName(raster_map->bitmap_filename);
	if (gf == NULL) {
		gps_error("%s: %s", raster_map->bitmap_filename, strerror(errno));
		return -1;
	}
	r = -1;
	do {
		if (DGifGetRecordType(gf, &record_type) == GIF_ERROR) {
			PrintGifError();
			goto fail;
		}
		switch (record_type) {
		case IMAGE_DESC_RECORD_TYPE:
			if (DGifGetImageDesc(gf) == GIF_ERROR) {
				PrintGifError();
				goto fail;
			}
			if (gf->Image.Width != map->width ||
			    gf->Image.Height != map->height) {
				gps_error("%s: GIF subimages not supported",
					  raster_map->bitmap_filename);
				goto fail;
			}
			if (gf->Image.Interlace) {
				gps_error("%s: interlaced GIFs not supported",
					  raster_map->bitmap_filename);
				goto fail;
			}
			output_gif_pixels(map, gf, x, y, width, height, row_stride, out);
			break;
		case EXTENSION_RECORD_TYPE:
			gps_error("%s: GIF extensions not supported",
				  raster_map->bitmap_filename);
			goto fail;
		case UNDEFINED_RECORD_TYPE:
		case SCREEN_DESC_RECORD_TYPE:
		case TERMINATE_RECORD_TYPE:
			break;
		}
	} while (record_type != IMAGE_DESC_RECORD_TYPE);
	r = 0;
fail:
	DGifCloseFile(gf);
	return r;
}
Example #16
0
GifFilesCloser::~GifFilesCloser() {
    if (mGifIn) {
        DGifCloseFile(mGifIn);
        mGifIn = NULL;
    }
    if (mGifOut) {
        EGifCloseFile(mGifOut);
        mGifOut = NULL;
    }
}
Example #17
0
BIGGIFDataset::~BIGGIFDataset()

{
    FlushCache();
    if( hGifFile )
        DGifCloseFile( hGifFile );
    if( fp != NULL )
        VSIFCloseL( fp );

    CloseDependentDatasets();
}
void cleanUp(GifInfo *info) {
	free(info->backupPtr);
	info->backupPtr = NULL;
	free(info->controlBlock);
	info->controlBlock = NULL;
	free(info->rasterBits);
	info->rasterBits = NULL;
	free(info->comment);
	info->comment = NULL;

	DGifCloseFile(info->gifFilePtr);
	free(info);
}
Example #19
0
int main(int argc, char **argv)
{
    int	i, ErrorCode;
    GifFileType *GifFileIn, *GifFileOut = (GifFileType *)NULL;

    if ((GifFileIn = DGifOpenFileHandle(0, &ErrorCode)) == NULL) {
	PrintGifError(ErrorCode);
	exit(EXIT_FAILURE);
    }
    if (DGifSlurp(GifFileIn) == GIF_ERROR) {
	PrintGifError(GifFileIn->Error);
	exit(EXIT_FAILURE);
    }
    if ((GifFileOut = EGifOpenFileHandle(1, &ErrorCode)) == NULL) {
	PrintGifError(ErrorCode);
	exit(EXIT_FAILURE);
    }

    /*
     * Your operations on in-core structures go here.  
     * This code just copies the header and each image from the incoming file.
     */
    GifFileOut->SWidth = GifFileIn->SWidth;
    GifFileOut->SHeight = GifFileIn->SHeight;
    GifFileOut->SColorResolution = GifFileIn->SColorResolution;
    GifFileOut->SBackGroundColor = GifFileIn->SBackGroundColor;
    GifFileOut->SColorMap = GifMakeMapObject(
				 GifFileIn->SColorMap->ColorCount,
				 GifFileIn->SColorMap->Colors);

    for (i = 0; i < GifFileIn->ImageCount; i++)
	(void) GifMakeSavedImage(GifFileOut, &GifFileIn->SavedImages[i]);

    /*
     * Note: don't do DGifCloseFile early, as this will
     * deallocate all the memory containing the GIF data!
     *
     * Further note: EGifSpew() doesn't try to validity-check any of this
     * data; it's *your* responsibility to keep your changes consistent.
     * Caveat hacker!
     */
    if (EGifSpew(GifFileOut) == GIF_ERROR)
	PrintGifError(GifFileOut->Error);

    if (DGifCloseFile(GifFileIn, &ErrorCode) == GIF_ERROR)
	PrintGifError(ErrorCode);
    if (EGifCloseFile(GifFileOut, &ErrorCode) == GIF_ERROR)
	PrintGifError(ErrorCode);

    return 0;
}
Example #20
0
File: gif.c Project: UkCvs/commando
int fh_gif_getsize(const char *name,int *x,int *y, int wanted_width, int wanted_height)
{
	int err = 0;
	int px,py;
	GifFileType *gft;
	GifByteType *extension;
	int extcode;
	GifRecordType rt;

	gft=DGifOpenFileName(name, &err);
	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, &err);
				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, &err);
	return(FH_ERROR_FORMAT);
}
SkGIFMovie::SkGIFMovie(SkStream* stream)
{
    fGIF = DGifOpen( stream, Decode );
    if (NULL == fGIF)
        return;

    if (DGifSlurp(fGIF) != GIF_OK)
    {
        DGifCloseFile(fGIF);
        fGIF = NULL;
    }
    fCurrIndex = -1;
    fLastDrawIndex = -1;
}
Example #22
0
inline bool
GIFInput::close (void)
{
    if (m_gif_file) {
        if (DGifCloseFile (m_gif_file) == GIF_ERROR) {
            error ("Error trying to close the file.");
            return false;
        }
        m_gif_file = NULL;
    }
    m_cached_data.clear ();

    return true;
}
Example #23
0
static void
gif_done(void *data)
{
    struct gif_state *h = (struct gif_state *) data;

    if (FbiStuff::fim_filereading_debug())
	FIM_FBI_PRINTF("gif: done, cleaning up\n");
    DGifCloseFile(h->gif);
    fclose(h->infile);
    if (h->il)
	fim_free(h->il);
    fim_free(h->row);
    fim_free(h);
}
Example #24
0
static int read_gif_header(struct gps_map *map)
{
	GifFileType *gif_file;
	struct raster_map *raster_map = map->data;

	gif_file = DGifOpenFileName(raster_map->bitmap_filename);
	if (gif_file == NULL) {
		gps_error("%s: %s", raster_map->bitmap_filename, strerror(errno));
		return -1;
	}
	map->width = gif_file->SWidth;
	map->height = gif_file->SHeight;
	DGifCloseFile(gif_file);
	return 0;
}
void cleanUp(GifInfo *info) {
    info->surfaceDescriptor = NULL;
    free(info->backupPtr);
    info->backupPtr = NULL;
    free(info->controlBlock);
    info->controlBlock = NULL;
    free(info->rasterBits);
    info->rasterBits = NULL;
    free(info->comment);
    info->comment = NULL;

    GifFileType *GifFile = info->gifFilePtr;
    DGifCloseFile(GifFile);
    free(info);
}
static GifFileType *loadGif(ByteInputStream &in) {
  int error;
  GifFileType *gf = DGifOpen(&in, readGifStreamFunction, &error);
  if(gf == NULL) {
    THROWGIFERROR(error);
  }
  try {
    if(DGifSlurp(gf) != GIF_OK) {
      THROWGIFERROR(gf->Error);
    }
    return gf;
  } catch(...) {
    DGifCloseFile(gf, &error);
    throw;
  }
}
Example #27
0
static ULONG WINAPI GifDecoder_Release(IWICBitmapDecoder *iface)
{
    GifDecoder *This = (GifDecoder*)iface;
    ULONG ref = InterlockedDecrement(&This->ref);

    TRACE("(%p) refcount=%u\n", iface, ref);

    if (ref == 0)
    {
        This->lock.DebugInfo->Spare[0] = 0;
        DeleteCriticalSection(&This->lock);
        DGifCloseFile(This->gif);
        HeapFree(GetProcessHeap(), 0, This);
    }

    return ref;
}
Example #28
0
SkGIFMovie::SkGIFMovie(SkStream* stream)
{
#if GIFLIB_MAJOR < 5
    fGIF = DGifOpen( stream, Decode );
#else
    fGIF = DGifOpen( stream, Decode, NULL );
#endif
    if (NULL == fGIF)
        return;

    if (DGifSlurp(fGIF) != GIF_OK)
    {
        DGifCloseFile(fGIF);
        fGIF = NULL;
    }
    fCurrIndex = -1;
    fLastDrawIndex = -1;
}
Example #29
0
File: ipas.cpp Project: macx0r/ipas
image* load_image (char* file, image_format fmt) {
  image* img = NULL;
  if (fmt == imgIRMID) {
    FILE* fp;
    fp = fopen (file, "r");
    image simage;
    fread (&simage, sizeof(image), 1, fp);
    img = (image*) malloc (simage.size);
    fseek (fp, 0, SEEK_SET);
    fread (img, simage.size, 1, fp);
    fclose (fp);
  } else if (fmt == imgGIF) {
    GifFileType* GifFileIn = DGifOpenFileName (file);
    int size = GifFileIn->SWidth * GifFileIn->SHeight * sizeof (rtbyte) + sizeof (image) - sizeof (rtbyte);
    img = (image*) malloc (size);
    img->size = size;
    img->dimx = GifFileIn->SWidth;
    img->dimy = GifFileIn->SHeight;
    img->dimc = 1;
    img->dimz = 1;
    img->dimt = 1;
    img->xyz = img->xy = img->dimx * img->dimy;
    img->len = img->xy * sizeof (rdword);
    img->clr = clrmGrey;

    GifRecordType record;
    GifRowType pixels = (GifRowType) new GifPixelType[img->xy];
    do {
      DGifGetRecordType(GifFileIn, &record);
      if (record != IMAGE_DESC_RECORD_TYPE)
        continue;
      DGifGetImageDesc (GifFileIn);
      for (int row = 0; row < img->dimy; ++row)
        DGifGetLine (GifFileIn, pixels + row * img->dimx, img->dimx);
    } while (record != TERMINATE_RECORD_TYPE);

    for (uint n = 0; n < img->xy; ++n)
      data(img)[n] = (rtbyte)pixels[n];

    DGifCloseFile (GifFileIn);
  }
  return (img);
}
BIGGIFDataset::~BIGGIFDataset()

{
    FlushCache();
    if( hGifFile )
        DGifCloseFile( hGifFile );
    if( fp != NULL )
        VSIFCloseL( fp );

    if( poWorkDS != NULL )
    {
        CPLString osTempFilename = poWorkDS->GetDescription();

        GDALClose( (GDALDatasetH) poWorkDS );
        poWorkDS = NULL;

        GDALDriver *poGTiff = (GDALDriver *) GDALGetDriverByName( "GTiff" );
        poGTiff->Delete( osTempFilename );
    }
}