Debian Codegraph @

contrib/xwintoppm/xwintoppm.c

raw ◀ ▶
1 Debian patch touch this file
1 /*
2 * Copyright (C) 1997 and 1998 WIDE Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the project nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 /* $XConsortium: xwd.c /main/64 1996/01/14 16:53:13 kaleb $ */
30 /* $XFree86: xc/programs/xwd/xwd.c,v 3.2 1996/07/08 10:37:37 dawes Exp $ */
31
32 /*
33
34 Copyright (c) 1987 X Consortium
35
36 Permission is hereby granted, free of charge, to any person obtaining a copy
37 of this software and associated documentation files (the "Software"), to deal
38 in the Software without restriction, including without limitation the rights
39 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40 copies of the Software, and to permit persons to whom the Software is
41 furnished to do so, subject to the following conditions:
42
43 The above copyright notice and this permission notice shall be included in
44 all copies or substantial portions of the Software.
45
46 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
50 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
51 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52
53 Except as contained in this notice, the name of the X Consortium shall not be
54 used in advertising or otherwise to promote the sale, use or other dealings
55 in this Software without prior written authorization from the X Consortium.
56
57 */
58
59 /*
60 * xwd.c MIT Project Athena, X Window system window raster image dumper.
61 *
62 * This program will dump a raster image of the contents of a window into a
63 * file for output on graphics printers or for other uses.
64 *
65 * Author: Tony Della Fera, DEC
66 * 17-Jun-85
67 *
68 * Modification history:
69 *
70 * 11/14/86 Bill Wyatt, Smithsonian Astrophysical Observatory
71 * - Removed Z format option, changing it to an XY option. Monochrome
72 * windows will always dump in XY format. Color windows will dump
73 * in Z format by default, but can be dumped in XY format with the
74 * -xy option.
75 *
76 * 11/18/86 Bill Wyatt
77 * - VERSION 6 is same as version 5 for monchrome. For colors, the
78 * appropriate number of Color structs are dumped after the header,
79 * which has the number of colors (=0 for monochrome) in place of the
80 * V5 padding at the end. Up to 16-bit displays are supported. I
81 * don't yet know how 24- to 32-bit displays will be handled under
82 * the Version 11 protocol.
83 *
84 * 6/15/87 David Krikorian, MIT Project Athena
85 * - VERSION 7 runs under the X Version 11 servers, while the previous
86 * versions of xwd were are for X Version 10. This version is based
87 * on xwd version 6, and should eventually have the same color
88 * abilities. (Xwd V7 has yet to be tested on a color machine, so
89 * all color-related code is commented out until color support
90 * becomes practical.)
91 */
92
93 /*%
94 *% This is the format for commenting out color-related code until
95 *% color can be supported.
96 %*/
97
98 #include <stdio.h>
99 #include <errno.h>
100 #include <X11/Xos.h>
101
102 #ifdef X_NOT_STDC_ENV
103 extern int errno;
104 char *calloc();
105 #else
106 #include <stdlib.h>
107 #endif
108
109 #include <X11/Xlib.h>
110 #include <X11/Xutil.h>
111
112 #include <X11/Xmu/WinUtil.h>
113 typedef unsigned long Pixel;
114 #include "X11/XWDFile.h"
115
116 #define FEEP_VOLUME 0
117
118 /* Include routines to do parsing */
119 #include "dsimple.h"
120 #include "list.h"
121 #include "wsutils.h"
122 #include "multiVis.h"
123
124 #ifdef XKB
125 #include <X11/extensions/XKBbells.h>
126 #endif
127
•128 void usage(void) __attribute__((__noreturn__));
129 static void Error(char *) __attribute__((__noreturn__));
130 static void Window_Dump(Window, FILE *);
131 int Image_Size(XImage *);
132 int Get_XColors(XWindowAttributes *, XColor **);
133
134 void outl(); /* aieee! */
135
136 /* Setable Options */
137
138 int format = ZPixmap;
139 Bool nobdrs = False;
140 Bool on_root = False;
141 Bool standard_out = True;
142 Bool debug = False;
143 Bool silent = False;
144 Bool use_installed = False;
145 long add_pixel_value = 0;
146
147 extern int (*_XErrorFunction)();
148 extern int _XDefaultError();
149
150 static long parse_long (s)
151 char *s;
152 {
153 char *fmt = "%lu";
154 long retval = 0L;
155 int thesign = 1;
156
157 if (s && s[0]) {
158 if (s[0] == '-') s++, thesign = -1;
159 if (s[0] == '0') s++, fmt = "%lo";
160 if (s[0] == 'x' || s[0] == 'X') s++, fmt = "%lx";
161 (void) sscanf (s, fmt, &retval);
162 }
163 return (thesign * retval);
164 }
165
•166 int
167 main(argc, argv)
168 int argc;
169 char **argv;
170 {
•171 register int i;
172 Window target_win;
173 FILE *out_file = stdout;
174 Bool frame_only = False;
175
176 INIT_NAME;
177
178 Setup_Display_And_Screen(&argc, argv);
179
180 /* Get window select on command line, if any */
181 target_win = Select_Window_Args(&argc, argv);
182
183 for (i = 1; i < argc; i++) {
184 if (!strcmp(argv[i], "-nobdrs")) {
185 nobdrs = True;
186 continue;
187 }
188 if (!strcmp(argv[i], "-debug")) {
189 debug = True;
190 continue;
191 }
192 if (!strcmp(argv[i], "-help"))
193 usage();
194 if (!strcmp(argv[i], "-out")) {
195 if (++i >= argc) usage();
196 if (!(out_file = fopen(argv[i], "wb")))
197 Error("Can't open output file as specified.");
198 standard_out = False;
199 continue;
200 }
201 if (!strcmp(argv[i], "-xy")) {
202 format = XYPixmap;
203 continue;
204 }
205 if (!strcmp(argv[i], "-screen")) {
206 on_root = True;
207 continue;
208 }
209 if (!strcmp(argv[i], "-icmap")) {
210 use_installed = True;
211 continue;
212 }
213 if (!strcmp(argv[i], "-add")) {
214 if (++i >= argc) usage();
215 add_pixel_value = parse_long (argv[i]);
216 continue;
217 }
218 if (!strcmp(argv[i], "-frame")) {
219 frame_only = True;
220 continue;
221 }
222 if (!strcmp(argv[i], "-silent")) {
223 silent = True;
224 continue;
225 }
226 usage();
227 }
228 #ifdef WIN32
229 if (standard_out)
230 _setmode(fileno(out_file), _O_BINARY);
231 #endif
232
233 /*
234 * Let the user select the target window.
235 */
236 if (!target_win) {
237 #if 0
238 target_win = Select_Window(dpy);
239 if (target_win != None && !frame_only) {
240 Window root;
241 int dummyi;
242 unsigned int dummy;
243
244 if (XGetGeometry (dpy, target_win, &root, &dummyi, &dummyi,
245 &dummy, &dummy, &dummy, &dummy) &&
246 target_win != root)
247 target_win = XmuClientWindow (dpy, target_win);
248 }
249 #else
250 fprintf(stderr, "window must be specified\n");
251 exit(1);
252 #endif
253 }
254
255
256 /*
257 * Dump it!
258 */
259 Window_Dump(target_win, out_file);
260
261 XCloseDisplay(dpy);
262 if (fclose(out_file)) {
263 perror("xwintoppm");
264 exit(1);
265 }
266 exit(0);
267 }
268
269 static int
270 Get24bitDirectColors(colors)
271 XColor **colors ;
272 {
273 int i , ncolors = 256 ;
274 XColor *tcol ;
275
276 *colors = tcol = (XColor *)malloc(sizeof(XColor) * ncolors) ;
277
278 for(i=0 ; i < ncolors ; i++)
279 {
280 tcol[i].pixel = i << 16 | i << 8 | i ;
281 tcol[i].red = tcol[i].green = tcol[i].blue = i << 8 | i ;
282 }
283
284 return ncolors ;
285 }
286
287
288 /*
289 * Window_Dump: dump a window to a file which must already be open for
290 * writting.
291 */
292
•293 void
294 Window_Dump(window, out)
295 Window window;
296 FILE *out;
297 {
298 unsigned long swaptest = 1;
299 XColor *colors;
300 unsigned buffer_size;
301 int win_name_size;
302 int header_size;
303 int ncolors, i;
304 char *win_name;
305 Bool got_win_name;
306 XWindowAttributes win_info;
307 XImage *image;
308 int absx, absy, x, y;
309 unsigned width, height;
310 int dwidth, dheight;
311 int bw;
312 Window dummywin;
313 XWDFileHeader header;
314 XWDColor xwdcolor;
315
316 int transparentOverlays , multiVis;
317 int numVisuals;
318 XVisualInfo *pVisuals;
319 int numOverlayVisuals;
320 OverlayInfo *pOverlayVisuals;
321 int numImageVisuals;
322 XVisualInfo **pImageVisuals;
323 list_ptr vis_regions; /* list of regions to read from */
324 list_ptr vis_image_regions ;
325 Colormap cmap ;
326 Visual vis_h,*vis ;
327 int allImage = 0 ;
328
329 /*
330 * Inform the user not to alter the screen.
331 */
332 if (!silent) {
333 #ifdef XKB
334 XkbStdBell(dpy,None,50,XkbBI_Wait);
335 #else
336 XBell(dpy,FEEP_VOLUME);
337 #endif
338 XFlush(dpy);
339 }
340
341 /*
342 * Get the parameters of the window being dumped.
343 */
344 if (debug) outl("xwintoppm: Getting target window information.\n");
345 if(!XGetWindowAttributes(dpy, window, &win_info))
346 Fatal_Error("Can't get target window attributes.");
347
348 /* handle any frame window */
349 if (!XTranslateCoordinates (dpy, window, RootWindow (dpy, screen), 0, 0,
350 &absx, &absy, &dummywin)) {
351 fprintf (stderr,
352 "%s: unable to translate window coordinates (%d,%d)\n",
353 program_name, absx, absy);
354 exit (1);
355 }
356 win_info.x = absx;
357 win_info.y = absy;
358 width = win_info.width;
359 height = win_info.height;
360 bw = 0;
361
362 if (!nobdrs) {
363 absx -= win_info.border_width;
364 absy -= win_info.border_width;
365 bw = win_info.border_width;
366 width += (2 * bw);
367 height += (2 * bw);
368 }
369 dwidth = DisplayWidth (dpy, screen);
370 dheight = DisplayHeight (dpy, screen);
371
372
373 /* clip to window */
374 if (absx < 0) width += absx, absx = 0;
375 if (absy < 0) height += absy, absy = 0;
376 if (absx + width > dwidth) width = dwidth - absx;
377 if (absy + height > dheight) height = dheight - absy;
378
379 XFetchName(dpy, window, &win_name);
380 if (!win_name || !win_name[0]) {
381 win_name = "xwdump";
382 got_win_name = False;
383 } else {
384 got_win_name = True;
385 }
386
387 /* sizeof(char) is included for the null string terminator. */
388 win_name_size = strlen(win_name) + sizeof(char);
389
390 /*
391 * Snarf the pixmap with XGetImage.
392 */
393
394 x = absx - win_info.x;
395 y = absy - win_info.y;
396
397 multiVis = GetMultiVisualRegions(dpy,RootWindow(dpy, screen),
398 absx, absy,
399 width, height,&transparentOverlays,&numVisuals, &pVisuals,
400 &numOverlayVisuals,&pOverlayVisuals,&numImageVisuals,
401 &pImageVisuals,&vis_regions,&vis_image_regions,&allImage) ;
402 if (on_root || multiVis)
403 {
404 if(!multiVis)
405 image = XGetImage (dpy, RootWindow(dpy, screen), absx, absy,
406 width, height, AllPlanes, format);
407 else
408 image = ReadAreaToImage(dpy, RootWindow(dpy, screen), absx, absy,
409 width, height,
410 numVisuals,pVisuals,numOverlayVisuals,pOverlayVisuals,
411 numImageVisuals, pImageVisuals,vis_regions,
412 vis_image_regions,format,allImage);
413 }
414 else
415 image = XGetImage (dpy, window, x, y, width, height, AllPlanes, format);
416 if (!image) {
417 fprintf (stderr, "%s: unable to get image at %dx%d+%d+%d\n",
418 program_name, width, height, x, y);
419 exit (1);
420 }
421
422 if (add_pixel_value != 0) XAddPixel (image, add_pixel_value);
423
424 /*
425 * Determine the pixmap size.
426 */
427 buffer_size = Image_Size(image);
428
429 if (debug) outl("xwintoppm: Getting Colors.\n");
430
431 if( !multiVis)
432 {
433 ncolors = Get_XColors(&win_info, &colors);
434 vis = win_info.visual ;
435 }
436 else
437 {
438 ncolors = Get24bitDirectColors(&colors) ;
439 initFakeVisual(&vis_h) ;
440 vis = &vis_h ;
441 }
442 /*
443 * Inform the user that the image has been retrieved.
444 */
445 if (!silent) {
446 #ifdef XKB
447 XkbStdBell(dpy,window,FEEP_VOLUME,XkbBI_Proceed);
448 XkbStdBell(dpy,window,FEEP_VOLUME,XkbBI_RepeatingLastBell);
449 #else
450 XBell(dpy, FEEP_VOLUME);
451 XBell(dpy, FEEP_VOLUME);
452 #endif
453 XFlush(dpy);
454 }
455
456 /*
457 * Calculate header size.
458 */
459 if (debug) outl("xwintoppm: Calculating header size.\n");
460 header_size = SIZEOF(XWDheader) + win_name_size;
461
462 #if 0
463 /*
464 * Write out header information.
465 */
466 if (debug) outl("xwintoppm: Constructing and dumping file header.\n");
467 header.header_size = (CARD32) header_size;
468 header.file_version = (CARD32) XWD_FILE_VERSION;
469 header.pixmap_format = (CARD32) format;
470 header.pixmap_depth = (CARD32) image->depth;
471 header.pixmap_width = (CARD32) image->width;
472 header.pixmap_height = (CARD32) image->height;
473 header.xoffset = (CARD32) image->xoffset;
474 header.byte_order = (CARD32) image->byte_order;
475 header.bitmap_unit = (CARD32) image->bitmap_unit;
476 header.bitmap_bit_order = (CARD32) image->bitmap_bit_order;
477 header.bitmap_pad = (CARD32) image->bitmap_pad;
478 header.bits_per_pixel = (CARD32) image->bits_per_pixel;
479 header.bytes_per_line = (CARD32) image->bytes_per_line;
480 /****
481 header.visual_class = (CARD32) win_info.visual->class;
482 header.red_mask = (CARD32) win_info.visual->red_mask;
483 header.green_mask = (CARD32) win_info.visual->green_mask;
484 header.blue_mask = (CARD32) win_info.visual->blue_mask;
485 header.bits_per_rgb = (CARD32) win_info.visual->bits_per_rgb;
486 header.colormap_entries = (CARD32) win_info.visual->map_entries;
487 *****/
488 header.visual_class = (CARD32) vis->class;
489 header.red_mask = (CARD32) vis->red_mask;
490 header.green_mask = (CARD32) vis->green_mask;
491 header.blue_mask = (CARD32) vis->blue_mask;
492 header.bits_per_rgb = (CARD32) vis->bits_per_rgb;
493 header.colormap_entries = (CARD32) vis->map_entries;
494
495 header.ncolors = ncolors;
496 header.window_width = (CARD32) win_info.width;
497 header.window_height = (CARD32) win_info.height;
498 header.window_x = absx;
499 header.window_y = absy;
500 header.window_bdrwidth = (CARD32) win_info.border_width;
501
502 if (*(char *) &swaptest) {
503 _swaplong((char *) &header, sizeof(header));
504 for (i = 0; i < ncolors; i++) {
505 _swaplong((char *) &colors[i].pixel, sizeof(long));
506 _swapshort((char *) &colors[i].red, 3 * sizeof(short));
507 }
508 }
509
510 if (fwrite((char *)&header, SIZEOF(XWDheader), 1, out) != 1 ||
511 fwrite(win_name, win_name_size, 1, out) != 1) {
512 perror("xwintoppm");
513 exit(1);
514 }
515 #else
516 fprintf(out, "P6\n%d %d %d\n", win_info.width, win_info.height, 255);
517 #endif
518
519 #if 0
520 /*
521 * Write out the color maps, if any
522 */
523
524 if (debug) outl("xwintoppm: Dumping %d colors.\n", ncolors);
525 for (i = 0; i < ncolors; i++) {
526 xwdcolor.pixel = colors[i].pixel;
527 xwdcolor.red = colors[i].red;
528 xwdcolor.green = colors[i].green;
529 xwdcolor.blue = colors[i].blue;
530 xwdcolor.flags = colors[i].flags;
531 if (fwrite((char *) &xwdcolor, SIZEOF(XWDColor), 1, out) != 1) {
532 perror("xwd");
533 exit(1);
534 }
535 }
536 #endif
537
538 /*
539 * Write out the buffer.
540 */
541 if (debug) outl("xwintoppm: Dumping pixmap. bufsize=%d\n",buffer_size);
542
543 #if 0
544 /*
545 * This copying of the bit stream (data) to a file is to be replaced
546 * by an Xlib call which hasn't been written yet. It is not clear
547 * what other functions of xwd will be taken over by this (as yet)
548 * non-existant X function.
549 */
550 if (fwrite(image->data, (int) buffer_size, 1, out) != 1) {
551 perror("xwd");
552 exit(1);
553 }
554 #else
555 {
556 int x, y;
557 int i;
558 unsigned long pixel;
559 unsigned char buf[3];
560 unsigned long mask[3];
561 unsigned int shift0[3], shift8[3];
562
563 mask[0] = image->red_mask;
564 mask[1] = image->green_mask;
565 mask[2] = image->blue_mask;
566 if (!mask[0] || !mask[1] || !mask[2]) {
567 fprintf(stderr, "unsupported screen depth; bailing out\n");
568 exit(1);
569 }
570 for (i = 0; i < 3; i++) {
571 shift0[i] = 0;
572 while (!(mask[i] & (1 << shift0[i])))
573 shift0[i]++;
574 shift8[i] = shift0[i];
575 while (mask[i] & (1 << shift8[i]))
576 shift8[i]++;
577 shift8[i] = 8 - (shift8[i] - shift0[i]);
578 }
579 for (y = 0; y < win_info.height; y++) {
580 for (x = 0; x < win_info.width; x++) {
581 pixel = (*image->f.get_pixel)(image, x, y);
582 #if 0
583 if (ncolors && pixel < ncolors) {
584 buf[0] = colors[pixel].red;
585 buf[1] = colors[pixel].green;
586 buf[2] = colors[pixel].blue;
587 } else
588 #endif
589 {
590 buf[0] = (pixel & mask[0]) >> shift0[0] << shift8[0];
591 buf[1] = (pixel & mask[1]) >> shift0[1] << shift8[1];
592 buf[2] = (pixel & mask[2]) >> shift0[2] << shift8[2];
593 }
594 fwrite(buf, 3, 1, out);
595 }
596 }
597 }
598 #endif
599
600 /*
601 * free the color buffer.
602 */
603
604 if(debug && ncolors > 0) outl("xwd: Freeing colors.\n");
605 if(ncolors > 0) free(colors);
606
607 /*
608 * Free window name string.
609 */
610 if (debug) outl("xwd: Freeing window name string.\n");
611 if (got_win_name) XFree(win_name);
612
613 /*
614 * Free image
615 */
616 XDestroyImage(image);
617 }
618
619 /*
620 * Report the syntax for calling xwd.
621 */
•622 void
623 usage()
624 {
625 fprintf (stderr,
626 "usage: %s [-display host:dpy] [-debug] [-help] %s [-nobdrs] [-out <file>]",
627 program_name, SELECT_USAGE);
628 fprintf (stderr, " [-xy] [-add value] [-frame]\n");
629 exit(1);
630 }
631
632
633 /*
634 * Error - Fatal xwd error.
635 */
636
•637 static void
638 Error(string)
639 char *string; /* Error description string. */
640 {
641 outl("\nxwd: Error => %s\n", string);
642 if (errno != 0) {
643 perror("xwd");
644 outl("\n");
645 }
646
647 exit(1);
648 }
649
650
651 /*
652 * Determine the pixmap size.
653 */
654
655 int Image_Size(image)
656 XImage *image;
657 {
658 if (image->format != ZPixmap)
659 return(image->bytes_per_line * image->height * image->depth);
660
661 return(image->bytes_per_line * image->height);
662 }
663
664 #define lowbit(x) ((x) & (~(x) + 1))
665
666 static int
667 ReadColors(vis,cmap,colors)
668 Visual *vis ;
669 Colormap cmap ;
670 XColor **colors ;
671 {
672 int i,ncolors ;
673
674 ncolors = vis->map_entries;
675
676 if (!(*colors = (XColor *) malloc (sizeof(XColor) * ncolors)))
677 Fatal_Error("Out of memory!");
678
679 if (vis->class == DirectColor ||
680 vis->class == TrueColor) {
681 Pixel red, green, blue, red1, green1, blue1;
682
683 red = green = blue = 0;
684 red1 = lowbit(vis->red_mask);
685 green1 = lowbit(vis->green_mask);
686 blue1 = lowbit(vis->blue_mask);
687 for (i=0; i<ncolors; i++) {
688 (*colors)[i].pixel = red|green|blue;
689 (*colors)[i].pad = 0;
690 red += red1;
691 if (red > vis->red_mask)
692 red = 0;
693 green += green1;
694 if (green > vis->green_mask)
695 green = 0;
696 blue += blue1;
697 if (blue > vis->blue_mask)
698 blue = 0;
699 }
700 } else {
701 for (i=0; i<ncolors; i++) {
702 (*colors)[i].pixel = i;
703 (*colors)[i].pad = 0;
704 }
705 }
706
707 XQueryColors(dpy, cmap, *colors, ncolors);
708
709 return(ncolors);
710 }
711
712 /*
713 * Get the XColors of all pixels in image - returns # of colors
714 */
715 int Get_XColors(win_info, colors)
716 XWindowAttributes *win_info;
717 XColor **colors;
718 {
719 int i, ncolors;
720 Colormap cmap = win_info->colormap;
721
722 if (use_installed)
723 /* assume the visual will be OK ... */
724 cmap = XListInstalledColormaps(dpy, win_info->root, &i)[0];
725 if (!cmap)
726 return(0);
727 ncolors = ReadColors(win_info->visual,cmap,colors) ;
728 return ncolors ;
729 }
730
•731 void
732 _swapshort (bp, n)
733 register char *bp;
734 register unsigned n;
735 {
736 register char c;
737 register char *ep = bp + n;
738
739 while (bp < ep) {
740 c = *bp;
741 *bp = *(bp + 1);
742 bp++;
743 *bp++ = c;
744 }
745 }
746
•747 void
748 _swaplong (bp, n)
749 register char *bp;
750 register unsigned n;
751 {
752 register char c;
753 register char *ep = bp + n;
754 register char *sp;
755
756 while (bp < ep) {
757 sp = bp + 3;
758 c = *sp;
759 *sp = *bp;
760 *bp++ = c;
761 sp = bp + 1;
762 c = *sp;
763 *sp = *bp;
764 *bp++ = c;
765 bp += 2;
766 }
767 }