home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume13 / imagemagic / part18 < prev    next >
Internet Message Format  |  1991-05-23  |  75KB

  1. Path: uunet!uunet!elroy.jpl.nasa.gov!usc!apple!sun-barr!newstop!exodus!dupont.com!cristy
  2. From: cristy@dupont.com
  3. Newsgroups: comp.sources.x
  4. Subject: v13i034: ImageMagick - Graphics display programs, Part18/21
  5. Message-ID: <13948@exodus.Eng.Sun.COM>
  6. Date: 24 May 91 03:20:35 GMT
  7. References: <csx-13i017:imagemagic@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 2370
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: cristy@dupont.com
  13. Posting-number: Volume 13, Issue 34
  14. Archive-name: imagemagic/part18
  15.  
  16. #!/bin/sh
  17. # this is img.18 (part 18 of ImageMagick)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file ImageMagick/display.c continued
  20. #
  21. if test ! -r _shar_seq_.tmp; then
  22.     echo 'Please unpack part 1 first!'
  23.     exit 1
  24. fi
  25. (read Scheck
  26.  if test "$Scheck" != 18; then
  27.     echo Please unpack part "$Scheck" next!
  28.     exit 1
  29.  else
  30.     exit 0
  31.  fi
  32. ) < _shar_seq_.tmp || exit 1
  33. if test ! -f _shar_wnt_.tmp; then
  34.     echo 'x - still skipping ImageMagick/display.c'
  35. else
  36. echo 'x - continuing file ImageMagick/display.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/display.c' &&
  38. X  magnify_window)
  39. Display
  40. X  *display;
  41. X
  42. XXResourceInfo
  43. X  *resource_info;
  44. X
  45. XXWindowInfo
  46. X  *info_window,
  47. X  *image_window,
  48. X  *magnify_window;
  49. {
  50. X  char
  51. X    text[256];
  52. X
  53. X  register int
  54. X    x,
  55. X    y;
  56. X
  57. X  unsigned int
  58. X    state;
  59. X
  60. X  XColor
  61. X    color;
  62. X
  63. X  XEvent
  64. X    event;
  65. X
  66. X  /*
  67. X    Map info window.
  68. X  */
  69. X  state=DefaultState;
  70. X  (void) sprintf(text," %+d%+d #%02x%02x%02x  \0",image_window->width,
  71. X    image_window->height,MaxRgb,MaxRgb,MaxRgb);
  72. X  info_window->width=XTextWidth(info_window->font_info,text,strlen(text));
  73. X  info_window->height=
  74. X    info_window->font_info->ascent+info_window->font_info->descent+4;
  75. X  XResizeWindow(display,info_window->id,info_window->width,
  76. X    info_window->height);
  77. X  XMapWindow(display,info_window->id);
  78. X  state|=InfoMappedState;
  79. X  /*
  80. X    Update magnified image until the mouse button is released.
  81. X  */
  82. X  XDefineCursor(display,image_window->id,magnify_window->cursor);
  83. X  ConstrainMagnifyFactor(image_window,magnify_window,resource_info->magnify);
  84. X  state|=MagnifyState;
  85. X  do
  86. X  {
  87. X    if (state & MagnifyState)
  88. X      {
  89. X        /*
  90. X          Display pointer position.
  91. X        */
  92. X        color.pixel=
  93. X          XGetPixel(image_window->ximage,magnify_window->x,magnify_window->y);
  94. X        XQueryColor(display,image_window->map_info->colormap,&color);
  95. X        (void) sprintf(text," %+d%+d #%02x%02x%02x \0",magnify_window->x,
  96. X          magnify_window->y,color.red >> 8,color.green >> 8,color.blue >> 8);
  97. X        XClearWindow(display,info_window->id);
  98. X        XDrawString(display,info_window->id,info_window->graphic_context,2,
  99. X          info_window->font_info->ascent+2,text,strlen(text));
  100. X        /*
  101. X          Display magnified image.
  102. X        */
  103. X        XMakeMagnifyImage(magnify_window,image_window->ximage,
  104. X          resource_info->magnify);
  105. X        XPutImage(display,magnify_window->id,magnify_window->graphic_context,
  106. X          magnify_window->ximage,0,0,0,0,magnify_window->width,
  107. X          magnify_window->height);
  108. X      }
  109. X    /*
  110. X      Wait for next event.
  111. X    */
  112. X    XMaskEvent(display,ButtonPressMask | Button3MotionMask |
  113. X      ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | KeyPressMask,
  114. X      &event);
  115. X    switch (event.type)
  116. X    {
  117. X      case ButtonPress:
  118. X        break;
  119. X      case ButtonRelease:
  120. X      {
  121. X        /*
  122. X          User has finished magnifying image.
  123. X        */
  124. X        if (event.xbutton.button != Button3)
  125. X          break;
  126. X        state|=ExitState;
  127. X        break;
  128. X      }
  129. X      case KeyPress:
  130. X      {
  131. X        static char
  132. X          command[256];
  133. X
  134. X        static KeySym
  135. X          key_symbol;
  136. X
  137. X        /*
  138. X          Respond to a user key press.
  139. X        */
  140. X        *command=(char) NULL;
  141. X        XLookupString((XKeyEvent *) &event.xkey,command,sizeof(command),
  142. X          &key_symbol,(XComposeStatus *) NULL);
  143. X        if (!isdigit(*command))
  144. X          XBell(display,0);
  145. X        else
  146. X          {
  147. X            /*
  148. X              User specified a new magnify factor.
  149. X            */
  150. X            resource_info->magnify=1 << atoi(command);
  151. X            ConstrainMagnifyFactor(image_window,magnify_window,
  152. X              resource_info->magnify);
  153. X            break;
  154. X          }
  155. X        break;
  156. X      }
  157. X      case EnterNotify:
  158. X      {
  159. X        x=event.xcrossing.x;
  160. X        y=event.xcrossing.y;
  161. X        /*
  162. X          Check boundary conditions.
  163. X        */
  164. X        if (x < 0)
  165. X          x=0;
  166. X        else
  167. X          if (x >= image_window->width)
  168. X            x=image_window->width-1;
  169. X        if (y < 0)
  170. X          y=0;
  171. X        else
  172. X         if (y >= image_window->height)
  173. X           y=image_window->height-1;
  174. X        magnify_window->x=x-image_window->x;
  175. X        magnify_window->y=y-image_window->y;
  176. X        state|=MagnifyState;
  177. X        break;
  178. X      }
  179. X      case LeaveNotify:
  180. X      {
  181. X        state&=(~MagnifyState);
  182. X        break;
  183. X      }
  184. X      case MotionNotify:
  185. X      {
  186. X        /*
  187. X          Discard pending button motion events.
  188. X        */
  189. X        while (XCheckMaskEvent(display,Button3MotionMask,&event));
  190. X        x=event.xmotion.x;
  191. X        y=event.xmotion.y;
  192. X        /*
  193. X          Check boundary conditions.
  194. X        */
  195. X        if (x < 0)
  196. X          x=0;
  197. X        else
  198. X          if (x >= image_window->width)
  199. X            x=image_window->width-1;
  200. X        if (y < 0)
  201. X          y=0;
  202. X        else
  203. X         if (y >= image_window->height)
  204. X           y=image_window->height-1;
  205. X        magnify_window->x=x-image_window->x;
  206. X        magnify_window->y=y-image_window->y;
  207. X        break;
  208. X      }
  209. X      default:
  210. X        break;
  211. X    }
  212. X  } while (!(state & ExitState));
  213. X  XDefineCursor(display,image_window->id,image_window->cursor);
  214. X  XWithdrawWindow(display,info_window->id,info_window->screen);
  215. }
  216. X
  217. /*
  218. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  219. %                                                                             %
  220. %                                                                             %
  221. %                                                                             %
  222. %   X M a k e C u r s o r                                                     %
  223. %                                                                             %
  224. %                                                                             %
  225. %                                                                             %
  226. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  227. %
  228. %  Function XMakeCursor creates a crosshairs X11 cursor.
  229. %
  230. %  The format of the XMakeCursor routine is:
  231. %
  232. %      XMakeCursor(display,window,colormap,background_color,foreground_color)
  233. %
  234. %  A description of each parameter follows:
  235. %
  236. %    o display: Specifies a connection to an X server;  returned from
  237. %      XOpenDisplay.
  238. %
  239. %    o window: Specifies the ID of the window for which the cursor is
  240. %      assigned.
  241. %
  242. %    o colormap: Specifies the ID of the colormap from which the background
  243. %      and foreground color will be retrieved.
  244. %
  245. %    o background_color: Specifies the color to use for the cursor background.
  246. %
  247. %    o foreground_color: Specifies the color to use for the cursor foreground.
  248. %
  249. %
  250. */
  251. static Cursor XMakeCursor(display,window,colormap,background_color,
  252. X  foreground_color)
  253. Display
  254. X  *display;
  255. X
  256. Colormap
  257. X  colormap;
  258. X
  259. Window
  260. X  window;
  261. X
  262. char
  263. X  *background_color,
  264. X  *foreground_color;
  265. {
  266. #define scope_height 17
  267. #define scope_mask_width 17
  268. #define scope_mask_height 17
  269. #define scope_x_hot 8
  270. #define scope_y_hot 8
  271. #define scope_width 17
  272. X
  273. X  static unsigned char scope_bit[] =
  274. X    {
  275. X      0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
  276. X      0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  277. X      0x7e, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
  278. X      0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
  279. X      0x00, 0x00, 0x00
  280. X    };
  281. X
  282. X  static unsigned char scope_mask_bit[] =
  283. X    {
  284. X      0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00,
  285. X      0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x7f, 0xfc, 0x01,
  286. X      0x7f, 0xfc, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00,
  287. X      0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00, 0x80, 0x03, 0x00,
  288. X      0x80, 0x03, 0x00
  289. X    };
  290. X
  291. X  Cursor
  292. X    cursor;
  293. X
  294. X  Pixmap
  295. X    mask,
  296. X    source;
  297. X
  298. X  XColor
  299. X    background,
  300. X    foreground;
  301. X
  302. X  source=XCreateBitmapFromData(display,window,(char *) scope_bit,scope_width,
  303. X    scope_height);
  304. X  mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bit,
  305. X    scope_width,scope_height);
  306. X  if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
  307. X    Error("unable to create pixmap",(char *) NULL);
  308. X  XParseColor(display,colormap,background_color,&background);
  309. X  XParseColor(display,colormap,foreground_color,&foreground);
  310. X  cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
  311. X    scope_x_hot,scope_y_hot);
  312. X  if (cursor == (Cursor) NULL)
  313. X    Error("unable to create cursor",(char *) NULL);
  314. X  XFreePixmap(display,source);
  315. X  XFreePixmap(display,mask);
  316. X  return(cursor);
  317. }
  318. X
  319. /*
  320. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  321. %                                                                             %
  322. %                                                                             %
  323. %                                                                             %
  324. %   X M a k e M a g n i f y I m a g e                                         %
  325. %                                                                             %
  326. %                                                                             %
  327. %                                                                             %
  328. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  329. %
  330. %  Function XMakeMagnifyImage magnifies a region of an X image and returns it.
  331. %
  332. %  The format of the XMakeMagnifyImage routine is:
  333. %
  334. %      XMakeMagnifyImage(magnify_window,ximage,magnify)
  335. %
  336. %  A description of each parameter follows:
  337. %
  338. %    o magnify_window: Specifies a pointer to a XWindowInfo structure.
  339. %
  340. %    o ximage: Specifies a pointer to a XImage structure;  returned from
  341. %      XMakeImage.
  342. %
  343. %    o magnify: level of image magnification.
  344. %
  345. %
  346. */
  347. static void XMakeMagnifyImage(magnify_window,ximage,magnify)
  348. XXWindowInfo
  349. X  *magnify_window;
  350. X
  351. XXImage
  352. X  *ximage;
  353. X
  354. unsigned int
  355. X  magnify;
  356. {
  357. X  int
  358. X    x,
  359. X    y;
  360. X
  361. X  register unsigned char
  362. X    *p,
  363. X    *q;
  364. X
  365. X  register unsigned int
  366. X    j,
  367. X    k,
  368. X    l;
  369. X
  370. X  unsigned int
  371. X    i,
  372. X    scanline_pad;
  373. X
  374. X  /*
  375. X    Check boundry conditions.
  376. X  */
  377. X  x=magnify_window->x-(magnify_window->ximage->width/magnify/2);
  378. X  if (x < 0)
  379. X    x=0;
  380. X  else
  381. X    if (x > (ximage->width-(magnify_window->ximage->width/magnify)))
  382. X      x=ximage->width-magnify_window->ximage->width/magnify;
  383. X  y=magnify_window->y-(magnify_window->ximage->width/magnify/2);
  384. X  if (y < 0)
  385. X    y=0;
  386. X  else
  387. X    if (y > (ximage->height-(magnify_window->ximage->height/magnify)))
  388. X      y=ximage->height-magnify_window->ximage->height/magnify;
  389. X  q=(unsigned char *) magnify_window->ximage->data;
  390. X  scanline_pad=magnify_window->ximage->bytes_per_line-
  391. X    ((magnify_window->ximage->width*
  392. X    magnify_window->ximage->bits_per_pixel) >> 3);
  393. X  if (ximage->bits_per_pixel < 8)
  394. X    {
  395. X      register unsigned char
  396. X        byte,
  397. X        p_bit,
  398. X        q_bit;
  399. X
  400. X      register unsigned int
  401. X        plane;
  402. X
  403. X      switch (ximage->bitmap_bit_order)
  404. X      {
  405. X        case LSBFirst:
  406. X        {
  407. X          /*
  408. X            Magnify little-endian bitmap.
  409. X          */
  410. X          for (i=0; i < magnify_window->ximage->height; i+=magnify)
  411. X          {
  412. X            /*
  413. X              Propogate pixel magnify rows.
  414. X            */
  415. X            for (j=0; j < magnify; j++)
  416. X            {
  417. X              p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
  418. X                ((x*ximage->bits_per_pixel) >> 3);
  419. X              p_bit=(x*ximage->bits_per_pixel) & 0x07;
  420. X              q_bit=0;
  421. X              byte=0;
  422. X              for (k=0; k < magnify_window->ximage->width; k+=magnify)
  423. X              {
  424. X                /*
  425. X                  Propogate pixel magnify columns.
  426. X                */
  427. X                for (l=0; l < magnify; l++)
  428. X                {
  429. X                  /*
  430. X                    Propogate each bit plane.
  431. X                  */
  432. X                  for (plane=0; plane < ximage->bits_per_pixel; plane++)
  433. X                  {
  434. X                    byte>>=1;
  435. X                    if (*p & (0x01 << (p_bit+plane)))
  436. X                      byte|=0x80;
  437. X                    q_bit++;
  438. X                    if (q_bit == 8)
  439. X                      {
  440. X                        *q++=byte;
  441. X                        q_bit=0;
  442. X                        byte=0;
  443. X                      }
  444. X                  }
  445. X                }
  446. X                p_bit+=ximage->bits_per_pixel;
  447. X                if (p_bit == 8)
  448. X                  {
  449. X                    p++;
  450. X                    p_bit=0;
  451. X                  }
  452. X                if (q_bit > 0)
  453. X                  *q=byte >> (8-q_bit);
  454. X                q+=scanline_pad;
  455. X              }
  456. X            }
  457. X            y++;
  458. X          }
  459. X          break;
  460. X        }
  461. X        case MSBFirst:
  462. X        default:
  463. X        {
  464. X          /*
  465. X            Magnify big-endian bitmap.
  466. X          */
  467. X          for (i=0; i < magnify_window->ximage->height; i+=magnify)
  468. X          {
  469. X            /*
  470. X              Propogate pixel magnify rows.
  471. X            */
  472. X            for (j=0; j < magnify; j++)
  473. X            {
  474. X              p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
  475. X                ((x*ximage->bits_per_pixel) >> 3);
  476. X              p_bit=(x*ximage->bits_per_pixel) & 0x07;
  477. X              q_bit=0;
  478. X              byte=0;
  479. X              for (k=0; k < magnify_window->ximage->width; k+=magnify)
  480. X              {
  481. X                /*
  482. X                  Propogate pixel magnify columns.
  483. X                */
  484. X                for (l=0; l < magnify; l++)
  485. X                {
  486. X                  /*
  487. X                    Propogate each bit plane.
  488. X                  */
  489. X                  for (plane=0; plane < ximage->bits_per_pixel; plane++)
  490. X                  {
  491. X                    byte<<=1;
  492. X                    if (*p & (0x80 >> (p_bit+plane)))
  493. X                      byte|=0x01;
  494. X                    q_bit++;
  495. X                    if (q_bit == 8)
  496. X                      {
  497. X                        *q++=byte;
  498. X                        q_bit=0;
  499. X                        byte=0;
  500. X                      }
  501. X                  }
  502. X                }
  503. X                p_bit+=ximage->bits_per_pixel;
  504. X                if (p_bit == 8)
  505. X                  {
  506. X                    p++;
  507. X                    p_bit=0;
  508. X                  }
  509. X                if (q_bit > 0)
  510. X                  *q=byte << (8-q_bit);
  511. X                q+=scanline_pad;
  512. X              }
  513. X            }
  514. X            y++;
  515. X          }
  516. X          break;
  517. X        }
  518. X      }
  519. X    }
  520. X  else
  521. X    switch (ximage->bits_per_pixel)
  522. X    {
  523. X      case 8:
  524. X      {
  525. X        /*
  526. X          Magnify 8 bit X image.
  527. X        */
  528. X        for (i=0; i < magnify_window->ximage->height; i+=magnify)
  529. X        {
  530. X          /*
  531. X            Propogate pixel magnify rows.
  532. X          */
  533. X          for (j=0; j < magnify; j++)
  534. X          {
  535. X            p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
  536. X              ((x*ximage->bits_per_pixel) >> 3);
  537. X            for (k=0; k < magnify_window->ximage->width; k+=magnify)
  538. X            {
  539. X              /*
  540. X                Propogate pixel magnify columns.
  541. X              */
  542. X              for (l=0; l < magnify; l++)
  543. X                *q++=(*p);
  544. X              p++;
  545. X            }
  546. X            q+=scanline_pad;
  547. X          }
  548. X          y++;
  549. X        }
  550. X        break;
  551. X      }
  552. X      default:
  553. X      {
  554. X        register unsigned int
  555. X          bytes_per_pixel,
  556. X          m;
  557. X
  558. X        /*
  559. X          Magnify multi-byte X image.
  560. X        */
  561. X        bytes_per_pixel=ximage->bits_per_pixel >> 3;
  562. X        for (i=0; i < magnify_window->ximage->height; i+=magnify)
  563. X        {
  564. X          /*
  565. X            Propogate pixel magnify rows.
  566. X          */
  567. X          for (j=0; j < magnify; j++)
  568. X          {
  569. X            p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
  570. X              ((x*ximage->bits_per_pixel) >> 3);
  571. X            for (k=0; k < magnify_window->ximage->width; k+=magnify)
  572. X            {
  573. X              /*
  574. X                Propogate pixel magnify columns.
  575. X              */
  576. X              for (l=0; l < magnify; l++)
  577. X                for (m=0; m < bytes_per_pixel; m++)
  578. X                  *q++=(*(p+m));
  579. X              p+=bytes_per_pixel;
  580. X            }
  581. X            q+=scanline_pad;
  582. X          }
  583. X          y++;
  584. X        }
  585. X        break;
  586. X      }
  587. X    }
  588. }
  589. X
  590. /*
  591. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  592. %                                                                             %
  593. %                                                                             %
  594. %                                                                             %
  595. %   X M e n u W i n d o w                                                     %
  596. %                                                                             %
  597. %                                                                             %
  598. %                                                                             %
  599. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  600. %
  601. %  Function XMenuWindow maps a menu and returns the command pointed to by the
  602. %  user when the button is released.
  603. %
  604. %  The format of the XMenuWindow routine is:
  605. %
  606. %    XMenuWindow(display,menu_window,x,y)
  607. %
  608. %  A description of each parameter follows:
  609. %
  610. %    o display: Specifies a connection to an X server;  returned from
  611. %      XOpenDisplay.
  612. %
  613. %    o menu_window: Specifies a pointer to a XWindowInfo structure.
  614. %
  615. %    o x: Specifies an unsigned integer representing the root offset the
  616. %      x-direction.
  617. %
  618. %    o y: Specifies an unsigned integer representing the root offset the
  619. %      x-direction.
  620. %
  621. %    o command: Specifies a character array.  The command selected from
  622. %      the menu is returned here.
  623. %
  624. %
  625. */
  626. static void XMenuWindow(display,menu_window,x,y,command)
  627. Display
  628. X  *display;
  629. X
  630. XXWindowInfo
  631. X  *menu_window;
  632. X
  633. int
  634. X  x,
  635. X  y;
  636. X
  637. char
  638. X  *command;
  639. {
  640. #define MaxMenuSelections  11
  641. X
  642. X  typedef struct _Selection
  643. X  {
  644. X    int
  645. X      id,
  646. X      x,
  647. X      y;
  648. X
  649. X    unsigned int
  650. X      width,
  651. X      height;
  652. X  } Selection;
  653. X
  654. X  static char
  655. X    *MenuSelections[]=
  656. X    {
  657. X      "iImage Info    ",
  658. X      "<Half Size     ",
  659. X      ">Double Size   ",
  660. X      "/Rotate Right  ",
  661. X      "\\Rotate Left   ",
  662. X      "rReflect Image ",
  663. X      "oRestore Image ",
  664. X      "wRestore Window",
  665. X      "mMagnify Window",
  666. X      "nNext Image    ",
  667. X      "qQuit          ",
  668. X    };
  669. X
  670. X  char
  671. X    text[256];
  672. X
  673. X  Selection
  674. X    last_selection,
  675. X    selection;
  676. X
  677. X  unsigned int
  678. X    height,
  679. X    state,
  680. X    width;
  681. X
  682. X  XEvent
  683. X    event;
  684. X
  685. X  /*
  686. X    Size and position menu window under current pointer location and map.
  687. X  */
  688. X  (void) sprintf(text," %s\0",MenuSelections[0]);
  689. X  menu_window->width=XTextWidth(menu_window->font_info,text,strlen(text));
  690. X  menu_window->height=MaxMenuSelections*
  691. X    (menu_window->font_info->ascent+menu_window->font_info->descent+4);
  692. X  width=menu_window->width+2*menu_window->border_width; 
  693. X  menu_window->x=x-(int) width/2;
  694. X  if (menu_window->x < 0)
  695. X    menu_window->x=0;
  696. X  else
  697. X    if (menu_window->x > (XDisplayWidth(display,menu_window->screen)-width))
  698. X      menu_window->x=XDisplayWidth(display,menu_window->screen)-width;
  699. X  height=menu_window->height+2*menu_window->border_width;
  700. X  menu_window->y=y-(int) menu_window->border_width;
  701. X  if (menu_window->y < 0)
  702. X    menu_window->y=0;
  703. X  else
  704. X    if (menu_window->y > (XDisplayHeight(display,menu_window->screen)-height))
  705. X      menu_window->y=XDisplayHeight(display,menu_window->screen)-height;
  706. X  XMoveResizeWindow(display,menu_window->id,menu_window->x,menu_window->y,
  707. X    menu_window->width,menu_window->height);
  708. X  XMapRaised(display,menu_window->id);
  709. X  XWindowEvent(display,menu_window->id,ExposureMask,&event);
  710. X  /*
  711. X    Draw menu selection selections.
  712. X  */
  713. X  selection.x=menu_window->font_info->max_bounds.rbearing-
  714. X    menu_window->font_info->min_bounds.lbearing;
  715. X  selection.y=menu_window->font_info->ascent+2;
  716. X  selection.width=strlen(MenuSelections[0]+1);
  717. X  selection.height=menu_window->font_info->descent+
  718. X    menu_window->font_info->ascent+4;
  719. X  for (selection.id=0; selection.id < MaxMenuSelections; selection.id++)
  720. X  {
  721. X    XDrawString(display,menu_window->id,menu_window->graphic_context,
  722. X      selection.x,selection.y,MenuSelections[selection.id]+1,selection.width);
  723. X    selection.y+=(int) selection.height;
  724. X  }
  725. X  /*
  726. X    Highlight menu as pointer moves;  return command on button release.
  727. X  */
  728. X  selection.id=0;
  729. X  last_selection=selection;
  730. X  state=DefaultState;
  731. X  do
  732. X  {
  733. X    /*
  734. X      Wait for next event.
  735. X    */
  736. X    XMaskEvent(display,ButtonPressMask | Button1MotionMask |
  737. X      ButtonReleaseMask | EnterWindowMask | LeaveWindowMask,&event);
  738. X    switch (event.type)
  739. X    {
  740. X      case ButtonPress:
  741. X        break;
  742. X      case ButtonRelease:
  743. X      {
  744. X        /*
  745. X          Determine if user choose a menu item.
  746. X        */
  747. X        if (event.xbutton.button != Button1)
  748. X          break;
  749. X        state|=ExitState;
  750. X        break;
  751. X      }
  752. X      case EnterNotify:
  753. X      {
  754. X        if (event.xcrossing.window != menu_window->id)
  755. X          break;
  756. X        selection.id=event.xcrossing.y/(int) selection.height;
  757. X        /*
  758. X          Check boundary conditions.
  759. X        */
  760. X        if (selection.id < 0)
  761. X          selection.id=0;
  762. X        if (selection.id >= MaxMenuSelections)
  763. X          selection.id=MaxMenuSelections-1;
  764. X        /*
  765. X          Highlight this selection.
  766. X        */
  767. X        selection.y=
  768. X          menu_window->font_info->ascent+2+selection.id*selection.height;
  769. X        XSetBackground(display,menu_window->graphic_context,
  770. X          menu_window->pixel_info->foreground_pixel);
  771. X        XSetForeground(display,menu_window->graphic_context,
  772. X          menu_window->pixel_info->background_pixel);
  773. X        XDrawImageString(display,menu_window->id,
  774. X          menu_window->graphic_context,selection.x,selection.y,
  775. X          MenuSelections[selection.id]+1,selection.width);
  776. X        XSetBackground(display,menu_window->graphic_context,
  777. X          menu_window->pixel_info->background_pixel);
  778. X        XSetForeground(display,menu_window->graphic_context,
  779. X          menu_window->pixel_info->foreground_pixel);
  780. X        last_selection=selection;
  781. X        state|=HighlightState;
  782. X        break;
  783. X      }
  784. X      case LeaveNotify:
  785. X      {
  786. X        if (event.xcrossing.window != menu_window->id)
  787. X          break;
  788. X        /*
  789. X          Unhighlight last selection.
  790. X        */
  791. X        XDrawImageString(display,menu_window->id,
  792. X          menu_window->graphic_context,last_selection.x,last_selection.y,
  793. X          MenuSelections[last_selection.id]+1,last_selection.width);
  794. X        state&=(~HighlightState);
  795. X        break;
  796. X      }
  797. X      case MotionNotify:
  798. X      {
  799. X        /*
  800. X          Discard pending selection motion events.
  801. X        */
  802. X        while (XCheckMaskEvent(display,Button1MotionMask,&event));
  803. X        if (event.xmotion.window != menu_window->id)
  804. X          break;
  805. X        /*
  806. X          Check boundary conditions.
  807. X        */
  808. X        selection.id=event.xmotion.y/(int) selection.height;
  809. X        if (selection.id < 0)
  810. X          selection.id=0;
  811. X        if (selection.id >= MaxMenuSelections)
  812. X          selection.id=MaxMenuSelections-1;
  813. X        if (!(state & HighlightState))
  814. X          break;
  815. X        if (selection.id == last_selection.id)
  816. X          break;
  817. X        /*
  818. X          Unhighlight last selection.
  819. X        */
  820. X        XDrawImageString(display,menu_window->id,
  821. X          menu_window->graphic_context,last_selection.x,last_selection.y,
  822. X          MenuSelections[last_selection.id]+1,last_selection.width);
  823. X        /*
  824. X          Highlight this selection.
  825. X        */
  826. X        selection.y=
  827. X          menu_window->font_info->ascent+2+selection.id*selection.height;
  828. X        XSetBackground(display,menu_window->graphic_context,
  829. X          menu_window->pixel_info->foreground_pixel);
  830. X        XSetForeground(display,menu_window->graphic_context,
  831. X          menu_window->pixel_info->background_pixel);
  832. X        XDrawImageString(display,menu_window->id,
  833. X          menu_window->graphic_context,selection.x,selection.y,
  834. X          MenuSelections[selection.id]+1,selection.width);
  835. X        XSetBackground(display,menu_window->graphic_context,
  836. X          menu_window->pixel_info->background_pixel);
  837. X        XSetForeground(display,menu_window->graphic_context,
  838. X          menu_window->pixel_info->foreground_pixel);
  839. X        last_selection=selection;
  840. X        break;
  841. X      }
  842. X      default:
  843. X        break;
  844. X    }
  845. X  } while (!(state & ExitState));
  846. X  XWithdrawWindow(display,menu_window->id,menu_window->screen);
  847. X  *command=(char) NULL;
  848. X  if (state & HighlightState)
  849. X    (void) strcpy(command,MenuSelections[selection.id]);
  850. }
  851. X
  852. /*
  853. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  854. %                                                                             %
  855. %                                                                             %
  856. %                                                                             %
  857. %   X P a n I m a g e W i n d o w                                             %
  858. %                                                                             %
  859. %                                                                             %
  860. %                                                                             %
  861. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  862. %
  863. %  Function XPanImageWindow pans the image until the mouse button is released.
  864. %
  865. %  The format of the XPanImageWindow routine is:
  866. %
  867. %    XPanImageWindow(display,info_window,image_window,x_offset,y_offset)
  868. %
  869. %  A description of each parameter follows:
  870. %
  871. %    o display: Specifies a connection to an X server;  returned from
  872. %      XOpenDisplay.
  873. %
  874. %    o info_window: Specifies a pointer to a XWindowInfo structure.
  875. %
  876. %    o image_window: Specifies a pointer to a XWindowInfo structure.
  877. %
  878. %    o x_offset: Specifies the initial offset in the x-direction.
  879. %
  880. %    o y_offset: Specifies the initial offset in the y-direction.
  881. %
  882. %
  883. */
  884. static void XPanImageWindow(display,info_window,image_window,x_offset,y_offset)
  885. Display
  886. X  *display;
  887. X
  888. XXWindowInfo
  889. X  *info_window,
  890. X  *image_window;
  891. X
  892. int
  893. X  x_offset,
  894. X  y_offset;
  895. {
  896. X  char
  897. X    text[256];
  898. X
  899. X  Cursor
  900. X    cursor;
  901. X
  902. X  unsigned int
  903. X    state;
  904. X
  905. X  XEvent
  906. X    event;
  907. X
  908. X  /*
  909. X    Map info window.
  910. X  */
  911. X  state=DefaultState;
  912. X  (void) sprintf(text," %dx%d%+d%+d  \0",image_window->ximage->width,
  913. X    image_window->ximage->height,image_window->ximage->width,
  914. X    image_window->ximage->height);
  915. X  info_window->width=XTextWidth(info_window->font_info,text,strlen(text));
  916. X  info_window->height=
  917. X    info_window->font_info->ascent+info_window->font_info->descent+4;
  918. X  XResizeWindow(display,info_window->id,info_window->width,
  919. X    info_window->height);
  920. X  XMapWindow(display,info_window->id);
  921. X  state|=InfoMappedState;
  922. X  /*
  923. X    Define cursor.
  924. X  */
  925. X  if ((image_window->ximage->width > image_window->width) &&
  926. X      (image_window->ximage->height > image_window->height))
  927. X    cursor=XCreateFontCursor(display,XC_fleur);
  928. X  else
  929. X    if (image_window->ximage->width > image_window->width)
  930. X      cursor=XCreateFontCursor(display,XC_sb_h_double_arrow);
  931. X    else
  932. X      if (image_window->ximage->height > image_window->height)
  933. X        cursor=XCreateFontCursor(display,XC_sb_v_double_arrow);
  934. X      else
  935. X        cursor=XCreateFontCursor(display,XC_arrow);
  936. X  if (cursor == (Cursor) NULL)
  937. X    Error("unable to create cursor",(char *) NULL);
  938. X  XDefineCursor(display,image_window->id,cursor);
  939. X  /*
  940. X    Pan image as pointer moves until the mouse button is released.
  941. X  */
  942. X  do
  943. X  {
  944. X    /*
  945. X      Display image pan offset.
  946. X    */
  947. X    (void) sprintf(text," %dx%d%+d%+d \0",image_window->ximage->width,
  948. X      image_window->ximage->height,image_window->x,image_window->y);
  949. X    XClearWindow(display,info_window->id);
  950. X    XDrawString(display,info_window->id,info_window->graphic_context,2,
  951. X      info_window->font_info->ascent+2,text,strlen(text));
  952. X    /*
  953. X      Display image window.
  954. X    */
  955. X    XDisplayImageWindow(display,image_window,0,0,image_window->width,
  956. X      image_window->height);
  957. X    /*
  958. X      Wait for next event.
  959. X    */
  960. X    XMaskEvent(display,ButtonPressMask | Button1MotionMask | ButtonReleaseMask,
  961. X      &event);
  962. X    switch (event.type)
  963. X    {
  964. X      case ButtonPress:
  965. X        break;
  966. X      case ButtonRelease:
  967. X      {
  968. X        /*
  969. X          User has finished panning the image.
  970. X        */
  971. X        if (event.xbutton.button != Button1)
  972. X          break;
  973. X        state|=ExitState;
  974. X        break;
  975. X      }
  976. X      case MotionNotify:
  977. X      {
  978. X        /*
  979. X          Discard pending button motion events.
  980. X        */
  981. X        while (XCheckMaskEvent(display,Button1MotionMask,&event));
  982. X        image_window->x-=(x_offset-event.xmotion.x);
  983. X        image_window->y-=(y_offset-event.xmotion.y);
  984. X        x_offset=event.xmotion.x;
  985. X        y_offset=event.xmotion.y;
  986. X        /*
  987. X          Check boundary conditions.
  988. X        */
  989. X        if (image_window->x < (-image_window->ximage->width))
  990. X          image_window->x=(-image_window->ximage->width);
  991. X        else
  992. X          if (image_window->x > image_window->ximage->width)
  993. X            image_window->x=image_window->ximage->width;
  994. X        if (image_window->y < (-image_window->ximage->height))
  995. X          image_window->y=(-image_window->ximage->height);
  996. X        else
  997. X          if (image_window->y > image_window->ximage->height)
  998. X            image_window->y=image_window->ximage->height;
  999. X      }
  1000. X      default:
  1001. X        break;
  1002. X    }
  1003. X  } while (!(state & ExitState));
  1004. X  XDefineCursor(display,image_window->id,image_window->cursor);
  1005. X  XFreeCursor(display,cursor);
  1006. X  XWithdrawWindow(display,info_window->id,info_window->screen);
  1007. }
  1008. X
  1009. /*
  1010. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1011. %                                                                             %
  1012. %                                                                             %
  1013. %                                                                             %
  1014. %   X R e f l e c t I m a g e W i n d o w                                     %
  1015. %                                                                             %
  1016. %                                                                             %
  1017. %                                                                             %
  1018. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1019. %
  1020. %  Function XReflectImageWindow reflects the scanlines of an image.
  1021. %
  1022. %  The format of the XReflectImageWindow routine is:
  1023. %
  1024. %    status=XReflectImageWindow(display,info_window,image_window,image)
  1025. %
  1026. %  A description of each parameter follows:
  1027. %
  1028. %    o status: Function XReflectImageWindow return True if the window scanlines
  1029. %      reverse.  False is returned is there is a memory shortage or if the
  1030. %      window scanlines fails to reverse.
  1031. %
  1032. %    o display: Specifies a connection to an X server; returned from
  1033. %      XOpenDisplay.
  1034. %
  1035. %    o info_window: Specifies a pointer to a XWindowInfo structure.
  1036. %
  1037. %    o image_window: Specifies a pointer to a XWindowInfo structure.
  1038. %
  1039. %    o image: Specifies a pointer to a Image structure;  returned from
  1040. %      ReadImage.
  1041. %
  1042. %
  1043. */
  1044. static unsigned int XReflectImageWindow(display,info_window,image_window,image)
  1045. Display
  1046. X  *display;
  1047. X
  1048. XXWindowInfo
  1049. X  *info_window,
  1050. X  *image_window;
  1051. X
  1052. Image
  1053. X  **image;
  1054. {
  1055. X  char
  1056. X    text[256];
  1057. X
  1058. X  Image
  1059. X    *reflected_image;
  1060. X
  1061. X  unsigned int
  1062. X    state;
  1063. X
  1064. X  state=DefaultState;
  1065. X  if (((*image)->columns*(*image)->rows) > MinInfoSize)
  1066. X    {
  1067. X      /*
  1068. X        Map image window.
  1069. X      */
  1070. X      (void) strcpy(text," Reflecting image... ");
  1071. X      info_window->width=XTextWidth(info_window->font_info,text,strlen(text));
  1072. X      info_window->height=
  1073. X        info_window->font_info->ascent+info_window->font_info->descent+4;
  1074. X      XResizeWindow(display,info_window->id,info_window->width,
  1075. X        info_window->height);
  1076. X      XMapWindow(display,info_window->id);
  1077. X      XClearWindow(display,info_window->id);
  1078. X      XDrawString(display,info_window->id,info_window->graphic_context,2,
  1079. X        info_window->font_info->ascent+2,text,strlen(text));
  1080. X      state|=InfoMappedState;
  1081. X    }
  1082. X  /*
  1083. X    Reflect image scanlines.
  1084. X  */
  1085. X  XDefineCursor(display,image_window->id,image_window->busy_cursor);
  1086. X  XFlush(display);
  1087. X  reflected_image=ReflectImage(*image);
  1088. X  if (reflected_image == (Image *) NULL)
  1089. X    {
  1090. X      Warning("unable to reflect X image",image_window->name);
  1091. X      XDefineCursor(display,image_window->id,image_window->cursor);
  1092. X      if (state & InfoMappedState)
  1093. X        XWithdrawWindow(display,info_window->id,info_window->screen);
  1094. X      return(False);
  1095. X    }
  1096. X  DestroyImage(*image);
  1097. X  *image=reflected_image;
  1098. X  if (image_window->clip_geometry != (char *) NULL)
  1099. X    {
  1100. X      int
  1101. X        x,
  1102. X        y;
  1103. X
  1104. X      unsigned int
  1105. X        height,
  1106. X        width;
  1107. X
  1108. X      /*
  1109. X        Reverse clip geometry.
  1110. X      */
  1111. X      (void) XParseGeometry(image_window->clip_geometry,&x,&y,&width,&height);
  1112. X      (void) sprintf(image_window->clip_geometry,"%dx%d%+d%+d\0",width,height,
  1113. X        (*image)->columns-width-x,y);
  1114. X    }
  1115. X  /*
  1116. X    Restore cursor.
  1117. X  */
  1118. X  XDefineCursor(display,image_window->id,image_window->cursor);
  1119. X  if (state & InfoMappedState)
  1120. X    XWithdrawWindow(display,info_window->id,info_window->screen);
  1121. X  return(True);
  1122. }
  1123. X
  1124. /*
  1125. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1126. %                                                                             %
  1127. %                                                                             %
  1128. %                                                                             %
  1129. %   X R e s i z e I m a g e W i n d o w                                       %
  1130. %                                                                             %
  1131. %                                                                             %
  1132. %                                                                             %
  1133. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1134. %
  1135. %  Function XResizeImageWindow creates a new X image the same size as the
  1136. %  image window.
  1137. %
  1138. %  The format of the XResizeImageWindow routine is:
  1139. %
  1140. %    status=XResizeImageWindow(display,resource_info,info_window,image_window,
  1141. %      image);
  1142. %
  1143. %  A description of each parameter follows:
  1144. %
  1145. %    o status: Function XResizeImageWindow return True if the window is
  1146. %      resized.  False is returned is there is a memory shortage or if the
  1147. %      window fails to resize.
  1148. %
  1149. %    o display: Specifies a connection to an X server; returned from
  1150. %      XOpenDisplay.
  1151. %
  1152. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1153. %
  1154. %    o info_window: Specifies a pointer to a XWindowInfo structure.
  1155. %
  1156. %    o image_window: Specifies a pointer to a XWindowInfo structure.
  1157. %
  1158. %    o image: Specifies a pointer to a Image structure;  returned from
  1159. %      ReadImage.
  1160. %
  1161. %
  1162. */
  1163. static unsigned int XResizeImageWindow(display,resource_info,info_window,
  1164. X  image_window,image)
  1165. Display
  1166. X  *display;
  1167. X
  1168. XXResourceInfo
  1169. X  *resource_info;
  1170. X
  1171. XXWindowInfo
  1172. X  *info_window,
  1173. X  *image_window;
  1174. X
  1175. Image
  1176. X  *image;
  1177. {
  1178. X  char
  1179. X    text[256];
  1180. X
  1181. X  unsigned int
  1182. X    state;
  1183. X
  1184. X  XImage
  1185. X    *resized_ximage;
  1186. X
  1187. X  state=DefaultState;
  1188. X  if ((image_window->width*image_window->height) > MinInfoSize)
  1189. X    {
  1190. X      /*
  1191. X        Map image window.
  1192. X      */
  1193. X      (void) strcpy(text," Resizing image... ");
  1194. X      info_window->width=XTextWidth(info_window->font_info,text,strlen(text));
  1195. X      info_window->height=info_window->font_info->ascent+
  1196. X        info_window->font_info->descent+4;
  1197. X      XResizeWindow(display,info_window->id,info_window->width,
  1198. X        info_window->height);
  1199. X      XMapWindow(display,info_window->id);
  1200. X      XClearWindow(display,info_window->id);
  1201. X      XDrawString(display,info_window->id,info_window->graphic_context,2,
  1202. X        info_window->font_info->ascent+2,text,strlen(text));
  1203. X      state|=InfoMappedState;
  1204. X    }
  1205. X  /*
  1206. X    Resize image to fit image window dimensions.
  1207. X  */
  1208. X  XDefineCursor(display,image_window->id,image_window->busy_cursor);
  1209. X  XFlush(display);
  1210. X  resized_ximage=XMakeImage(display,resource_info,image_window,image,
  1211. X    image_window->width,image_window->height);
  1212. X  if (resized_ximage == (XImage *) NULL)
  1213. X    {
  1214. X      Warning("unable to resize X image",image_window->name);
  1215. X      XDefineCursor(display,image_window->id,image_window->cursor);
  1216. X      if (state & InfoMappedState)
  1217. X        XWithdrawWindow(display,info_window->id,info_window->screen);
  1218. X      return(False);
  1219. X    }
  1220. X  XDestroyImage(image_window->ximage);
  1221. X  image_window->x=0;
  1222. X  image_window->y=0;
  1223. X  image_window->ximage=resized_ximage;
  1224. X  /*
  1225. X    Restore cursor.
  1226. X  */
  1227. X  XDefineCursor(display,image_window->id,image_window->cursor);
  1228. X  if (state & InfoMappedState)
  1229. X    XWithdrawWindow(display,info_window->id,info_window->screen);
  1230. X  return(True);
  1231. }
  1232. X
  1233. /*
  1234. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1235. %                                                                             %
  1236. %                                                                             %
  1237. %                                                                             %
  1238. %   X R o t a t e I m a g e W i n d o w                                       %
  1239. %                                                                             %
  1240. %                                                                             %
  1241. %                                                                             %
  1242. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1243. %
  1244. %  Function XRotateImageWindow rotates the X image left or right 90 degrees.
  1245. %
  1246. %  The format of the XRotateImageWindow routine is:
  1247. %
  1248. %    status=XRotateImageWindow(display,info_window,image_window,degrees,image)
  1249. %
  1250. %  A description of each parameter follows:
  1251. %
  1252. %    o status: Function XRotateImageWindow return True if the window is
  1253. %      rotated.  False is returned is there is a memory shortage or if the
  1254. %      window fails to rotate.
  1255. %
  1256. %    o display: Specifies a connection to an X server; returned from
  1257. %      XOpenDisplay.
  1258. %
  1259. %    o info_window: Specifies a pointer to a XWindowInfo structure.
  1260. %
  1261. %    o image_window: Specifies a pointer to a XWindowInfo structure.
  1262. %
  1263. %    o degrees: Specifies the number of degrees to rotate the image.
  1264. %
  1265. %    o image: Specifies a pointer to a Image structure;  returned from
  1266. %      ReadImage.
  1267. %
  1268. %
  1269. */
  1270. static unsigned int XRotateImageWindow(display,info_window,image_window,
  1271. X  degrees,image)
  1272. Display
  1273. X  *display;
  1274. X
  1275. XXWindowInfo
  1276. X  *info_window,
  1277. X  *image_window;
  1278. X
  1279. unsigned int
  1280. X  degrees;
  1281. X
  1282. Image
  1283. X  **image;
  1284. {
  1285. X  char
  1286. X    text[256];
  1287. X
  1288. X  int
  1289. X    x,
  1290. X    y;
  1291. X
  1292. X  Image
  1293. X    *rotated_image;
  1294. X
  1295. X  unsigned int
  1296. X    state;
  1297. X
  1298. X  state=DefaultState;
  1299. X  if (((*image)->columns*(*image)->rows) > MinInfoSize)
  1300. X    {
  1301. X      /*
  1302. X        Map info window.
  1303. X      */
  1304. X      (void) strcpy(text," Rotating image... ");
  1305. X      info_window->width=XTextWidth(info_window->font_info,text,strlen(text));
  1306. X      info_window->height=info_window->font_info->ascent+
  1307. X        info_window->font_info->descent+4;
  1308. X      XResizeWindow(display,info_window->id,info_window->width,
  1309. X        info_window->height);
  1310. X      XMapWindow(display,info_window->id);
  1311. X      XClearWindow(display,info_window->id);
  1312. X      XDrawString(display,info_window->id,info_window->graphic_context,2,
  1313. X        info_window->font_info->ascent+2,text,strlen(text));
  1314. X      state|=InfoMappedState;
  1315. X    }
  1316. X  /*
  1317. X    Rotate image.
  1318. X  */
  1319. X  XDefineCursor(display,image_window->id,image_window->busy_cursor);
  1320. X  XFlush(display);
  1321. X  rotated_image=RotateImage(*image,(double) degrees,True);
  1322. X  if (rotated_image == (Image *) NULL)
  1323. X    {
  1324. X      Warning("unable to rotate X image",image_window->name);
  1325. X      XDefineCursor(display,image_window->id,image_window->cursor);
  1326. X      if (state & InfoMappedState)
  1327. X        XWithdrawWindow(display,info_window->id,info_window->screen);
  1328. X      return(False);
  1329. X    }
  1330. X  DestroyImage(*image);
  1331. X  *image=rotated_image;
  1332. X  if (image_window->clip_geometry != (char *) NULL)
  1333. X    {
  1334. X      unsigned int
  1335. X        height,
  1336. X        width;
  1337. X
  1338. X      /*
  1339. X        Rotate clip geometry.
  1340. X      */
  1341. X      (void) XParseGeometry(image_window->clip_geometry,&x,&y,&width,&height);
  1342. X      if (degrees < 180.0)
  1343. X        (void) sprintf(image_window->clip_geometry,"%dx%d%+d%+d\0",height,
  1344. X          width,(*image)->columns-height-y,x);
  1345. X      else
  1346. X        (void) sprintf(image_window->clip_geometry,"%dx%d%+d%+d\0",height,
  1347. X          width,y,(*image)->rows-width-x);
  1348. X    }
  1349. X  /*
  1350. X    Restore cursor.
  1351. X  */
  1352. X  XDefineCursor(display,image_window->id,image_window->cursor);
  1353. X  if (state & InfoMappedState)
  1354. X    XWithdrawWindow(display,info_window->id,info_window->screen);
  1355. X  return(True);
  1356. }
  1357. X
  1358. /*
  1359. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1360. %                                                                             %
  1361. %                                                                             %
  1362. %                                                                             %
  1363. %    M a i n                                                                  %
  1364. %                                                                             %
  1365. %                                                                             %
  1366. %                                                                             %
  1367. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1368. %
  1369. %
  1370. */
  1371. int main(argc,argv)
  1372. int
  1373. X  argc;
  1374. X
  1375. char
  1376. X  **argv;
  1377. {
  1378. X  char
  1379. X    *clip_geometry,
  1380. X    *image_geometry,
  1381. X    *option,
  1382. X    *print_filename,
  1383. X    *scale_geometry,
  1384. X    *server_name,
  1385. X    *write_filename;
  1386. X
  1387. X  Display
  1388. X    *display;
  1389. X
  1390. X  double
  1391. X    gamma;
  1392. X
  1393. X  int
  1394. X    degrees;
  1395. X
  1396. X  register int
  1397. X    i;
  1398. X
  1399. X  unsigned int
  1400. X    compression,
  1401. X    display_image,
  1402. X    dither,
  1403. X    enhance,
  1404. X    gray,
  1405. X    image_number,
  1406. X    inverse,
  1407. X    monochrome,
  1408. X    noise,
  1409. X    normalize,
  1410. X    number_colors,
  1411. X    reflect,
  1412. X    scene,
  1413. X    tree_depth,
  1414. X    root,
  1415. X    verbose;
  1416. X
  1417. X  XResourceInfo
  1418. X    resource_info;
  1419. X
  1420. X  /*
  1421. X    Display usage profile if there are no command line arguments.
  1422. X  */
  1423. X  application_name=(*argv);
  1424. X  if (argc < 2)
  1425. X    Usage((char *) NULL,True);
  1426. X  /*
  1427. X    Set defaults.
  1428. X  */
  1429. X  clip_geometry=(char *) NULL;
  1430. X  compression=UnknownCompression;
  1431. X  degrees=0;
  1432. X  display=(Display *) NULL;
  1433. X  display_image=True;
  1434. X  dither=False;
  1435. X  enhance=False;
  1436. X  gamma=0.0;
  1437. X  gray=False;
  1438. X  image_geometry=(char *) NULL;
  1439. X  inverse=False;
  1440. X  monochrome=False;
  1441. X  noise=False;
  1442. X  normalize=False;
  1443. X  number_colors=0;
  1444. X  print_filename=(char *) NULL;
  1445. X  reflect=False;
  1446. X  root=False;
  1447. X  scale_geometry=(char *) NULL;
  1448. X  scene=0;
  1449. X  server_name=(char *) NULL;
  1450. X  tree_depth=0;
  1451. X  verbose=False;
  1452. X  write_filename=(char *) NULL;
  1453. X  /*
  1454. X    Check for server name specified on the command line.
  1455. X  */
  1456. X  for (i=1; i < argc-1; i++)
  1457. X  {
  1458. X    /*
  1459. X      Check command line for server name.
  1460. X    */
  1461. X    option=argv[i];
  1462. X    if ((strlen(option) > 1) && ((*option == '-') || (*option == '+')))
  1463. X      if (strncmp("display",option+1,3) == 0)
  1464. X        {
  1465. X          /*
  1466. X            User specified server name.
  1467. X          */
  1468. X          display_image=(*option == '-');
  1469. X          if (display_image)
  1470. X            {
  1471. X              i++;
  1472. X              if (i == argc)
  1473. X                Usage("missing server name on -display",True);
  1474. X              server_name=argv[i];
  1475. X            }
  1476. X          break;
  1477. X        }
  1478. X  }
  1479. X  if (display_image)
  1480. X    {
  1481. X      char
  1482. X        *user_default;
  1483. X
  1484. X      /*
  1485. X        Open X server connection.
  1486. X      */
  1487. X      display=XOpenDisplay(server_name);
  1488. X      if (display == (Display *) NULL)
  1489. X        Error("unable to connect to X server",XDisplayName(server_name));
  1490. X      /*
  1491. X        Get user_defaults from X resource database.
  1492. X      */
  1493. X      user_default=XGetDefault(display,application_name,"backdrop");
  1494. X      resource_info.backdrop=IsTrue(user_default);
  1495. X      user_default=XGetDefault(display,application_name,"background");
  1496. X      if (user_default == (char *) NULL)
  1497. X        user_default=XGetDefault(display,application_name,"Background");
  1498. X      if (user_default == (char *) NULL)
  1499. X        user_default="black";
  1500. X      resource_info.background_color=user_default;
  1501. X      user_default=XGetDefault(display,application_name,"borderColor");
  1502. X      if (user_default == (char *) NULL)
  1503. X        user_default=XGetDefault(display,application_name,"BorderColor");
  1504. X      if (user_default == (char *) NULL)
  1505. X        user_default="white";
  1506. X      resource_info.border_color=user_default;
  1507. X      user_default=XGetDefault(display,application_name,"borderWidth");
  1508. X      if (user_default == (char *) NULL)
  1509. X        user_default=XGetDefault(display,application_name,"BorderWidth");
  1510. X      resource_info.border_width=
  1511. X        (user_default == (char *) NULL) ? 2 : atoi(user_default);
  1512. X      clip_geometry=XGetDefault(display,application_name,"clip");
  1513. X      user_default=XGetDefault(display,application_name,"colors");
  1514. X      number_colors=user_default ? atoi(user_default) : 0;
  1515. X      user_default=XGetDefault(display,application_name,"compression");
  1516. X      if (user_default == (char *) NULL)
  1517. X        compression=UnknownCompression;
  1518. X      else
  1519. X        if (*user_default == 'R')
  1520. X          compression=RunlengthEncodedCompression;
  1521. X        else
  1522. X          if (*user_default == 'Q')
  1523. X            compression=QEncodedCompression;
  1524. X          else
  1525. X            compression=UnknownCompression;
  1526. X      user_default=XGetDefault(display,application_name,"delay");
  1527. X      resource_info.delay=
  1528. X        (user_default == (char *) NULL) ? 0 : atoi(user_default);
  1529. X      user_default=XGetDefault(display,application_name,"dither");
  1530. X      dither=IsTrue(user_default);
  1531. X      user_default=XGetDefault(display,application_name,"enhance");
  1532. X      enhance=IsTrue(user_default);
  1533. X      user_default=XGetDefault(display,application_name,"font");
  1534. X      if (user_default == (char *) NULL)
  1535. X        user_default=XGetDefault(display,application_name,"Font");
  1536. X      resource_info.font_name=user_default;
  1537. X      user_default=XGetDefault(display,application_name,"foreground");
  1538. X      if (user_default == (char *) NULL)
  1539. X        user_default=XGetDefault(display,application_name,"Foreground");
  1540. X      if (user_default == (char *) NULL)
  1541. X        user_default="white";
  1542. X      resource_info.foreground_color=user_default;
  1543. X      user_default=XGetDefault(display,application_name,"gamma");
  1544. X      gamma=(user_default == (char *) NULL) ? 0.0 : atof(user_default);
  1545. X      user_default=XGetDefault(display,application_name,"geometry");
  1546. X      if (user_default == (char *) NULL)
  1547. X        user_default=XGetDefault(display,application_name,"Geometry");
  1548. X      image_geometry=user_default;
  1549. X      user_default=XGetDefault(display,application_name,"gray");
  1550. X      gray=IsTrue(user_default);
  1551. X      user_default=XGetDefault(display,application_name,"iconGeometry");
  1552. X      if (user_default == (char *) NULL)
  1553. X        user_default=XGetDefault(display,application_name,"IconGeometry");
  1554. X      resource_info.icon_geometry=user_default;
  1555. X      user_default=XGetDefault(display,application_name,"iconic");
  1556. X      if (user_default == (char *) NULL)
  1557. X        user_default=XGetDefault(display,application_name,"Iconic");
  1558. X      resource_info.iconic=IsTrue(user_default);
  1559. X      user_default=XGetDefault(display,application_name,"inverse");
  1560. X      inverse=IsTrue(user_default);
  1561. X      user_default=XGetDefault(display,application_name,"magnify");
  1562. X      resource_info.magnify=
  1563. X        (user_default == (char *) NULL) ? 2 : Max(atoi(user_default),2);
  1564. X      resource_info.map_type=XGetDefault(display,application_name,"map");
  1565. X      user_default=XGetDefault(display,application_name,"monochrome");
  1566. X      monochrome=IsTrue(user_default);
  1567. X      user_default=XGetDefault(display,application_name,"name");
  1568. X      if (user_default == (char *) NULL)
  1569. X        user_default=XGetDefault(display,application_name,"Name");
  1570. X      resource_info.name=user_default;
  1571. X      user_default=XGetDefault(display,application_name,"noise");
  1572. X      noise=IsTrue(user_default);
  1573. X      user_default=XGetDefault(display,application_name,"normalize");
  1574. X      normalize=IsTrue(user_default);
  1575. X      print_filename=XGetDefault(display,application_name,"print");
  1576. X      user_default=XGetDefault(display,application_name,"reflect");
  1577. X      reflect=IsTrue(user_default);
  1578. X      user_default=XGetDefault(display,application_name,"root");
  1579. X      root=IsTrue(user_default);
  1580. X      user_default=XGetDefault(display,application_name,"rotate");
  1581. X      user_default=XGetDefault(display,application_name,"scale");
  1582. X      if (user_default == (char *) NULL)
  1583. X        user_default=XGetDefault(display,application_name,"Scale");
  1584. X      scale_geometry=user_default;
  1585. X      user_default=XGetDefault(display,application_name,"scene");
  1586. X      scene=(user_default == (char *) NULL) ? 0 : atoi(user_default);
  1587. X      user_default=XGetDefault(display,application_name,"title");
  1588. X      if (user_default == (char *) NULL)
  1589. X        user_default=XGetDefault(display,application_name,"Title");
  1590. X      resource_info.title=user_default;
  1591. X      degrees=(user_default == (char *) NULL) ? 0 : atoi(user_default);
  1592. X      user_default=XGetDefault(display,application_name,"treedepth");
  1593. X      tree_depth=(user_default == (char *) NULL) ? 0 : atoi(user_default);
  1594. X      user_default=XGetDefault(display,application_name,"verbose");
  1595. X      verbose=IsTrue(user_default);
  1596. X      resource_info.visual_type=XGetDefault(display,application_name,"visual");
  1597. X      write_filename=XGetDefault(display,application_name,"write");
  1598. X    }
  1599. X  /*
  1600. X    Parse command line.
  1601. X  */
  1602. X  image_number=0;
  1603. X  for (i=1; i < argc; i++)
  1604. X  {
  1605. X    option=argv[i];
  1606. X    if ((strlen(option) > 1) && ((*option == '-') || (*option == '+')))
  1607. X      switch (*(option+1))
  1608. X      {
  1609. X        case 'b':
  1610. X        {
  1611. X          if (strncmp("backdrop",option+1,5) == 0)
  1612. X            resource_info.backdrop=(*option == '-');
  1613. X          else
  1614. X            if (strncmp("background",option+1,5) == 0)
  1615. X              {
  1616. X                resource_info.background_color=(char *) NULL;
  1617. X                if (*option == '-')
  1618. X                  {
  1619. X                    i++;
  1620. X                    if (i == argc)
  1621. X                      Usage("missing color on -background",True);
  1622. X                    resource_info.background_color=argv[i];
  1623. X                  }
  1624. X              }
  1625. X            else
  1626. X              if (strncmp("bordercolor",option+1,7) == 0)
  1627. X                {
  1628. X                  resource_info.border_color=(char *) NULL;
  1629. X                  if (*option == '-')
  1630. X                    {
  1631. X                      i++;
  1632. X                      if (i == argc)
  1633. X                        Usage("missing color on -bordercolor",True);
  1634. X                      resource_info.border_color=argv[i];
  1635. X                    }
  1636. X                }
  1637. X              else
  1638. X                if (strncmp("borderwidth",option+1,7) == 0)
  1639. X                  {
  1640. X                    resource_info.border_width=0;
  1641. X                    if (*option == '-')
  1642. X                      {
  1643. X                        i++;
  1644. X                        if (i == argc)
  1645. X                          Usage("missing width on -borderwidth",True);
  1646. X                        resource_info.border_width=atoi(argv[i]);
  1647. X                      }
  1648. X                  }
  1649. X                else
  1650. X                  Usage(option,True);
  1651. X          break;
  1652. X        }
  1653. X        case 'c':
  1654. X        {
  1655. X          if (strncmp("clip",option+1,2) == 0)
  1656. X            {
  1657. X              clip_geometry=(char *) NULL;
  1658. X              if (*option == '-')
  1659. X                {
  1660. X                  i++;
  1661. X                  if (i == argc)
  1662. X                    Usage("missing geometry on -clip",True);
  1663. X                  clip_geometry=argv[i];
  1664. X                }
  1665. X            }
  1666. X          else
  1667. X            if (strncmp("color",option+1,3) == 0)
  1668. X              {
  1669. X                number_colors=0;
  1670. X                if (*option == '-')
  1671. X                  {
  1672. X                    i++;
  1673. X                    if (i == argc)
  1674. X                      Usage("missing colors on -colors",True);
  1675. X                    number_colors=atoi(argv[i]);
  1676. X                  }
  1677. X              }
  1678. X            else
  1679. X              if (strncmp("compress",option+1,3) == 0)
  1680. X                {
  1681. X                  compression=NoCompression;
  1682. X                  if (*option == '-')
  1683. X                    {
  1684. X                      i++;
  1685. X                      if (i == argc)
  1686. X                        Usage("missing type on -compress",True);
  1687. X                      if ((*argv[i] == 'R') || (*argv[i] == 'r'))
  1688. X                        compression=RunlengthEncodedCompression;
  1689. X                      else
  1690. X                        if ((*argv[i] == 'Q') || (*argv[i] == 'q'))
  1691. X                          compression=QEncodedCompression;
  1692. X                        else
  1693. X                          Usage("invalid compression type on -compress",True);
  1694. X                    }
  1695. X                }
  1696. X              else
  1697. X                Usage(option,True);
  1698. X          break;
  1699. X        }
  1700. X        case 'd':
  1701. X        {
  1702. X          if (strncmp("delay",option+1,2) == 0)
  1703. X            {
  1704. X              resource_info.delay=0;
  1705. X              if (*option == '-')
  1706. X                {
  1707. X                  i++;
  1708. X                  if (i == argc)
  1709. X                    Usage("missing seconds on -delay",True);
  1710. X                  resource_info.delay=atoi(argv[i]);
  1711. X                }
  1712. X            }
  1713. X          else
  1714. X            if (strncmp("display",option+1,3) == 0)
  1715. X              {
  1716. X                server_name=(char *) NULL;
  1717. X                if (*option == '-')
  1718. X                  {
  1719. X                    i++;
  1720. X                    if (i == argc)
  1721. X                      Usage("missing server name on -display",True);
  1722. X                    server_name=argv[i];
  1723. X                  }
  1724. X              }
  1725. X            else
  1726. X              if (strncmp("dither",option+1,3) == 0)
  1727. X                dither=(*option == '-');
  1728. X              else
  1729. X                Usage(option,True);
  1730. X          break;
  1731. X        }
  1732. X        case 'e':
  1733. X        {
  1734. X          enhance=(*option == '-');
  1735. X          break;
  1736. X        }
  1737. X        case 'f':
  1738. X        {
  1739. X          if (strncmp("font",option+1,3) == 0)
  1740. X            {
  1741. X              resource_info.font_name=(char *) NULL;
  1742. X              if (*option == '-')
  1743. X                {
  1744. X                  i++;
  1745. X                  if (i == argc)
  1746. X                    Usage("missing font name on -font",True);
  1747. X                  resource_info.font_name=argv[i];
  1748. X                }
  1749. X            }
  1750. X          else
  1751. X            if (strncmp("foreground",option+1,3) == 0)
  1752. X              {
  1753. X                resource_info.foreground_color=(char *) NULL;
  1754. X                if (*option == '-')
  1755. X                  {
  1756. X                    i++;
  1757. X                    if (i == argc)
  1758. X                      Usage("missing foreground on -foreground",True);
  1759. X                    resource_info.foreground_color=argv[i];
  1760. X                  }
  1761. X              }
  1762. X            else
  1763. X              Usage(option,True);
  1764. X          break;
  1765. X        }
  1766. X        case 'g':
  1767. X        {
  1768. X          if (strncmp("gamma",option+1,2) == 0)
  1769. X            {
  1770. X              gamma=0.0;
  1771. X              if (*option == '-')
  1772. X                {
  1773. X                  i++;
  1774. X                  if (i == argc)
  1775. X                    Usage("missing gamma on -gamma",True);
  1776. X                  gamma=atof(argv[i]);
  1777. X                }
  1778. X            }
  1779. X          else
  1780. X            if (strncmp("geometry",option+1,2) == 0)
  1781. X              {
  1782. X                image_geometry=(char *) NULL;
  1783. X                if (*option == '-')
  1784. X                  {
  1785. X                    i++;
  1786. X                    if (i == argc)
  1787. X                      Usage("missing geometry on -geometry",True);
  1788. X                    image_geometry=argv[i];
  1789. X                  }
  1790. X              }
  1791. X            else
  1792. X              if (strncmp("gray",option+1,2) == 0)
  1793. X                gray=(*option == '-');
  1794. X              else
  1795. X                Usage(option,True);
  1796. X          break;
  1797. X        }
  1798. X        case 'h':
  1799. X        {
  1800. X          Usage((char *) NULL,True);
  1801. X          break;
  1802. X        }
  1803. X        case 'i':
  1804. X        {
  1805. X          if (strncmp("iconGeometry",option+1,5) == 0)
  1806. X            {
  1807. X              resource_info.icon_geometry=(char *) NULL;
  1808. X              if (*option == '-')
  1809. X                {
  1810. X                  i++;
  1811. X                  if (i == argc)
  1812. X                    Usage("missing geometry on -iconGeometry",True);
  1813. X                  resource_info.icon_geometry=argv[i];
  1814. X                }
  1815. X            }
  1816. X          else
  1817. X            if (strncmp("iconic",option+1,5) == 0)
  1818. X              resource_info.iconic=(*option == '-');
  1819. X            else
  1820. X              if (strncmp("inverse",option+1,2) == 0)
  1821. X                inverse=(*option == '-');
  1822. X              else
  1823. X                Usage(option,True);
  1824. X          break;
  1825. X        }
  1826. X        case 'm':
  1827. X        {
  1828. X          if (strncmp("magnify",option+1,3) == 0)
  1829. X            {
  1830. X              resource_info.magnify=2;
  1831. X              if (*option == '-')
  1832. X                {
  1833. X                  i++;
  1834. X                  if (i == argc)
  1835. X                    Usage("missing level on -magnify",True);
  1836. X                  resource_info.magnify=Max(1 << atoi(argv[i]),2);
  1837. X                }
  1838. X            }
  1839. X          else
  1840. X            if (strncmp("map",option+1,3) == 0)
  1841. X              {
  1842. X                resource_info.map_type=(char *) NULL;
  1843. X                if (*option == '-')
  1844. X                  {
  1845. X                    i++;
  1846. X                    if (i == argc)
  1847. X                      Usage("missing map type on -map",True);
  1848. X                    resource_info.map_type=argv[i];
  1849. X                  }
  1850. X              }
  1851. X            else
  1852. X              if (strncmp("monochrome",option+1,2) == 0)
  1853. X                monochrome=(*option == '-');
  1854. X              else
  1855. X                Usage(option,True);
  1856. X          break;
  1857. X        }
  1858. X        case 'n':
  1859. X        {
  1860. X          if (strncmp("name",option+1,2) == 0)
  1861. X            {
  1862. X              resource_info.name=(char *) NULL;
  1863. X              if (*option == '-')
  1864. X                {
  1865. X                  i++;
  1866. X                  if (i == argc)
  1867. X                    Usage("missing name on -name",True);
  1868. X                  resource_info.name=argv[i];
  1869. X                }
  1870. X            }
  1871. X          else
  1872. X            if (strncmp("noise",option+1,3) == 0)
  1873. X              noise=(*option == '-');
  1874. X            else
  1875. X              if (strncmp("normalize",option+1,3) == 0)
  1876. X                normalize=(*option == '-');
  1877. X              else
  1878. X                Usage(option,True);
  1879. X          break;
  1880. X        }
  1881. X        case 'p':
  1882. X        {
  1883. X          if (strncmp("print",option+1,2) == 0)
  1884. X            {
  1885. X              print_filename=(char *) NULL;
  1886. X              if (*option == '-')
  1887. X                {
  1888. X                  i++;
  1889. X                  if (i == argc)
  1890. X                    Usage("missing file name on -print",True);
  1891. X                  print_filename=argv[i];
  1892. X                  if (access(print_filename,0) == 0)
  1893. X                    {
  1894. X                      char
  1895. X                        answer[2];
  1896. X  
  1897. X                      (void) fprintf(stderr,"Overwrite %s? ",print_filename);
  1898. X                      (void) gets(answer);
  1899. X                      if (!((*answer == 'y') || (*answer == 'Y')))
  1900. X                    exit(1);
  1901. X                    }
  1902. X                }
  1903. X            }
  1904. X          else
  1905. X            Usage(option,True);
  1906. X          break;
  1907. X        }
  1908. X        case 'r':
  1909. X        {
  1910. X          if (strncmp("reflect",option+1,2) == 0)
  1911. X            reflect=(*option == '-');
  1912. X          else
  1913. X            if (strncmp("root",option+1,3) == 0)
  1914. X              root=(*option == '-');
  1915. X            else
  1916. X              if (strncmp("rotate",option+1,3) == 0)
  1917. X                {
  1918. X                  degrees=0.0;
  1919. X                  if (*option == '-')
  1920. X                    {
  1921. X                      i++;
  1922. X                      if (i == argc)
  1923. X                        Usage("missing degrees on -rotate",True);
  1924. X                      degrees=atoi(argv[i]);
  1925. X                    }
  1926. X                }
  1927. X              else
  1928. X                Usage(option,True);
  1929. X          break;
  1930. X        }
  1931. X        case 's':
  1932. X        {
  1933. X          if (strncmp("scale",option+1,3) == 0)
  1934. X            {
  1935. X              scale_geometry=(char *) NULL;
  1936. X              if (*option == '-')
  1937. X                {
  1938. X                  i++;
  1939. X                  if (i == argc)
  1940. X                    Usage("missing scale geometry on -scale",True);
  1941. X                  scale_geometry=argv[i];
  1942. X                }
  1943. X            }
  1944. X          else
  1945. X            if (strncmp("scene",option+1,3) == 0)
  1946. X              {
  1947. X                scene=0;
  1948. X                if (*option == '-')
  1949. X                  {
  1950. X                    i++;
  1951. X                    if (i == argc)
  1952. X                      Usage("missing scene number on -scene",True);
  1953. X                    scene=atoi(argv[i]);
  1954. X                  }
  1955. X              }
  1956. X            else
  1957. X              Usage(option,True);
  1958. X          break;
  1959. X        }
  1960. X        case 't':
  1961. X        {
  1962. X          if (strncmp("title",option+1,2) == 0)
  1963. X            {
  1964. X              resource_info.title=(char *) NULL;
  1965. X              if (*option == '-')
  1966. X                {
  1967. X                  i++;
  1968. X                  if (i == argc)
  1969. X                    Usage("missing title on -title",True);
  1970. X                  resource_info.title=argv[i];
  1971. X                }
  1972. X            }
  1973. X          else
  1974. X            if (strncmp("treedepth",option+1,2) == 0)
  1975. X              {
  1976. X                tree_depth=0;
  1977. X                if (*option == '-')
  1978. X                  {
  1979. X                    i++;
  1980. X                    if (i == argc)
  1981. X                      Usage("missing depth on -treedepth",True);
  1982. X                    tree_depth=atoi(argv[i]);
  1983. X                  }
  1984. X              }
  1985. X            else
  1986. X              Usage(option,True);
  1987. X          break;
  1988. X        }
  1989. X        case 'v':
  1990. X        {
  1991. X          if (strncmp("verbose",option+1,2) == 0)
  1992. X            verbose=(*option == '-');
  1993. X          else
  1994. X            if (strncmp("visual",option+1,2) == 0)
  1995. X              {
  1996. X                resource_info.visual_type=(char *) NULL;
  1997. X                if (*option == '-')
  1998. X                  {
  1999. X                    i++;
  2000. X                    if (i == argc)
  2001. X                      Usage("missing visual class on -visual",True);
  2002. X                    resource_info.visual_type=argv[i];
  2003. X                  }
  2004. X              }
  2005. X            else
  2006. X              Usage(option,True);
  2007. X          break;
  2008. X        }
  2009. X        case 'w':
  2010. X        {
  2011. X          write_filename=(char *) NULL;
  2012. X          if (*option == '-')
  2013. X            {
  2014. X              i++;
  2015. X              if (i == argc)
  2016. X                Usage("missing file name on -write",True);
  2017. X              write_filename=argv[i];
  2018. X              if (access(write_filename,0) == 0)
  2019. X                {
  2020. X                  char
  2021. X                    answer[2];
  2022. X
  2023. X                  (void) fprintf(stderr,"Overwrite %s? ",write_filename);
  2024. X                  (void) gets(answer);
  2025. X                  if (!((*answer == 'y') || (*answer == 'Y')))
  2026. X                    exit(1);
  2027. X                }
  2028. X            }
  2029. X          break;
  2030. X        }
  2031. X        default:
  2032. X        {
  2033. X          Usage((char *) NULL,True);
  2034. X          break;
  2035. X        }
  2036. X      }
  2037. X    else
  2038. X      {
  2039. X        Image
  2040. X          *image,
  2041. X          info_image;
  2042. X
  2043. X        long
  2044. X          start_time;
  2045. X
  2046. X        unsigned int
  2047. X          terminate;
  2048. X
  2049. X        unsigned long
  2050. X          total_colors;
  2051. X
  2052. X        /*
  2053. X          Option is a file name: begin by reading image from specified file.
  2054. X        */
  2055. X        terminate=root;
  2056. X        image_number++;
  2057. X        (void) strcpy(info_image.filename,option);
  2058. X        start_time=time((long *) 0);
  2059. X        image=ReadImage(info_image.filename);
  2060. X        if (image == (Image *) NULL)
  2061. X          continue;
  2062. X        info_image=(*image);
  2063. X        if (scene > 0)
  2064. X          image->scene=scene;
  2065. X        /*
  2066. X          Transform image as defined by the clip, image and scale geometries.
  2067. X        */
  2068. X        image=
  2069. X          TransformImage(image,clip_geometry,image_geometry,scale_geometry);
  2070. X        if (reflect)
  2071. X          {
  2072. X            Image
  2073. X              *reflected_image;
  2074. X
  2075. X            /*
  2076. X              Reverse image scanlines.
  2077. X            */
  2078. X            reflected_image=ReflectImage(image);
  2079. X            if (reflected_image != (Image *) NULL)
  2080. X              {
  2081. X                DestroyImage(image);
  2082. X                image=reflected_image;
  2083. X              }
  2084. X          }
  2085. X        if ((degrees % 360) != 0)
  2086. X          {
  2087. X            Image
  2088. X              *rotated_image;
  2089. X
  2090. X            /*
  2091. X              Rotate image.
  2092. X            */
  2093. X            rotated_image=RotateImage(image,(double) degrees,False);
  2094. X            if (rotated_image != (Image *) NULL)
  2095. X              {
  2096. X                DestroyImage(image);
  2097. X                image=rotated_image;
  2098. X              }
  2099. X          }
  2100. X        if (enhance)
  2101. X          {
  2102. X            Image
  2103. X              *enhanced_image;
  2104. X
  2105. X            /*
  2106. X              Enhance image.
  2107. X            */
  2108. X            enhanced_image=EnhanceImage(image);
  2109. X            if (enhanced_image != (Image *) NULL)
  2110. X              {
  2111. X                DestroyImage(image);
  2112. X                image=enhanced_image;
  2113. X              }
  2114. X          }
  2115. X        if (noise)
  2116. X          {
  2117. X            Image
  2118. X              *noisy_image;
  2119. X
  2120. X            /*
  2121. X              Reduce noise in image.
  2122. X            */
  2123. X            noisy_image=NoisyImage(image);
  2124. X            if (noisy_image != (Image *) NULL)
  2125. X              {
  2126. X                DestroyImage(image);
  2127. X                image=noisy_image;
  2128. X              }
  2129. X          }
  2130. X        if (gamma > 0.0)
  2131. X          (void) GammaImage(image,gamma);
  2132. X        if (inverse)
  2133. X          (void) InverseImage(image);
  2134. X        if (normalize)
  2135. X          (void) NormalizeImage(image);
  2136. X        if (verbose)
  2137. X          {
  2138. X            /*
  2139. X              Initialize image error attributes.
  2140. X            */
  2141. X            if (image->class == DirectClass)
  2142. X              image->colors=NumberColors(image);
  2143. X            total_colors=image->colors;
  2144. X          }
  2145. X        if (gray)
  2146. X          {
  2147. X            /*
  2148. X              Convert image to gray scale PseudoColor class.
  2149. X            */
  2150. X            (void) GrayImage(image);
  2151. X            if (image->class == DirectClass)
  2152. X              QuantizeImage(image,256,tree_depth,dither,True);
  2153. X          }
  2154. X        if (monochrome)
  2155. X          {
  2156. X            register unsigned int
  2157. X              bit;
  2158. X
  2159. X            /*
  2160. X              Convert image to monochrome PseudoColor class.
  2161. X            */
  2162. X            (void) GrayImage(image);
  2163. X            if ((image->class == DirectClass) || (image->colors > 2))
  2164. X              (void) QuantizeImage(image,2,tree_depth,dither,True);
  2165. X            bit=Intensity(image->colormap[0]) > Intensity(image->colormap[1]);
  2166. X            image->colormap[bit].red=0;
  2167. X            image->colormap[bit].green=0;
  2168. X            image->colormap[bit].blue=0;
  2169. X            image->colormap[!bit].red=255;
  2170. X            image->colormap[!bit].green=255;
  2171. X            image->colormap[!bit].blue=255;
  2172. X          }
  2173. X        if (number_colors > 0)
  2174. X          if ((image->class == DirectClass) || (image->colors > number_colors))
  2175. X            QuantizeImage(image,number_colors,tree_depth,dither,True);
  2176. X        if (display != (Display *) NULL)
  2177. X          {
  2178. X            /*
  2179. X              Display image to X server.
  2180. X            */
  2181. X            resource_info.monochrome=monochrome;
  2182. X            resource_info.image_geometry=image_geometry;
  2183. X            if (root)
  2184. X              XDisplayRootImage(display,&resource_info,image);
  2185. X            else
  2186. X              {
  2187. X                char
  2188. X                  *clip_geometry,
  2189. X                  *image_geometry;
  2190. X
  2191. X                image=XDisplayImage(display,&resource_info,argv,argc,image,
  2192. X                  &clip_geometry,&image_geometry,&terminate);
  2193. X                if ((print_filename != (char *) NULL) ||
  2194. X                    (write_filename != (char *) NULL))
  2195. X                  if ((clip_geometry != (char *) NULL) ||
  2196. X                      (image_geometry != (char *) NULL))
  2197. X                    {
  2198. X                      /*
  2199. X                        Apply user specified changes to the image.
  2200. X                      */
  2201. X                      image=TransformImage(image,clip_geometry,image_geometry,
  2202. X                        (char *) NULL);
  2203. X                      if (number_colors > 0)
  2204. X                        if ((image->class == DirectClass) ||
  2205. X                            (image->colors > number_colors))
  2206. X                          QuantizeImage(image,number_colors,tree_depth,dither,
  2207. X                            True);
  2208. X                    }
  2209. X                if (clip_geometry != (char *) NULL)
  2210. X                  (void) free((char *) clip_geometry);
  2211. X                if (image_geometry != (char *) NULL)
  2212. X                  (void) free((char *) image_geometry);
  2213. X              }
  2214. X          }
  2215. X        if (compression != UnknownCompression)
  2216. X          image->compression=compression;
  2217. X        else
  2218. X          image->compression=info_image.compression;
  2219. X        if (print_filename != (char *) NULL)
  2220. X          {
  2221. X            /*
  2222. X              Print image as Encapsulated Postscript.
  2223. X            */
  2224. X            (void) strcpy(image->filename,print_filename);
  2225. X            (void) PrintImage(image,image_geometry);
  2226. X            (void) strcpy(image->filename,info_image.filename);
  2227. X          }
  2228. X        if (write_filename != (char *) NULL)
  2229. X          {
  2230. X            /*
  2231. X              Write image in MIFF format.
  2232. X            */
  2233. X            (void) strcpy(image->filename,write_filename);
  2234. X            (void) WriteImage(image);
  2235. X            (void) strcpy(image->filename,info_image.filename);
  2236. X          }
  2237. X        if (verbose)
  2238. X          {
  2239. X            /*
  2240. X              Display detailed info about the image.
  2241. X            */
  2242. X            (void) fprintf(stderr,"[%d] %s",(image->scene == 0 ? image_number :
  2243. X              image->scene),image->filename);
  2244. X            if (write_filename != (char *) NULL)
  2245. X              (void) fprintf(stderr,"=>%s",write_filename);
  2246. X            (void) fprintf(stderr," %dx%d",info_image.columns,info_image.rows);
  2247. X            if ((info_image.columns != image->columns) ||
  2248. X                (info_image.rows != image->rows))
  2249. X              (void) fprintf(stderr,"=>%dx%d",image->columns,image->rows);
  2250. X            if (image->class == DirectClass)
  2251. X              (void) fprintf(stderr," DirectClass ");
  2252. X            else
  2253. X              (void) fprintf(stderr," PseudoClass ");
  2254. X            if (total_colors != image->colors)
  2255. X              (void) fprintf(stderr,"%d=>",total_colors);
  2256. X            (void) fprintf(stderr,"%dc",image->colors);
  2257. X            if ((number_colors > 0) || gray || monochrome)
  2258. X              {
  2259. X                double
  2260. X                  normalized_maximum_error,
  2261. X                  normalized_mean_error;
  2262. X
  2263. X                unsigned int
  2264. X                  mean_error_per_pixel;
  2265. X
  2266. X                /*
  2267. X                  Measure quantization error.
  2268. X                */
  2269. X                QuantizationError(image,&mean_error_per_pixel,
  2270. X                  &normalized_mean_error,&normalized_maximum_error);
  2271. X                (void) fprintf(stderr," %d/%.6f/%.6fe",mean_error_per_pixel,
  2272. X                  normalized_mean_error,normalized_maximum_error);
  2273. X              }
  2274. X            (void) fprintf(stderr," %ds\n",time((long *) 0)-start_time+1);
  2275. X          }
  2276. X        /*
  2277. X          Deallocate image resources.
  2278. X        */
  2279. X        DestroyImage(image);
  2280. X        if (terminate)
  2281. X          break;
  2282. X      }
  2283. X    }
  2284. X  if (image_number == 0)
  2285. X    Usage("missing an image file name",True);
  2286. X  if (display != (Display *) NULL)
  2287. X    XCloseDisplay(display);
  2288. X  return(False);
  2289. }
  2290. SHAR_EOF
  2291. echo 'File ImageMagick/display.c is complete' &&
  2292. chmod 0755 ImageMagick/display.c ||
  2293. echo 'restore of ImageMagick/display.c failed'
  2294. Wc_c="`wc -c < 'ImageMagick/display.c'`"
  2295. test 148390 -eq "$Wc_c" ||
  2296.     echo 'ImageMagick/display.c: original size 148390, current size' "$Wc_c"
  2297. rm -f _shar_wnt_.tmp
  2298. fi
  2299. # ============= ImageMagick/X.h ==============
  2300. if test -f 'ImageMagick/X.h' -a X"$1" != X"-c"; then
  2301.     echo 'x - skipping ImageMagick/X.h (File already exists)'
  2302.     rm -f _shar_wnt_.tmp
  2303. else
  2304. > _shar_wnt_.tmp
  2305. echo 'x - extracting ImageMagick/X.h (Text)'
  2306. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/X.h' &&
  2307. X
  2308. #undef False
  2309. #undef True
  2310. #include <X11/Xos.h>
  2311. #include <X11/Xlib.h>
  2312. #include <X11/Xutil.h>
  2313. #include <X11/Xatom.h>
  2314. #include <X11/cursorfont.h>
  2315. #include <X11/keysym.h>
  2316. #undef index
  2317. /*
  2318. X  Define declarations.
  2319. */
  2320. #define XStandardPixel(map,color,shift)  map->base_pixel+  \
  2321. X  ((color.red*map->red_max+(1 << (shift-1))) >> shift)*map->red_mult+  \
  2322. X  ((color.green*map->green_max+(1 << (shift-1))) >> shift)*map->green_mult+  \
  2323. X  ((color.blue*map->blue_max+(1 << (shift-1))) >> shift)*map->blue_mult
  2324. X
  2325. /*
  2326. X  Typedef declarations.
  2327. */
  2328. typedef struct _XPixelInfo
  2329. {
  2330. X  unsigned long
  2331. X    background_pixel,
  2332. X    border_pixel,
  2333. X    foreground_pixel,
  2334. X    *pixels;
  2335. } XPixelInfo;
  2336. X
  2337. typedef struct _XResourceInfo
  2338. {
  2339. X  unsigned int
  2340. X    backdrop;
  2341. X
  2342. X  char
  2343. X    *background_color;
  2344. X
  2345. X  char
  2346. X    *border_color;
  2347. X
  2348. X  unsigned int
  2349. X    border_width,
  2350. X    delay;
  2351. X
  2352. X  char
  2353. X    *font_name;
  2354. X
  2355. X  char
  2356. X    *foreground_color,
  2357. X    *icon_geometry;
  2358. X
  2359. X  unsigned int
  2360. X    iconic;
  2361. X
  2362. X  char
  2363. X    *image_geometry;
  2364. X
  2365. X  unsigned int
  2366. X    magnify;
  2367. X
  2368. X  char
  2369. X    *map_type;
  2370. SHAR_EOF
  2371. true || echo 'restore of ImageMagick/X.h failed'
  2372. fi
  2373. echo 'End of ImageMagick part 18'
  2374. echo 'File ImageMagick/X.h is continued in part 19'
  2375. echo 19 > _shar_seq_.tmp
  2376. exit 0
  2377. --
  2378. Dan Heller
  2379. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  2380. Senior Writer                President          comp-sources-x@uunet.uu.net
  2381. argv@ora.com                 argv@zipcode.com
  2382.