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

  1. Newsgroups: comp.sources.x
  2. From: cristy@eplrx7.es.duPont.com (Cristy)
  3. Subject: v20i080:  imagemagic - X11 image processing and display, Part24/38
  4. Message-ID: <1993Jul14.231945.22227@sparky.sterling.com>
  5. X-Md4-Signature: adea864b278bfafee3d20fd90b273cac
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Wed, 14 Jul 1993 23:19:45 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: cristy@eplrx7.es.duPont.com (Cristy)
  12. Posting-number: Volume 20, Issue 80
  13. Archive-name: imagemagic/part24
  14. Environment: X11
  15. Supersedes: imagemagic: Volume 13, Issue 17-37
  16.  
  17. #!/bin/sh
  18. # this is magick.24 (part 24 of ImageMagick)
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file ImageMagick/display.c continued
  21. #
  22. if test ! -r _shar_seq_.tmp; then
  23.     echo 'Please unpack part 1 first!'
  24.     exit 1
  25. fi
  26. (read Scheck
  27.  if test "$Scheck" != 24; then
  28.     echo Please unpack part "$Scheck" next!
  29.     exit 1
  30.  else
  31.     exit 0
  32.  fi
  33. ) < _shar_seq_.tmp || exit 1
  34. if test ! -f _shar_wnt_.tmp; then
  35.     echo 'x - still skipping ImageMagick/display.c'
  36. else
  37. echo 'x - continuing file ImageMagick/display.c'
  38. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/display.c' &&
  39. %                                                                             %
  40. %                                                                             %
  41. %                                                                             %
  42. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  43. %
  44. %  Function XImageWindowCommand makes a transform to the image or image window
  45. %  as specified by a user menu button or keyboard command.
  46. %
  47. %  The format of the XImageWindowCommand routine is:
  48. %
  49. %    loaded_image=XImageWindowCommand(display,resource_info,window,key_symbol,
  50. %      image,state)
  51. %
  52. %  A description of each parameter follows:
  53. %
  54. %    o loaded_image:  Function XImageWindowCommand returns an image when the
  55. %      user chooses 'Load Image' from the command menu.  Otherwise a null
  56. %      image is returned.
  57. %
  58. %    o display: Specifies a connection to an X server; returned from
  59. %      XOpenDisplay.
  60. %
  61. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  62. %
  63. %    o window: Specifies a pointer to a XWindows structure.
  64. %
  65. %    o key_symbol: Specifies a command to perform.
  66. %
  67. %    o image: Specifies a pointer to a Image structure;  XImageWindowCommand
  68. %      may transform the image and return a new image pointer.
  69. %
  70. %    o state: Specifies an unsigned int;  XImageWindowCommand may return a
  71. %      modified state.
  72. %
  73. %
  74. */
  75. static Image *XImageWindowCommand(display,resource_info,window,key_symbol,
  76. X  image,state)
  77. Display
  78. X  *display;
  79. X
  80. XXResourceInfo
  81. X  *resource_info;
  82. X
  83. XXWindows
  84. X  *window;
  85. X
  86. KeySym
  87. X  key_symbol;
  88. X
  89. Image
  90. X  **image;
  91. X
  92. unsigned long
  93. X  *state;
  94. {
  95. X  Image
  96. X    *loaded_image;
  97. X
  98. X  unsigned int
  99. X    height,
  100. X    status,
  101. X    width;
  102. X
  103. X  XEvent
  104. X    event;
  105. X
  106. X  if (*state & InfoMappedState)
  107. X    XWithdrawWindow(display,window->info.id,window->info.screen);
  108. X  XSync(display,False);
  109. X  while (XCheckTypedWindowEvent(display,window->image.id,Expose,&event))
  110. X    XRefreshWindow(display,&window->image,&event);
  111. X  /*
  112. X    Process user command.
  113. X  */
  114. X  loaded_image=(Image *) NULL;
  115. X  width=0;
  116. X  height=0;
  117. X  switch (key_symbol)
  118. X  {
  119. X    case XK_Help:
  120. X    {
  121. X      Usage(False);
  122. X      break;
  123. X    }
  124. X    case XK_Up:
  125. X    case XK_Down:
  126. X    case XK_Left:
  127. X    case XK_Right:
  128. X    {
  129. X      if (*state & ControlState)
  130. X        {
  131. X          RectangleInfo
  132. X            clip_info;
  133. X
  134. X          /*
  135. X            Trim one pixel from edge of image.
  136. X          */
  137. X          clip_info.x=0;
  138. X          clip_info.y=0;
  139. X          clip_info.width=window->image.ximage->width;
  140. X          clip_info.height=window->image.ximage->height;
  141. X          if (key_symbol == XK_Up)
  142. X            {
  143. X              clip_info.y++;
  144. X              clip_info.height--;
  145. X            }
  146. X          if (key_symbol == XK_Down)
  147. X            clip_info.height--;
  148. X          if (key_symbol == XK_Right)
  149. X            {
  150. X              clip_info.x++;
  151. X              clip_info.width--;
  152. X            }
  153. X          if (key_symbol == XK_Left)
  154. X            clip_info.width--;
  155. X          XSetClipGeometry(display,window,&clip_info,*image);
  156. X          width=clip_info.width;
  157. X          height=clip_info.height;
  158. X          /*
  159. X            Prevent image flashing-- do not repaint window background.
  160. X          */
  161. X          XSetWindowBackgroundPixmap(display,window->image.id,None);
  162. X          break;
  163. X        }
  164. X      if (*state & PanMappedState)
  165. X        {
  166. X          /*
  167. X            Pan image by one pixel.
  168. X          */
  169. X          if (key_symbol == XK_Up)
  170. X            if (window->image.y != 0)
  171. X              window->image.y--;
  172. X          if (key_symbol == XK_Down)
  173. X            if ((window->image.y+window->image.height) <
  174. X                (window->image.ximage->height-1))
  175. X              window->image.y++;
  176. X          if (key_symbol == XK_Left)
  177. X            if ((window->image.x+window->image.width) <
  178. X                (window->image.ximage->width-1))
  179. X              window->image.x++;
  180. X          if (key_symbol == XK_Right)
  181. X            if (window->image.x != 0)
  182. X              window->image.x--;
  183. X          XDrawPanRectangle(display,window);
  184. X          XRefreshWindow(display,&window->image,(XEvent *) NULL);
  185. X        }
  186. X      break;
  187. X    }
  188. X    case XK_less:
  189. X    {
  190. X      /*
  191. X        Half image size.
  192. X      */
  193. X      width=window->image.ximage->width >> 1;
  194. X      height=window->image.ximage->height >> 1;
  195. X      break;
  196. X    }
  197. X    case XK_greater:
  198. X    {
  199. X      /*
  200. X        Double the image size.
  201. X      */
  202. X      width=window->image.ximage->width << 1;
  203. X      height=window->image.ximage->height << 1;
  204. X      break;
  205. X    }
  206. X    case XK_slash:
  207. X    case XK_backslash:
  208. X    {
  209. X      /*
  210. X        Rotate image 90 degrees to clockwise or counter-clockwise.
  211. X      */
  212. X      status=XRotateImageWindow(display,window,(unsigned int)
  213. X        (key_symbol == XK_slash ? 90 : 270),image);
  214. X      if (status == False)
  215. X        {
  216. X          XPopupAlert(display,&window->popup,"unable to rotate X image",
  217. X            window->image.name);
  218. X          break;
  219. X        }
  220. X      width=window->image.ximage->height;
  221. X      height=window->image.ximage->width;
  222. X      break;
  223. X    }
  224. X    case XK_a:
  225. X    {
  226. X      /*
  227. X        Annotate the image with text.
  228. X      */
  229. X      status=XAnnotateImageWindow(display,resource_info,window,*image);
  230. X      if (status == False)
  231. X        {
  232. X          XPopupAlert(display,&window->popup,"unable to annotate X image",
  233. X            window->image.name);
  234. X          break;
  235. X        }
  236. X      width=window->image.ximage->width;
  237. X      height=window->image.ximage->height;
  238. X      break;
  239. X    }
  240. X    case XK_c:
  241. X    {
  242. X      /*
  243. X        Composite image.
  244. X      */
  245. X      status=XCompositeImageWindow(display,resource_info,window,image);
  246. X      if (status == False)
  247. X        {
  248. X          XPopupAlert(display,&window->popup,"unable to composite X image",
  249. X            window->image.name);
  250. X          break;
  251. X        }
  252. X      XMakeStandardColormap(display,window->image.visual_info,resource_info,
  253. X        window->image.pixel_info,*image,window->image.map_info);
  254. X      width=window->image.ximage->width;
  255. X      height=window->image.ximage->height;
  256. X      *state|=UpdateColormapState;
  257. X      break;
  258. X    }
  259. X    case XK_i:
  260. X    {
  261. X      char
  262. X        text[2048];
  263. X
  264. X      /*
  265. X        Display information about the image in the info window.
  266. X      */
  267. X      (void) sprintf(text," [%u] %s %dx%d %s ",(*image)->scene,
  268. X        (*image)->filename,window->image.ximage->width,
  269. X        window->image.ximage->height,
  270. X        XVisualClassName(window->info.visual_info));
  271. X      if ((*image)->colors != 0)
  272. X        (void) sprintf(text,"%s%uc ",text,(*image)->colors);
  273. X      (void) strcat(text,(*image)->magick);
  274. X      XSetWindowExtents(display,&window->info,text);
  275. X      XMapWindow(display,window->info.id);
  276. X      XDisplayInfoString(display,&window->info,text);
  277. X      break;
  278. X    }
  279. X    case XK_l:
  280. X    {
  281. X      /*
  282. X        Load image.
  283. X      */
  284. X      loaded_image=XLoadImageWindow(display,resource_info,window,*image);
  285. X      if (loaded_image != (Image *) NULL)
  286. X        *state|=NextImageState | ExitState;
  287. X      break;
  288. X    }
  289. X    case XK_n:
  290. X    case XK_Next:
  291. X    case XK_space:
  292. X    {
  293. X      /*
  294. X        Display next image.
  295. X      */
  296. X      *state|=NextImageState | ExitState;
  297. X      break;
  298. X    }
  299. X    case XK_o:
  300. X    {
  301. X      /*
  302. X        Restore image window to its original size.
  303. X      */
  304. X      if (window->image.clip_geometry != (char *) NULL)
  305. X        {
  306. X          (void) free((char *) window->image.clip_geometry);
  307. X          window->image.clip_geometry=(char *) NULL;
  308. X          window->image.x=0;
  309. X          window->image.y=0;
  310. X        }
  311. X      width=(*image)->columns;
  312. X      height=(*image)->rows;
  313. X      break;
  314. X    }
  315. X    case XK_p:
  316. X    case XK_Prior:
  317. X    case XK_BackSpace:
  318. X    {
  319. X      /*
  320. X        Display previous image.
  321. X      */
  322. X      *state|=LastImageState | ExitState;
  323. X      break;
  324. X    }
  325. X    case XK_q:
  326. X    {
  327. X      /*
  328. X        Exit program
  329. X      */
  330. X      *state|=ExitState;  /* exit program */
  331. X      break;
  332. X    }
  333. X    case XK_r:
  334. X    {
  335. X      /*
  336. X        Reflect image scanlines.
  337. X      */
  338. X      status=XReflectImageWindow(display,window,image);
  339. X      if (status == False)
  340. X        {
  341. X          XPopupAlert(display,&window->popup,"unable to reflect X image",
  342. X            window->image.name);
  343. X          break;
  344. X        }
  345. X      width=window->image.ximage->width;
  346. X      height=window->image.ximage->height;
  347. X      break;
  348. X    }
  349. X    case XK_w:
  350. X    {
  351. X      /*
  352. X        Write image.
  353. X      */
  354. X      status=XWriteImageWindow(display,resource_info,window,image);
  355. X      if (status == False)
  356. X        {
  357. X          XPopupAlert(display,&window->popup,"unable to write X image",
  358. X            window->image.name);
  359. X          break;
  360. X        }
  361. X      break;
  362. X    }
  363. X    case XK_Return:
  364. X      break;
  365. X    default:
  366. X    {
  367. X      if (!IsModifierKey(key_symbol))
  368. X        XBell(display,0);
  369. X      break;
  370. X    }
  371. X  }
  372. X  if ((width != 0) && (height != 0))
  373. X    {
  374. X      unsigned int
  375. X        mask;
  376. X
  377. X      XWindowChanges
  378. X        window_changes;
  379. X
  380. X      /*
  381. X        Image configuration has changed.
  382. X      */
  383. X      status=XConfigureImageWindow(display,resource_info,window,width,height,
  384. X        *image);
  385. X      if (status == False)
  386. X        XPopupAlert(display,&window->popup,"unable to configure X image",
  387. X          window->image.name);
  388. X      /*
  389. X        Window size must not exceed that of the X server screen.
  390. X      */
  391. X      if (width >= XDisplayWidth(display,window->image.screen))
  392. X        width=(XDisplayWidth(display,window->image.screen)*7) >> 3;
  393. X      if (height >= XDisplayHeight(display,window->image.screen))
  394. X        height=(XDisplayHeight(display,window->image.screen)*7) >> 3;
  395. X      if ((width == window->image.width) && (height == window->image.height))
  396. X        {
  397. X          *state|=UpdateConfigurationState;
  398. X          return(loaded_image);
  399. X        }
  400. X      /*
  401. X        Notify window manager of the new configuration.
  402. X      */
  403. X      window_changes.width=width;
  404. X      window_changes.height=height;
  405. X      mask=CWWidth | CWHeight;
  406. X      if (resource_info->backdrop)
  407. X        {
  408. X          window_changes.x=
  409. X            XDisplayWidth(display,window->image.screen)/2-width/2;
  410. X          window_changes.y=
  411. X            XDisplayHeight(display,window->image.screen)/2-height/2;
  412. X          mask|=CWX | CWY;
  413. X        }
  414. X      XReconfigureWMWindow(display,window->image.id,window->image.screen,mask,
  415. X        &window_changes);
  416. X      *state|=ReconfigureImageState;
  417. X    }
  418. X  return(loaded_image);
  419. }
  420. X
  421. /*
  422. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  423. %                                                                             %
  424. %                                                                             %
  425. %                                                                             %
  426. %   X L o a d I m a g e W i n d o w                                           %
  427. %                                                                             %
  428. %                                                                             %
  429. %                                                                             %
  430. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  431. %
  432. %  Function XLoadImageWindow loads an image from a file.
  433. %
  434. %  The format of the XLoadImageWindow routine is:
  435. %
  436. %    loaded_image=XLoadImageWindow(display,resource_info,window,image)
  437. %
  438. %  A description of each parameter follows:
  439. %
  440. %    o status: Function XLoadImageWindow returns an image if can be loaded
  441. %      successfully.  Otherwise a null image is returned.
  442. %
  443. %    o display: Specifies a connection to an X server; returned from
  444. %      XOpenDisplay.
  445. %
  446. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  447. %
  448. %    o window: Specifies a pointer to a XWindows structure.
  449. %
  450. %    o image: Specifies a pointer to a Image structure;  returned from
  451. %      ReadImage.
  452. %
  453. %
  454. */
  455. static Image *XLoadImageWindow(display,resource_info,window,image)
  456. Display
  457. X  *display;
  458. X
  459. XXResourceInfo
  460. X  *resource_info;
  461. X
  462. XXWindows
  463. X  *window;
  464. X
  465. Image
  466. X  *image;
  467. {
  468. X  char
  469. X    filename[2048],
  470. X    text[2048];
  471. X
  472. X  Image
  473. X    *loaded_image;
  474. X
  475. X  /*
  476. X    Request file name from user.
  477. X  */
  478. X  (void) strcpy(filename,image->filename);
  479. X  XPopupQuery(display,&window->popup,"File name:",filename);
  480. X  if (*filename == '\0')
  481. X    return((Image *) NULL);
  482. X  /*
  483. X    Map info window.
  484. X  */
  485. X  (void) strcpy(text," Loading image... ");
  486. X  XSetWindowExtents(display,&window->info,text);
  487. X  XMapWindow(display,window->info.id);
  488. X  XDisplayInfoString(display,&window->info,text);
  489. X  /*
  490. X    Load the image.
  491. X  */
  492. X  XDefineCursor(display,window->image.id,window->image.busy_cursor);
  493. X  XFlush(display);
  494. X  (void) strcpy(resource_info->image_info->filename,filename);
  495. X  loaded_image=ReadImage(resource_info->image_info);
  496. X  XDefineCursor(display,window->image.id,window->image.cursor);
  497. X  XWithdrawWindow(display,window->info.id,window->info.screen);
  498. X  if (loaded_image == (Image *) NULL)
  499. X    XPopupAlert(display,&window->popup,"unable to load image",filename);
  500. X  return(loaded_image);
  501. }
  502. X
  503. /*
  504. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  505. %                                                                             %
  506. %                                                                             %
  507. %                                                                             %
  508. %   X M a g n i f y W i n d o w C o m m a n d                                 %
  509. %                                                                             %
  510. %                                                                             %
  511. %                                                                             %
  512. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  513. %
  514. %  Function XMagnifyWindowCommand moves the image within the magnify window by
  515. %  one pixel as specified by the key symbol.
  516. %
  517. %  The format of the XMagnifyWindowCommand routine is:
  518. %
  519. %    XMagnifyWindowCommand(display,resource_info,window,key_symbol)
  520. %
  521. %  A description of each parameter follows:
  522. %
  523. %    o display: Specifies a connection to an X server; returned from
  524. %      XOpenDisplay.
  525. %
  526. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  527. %
  528. %    o window: Specifies a pointer to a XWindows structure.
  529. %
  530. %    o key_symbol: Specifies a KeySym which indicates which side of the image
  531. %      to trim.
  532. %
  533. %
  534. */
  535. static void XMagnifyWindowCommand(display,resource_info,window,key_symbol)
  536. Display
  537. X  *display;
  538. X
  539. XXResourceInfo
  540. X  *resource_info;
  541. X
  542. XXWindows
  543. X  *window;
  544. X
  545. KeySym
  546. X  key_symbol;
  547. {
  548. X  /*
  549. X    User specified a magnify factor or position.
  550. X  */
  551. X  switch (key_symbol)
  552. X  {
  553. X    case XK_Home:
  554. X    {
  555. X      window->magnify.x=window->image.width >> 1;
  556. X      window->magnify.y=window->image.height >> 1;
  557. X      break;
  558. X    }
  559. X    case XK_Left:
  560. X    {
  561. X      if (window->magnify.x > 0)
  562. X        window->magnify.x--;
  563. X      break;
  564. X    }
  565. X    case XK_Up:
  566. X    {
  567. X      if (window->magnify.y > 0)
  568. X        window->magnify.y--;
  569. X      break;
  570. X    }
  571. X    case XK_Right:
  572. X    {
  573. X      if (window->magnify.x < (window->image.width-1))
  574. X        window->magnify.x++;
  575. X      break;
  576. X    }
  577. X    case XK_Down:
  578. X    {
  579. X      if (window->magnify.y < (window->image.height-1))
  580. X        window->magnify.y++;
  581. X      break;
  582. X    }
  583. X    case XK_0:
  584. X    case XK_1:
  585. X    case XK_2:
  586. X    case XK_3:
  587. X    case XK_4:
  588. X    case XK_5:
  589. X    case XK_6:
  590. X    case XK_7:
  591. X    case XK_8:
  592. X    case XK_9:
  593. X    {
  594. X      resource_info->magnify=key_symbol-XK_0;
  595. X      break;
  596. X    }
  597. X    default:
  598. X      break;
  599. X  }
  600. X  XMakeMagnifyImage(display,resource_info,window);
  601. }
  602. X
  603. /*
  604. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  605. %                                                                             %
  606. %                                                                             %
  607. %                                                                             %
  608. %   X M a g n i f y I m a g e W i n d o w                                     %
  609. %                                                                             %
  610. %                                                                             %
  611. %                                                                             %
  612. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  613. %
  614. %  Function XMagnifyImageWindow magnifies portions of the image as indicated
  615. %  by the pointer.  The magnified portion is displayed in a separate window.
  616. %
  617. %  The format of the XMagnifyImageWindow routine is:
  618. %
  619. %    XMagnifyImageWindow(display,resource_info,window,event)
  620. %
  621. %  A description of each parameter follows:
  622. %
  623. %    o display: Specifies a connection to an X server;  returned from
  624. %      XOpenDisplay.
  625. %
  626. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  627. %
  628. %    o window: Specifies a pointer to a XWindows structure.
  629. %
  630. %    o event: Specifies a pointer to a XEvent structure.  If it is NULL,
  631. %      the entire image is refreshed.
  632. %
  633. %
  634. */
  635. static void XMagnifyImageWindow(display,resource_info,window,event)
  636. Display
  637. X  *display;
  638. X
  639. XXResourceInfo
  640. X  *resource_info;
  641. X
  642. XXWindows
  643. X  *window;
  644. X
  645. XXEvent
  646. X  *event;
  647. {
  648. X  char
  649. X    text[2048];
  650. X
  651. X  register int
  652. X    x,
  653. X    y;
  654. X
  655. X  unsigned long
  656. X    state;
  657. X
  658. X  /*
  659. X    Map info window.
  660. X  */
  661. X  state=DefaultState;
  662. X  (void) sprintf(text," +%u+%u ",window->image.width,window->image.height);
  663. X  XSetWindowExtents(display,&window->info,text);
  664. X  XMapWindow(display,window->info.id);
  665. X  state|=InfoMappedState;
  666. X  /*
  667. X    Update magnified image until the mouse button is released.
  668. X  */
  669. X  XDefineCursor(display,window->image.id,window->magnify.cursor);
  670. X  x=event->xbutton.x;
  671. X  y=event->xbutton.y;
  672. X  window->magnify.x=x+1;
  673. X  window->magnify.y=y+1;
  674. X  do
  675. X  {
  676. X    /*
  677. X      Check boundary conditions.
  678. X    */
  679. X    if (x < 0)
  680. X      x=0;
  681. X    else
  682. X      if (x >= window->image.width)
  683. X        x=window->image.width-1;
  684. X    if (y < 0)
  685. X      y=0;
  686. X    else
  687. X     if (y >= window->image.height)
  688. X       y=window->image.height-1;
  689. X    if ((window->magnify.x != (window->image.x+x)) ||
  690. X        (window->magnify.y != (window->image.y+y)))
  691. X      {
  692. X        window->magnify.x=window->image.x+x;
  693. X        window->magnify.y=window->image.y+y;
  694. X        /*
  695. X          Map and unmap info window as text cursor crosses its boundaries.
  696. X        */
  697. X        if (state & InfoMappedState)
  698. X          {
  699. X            if ((x < (window->info.x+window->info.width)) &&
  700. X                (y < (window->info.y+window->info.height)))
  701. X              {
  702. X                XWithdrawWindow(display,window->info.id,window->info.screen);
  703. X                state&=(~InfoMappedState);
  704. X              }
  705. X          }
  706. X        else
  707. X          if ((x > (window->info.x+window->info.width)) ||
  708. X              (y > (window->info.y+window->info.height)))
  709. X            {
  710. X              XMapWindow(display,window->info.id);
  711. X              state|=InfoMappedState;
  712. X            }
  713. X        if (state & InfoMappedState)
  714. X          {
  715. X            /*
  716. X              Display pointer position.
  717. X            */
  718. X            (void) sprintf(text," %+d%+d ",window->magnify.x,window->magnify.y);
  719. X            XDisplayInfoString(display,&window->info,text);
  720. X          }
  721. X        /*
  722. X          Display magnified image.
  723. X        */
  724. X        XMakeMagnifyImage(display,resource_info,window);
  725. X      }
  726. X    /*
  727. X      Wait for next event.
  728. X    */
  729. X    XWindowEvent(display,window->image.id,ButtonPressMask | Button3MotionMask |
  730. X      ButtonReleaseMask | ExposureMask,event);
  731. X    switch (event->type)
  732. X    {
  733. X      case ButtonPress:
  734. X        break;
  735. X      case ButtonRelease:
  736. X      {
  737. X        /*
  738. X          User has finished magnifying image.
  739. X        */
  740. X        if (event->xbutton.button != Button3)
  741. X          break;
  742. X        x=event->xbutton.x;
  743. X        y=event->xbutton.y;
  744. X        state|=ExitState;
  745. X        break;
  746. X      }
  747. X      case Expose:
  748. X      {
  749. X        /*
  750. X          Refresh image window.
  751. X        */
  752. X        XRefreshWindow(display,&window->image,event);
  753. X        break;
  754. X      }
  755. X      case MotionNotify:
  756. X      {
  757. X        /*
  758. X          Discard pending button motion events.
  759. X        */
  760. X        while (XCheckMaskEvent(display,Button3MotionMask,event));
  761. X        x=event->xmotion.x;
  762. X        y=event->xmotion.y;
  763. X        break;
  764. X      }
  765. X      default:
  766. X        break;
  767. X    }
  768. X  } while (!(state & ExitState));
  769. X  /*
  770. X    Check boundary conditions.
  771. X  */
  772. X  if (x < 0)
  773. X    x=0;
  774. X  else
  775. X    if (x >= window->image.width)
  776. X      x=window->image.width-1;
  777. X  window->magnify.x=window->image.x+x;
  778. X  if (y < 0)
  779. X    y=0;
  780. X  else
  781. X   if (y >= window->image.height)
  782. X     y=window->image.height-1;
  783. X  window->magnify.y=window->image.y+y;
  784. X  /*
  785. X    Display magnified image.
  786. X  */
  787. X  XMakeMagnifyImage(display,resource_info,window);
  788. X  /*
  789. X    Restore cursor.
  790. X  */
  791. X  XDefineCursor(display,window->image.id,window->image.cursor);
  792. X  if (state & InfoMappedState)
  793. X    XWithdrawWindow(display,window->info.id,window->info.screen);
  794. }
  795. X
  796. /*
  797. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  798. %                                                                             %
  799. %                                                                             %
  800. %                                                                             %
  801. %   X M a k e M a g n i f y C u r s o r                                       %
  802. %                                                                             %
  803. %                                                                             %
  804. %                                                                             %
  805. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  806. %
  807. %  Function XMakeMagnifyCursor creates a crosshairs X11 cursor.
  808. %
  809. %  The format of the XMakeMagnifyCursor routine is:
  810. %
  811. %      XMakeMagnifyCursor(display,window,colormap,background_color,
  812. %        foreground_color)
  813. %
  814. %  A description of each parameter follows:
  815. %
  816. %    o display: Specifies a connection to an X server;  returned from
  817. %      XOpenDisplay.
  818. %
  819. %    o window: Specifies the ID of the window for which the cursor is
  820. %      assigned.
  821. %
  822. %    o colormap: Specifies the ID of the colormap from which the background
  823. %      and foreground color will be retrieved.
  824. %
  825. %    o background_color: Specifies the color to use for the cursor background.
  826. %
  827. %    o foreground_color: Specifies the color to use for the cursor foreground.
  828. %
  829. %
  830. */
  831. static Cursor XMakeMagnifyCursor(display,window,colormap,background_color,
  832. X  foreground_color)
  833. Display
  834. X  *display;
  835. X
  836. Window
  837. X  window;
  838. X
  839. Colormap
  840. X  colormap;
  841. X
  842. char
  843. X  *background_color,
  844. X  *foreground_color;
  845. {
  846. #define scope_height 17
  847. #define scope_x_hot 8
  848. #define scope_y_hot 8
  849. #define scope_width 17
  850. X
  851. X  static unsigned char scope_bits[] =
  852. X  {
  853. X    0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
  854. X    0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
  855. X    0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
  856. X    0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
  857. X    0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
  858. X  };
  859. X
  860. X  static unsigned char scope_mask_bits[] =
  861. X  {
  862. X    0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
  863. X    0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
  864. X    0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
  865. X    0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
  866. X    0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
  867. X  };
  868. X
  869. X  Cursor
  870. X    cursor;
  871. X
  872. X  Pixmap
  873. X    mask,
  874. X    source;
  875. X
  876. X  XColor
  877. X    background,
  878. X    foreground;
  879. X
  880. X  source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
  881. X    scope_height);
  882. X  mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
  883. X    scope_width,scope_height);
  884. X  if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
  885. X    Error("unable to create pixmap",(char *) NULL);
  886. X  XParseColor(display,colormap,background_color,&background);
  887. X  XParseColor(display,colormap,foreground_color,&foreground);
  888. X  cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
  889. X    scope_x_hot,scope_y_hot);
  890. X  XFreePixmap(display,source);
  891. X  XFreePixmap(display,mask);
  892. X  return(cursor);
  893. }
  894. X
  895. /*
  896. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  897. %                                                                             %
  898. %                                                                             %
  899. %                                                                             %
  900. %   X M a k e M a g n i f y I m a g e                                         %
  901. %                                                                             %
  902. %                                                                             %
  903. %                                                                             %
  904. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  905. %
  906. %  Function XMakeMagnifyImage magnifies a region of an X image and displays it.
  907. %
  908. %  The format of the XMakeMagnifyImage routine is:
  909. %
  910. %      XMakeMagnifyImage(display,resource_info,window)
  911. %
  912. %  A description of each parameter follows:
  913. %
  914. %    o display: Specifies a connection to an X server;  returned from
  915. %      XOpenDisplay.
  916. %
  917. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  918. %
  919. %    o window: Specifies a pointer to a XWindows structure.
  920. %
  921. %
  922. */
  923. static void XMakeMagnifyImage(display,resource_info,window)
  924. Display
  925. X  *display;
  926. X
  927. XXResourceInfo
  928. X  *resource_info;
  929. X
  930. XXWindows
  931. X  *window;
  932. {
  933. X  register int
  934. X    x,
  935. X    y;
  936. X
  937. X  register unsigned char
  938. X    *p,
  939. X    *q;
  940. X
  941. X  register unsigned int
  942. X    j,
  943. X    k,
  944. X    l;
  945. X
  946. X  static char
  947. X    text[2048];
  948. X
  949. X  static unsigned int
  950. X    previous_magnify=0;
  951. X
  952. X  static XWindowInfo
  953. X    magnify_window;
  954. X
  955. X  unsigned int
  956. X    height,
  957. X    i,
  958. X    magnify,
  959. X    scanline_pad,
  960. X    width;
  961. X
  962. X  XColor
  963. X    color;
  964. X
  965. X  XImage
  966. X    *ximage;
  967. X
  968. X  /*
  969. X    Check boundry conditions.
  970. X  */
  971. X  magnify=1;
  972. X  for (i=1; i < resource_info->magnify; i++)
  973. X    magnify<<=1;
  974. X  while ((magnify*window->image.ximage->width) < window->magnify.width)
  975. X    magnify<<=1;
  976. X  while ((magnify*window->image.ximage->height) < window->magnify.height)
  977. X    magnify<<=1;
  978. X  while (magnify > window->magnify.width)
  979. X    magnify>>=1;
  980. X  while (magnify > window->magnify.height)
  981. X    magnify>>=1;
  982. X  if (magnify != previous_magnify)
  983. X    {
  984. X      unsigned int
  985. X        status;
  986. X
  987. X      XTextProperty
  988. X        window_name;
  989. X
  990. X      /*
  991. X        New magnify factor:  update magnify window name.
  992. X      */
  993. X      i=0;
  994. X      while ((1 << i) <= magnify)
  995. X        i++;
  996. X      (void) sprintf(window->magnify.name,"Magnify %uX",i);
  997. X      status=XStringListToTextProperty(&window->magnify.name,1,&window_name);
  998. X      if (status != 0)
  999. X        XSetWMName(display,window->magnify.id,&window_name);
  1000. X    }
  1001. X  previous_magnify=magnify;
  1002. X  ximage=window->image.ximage;
  1003. X  width=window->magnify.ximage->width;
  1004. X  height=window->magnify.ximage->height;
  1005. X  x=window->magnify.x-(width/magnify/2);
  1006. X  if (x < 0)
  1007. X    x=0;
  1008. X  else
  1009. X    if (x > (ximage->width-(width/magnify)))
  1010. X      x=ximage->width-width/magnify;
  1011. X  y=window->magnify.y-(height/magnify/2);
  1012. X  if (y < 0)
  1013. X    y=0;
  1014. X  else
  1015. X    if (y > (ximage->height-(height/magnify)))
  1016. X      y=ximage->height-height/magnify;
  1017. X  q=(unsigned char *) window->magnify.ximage->data;
  1018. X  scanline_pad=window->magnify.ximage->bytes_per_line-
  1019. X    ((width*window->magnify.ximage->bits_per_pixel) >> 3);
  1020. X  if (ximage->bits_per_pixel < 8)
  1021. X    {
  1022. X      register unsigned char
  1023. X        byte,
  1024. X        p_bit,
  1025. X        q_bit;
  1026. X
  1027. X      register unsigned int
  1028. X        plane;
  1029. X
  1030. X      switch (ximage->bitmap_bit_order)
  1031. X      {
  1032. X        case LSBFirst:
  1033. X        {
  1034. X          /*
  1035. X            Magnify little-endian bitmap.
  1036. X          */
  1037. X          for (i=0; i < height; i+=magnify)
  1038. X          {
  1039. X            /*
  1040. X              Propogate pixel magnify rows.
  1041. X            */
  1042. X            for (j=0; j < magnify; j++)
  1043. X            {
  1044. X              p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
  1045. X                ((x*ximage->bits_per_pixel) >> 3);
  1046. X              p_bit=(x*ximage->bits_per_pixel) & 0x07;
  1047. X              q_bit=0;
  1048. X              byte=0;
  1049. X              for (k=0; k < width; k+=magnify)
  1050. X              {
  1051. X                /*
  1052. X                  Propogate pixel magnify columns.
  1053. X                */
  1054. X                for (l=0; l < magnify; l++)
  1055. X                {
  1056. X                  /*
  1057. X                    Propogate each bit plane.
  1058. X                  */
  1059. X                  for (plane=0; plane < ximage->bits_per_pixel; plane++)
  1060. X                  {
  1061. X                    byte>>=1;
  1062. X                    if (*p & (0x01 << (p_bit+plane)))
  1063. X                      byte|=0x80;
  1064. X                    q_bit++;
  1065. X                    if (q_bit == 8)
  1066. X                      {
  1067. X                        *q++=byte;
  1068. X                        q_bit=0;
  1069. X                        byte=0;
  1070. X                      }
  1071. X                  }
  1072. X                }
  1073. X                p_bit+=ximage->bits_per_pixel;
  1074. X                if (p_bit == 8)
  1075. X                  {
  1076. X                    p++;
  1077. X                    p_bit=0;
  1078. X                  }
  1079. X                if (q_bit != 0)
  1080. X                  *q=byte >> (8-q_bit);
  1081. X                q+=scanline_pad;
  1082. X              }
  1083. X            }
  1084. X            y++;
  1085. X          }
  1086. X          break;
  1087. X        }
  1088. X        case MSBFirst:
  1089. X        default:
  1090. X        {
  1091. X          /*
  1092. X            Magnify big-endian bitmap.
  1093. X          */
  1094. X          for (i=0; i < height; i+=magnify)
  1095. X          {
  1096. X            /*
  1097. X              Propogate pixel magnify rows.
  1098. X            */
  1099. X            for (j=0; j < magnify; j++)
  1100. X            {
  1101. X              p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
  1102. X                ((x*ximage->bits_per_pixel) >> 3);
  1103. X              p_bit=(x*ximage->bits_per_pixel) & 0x07;
  1104. X              q_bit=0;
  1105. X              byte=0;
  1106. X              for (k=0; k < width; k+=magnify)
  1107. X              {
  1108. X                /*
  1109. X                  Propogate pixel magnify columns.
  1110. X                */
  1111. X                for (l=0; l < magnify; l++)
  1112. X                {
  1113. X                  /*
  1114. X                    Propogate each bit plane.
  1115. X                  */
  1116. X                  for (plane=0; plane < ximage->bits_per_pixel; plane++)
  1117. X                  {
  1118. X                    byte<<=1;
  1119. X                    if (*p & (0x80 >> (p_bit+plane)))
  1120. X                      byte|=0x01;
  1121. X                    q_bit++;
  1122. X                    if (q_bit == 8)
  1123. X                      {
  1124. X                        *q++=byte;
  1125. X                        q_bit=0;
  1126. X                        byte=0;
  1127. X                      }
  1128. X                  }
  1129. X                }
  1130. X                p_bit+=ximage->bits_per_pixel;
  1131. X                if (p_bit == 8)
  1132. X                  {
  1133. X                    p++;
  1134. X                    p_bit=0;
  1135. X                  }
  1136. X                if (q_bit != 0)
  1137. X                  *q=byte << (8-q_bit);
  1138. X                q+=scanline_pad;
  1139. X              }
  1140. X            }
  1141. X            y++;
  1142. X          }
  1143. X          break;
  1144. X        }
  1145. X      }
  1146. X    }
  1147. X  else
  1148. X    switch (ximage->bits_per_pixel)
  1149. X    {
  1150. X      case 8:
  1151. X      {
  1152. X        /*
  1153. X          Magnify 8 bit X image.
  1154. X        */
  1155. X        for (i=0; i < height; i+=magnify)
  1156. X        {
  1157. X          /*
  1158. X            Propogate pixel magnify rows.
  1159. X          */
  1160. X          for (j=0; j < magnify; j++)
  1161. X          {
  1162. X            p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
  1163. X              ((x*ximage->bits_per_pixel) >> 3);
  1164. X            for (k=0; k < width; k+=magnify)
  1165. X            {
  1166. X              /*
  1167. X                Propogate pixel magnify columns.
  1168. X              */
  1169. X              for (l=0; l < magnify; l++)
  1170. X                *q++=(*p);
  1171. X              p++;
  1172. X            }
  1173. X            q+=scanline_pad;
  1174. X          }
  1175. X          y++;
  1176. X        }
  1177. X        break;
  1178. X      }
  1179. X      default:
  1180. X      {
  1181. X        register unsigned int
  1182. X          bytes_per_pixel,
  1183. X          m;
  1184. X
  1185. X        /*
  1186. X          Magnify multi-byte X image.
  1187. X        */
  1188. X        bytes_per_pixel=ximage->bits_per_pixel >> 3;
  1189. X        for (i=0; i < height; i+=magnify)
  1190. X        {
  1191. X          /*
  1192. X            Propogate pixel magnify rows.
  1193. X          */
  1194. X          for (j=0; j < magnify; j++)
  1195. X          {
  1196. X            p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
  1197. X              ((x*ximage->bits_per_pixel) >> 3);
  1198. X            for (k=0; k < width; k+=magnify)
  1199. X            {
  1200. X              /*
  1201. X                Propogate pixel magnify columns.
  1202. X              */
  1203. X              for (l=0; l < magnify; l++)
  1204. X                for (m=0; m < bytes_per_pixel; m++)
  1205. X                  *q++=(*(p+m));
  1206. X              p+=bytes_per_pixel;
  1207. X            }
  1208. X            q+=scanline_pad;
  1209. X          }
  1210. X          y++;
  1211. X        }
  1212. X        break;
  1213. X      }
  1214. X    }
  1215. X  /*
  1216. X    Copy X image to magnify pixmap.
  1217. X  */
  1218. X  x=window->magnify.x-(width/magnify/2);
  1219. X  if (x < 0)
  1220. X    x=width/2-window->magnify.x*magnify;
  1221. X  else
  1222. X    if (x > (ximage->width-(width/magnify)))
  1223. X      x=(ximage->width-window->magnify.x)*magnify-width/2;
  1224. X    else
  1225. X      x=0;
  1226. X  y=window->magnify.y-(height/magnify/2);
  1227. X  if (y < 0)
  1228. X    y=height/2-window->magnify.y*magnify;
  1229. X  else
  1230. X    if (y > (ximage->height-(height/magnify)))
  1231. X      y=(ximage->height-window->magnify.y)*magnify-height/2;
  1232. X    else
  1233. X      y=0;
  1234. X  if ((x != 0) || (y != 0))
  1235. X    XFillRectangle(display,window->magnify.pixmap,
  1236. X      window->magnify.highlight_context,0,0,width,height);
  1237. X  XPutImage(display,window->magnify.pixmap,window->magnify.graphic_context,
  1238. X    window->magnify.ximage,0,0,x,y,width-x,height-y);
  1239. X  if ((magnify > 1) && ((magnify <= (width/2)) && (magnify <= (height/2))))
  1240. X    {
  1241. X      /*
  1242. X        Highlight center pixel.
  1243. X      */
  1244. X      x=window->magnify.width/2;
  1245. X      y=window->magnify.height/2;
  1246. X      XSetForeground(display,window->magnify.graphic_context,
  1247. X        window->magnify.pixel_info->background_color.pixel);
  1248. X      XDrawRectangle(display,window->magnify.pixmap,
  1249. X        window->magnify.graphic_context,x+1,y+1,magnify-2,magnify-2);
  1250. X      XSetForeground(display,window->magnify.graphic_context,
  1251. X        window->magnify.pixel_info->foreground_color.pixel);
  1252. X      XDrawRectangle(display,window->magnify.pixmap,
  1253. X        window->magnify.graphic_context,x,y,magnify,magnify);
  1254. X    }
  1255. X  /*
  1256. X    Show center pixel color.
  1257. X  */
  1258. X  color.pixel=
  1259. X    XGetPixel(window->image.ximage,window->magnify.x,window->magnify.y);
  1260. X  XQueryColor(display,window->image.map_info->colormap,&color);
  1261. X  if (window->magnify.depth > 12)
  1262. X    (void) sprintf(text,"%+d%+d  (%3u,%3u,%3u)",window->magnify.x,
  1263. X      window->magnify.y,color.red >> 8,color.green >> 8,color.blue >> 8);
  1264. X  else
  1265. X    (void) sprintf(text,"%+d%+d  (%3u,%3u,%3u)  %lu ",window->magnify.x,
  1266. X      window->magnify.y,color.red >> 8,color.green >> 8,color.blue >> 8,
  1267. X      color.pixel);
  1268. X  height=window->magnify.font_info->ascent+window->magnify.font_info->descent;
  1269. X  XDrawImageString(display,window->magnify.pixmap,
  1270. X    window->magnify.graphic_context,
  1271. X    (3*window->magnify.font_info->max_bounds.width) >> 2,
  1272. X    window->magnify.font_info->ascent+(height >> 2),text,strlen(text));
  1273. X  /*
  1274. X    Refresh magnify window.
  1275. X  */
  1276. X  magnify_window=window->magnify;
  1277. X  magnify_window.x=0;
  1278. X  magnify_window.y=0;
  1279. X  XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
  1280. }
  1281. X
  1282. /*
  1283. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1284. %                                                                             %
  1285. %                                                                             %
  1286. %                                                                             %
  1287. %   X M a k e P a n I m a g e                                                 %
  1288. %                                                                             %
  1289. %                                                                             %
  1290. %                                                                             %
  1291. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1292. %
  1293. %  Function XMakePanImage creates a thumbnail of the image and displays it in
  1294. %  the pan icon window.
  1295. %
  1296. %  The format of the XMakePanImage routine is:
  1297. %
  1298. %      XMakePanImage(display,resource_info,window,image)
  1299. %
  1300. %  A description of each parameter follows:
  1301. %
  1302. %    o display: Specifies a connection to an X server;  returned from
  1303. %      XOpenDisplay.
  1304. %
  1305. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1306. %
  1307. %    o window: Specifies a pointer to a XWindows structure.
  1308. %
  1309. %    o image: Specifies a pointer to a Image structure;  returned from
  1310. %      ReadImage.
  1311. %
  1312. %
  1313. */
  1314. static void XMakePanImage(display,resource_info,window,image)
  1315. Display
  1316. X  *display;
  1317. X
  1318. XXResourceInfo
  1319. X  *resource_info;
  1320. X
  1321. XXWindows
  1322. X  *window;
  1323. X
  1324. Image
  1325. X  *image;
  1326. {
  1327. X  unsigned int
  1328. X    status;
  1329. X
  1330. X  /*
  1331. X    Create and display image for panning icon.
  1332. X  */
  1333. X  XDefineCursor(display,window->image.id,window->image.busy_cursor);
  1334. X  XFlush(display);
  1335. X  window->pan.x=window->image.x;
  1336. X  window->pan.y=window->image.y;
  1337. X  status=XMakeImage(display,resource_info,&window->pan,image,window->pan.width,
  1338. X    window->pan.height);
  1339. X  status|=XMakePixmap(display,resource_info,&window->pan);
  1340. X  if (status == False)
  1341. X    Error("unable to create pan icon image",(char *) NULL);
  1342. X  XSetWindowBackgroundPixmap(display,window->pan.id,window->pan.pixmap);
  1343. X  XClearWindow(display,window->pan.id);
  1344. X  XDrawPanRectangle(display,window);
  1345. X  XDefineCursor(display,window->image.id,window->image.cursor);
  1346. }
  1347. X
  1348. /*
  1349. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1350. %                                                                             %
  1351. %                                                                             %
  1352. %                                                                             %
  1353. %   X P a n I m a g e W i n d o w                                             %
  1354. %                                                                             %
  1355. %                                                                             %
  1356. %                                                                             %
  1357. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1358. %
  1359. %  Function XPanImageWindow pans the image until the mouse button is released.
  1360. %
  1361. %  The format of the XPanImageWindow routine is:
  1362. %
  1363. %    XPanImageWindow(display,window,event)
  1364. %
  1365. %  A description of each parameter follows:
  1366. %
  1367. %    o display: Specifies a connection to an X server;  returned from
  1368. %      XOpenDisplay.
  1369. %
  1370. %    o window: Specifies a pointer to a XWindows structure.
  1371. %
  1372. %    o event: Specifies a pointer to a XEvent structure.  If it is NULL,
  1373. %      the entire image is refreshed.
  1374. %
  1375. */
  1376. static void XPanImageWindow(display,window,event)
  1377. Display
  1378. X  *display;
  1379. X
  1380. XXWindows
  1381. X  *window;
  1382. X
  1383. XXEvent
  1384. X  *event;
  1385. {
  1386. X  char
  1387. X    text[2048];
  1388. X
  1389. X  Cursor
  1390. X    cursor;
  1391. X
  1392. X  unsigned long
  1393. X    state;
  1394. X
  1395. X  unsigned long
  1396. X    x_factor,
  1397. X    y_factor;
  1398. X
  1399. X  XRectangle
  1400. X    pan_info;
  1401. X
  1402. X  /*
  1403. X    Map info window.
  1404. X  */
  1405. X  state=DefaultState;
  1406. X  (void) sprintf(text," %ux%u%+d%+d  ",window->image.width,window->image.height,
  1407. X    window->image.ximage->width,window->image.ximage->height);
  1408. X  XSetWindowExtents(display,&window->info,text);
  1409. X  XMapWindow(display,window->info.id);
  1410. X  state|=InfoMappedState;
  1411. X  /*
  1412. X    Define cursor.
  1413. X  */
  1414. X  if ((window->image.ximage->width > window->image.width) &&
  1415. X      (window->image.ximage->height > window->image.height))
  1416. X    cursor=XCreateFontCursor(display,XC_fleur);
  1417. X  else
  1418. X    if (window->image.ximage->width > window->image.width)
  1419. X      cursor=XCreateFontCursor(display,XC_sb_h_double_arrow);
  1420. X    else
  1421. X      if (window->image.ximage->height > window->image.height)
  1422. X        cursor=XCreateFontCursor(display,XC_sb_v_double_arrow);
  1423. X      else
  1424. X        cursor=XCreateFontCursor(display,XC_arrow);
  1425. X  if (cursor == (Cursor) NULL)
  1426. X    {
  1427. X      Warning("unable to create cursor",(char *) NULL);
  1428. X      return;
  1429. X    }
  1430. X  XRecolorCursor(display,cursor,&window->image.pixel_info->background_color,
  1431. X    &window->image.pixel_info->foreground_color);
  1432. X  XDefineCursor(display,window->pan.id,cursor);
  1433. X  /*
  1434. X    Pan image as pointer moves until the mouse button is released.
  1435. X  */
  1436. X  x_factor=(unsigned long)
  1437. X    UpShift(window->image.ximage->width)/window->pan.width;
  1438. X  y_factor=(unsigned long)
  1439. X    UpShift(window->image.ximage->height)/window->pan.height;
  1440. X  pan_info.x=event->xbutton.x;
  1441. X  pan_info.y=event->xbutton.y;
  1442. X  pan_info.width=(unsigned short) (UpShift(window->image.width)/x_factor);
  1443. X  pan_info.height=(unsigned short) (UpShift(window->image.height)/y_factor);
  1444. X  window->image.x=pan_info.x+1;
  1445. X  window->image.y=pan_info.y+1;
  1446. X  do
  1447. X  {
  1448. X    /*
  1449. X      Check boundary conditions.
  1450. X    */
  1451. X    pan_info.x=DownShift((pan_info.x-pan_info.width/2)*x_factor);
  1452. X    if (pan_info.x < 0)
  1453. X      pan_info.x=0;
  1454. X    else
  1455. X      if ((pan_info.x+window->image.width) > window->image.ximage->width)
  1456. X        pan_info.x=window->image.ximage->width-window->image.width;
  1457. X    pan_info.y=DownShift((pan_info.y-pan_info.height/2)*y_factor);
  1458. X    if (pan_info.y < 0)
  1459. X      pan_info.y=0;
  1460. X    else
  1461. X      if ((pan_info.y+window->image.height) > window->image.ximage->height)
  1462. X        pan_info.y=window->image.ximage->height-window->image.height;
  1463. X    if ((window->image.x != pan_info.x) || (window->image.y != pan_info.y))
  1464. X      {
  1465. X        /*
  1466. X          Display image pan offset.
  1467. X        */
  1468. X        window->image.x=pan_info.x;
  1469. X        window->image.y=pan_info.y;
  1470. X        (void) sprintf(text," %ux%u%+d%+d ",window->image.width,
  1471. X          window->image.height,window->image.x,window->image.y);
  1472. X        XDisplayInfoString(display,&window->info,text);
  1473. X        /*
  1474. X          Refresh image window.
  1475. X        */
  1476. X        XDrawPanRectangle(display,window);
  1477. X        XRefreshWindow(display,&window->image,(XEvent *) NULL);
  1478. X      }
  1479. X    /*
  1480. X      Wait for next event.
  1481. X    */
  1482. X    XWindowEvent(display,window->pan.id,ButtonPressMask | ButtonMotionMask |
  1483. X      ButtonReleaseMask,event);
  1484. X    switch (event->type)
  1485. X    {
  1486. X      case ButtonRelease:
  1487. X      {
  1488. X        /*
  1489. X          User has finished panning the image.
  1490. X        */
  1491. X        pan_info.x=event->xbutton.x;
  1492. X        pan_info.y=event->xbutton.y;
  1493. X        state|=ExitState;
  1494. X        break;
  1495. X      }
  1496. X      case MotionNotify:
  1497. X      {
  1498. X        /*
  1499. X          Discard pending button motion events.
  1500. X        */
  1501. X        while (XCheckMaskEvent(display,ButtonMotionMask,event));
  1502. X        pan_info.x=event->xmotion.x;
  1503. X        pan_info.y=event->xmotion.y;
  1504. X      }
  1505. X      default:
  1506. X        break;
  1507. X    }
  1508. X  } while (!(state & ExitState));
  1509. X  /*
  1510. X    Check boundary conditions.
  1511. X  */
  1512. X  pan_info.x=DownShift((pan_info.x-pan_info.width/2)*x_factor);
  1513. X  if (pan_info.x < 0)
  1514. X    pan_info.x=0;
  1515. X  else
  1516. X    if ((pan_info.x+window->image.width) > window->image.ximage->width)
  1517. X      pan_info.x=window->image.ximage->width-window->image.width;
  1518. X  pan_info.y=DownShift((pan_info.y-pan_info.height/2)*y_factor);
  1519. X  if (pan_info.y < 0)
  1520. X    pan_info.y=0;
  1521. X  else
  1522. X    if ((pan_info.y+window->image.height) > window->image.ximage->height)
  1523. X      pan_info.y=window->image.ximage->height-window->image.height;
  1524. X  if ((window->image.x != pan_info.x) || (window->image.y != pan_info.y))
  1525. X    {
  1526. X      /*
  1527. X        Refresh image window.
  1528. X      */
  1529. X      window->image.x=pan_info.x;
  1530. X      window->image.y=pan_info.y;
  1531. X      XDrawPanRectangle(display,window);
  1532. X      XRefreshWindow(display,&window->image,(XEvent *) NULL);
  1533. X    }
  1534. X  /*
  1535. X    Restore cursor.
  1536. X  */
  1537. X  XDefineCursor(display,window->pan.id,window->pan.cursor);
  1538. X  XFreeCursor(display,cursor);
  1539. X  XWithdrawWindow(display,window->info.id,window->info.screen);
  1540. }
  1541. X
  1542. /*
  1543. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1544. %                                                                             %
  1545. %                                                                             %
  1546. %                                                                             %
  1547. %   X R e f l e c t I m a g e W i n d o w                                     %
  1548. %                                                                             %
  1549. %                                                                             %
  1550. %                                                                             %
  1551. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1552. %
  1553. %  Function XReflectImageWindow reflects the scanlines of an image.
  1554. %
  1555. %  The format of the XReflectImageWindow routine is:
  1556. %
  1557. %    status=XReflectImageWindow(display,window,image)
  1558. %
  1559. %  A description of each parameter follows:
  1560. %
  1561. %    o status: Function XReflectImageWindow return True if the window scanlines
  1562. %      reverse.  False is returned is there is a memory shortage or if the
  1563. %      window scanlines fails to reverse.
  1564. %
  1565. %    o display: Specifies a connection to an X server; returned from
  1566. %      XOpenDisplay.
  1567. %
  1568. %    o window: Specifies a pointer to a XWindows structure.
  1569. %
  1570. %    o image: Specifies a pointer to a Image structure;  returned from
  1571. %      ReadImage.
  1572. %
  1573. %
  1574. */
  1575. static unsigned int XReflectImageWindow(display,window,image)
  1576. Display
  1577. X  *display;
  1578. X
  1579. XXWindows
  1580. X  *window;
  1581. X
  1582. Image
  1583. X  **image;
  1584. {
  1585. X  char
  1586. X    text[2048];
  1587. X
  1588. X  Image
  1589. X    *reflected_image;
  1590. X
  1591. X  unsigned long
  1592. X    state;
  1593. X
  1594. X  state=DefaultState;
  1595. X  if (((*image)->columns*(*image)->rows) > MinInfoSize)
  1596. X    {
  1597. X      /*
  1598. X        Map image window.
  1599. X      */
  1600. X      (void) strcpy(text," Reflecting image... ");
  1601. X      XSetWindowExtents(display,&window->info,text);
  1602. X      XMapWindow(display,window->info.id);
  1603. X      XDisplayInfoString(display,&window->info,text);
  1604. X      state|=InfoMappedState;
  1605. X    }
  1606. X  /*
  1607. X    Reflect image scanlines.
  1608. X  */
  1609. X  XDefineCursor(display,window->image.id,window->image.busy_cursor);
  1610. X  XFlush(display);
  1611. X  reflected_image=ReflectImage(*image);
  1612. X  XDefineCursor(display,window->image.id,window->image.cursor);
  1613. X  if (state & InfoMappedState)
  1614. X    XWithdrawWindow(display,window->info.id,window->info.screen);
  1615. X  if (reflected_image == (Image *) NULL)
  1616. X    return(False);
  1617. X  DestroyImage(*image);
  1618. X  *image=reflected_image;
  1619. X  if (window->image.clip_geometry != (char *) NULL)
  1620. X    {
  1621. X      int
  1622. X        x,
  1623. X        y;
  1624. X
  1625. X      unsigned int
  1626. X        height,
  1627. X        width;
  1628. X
  1629. X      /*
  1630. X        Reverse clip geometry.
  1631. X      */
  1632. X      (void) XParseGeometry(window->image.clip_geometry,&x,&y,&width,&height);
  1633. X      (void) sprintf(window->image.clip_geometry,"%ux%u%+d%+d",width,height,
  1634. X        (int) (*image)->columns-(int) width-x,y);
  1635. X    }
  1636. X  return(True);
  1637. }
  1638. X
  1639. /*
  1640. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1641. %                                                                             %
  1642. %                                                                             %
  1643. %                                                                             %
  1644. %   X R o t a t e I m a g e W i n d o w                                       %
  1645. %                                                                             %
  1646. %                                                                             %
  1647. %                                                                             %
  1648. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1649. %
  1650. %  Function XRotateImageWindow rotates the X image left or right 90 degrees.
  1651. %
  1652. %  The format of the XRotateImageWindow routine is:
  1653. %
  1654. %    status=XRotateImageWindow(display,window,degrees,image)
  1655. %
  1656. %  A description of each parameter follows:
  1657. %
  1658. %    o status: Function XRotateImageWindow return True if the image is
  1659. %      rotated.  False is returned is there is a memory shortage or if the
  1660. %      image fails to rotate.
  1661. %
  1662. %    o display: Specifies a connection to an X server; returned from
  1663. %      XOpenDisplay.
  1664. %
  1665. %    o window: Specifies a pointer to a XWindows structure.
  1666. %
  1667. %    o degrees: Specifies the number of degrees to rotate the image.
  1668. %
  1669. %    o image: Specifies a pointer to a Image structure;  returned from
  1670. %      ReadImage.
  1671. %
  1672. %
  1673. */
  1674. static unsigned int XRotateImageWindow(display,window,degrees,image)
  1675. Display
  1676. X  *display;
  1677. X
  1678. XXWindows
  1679. X  *window;
  1680. X
  1681. unsigned int
  1682. X  degrees;
  1683. X
  1684. Image
  1685. X  **image;
  1686. {
  1687. X  char
  1688. X    text[2048];
  1689. X
  1690. X  int
  1691. X    x,
  1692. X    y;
  1693. X
  1694. X  Image
  1695. X    *rotated_image;
  1696. X
  1697. X  unsigned long
  1698. X    state;
  1699. X
  1700. X  state=DefaultState;
  1701. X  if (((*image)->columns*(*image)->rows) > MinInfoSize)
  1702. X    {
  1703. X      /*
  1704. X        Map info window.
  1705. X      */
  1706. X      (void) strcpy(text," Rotating image... ");
  1707. X      XSetWindowExtents(display,&window->info,text);
  1708. X      XMapWindow(display,window->info.id);
  1709. X      XDisplayInfoString(display,&window->info,text);
  1710. X      state|=InfoMappedState;
  1711. X    }
  1712. X  /*
  1713. X    Rotate image.
  1714. X  */
  1715. X  XDefineCursor(display,window->image.id,window->image.busy_cursor);
  1716. X  XFlush(display);
  1717. X  rotated_image=RotateImage(*image,(double) degrees,True);
  1718. X  XDefineCursor(display,window->image.id,window->image.cursor);
  1719. X  if (state & InfoMappedState)
  1720. X    XWithdrawWindow(display,window->info.id,window->info.screen);
  1721. X  if (rotated_image == (Image *) NULL)
  1722. X    return(False);
  1723. X  DestroyImage(*image);
  1724. X  *image=rotated_image;
  1725. X  if (window->image.clip_geometry != (char *) NULL)
  1726. X    {
  1727. X      unsigned int
  1728. X        height,
  1729. X        width;
  1730. X
  1731. X      /*
  1732. X        Rotate clip geometry.
  1733. X      */
  1734. X      (void) XParseGeometry(window->image.clip_geometry,&x,&y,&width,&height);
  1735. X      if (degrees < 180.0)
  1736. X        (void) sprintf(window->image.clip_geometry,"%ux%u%+d%+d",height,width,
  1737. X          (int) (*image)->columns-(int) height-y,x);
  1738. X      else
  1739. X        (void) sprintf(window->image.clip_geometry,"%ux%u%+d%+d",height,width,
  1740. X          y,(int) (*image)->rows-(int) width-x);
  1741. X    }
  1742. X  return(True);
  1743. }
  1744. X
  1745. /*
  1746. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1747. %                                                                             %
  1748. SHAR_EOF
  1749. true || echo 'restore of ImageMagick/display.c failed'
  1750. fi
  1751. echo 'End of ImageMagick part 24'
  1752. echo 'File ImageMagick/display.c is continued in part 25'
  1753. echo 25 > _shar_seq_.tmp
  1754. exit 0
  1755.  
  1756. exit 0 # Just in case...
  1757. -- 
  1758.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  1759. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  1760.  "It's intuitively obvious to the |
  1761.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  1762.