File: common\loadmap.c

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