[comp.graphics] Sun color graphics

guansy@cs.tamu.edu (Sheng-Yih Guan) (09/30/90)

Sorry, there is a mistake in the original posting.  This one is
tested o.k. on a color monitor.  Enjoy it!

/* What you need to do is: 			 		*/
/*   1. change the colormap in the routine setup_colourmap	*/
/*   2. change pw_vector(pw,5,i,700-i,5, PIX_SRC,1)		*/
/*	==> pw_vector(pw,5,i,700-i,5, PIX_SRC, 0<=anyvalue<=255)*/
/*   3. cc <inputfile>  -lsuntool -lsunwindow -lpixrect -lm 	*/
/* This program has been tested.  It compliles o.k.  But, need  */
/* to be tested on a color monitor.				*/


#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include <stdio.h>


Frame	 frame, any_frame;
Canvas 	 canvas, test_canvas;
Pixwin	 *pw, *test_pw;
int      colour;
int	 mono_override;
unsigned char  red[256], green[256], blue[256];
colormap_t colormap;
int      iscolour();

main()
  {
  int i;

  frame = window_create(NULL,FRAME,0);
  canvas = window_create(frame,CANVAS,0);

  pw=canvas_pixwin(canvas);
  /* the following objects are temporary created for testing if the 
   workstation is colour or not */
  any_frame = window_create(NULL, FRAME, FRAME_NO_CONFIRM, TRUE, 0);
  test_canvas = window_create(any_frame, CANVAS, 0);
  test_pw = canvas_pixwin(test_canvas);
  colour = iscolour(test_pw);
  window_destroy(any_frame);



  if (colour) 
    {
    setup_colourmap(pw);
    }



  for (i=5; i<=700; i+=7)
    {
    pw_vector(pw,5,i,700-i,5, PIX_SRC,100);
    pw_vector(pw,5,700-i,i,5, PIX_SRC,10);

    pw_vector(pw,i,5,700,i, PIX_SRC,100);
    pw_vector(pw,700,700-i,700-i,5, PIX_SRC,10);

    pw_vector(pw,700,i,700-i,700, PIX_SRC,100);
    pw_vector(pw,i,700,700,700-i, PIX_SRC,10);

    pw_vector(pw,5,700-i,700-i,700, PIX_SRC,100);
    pw_vector(pw,5,i,i,700, PIX_SRC,10);
    }

  window_main_loop(frame);
  exit(0);
  }

int
iscolour(pw)
Pixwin *pw;
  {

  return ((pw->pw_pixrect->pr_depth > 1) ? TRUE : FALSE);
  }


static char    cmsname[BUFSIZ];

setup_colourmap(fpw)
  {
  register int i;

  for (i = 0; i < 256; i++) 
    {
    red[i] = green[i] = blue[i] = -1;
    }


  if (colormap.type == RMT_NONE || colormap.length == 0) 
    {
    /*sprintf(cmsname, "greyscale%d", pr->pr_depth);*/
    sprintf(cmsname, "greyscale%d", 8);

    pw_setcmsname(fpw, cmsname);

    for (i = 1; i < 255; i++) 
      {
      red[i] = i;
      green[i] = i;
      blue[i] = i;
      }
    if (mono_override) 
      {
      red[255] = blue[255] = green[255] = 255;
      red[0] = blue[0] = green[0] = 0;
      }
    pw_putcolormap(fpw, 0, 256, red, green, blue);
    } 
  else 
    {
    pw_setcmsname(fpw, "non_greyscale");
    pw_putcolormap(fpw, 0, colormap.length, colormap.map[0], 
                   colormap.map[1], colormap.map[2]);
    }
  window_set(frame, FRAME_INHERIT_COLORS, TRUE, 0);
  }
 _       _   _                            ___________          
|  \    /_| / /    Visualization Lab     /____  ____/         
 \  \  //  / /   Computer Science Dept       / /  _   _    _   _   
  | | //  / /     Texas A&M University      / /  / | | \  / | | | ||
  | |//  / / College Station, TX 77843-3112/ /  / /| |  \//|| | | ||
  /  /  / /____    Tel: (409)845-0531     / /  / -|| | |\/ || | !_!|  
 !__/  /______/ stanley@visual1.tamu.edu /_/  /_/ || !_!   || !____!