00001 /* vGif - a virtual graphic object wrapper around 00002 * an in-memory buffer destined to become a 00003 * 256-color GIF file. */ 00004 00005 #include "common.h" 00006 #include "memgfx.h" 00007 #include "vGfx.h" 00008 #include "vGfxPrivate.h" 00009 00010 static char const rcsid[] = "$Id: vGif.c,v 1.4 2003/05/06 07:33:44 kate Exp $"; 00011 00012 struct memGif 00013 /* Something that handles a gif. */ 00014 { 00015 struct memGfx mg; /* Memory form. This needs to be first field. */ 00016 char *fileName; /* Gif file name. */ 00017 }; 00018 00019 void memGifClose(struct memGif **pG) 00020 /* Write out and close and free. */ 00021 { 00022 struct memGif *g = *pG; 00023 if (g != NULL) 00024 { 00025 struct memGfx *mg = (struct memGfx *)g; 00026 mgSaveGif(mg, g->fileName); 00027 freez(&g->fileName); 00028 mgFree(&mg); 00029 *pG = NULL; 00030 } 00031 } 00032 00033 struct vGfx *vgOpenGif(int width, int height, char *fileName) 00034 /* Open up something that will someday be a PostScript file. */ 00035 { 00036 struct memGif *gif; 00037 struct memGfx *mg; 00038 struct vGfx *vg; 00039 00040 /* Set up virtual graphics with memory methods. */ 00041 vg = vgHalfInit(width, height); 00042 vgMgMethods(vg); 00043 vg->close = (vg_close)memGifClose; 00044 00045 /* Get our mg + fileName structure. We're forcing 00046 * inheritence from mg essentially. */ 00047 AllocVar(gif); 00048 gif->fileName = cloneString(fileName); 00049 00050 /* Fill in the mg part of this structure with normal memGfx. */ 00051 mg = mgNew(width, height); 00052 mgClearPixels(mg); 00053 gif->mg = *mg; 00054 freez(&mg); /* We don't need this copy any more. */ 00055 00056 vg->data = gif; 00057 return vg; 00058 } 00059
1.5.2