home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sources / misc / 4183 < prev    next >
Encoding:
Text File  |  1992-12-14  |  57.5 KB  |  1,929 lines

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: cristy@eplrx7.es.duPont.com (John Cristy)
  4. Subject:  v34i043:  imagemagick - X11 image processing and display v2.2, Part15/26
  5. Message-ID: <1992Dec15.035306.21767@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: 1086d1438ed16b38f0222734314e8700
  8. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  9. Organization: Sterling Software
  10. References: <csm-v34i028=imagemagick.141926@sparky.IMD.Sterling.COM>
  11. Date: Tue, 15 Dec 1992 03:53:06 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 1914
  14.  
  15. Submitted-by: cristy@eplrx7.es.duPont.com (John Cristy)
  16. Posting-number: Volume 34, Issue 43
  17. Archive-name: imagemagick/part15
  18. Environment: UNIX, VMS, X11, SGI, DEC, Cray, Sun, Vax
  19.  
  20. #!/bin/sh
  21. # this is Part.15 (part 15 of a multipart archive)
  22. # do not concatenate these parts, unpack them in order with /bin/sh
  23. # file ImageMagick/X.c continued
  24. #
  25. if test ! -r _shar_seq_.tmp; then
  26.     echo 'Please unpack part 1 first!'
  27.     exit 1
  28. fi
  29. (read Scheck
  30.  if test "$Scheck" != 15; then
  31.     echo Please unpack part "$Scheck" next!
  32.     exit 1
  33.  else
  34.     exit 0
  35.  fi
  36. ) < _shar_seq_.tmp || exit 1
  37. if test ! -f _shar_wnt_.tmp; then
  38.     echo 'x - still skipping ImageMagick/X.c'
  39. else
  40. echo 'x - continuing file ImageMagick/X.c'
  41. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/X.c' &&
  42. X      (image->comments == (char *) NULL))
  43. X    {
  44. X      Warning("unable to allocate image","memory allocation error");
  45. X      DestroyImage(image);
  46. X      return((Image *) NULL);
  47. X    }
  48. X  (void) sprintf(image->comments,"\n  Imported from text file:  %s\n",
  49. X    image->filename);
  50. X  /*
  51. X    Create colormap.
  52. X  */
  53. X  image->colors=2;
  54. X  image->colormap=(ColorPacket *) malloc(image->colors*sizeof(ColorPacket));
  55. X  if (image->colormap == (ColorPacket *) NULL)
  56. X    {
  57. X      Warning("unable to read image","memory allocation failed");
  58. X      DestroyImage(image);
  59. X      return((Image *) NULL);
  60. X    }
  61. X  image->colormap[0].red=pixel_info.background_color.red >> 8;
  62. X  image->colormap[0].green=pixel_info.background_color.green >> 8;
  63. X  image->colormap[0].blue=pixel_info.background_color.blue >> 8;
  64. X  image->colormap[1].red=pixel_info.foreground_color.red >> 8;
  65. X  image->colormap[1].green=pixel_info.foreground_color.green >> 8;
  66. X  image->colormap[1].blue=pixel_info.foreground_color.blue >> 8;
  67. X  /*
  68. X    Initialize text image to background color.
  69. X  */
  70. X  background_color.red=image->colormap[0].red;
  71. X  background_color.green=image->colormap[0].green;
  72. X  background_color.blue=image->colormap[0].blue;
  73. X  background_color.index=0;
  74. X  background_color.length=0;
  75. X  p=image->pixels;
  76. X  for (i=0; i < image->packets; i++)
  77. X    *p++=background_color;
  78. X  /*
  79. X    Annotate the text image.
  80. X  */
  81. X  XGetAnnotateInfo(&annotate_info);
  82. X  annotate_info.font_info=font_info;
  83. X  annotate_info.text=(char *)
  84. X    malloc((image->columns/Max(font_info->min_bounds.width,1)+2)*sizeof(char));
  85. X  if (annotate_info.text == (char *) NULL)
  86. X    {
  87. X      Warning("unable to read image","memory allocation failed");
  88. X      DestroyImage(image);
  89. X      return((Image *) NULL);
  90. X    }
  91. X  image->colormap[0].red=pixel_info.background_color.red >> 8;
  92. X  annotate_info.height=font_info->ascent+font_info->descent;
  93. X  x=0;
  94. X  y=0;
  95. X  text_status=fgets(text,sizeof(text),image->file);
  96. X  if ((int) strlen(text) > 0)
  97. X    text[strlen(text)-1]='\0';
  98. X  while (text_status != (char *) NULL)
  99. X  {
  100. X    *annotate_info.text='\0';
  101. X    if (*text != '\0')
  102. X      {
  103. X        /*
  104. X          Compute width of text.
  105. X        */
  106. X        (void) strcpy(annotate_info.text,text);
  107. X        annotate_info.width=
  108. X          XTextWidth(font_info,annotate_info.text,strlen(annotate_info.text));
  109. X        if ((annotate_info.width+4) >= image->columns)
  110. X          {
  111. X            /*
  112. X              Reduce text until width is within bounds.
  113. X            */
  114. X            i=strlen(annotate_info.text);
  115. X            for (; (annotate_info.width+4) >= image->columns; i--)
  116. X              annotate_info.width=XTextWidth(font_info,annotate_info.text,
  117. X                (unsigned int) i);
  118. X            annotate_info.text[i]='\0';
  119. X            while ((i > 0) && !isspace(annotate_info.text[i]))
  120. X              i--;
  121. X            if (i > 0)
  122. X              annotate_info.text[i]='\0';
  123. X            annotate_info.width=XTextWidth(font_info,annotate_info.text,
  124. X              strlen(annotate_info.text));
  125. X          }
  126. X        /*
  127. X          Annotate image with text.
  128. X        */
  129. X        (void) sprintf(annotate_info.geometry,"%ux%u%+d%+d\0",
  130. X          annotate_info.width,annotate_info.height,x+2,y+2);
  131. X        status=XAnnotateImage(display,&image_window,&annotate_info,False,image);
  132. X        if (status == 0)
  133. X          {
  134. X            Warning("unable to annotate image","memory allocation error");
  135. X            DestroyImage(image);
  136. X            return((Image *) NULL);
  137. X          }
  138. X      }
  139. X    /*
  140. X      Get next string.
  141. X    */
  142. X    if (strlen(text) != strlen(annotate_info.text))
  143. X      (void) strcpy(text,text+strlen(annotate_info.text)+1);
  144. X    else
  145. X      {
  146. X        text_status=fgets(text,sizeof(text),image->file);
  147. X        if ((int) strlen(text) > 0)
  148. X          text[strlen(text)-1]='\0';
  149. X      }
  150. X    y+=annotate_info.height;
  151. X    if ((text_status != (char *) NULL) &&
  152. X        ((y+font_info->ascent+4) > image->rows))
  153. X      {
  154. X        /*
  155. X          Page is full-- allocate next image structure.
  156. X        */
  157. X        image->orphan=True;
  158. X        image->next=CopyImage(image,image->columns,image->rows,False);
  159. X        image->orphan=False;
  160. X        if (image->next == (Image *) NULL)
  161. X          {
  162. X            DestroyImages(image);
  163. X            return((Image *) NULL);
  164. X          }
  165. X        image->next->last=image;
  166. X        image=image->next;
  167. X        /*
  168. X          Initialize text image to background color.
  169. X        */
  170. X        p=image->pixels;
  171. X        for (i=0; i < image->packets; i++)
  172. X          *p++=background_color;
  173. X        y=0;
  174. X      }
  175. X  }
  176. X  /*
  177. X    Free resources.
  178. X  */
  179. X  (void) free((char *) annotate_info.text);
  180. X  XFreeFont(display,font_info);
  181. X  XFree((void *) visual_info);
  182. X  /*
  183. X    Force to runlength-encoded PseudoClass image.
  184. X  */
  185. X  while (image->last != (Image *) NULL)
  186. X  {
  187. X    image->class=PseudoClass;
  188. X    image=image->last;
  189. X  }
  190. X  image->class=PseudoClass;
  191. X  CloseImage(image);
  192. X  XCloseDisplay(display);
  193. X  return(image);
  194. }
  195. X
  196. /*
  197. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  198. %                                                                             %
  199. %                                                                             %
  200. %                                                                             %
  201. %   R e a d X I m a g e                                                       %
  202. %                                                                             %
  203. %                                                                             %
  204. %                                                                             %
  205. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  206. %
  207. %  Procedure ReadXImage reads an image from an X window.
  208. %
  209. %  The format of the ReadXImage routine is:
  210. %
  211. %      image=ReadXImage(filename,server_name,frame,screen,borders)
  212. %
  213. %  A description of each parameter follows:
  214. %
  215. %    o image: Specifies a pointer to the Image structure.
  216. %
  217. %    o filename: Specifies the name of the image to read.
  218. %
  219. %    o server_name: Specifies the name of the X server to read image from.
  220. %
  221. %    o frame: Specifies whether to include the window manager frame with the
  222. %      image.
  223. %
  224. %    o screen: Specifies whether the GetImage request used to obtain the image
  225. %      should be done on the root window, rather than directly on the specified
  226. %      window.
  227. %
  228. %    o borders: Specifies whether borders pixels are to be saved with
  229. %      the image.
  230. %
  231. %
  232. */
  233. Image *ReadXImage(filename,server_name,frame,screen,borders)
  234. char
  235. X  *filename,
  236. X  *server_name;
  237. X
  238. unsigned int
  239. X  frame,
  240. X  screen,
  241. X  borders;
  242. {
  243. X  Display
  244. X    *display;
  245. X
  246. X  Image
  247. X    *image;
  248. X
  249. X  int
  250. X    display_width,
  251. X    display_height,
  252. X    number_colors,
  253. X    status,
  254. X    x,
  255. X    y;
  256. X
  257. X  register int
  258. X    i;
  259. X
  260. X  register RunlengthPacket
  261. X    *p;
  262. X
  263. X  register unsigned long
  264. X    pixel;
  265. X
  266. X  unsigned int
  267. X    d;
  268. X
  269. X  Window
  270. X    client_window,
  271. X    root_window,
  272. X    target_window;
  273. X
  274. X  XColor
  275. X    *colors;
  276. X
  277. X  XImage
  278. X    *ximage;
  279. X
  280. X  XRectangle
  281. X    clip_info;
  282. X
  283. X  XTextProperty
  284. X    window_name;
  285. X
  286. X  XWindowAttributes
  287. X    client_attributes,
  288. X    target_attributes;
  289. X
  290. X  /*
  291. X    Open X server connection.
  292. X  */
  293. X  display=XOpenDisplay(server_name);
  294. X  if (display == (Display *) NULL)
  295. X    {
  296. X      Warning("unable to connect to X server",XDisplayName(server_name));
  297. X      return((Image *) NULL);
  298. X    }
  299. X  /*
  300. X    Set our forgiving error handler.
  301. X  */
  302. X  XSetErrorHandler(XError);
  303. X  /*
  304. X    Select image window.
  305. X  */
  306. X  clip_info.x=0;
  307. X  clip_info.y=0;
  308. X  clip_info.width=0;
  309. X  clip_info.height=0;
  310. X  root_window=XRootWindow(display,XDefaultScreen(display));
  311. X  target_window=(Window) NULL;
  312. X  if ((filename != (char *) NULL) && (*filename != '\0'))
  313. X    if (Latin1Compare(filename,"root") == 0)
  314. X      target_window=root_window;
  315. X    else
  316. X      {
  317. X        if (isdigit(*filename))
  318. X          target_window=XWindowByID(display,root_window,
  319. X            (Window) strtol(filename,(char **) NULL,0));
  320. X        if (target_window == (Window) NULL)
  321. X          target_window=XWindowByName(display,root_window,filename);
  322. X        if (target_window == (Window) NULL)
  323. X          Warning("No window with specified id exists",filename);
  324. X      }
  325. X  if (target_window == (Window) NULL)
  326. X    target_window=XSelectWindow(display,&clip_info);
  327. X  /*
  328. X    Inform the user not to alter the screen.
  329. X  */
  330. X  XBell(display,0);
  331. X  /*
  332. X    Get attributes of the target & client window.
  333. X  */
  334. X  client_window=target_window;
  335. X  if (target_window != root_window)
  336. X    if (XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d) != 0)
  337. X      {
  338. X        /*
  339. X          Get client window.
  340. X        */
  341. X        client_window=XClientWindow(display,target_window);
  342. X        if (!frame)
  343. X          target_window=client_window;
  344. X      }
  345. X  status=XGetWindowAttributes(display,target_window,&target_attributes);
  346. X  status|=XGetWindowAttributes(display,client_window,&client_attributes);
  347. X  if (status == 0)
  348. X    {
  349. X      Warning("unable to get target window attributes",(char *) NULL);
  350. X      return((Image *) NULL);
  351. X    }
  352. X  /*
  353. X    Initialize X image structure.
  354. X  */
  355. X  if ((clip_info.width*clip_info.height) > (unsigned int) 0)
  356. X    ximage=XGetImage(display,root_window,clip_info.x,clip_info.y,
  357. X      clip_info.width,clip_info.height,AllPlanes,ZPixmap);
  358. X  else
  359. X    {
  360. X      unsigned int
  361. X        height,
  362. X        width;
  363. X
  364. X      Window
  365. X        child;
  366. X
  367. X      /*
  368. X        Image by window id.
  369. X      */
  370. X      XTranslateCoordinates(display,target_window,root_window,0,0,&x,&y,&child);
  371. X      target_attributes.x=x;
  372. X      target_attributes.y=y;
  373. X      width=target_attributes.width;
  374. X      height=target_attributes.height;
  375. X      if (borders)
  376. X        {
  377. X          /*
  378. X            Do not include border in image.
  379. X          */
  380. X          x-=target_attributes.border_width;
  381. X          y-=target_attributes.border_width;
  382. X          width+=2*target_attributes.border_width;
  383. X          height+=2*target_attributes.border_width;
  384. X        }
  385. X      /*
  386. X        clip to window
  387. X      */
  388. X      if (x < 0)
  389. X        {
  390. X          width+=x;
  391. X          x=0;
  392. X        }
  393. X      if (y < 0)
  394. X        {
  395. X          height+=y;
  396. X          y=0;
  397. X        }
  398. X      display_width=DisplayWidth(display,XDefaultScreen(display));
  399. X      display_height=DisplayHeight(display,XDefaultScreen(display));
  400. X      if ((x+(int) width) > display_width)
  401. X        width=display_width-x;
  402. X      if ((y+(int) height) > display_height)
  403. X        height=display_height-y;
  404. X      /*
  405. X        Get image from window with XGetImage.
  406. X      */
  407. X      if (screen)
  408. X        ximage=
  409. X          XGetImage(display,root_window,x,y,width,height,AllPlanes,ZPixmap);
  410. X      else
  411. X        {
  412. X          x-=target_attributes.x;
  413. X          y-=target_attributes.y;
  414. X          ximage=XGetImage(display,target_window,x,y,width,height,AllPlanes,
  415. X            ZPixmap);
  416. X        }
  417. X    }
  418. X  if (ximage == (XImage *) NULL)
  419. X    {
  420. X      Warning("unable to read image",(char *) NULL);
  421. X      return((Image *) NULL);
  422. X    }
  423. X  /*
  424. X    Obtain the window colormap from the client of the target window.
  425. X  */
  426. X  number_colors=XReadColormap(display,&client_attributes,&colors);
  427. X  XBell(display,0);
  428. X  XBell(display,0);
  429. X  XFlush(display);
  430. X  /*
  431. X    Allocate image structure.
  432. X  */
  433. X  image=AllocateImage("X");
  434. X  if (image == (Image *) NULL)
  435. X    {
  436. X      Warning("unable to read image","memory allocation failed");
  437. X      return((Image *) NULL);
  438. X    }
  439. X  /*
  440. X    Convert X image to MIFF format.
  441. X  */
  442. X  if (XGetWMName(display,target_window,&window_name) != 0)
  443. X    {
  444. X      if ((filename != (char *) NULL) && (*filename == '\0'))
  445. X        (void) strcpy(image->filename,(char *) window_name.value);
  446. X      /*
  447. X        Initial image comment.
  448. X      */
  449. X      image->comments=(char *)
  450. X        malloc((strlen((char *) window_name.value)+2048)*sizeof(char));
  451. X      if (image->comments == (char *) NULL)
  452. X        {
  453. X          Warning("unable to read image","memory allocation failed");
  454. X          DestroyImage(image);
  455. X          return((Image *) NULL);
  456. X        }
  457. X      (void) sprintf(image->comments,"\n  Imported from X11 window:  %s\n\0",
  458. X        window_name.value);
  459. X    }
  460. X  if ((target_attributes.visual->class != TrueColor) &&
  461. X      (target_attributes.visual->class != DirectColor))
  462. X    image->class=PseudoClass;
  463. X  image->columns=ximage->width;
  464. X  image->rows=ximage->height;
  465. X  image->packets=image->columns*image->rows;
  466. X  image->pixels=(RunlengthPacket *)
  467. X    malloc((unsigned int) image->packets*sizeof(RunlengthPacket));
  468. X  if (image->pixels == (RunlengthPacket *) NULL)
  469. X    {
  470. X      Warning("unable to read image","memory allocation failed");
  471. X      DestroyImage(image);
  472. X      return((Image *) NULL);
  473. X    }
  474. X  p=image->pixels;
  475. X  switch (image->class)
  476. X  {
  477. X    case DirectClass:
  478. X    {
  479. X      register unsigned long
  480. X        color,
  481. X        index;
  482. X
  483. X      unsigned long
  484. X        blue_mask,
  485. X        blue_shift,
  486. X        green_mask,
  487. X        green_shift,
  488. X        red_mask,
  489. X        red_shift;
  490. X
  491. X      /*
  492. X        Determine shift and mask for red, green, and blue.
  493. X      */
  494. X      red_mask=target_attributes.visual->red_mask;
  495. X      red_shift=0;
  496. X      while ((red_mask & 0x01) == 0)
  497. X      {
  498. X        red_mask>>=1;
  499. X        red_shift++;
  500. X      }
  501. X      green_mask=target_attributes.visual->green_mask;
  502. X      green_shift=0;
  503. X      while ((green_mask & 0x01) == 0)
  504. X      {
  505. X        green_mask>>=1;
  506. X        green_shift++;
  507. X      }
  508. X      blue_mask=target_attributes.visual->blue_mask;
  509. X      blue_shift=0;
  510. X      while ((blue_mask & 0x01) == 0)
  511. X      {
  512. X        blue_mask>>=1;
  513. X        blue_shift++;
  514. X      }
  515. X      /*
  516. X        Convert X image to DirectClass packets.
  517. X      */
  518. X      if ((number_colors > 0) &&
  519. X          (target_attributes.visual->class == DirectColor))
  520. X        for (y=0; y < image->rows; y++)
  521. X        {
  522. X          for (x=0; x < image->columns; x++)
  523. X          {
  524. X            pixel=XGetPixel(ximage,x,y);
  525. X            index=(pixel >> red_shift) & red_mask;
  526. X            p->red=(unsigned char) (colors[index].red >> 8);
  527. X            index=(pixel >> green_shift) & green_mask;
  528. X            p->green=(unsigned char) (colors[index].green >> 8);
  529. X            index=(pixel >> blue_shift) & blue_mask;
  530. X            p->blue=(unsigned char) (colors[index].blue >> 8);
  531. X            p->index=0;
  532. X            p->length=0;
  533. X            p++;
  534. X          }
  535. X        }
  536. X      else
  537. X        for (y=0; y < image->rows; y++)
  538. X          for (x=0; x < image->columns; x++)
  539. X          {
  540. X            pixel=XGetPixel(ximage,x,y);
  541. X            color=(pixel >> red_shift) & red_mask;
  542. X            p->red=(unsigned char)
  543. X              ((((unsigned long) color*65535)/red_mask) >> 8);
  544. X            color=(pixel >> green_shift) & green_mask;
  545. X            p->green=(unsigned char)
  546. X              ((((unsigned long) color*65535)/green_mask) >> 8);
  547. X            color=(pixel >> blue_shift) & blue_mask;
  548. X            p->blue=(unsigned char)
  549. X              ((((unsigned long) color*65535)/blue_mask) >> 8);
  550. X            p->index=0;
  551. X            p->length=0;
  552. X            p++;
  553. X          }
  554. X      break;
  555. X    }
  556. X    case PseudoClass:
  557. X    {
  558. X      register unsigned short
  559. X        index;
  560. X
  561. X      /*
  562. X        Create colormap.
  563. X      */
  564. X      image->colors=number_colors;
  565. X      image->colormap=(ColorPacket *) malloc(image->colors*sizeof(ColorPacket));
  566. X      if (image->colormap == (ColorPacket *) NULL)
  567. X        {
  568. X          Warning("unable to read image","memory allocation failed");
  569. X          DestroyImage(image);
  570. X          return((Image *) NULL);
  571. X        }
  572. X      for (i=0; i < image->colors; i++)
  573. X      {
  574. X        image->colormap[colors[i].pixel].red=colors[i].red >> 8;
  575. X        image->colormap[colors[i].pixel].green=colors[i].green >> 8;
  576. X        image->colormap[colors[i].pixel].blue=colors[i].blue >> 8;
  577. X      }
  578. X      /*
  579. X        Convert X image to PseudoClass packets.
  580. X      */
  581. X      for (y=0; y < image->rows; y++)
  582. X        for (x=0; x < image->columns; x++)
  583. X        {
  584. X          pixel=XGetPixel(ximage,x,y);
  585. X          index=(unsigned short) pixel;
  586. X          p->red=image->colormap[index].red;
  587. X          p->green=image->colormap[index].green;
  588. X          p->blue=image->colormap[index].blue;
  589. X          p->index=index;
  590. X          p->length=0;
  591. X          p++;
  592. X        }
  593. X      CompressColormap(image);
  594. X      break;
  595. X    }
  596. X  }
  597. X  /*
  598. X    Free image and colormap.
  599. X  */
  600. X  XDestroyImage(ximage);
  601. X  if (number_colors > 0)
  602. X    (void) free((char *) colors);
  603. X  XCloseDisplay(display);
  604. X  return(image);
  605. }
  606. X
  607. /*
  608. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  609. %                                                                             %
  610. %                                                                             %
  611. %                                                                             %
  612. %  R e a d X C I m a g e                                                      %
  613. %                                                                             %
  614. %                                                                             %
  615. %                                                                             %
  616. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  617. %
  618. %  Function ReadXCImage creates a constant image and initializes to the
  619. %  background color of the X server and returns it.  It allocates the memory
  620. %  necessary for the new Image structure and returns a pointer to the new
  621. %  image.
  622. %
  623. %  The format of the ReadXCImage routine is:
  624. %
  625. %      image=ReadXCImage(filename,server_name,density)
  626. %
  627. %  A description of each parameter follows:
  628. %
  629. %    o image:  Function ReadXCImage returns a pointer to the image after
  630. %      creating it. A null image is returned if there is a a memory shortage
  631. %      or if the image cannot be read.
  632. %
  633. %    o filename: Specifies the name of the image to read.
  634. %
  635. %    o server_name: Specifies the name of the X server to read fonts from.
  636. %
  637. %    o density: Specifies the vertical and horizonal density of the image.
  638. %
  639. %
  640. */
  641. Image *ReadXCImage(filename,server_name,geometry)
  642. char
  643. X  *filename,
  644. X  *server_name,
  645. X  *geometry;
  646. {
  647. X  char
  648. X    *resource_value;
  649. X
  650. X  Display
  651. X    *display;
  652. X
  653. X  Image
  654. X    *image;
  655. X
  656. X  int
  657. X    x,
  658. X    y;
  659. X
  660. X  register int
  661. X    i;
  662. X
  663. X  register RunlengthPacket
  664. X    *p;
  665. X
  666. X  unsigned int
  667. X    height,
  668. X    width;
  669. X
  670. X  XPixelInfo
  671. X    pixel_info;
  672. X
  673. X  XResourceInfo
  674. X    resource_info;
  675. X
  676. X  XrmDatabase
  677. X    resource_database,
  678. X    server_database;
  679. X
  680. X  XStandardColormap
  681. X    map_info;
  682. X
  683. X  XVisualInfo
  684. X    *visual_info;
  685. X
  686. X  /*
  687. X    Allocate image structure.
  688. X  */
  689. X  image=AllocateImage("XC");
  690. X  if (image == (Image *) NULL)
  691. X    return((Image *) NULL);
  692. X  (void) strcpy(image->filename,filename);
  693. X  /*
  694. X    Open X server connection.
  695. X  */
  696. X  display=XOpenDisplay(server_name);
  697. X  if (display == (Display *) NULL)
  698. X    {
  699. X      Warning("unable to connect to X server",XDisplayName(server_name));
  700. X      return((Image *) NULL);
  701. X    }
  702. X  /*
  703. X    Set our forgiving error handler.
  704. X  */
  705. X  XSetErrorHandler(XError);
  706. X  /*
  707. X    Initialize resource database.
  708. X  */
  709. X  XrmInitialize();
  710. X  resource_database=XrmGetDatabase(display);
  711. X  resource_value=XResourceManagerString(display);
  712. X  if (resource_value == (char *) NULL)
  713. X    resource_value="";
  714. X  server_database=XrmGetStringDatabase(resource_value);
  715. X  XrmMergeDatabases(server_database,&resource_database);
  716. X  /*
  717. X    Get user defaults from X resource database.
  718. X  */
  719. X  XGetResourceInfo(resource_database,application_name,&resource_info);
  720. X  /*
  721. X    Initialize visual info.
  722. X  */
  723. X  visual_info=XBestVisualInfo(display,"default",(char *) NULL,
  724. X    (XStandardColormap *) NULL);
  725. X  if (visual_info == (XVisualInfo *) NULL)
  726. X    {
  727. X      Warning("unable to get visual",resource_info.visual_type);
  728. X      return((Image *) NULL);
  729. X    }
  730. X  /*
  731. X    Determine background foreground colors.
  732. X  */
  733. X  map_info.colormap=XDefaultColormap(display,visual_info->screen);
  734. X  XGetPixelInfo(display,visual_info,&map_info,&resource_info,(Image *) NULL,
  735. X    &pixel_info);
  736. X  /*
  737. X    Initialize Image structure.
  738. X  */
  739. X  width=512;
  740. X  height=512;
  741. X  if (geometry != (char *) NULL)
  742. X    (void) XParseGeometry(geometry,&x,&y,&width,&height);
  743. X  image->columns=width;
  744. X  image->rows=height;
  745. X  image->packets=image->columns*image->rows;
  746. X  image->pixels=(RunlengthPacket *)
  747. X    malloc((unsigned int) image->packets*sizeof(RunlengthPacket));
  748. X  image->comments=(char *) malloc((strlen(image->filename)+2048)*sizeof(char));
  749. X  if ((image->pixels == (RunlengthPacket *) NULL) ||
  750. X      (image->comments == (char *) NULL))
  751. X    {
  752. X      Warning("unable to allocate image","memory allocation error");
  753. X      DestroyImage(image);
  754. X      return((Image *) NULL);
  755. X    }
  756. X  (void) sprintf(image->comments,"\n  Imported from constant file:  %s\n",
  757. X    image->filename);
  758. X  /*
  759. X    Create colormap.
  760. X  */
  761. X  image->colors=1;
  762. X  image->colormap=(ColorPacket *) malloc(image->colors*sizeof(ColorPacket));
  763. X  if (image->colormap == (ColorPacket *) NULL)
  764. X    {
  765. X      Warning("unable to create image","memory allocation failed");
  766. X      DestroyImage(image);
  767. X      return((Image *) NULL);
  768. X    }
  769. X  image->colormap[0].red=pixel_info.background_color.red >> 8;
  770. X  image->colormap[0].green=pixel_info.background_color.red >> 8;
  771. X  image->colormap[0].blue=pixel_info.background_color.red >> 8;
  772. X  p=image->pixels;
  773. X  for (i=0; i < (image->columns*image->rows); i++)
  774. X  {
  775. X    p->red=image->colormap[0].red;
  776. X    p->green=image->colormap[0].green;
  777. X    p->blue=image->colormap[0].blue;
  778. X    p->index=0;
  779. X    p->length=0;
  780. X    p++;
  781. X  }
  782. X  /*
  783. X    Free resources.
  784. X  */
  785. X  XFree((void *) visual_info);
  786. X  XCloseDisplay(display);
  787. X  return(image);
  788. }
  789. X
  790. /*
  791. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  792. %                                                                             %
  793. %                                                                             %
  794. %                                                                             %
  795. %   X A n n o t a t e I m a g e                                               %
  796. %                                                                             %
  797. %                                                                             %
  798. %                                                                             %
  799. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  800. %
  801. %  Function XAnnotateImage annotates the image with text.
  802. %
  803. %  The format of the XAnnotateImage routine is:
  804. %
  805. %    status=XAnnotateImage(display,window,annotate_info,background,image)
  806. %
  807. %  A description of each parameter follows:
  808. %
  809. %    o status: Function XAnnotateImage returns True if the image is
  810. %      successfully annotated with text.  False is returned is there is a
  811. %      memory shortage.
  812. %
  813. %    o display: Specifies a connection to an X server;  returned from
  814. %      XOpenDisplay.
  815. %
  816. %    o window: Specifies a pointer to a XWindowInfo structure.
  817. %
  818. %    o text: Specifies the text to annotate the image.
  819. %
  820. %    o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
  821. %
  822. %    o background: Specifies whether the background color is included in
  823. %      the annotation.  Must be either True or False;
  824. %
  825. %    o image: Specifies a pointer to a Image structure;  returned from
  826. %      ReadImage.
  827. %
  828. %
  829. */
  830. unsigned int XAnnotateImage(display,window,annotate_info,background,image)
  831. Display
  832. X  *display;
  833. X
  834. XXWindowInfo
  835. X  *window;
  836. X
  837. XXAnnotateInfo
  838. X  *annotate_info;
  839. X
  840. unsigned int
  841. X  background;
  842. X
  843. Image
  844. X  *image;
  845. {
  846. X  GC
  847. X    graphic_context;
  848. X
  849. X  Image
  850. X    *annotate_image;
  851. X
  852. X  int
  853. X    x,
  854. X    y;
  855. X
  856. X  Pixmap
  857. X    annotate_pixmap;
  858. X
  859. X  register short int
  860. X    pixel;
  861. X
  862. X  register RunlengthPacket
  863. X    *p,
  864. X    *q;
  865. X
  866. X  RunlengthPacket
  867. X    background_color;
  868. X
  869. X  unsigned int
  870. X    height,
  871. X    width;
  872. X
  873. X  XGCValues
  874. X    graphic_context_value;
  875. X
  876. X  XImage
  877. X    *annotate_ximage;
  878. X
  879. X  XPixelInfo
  880. X    *pixel_info;
  881. X
  882. X  /*
  883. X    Initialize annotated image.
  884. X  */
  885. X  if (image->packets != (image->columns*image->rows))
  886. X    if (!UncompressImage(image))
  887. X      return(False);
  888. X  /*
  889. X    Initialize annotated pixmap.
  890. X  */
  891. X  annotate_pixmap=XCreatePixmap(display,window->id,annotate_info->width,
  892. X    annotate_info->height,window->depth);
  893. X  if (annotate_pixmap == (Pixmap) NULL)
  894. X    return(False);
  895. X  /*
  896. X    Initialize graphics info.
  897. X  */
  898. X  graphic_context_value.background=0;
  899. X  graphic_context_value.foreground=(~0);
  900. X  graphic_context_value.font=annotate_info->font_info->fid;
  901. X  graphic_context=XCreateGC(display,window->id,GCBackground | GCFont |
  902. X    GCForeground,&graphic_context_value);
  903. X  if (graphic_context == (GC) NULL)
  904. X    return(False);
  905. X  /*
  906. X    Draw text to pixmap.
  907. X  */
  908. X  XDrawImageString(display,annotate_pixmap,graphic_context,0,
  909. X    annotate_info->font_info->ascent,annotate_info->text,
  910. X    strlen(annotate_info->text));
  911. X  XFreeGC(display,graphic_context);
  912. X  /*
  913. X    Initialize annotated X image.
  914. X  */
  915. X  annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
  916. X    annotate_info->height,AllPlanes,ZPixmap);
  917. X  if (annotate_ximage == (XImage *) NULL)
  918. X    return(False);
  919. X  XFreePixmap(display,annotate_pixmap);
  920. X  /*
  921. X    Initialize annotated image.
  922. X  */
  923. X  annotate_image=AllocateImage("MIFF");
  924. X  if (annotate_image == (Image *) NULL)
  925. X    return(False);
  926. X  annotate_image->columns=annotate_info->width;
  927. X  annotate_image->rows=annotate_info->height;
  928. X  annotate_image->packets=annotate_image->columns*annotate_image->rows;
  929. X  annotate_image->pixels=(RunlengthPacket *)
  930. X    malloc((unsigned int) image->packets*sizeof(RunlengthPacket));
  931. X  if (annotate_image->pixels == (RunlengthPacket *) NULL)
  932. X    {
  933. X      DestroyImage(annotate_image);
  934. X      return(False);
  935. X    }
  936. X  /*
  937. X    Transfer annotated X image to image.
  938. X  */
  939. X  pixel_info=window->pixel_info;
  940. X  q=annotate_image->pixels;
  941. X  for (y=0; y < annotate_image->rows; y++)
  942. X    for (x=0; x < annotate_image->columns; x++)
  943. X    {
  944. X      pixel=(short int) XGetPixel(annotate_ximage,x,y);
  945. X      if (pixel == 0)
  946. X        {
  947. X          /*
  948. X            Set this pixel to the background color.
  949. X          */
  950. X          q->red=pixel_info->background_color.red >> 8;
  951. X          q->green=pixel_info->background_color.green >> 8;
  952. X          q->blue=pixel_info->background_color.blue >> 8;
  953. X          q->index=pixel_info->background_index;
  954. X        }
  955. X      else
  956. X        {
  957. X          /*
  958. X            Set this pixel to the pen color.
  959. X          */
  960. X          q->red=pixel_info->annotate_color.red >> 8;
  961. X          q->green=pixel_info->annotate_color.green >> 8;
  962. X          q->blue=pixel_info->annotate_color.blue >> 8;
  963. X          q->index=pixel_info->annotate_index;
  964. X        }
  965. X      q->length=0;
  966. X      q++;
  967. X    }
  968. X  XDestroyImage(annotate_ximage);
  969. X  /*
  970. X    Determine annotate geometry.
  971. X  */
  972. X  (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
  973. X  if ((width != annotate_image->columns) || (height != annotate_image->rows))
  974. X    TransformImage(&annotate_image,(char *) NULL,
  975. X      annotate_info->geometry,(char *) NULL);
  976. X  if (annotate_info->degrees != 0.0)
  977. X    {
  978. X      Image
  979. X        *rotated_image;
  980. X
  981. X      /*
  982. X        Rotate image.
  983. X      */
  984. X      rotated_image=RotateImage(annotate_image,annotate_info->degrees,False);
  985. X      if (rotated_image == (Image *) NULL)
  986. X        return(False);
  987. X      DestroyImage(annotate_image);
  988. X      annotate_image=rotated_image;
  989. X    }
  990. X  /*
  991. X    Paste annotated image to image.
  992. X  */
  993. X  background_color.red=pixel_info->background_color.red >> 8;
  994. X  background_color.green=pixel_info->background_color.green >> 8;
  995. X  background_color.blue=pixel_info->background_color.blue >> 8;
  996. X  image->class=DirectClass;
  997. X  p=annotate_image->pixels;
  998. X  q=image->pixels+y*image->columns+x;
  999. X  for (y=0; y < annotate_image->rows; y++)
  1000. X  {
  1001. X    for (x=0; x < annotate_image->columns; x++)
  1002. X    {
  1003. X      if ((p->red != background_color.red) ||
  1004. X          (p->green != background_color.green) ||
  1005. X          (p->blue != background_color.blue))
  1006. X        {
  1007. X          /*
  1008. X            Set this pixel to the pen color.
  1009. X          */
  1010. X          *q=(*p);
  1011. X          q->index=pixel_info->annotate_index;
  1012. X        }
  1013. X      else
  1014. X        if (background)
  1015. X          {
  1016. X            /*
  1017. X              Set this pixel to the background color.
  1018. X            */
  1019. X            *q=(*p);
  1020. X            q->index=pixel_info->background_index;
  1021. X          }
  1022. X      p++;
  1023. X      q++;
  1024. X    }
  1025. X    q+=image->columns-annotate_image->columns;
  1026. X  }
  1027. X  DestroyImage(annotate_image);
  1028. X  return(True);
  1029. }
  1030. X
  1031. /*
  1032. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1033. %                                                                             %
  1034. %                                                                             %
  1035. %                                                                             %
  1036. %   X B e s t F o n t                                                         %
  1037. %                                                                             %
  1038. %                                                                             %
  1039. %                                                                             %
  1040. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1041. %
  1042. %  Function XBestFont returns the "best" font.  "Best" is defined as a font
  1043. %  specified in the X resource database or a font such that the text width
  1044. %  displayed with the font does not exceed the specified maximum width.
  1045. %
  1046. %  The format of the XBestFont routine is:
  1047. %
  1048. %      font=XBestFont(display,resource_info,text,maximum_width)
  1049. %
  1050. %  A description of each parameter follows:
  1051. %
  1052. %    o font: XBestFont returns a pointer to a XFontStruct structure.
  1053. %
  1054. %    o display: Specifies a connection to an X server;  returned from
  1055. %      XOpenDisplay.
  1056. %
  1057. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1058. %
  1059. %    o text: Specifies the text whose width is compared to the maximum.
  1060. %
  1061. %    o maximum_width: Specifies the maximum width in pixels of the text.
  1062. %
  1063. %
  1064. */
  1065. XXFontStruct *XBestFont(display,resource_info,text,maximum_width)
  1066. Display
  1067. X  *display;
  1068. X
  1069. XXResourceInfo
  1070. X  *resource_info;
  1071. X
  1072. char
  1073. X  *text;
  1074. X
  1075. unsigned int
  1076. X  maximum_width;
  1077. {
  1078. X  static char
  1079. X    *fonts[]=
  1080. X    {
  1081. X      "fixed",
  1082. X      "9x15",
  1083. X      "6x13",
  1084. X      "6x10",
  1085. X      (char *) NULL
  1086. X    };
  1087. X
  1088. X  char
  1089. X    *font_name,
  1090. X    **p;
  1091. X
  1092. X  unsigned int
  1093. X    width;
  1094. X
  1095. X  XFontStruct
  1096. X    *font_info;
  1097. X
  1098. X  font_info=(XFontStruct *) NULL;
  1099. X  font_name=resource_info->font;
  1100. X  if (font_name != (char *) NULL)
  1101. X    {
  1102. X      /*
  1103. X        Load preferred font specified in the X resource database.
  1104. X      */
  1105. X      font_info=XLoadQueryFont(display,font_name);
  1106. X      if (font_info == (XFontStruct *) NULL)
  1107. X        Warning("unable to load font",font_name);
  1108. X    }
  1109. X  else
  1110. X    if (text != (char *) NULL)
  1111. X      {
  1112. X        /*
  1113. X          Load a font that does not exceed the text width.
  1114. X        */
  1115. X        for (p=fonts; *p != (char *) NULL; p++)
  1116. X        {
  1117. X          if (font_info != (XFontStruct *) NULL)
  1118. X            {
  1119. X              width=XTextWidth(font_info,text,strlen(text))+
  1120. X                2*font_info->max_bounds.width+2*WindowBorderWidth;
  1121. X              if (width < maximum_width)
  1122. X                break;
  1123. X              font_name=(*p);
  1124. X              XFreeFont(display,font_info);
  1125. X            }
  1126. X          font_info=XLoadQueryFont(display,*p);
  1127. X        }
  1128. X      }
  1129. X  if (font_info == (XFontStruct *) NULL)
  1130. X    font_info=XLoadQueryFont(display,"fixed");  /* backup font */
  1131. X  if (font_info == (XFontStruct *) NULL)
  1132. X    font_info=XLoadQueryFont(display,"variable");  /* backup font */
  1133. X  return(font_info);
  1134. }
  1135. X
  1136. /*
  1137. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1138. %                                                                             %
  1139. %                                                                             %
  1140. %                                                                             %
  1141. %   X B e s t I c o n S i z e                                                 %
  1142. %                                                                             %
  1143. %                                                                             %
  1144. %                                                                             %
  1145. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1146. %
  1147. %  Function XBestIconSize returns the "best" icon size.  "Best" is defined as
  1148. %  an icon size that maintains the aspect ratio of the image.  If the window
  1149. %  manager has preferred icon sizes, one of the preferred sizes is used.
  1150. %
  1151. %  The format of the XBestIconSize routine is:
  1152. %
  1153. %      XBestIconSize(display,window,image)
  1154. %
  1155. %  A description of each parameter follows:
  1156. %
  1157. %    o display: Specifies a connection to an X server;  returned from
  1158. %      XOpenDisplay.
  1159. %
  1160. %    o image: Specifies a pointer to a Image structure;  returned from
  1161. %      ReadImage.
  1162. %
  1163. %
  1164. */
  1165. void XBestIconSize(display,window,image)
  1166. Display
  1167. X  *display;
  1168. X
  1169. XXWindowInfo
  1170. X  *window;
  1171. X
  1172. Image
  1173. X  *image;
  1174. {
  1175. #define MaxIconSize  64
  1176. X
  1177. X  int
  1178. X    number_sizes;
  1179. X
  1180. X  unsigned int
  1181. X    icon_height,
  1182. X    icon_width;
  1183. X
  1184. X  unsigned long int
  1185. X    scale_factor;
  1186. X
  1187. X  Window
  1188. X    root_window;
  1189. X
  1190. X  XIconSize
  1191. X    *icon_size,
  1192. X    *size_list;
  1193. X
  1194. X  /*
  1195. X    Determine if the window manager has specified preferred icon sizes.
  1196. X  */
  1197. X  window->width=MaxIconSize;
  1198. X  window->height=MaxIconSize;
  1199. X  icon_size=(XIconSize *) NULL;
  1200. X  number_sizes=0;
  1201. X  root_window=XRootWindow(display,window->screen);
  1202. X  if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
  1203. X    if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
  1204. X      icon_size=size_list;
  1205. X  if (icon_size == (XIconSize *) NULL)
  1206. X    {
  1207. X      /*
  1208. X        Window manager does not restrict icon size.
  1209. X      */
  1210. X      icon_size=XAllocIconSize();
  1211. X      if (icon_size == (XIconSize *) NULL)
  1212. X        {
  1213. X          Warning("unable to choose best icon size","memory allocation failed");
  1214. X          return;
  1215. X        }
  1216. X      icon_size->min_width=1;
  1217. X      icon_size->max_width=MaxIconSize;
  1218. X      icon_size->min_height=1;
  1219. X      icon_size->max_height=MaxIconSize;
  1220. X      icon_size->width_inc=1;
  1221. X      icon_size->height_inc=1;
  1222. X    }
  1223. X  /*
  1224. X    Look for an icon size that maintains the aspect ratio of image.
  1225. X  */
  1226. X  scale_factor=UpShift(icon_size->max_width)/image->columns;
  1227. X  if (scale_factor > (UpShift(icon_size->max_height)/image->rows))
  1228. X    scale_factor=UpShift(icon_size->max_height)/image->rows;
  1229. X  icon_width=icon_size->min_width;
  1230. X  while (icon_width < icon_size->max_width)
  1231. X  {
  1232. X    if (icon_width >= (DownShift(image->columns*scale_factor)))
  1233. X      break;
  1234. X    icon_width+=icon_size->width_inc;
  1235. X  }
  1236. X  icon_height=icon_size->min_height;
  1237. X  while (icon_height < icon_size->max_height)
  1238. X  {
  1239. X    if (icon_height >= (DownShift(image->rows*scale_factor)))
  1240. X      break;
  1241. X    icon_height+=icon_size->height_inc;
  1242. X  }
  1243. X  XFree((void *) icon_size);
  1244. X  window->width=icon_width;
  1245. X  window->height=icon_height;
  1246. }
  1247. X
  1248. /*
  1249. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1250. %                                                                             %
  1251. %                                                                             %
  1252. %                                                                             %
  1253. %   X B e s t P i x e l                                                       %
  1254. %                                                                             %
  1255. %                                                                             %
  1256. %                                                                             %
  1257. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1258. %
  1259. %  Function XBestPixel returns a pixel from an array of pixels that is closest
  1260. %  to the requested color.
  1261. %
  1262. %  The format of the XBestPixel routine is:
  1263. %
  1264. %      pixel=XBestPixel(colors,number_colors,color)
  1265. %
  1266. %  A description of each parameter follows:
  1267. %
  1268. %    o pixel: XBestPixel returns the pixel value closest to the requested
  1269. %      color.
  1270. %
  1271. %    o colors: Specifies an array of XColor structures.
  1272. %
  1273. %    o number_colors: Specifies the number of XColor structures in the
  1274. %      color definition array.
  1275. %
  1276. %    o color: Specifies the desired RGB value to find in the colors array.
  1277. %
  1278. %
  1279. */
  1280. static void XBestPixel(colors,number_colors,color)
  1281. XXColor
  1282. X  *colors;
  1283. X
  1284. unsigned int
  1285. X  number_colors;
  1286. X
  1287. XXColor
  1288. X  *color;
  1289. {
  1290. X  register int
  1291. X    blue_distance,
  1292. X    green_distance,
  1293. X    i,
  1294. X    red_distance;
  1295. X
  1296. X  register unsigned long
  1297. X    distance,
  1298. X    min_distance;
  1299. X
  1300. X  /*
  1301. X    Find closest representation for the requested RGB color.
  1302. X  */
  1303. X  color->pixel=0;
  1304. X  min_distance=(~0);
  1305. X  for (i=0; i < number_colors; i++)
  1306. X  {
  1307. X    red_distance=(colors[i].red >> 8)-(color->red >> 8);
  1308. X    green_distance=(colors[i].green >> 8)-(color->green >> 8);
  1309. X    blue_distance=(colors[i].blue >> 8)-(color->blue >> 8);
  1310. X    distance=red_distance*red_distance+green_distance*green_distance+
  1311. X      blue_distance*blue_distance;
  1312. X    if (distance < min_distance)
  1313. X      {
  1314. X        min_distance=distance;
  1315. X        color->pixel=colors[i].pixel;
  1316. X      }
  1317. X  }
  1318. X  return;
  1319. }
  1320. X
  1321. /*
  1322. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1323. %                                                                             %
  1324. %                                                                             %
  1325. %                                                                             %
  1326. %   X B e s t V i s u a l I n f o                                             %
  1327. %                                                                             %
  1328. %                                                                             %
  1329. %                                                                             %
  1330. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1331. %
  1332. %  Function XBestVisualInfo returns visual information for a visual that is
  1333. %  the "best" the server supports.  "Best" is defined as:
  1334. %
  1335. %    1. Restrict the visual list to those supported by the default screen.
  1336. %
  1337. %    2. If a visual type is specified, restrict the visual list to those of
  1338. %       that type.
  1339. %
  1340. %    3. If a map type is specified, choose the visual that matches the id
  1341. %       specified by the Standard Colormap.
  1342. %
  1343. %    4  From the list of visuals, choose one that can display the most
  1344. %       simultaneous colors.  If more than one visual can display the same
  1345. %       number of simultaneous colors, one is choosen based on a rank.
  1346. %
  1347. %  The format of the XBestVisualInfo routine is:
  1348. %
  1349. %      visual_info=XBestVisualInfo(display,visual_type,map_type,map_info)
  1350. %
  1351. %  A description of each parameter follows:
  1352. %
  1353. %    o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
  1354. %      structure.
  1355. %
  1356. %    o display: Specifies a connection to an X server;  returned from
  1357. %      XOpenDisplay.
  1358. %
  1359. %    o visual_type: Specifies the desired visual type.
  1360. %
  1361. %    o map_type: Specifies the desired Standard Colormap type.
  1362. %
  1363. %    o map_info: If map_type is specified, this structure is initialized
  1364. %      with info from the Standard Colormap.
  1365. %
  1366. %
  1367. */
  1368. XXVisualInfo *XBestVisualInfo(display,visual_type,map_type,map_info)
  1369. Display
  1370. X  *display;
  1371. X
  1372. char
  1373. X  *visual_type,
  1374. X  *map_type;
  1375. X
  1376. XXStandardColormap
  1377. X  *map_info;
  1378. {
  1379. #define XVisualColormapSize(visual_info) \
  1380. X  ((visual_info->class == TrueColor) || (visual_info->class == DirectColor) ? \
  1381. X    visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
  1382. X    visual_info->colormap_size)
  1383. X
  1384. X  int
  1385. X    number_visuals;
  1386. X
  1387. X  register int
  1388. X    i;
  1389. X
  1390. X  unsigned int
  1391. X    visual_mask;
  1392. X
  1393. X  XVisualInfo
  1394. X    *visual_info,
  1395. X    *visual_list,
  1396. X    visual_template;
  1397. X
  1398. X  /*
  1399. X    Restrict visual search by screen number.
  1400. X  */
  1401. X  visual_mask=VisualScreenMask;
  1402. X  visual_template.screen=XDefaultScreen(display);
  1403. X  if (visual_type != (char *) NULL)
  1404. X    {
  1405. X      /*
  1406. X        Restrict visual search by class or visual id.
  1407. X      */
  1408. X      if (Latin1Compare("staticgray",visual_type) == 0)
  1409. X        {
  1410. X          visual_mask|=VisualClassMask;
  1411. X          visual_template.class=StaticGray;
  1412. X        }
  1413. X      else
  1414. X        if (Latin1Compare("grayscale",visual_type) == 0)
  1415. X          {
  1416. X            visual_mask|=VisualClassMask;
  1417. X            visual_template.class=GrayScale;
  1418. X          }
  1419. X        else
  1420. X          if (Latin1Compare("staticcolor",visual_type) == 0)
  1421. X            {
  1422. X              visual_mask|=VisualClassMask;
  1423. X              visual_template.class=StaticColor;
  1424. X            }
  1425. X          else
  1426. X            if (Latin1Compare("pseudocolor",visual_type) == 0)
  1427. X              {
  1428. X                visual_mask|=VisualClassMask;
  1429. X                visual_template.class=PseudoColor;
  1430. X              }
  1431. X            else
  1432. X              if (Latin1Compare("truecolor",visual_type) == 0)
  1433. X                {
  1434. X                  visual_mask|=VisualClassMask;
  1435. X                  visual_template.class=TrueColor;
  1436. X                }
  1437. X              else
  1438. X                if (Latin1Compare("directcolor",visual_type) == 0)
  1439. X                  {
  1440. X                    visual_mask|=VisualClassMask;
  1441. X                    visual_template.class=DirectColor;
  1442. X                  }
  1443. X                else
  1444. X                  if (Latin1Compare("default",visual_type) == 0)
  1445. X                    {
  1446. X                      visual_mask|=VisualIDMask;
  1447. X                      visual_template.visualid=XVisualIDFromVisual(
  1448. X                        XDefaultVisual(display,XDefaultScreen(display)));
  1449. X                    }
  1450. X                  else
  1451. X                    if (isdigit(*visual_type))
  1452. X                      {
  1453. X                        visual_mask|=VisualIDMask;
  1454. X                        visual_template.visualid=
  1455. X                          strtol(visual_type,(char **) NULL,0);
  1456. X                      }
  1457. X                    else
  1458. X                      Warning("invalid visual specifier",visual_type);
  1459. X    }
  1460. X  /*
  1461. X    Get all visuals that meet our criteria so far.
  1462. X  */
  1463. X  number_visuals=0;
  1464. X  visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
  1465. X    &number_visuals);
  1466. X  visual_mask=VisualScreenMask | VisualIDMask;
  1467. X  if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
  1468. X    {
  1469. X      /*
  1470. X        Failed to get visual;  try using the default visual.
  1471. X      */
  1472. X      Warning("unable to get visual",visual_type);
  1473. X      visual_template.visualid=
  1474. X        XVisualIDFromVisual(XDefaultVisual(display,XDefaultScreen(display)));
  1475. X      visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
  1476. X        &number_visuals);
  1477. X      if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
  1478. X        return((XVisualInfo *) NULL);
  1479. X      Warning("using default visual",XVisualClassName(visual_list));
  1480. X    }
  1481. X  if (map_type != (char *) NULL)
  1482. X    {
  1483. X      Atom
  1484. X        map_property;
  1485. X
  1486. X      char
  1487. X        map_name[2048];
  1488. X
  1489. X      int
  1490. X        j,
  1491. X        number_maps,
  1492. X        status;
  1493. X
  1494. X      Window
  1495. X        root_window;
  1496. X
  1497. X      XStandardColormap
  1498. X        *map_list;
  1499. X
  1500. X      /*
  1501. X        Restrict visual search by Standard Colormap visual id.
  1502. X      */
  1503. X      (void) sprintf((char *) map_name,"RGB_%s_MAP",map_type);
  1504. X      Latin1Upper(map_name);
  1505. X      map_property=XInternAtom(display,(char *) map_name,True);
  1506. X      if (map_property == (Atom) NULL)
  1507. X        Error("unable to get Standard Colormap",map_type);
  1508. X      root_window=XRootWindow(display,XDefaultScreen(display));
  1509. X      status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
  1510. X        map_property);
  1511. X      if (status == 0)
  1512. X        Error("unable to get Standard Colormap",map_type);
  1513. X      /*
  1514. X        Search all Standard Colormaps and visuals for ids that match.
  1515. X      */
  1516. X      *map_info=map_list[0];
  1517. #ifndef PRE_R4_ICCCM
  1518. X      visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
  1519. X      for (i=0; i < number_maps; i++)
  1520. X        for (j=0; j < number_visuals; j++)
  1521. X          if (map_list[i].visualid ==
  1522. X              XVisualIDFromVisual(visual_list[j].visual))
  1523. X            {
  1524. X              *map_info=map_list[i];
  1525. X              visual_template.visualid=
  1526. X                XVisualIDFromVisual(visual_list[j].visual);
  1527. X              break;
  1528. X            }
  1529. X      if (map_info->visualid != visual_template.visualid)
  1530. X        Error("unable to match visual to Standard Colormap",map_type);
  1531. #endif
  1532. X      if (map_info->colormap == (Colormap) NULL)
  1533. X        Error("Standard Colormap is not initialized",map_type);
  1534. X      XFree((void *) map_list);
  1535. X    }
  1536. X  else
  1537. X    {
  1538. X      static unsigned int
  1539. X        rank[]=
  1540. X          {
  1541. X            StaticGray,
  1542. X            GrayScale,
  1543. X            StaticColor,
  1544. X            DirectColor,
  1545. X            TrueColor,
  1546. X            PseudoColor
  1547. X          };
  1548. X
  1549. X      XVisualInfo
  1550. X        *p;
  1551. X
  1552. X      /*
  1553. X        Pick one visual that displays the most simultaneous colors.
  1554. X      */
  1555. X      visual_info=visual_list;
  1556. X      p=visual_list;
  1557. X      for (i=1; i < number_visuals; i++)
  1558. X      {
  1559. X        p++;
  1560. X        if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
  1561. X          visual_info=p;
  1562. X        else
  1563. X          if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
  1564. X            if (rank[p->class] > rank[visual_info->class])
  1565. X              visual_info=p;
  1566. X      }
  1567. X      visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
  1568. X    }
  1569. X  XFree((void *) visual_list);
  1570. X  /*
  1571. X    Retrieve only one visual by its screen & id number.
  1572. X  */
  1573. X  visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
  1574. X    &number_visuals);
  1575. X  if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
  1576. X    return((XVisualInfo *) NULL);
  1577. X  return(visual_info);
  1578. }
  1579. X
  1580. /*
  1581. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1582. %                                                                             %
  1583. %                                                                             %
  1584. %                                                                             %
  1585. %   X C l i e n t W i n d o w                                                 %
  1586. %                                                                             %
  1587. %                                                                             %
  1588. %                                                                             %
  1589. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1590. %
  1591. %  Function XClientWindow finds a window, at or below the specified window,
  1592. %  which has a WM_STATE property.  If such a window is found, it is returned,
  1593. %  otherwise the argument window is returned.
  1594. %
  1595. %  The format of the XClientWindow function is:
  1596. %
  1597. %      client_window=XClientWindow(display,target_window)
  1598. %
  1599. %  A description of each parameter follows:
  1600. %
  1601. %    o client_window: XClientWindow returns a window, at or below the specified
  1602. %      window, which has a WM_STATE property otherwise the argument
  1603. %      target_window is returned.
  1604. %
  1605. %    o display: Specifies a pointer to the Display structure;  returned from
  1606. %      XOpenDisplay.
  1607. %
  1608. %    o target_window: Specifies the window to find a WM_STATE property.
  1609. %
  1610. %
  1611. */
  1612. Window XClientWindow(display,target_window)
  1613. Display
  1614. X  *display;
  1615. X
  1616. Window
  1617. X  target_window;
  1618. {
  1619. X  Atom
  1620. X    state,
  1621. X    type;
  1622. X
  1623. X  int
  1624. X    format,
  1625. X    status;
  1626. X
  1627. X  unsigned char
  1628. X    *data;
  1629. X
  1630. X  unsigned long
  1631. X    after,
  1632. X    number_items;
  1633. X
  1634. X  Window
  1635. X    client_window;
  1636. X
  1637. X  state=XInternAtom(display,"WM_STATE",True);
  1638. X  if (state == (Atom) NULL)
  1639. X    return(target_window);
  1640. X  type=(Atom) NULL;
  1641. X  status=XGetWindowProperty(display,target_window,state,0L,0L,False,
  1642. X    (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
  1643. X  if ((status == Success) && (type != (Atom) NULL))
  1644. X    return(target_window);
  1645. X  client_window=XWindowByProperty(display,target_window,state);
  1646. X  if (client_window == (Window) NULL)
  1647. X    return(target_window);
  1648. X  return(client_window);
  1649. }
  1650. X
  1651. /*
  1652. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1653. %                                                                             %
  1654. %                                                                             %
  1655. %                                                                             %
  1656. %   X E r r o r                                                               %
  1657. %                                                                             %
  1658. %                                                                             %
  1659. %                                                                             %
  1660. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1661. %
  1662. %  Function XError ignores BadWindow errors for XQueryTree and
  1663. %  XGetWindowAttributes, and ignores BadDrawable errors for XGetGeometry, and
  1664. %  ignores BadValue errors for XQueryColor.  It returns False in those cases.
  1665. %  Otherwise it returns True.
  1666. %
  1667. %  The format of the XError function is:
  1668. %
  1669. %      XError(display,error)
  1670. %
  1671. %  A description of each parameter follows:
  1672. %
  1673. %    o display: Specifies a pointer to the Display structure;  returned from
  1674. %      XOpenDisplay.
  1675. %
  1676. %    o error: Specifies the error event.
  1677. %
  1678. %
  1679. */
  1680. int XError(display,error)
  1681. Display
  1682. X  *display;
  1683. X
  1684. XXErrorEvent
  1685. X  *error;
  1686. {
  1687. X  switch (error->request_code)
  1688. X  {
  1689. X    case X_GetGeometry:
  1690. X    {
  1691. X      if (error->error_code == BadDrawable)
  1692. X        return(False);
  1693. X      break;
  1694. X    }
  1695. X    case X_GetWindowAttributes:
  1696. X    case X_QueryTree:
  1697. X    {
  1698. X      if (error->error_code == BadWindow)
  1699. X        return(False);
  1700. X      break;
  1701. X    }
  1702. X    case X_QueryColors:
  1703. X    {
  1704. X      if (error->error_code == BadValue)
  1705. X        return(False);
  1706. X      break;
  1707. X    }
  1708. X  }
  1709. X  return(True);
  1710. }
  1711. X
  1712. /*
  1713. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1714. %                                                                             %
  1715. %                                                                             %
  1716. %                                                                             %
  1717. %   X F r e e S t a n d a r d C o l o r m a p                                 %
  1718. %                                                                             %
  1719. %                                                                             %
  1720. %                                                                             %
  1721. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1722. %
  1723. %  Function XFreeStandardColormap frees an X11 colormap.
  1724. %
  1725. %  The format of the XFreeStandardColormap routine is:
  1726. %
  1727. %      XFreeStandardColormap(display,visual_info,pixel_info,map_info)
  1728. %
  1729. %  A description of each parameter follows:
  1730. %
  1731. %    o display: Specifies a connection to an X server; returned from
  1732. %      XOpenDisplay.
  1733. %
  1734. %    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
  1735. %      returned from XGetVisualInfo.
  1736. %
  1737. %    o pixel_info: Specifies a pointer to a XPixelInfo structure.
  1738. %
  1739. %    o map_info: If map_type is specified, this structure is initialized
  1740. %      with info from the Standard Colormap.
  1741. %
  1742. %
  1743. */
  1744. void XFreeStandardColormap(display,visual_info,pixel_info,map_info)
  1745. Display
  1746. X  *display;
  1747. X
  1748. XXVisualInfo
  1749. X  *visual_info;
  1750. X
  1751. XXPixelInfo
  1752. X  *pixel_info;
  1753. X
  1754. XXStandardColormap
  1755. X  *map_info;
  1756. {
  1757. X  /*
  1758. X    Free colormap.
  1759. X  */
  1760. X  XFlush(display);
  1761. X  if (map_info->colormap != (Colormap) NULL)
  1762. X    if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
  1763. X      XFreeColormap(display,map_info->colormap);
  1764. X    else
  1765. X      if ((visual_info->class != TrueColor) &&
  1766. X          (visual_info->class != DirectColor))
  1767. X        XFreeColors(display,map_info->colormap,pixel_info->pixels,
  1768. X          (int) pixel_info->colors,0);
  1769. X  map_info->colormap=(Colormap) NULL;
  1770. X  if (pixel_info->pixels != (unsigned long *) NULL)
  1771. X    (void) free((char *) pixel_info->pixels);
  1772. X  pixel_info->pixels=(unsigned long *) NULL;
  1773. }
  1774. X
  1775. /*
  1776. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1777. %                                                                             %
  1778. %                                                                             %
  1779. %                                                                             %
  1780. %   X G e t A n n o t a t e I n f o                                           %
  1781. %                                                                             %
  1782. %                                                                             %
  1783. %                                                                             %
  1784. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1785. %
  1786. %  Function XGetAnnotateInfo initializes the AnnotateInfo structure.
  1787. %
  1788. %  The format of the GetAnnotateInfo routine is:
  1789. %
  1790. %      XGetAnnotateInfo(alien_info)
  1791. %
  1792. %  A description of each parameter follows:
  1793. %
  1794. %    o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
  1795. %
  1796. %
  1797. */
  1798. void XGetAnnotateInfo(annotate_info)
  1799. XXAnnotateInfo
  1800. X  *annotate_info;
  1801. {
  1802. X  /*
  1803. X    Initialize annotate structure.
  1804. X  */
  1805. X  annotate_info->x=0;
  1806. X  annotate_info->y=0;
  1807. X  annotate_info->width=0;
  1808. X  annotate_info->height=0;
  1809. X  annotate_info->degrees=0.0;
  1810. X  annotate_info->font_info=(XFontStruct *) NULL;
  1811. X  annotate_info->text=(char *) NULL;
  1812. X  *annotate_info->geometry=(char) NULL;
  1813. X  annotate_info->previous=(XAnnotateInfo *) NULL;
  1814. X  annotate_info->next=(XAnnotateInfo *) NULL;
  1815. }
  1816. X
  1817. /*
  1818. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1819. %                                                                             %
  1820. %                                                                             %
  1821. %                                                                             %
  1822. %   X G e t P i x e l I n f o                                                 %
  1823. %                                                                             %
  1824. %                                                                             %
  1825. %                                                                             %
  1826. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1827. %
  1828. %  Function XGetPixelInfo initializes the PixelInfo structure.
  1829. %
  1830. %  The format of the XGetPixelInfo routine is:
  1831. %
  1832. %      XGetPixelInfo(display,visual_info,map_info,resource_info,image,
  1833. %        pixel_info)
  1834. %
  1835. %  A description of each parameter follows:
  1836. %
  1837. %    o display: Specifies a connection to an X server; returned from
  1838. %      XOpenDisplay.
  1839. %
  1840. %    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
  1841. %      returned from XGetVisualInfo.
  1842. %
  1843. %    o map_info: If map_type is specified, this structure is initialized
  1844. %      with info from the Standard Colormap.
  1845. %
  1846. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1847. %
  1848. %    o image: Specifies a pointer to a Image structure;  returned from
  1849. %      ReadImage.
  1850. %
  1851. %    o pixel_info: Specifies a pointer to a XPixelInfo structure.
  1852. %
  1853. %
  1854. */
  1855. void XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel_info)
  1856. Display
  1857. X  *display;
  1858. X
  1859. XXVisualInfo
  1860. X  *visual_info;
  1861. X
  1862. XXStandardColormap
  1863. X  *map_info;
  1864. X
  1865. XXResourceInfo
  1866. X  *resource_info;
  1867. X
  1868. Image
  1869. X  *image;
  1870. X
  1871. XXPixelInfo
  1872. X  *pixel_info;
  1873. {
  1874. X  register int
  1875. X    i;
  1876. X
  1877. X  int
  1878. X    status;
  1879. X
  1880. X  unsigned int
  1881. X    packets;
  1882. X
  1883. X  pixel_info->colors=0;
  1884. X  if (image != (Image *) NULL)
  1885. X    if (image->class == PseudoClass)
  1886. X      pixel_info->colors=image->colors;
  1887. X  packets=Max(pixel_info->colors,visual_info->colormap_size)+MaxNumberPens;
  1888. X  pixel_info->pixels=(unsigned long *) malloc(packets*sizeof(unsigned long));
  1889. X  if (pixel_info->pixels == (unsigned long *) NULL)
  1890. X    Error("unable to get pixel info","memory allocation failed");
  1891. X  status=XParseColor(display,map_info->colormap,resource_info->background_color,
  1892. X    &pixel_info->background_color);
  1893. X  if (status == 0)
  1894. X    Warning("color is not known to X server",resource_info->background_color);
  1895. X  pixel_info->background_color.pixel=
  1896. X    XStandardPixel(map_info,pixel_info->background_color,16);
  1897. X  pixel_info->background_color.flags=DoRed | DoGreen | DoBlue;
  1898. X  status=XParseColor(display,map_info->colormap,resource_info->border_color,
  1899. X    &pixel_info->border_color);
  1900. X  if (status == 0)
  1901. X    Warning("color is not known to X server",resource_info->border_color);
  1902. X  pixel_info->border_color.pixel=
  1903. X    XStandardPixel(map_info,pixel_info->border_color,16);
  1904. X  pixel_info->border_color.flags=DoRed | DoGreen | DoBlue;
  1905. X  status=XParseColor(display,map_info->colormap,resource_info->foreground_color,
  1906. X    &pixel_info->foreground_color);
  1907. X  if (status == 0)
  1908. X    Warning("color is not known to X server",resource_info->foreground_color);
  1909. X  pixel_info->foreground_color.pixel=
  1910. X    XStandardPixel(map_info,pixel_info->foreground_color,16);
  1911. X  pixel_info->foreground_color.flags=DoRed | DoGreen | DoBlue;
  1912. X  for (i=0; i < MaxNumberPens; i++)
  1913. X  {
  1914. X    status=XParseColor(display,map_info->colormap,resource_info->pen_color[i],
  1915. X      &pixel_info->pen_color[i]);
  1916. X    if (status == 0)
  1917. X      Warning("color is not known to X server",resource_info->pen_color[i]);
  1918. X    pixel_info->pen_color[i].pixel=
  1919. X      XStandardPixel(map_info,pixel_info->pen_color[i],16);
  1920. X    pixel_info->pen_color[i].flags=DoRed | DoGreen | DoBlue;
  1921. SHAR_EOF
  1922. true || echo 'restore of ImageMagick/X.c failed'
  1923. fi
  1924. echo 'End of  part 15'
  1925. echo 'File ImageMagick/X.c is continued in part 16'
  1926. echo 16 > _shar_seq_.tmp
  1927. exit 0
  1928. exit 0 # Just in case...
  1929.