home *** CD-ROM | disk | FTP | other *** search
/ Fractal Frenzy 1 / WalnutCreekFractalFrenzy-1.iso / pc / programs / frasrc.exe / LOADMAP.C < prev    next >
C/C++ Source or Header  |  1993-04-07  |  2KB  |  94 lines

  1. /** loadmap.c **/
  2.  
  3.  
  4. #include    <stdio.h>
  5. #include    <stdlib.h>
  6. #ifndef XFRACT
  7. #include    <dos.h>
  8. #endif
  9. #include    <string.h>
  10. #include    "fractint.h"
  11. #include    "prototyp.h"
  12.  
  13. typedef struct palett {
  14.    BYTE red;
  15.    BYTE green;
  16.    BYTE blue;
  17. } Palettetype;
  18.  
  19. extern Palettetype    dacbox[ 256 ];
  20. extern unsigned far    *tga16;
  21. extern long    far    *tga32;
  22. extern char    far    *mapdacbox;
  23. extern int        colorstate; /* comments in cmdfiles */
  24. extern char        colorfile[];
  25.  
  26. /***************************************************************************/
  27.  
  28. void SetTgaColors() {
  29. unsigned    r, g, b, index;
  30.     if (tga16 != NULL)
  31.     for( index = 0; index < 256; index++ ) {
  32.         r = dacbox[index].red    << 2;
  33.         g = dacbox[index].green << 2;
  34.         b = dacbox[index].blue    << 2;
  35.         tga16[index] = ((r&248)<<7) | ((g&248)<<2) | (b>>3);
  36.         tga32[index] = ((long)r<<16) | (g<<8) | b;
  37.     }
  38. }
  39.  
  40. int ValidateLuts( char * fn )
  41. {
  42. FILE * f;
  43. unsigned    r, g, b, index;
  44. CHAR    line[160];
  45. CHAR    temp[81];
  46.     strcpy (temp,fn);
  47.     if (strchr(temp,'.') == NULL) /* Did name have an extension? */
  48.         strcat(temp,".map");  /* No? Then add .map */
  49.     findpath( temp, line);          /* search the dos path */
  50.     f = fopen( line, "r" );
  51.     if (f == NULL) {
  52.         sprintf(line,"Could not load color map %s",fn);
  53.         stopmsg(0,line);
  54.         return 1;
  55.         }
  56.     for( index = 0; index < 256; index++ ) {
  57.         if (fgets(line,100,f) == NULL)
  58.             break;
  59.         sscanf( line, "%u %u %u", &r, &g, &b );
  60.         /** load global dac values **/
  61.         dacbox[index].red   = (r%256) >> 2;    /* maps default to 8 bits */
  62.         dacbox[index].green = (g%256) >> 2;    /* DAC wants 6 bits */
  63.         dacbox[index].blue  = (b%256) >> 2;
  64.     }
  65.     fclose( f );
  66.     while (index < 256)  { /* zap unset entries */
  67.         dacbox[index].red = dacbox[index].blue = dacbox[index].green = 40;
  68.         ++index;
  69.     }
  70.     SetTgaColors();
  71.     colorstate = 2;
  72.     strcpy(colorfile,fn);
  73.     return 0;
  74. }
  75.  
  76.  
  77. /***************************************************************************/
  78.  
  79. int SetColorPaletteName( char * fn )
  80. {
  81.     if( ValidateLuts( fn ) != 0)
  82.         return 1;
  83.     if( mapdacbox == NULL && (mapdacbox = farmemalloc(768L)) == NULL) {
  84.         static char far msg[]={"Insufficient memory for color map."};
  85.         stopmsg(0,msg);
  86.         return 1;
  87.         }
  88.     far_memcpy((char far *)mapdacbox,(char far *)dacbox,768);
  89.     /* PB, 900829, removed atexit(RestoreMap) stuff, goodbye covers it */
  90.     return 0;
  91. }
  92.  
  93.  
  94.