home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / grap / util / 010 / encoder.c < prev    next >
C/C++ Source or Header  |  1993-03-28  |  29KB  |  880 lines

  1. /*
  2.     encoder.c - GIF Encoder and associated routines
  3.     This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
  4. */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #ifndef XFRACT
  10. #include <io.h>
  11. #endif
  12. #include "fractint.h"
  13. #include "fractype.h"
  14. #include "prototyp.h"
  15.  
  16. /* MCP 10-27-91 */
  17. #ifdef WINFRACT
  18.    extern int OperCancelled;
  19.    void OpenStatusBox(void);
  20.    void UpdateStatusBox(unsigned long Partial, unsigned long Total);
  21.    void CloseStatusBox(void);
  22. #endif
  23.  
  24. extern char s_cantopen[];
  25. extern char s_cantwrite[];
  26. extern char s_cantcreate[];
  27. extern char s_cantunderstand[];
  28. extern char s_cantfind[];
  29. extern char maxfn;
  30. static void _fastcall setup_save_info(struct fractal_info *);
  31. static int inittable(void);
  32. static int _fastcall shftwrite(BYTE *color,int numcolors);
  33. static int _fastcall raster(unsigned int);
  34. static int  _fastcall extend_blk_len(int datalen);
  35. static int _fastcall put_extend_blk(int block_id,int block_len,char far *block_data);
  36. static int  _fastcall store_item_name(char *);
  37.  
  38. extern int initbatch;
  39. extern char far *resume_info;        /* pointer to resume info if allocated */
  40. extern int  resume_len;         /* length of resume info */
  41. extern char LName[];
  42. extern char FormName[];         /* formula name */
  43. extern char IFSName[];
  44. extern int  active_system;        /* 0=dos, 1=windows */
  45. extern int  far *ranges;
  46. extern int  rangeslen;
  47.  
  48. extern    int    sxdots,sydots;        /* # of dots on the physical screen    */
  49. extern    int    sxoffs,syoffs;        /* physical top left of logical screen */
  50. extern    int    xdots, ydots;        /* # of dots on the logical screen     */
  51. extern    int    viewwindow;        /* 0 for full screen, 1 for window */
  52. extern    float    finalaspectratio;    /* for view shape and rotation */
  53. extern    int    viewxdots,viewydots;    /* explicit view sizing */
  54. extern    int    colors;         /* maximum colors available */
  55. extern    int    dotmode;        /* so we can detect disk-video */
  56. extern    char overwrite;         /* overwrite on/off */
  57. extern    int    resave_flag;        /* resaving after a timed save */
  58. extern    int    started_resaves;
  59. extern    int    timedsave;        /* if doing an auto save */
  60. extern    int    disk16bit;        /* 16 bit continuous potential */
  61.  
  62. extern BYTE dacbox[256][3];    /* Video-DAC (filled in by SETVIDEO) */
  63. extern    int    gotrealdac;        /* DAC valid? */
  64. extern int    daclearn, daccount;    /* used by the color-cyclers */
  65. extern int    extraseg;        /* used by Save-to-GIF routines */
  66. extern int    debugflag;
  67.  
  68. extern int    gif87a_flag;        /* if 1, supress GIF extension blocks */
  69.  
  70. extern int    calc_status;
  71. extern long   calctime;
  72. extern char   stdcalcmode;
  73. extern int    fractype;
  74. extern double xxmin,xxmax;
  75. extern double yymin,yymax;
  76. extern double xx3rd,yy3rd;
  77. extern double param[];
  78. extern int    major_method;        /* inverse julia parms */
  79. extern int    minor_method;
  80. extern int    maxit;            /* try this many iterations */
  81. extern int    fillcolor;        /* fill color: -1 = normal  */
  82. extern int    inside;            /* inside color: 1=blue     */
  83. extern int    outside;            /* outside color, if set    */
  84. extern int    finattract;        /* finite attractor option  */
  85. extern int    forcesymmetry;
  86. extern int    LogFlag;            /* non-zero if logarithmic palettes */
  87. extern int    rflag, rseed;
  88. extern int    periodicitycheck;
  89. extern char   useinitorbit;
  90. extern _CMPLX initorbit;
  91. extern int    pot16bit;
  92. extern float  finalaspectratio;
  93. extern double potparam[3];        /* three potential parameters*/
  94. extern double inversion[];
  95. extern int    decomp[];
  96. extern int    distest;            /* non-zero if distance estimator   */
  97. extern int    distestwidth;
  98. extern int    init3d[20];        /* '3d=nn/nn/nn/...' values */
  99. extern char   floatflag;        /* floating-point fractals? */
  100. extern int    usr_biomorph;
  101. extern int    bailout;            /* user input bailout value */
  102. extern int    previewfactor;
  103. extern int    xtrans;
  104. extern int    ytrans;
  105. extern int    red_crop_left;
  106. extern int    red_crop_right;
  107. extern int    blue_crop_left;
  108. extern int    blue_crop_right;
  109. extern int    red_bright;
  110. extern int    blue_bright;
  111. extern int    xadjust;
  112. extern int    eyeseparation;
  113. extern int    glassestype;
  114. extern int    save_system;
  115. extern int    save_release;
  116. extern int    display3d;        /* 3D display flag: 0 = OFF */
  117. extern int    Ambient;
  118. extern int    RANDOMIZE;
  119. extern int    haze;
  120. extern int    transparent[2];
  121. extern int    rotate_lo,rotate_hi;
  122. extern char   busy;
  123. extern float  screenaspect;
  124. extern     double mxmaxfp;
  125. extern     double mxminfp;
  126. extern     double mymaxfp;
  127. extern     double myminfp;
  128. extern     int zdots;        
  129. extern     float originfp;
  130. extern     float depthfp;    
  131. extern     float heightfp;
  132. extern     float widthfp;    
  133. extern     float distfp;    
  134. extern     float eyesfp;    
  135. extern     int neworbittype;
  136. extern     short juli3Dmode;
  137.     
  138. #ifdef XFRACT
  139. extern int decode_fractal_info();
  140. #endif
  141.  
  142. /*
  143.             Save-To-Disk Routines (GIF)
  144.  
  145. GIF and 'Graphics Interchange Format' are trademarks (tm) of Compuserve
  146. Incorporated, an H&R Block Company.
  147.  
  148.  
  149. The following routines perform the GIF encoding when the 's' key is pressed.
  150. The routines refer to several variables that are declared elsewhere
  151. [colors, xdots, ydots, and 'dacbox'], and rely on external routines to
  152. actually read and write screen pixels [getcolor(x,y) and putcolor(x,y,color)].
  153. (Writing pixels is just stuffed in here as a sort of visual status report,
  154. and has nothing to do with any GIF function.)    They also rely on the
  155. existence of an externally-defined 64K dataspace and they use the routines
  156. 'toextra()' and 'cmpextra()' to deal with that dataspace (in the same manner
  157. as 'memcpy()' and 'memcmp()' would).   Otherwise, they perform a generic
  158. GIF-encoder function.
  159.  
  160. Note that these routines use small string- and hash-tables, and "flush"
  161. the GIF entries whenever the hash-table gets two-thirds full or the string
  162. table gets full.   They also use the GIF encoding technique of limiting the
  163. encoded string length to a specific size, "adding" a string to the hash table
  164. at that point even if a matching string exists ("adding" is in quotes, because
  165. if a matching string exists we can increment the code counter but safely throw
  166. the duplicate string away, saving both string space and a hash table entry).
  167.  
  168.    This results in relatively good speed and small data space, but at the
  169. expense of compression efficiency (filesize).    These trade-offs could be
  170. adjusted by modifying the #DEFINEd variables below.
  171.  
  172. Note that the 'strlocn' and 'teststring' routines are declared
  173. to be external just so that they can be defined (and the space re-used)
  174. elsewhere.  The actual declarations are in the assembler code.
  175.  
  176. */
  177.  
  178. #define MAXTEST   100        /* maximum single string length */
  179. #define MAXSTRING 64000     /* total space reserved for strings */
  180.                 /* maximum number of strings available */
  181. #define MAXENTRY  5003        /* (a prime number is best for hashing) */
  182.  
  183. #ifndef XFRACT
  184. extern unsigned int strlocn[MAXENTRY];
  185. extern BYTE teststring[MAXTEST];
  186. extern BYTE block[266];   /* GIF-encoded blocks go here */
  187. #else
  188. unsigned int strlocn[10240];
  189. BYTE teststring[MAXTEST];
  190. BYTE block[266];   /* GIF-encoded blocks go here */
  191. #endif
  192.  
  193. static int numsaves = 0;    /* For adjusting 'save-to-disk' filenames */
  194.  
  195. static FILE *out;
  196. static int last_colorbar;
  197. static int save16bit;
  198. static int outcolor1s, outcolor2s;
  199.  
  200. static int lentest, lastentry, numentries, numrealentries;
  201. static unsigned int nextentry;
  202. static int clearcode, endcode;
  203. static unsigned int hashcode;
  204.  
  205. static BYTE blockcount;
  206. static int startbits, codebits, bytecount, bitcount;
  207.  
  208. static char paletteBW[] = {            /* B&W palette */
  209.       0,  0,  0, 63, 63, 63,
  210.     };
  211. static char paletteCGA[] = {            /* 4-color (CGA) palette  */
  212.       0,  0,  0, 21, 63, 63, 63, 21, 63, 63, 63, 63,
  213.     };
  214. static char paletteEGA[] = {            /* 16-color (EGA/CGA) pal */
  215.       0,  0,  0,  0,  0, 42,  0, 42,  0,  0, 42, 42,
  216.      42,  0,  0, 42,  0, 42, 42, 21,  0, 42, 42, 42,
  217.      21, 21, 21, 21, 21, 63, 21, 63, 21, 21, 63, 63,
  218.      63, 21, 21, 63, 21, 63, 63, 63, 21, 63, 63, 63,
  219.     };
  220.  
  221. void encoder_overlay() { }    /* for restore_active_ovly */
  222.  
  223. int savetodisk(filename)    /* save-to-disk routine */
  224.    char *filename;
  225.    {
  226.    char tmpmsg[41]