当前位置: 首页>>代码示例>>C++>>正文


C++ DGifGetRecordType函数代码示例

本文整理汇总了C++中DGifGetRecordType函数的典型用法代码示例。如果您正苦于以下问题:C++ DGifGetRecordType函数的具体用法?C++ DGifGetRecordType怎么用?C++ DGifGetRecordType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DGifGetRecordType函数的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;
}
开发者ID:hdfeos,项目名称:gdal,代码行数:25,代码来源:gifabstractdataset.cpp

示例2: decode_gif_pixels

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;
}
开发者ID:vtervo,项目名称:gropes,代码行数:56,代码来源:map-raster.c

示例3: dGifGetRecordType

value dGifGetRecordType( value hdl )
{
  CAMLparam1(hdl);

  GifRecordType RecordType;
  if (DGifGetRecordType((GifFileType*) hdl, &RecordType) == GIF_ERROR) {
    failwith("DGifGetRecordType");
  }
  CAMLreturn(Val_int(RecordType));
}
开发者ID:philipdexter,项目名称:camlimages,代码行数:10,代码来源:gifread.c

示例4: 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;
	}
    }
}
开发者ID:phantasea,项目名称:fim,代码行数:55,代码来源:FbiStuffGif.cpp

示例5: load_image

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);
}
开发者ID:macx0r,项目名称:ipas,代码行数:43,代码来源:ipas.cpp

示例6: 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);
}
开发者ID:j00zek,项目名称:j00zeks-neutrino-mp-cst-next,代码行数:42,代码来源:gif.cpp

示例7: 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);
}
开发者ID:Pivosgroup,项目名称:aml-original-linux-buildroot,代码行数:37,代码来源:gif.c

示例8: 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 )
    {
//.........这里部分代码省略.........
开发者ID:GeospatialDaryl,项目名称:VS2013__00_GDAL_111_x64,代码行数:101,代码来源:gifdataset.cpp

示例9: main


//.........这里部分代码省略.........
    /* the GIF file parameters itself.					     */
    if ((ScreenBuffer = (GifRowType *)
	malloc(GifFile -> SHeight * sizeof(GifRowType *))) == NULL)
	    GIF_EXIT("Failed to allocate memory required, aborted.");

    Size = GifFile -> SWidth * sizeof(GifPixelType);/* Size in bytes of one row.*/
    if ((ScreenBuffer[0] = (GifRowType) malloc(Size)) == NULL)    /* First row. */
	GIF_EXIT("Failed to allocate memory required, aborted.");

    for (i = 0; i < GifFile -> SWidth; i++)  /* Set its color to BackGround. */
	ScreenBuffer[0][i] = GifFile -> SBackGroundColor;
    MaximumScreenHeight = GifFile -> SHeight - 1;
    for (i = 1; i < GifFile -> SHeight; i++) {
	/* Allocate the other rows, and set their color to background too: */
	if ((ScreenBuffer[i] = (GifRowType) malloc(Size)) == NULL) {
	    if (i > 30) {
		/* Free some memory for the BGI driver and auxilary. */
		for (j = 1; j < 28; j++)
	    	    free((char *) ScreenBuffer[i - j]);
	    	MaximumScreenHeight = i - 28;
	    	fprintf(stderr, "\n%s: Failed to allocate all memory required, last line %d.\n",
			PROGRAM_NAME, MaximumScreenHeight);
	    	break;
	    }
	    else
		GIF_EXIT("Failed to allocate memory required, aborted.");
	}

	memcpy(ScreenBuffer[i], ScreenBuffer[0], Size);
    }

    /* Scan the content of the GIF file and load the image(s) in: */
    do {
	if (DGifGetRecordType(GifFile, &RecordType) == GIF_ERROR) {
	    PrintGifError();
	    break;
	}
	switch (RecordType) {
	    case IMAGE_DESC_RECORD_TYPE:
		if (DGifGetImageDesc(GifFile) == GIF_ERROR) {
		    PrintGifError();
		    exit(-1);
		}

		Row = GifFile -> ITop; /* Image Position relative to Screen. */
		Col = GifFile -> ILeft;
		Width = GifFile -> IWidth;
		Height = GifFile -> IHeight;
		GifQprintf("\n%s: Image %d at (%d, %d) [%dx%d]:     ",
		    PROGRAM_NAME, ++ImageNum, Col, Row, Width, Height);
		if (GifFile -> ILeft + GifFile -> IWidth > GifFile -> SWidth ||
		   GifFile -> ITop + GifFile -> IHeight > GifFile -> SHeight) {
		    fprintf(stderr, "Image %d is not confined to screen dimension, aborted.\n");
		    exit(-2);
		}
		if (GifFile -> IInterlace) {
		    /* 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]) {
			    GifQprintf("\b\b\b\b%-4d", Count++);
			    if (DGifGetLine(GifFile,
				&ScreenBuffer[MIN(j, MaximumScreenHeight)][Col],
				Width) == GIF_ERROR) {
				PrintGifError();
				exit(-1);
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:67,代码来源:GIF2BGI.C

示例10: main

int main(int argc, char **argv) {
   //
   // local vars
   //
   GifFileType *GIFfile;
   GifRecordType GIFtype;
   GifByteType *GIFextension;
   GifPixelType *GIFline;
   uint32_t w[8],**lower_array,**upper_array;
   int x,y,z,i,j,k,n,p,imin,imax;
   int image_width,image_height,image_count,color_resolution,GIFcode,ret;
   float threshold,voxel_size;
   char comment[256],rules[255][20];
   struct fab_vars v;
   init_vars(&v);
   //
   // command line args
   //
   if (!((argc == 3) || (argc == 4) || (argc == 5) || (argc == 6))) {
      printf("command line: gif_stl in.gif out.stl [threshold [size [points [angle]]]]\n");
      printf("   in.gif = input GIF section file\n");
      printf("   out.stl = output STL file\n");
      printf("   threshold: surface intensity threshold (0 = min, 1 = max, default 0.5))\n");
      printf("   size = voxel size (mm, default from file))\n");
      printf("   points = points to interpolate per point (default 0)\n");
      printf("   to be implemented: angle = minimum relative face angle to decimate vertices (default 0)\n");
      exit(-1);
      }
   p = 0;
   threshold = 0.5;
   voxel_size = -1;
   image_width = -1;
   image_height = -1;
   image_count = -1;
   if (argc >= 4)
      sscanf(argv[3],"%f",&threshold);
   if (argc >= 5)
      sscanf(argv[4],"%f",&voxel_size);
   if (argc >= 6)
      sscanf(argv[5],"%d",&p);
   //
   // initialize the rule table
   //
   init_rules(rules);
   //
   // scan the file 
   //
   printf("read %s\n",argv[1]);
   color_resolution = -1;
#if GIFLIB_MAJOR >= 5
   GIFfile = DGifOpenFileName(argv[1], NULL);
#else
   GIFfile = DGifOpenFileName(argv[1]);
#endif
   if (GIFfile == NULL) {
      printf("gif_stl: oops -- can not open %s\n",argv[1]);
      exit(-1);
      }
   GIFline = malloc(MAX_LINE*sizeof(GifPixelType));
   imin = 256;
   imax = 0;
   do {
      DGifGetRecordType(GIFfile,&GIFtype);
      switch (GIFtype) {
         case IMAGE_DESC_RECORD_TYPE:
            DGifGetImageDesc(GIFfile);
            image_width = GIFfile->SWidth;
            image_height = GIFfile->SHeight;
            image_count = GIFfile->ImageCount;
            color_resolution = GIFfile->SColorResolution;
            for (y = 0; y < GIFfile->SHeight; ++y) {
               ret = DGifGetLine(GIFfile,GIFline,GIFfile->SWidth);
               if (ret != GIF_OK) {
                  printf("gif_stl: oops -- error reading line\n");
                  exit(-1);
                  }
               for (x = 0; x < GIFfile->SWidth; ++x) {
                  if (GIFline[x] < imin) imin = GIFline[x];
                  if (GIFline[x] > imax) imax = GIFline[x];
                  }
               }
            break;
         case EXTENSION_RECORD_TYPE:
            DGifGetExtension(GIFfile,&GIFcode,&GIFextension);
            if (GIFcode == COMMENT_EXT_FUNC_CODE) {
               n = GIFextension[0];
               for (i = 1; i <= n; ++i)
                  comment[i-1] = GIFextension[i];
               comment[n] = 0;
               if (voxel_size == -1)
                  sscanf(comment,"mm per pixel: %f;",&voxel_size);
               }
            while (GIFextension != NULL)
               DGifGetExtensionNext(GIFfile,&GIFextension);
            break;
         case SCREEN_DESC_RECORD_TYPE:
            DGifGetScreenDesc(GIFfile);
            break;
         case TERMINATE_RECORD_TYPE:
            break;
//.........这里部分代码省略.........
开发者ID:TheBeachLab,项目名称:kokoretro,代码行数:101,代码来源:gif_stl.c

示例11: 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) {
开发者ID:kkb7401,项目名称:sxiv,代码行数:74,代码来源:image.c

示例12: 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 ||
//.........这里部分代码省略.........
开发者ID:JulioJu,项目名称:sxiv,代码行数:101,代码来源:image.c

示例13: main

int main(int argc, char **argv) {
   //
   // local vars
   //
   GifFileType *GIFfile;
   GifRecordType GIFtype;
   GifByteType *GIFextension;
   GifPixelType *GIFline;
   uint32_t **lower_array,**upper_array;
   double **image_array;
   double f,fmin,fmax;
   int x,y,z,h,i,j,k,n,p;
   int image_width,image_height,image_count,color_resolution,GIFcode,ret;
   float pixel_size,arg,rx,ry,rz;
   char type,comment[256];
   struct fab_vars v;
   init_vars(&v);
   //
   // command line args
   //
   if (!((argc == 3) || (argc == 4) || (argc == 5) || (argc == 6) || (argc == 7) || (argc == 10))) {
      printf("command line: gif_png in.gif out.png [type [arg [points [size [rx ry rz]]]]]\n");
      printf("   in.gif = input gif file\n");
      printf("   out.png = output PNG file\n");
      printf("   type = 'z' of density, 'h' for height (default z)\n");
      printf("   arg = gamma for 'z', threshold for 'h' (default 1)\n");
      printf("   points = points to interpolate per point (linear, default 0)\n");
      printf("   size = voxel size (mm, default from file))\n");
      printf("   to be implemented: rx,ry,rz = x,y,z rotation angles (degrees; default 0)\n");
      exit(-1);
      }
   type = 'z';
   p = 0;
   arg = 1;
   rx = ry = rz = 0;
   pixel_size = -1;
   image_width = -1;
   image_height = -1;
   if (argc >= 4) {
      sscanf(argv[3],"%c",&type);
      if (!((type == 'z') || (type == 'h'))) {
         printf("gif_png: oops -- type must be 'z' or 'h'\n");
         exit(-1);
         }
   if (argc >= 5)
      sscanf(argv[4],"%f",&arg);
      }
   if (argc >= 6)
      sscanf(argv[5],"%d",&p);
   if (argc >= 7)
      sscanf(argv[6],"%f",&pixel_size);
   if (argc >= 10) {
      sscanf(argv[7],"%f",&rx);
      sscanf(argv[8],"%f",&ry);
      sscanf(argv[9],"%f",&rz);
      }
   //
   // scan the file 
   //
   printf("read %s\n",argv[1]);
   color_resolution = -1;
   GIFfile = DGifOpenFileName(argv[1]);
   if (GIFfile == NULL) {
      printf("gif_png: oops -- can not open %s\n",argv[1]);
      exit(-1);
      }
   GIFline = malloc(MAX_LINE*sizeof(GifPixelType));
   do {
      DGifGetRecordType(GIFfile,&GIFtype);
      switch (GIFtype) {
         case IMAGE_DESC_RECORD_TYPE:
            DGifGetImageDesc(GIFfile);
            image_width = GIFfile->SWidth;
            image_height = GIFfile->SHeight;
            image_count = GIFfile->ImageCount;
            color_resolution = GIFfile->SColorResolution;
            for (y = 0; y < GIFfile->SHeight; ++y) {
               ret = DGifGetLine(GIFfile,GIFline,GIFfile->SWidth);
               if (ret != GIF_OK) {
                  printf("gif_png: oops -- error reading line\n");
                  exit(-1);
                  }
               }
            break;
         case EXTENSION_RECORD_TYPE:
            DGifGetExtension(GIFfile,&GIFcode,&GIFextension);
            if (GIFcode == COMMENT_EXT_FUNC_CODE) {
               n = GIFextension[0];
               for (i = 1; i <= n; ++i)
                  comment[i-1] = GIFextension[i];
               comment[n] = 0;
               if (pixel_size == -1)
                  sscanf(comment,"mm per pixel: %f;",&pixel_size);
               }
            while (GIFextension != NULL)
               DGifGetExtensionNext(GIFfile,&GIFextension);
            break;
         case SCREEN_DESC_RECORD_TYPE:
            DGifGetScreenDesc(GIFfile);
            break;
//.........这里部分代码省略.........
开发者ID:fibasile,项目名称:osx_fab_src,代码行数:101,代码来源:gif_png.c

示例14: DGifOpen

int FileGIF::read_frame(VFrame *output, VFrame *input)
{
	data = input->get_data();
	offset = 0;
	size = input->get_compressed_size();

	GifFileType *gif_file;
	GifRowType *gif_buffer;
	gif_file = DGifOpen(this, input_func);
	
	
	if(gif_file == 0)
	{
		printf("FileGIF::read_frame %d: %s\n", __LINE__, GifErrorString());
		return 1;
	}
	gif_buffer = (GifRowType*)malloc(sizeof(GifRowType) * gif_file->SHeight);
	int row_size = gif_file->SWidth * sizeof(GifPixelType);
	gif_buffer[0] = (GifRowType)malloc(row_size);

	for(int i = 0; i < gif_file->SWidth; i++)
	{
		gif_buffer[0][i] = gif_file->SBackGroundColor;
	}

	for(int i = 0; i < gif_file->SHeight; i++)
	{
		gif_buffer[i] = (GifRowType)malloc(row_size);
		memcpy(gif_buffer[i], gif_buffer[0], row_size);
	}

	GifRecordType record_type;
	do
	{
		if(DGifGetRecordType(gif_file, &record_type) == GIF_ERROR)
		{
			printf("FileGIF::read_frame %d: %s\n", __LINE__, GifErrorString());
			break;
		}
		
		switch(record_type)
		{
			case IMAGE_DESC_RECORD_TYPE:
			{
				if(DGifGetImageDesc(gif_file) == GIF_ERROR)
				{
					printf("FileGIF::read_frame %d: %s\n", __LINE__, GifErrorString());
					break;
				}

				int row = gif_file->Image.Top;
				int col = gif_file->Image.Left;
				int width = gif_file->Image.Width;
				int height = gif_file->Image.Height;
				if(gif_file->Image.Left + gif_file->Image.Width > gif_file->SWidth ||
		 		  gif_file->Image.Top + gif_file->Image.Height > gif_file->SHeight)
				{
					DGifCloseFile(gif_file);
					for(int k = 0; k < gif_file->SHeight; k++)
					{
						free(gif_buffer[k]);
					}
					free(gif_buffer);
					return 1;
				}
				
				if (gif_file->Image.Interlace) 
				{
				    static int InterlacedOffset[] = { 0, 4, 2, 1 };
				    static int InterlacedJumps[] = { 8, 8, 4, 2 };
/* Need to perform 4 passes on the images: */
		    		for (int i = 0; i < 4; i++)
					{
						for (int j = row + InterlacedOffset[i]; 
							j < row + height;
							j += InterlacedJumps[i]) 
						{
			    			if (DGifGetLine(gif_file, 
								&gif_buffer[j][col],
								width) == GIF_ERROR) 
							{
								DGifCloseFile(gif_file);
								for(int k = 0; k < gif_file->SHeight; k++)
								{
									free(gif_buffer[k]);
								}
								free(gif_buffer);
								return 1;
			    			}
						}
					}
				}
				else 
				{
		    		for (int i = 0; i < height; i++) 
					{
						if (DGifGetLine(gif_file, &gif_buffer[row++][col],
							width) == GIF_ERROR) 
						{
							DGifCloseFile(gif_file);
//.........这里部分代码省略.........
开发者ID:petterreinholdtsen,项目名称:cinelerra-hv,代码行数:101,代码来源:filegif.C

示例15: DGifOpenFileName

/******************************************************************************
 This routine reads an entire GIF into core, hanging all its state info off
 the GifFileType pointer.  Call DGifOpenFileName() or DGifOpenFileHandle()
 first to initialize I/O.  Its inverse is EGifSpew().
*******************************************************************************/
int
DGifSlurp(GifFileType *GifFile)
{
    size_t ImageSize;
    GifRecordType RecordType;
    SavedImage *sp;
    GifByteType *ExtData;
    int ExtFunction;

    GifFile->ExtensionBlocks = NULL;
    GifFile->ExtensionBlockCount = 0;

    do {
        if (DGifGetRecordType(GifFile, &RecordType) == GIF_ERROR)
            return (GIF_ERROR);

        switch (RecordType) {
          case IMAGE_DESC_RECORD_TYPE:
              if (DGifGetImageDesc(GifFile) == GIF_ERROR)
                  return (GIF_ERROR);

              sp = &GifFile->SavedImages[GifFile->ImageCount - 1];
              /* Allocate memory for the image */
              if (sp->ImageDesc.Width < 0 && sp->ImageDesc.Height < 0 &&
                      sp->ImageDesc.Width > (INT_MAX / sp->ImageDesc.Height)) {
                  return GIF_ERROR;
              }
              ImageSize = sp->ImageDesc.Width * sp->ImageDesc.Height;

              if (ImageSize > (SIZE_MAX / sizeof(GifPixelType))) {
                  return GIF_ERROR;
              }
              sp->RasterBits = (unsigned char *)malloc(ImageSize *
                      sizeof(GifPixelType));

              if (sp->RasterBits == NULL) {
                  return GIF_ERROR;
              }

	      if (sp->ImageDesc.Interlace) {
		  int i, j;
		   /* 
		    * The way an interlaced image should be read - 
		    * offsets and jumps...
		    */
		  int InterlacedOffset[] = { 0, 4, 2, 1 };
		  int InterlacedJumps[] = { 8, 8, 4, 2 };
		  /* Need to perform 4 passes on the image */
		  for (i = 0; i < 4; i++)
		      for (j = InterlacedOffset[i]; 
			   j < sp->ImageDesc.Height;
			   j += InterlacedJumps[i]) {
			  if (DGifGetLine(GifFile, 
					  sp->RasterBits+j*sp->ImageDesc.Width, 
					  sp->ImageDesc.Width) == GIF_ERROR)
			      return GIF_ERROR;
		      }
	      }
	      else {
		  if (DGifGetLine(GifFile,sp->RasterBits,ImageSize)==GIF_ERROR)
		      return (GIF_ERROR);
	      }

              if (GifFile->ExtensionBlocks) {
                  sp->ExtensionBlocks = GifFile->ExtensionBlocks;
                  sp->ExtensionBlockCount = GifFile->ExtensionBlockCount;

                  GifFile->ExtensionBlocks = NULL;
                  GifFile->ExtensionBlockCount = 0;
              }
              break;

          case EXTENSION_RECORD_TYPE:
              if (DGifGetExtension(GifFile,&ExtFunction,&ExtData) == GIF_ERROR)
                  return (GIF_ERROR);
	      /* Create an extension block with our data */
	      if (GifAddExtensionBlock(&GifFile->ExtensionBlockCount,
				       &GifFile->ExtensionBlocks, 
				       ExtFunction, ExtData[0], &ExtData[1])
		  == GIF_ERROR)
		  return (GIF_ERROR);
              while (ExtData != NULL) {
                  if (DGifGetExtensionNext(GifFile, &ExtData) == GIF_ERROR)
                      return (GIF_ERROR);
                  /* Continue the extension block */
		  if (ExtData != NULL)
		      if (GifAddExtensionBlock(&GifFile->ExtensionBlockCount,
					       &GifFile->ExtensionBlocks,
					       CONTINUE_EXT_FUNC_CODE, 
					       ExtData[0], &ExtData[1]) == GIF_ERROR)
                      return (GIF_ERROR);
              }
              break;

          case TERMINATE_RECORD_TYPE:
//.........这里部分代码省略.........
开发者ID:9miao,项目名称:CrossApp,代码行数:101,代码来源:dgif_lib.c


注:本文中的DGifGetRecordType函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。