From: chris@ods.com (Chris Atkins)
Subject: Re: Colormaps: pict.c, xgifload.c, motifgif.c code on motif release 1.1.4
Organization: Optical Data Systems, Inc.
X-Newsreader: Tin 1.1 PL5
Distribution: inet
Date: Thu, 3 Sep 1992 21:42:25 GMT

lr@laurie.smec.Sony.COM wrote:
: Hello,
: 	Thanks to all who helped with my text placement and transparent
: widget queries.  I'm now wrestling with understanding colormaps.  I ran
: the demo  program pict in the motifgif demo directory on the motif
: release 1.1.4 tape.  The following is a test sequence that I ran:
:  
: 
: 1.  pict -ns challenger.gif&
: 	The image displays and the following message appears 
: 	"failed to allocate 20 out of 254 colors.  Trying extra hard."
: 
: 2.  pict -ns toucan.gif&
: 	The image displays and the following message appears
: 	"failed to allocate 106 out of 108 colors.  Trying extra hard."
: 
: 3.  close challenger.gif display  ( I tried File Quit, kill -9, and
: closing the window)
: 	The toucan.gif image is still displayed and looks fine. 
: 
: 4.  pict -ns toucan.gif&
: 	The image displays fine, but the first toucan.gif display's
: colortable is somehow corrupted.
: 	No "failed to allocate" message appears.
: 
: Does this mean:
: 
: A)    When an application closes,  it's color table entries are
: automatically freed regardless if some other application is currently
: using those colors????!!!  OUCH!
: 
: OR
: 
: B)    The "Trying extra hard" section of xgifload.c is not quite complete?  HELP!
: 
: 
: So, the questions are:
: 
: 1.   Is there some way of registering that multiple applications are
: using the same color entries through Motif, Xlib, or some other standard calls?
  If you wish to allocate some resources which should not be freed when your
  client goes away, you should use XSetCloseDownMode.  This function is 
  doccumented in O'Reilly volume 2.  If you do not use this function, all
  your resources are freed when your client exits.  This function should be
  used sparingly in that all resources for the client are maintained until
  a call to XKillClient.

  This applies to read/write colorcells also.  As for read only cells, 
  the servers seem to be free to do what they want to with these.  
  My obersavation of servers is that read only color cells are only freed 
  if no other client is using them.  The sun X/News server tries to adjust the
  colormap to contain cells for the active window and optimize for the other
  windows.
: 
: 2.   Is there some method of determining which color entries will be
: eventually freed when the application is no longer running?
:
  Not without implementing an extension for this.  If this is important you 
  should have a client come up and allocate needed colors and then set 
  the close down mode to RetainPermament.
: 
: 3.   Is there some method of identifying exactly what colors an
: application is using without specifically querying for each widget
: attribute?  By this I mean everything including all the borders,
: background pixels, shadows and all.
: 
  No.  The best you can do is look at all colormaps the client knows about and
  record the rgb indices for each pixel.  This approach says nothing about what
  pixels of which colormaps could actually be used, or if the application has
  an interface which allocates a private colormap or uses a colormap which you
  do not know about(gets the colormap from a window property, etc).
: 

Chris Atkins
chris@ods.com
Newsgroups: comp.windows.x.motif