home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / sgi / 13619 < prev    next >
Encoding:
Text File  |  1992-09-14  |  8.3 KB  |  256 lines

  1. Xref: sparky comp.sys.sgi:13619 comp.windows.x.motif:6175
  2. Newsgroups: comp.sys.sgi,comp.windows.x.motif
  3. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uchinews!iitmax!chien
  4. From: chien@iitmax.iit.edu (Greg Chien)
  5. Subject: Colormap on Indigo XS24
  6. Message-ID: <1992Sep14.183026.4852@iitmax.iit.edu>
  7. Keywords: Pseudo Color Colormap Indigo X11 X Windows
  8. Organization: Illinois Institute of Technology / Academic Computing Center
  9. Date: Mon, 14 Sep 92 18:30:26 GMT
  10. Lines: 244
  11.  
  12. Hi,
  13.  
  14. The following program runs on an SGI IRIS 320/VGX and a few Personal
  15. IRISes but just doesn't like the Indigos.  Can anyone point out what
  16. I have missed? or anything related to Indigo's Virtual 24 scheme?
  17. I am running it only in PseudoColor mode.
  18.  
  19. Thanks in advance,
  20. Greg
  21. ===========================================================================
  22. | Greg T.H. Chien                       It is engineered, not designed.   |
  23. | Illinois Institute of Technology         Phone:    (312) 567-5922       |
  24. | Dept. of Computer Science, 237SB         BITNET:   THSSCHIEN@IITVAX     |
  25. | Chicago, IL 60616                        Internet: chien@iitmax.iit.edu |
  26. ===========================================================================
  27. /* -------- 8< --------------- CUT HERE ------------ 8< ------------- */
  28. /* colortest.c - test color ramp setup
  29.  *
  30.  * This program instantiates a DrawingArea and sets up a
  31.  * color ramp in color pixel index 128-256.  It cycles
  32.  * through the color ramp and clears the DrawingArea
  33.  * using the colors as the DrawingArea's background after
  34.  * the Start button is hit.
  35.  * compile with: cc -o colortest colortest.c -lXm -lXt -lX11
  36.  */
  37.  
  38. #include <Xm/Xm.h>
  39. #include <Xm/DrawingA.h>
  40. #include <Xm/RowColumn.h>
  41. #include <Xm/PushB.h>
  42.  
  43. #define MAXCOLORS   256 
  44. #define MAXRGBVAL   65535
  45. #define BASECOLORS  128
  46.  
  47. Display    *dpy;
  48. Colormap    my_colormap;
  49. int         ncolors;
  50. Widget      canvas;
  51.  
  52. void start(w, cl, ca)
  53. Widget w;
  54. XtPointer cl, ca;
  55. {
  56.   int       i;
  57.  
  58.   for (i = BASECOLORS; i < ncolors; i++) {  /* cycle through color ramp */
  59.     XtVaSetValues(canvas, XmNbackground, i, NULL);
  60.     XClearWindow(dpy, XtWindow(canvas));
  61.   }
  62. }
  63.  
  64. void quit(w, cl, ca)
  65. Widget w;
  66. XtPointer cl, ca;
  67. {
  68.   XtCloseDisplay(dpy);
  69.   exit(0);
  70. }
  71.  
  72. main(argc, argv)
  73.   int    argc;
  74.   char  *argv[];
  75. {
  76.   int       i;
  77.   int       nrampcolors, qtrnramp, delta;
  78.   int       quarter, index, offset;
  79.   XtAppContext    app_context;
  80.   Widget    toplevel, base, control;
  81.   Widget    startB, quitB;
  82.   Colormap  def_colormap;
  83.   XColor    Colors[MAXCOLORS];
  84.   XmString  xmstr;
  85.  
  86.   toplevel = XtAppInitialize(&app_context, "Coloredit", NULL, 0,
  87.                           &argc, argv, NULL, NULL);
  88.   dpy = XtDisplay(toplevel);
  89.  
  90.   ncolors = DisplayCells(dpy, DefaultScreen(dpy));
  91.   if (ncolors > MAXCOLORS) ncolors = MAXCOLORS;
  92.  
  93.   base = XtCreateManagedWidget("base",xmRowColumnWidgetClass, 
  94.                              toplevel, NULL, 0);
  95.   canvas = XtCreateManagedWidget("canvas", xmDrawingAreaWidgetClass,
  96.                  base, NULL, 0);
  97.   XtVaSetValues(canvas, XmNwidth, 400, XmNheight, 400, NULL);
  98.  
  99.   control = XtCreateManagedWidget("control", xmRowColumnWidgetClass,
  100.                              base, NULL, 0);
  101.  
  102.   startB = XtCreateManagedWidget("startB", xmPushButtonWidgetClass,
  103.                  control, NULL, 0);
  104.   quitB = XtCreateManagedWidget("quitB", xmPushButtonWidgetClass,
  105.                  control, NULL, 0);
  106.  
  107.   xmstr = XmStringCreate("Start", XmSTRING_DEFAULT_CHARSET);
  108.   XtVaSetValues(startB, XmNlabelString, xmstr);
  109.   XmStringFree(xmstr);
  110.   xmstr = XmStringCreate("Quit", XmSTRING_DEFAULT_CHARSET);
  111.   XtVaSetValues(quitB, XmNlabelString, xmstr);
  112.   XmStringFree(xmstr);
  113.  
  114.   XtAddCallback(startB, XmNactivateCallback, start, NULL);
  115.   XtAddCallback(quitB,  XmNactivateCallback, quit,  NULL);
  116.  
  117.   def_colormap = DefaultColormap(dpy, DefaultScreen(dpy));
  118.   for(i = 0; i < ncolors; i++ ) {
  119.     Colors[i].pixel = i;
  120.     Colors[i].flags = DoRed|DoGreen|DoBlue;
  121.   }
  122.  
  123.   XQueryColors(dpy, def_colormap, Colors, ncolors);
  124.  
  125.   nrampcolors = ncolors - BASECOLORS;
  126.   qtrnramp = nrampcolors / 4;
  127.   delta = MAXRGBVAL / qtrnramp;
  128.   for (i = 0; i < nrampcolors; i++) {     /* setting up color ramp */
  129.     quarter = i / qtrnramp;
  130.     index = i % qtrnramp;
  131.     offset = i + BASECOLORS;
  132.     switch (quarter) {
  133.       case 0:
  134.         Colors[offset].blue = MAXRGBVAL;
  135.         Colors[offset].green = index * delta;
  136.         Colors[offset].red = 0;
  137.         break;
  138.       case 1:
  139.         Colors[offset].blue = (qtrnramp - index) * delta;
  140.         Colors[offset].green = MAXRGBVAL;
  141.         Colors[offset].red = 0;
  142.         break;
  143.       case 2:
  144.         Colors[offset].blue = 0;
  145.         Colors[offset].green = MAXRGBVAL;
  146.         Colors[offset].red = index * delta;
  147.         break;
  148.       case 3:
  149.         Colors[offset].blue = 0;
  150.         Colors[offset].green = (qtrnramp - index) * delta;
  151.         Colors[offset].red = MAXRGBVAL;
  152.         break;
  153.       default:
  154.         break;
  155.     }
  156.   }
  157.  
  158.   my_colormap = XCreateColormap(dpy, DefaultRootWindow(dpy), 
  159.                        DefaultVisual(dpy, DefaultScreen(dpy)),
  160.                        AllocAll);
  161.   XStoreColors(dpy, my_colormap, Colors, ncolors);
  162.  
  163.   XtRealizeWidget(toplevel);
  164.  
  165.   XSetWindowColormap(dpy, XtWindow(toplevel), my_colormap);
  166.  
  167.   XtAppMainLoop(app_context);
  168. }
  169. /* -------- 8< --------------- CUT HERE ------------ 8< ------------- */
  170. #ifdef INFO_BELOW
  171.  
  172. xwininfo output from an Indigo XS24
  173.  
  174. xwininfo ==> Please select the window about which you
  175.          ==> would like information by clicking the
  176.          ==> mouse in that window.
  177.  
  178. xwininfo ==> Window id: 0x280000f (colortest)
  179.  
  180.          ==> Absolute upper-left X:  590
  181.          ==> Absolute upper-left Y:  104
  182.          ==> Relative upper-left X:  0
  183.          ==> Relative upper-left Y:  0
  184.          ==> Width: 406
  185.          ==> Height: 476
  186.          ==> Visual: 0x25 (8 bit PseudoColor)
  187.          ==> Border width: 0
  188.          ==> Window class: InputOutput
  189.          ==> Colormap: 0x280000e (installed)
  190.          ==> Window Bit Gravity State: NorthWestGravity
  191.          ==> Window Window Gravity State: NorthWestGravity
  192.          ==> Window Backing Store State: NotUseful
  193.          ==> Window Save Under State: no
  194.          ==> Window Map State: IsViewable
  195.          ==> Window Override Redirect State: no
  196.          ==> Corners:  +590+104  -284+104  -284-444  +590-444
  197.  
  198. Portion of the xdpyinfo output from an Indigo XS24
  199.  
  200.   visual:
  201.     visual id:    0x25
  202.     class:    PseudoColor
  203.     depth:    8 planes
  204.     size of colormap:    256 entries
  205.     red, green, blue masks:    0x0, 0x0, 0x0
  206.     significant bits in color specification:    8 bits
  207.  
  208. ------------------------------------------------------------------
  209.  
  210. xwininfo output from a PI30 with Turbo Graphics
  211.  
  212. xwininfo ==> Please select the window about which you
  213.          ==> would like information by clicking the
  214.          ==> mouse in that window.
  215.  
  216. xwininfo ==> Window id: 0x300000f (colortest)
  217.  
  218.          ==> Absolute upper-left X:  610
  219.          ==> Absolute upper-left Y:  213
  220.          ==> Relative upper-left X:  0
  221.          ==> Relative upper-left Y:  0
  222.          ==> Width: 406
  223.          ==> Height: 476
  224.          ==> Visual: 0x20 (8 bit PseudoColor)
  225.          ==> Border width: 0
  226.          ==> Window class: InputOutput
  227.          ==> Colormap: 0x300000e (not installed)
  228.          ==> Window Bit Gravity State: NorthWestGravity
  229.          ==> Window Window Gravity State: NorthWestGravity
  230.          ==> Window Backing Store State: NotUseful
  231.          ==> Window Save Under State: no
  232.          ==> Window Map State: IsViewable
  233.          ==> Window Override Redirect State: no
  234.          ==> Corners:  +610+213  -264+213  -264-335  +610-335
  235.  
  236. Portion of the xdpyinfo output from a PI30 with Turbo Graphics:
  237.  
  238.   visual:
  239.     visual id:    0x20
  240.     class:    PseudoColor
  241.     depth:    8 planes
  242.     size of colormap:    256 entries
  243.     red, green, blue masks:    0x0, 0x0, 0x0
  244.     significant bits in color specification:    8 bits
  245.  
  246. ------------------------------------------------------------------
  247. #endif /* INFO_BELOW */
  248.  
  249. -- 
  250. ===========================================================================
  251. | Greg T.H. Chien                       It is engineered, not designed.   |
  252. | Illinois Institute of Technology         Phone:    (312) 567-5922       |
  253. | Dept. of Computer Science, 237SB         BITNET:   THSSCHIEN@IITVAX     |
  254. | Chicago, IL 60616                        Internet: chien@iitmax.iit.edu |
  255. ===========================================================================
  256.