Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
getx11.h
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notices are
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 
19 /*
20  * getx11.h - Declaration for image_information structure... (tote a global)
21  *
22  * Author: Martin R. Friedmann
23  * Dept of Electrical Engineering and Computer Science
24  * University of Michigan
25  * Date: Tue, Dec 10, 1989
26  * Copyright (c) 1989, University of Michigan
27  */
28 
29 #include <stdio.h>
30 #include <math.h>
31 #include <ctype.h>
32 #include <X11/X.h>
33 #include <X11/Xlib.h>
34 #ifndef XLIBINT_H_NOT_AVAILABLE
35 #include <X11/Xlibint.h>
36 #endif
37 #include <X11/Xutil.h>
38 #include <X11/cursorfont.h>
39 
40 #include "rle.h"
41 #ifdef X_SHARED_MEMORY
42 #include <sys/ipc.h>
43 #include <sys/shm.h>
44 #include <X11/extensions/XShm.h>
45 #ifndef USE_PROTOTYPES
46 extern void_star shmat();
47 #endif
48 #endif
49 
50 #define COUNT_OF(_array_) ( sizeof (_array_) / sizeof (_array_[0]) )
51 #define IMAGE_BORDERWIDTH 3
52 
53 typedef int Boolean;
54 typedef unsigned long Pixel;
55 
56 #define MALLOC_FAILURE 3
57 #define FILE_FAILURE 2
58 #define FATAL_FAILURE 1
59 #define SUCCESS 0
60 
61 #define VPRINTF if (verbose_flag) fprintf
62 #define DPRINTF if (debug_flag) fprintf
63 
64 #define SHIFT_MASK_PIXEL(r, g, b)
65  ( (( ( (r) << cmap_i.red_shift ) & cmap_i.red_mask )
66  | ( ( (g) << cmap_i.green_shift) & cmap_i.green_mask )
67  | ( ( (b) << cmap_i.blue_shift ) & cmap_i.blue_mask )) +
68  cmap_i.pixel_base)
69 
70 #define SHIFT_MASK_PIXEL_32(r, g, b)
71  (( (r) << cmap_i.red_shift )
72  | ( (g) << cmap_i.green_shift)
73  | ( (b) << cmap_i.blue_shift ))
74 
75 #define Min(x,y) (((x) < (y)) ? (x) : (y))
76 #define Max(x,y) (((x) > (y)) ? (x) : (y))
77 
78 typedef void VOID_FUNCTION();
79 typedef int array16[16];
80 
81 extern double display_gamma;
82 extern int iflag;
83 
84 extern char *progname;
85 extern Display *dpy;
86 extern Window root_window;
87 extern int screen;
88 
89 extern Boolean debug_flag; /* set if debug mode -D */
90 extern Boolean verbose_flag; /* set if verbose mode -v */
91 extern int stingy_flag;
92 extern int specified_levels;
93 #ifdef X_SHARED_MEMORY
94 /*
95  * use_shared_pixmaps is TRUE if the server supports shared images.
96  * no_shared_space is set to TRUE the first time shmget returns
97  * ENOSPC, so the error message is only printed once. We still
98  * try, though, as an 'r' or 'q' command could release segments.
99  */
100 extern Boolean do_sharing;
102 extern Boolean no_shared_space;
103 #endif
104 
105 /* X11/NeWS server bug workaround. */
106 extern int no_color_ref_counts;
107 
108 /*
109  * Color map, gamma correction map, and lookup tables
110  */
111 
112 typedef struct _cmap_info_struct
113 {
121 } cmap_info;
122 
123 typedef struct _image_info_struct
124 {
125  Window window, icn_window; /* X windows and pixmaps */
128  GC gc, icn_gc; /* And GC's and XImages */
129  XImage *image, *icn_image;
130  Colormap colormap;
132  Visual *dpy_visual;
135 
136  CONST_DECL char *filename; /* file that Image came from. */
137  CONST_DECL char *title; /* title for this image... */
138  int img_num; /* Number of image within file. */
139  FILE *fd;
140  unsigned char *scan_data; /* a[img_h][img_w][img_clr_channels] */
141  int img_channels; /* # of color channels in file */
142  int dpy_channels; /* # of channels we will display */
143  VOID_FUNCTION *map_scanline; /* map_scanline routine to use */
144  VOID_FUNCTION *MAG_scanline; /* MAG_scanline routine to use */
145  float gamma;
146  float dpy_gamma;
147 
148  int x, y; /* Original origin of image */
149  int xo, yo; /* Origin of image in X11 window (-y)*/
150  int w, h; /* width and height of image */
151  int win_w, win_h; /* width and height of window */
152  int icn_w, icn_h; /* width and height of icon */
153  int pix_w, pix_h; /* width and height of img->pixmap */
154  int icn_factor; /* divide factor from img -> icon */
155 
156  int pan_x, pan_y, pan_w, pan_h; /* image rect currently being viewed */
157  int mag_fact, save_mag_fact; /* current magnification factor */
158  Boolean mag_mode; /* are we display magnified image? */
161  int save_win_w, save_win_h; /* wdth and hgt of window when saved */
162 
163  Boolean binary_img; /* will we make it 2 color? (-W) */
164  Boolean mono_img; /* do we make it grey scale? (-w) */
165  Boolean dither_img; /* do we dither it? (-a) */
166  Boolean rw_cmap; /* is the colormap writable? */
167  Boolean sep_colors; /* is the visual True or DirectColor?*/
168  Boolean mono_color; /* a one channel color image (mcut) */
169  Boolean color_dpy; /* False if we are FORCED to b/w */
170 
172  int ncmap; /* rle_hdr.ncmap */
173  int cmlen; /* Comment `color_map_length` in file*/
174 
175  int *modN; /* dither arrays, all of them */
176  int *divN;
178  cmap_info x_cmap;
182 #ifdef X_SHARED_MEMORY
183  XShmSegmentInfo shm_img;
184  XShmSegmentInfo shm_pix;
185 #endif
186 } image_information;
187 
188 /* pointer arithmetic... gack! */
189 /* Returns Y'th row in our saved data array. Works around problem with */
190 /* rle_getrow by adding 1 to y. We waste the first line of this array */
191 /* SAVED_RLE_ROW(img, -1) == img->scan_data, and is never used... */
192 #define SAVED_RLE_ROW( img, y )
193  ((img)->scan_data + (((y) + 1) * (img)->w * (img)->dpy_channels))
194 
195 
196 #define duff8(counter, block) {
197  while (counter >= 8) {
198  { block; }
199  { block; }
200  { block; }
201  { block; }
202  { block; }
203  { block; }
204  { block; }
205  { block; }
206  counter -= 8;
207  }
208  switch (counter & 7) {
209  case 7: { block; }
210  case 6: { block; }
211  case 5: { block; }
212  case 4: { block; }
213  case 3: { block; }
214  case 2: { block; }
215  case 1: { block; }
216  case 0: counter = 0;
217  }\
218 }
219 
220 /* add missing prototype (moved to prototypes.h)
221  * extern Status XAllocColors(register Display *dpy, Colormap cmap, XColor *defs, int ndefs, Status *statuses);
222 */
223 
224 #ifdef USE_PROTOTYPES
225 /* Prototypes.h contains prototypes for all global functions. It is
226  * automatically generated using the cproto program.
227  */
228 #include "prototypes.h"
229 #else
230 /* This is also automatically generated by cproto. */
231 #include "fn_decls.h"
232 #endif
unsigned char * scan_data
Definition: getx11.h:140
Boolean use_shared_pixmaps
Definition: getx11.c:85
int Boolean
Definition: getx11.h:53
cmap_info x_cmap
Definition: getx11.h:178
Pixel blue_mask
Definition: getx11.h:119
Boolean rw_cmap
Definition: getx11.h:166
int stingy_flag
Definition: getx11.c:81
Pixel green_mask
Definition: getx11.h:118
Boolean pixmap_failed
Definition: getx11.h:134
int no_color_ref_counts
Definition: getx11.c:88
#define USE_PROTOTYPES
Definition: rle_config.h:22
Boolean mag_mode
Definition: getx11.h:158
XShmSegmentInfo shm_img
Definition: getx11.h:183
Boolean debug_flag
Definition: get_orion.c:79
int array16[16]
Definition: getx11.h:79
Display * dpy
Definition: getx10.c:94
Pixel red_mask
Definition: getx11.h:117
int specified_levels
Definition: getx11.c:82
Boolean no_shared_space
Definition: getx11.c:86
const char * title
Definition: getx11.h:137
XShmSegmentInfo shm_pix
Definition: getx11.h:184
char * progname
Definition: unslice.c:51
Pixel pixel_base
Definition: getx11.h:120
Visual * dpy_visual
Definition: getx11.h:132
short verbose_flag
Definition: qcr.c:17
const char * filename
Definition: getx11.h:136
Boolean mono_color
Definition: getx11.h:168
Window icn_window
Definition: getx11.h:125
int screen
Definition: show3.c:29
Pixel * pixel_table
Definition: getx11.h:179
Window root_window
Definition: getx11.c:76
#define X_SHARED_MEMORY
Definition: rle_config.h:30
int iflag
Definition: getsun.c:80
Boolean color_dpy
Definition: getx11.h:169
#define CONST_DECL
Definition: rle_config.h:42
void VOID_FUNCTION()
Definition: getx11.h:78
Boolean binary_img
Definition: getx11.h:163
Boolean sep_colors
Definition: getx11.h:167
Pixmap icn_pixmap
Definition: getx11.h:127
XImage * image
Definition: getx11.h:129
XImage * icn_image
Definition: getx11.h:129
unsigned char rle_pixel
Definition: rle.h:56
Boolean mono_img
Definition: getx11.h:164
rle_pixel ** in_cmap
Definition: getx11.h:171
Pixel black_pixel
Definition: getx11.h:180
VOID_FUNCTION * MAG_scanline
Definition: getx11.h:144
Window pix_info_window
Definition: getx11.h:126
Colormap colormap
Definition: getx11.h:130
Boolean dither_img
Definition: getx11.h:165
double display_gamma
Definition: getx11.c:64
VOID_FUNCTION * map_scanline
Definition: getx11.h:143
array16 * dm16
Definition: getx11.h:177
Pixel white_pixel
Definition: getx11.h:180
Boolean do_sharing
Definition: getx11.c:84
unsigned long Pixel
Definition: getx11.h:54