1 /*
2  * $Id: pixels.i,v 1.1 2005-09-18 22:06:03 dhmunro Exp $
3  * Attempt to plot images on an X display one pixel to the cell.
4  */
5 /* Copyright (c) 2005, The Regents of the University of California.
6  * All rights reserved.
7  * This file is part of yorick (http://yorick.sourceforge.net).
8  * Read the accompanying LICENSE file for details.
9  */
10 
pix_window(dpi,n)11 func pix_window(dpi, n)
12 /* DOCUMENT pix_window, dpi
13          or pix_window, dpi, n
14      create a new window for the pixels command with the given DPI
15      (dots per inch).  If N is specified, the new window will be
16      number N (0-7).  Also sets the pix_dpi variable appropriately.
17 
18      pix_window, 75           // makes a small window
19      pix_window, 100          // makes a large window
20 
21    SEE ALSO: pix_dpi, pixels, window
22  */
23 {
24   dpi= (dpi<87.5? 75 : 100);
25   if (is_void(n)) window, dpi=dpi;
26   else window, n, dpi=dpi;
27   pix_dpi= dpi;
28 }
29 
30 func pixels(z,dx0,dy0,top=,cmin=,cmax=)
31 /* DOCUMENT pixels, z
32          or pixels, z, dx0, dy0
33      plots the image Z as a cell array -- an array of equal rectangular
34      cells colored according to the 2-D array Z.  The first dimension
35      of Z is plotted along x, the second dimension is along y.
36      If Z is of type char, it is used "as is", otherwise it is linearly
37      scaled to fill the current palette, as with the bytscl function.
38      (See the bytscl function for explanation of top, cmin, cmax.)
39 
40      The image is placed in "coordinate system zero"; that is, outside
41      Yorick's ordinary coordinate system, so zooming and coordinate
42      system changes will not effect it.  Unlike pli, Yorick attempts
43      to make each X pixel correspond to one cell of the Z array.
44      In order to do this, the pix_dpi variable must be set to the
45      dots-per-inch (either 75 or 100) of the X window in which the
46      result of pixels will be displayed (see the dpi keyword of the
47      window command).
48 
49      The default position of the upper left hand corner of the picture
50      is specified by the pix_origin variable.  If DX0 and/or DY0 are
51      present, they adjust this origin for this image.  The units of
52      DX0 and DY0 are in pixels; DY0 is positive downwards.  (However,
53      the 2nd index of the image increases upwards.)  Resizing the X
54      window will probably necessitate changing pix_origin.
55 
56      The following keywords are legal (each has a separate help entry):
57    KEYWORDS: top, cmin, cmax
58    SEE ALSO: pix_window, window, palette, bytscl, histeq_scale
59              pix_dpi, pix_origin
60  */
61 {
62   ny= dimsof(z);
63   nx= ny(2);
64   ny= ny(3);
65   scale= 0.0013*72.27/(pix_dpi<87.5? 75.0 : 100.0);
66 
67   if (is_void(dx0)) dx0= 0.0;
68   if (is_void(dy0)) dy0= 0.0;
69   dx0*= scale;
70   dy0*= -scale;
71   dx0+= pix_origin(1);
72   dy0+= pix_origin(2);
73 
74   plsys, 0;
75   pli, z, dx0,dy0-ny*scale,dx0+nx*scale,dy0, top=top,cmin=cmin,cmax=cmax;
76   plsys, 1;
77   redraw;   /* yes, there is a bug with detecting updates when things
78                in coordinate system 0 change... */
79 }
80 
81 local pix_dpi;
82 /* DOCUMENT pix_dpi= 75
83          or pix_dpi= 100
84      set the number of dots per inch for the pixels function.
85      X displays are either 75 dpi (default) or 100 dpi in Yorick.
86      The pix_dpi number must match the dpi of the window in which
87      the pixels command is to be issued; the other number will
88      result in blurred images.
89 
90    SEE ALSO: pixels, pix_window, window
91  */
92 pix_dpi= 75;
93 
94 local pix_origin;
95 /* DOCUMENT pix_origin= [0.12,0.91]
96      set [x,y] for the default upper left hand corner of the pixels
97      image.  The default value is shown.  [0,0] is the lower left of
98      an 8.5-by-11 sheet of paper.  Yorick units are 0.0013/point or
99      0.0013*72.27/inch (11 inches is a little more than 1.0);  Yorick
100      keeps the "middle" of an 8.5-by-11 sheet centered in the visible
101      part of its X windows, so you might want to change the default
102      pix_origin if you resize the Yorick window.
103 
104    SEE ALSO: pixels, window
105  */
106 pix_origin= [0.12,0.91];
107