graPHIGS PostScript output ?

Curt Schroeder curts at usenet.umr.edu
Sat Mar 30 06:30:08 AEST 1991


In article <IVAN%NEPJT.91Mar28150505 at nepjt.ncsuvx.ncsu.edu> ivan at nepjt.ncsu.edu (Ivan Maldonado) writes:
>The only way we're now able to get PostScript output
>from our rs6000/graPHIGS displays has been through
>an "X window screen dump", by piping commands as:
>xwd | xpr -device ps -out somefile.ps
>However, the actual hardcopy ends up "very ugly" (i.e.,
>very coarse definition plus the x-window border around
>it).  Anyone familiar with this that can recommend an
>alternate route ?

I would like to share my solution to this problem (although I use DEC Phigs on
a DEC 3100).  I have a function that I pass the X display pointer and the X
window ID to and it creates a Utah format .rle file (using the color map info).
The .rle file can then be manipulated using all the Utah tools (including the
production of B&W or color Postscript).  The hard part is to determine the
display pointer and window ID.  I found an "escape" buried in the back of the
DEC Phigs manual that gives me the display pointer when called.  Hopefully, 
you can find something similar in graPhigs, or some back door approach to get 
the info if you can't get it any other way.  The nice part is that you can 
then do a screen dump under program control.  The code for doing this in DEC 
Phigs is included below.

Curt

================== cut here ============================
/******************************************************************************
*
*  Header to make use of Xwindows easier.
*
*  File: xwindows.h
*
*  Author: Curt Schroeder
*
*  Date: 1/15/90
*
******************************************************************************/

#include <X11/Xlib.h>
#include <X11/Xutil.h>

#define PIXELS         256
#define MAX_INTENS     65535L

extern Display *primary_display;
extern Colormap color_map;
extern Colormap alt_map;
extern unsigned long pixels[PIXELS];
extern int pixel_flags;
extern Window main_window;
extern Pixmap main_pixmap;
extern GC primary_gc;  /* initialized as black-on-white */

================== cut here ============================
/******************************************************************************
*
*  Routines to make use of Xwindows easier.
*
*  File: xwindows.c
*
*  Author: Curt Schroeder
*
*  Date: 3/13/91
*
******************************************************************************/

#include "xwindows.h"
#include <rle.h>

/* global declarations */

  Display *primary_display;
  Visual *vis;
  int depth;
  Colormap color_map;
  Colormap alt_map;
  Window main_window, root_window;
  Pixmap main_pixmap;
  GC primary_gc;
  XEvent main_event;
  KeySym main_key;
  XSizeHints main_hint;
  int primary_screen;
  unsigned long black_pixel, white_pixel;
  unsigned long pixels[PIXELS];
  int pixel_flags = {DoRed|DoGreen|DoBlue};

/* function declarations */


init_windows ()
{
  struct esc_data_struct
    {
    int     num_ints;
    int     num_floats;
    int     num_strings;
    int     *ints;
    float   *floats;
    int     *string_sizes;
    char    **strings;
    } out_esc_data, in_esc_data;
  Pint esc_id = PHIGS$K_ESC_INQ_WINDOW_IDS;
  Pint ws_id = WSID;
  Pint out_size;
  Pint int_buffer[2];
  Pint in_size;

  char main_title[15];
  int class;
  Status rc;
  XColor default_pixels[PIXELS];
  int i;

  Window parent;
  Window *children;
  unsigned int nchildren;
  Status result;


  /* init data records for DEC Phigs escape call */
  in_esc_data.num_ints = 1;
  in_esc_data.num_floats = 0;
  in_esc_data.num_strings = 0;
  in_esc_data.ints = &ws_id;
  in_esc_data.floats = NULL;
  in_esc_data.string_sizes = NULL;
  in_esc_data.strings = NULL;
  in_size = sizeof(struct esc_data_struct);
   
  out_esc_data.num_ints = 2;
  out_esc_data.num_floats = 0;
  out_esc_data.num_strings = 0;
  out_esc_data.ints = int_buffer;
  out_esc_data.floats = NULL;
  out_esc_data.string_sizes = NULL;
  out_esc_data.strings = NULL;
  out_size = sizeof(struct esc_data_struct);

  pescape(esc_id,&in_esc_data,in_size,&out_esc_data,&out_size);

  /* initialization */
  primary_display = (Display *)int_buffer[0];
  primary_screen = DefaultScreen(primary_display);
  color_map = DefaultColormap(primary_display,primary_screen);

  /* display visiual info */
  depth = DefaultDepth(primary_display,primary_screen);
  vis = DefaultVisual(primary_display,primary_screen);
  class = vis->class;
  if (depth == 1)
    { printf("one-plane monochrome\n"); }
  else 
    if (class == PseudoColor )
      { printf("multi-plane color\n"); }
    else
      if (class == GrayScale)
        { printf("multi-plane monochrome\n"); }
      else 
        if (class == DirectColor)
          { printf("direct color\n"); }
        else
          if (class == TrueColor)
            { printf("direct color, unchangeable color map\n"); }

  /* define main_window */
  main_window = (Window)int_buffer[1];
}


/******************************************************************************
*
*  Function to store an X image to disk in the Utah Raster Toolkit RLE format.
*
*  Author: Curt Schroeder
*
*  Date: 3/13/91
*
******************************************************************************/

store_rle (display, drawable, file_name)
  Display *display;
  Window drawable;
  char* file_name;
{
  XColor table[PIXELS];
  int i, j, x, y;
  Window root;
  unsigned int width, height, border_width, depth;
  XImage *image;
  FILE *image_file;
  long pixel;

  XWindowAttributes window_attr;
  
  rle_hdr   the_hdr;
  rle_pixel **scan_line;
  rle_map   cmap[768];

  
  /* init variables */
  image_file = rle_open_f_noexit("DEC PHIGS",file_name,"wb");
  if (image_file != NULL)
    {
    printf("image file %s opened\n",file_name);

    /* get the color map */
    XGetWindowAttributes(primary_display,main_window,&window_attr);
    for (i = 0; i < PIXELS; i++)
      table[i].pixel = i;
    XQueryColors(display,window_attr.colormap,table,PIXELS);

    /* make certain no RGB values are out of range and store in cmap */
    for (i = 0; i < PIXELS; i++)
      {
      if (table[i].red > MAX_INTENS)
        table[i].red = 0;
      cmap[i] = table[i].red;

      if (table[i].green > MAX_INTENS)
        table[i].green = 0;
      cmap[256 + i] = table[i].green;

      if (table[i].blue > MAX_INTENS)
        table[i].blue = 0;
      cmap[512 + i] = table[i].blue;
      }

    /* get the image and store it and it's color map */
    if (XGetGeometry(display,drawable,&root,&x,&y,&width,&height,
                     &border_width,&depth))
      {
      printf("image at (%d,%d) %d x %d will be fetched\n",x,y,width,height);
      image = XGetImage(display,drawable,x,y,width,height,-1,ZPixmap);

      /* init the RLE header */
      the_hdr.ncolors = 1;
      the_hdr.bg_color = NULL;
      the_hdr.alpha = 0;
      the_hdr.background = 0;
      the_hdr.xmin = 0;
      the_hdr.xmax = width - 1;
      the_hdr.ymin = 0;
      the_hdr.ymax = height - 1;
      the_hdr.ncmap = 3;
      the_hdr.cmaplen = 8;
      the_hdr.cmap = cmap;
      the_hdr.comments = NULL;
      the_hdr.rle_file = image_file;
      RLE_SET_BIT(the_hdr,RLE_RED);
      RLE_SET_BIT(the_hdr,RLE_GREEN);
      RLE_SET_BIT(the_hdr,RLE_BLUE);
      RLE_CLR_BIT(the_hdr,RLE_ALPHA);


      /* write out the image */
      rle_put_setup(&the_hdr);
      rle_row_alloc(&the_hdr,&scan_line);

      for (i = 0; i < height; i++)
        {
        for (j = 0; j < width; j++)
          {
          pixel = XGetPixel(image,j,(height - 1 - i));
          scan_line[0][j] = (rle_pixel)pixel;
	  }  /* load each pixel in the current row into RLE row structure */
        rle_putrow(scan_line,width,&the_hdr);
        }
      

      /* close the image file */
      rle_puteof(&the_hdr);
      fclose(image_file);
      printf("image storage completed...\n\n");

      /* destroy the image structure */
      XDestroyImage(image);
      }
    }
  return(0);
}
================== cut here ============================

Curt Schroeder | U of Missouri - Rolla | curts at ee.umr.edu       |
---------------------------------------| curts at cs.umr.edu       |
"Oops?  What do you mean, oops?  I     | s076895 at umrvma.bitnet  |
 distinctly heard an oops!" - Opus     | -- Apple II Forever -- |



More information about the Comp.unix.aix mailing list