Changeset 42489
- Timestamp:
- Aug 12, 2023, 10:23:09 AM (3 years ago)
- Location:
- branches/eam_branches/ipp-20230313/Ohana/src/kapa2
- Files:
-
- 5 edited
- 1 moved
-
Makefile (modified) (2 diffs)
-
colormaps (moved) (moved from branches/eam_branches/ipp-20230313/Ohana/src/kapa2/cmaps )
-
include/constants.h (modified) (1 diff)
-
include/prototypes.h (modified) (1 diff)
-
src/FindColormap.c.in (modified) (6 diffs)
-
src/SetColormap.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20230313/Ohana/src/kapa2/Makefile
r42427 r42489 10 10 SRC = $(HOME)/src 11 11 INC = $(HOME)/include 12 DATA = $(DESTDATA)/kapa 12 13 include ../../Makefile.Common 13 14 … … 110 111 OBJ = $(KAPA) $(PDF) $(BDRAW) $(PSFILES) 111 112 113 cmaps: 114 @echo "installing colormaps for kapa" 115 @if [ ! -d $(DATA)/colormaps ]; then mkdir -p $(DATA)/colormaps; fi 116 @if [ -d $(HOME)/colormaps ]; then rm -f $(HOME)/colormaps/*~; fi 117 @if [ -d $(HOME)/colormaps ]; then rm -f $(HOME)/colormaps/#*; fi 118 @if [ -d $(HOME)/colormaps ]; then for i in `find $(HOME)/colormaps -name CVS -prune -o -type f -print`; do cp -f $$i $(DATA)/colormaps; done; fi 119 112 120 # dependancy rules for include files ######################## 113 121 $(OBJ): $(INC)/Ximage.h \ -
branches/eam_branches/ipp-20230313/Ohana/src/kapa2/include/constants.h
r42427 r42489 55 55 56 56 typedef enum { 57 KAPA_CM_NONE, 57 58 KAPA_CM_RAW, 58 59 KAPA_CM_CSV, -
branches/eam_branches/ipp-20230313/Ohana/src/kapa2/include/prototypes.h
r42427 r42489 331 331 int CheckFileAccess (char *name); 332 332 char *FindColormap (char *name); 333 334 333 char *ParseColormapModeFromEnum (KapaColorMapMode mode); 334 void ListColormap (void); -
branches/eam_branches/ipp-20230313/Ohana/src/kapa2/src/FindColormap.c.in
r42437 r42489 1 1 # include "Ximage.h" 2 # include <glob.h> 2 3 3 4 // look for the colormap files in the local directory first, then 4 5 // in the directory given by @DATADIR@ 5 6 // XXX : probably need to check the input name length 7 8 // XXX it would help to be able to list the existing colormaps 9 // XXX it would help to be able to recognize the colormap format 10 // or better yet have kapa recognize the type from the file 6 11 7 12 char *ParseColormapName (char *name, KapaColorMapMode *mode) { … … 19 24 20 25 return (strcreate (&name[5])); 26 } 27 28 static char *KAPA_CM_NAME_NONE = "none"; 29 static char *KAPA_CM_NAME_STATIC = "static"; 30 static char *KAPA_CM_NAME_RAW = "raw"; 31 static char *KAPA_CM_NAME_LGCY = "lgcy"; 32 static char *KAPA_CM_NAME_CETF = "cetf"; 33 static char *KAPA_CM_NAME_CETR = "cetr"; 34 static char *KAPA_CM_NAME_CSVF = "csvf"; 35 36 char *ParseColormapModeFromEnum (KapaColorMapMode mode) { 37 38 if (mode == KAPA_CM_NONE) { return KAPA_CM_NAME_NONE; } 39 if (mode == KAPA_CM_STATIC) { return KAPA_CM_NAME_STATIC; } 40 if (mode == KAPA_CM_RAW) { return KAPA_CM_NAME_RAW; } 41 if (mode == KAPA_CM_LEGACY) { return KAPA_CM_NAME_LGCY; } 42 if (mode == KAPA_CM_CET) { return KAPA_CM_NAME_CETF; } 43 if (mode == KAPA_CM_CET_REV) { return KAPA_CM_NAME_CETR; } 44 if (mode == KAPA_CM_CSV) { return KAPA_CM_NAME_CSVF; } 45 return NULL; 46 } 47 48 int CheckColormapFileFormat (char *filename) { 49 50 // is the name one of the static colormaps? 51 int isStatic = FALSE; 52 isStatic = isStatic || !strcasecmp (filename, "fullcolor"); 53 isStatic = isStatic || !strcasecmp (filename, "ruffcolor"); 54 isStatic = isStatic || !strcasecmp (filename, "grayscale"); 55 isStatic = isStatic || !strcasecmp (filename, "greyscale"); 56 isStatic = isStatic || !strcasecmp (filename, "-grayscale"); 57 isStatic = isStatic || !strcasecmp (filename, "-greyscale"); 58 isStatic = isStatic || !strcasecmp (filename, "Heat"); 59 isStatic = isStatic || !strcasecmp (filename, "Rainbow"); 60 isStatic = isStatic || !strcasecmp (filename, "anuenue"); 61 if (isStatic) return KAPA_CM_STATIC; 62 63 // open the file 64 65 FILE *f = fopen (filename, "r"); 66 if (!f) { 67 fprintf (stderr, "failed to open colormap file %s\n", filename); 68 return FALSE; 69 } 70 71 char line[1024]; 72 73 // read until we get a line which is not blank or commented out 74 while (scan_line_maxlen (f, line, 1024) != EOF) { 75 76 // scan past leading whitespace 77 char *p = line; 78 while ((*p != 0) && OHANA_WHITESPACE(*p)) { p++; } 79 if (*p == 0) { continue; } 80 81 // skip any lines with comment character: 82 if (*p == '#') { continue; } 83 84 float fracIndex, fracRed, fracBlue, fracGreen; 85 86 // we have a line to test: 87 int Nscan1 = sscanf (line, "%f,%f,%f,%f", &fracIndex, &fracRed, &fracGreen, &fracBlue); 88 int Nscan2 = sscanf (line, "%f,%f,%f", &fracRed, &fracGreen, &fracBlue); 89 int Nscan3 = sscanf (line, "%f %f %f %f", &fracIndex, &fracRed, &fracBlue, &fracGreen); 90 91 // the scanf does not require the comma, can 92 if (Nscan1 == 4) { return KAPA_CM_CSV; } 93 if (Nscan2 == 3) { return KAPA_CM_CET; } // could also be CET_REV 94 if (Nscan3 == 4) { return KAPA_CM_RAW; } // could also be LEGACY 95 96 fclose (f); 97 return KAPA_CM_NONE; 98 } 99 fclose (f); 100 return KAPA_CM_NONE; 21 101 } 22 102 … … 51 131 char *FindColormap (char *name) { 52 132 53 static char *datadir = "@DATADIR@ ";133 static char *datadir = "@DATADIR@/colormaps"; 54 134 55 135 char *filename; … … 58 138 // make a copy of the file name if it is found locally 59 139 if (CheckFileAccess (name)) { 140 fprintf (stderr, "found local: %s\n", name); 60 141 return (strcreate (name)); 61 142 } … … 68 149 // make a copy of the file name if it is found locally 69 150 if (CheckFileAccess (filename)) { 151 fprintf (stderr, "found installed: %s\n", filename); 70 152 return (strcreate (filename)); 71 153 } … … 74 156 } 75 157 158 // returns the name of an existing file 159 void ListColormaps (void) { 160 161 static char *datadir = "@DATADIR@/colormaps"; 162 char dataglob[1024]; 163 164 sprintf (dataglob, "%s/*.cm", datadir); 165 166 glob_t globList; 167 168 // parse the filename as a glob 169 globList.gl_offs = 0; 170 glob (dataglob, 0, NULL, &globList); 171 172 int Nfile = globList.gl_pathc; 173 for (int i = 0; i < Nfile; i++) { 174 int format = CheckColormapFileFormat (globList.gl_pathv[i]); 175 fprintf (stderr, "%s : %s\n", globList.gl_pathv[i], ParseColormapModeFromEnum (format)); 176 } 177 } 178 -
branches/eam_branches/ipp-20230313/Ohana/src/kapa2/src/SetColormap.c
r42437 r42489 21 21 float scale, blueRef, redRef, greenRef; 22 22 Graphic *graphic; 23 24 if (!strcasecmp(inName, "list")) { 25 ListColormaps (); 26 return TRUE; 27 } 23 28 24 29 graphic = GetGraphic(); … … 232 237 return FALSE; 233 238 } 234 239 235 240 FILE *f = fopen (truename, "r"); 236 241 if (!f) { … … 252 257 if (mode == KAPA_CM_CET || mode == KAPA_CM_CET_REV) fracIndex = 0.0; 253 258 259 int checkFormat = TRUE; 260 254 261 while (scan_line_maxlen (f, line, 1024) != EOF) { 255 262 // file contains f R G B : f = 0.0 - 1.0, R,G,B = 0.0 - 1.0 263 // skip any lines with comment character: 264 265 char *p = line; 266 while ((*p != 0) && OHANA_WHITESPACE(*p)) { p++; } 267 if (*p == 0) { continue; } 268 if (*p == '#') { continue; } 269 270 // attempt to confirm the format (and warn if it does not seem to match) 271 if (checkFormat) { 272 int Nscan1 = sscanf (line, "%f,%f,%f,%f", &fracIndex, &fracRed, &fracGreen, &fracBlue); 273 int Nscan2 = sscanf (line, "%f,%f,%f", &fracRed, &fracGreen, &fracBlue); 274 int Nscan3 = sscanf (line, "%f %f %f %f", &fracIndex, &fracRed, &fracBlue, &fracGreen); 275 276 if (Nscan1 == 4) { 277 if (mode != KAPA_CM_CSV) { fprintf (stderr, "warning: %s appears to be format csvf: not %s\n line: %s\n", graphic->colormapName, ParseColormapModeFromEnum(mode), line); } 278 } 279 if (Nscan2 == 3) { 280 if ((mode != KAPA_CM_CET) && (mode != KAPA_CM_CET_REV)) { fprintf (stderr, "warning: %s appears to be format cetf: or cetf: not %s\n line: %s\n", graphic->colormapName, ParseColormapModeFromEnum(mode), line); } 281 } 282 if (Nscan3 == 4) { 283 if (mode != KAPA_CM_RAW) { fprintf (stderr, "warning: %s appears to be format file: not %s\n line: %s\n", graphic->colormapName, ParseColormapModeFromEnum(mode), line); } 284 } 285 checkFormat = FALSE; 286 } 256 287 257 288 int Nscan;
Note:
See TracChangeset
for help on using the changeset viewer.
