home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume34 / imagemagick / part15 < prev    next >
Text File  |  1992-12-14  |  59KB  |  1,923 lines

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