home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume20 / imagemgc / part09 < prev    next >
Encoding:
Text File  |  1993-07-13  |  50.6 KB  |  1,565 lines

  1. Newsgroups: comp.sources.x
  2. From: cristy@eplrx7.es.duPont.com (Cristy)
  3. Subject: v20i065:  imagemagic - X11 image processing and display, Part09/38
  4. Message-ID: <1993Jul14.175459.1141@sparky.sterling.com>
  5. X-Md4-Signature: bd1615cb4a7e4f84e93b9d1a63e1023c
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Wed, 14 Jul 1993 17:54:59 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: cristy@eplrx7.es.duPont.com (Cristy)
  12. Posting-number: Volume 20, Issue 65
  13. Archive-name: imagemagic/part09
  14. Environment: X11
  15. Supersedes: imagemagic: Volume 13, Issue 17-37
  16.  
  17. #!/bin/sh
  18. # this is magick.09 (part 9 of ImageMagick)
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file ImageMagick/X.c continued
  21. #
  22. if test ! -r _shar_seq_.tmp; then
  23.     echo 'Please unpack part 1 first!'
  24.     exit 1
  25. fi
  26. (read Scheck
  27.  if test "$Scheck" != 9; then
  28.     echo Please unpack part "$Scheck" next!
  29.     exit 1
  30.  else
  31.     exit 0
  32.  fi
  33. ) < _shar_seq_.tmp || exit 1
  34. if test ! -f _shar_wnt_.tmp; then
  35.     echo 'x - still skipping ImageMagick/X.c'
  36. else
  37. echo 'x - continuing file ImageMagick/X.c'
  38. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/X.c' &&
  39. X  */
  40. X  pixel_info=window->pixel_info;
  41. X  q=annotate_image->pixels;
  42. X  for (y=0; y < annotate_image->rows; y++)
  43. X    for (x=0; x < annotate_image->columns; x++)
  44. X    {
  45. X      q->index=(unsigned short) XGetPixel(annotate_ximage,x,y);
  46. X      if (q->index == 0)
  47. X        {
  48. X          /*
  49. X            Set this pixel to the background color.
  50. X          */
  51. X          q->red=pixel_info->background_color.red >> 8;
  52. X          q->green=pixel_info->background_color.green >> 8;
  53. X          q->blue=pixel_info->background_color.blue >> 8;
  54. X        }
  55. X      else
  56. X        {
  57. X          /*
  58. X            Set this pixel to the pen color.
  59. X          */
  60. X          q->red=pixel_info->annotate_color.red >> 8;
  61. X          q->green=pixel_info->annotate_color.green >> 8;
  62. X          q->blue=pixel_info->annotate_color.blue >> 8;
  63. X        }
  64. X      q->length=0;
  65. X      q++;
  66. X    }
  67. X  XDestroyImage(annotate_ximage);
  68. X  /*
  69. X    Determine annotate geometry.
  70. X  */
  71. X  (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
  72. X  if ((width != annotate_image->columns) || (height != annotate_image->rows))
  73. X    TransformImage(&annotate_image,(char *) NULL,annotate_info->geometry,
  74. X      (char *) NULL);
  75. X  if (annotate_info->degrees != 0.0)
  76. X    {
  77. X      Image
  78. X        *rotated_image;
  79. X
  80. X      /*
  81. X        Rotate image.
  82. X      */
  83. X      rotated_image=RotateImage(annotate_image,annotate_info->degrees,False);
  84. X      if (rotated_image == (Image *) NULL)
  85. X        return(False);
  86. X      DestroyImage(annotate_image);
  87. X      annotate_image=rotated_image;
  88. X    }
  89. X  /*
  90. X    Paste annotated image to image.
  91. X  */
  92. X  image->class=DirectClass;
  93. X  p=annotate_image->pixels;
  94. X  q=image->pixels+y*image->columns+x;
  95. X  for (y=0; y < annotate_image->rows; y++)
  96. X  {
  97. X    for (x=0; x < annotate_image->columns; x++)
  98. X    {
  99. X      if (p->index != 0)
  100. X        {
  101. X          /*
  102. X            Set this pixel to the pen color.
  103. X          */
  104. X          *q=(*p);
  105. X          q->index=pixel_info->annotate_index;
  106. X        }
  107. X      else
  108. X        if (background)
  109. X          {
  110. X            /*
  111. X              Set this pixel to the background color.
  112. X            */
  113. X            *q=(*p);
  114. X            q->index=pixel_info->background_index;
  115. X          }
  116. X      p++;
  117. X      q++;
  118. X    }
  119. X    q+=image->columns-annotate_image->columns;
  120. X  }
  121. X  DestroyImage(annotate_image);
  122. X  return(True);
  123. }
  124. X
  125. /*
  126. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  127. %                                                                             %
  128. %                                                                             %
  129. %                                                                             %
  130. %   X B e s t F o n t                                                         %
  131. %                                                                             %
  132. %                                                                             %
  133. %                                                                             %
  134. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  135. %
  136. %  Function XBestFont returns the "best" font.  "Best" is defined as a font
  137. %  specified in the X resource database or a font such that the text width
  138. %  displayed with the font does not exceed the specified maximum width.
  139. %
  140. %  The format of the XBestFont routine is:
  141. %
  142. %      font=XBestFont(display,resource_info,text,maximum_width)
  143. %
  144. %  A description of each parameter follows:
  145. %
  146. %    o font: XBestFont returns a pointer to a XFontStruct structure.
  147. %
  148. %    o display: Specifies a connection to an X server;  returned from
  149. %      XOpenDisplay.
  150. %
  151. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  152. %
  153. %    o text: Specifies the text whose width is compared to the maximum.
  154. %
  155. %    o maximum_width: Specifies the maximum width in pixels of the text.
  156. %
  157. %
  158. */
  159. XXFontStruct *XBestFont(display,resource_info,text,maximum_width)
  160. Display
  161. X  *display;
  162. X
  163. XXResourceInfo
  164. X  *resource_info;
  165. X
  166. char
  167. X  *text;
  168. X
  169. unsigned int
  170. X  maximum_width;
  171. {
  172. X  static char
  173. X    *fonts[]=
  174. X    {
  175. X      "fixed",
  176. X      "9x15",
  177. X      "6x13",
  178. X      "6x10",
  179. X      (char *) NULL
  180. X    };
  181. X
  182. X  char
  183. X    *font_name,
  184. X    **p;
  185. X
  186. X  unsigned int
  187. X    width;
  188. X
  189. X  XFontStruct
  190. X    *font_info;
  191. X
  192. X  font_info=(XFontStruct *) NULL;
  193. X  font_name=resource_info->font;
  194. X  if (font_name != (char *) NULL)
  195. X    {
  196. X      /*
  197. X        Load preferred font specified in the X resource database.
  198. X      */
  199. X      font_info=XLoadQueryFont(display,font_name);
  200. X      if (font_info == (XFontStruct *) NULL)
  201. X        Warning("unable to load font",font_name);
  202. X    }
  203. X  else
  204. X    if (text != (char *) NULL)
  205. X      {
  206. X        /*
  207. X          Load a font that does not exceed the text width.
  208. X        */
  209. X        for (p=fonts; *p != (char *) NULL; p++)
  210. X        {
  211. X          if (font_info != (XFontStruct *) NULL)
  212. X            {
  213. X              width=XTextWidth(font_info,text,strlen(text))+
  214. X                2*font_info->max_bounds.width+2*WindowBorderWidth;
  215. X              if (width < maximum_width)
  216. X                break;
  217. X              font_name=(*p);
  218. X              XFreeFont(display,font_info);
  219. X            }
  220. X          font_info=XLoadQueryFont(display,*p);
  221. X        }
  222. X      }
  223. X  if (font_info == (XFontStruct *) NULL)
  224. X    font_info=XLoadQueryFont(display,"fixed");  /* backup font */
  225. X  if (font_info == (XFontStruct *) NULL)
  226. X    font_info=XLoadQueryFont(display,"variable");  /* backup font */
  227. X  return(font_info);
  228. }
  229. X
  230. /*
  231. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  232. %                                                                             %
  233. %                                                                             %
  234. %                                                                             %
  235. %   X B e s t I c o n S i z e                                                 %
  236. %                                                                             %
  237. %                                                                             %
  238. %                                                                             %
  239. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  240. %
  241. %  Function XBestIconSize returns the "best" icon size.  "Best" is defined as
  242. %  an icon size that maintains the aspect ratio of the image.  If the window
  243. %  manager has preferred icon sizes, one of the preferred sizes is used.
  244. %
  245. %  The format of the XBestIconSize routine is:
  246. %
  247. %      XBestIconSize(display,window,image)
  248. %
  249. %  A description of each parameter follows:
  250. %
  251. %    o display: Specifies a connection to an X server;  returned from
  252. %      XOpenDisplay.
  253. %
  254. %    o image: Specifies a pointer to a Image structure;  returned from
  255. %      ReadImage.
  256. %
  257. %
  258. */
  259. void XBestIconSize(display,window,image)
  260. Display
  261. X  *display;
  262. X
  263. XXWindowInfo
  264. X  *window;
  265. X
  266. Image
  267. X  *image;
  268. {
  269. #define MaxIconSize  96
  270. X
  271. X  int
  272. X    i,
  273. X    number_sizes;
  274. X
  275. X  unsigned int
  276. X    height,
  277. X    icon_height,
  278. X    icon_width,
  279. X    width;
  280. X
  281. X  unsigned long
  282. X    scale_factor;
  283. X
  284. X  Window
  285. X    root_window;
  286. X
  287. X  XIconSize
  288. X    *icon_size,
  289. X    *size_list;
  290. X
  291. X  /*
  292. X    Determine if the window manager has specified preferred icon sizes.
  293. X  */
  294. X  window->width=MaxIconSize;
  295. X  window->height=MaxIconSize;
  296. X  icon_size=(XIconSize *) NULL;
  297. X  number_sizes=0;
  298. X  root_window=XRootWindow(display,window->screen);
  299. X  if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
  300. X    if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
  301. X      icon_size=size_list;
  302. X  if (icon_size == (XIconSize *) NULL)
  303. X    {
  304. X      /*
  305. X        Window manager does not restrict icon size.
  306. X      */
  307. X      icon_size=XAllocIconSize();
  308. X      if (icon_size == (XIconSize *) NULL)
  309. X        {
  310. X          Warning("unable to choose best icon size","memory allocation failed");
  311. X          return;
  312. X        }
  313. X      icon_size->min_width=1;
  314. X      icon_size->max_width=MaxIconSize;
  315. X      icon_size->min_height=1;
  316. X      icon_size->max_height=MaxIconSize;
  317. X      icon_size->width_inc=1;
  318. X      icon_size->height_inc=1;
  319. X    }
  320. X  /*
  321. X    Determine aspect ratio of image.
  322. X  */
  323. X  width=image->columns;
  324. X  height=image->rows;
  325. X  if (window->clip_geometry)
  326. X    (void) XParseGeometry(window->clip_geometry,&i,&i,&width,&height);
  327. X  /*
  328. X    Look for an icon size that maintains the aspect ratio of image.
  329. X  */
  330. X  scale_factor=UpShift(icon_size->max_width)/width;
  331. X  if (scale_factor > (UpShift(icon_size->max_height)/height))
  332. X    scale_factor=UpShift(icon_size->max_height)/height;
  333. X  icon_width=icon_size->min_width;
  334. X  while (icon_width < icon_size->max_width)
  335. X  {
  336. X    if (icon_width >= (DownShift(width*scale_factor)))
  337. X      break;
  338. X    icon_width+=icon_size->width_inc;
  339. X  }
  340. X  icon_height=icon_size->min_height;
  341. X  while (icon_height < icon_size->max_height)
  342. X  {
  343. X    if (icon_height >= (DownShift(height*scale_factor)))
  344. X      break;
  345. X    icon_height+=icon_size->height_inc;
  346. X  }
  347. X  XFree((void *) icon_size);
  348. X  window->width=icon_width;
  349. X  window->height=icon_height;
  350. }
  351. X
  352. /*
  353. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  354. %                                                                             %
  355. %                                                                             %
  356. %                                                                             %
  357. %   X B e s t P i x e l                                                       %
  358. %                                                                             %
  359. %                                                                             %
  360. %                                                                             %
  361. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  362. %
  363. %  Function XBestPixel returns a pixel from an array of pixels that is closest
  364. %  to the requested color.
  365. %
  366. %  The format of the XBestPixel routine is:
  367. %
  368. %      pixel=XBestPixel(colors,number_colors,color)
  369. %
  370. %  A description of each parameter follows:
  371. %
  372. %    o pixel: XBestPixel returns the pixel value closest to the requested
  373. %      color.
  374. %
  375. %    o colors: Specifies an array of XColor structures.
  376. %
  377. %    o number_colors: Specifies the number of XColor structures in the
  378. %      color definition array.
  379. %
  380. %    o color: Specifies the desired RGB value to find in the colors array.
  381. %
  382. %
  383. */
  384. static void XBestPixel(colors,number_colors,color)
  385. XXColor
  386. X  *colors;
  387. X
  388. unsigned int
  389. X  number_colors;
  390. X
  391. XXColor
  392. X  *color;
  393. {
  394. X  register int
  395. X    blue_distance,
  396. X    green_distance,
  397. X    i,
  398. X    red_distance;
  399. X
  400. X  register unsigned long
  401. X    distance,
  402. X    min_distance;
  403. X
  404. X  /*
  405. X    Find closest representation for the requested RGB color.
  406. X  */
  407. X  color->pixel=0;
  408. X  min_distance=(unsigned long) (~0);
  409. X  for (i=0; i < number_colors; i++)
  410. X  {
  411. X    red_distance=(int) (colors[i].red >> 8)-(int) (color->red >> 8);
  412. X    green_distance=(int) (colors[i].green >> 8)-(int) (color->green >> 8);
  413. X    blue_distance=(int) (colors[i].blue >> 8)-(int) (color->blue >> 8);
  414. X    distance=red_distance*red_distance+green_distance*green_distance+
  415. X      blue_distance*blue_distance;
  416. X    if (distance < min_distance)
  417. X      {
  418. X        min_distance=distance;
  419. X        color->pixel=colors[i].pixel;
  420. X      }
  421. X  }
  422. X  return;
  423. }
  424. X
  425. /*
  426. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  427. %                                                                             %
  428. %                                                                             %
  429. %                                                                             %
  430. %   X B e s t V i s u a l I n f o                                             %
  431. %                                                                             %
  432. %                                                                             %
  433. %                                                                             %
  434. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  435. %
  436. %  Function XBestVisualInfo returns visual information for a visual that is
  437. %  the "best" the server supports.  "Best" is defined as:
  438. %
  439. %    1. Restrict the visual list to those supported by the default screen.
  440. %
  441. %    2. If a visual type is specified, restrict the visual list to those of
  442. %       that type.
  443. %
  444. %    3. If a map type is specified, choose the visual that matches the id
  445. %       specified by the Standard Colormap.
  446. %
  447. %    4  From the list of visuals, choose one that can display the most
  448. %       simultaneous colors.  If more than one visual can display the same
  449. %       number of simultaneous colors, one is choosen based on a rank.
  450. %
  451. %  The format of the XBestVisualInfo routine is:
  452. %
  453. %      visual_info=XBestVisualInfo(display,visual_type,map_type,map_info)
  454. %
  455. %  A description of each parameter follows:
  456. %
  457. %    o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
  458. %      structure.
  459. %
  460. %    o display: Specifies a connection to an X server;  returned from
  461. %      XOpenDisplay.
  462. %
  463. %    o visual_type: Specifies the desired visual type.
  464. %
  465. %    o map_type: Specifies the desired Standard Colormap type.
  466. %
  467. %    o map_info: If map_type is specified, this structure is initialized
  468. %      with info from the Standard Colormap.
  469. %
  470. %
  471. */
  472. XXVisualInfo *XBestVisualInfo(display,visual_type,map_type,map_info)
  473. Display
  474. X  *display;
  475. X
  476. char
  477. X  *visual_type,
  478. X  *map_type;
  479. X
  480. XXStandardColormap
  481. X  *map_info;
  482. {
  483. #define XVisualColormapSize(visual_info) \
  484. X  ((visual_info->class == TrueColor) || (visual_info->class == DirectColor) ? \
  485. X    visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
  486. X    visual_info->colormap_size)
  487. X
  488. X  int
  489. X    number_visuals;
  490. X
  491. X  register int
  492. X    i;
  493. X
  494. X  unsigned int
  495. X    visual_mask;
  496. X
  497. X  XVisualInfo
  498. X    *visual_info,
  499. X    *visual_list,
  500. X    visual_template;
  501. X
  502. X  /*
  503. X    Restrict visual search by screen number.
  504. X  */
  505. X  visual_mask=VisualScreenMask;
  506. X  visual_template.screen=XDefaultScreen(display);
  507. X  if (visual_type != (char *) NULL)
  508. X    {
  509. X      /*
  510. X        Restrict visual search by class or visual id.
  511. X      */
  512. X      if (Latin1Compare("staticgray",visual_type) == 0)
  513. X        {
  514. X          visual_mask|=VisualClassMask;
  515. X          visual_template.class=StaticGray;
  516. X        }
  517. X      else
  518. X        if (Latin1Compare("grayscale",visual_type) == 0)
  519. X          {
  520. X            visual_mask|=VisualClassMask;
  521. X            visual_template.class=GrayScale;
  522. X          }
  523. X        else
  524. X          if (Latin1Compare("staticcolor",visual_type) == 0)
  525. X            {
  526. X              visual_mask|=VisualClassMask;
  527. X              visual_template.class=StaticColor;
  528. X            }
  529. X          else
  530. X            if (Latin1Compare("pseudocolor",visual_type) == 0)
  531. X              {
  532. X                visual_mask|=VisualClassMask;
  533. X                visual_template.class=PseudoColor;
  534. X              }
  535. X            else
  536. X              if (Latin1Compare("truecolor",visual_type) == 0)
  537. X                {
  538. X                  visual_mask|=VisualClassMask;
  539. X                  visual_template.class=TrueColor;
  540. X                }
  541. X              else
  542. X                if (Latin1Compare("directcolor",visual_type) == 0)
  543. X                  {
  544. X                    visual_mask|=VisualClassMask;
  545. X                    visual_template.class=DirectColor;
  546. X                  }
  547. X                else
  548. X                  if (Latin1Compare("default",visual_type) == 0)
  549. X                    {
  550. X                      visual_mask|=VisualIDMask;
  551. X                      visual_template.visualid=XVisualIDFromVisual(
  552. X                        XDefaultVisual(display,XDefaultScreen(display)));
  553. X                    }
  554. X                  else
  555. X                    if (isdigit(*visual_type))
  556. X                      {
  557. X                        visual_mask|=VisualIDMask;
  558. X                        visual_template.visualid=
  559. X                          strtol(visual_type,(char **) NULL,0);
  560. X                      }
  561. X                    else
  562. X                      Warning("invalid visual specifier",visual_type);
  563. X    }
  564. X  /*
  565. X    Get all visuals that meet our criteria so far.
  566. X  */
  567. X  number_visuals=0;
  568. X  visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
  569. X    &number_visuals);
  570. X  visual_mask=VisualScreenMask | VisualIDMask;
  571. X  if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
  572. X    {
  573. X      /*
  574. X        Failed to get visual;  try using the default visual.
  575. X      */
  576. X      Warning("unable to get visual",visual_type);
  577. X      visual_template.visualid=
  578. X        XVisualIDFromVisual(XDefaultVisual(display,XDefaultScreen(display)));
  579. X      visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
  580. X        &number_visuals);
  581. X      if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
  582. X        return((XVisualInfo *) NULL);
  583. X      Warning("using default visual",XVisualClassName(visual_list));
  584. X    }
  585. X  if (map_type != (char *) NULL)
  586. X    {
  587. X      Atom
  588. X        map_property;
  589. X
  590. X      char
  591. X        map_name[2048];
  592. X
  593. X      int
  594. X        j,
  595. X        number_maps,
  596. X        status;
  597. X
  598. X      Window
  599. X        root_window;
  600. X
  601. X      XStandardColormap
  602. X        *map_list;
  603. X
  604. X      /*
  605. X        Restrict visual search by Standard Colormap visual id.
  606. X      */
  607. X      (void) sprintf((char *) map_name,"RGB_%s_MAP",map_type);
  608. X      Latin1Upper(map_name);
  609. X      map_property=XInternAtom(display,(char *) map_name,True);
  610. X      if (map_property == (Atom) NULL)
  611. X        Error("unable to get Standard Colormap",map_type);
  612. X      root_window=XRootWindow(display,XDefaultScreen(display));
  613. X      status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
  614. X        map_property);
  615. X      if (status == 0)
  616. X        Error("unable to get Standard Colormap",map_type);
  617. X      /*
  618. X        Search all Standard Colormaps and visuals for ids that match.
  619. X      */
  620. X      *map_info=map_list[0];
  621. #ifndef PRE_R4_ICCCM
  622. X      visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
  623. X      for (i=0; i < number_maps; i++)
  624. X        for (j=0; j < number_visuals; j++)
  625. X          if (map_list[i].visualid ==
  626. X              XVisualIDFromVisual(visual_list[j].visual))
  627. X            {
  628. X              *map_info=map_list[i];
  629. X              visual_template.visualid=
  630. X                XVisualIDFromVisual(visual_list[j].visual);
  631. X              break;
  632. X            }
  633. X      if (map_info->visualid != visual_template.visualid)
  634. X        Error("unable to match visual to Standard Colormap",map_type);
  635. #endif
  636. X      if (map_info->colormap == (Colormap) NULL)
  637. X        Error("Standard Colormap is not initialized",map_type);
  638. X      XFree((void *) map_list);
  639. X    }
  640. X  else
  641. X    {
  642. X      static unsigned int
  643. X        rank[]=
  644. X          {
  645. X            StaticGray,
  646. X            GrayScale,
  647. X            StaticColor,
  648. X            DirectColor,
  649. X            TrueColor,
  650. X            PseudoColor
  651. X          };
  652. X
  653. X      XVisualInfo
  654. X        *p;
  655. X
  656. X      /*
  657. X        Pick one visual that displays the most simultaneous colors.
  658. X      */
  659. X      visual_info=visual_list;
  660. X      p=visual_list;
  661. X      for (i=1; i < number_visuals; i++)
  662. X      {
  663. X        p++;
  664. X        if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
  665. X          visual_info=p;
  666. X        else
  667. X          if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
  668. X            if (rank[p->class] > rank[visual_info->class])
  669. X              visual_info=p;
  670. X      }
  671. X      visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
  672. X    }
  673. X  XFree((void *) visual_list);
  674. X  /*
  675. X    Retrieve only one visual by its screen & id number.
  676. X  */
  677. X  visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
  678. X    &number_visuals);
  679. X  if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
  680. X    return((XVisualInfo *) NULL);
  681. X  return(visual_info);
  682. }
  683. X
  684. /*
  685. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  686. %                                                                             %
  687. %                                                                             %
  688. %                                                                             %
  689. %   X C l i e n t W i n d o w                                                 %
  690. %                                                                             %
  691. %                                                                             %
  692. %                                                                             %
  693. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  694. %
  695. %  Function XClientWindow finds a window, at or below the specified window,
  696. %  which has a WM_STATE property.  If such a window is found, it is returned,
  697. %  otherwise the argument window is returned.
  698. %
  699. %  The format of the XClientWindow function is:
  700. %
  701. %      client_window=XClientWindow(display,target_window)
  702. %
  703. %  A description of each parameter follows:
  704. %
  705. %    o client_window: XClientWindow returns a window, at or below the specified
  706. %      window, which has a WM_STATE property otherwise the argument
  707. %      target_window is returned.
  708. %
  709. %    o display: Specifies a pointer to the Display structure;  returned from
  710. %      XOpenDisplay.
  711. %
  712. %    o target_window: Specifies the window to find a WM_STATE property.
  713. %
  714. %
  715. */
  716. static Window XClientWindow(display,target_window)
  717. Display
  718. X  *display;
  719. X
  720. Window
  721. X  target_window;
  722. {
  723. X  Atom
  724. X    state,
  725. X    type;
  726. X
  727. X  int
  728. X    format,
  729. X    status;
  730. X
  731. X  unsigned char
  732. X    *data;
  733. X
  734. X  unsigned long
  735. X    after,
  736. X    number_items;
  737. X
  738. X  Window
  739. X    client_window;
  740. X
  741. X  state=XInternAtom(display,"WM_STATE",True);
  742. X  if (state == (Atom) NULL)
  743. X    return(target_window);
  744. X  type=(Atom) NULL;
  745. X  status=XGetWindowProperty(display,target_window,state,0L,0L,False,
  746. X    (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
  747. X  if ((status == Success) && (type != (Atom) NULL))
  748. X    return(target_window);
  749. X  client_window=XWindowByProperty(display,target_window,state);
  750. X  if (client_window == (Window) NULL)
  751. X    return(target_window);
  752. X  return(client_window);
  753. }
  754. X
  755. /*
  756. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  757. %                                                                             %
  758. %                                                                             %
  759. %                                                                             %
  760. %   X D i s p l a y I n f o S t r i n g                                       %
  761. %                                                                             %
  762. %                                                                             %
  763. %                                                                             %
  764. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  765. %
  766. %  Function XDisplayInfoString resizes the window to a size determined by the
  767. %  text, the font size and the border.
  768. %
  769. %  The format of the XDisplayInfoString function is:
  770. %
  771. %      XDisplayInfoString(display,window,text,borders)
  772. %
  773. %  A description of each parameter follows:
  774. %
  775. %    o display: Specifies a pointer to the Display structure;  returned from
  776. %      XOpenDisplay.
  777. %
  778. %    o window: Specifies a pointer to a XWindowInfo structure.
  779. %
  780. %    o text: Specifies a pointer to a text string.
  781. %
  782. %
  783. */
  784. void XDisplayInfoString(display,window,text)
  785. Display
  786. X  *display;
  787. X
  788. XXWindowInfo
  789. X  *window;
  790. X
  791. char
  792. X  *text;
  793. {
  794. X  unsigned int
  795. X    height;
  796. X
  797. X  XClearWindow(display,window->id);
  798. X  height=window->font_info->ascent+window->font_info->descent;
  799. X  XDrawImageString(display,window->id,window->graphic_context,
  800. X    (3*window->font_info->max_bounds.width) >> 2,window->font_info->ascent+
  801. X    (height >> 2),text,strlen(text));
  802. }
  803. X
  804. /*
  805. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  806. %                                                                             %
  807. %                                                                             %
  808. %                                                                             %
  809. %   X E r r o r                                                               %
  810. %                                                                             %
  811. %                                                                             %
  812. %                                                                             %
  813. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  814. %
  815. %  Function XError ignores BadWindow errors for XQueryTree and
  816. %  XGetWindowAttributes, and ignores BadDrawable errors for XGetGeometry, and
  817. %  ignores BadValue errors for XQueryColor.  It returns False in those cases.
  818. %  Otherwise it returns True.
  819. %
  820. %  The format of the XError function is:
  821. %
  822. %      XError(display,error)
  823. %
  824. %  A description of each parameter follows:
  825. %
  826. %    o display: Specifies a pointer to the Display structure;  returned from
  827. %      XOpenDisplay.
  828. %
  829. %    o error: Specifies the error event.
  830. %
  831. %
  832. */
  833. int XError(display,error)
  834. Display
  835. X  *display;
  836. X
  837. XXErrorEvent
  838. X  *error;
  839. {
  840. X  switch (error->request_code)
  841. X  {
  842. X    case X_GetGeometry:
  843. X    {
  844. X      if (error->error_code == BadDrawable)
  845. X        return(False);
  846. X      break;
  847. X    }
  848. X    case X_GetWindowAttributes:
  849. X    case X_QueryTree:
  850. X    {
  851. X      if (error->error_code == BadWindow)
  852. X        return(False);
  853. X      break;
  854. X    }
  855. X    case X_QueryColors:
  856. X    {
  857. X      if (error->error_code == BadValue)
  858. X        return(False);
  859. X      break;
  860. X    }
  861. X  }
  862. X  return(True);
  863. }
  864. X
  865. /*
  866. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  867. %                                                                             %
  868. %                                                                             %
  869. %                                                                             %
  870. %   X F r e e S t a n d a r d C o l o r m a p                                 %
  871. %                                                                             %
  872. %                                                                             %
  873. %                                                                             %
  874. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  875. %
  876. %  Function XFreeStandardColormap frees an X11 colormap.
  877. %
  878. %  The format of the XFreeStandardColormap routine is:
  879. %
  880. %      XFreeStandardColormap(display,visual_info,pixel_info,map_info)
  881. %
  882. %  A description of each parameter follows:
  883. %
  884. %    o display: Specifies a connection to an X server; returned from
  885. %      XOpenDisplay.
  886. %
  887. %    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
  888. %      returned from XGetVisualInfo.
  889. %
  890. %    o pixel_info: Specifies a pointer to a XPixelInfo structure.
  891. %
  892. %    o map_info: If map_type is specified, this structure is initialized
  893. %      with info from the Standard Colormap.
  894. %
  895. %
  896. */
  897. void XFreeStandardColormap(display,visual_info,pixel_info,map_info)
  898. Display
  899. X  *display;
  900. X
  901. XXVisualInfo
  902. X  *visual_info;
  903. X
  904. XXPixelInfo
  905. X  *pixel_info;
  906. X
  907. XXStandardColormap
  908. X  *map_info;
  909. {
  910. X  /*
  911. X    Free colormap.
  912. X  */
  913. X  XFlush(display);
  914. X  if (map_info->colormap != (Colormap) NULL)
  915. X    if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
  916. X      XFreeColormap(display,map_info->colormap);
  917. X    else
  918. X      if ((visual_info->class != TrueColor) &&
  919. X          (visual_info->class != DirectColor))
  920. X        XFreeColors(display,map_info->colormap,pixel_info->pixels,
  921. X          (int) pixel_info->colors,0);
  922. X  map_info->colormap=(Colormap) NULL;
  923. X  if (pixel_info->pixels != (unsigned long *) NULL)
  924. X    (void) free((char *) pixel_info->pixels);
  925. X  pixel_info->pixels=(unsigned long *) NULL;
  926. }
  927. X
  928. /*
  929. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  930. %                                                                             %
  931. %                                                                             %
  932. %                                                                             %
  933. %   X G e t A n n o t a t e I n f o                                           %
  934. %                                                                             %
  935. %                                                                             %
  936. %                                                                             %
  937. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  938. %
  939. %  Function XGetAnnotateInfo initializes the AnnotateInfo structure.
  940. %
  941. %  The format of the GetAnnotateInfo routine is:
  942. %
  943. %      XGetAnnotateInfo(image_info)
  944. %
  945. %  A description of each parameter follows:
  946. %
  947. %    o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
  948. %
  949. %
  950. */
  951. void XGetAnnotateInfo(annotate_info)
  952. XXAnnotateInfo
  953. X  *annotate_info;
  954. {
  955. X  /*
  956. X    Initialize annotate structure.
  957. X  */
  958. X  annotate_info->x=0;
  959. X  annotate_info->y=0;
  960. X  annotate_info->width=0;
  961. X  annotate_info->height=0;
  962. X  annotate_info->degrees=0.0;
  963. X  annotate_info->font_info=(XFontStruct *) NULL;
  964. X  annotate_info->text=(char *) NULL;
  965. X  *annotate_info->geometry=(char) NULL;
  966. X  annotate_info->previous=(XAnnotateInfo *) NULL;
  967. X  annotate_info->next=(XAnnotateInfo *) NULL;
  968. }
  969. X
  970. /*
  971. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  972. %                                                                             %
  973. %                                                                             %
  974. %                                                                             %
  975. %   X G e t P i x e l I n f o                                                 %
  976. %                                                                             %
  977. %                                                                             %
  978. %                                                                             %
  979. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  980. %
  981. %  Function XGetPixelInfo initializes the PixelInfo structure.
  982. %
  983. %  The format of the XGetPixelInfo routine is:
  984. %
  985. %      XGetPixelInfo(display,visual_info,map_info,resource_info,image,
  986. %        pixel_info)
  987. %
  988. %  A description of each parameter follows:
  989. %
  990. %    o display: Specifies a connection to an X server; returned from
  991. %      XOpenDisplay.
  992. %
  993. %    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
  994. %      returned from XGetVisualInfo.
  995. %
  996. %    o map_info: If map_type is specified, this structure is initialized
  997. %      with info from the Standard Colormap.
  998. %
  999. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1000. %
  1001. %    o image: Specifies a pointer to a Image structure;  returned from
  1002. %      ReadImage.
  1003. %
  1004. %    o pixel_info: Specifies a pointer to a XPixelInfo structure.
  1005. %
  1006. %
  1007. */
  1008. void XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel_info)
  1009. Display
  1010. X  *display;
  1011. X
  1012. XXVisualInfo
  1013. X  *visual_info;
  1014. X
  1015. XXStandardColormap
  1016. X  *map_info;
  1017. X
  1018. XXResourceInfo
  1019. X  *resource_info;
  1020. X
  1021. Image
  1022. X  *image;
  1023. X
  1024. XXPixelInfo
  1025. X  *pixel_info;
  1026. {
  1027. X  register int
  1028. X    i;
  1029. X
  1030. X  int
  1031. X    status;
  1032. X
  1033. X  unsigned int
  1034. X    packets;
  1035. X
  1036. X  pixel_info->graphic_context=XDefaultGC(display,visual_info->screen);
  1037. X  pixel_info->highlight_context=XDefaultGC(display,visual_info->screen);
  1038. X  pixel_info->colors=0;
  1039. X  if (image != (Image *) NULL)
  1040. X    if (image->class == PseudoClass)
  1041. X      pixel_info->colors=image->colors;
  1042. X  packets=Max(pixel_info->colors,visual_info->colormap_size)+MaxNumberPens;
  1043. X  pixel_info->pixels=(unsigned long *) malloc(packets*sizeof(unsigned long));
  1044. X  if (pixel_info->pixels == (unsigned long *) NULL)
  1045. X    Error("unable to get pixel info","memory allocation failed");
  1046. X  status=XParseColor(display,map_info->colormap,resource_info->background_color,
  1047. X    &pixel_info->background_color);
  1048. X  if (status == 0)
  1049. X    Warning("color is not known to X server",resource_info->background_color);
  1050. X  pixel_info->background_color.pixel=
  1051. X    XStandardPixel(map_info,pixel_info->background_color,16);
  1052. X  pixel_info->background_color.flags=DoRed | DoGreen | DoBlue;
  1053. X  status=XParseColor(display,map_info->colormap,resource_info->border_color,
  1054. X    &pixel_info->border_color);
  1055. X  if (status == 0)
  1056. X    Warning("color is not known to X server",resource_info->border_color);
  1057. X  pixel_info->border_color.pixel=
  1058. X    XStandardPixel(map_info,pixel_info->border_color,16);
  1059. X  pixel_info->border_color.flags=DoRed | DoGreen | DoBlue;
  1060. X  status=XParseColor(display,map_info->colormap,resource_info->foreground_color,
  1061. X    &pixel_info->foreground_color);
  1062. X  if (status == 0)
  1063. X    Warning("color is not known to X server",resource_info->foreground_color);
  1064. X  pixel_info->foreground_color.pixel=
  1065. X    XStandardPixel(map_info,pixel_info->foreground_color,16);
  1066. X  pixel_info->foreground_color.flags=DoRed | DoGreen | DoBlue;
  1067. X  status=XParseColor(display,map_info->colormap,resource_info->highlight_color,
  1068. X    &pixel_info->highlight_color);
  1069. X  if (status == 0)
  1070. X    Warning("color is not known to X server",resource_info->highlight_color);
  1071. X  pixel_info->highlight_color.pixel=
  1072. X    XStandardPixel(map_info,pixel_info->highlight_color,16);
  1073. X  pixel_info->highlight_color.flags=DoRed | DoGreen | DoBlue;
  1074. X  for (i=0; i < MaxNumberPens; i++)
  1075. X  {
  1076. X    status=XParseColor(display,map_info->colormap,resource_info->pen_color[i],
  1077. X      &pixel_info->pen_color[i]);
  1078. X    if (status == 0)
  1079. X      Warning("color is not known to X server",resource_info->pen_color[i]);
  1080. X    pixel_info->pen_color[i].pixel=
  1081. X      XStandardPixel(map_info,pixel_info->pen_color[i],16);
  1082. X    pixel_info->pen_color[i].flags=DoRed | DoGreen | DoBlue;
  1083. X  }
  1084. X  pixel_info->annotate_color=pixel_info->foreground_color;
  1085. X  if (image != (Image *) NULL)
  1086. X    if (image->class == PseudoClass)
  1087. X      {
  1088. X        /*
  1089. X          Initialize pixel array for images of type PseudoClass.
  1090. X        */
  1091. X        for (i=0; i < image->colors; i++)
  1092. X          pixel_info->pixels[i]=XStandardPixel(map_info,image->colormap[i],8);
  1093. X        for (i=0; i < MaxNumberPens; i++)
  1094. X          pixel_info->pixels[image->colors+i]=pixel_info->pen_color[i].pixel;
  1095. X        pixel_info->colors+=MaxNumberPens;
  1096. X      }
  1097. }
  1098. X
  1099. /*
  1100. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1101. %                                                                             %
  1102. %                                                                             %
  1103. %                                                                             %
  1104. %   X G e t R e s o u r c e                                                   %
  1105. %                                                                             %
  1106. %                                                                             %
  1107. %                                                                             %
  1108. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1109. %
  1110. %  Function XGetResource queries the X server for the specified resource name
  1111. %  or class.  If the resource name or class is not defined in the database, the
  1112. %  supplied default value is returned.
  1113. %
  1114. %  The format of the XGetResource routine is:
  1115. %
  1116. %      value=XGetResource(database,client,keyword,resource_default)
  1117. %
  1118. %  A description of each parameter follows:
  1119. %
  1120. %    o value: Function XGetResource returns the resource value associated with
  1121. %      the name or class.  If none is found, the supplied default value is
  1122. %      returned.
  1123. %
  1124. %    o database: Specifies a resource database; returned from
  1125. %      XrmGetStringDatabase.
  1126. %
  1127. %    o client:  Specifies the application name used to retrieve
  1128. %      resource info from the X server database.
  1129. %
  1130. %    o keyword: Specifies the keyword of the value being retrieved.
  1131. %
  1132. %    o resource_default: Specifies the default value to return if the query
  1133. %      fails to find the specified keyword/class.
  1134. %
  1135. %
  1136. */
  1137. char *XGetResource(database,client,keyword,resource_default)
  1138. XXrmDatabase
  1139. X  database;
  1140. X
  1141. char
  1142. X  *client,
  1143. X  *keyword,
  1144. X  *resource_default;
  1145. {
  1146. X  char
  1147. X    *resource_type,
  1148. X    resource_class[2048],
  1149. X    resource_name[2048];
  1150. X
  1151. X  int
  1152. X    status;
  1153. X
  1154. X  XrmValue
  1155. X    resource_value;
  1156. X
  1157. X  if (database == (XrmDatabase) NULL)
  1158. X    return(resource_default);
  1159. X  *resource_name='\0';
  1160. X  *resource_class='\0';
  1161. X  if (keyword != (char *) NULL)
  1162. X    {
  1163. X      unsigned char
  1164. X        c,
  1165. X        k;
  1166. X
  1167. X      /*
  1168. X        Initialize resource keyword and class.
  1169. X      */
  1170. X      (void) sprintf(resource_name,"%s.%s",client,keyword);
  1171. X      c=(*client);
  1172. X      if ((c >= XK_a) && (c <= XK_z))
  1173. X        c-=(XK_a-XK_A);
  1174. X      else
  1175. X        if ((c >= XK_agrave) && (c <= XK_odiaeresis))
  1176. X          c-=(XK_agrave-XK_Agrave);
  1177. X        else
  1178. X          if ((c >= XK_oslash) && (c <= XK_thorn))
  1179. X            c-=(XK_oslash-XK_Ooblique);
  1180. X      k=(*keyword);
  1181. X      if ((k >= XK_a) && (k <= XK_z))
  1182. X        k-=(XK_a-XK_A);
  1183. X      else
  1184. X        if ((k >= XK_agrave) && (k <= XK_odiaeresis))
  1185. X          k-=(XK_agrave-XK_Agrave);
  1186. X        else
  1187. X          if ((k >= XK_oslash) && (k <= XK_thorn))
  1188. X            k-=(XK_oslash-XK_Ooblique);
  1189. X      (void) sprintf(resource_class,"%c%s.%c%s",c,client+1,k,keyword+1);
  1190. X    }
  1191. X  status=XrmGetResource(database,resource_name,resource_class,&resource_type,
  1192. X    &resource_value);
  1193. X  if (status == False)
  1194. X    return(resource_default);
  1195. X  return(resource_value.addr);
  1196. }
  1197. X
  1198. /*
  1199. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1200. %                                                                             %
  1201. %                                                                             %
  1202. %                                                                             %
  1203. %   X G e t R e s o u r c e I n f o                                           %
  1204. %                                                                             %
  1205. %                                                                             %
  1206. %                                                                             %
  1207. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1208. %
  1209. %  Function XGetResourceInfo initializes the ResourceInfo structure.
  1210. %
  1211. %  The format of the XGetResourceInfo routine is:
  1212. %
  1213. %      XGetResourceInfo(resource_database,client_name,resource_info)
  1214. %
  1215. %  A description of each parameter follows:
  1216. %
  1217. %    o resource_database: Specifies a resource database; returned from
  1218. %      XrmGetStringDatabase.
  1219. %
  1220. %    o client_name:  Specifies the application name used to retrieve
  1221. %      resource info from the X server database.
  1222. %
  1223. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1224. %
  1225. %
  1226. */
  1227. void XGetResourceInfo(resource_database,client_name,resource_info)
  1228. XXrmDatabase
  1229. X  resource_database;
  1230. X
  1231. char
  1232. X  *client_name;
  1233. X
  1234. XXResourceInfo
  1235. X  *resource_info;
  1236. {
  1237. X  char
  1238. X    *resource_value;
  1239. X
  1240. X  register char
  1241. X    *p;
  1242. X
  1243. X  /*
  1244. X    Get basename of client.
  1245. X  */
  1246. X  p=client_name+(strlen(client_name)-1);
  1247. X  while ((p > client_name) && (*p != '/'))
  1248. X    p--;
  1249. X  if (*p == '/')
  1250. X    client_name=p+1;
  1251. X  /*
  1252. X    Initialize resource info fields.
  1253. X  */
  1254. X  resource_value=XGetResource(resource_database,client_name,"backdrop","False");
  1255. X  resource_info->backdrop=IsTrue(resource_value);
  1256. X  resource_info->background_color=
  1257. X    XGetResource(resource_database,client_name,"background","black");
  1258. X  resource_info->border_color=
  1259. X    XGetResource(resource_database,client_name,"borderColor","white");
  1260. X  resource_value=XGetResource(resource_database,client_name,"borderWidth","2");
  1261. X  resource_info->border_width=atoi(resource_value);
  1262. X  resource_value=
  1263. X    XGetResource(resource_database,client_name,"colormap","shared");
  1264. X  resource_info->colormap=UndefinedColormap;
  1265. X  if (Latin1Compare("private",resource_value) == 0)
  1266. X    resource_info->colormap=PrivateColormap;
  1267. X  if (Latin1Compare("shared",resource_value) == 0)
  1268. X    resource_info->colormap=SharedColormap;
  1269. X  if (resource_info->colormap == UndefinedColormap)
  1270. X    Warning("unrecognized colormap type",resource_value);
  1271. X  resource_value=XGetResource(resource_database,client_name,"colors","0");
  1272. X  resource_info->number_colors=atoi(resource_value);
  1273. X  resource_value=XGetResource(resource_database,client_name,"colorspace","rgb");
  1274. X  resource_info->colorspace=UndefinedColorspace;
  1275. X  if (Latin1Compare("gray",resource_value) == 0)
  1276. X    resource_info->colorspace=GRAYColorspace;
  1277. X  if (Latin1Compare("rgb",resource_value) == 0)
  1278. X    resource_info->colorspace=RGBColorspace;
  1279. X  if (Latin1Compare("yiq",resource_value) == 0)
  1280. X    resource_info->colorspace=YIQColorspace;
  1281. X  if (Latin1Compare("yuv",resource_value) == 0)
  1282. X    resource_info->colorspace=YUVColorspace;
  1283. X  if (Latin1Compare("xyz",resource_value) == 0)
  1284. X    resource_info->colorspace=XYZColorspace;
  1285. X  if (resource_info->colorspace == UndefinedColorspace)
  1286. X    Warning("unrecognized colorspace type",resource_value);
  1287. X  resource_value=XGetResource(resource_database,client_name,"debug","False");
  1288. X  resource_info->debug=IsTrue(resource_value);
  1289. X  resource_value=XGetResource(resource_database,client_name,"delay","0");
  1290. X  resource_info->delay=atoi(resource_value);
  1291. X  resource_value=XGetResource(resource_database,client_name,"dither","False");
  1292. X  resource_info->dither=IsTrue(resource_value);
  1293. X  resource_info->font=
  1294. X    XGetResource(resource_database,client_name,"font",(char *) NULL);
  1295. X  resource_info->font_name[0]=
  1296. X    XGetResource(resource_database,client_name,"font1","fixed");
  1297. X  resource_info->font_name[1]=
  1298. X    XGetResource(resource_database,client_name,"font2","variable");
  1299. X  resource_info->font_name[2]=
  1300. X    XGetResource(resource_database,client_name,"font3","5x8");
  1301. X  resource_info->font_name[3]=
  1302. X    XGetResource(resource_database,client_name,"font4","6x10");
  1303. X  resource_info->font_name[4]=
  1304. X    XGetResource(resource_database,client_name,"font5","7x13bold");
  1305. X  resource_info->font_name[5]=
  1306. X    XGetResource(resource_database,client_name,"font6","8x13bold");
  1307. X  resource_info->font_name[6]=
  1308. X    XGetResource(resource_database,client_name,"font7","9x15bold");
  1309. X  resource_info->font_name[7]=
  1310. X    XGetResource(resource_database,client_name,"font8","10x20");
  1311. X  resource_info->font_name[8]=
  1312. X    XGetResource(resource_database,client_name,"font9","12x24");
  1313. X  resource_info->foreground_color=
  1314. X    XGetResource(resource_database,client_name,"foreground","white");
  1315. X  resource_info->icon_geometry=
  1316. X    XGetResource(resource_database,client_name,"iconGeometry",(char *) NULL);
  1317. X  resource_value=XGetResource(resource_database,client_name,"gravity","North");
  1318. X  resource_info->gravity=(-1);
  1319. X  if (Latin1Compare("Forget",resource_value) == 0)
  1320. X    resource_info->gravity=ForgetGravity;
  1321. X  if (Latin1Compare("NorthWest",resource_value) == 0)
  1322. X    resource_info->gravity=NorthWestGravity;
  1323. X  if (Latin1Compare("North",resource_value) == 0)
  1324. X    resource_info->gravity=NorthGravity;
  1325. X  if (Latin1Compare("NorthEast",resource_value) == 0)
  1326. X    resource_info->gravity=NorthEastGravity;
  1327. X  if (Latin1Compare("West",resource_value) == 0)
  1328. X    resource_info->gravity=WestGravity;
  1329. X  if (Latin1Compare("Center",resource_value) == 0)
  1330. X    resource_info->gravity=CenterGravity;
  1331. X  if (Latin1Compare("East",resource_value) == 0)
  1332. X    resource_info->gravity=EastGravity;
  1333. X  if (Latin1Compare("SouthWest",resource_value) == 0)
  1334. X    resource_info->gravity=SouthWestGravity;
  1335. X  if (Latin1Compare("South",resource_value) == 0)
  1336. X    resource_info->gravity=SouthGravity;
  1337. X  if (Latin1Compare("SouthEast",resource_value) == 0)
  1338. X    resource_info->gravity=SouthEastGravity;
  1339. X  if (Latin1Compare("Static",resource_value) == 0)
  1340. X    resource_info->gravity=StaticGravity;
  1341. X  if (resource_info->gravity == (-1))
  1342. X    {
  1343. X      Warning("unrecognized gravity type",resource_value);
  1344. X      resource_info->gravity=CenterGravity;
  1345. X    }
  1346. X  resource_info->highlight_color=XGetResource(resource_database,client_name,
  1347. X    "highlightColor",resource_info->border_color);
  1348. X  resource_value=XGetResource(resource_database,client_name,"iconic","False");
  1349. X  resource_info->iconic=IsTrue(resource_value);
  1350. X  resource_info->image_geometry=
  1351. X    XGetResource(resource_database,client_name,"imageGeometry",(char *) NULL);
  1352. X  resource_value=XGetResource(resource_database,client_name,"magnify","2");
  1353. X  resource_info->magnify=atoi(resource_value);
  1354. X  resource_info->map_type=
  1355. X    XGetResource(resource_database,client_name,"map",(char *) NULL);
  1356. X  resource_value=
  1357. X    XGetResource(resource_database,client_name,"monochrome","False");
  1358. X  resource_info->monochrome=IsTrue(resource_value);
  1359. X  resource_info->name=
  1360. X    XGetResource(resource_database,client_name,"name",(char *) NULL);
  1361. X  resource_info->pen_color[0]=
  1362. X    XGetResource(resource_database,client_name,"pen1","black");
  1363. X  resource_info->pen_color[1]=
  1364. X    XGetResource(resource_database,client_name,"pen2","blue");
  1365. X  resource_info->pen_color[2]=
  1366. X    XGetResource(resource_database,client_name,"pen3","cyan");
  1367. X  resource_info->pen_color[3]=
  1368. X    XGetResource(resource_database,client_name,"pen4","green");
  1369. X  resource_info->pen_color[4]=
  1370. X    XGetResource(resource_database,client_name,"pen5","gray");
  1371. X  resource_info->pen_color[5]=
  1372. X    XGetResource(resource_database,client_name,"pen6","red");
  1373. X  resource_info->pen_color[6]=
  1374. X    XGetResource(resource_database,client_name,"pen7","magenta");
  1375. X  resource_info->pen_color[7]=
  1376. X    XGetResource(resource_database,client_name,"pen8","yellow");
  1377. X  resource_info->pen_color[8]=
  1378. X    XGetResource(resource_database,client_name,"pen9","white");
  1379. X  resource_info->server_name=
  1380. X    XGetResource(resource_database,client_name,"serverName",(char *) NULL);
  1381. X  resource_info->title=
  1382. X    XGetResource(resource_database,client_name,"title",(char *) NULL);
  1383. X  resource_value=XGetResource(resource_database,client_name,"treeDepth","0");
  1384. X  resource_info->tree_depth=atoi(resource_value);
  1385. X  resource_value=XGetResource(resource_database,client_name,"update","False");
  1386. X  resource_info->update=IsTrue(resource_value);
  1387. X  resource_value=
  1388. X    XGetResource(resource_database,client_name,"usePixmap","False");
  1389. X  resource_info->use_pixmap=IsTrue(resource_value);
  1390. X  resource_info->visual_type=
  1391. X    XGetResource(resource_database,client_name,"visual",(char *) NULL);
  1392. X  resource_info->write_filename=
  1393. X    XGetResource(resource_database,client_name,"writeFilename",(char *) NULL);
  1394. }
  1395. X
  1396. /*
  1397. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1398. %                                                                             %
  1399. %                                                                             %
  1400. %                                                                             %
  1401. %   X G e t W i n d o w I m a g e                                             %
  1402. %                                                                             %
  1403. %                                                                             %
  1404. %                                                                             %
  1405. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1406. %
  1407. %  Function XGetWindowImage reads an image from the target X window and returns
  1408. %  it.  XGetWindowImage optionally descends the window hierarchy and overlays
  1409. %  the target image with each subwindow image.
  1410. %
  1411. %  The format of the XGetWindowImage routine is:
  1412. %
  1413. %      image=XGetWindowImage(display,window,borders,level)
  1414. %
  1415. %  A description of each parameter follows:
  1416. %
  1417. %    o image: Function XGetWindowImage returns a MIFF image if it can be
  1418. %      successfully read from the X window.  A null image is returned if
  1419. %      any errors occurs.
  1420. %
  1421. %    o display: Specifies a connection to an X server;  returned from
  1422. %      XOpenDisplay.
  1423. %
  1424. %    o window: Specifies the window to obtain the image from.
  1425. %
  1426. %    o borders: Specifies whether borders pixels are to be saved with
  1427. %      the image.
  1428. %
  1429. %    o level: Specifies an unsigned integer representing the level of
  1430. %      decent in the window hierarchy.  This value must be zero or one on
  1431. %      the initial call to XGetWindowImage.  A value of zero returns after
  1432. %      one call.  A value of one causes the function to descend the window
  1433. %      hierarchy and overlays the target image with each subwindow image.
  1434. %
  1435. %
  1436. */
  1437. static Image *XGetWindowImage(display,window,borders,level)
  1438. Display
  1439. X  *display;
  1440. X
  1441. Window
  1442. X  window;
  1443. X
  1444. unsigned int
  1445. X  borders,
  1446. X  level;
  1447. {
  1448. X  typedef struct _ColormapList
  1449. X  {
  1450. X    Colormap
  1451. X      colormap;
  1452. X
  1453. X    XColor
  1454. X      *colors;
  1455. X
  1456. X    struct _ColormapList
  1457. X      *next;
  1458. X  } ColormapList;
  1459. X
  1460. X  GC
  1461. X    graphic_context;
  1462. X
  1463. X  Image
  1464. X    *image;
  1465. X
  1466. X  int
  1467. X    display_height,
  1468. X    display_width,
  1469. X    number_colors,
  1470. X    status,
  1471. X    x_offset,
  1472. X    y_offset;
  1473. X
  1474. X  RectangleInfo
  1475. X    clip_info;
  1476. X
  1477. X  register int
  1478. X    i,
  1479. X    x,
  1480. X    y;
  1481. X
  1482. X  register RunlengthPacket
  1483. X    *p;
  1484. X
  1485. X  register unsigned long
  1486. X    pixel;
  1487. X
  1488. X  static ColormapList
  1489. X    *colormap_list = (ColormapList *) NULL;
  1490. X
  1491. X  Window
  1492. X    child,
  1493. X    root_window;
  1494. X
  1495. X  XColor
  1496. X    *colors;
  1497. X
  1498. X  XGCValues
  1499. X    graphic_context_value;
  1500. X
  1501. X  XImage
  1502. X    *ximage;
  1503. X
  1504. X  XWindowAttributes
  1505. X    window_attributes;
  1506. X
  1507. X  /*
  1508. X    Verify window is viewable.
  1509. X  */
  1510. X  status=XGetWindowAttributes(display,window,&window_attributes);
  1511. X  if ((status == False) || (window_attributes.map_state != IsViewable))
  1512. X    return((Image *) NULL);
  1513. X  /*
  1514. X    Clipping rectangle is relative to root window.
  1515. X  */
  1516. X  root_window=XRootWindow(display,XDefaultScreen(display));
  1517. X  XTranslateCoordinates(display,window,root_window,0,0,&x_offset,&y_offset,
  1518. X    &child);
  1519. X  clip_info.x=x_offset;
  1520. X  clip_info.y=y_offset;
  1521. X  clip_info.width=window_attributes.width;
  1522. X  clip_info.height=window_attributes.height;
  1523. X  if (borders)
  1524. X    {
  1525. X      /*
  1526. X        Include border in image.
  1527. X      */
  1528. X      clip_info.x-=window_attributes.border_width;
  1529. X      clip_info.y-=window_attributes.border_width;
  1530. X      clip_info.width+=2*window_attributes.border_width;
  1531. X      clip_info.height+=2*window_attributes.border_width;
  1532. X    }
  1533. X  /*
  1534. X    Clip to root window.
  1535. X  */
  1536. X  if (clip_info.x < 0)
  1537. X    {
  1538. X      if ((clip_info.x+(int) clip_info.width) < 0)
  1539. X        return((Image *) NULL);
  1540. X      clip_info.width+=clip_info.x;
  1541. X      clip_info.x=0;
  1542. X    }
  1543. X  if (clip_info.y < 0)
  1544. X    {
  1545. X      if ((clip_info.y+(int) clip_info.height) < 0)
  1546. X        return((Image *) NULL);
  1547. X      clip_info.height+=clip_info.y;
  1548. X      clip_info.y=0;
  1549. X    }
  1550. X  display_width=DisplayWidth(display,XDefaultScreen(display));
  1551. SHAR_EOF
  1552. true || echo 'restore of ImageMagick/X.c failed'
  1553. fi
  1554. echo 'End of ImageMagick part 9'
  1555. echo 'File ImageMagick/X.c is continued in part 10'
  1556. echo 10 > _shar_seq_.tmp
  1557. exit 0
  1558.  
  1559. exit 0 # Just in case...
  1560. -- 
  1561.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  1562. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  1563.  "It's intuitively obvious to the |
  1564.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  1565.