⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dev2gif.c

📁 giflib-4.1.6.tar.gz,最新的GIF 解码库
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** *   "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__). * 4. (2 & 3 have been changed to HAVE_GL_S and HAVE_LIBX11 and should be set * by the configure script.) ***************************************************************************** * History: * 22 Jun 89 - Version 1.0 by Gershon Elber. * 12 Aug 90 - Version 1.1 by Gershon Elber (added devices). ****************************************************************************/#ifdef HAVE_CONFIG_H#include <config.h>#endif#ifdef __MSDOS__#include <dos.h>#include <alloc.h>#include <graphics.h>#endif /* __MSDOS__ */#ifdef HAVE_LIBX11#include <X11/Xlib.h>#include <X11/Xutil.h>#endif /* HAVE_LIBX11 */#ifdef HAVE_LIBGL_S#include <gl/gl.h>#endif /* HAVE_LIBGL_S */#include <stdlib.h>#include <stdio.h>#include <string.h>#include "gif_lib.h"#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;#ifdef __MSDOS__static unsigned int ScreenBase;#endif /* __MSDOS__ */#if defined(HAVE_LIBGL_S) || defined(HAVE_LIBX11)GifByteType *GlblGifBuffer = NULL, *GlblGifBufferPtr = NULL;#endif /* HAVE_LIBGL_S || HAVE_LIBX11 */#ifdef HAVE_LIBGL_Sstatic int QuantizeRGBBuffer(int Width, int Height, long *RGBBuffer,                             GifColorType * ColorMap,                             GifByteType * GIFBuffer);#endif /* HAVE_LIBGL_S */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. *****************************************************************************/intDumpScreen2Gif(const char *FileName,               int ReqGraphDriver,               long ReqGraphMode1,               long ReqGraphMode2,               long 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(HAVE_LIBGL_S)    long *RGBBuffer;#ifndef HAVE_LIBX11    GifColorType ColorMap256[256];#endif /* Undefined HAVE_LIBX11 */#endif /* HAVE_LIBGL_S */#ifdef HAVE_LIBX11    XImage *XImg;    unsigned long XPixel;    GifColorType ColorMap256[256];    XColor XColorTable[256];    /* Up to 256 colors in X. */    XWindowAttributes WinAttr;#endif /* HAVE_LIBX11 */    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 HAVE_LIBGL_S      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 /* HAVE_LIBGL_S */#ifdef HAVE_LIBX11      case GIF_DUMP_X_WINDOW:          XGetWindowAttributes((Display *) ReqGraphMode2,                               (Window) ReqGraphMode1, &WinAttr);          ScreenXMax = WinAttr.width;          ScreenYMax = WinAttr.height;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -