#include #include #include #include #include #include #include #include #include "mview_view.h" #include "mview_misc.h" #include "mview_macros.h" #include "mview_widgets.h" #include #ifdef underscore #define sic_ctrans sic_ctrans_ #define hsv_to_rgb hsv_to_rgb_ #endif #ifdef f2c #define sic_ctrans sic_ctrans__ #define hsv_to_rgb hsv_to_rgb__ #endif #define k_hdraw 1 #define k_sdraw 2 #define k_vdraw 3 #define k_single_draw_a 4 #define k_wedge 5 #define MAXCOL 127 #define MAXCOLWITHB 128 #define MAXPOINT 5 #define NFIRST 120 static int nfirstcol = NFIRST; #define L 126 #define R 3 /* typedef char *caddr_t; */ static Widget hsvshell, hdraw, sdraw, vdraw, lowboundscale, highboundscale; static Widget lutcol, single_draw_a, return_to_hsv_control; static Widget scrolled_list, lutmenu, *savlut=NULL; static float *lutr=NULL; static float *lutg=NULL; static float *lutb=NULL; static XPoint *luth=NULL, *luts=NULL, *lutv=NULL; static float *lutAH=NULL, *lutAS=NULL, *lutAV=NULL; static float *lutBH=NULL, *lutBS=NULL, *lutBV=NULL; static int count=1; static int firstind, *lutind=NULL; static char dumstr[80]; static char lutpath[64], tmppath[64]; static float hp[127], lp[127]; static XPoint h[5], s[5], v[5]; static float AH[4], AS[4], AV[4]; static float BH[4], BS[4], BV[4]; static float hue[MAXCOL]; static float sat[MAXCOL]; static float val[MAXCOL]; static float red[MAXCOL]; static float green[MAXCOL]; static float blue[MAXCOL]; unsigned long ncolors; unsigned char colmap[MAXCOLWITHB]; unsigned long blackpix, graypix, redpix; static XColor cdef, rdef; static unsigned long colors[MAXCOL]; static unsigned long firstcolors[NFIRST]; static char *namec[MAXCOL]; static Colormap cmap, cmap1, cmap2, default_cmap; static XColor exact_defs[MAXCOL]; static XColor first_defs[NFIRST]; static char colnam[8]; #define CTRLZONE(x, y) ((x >= 0) && (x <= L) && \ (y >= 0) && (y <= L)) #define DRAW(w, p) XSetForeground(display, gc, \ BlackPixel(display, screen)); \ XFillRectangle (display, \ XtWindow(w), \ gc, 0, 0, L+1, L+1); \ XSetForeground(display, gc, \ WhitePixel(display, screen)); \ XDrawArc(display, XtWindow(w), gc, \ p[0].x - R, p[0].y - R, 2*R, 2*R, 360*64, 360*64);\ XDrawArc(display, XtWindow(w), gc, \ p[1].x - R, p[1].y - R, 2*R, 2*R, 360*64, 360*64);\ XDrawArc(display, XtWindow(w), gc, \ p[2].x - R, p[2].y - R, 2*R, 2*R, 360*64, 360*64);\ XDrawArc(display, XtWindow(w), gc, \ p[3].x - R, p[3].y - R, 2*R, 2*R, 360*64, 360*64);\ XDrawArc(display, XtWindow(w), gc, \ p[4].x - R, p[4].y - R, 2*R, 2*R, 360*64, 360*64);\ XDrawLines(display, XtWindow(w), gc, p, 5, CoordModeOrigin) extern void create_hsvcontrol(); extern void expose_hsvcontrol(); extern void dismiss_hsv(); extern void hardsave_lut(); extern void return_to_hsv(); static MRMRegisterArg reglist[] = { {"CREATE_HSVCONTROL", (caddr_t) create_hsvcontrol}, {"EXPOSE_HSVCONTROL", (caddr_t) expose_hsvcontrol}, {"DISMISS_HSV", (caddr_t) dismiss_hsv}, {"HARDSAVE_LUT", (caddr_t) hardsave_lut}, {"RETURN_TO_HSV", (caddr_t) return_to_hsv}, }; extern void color_input(); extern void reset(); /* Actions to be added to the Translation Manager */ static XtActionsRec actions_list[] = { {"color_input", color_input}, {"reset", reset}, }; static char color_translations [] = ": color_input()\n\ : color_input()\n\ : reset()\n\ Button1: color_input()\n\ Button2: color_input()"; static XPoint huepoints[127], satpoints[127], valpoints[127], lutpoints[127]; void cmap_transfert_function() { int k; for (k=0; k < ncolors; k++) if (!XParseColor(display, cmap, namec[(short) lp[k]], &exact_defs[k])){ sprintf(dumstr, "I can't parse col # %d, value %s.\n", k, namec[(short) lp[k]]); fprintf(stderr, "%s\n", dumstr); } XStoreColors(display, cmap, exact_defs, ncolors); } void transfert_function() { int k; for (k = 0; k < ncolors; k++) sprintf(namec[k], "#%02X%02X%02X", (unsigned short) (255*red[k]), (unsigned short) (255*green[k]), (unsigned short) (255*blue[k])); for (k=0; k < ncolors; k++) if (!XParseColor(display, cmap, namec[k], &exact_defs[k])){ sprintf(dumstr, "I can't parse col # %d, value %s.\n", k, namec[k]); fprintf(stderr, "%s\n", dumstr); } XStoreColors(display, cmap, exact_defs, ncolors); } static int lowbound = 0; static int highbound = 360; void return_to_hsv(w, tag, cbs) Widget w; int *tag; XmAnyCallbackStruct *cbs; { int j; XtUnmapWidget(lutcol); XtUnmapWidget(return_to_hsv_control); for (j=0; jvalue; else highbound = cbs->value; for (j=0; jitem, charset, &choice); sprintf(lutname, "%s/%s", tmppath, choice); lut_id = fopen(lutname, "r"); if (lut_id == NULL) { local = 0; sprintf(lutname, "%s/%s", lutpath, choice); lut_id = fopen(lutname, "r"); } if (lut_id != NULL) { for (i = 0; itype == ButtonPress) { if (event->xbutton.button == Button1) reverseon = 0; else reverseon = 1; } x = event->xmotion.x; y = event->xmotion.y; if (!CTRLZONE(x, y)) return; i = (float) x/ncolors; if (!reverseon) j = 1. - i; else j = -1. + i; /* orig par pente */ orig= (1. - i/j)*0.5; for (k=0; k 1.) f = 1.; if (w == single_draw_a) { lutpoints[k].y = (L-1)*(1.-f); lp[k] = f*(ncolors - 1); } else { if (w == hdraw) { huepoints[k].y = (L-1)*(1.-f); hp[k] = f; hue[k] = (float) (lowbound) + hp[k]*(highbound-lowbound); } else if (w == sdraw) { satpoints[k].y = (L-1)*(1.-f); sat[k] = f; } else { valpoints[k].y = (L-1)*(1.-f); val[k] = f; } hsv_to_rgb(&hue[k], &sat[k], &val[k], &red[k], &green[k], &blue[k]); } } if (w == single_draw_a) cmap_transfert_function(); else transfert_function(); XSetForeground(display, gc, BlackPixel(display, screen)); XFillRectangle (display, XtWindow(w), gc, 0, 0, L+1, L+1); XSetForeground(display, gc, WhitePixel(display, screen)); if (w == hdraw) XDrawLines(display, XtWindow(w), gc, huepoints, ncolors, CoordModeOrigin); else if(w == sdraw) XDrawLines(display, XtWindow(w), gc, satpoints, ncolors, CoordModeOrigin); else if (w == vdraw) XDrawLines(display, XtWindow(w), gc, valpoints, ncolors, CoordModeOrigin); else XDrawLines(display, XtWindow(w), gc, lutpoints, ncolors, CoordModeOrigin); } void dismiss_hsv(w, w_code, cbs) Widget w; XmAnyCallbackStruct *cbs; int *w_code; { XtUnmapWidget(hsvshell); } void change_lut(w, w_code, cbs) Widget w; XmAnyCallbackStruct *cbs; int *w_code; { int i, ind=*w_code; for (i = 0; i < MAXCOL; i++) { red[i] = lutr[(ind - 1)*MAXCOL + i]; green[i] = lutg[(ind - 1)*MAXCOL + i]; blue[i] = lutb[(ind - 1)*MAXCOL + i]; } transfert_function(); for (i=0; i