IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42489


Ignore:
Timestamp:
Aug 12, 2023, 10:23:09 AM (3 years ago)
Author:
eugene
Message:

install colormaps in defined location, make them discoverable

Location:
branches/eam_branches/ipp-20230313/Ohana/src/kapa2
Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20230313/Ohana/src/kapa2/Makefile

    r42427 r42489  
    1010SRC     =       $(HOME)/src
    1111INC     =       $(HOME)/include
     12DATA    =       $(DESTDATA)/kapa
    1213include ../../Makefile.Common
    1314
     
    110111OBJ  =  $(KAPA) $(PDF) $(BDRAW) $(PSFILES)
    111112
     113cmaps:
     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
    112120# dependancy rules for include files ########################
    113121$(OBJ): $(INC)/Ximage.h \
  • branches/eam_branches/ipp-20230313/Ohana/src/kapa2/include/constants.h

    r42427 r42489  
    5555
    5656typedef enum {
     57  KAPA_CM_NONE,
    5758  KAPA_CM_RAW,
    5859  KAPA_CM_CSV,
  • branches/eam_branches/ipp-20230313/Ohana/src/kapa2/include/prototypes.h

    r42427 r42489  
    331331int CheckFileAccess (char *name);
    332332char *FindColormap (char *name);
    333 
    334 
     333char *ParseColormapModeFromEnum (KapaColorMapMode mode);
     334void ListColormap (void);
  • branches/eam_branches/ipp-20230313/Ohana/src/kapa2/src/FindColormap.c.in

    r42437 r42489  
    11# include "Ximage.h"
     2# include <glob.h>
    23
    34// look for the colormap files in the local directory first, then
    45// in the directory given by @DATADIR@
    56// 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
    611
    712char *ParseColormapName (char *name, KapaColorMapMode *mode) {
     
    1924
    2025  return (strcreate (&name[5]));
     26}
     27
     28static char *KAPA_CM_NAME_NONE   = "none";
     29static char *KAPA_CM_NAME_STATIC = "static";
     30static char *KAPA_CM_NAME_RAW    = "raw";
     31static char *KAPA_CM_NAME_LGCY   = "lgcy";
     32static char *KAPA_CM_NAME_CETF   = "cetf";
     33static char *KAPA_CM_NAME_CETR   = "cetr";
     34static char *KAPA_CM_NAME_CSVF   = "csvf";
     35
     36char *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
     48int 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;
    21101}
    22102
     
    51131char *FindColormap (char *name) {
    52132
    53   static char *datadir = "@DATADIR@";
     133  static char *datadir = "@DATADIR@/colormaps";
    54134
    55135  char *filename;
     
    58138  // make a copy of the file name if it is found locally
    59139  if (CheckFileAccess (name)) {
     140    fprintf (stderr, "found local: %s\n", name);
    60141    return (strcreate (name));
    61142  }
     
    68149  // make a copy of the file name if it is found locally
    69150  if (CheckFileAccess (filename)) {
     151    fprintf (stderr, "found installed: %s\n", filename);
    70152    return (strcreate (filename));
    71153  }
     
    74156}
    75157
     158// returns the name of an existing file
     159void 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  
    2121  float scale, blueRef, redRef, greenRef;
    2222  Graphic *graphic;
     23
     24  if (!strcasecmp(inName, "list")) {
     25    ListColormaps ();
     26    return TRUE;
     27  }
    2328
    2429  graphic = GetGraphic();
     
    232237      return FALSE;
    233238  }
    234 
     239 
    235240  FILE *f = fopen (truename, "r");
    236241  if (!f) {
     
    252257  if (mode == KAPA_CM_CET || mode == KAPA_CM_CET_REV) fracIndex = 0.0;
    253258
     259  int checkFormat = TRUE;
     260
    254261  while (scan_line_maxlen (f, line, 1024) != EOF) {
    255262    // 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    }
    256287
    257288    int Nscan;
Note: See TracChangeset for help on using the changeset viewer.