📄 dev2gif.c
字号:
/****************************************************************************** "Gif-Lib" - Yet another gif library. ** ** Written by: Gershon Elber IBM PC Ver 1.1, Jun. 1989 ******************************************************************************** Module to dump graphic devices into a GIF file. Current supported devices: ** 1. EGA, VGA, SVGA (800x600), Hercules on the IBM PC (#define __MSDOS__). ** 2. SGI 4D Irix using gl library (#define __SGI_GL__). ** 3. X11 using libX.a (#define __X11__). ******************************************************************************** History: ** 22 Jun 89 - Version 1.0 by Gershon Elber. ** 12 Aug 90 - Version 1.1 by Gershon Elber (added devices). ******************************************************************************/#ifdef __MSDOS__#include <dos.h>#include <alloc.h>#include <graphics.h>#endif /* __MSDOS__ */#ifdef __SGI_GL__#include <gl/gl.h>#endif /* __SGI_GL__ */#ifdef __X11__#include <X11/Xlib.h>#endif /* __X11__ */#include <stdlib.h>#include <stdio.h>#include <string.h>#include "gif_lib.h"#define PROGRAM_NAME "GIF_LIBRARY"#define SVGA_SPECIAL 999 /* 800 by 600 Super VGA mode. */static int GraphDriver = -1, /* Device parameters - reasonable values. */ GraphMode = -1, ScreenColorBits = 1;static long ScreenXMax = 100, ScreenYMax = 100;static unsigned int ScreenBase;#ifdef SYSVstatic char *VersionStr = "Gif library module,\t\tEric S. Raymond\n\ (C) Copyright 1997 Eric S. Raymond\n";#elsestatic char *VersionStr = PROGRAM_NAME " IBMPC " GIF_LIB_VERSION " Eric S. Raymond, " __DATE__ ", " __TIME__ "\n" "(C) Copyright 1997 Eric S. Raymond\n";#endif /* SYSV */#if defined(__SGI_GL__) || defined(__X11__) GifByteType *GlblGifBuffer = NULL, *GlblGifBufferPtr = NULL;#endif /* __SGI_GL__ || __X11__ */#ifdef __SGI_GL__static int QuantizeRGBBuffer(int Width, int Height, long *RGBBuffer, GifColorType *ColorMap, GifByteType *GIFBuffer);#endif /* __SGI_GL__ */static void GetScanLine(GifPixelType *ScanLine, int Y);static int HandleGifError(GifFileType *GifFile);/******************************************************************************* Dump the given Device, into given File as GIF format: ** Return 0 on success, -1 if device not supported, or GIF-LIB error number. ** Device is selected via the ReqGraphDriver. Device mode is selected via ** ReqGraphMode1/2 as follows: ** 1. IBM PC Hercules card: HERCMONO (one mode only) in ReqGraphMode1, ** ReqGraphMode2/3 are ignored. ** 2. IBM PC EGA card: EGALO/EGAHI in ReqGraphMode1, ** ReqGraphMode2/3 are ignored. ** 3. IBM PC EGA64 card: EGA64LO/EGA64HI in ReqGraphMode1, ** ReqGraphMode2/3 are ignored. ** 4. IBM PC EGAMONO card: EGAMONOHI (one mode only) in ReqGraphMode1, ** ReqGraphMode2/3 are ignored. ** 5. IBM PC VGA card: VGALO/VGAMED/VGAHI in ReqGraphMode1, ** ReqGraphMode2/3 are ignored. ** 6. IBM PC SVGA card: ReqGraphMode1/2 are both ignored. Fixed mode (800x600 ** 16 colors) is assumed. ** 7. SGI 4D using GL: window id to dump (as returned by winget()) in ** ReqGraphMode1, ReqGraphMode2/3 are ignored. ** 8. X11: Window id in ReqGraphMode1, Display id in ReqGraphMode2, Color ** map id in ReqGraphMode3. *******************************************************************************/int DumpScreen2Gif(char *FileName, int ReqGraphDriver, int ReqGraphMode1, int ReqGraphMode2, int ReqGraphMode3){ int i, j, k; GifPixelType *ScanLine; GifFileType *GifFile; ColorMapObject *ColorMap = NULL;#ifdef __MSDOS__ static GifColorType MonoChromeColorMap[] = { { 0, 0, 0 }, { 255, 255, 255 } }; /* I have no idea what default EGA64 (4 colors) should be (I guessed...).*/ static GifColorType EGA64ColorMap[] = { { 0, 0, 0 }, /* 0. Black */ { 255, 0, 0 }, /* 1. Red */ { 0, 255, 0 }, /* 2. Green */ { 0, 0, 255 }, /* 3. Blue */ }; static GifColorType EGAColorMap[] = { { 0, 0, 0 }, /* 0. Black */ { 0, 0, 170 }, /* 1. Blue */ { 0, 170, 0 }, /* 2. Green */ { 0, 170, 170 }, /* 3. Cyan */ { 170, 0, 0 }, /* 4. Red */ { 170, 0, 170 }, /* 5. Magenta */ { 170, 170, 0 }, /* 6. Brown */ { 170, 170, 170 }, /* 7. LightGray */ { 85, 85, 85 }, /* 8. DarkGray */ { 85, 85, 255 }, /* 9. LightBlue */ { 85, 255, 85 }, /* 10. LightGreen */ { 85, 255, 255 }, /* 11. LightCyan */ { 255, 85, 85 }, /* 12. LightRed */ { 255, 85, 255 }, /* 13. LightMagenta */ { 255, 255, 85 }, /* 14. Yellow */ { 255, 255, 255 }, /* 15. White */ };#endif /* __MSDOS__ */#if defined(__SGI_GL__) || defined(__X11__) long *RGBBuffer; GifColorType ColorMap256[256];#endif#ifdef __X11__ XImage *XImg; unsigned long XPixel; XColor XColorTable[256]; /* Up to 256 colors in X. */ XWindowAttributes WinAttr;#endif /* __X11__ */ switch (ReqGraphDriver) { /* Return on non supported screens. */#ifdef __MSDOS__ case HERCMONO: ScreenXMax = 720; ScreenYMax = 350; ScreenColorBits = 1; ScreenBase = 0xb000; ColorMap = MakeMapObject(2, MonoChromeColorMap); break; case EGA: switch (ReqGraphMode1) { case EGALO: ScreenYMax = 200; break; case EGAHI: ScreenYMax = 350; break; default: return -1; } ScreenXMax = 640; ScreenColorBits = 4; ScreenBase = 0xa000; ColorMap = MakeMapObject(16, EGAColorMap); break; case EGA64: switch (ReqGraphMode1) { case EGA64LO: ScreenYMax = 200; break; case EGA64HI: ScreenYMax = 350; break; default: return -1; } ScreenXMax = 640; ScreenColorBits = 2; ScreenBase = 0xa000; ColorMap = MakeMapObject(4, EGA64ColorMap); break; case EGAMONO: switch (ReqGraphMode1) { case EGAMONOHI: ScreenYMax = 350; break; default: return -1; } ScreenXMax = 640; ScreenColorBits = 1; ScreenBase = 0xa000; ColorMap = MakeMapObject(2, MonoChromeColorMap); break; case VGA: switch (ReqGraphMode1) { case VGALO: ScreenYMax = 200; break; case VGAMED: ScreenYMax = 350; break; case VGAHI: ScreenYMax = 480; break; default: return -1; } ScreenXMax = 640; ScreenColorBits = 4; ScreenBase = 0xa000; ColorMap = MakeMapObject(16, EGAColorMap); break; case SVGA_SPECIAL: ScreenXMax = 800; ScreenYMax = 600; ScreenColorBits = 4; ScreenBase = 0xa000; ColorMap = MakeMapObject(16, EGAColorMap); break;#endif /* __MSDOS__ */#ifdef __SGI_GL__ case GIF_DUMP_SGI_WINDOW: winset(ReqGraphMode1); /* Select window as active window. */ getsize(&ScreenXMax, &ScreenYMax); RGBBuffer = (long *) malloc(sizeof(long) * ScreenXMax * ScreenYMax); readsource(SRC_FRONT); if (lrectread((short) 0, (short) 0, (short) (ScreenXMax - 1), (short) (ScreenYMax - 1), RGBBuffer) != ScreenXMax * ScreenYMax) { /* Get data. */ free(RGBBuffer); return -1; } GlblGifBuffer = (GifByteType *) malloc(sizeof(GifByteType) * ScreenXMax * ScreenYMax); i = QuantizeRGBBuffer(ScreenXMax, ScreenYMax, RGBBuffer, ColorMap256, GlblGifBuffer); /* Find minimum color map size to hold all quantized colors. */ for (ScreenColorBits = 1; (1 << ScreenColorBits) < i && ScreenColorBits < 8; ScreenColorBits++); /* Start to dump with top line as GIF expects it. */ GlblGifBufferPtr = GlblGifBuffer + ScreenXMax * (ScreenYMax - 1); ColorMap = MakeMapObject(256, ColorMap256); free(RGBBuffer); break;#endif /* __SGI_GL__ */#ifdef __X11__ case GIF_DUMP_X_WINDOW: XGetWindowAttributes((Display *) ReqGraphMode2, (Window) ReqGraphMode1,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -