home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume30 / ascgif / part01 next >
Text File  |  1992-05-23  |  22KB  |  564 lines

  1. Newsgroups: comp.sources.misc
  2. From: jwf10@ccc.amdahl.com (John Ferrell Jr)
  3. Subject:  v30i019:  ascgif - ASCII gif viewer for mainframes, Part01/01
  4. Message-ID: <1992May24.040232.21900@sparky.imd.sterling.com>
  5. X-Md4-Signature: 72968f6a036b0ee6f1fa50da1049537e
  6. Date: Sun, 24 May 1992 04:02:32 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jwf10@ccc.amdahl.com (John Ferrell Jr)
  10. Posting-number: Volume 30, Issue 19
  11. Archive-name: ascgif/part01
  12. Environment: UNIX
  13.  
  14. Ascgif version 1.6 is a mainframe gif viewer for text output.  New with 
  15. version 1.6 is screen capture.  Views gifs in ascii characters. Not 
  16. breath-taking but good for a preview or gif 87a checker before file 
  17. transfer to pc. Best when viewed by a terminal with light characters and 
  18. a black background.  C code for mainframes follows at end.
  19. Here are some samples:
  20.  
  21. 79x23 output from ascgif
  22. rat.gif    A rat leaning over a shelf.
  23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  25. ;;;;;;;;;;;;;;;;;;;;;;;;;+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;+;;;;;;+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  27. ;;;;;;;;;;;;;;+;;;;;;;+;;++;++++++++;+;;;;;;IT=;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  28. ;;;;;;;;;;;;;;;++;+;+++++(IHXXXXXXOOOHLT)(TI))IIT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  29. ;;;;;;;;;;;;;;;++HHHLLHX88888888X8XXXOOHHTI)IITIIT;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  30. +;;;;;+;;+;;;;++TOOOHTTHHO888XXXXXOOOXOLL))IIIITTT)++;;;;;;;;;;;;;;;;;;;;;;;;;; 
  31. +;;;;;++++++++IOOOOLHLHOXX888888888888OLI)I)IITTTTTI)=+;;;;;;;;;;;;;;;;;;;;;;;; 
  32. ;+;;;;+++++=H888OOHHHOXXX88888888XOOOHHTTI(()ITTTIIII)(=+;;;;;;;;;;;;;;;;;;;;;; 
  33. +;;+;++++=IO88888OOOHOO888888888XOLLLLTT)()()))IIIII)))(+;;;;;;;;;;;;;;;;;;;;;; 
  34. +;++++++=IX8888888XXHHX8XXX888XXHLT)))I)I)((((()((((((((=+;;;;;;;;;;;;;;;;;;;;; 
  35. ++;;+++=(HX88888888OOHOX;LOXXXXOHI+..;)))(===+=(((=======+;;++;;;;;;;;;;;;;;;;; 
  36. ++;++++=)HOXX888888XXHHOOOOXXOOHTIIIIII)=((=====(((=++++++;;;;;;;;;;;;;;;;;;;;; 
  37. ++++++++=THOXXXXXXXXOHHHHHHOHLLTTI)I)(((==++=((((==++;++++;;;;;;;;;;;;;;;;;;;;; 
  38. +++++++++IHHOOXOOOOHHHLTHLLLTTI)))()(((=(==(=======+;++;;;;;;;;;;;;;;;;;;;;;;;; 
  39. =())II(+++(THHHOHLHLLLHLTTT)==+(((=========+====(==++;,,:;;;;;;;;;;;;;;;;;;;;;; 
  40. )))III=:+++(ITHHHLLTTTTLLTT)(((=+===((==+++========+,,:,:;;;;;;;;;;;;;;;;;;;;;; 
  41. .............,.,,:==)IIIITII))((========+;::,..;==+:.................,,,,,::::: 
  42. ......................,,=))))(((==:............:+++,;.......................... 
  43. .........................,.,,:+====+;:........+:.+:;........................... 
  44. ..................................+==+;.........:.............................. 
  45. ..................................,..:;........................................ 
  46. (v)iew (z Z)oom (c)opy (l,r,u,d)=PAN (g)rey (+)(-) (s)wap (1-4)=MIX (q)uit:
  47.  
  48. ----------------------------------------------------------------
  49. #! /bin/sh
  50. # This is a shell archive.  Remove anything before this line, then feed it
  51. # into a shell via "sh file" or similar.  To overwrite existing files,
  52. # type "sh file -c".
  53. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  54. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  55. # Contents:  ascgif.c
  56. # Wrapped by kent@sparky on Sat May 23 22:57:11 1992
  57. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  58. echo If this archive is complete, you will see the following message:
  59. echo '          "shar: End of archive."'
  60. if test -f 'ascgif.c' -a "${1}" != "-c" ; then 
  61.   echo shar: Will not clobber existing file \"'ascgif.c'\"
  62. else
  63.   echo shar: Extracting \"'ascgif.c'\" \(17535 characters\)
  64.   sed "s/^X//" >'ascgif.c' <<'END_OF_FILE'
  65. X/* Ascii Gif Viewer Version 1.6 May (c) 1992 John Ferrell jwf10@juts.ccc.amdahl.com*/
  66. X/* 5 changes for pc to mainframe portability. (search on 'mainframes') */
  67. X
  68. X#include <string.h>
  69. X#include <libc.h>     /* libc.h for mainframes, stdlib.h for pc */
  70. X#include <stdio.h>
  71. X
  72. X#define UBYTE unsigned char  /* 8Bit */
  73. X#define UWORD unsigned short /* 16Bit */
  74. X#define ULONG unsigned int   /* 32Bit  int for mainframes, long for pc */
  75. X#define BOOL unsigned short
  76. X
  77. X#define TRUE  1
  78. X#define FALSE 0
  79. X
  80. X
  81. Xstruct GIFdescriptor {
  82. X   UWORD gd_Width;
  83. X   UWORD gd_Height;
  84. X   UBYTE gd_ColInfo;
  85. X   UBYTE gd_BackGround;
  86. X   UBYTE gd_PixelAspect;
  87. X};
  88. X
  89. Xstruct ImageDesc {
  90. X   UWORD id_Left;
  91. X   UWORD id_Top;
  92. X   UWORD id_Width;
  93. X   UWORD id_Height;
  94. X   UBYTE id_Info;
  95. X};
  96. X
  97. Xstruct RGB {
  98. X   UBYTE rgb_Red;
  99. X   UBYTE rgb_Green;
  100. X   UBYTE rgb_Blue;
  101. X};
  102. X
  103. X
  104. X#define GIF_IMAGE       0x2C
  105. X#define GIF_EXTENSION   0x21
  106. X#define GIF_TERMINATOR  0x3B
  107. X#define GIF_COMMENT_EXT 0xFE
  108. X
  109. X/* void *screen; */  /* uncomment for pc, comment out for mainframes */
  110. X
  111. Xint gx=79;
  112. Xint gy=23;
  113. X
  114. Xstruct GIFdescriptor gdesc;
  115. X
  116. XUBYTE **BitPlane;
  117. Xstruct RGB GlobalColourTable[256];
  118. X
  119. XUBYTE Map[256];
  120. X
  121. XULONG ImageNumber;
  122. X
  123. XFILE *GIFfh = NULL;
  124. XFILE *CAPT = NULL;
  125. X
  126. Xvoid ERROR(str)
  127. X   char *str;
  128. X   {
  129. X   printf(str);
  130. X   exit(1);
  131. X   }
  132. X
  133. Xvoid FlipWord(word)
  134. X   UWORD *word;
  135. X   {
  136. X   UBYTE swap1;
  137. X   UBYTE swap2;
  138. X   swap1 = *word & 0xFF;                /*comment out for pc, needed for mainframes */
  139. X   swap2 = (*word & 0xFF00) >> 8;       /*       "                "                 */
  140. X   *word = swap1 << 8 | swap2;          /*       "                "                 */
  141. X   }
  142. X
  143. Xstatic struct ImageDesc idesc;
  144. Xstatic struct RGB LocalColourTable[256];
  145. X
  146. Xstatic UWORD Xpos, Ypos;
  147. Xstatic BOOL interleave;
  148. X
  149. Xstatic UBYTE LeaveStep[5]  = {1, 8, 8, 4, 2};
  150. Xstatic UBYTE LeaveFirst[5] = {0, 0, 4, 2, 1};
  151. X
  152. Xstatic int ReadError;
  153. Xstatic UBYTE CodeSize;
  154. Xstatic int EOFCode;
  155. Xstatic UBYTE ReadMask;
  156. Xstatic int CompDataPointer;
  157. Xstatic int CompDataCount;
  158. Xstatic UBYTE CompData[256];
  159. X
  160. Xstatic UWORD Prefix[4096];
  161. Xstatic UBYTE Suffix[4096];
  162. Xstatic UBYTE OutCode[1025];
  163. X
  164. Xstatic UBYTE ByteBuf;
  165. X
  166. Xint ReadCode(fh)
  167. X   FILE *fh;
  168. X   {
  169. X   register int temp;
  170. X   register int DstMasked;
  171. X   register int DstMask;
  172. X   long size;
  173. X   temp = 0;                             
  174. X   DstMasked = 1L << CodeSize;           
  175. X   for (DstMask = 1; DstMask != DstMasked; DstMask <<= 1)
  176. X      {                                  
  177. X      if (!ReadMask)                     
  178. X         {                               
  179. X         if (CompDataPointer == CompDataCount)
  180. X            {
  181. X            if ((size = fgetc(fh)) == -1)
  182. X               {                         
  183. X               printf("\nI/O Error during decompression.\n");
  184. X               ReadError = 1;            
  185. X               return EOFCode;           
  186. X               }                         
  187. X            if (fread((char *)CompData,1,size,fh) != size)
  188. X               {                         
  189. X               printf("\nI/O Error during decompression.\n");
  190. X               ReadError = 1;            
  191. X               return EOFCode;           
  192. X               }                         
  193. X            CompDataCount = size;        
  194. X            CompDataPointer = 0;         
  195. X            }                            
  196. X         ReadMask = 1;                   
  197. X         ByteBuf = CompData[CompDataPointer++];
  198. X         }                               
  199. X      if (ByteBuf & ReadMask) temp |= DstMask;
  200. X      ReadMask <<= 1;                    
  201. X      }                                  
  202. X   return temp;                          
  203. X   }                                     
  204. X                                         
  205. Xvoid AddPixel(index)                     
  206. X   UBYTE index;                          
  207. X   {                                     
  208. X   register UWORD XStore;
  209. X   register UWORD YStore;
  210. X   XStore = Xpos + idesc.id_Left;        
  211. X   YStore = Ypos + idesc.id_Top;         
  212. X   BitPlane[YStore][XStore] = index;
  213. X   if (++Xpos == idesc.id_Width)         
  214. X      {                                  
  215. X      Xpos = 0;                          
  216. X      Ypos += LeaveStep[interleave];
  217. X      if (Ypos >= idesc.id_Height) Ypos = LeaveFirst[++interleave];
  218. X      }                                  
  219. X   }                                     
  220. X                                         
  221. XBOOL DoImage(fh)                         
  222. X   FILE *fh;                             
  223. X   {                                     
  224. X   register int index;
  225. X   register int colours;
  226. X   int Code;
  227. X   printf("Image #%ld encountered.\n", ImageNumber++);
  228. X   if (fread((char *)&idesc,1,9,fh) != 9)
  229. X      ERROR("Error reading image descriptor.\n");
  230. X   FlipWord(&idesc.id_Left);             
  231. X   FlipWord(&idesc.id_Top);              
  232. X   FlipWord(&idesc.id_Width);            
  233. X   FlipWord(&idesc.id_Height);           
  234. X   interleave = idesc.id_Info & 1L << 6;
  235. X   if (interleave) interleave = 1;       
  236. X   printf("Xpos from %d to %d, Ypos from %d to %d, %sinterlaced.\n",
  237. X      idesc.id_Left, idesc.id_Left + idesc.id_Width - 1,
  238. X      idesc.id_Top, idesc.id_Top + idesc.id_Height - 1,
  239. X      interleave ? "" : "not ");         
  240. X   if (idesc.id_Info & 1L << 7)          
  241. X      {                                  
  242. X      colours = 1L << ((idesc.id_Info & 7) + 1);
  243. X      printf("Local colour map contains %d entries.\n", colours);
  244. X      for (index = 0; index < colours; index++)
  245. X        if (fread(&LocalColourTable[index],1,3,fh) != 3)
  246. X            ERROR("......Error reading local colour\n");
  247. X      }                                  
  248. X   else                                  
  249. X      {                                  
  250. X      colours = 1L << ((gdesc.gd_ColInfo & 7) + 1);
  251. X      for (index=0; index<colours; index++)
  252. X        LocalColourTable[index]=GlobalColourTable[index];
  253. X      }                                  
  254. X   Xpos = Ypos = 0;                      
  255. X                                         
  256. X   {                                     
  257. X      int MaxCode, ClearCode, CurCode,   
  258. X          OldCode, InCode, FreeCode;     
  259. X      int OutCount;                      
  260. X      int FirstFree;                     
  261. X      UBYTE InitCodeSize, FinChar, BitMask;
  262. X      if ((CodeSize = fgetc(fh)) == -1)
  263. X         ERROR("\n......I/O Error during decompression.\n");
  264. X      ClearCode = 1L << CodeSize;        
  265. X      EOFCode = ClearCode + 1;           
  266. X      FreeCode = FirstFree = ClearCode + 2;
  267. X      CodeSize++;                        
  268. X      InitCodeSize = CodeSize;           
  269. X      MaxCode = 1L << CodeSize;          
  270. X      ReadError = ReadMask = OutCount = 0;
  271. X      CompDataPointer = CompDataCount = 0;
  272. X      BitMask = colours - 1;             
  273. X      Code = ReadCode(fh);               
  274. X      while (Code != EOFCode)            
  275. X         {                               
  276. X         if (ReadError) return TRUE;     
  277. X         if (Code == ClearCode)          
  278. X            {                            
  279. X            CodeSize = InitCodeSize;     
  280. X            MaxCode = 1L << CodeSize;    
  281. X            FreeCode = FirstFree;        
  282. X            FinChar = CurCode = OldCode = Code = ReadCode(fh);
  283. X            AddPixel(FinChar);           
  284. X            }                            
  285. X         else                            
  286. X            {                            
  287. X            CurCode = InCode = Code;     
  288. X            if (CurCode >= FreeCode)     
  289. X               {                         
  290. X               CurCode = OldCode;        
  291. X               OutCode[OutCount++] = FinChar;
  292. X               }                         
  293. X            while (CurCode > BitMask)    
  294. X               {                         
  295. X               if (OutCount > 1024)      
  296. X                  {                      
  297. X                  printf("\nCorrupt GIF file (OutCount)\n");
  298. X                  return TRUE;           
  299. X                  }                      
  300. X                  OutCode[OutCount++] = Suffix[CurCode];
  301. X                  CurCode = Prefix[CurCode];
  302. X               }                         
  303. X            FinChar = CurCode;           
  304. X            AddPixel(FinChar);           
  305. X            for (index = OutCount - 1; index >= 0; index--)
  306. X              AddPixel(OutCode[index]);
  307. X            OutCount = 0;                
  308. X            Prefix[FreeCode] = OldCode;
  309. X            Suffix[FreeCode] = FinChar;
  310. X            OldCode = InCode;            
  311. X            if (++FreeCode >= MaxCode)   
  312. X               {                         
  313. X               if (CodeSize < 12)        
  314. X                  {                      
  315. X                  CodeSize++;            
  316. X                  MaxCode <<= 1;         
  317. X                  }                      
  318. X               }                         
  319. X            }                            
  320. X         Code = ReadCode(fh);            
  321. X      }                                  
  322. X   }                                     
  323. X   if ((Code = fgetc(fh)) == -1) return TRUE;
  324. X   if (Code != 0) printf("Warning:  Unaligned packet.\n");
  325. X   return FALSE;                         
  326. X   }                                     
  327. X                                         
  328. X/* #define gx 79 */
  329. X/* #define gy 23 */
  330. X#define base 5                           
  331. X#define colors 16
  332. X
  333. Xchar *colortab[colors] =
  334. X   {".",",",":",";","+","=","i",")","I","T","L","H","O","X","8","#"};
  335. X                                         
  336. Xvoid show(name)
  337. X   char *name;
  338. X   {
  339. X   register int i,j,x,y;
  340. X   register int ix,iy,ii,jj;
  341. X   struct RGB colour;
  342. X   char Cbuf [1];
  343. X   int flag, cc, zz, dx, dy, z, dcnt, g, gc;
  344. X   x=y=ix=iy=dx=dy=i=j=zz=z=dcnt=g=0;
  345. X   gc=20;
  346. X   cc=1;
  347. X   dx=(idesc.id_Width<<base)/gx;
  348. X   dy=(idesc.id_Height<<base)/gy;
  349. X   do                                    
  350. X   {                                     
  351. X   printf("\n(v)iew (z Z)oom (c)opy (l,r,u,d)=PAN (g)rey (+)(-) (s)wap (1-4)=MIX (h)elp: ");
  352. X   while ((flag=getchar())==(char)10);
  353. X   if (flag == 'v' || flag == 'z' || flag == 'Z' ||
  354. X       flag == 'l' || flag == 'h' || flag == 'c' ||
  355. X       flag == 'r' || flag == 'u' || flag == 'd' || flag == 's' ||
  356. X       flag == 'g' || flag == 'G' || flag == '1' || flag == '2' ||
  357. X       flag == '3' || flag == '4' || flag == '+' || flag == '-'); else return;
  358. X   if (flag=='v')cc=1;
  359. X   if (flag=='1'){cc=1; printf("\nDefault Mix\n");}
  360. X   if (flag=='2'){cc=2; printf("\nRed Mix Blocked\n");}
  361. X   if (flag=='3'){cc=3; printf("\nGreen Mix Blocked\n");}
  362. X   if (flag=='4'){cc=4; printf("\nBlue Mix Blocked\n");}
  363. X   if (flag=='g'){cc=5; printf("\nAssuming This Is A Grey Scale Gif\n");}
  364. X   if (flag=='+'){cc=5; gc+=5; printf("\nRaising Sensitivity To %d, Assuming This Is A Grey Scale Gif\n", gc);}
  365. X   if (flag=='-'){cc=5; gc-=5; printf("\nLowering Sensitivity To %d Assuming This Is A Grey Scale Gif\n", gc);}
  366. X   if (flag=='s'){cc=5;if (g==0)g=1; else g=0; printf("\nSwapping Background For Grey Scale Gif, Assuming This Is A Grey Scale Gif\n");}
  367. X   if (flag=='c'){
  368. X      printf("\nAppending copy of screen to file ascgifs\n");
  369. X      if (!(CAPT = fopen("ascgifs","a"))) ERROR("Open error\n");
  370. X      Cbuf[0] = 10;
  371. X      if(fwrite(Cbuf,1,1,CAPT) != 1)
  372. X         ERROR("Unable to write to ascgifs.\n");
  373. X      if(fwrite(name,1,strlen(name),CAPT) != strlen(name))
  374. X          ERROR("Unable to write to ascgifs.\n");
  375. X      }
  376. X   if (flag=='u'){if(iy>=dy*gy/4) iy=iy-dy*gy/4;};
  377. X   if (flag=='d'){if(iy+dy*gy+2*dy<((idesc.id_Height)<<base)) iy=iy+dy*gy/4;};
  378. X   if (flag=='z'){
  379. X      dx>>=1;                            
  380. X      dy>>=1;
  381. X      ix=ix+dx*gx/2;
  382. X      iy=iy+dy*gy/2;
  383. X      };
  384. X   if (flag=='Z'){
  385. X      dx=(idesc.id_Width<<base)/gx;
  386. X      dy=(idesc.id_Height<<base)/gy;
  387. X      ix=0;
  388. X      iy=0;
  389. X      };
  390. X   if (flag=='r'){if(ix+dx*gx+2*dx<((idesc.id_Width)<<base)) ix=ix+dx*gx/4;};
  391. X   if (flag=='l'){if(ix>=dx*gx/4) ix=ix-dx*gx/4;};
  392. X   y=iy;
  393. X   if (zz == 0){
  394. X      colour=LocalColourTable[BitPlane[(y>>base)+idesc.id_Top]
  395. X                       [(x>>base)+idesc.id_Left]];
  396. X      zz=(colour.rgb_Red+colour.rgb_Green+colour.rgb_Blue)/3;
  397. X   }
  398. X   if (flag == 'h'){
  399. X   printf("\nv = View The Gif\n");
  400. X   printf("z = Zoom In On The Center\n");
  401. X   printf("Z = Zoom Out To Normal Size\n");
  402. X   printf("c = Capture screen\n");
  403. X   printf("l = Pan Left\n");
  404. X   printf("r = Pan Right\n");
  405. X   printf("u = Pan Up\n");
  406. X   printf("d = Pan Down\n");
  407. X   printf("g = Display A Grey Scale Gif, Use Only With A Grey Scale Gif\n");
  408. X   printf("+ = Raise Sensitivity For A Grey Scale Gif\n");
  409. X   printf("- = Lower Sensitivity For A Grey Scale Gif\n");
  410. X   printf("s = Swap Background For Grey Scale Gif From/To Black/White\n");
  411. X   printf("1 = Default Mix\n");
  412. X   printf("2 = Red Mix Blocked\n");
  413. X   printf("3 = Green Mix Blocked\n");
  414. X   printf("4 = Blue Mix Blocked\n");
  415. X   printf("Any other character will quit\n");
  416. X   }
  417. X   else {
  418. X   for (j=0; j<gy; j++)
  419. X      {
  420. X      if (flag== 'c'){
  421. X        Cbuf[0] = 10;
  422. X        if(fwrite(Cbuf,1,1,CAPT) != 1)
  423. X          ERROR("Unable to write to ascgifs.\n");
  424. X      }
  425. X      printf("\n");
  426. X      x=ix;
  427. X      for (i=0; i<gx; i++)
  428. X         {                               
  429. X         if (cc==5){
  430. X          dcnt=0;
  431. X           for (jj=y; jj-y<dy; jj+=4){
  432. X              for (ii=x; ii-x<dx; ii+=4){
  433. X                colour=LocalColourTable[BitPlane[(jj>>base)+idesc.id_Top]
  434. X                                             [(ii>>base)+idesc.id_Left]];
  435. X                z=(colour.rgb_Red+colour.rgb_Green+colour.rgb_Blue)/3;
  436. X                if (g == 1){
  437. X                  if (zz==z)dcnt++;}
  438. X                else if (zz!=z) dcnt++;
  439. X              }
  440. X           };
  441. X           z=dcnt/(dx/gc+dy/gc);
  442. X           if (z<1)z=1;
  443. X           if (z>256)z=256;
  444. X         }
  445. X         else {
  446. X          colour=LocalColourTable[BitPlane[(y>>base)+idesc.id_Top]
  447. X                                         [(x>>base)+idesc.id_Left]];
  448. X          if (cc==2){
  449. X            z=(colour.rgb_Green+colour.rgb_Blue)/2;}
  450. X          else if (cc==3){
  451. X                 z=(colour.rgb_Red+colour.rgb_Blue)/2;}
  452. X              else if (cc==4){
  453. X                      z=(colour.rgb_Red+colour.rgb_Green)/2;}
  454. X                   else {
  455. X                        z=(colour.rgb_Red+colour.rgb_Green+colour.rgb_Blue)/3;
  456. X                        };
  457. X         }
  458. X         if (flag=='c'){
  459. X           Cbuf[0] = *colortab[(z+gc-20)*colors/0x100];
  460. X           if(fwrite(Cbuf,1,1,CAPT) != 1)
  461. X             ERROR("Unable to write to ascgifs.\n");
  462. X         }
  463. X         printf(colortab[(z+gc-20)*colors/0x100]);
  464. X         x+=dx;
  465. X         if (x<0)return;
  466. X      }
  467. X      y+=dy;                             
  468. X      }
  469. X      }
  470. X   if (flag== 'c') fclose(CAPT);
  471. X   } while (TRUE);
  472. X   }                                     
  473. X                                         
  474. Xmain(argc,argv)                          
  475. X   int argc;
  476. X   char *argv[];
  477. X   {                                     
  478. X   register int index;
  479. X   char sig[7];
  480. X   int size;
  481. X   int error;                            
  482. X   int colours;                          
  483. X   long cmdcode;                         
  484. X   if (argc < 2) ERROR("ascgif(1.6) use: ascgif name.gif <output width> <output height>\n");
  485. X   if (!(GIFfh = fopen(argv[1],"r"))) ERROR("Open error\n"); /*"rb" for pc, "r" for SOME mainframes */
  486. X   if (argc > 2){
  487. X     if (!(gx=atoi(argv[2]))) ERROR("3rd parameter not numeric, (width)\n");
  488. X     if (!(gy=atoi(argv[3]))) ERROR("4th parameter not numeric, (height)\n");
  489. X     }
  490. X   else { gx = 79;
  491. X          gy = 23;
  492. X        };
  493. X   sig[6] = '\0';
  494. X   if (fread(sig,1,6,GIFfh) != 6 || strcmp("GIF87a", sig))
  495. X      ERROR("Not an 87a GIF file...\n");
  496. X   if (fread((char *)&gdesc,1,7,GIFfh) != 7)
  497. X      ERROR("Error reading screen descriptor\n");
  498. X   FlipWord(&gdesc.gd_Width);
  499. X   FlipWord(&gdesc.gd_Height);           
  500. X   printf("Ascgif Ver 1.6\n");
  501. X   printf("Signature = \"%s\", Width = %u, Height = %u\n",
  502. X      sig, gdesc.gd_Width, gdesc.gd_Height);
  503. X   colours = 1L << ((gdesc.gd_ColInfo & 7) + 1);
  504. X   if (!(gdesc.gd_ColInfo & 1L << 7))    
  505. X      {                                  
  506. X      printf("No global colour map supplied, using internal.\n");
  507. X      for (index = 0; index < colours; index++)
  508. X         {                               
  509. X         GlobalColourTable[index].rgb_Red   =
  510. X         GlobalColourTable[index].rgb_Green =
  511. X         GlobalColourTable[index].rgb_Blue  = index;
  512. X         }                               
  513. X      }                                  
  514. X   else                                  
  515. X      {                                  
  516. X      printf("Global colour map contains %d entries.\n", colours);
  517. X      for (index = 0; index < colours; index++)
  518. X         if (fread(&GlobalColourTable[index],1,3,GIFfh) != 3)
  519. X            ERROR("Error reading global colour\n");
  520. X      }
  521. X   size = ((gdesc.gd_Width + 7) / 8) + 1;
  522. X   size += (size + 127) >> 7;
  523. X   if (!(BitPlane = (UBYTE **)malloc(gdesc.gd_Height * sizeof(UBYTE *))))
  524. X      ERROR("Not enough memory\n");
  525. X   size = (gdesc.gd_Width + 1) * sizeof(UBYTE);
  526. X   for (index = 0; index < gdesc.gd_Height; index++)
  527. X      if (!(BitPlane[index] = (UBYTE *)malloc(size)))
  528. X         ERROR("Not enough memory\n");
  529. X   ImageNumber = 1;
  530. X   for (error = FALSE; error == FALSE;)
  531. X      {
  532. X      if ((cmdcode = fgetc(GIFfh)) == -1) break;
  533. X      if (cmdcode ==
  534. X          GIF_IMAGE){
  535. X            error = DoImage(GIFfh);
  536. X            } else
  537. X      if (cmdcode ==
  538. X           GIF_EXTENSION){
  539. X            error = TRUE;                
  540. X           } else
  541. X      if (cmdcode ==
  542. X           GIF_TERMINATOR){
  543. X            show(argv[1]);
  544. X            break;
  545. X           }
  546. X           else {
  547. X            printf("Unknown directive encountered.\n");                         
  548. X            error = TRUE;                
  549. X           }
  550. X      }                                  
  551. X      printf("End of GIF session\n");    
  552. X      exit(0);                           
  553. X   } 
  554. X
  555. END_OF_FILE
  556.   if test 17535 -ne `wc -c <'ascgif.c'`; then
  557.     echo shar: \"'ascgif.c'\" unpacked with wrong size!
  558.   fi
  559.   # end of 'ascgif.c'
  560. fi
  561. echo shar: End of archive.
  562. exit 0
  563. exit 0 # Just in case...
  564.