Changeset 42427
- Timestamp:
- Mar 18, 2023, 9:52:09 AM (3 years ago)
- Location:
- branches/eam_branches/ipp-20230313/Ohana/src/kapa2
- Files:
-
- 1 added
- 4 edited
-
Makefile (modified) (3 diffs)
-
include/constants.h (modified) (1 diff)
-
include/prototypes.h (modified) (1 diff)
-
src/FindColormap.c.in (added)
-
src/SetColormap.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20230313/Ohana/src/kapa2/Makefile
r41344 r42427 11 11 INC = $(HOME)/include 12 12 include ../../Makefile.Common 13 14 %.c : %.c.in 15 sed "s|@DATADIR@|$(DATA)|" $< > $@ 13 16 14 17 # programs may add their own internal requirements here … … 100 103 $(SRC)/CheckButtons.$(ARCH).o $(SRC)/InvertButton.$(ARCH).o \ 101 104 $(SRC)/UpdatePointer.$(ARCH).o $(SRC)/JPEGit24.$(ARCH).o \ 102 $(SRC)/ButtonFunctions.$(ARCH).o \ 103 $(SRC)/SetChannel.$(ARCH).o \ 105 $(SRC)/ButtonFunctions.$(ARCH).o $(SRC)/FindColormap.$(ARCH).o \ 104 106 $(SRC)/SetColorScale.$(ARCH).o $(SRC)/ColorCube.$(ARCH).o \ 105 $(SRC)/ColorHistogram.$(ARCH).o $(SRC)/CreateWide.$(ARCH).o 107 $(SRC)/ColorHistogram.$(ARCH).o $(SRC)/CreateWide.$(ARCH).o \ 108 $(SRC)/SetChannel.$(ARCH).o 106 109 107 110 OBJ = $(KAPA) $(PDF) $(BDRAW) $(PSFILES) … … 116 119 117 120 $(BIN)/kapa.$(ARCH): $(OBJ) 121 122 .PRECIOUS: $(SRC)/FindColormap.c -
branches/eam_branches/ipp-20230313/Ohana/src/kapa2/include/constants.h
r40501 r42427 54 54 } KapaChannels; 55 55 56 typedef enum { 57 KAPA_CM_RAW, 58 KAPA_CM_CSV, 59 KAPA_CM_CET, 60 KAPA_CM_CET_REV, 61 KAPA_CM_LEGACY, 62 KAPA_CM_STATIC, 63 } KapaColorMapMode; 64 56 65 // use an enum to identify the 3 dimensions: 57 66 typedef enum { -
branches/eam_branches/ipp-20230313/Ohana/src/kapa2/include/prototypes.h
r41344 r42427 328 328 int ResizeByImage (int sock); 329 329 330 char *ParseColormapName (char *name, KapaColorMapMode *mode); 331 int CheckFileAccess (char *name); 332 char *FindColormap (char *name); 333 334 -
branches/eam_branches/ipp-20230313/Ohana/src/kapa2/src/SetColormap.c
r41341 r42427 214 214 215 215 /* anuenue */ 216 if (!strncmp (graphic->colormapName, "file:", 5) || 217 !strncmp (graphic->colormapName, "lgcy:", 5) || 218 !strncmp (graphic->colormapName, "cetf:", 5) || 219 !strncmp (graphic->colormapName, "cetr:", 5) || 220 !strncmp (graphic->colormapName, "csvf:", 5)) { 221 222 FILE *f = fopen (&graphic->colormapName[5], "r"); 223 if (!f) { 224 fprintf (stderr, "failed to open colormap file %s\n", &graphic->colormapName[5]); 216 KapaColorMapMode mode = KAPA_CM_STATIC; 217 218 char *basename = ParseColormapName (graphic->colormapName, &mode); 219 if (mode == KAPA_CM_STATIC) { 220 fprintf (stderr, "unknown static colormap name %s\n", &graphic->colormapName); 221 free (basename); 222 return FALSE; 223 } 224 225 // look in local directory and installation directory 226 char *truename = FindColormap (basename); 227 FREE (basename); 228 229 if (!truename) { 230 fprintf (stderr, "cannot find colormap file %s\n", &graphic->colormapName[5]); 225 231 return FALSE; 226 } 227 char line[1024]; 228 229 int lastIndex = 0; 230 float lastRed = 0.0; 231 float lastBlue = 0.0; 232 float lastGreen = 0.0; 233 234 int isCSV = !strncmp (graphic->colormapName, "csvf:", 5); 235 int isCET = !strncmp (graphic->colormapName, "cetf:", 5); 236 int isCETRev = !strncmp (graphic->colormapName, "cetr:", 5); 237 int isLegacy = !strncmp (graphic->colormapName, "lgcy:", 5); 238 239 float fracIndex, fracRed, fracBlue, fracGreen; 240 241 if (isCET || isCETRev) fracIndex = 0.0; 242 243 while (scan_line_maxlen (f, line, 1024) != EOF) { 244 // file contains f R G B : f = 0.0 - 1.0, R,G,B = 0.0 - 1.0 245 246 int Nscan; 247 if (isCSV) { 248 Nscan = sscanf (line, "%f,%f,%f,%f", &fracIndex, &fracRed, &fracGreen, &fracBlue); 249 if (Nscan != 4) continue; 250 } 251 if (isCET || isCETRev) { 252 Nscan = sscanf (line, "%f,%f,%f", &fracRed, &fracGreen, &fracBlue); 253 fracIndex += 1.0 / 256.0; 254 if (Nscan != 3) continue; 255 } 256 if (isLegacy) { 257 Nscan = sscanf (line, "%f %f %f %f", &fracIndex, &fracRed, &fracBlue, &fracGreen); 258 if (Nscan != 4) continue; 259 } 260 if (!isCSV && !isLegacy && !isCET && !isCETRev) { 261 Nscan = sscanf (line, "%f %f %f %f", &fracIndex, &fracRed, &fracGreen, &fracBlue); 262 if (Nscan != 4) continue; 263 } 264 265 int nextIndex = fracIndex * MaxValue; 266 if (nextIndex <= lastIndex) { 267 lastRed = fracRed; 268 lastBlue = fracBlue; 269 lastGreen = fracGreen; 270 continue; 271 } 272 float dRdI = (fracRed - lastRed) / (float) (nextIndex - lastIndex); 273 float dBdI = (fracBlue - lastBlue) / (float) (nextIndex - lastIndex); 274 float dGdI = (fracGreen - lastGreen) / (float) (nextIndex - lastIndex); 275 for (i = lastIndex; i < nextIndex; i++) { 276 float redValue = 0xffff * (dRdI * (i - lastIndex) + lastRed); 277 float blueValue = 0xffff * (dBdI * (i - lastIndex) + lastBlue); 278 float greenValue = 0xffff * (dGdI * (i - lastIndex) + lastGreen); 279 SETVALUE (graphic[0].cmap[i].red, redValue, 0, 0xffff); 280 SETVALUE (graphic[0].cmap[i].blue, blueValue, 0, 0xffff); 281 SETVALUE (graphic[0].cmap[i].green, greenValue, 0, 0xffff); 282 } 232 } 233 234 FILE *f = fopen (truename, "r"); 235 if (!f) { 236 fprintf (stderr, "failed to open colormap file %s\n", truename); 237 FREE (truename); 238 return FALSE; 239 } 240 FREE (truename); 241 242 char line[1024]; 243 244 int lastIndex = 0; 245 float lastRed = 0.0; 246 float lastBlue = 0.0; 247 float lastGreen = 0.0; 248 249 float fracIndex, fracRed, fracBlue, fracGreen; 250 251 if (mode == KAPA_CM_CET || mode == KAPA_CM_CET_REV) fracIndex = 0.0; 252 253 while (scan_line_maxlen (f, line, 1024) != EOF) { 254 // file contains f R G B : f = 0.0 - 1.0, R,G,B = 0.0 - 1.0 255 256 int Nscan; 257 if (mode == KAPA_CM_CSV) { 258 Nscan = sscanf (line, "%f,%f,%f,%f", &fracIndex, &fracRed, &fracGreen, &fracBlue); 259 if (Nscan != 4) continue; 260 } 261 if ((mode == KAPA_CM_CET || mode == KAPA_CM_CET_REV)) { 262 Nscan = sscanf (line, "%f,%f,%f", &fracRed, &fracGreen, &fracBlue); 263 fracIndex += 1.0 / 256.0; 264 if (Nscan != 3) continue; 265 } 266 if (mode == KAPA_CM_LEGACY) { 267 Nscan = sscanf (line, "%f %f %f %f", &fracIndex, &fracRed, &fracBlue, &fracGreen); 268 if (Nscan != 4) continue; 269 } 270 if (mode == KAPA_CM_RAW) { 271 Nscan = sscanf (line, "%f %f %f %f", &fracIndex, &fracRed, &fracGreen, &fracBlue); 272 if (Nscan != 4) continue; 273 } 274 275 int nextIndex = fracIndex * MaxValue; 276 if (nextIndex <= lastIndex) { 283 277 lastRed = fracRed; 284 278 lastBlue = fracBlue; 285 279 lastGreen = fracGreen; 286 lastIndex = nextIndex; 287 } 288 fclose (f); 289 290 if ((int) (MaxValue*fracIndex) < MaxValue) { 291 float dRdI = (1.0 - lastRed) / (float) (MaxValue - lastIndex); 292 float dBdI = (1.0 - lastBlue) / (float) (MaxValue - lastIndex); 293 float dGdI = (1.0 - lastGreen) / (float) (MaxValue - lastIndex); 294 for (i = lastIndex; i < MaxValue; i++) { 295 float redValue = 0xffff * (dRdI * (i - lastIndex) + lastRed); 296 float blueValue = 0xffff * (dBdI * (i - lastIndex) + lastBlue); 297 float greenValue = 0xffff * (dGdI * (i - lastIndex) + lastGreen); 298 SETVALUE (graphic[0].cmap[i].red, redValue, 0, 0xffff); 299 SETVALUE (graphic[0].cmap[i].blue, blueValue, 0, 0xffff); 300 SETVALUE (graphic[0].cmap[i].green, greenValue, 0, 0xffff); 301 } 302 } 303 304 // reverse the color sequence: 305 if (isCETRev) { 306 for (i = 0; i < MaxValue / 2; i++) { 307 unsigned short tmp; 308 // fprintf (stderr, "swap: %d %d\n", graphic[0].cmap[i].red, graphic[0].cmap[MaxValue - 1 - i].red); 309 tmp = graphic[0].cmap[i].red; graphic[0].cmap[i].red = graphic[0].cmap[MaxValue - 1 - i].red; graphic[0].cmap[MaxValue - 1 - i].red = tmp; 310 tmp = graphic[0].cmap[i].blue; graphic[0].cmap[i].blue = graphic[0].cmap[MaxValue - 1 - i].blue; graphic[0].cmap[MaxValue - 1 - i].blue = tmp; 311 tmp = graphic[0].cmap[i].green; graphic[0].cmap[i].green = graphic[0].cmap[MaxValue - 1 - i].green; graphic[0].cmap[MaxValue - 1 - i].green = tmp; 312 } 313 } 314 315 goto store_colors; 316 } 317 318 return (FALSE); 280 continue; 281 } 282 float dRdI = (fracRed - lastRed) / (float) (nextIndex - lastIndex); 283 float dBdI = (fracBlue - lastBlue) / (float) (nextIndex - lastIndex); 284 float dGdI = (fracGreen - lastGreen) / (float) (nextIndex - lastIndex); 285 for (i = lastIndex; i < nextIndex; i++) { 286 float redValue = 0xffff * (dRdI * (i - lastIndex) + lastRed); 287 float blueValue = 0xffff * (dBdI * (i - lastIndex) + lastBlue); 288 float greenValue = 0xffff * (dGdI * (i - lastIndex) + lastGreen); 289 SETVALUE (graphic[0].cmap[i].red, redValue, 0, 0xffff); 290 SETVALUE (graphic[0].cmap[i].blue, blueValue, 0, 0xffff); 291 SETVALUE (graphic[0].cmap[i].green, greenValue, 0, 0xffff); 292 } 293 lastRed = fracRed; 294 lastBlue = fracBlue; 295 lastGreen = fracGreen; 296 lastIndex = nextIndex; 297 } 298 fclose (f); 299 300 if ((int) (MaxValue*fracIndex) < MaxValue) { 301 float dRdI = (1.0 - lastRed) / (float) (MaxValue - lastIndex); 302 float dBdI = (1.0 - lastBlue) / (float) (MaxValue - lastIndex); 303 float dGdI = (1.0 - lastGreen) / (float) (MaxValue - lastIndex); 304 for (i = lastIndex; i < MaxValue; i++) { 305 float redValue = 0xffff * (dRdI * (i - lastIndex) + lastRed); 306 float blueValue = 0xffff * (dBdI * (i - lastIndex) + lastBlue); 307 float greenValue = 0xffff * (dGdI * (i - lastIndex) + lastGreen); 308 SETVALUE (graphic[0].cmap[i].red, redValue, 0, 0xffff); 309 SETVALUE (graphic[0].cmap[i].blue, blueValue, 0, 0xffff); 310 SETVALUE (graphic[0].cmap[i].green, greenValue, 0, 0xffff); 311 } 312 } 313 314 // reverse the color sequence: 315 if (mode == KAPA_CM_CET_REV) { 316 for (i = 0; i < MaxValue / 2; i++) { 317 unsigned short tmp; 318 // fprintf (stderr, "swap: %d %d\n", graphic[0].cmap[i].red, graphic[0].cmap[MaxValue - 1 - i].red); 319 tmp = graphic[0].cmap[i].red; graphic[0].cmap[i].red = graphic[0].cmap[MaxValue - 1 - i].red; graphic[0].cmap[MaxValue - 1 - i].red = tmp; 320 tmp = graphic[0].cmap[i].blue; graphic[0].cmap[i].blue = graphic[0].cmap[MaxValue - 1 - i].blue; graphic[0].cmap[MaxValue - 1 - i].blue = tmp; 321 tmp = graphic[0].cmap[i].green; graphic[0].cmap[i].green = graphic[0].cmap[MaxValue - 1 - i].green; graphic[0].cmap[MaxValue - 1 - i].green = tmp; 322 } 323 } 319 324 320 325 store_colors:
Note:
See TracChangeset
for help on using the changeset viewer.
