home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume20 / pexdraw / part14 < prev    next >
Encoding:
Text File  |  1993-06-07  |  46.9 KB  |  1,443 lines

  1. Newsgroups: comp.sources.x
  2. From: jch@okimicro.oki.com (Jan Hardenbergh)
  3. Subject: v20i024:  pexdraw - A PEX drawing program, Part14/14
  4. Message-ID: <1993Jun8.150344.19549@sparky.imd.sterling.com>
  5. X-Md4-Signature: 9247c12f38adfbf44d5ee2db3cfdb38b
  6. Sender: chris@sparky.imd.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Tue, 8 Jun 1993 15:03:44 GMT
  9. Approved: chris@sparky.imd.sterling.com
  10.  
  11. Submitted-by: jch@okimicro.oki.com (Jan Hardenbergh)
  12. Posting-number: Volume 20, Issue 24
  13. Archive-name: pexdraw/part14
  14. Environment: X11R5, PEX
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  Imakefile XMU/CmapAlloc.c XMU/LookupCmap.c rgbc.c
  21. #   util/pexutcmaphp.h util/pexutcmapint.h
  22. # Wrapped by chris@sparky on Tue Jun  8 09:46:38 1993
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 14 (of 14)."'
  26. if test -f 'Imakefile' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'Imakefile'\"
  28. else
  29.   echo shar: Extracting \"'Imakefile'\" \(3809 characters\)
  30.   sed "s/^X//" >'Imakefile' <<'END_OF_FILE'
  31. X/*
  32. X *            Copyright (c) 1992,1993 by
  33. X *            Oki Electric Industry Co., Ltd.
  34. X *            All Rights Reserved
  35. X *
  36. X * Permission to use, copy, modify, and distribute this software and its
  37. X * documentation for any purpose and without fee is hereby granted,
  38. X * provided that the above copyright notice appear in all copies and that
  39. X * both that copyright notice and this permission notice appear in
  40. X * supporting documentation, and that the name of Oki not be
  41. X * used in advertising or publicity pertaining to distribution of the
  42. X * software without specific, written prior permission. Oki
  43. X * makes no representations about the suitability of this software for any
  44. X * purpose.  It is provided "as is" without express or implied warranty.
  45. X *************************************************************************
  46. X *
  47. X *                         P E X D R A W
  48. X *
  49. X *  A PEX drawing program. (or the baby CAD program)
  50. X *
  51. X *  %xmkmf  [-DNO_MOTIF if no Motif]
  52. X *
  53. X *  Jan "YON" Hardenbergh, May 1993
  54. X *
  55. X * Note: MSimpleUidTarget(pdraw) is a Motif rule. As are:
  56. X *    $(MRESOURCELIB) $(XMLIB)
  57. X *
  58. X * iffa you agotta no motif, add -DNO_MOTIF to your imake command, or as
  59. X * David Boyce said, just do xmkmf, ^c then copy the line and add...
  60. X *
  61. X * This will build the pexdraw application and five other sample's that can
  62. X * be "Executed" from pexdraw to create various structures. These create
  63. X * a PEX cube, PEXlib logo, an RGB cude, a teapot and a SOFAS example.
  64. X *
  65. X */
  66. X
  67. X#ifdef SVR4
  68. XUCBLIB = /usr/ucblib/libucb.a
  69. X#endif
  70. X
  71. X#ifndef NO_MOTIF
  72. X#ifdef MOTIF
  73. X#include "Motif.tmpl"
  74. X#include "Motif.rules"
  75. XMOTIF_LIBS =  $(MRESOURCELIB) $(XMLIB) $(UCBLIB)
  76. X#endif
  77. X#if (!defined(MOTIF) || defined(UseInstalled))
  78. X/* the version of Motif.tmpl I have is broken with respect to R5... */
  79. XMOTIF_LIBS = -lMrm -lXm  $(UCBLIB)
  80. X#endif
  81. X#else
  82. XMOTIF_LIBS = 
  83. X#endif
  84. X
  85. X#define IHaveSubdirs
  86. X
  87. X/* Hopefully, you have the patched Project.tmpl when you imake
  88. X * otherwise, use one of these.
  89. X * PEXLIB=$(TOP)/extensions/lib/PEXlib/libPEX5.a
  90. X * PEXLIB=-lPEX5
  91. X */
  92. XDBUTOBJS = util/pexutdb.o util/pexutdbint.o \
  93. X     util/pexutcmap.o  util/pexutcmapint.o util/pexutcmaphp.o
  94. X
  95. XLOCAL_LIBRARIES = $(MOTIF_LIBS) $(XTOOLLIB) $(XMULIB) $(PEXLIB) -lm $(XLIB) -lgen -lw
  96. XXOCAL_LIBRARIES = $(XMULIB) $(PEXLIB) -lm $(XLIB)
  97. X
  98. XSLOCAL_LIBS =  $(PEXLIB) -lm $(XLIB)
  99. X
  100. XDEFINES = 
  101. XINCLUDES = -I.  -I$(MTOOLKITSRC) -I$(TOP) -I$(TOP)/X11/extensions
  102. XCCOPTIONS = $(G)
  103. X
  104. X
  105. XPOBJS = pexdraw.o ui.o fb.o wks.o rdr.o init.o $(DBUTOBJS)
  106. XXOBJS = pexdraw.o ui_x.o fb.o wks.o rdr.o init.o $(DBUTOBJS)
  107. X
  108. XPLCOBJS = plcube.o
  109. XRGBC    = rgbc.o
  110. XSOFAS   = sofas.o
  111. XTEAPOT  = teapot.o
  112. XPLOGO   = plogo.o
  113. X    
  114. X#ifdef IHaveSubdirs
  115. X#define PassCDebugFlags 
  116. X SUBDIRS = util
  117. X
  118. XMakeSubdirs($(SUBDIRS))
  119. XDependSubdirs($(SUBDIRS))
  120. X#endif
  121. X
  122. Xall:: pexdraw plcube rgbc sofas teapot
  123. X
  124. X#ifndef NO_MOTIF
  125. XNormalProgramTarget(pexdraw,$(POBJS),,$(LOCAL_LIBRARIES),)
  126. X#endif
  127. X
  128. XNormalProgramTarget(pxd,$(XOBJS),,$(LOCAL_LIBRARIES),)
  129. X
  130. XNormalProgramTarget(plcube,$(PLCOBJS),,$(SLOCAL_LIBS),)
  131. X
  132. XNormalProgramTarget(rgbc,$(RGBC),,$(SLOCAL_LIBS),)
  133. X
  134. XNormalProgramTarget(sofas,$(SOFAS),,$(SLOCAL_LIBS),)
  135. X
  136. XNormalProgramTarget(teapot,$(TEAPOT),,$(SLOCAL_LIBS),)
  137. X
  138. XNormalProgramTarget(plogo,$(PLOGO),,$(SLOCAL_LIBS),)
  139. X
  140. X#ifndef NO_MOTIF
  141. X#ifdef MOTIF
  142. X   CLIENTSRC = /usr/X/motif/clients/
  143. XMSimpleUidTarget(pexdraw)
  144. X#else
  145. XXCOMM   you may need to try /usr/X/motif/clients/uil/uil
  146. Xpexdraw.uid: pexdraw.uil
  147. X     uil -o pexdraw.uid pexdraw.uil
  148. X#endif
  149. X#endif
  150. X
  151. Xtar:
  152. X     tar cvf new.tar README pexdraw.c pexdraw.h pexdraw.uil Imakefile \
  153. X     rdr.c wks.c fb.c ui.c ui_x.c init.c \
  154. X      util/pexutdbint.h  util/pexutdbint.c  util/pexutdb.h  util/pexutdb.c \
  155. X      util/Imakefile util/pexutcmap.c util/pexutcmap.h \
  156. X      util/pexutext.h util/pexutcmapint.c util/pexutcmapint.h \
  157. X      util/pexutcmaphp.c util/pexutcmaphp.h \
  158. X          rgbc.c plcube.c sofas.c teapot.c plogo.c XMU
  159. X
  160. XDependTarget()
  161. END_OF_FILE
  162.   if test 3809 -ne `wc -c <'Imakefile'`; then
  163.     echo shar: \"'Imakefile'\" unpacked with wrong size!
  164.   fi
  165.   # end of 'Imakefile'
  166. fi
  167. if test -f 'XMU/CmapAlloc.c' -a "${1}" != "-c" ; then 
  168.   echo shar: Will not clobber existing file \"'XMU/CmapAlloc.c'\"
  169. else
  170.   echo shar: Extracting \"'XMU/CmapAlloc.c'\" \(9405 characters\)
  171.   sed "s/^X//" >'XMU/CmapAlloc.c' <<'END_OF_FILE'
  172. X#ifdef SCCS
  173. Xstatic char sccsid[]="@(#)CmapAlloc.c    1.3 Oki 92/11/30";
  174. X#endif
  175. X/*
  176. X    This file is under sccs control at Oki in:
  177. X    /nfs/sole/root/sccs1.p/X11R5/mit/lib/Xmu/s.CmapAlloc.c
  178. X*/
  179. X/*
  180. X * $XConsortium: CmapAlloc.c,v 1.7 92/11/24 14:15:51 rws Exp $
  181. X * 
  182. X * Copyright 1989 by the Massachusetts Institute of Technology
  183. X *
  184. X * Permission to use, copy, modify, and distribute this software and its
  185. X * documentation for any purpose and without fee is hereby granted, provided 
  186. X * that the above copyright notice appear in all copies and that both that 
  187. X * copyright notice and this permission notice appear in supporting 
  188. X * documentation, and that the name of M.I.T. not be used in advertising
  189. X * or publicity pertaining to distribution of the software without specific, 
  190. X * written prior permission. M.I.T. makes no representations about the 
  191. X * suitability of this software for any purpose.  It is provided "as is"
  192. X * without express or implied warranty.
  193. X *
  194. X * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  195. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  196. X * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  197. X * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  198. X * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  199. X * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  200. X *
  201. X * Author:  Donna Converse, MIT X Consortium
  202. X */
  203. X
  204. X#include <X11/Xlib.h>
  205. X#include <X11/Xatom.h>
  206. X#include <X11/Xutil.h>
  207. X#include <stdio.h>
  208. X
  209. X#define lowbit(x) ((x) & (~(x) + 1))
  210. X
  211. Xstatic int default_allocation();
  212. Xstatic void best_allocation();
  213. Xstatic void gray_allocation();
  214. Xstatic int icbrt();
  215. Xstatic int icbrt_with_bits();
  216. Xstatic int icbrt_with_guess();
  217. X
  218. X/* To determine the best allocation of reds, greens, and blues in a 
  219. X * standard colormap, use XmuGetColormapAllocation.
  220. X *     vinfo        specifies visual information for a chosen visual
  221. X *    property    specifies one of the standard colormap property names
  222. X *     red_max        returns maximum red value 
  223. X *      green_max    returns maximum green value
  224. X *     blue_max    returns maximum blue value
  225. X *
  226. X * XmuGetColormapAllocation returns 0 on failure, non-zero on success.
  227. X * It is assumed that the visual is appropriate for the colormap property.
  228. X */
  229. X
  230. XStatus XmuGetColormapAllocation(vinfo, property, red_max, green_max, blue_max)
  231. X    XVisualInfo        *vinfo;
  232. X    Atom        property;
  233. X    unsigned long    *red_max, *green_max, *blue_max;
  234. X{
  235. X    Status     status = 1;
  236. X
  237. X    if (vinfo->colormap_size <= 2)
  238. X    return 0;
  239. X
  240. X    switch (property)
  241. X    {
  242. X      case XA_RGB_DEFAULT_MAP:
  243. X    status = default_allocation(vinfo, red_max, green_max, blue_max);
  244. X    break;
  245. X      case XA_RGB_BEST_MAP:
  246. X    best_allocation(vinfo, red_max, green_max, blue_max);
  247. X    break;
  248. X      case XA_RGB_GRAY_MAP:
  249. X    gray_allocation(vinfo->colormap_size, red_max, green_max, blue_max);
  250. X    break;
  251. X      case XA_RGB_RED_MAP:
  252. X    *red_max = vinfo->colormap_size - 1;
  253. X    *green_max = *blue_max = 0;
  254. X    break;
  255. X      case XA_RGB_GREEN_MAP:
  256. X    *green_max = vinfo->colormap_size - 1;
  257. X    *red_max = *blue_max = 0;
  258. X    break;
  259. X      case XA_RGB_BLUE_MAP:
  260. X    *blue_max = vinfo->colormap_size - 1;
  261. X    *red_max = *green_max = 0;
  262. X    break;
  263. X      default:
  264. X    status = 0;
  265. X    }
  266. X    return status;
  267. X}
  268. X
  269. X/****************************************************************************/
  270. X/* Determine the appropriate color allocations of a gray scale.
  271. X *
  272. X * Keith Packard, MIT X Consortium
  273. X */
  274. X
  275. Xstatic void gray_allocation(n, red_max, green_max, blue_max)
  276. X    int        n;    /* the number of cells of the gray scale */
  277. X    unsigned long *red_max, *green_max, *blue_max;
  278. X{
  279. X    *red_max = (n * 30) / 100;
  280. X    *green_max = (n * 59) / 100; 
  281. X    *blue_max = (n * 11) / 100; 
  282. X    *green_max += ((n - 1) - (*red_max + *green_max + *blue_max));
  283. X}
  284. X
  285. X/****************************************************************************/
  286. X/* Determine an appropriate color allocation for the RGB_DEFAULT_MAP.
  287. X * If a map has less than a minimum number of definable entries, we do not
  288. X * produce an allocation for an RGB_DEFAULT_MAP.  
  289. X *
  290. X * For 16 planes, the default colormap will have 27 each RGB; for 12 planes,
  291. X * 12 each.  For 8 planes, let n = the number of colormap entries, which may
  292. X * be 256 or 254.  Then, maximum red value = floor(cube_root(n - 125)) - 1.
  293. X * Maximum green and maximum blue values are identical to maximum red.
  294. X * This leaves at least 125 cells which clients can allocate.
  295. X *
  296. X * Return 0 if an allocation has been determined, non-zero otherwise.
  297. X */
  298. X
  299. Xstatic int default_allocation(vinfo, red, green, blue)
  300. X    XVisualInfo        *vinfo;
  301. X    unsigned long    *red, *green, *blue;
  302. X{
  303. X    int            ngrays;        /* number of gray cells */
  304. X
  305. X    if (vinfo->colormap_size < 250)    /* skip it */
  306. X    return 0;
  307. X
  308. X    switch (vinfo->class) {
  309. X      case PseudoColor:
  310. X
  311. X    if (vinfo->colormap_size > 65000)
  312. X        /* intended for displays with 16 planes */
  313. X        *red = *green = *blue = (unsigned long) 27;
  314. X    else if (vinfo->colormap_size > 4000)
  315. X        /* intended for displays with 12 planes */
  316. X        *red = *green = *blue = (unsigned long) 12;
  317. X    else
  318. X        /* intended for displays with 8 planes */
  319. X        *red = *green = *blue = (unsigned long)
  320. X        (icbrt(vinfo->colormap_size - 125) - 1);
  321. X    break;
  322. X
  323. X      case DirectColor:
  324. X
  325. X    *red = *green = *blue = vinfo->colormap_size / 2 - 1;
  326. X    break;
  327. X
  328. X      case TrueColor:
  329. X
  330. X    *red = vinfo->red_mask / lowbit(vinfo->red_mask);
  331. X    *green = vinfo->green_mask / lowbit(vinfo->green_mask);
  332. X    *blue = vinfo->blue_mask / lowbit(vinfo->blue_mask);
  333. X    break;
  334. X
  335. X      case GrayScale:
  336. X
  337. X    if (vinfo->colormap_size > 65000)
  338. X        ngrays = 4096;
  339. X    else if (vinfo->colormap_size > 4000)
  340. X        ngrays = 512;
  341. X    else
  342. X        ngrays = 12;
  343. X    gray_allocation(ngrays, red, green, blue);
  344. X    break;
  345. X    
  346. X      default:
  347. X    return 0;
  348. X    }
  349. X    return 1;
  350. X}
  351. X
  352. X/****************************************************************************/
  353. X/* Determine an appropriate color allocation for the RGB_BEST_MAP.
  354. X *
  355. X * For a DirectColor or TrueColor visual, the allocation is determined
  356. X * by the red_mask, green_mask, and blue_mask members of the visual info.
  357. X *
  358. X * Otherwise, if the colormap size is an integral power of 2, determine
  359. X * the allocation according to the number of bits given to each color,
  360. X * with green getting more than red, and red more than blue, if there
  361. X * are to be inequities in the distribution.  If the colormap size is
  362. X * not an integral power of 2, let n = the number of colormap entries.
  363. X * Then maximum red value = floor(cube_root(n)) - 1;
  364. X *     maximum blue value = floor(cube_root(n)) - 1;
  365. X *    maximum green value = n / ((# red values) * (# blue values)) - 1;
  366. X * Which, on a GPX, allows for 252 entries in the best map, out of 254
  367. X * defineable colormap entries.
  368. X */
  369. Xstatic void best_allocation(vinfo, red, green, blue)
  370. X    XVisualInfo        *vinfo;
  371. X    unsigned long    *red, *green, *blue;
  372. X{
  373. X
  374. X    if (vinfo->class == DirectColor ||    vinfo->class == TrueColor)
  375. X    {
  376. X    *red = vinfo->red_mask;
  377. X    while ((*red & 01) == 0)
  378. X        *red >>= 1;
  379. X    *green = vinfo->green_mask;
  380. X    while ((*green & 01) == 0)
  381. X        *green >>=1;
  382. X    *blue = vinfo->blue_mask;
  383. X    while ((*blue & 01) == 0)
  384. X        *blue >>= 1;
  385. X    }
  386. X    else
  387. X    {
  388. X    register int bits, n;
  389. X    
  390. X    /* Determine n such that n is the least integral power of 2 which is
  391. X     * greater than or equal to the number of entries in the colormap.
  392. X         */
  393. X    n = 1;
  394. X    bits = 0;
  395. X    while (vinfo->colormap_size > n)
  396. X    {
  397. X        n = n << 1;
  398. X        bits++;
  399. X    }
  400. X    
  401. X    /* If the number of entries in the colormap is a power of 2, determine
  402. X     * the allocation by "dealing" the bits, first to green, then red, then
  403. X     * blue.  If not, find the maximum integral red, green, and blue values
  404. X     * which, when multiplied together, do not exceed the number of 
  405. X
  406. X     * colormap entries.
  407. X     */
  408. X    if (n == vinfo->colormap_size)
  409. X    {
  410. X        register int r, g, b;
  411. X        b = bits / 3;
  412. X        g = b + ((bits % 3) ? 1 : 0);
  413. X        r = b + (((bits % 3) == 2) ? 1 : 0);
  414. X        *red = 1 << r;
  415. X        *green = 1 << g;
  416. X        *blue = 1 << b;
  417. X    }
  418. X    else
  419. X    {
  420. X        *red = icbrt_with_bits(vinfo->colormap_size, bits);
  421. X        *blue = *red;    
  422. X        *green = (vinfo->colormap_size / ((*red) * (*blue)));
  423. X    }
  424. X    (*red)--;
  425. X    (*green)--;
  426. X    (*blue)--;
  427. X    }
  428. X    return;
  429. X}
  430. X
  431. X/*
  432. X * integer cube roots by Newton's method
  433. X *
  434. X * Stephen Gildea, MIT X Consortium, July 1991
  435. X */
  436. X
  437. Xstatic int icbrt(a)        /* integer cube root */
  438. X    int a;
  439. X{
  440. X    register int bits = 0;
  441. X    register unsigned n = a;
  442. X
  443. X    while (n)
  444. X    {
  445. X    bits++;
  446. X    n >>= 1;
  447. X    }
  448. X    return icbrt_with_bits(a, bits);
  449. X}
  450. X
  451. X
  452. Xstatic int icbrt_with_bits(a, bits)
  453. X    int a;
  454. X    int bits;            /* log 2 of a */
  455. X{
  456. X    return icbrt_with_guess(a, a>>2*bits/3);
  457. X}
  458. X
  459. X#ifdef _X_ROOT_STATS
  460. Xint icbrt_loopcount;
  461. X#endif
  462. X
  463. X/* Newton's Method:  x_n+1 = x_n - ( f(x_n) / f'(x_n) ) */
  464. X
  465. X/* for cube roots, x^3 - a = 0,  x_new = x - 1/3 (x - a/x^2) */
  466. X
  467. X/*
  468. X * Quick and dirty cube roots.  Nothing fancy here, just Newton's method.
  469. X * Only works for positive integers (since that's all we need).
  470. X * We actually return floor(cbrt(a)) because that's what we need here, too.
  471. X */
  472. X
  473. Xstatic int icbrt_with_guess(a, guess)
  474. X    int a, guess;
  475. X{
  476. X    register int delta;
  477. X
  478. X#ifdef _X_ROOT_STATS
  479. X    icbrt_loopcount = 0;
  480. X#endif
  481. X    if (a <= 0)
  482. X    return 0;
  483. X    if (guess < 1)
  484. X    guess = 1;
  485. X
  486. X    do {
  487. X#ifdef _X_ROOT_STATS
  488. X    icbrt_loopcount++;
  489. X#endif
  490. X    delta = (guess - a/(guess*guess))/3;
  491. X#ifdef DEBUG
  492. X    printf("pass %d: guess=%d, delta=%d\n", icbrt_loopcount, guess, delta);
  493. X#endif
  494. X    guess -= delta;
  495. X    } while (delta != 0);
  496. X
  497. X    if (guess*guess*guess > a)
  498. X    guess--;
  499. X
  500. X    return guess;
  501. X}
  502. END_OF_FILE
  503.   if test 9405 -ne `wc -c <'XMU/CmapAlloc.c'`; then
  504.     echo shar: \"'XMU/CmapAlloc.c'\" unpacked with wrong size!
  505.   fi
  506.   # end of 'XMU/CmapAlloc.c'
  507. fi
  508. if test -f 'XMU/LookupCmap.c' -a "${1}" != "-c" ; then 
  509.   echo shar: Will not clobber existing file \"'XMU/LookupCmap.c'\"
  510. else
  511.   echo shar: Extracting \"'XMU/LookupCmap.c'\" \(10375 characters\)
  512.   sed "s/^X//" >'XMU/LookupCmap.c' <<'END_OF_FILE'
  513. X#ifdef SCCS
  514. Xstatic char sccsid[]="@(#)LookupCmap.c    1.3 Oki 92/11/30";
  515. X#endif
  516. X/*
  517. X    This file is under sccs control at Oki in:
  518. X    /nfs/sole/root/sccs1.p/X11R5/mit/lib/Xmu/s.LookupCmap.c
  519. X*/
  520. X/* $XConsortium: LookupCmap.c,v 1.8 92/11/23 15:43:44 rws Exp $ 
  521. X * 
  522. X * Copyright 1989 by the Massachusetts Institute of Technology
  523. X *
  524. X * Permission to use, copy, modify, and distribute this software and its
  525. X * documentation for any purpose and without fee is hereby granted, provided 
  526. X * that the above copyright notice appear in all copies and that both that 
  527. X * copyright notice and this permission notice appear in supporting 
  528. X * documentation, and that the name of M.I.T. not be used in advertising
  529. X * or publicity pertaining to distribution of the software without specific, 
  530. X * written prior permission. M.I.T. makes no representations about the 
  531. X * suitability of this software for any purpose.  It is provided "as is"
  532. X * without express or implied warranty.
  533. X *
  534. X * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  535. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  536. X * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  537. X * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  538. X * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  539. X * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  540. X *
  541. X * Author:  Donna Converse, MIT X Consortium
  542. X */
  543. X
  544. X#include <stdio.h>
  545. X#include <X11/Xlib.h>
  546. X#include <X11/Xatom.h>
  547. X#include <X11/Xutil.h>
  548. X#include <X11/Xmu/StdCmap.h>
  549. X
  550. Xextern char *malloc();
  551. Xstatic Status lookup();
  552. X
  553. X/*
  554. X * To create a standard colormap if one does not currently exist, or
  555. X * replace the currently existing standard colormap, use 
  556. X * XmuLookupStandardColormap().
  557. X *
  558. X * Given a screen, a visual, and a property, XmuLookupStandardColormap()
  559. X * will determine the best allocation for the property under the specified
  560. X * visual, and determine the whether to create a new colormap or to use
  561. X * the default colormap of the screen.  It will call XmuStandardColormap()
  562. X * to create the standard colormap.
  563. X *
  564. X * If replace is true, any previous definition of the property will be 
  565. X * replaced.  If retain is true, the property and the colormap will be
  566. X * made permanent for the duration of the server session.  However,
  567. X * pre-existing property definitions which are not replaced cannot be made
  568. X * permanent by a call to XmuLookupStandardColormap(); a request to retain 
  569. X * resources pertains to newly created resources.
  570. X *
  571. X * Returns 0 on failure, non-zero on success.  A request to create a 
  572. X * standard colormap upon a visual which cannot support such a map is
  573. X * considered a failure.  An example of this would be requesting any
  574. X * standard colormap property on a monochrome visual, or, requesting an
  575. X * RGB_BEST_MAP on a display whose colormap size is 16.
  576. X */
  577. X
  578. XStatus XmuLookupStandardColormap(dpy, screen, visualid, depth, property,
  579. X                 replace, retain)
  580. X    Display        *dpy;        /* specifies X server connection */
  581. X    int            screen;     /* specifies screen of display */
  582. X    VisualID        visualid;    /* specifies the visual type */
  583. X    unsigned int    depth;        /* specifies  the visual type */
  584. X    Atom        property;    /* a standard colormap property */
  585. X    Bool        replace;    /* specifies whether to replace */
  586. X    Bool        retain;        /* specifies whether to retain */
  587. X{
  588. X    Display        *odpy;        /* original display connection */
  589. X    XStandardColormap    *colormap;    
  590. X    XVisualInfo        vinfo_template, *vinfo;    /* visual */
  591. X    long        vinfo_mask;
  592. X    unsigned long    r_max, g_max, b_max;    /* allocation */
  593. X    int            count;    
  594. X    Colormap        cmap;            /* colormap ID */
  595. X    Status        status = 0;
  596. X
  597. X
  598. X    /* Match the requested visual */
  599. X
  600. X    vinfo_template.visualid = visualid;    
  601. X    vinfo_template.screen = screen;
  602. X    vinfo_template.depth = depth;
  603. X    vinfo_mask = VisualIDMask | VisualScreenMask | VisualDepthMask;
  604. X    if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &count)) ==
  605. X    NULL)
  606. X    return 0;
  607. X
  608. X    /* Monochrome visuals have no standard maps */
  609. X
  610. X    if (vinfo->colormap_size <= 2) {
  611. X    XFree((char *) vinfo);
  612. X    return 0;    
  613. X    }
  614. X
  615. X    /* If the requested property already exists on this screen, and, 
  616. X     * if the replace flag has not been set to true, return success.
  617. X     * lookup() will remove a pre-existing map if replace is true.
  618. X     */
  619. X
  620. X    if (lookup(dpy, screen, visualid, property, (XStandardColormap *) NULL,
  621. X           replace) && !replace) {
  622. X    XFree((char *) vinfo);
  623. X    return 1;
  624. X    }
  625. X
  626. X    /* Determine the best allocation for this property under the requested
  627. X     * visualid and depth, and determine whether or not to use the default
  628. X     * colormap of the screen.
  629. X     */
  630. X
  631. X    if (!XmuGetColormapAllocation(vinfo, property, &r_max, &g_max, &b_max)) {
  632. X    XFree((char *) vinfo);
  633. X    return 0;
  634. X    }
  635. X
  636. X    cmap = (property == XA_RGB_DEFAULT_MAP &&
  637. X        visualid == XVisualIDFromVisual(DefaultVisual(dpy, screen)))
  638. X    ? DefaultColormap(dpy, screen) : None;
  639. X
  640. X    /* If retaining resources, open a new connection to the same server */
  641. X
  642. X    if (retain) {
  643. X    odpy = dpy;
  644. X    if ((dpy = XOpenDisplay(XDisplayString(odpy))) == NULL) {
  645. X        XFree((char *) vinfo);
  646. X        return 0;
  647. X    }
  648. X    }
  649. X
  650. X    /* Create the standard colormap */
  651. X
  652. X    colormap = XmuStandardColormap(dpy, screen, visualid, depth, property,
  653. X                   cmap, r_max, g_max, b_max);
  654. X
  655. X    /* Set the standard colormap property */
  656. X
  657. X    if (colormap) {
  658. X    XGrabServer(dpy);
  659. X
  660. X    if (lookup(dpy, screen, visualid, property, colormap, replace) &&
  661. X        !replace) {
  662. X        /* Someone has defined the property since we last looked.
  663. X         * Since we will not replace it, release our own resources.
  664. X         * If this is the default map, our allocations will be freed 
  665. X         * when this connection closes.
  666. X         */
  667. X        if (colormap->killid == ReleaseByFreeingColormap)
  668. X        XFreeColormap(dpy, colormap->colormap);
  669. X    }
  670. X    else if (retain) {
  671. X        XSetCloseDownMode(dpy, RetainPermanent);
  672. X    }
  673. X    XUngrabServer(dpy);
  674. X    XFree((char *) colormap);
  675. X    status = 1;
  676. X    }
  677. X
  678. X    if (retain)
  679. X    XCloseDisplay(dpy);
  680. X    XFree((char *) vinfo);
  681. X    return status;
  682. X}
  683. X
  684. X/***************************************************************************/
  685. X
  686. X/* Lookup a standard colormap property.  If the property is RGB_DEFAULT_MAP,
  687. X * the visualid is used to determine whether the indicated standard colormap
  688. X * exists.  If the map exists and replace is true, delete the resources used
  689. X * by the map and remove the property.  Return true if the map exists,
  690. X * or did exist and was deleted; return false if the map was not found.
  691. X *
  692. X * Note that this is not the way that a Status return is normally used.
  693. X *
  694. X * If new is not NULL, new points to an XStandardColormap structure which
  695. X * describes a standard colormap of the specified property.  It will be made
  696. X * a standard colormap of the screen if none already exists, or if replace 
  697. X * is true.
  698. X */
  699. X
  700. Xstatic Status lookup(dpy, screen, visualid, property, new, replace)
  701. X    Display        *dpy;        /* specifies display connection */
  702. X    int            screen;        /* specifies screen number */
  703. X    VisualID        visualid;    /* specifies visualid for std map */
  704. X    Atom        property;    /* specifies colormap property name */
  705. X    XStandardColormap    *new;        /* specifies a standard colormap */
  706. X    Bool        replace;    /* specifies whether to replace */
  707. X{
  708. X    register int    i;
  709. X    int            count;
  710. X    XStandardColormap    *stdcmaps, *s;
  711. X    Window        win = RootWindow(dpy, screen);
  712. X
  713. X    /* The property does not already exist */
  714. X
  715. X    if (! XGetRGBColormaps(dpy, win, &stdcmaps, &count, property)) {
  716. X    if (new)
  717. X        XSetRGBColormaps(dpy, win, new, 1, property);
  718. X    return 0;
  719. X    }
  720. X
  721. X    /* The property exists and is not describing the RGB_DEFAULT_MAP */
  722. X
  723. X    if (property != XA_RGB_DEFAULT_MAP) {
  724. X    if (replace) {
  725. X        XmuDeleteStandardColormap(dpy, screen, property);
  726. X        if (new)
  727. X        XSetRGBColormaps(dpy, win, new, 1, property);
  728. X    }
  729. X    XFree((char *)stdcmaps);
  730. X    return 1;
  731. X    }
  732. X
  733. X    /* The property exists and is RGB_DEFAULT_MAP */
  734. X    
  735. X    for (i=0, s=stdcmaps; (i < count) && (s->visualid != visualid); i++, s++)
  736. X    ;
  737. X
  738. X    /* No RGB_DEFAULT_MAP property matches the given visualid */
  739. X
  740. X    if (i == count) {
  741. X    if (new) {
  742. X        XStandardColormap    *m, *maps;
  743. X
  744. X        s = (XStandardColormap *) malloc((unsigned) ((count+1) * sizeof
  745. X                          (XStandardColormap)));
  746. X
  747. X        for (i = 0, m = s, maps = stdcmaps; i < count; i++, m++, maps++) {
  748. X        m->colormap   = maps->colormap;
  749. X        m->red_max    = maps->red_max;
  750. X        m->red_mult   = maps->red_mult;
  751. X        m->green_max  = maps->green_max;
  752. X        m->green_mult = maps->green_mult;
  753. X        m->blue_max   = maps->blue_max;
  754. X        m->blue_mult  = maps->blue_mult;
  755. X        m->visualid   = maps->visualid;
  756. X        m->killid     = maps->killid;
  757. X        }
  758. X        m->colormap   = new->colormap;
  759. X        m->red_max    = new->red_max;
  760. X        m->red_mult   = new->red_mult;
  761. X        m->green_max  = new->green_max;
  762. X        m->green_mult = new->green_mult;
  763. X        m->blue_max   = new->blue_max;
  764. X        m->blue_mult  = new->blue_mult;
  765. X        m->visualid   = new->visualid;
  766. X        m->killid     = new->killid;
  767. X
  768. X        XSetRGBColormaps(dpy, win, s, ++count, property);
  769. X        free((char *) s);
  770. X    }
  771. X    XFree((char *) stdcmaps);
  772. X    return 0;
  773. X    }
  774. X
  775. X    /* Found an RGB_DEFAULT_MAP property with a matching visualid */
  776. X
  777. X    if (replace) {
  778. X    /* Free old resources first - we may need them, particularly in 
  779. X     * the default colormap of the screen.  However, because of this,
  780. X     * it is possible that we will destroy the old resource and fail 
  781. X     * to create a new one if XmuStandardColormap() fails.
  782. X     */
  783. X
  784. X    if (count == 1) {
  785. X        XmuDeleteStandardColormap(dpy, screen, property);
  786. X        if (new)
  787. X        XSetRGBColormaps(dpy, win, new, 1, property);
  788. X    }
  789. X    else {
  790. X        XStandardColormap    *map;
  791. X
  792. X        /* s still points to the matching standard colormap */
  793. X
  794. X        if (s->killid == ReleaseByFreeingColormap) {
  795. X        if ((s->colormap != None) &&
  796. X            (s->colormap != DefaultColormap(dpy, screen)))
  797. X            XFreeColormap(dpy, s->colormap);
  798. X        }
  799. X        else if (s->killid != None)
  800. X        XKillClient(dpy, s->killid);
  801. X
  802. X        map = (new) ? new : stdcmaps + --count;
  803. X
  804. X        s->colormap   = map->colormap;
  805. X        s->red_max    = map->red_max;
  806. X        s->red_mult   = map->red_mult;
  807. X        s->green_max  = map->green_max;
  808. X        s->green_mult = map->green_mult;
  809. X        s->blue_max   = map->blue_max;
  810. X        s->blue_mult  = map->blue_mult;
  811. X        s->visualid   = map->visualid;
  812. X        s->killid     = map->killid;
  813. X
  814. X        XSetRGBColormaps(dpy, win, stdcmaps, count, property);
  815. X    }
  816. X    }
  817. X    XFree((char *) stdcmaps);
  818. X    return 1;
  819. X}
  820. END_OF_FILE
  821.   if test 10375 -ne `wc -c <'XMU/LookupCmap.c'`; then
  822.     echo shar: \"'XMU/LookupCmap.c'\" unpacked with wrong size!
  823.   fi
  824.   # end of 'XMU/LookupCmap.c'
  825. fi
  826. if test -f 'rgbc.c' -a "${1}" != "-c" ; then 
  827.   echo shar: Will not clobber existing file \"'rgbc.c'\"
  828. else
  829.   echo shar: Extracting \"'rgbc.c'\" \(4510 characters\)
  830.   sed "s/^X//" >'rgbc.c' <<'END_OF_FILE'
  831. X/*
  832. X * rgbc.c - RGB Cube
  833. X cc -o rgbc rgbc.c -lPEX5 -lm -lX11                    -lnsl
  834. X
  835. X            Copyright (c) 1993 by 
  836. X            Oki Electric Industry Co., Ltd.
  837. X            All Rights Reserved
  838. X    
  839. X * Permission to use, copy, modify, and distribute this software and its
  840. X * documentation for any purpose and without fee is hereby granted,
  841. X * provided that the above copyright notice appear in all copies and that
  842. X * both that copyright notice and this permission notice appear in
  843. X * supporting documentation, and that the name of Oki not be
  844. X * used in advertising or publicity pertaining to distribution of the
  845. X * software without specific, written prior permission. Oki
  846. X * makes no representations about the suitability of this software for any
  847. X * purpose.  It is provided "as is" without express or implied warranty.
  848. X*/
  849. X#include <X11/Xlib.h>
  850. X#include <X11/PEX5/PEXlib.h>
  851. X
  852. X#define SET_POINT(p,a,b,c) {(p)->x=(a);(p)->y=(b);(p)->z=(c);}
  853. X#define SET_RGB(p,a,b,c) {(p)->red=(a);(p)->green=(b);(p)->blue=(c);}
  854. X
  855. X#define RADICAL3 1.732
  856. X#define RAD3INV  (1.0/RADICAL3)
  857. X
  858. Xmain (argc, argv)
  859. X     int argc;
  860. X     char  *argv[];
  861. X{
  862. X  Display        *theDisplay;
  863. X  char            *displayString = (char *)0;
  864. X  PEXExtensionInfo    *info_return;
  865. X  char            err_msg[PEXErrorStringLength];
  866. X  XID                   theStrux;  
  867. X  int                   i;
  868. X  PEXCoord p[2];
  869. X
  870. X  for ( i = 1; i<argc; i++ ) {
  871. X    if ((strncmp(argv[i],"-display",strlen(argv[i]))) == 0) {
  872. X      if (++i > argc) { printf("not enough args"); exit(1); }
  873. X      displayString = argv[i];
  874. X    } else if ((strncmp(argv[i],"-strux",strlen(argv[i]))) == 0) {
  875. X      if (++i > argc) { printf("not enough args"); exit(1); }
  876. X      theStrux = atoi(argv[i]);
  877. X    }
  878. X  }
  879. X
  880. X  /*
  881. X   * Open the display and initialize the PEX extension.
  882. X   */
  883. X  
  884. X  if (!(theDisplay = XOpenDisplay(displayString)))
  885. X    {
  886. X      printf ( "Could not open display %s\n",displayString);
  887. X      exit (1);
  888. X    }
  889. X  
  890. X  if (PEXInitialize(theDisplay, &info_return, PEXErrorStringLength, err_msg))
  891. X    {
  892. X      printf ("%s\n", err_msg);
  893. X      exit (1);        
  894. X    }
  895. X
  896. X  PEXSetLineColorIndex( theDisplay, theStrux, PEXOCStore, 2);
  897. X  p[0].x = 0; p[0].y = 0; p[0].z = 0;
  898. X  p[1].x = -1; p[1].y = -1; p[1].z = -1;
  899. X  PEXPolyline(theDisplay, theStrux, PEXOCStore, 2, p );
  900. X
  901. X  PEXSetSurfaceColorIndex( theDisplay, theStrux, PEXOCStore, 7 );
  902. X
  903. X  {
  904. X    PEXVertexRGB             coords[8];
  905. X    PEXArrayOfVertex         varr;
  906. X    PEXConnectivityData      c10y[6];
  907. X    PEXListOfUShort          clist[6];
  908. X    unsigned short           indices[24];
  909. X    
  910. X    PEXArrayOfFacetData      aFacetData;
  911. X    
  912. X    
  913. X    SET_POINT(&coords[0].point, 0,0,0); SET_RGB(&coords[0].rgb, 0,0,0);
  914. X    SET_POINT(&coords[1].point, 1,0,0); SET_RGB(&coords[1].rgb, 1,0,0);
  915. X    SET_POINT(&coords[2].point, 0,1,0); SET_RGB(&coords[2].rgb, 0,1,0);
  916. X    SET_POINT(&coords[3].point, 0,0,1); SET_RGB(&coords[3].rgb, 0,0,1);
  917. X    SET_POINT(&coords[4].point, 1,1,0); SET_RGB(&coords[4].rgb, 1,1,0);
  918. X    SET_POINT(&coords[5].point, 1,0,1); SET_RGB(&coords[5].rgb, 1,0,1);
  919. X    SET_POINT(&coords[6].point, 0,1,1); SET_RGB(&coords[6].rgb, 0,1,1);
  920. X    SET_POINT(&coords[7].point, 1,1,1); SET_RGB(&coords[7].rgb, 1,1,1);
  921. X
  922. X    
  923. X    indices[0] = 0; indices[1] = 1; indices[2] = 4; indices[3] = 2;
  924. X    indices[4] = 0; indices[5] = 2; indices[6] = 6; indices[7] = 3;
  925. X    indices[8] = 0; indices[9] = 3; indices[10] = 5; indices[11] = 1;
  926. X    indices[12] = 7; indices[13] = 6; indices[14] = 2; indices[15] = 4;
  927. X    indices[16] = 7; indices[17] = 4; indices[18] = 1; indices[19] = 5;
  928. X    indices[20] = 7; indices[21] = 5; indices[22] = 3; indices[23] = 6;
  929. X    
  930. X    clist[0].count = 4;
  931. X    clist[0].shorts = &indices[0];
  932. X    clist[1].count = 4;
  933. X    clist[1].shorts = &indices[4];
  934. X    clist[2].count = 4;
  935. X    clist[2].shorts = &indices[8];
  936. X    clist[3].count = 4;
  937. X    clist[3].shorts = &indices[12];
  938. X    clist[4].count = 4;
  939. X    clist[4].shorts = &indices[16];
  940. X    clist[5].count = 4;
  941. X    clist[5].shorts = &indices[20];
  942. X    
  943. X    c10y[0].count = 1;
  944. X    c10y[0].lists = &clist[0];
  945. X    c10y[1].count = 1;
  946. X    c10y[1].lists = &clist[1];
  947. X    c10y[2].count = 1;
  948. X    c10y[2].lists = &clist[2];
  949. X    c10y[3].count = 1;
  950. X    c10y[3].lists = &clist[3];
  951. X    c10y[4].count = 1;
  952. X    c10y[4].lists = &clist[4];
  953. X    c10y[5].count = 1;
  954. X    c10y[5].lists = &clist[5];
  955. X    
  956. X    varr.rgb = coords;
  957. X    PEXSetOfFillAreaSets( theDisplay, theStrux, PEXOCStore,
  958. X             PEXShapeUnknown, PEXGANone, PEXGAColor, 
  959. X             PEXGANone, PEXContourUnknown, 1, PEXColorTypeRGB,
  960. X             6, aFacetData, 8, varr, 24, (PEXSwitch *)0, c10y );
  961. X  }
  962. X
  963. X  XSync(theDisplay,0);
  964. X}
  965. END_OF_FILE
  966.   if test 4510 -ne `wc -c <'rgbc.c'`; then
  967.     echo shar: \"'rgbc.c'\" unpacked with wrong size!
  968.   fi
  969.   # end of 'rgbc.c'
  970. fi
  971. if test -f 'util/pexutcmaphp.h' -a "${1}" != "-c" ; then 
  972.   echo shar: Will not clobber existing file \"'util/pexutcmaphp.h'\"
  973. else
  974.   echo shar: Extracting \"'util/pexutcmaphp.h'\" \(3626 characters\)
  975.   sed "s/^X//" >'util/pexutcmaphp.h' <<'END_OF_FILE'
  976. X#ifndef PEXUTCMAP_HP_IH /* { */
  977. X#define PEXUTCMAP_HP_IH
  978. X
  979. X/******************************************************************************/
  980. X/*                                                                            */
  981. X/*  (c) Copyright Hewlett-Packard Company, 1992, Fort Collins, Colorado       */
  982. X/*                                                                            */
  983. X/*                            All Rights Reserved                             */
  984. X/*                                                                            */
  985. X/*  Permission to use, copy, modify, and distribute this software and its     */
  986. X/*  documentation for any purpose and without fee is hereby granted,          */
  987. X/*  provided that the above copyright notices appear in all copies and that   */
  988. X/*  both the copyright notices and this permission notice appear in           */
  989. X/*  supporting documentation, and that the name of Hewlett-Packard not be     */
  990. X/*  used in advertising or publicity pertaining to distribution of the        */
  991. X/*  software without specific, written prior permission.                      */
  992. X/*                                                                            */
  993. X/*  HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS         */
  994. X/*  SOFTWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
  995. X/*  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  Hewlett-Packard    */
  996. X/*  shall not be liable for errors contained herein or direct, indirect,      */
  997. X/*  special, incidental or consequential damages in connection with the       */
  998. X/*  furnishing, performance or use of this software.                          */
  999. X/*                                                                            */
  1000. X/******************************************************************************/
  1001. X
  1002. X/******************************************************************************/
  1003. X/*                                                                            */
  1004. X/* $Source: /BE700/9.0/gtd/R903/wbuild/PEX5/head/RCS/pexutcmaphp.h,v $                                */
  1005. X/* $Date: 93/03/17 14:14:27 $                                                 */
  1006. X/* $Revision: 500.1.200.1 $                                                   */
  1007. X/*                                                                            */
  1008. X/* Description:                                                               */
  1009. X/*   Internal header file of Hewlett-Packard-specific functionality           */
  1010. X/*   for PEXUt colormap/visual utilities, not to be included by applications. */
  1011. X/*                                                                            */
  1012. X/* Notes:                                                                     */
  1013. X/*                                                                            */
  1014. X/******************************************************************************/
  1015. X
  1016. X
  1017. X#ifndef NeedFunctionPrototypes
  1018. X#if defined(FUNCPROTO) || defined(__STDC__) || \
  1019. X    defined(__cplusplus) || defined(c_plusplus)
  1020. X#define NeedFunctionPrototypes  1
  1021. X#else
  1022. X#define NeedFunctionPrototypes  0
  1023. X#endif /* FUNCPROTO, __STDC__, __cplusplus, c_plusplus */
  1024. X#endif /* NeedFunctionPrototypes */
  1025. X
  1026. X
  1027. X#ifdef __cplusplus   /* do not leave open across includes */
  1028. Xextern "C" {         /* for C++ V2.0 */
  1029. X#endif
  1030. X
  1031. Xextern
  1032. Xint pexut_modify_colormap_for_HP_dependencies (
  1033. X#if NeedFunctionPrototypes
  1034. X        Display                *display,
  1035. X        Colormap            colormap_id,
  1036. X        XVisualInfo            *vis_info,
  1037. X        PEXColorApproxEntry        *capx_info
  1038. X#endif
  1039. X        );
  1040. X
  1041. X#ifdef __cplusplus
  1042. X}                    /* for C++ V2.0 */
  1043. X#endif
  1044. X
  1045. X#endif /* } PEXUTCMAP_HP_IH */
  1046. END_OF_FILE
  1047.   if test 3626 -ne `wc -c <'util/pexutcmaphp.h'`; then
  1048.     echo shar: \"'util/pexutcmaphp.h'\" unpacked with wrong size!
  1049.   fi
  1050.   # end of 'util/pexutcmaphp.h'
  1051. fi
  1052. if test -f 'util/pexutcmapint.h' -a "${1}" != "-c" ; then 
  1053.   echo shar: Will not clobber existing file \"'util/pexutcmapint.h'\"
  1054. else
  1055.   echo shar: Extracting \"'util/pexutcmapint.h'\" \(10605 characters\)
  1056.   sed "s/^X//" >'util/pexutcmapint.h' <<'END_OF_FILE'
  1057. X#ifndef PEXUTCMAP_IH /* { */
  1058. X#define PEXUTCMAP_IH
  1059. X
  1060. X/******************************************************************************/
  1061. X/*                                                                            */
  1062. X/*  (c) Copyright Hewlett-Packard Company, 1992, Fort Collins, Colorado       */
  1063. X/*                                                                            */
  1064. X/*                            All Rights Reserved                             */
  1065. X/*                                                                            */
  1066. X/*  Permission to use, copy, modify, and distribute this software and its     */
  1067. X/*  documentation for any purpose and without fee is hereby granted,          */
  1068. X/*  provided that the above copyright notices appear in all copies and that   */
  1069. X/*  both the copyright notices and this permission notice appear in           */
  1070. X/*  supporting documentation, and that the name of Hewlett-Packard not be     */
  1071. X/*  used in advertising or publicity pertaining to distribution of the        */
  1072. X/*  software without specific, written prior permission.                      */
  1073. X/*                                                                            */
  1074. X/*  HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS         */
  1075. X/*  SOFTWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
  1076. X/*  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  Hewlett-Packard    */
  1077. X/*  shall not be liable for errors contained herein or direct, indirect,      */
  1078. X/*  special, incidental or consequential damages in connection with the       */
  1079. X/*  furnishing, performance or use of this software.                          */
  1080. X/*                                                                            */
  1081. X/******************************************************************************/
  1082. X
  1083. X/******************************************************************************/
  1084. X/*                                                                            */
  1085. X/* $Source: /users/waitz/work/tmp/RCS/pexutcmapint.h,v $                                */
  1086. X/* $Date: 93/03/02 16:39:31 $                                                 */
  1087. X/* $Revision: 1.1 $                                                   */
  1088. X/*                                                                            */
  1089. X/* Description:                                                               */
  1090. X/*   Internal header file for PEXUt cmap/visual utilities,                    */
  1091. X/*   not to be included by application programs.                              */
  1092. X/*                                                                            */
  1093. X/* Notes:                                                                     */
  1094. X/*                                                                            */
  1095. X/******************************************************************************/
  1096. X
  1097. X
  1098. X#ifndef NeedFunctionPrototypes
  1099. X#if defined(FUNCPROTO) || defined(__STDC__) || \
  1100. X    defined(__cplusplus) || defined(c_plusplus)
  1101. X#define NeedFunctionPrototypes  1
  1102. X#else
  1103. X#define NeedFunctionPrototypes  0
  1104. X#endif /* FUNCPROTO, __STDC__, __cplusplus, c_plusplus */
  1105. X#endif /* NeedFunctionPrototypes */
  1106. X
  1107. X
  1108. X#ifdef __cplusplus   /* do not leave open across includes */
  1109. Xextern "C" {         /* for C++ V2.0 */
  1110. X#endif
  1111. X
  1112. X
  1113. X/*
  1114. X    This structure type is used to describe standard colormap properties
  1115. X    that should searched as part of an interoperability convention.
  1116. X    The ordering of entries in an array of these structures is the search
  1117. X    order of the properties.
  1118. X
  1119. X    The fields are used as follows:
  1120. X
  1121. X    is_standard        True if the colormap property is a current
  1122. X                standard, i.e. supported by XGetRGBColormaps.
  1123. X                False otherwise.
  1124. X
  1125. X    have_atom        True if the Atom in the property_atom field
  1126. X                is valid, False if only the property_name
  1127. X                string is valid.
  1128. X
  1129. X    property_atom        Atom value for the property name, which may
  1130. X                be predefined or may have been fetched by
  1131. X                an earlier call to XInternAtom.
  1132. X
  1133. X    property_name        the property name as a NULL-terminated
  1134. X                character string.
  1135. X*/
  1136. X    
  1137. Xtypedef struct {
  1138. X    int    is_standard;
  1139. X    int    have_atom;
  1140. X    Atom    property_atom;
  1141. X    char    *property_name;
  1142. X} interop_property_type;
  1143. X
  1144. X
  1145. X/*
  1146. X    This structure type is the entry type for the SERVER_OVERLAY_VISUALS
  1147. X    property.  The property contains an entry for each Visual on the screen
  1148. X    of the root window where it is attached.
  1149. X    
  1150. X    The fields are used as follows:
  1151. X
  1152. X    visualid        identifier of the Visual.
  1153. X
  1154. X    transparent_type    specifies the mechanism that controls
  1155. X                transparency in the Visual: one of None,
  1156. X                TransparentPixel, or TransparentMask.
  1157. X
  1158. X    value            pixel value that is transparent, if
  1159. X                the transparent_type is TransparentPixel.
  1160. X
  1161. X    layer            specifies the layer of the Visual.  Image
  1162. X                layer is 0, overlay layer is 1.
  1163. X*/
  1164. X    
  1165. Xtypedef struct {
  1166. X    VisualID    visualid;
  1167. X    int        transparent_type;
  1168. X    int        value;
  1169. X    int        layer;
  1170. X} overlay_visuals_type;
  1171. X
  1172. X
  1173. X
  1174. X/*
  1175. X    This structure type is used internally by the PEXUt code to record
  1176. X    information about each Visual that is considered.  The central
  1177. X    creator and user of the structure type is PEXUtFindVisual; it passes
  1178. X    pointers to this structure type to several subsidiary routines.
  1179. X    
  1180. X    The fields are used as follows:
  1181. X
  1182. X    unmet_hard_criteria    a mask of the hard criteria that are not
  1183. X                met by the Visual; if this is mask is non-zero,
  1184. X                the Visual is not a candidate for selection.
  1185. X
  1186. X    unmet_soft_criteria    a mask of the soft criteria that are not
  1187. X                met by the Visual; this mask is used in
  1188. X                choosing among several Visuals that are
  1189. X                candidates.
  1190. X
  1191. X    property_ptr        a pointer to the entry for the Visual in the 
  1192. X                first standard colormap property (in priority)
  1193. X                that contains an entry for the Visual; if 
  1194. X                properties were not searched then this pointer
  1195. X                is NULL.
  1196. X
  1197. X    property_atom        the atom for the property whose entry is
  1198. X                addressed by property_ptr.
  1199. X
  1200. X    visual_ptr        a pointer to the description of the Visual.
  1201. X
  1202. X    order_rating,        independent integers that represent the
  1203. X    soft_rating,        relative rank of the Visual in the respective
  1204. X    color_rating        category:  order of appearance in a target
  1205. X                list or colormap property; number of soft
  1206. X                criteria that the Visual meets; level of
  1207. X                color resolution.  These fields are combined
  1208. X                to form an overall rating in order to choose
  1209. X                among several candidate Visuals.
  1210. X*/
  1211. X
  1212. Xtypedef struct {
  1213. X    unsigned int        unmet_hard_criteria;
  1214. X    unsigned int        unmet_soft_criteria;
  1215. X    XStandardColormap    *property_ptr;
  1216. X    Atom            property_atom;
  1217. X    XVisualInfo        *visual_ptr;
  1218. X    unsigned int        order_rating;
  1219. X    unsigned int        soft_rating;
  1220. X    unsigned int        color_rating;
  1221. X    unsigned int        class_rating;
  1222. X} visual_info_type;
  1223. X
  1224. X
  1225. X/*
  1226. X    MAX_ORDER_RATING is the maximum value of the order rating, i.e. the rating 
  1227. X    for each candidate visual that is based on its relative order in a
  1228. X    target list or standard colormap property.  The value range should
  1229. X    map to a range compatible with the ORDER_SHIFT,
  1230. X    such that the range and the shift do not exceed 32 bits when combined.
  1231. X
  1232. X    Similarly, MAX_SOFT_RATING is the maximum value for the rating based
  1233. X    on how well a Visual meets the soft criteria.  It must be compatible
  1234. X    with SOFT_SHIFT.  And so on for the other factors used in rating Visuals.
  1235. X*/
  1236. X
  1237. X#define MAX_CLASS_RATING  0x1
  1238. X#define CLASS_SHIFT       0
  1239. X#define MAX_COLOR_RATING  0xFFFF
  1240. X#define COLOR_SHIFT       1
  1241. X#define MAX_ORDER_RATING  0x1FF
  1242. X#define ORDER_SHIFT       17
  1243. X#define MAX_SOFT_RATING   0x1FF
  1244. X#define SOFT_SHIFT        22
  1245. X
  1246. X
  1247. X/*
  1248. X    No specifications are provided for these internal utilities.
  1249. X    For the most part, their names describe their functionality.
  1250. X*/
  1251. X
  1252. Xextern
  1253. Xint pexut_get_standard_cmap_property (
  1254. X#if NeedFunctionPrototypes
  1255. X        Display                *display,
  1256. X        int                screen,
  1257. X        interop_property_type        *property_info,
  1258. X        Atom                *property_atom_return,
  1259. X        int                *property_count_return,
  1260. X        XStandardColormap        **property_data_return
  1261. X#endif
  1262. X        );
  1263. X        
  1264. Xextern
  1265. Xint pexut_get_overlay_visuals_property (
  1266. X#if NeedFunctionPrototypes
  1267. X        Display                *display,
  1268. X        int                screen,
  1269. X        int                *property_count_return,
  1270. X        overlay_visuals_type        **property_data_return
  1271. X#endif
  1272. X        );
  1273. X        
  1274. Xextern
  1275. Xint pexut_evaluate_color_criteria (
  1276. X#if NeedFunctionPrototypes
  1277. X        Display                *display,
  1278. X        PEXUtVisualCriteria        *criteria,
  1279. X        XVisualInfo            *vis_info,
  1280. X        visual_info_type        *p_info
  1281. X#endif
  1282. X        );
  1283. X
  1284. Xextern
  1285. Xint pexut_evaluate_double_buffering_capability (
  1286. X#if NeedFunctionPrototypes
  1287. X        Display                *display,
  1288. X        PEXUtVisualCriteria        *criteria,
  1289. X        XVisualInfo            *vis_info,
  1290. X        visual_info_type        *p_info
  1291. X#endif
  1292. X        );
  1293. X
  1294. Xextern
  1295. Xint pexut_evaluate_color_approx_type (
  1296. X#if NeedFunctionPrototypes
  1297. X        Display                *display,
  1298. X        PEXUtVisualCriteria        *criteria,
  1299. X        XVisualInfo            *vis_info,
  1300. X        visual_info_type        *p_info
  1301. X#endif
  1302. X        );
  1303. X
  1304. Xextern
  1305. Xunsigned int pexut_compute_overall_rating (
  1306. X#if NeedFunctionPrototypes
  1307. X        visual_info_type        *p_info
  1308. X#endif
  1309. X        );
  1310. X
  1311. Xextern
  1312. Xint pexut_create_temporary_window (
  1313. X#if NeedFunctionPrototypes
  1314. X        Display                *display,
  1315. X        XVisualInfo            *vis_info,
  1316. X        Window                *window_return
  1317. X#endif
  1318. X        );
  1319. X
  1320. Xextern
  1321. Xint pexut_destroy_temporary_window (
  1322. X#if NeedFunctionPrototypes
  1323. X        Display                *display,
  1324. X        XVisualInfo            *vis_info,
  1325. X        Window                window
  1326. X#endif
  1327. X        );
  1328. X
  1329. Xextern
  1330. Xint pexut_verify_color_approx_type (
  1331. X#if NeedFunctionPrototypes
  1332. X        Display                *display,
  1333. X        Window                window,
  1334. X        PEXEnumTypeIndex        color_approx_type
  1335. X#endif
  1336. X        );
  1337. X
  1338. Xextern
  1339. Xint pexut_synthesize_cmap_from_visual (
  1340. X#if NeedFunctionPrototypes
  1341. X        XVisualInfo            *vis_info,
  1342. X        XStandardColormap        *cmap_info_return
  1343. X#endif
  1344. X        );
  1345. X
  1346. Xextern
  1347. Xint pexut_load_color_approx_from_std_cmap (
  1348. X#if NeedFunctionPrototypes
  1349. X        int                color_approx_type,
  1350. X        XVisualInfo            *vis_info,
  1351. X        XStandardColormap        *cmap_info,
  1352. X        PEXColorApproxEntry        *capx_info_return
  1353. X#endif
  1354. X        );
  1355. X
  1356. Xextern
  1357. Xint pexut_match_color_approx_entry (
  1358. X#if NeedFunctionPrototypes
  1359. X        PEXColorApproxEntry        *entry1, 
  1360. X        PEXColorApproxEntry        *entry2
  1361. X#endif
  1362. X        );
  1363. X
  1364. Xextern
  1365. Xint pexut_create_one_channel_map (
  1366. X#if NeedFunctionPrototypes
  1367. X        Display                *display,
  1368. X        XVisualInfo            *vis_info,
  1369. X        PEXColorApproxEntry        *capx_info,
  1370. X        Colormap            *colormap_id_return
  1371. X#endif
  1372. X        );
  1373. X
  1374. Xextern
  1375. Xint pexut_create_three_channel_map (
  1376. X#if NeedFunctionPrototypes
  1377. X        Display                *display,
  1378. X        XVisualInfo            *vis_info,
  1379. X        PEXColorApproxEntry        *capx_info,
  1380. X        Colormap            *colormap_id_return
  1381. X#endif
  1382. X        );
  1383. X
  1384. Xextern
  1385. Xint pexut_create_read_only_map (
  1386. X#if NeedFunctionPrototypes
  1387. X        Display                *display,
  1388. X        XVisualInfo            *vis_info,
  1389. X        PEXColorApproxEntry        *capx_info,
  1390. X        Colormap            *colormap_id_return
  1391. X#endif
  1392. X        );
  1393. X
  1394. Xextern
  1395. Xint pexut_count_bits_in_mask (
  1396. X#if NeedFunctionPrototypes
  1397. X        unsigned int mask
  1398. X#endif
  1399. X        );
  1400. X
  1401. X#ifdef __cplusplus
  1402. X}                    /* for C++ V2.0 */
  1403. X#endif
  1404. X
  1405. X#endif /* } PEXUTCMAP_IH */
  1406. END_OF_FILE
  1407.   if test 10605 -ne `wc -c <'util/pexutcmapint.h'`; then
  1408.     echo shar: \"'util/pexutcmapint.h'\" unpacked with wrong size!
  1409.   fi
  1410.   # end of 'util/pexutcmapint.h'
  1411. fi
  1412. echo shar: End of archive 14 \(of 14\).
  1413. cp /dev/null ark14isdone
  1414. MISSING=""
  1415. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
  1416.     if test ! -f ark${I}isdone ; then
  1417.     MISSING="${MISSING} ${I}"
  1418.     fi
  1419. done
  1420. if test "${MISSING}" = "" ; then
  1421.     echo You have unpacked all 14 archives.
  1422.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1423.     echo "concatentating pexdraw.c ..."
  1424.     cat pexdrawc.? > pexdraw.c
  1425.     rm pexdrawc.?
  1426.     echo "concatentating pexdraw.uil ..."
  1427.     cat pexdrawu.? > pexdraw.uil
  1428.     rm pexdrawu.?
  1429.     echo "concatentating teapot.c ..."
  1430.     rm teapotc.?
  1431. else
  1432.     echo You still must unpack the following archives:
  1433.     echo "        " ${MISSING}
  1434. fi
  1435. exit 0
  1436. exit 0 # Just in case...
  1437. -- 
  1438.   // chris@IMD.Sterling.COM       | Send comp.sources.x submissions to:
  1439. \X/  Amiga - The only way to fly! |    sources-x@imd.sterling.com
  1440.  "It's intuitively obvious to the |
  1441.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  1442.