Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
x11_stuff.c
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  * x11_stuff.c - Do colormaps, visuals, pix_info window...
21  *
22  * Author: Spencer W. Thomas (x10)
23  * Computer Science Dept.
24  * University of Utah
25  * Date: Thu Feb 20 1986
26  * Copyright (c) 1986, University of Utah
27  *
28  * Modified: Andrew F. Vesper (x 11)
29  * High Performance Workstations
30  * Digital Equipment Corp
31  * Date: Fri, Aug 7, 1987
32  * Thu, Jan 14, 1988
33  * Copyright (c) 1987,1988, Digital Equipment Corporation
34  *
35  * Modified: Martin R. Friedmann (better X11, flipbook, mag, pix_info)
36  * Dept of Electrical Engineering and Computer Science
37  * University of Michigan
38  * Date: Tue, Nov 14, 1989
39  * Copyright (c) 1989, University of Michigan
40  */
41 #include "getx11.h"
42 
43 #ifdef X_SHARED_MEMORY
44 #include <sys/errno.h>
45 #endif
46 #include <errno.h>
47 
48 #include "circle.bitmap"
49 #include "circle_mask.bitmap"
50 
51 static Boolean init_separate_color_rw(), init_color_rw(),
52  init_separate_color_ro(), init_color_ro(), init_mono_rw(), init_mono_ro();
53 static CONST_DECL char *visual_class_to_string();
54 
55 static Cursor circle_cursor = NULL;
56 static Cursor left_ptr_cursor = NULL;
57 static Cursor watch_cursor = NULL;
58 
59 static int specified_screen = -1; /* No specific screen. */
60 
61 static image_information *wait_img = NULL;
62 
64 Window window;
65 {
66  XDefineCursor( dpy, window, watch_cursor );
67  XFlush(dpy);
68 }
69 
71 Window window;
72 {
73  XDefineCursor( dpy, window, circle_cursor );
74  XFlush(dpy);
75 }
76 
78 Window window;
79 {
80  XDefineCursor( dpy, window, left_ptr_cursor );
81  XFlush(dpy);
82 }
83 
85 Window window;
86 {
87  if (circle_cursor == NULL)
88  circle_cursor = XCreateFontCursor (dpy, XC_circle);
89 
90  if (watch_cursor == NULL)
91  watch_cursor = XCreateFontCursor (dpy, XC_watch);
92 
93  if (left_ptr_cursor == NULL)
94  left_ptr_cursor = XCreateFontCursor (dpy, XC_left_ptr);
95 
96  if (circle_cursor == NULL) {
97  Pixmap source;
98  Pixmap mask;
99  XColor color_1;
100  XColor color_2;
101 
102  source = XCreateBitmapFromData(dpy, window, circle_bits,
103  circle_width, circle_height);
104 
105  mask = XCreateBitmapFromData(dpy, window, circle_mask_bits,
106  circle_width, circle_height);
107 
108  color_1.pixel = WhitePixel (dpy, screen);
109  color_1.red = 0xffff;
110  color_1.green = 0xffff;
111  color_1.blue = 0xffff;
112  color_1.flags = DoRed | DoGreen | DoBlue;
113 
114  color_1.pixel = BlackPixel (dpy, screen);
115  color_2.red = 0;
116  color_2.green = 0;
117  color_2.blue = 0;
118  color_2.flags = DoRed | DoGreen | DoBlue;
119 
120  circle_cursor = XCreatePixmapCursor (dpy, source, mask,
121  &color_1, &color_2,
122  circle_x_hot, circle_y_hot);
123  XFreePixmap (dpy, source);
124  XFreePixmap (dpy, mask);
125  }
126 
127  if (watch_cursor == NULL)
129 
130  if (left_ptr_cursor == NULL)
132 }
133 
134 
136 image_information *img;
137 int width, height;
138 Boolean share;
139 {
140  XImage *image;
141 #ifdef X_SHARED_MEMORY
142  int shmid = -1;
143 
144  if ( use_shared_pixmaps && share )
145  {
146  img->shm_img.shmid = -1;
147  image = XShmCreateImage( dpy, img->dpy_visual,
148  (img->binary_img ? 1 : img->dpy_depth),
149  (img->binary_img ? XYBitmap : ZPixmap),
150  NULL, &img->shm_img, width, height );
151  if ( image != NULL )
152  {
153  /* Allocate shared segment. */
154  img->shm_img.shmid =
155  shmget( IPC_PRIVATE,
156  image->bytes_per_line * image->height,
157  IPC_CREAT|0777 );
158  if ( img->shm_img.shmid < 0 )
159  {
160  if ( errno == ENOSPC )
161  {
162  if ( !no_shared_space )
163  fprintf( stderr,
164  "getx11: No more shared memory segments\n" );
165  no_shared_space = True;
166  }
167  else
168  perror( "getx11: shared memory allocation failed" );
169  XDestroyImage( image );
170  image = NULL;
171  }
172  else
173  {
174  /* Attach the segment & get its address. */
175  img->shm_img.shmaddr = image->data =
176  shmat( img->shm_img.shmid, 0, 0 );
177 
178  if ( image->data == NULL) {
179  perror ( "getx11: attach shared image->data" );
180  XDestroyImage (image);
181  shmctl( img->shm_img.shmid, IPC_RMID, 0 );
182  img->shm_img.shmid = -1;
183  image = NULL;
184  }
185  else
186  {
187  /* Want to write into the segment! */
188  img->shm_img.readOnly = False;
189 
190  /* Tell the X server about it. */
191  if ( !XShmAttach( dpy, &img->shm_img ) )
192  {
193  fprintf( stderr, "getx11: XShmAttach failed.\n" );
194  XDestroyImage (image);
195  shmdt( img->shm_img.shmaddr );
196  shmctl( img->shm_img.shmid, IPC_RMID, 0 );
197  img->shm_img.shmid = -1;
198  image = NULL;
199  }
200  }
201  }
202  }
203  shmid = img->shm_img.shmid;
204  }
205 
206  /* If not sharing, or if sharing failed, make a normal XImage. */
207  if ( shmid >= 0 )
208  {
209  /* Remove it now so it will go when we die.
210  * Another nice side effect: we don't fill up the SHM table,
211  * so we can allocate hundreds of them.
212  */
213  XSync( dpy, False ); /* Make sure the server knows about it. */
214  shmctl( shmid, IPC_RMID, 0 );
215  }
216  else
217 #endif
218  {
219  image = XCreateImage ( dpy, img->dpy_visual,
220  (img->binary_img ? 1 : img->dpy_depth),
221  (img->binary_img ? XYBitmap : ZPixmap),
222  0, NULL, width, height, 32, 0);
223 
224  if (image != NULL) {
225  image->data = (char *)malloc ( image->bytes_per_line * height );
226  if ( image->data == NULL) {
227  perror ( "malloc image->data" );
228  XDestroyImage (image);
229  image = NULL;
230  }
231  }
232  }
233  return (image);
234 
235 }
236 
237 void
239 image_information *img;
240 XImage *image;
241 {
242 #ifdef X_SHARED_MEMORY
243  if ( use_shared_pixmaps && image == img->image && img->shm_img.shmid >= 0 )
244  {
245  XShmDetach (dpy, &img->shm_img);
246  XDestroyImage (image);
247  shmdt( img->shm_img.shmaddr );
248  shmctl( img->shm_img.shmid, IPC_RMID, 0 );
249  img->shm_img.shmid = -1;
250  }
251  else
252 #endif
253  XDestroyImage( image );
254 
255  image = NULL;
256 }
257 
258 static int handle_x_errors( dpy, event)
259  Display *dpy;
260  XErrorEvent *event;
261 {
262  XID xid = event->resourceid;
263  image_information *img = wait_img;
264 
265  switch ( event->error_code ) {
266  case BadAlloc:
267  if ( img ) {
268  if ( xid == img->pixmap ){
269  DPRINTF(stderr, "img->pixmap allocation failed\n");
270  img->pixmap = NULL;
271  img->pixmap_failed = True;
272  } else
273  if ( xid == img->icn_pixmap ){
274  DPRINTF(stderr, "img->icn_pixmap allocation failed\n");
275  img->icn_pixmap = NULL;
276  img->pixmap_failed = True;
277  } else
278  _XDefaultError (dpy, event);
279  break;
280  }
281  case BadWindow:
282  case BadDrawable:
283  case BadMatch:
284  _XDefaultError( dpy, event );
285  break;
286  default:
287  _XDefaultError( dpy, event );
288  break;
289  }
290  return 0;
291 }
292 
294 image_information *img;
295 {
296  wait_img = img;
297  XSetErrorHandler( handle_x_errors );
298  XSync( dpy, False );
299 }
300 
302 image_information *img;
303 Boolean reallocate;
304 {
305  int iw = img->w * img->mag_fact;
306  int ih = img->h * img->mag_fact;
307 
308  if ( img->image != NULL &&
309  ( reallocate || (img->image->width < iw || img->image->height < ih))) {
310  destroy_X_image( img, img->image );
311  img->image = NULL;
312  }
313  if (img->image == NULL) {
314  int w, h;
315  w = Min( iw, img->win_w );
316  h = Min( ih, img->win_h );
317  img->image = get_X_image( img, w, h, True );
318  }
319  if ( img->image == NULL )
320  perror("problem getting XImage");
321 
322  return( img->image != NULL );
323 }
324 
326 image_information *img;
327 Boolean reallocate;
328 {
329  extern int stingy_flag;
330 
331  int iw = img->w * img->mag_fact;
332  int ih = img->h * img->mag_fact;
333 
334  if (( img->pixmap != NULL && reallocate ) ||
335  ( img->pixmap != NULL && (img->pix_w < iw || img->pix_h < ih ))){
337  img->pixmap = NULL;
338  }
339 
340  /* reallocate it: use the Min of the winsize and (pic * mag) */
341  if ( !img->pixmap && !img->pixmap_failed && !stingy_flag) {
342  img->pix_w = Min( iw, img->win_w );
343  img->pix_h = Min( ih, img->win_h );
344 #ifdef X_SHARED_MEMORY
345  img->shm_pix.shmid = -1;
346  if ( use_shared_pixmaps )
347  {
348  XImage *image;
349  XShmSegmentInfo shminfo;
350 
351  /* Allocate an image structure to get bytes_per_line. */
352  image = XShmCreateImage( dpy, img->dpy_visual,
353  img->dpy_depth, ZPixmap,
354  NULL, &shminfo,
355  img->pix_w, img->pix_h );
356  /* Get a shared segment for the pixmap. */
357  img->shm_pix.shmid =
358  shmget( IPC_PRIVATE,
359  image->bytes_per_line * image->height,
360  IPC_CREAT|0777 );
361  XDestroyImage( image );
362  if ( img->shm_pix.shmid < 0 )
363  {
364  if ( errno == ENOSPC )
365  {
366  if ( !no_shared_space )
367  fprintf( stderr,
368  "getx11: No more shared memory segments\n" );
369  no_shared_space = True;
370  }
371  else
372  perror( "getx11: shared memory allocation failed" );
373  }
374  else
375  {
376  /* Attach the segment & get its address. */
377  img->shm_pix.shmaddr = shmat( img->shm_pix.shmid, 0, 0 );
378 
379  if ( img->shm_pix.shmaddr == NULL) {
380  perror ( "getx11: attach shared pixmap" );
381  shmctl( img->shm_pix.shmid, IPC_RMID, 0 );
382  img->shm_pix.shmid = -1;
383  }
384  else
385  {
386  /* Want to write into the segment! */
387  img->shm_pix.readOnly = False;
388 
389  /* Tell the X server about it. */
390  if ( !XShmAttach( dpy, &img->shm_pix ) )
391  {
392  fprintf( stderr, "getx11: XShmAttach failed.\n" );
393  shmdt( img->shm_pix.shmaddr );
394  shmctl( img->shm_pix.shmid, IPC_RMID, 0 );
395  img->shm_pix.shmid = -1;
396  }
397  else
398  {
399  img->pixmap = XShmCreatePixmap(
400  dpy, img->window, img->shm_pix.shmaddr,
401  &img->shm_pix, img->pix_w, img->pix_h,
402  img->dpy_depth );
403  }
404  }
405  }
406  }
407 
408  /* If not sharing, or sharing failed, then try to do it normally. */
409  if ( img->shm_pix.shmid < 0 )
410 #endif /* X_SHARED_MEMORY */
411  img->pixmap = XCreatePixmap(dpy, img->window,
412  img->pix_w, img->pix_h,
413  img->dpy_depth );
415 #ifdef X_SHARED_MEMORY
416  if ( img->shm_pix.shmid >= 0 )
417  {
418  /* Remove it now so it will go when we die.
419  * Another nice side effect: we don't fill up the SHM table,
420  * so we can allocate hundreds of them.
421  */
422  shmctl( img->shm_pix.shmid, IPC_RMID, 0 );
423  }
424 #endif
425  }
426 }
427 
428 void
430 image_information *img;
431 Pixmap pix;
432 {
433  XFreePixmap( dpy, pix );
434 #ifdef X_SHARED_MEMORY
435  if ( use_shared_pixmaps && pix == img->pixmap && img->shm_pix.shmid >= 0 )
436  {
437  XShmDetach( dpy, &img->shm_pix );
438  shmdt( img->shm_pix.shmaddr );
439  shmctl( img->shm_pix.shmid, IPC_RMID, 0 );
440  img->shm_pix.shmid = -1;
441  }
442 #endif
443 }
444 
445 void
447  width, height )
448 image_information *img;
449 Drawable d;
450 GC gc;
451 XImage *image;
452 int src_x, src_y, dest_x, dest_y;
453 unsigned int width, height;
454 {
455 #ifdef X_SHARED_MEMORY
456  if ( use_shared_pixmaps && img->image == image && img->shm_img.shmid >= 0 )
457  XShmPutImage( dpy, d, gc, image, src_x, src_y, dest_x, dest_y,
458  width, height, False );
459  else
460 #endif
461  XPutImage( dpy, d, gc, image, src_x, src_y, dest_x, dest_y,
462  width, height );
463 }
464 
465 void
468 int image_width, image_height;
469 int *icon_width, *icon_height, *icon_factor;
470 {
471  XIconSize *icon_sizes;
472  int icon_size_count;
473  int width, height, factor;
474  int i;
475 
476  /*
477  * We want the Icon to be about DESIRED_ICON_WIDTH x DESIRED_ICON_HEIGHT.
478  * First, make sure that is OK with the window manager.
479  * Then figure out the icon scaling factor.
480  */
481 
482 #define DESIRED_ICON_WIDTH 48
483 #define DESIRED_ICON_HEIGHT 48
484 
485  width = DESIRED_ICON_WIDTH;
486  height = DESIRED_ICON_HEIGHT;
487 
488  if (XGetIconSizes (dpy, root_window, &icon_sizes, &icon_size_count)
489  && icon_size_count >= 1) {
490 
491  for (i = 0; i < icon_size_count; i++) {
492  if (icon_sizes[i].min_width <= DESIRED_ICON_WIDTH
493  && icon_sizes[i].max_width >= DESIRED_ICON_WIDTH
494  && icon_sizes[i].min_height <= DESIRED_ICON_HEIGHT
495  && icon_sizes[i].max_height >= DESIRED_ICON_HEIGHT) {
496  break;
497  }
498  }
499 
500  if (i >= icon_size_count) {
501  width = icon_sizes[0].max_width;
502  height = icon_sizes[0].max_height;
503  }
504 
505  }
506 
507  factor = image_width / width;
508  if (factor < image_height / height)
509  factor = image_height / height;
510  if ( factor == 0 )
511  factor = 1;
512 
513  *icon_width = 1 + (image_width / factor);
514  *icon_height = 1 + (image_height / factor);
515  *icon_factor = factor;
516 }
517 
518 
520 image_information *img;
521 {
522  img->colormap = XCreateColormap (dpy, root_window,
523  img->dpy_visual, AllocNone );
524  if (img->colormap == NULL)
525  fprintf(stderr, "getx11: Could not create color map for visual\n");
526  else {
527  VPRINTF(stderr, "created colormap for visual type %s\n",
528  visual_class_to_string(img->visual_class));
529  }
530 }
531 
533 char *display_name;
534 {
535  /* Check to see if user explicitly specified the screen with -d. */
536  if ( display_name )
537  {
538  char *dotp = strrchr( display_name, '.' );
539  char *colonp = strrchr( display_name, ':' );
540 
541  /* If the dot follows the colon, then it's a screen designator. */
542  if ( dotp && colonp && dotp > colonp && dotp[1] != '\0' )
543  specified_screen = atoi( dotp+1 );
544  }
545 
546  if (display_name == NULL || *display_name == '\0')
547  display_name = getenv("DISPLAY");
548 
549  dpy = XOpenDisplay(display_name);
550 
551  if (dpy == NULL) {
552  fprintf(stderr, "%s: Cant open display %s\n", progname,
553  (display_name == NULL) ? "" : display_name);
554  exit(1);
555  }
556 
557 #ifdef X_SHARED_MEMORY
558  if (do_sharing)
559  {
560  Status sh_status;
561  int sh_major, sh_minor;
562  Boolean sh_pixmaps = False;
563 
564  sh_status = XShmQueryVersion( dpy, &sh_major, &sh_minor, &sh_pixmaps );
565  use_shared_pixmaps = (Boolean)(sh_status && sh_pixmaps);
566  }
567 #endif
568  /* Work around bug in X11/NeWS server colormap allocation. */
569  if (strcmp("X11/NeWS - Sun Microsystems Inc.", ServerVendor(dpy)) == 0 &&
570  VendorRelease(dpy) == 2000)
571  no_color_ref_counts = True;
572 
573 }
574 
576 image_information *img;
577 {
578  img->xo = (img->win_w - (img->w * img->mag_fact)) / 2;
579  img->yo = (img->win_h - (img->h * img->mag_fact)) / 2;
580  img->xo = Max (0, img->xo);
581  img->yo = Max (0, img->yo);
582 }
583 /*
584  * Create a window with no help from user.
585  */
586 void
588 char *window_geometry;
589 register image_information *img;
590 {
591  static char prog_name[] = "getx11";
592  static char class_name[] = "Getx11";
593  static XClassHint class_hint = {prog_name, class_name};
594  char default_geometry[30];
595  int width, height, x, y;
596  XSizeHints size_hints;
597  unsigned int mask;
598  unsigned long gc_mask = 0;
599  XGCValues gc_values;
600  XWMHints wm_hints;
601  XSetWindowAttributes xswa;
602  unsigned long xswa_mask;
603  Boolean new_window;
604  int icn_alloc = False;
605  Boolean new_pixmaps;
606 
607  /*
608  * Now, make the window.
609  */
610 
611  new_window = (img->window == NULL && img->icn_window == NULL);
612  new_pixmaps = ((img->pixmap == NULL || img->icn_pixmap == NULL) &&
613  !img->pixmap_failed && !stingy_flag);
614 
615  if ( !img->window )
616  {
617  sprintf( default_geometry, "=%dx%d", img->w, img->h );
618 
619  mask = XGeometry(dpy, screen, window_geometry, default_geometry,
620  IMAGE_BORDERWIDTH, 1, 1, 0, 0,
621  &x, &y, &width, &height );
622 
623  size_hints.flags = 0;
624 
625  if ( mask & (XValue | YValue) ) {
626  size_hints.flags |= USPosition;
627  size_hints.x = x;
628  size_hints.y = y;
629  } else {
630  size_hints.flags |= PPosition;
631  size_hints.x = x = (DisplayWidth(dpy, screen) - width)/2;
632  size_hints.y = y = (DisplayHeight(dpy, screen) - height)/2;
633  }
634 
635  if ( mask & (WidthValue | HeightValue) ) {
636  size_hints.flags |= USSize;
637  size_hints.width = width;
638  size_hints.height = height;
639  }
640 
641  VPRINTF (stderr, "window at (%d, %d) %dx%d\n",
642  x, y, width, height);
643 
644  xswa_mask = CWBackPixel | CWEventMask | CWBorderPixel;
645  xswa.background_pixel = BlackPixel (dpy, screen);
646  xswa.border_pixel = WhitePixel (dpy, screen);
647  xswa.event_mask = ButtonPressMask | ExposureMask | KeyPressMask |
648  StructureNotifyMask;
649 
650  if (img->colormap) {
651  xswa.colormap = img->colormap;
652  xswa_mask |= CWColormap;
653  }
654 
655  img->window = XCreateWindow ( dpy, root_window, x, y,
656  width, height,
658  InputOutput, img->dpy_visual,
659  xswa_mask, &xswa);
660 
661  img->win_w = width;
662  img->win_h = height;
663  calc_view_origin ( img );
664 
665  XSetNormalHints (dpy, img->window, &size_hints);
666  XSetClassHint(dpy, img->window, &class_hint);
667  XSetIconName (dpy, img->window, img->title);
668  }
669  XStoreName(dpy, img->window, img->title);
670 
671  if ( new_pixmaps )
672  allocate_pixmap( img, False );
673 
674  if ( !img->icn_window )
675  {
676  /* dies with BadMatch on some server/visual pairs without these?!?!? */
677  xswa_mask = CWBackPixel | CWBorderPixel;
678  xswa.background_pixel = BlackPixel (dpy, screen);
679  xswa.border_pixel = WhitePixel (dpy, screen);
680 
681  if (img->colormap) {
682  xswa.colormap = img->colormap;
683  xswa_mask |= CWColormap;
684  }
685 
686  img->icn_window = XCreateWindow (dpy, root_window, 0, 0,
687  img->icn_w, img->icn_h,
688  0, img->dpy_depth,
689  InputOutput, img->dpy_visual,
690  xswa_mask, &xswa);
691 
692  size_hints.flags = PMinSize | PMaxSize;
693  size_hints.min_width = img->icn_w;
694  size_hints.max_width = img->icn_w;
695  size_hints.min_height = img->icn_h;
696  size_hints.max_height = img->icn_h;
697 
698  XSetNormalHints(dpy, img->icn_window, &size_hints);
699  XStoreName(dpy, img->icn_window, img->title);
700  }
701 
702  if ( !img->gc )
703  {
704  gc_mask = 0;
705  gc_values.function = GXcopy; gc_mask |= GCFunction;
706  gc_values.plane_mask = AllPlanes; gc_mask |= GCPlaneMask;
707 
708  gc_values.foreground = img->white_pixel; gc_mask |= GCForeground;
709  gc_values.background = img->black_pixel; gc_mask |= GCBackground;
710 
711  gc_values.graphics_exposures = False; gc_mask |= GCGraphicsExposures;
712 
713  img->gc = XCreateGC (dpy, img->window, gc_mask, &gc_values);
714  }
715 
716  if ( !img->icn_pixmap )
717  {
718  img->icn_pixmap = XCreatePixmap(dpy, img->icn_window, img->icn_w,
719  img->icn_h, img->dpy_depth );
720 
721  img->icn_gc = XCreateGC(dpy, img->icn_window, gc_mask, &gc_values);
722  icn_alloc = True;
723  }
724 
725  if ( new_pixmaps || icn_alloc )
727 
728  if ( new_window )
729  {
730  if ( img->icn_pixmap && img->icn_window ) {
731  wm_hints.flags = ( StateHint | IconPixmapHint | IconMaskHint |
732  IconWindowHint | InputHint );
733  wm_hints.initial_state = NormalState;
734  wm_hints.icon_pixmap = img->icn_pixmap;
735  wm_hints.icon_window = img->icn_window;
736  wm_hints.icon_mask = img->icn_pixmap;
737  wm_hints.input = True;
738 
739  XSetWMHints (dpy, img->window, &wm_hints);
740  }
741 
742  XSetWindowBackgroundPixmap(dpy, img->icn_window, img->icn_pixmap);
743 
744  XMapWindow( dpy, img->window );
745  XClearWindow( dpy, img->window );
746 
748  }
749 
750  XFlush( dpy );
751 }
752 
753 /*
754  * Get the most contrasting colors from the colormap.
755  */
756 static void
757 get_most_contrasting( img, lightest, darkest )
758 register image_information *img;
759 unsigned long *lightest, *darkest;
760 {
761  register int c, l, d;
762  long li, di, i;
763  int n = img->dpy_visual->map_entries;
764  XColor *cells = (XColor *)malloc( n * sizeof(XColor) );
765 
766  for ( c = 0; c < n; c++ )
767  cells[c].pixel = c;
768  XQueryColors( dpy, img->colormap, cells, n );
769 
770  /* Find lightest & darkest. */
771  d = l = 0;
772  di = li = cells[0].red + cells[0].green + cells[0].blue;
773  for ( c = 0; c < n; c++ )
774  {
775  i = cells[c].red + cells[c].green + cells[c].blue;
776  if ( i < di )
777  {
778  d = c;
779  di = i;
780  }
781  if ( i > li )
782  {
783  l = c;
784  li = i;
785  }
786  }
787  *lightest = cells[l].pixel;
788  *darkest = cells[d].pixel;
789 
790  free( cells );
791 }
792 
793 static void set_white_black_pixel( img )
794 image_information *img;
795 {
796  static cmap_info cmap_i;
797  cmap_i = img->x_cmap;
798  if ( img->binary_img || img->mono_color ) {
799  if ( img->colormap )
800  get_most_contrasting( img, &img->white_pixel, &img->black_pixel );
801  else
802  {
803  img->black_pixel = BlackPixel (dpy, screen);
804  img->white_pixel = WhitePixel (dpy, screen);
805  }
806 
807  }
808  else if ( img->pixel_table != NULL ) {
809  img->black_pixel = img->pixel_table[0];
810  img->white_pixel =
811  img->pixel_table[(img->mono_img) ? img->lvls - 1 :
812  img->lvls * img->lvls * img->lvls - 1];
813  }
814  else {
815  img->black_pixel = 0;
816  img->white_pixel =
817  SHIFT_MASK_PIXEL(img->lvls - 1,img->lvls - 1,img->lvls - 1);
818  }
819 }
820 
821 
822 /* this is a relic */
823 static int log2_levels;
824 
825 /*
826  * This routine builds the color map (for X window system, details may
827  * differ in your system. Note particularly the two level color
828  * mapping: X will give back 216 color map entries, but there is no
829  * guarantee they are sequential. The dithering code above wants to
830  * compute a number in 0 - 215, so we must map from this to the X color
831  * map entry id.
832  */
833 
834 /*
835  * Initialize the 8 bit color map. Use gamma corrected map.
836  */
837 
838 #define IS_BINARY 1
839 #define IS_MONO 2
840 #define WANT_READ_WRITE 4
841 #define NOT_BINARY 0
842 #define NOT_MONO 0
843 #define WANT_READ_ONLY 0
844 
846 register image_information *img;
847 {
848  register int type;
849  Boolean done = False, try_ro = True;
850 
851  while ( ! done ) {
852  DPRINTF (stderr, "Cmap type: binary %d, mono %d, read/write %d\n",
853  img->binary_img, img->mono_img, img->rw_cmap );
854 
855  type = ((( img->binary_img ) ? IS_BINARY : NOT_BINARY ) |
856  (( img->mono_img ) ? IS_MONO : NOT_MONO ) |
857  ((( img->rw_cmap && img->sep_colors ) ||
858  ( img->rw_cmap && !try_ro)) ?
860 
861  switch ( type ) {
862 
864  done = (( img->sep_colors ) ?
865  init_separate_color_rw( img ) :
866  init_color_rw( img ));
867  if ( !done && !try_ro) {
868  fprintf( stderr,
869  "%s: not enough cmap entries available, trying b/w.\n",
870  progname );
871  img->mono_img = True;
872  img->dpy_channels = 1;
873  }
874  break;
875 
877  done = (( img->sep_colors ) ?
878  init_separate_color_ro( img, try_ro ) :
879  init_color_ro( img, try_ro ));
880  if ( !done && !try_ro ) {
881  fprintf( stderr,
882  "%s: not enough cmap entries available, trying b/w.\n",
883  progname );
884  img->mono_img = True;
885  img->dpy_channels = 1;
886  }
887  break;
888 
890  done = (img->sep_colors ?
891  init_separate_color_rw( img ) : init_mono_rw( img ));
892  if ( !done & !try_ro ) img->binary_img = True;
893  break;
894 
896  done = ( img->sep_colors ?
897  init_separate_color_ro( img, try_ro ) :
898  init_mono_ro( img, try_ro ));
899  if ( !done & !try_ro ) img->binary_img = True;
900  break;
901 
903  /* make the magic square */
904  get_dither_arrays( img );
905  make_square( 255.0, img->divN, img->modN, img->dm16 );
906 
907  img->lvls = 2;
908  img->lvls_squared = 4;
909  done = True;
910  break;
911 
912  default:
913  fprintf (stderr, "Unknown type in init_colors: %d\n", type);
914  exit (1);
915  }
916  if (! done) {
917  try_ro = False;
918  if ( img->rw_cmap == True ) {
919  get_x_colormap( img );
920  }
921  }
922  }
923 
924  /* If not dithering, center the quantization intervals. */
925  if ( !img->dither_img )
926  {
927  int n = (int)(0.5 + 255.0 / (2 * (img->lvls - 1)));
928  register int i, j;
929  register int *divN = img->divN;
930 
931  for ( i = 0, j = n; j <= 255; i++, j++ )
932  divN[i] = divN[j];
933  for ( ; i < 255; i++ )
934  divN[i] = divN[255];
935  }
936 
937  VPRINTF (stderr, "Created color map with %d entries", img->lvls);
938 
939  if (! img->mono_img ) {
940  VPRINTF (stderr, " per color, %d total\n", img->lvls * img->lvls * img->lvls);}
941  else VPRINTF (stderr, "\n");
942 
943  set_white_black_pixel( img );
944 }
945 
946 /* Used to allocate the colormap for a DirectColor visual. */
947 
948 static
949 Boolean
950 init_separate_color_rw ( img )
951 image_information *img;
952 {
953  register int i;
954  int log2_num_lvls, num_lvls, total_levels;
955  int *map;
956  XColor *color_defs;
957  cmap_info cmap_i;
958 
959  /*
960  * use XAllocColorPlanes to allocate all the cells we need --
961  * this makes it simple for me.
962  */
963 
964  img->pixel_table = NULL;
965  map = NULL;
966  color_defs = NULL;
967 
968  for (log2_num_lvls = log2_levels;
969  log2_num_lvls >= 1;
970  log2_num_lvls-- ) {
971 
972  num_lvls = 1 << log2_num_lvls;
973  total_levels = 1 << (log2_num_lvls * 3);
974 
975  if (map == NULL) {
976  map = (int *) malloc (num_lvls * sizeof (int) );
977  if (map == NULL) continue;
978  }
979 
980  if (color_defs == NULL) {
981  color_defs = (XColor *) malloc ( num_lvls * sizeof (XColor) );
982  if (color_defs == NULL)
983  continue;
984  }
985 
986  if ( XAllocColorPlanes (dpy, img->colormap, 1, &cmap_i.pixel_base, 1,
987  log2_num_lvls, log2_num_lvls,
988  log2_num_lvls,
989  &cmap_i.red_mask,
990  &cmap_i.green_mask,
991  &cmap_i.blue_mask) == 0)
992  continue;
993 
994  if (log2_num_lvls == 8) img->dither_img = False;
995 
996  get_dither_arrays( img );
997  bwdithermap ( num_lvls, display_gamma, map,
998  img->divN, img->modN, img->dm16 );
999 
1003  img->x_cmap = cmap_i;
1004 
1005  /*
1006  * Set up the color map entries.
1007  */
1008 
1009  for (i = 0; i < num_lvls; i++)
1010  {
1011  color_defs[i].pixel = SHIFT_MASK_PIXEL(i, i, i);
1012 
1013  color_defs[i].red = map[i] << 8;
1014  color_defs[i].green = map[i] << 8;
1015  color_defs[i].blue = map[i] << 8;
1016 
1017  color_defs[i].flags = DoRed | DoGreen | DoBlue;
1018  }
1019 
1020  XStoreColors (dpy, img->colormap, color_defs, num_lvls);
1021 
1022  if (img->lvls != num_lvls) {
1023  img->lvls = num_lvls;
1024  img->lvls_squared = num_lvls * num_lvls;
1025  log2_levels = log2_num_lvls;
1026  }
1027 
1028  /* pack into a pixel the pre shifted and masked pixel values */
1029  if ( img->mono_color ) {
1030  int shift = 8 - log2_num_lvls;
1031  img->pixel_table = (Pixel *)malloc(img->cmlen * sizeof (Pixel));
1032  if (!img->pixel_table) continue;
1033  for ( i = 0; i < img->cmlen; i++ )
1034  img->pixel_table[i] =
1035  SHIFT_MASK_PIXEL(img->in_cmap[RLE_RED][i] >> shift,
1036  img->in_cmap[RLE_GREEN][i] >> shift,
1037  img->in_cmap[RLE_BLUE][i] >> shift);
1038  }
1039 
1040  free (map);
1041  free (color_defs);
1042 
1043  return (True);
1044 
1045  }
1046 
1047  return (False);
1048 }
1049 
1050 /*
1051  * Used for allocating the colormap in a PsuedoColor visual or other color
1052  * type. Used for the standard 8 bit display
1053  */
1054 static
1055 Boolean
1056 init_color_rw ( img )
1057 image_information *img;
1058 {
1059  int num_lvls;
1060  int *map;
1061  XColor *color_defs, *color;
1062  int total_levels;
1063  int red_index;
1064  int green_index;
1065  int blue_index;
1066  int i, j;
1067  int free_pixels = 0, shift, cmap_size;
1068  Pixel *pixels;
1069 
1070  DPRINTF(stderr, "In init_color_rw\n");
1071 
1072  /* get free pixels from the default colormap */
1073  cmap_size = (1 << img->dpy_depth);
1074 
1075  /* get all free cells in the colormap in <depth> calls to AllocColor */
1076  pixels = (Pixel *) malloc (cmap_size * sizeof (Pixel) );
1077  color_defs = (XColor *) malloc (cmap_size * sizeof (XColor) );
1078  if ( pixels && color_defs )
1079  {
1080  DPRINTF(stderr, "Allocating colors: success/failure ");
1081  for (shift = img->dpy_depth; shift >= 0; shift--)
1082  if (XAllocColorCells (dpy, img->colormap, False, 0, 0,
1083  &pixels[free_pixels],
1084  (int)1 << shift))
1085  {
1086  DPRINTF(stderr, "1");
1087  free_pixels += (unsigned int)1 << shift;
1088  }
1089  else DPRINTF(stderr, "0");
1090  DPRINTF(stderr, " got %d\n", free_pixels);
1091  }
1092 
1093  total_levels = 1;
1094 
1095  for (num_lvls = img->lvls;
1096  num_lvls > 1;
1097  num_lvls-- )
1098  {
1099  total_levels = num_lvls * num_lvls * num_lvls;
1100  if ( total_levels <= free_pixels )
1101  break;
1102  }
1103  if ( !num_lvls )
1104  return (False);
1105 
1106  if (img->lvls > num_lvls) {
1107  img->lvls = num_lvls;
1108  img->lvls_squared = num_lvls * num_lvls;
1109  for (log2_levels = 1, i = 2; i < img->lvls; i <<= 1, log2_levels++) {
1110  /* do nothing */
1111  }
1112  }
1113 
1114  if ( num_lvls == 256 )
1115  img->dither_img = False;
1116 
1117  if (! img->pixel_table )
1118  img->pixel_table = (Pixel *) malloc (total_levels * sizeof (Pixel) );
1119 
1120  map = (int *) malloc (num_lvls * sizeof (int) );
1121 
1122  get_dither_arrays( img );
1123  bwdithermap ( num_lvls, display_gamma, map,
1124  img->divN, img->modN, img->dm16 );
1125 
1126  /*
1127  * Use the top free_pixels NOT the bottom ones. This makes it right for
1128  * 99% of the DISPLAYs out there which begin using colors at the bottom.
1129  * We take the top color cells, and copy the bottom ones into the extra
1130  * spaces, *some* other windows won't be clobbered by our colormap.
1131  */
1132  shift = free_pixels - total_levels;
1133 
1134  for (j = 0, i = shift; j < total_levels; i++, j++)
1135  img->pixel_table[j] = pixels[i];
1136 
1137  for (i = 0; i < shift; i++)
1138  color_defs[i].pixel = pixels[i];
1139 
1140  XQueryColors( dpy, DefaultColormap(dpy, screen),
1141  color_defs, shift );
1142 
1143  /*
1144  * Set up the color map entries.
1145  */
1146 
1147  color = &color_defs[shift];
1148 
1149  red_index = 0;
1150  green_index = 0;
1151  blue_index = 0;
1152 
1153  for (i = 0; i < total_levels; i++) {
1154  color->pixel = img->pixel_table[i];
1155  color->red = map[red_index] << 8;
1156  color->green = map[green_index] << 8;
1157  color->blue = map[blue_index] << 8;
1158 
1159  color->flags = DoRed | DoGreen | DoBlue;
1160  color++;
1161 
1162  if (++red_index >= num_lvls) {
1163  if (++green_index >= num_lvls) {
1164  ++blue_index;
1165  green_index = 0;
1166  }
1167  red_index = 0;
1168  }
1169 
1170  }
1171 
1172  XStoreColors (dpy, img->colormap, color_defs, free_pixels);
1173 
1174  free (map);
1175  free (color_defs);
1176  free (pixels);
1177  return (True);
1178 }
1179 
1180 static
1181 Boolean
1182 init_separate_color_ro ( img, try_ro )
1183 image_information *img;
1184 int try_ro;
1185 {
1186  cmap_info cmap_i;
1187  register int num_lvls;
1188  register int log2_num_lvls;
1189  register int *map = NULL;
1190  register int i;
1191 
1192  cmap_i = img->x_cmap;
1193  DPRINTF(stderr, "In init_separate_color_ro\n");
1194 
1195  for (log2_num_lvls = log2_levels;
1196  log2_num_lvls >= 1;
1197  log2_num_lvls-- ) {
1198 
1199  num_lvls = 1 << log2_num_lvls;
1200 
1201  if (map == NULL) {
1202  map = (int *) malloc (num_lvls * sizeof (int) );
1203  if (map == NULL) continue;
1204  }
1205 
1206  if (num_lvls == 256) img->dither_img = False;
1207 
1208  DPRINTF (stderr, "num_lvls = %d\n", num_lvls);
1209 
1210  get_dither_arrays( img );
1211  bwdithermap( num_lvls, display_gamma, map,
1212  img->divN, img->modN, img->dm16 );
1213 
1214  cmap_i.red_mask = img->dpy_visual->red_mask;
1215  cmap_i.green_mask = img->dpy_visual->green_mask;
1216  cmap_i.blue_mask = img->dpy_visual->blue_mask;
1217 
1218  cmap_i.red_shift = shift_match_left(cmap_i.red_mask, log2_num_lvls);
1219  cmap_i.green_shift = shift_match_left(cmap_i.green_mask, log2_num_lvls);
1220  cmap_i.blue_shift = shift_match_left(cmap_i.blue_mask, log2_num_lvls);
1221 
1222  img->x_cmap = cmap_i;
1223 
1224  if (img->lvls > num_lvls) {
1225  img->lvls = num_lvls;
1226  img->lvls_squared = num_lvls * num_lvls;
1227  log2_levels = log2_num_lvls;
1228  }
1229 
1230  /* pack into a pixel the pre shifted and masked pixel values */
1231  if ( img->mono_color ) {
1232  int shift = 8 - log2_num_lvls;
1233  img->pixel_table = (Pixel *)malloc(img->cmlen * sizeof (Pixel));
1234  if (!img->pixel_table) continue;
1235  for ( i = 0; i < img->cmlen; i++ )
1236  img->pixel_table[i] =
1237  SHIFT_MASK_PIXEL(img->in_cmap[RLE_RED][i] >> shift,
1238  img->in_cmap[RLE_GREEN][i] >> shift,
1239  img->in_cmap[RLE_BLUE][i] >> shift);
1240  }
1241 
1242  if ( map )
1243  free (map);
1244 
1245  return (True);
1246 
1247  }
1248 
1249  return (False);
1250 
1251 }
1252 
1253 static int pixcompare(pixel1, pixel2 )
1254 Pixel *pixel1, *pixel2;
1255 {
1256  return( *pixel1 - *pixel2 );
1257 }
1258 
1260 image_information *img;
1261 Pixel *pixels;
1262 int npixels;
1263 {
1264  Pixel *p;
1265  int i, nunique;
1266 
1267  if ( no_color_ref_counts )
1268  {
1269  qsort(pixels, npixels, sizeof(Pixel), pixcompare);
1270  p = pixels;
1271 
1272  for (i=1; i<npixels; i++ ) {
1273  if ( pixels[i] != *p ) {
1274  p += 1;
1275  *p = pixels[i];
1276  }
1277  }
1278 
1279  nunique = (p - pixels) + 1;
1280 
1281  DPRINTF(stderr, "In free_unique_pixels \n\nPixels: ");
1282  for (i=0;i<nunique;i++) DPRINTF(stderr, " %d ",pixels[i]);
1283  DPRINTF(stderr, "\n");
1284  }
1285  else
1286  nunique = npixels;
1287 
1288  XFreeColors(dpy, img->colormap, pixels, nunique, 0);
1289 }
1290 
1291 static
1292 Boolean
1293 init_color_ro ( img, try_ro )
1294 image_information *img;
1295 int try_ro;
1296 {
1297  register int num_lvls;
1298  register int total_levels;
1299 #ifdef XLIBINT_H_NOT_AVAILABLE
1300  XColor color_def;
1301 #else
1302  register XColor *color_defs = NULL;
1303  register Status *status = NULL;
1304 #endif
1305  register int red_index;
1306  register int green_index;
1307  register int blue_index;
1308  register int *map = NULL;
1309  register int i;
1310 #ifndef XLIBINT_H_NOT_AVAILABLE
1311  register int j;
1312 #endif
1313  int first = True;
1314 
1315  DPRINTF(stderr, "In init_color_ro\n");
1316 
1317  for (num_lvls = img->lvls; num_lvls >= 2; num_lvls -- ) {
1318 
1319  if (try_ro && !first && specified_levels) break;
1320  else first = False;
1321 
1322  total_levels = num_lvls * num_lvls * num_lvls;
1323 
1324  if ( !img->pixel_table ) {
1325  img->pixel_table = (Pixel *)malloc(total_levels * sizeof (Pixel) );
1326  if ( !img->pixel_table ) continue;
1327  }
1328 
1329  if ( map == NULL ) {
1330  map = (int *) malloc (num_lvls * sizeof (int) );
1331  if (map == NULL) continue;
1332  }
1333 
1334  if (num_lvls == 256) img->dither_img = False;
1335 
1336  get_dither_arrays( img );
1337  bwdithermap( num_lvls, display_gamma, map,
1338  img->divN, img->modN, img->dm16 );
1339 
1340  /* try to get a color map entry for each color. */
1341  red_index = green_index = blue_index = 0;
1342 
1343 #ifdef XLIBINT_H_NOT_AVAILABLE
1344  for ( i = 0; i < total_levels; i++ ) {
1345  color_def.red = map[red_index] << 8;
1346  color_def.green = map[green_index] << 8;
1347  color_def.blue = map[blue_index] << 8;
1348 
1349  if ( XAllocColor (dpy, img->colormap, &color_def ) == 0 ) {
1350  break;
1351  }
1352 
1353  if (++red_index >= num_lvls) {
1354  if (++green_index >= num_lvls) {
1355  ++blue_index; green_index = 0;
1356  }
1357  red_index = 0;
1358  }
1359 
1360  img->pixel_table[i] = color_def.pixel;
1361  }
1362 
1363  /* Check if the colors are available */
1364  if ( i < total_levels ) { /* Free the colors already obtained */
1365  free_unique_colors (img, img->pixel_table, i );
1366  continue;
1367  }
1368 #else
1369  if (!color_defs)
1370  color_defs = (XColor *) malloc(total_levels * sizeof (XColor));
1371  if (!status)
1372  status = (Status *) malloc(total_levels * sizeof (Status));
1373  if ( !status || !color_defs ) continue;
1374 
1375  for ( i = 0; i < total_levels; i++ ) {
1376  color_defs[i].red = map[red_index] << 8;
1377  color_defs[i].green = map[green_index] << 8;
1378  color_defs[i].blue = map[blue_index] << 8;
1379  if (++red_index >= num_lvls) {
1380  if (++green_index >= num_lvls) {
1381  ++blue_index; green_index = 0;
1382  }
1383  red_index = 0;
1384  }
1385  }
1386 
1387  if (XAllocColors(dpy, img->colormap, color_defs, total_levels, status)== 0)
1388  {
1389  for ( i = 0, j = 0; i < total_levels; i++ )
1390  if (status[i])
1391  img->pixel_table[j++] = color_defs[i].pixel;
1393  continue;
1394  } else
1395  for ( i = 0; i < total_levels; i++ )
1396  img->pixel_table[i] = color_defs[i].pixel;
1397 
1398 #endif
1399  img->lvls = num_lvls;
1400  img->lvls_squared = num_lvls * num_lvls;
1401 
1402  for (log2_levels = 1, i = 2; i < img->lvls; i <<= 1, log2_levels++) {
1403  /* do nothing */
1404  }
1405  if (map) free (map);
1406 #ifndef XLIBINT_H_NOT_AVAILABLE
1407  if (color_defs) free (color_defs);
1408  if (status) free (status);
1409 #endif
1410  return (True);
1411  }
1412  if (map) free (map);
1413 #ifndef XLIBINT_H_NOT_AVAILABLE
1414  if (color_defs) free (color_defs);
1415  if (status) free (status);
1416 #endif
1417  return (False);
1418 }
1419 
1420 static
1421 Boolean
1422 init_mono_rw ( img )
1423 image_information *img;
1424 {
1425  int num_lvls;
1426  int *map;
1427  XColor *color_defs, *color;
1428  int i, j;
1429  int free_pixels = 0, shift, cmap_size;
1430  Pixel *pixels;
1431 
1432  DPRINTF(stderr, "In init_mono_rw\n");
1433 
1434  /* get free pixels from the default colormap */
1435  cmap_size = (1 << img->dpy_depth);
1436 
1437  /* get all free cells in the colormap in <depth> calls to AllocColor */
1438  pixels = (Pixel *) malloc (cmap_size * sizeof (Pixel) );
1439  color_defs = (XColor *) malloc (cmap_size * sizeof (XColor) );
1440  if ( pixels && color_defs ) {
1441  DPRINTF(stderr, "Allocating colors: success/failure ");
1442  for (shift = img->dpy_depth; shift >= 0; shift--)
1443  if (XAllocColorCells (dpy, img->colormap, False, 0, 0,
1444  &pixels[free_pixels],
1445  (int)1 << shift))
1446  {
1447  DPRINTF(stderr, "1");
1448  free_pixels += (unsigned int)1 << shift;
1449  }
1450  else DPRINTF(stderr, "0");
1451  DPRINTF(stderr, " got %d\n", free_pixels);
1452  }
1453 
1454  if ( img->mono_color ) {
1455  img->lvls = img->cmlen;
1456  if ( img->cmlen > free_pixels )
1457  fprintf(stderr, "%s: Warning: Not enough cells for input cmap\n",
1458  progname);
1459  }
1460 
1461  if ( free_pixels == 0 ) return False;
1462 
1463  num_lvls = img->lvls;
1464  while ( num_lvls > free_pixels && num_lvls >= 2 )
1465  num_lvls = ((num_lvls > 16) ? num_lvls / 2 : num_lvls - 1);
1466 
1467  img->lvls = num_lvls;
1468  img->lvls_squared = num_lvls * num_lvls;
1469  for (log2_levels = 1, i = 2; i < img->lvls; i <<= 1, log2_levels++) {
1470  /* do nothing */
1471  }
1472 
1473  if ( num_lvls == 256 && img->mono_color )
1474  img->dither_img = False;
1475 
1476  if ( !img->pixel_table )
1477  img->pixel_table = (Pixel *)
1478  malloc ((img->mono_color? img->cmlen : num_lvls) * sizeof(Pixel) );
1479  map = (int *) malloc ( num_lvls * sizeof(int) );
1480 
1481  if (!map || !img->pixel_table) {
1482  fprintf(stderr, "malloc problems in init_mono_rw\n");
1483  return False;
1484  }
1485 
1486  get_dither_arrays( img );
1487  bwdithermap(num_lvls, display_gamma, map,
1488  img->divN, img->modN, img->dm16 );
1489 
1490  /*
1491  * Use the top free_pixels NOT the bottom ones. This makes it right for
1492  * 99% of the DISPLAYs out there which begin using colors at the bottom.
1493  * We take the top color cells, and copy the bottom ones into the extra
1494  * spaces, *some* other windows won't be clobbered by our colormap.
1495  */
1496  shift = free_pixels - num_lvls;
1497 
1498  for (j = 0, i = shift; j < num_lvls; i++, j++)
1499  img->pixel_table[j] = pixels[i];
1500 
1501  for (i = 0; i < shift; i++)
1502  color_defs[i].pixel = pixels[i];
1503 
1504  XQueryColors( dpy, DefaultColormap(dpy, screen), color_defs, shift );
1505 
1506  /*
1507  * Set up the color map entries.
1508  */
1509 
1510  color = &color_defs[shift];
1511 
1512  if (img->mono_color)
1513  for ( i = 0; i < num_lvls; i++ ) {
1514  color->pixel = img->pixel_table[i];
1515  color->red = img->in_cmap[RLE_RED][i] << 8;
1516  color->green = img->in_cmap[RLE_GREEN][i] << 8;
1517  color->blue = img->in_cmap[RLE_BLUE][i] << 8;
1518  color->flags = DoRed | DoGreen | DoBlue;
1519  color++;
1520  }
1521  else
1522  for ( i = 0; i < num_lvls; i++ ) {
1523  color->pixel = img->pixel_table[i];
1524  color->red = map[i] << 8;
1525  color->green = map[i] << 8;
1526  color->blue = map[i] << 8;
1527  color->flags = DoRed | DoGreen | DoBlue;
1528  color++;
1529  }
1530 
1531  XStoreColors (dpy, img->colormap, color_defs, free_pixels);
1532 
1533  free (map);
1534  free (color_defs);
1535  free (pixels);
1536  return (True);
1537 }
1538 
1539 static
1540 Boolean
1541 init_mono_ro ( img, try_ro )
1542 image_information *img;
1543 int try_ro;
1544 {
1545  register int num_lvls;
1546 #ifdef XLIBINT_H_NOT_AVAILABLE
1547  XColor color_def;
1548 #else
1549  register XColor *color_defs = NULL;
1550  register Status *status = NULL;
1551 #endif
1552  register int * map = NULL;
1553  register int i;
1554 #ifndef XLIBINT_H_NOT_AVAILABLE
1555  register int j;
1556 #endif
1557  int first = True;
1558 
1559  DPRINTF(stderr, "In init_mono_ro");
1560  if ( try_ro ) {
1561  DPRINTF(stderr, " trying read/only\n");
1562  } else {
1563  DPRINTF(stderr, "\n");
1564  }
1565 
1566  if ( img->mono_color )
1567  img->lvls = img->cmlen;
1568 
1569  for (num_lvls = img->lvls; num_lvls >= 2;
1570  num_lvls = (num_lvls > 16) ? num_lvls / 2 : num_lvls - 1 ) {
1571 
1572  if ( try_ro && !first && specified_levels ) break;
1573  else if ( !first && img->mono_color ) break;
1574  else first = False;
1575 
1576  if (img->pixel_table == NULL) {
1577  img->pixel_table = (Pixel *) malloc (num_lvls * sizeof (Pixel) );
1578  if (img->pixel_table == NULL) continue;
1579  }
1580 
1581  if (map == NULL) {
1582  map = (int *) malloc (num_lvls * sizeof (int) );
1583  if (map == NULL) continue;
1584  }
1585 
1586  if (num_lvls == 256 || img->mono_color)
1587  img->dither_img = False;
1588 
1589  get_dither_arrays( img );
1590  bwdithermap(num_lvls, display_gamma, map,
1591  img->divN, img->modN, img->dm16 );
1592 
1593  /* try to get a color map entry for each color. */
1594 
1595 #ifdef XLIBINT_H_NOT_AVAILABLE
1596  for ( i = 0; i < num_lvls; i++ ) {
1597  if ( img->mono_color ) {
1598  color_def.red = img->in_cmap[RLE_RED][i] << 8;
1599  color_def.green = img->in_cmap[RLE_GREEN][i] << 8;
1600  color_def.blue = img->in_cmap[RLE_BLUE][i] << 8;
1601  } else {
1602  color_def.red = map[i] << 8;
1603  color_def.green = map[i] << 8;
1604  color_def.blue = map[i] << 8;
1605  }
1606 
1607  if ( XAllocColor (dpy, img->colormap, &color_def ) == 0 ){
1608  break;
1609  }
1610  img->pixel_table[i] = color_def.pixel;
1611  }
1612 
1613  /* Check if the colors are available */
1614 
1615  if ( i < num_lvls) {
1616  /* Free the colors already obtained */
1617 
1618  free_unique_colors (img, img->pixel_table, i );
1619  continue; /* adjust level & repeat */
1620  }
1621 #else
1622  if (!color_defs)
1623  color_defs = (XColor *) malloc(num_lvls * sizeof (XColor));
1624  if (!status)
1625  status = (Status *) malloc(num_lvls * sizeof (Status));
1626  if ( !status || !color_defs ) continue;
1627 
1628  for ( i = 0; i < num_lvls; i++ ) {
1629  color_defs[i].pixel = 0;
1630  if ( img->mono_color ) {
1631  color_defs[i].red = img->in_cmap[RLE_RED][i] << 8;
1632  color_defs[i].green = img->in_cmap[RLE_GREEN][i] << 8;
1633  color_defs[i].blue = img->in_cmap[RLE_BLUE][i] << 8;
1634  } else {
1635  color_defs[i].red = map[i] << 8;
1636  color_defs[i].green = map[i] << 8;
1637  color_defs[i].blue = map[i] << 8;
1638  }
1639  }
1640 
1641  if (XAllocColors(dpy, img->colormap, color_defs, num_lvls, status)== 0)
1642  {
1643  for ( i = 0, j = 0; i < num_lvls; i++ )
1644  if (status[i])
1645  img->pixel_table[j++] = color_defs[i].pixel;
1647  continue;
1648  } else
1649  for ( i = 0; i < num_lvls; i++ )
1650  img->pixel_table[i] = color_defs[i].pixel;
1651 
1652 #endif
1653  img->lvls = num_lvls;
1654  img->lvls_squared = num_lvls * num_lvls;
1655 
1656  for (log2_levels = 1, i = 2; i < img->lvls; i <<= 1, log2_levels++);
1657  /* do nothing */
1658 
1659  free (map);
1660 #ifndef XLIBINT_H_NOT_AVAILABLE
1661  if (status) free (status);
1662  if (color_defs) free (color_defs);
1663 #endif
1664  return (True);
1665 
1666  }
1667  if (img->pixel_table)
1668  free (img->pixel_table);
1669  img->pixel_table = NULL;
1670 
1671  if (map) free (map);
1672 #ifndef XLIBINT_H_NOT_AVAILABLE
1673  if (status) free (status);
1674  if (color_defs) free (color_defs);
1675 #endif
1676  return (False);
1677 }
1678 
1680 image_information *img;
1681 {
1682  int ncells = img->mono_img ? img->lvls : img->lvls*img->lvls*img->lvls;
1683  if ( img->rw_cmap && !img->binary_img )
1684  XFreeColors(dpy, img->colormap, img->pixel_table, ncells, 0);
1685 }
1686 
1687 static CONST_DECL char *visual_class_to_string(visual_type)
1688  int visual_type;
1689 {
1690  CONST_DECL char *type_string;
1691  switch (visual_type) {
1692  case DirectColor: type_string = "DirectColor"; break;
1693  case PseudoColor: type_string = "PseudoColor"; break;
1694  case TrueColor: type_string = "TrueColor"; break;
1695  case StaticColor: type_string = "StaticColor"; break;
1696  case GrayScale: type_string = "GrayScale"; break;
1697  case StaticGray: type_string = "StaticGray"; break;
1698  default: type_string = "any/unknown"; break;
1699  }
1700  return type_string;
1701 }
1702 
1703 #define BINARY_TABLE_INDEX 0
1704 #define MONOCHROME_TABLE_INDEX 1
1705 #define COLOR_TABLE_INDEX 2
1706 
1707 /* Here we ALWAYS want to take a PseudoColor over the next best visual... */
1708 /* in Monochrome, we can do just as much with a pseudo color visual, and */
1709 /* we may be able to preserve some of the default colors from other windows*/
1710 /* In color mode, some eight bit displays offer a Direct and TrueColor */
1711 /* visual.. This is quite confusing, Have you ever seen a 24bit display */
1712 /* offer a 24-bit PseudoColor visual? They offer 8 bit PC visuals usually */
1713 
1714 static int desired_class_table [][6] = {
1715 { PseudoColor, StaticGray, GrayScale, DirectColor, TrueColor, StaticColor},
1716 { PseudoColor, GrayScale, StaticGray, DirectColor, TrueColor, StaticColor},
1717 { PseudoColor, DirectColor, TrueColor, StaticColor, GrayScale, StaticGray}
1718 };
1719 
1720 void
1722 register image_information *img;
1723 {
1724  static int num_visuals = 0;
1725  static XVisualInfo *visual_info = NULL;
1726  register XVisualInfo *vi, *found_vi;
1727  XVisualInfo *XGetVisualInfo ();
1728  VisualID def_visual_id;
1729  int def_visual_index = 0;
1730  int def_scrn = DefaultScreen(dpy);
1731  int desired_class;
1732  int desired_depth;
1733  int deepest_visual;
1734  int depth_delta;
1735  register int i;
1736 
1737  DPRINTF(stderr, "In find_appropriate_visual(%d)\n", img->img_channels);
1738 
1739  if (visual_info == NULL) {
1740  visual_info = XGetVisualInfo (dpy, VisualNoMask, NULL, &num_visuals);
1741  if (visual_info == NULL || num_visuals == 0) {
1742  fprintf (stderr, "XGetVisualInfo failed\n");
1743  exit (1);
1744  }
1745  }
1746 
1747  desired_depth = 1;
1748 
1749  for (i = 2; i < img->lvls; i <<= 1) {
1750  desired_depth++;
1751  }
1752 
1753  if ( img->mono_img && img->lvls == 2 )
1754  img->binary_img = True;
1755 
1756  if ( img->binary_img ) {
1757  desired_class = BINARY_TABLE_INDEX;
1758  desired_depth = 1;
1759  depth_delta = 1;
1760  }
1761  else if ( img->mono_img && !img->mono_color ) {
1762  desired_class = MONOCHROME_TABLE_INDEX;
1763  depth_delta = 1;
1764  }
1765  else {
1766  desired_class = COLOR_TABLE_INDEX;
1767  desired_depth *= 3; /* needed if separate colors */
1768  depth_delta = 3;
1769  }
1770 
1771  VPRINTF (stderr, "Searching for %s visual with desired depth >= %d\n",
1772  visual_class_to_string(img->visual_class), desired_depth);
1773 
1774  /*
1775  * find visual such that:
1776  *
1777  * 1. depth is as large as possible (up to true desired depth)
1778  * 2. visual depth is the smallest of those supported >= depth
1779  * 3. visual class is the `most desired' for the image type
1780  * Meaning! that if it is the DefaultVisual it IS the
1781  * most desired. We can't choose one visual class over
1782  * another for all displays! If the depth of the DefaultVisual
1783  * is large enough for the image, or as large as all others, we
1784  * use it! This minimizes screw ups on our part.
1785  * 4. If specified_screen is >=0, visual must be on that screen.
1786  * 5. Prefer visuals on default screen.
1787  */
1788 
1789  found_vi = NULL;
1790 
1791  def_visual_id = DefaultVisual(dpy, def_scrn)->visualid ;
1792  deepest_visual = 0;
1793 
1794  for (i = 0; i < num_visuals; i++)
1795  {
1796  if ( deepest_visual < visual_info[i].depth )
1797  deepest_visual = visual_info[i].depth;
1798 
1799  if ( def_visual_id == visual_info[i].visualid &&
1800  def_scrn == visual_info[i].screen )
1801  def_visual_index = i;
1802  }
1803 
1804  /* Take the Default Visual if it's cool enough... */
1805  if ( visual_info[def_visual_index].depth >= desired_depth ||
1806  visual_info[def_visual_index].depth == deepest_visual )
1807  found_vi = &visual_info[def_visual_index];
1808 
1809  /* if we were told to look for a specific type first, do it */
1810  if ( img->visual_class >= 0 ) {
1811  int depth;
1812  for (depth = desired_depth; depth >= 1; depth -= depth_delta) {
1813  for (vi = visual_info; vi < visual_info + num_visuals; vi++)
1814  if (vi->class == img->visual_class && vi->depth >= depth &&
1815  (specified_screen < 0 || vi->screen == specified_screen) )
1816  {
1817  found_vi = vi;
1818 
1819  if (found_vi->depth == depth) break;
1820  }
1821  if (found_vi != NULL && found_vi->class == img->visual_class)
1822  break;
1823  }
1824  }
1825 
1826  /* Werent told to get any type of Visual, or didn't find one, wingit */
1827  if ( img->visual_class < 0 ) {
1828  int depth;
1829  for (depth = desired_depth; depth >= 0; depth -= depth_delta) {
1830  if (found_vi != NULL)
1831  break;
1832  for (i = 0; i < 6; i++) {
1833  int vt;
1834 
1835  /* search for class and depth */
1836  vt = desired_class_table[desired_class][i];
1837 
1838  for (vi = visual_info; vi < visual_info+num_visuals; vi++)
1839  if (vi->class == vt && vi->depth >= depth) {
1840  if (found_vi==NULL || found_vi->depth > vi->depth)
1841  found_vi = vi;
1842  if (vi->depth == depth)
1843  break;
1844  }
1845  }
1846  }
1847  }
1848 
1849  if (found_vi == NULL) {
1850  fprintf (stderr, "%s: Could not find appropriate visual type - %s\n",
1851  progname, visual_class_to_string(img->visual_class));
1852  exit (1);
1853  }
1854 
1855  /* Now, if screen not explicitly specified, try to find this visual on
1856  * the default screen.
1857  */
1858  if ( specified_screen < 0 )
1859  for (vi = visual_info; vi < visual_info+num_visuals; vi++)
1860  if (vi->class == found_vi->class &&
1861  vi->depth == found_vi->depth &&
1862  vi->screen == def_scrn )
1863  {
1864  found_vi = vi;
1865  break;
1866  }
1867 
1868  /* set program the_hdr */
1869  screen = found_vi->screen;
1870  root_window = RootWindow (dpy, screen);
1871 
1872  /* set img variables */
1873  img->dpy_depth = found_vi->depth;
1874  img->dpy_visual = found_vi->visual;
1875  img->visual_class = found_vi->class;
1876 
1877  /* We want to give the DefaultColormap a shot first */
1878  if ( found_vi->visualid == def_visual_id )
1879  img->colormap = DefaultColormap( dpy, screen );
1880  else
1881  get_x_colormap( img );
1882 
1883  if ( img->dpy_depth == 1 || img->binary_img ) {
1884  img->binary_img = True;
1885  img->mono_img = True;
1886  img->color_dpy = False;
1887  img->dpy_channels = 1;
1888  img->sep_colors = False;
1889  img->rw_cmap = False;
1890 
1891  img->lvls = 2;
1892  img->lvls_squared = 4;
1893  log2_levels = 1;
1894  }
1895  else {
1896  int class = img->visual_class;
1897 
1898  if ( class == GrayScale || class == StaticGray ) {
1899  img->mono_img = True;
1900  img->color_dpy = False;
1901  img->dpy_channels = 1;
1902  depth_delta = 1;
1903  }
1904 
1905  img->rw_cmap = class == PseudoColor || class == GrayScale ||
1906  class == DirectColor;
1907 
1908  if ( class == DirectColor || class == TrueColor ||
1909  (class == StaticColor &&
1910  (!img->dither_img || img->dpy_depth > 8) &&
1911  (found_vi->visual->red_mask != 0 ||
1912  found_vi->visual->blue_mask != 0 ||
1913  found_vi->visual->green_mask != 0))) {
1914  /* StaticColor could be like a PseudoColor Display with a dither
1915  * cube, or like a Direct or TrueColor display with shifts and
1916  * masks... The dither cube would probubly look better on an 8
1917  * bit SC display. For 8 bit or less SC visuals PseudoColor
1918  * (dither cube, dithering or no) will be used unless you specify
1919  * -a(nodither) on the command line and there are masks provided
1920  * in the visual structure.
1921  */
1922 
1923  img->sep_colors = True;
1924 
1925  i = 1 << (img->dpy_depth / depth_delta);
1926 
1927  if ( img->lvls > i) {
1928  img->lvls = i;
1929  img->lvls_squared = i * i;
1930  }
1931  } else {
1932  img->sep_colors = False;
1933 
1934  /* Image is monochrome??? */
1935  if (depth_delta == 1) {
1936  i = found_vi->colormap_size;
1937  }
1938  else { /* color */
1939  for (i = 1; i * i * i < found_vi->colormap_size; i++) {}
1940  i--;
1941  }
1942 
1943  if (img->lvls > i) {
1944  img->lvls = i;
1945  img->lvls_squared = i * i;
1946  }
1947  }
1948 
1949  for (log2_levels = 1, i = 2; i < img->lvls; i <<= 1, log2_levels++);
1950  /* do nothing */
1951  }
1952 
1953  VPRINTF(stderr, "Visual type %s, depth %d, screen %d\n",
1954  visual_class_to_string(img->visual_class), img->dpy_depth, screen);
1955 
1956  VPRINTF(stderr, "levels: %d, log(2) levels: %d\n", img->lvls, log2_levels);
1957 }
1958 
1959 static XFontStruct *pixel_font_info = NULL;
1960 
1961 void
1963 image_information *img;
1964 int use_top;
1965 {
1966  Window hukairz;
1967  int x, y;
1968  unsigned int w, h, hunoz, huwanz, font_height;
1969 
1970  XGetGeometry (dpy, img->window, &hukairz, &x, &y, &w, &h, &hunoz, &huwanz);
1971 
1972  if (!pixel_font_info) {
1973  pixel_font_info = XLoadQueryFont (dpy, "fixed");
1974  if (!pixel_font_info) {
1975  fprintf (stderr, "%s: unable to load font '%s'\n",
1976  progname, "fixed");
1977  exit (1);
1978  }
1979  }
1980 
1981  font_height = pixel_font_info->ascent + pixel_font_info->descent + 4;
1982  y = (use_top ? 0 : (h - font_height));
1983 
1984  if ( img->pix_info_window == NULL ) {
1985  XSetFont (dpy, img->gc, pixel_font_info->fid );
1986  img->pix_info_window = XCreateSimpleWindow(
1987  dpy, img->window, 0, y, w, font_height, 0, None,
1988  img->black_pixel );
1989  }
1990  else
1991  XMoveResizeWindow ( dpy, img->pix_info_window, 0, y, w, font_height );
1992 
1993  XMapWindow ( dpy, img->pix_info_window );
1994 }
1995 
1996 void
1998 image_information *img;
1999 int x, y;
2000 {
2001  char str[256];
2002  unsigned char *r, *g, *b;
2003 
2004  r = SAVED_RLE_ROW( img, y ) + x;
2005 
2006  switch ( img->dpy_channels ) {
2007  case 1:
2008  if ( img->mono_color && img->in_cmap ) {
2009  unsigned char R = img->in_cmap[0][*r];
2010  unsigned char G = img->in_cmap[1][*r];
2011  unsigned char B = img->in_cmap[2][*r];
2012  if ( img->mag_fact > 1 )
2013  sprintf (str, "(%4d,%4d): %3d -> 0x%02x%02x%02x ( %3d, %3d, %3d ) (Mag %2d)",
2014  x + img->x, img->h - y - 1 + img->y,
2015  *r, R, G, B, R, G, B, img->mag_fact);
2016  else
2017  sprintf (str, "(%4d,%4d): %3d -> 0x%02x%02x%02x ( %3d, %3d, %3d )",
2018  x + img->x, img->h - y - 1 + img->y,
2019  *r, R, G, B, R, G, B);
2020  } else {
2021  if ( img->mag_fact > 1 )
2022  sprintf (str, "(%4d,%4d): ( %3d ) (Mag %2d)",
2023  x + img->x, img->h - y - 1 + img->y,
2024  *r, img->mag_fact);
2025  else
2026  sprintf (str, "(%4d,%4d): ( %3d )",
2027  x + img->x, img->h - y - 1 + img->y, *r);
2028  }
2029  break;
2030  case 2:
2031  g = r + img->w;
2032  if ( img->mag_fact > 1 )
2033  sprintf (str, "(%4d,%4d): ( %3d, %3d ) (Mag %2d)",
2034  x + img->x, img->h - y - 1 + img->y,
2035  *r, *g, img->mag_fact);
2036  else
2037  sprintf (str, "(%4d,%4d): ( %3d, %3d )",
2038  x + img->x, img->h - y - 1 + img->y,
2039  *r, *g);
2040  break;
2041  case 3:
2042  g = r + img->w;
2043  b = g + img->w;
2044  if ( img->mag_fact > 1 )
2045  sprintf (str,
2046  "(%4d,%4d): 0x%02x%02x%02x ( %3d, %3d, %3d ) (Mag %2d)",
2047  x + img->x, img->h - y - 1 + img->y,
2048  *r, *g, *b, *r, *g, *b, img->mag_fact);
2049  else
2050  sprintf (str, "(%4d,%4d): 0x%02x%02x%02x ( %3d, %3d, %3d )",
2051  x + img->x, img->h - y - 1 + img->y,
2052  *r, *g, *b, *r, *g, *b);
2053  break;
2054  }
2055 
2056  XClearWindow ( dpy, img->pix_info_window );
2057  XDrawString ( dpy, img->pix_info_window, img->gc,
2058  4, 2 + pixel_font_info->ascent, str, strlen (str) );
2059 }
2060 
2061 void
2063 image_information *img;
2064 int s;
2065 {
2066  char str[256];
2067 
2068  if ( s > 0 )
2069  sprintf( str, "%s%d Frames/Second", (s > 0) ? "": "1/", (s>0)?s:-s );
2070  else
2071  sprintf( str, "As fast as possible" );
2072 
2073  XClearWindow ( dpy, img->pix_info_window );
2074  XDrawString ( dpy, img->pix_info_window, img->gc,
2075  4, 2 + pixel_font_info->ascent, str, strlen (str) );
2076 }
2077 
2078 
2079 void
2081 image_information *img;
2082 {
2083  XUnmapWindow ( dpy, img->pix_info_window );
2084 }
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
void allocate_pixmap(image_information *img, Boolean reallocate)
Definition: x11_stuff.c:325
void MapPixWindow(image_information *img, int use_top)
Definition: x11_stuff.c:1962
void get_dither_arrays(register image_information *img)
Boolean rw_cmap
Definition: getx11.h:166
void free_X_pixmap(image_information *img, Pixmap pix)
Definition: x11_stuff.c:429
int stingy_flag
Definition: getx11.c:81
static image_information * wait_img
Definition: x11_stuff.c:61
Pixel green_mask
Definition: getx11.h:118
void make_square(double N, divN, modN, magic)
Definition: dither.c:192
Boolean pixmap_failed
Definition: getx11.h:134
int no_color_ref_counts
Definition: getx11.c:88
void UnmapPixWindow(image_information *img)
Definition: x11_stuff.c:2080
#define Max(x, y)
Definition: getx11.h:76
void check_pixmap_allocation(image_information *img)
Definition: x11_stuff.c:293
XShmSegmentInfo shm_img
Definition: getx11.h:183
#define WANT_READ_WRITE
Definition: x11_stuff.c:840
Display * dpy
Definition: getx10.c:94
Pixel red_mask
Definition: getx11.h:117
void get_cursors(Window window)
Definition: x11_stuff.c:84
void open_x_display(char *display_name)
Definition: x11_stuff.c:532
int specified_levels
Definition: getx11.c:82
static Cursor circle_cursor
Definition: x11_stuff.c:55
Boolean no_shared_space
Definition: getx11.c:86
#define WANT_READ_ONLY
Definition: x11_stuff.c:843
#define RLE_GREEN
Definition: rle.h:63
#define NOT_BINARY
Definition: x11_stuff.c:841
void calc_view_origin(image_information *img)
Definition: x11_stuff.c:575
const char * title
Definition: getx11.h:137
static int log2_levels
Definition: x11_stuff.c:823
XShmSegmentInfo shm_pix
Definition: getx11.h:184
#define RLE_BLUE
Definition: rle.h:64
#define IS_BINARY
Definition: x11_stuff.c:838
#define DESIRED_ICON_HEIGHT
char * progname
Definition: unslice.c:51
Pixel pixel_base
Definition: getx11.h:120
Visual * dpy_visual
Definition: getx11.h:132
Boolean mono_color
Definition: getx11.h:168
void init_color(register image_information *img)
void find_appropriate_visual(register image_information *img)
void get_x_colormap(image_information *img)
Definition: x11_stuff.c:519
Window icn_window
Definition: getx11.h:125
int screen
Definition: show3.c:29
#define RLE_RED
Definition: rle.h:62
#define IS_MONO
Definition: x11_stuff.c:839
static int specified_screen
Definition: x11_stuff.c:59
static Cursor watch_cursor
Definition: x11_stuff.c:57
Pixel * pixel_table
Definition: getx11.h:179
Window root_window
Definition: getx11.c:76
#define X_SHARED_MEMORY
Definition: rle_config.h:30
int shift_match_right(Pixel mask)
Definition: map_scan.c:2227
Boolean color_dpy
Definition: getx11.h:169
#define CONST_DECL
Definition: rle_config.h:42
void create_windows(register image_information *img, char *window_geometry)
Boolean binary_img
Definition: getx11.h:163
Boolean sep_colors
Definition: getx11.h:167
int shift_match_left(Pixel mask, int high_bit_index)
Definition: map_scan.c:2205
static int desired_class_table[][6]
Definition: x11_stuff.c:1714
#define SAVED_RLE_ROW(img, y)
Definition: getx11.h:192
#define DPRINTF
Definition: getx11.h:62
void destroy_X_image(image_information *img, XImage *image)
Definition: x11_stuff.c:238
#define VPRINTF
Definition: aliastorle.c:42
static Cursor left_ptr_cursor
Definition: x11_stuff.c:56
void set_circle_cursor(Window window)
Definition: x11_stuff.c:70
#define IMAGE_BORDERWIDTH
Definition: getx11.h:51
Pixmap icn_pixmap
Definition: getx11.h:127
XImage * image
Definition: getx11.h:129
void set_watch_cursor(Window window)
Definition: x11_stuff.c:63
void determine_icon_size(int image_width, int image_height, int *icon_width, int *icon_height, int *icon_factor)
Definition: x11_stuff.c:466
void free_unique_colors(image_information *img, Pixel *pixels, int npixels)
Definition: x11_stuff.c:1259
#define MONOCHROME_TABLE_INDEX
Definition: x11_stuff.c:1704
Boolean mono_img
Definition: getx11.h:164
#define BINARY_TABLE_INDEX
Definition: x11_stuff.c:1703
int XAllocColors(register Display *dpy, Colormap cmap, XColor *defs, int ndefs, int *statuses)
static XFontStruct * pixel_font_info
Definition: x11_stuff.c:1959
rle_pixel ** in_cmap
Definition: getx11.h:171
#define COLOR_TABLE_INDEX
Definition: x11_stuff.c:1705
#define SHIFT_MASK_PIXEL(r, g, b)
Definition: getx11.h:64
Pixel black_pixel
Definition: getx11.h:180
Window pix_info_window
Definition: getx11.h:126
void DrawSpeedWindow(image_information *img, int s)
Definition: x11_stuff.c:2062
#define DESIRED_ICON_WIDTH
void put_X_image(image_information *img, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height)
Definition: x11_stuff.c:446
#define NOT_MONO
Definition: x11_stuff.c:842
Colormap colormap
Definition: getx11.h:130
Boolean dither_img
Definition: getx11.h:165
int allocate_ximage(image_information *img, Boolean reallocate)
Definition: x11_stuff.c:301
double display_gamma
Definition: getx11.c:64
#define Min(x, y)
Definition: getx11.h:75
void DrawPixWindow(image_information *img, int x, int y)
Definition: x11_stuff.c:1997
void free_image_colors(image_information *img)
Definition: x11_stuff.c:1679
XImage * get_X_image(image_information *img, int width, int height, Boolean share)
Definition: x11_stuff.c:135
array16 * dm16
Definition: getx11.h:177
Pixel white_pixel
Definition: getx11.h:180
Boolean do_sharing
Definition: getx11.c:84
void bwdithermap(int levels, double gamma, bwmap, divN, modN, magic)
Definition: dither.c:142
unsigned long Pixel
Definition: getx11.h:54
void set_left_ptr_cursor(Window window)
Definition: x11_stuff.c:77