这篇教程C++ DGifGetImageDesc函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中DGifGetImageDesc函数的典型用法代码示例。如果您正苦于以下问题:C++ DGifGetImageDesc函数的具体用法?C++ DGifGetImageDesc怎么用?C++ DGifGetImageDesc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了DGifGetImageDesc函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: img_load_gif/* Originally based on, but in its current form merely inspired by Imlib2's * src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler. */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 intoffset[] = { 0, 4, 2, 1 }; int intjump[] = { 8, 8, 4, 2 }; int transp = -1; 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 = 0; img->multi.sel = 0; gif = DGifOpenFileName(file->path); if (gif == NULL) { warn("could not open gif file: %s", file->name); return false; } bg = gif->SBackGroundColor; sw = gif->SWidth; sh = gif->SHeight; 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 == 0xf9) { 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); /* TODO: handle disposal method, section 23.c.iv of http://www.w3.org/Graphics/GIF/spec-gif89a.txt */ } 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) *ptr = prev_frame[i * sw + j];//.........这里部分代码省略.........
开发者ID:paradigm,项目名称:sxiv,代码行数:101,
示例2: CPLErrorGDALDataset *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,
示例3: main//.........这里部分代码省略......... XScale = XSize / ((double) GifFileIn->SWidth); YScale = YSize / ((double) GifFileIn->SHeight); } else { XSize = (int) (GifFileIn->SWidth * XScale + 0.5); YSize = (int) (GifFileIn->SHeight * YScale + 0.5); } /* As at this time we know the Screen size of the input gif file, and as */ /* all image(s) in file must be less/equal to it, we can allocate the */ /* scan lines for the input file, and output file. The number of lines */ /* to allocate for each is set by ScaleDown & XScale & YScale: */ LineOut = (GifRowType) malloc(XSize * sizeof(GifPixelType)); LineIn = (GifRowType) malloc(GifFileIn->SWidth * sizeof(GifPixelType)); /* Open stdout for the output file: */ if ((GifFileOut = EGifOpenFileHandle(1)) == NULL) QuitGifError(GifFileIn, GifFileOut); /* And dump out its new scaled screen information: */ if (EGifPutScreenDesc(GifFileOut, XSize, YSize, GifFileIn->SColorResolution, GifFileIn->SBackGroundColor, GifFileIn->SColorMap) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); /* Scan the content of the 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 the image descriptor to out file: */ l = (int) (GifFileIn->Image.Left * XScale + 0.5); w = (int) (GifFileIn->Image.Width * XScale + 0.5); t = (int) (GifFileIn->Image.Top * YScale + 0.5); h = (int) (GifFileIn->Image.Height * YScale + 0.5); if (l < 0) l = 0; if (t < 0) t = 0; if (l + w > XSize) w = XSize - l; if (t + h > YSize) h = YSize - t; if (EGifPutImageDesc(GifFileOut, l, t, w, h, GifFileIn->Image.Interlace, GifFileIn->Image.ColorMap) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); if (GifFileIn->Image.Interlace) { GIF_EXIT("Cannt resize interlaced images - use GifInter first."); } else { GifQprintf("/n%s: Image %d at (%d, %d) [%dx%d]: ", PROGRAM_NAME, ++ImageNum, GifFileOut->Image.Left, GifFileOut->Image.Top, GifFileOut->Image.Width, GifFileOut->Image.Height); for (i = GifFileIn->Image.Height, y = 0.0, last_iy = -1; i-- > 0; y += YScale) { if (DGifGetLine(GifFileIn, LineIn, GifFileIn->Image.Width) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut);
开发者ID:BOTCrusher,项目名称:sagetv,代码行数:66,
示例4: loader_gifunsigned 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);//.........这里部分代码省略.........
开发者ID:dbentall,项目名称:Multiprocessing,代码行数:101,
示例5: mainint 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,
示例6: DGifOpenFileName/* * Partially based on code in gif2rgb from giflib, by Gershon Elber. */RImage *RLoadGIF(const char *file, int index){ RImage *image = NULL; unsigned char *cptr; GifFileType *gif = NULL; GifPixelType *buffer = NULL; int i, j, k; int width, height; GifRecordType recType; ColorMapObject *colormap; unsigned char rmap[256]; unsigned char gmap[256]; unsigned char bmap[256]; if (index < 0) index = 0; /* default error message */ RErrorCode = RERR_BADINDEX; gif = DGifOpenFileName(file); if (!gif) { switch (GifLastError()) { case D_GIF_ERR_OPEN_FAILED: RErrorCode = RERR_OPEN; break; case D_GIF_ERR_READ_FAILED: RErrorCode = RERR_READ; break; default: RErrorCode = RERR_BADIMAGEFILE; break; } return NULL; } if (gif->SWidth < 1 || gif->SHeight < 1) { DGifCloseFile(gif); RErrorCode = RERR_BADIMAGEFILE; return NULL; } colormap = gif->SColorMap; i = 0; do { int extCode; GifByteType *extension; if (DGifGetRecordType(gif, &recType) == GIF_ERROR) { goto giferr; } switch (recType) { case IMAGE_DESC_RECORD_TYPE: if (i++ != index) break; if (DGifGetImageDesc(gif) == GIF_ERROR) { goto giferr; } width = gif->Image.Width; height = gif->Image.Height; if (gif->Image.ColorMap) colormap = gif->Image.ColorMap; /* the gif specs talk about a default colormap, but it * doesnt say what the heck is this default colormap */ if (!colormap) { /* * Well, since the spec says the colormap can be anything, * lets just render it with whatever garbage the stack * has :) * goto bye; */ } else { for (j = 0; j < colormap->ColorCount; j++) { rmap[j] = colormap->Colors[j].Red; gmap[j] = colormap->Colors[j].Green; bmap[j] = colormap->Colors[j].Blue; } } buffer = malloc(width * sizeof(GifColorType)); if (!buffer) { RErrorCode = RERR_NOMEMORY; goto bye; } image = RCreateImage(width, height, False); if (!image) { goto bye;//.........这里部分代码省略.........
开发者ID:crmafra,项目名称:wmaker,代码行数:101,
示例7: main/******************************************************************************* Main sequence******************************************************************************/int main(int argc, char **argv){ GifFileType *GifFileIn = NULL, *GifFileOut = NULL; GifRecordType RecordType; int CodeSize, ExtCode; GifByteType *CodeBlock, *Extension; /* * Command-line processing goes here. */ /* Use the stdin as input (note this also read screen descriptor in: */ if ((GifFileIn = DGifOpenFileHandle(0)) == NULL) QuitGifError(GifFileIn, GifFileOut); /* Use the stdout as output: */ if ((GifFileOut = EGifOpenFileHandle(1)) == NULL) QuitGifError(GifFileIn, GifFileOut); /* 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: /* Skip any extension blocks in file: */ if (DGifGetExtension(GifFileIn, &ExtCode, &Extension) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); if (EGifPutExtension(GifFileOut, ExtCode, Extension[0], Extension + 1) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); /* No support to more than one extension blocks, so discard: */ while (Extension != NULL) { if (DGifGetExtensionNext(GifFileIn, &Extension) == 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) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); if (EGifCloseFile(GifFileOut) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); return 0;}
开发者ID:15521054523,项目名称:fis3,代码行数:86,
示例8: readGifstatic Image*readGif ( GifFileType *gf ){ Image* firstImg = 0; Image* img = 0; int i, extCode, width, height, row, cmapSize; int trans = -1, nFrames = 0, delay = 0; GifRecordType rec; GifByteType *ext; ColorMapObject *cmap; GifColorType *clrs; GifPixelType *rowBuf = (GifPixelType*) AWT_MALLOC( gf->SWidth * sizeof( GifPixelType) ); do { CHECK( DGifGetRecordType( gf, &rec)); switch ( rec ) { case IMAGE_DESC_RECORD_TYPE: CHECK( DGifGetImageDesc( gf)); width = gf->Image.Width; height = gf->Image.Height; cmap = (gf->Image.ColorMap) ? gf->Image.ColorMap : gf->SColorMap; clrs = cmap->Colors; cmapSize = cmap->ColorCount; /* * create our image objects and keep track of frames */ if ( !firstImg ) { /* this is the first (maybe only) frame */ firstImg = img = createImage( width, height); } else { /* this is a subsequent gif-movie frame, link it in */ img->next = createImage( width, height); img = img->next; } /* * The trans index might have been cached by a preceeding extension record. Now * that we have the Image object, it's time to store it in img and to create the * mask */ if ( trans != -1 ) { img->trans = trans; createXMaskImage( X, img); trans = -1; } /* * Some browsers seem to assume minimal values, and some animations * seem to rely on this. But there's no safe guess, so we * skip it completely *//* if ( delay == 0 ) delay = 1000; else if ( delay < 100 ) delay = 100;*/ img->latency = delay; img->left = gf->Image.Left; img->top = gf->Image.Top; img->frame = nFrames; nFrames++; createXImage( X, img); /* * start reading in the image data */ if ( gf->Image.Interlace ) { /* Need to perform 4 passes on the images: */ for ( i = 0; i < 4; i++ ) { for (row = iOffset[i]; row < height; row += iJumps[i]) { memset( rowBuf, gf->SBackGroundColor, width); CHECK( DGifGetLine( gf, rowBuf, width)); writeRow( img, rowBuf, clrs, row); } } } else { for ( row = 0; row < height; row++) { memset( rowBuf, gf->SBackGroundColor, width); CHECK( DGifGetLine(gf, rowBuf, width)); writeRow( img, rowBuf, clrs, row); } } break; case EXTENSION_RECORD_TYPE: CHECK( DGifGetExtension( gf, &extCode, &ext)); if ( extCode == 0xf9 ) { /* graphics extension */ /* * extension record with transparency spec are preceeding description records * (which create new Images), so just cache the transp index, here//.........这里部分代码省略.........
开发者ID:jameshilliard,项目名称:actiontec_opensrc_mi424wr-rev-e-f_fw-20-10-7-5,代码行数:101,
示例9: DGifSlurpintDGifSlurp(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) { //每一帧图片的图片头 Descriptor 也就是0x2c //包含当前帧的上下左右位置(为了节省空间,GIF的单个帧可以不是完整的GIF的大小,如果小于GIF的分辨率 就需要上下左右来定位) //局部的颜色空间(每一帧可以有自己的颜色空间,是可选的) 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 (ExtData != NULL) { 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, //.........这里部分代码省略.........
开发者ID:7heaven,项目名称:libgif_comment,代码行数:101,
示例10: fh_gif_load//int fh_gif_load(char *name,unsigned char *buffer, unsigned char ** alpha, int x,int y)int fh_gif_load(aml_dec_para_t* para , aml_image_info_t* image){ int in_nextrow[4]={8,8,4,2}; //interlaced jump to the row current+in_nextrow int in_beginrow[4]={0,4,2,1}; //begin pass j from that row number int transparency=-1; //-1 means not transparency present int px,py,i,ibxs; int j; char *fbptr; char *lb; char *slb; GifFileType *gft; GifByteType *extension; int extcode; GifRecordType rt; ColorMapObject *cmap; int cmaps; char *p,*q; int buf_len; char* name; char* buffer; char* alpha = NULL; int x,y; name = para->fn; buffer = (unsigned char*) malloc(para->iwidth * para->iheight * 4); buf_len = para->iwidth * para->iheight; x = para->iwidth; y = para->iheight; gft=DGifOpenFileName(name); if(gft==NULL){printf("err5/n"); 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; lb=(char*)malloc(px*3); slb=(char*) malloc(px);// printf("reading.../n"); if(lb!=NULL && slb!=NULL) { unsigned char *alphaptr = NULL; cmap=(gft->Image.ColorMap ? gft->Image.ColorMap : gft->SColorMap); cmaps=cmap->ColorCount; ibxs=ibxs*3; fbptr=(char*)buffer; if(transparency != -1) { alphaptr = malloc(px * py); alpha = alphaptr; } if(!(gft->Image.Interlace)) { for(i=0;i<py;i++,fbptr+=px*3) { int j; if(DGifGetLine(gft,(GifPixelType*)slb,px)==GIF_ERROR) mgrflush; m_rend_gif_decodecolormap((unsigned char*)slb,(unsigned char*)lb,cmap,cmaps,px,transparency); memcpy(fbptr,lb,px*3); if(alphaptr) for(j = 0; j<px; j++) *(alphaptr++) = (((unsigned char*) slb)[j] == transparency) ? 0x00 : 0xff; } } else { unsigned char * aptr = NULL; for(j=0;j<4;j++) { int k; if(alphaptr) aptr = alphaptr + (in_beginrow[j] * px); fbptr=(char*)buffer + (in_beginrow[j] * px * 3); for(i = in_beginrow[j]; i<py; i += in_nextrow[j], fbptr += px * 3 * in_nextrow[j], aptr += px * in_nextrow[j]) { if(DGifGetLine(gft,(GifPixelType*)slb,px)==GIF_ERROR) mgrflush; ///////////// m_rend_gif_decodecolormap((unsigned char*)slb,(unsigned char*)lb,cmap,cmaps,px,transparency); memcpy(fbptr,lb,px*3); if(alphaptr) for(k = 0; k<px; k++) aptr[k] = (((unsigned char*) slb)[k] == transparency) ? 0x00 : 0xff; } } } } if(lb) free(lb); if(slb) free(slb); break; case EXTENSION_RECORD_TYPE: if(DGifGetExtension(gft,&extcode,&extension)==GIF_ERROR) grflush; ////////// if(extcode==0xf9) //look image transparency in graph ctr extension {//.........这里部分代码省略.........
开发者ID:Pivosgroup,项目名称:aml-original-linux-buildroot,代码行数:101,
示例11: open_gif_filevoid*open_gif_file (const char *filename, int *width, int *height){ int interlace_offset[] = { 0, 4, 2, 1 }; int interlace_jump[] = { 8, 8, 4, 2 }; GifColorType *colormap; GifRecordType record_type; GifRowType *buffer = NULL; int i, j; int color_index; unsigned char *ptr = NULL; gif_data_t *data = (gif_data_t*)malloc(sizeof(gif_data_t)); assert(data != 0); int error; data->file = DGifOpenFileName(filename, &error); assert(data->file !=0); do { assert(DGifGetRecordType(data->file, &record_type) != GIF_ERROR) ; switch (record_type) { case IMAGE_DESC_RECORD_TYPE: assert(DGifGetImageDesc(data->file) != GIF_ERROR); *width = data->file->Image.Width; *height = data->file->Image.Height; data->width = *width; data->height = *height; buffer = malloc(*height * sizeof(GifRowType *)); assert(buffer != NULL); for (i = 0; i < *height; i++) { buffer[i] = malloc(*width * sizeof(GifPixelType)); assert(buffer[i] != NULL); } if (data->file->Image.Interlace) { for (i = 0; i < 4; i++) for (j = interlace_offset[i]; j < *height; j += interlace_jump[i]) DGifGetLine(data->file, buffer[j], *width); } else { for (i = 0; i < *height; i++) DGifGetLine(data->file, buffer[i], *width); } break; case EXTENSION_RECORD_TYPE: { /* Skip extension blocks */ int ext_code; GifByteType *ext; assert(DGifGetExtension(data->file, &ext_code, &ext) != GIF_ERROR); while (ext != NULL) { assert(DGifGetExtensionNext(data->file, &ext) != GIF_ERROR); } } break; case TERMINATE_RECORD_TYPE: break; default: fprintf(stderr, "unknown record type in GIF file/n"); break; } } while (record_type != TERMINATE_RECORD_TYPE); colormap = (data->file->Image.ColorMap ? data->file->Image.ColorMap->Colors : data->file->SColorMap->Colors); data->rgb = (unsigned char*)malloc( (data->width* data->height * 3) ); assert(data->rgb != NULL); ptr = data->rgb; for (j = 0; j < *height; j++) { for (i = 0; i < *width; i++) { color_index = (int) buffer[j][i]; *ptr++ = (unsigned char) colormap[color_index].Red; *ptr++ = (unsigned char) colormap[color_index].Green; *ptr++ = (unsigned char) colormap[color_index].Blue; } free(buffer[j]); } free(buffer);//.........这里部分代码省略.........
开发者ID:schani,项目名称:rwimg,代码行数:101,
示例12: GIF2RGBstatic void GIF2RGB(int NumFiles, char *FileName, bool OneFileFlag, char *OutFileName){ int i, j, Size, Row, Col, Width, Height, ExtCode, Count; GifRecordType RecordType; GifByteType *Extension; GifRowType *ScreenBuffer; GifFileType *GifFile; int InterlacedOffset[] = { 0, 4, 2, 1 }, /* The way Interlaced image should. */ InterlacedJumps[] = { 8, 8, 4, 2 }; /* be read - offsets and jumps... */ int ImageNum = 0; ColorMapObject *ColorMap; int Error; if (NumFiles == 1) { int Error; if ((GifFile = DGifOpenFileName(FileName, &Error)) == NULL) { PrintGifError(Error); exit(EXIT_FAILURE); } } else { int Error; /* Use stdin instead: */ if ((GifFile = DGifOpenFileHandle(0, &Error)) == NULL) { PrintGifError(Error); exit(EXIT_FAILURE); } } /* * Allocate the screen as vector of column of rows. Note this * screen is device independent - it's the screen defined by the * GIF file parameters. */ 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 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; 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) 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(GifFile->Error); exit(EXIT_FAILURE); } switch (RecordType) { case IMAGE_DESC_RECORD_TYPE: { if (DGifGetImageDesc(GifFile) == GIF_ERROR) { PrintGifError(GifFile->Error); exit(EXIT_FAILURE); } Row = GifFile->Image.Top; /* Image Position relative to Screen. */ Col = GifFile->Image.Left; Width = GifFile->Image.Width; Height = GifFile->Image.Height; GifQprintf("/n%s: Image %d at (%d, %d) [%dx%d]: ", PROGRAM_NAME, ++ImageNum, Col, Row, Width, Height); if (GifFile->Image.Left + GifFile->Image.Width > GifFile->SWidth || GifFile->Image.Top + GifFile->Image.Height > GifFile->SHeight) { fprintf(stderr, "Image %d is not confined to screen dimension, aborted./n",ImageNum); exit(EXIT_FAILURE); } 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]) { GifQprintf("/b/b/b/b%-4d", Count++); if (DGifGetLine(GifFile, &ScreenBuffer[j][Col], Width) == GIF_ERROR) { PrintGifError(GifFile->Error); exit(EXIT_FAILURE); } } } else { for (i = 0; i < Height; i++) { GifQprintf("/b/b/b/b%-4d", i); if (DGifGetLine(GifFile, &ScreenBuffer[Row++][Col], Width) == GIF_ERROR) { PrintGifError(GifFile->Error); exit(EXIT_FAILURE); } }//.........这里部分代码省略.........
开发者ID:moon-sky,项目名称:fishjam-template-library,代码行数:101,
示例13: DGifOpenFileHandle//.........这里部分代码省略......... rowsize = gifp->SWidth * sizeof(GifPixelType); buffer[0] = (GifRowType)malloc(rowsize); if(buffer[0] == NULL) { free(buffer); free(picture); DGifCloseFile(gifp); return NULL; } for(i = 0 ; i < gifp->SWidth ; i++) buffer[0][i] = gifp->SBackGroundColor; for(i = 0 ; i < gifp->SHeight ; i++) { buffer[i] = (GifRowType)malloc(rowsize); if(buffer[i] == NULL) { while(--i >= 0) free(buffer[i]); free(buffer); free(picture); DGifCloseFile(gifp); return NULL; } memcpy(buffer[i], buffer[0], rowsize); } /* We only read the first GIF image right now, since we are not * supporting animated GIF images. Perhaps the last image would * actually be a better choice. Oh well. */ images_read = 0; do { DGifGetRecordType(gifp, &record); ret = GIF_OK; switch(record) { case IMAGE_DESC_RECORD_TYPE: ret = DGifGetImageDesc(gifp); if(ret == GIF_ERROR) break;#if 0 fprintf(stderr, "image width=%d, height=%d, interlace=%d/n", gifp->Image.Width, gifp->Image.Height, gifp->Image.Interlace);#endif row = gifp->Image.Top; col = gifp->Image.Left; image_width = gifp->Image.Width; image_height = gifp->Image.Height; if(gifp->Image.Interlace) { for(i = 0 ; i < 4 ; i++) { for(j = row + interlaceoffset[i] ; j < row + image_height ; j += interlacejump[i]) { DGifGetLine(gifp, &buffer[j][col], image_width); } } } else { for(i = 0 ; i < image_height ; i++) { DGifGetLine(gifp, &buffer[row++][col], image_width); } } images_read++; break; /* Read and skip any extension. */
开发者ID:jmjeong-nemus,项目名称:rexy-embedded,代码行数:67,
示例14: DDGifSlurpvoid 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;//.........这里部分代码省略.........
开发者ID:bearprada,项目名称:android-gif-drawable,代码行数:101,
示例15: DGifSlurp/****************************************************************************** * 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(). ******************************************************************************/intDGifSlurp(GifFileType * GifFile) { int ImageSize; GifRecordType RecordType; SavedImage *sp; GifByteType *ExtData; Extensions temp_save; temp_save.ExtensionBlocks = NULL; temp_save.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]; ImageSize = sp->ImageDesc.Width * sp->ImageDesc.Height; sp->RasterBits = ungif_alloc(ImageSize * sizeof(GifPixelType)); if (sp->RasterBits == NULL) { return GIF_ERROR; } if (DGifGetLine(GifFile, sp->RasterBits, ImageSize) == GIF_ERROR) return (GIF_ERROR); if (temp_save.ExtensionBlocks) { sp->Extensions.ExtensionBlocks = temp_save.ExtensionBlocks; sp->Extensions.ExtensionBlockCount = temp_save.ExtensionBlockCount; temp_save.ExtensionBlocks = NULL; temp_save.ExtensionBlockCount = 0; /* FIXME: The following is wrong. It is left in only for * backwards compatibility. Someday it should go away. Use * the sp->ExtensionBlocks->Function variable instead. */ sp->Extensions.Function = sp->Extensions.ExtensionBlocks[0].Function; } break; case EXTENSION_RECORD_TYPE: { int Function; Extensions *Extensions; if (DGifGetExtension(GifFile, &Function, &ExtData) == GIF_ERROR) return (GIF_ERROR); if (GifFile->ImageCount || Function == GRAPHICS_EXT_FUNC_CODE) Extensions = &temp_save; else Extensions = &GifFile->Extensions; Extensions->Function = Function; /* Create an extension block with our data */ if (AddExtensionBlock(Extensions, ExtData[0], &ExtData[1]) == GIF_ERROR) return (GIF_ERROR); while (ExtData != NULL) { int Len; GifByteType *Data; if (DGifGetExtensionNext(GifFile, &ExtData) == GIF_ERROR) return (GIF_ERROR); if (ExtData) { Len = ExtData[0]; Data = &ExtData[1]; } else { Len = 0; Data = NULL; } if (AppendExtensionBlock(Extensions, Len, Data) == GIF_ERROR) return (GIF_ERROR); } break; } case TERMINATE_RECORD_TYPE: break; default: /* Should be trapped by DGifGetRecordType */ break; } } while (RecordType != TERMINATE_RECORD_TYPE);//.........这里部分代码省略.........
开发者ID:hoangduit,项目名称:reactos,代码行数:101,
示例16: DGifCloseFileCPLErr 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;//.........这里部分代码省略.........
开发者ID:afarnham,项目名称:gdal,代码行数:101,
示例17: image_gif_loadintimage_gif_load(image *im){ int x, y, ofs; GifRecordType RecordType; GifPixelType *line = NULL; int ExtFunction = 0; GifByteType *ExtData; SavedImage *sp; SavedImage temp_save; int BackGround = 0; int trans_index = 0; // transparent index if any ColorMapObject *ColorMap; GifColorType *ColorMapEntry; temp_save.ExtensionBlocks = NULL; temp_save.ExtensionBlockCount = 0; // If reusing the object a second time, start over if (im->used) { DEBUG_TRACE("Recreating giflib objects/n"); image_gif_finish(im); if (im->fh != NULL) { // reset file to begining of image PerlIO_seek(im->fh, im->image_offset, SEEK_SET); } else { // reset SV read im->sv_offset = im->image_offset; } buffer_clear(im->buf); image_gif_read_header(im); } do { if (DGifGetRecordType(im->gif, &RecordType) == GIF_ERROR) { warn("Image::Scale unable to read GIF file (%s)/n", SvPVX(im->path)); image_gif_finish(im); return 0; } switch (RecordType) { case IMAGE_DESC_RECORD_TYPE: if (DGifGetImageDesc(im->gif) == GIF_ERROR) { warn("Image::Scale unable to read GIF file (%s)/n", SvPVX(im->path)); image_gif_finish(im); return 0; } sp = &im->gif->SavedImages[im->gif->ImageCount - 1]; im->width = sp->ImageDesc.Width; im->height = sp->ImageDesc.Height; BackGround = im->gif->SBackGroundColor; // XXX needed? ColorMap = im->gif->Image.ColorMap ? im->gif->Image.ColorMap : im->gif->SColorMap; if (ColorMap == NULL) { warn("Image::Scale GIF image has no colormap (%s)/n", SvPVX(im->path)); image_gif_finish(im); return 0; } // Allocate storage for decompressed image image_alloc(im, im->width, im->height); New(0, line, im->width, GifPixelType); if (im->gif->Image.Interlace) { int i; for (i = 0; i < 4; i++) { for (x = InterlacedOffset[i]; x < im->height; x += InterlacedJumps[i]) { ofs = x * im->width; if (DGifGetLine(im->gif, line, 0) != GIF_OK) { warn("Image::Scale unable to read GIF file (%s)/n", SvPVX(im->path)); image_gif_finish(im); return 0; } for (y = 0; y < im->width; y++) { ColorMapEntry = &ColorMap->Colors[line[y]]; im->pixbuf[ofs++] = COL_FULL( ColorMapEntry->Red, ColorMapEntry->Green, ColorMapEntry->Blue, trans_index == line[y] ? 0 : 255 ); } } } } else { ofs = 0; for (x = 0; x < im->height; x++) { if (DGifGetLine(im->gif, line, 0) != GIF_OK) { warn("Image::Scale unable to read GIF file (%s)/n", SvPVX(im->path)); image_gif_finish(im);//.........这里部分代码省略.........
开发者ID:andygrundman,项目名称:Image-Scale,代码行数:101,
示例18: main/******************************************************************************* Interpret the command line and scan the given GIF file. *******************************************************************************/void main(int argc, char **argv){ int Error, NumFiles, ExtCode; GifRecordType RecordType; GifByteType *Extension; char **FileName = NULL; GifRowType *ImageBuffer; GifFileType *GifFileIn = NULL, *GifFileOut = NULL; if ((Error = GAGetArgs(argc, argv, CtrlStr, &GifQuitePrint, &InterlacedFlag, &SequencialFlag, &HelpFlag, &NumFiles, &FileName)) != FALSE || (NumFiles > 1 && !HelpFlag)) { if (Error) GAPrintErrMsg(Error); else if (NumFiles > 1) GIF_MESSAGE("Error in command line parsing - one GIF file please."); GAPrintHowTo(CtrlStr); exit(1); } if (HelpFlag) { fprintf(stderr, VersionStr); GAPrintHowTo(CtrlStr); exit(0); } if (NumFiles == 1) { if ((GifFileIn = DGifOpenFileName(*FileName)) == NULL) QuitGifError(GifFileIn, GifFileOut); } else { /* Use the stdin instead: */ if ((GifFileIn = DGifOpenFileHandle(0)) == NULL) QuitGifError(GifFileIn, GifFileOut); } /* Open stdout for the output file: */ if ((GifFileOut = EGifOpenFileHandle(1)) == NULL) QuitGifError(GifFileIn, GifFileOut); /* And dump out exactly same screen information: */ if (EGifPutScreenDesc(GifFileOut, GifFileIn -> SWidth, GifFileIn -> SHeight, GifFileIn -> SColorResolution, GifFileIn -> SBackGroundColor, GifFileIn -> SBitsPerPixel, GifFileIn -> SColorMap) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); /* Scan the content of the 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 the image descriptor to out file: */ if (EGifPutImageDesc(GifFileOut, GifFileIn -> ILeft, GifFileIn -> ITop, GifFileIn -> IWidth, GifFileIn -> IHeight, InterlacedFlag, GifFileIn -> IBitsPerPixel, GifFileIn -> IColorMap) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); /* Load the image (either Interlaced or not), and dump it as */ /* defined in GifFileOut -> IInterlaced. */ if (LoadImage(GifFileIn, &ImageBuffer) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); if (DumpImage(GifFileOut, ImageBuffer) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); break; case EXTENSION_RECORD_TYPE: /* Skip any extension blocks in file: */ if (DGifGetExtension(GifFileIn, &ExtCode, &Extension) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); if (EGifPutExtension(GifFileOut, ExtCode, Extension[0], Extension) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); /* No support to more than one extension blocks, so discard: */ while (Extension != NULL) { if (DGifGetExtensionNext(GifFileIn, &Extension) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); } break; case TERMINATE_RECORD_TYPE: break; default: /* Should be traps by DGifGetRecordType. */ break; } } while (RecordType != TERMINATE_RECORD_TYPE); if (DGifCloseFile(GifFileIn) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut);//.........这里部分代码省略.........
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:101,
示例19: Gif2Iconstatic void Gif2Icon(char *FileName, int fdin, int fdout, char NameTable[]){ int i, ExtCode, ImageNum = 1; GifPixelType *Line, *cp; GifRecordType RecordType; GifByteType *Extension; GifFileType *GifFile; if (fdin == -1) { if ((GifFile = DGifOpenFileName(FileName)) == NULL) { PrintGifError(); exit(EXIT_FAILURE); } } else { /* Use stdin instead: */ if ((GifFile = DGifOpenFileHandle(fdin)) == NULL) { PrintGifError(); exit(EXIT_FAILURE); } } printf("screen width %d/nscreen height %d/n", GifFile->SWidth, GifFile->SHeight); printf("screen colors %d/nscreen background %d/n/n", GifFile->SColorResolution, GifFile->SBackGroundColor); if (GifFile->SColorMap) { if (GifFile->SColorMap->ColorCount >= (int)strlen(NameTable)) { (void) fprintf(stderr, "%s: global color map has unprintable pixels/n", FileName); exit(EXIT_FAILURE); } printf("screen map/n"); for (i = 0; i < GifFile->SColorMap->ColorCount; i++) printf("/trgb %03d %03d %03d is %c/n", GifFile->SColorMap ->Colors[i].Red, GifFile->SColorMap ->Colors[i].Green, GifFile->SColorMap ->Colors[i].Blue, NameTable[i]); printf("end/n/n"); } do { if (DGifGetRecordType(GifFile, &RecordType) == GIF_ERROR) { PrintGifError(); exit(EXIT_FAILURE); } switch (RecordType) { case IMAGE_DESC_RECORD_TYPE: if (DGifGetImageDesc(GifFile) == GIF_ERROR) { PrintGifError(); 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);//.........这里部分代码省略.........
开发者ID:BOTCrusher,项目名称:sagetv,代码行数:101,
示例20: streamDeleter/* * Read enough of the stream to initialize the SkGifCodec. * Returns a bool representing success or failure. * * @param codecOut * If it returned true, and codecOut was not nullptr, * codecOut will be set to a new SkGifCodec. * * @param gifOut * If it returned true, and codecOut was nullptr, * gifOut must be non-nullptr and gifOut will be set to a new * GifFileType pointer. * * @param stream * Deleted on failure. * codecOut will take ownership of it in the case where we created a codec. * Ownership is unchanged when we returned a gifOut. * */bool SkGifCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, GifFileType** gifOut) { SkAutoTDelete<SkStream> streamDeleter(stream); // Read gif header, logical screen descriptor, and global color table SkAutoTCallVProc<GifFileType, CloseGif> gif(open_gif(stream)); if (nullptr == gif) { gif_error("DGifOpen failed./n"); return false; } // Read through gif extensions to get to the image data. Set the // transparent index based on the extension data. uint32_t transIndex; SkCodec::Result result = ReadUpToFirstImage(gif, &transIndex); if (kSuccess != result){ return false; } // Read the image descriptor if (GIF_ERROR == DGifGetImageDesc(gif)) { return false; } // If reading the image descriptor is successful, the image count will be // incremented. SkASSERT(gif->ImageCount >= 1); if (nullptr != codecOut) { SkISize size; SkIRect frameRect; if (!GetDimensions(gif, &size, &frameRect)) { gif_error("Invalid gif size./n"); return false; } bool frameIsSubset = (size != frameRect.size()); // Determine the recommended alpha type. The transIndex might be valid if it less // than 256. We are not certain that the index is valid until we process the color // table, since some gifs have color tables with less than 256 colors. If // there might be a valid transparent index, we must indicate that the image has // alpha. // In the case where we must support alpha, we have the option to set the // suggested alpha type to kPremul or kUnpremul. Both are valid since the alpha // component will always be 0xFF or the entire 32-bit pixel will be set to zero. // We prefer kPremul because we support kPremul, and it is more efficient to use // kPremul directly even when kUnpremul is supported. SkAlphaType alphaType = (transIndex < 256) ? kPremul_SkAlphaType : kOpaque_SkAlphaType; // Return the codec // kIndex is the most natural color type for gifs, so we set this as // the default. SkImageInfo imageInfo = SkImageInfo::Make(size.width(), size.height(), kIndex_8_SkColorType, alphaType); *codecOut = new SkGifCodec(imageInfo, streamDeleter.detach(), gif.detach(), transIndex, frameRect, frameIsSubset); } else { SkASSERT(nullptr != gifOut); streamDeleter.detach(); *gifOut = gif.detach(); } return true;}
开发者ID:crabfang,项目名称:skia,代码行数:81,
示例21: img_load_gifbool 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,
示例22: mainint 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,
示例23: main//.........这里部分代码省略......... 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); } } } else { for (i = 0; i < Height; i++, Row++) { GifQprintf("/b/b/b/b%-4d", i);
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:67,
示例24: 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;//.........这里部分代码省略.........
开发者ID:tok101,项目名称:tok101,代码行数:101,
示例25: GDALGetDriverByNameCPLErr BIGGIFDataset::ReOpen(){/* -------------------------------------------------------------------- *//* If the file is already open, close it so we can restart. *//* -------------------------------------------------------------------- */ if( hGifFile != NULL ) GIFAbstractDataset::myDGifCloseFile( 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; hGifFile = GIFAbstractDataset::myDGifOpen( fp, GIFAbstractDataset::ReadFunc ); 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 = FindFirstImage(hGifFile); if( RecordType != IMAGE_DESC_RECORD_TYPE ) { GIFAbstractDataset::myDGifCloseFile( 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) { GIFAbstractDataset::myDGifCloseFile( hGifFile ); hGifFile = NULL; CPLError( CE_Failure, CPLE_OpenFailed, "Image description reading failed in GIF file." ); return CE_Failure; } return CE_None;}
开发者ID:Mavrx-inc,项目名称:gdal,代码行数:76,
示例26: DGifOpenbool 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;}
开发者ID:JimLiu,项目名称:asptools,代码行数:98,
示例27: 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().*******************************************************************************/intDGifSlurp(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 (ExtData != NULL) { 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;//.........这里部分代码省略.........
开发者ID:1007650105,项目名称:aseprite,代码行数:101,
示例28: DoAssembly/******************************************************************************* Perform the assembly operation - take few input files into one output. *******************************************************************************/static void DoAssembly(int NumFiles, char **FileNames){ int i, ExtCode, CodeSize; GifRecordType RecordType; GifByteType *Extension, *CodeBlock; GifFileType *GifFileIn = NULL, *GifFileOut = NULL; /* Open stdout for the output file: */ if ((GifFileOut = EGifOpenFileHandle(1)) == NULL) QuitGifError(GifFileIn, GifFileOut); /* Scan the content of the GIF file and load the image(s) in: */ for (i = 0; i < NumFiles; i++) { if ((GifFileIn = DGifOpenFileName(FileNames[i])) == NULL) QuitGifError(GifFileIn, GifFileOut); /* And dump out screen descriptor iff its first image. */ if (i == 0) if (EGifPutScreenDesc(GifFileOut, GifFileIn -> SWidth, GifFileIn -> SHeight, GifFileIn -> SColorResolution, GifFileIn -> SBackGroundColor, GifFileIn -> SBitsPerPixel, GifFileIn -> SColorMap) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); 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 -> ILeft, GifFileIn -> ITop, GifFileIn -> IWidth, GifFileIn -> IHeight, GifFileIn -> IInterlace, GifFileIn -> IBitsPerPixel, GifFileIn -> IColorMap) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); /* Now read image itself in decoded form as we dont */ /* dont care what is 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: /* Skip any extension blocks in file: */ if (DGifGetExtension(GifFileIn, &ExtCode, &Extension) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); if (EGifPutExtension(GifFileOut, ExtCode, Extension[0], Extension) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); /* No support to more than one extension blocks, discard.*/ while (Extension != NULL) if (DGifGetExtensionNext(GifFileIn, &Extension) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); break; case TERMINATE_RECORD_TYPE: break; default: /* Should be traps by DGifGetRecordType. */ break; } } while (RecordType != TERMINATE_RECORD_TYPE); if (DGifCloseFile(GifFileIn) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut); } if (EGifCloseFile(GifFileOut) == GIF_ERROR) QuitGifError(GifFileIn, GifFileOut);}
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:83,
注:本文中的DGifGetImageDesc函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ DGifGetLine函数代码示例 C++ DGifGetExtensionNext函数代码示例 |