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

  1. Newsgroups: comp.sources.x
  2. From: cristy@eplrx7.es.duPont.com (Cristy)
  3. Subject: v20i068:  imagemagic - X11 image processing and display, Part12/38
  4. Message-ID: <1993Jul14.175551.1375@sparky.sterling.com>
  5. X-Md4-Signature: 2c3eb1f129d769cf8c3761064a436ff6
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Wed, 14 Jul 1993 17:55:51 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: cristy@eplrx7.es.duPont.com (Cristy)
  12. Posting-number: Volume 20, Issue 68
  13. Archive-name: imagemagic/part12
  14. Environment: X11
  15. Supersedes: imagemagic: Volume 13, Issue 17-37
  16.  
  17. #!/bin/sh
  18. # this is magick.12 (part 12 of ImageMagick)
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file ImageMagick/X.c continued
  21. #
  22. if test ! -r _shar_seq_.tmp; then
  23.     echo 'Please unpack part 1 first!'
  24.     exit 1
  25. fi
  26. (read Scheck
  27.  if test "$Scheck" != 12; then
  28.     echo Please unpack part "$Scheck" next!
  29.     exit 1
  30.  else
  31.     exit 0
  32.  fi
  33. ) < _shar_seq_.tmp || exit 1
  34. if test ! -f _shar_wnt_.tmp; then
  35.     echo 'x - still skipping ImageMagick/X.c'
  36. else
  37. echo 'x - continuing file ImageMagick/X.c'
  38. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/X.c' &&
  39. X            {
  40. X              key_symbol=XK_Delete;
  41. X              break;
  42. X            }
  43. X            default:
  44. X              break;
  45. X          }
  46. X        switch (key_symbol)
  47. X        {
  48. X          case XK_BackSpace:
  49. X          {
  50. X            /*
  51. X              Erase one character.
  52. X            */
  53. X            if (p == reply)
  54. X              break;
  55. X            p--;
  56. X            x-=XTextWidth(font_info,p,1);
  57. X            XClearArea(display,window->id,x,y-font_info->ascent,
  58. X              (unsigned int) font_info->max_bounds.width,height,False);
  59. X            break;
  60. X          }
  61. X          case XK_Escape:
  62. X          {
  63. X            /*
  64. X              Return null response.
  65. X            */
  66. X            *reply='\0';
  67. X            state|=ExitState;
  68. X          }
  69. X          case XK_Delete:
  70. X          {
  71. X            /*
  72. X              Erase the entire line of text.
  73. X            */
  74. X            while (p != reply)
  75. X            {
  76. X              p--;
  77. X              x-=XTextWidth(font_info,p,1);
  78. X              XClearArea(display,window->id,x,y-font_info->ascent,
  79. X                (unsigned int) font_info->max_bounds.width,height,False);
  80. X            }
  81. X            break;
  82. X          }
  83. X          case XK_Return:
  84. X          {
  85. X            /*
  86. X              Commit to current response.
  87. X            */
  88. X            state|=ExitState;
  89. X            break;
  90. X          }
  91. X          default:
  92. X          {
  93. X            /*
  94. X              Draw a single character on the popup window.
  95. X            */
  96. X            if (*command == '\0')
  97. X              break;
  98. X            *p=(*command);
  99. X            XDrawString(display,window->id,graphic_context,x,y,p,1);
  100. X            x+=XTextWidth(font_info,p,1);
  101. X            p++;
  102. X            break;
  103. X          }
  104. X        }
  105. X        break;
  106. X      }
  107. X      case KeyRelease:
  108. X      {
  109. X        static char
  110. X          command[2048];
  111. X
  112. X        static KeySym
  113. X          key_symbol;
  114. X
  115. X        /*
  116. X          Respond to a user key release.
  117. X        */
  118. X        *command='\0';
  119. X        XLookupString((XKeyEvent *) &event.xkey,command,sizeof(command),
  120. X          &key_symbol,(XComposeStatus *) NULL);
  121. X        if (key_symbol == XK_Control_L)
  122. X          state&=(~ControlState);
  123. X        break;
  124. X      }
  125. X      case VisibilityNotify:
  126. X      {
  127. X        XMapRaised(display,window->id);
  128. X        break;
  129. X      }
  130. X      default:
  131. X        break;
  132. X    }
  133. X  } while (!(state & ExitState));
  134. X  XDefineCursor(display,window->id,window->cursor);
  135. X  XFreeCursor(display,cursor);
  136. X  XWithdrawWindow(display,window->id,window->screen);
  137. }
  138. X
  139. /*
  140. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  141. %                                                                             %
  142. %                                                                             %
  143. %                                                                             %
  144. %   X R e f r e s h W i n d o w                                               %
  145. %                                                                             %
  146. %                                                                             %
  147. %                                                                             %
  148. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  149. %
  150. %  Function XRefreshWindow refreshes an image in a X window.
  151. %
  152. %  The format of the XRefreshWindow routine is:
  153. %
  154. %      XRefreshWindow(display,window,event)
  155. %
  156. %  A description of each parameter follows:
  157. %
  158. %    o display: Specifies a connection to an X server;  returned from
  159. %      XOpenDisplay.
  160. %
  161. %    o window: Specifies a pointer to a XWindowInfo structure.
  162. %
  163. %    o event: Specifies a pointer to a XEvent structure.  If it is NULL,
  164. %      the entire image is refreshed.
  165. %
  166. %
  167. */
  168. void XRefreshWindow(display,window,event)
  169. Display
  170. X  *display;
  171. X
  172. XXWindowInfo
  173. X  *window;
  174. X
  175. XXEvent
  176. X  *event;
  177. {
  178. X  int
  179. X    x,
  180. X    y;
  181. X
  182. X  unsigned int
  183. X    height,
  184. X    width;
  185. X
  186. X  if (event != (XEvent *) NULL)
  187. X    {
  188. X      /*
  189. X        Determine geometry from expose event.
  190. X      */
  191. X      x=event->xexpose.x;
  192. X      y=event->xexpose.y;
  193. X      width=event->xexpose.width;
  194. X      height=event->xexpose.height;
  195. X    }
  196. X  else
  197. X    {
  198. X      XEvent
  199. X        discard_event;
  200. X
  201. X      /*
  202. X        Refresh entire window; discard outstanding expose events.
  203. X      */
  204. X      x=0;
  205. X      y=0;
  206. X      width=window->width;
  207. X      height=window->height;
  208. X      XSync(display,False);
  209. X      while (XCheckTypedWindowEvent(display,window->id,Expose,&discard_event));
  210. X    }
  211. X  /*
  212. X    Check boundary conditions.
  213. X  */
  214. X  if ((window->ximage->width-(x+window->x)) < width)
  215. X    width=window->ximage->width-(x+window->x);
  216. X  if ((window->ximage->height-(y+window->y)) < height)
  217. X    height=window->ximage->height-(y+window->y);
  218. X  /*
  219. X    Refresh image.
  220. X  */
  221. X  if (window->pixmap != (Pixmap) NULL)
  222. X    {
  223. X      if (window->depth > 1)
  224. X        XCopyArea(display,window->pixmap,window->id,window->graphic_context,
  225. X          x+window->x,y+window->y,width,height,x,y);
  226. X      else
  227. X        XCopyPlane(display,window->pixmap,window->id,window->highlight_context,
  228. X          x+window->x,y+window->y,width,height,x,y,1L);
  229. X    }
  230. X  else
  231. X    XPutImage(display,window->id,window->graphic_context,window->ximage,
  232. X      x+window->x,y+window->y,x,y,width,height);
  233. }
  234. X
  235. /*
  236. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  237. %                                                                             %
  238. %                                                                             %
  239. %                                                                             %
  240. %   X S e l e c t W i n d o w                                                 %
  241. %                                                                             %
  242. %                                                                             %
  243. %                                                                             %
  244. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  245. %
  246. %  Function XSelectWindow allows a user to select a window using the mouse.  If
  247. %  the mouse moves, a clipping rectangle is drawn and the extents of the
  248. %  rectangle is returned in the clip_info structure.
  249. %
  250. %  The format of the XSelectWindow function is:
  251. %
  252. %      target_window=XSelectWindow(display,clip_info)
  253. %
  254. %  A description of each parameter follows:
  255. %
  256. %    o window: XSelectWindow returns the window id.
  257. %
  258. %    o display: Specifies a pointer to the Display structure;  returned from
  259. %      XOpenDisplay.
  260. %
  261. %    o clip_info: Specifies a pointer to a RectangleInfo structure.  It
  262. %      contains the extents of any clipping rectangle.
  263. %
  264. %
  265. */
  266. static Window XSelectWindow(display,clip_info)
  267. Display
  268. X  *display;
  269. X
  270. RectangleInfo
  271. X  *clip_info;
  272. {
  273. #define MinimumClipArea  (unsigned int) 9
  274. X
  275. X  Cursor
  276. X    target_cursor;
  277. X
  278. X  GC
  279. X    graphic_context;
  280. X
  281. X  int
  282. X    presses,
  283. X    status,
  284. X    x_offset,
  285. X    y_offset;
  286. X
  287. X  Window
  288. X    root_window,
  289. X    target_window;
  290. X
  291. X  XEvent
  292. X    event;
  293. X
  294. X  XGCValues
  295. X    graphic_context_value;
  296. X
  297. X  /*
  298. X    Initialize graphic context.
  299. X  */
  300. X  root_window=XRootWindow(display,XDefaultScreen(display));
  301. X  graphic_context_value.function=GXinvert;
  302. X  graphic_context_value.line_width=WindowBorderWidth;
  303. X  graphic_context_value.subwindow_mode=IncludeInferiors;
  304. X  graphic_context=XCreateGC(display,root_window,GCFunction | GCLineWidth |
  305. X    GCSubwindowMode,&graphic_context_value);
  306. X  if (graphic_context == (GC) NULL)
  307. X    return(False);
  308. X  /*
  309. X    Make the target cursor.
  310. X  */
  311. X  target_cursor=XCreateFontCursor(display,XC_tcross);
  312. X  /*
  313. X    Grab the pointer using target cursor.
  314. X  */
  315. X  status=XGrabPointer(display,root_window,False,(unsigned int)
  316. X    (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
  317. X    GrabModeAsync,root_window,target_cursor,CurrentTime);
  318. X  if (status != GrabSuccess)
  319. X    Error("unable to grab the mouse",(char *) NULL);
  320. X  /*
  321. X    Select a window.
  322. X  */
  323. X  clip_info->width=0;
  324. X  clip_info->height=0;
  325. X  presses=0;
  326. X  target_window=(Window) NULL;
  327. X  x_offset=0;
  328. X  y_offset=0;
  329. X  do
  330. X  {
  331. X    if ((clip_info->width*clip_info->height) >= MinimumClipArea)
  332. X      XDrawRectangle(display,root_window,graphic_context,clip_info->x,
  333. X        clip_info->y,clip_info->width-1,clip_info->height-1);
  334. X    /*
  335. X      Allow another event.
  336. X    */
  337. X    XAllowEvents(display,SyncPointer,CurrentTime);
  338. X    XWindowEvent(display,root_window,ButtonPressMask | ButtonReleaseMask |
  339. X      ButtonMotionMask,&event);
  340. X    if ((clip_info->width*clip_info->height) >= MinimumClipArea)
  341. X      XDrawRectangle(display,root_window,graphic_context,clip_info->x,
  342. X        clip_info->y,clip_info->width-1,clip_info->height-1);
  343. X    switch (event.type)
  344. X    {
  345. X      case ButtonPress:
  346. X      {
  347. X        if (target_window == (Window) NULL)
  348. X          {
  349. X            target_window=event.xbutton.subwindow;
  350. X            if (target_window == (Window) NULL)
  351. X              target_window=root_window;
  352. X          }
  353. X        x_offset=event.xbutton.x_root;
  354. X        y_offset=event.xbutton.y_root;
  355. X        clip_info->x=x_offset;
  356. X        clip_info->y=y_offset;
  357. X        clip_info->width=0;
  358. X        clip_info->height=0;
  359. X        presses++;
  360. X        break;
  361. X      }
  362. X      case ButtonRelease:
  363. X      {
  364. X        presses--;
  365. X        break;
  366. X      }
  367. X      case MotionNotify:
  368. X      {
  369. X        /*
  370. X          Discard pending button motion events.
  371. X        */
  372. X        while (XCheckMaskEvent(display,ButtonMotionMask,&event));
  373. X        clip_info->x=event.xmotion.x;
  374. X        clip_info->y=event.xmotion.y;
  375. X        /*
  376. X          Check boundary conditions.
  377. X        */
  378. X        if (clip_info->x < x_offset)
  379. X          clip_info->width=(unsigned int) (x_offset-clip_info->x);
  380. X        else
  381. X          {
  382. X            clip_info->width=(unsigned int) (clip_info->x-x_offset);
  383. X            clip_info->x=x_offset;
  384. X          }
  385. X        if (clip_info->y < y_offset)
  386. X          clip_info->height=(unsigned int) (y_offset-clip_info->y);
  387. X        else
  388. X          {
  389. X            clip_info->height=(unsigned int) (clip_info->y-y_offset);
  390. X            clip_info->y=y_offset;
  391. X          }
  392. X      }
  393. X      default:
  394. X        break;
  395. X    }
  396. X  }
  397. X  while ((target_window == (Window) NULL) || (presses > 0));
  398. X  XUngrabPointer(display,CurrentTime);
  399. X  XFreeCursor(display,target_cursor);
  400. X  XFreeGC(display,graphic_context);
  401. X  if ((clip_info->width*clip_info->height) < MinimumClipArea)
  402. X    {
  403. X      clip_info->width=0;
  404. X      clip_info->height=0;
  405. X    }
  406. X  if ((clip_info->width != 0) && (clip_info->height != 0))
  407. X    target_window=root_window;
  408. X  return(target_window);
  409. }
  410. X
  411. /*
  412. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  413. %                                                                             %
  414. %                                                                             %
  415. %                                                                             %
  416. %   X S e t W i n d o w E x t e n t s                                         %
  417. %                                                                             %
  418. %                                                                             %
  419. %                                                                             %
  420. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  421. %
  422. %  Function XSetWindowExtents resizes the window to a size determined by the
  423. %  text and the font size.
  424. %
  425. %  The format of the XSetWindowExtents function is:
  426. %
  427. %      XSetWindowExtents(display,window,text)
  428. %
  429. %  A description of each parameter follows:
  430. %
  431. %    o display: Specifies a pointer to the Display structure;  returned from
  432. %      XOpenDisplay.
  433. %
  434. %    o window: Specifies a pointer to a XWindowInfo structure.
  435. %
  436. %    o text: Specifies a pointer to a text string.
  437. %
  438. %
  439. */
  440. void XSetWindowExtents(display,window,text)
  441. Display
  442. X  *display;
  443. X
  444. XXWindowInfo
  445. X  *window;
  446. X
  447. char
  448. X  *text;
  449. {
  450. X  unsigned int
  451. X    height;
  452. X
  453. X  window->width=XTextWidth(window->font_info,text,strlen(text))+
  454. X    3*window->font_info->max_bounds.width;
  455. X  height=window->font_info->ascent+window->font_info->descent;
  456. X  window->height=height+(height >> 1);
  457. X  XResizeWindow(display,window->id,window->width,window->height);
  458. }
  459. X
  460. /*
  461. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  462. %                                                                             %
  463. %                                                                             %
  464. %                                                                             %
  465. %   X V i s u a l C l a s s N a m e                                           %
  466. %                                                                             %
  467. %                                                                             %
  468. %                                                                             %
  469. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  470. %
  471. %  Function XVisualClassName returns the visual class name as a character
  472. %  string.
  473. %
  474. %  The format of the XVisualClassName routine is:
  475. %
  476. %      visual_type=XVisualClassName(visual_info)
  477. %
  478. %  A description of each parameter follows:
  479. %
  480. %    o visual_type: XVisualClassName returns the visual class as a character
  481. %      string.
  482. %
  483. %    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
  484. %      returned from XGetVisualInfo.
  485. %
  486. %
  487. */
  488. char *XVisualClassName(visual_info)
  489. XXVisualInfo
  490. X  *visual_info;
  491. {
  492. X  if (visual_info == (XVisualInfo *) NULL)
  493. X    return((char *) NULL);
  494. X  switch (visual_info->class)
  495. X  {
  496. X    case StaticGray: return("StaticGray");
  497. X    case GrayScale: return("GrayScale");
  498. X    case StaticColor: return("StaticColor");
  499. X    case PseudoColor: return("PseudoColor");
  500. X    case TrueColor: return("TrueColor");
  501. X    case DirectColor: return("DirectColor");
  502. X  }
  503. X  return("unknown visual class");
  504. }
  505. X
  506. /*
  507. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  508. %                                                                             %
  509. %                                                                             %
  510. %                                                                             %
  511. %   X W i n d o w B y I D                                                     %
  512. %                                                                             %
  513. %                                                                             %
  514. %                                                                             %
  515. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  516. %
  517. %  Function XWindowByID locates a child window with a given ID.  If not window
  518. %  with the given name is found, 0 is returned.   Only the window specified
  519. %  and its subwindows are searched.
  520. %
  521. %  The format of the XWindowByID function is:
  522. %
  523. %      child=XWindowByID(display,window,id)
  524. %
  525. %  A description of each parameter follows:
  526. %
  527. %    o child: XWindowByID returns the window with the specified
  528. %      id.  If no windows are found, XWindowByID returns 0.
  529. %
  530. %    o display: Specifies a pointer to the Display structure;  returned from
  531. %      XOpenDisplay.
  532. %
  533. %    o id: Specifies the id of the window to locate.
  534. %
  535. %
  536. */
  537. Window XWindowByID(display,root_window,id)
  538. Display
  539. X  *display;
  540. X
  541. Window
  542. X  root_window;
  543. X
  544. unsigned long
  545. X  id;
  546. {
  547. X  register int
  548. X    i;
  549. X
  550. X  unsigned int
  551. X    number_children;
  552. X
  553. X  Window
  554. X    child,
  555. X    *children,
  556. X    window;
  557. X
  558. X  if (root_window == id)
  559. X    return(id);
  560. X  if (!XQueryTree(display,root_window,&child,&child,&children,&number_children))
  561. X    return((Window) NULL);
  562. X  window=(Window) NULL;
  563. X  for (i=0; i < number_children; i++)
  564. X  {
  565. X    /*
  566. X      Search each child and their children.
  567. X    */
  568. X    window=XWindowByID(display,children[i],id);
  569. X    if (window != (Window) NULL)
  570. X      break;
  571. X  }
  572. X  if (children != (Window *) NULL)
  573. X    XFree((void *) children);
  574. X  return(window);
  575. }
  576. X
  577. /*
  578. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  579. %                                                                             %
  580. %                                                                             %
  581. %                                                                             %
  582. %   X W i n d o w B y N a m e                                                 %
  583. %                                                                             %
  584. %                                                                             %
  585. %                                                                             %
  586. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  587. %
  588. %  Function XWindowByName locates a window with a given name on a display.
  589. %  If no window with the given name is found, 0 is returned. If more than
  590. %  one window has the given name, the first one is returned.  Only root and
  591. %  its children are searched.
  592. %
  593. %  The format of the XWindowByName function is:
  594. %
  595. %      window=XWindowByName(display,root_window,name)
  596. %
  597. %  A description of each parameter follows:
  598. %
  599. %    o window: XWindowByName returns the window id.
  600. %
  601. %    o display: Specifies a pointer to the Display structure;  returned from
  602. %      XOpenDisplay.
  603. %
  604. %    o root_window: Specifies the id of the root window.
  605. %
  606. %    o name: Specifies the name of the window to locate.
  607. %
  608. %
  609. */
  610. Window XWindowByName(display,root_window,name)
  611. Display
  612. X  *display;
  613. X
  614. Window
  615. X  root_window;
  616. X
  617. char
  618. X  *name;
  619. {
  620. X  register int
  621. X    i;
  622. X
  623. X  unsigned int
  624. X    number_children;
  625. X
  626. X  Window
  627. X    *children,
  628. X    child,
  629. X    window;
  630. X
  631. X  XTextProperty
  632. X    window_name;
  633. X
  634. X  if (XGetWMName(display,root_window,&window_name) != 0)
  635. X    if (strcmp((char *) window_name.value,name) == 0)
  636. X      return(root_window);
  637. X  if (!XQueryTree(display,root_window,&child,&child,&children,&number_children))
  638. X    return((Window) NULL);
  639. X  window=(Window) NULL;
  640. X  for (i=0; i < number_children; i++)
  641. X  {
  642. X    /*
  643. X      Search each child and their children.
  644. X    */
  645. X    window=XWindowByName(display,children[i],name);
  646. X    if (window != (Window) NULL)
  647. X      break;
  648. X  }
  649. X  if (children != (Window *) NULL)
  650. X    XFree((void *) children);
  651. X  return(window);
  652. }
  653. X
  654. /*
  655. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  656. %                                                                             %
  657. %                                                                             %
  658. %                                                                             %
  659. %   X W i n d o w B y P r o p e r y                                           %
  660. %                                                                             %
  661. %                                                                             %
  662. %                                                                             %
  663. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  664. %
  665. %  Function XWindowByProperty locates a child window with a given property.
  666. %  If no window with the given name is found, 0 is returned.  If more than
  667. %  one window has the given property, the first one is returned.  Only the
  668. %  window specified and its subwindows are searched.
  669. %
  670. %  The format of the XWindowByProperty function is:
  671. %
  672. %      child=XWindowByProperty(display,window,property)
  673. %
  674. %  A description of each parameter follows:
  675. %
  676. %    o child: XWindowByProperty returns the window id with the specified
  677. %      property.  If no windows are found, XWindowByProperty returns 0.
  678. %
  679. %    o display: Specifies a pointer to the Display structure;  returned from
  680. %      XOpenDisplay.
  681. %
  682. %    o property: Specifies the property of the window to locate.
  683. %
  684. %
  685. */
  686. static Window XWindowByProperty(display,window,property)
  687. Display
  688. X  *display;
  689. X
  690. Window
  691. X  window;
  692. X
  693. Atom
  694. X  property;
  695. {
  696. X  Atom
  697. X    type;
  698. X
  699. X  int
  700. X    format,
  701. X    status;
  702. X
  703. X  unsigned char
  704. X    *data;
  705. X
  706. X  unsigned int
  707. X    i,
  708. X    number_children;
  709. X
  710. X  unsigned long
  711. X    after,
  712. X    number_items;
  713. X
  714. X  Window
  715. X    *children,
  716. X    child,
  717. X    parent,
  718. X    root;
  719. X
  720. X  status=XQueryTree(display,window,&root,&parent,&children,&number_children);
  721. X  if (status == 0)
  722. X    return((Window) NULL);
  723. X  type=(Atom) NULL;
  724. X  child=(Window) NULL;
  725. X  for (i=0; (i < number_children) && (child == (Window) NULL); i++)
  726. X  {
  727. X    status=XGetWindowProperty(display,children[i],property,0L,0L,False,
  728. X      (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
  729. X    if ((status == Success) && (type != (Atom) NULL))
  730. X      child=children[i];
  731. X  }
  732. X  for (i=0; (i < number_children) && (child == (Window) NULL); i++)
  733. X    child=XWindowByProperty(display,children[i],property);
  734. X  if (children != (Window *) NULL)
  735. X    XFree((void *) children);
  736. X  return(child);
  737. }
  738. SHAR_EOF
  739. echo 'File ImageMagick/X.c is complete' &&
  740. chmod 0644 ImageMagick/X.c ||
  741. echo 'restore of ImageMagick/X.c failed'
  742. Wc_c="`wc -c < 'ImageMagick/X.c'`"
  743. test 187033 -eq "$Wc_c" ||
  744.     echo 'ImageMagick/X.c: original size 187033, current size' "$Wc_c"
  745. rm -f _shar_wnt_.tmp
  746. fi
  747. # ============= ImageMagick/X.h ==============
  748. if test -f 'ImageMagick/X.h' -a X"$1" != X"-c"; then
  749.     echo 'x - skipping ImageMagick/X.h (File already exists)'
  750.     rm -f _shar_wnt_.tmp
  751. else
  752. > _shar_wnt_.tmp
  753. echo 'x - extracting ImageMagick/X.h (Text)'
  754. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/X.h' &&
  755. #undef False
  756. #undef True
  757. #define XLIB_ILLEGAL_ACCESS  1
  758. #include <X11/Xos.h>
  759. #include <X11/Xlib.h>
  760. #include <X11/Xutil.h>
  761. #include <X11/Xresource.h>
  762. #include <X11/Xproto.h>
  763. #include <X11/Xatom.h>
  764. #include <X11/cursorfont.h>
  765. #include <X11/keysym.h>
  766. #undef index
  767. #ifdef hpux
  768. #undef SYSV
  769. #endif
  770. X
  771. /*
  772. X  Colormap declarations.
  773. */
  774. #define UndefinedColormap  0
  775. #define PrivateColormap  1
  776. #define SharedColormap  2
  777. /*
  778. X  Define declarations.
  779. */
  780. #define MaxNumberFonts  9
  781. #define MaxNumberPens  9
  782. #define WindowBorderWidth  2
  783. #define XStandardPixel(map,color,shift)  (unsigned long) (map->base_pixel+  \
  784. X  ((color.red*map->red_max+(1 << (shift-1))) >> shift)*map->red_mult+  \
  785. X  ((color.green*map->green_max+(1 << (shift-1))) >> shift)*map->green_mult+  \
  786. X  ((color.blue*map->blue_max+(1 << (shift-1))) >> shift)*map->blue_mult)
  787. X
  788. /*
  789. X  Typedef declarations.
  790. */
  791. typedef struct _DiversityPacket
  792. {
  793. X  unsigned char
  794. X    red,
  795. X    green,
  796. X    blue;
  797. X
  798. X  unsigned short
  799. X    index;
  800. X
  801. X  unsigned long
  802. X    count;
  803. } DiversityPacket;
  804. X
  805. typedef struct _XAnnotateInfo
  806. {
  807. X  int
  808. X    x,
  809. X    y;
  810. X
  811. X  unsigned int
  812. X    width,
  813. X    height;
  814. X
  815. X  double
  816. X    degrees;
  817. X
  818. X  XFontStruct
  819. X    *font_info;
  820. X
  821. X  char
  822. X    *text,
  823. X    geometry[2048];
  824. X
  825. X  struct _XAnnotateInfo
  826. X    *previous,
  827. X    *next;
  828. } XAnnotateInfo;
  829. X
  830. typedef struct _XPixelInfo
  831. {
  832. X  GC
  833. X   graphic_context,
  834. X   highlight_context;
  835. X
  836. X  unsigned int
  837. X    colors;
  838. X
  839. X  unsigned long
  840. X    *pixels;
  841. X
  842. X  XColor
  843. X    background_color,
  844. X    border_color,
  845. X    foreground_color,
  846. X    highlight_color,
  847. X    pen_color[MaxNumberPens],
  848. X    annotate_color;
  849. X
  850. X  unsigned short
  851. X    background_index,
  852. X    annotate_index;
  853. } XPixelInfo;
  854. X
  855. typedef struct _XResourceInfo
  856. {
  857. X  ImageInfo
  858. X    *image_info;
  859. X
  860. X  unsigned int
  861. X    backdrop;
  862. X
  863. X  char
  864. X    *background_color,
  865. X    *border_color;
  866. X
  867. X  unsigned int
  868. X    border_width,
  869. X    colormap,
  870. X    colorspace,
  871. X    debug,
  872. X    delay;
  873. X
  874. X  unsigned int
  875. X    dither;
  876. X
  877. X  char
  878. X    *font,
  879. X    *font_name[MaxNumberFonts],
  880. X    *foreground_color;
  881. X
  882. X  int
  883. X    gravity;
  884. X
  885. X  char
  886. X    *highlight_color,
  887. X    *icon_geometry;
  888. X
  889. X  unsigned int
  890. X    iconic;
  891. X
  892. X  char
  893. X    *image_geometry;
  894. X
  895. X  unsigned int
  896. X    magnify;
  897. X
  898. X  char
  899. X    *map_type;
  900. X
  901. X  unsigned int
  902. X    monochrome;
  903. X
  904. X  char
  905. X    *name;
  906. X
  907. X  unsigned int
  908. X    number_colors;
  909. X
  910. X  char
  911. X    *pen_color[MaxNumberPens],
  912. X    *server_name,
  913. X    *title;
  914. X
  915. X  unsigned int
  916. X    tree_depth,
  917. X    update,
  918. X    use_pixmap;
  919. X
  920. X  char
  921. X    *visual_type,
  922. X    *write_filename;
  923. } XResourceInfo;
  924. X
  925. typedef struct _XWindowInfo
  926. {
  927. X  Window
  928. X    id;
  929. X
  930. X  int
  931. X    screen;
  932. X
  933. X  unsigned int
  934. X    depth;
  935. X
  936. X  XVisualInfo
  937. X    *visual_info;
  938. X
  939. X  XStandardColormap
  940. X    *map_info;
  941. X
  942. X  XPixelInfo
  943. X    *pixel_info;
  944. X
  945. X  XFontStruct
  946. X    *font_info;
  947. X
  948. X  GC
  949. X    graphic_context,
  950. X    highlight_context;
  951. X
  952. X  Cursor
  953. X    cursor,
  954. X    busy_cursor;
  955. X
  956. X  char
  957. X    *name,
  958. X    *geometry,
  959. X    *icon_name,
  960. X    *icon_geometry,
  961. X    *clip_geometry;
  962. X
  963. X  unsigned long
  964. X    flags;
  965. X
  966. X  int
  967. X    x,
  968. X    y;
  969. X
  970. X  unsigned int
  971. X    width,
  972. X    height,
  973. X    min_width,
  974. X    min_height,
  975. X    width_inc,
  976. X    height_inc,
  977. X    border_width,
  978. X    immutable;
  979. X
  980. X  XImage
  981. X    *ximage;
  982. X
  983. X  Pixmap
  984. X    pixmap,
  985. X    *pixmaps;
  986. X
  987. X  int
  988. X    mask;
  989. X
  990. X  XSetWindowAttributes
  991. X    attributes;
  992. } XWindowInfo;
  993. X
  994. typedef struct _XWindows
  995. {
  996. X  XWindowInfo
  997. X    context,
  998. X    backdrop,
  999. X    icon,
  1000. X    info,
  1001. X    image,
  1002. X    magnify,
  1003. X    pan,
  1004. X    popup;
  1005. } XWindows;
  1006. X
  1007. /*
  1008. X  X utilities routines.
  1009. */
  1010. extern char
  1011. X  *XGetResource _Declare((XrmDatabase,char *,char *,char *)),
  1012. X  *XVisualClassName _Declare((XVisualInfo *));
  1013. X
  1014. extern Cursor
  1015. X  XMakeInvisibleCursor _Declare((Display *,Window));
  1016. X
  1017. extern Image
  1018. X  *ReadXImage _Declare((char *,char *,unsigned int,unsigned int,unsigned int,
  1019. X    unsigned int));
  1020. X
  1021. extern int
  1022. X  Latin1Compare _Declare((char *,char *)),
  1023. X  XError _Declare((Display *,XErrorEvent *)),
  1024. X  XPopupMenu _Declare((Display *,XWindowInfo *,int,int,char *,char **,
  1025. X    unsigned int,char *));
  1026. X
  1027. extern unsigned int
  1028. X  IsTrue _Declare((char *)),
  1029. X  XAnnotateImage _Declare((Display *,XWindowInfo *,XAnnotateInfo *,
  1030. X    unsigned int,Image *)),
  1031. X  XMakeImage _Declare((Display *,XResourceInfo *,XWindowInfo *,Image *,
  1032. X    unsigned int,unsigned int)),
  1033. X  XMakePixmap _Declare((Display *,XResourceInfo *,XWindowInfo *));
  1034. X
  1035. extern XVisualInfo
  1036. X  *XBestVisualInfo _Declare((Display *,char *,char *,XStandardColormap *));
  1037. X
  1038. extern void
  1039. X  XBestIconSize _Declare((Display *,XWindowInfo *,Image *)),
  1040. X  XDisplayInfoString _Declare((Display *,XWindowInfo *,char *)),
  1041. X  XFreeStandardColormap _Declare((Display *,XVisualInfo *,XPixelInfo *,
  1042. X    XStandardColormap *)),
  1043. X  XGetAnnotateInfo _Declare((XAnnotateInfo *)),
  1044. X  XGetPixelInfo _Declare((Display *,XVisualInfo *,XStandardColormap *,
  1045. X    XResourceInfo *,Image *,XPixelInfo *)),
  1046. X  XGetResourceInfo _Declare((XrmDatabase,char *,XResourceInfo *)),
  1047. X  XGetWindowInfo _Declare((Display *,XVisualInfo *,XStandardColormap *,
  1048. X    XPixelInfo *,XFontStruct *,XResourceInfo *,XWindowInfo *)),
  1049. X  XMakeStandardColormap _Declare((Display *,XVisualInfo *,XResourceInfo *,
  1050. X    XPixelInfo *,Image *,XStandardColormap *)),
  1051. X  XMakeWindow _Declare((Display *,Window,char **,int,XClassHint *,XWMHints *,
  1052. X    Atom,XWindowInfo *)),
  1053. X  XPopupAlert _Declare((Display *,XWindowInfo *,char *,char *)),
  1054. X  XPopupQuery _Declare((Display *,XWindowInfo *,char *,char *)),
  1055. X  XSetWindowExtents _Declare((Display *,XWindowInfo *,char *)),
  1056. X  XRefreshWindow _Declare((Display *,XWindowInfo *,XEvent *));
  1057. X
  1058. extern Window
  1059. X  XWindowByID _Declare((Display *,Window,unsigned long)),
  1060. X  XWindowByName _Declare((Display *,Window,char *));
  1061. X
  1062. extern XFontStruct
  1063. X  *XBestFont _Declare((Display *,XResourceInfo *,char *,unsigned int));
  1064. X
  1065. /*
  1066. X  Invoke pre-X11R5 ICCCM routines if XlibSpecificationRelease is not defined.
  1067. */
  1068. #ifndef XlibSpecificationRelease
  1069. #define PRE_R5_ICCCM
  1070. #endif
  1071. /*
  1072. X  Invoke pre-X11R4 ICCCM routines if PWinGravity is not defined.
  1073. */
  1074. #ifndef PWinGravity
  1075. #define PRE_R4_ICCCM
  1076. #endif
  1077. #include "PreRvIcccm.h"
  1078. SHAR_EOF
  1079. chmod 0644 ImageMagick/X.h ||
  1080. echo 'restore of ImageMagick/X.h failed'
  1081. Wc_c="`wc -c < 'ImageMagick/X.h'`"
  1082. test 5805 -eq "$Wc_c" ||
  1083.     echo 'ImageMagick/X.h: original size 5805, current size' "$Wc_c"
  1084. rm -f _shar_wnt_.tmp
  1085. fi
  1086. # ============= ImageMagick/XWDFile.h ==============
  1087. if test -f 'ImageMagick/XWDFile.h' -a X"$1" != X"-c"; then
  1088.     echo 'x - skipping ImageMagick/XWDFile.h (File already exists)'
  1089.     rm -f _shar_wnt_.tmp
  1090. else
  1091. > _shar_wnt_.tmp
  1092. echo 'x - extracting ImageMagick/XWDFile.h (Text)'
  1093. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/XWDFile.h' &&
  1094. /* Copyright 1985, 1986, Massachusetts Institute of Technology */
  1095. X
  1096. /* $XConsortium: XWDFile.h,v 1.12 89/10/08 16:33:57 rws Exp $ */
  1097. /*
  1098. X * XWDFile.h    MIT Project Athena, X Window system window raster
  1099. X *        image dumper, dump file format header file.
  1100. X *
  1101. X *  Author:    Tony Della Fera, DEC
  1102. X *        27-Jun-85
  1103. X * 
  1104. X * Modifier:    William F. Wyatt, SAO
  1105. X *              18-Nov-86  - version 6 for saving/restoring color maps
  1106. X */
  1107. X
  1108. X
  1109. /*
  1110. X * This is not portable between machines of differing word sizes.  To make
  1111. X * it portable, do the following things:
  1112. X *
  1113. X *     o  #include <X11/Xmd.h>
  1114. X *     o  remove the typedef for xwdval
  1115. X *     o  replace all instances of xwdval with the appropriate CARD32 ... B32
  1116. X *     o  make sure that XWDFileHeader is padded to quadword boundaries
  1117. X *     o  make sure the window name is written out quadword aligned
  1118. X *     o  create an XWDColor structure that contains the same fields as XColor
  1119. X *        but which is defined in terms of CARD32 B32, CARD16 B16, and CARD8
  1120. X *     o  convert XColor structures to XWDColor structures in xwd
  1121. X *     o  remove all xwdval casts from xwd
  1122. X *     o  pack image data before writing out if necessary
  1123. X *     o  replace casts from xwdval objects in xwud with cvtINT macros
  1124. X *     o  convert XWDColor structures to XColor structures
  1125. X *     o  unpack data after reading in if necessary
  1126. X */
  1127. X
  1128. X
  1129. #include <X11/Xmd.h>
  1130. X
  1131. #define XWD_FILE_VERSION 7
  1132. #ifdef WORD64
  1133. #define sz_XWDheader 104
  1134. #else
  1135. #define sz_XWDheader 100
  1136. #endif
  1137. #define sz_XWDColor 12
  1138. X
  1139. typedef CARD32 xwdval;        /* for old broken programs */
  1140. X
  1141. typedef struct _xwd_file_header {
  1142. X    CARD32 header_size B32;  /* Size of the entire file header (bytes). */
  1143. X    CARD32 file_version B32;    /* XWD_FILE_VERSION */
  1144. X    CARD32 pixmap_format B32;    /* Pixmap format */
  1145. X    CARD32 pixmap_depth B32;    /* Pixmap depth */
  1146. X    CARD32 pixmap_width B32;    /* Pixmap width */
  1147. X    CARD32 pixmap_height B32;    /* Pixmap height */
  1148. X    CARD32 xoffset B32;        /* Bitmap x offset */
  1149. X    CARD32 byte_order B32;        /* MSBFirst, LSBFirst */
  1150. X    CARD32 bitmap_unit B32;        /* Bitmap unit */
  1151. X    CARD32 bitmap_bit_order B32;    /* MSBFirst, LSBFirst */
  1152. X    CARD32 bitmap_pad B32;        /* Bitmap scanline pad */
  1153. X    CARD32 bits_per_pixel B32;    /* Bits per pixel */
  1154. X    CARD32 bytes_per_line B32;    /* Bytes per scanline */
  1155. X    CARD32 visual_class B32;    /* Class of colormap */
  1156. X    CARD32 red_mask B32;        /* Z red mask */
  1157. X    CARD32 green_mask B32;        /* Z green mask */
  1158. X    CARD32 blue_mask B32;        /* Z blue mask */
  1159. X    CARD32 bits_per_rgb B32;    /* Log2 of distinct color values */
  1160. X    CARD32 colormap_entries B32;    /* Number of entries in colormap */
  1161. X    CARD32 ncolors B32;        /* Number of Color structures */
  1162. X    CARD32 window_width B32;    /* Window width */
  1163. X    CARD32 window_height B32;    /* Window height */
  1164. X    CARD32 window_x B32;        /* Window upper left X coordinate */
  1165. X    CARD32 window_y B32;        /* Window upper left Y coordinate */
  1166. X    CARD32 window_bdrwidth B32;    /* Window border width */
  1167. #ifdef WORD64
  1168. X    CARD32 header_end B32;        /* Pad to fill out word */
  1169. #endif
  1170. } XWDFileHeader;
  1171. X
  1172. struct {
  1173. X        CARD32    pixel B32;
  1174. X        CARD16    red B16;
  1175. X    CARD16    green B16;
  1176. X    CARD16    blue B16;
  1177. X        CARD8    flags;
  1178. X        CARD8    pad;
  1179. } XWDColor;
  1180. SHAR_EOF
  1181. chmod 0644 ImageMagick/XWDFile.h ||
  1182. echo 'restore of ImageMagick/XWDFile.h failed'
  1183. Wc_c="`wc -c < 'ImageMagick/XWDFile.h'`"
  1184. test 3092 -eq "$Wc_c" ||
  1185.     echo 'ImageMagick/XWDFile.h: original size 3092, current size' "$Wc_c"
  1186. rm -f _shar_wnt_.tmp
  1187. fi
  1188. # ============= ImageMagick/colors.c ==============
  1189. if test -f 'ImageMagick/colors.c' -a X"$1" != X"-c"; then
  1190.     echo 'x - skipping ImageMagick/colors.c (File already exists)'
  1191.     rm -f _shar_wnt_.tmp
  1192. else
  1193. > _shar_wnt_.tmp
  1194. echo 'x - extracting ImageMagick/colors.c (Text)'
  1195. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/colors.c' &&
  1196. /*
  1197. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1198. %                                                                             %
  1199. %                                                                             %
  1200. %                                                                             %
  1201. %                  CCCC   OOO   L       OOO   RRRR    SSSSS                   %
  1202. %                 C      O   O  L      O   O  R   R   SS                      %
  1203. %                 C      O   O  L      O   O  RRRR     SSS                    %
  1204. %                 C      O   O  L      O   O  R R        SS                   %
  1205. %                  CCCC   OOO   LLLLL   OOO   R  R    SSSSS                   %
  1206. %                                                                             %
  1207. %                                                                             %
  1208. %                       Count the Colors in an Image                          %
  1209. %                                                                             %
  1210. %                                                                             %
  1211. %                                                                             %
  1212. %                           Software Design                                   %
  1213. %                             John Cristy                                     %
  1214. %                              July 1992                                      %
  1215. %                                                                             %
  1216. %                                                                             %
  1217. %  Copyright 1993 E. I. du Pont de Nemours & Company                          %
  1218. %                                                                             %
  1219. %  Permission to use, copy, modify, distribute, and sell this software and    %
  1220. %  its documentation for any purpose is hereby granted without fee,           %
  1221. %  provided that the above Copyright notice appear in all copies and that     %
  1222. %  both that Copyright notice and this permission notice appear in            %
  1223. %  supporting documentation, and that the name of E. I. du Pont de Nemours    %
  1224. %  & Company not be used in advertising or publicity pertaining to            %
  1225. %  distribution of the software without specific, written prior               %
  1226. %  permission.  E. I. du Pont de Nemours & Company makes no representations   %
  1227. %  about the suitability of this software for any purpose.  It is provided    %
  1228. %  "as is" without express or implied warranty.                               %
  1229. %                                                                             %
  1230. %  E. I. du Pont de Nemours & Company disclaims all warranties with regard    %
  1231. %  to this software, including all implied warranties of merchantability      %
  1232. %  and fitness, in no event shall E. I. du Pont de Nemours & Company be       %
  1233. %  liable for any special, indirect or consequential damages or any           %
  1234. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  1235. %  in an action of contract, negligence or other tortious action, arising     %
  1236. %  out of or in connection with the use or performance of this software.      %
  1237. %                                                                             %
  1238. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1239. %
  1240. %
  1241. %
  1242. */
  1243. X
  1244. /*
  1245. X  Include declarations.
  1246. */
  1247. #include "display.h"
  1248. #include "image.h"
  1249. /*
  1250. X  Define declarations.
  1251. */
  1252. #define MaxTreeDepth  8  /* Log2(MaxRGB) */
  1253. #define NodesInAList  2048
  1254. X
  1255. /*
  1256. X  Structures.
  1257. */
  1258. typedef struct _Node
  1259. {
  1260. X  struct _Node
  1261. X    *child[8];
  1262. X
  1263. X  unsigned char
  1264. X    level,
  1265. X    mid_red,
  1266. X    mid_green,
  1267. X    mid_blue;
  1268. X
  1269. X  unsigned long
  1270. X    number_colors;
  1271. } Node;
  1272. X
  1273. typedef struct _Nodes
  1274. {
  1275. X  Node
  1276. X    nodes[NodesInAList];
  1277. X
  1278. X  struct _Nodes
  1279. X    *next;
  1280. } Nodes;
  1281. X
  1282. typedef struct _Cube
  1283. {
  1284. X  Node
  1285. X    *root;
  1286. X
  1287. X  unsigned int
  1288. X    colors;
  1289. X
  1290. X  unsigned int
  1291. X    free_nodes;
  1292. X
  1293. X  Node
  1294. X    *node;
  1295. X
  1296. X  Nodes
  1297. X    *node_list;
  1298. } Cube;
  1299. X
  1300. /*
  1301. X  Global variables.
  1302. */
  1303. static Cube
  1304. X  cube;
  1305. X
  1306. /*
  1307. X  External declarations.
  1308. */
  1309. extern char
  1310. X  *client_name;
  1311. X
  1312. /*
  1313. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1314. %                                                                             %
  1315. %                                                                             %
  1316. %                                                                             %
  1317. %  H i s t o g r a m                                                          %
  1318. %                                                                             %
  1319. %                                                                             %
  1320. %                                                                             %
  1321. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1322. %
  1323. %  Procedure Histogram traverses the color cube tree and produces a list of
  1324. %  unique pixel field values and the number of times each occurs in the image.
  1325. %
  1326. %  The format of the Histogram routine is:
  1327. %
  1328. %      Histogram(node,file)
  1329. %
  1330. %  A description of each parameter follows.
  1331. %
  1332. %    o node: The address of a structure of type Node which points to a
  1333. %      node in the color cube tree that is to be pruned.
  1334. %
  1335. %
  1336. */
  1337. static void Histogram(node,file)
  1338. register Node
  1339. X  *node;
  1340. X
  1341. FILE
  1342. X  *file;
  1343. {
  1344. X  register unsigned int
  1345. X    id;
  1346. X
  1347. X  /*
  1348. X    Traverse any children.
  1349. X  */
  1350. X  for (id=0; id < 8; id++)
  1351. X    if (node->child[id] != (Node *) NULL)
  1352. X      Histogram(node->child[id],file);
  1353. X  if (node->level == MaxTreeDepth)
  1354. X    (void) fprintf(file,"%8lu\t%d\t%d\t%d\n",node->number_colors,
  1355. X      node->mid_red,node->mid_green,node->mid_blue);
  1356. }
  1357. X
  1358. /*
  1359. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1360. %                                                                             %
  1361. %                                                                             %
  1362. %                                                                             %
  1363. %  I n i t i a l i z e N o d e                                                %
  1364. %                                                                             %
  1365. %                                                                             %
  1366. %                                                                             %
  1367. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1368. %
  1369. %  Function InitializeNode allocates memory for a new node in the color cube
  1370. %  tree and presets all fields to zero.
  1371. %
  1372. %  The format of the InitializeNode routine is:
  1373. %
  1374. %      node=InitializeNode(level,mid_red,mid_green,mid_blue)
  1375. %
  1376. %  A description of each parameter follows.
  1377. %
  1378. %    o level: Specifies the level in the classification the node resides.
  1379. %
  1380. %    o mid_red: Specifies the mid point of the red axis for this node.
  1381. %
  1382. %    o mid_green: Specifies the mid point of the green axis for this node.
  1383. %
  1384. %    o mid_blue: Specifies the mid point of the blue axis for this node.
  1385. %
  1386. %
  1387. */
  1388. static Node *InitializeNode(level,mid_red,mid_green,mid_blue)
  1389. unsigned int
  1390. X  level,
  1391. X  mid_red,
  1392. X  mid_green,
  1393. X  mid_blue;
  1394. {
  1395. X  register int
  1396. X    i;
  1397. X
  1398. X  register Node
  1399. X    *node;
  1400. X
  1401. X  if (cube.free_nodes == 0)
  1402. X    {
  1403. X      register Nodes
  1404. X        *nodes;
  1405. X
  1406. X      /*
  1407. X        Allocate a new nodes of nodes.
  1408. X      */
  1409. X      nodes=(Nodes *) malloc(sizeof(Nodes));
  1410. X      if (nodes == (Nodes *) NULL)
  1411. X        return((Node *) NULL);
  1412. X      nodes->next=cube.node_list;
  1413. X      cube.node_list=nodes;
  1414. X      cube.node=nodes->nodes;
  1415. X      cube.free_nodes=NodesInAList;
  1416. X    }
  1417. X  cube.free_nodes--;
  1418. X  node=cube.node++;
  1419. X  for (i=0; i < 8; i++)
  1420. X    node->child[i]=(Node *) NULL;
  1421. X  node->level=level;
  1422. X  node->mid_red=mid_red;
  1423. X  node->mid_green=mid_green;
  1424. X  node->mid_blue=mid_blue;
  1425. X  node->number_colors=0;
  1426. X  return(node);
  1427. }
  1428. X
  1429. /*
  1430. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1431. %                                                                             %
  1432. %                                                                             %
  1433. %                                                                             %
  1434. %  N u m b e r C o l o r s                                                    %
  1435. %                                                                             %
  1436. %                                                                             %
  1437. %                                                                             %
  1438. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1439. %
  1440. %  Function NumberColors returns the number of unique colors in an image.
  1441. %
  1442. %  The format of the NumberColors routine is:
  1443. %
  1444. %      number_colors=NumberColors(image,file)
  1445. %
  1446. %  A description of each parameter follows.
  1447. %
  1448. %    o image: The address of a byte (8 bits) array of run-length
  1449. %      encoded pixel data of your source image.  The sum of the
  1450. %      run-length counts in the source image must be equal to or exceed
  1451. %      the number of pixels.
  1452. %
  1453. %    o file:  An pointer to a FILE.  If it is non-null a list of unique pixel
  1454. %      field values and the number of times each occurs in the image is
  1455. %      written to the file.
  1456. %
  1457. %
  1458. %
  1459. */
  1460. unsigned int NumberColors(image,file)
  1461. Image
  1462. X  *image;
  1463. X
  1464. FILE
  1465. X  *file;
  1466. {
  1467. X  Nodes
  1468. X    *nodes;
  1469. X
  1470. X  register RunlengthPacket
  1471. X    *p;
  1472. X
  1473. X  register int
  1474. X    i;
  1475. X
  1476. X  register Node
  1477. X    *node;
  1478. X
  1479. X  register unsigned int
  1480. X    count,
  1481. X    id,
  1482. X    level;
  1483. X
  1484. X  unsigned int
  1485. X    bisect;
  1486. X
  1487. X  /*
  1488. X    Initialize color description tree.
  1489. X  */
  1490. X  cube.node_list=(Nodes *) NULL;
  1491. X  cube.colors=0;
  1492. X  cube.free_nodes=0;
  1493. X  cube.root=InitializeNode(0,(MaxRGB+1) >> 1,(MaxRGB+1) >> 1,(MaxRGB+1) >> 1);
  1494. X  if (cube.root == (Node *) NULL)
  1495. X    {
  1496. X      Warning("unable to count colors","memory allocation failed");
  1497. X      return(0);
  1498. X    }
  1499. X  p=image->pixels;
  1500. X  for (i=0; i < image->packets; i++)
  1501. X  {
  1502. X    /*
  1503. X      Start at the root and proceed level by level.
  1504. X    */
  1505. X    count=p->length+1;
  1506. X    node=cube.root;
  1507. X    for (level=1; level <= MaxTreeDepth; level++)
  1508. X    {
  1509. X      id=(p->red >= node->mid_red ? 1 : 0) |
  1510. X        (p->green >= node->mid_green ? 1 : 0) << 1 |
  1511. X        (p->blue >= node->mid_blue ? 1 : 0) << 2;
  1512. X      if (node->child[id] == (Node *) NULL)
  1513. X        {
  1514. X          if (level == MaxTreeDepth)
  1515. X            {
  1516. X              node->child[id]=InitializeNode(level,p->red,p->green,p->blue);
  1517. X              cube.colors++;
  1518. X            }
  1519. X          else
  1520. X            {
  1521. X              bisect=(unsigned int) (1 << (MaxTreeDepth-level)) >> 1;
  1522. X              node->child[id]=InitializeNode(level,
  1523. X                node->mid_red+(id & 1 ? bisect : -bisect),
  1524. X                node->mid_green+(id & 2 ? bisect : -bisect),
  1525. X                node->mid_blue+(id & 4 ? bisect : -bisect));
  1526. X            }
  1527. X          if (node->child[id] == (Node *) NULL)
  1528. X            {
  1529. X              Warning("unable to count colors","memory allocation failed");
  1530. X              return(0);
  1531. X            }
  1532. X        }
  1533. X      node=node->child[id];
  1534. X    }
  1535. X    node->number_colors+=count;
  1536. X    p++;
  1537. X  }
  1538. X  if (file != (FILE *) NULL)
  1539. X    Histogram(cube.root,file);
  1540. X  /*
  1541. X    Release color cube tree storage.
  1542. X  */
  1543. X  do
  1544. X  {
  1545. X    nodes=cube.node_list->next;
  1546. X    (void) free((char *) cube.node_list);
  1547. X    cube.node_list=nodes;
  1548. X  }
  1549. X  while (cube.node_list != (Nodes *) NULL);
  1550. X  return(cube.colors);
  1551. }
  1552. SHAR_EOF
  1553. chmod 0644 ImageMagick/colors.c ||
  1554. echo 'restore of ImageMagick/colors.c failed'
  1555. Wc_c="`wc -c < 'ImageMagick/colors.c'`"
  1556. test 11194 -eq "$Wc_c" ||
  1557.     echo 'ImageMagick/colors.c: original size 11194, current size' "$Wc_c"
  1558. rm -f _shar_wnt_.tmp
  1559. fi
  1560. # ============= ImageMagick/shear.c ==============
  1561. if test -f 'ImageMagick/shear.c' -a X"$1" != X"-c"; then
  1562.     echo 'x - skipping ImageMagick/shear.c (File already exists)'
  1563.     rm -f _shar_wnt_.tmp
  1564. else
  1565. > _shar_wnt_.tmp
  1566. echo 'x - extracting ImageMagick/shear.c (Text)'
  1567. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/shear.c' &&
  1568. /*
  1569. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1570. %                                                                             %
  1571. %                                                                             %
  1572. %                                                                             %
  1573. %                      SSSSS  H   H  EEEEE   AAA    RRRR                      %
  1574. %                      SS     H   H  E      A   A   R   R                     %
  1575. %                       SSS   HHHHH  EEE    AAAAA   RRRR                      %
  1576. %                         SS  H   H  E      A   A   R R                       %
  1577. %                      SSSSS  H   H  EEEEE  A   A   R  R                      %
  1578. %                                                                             %
  1579. %                                                                             %
  1580. %              Shear or rotate a raster image by an arbitrary angle.          %
  1581. %                                                                             %
  1582. %                                                                             %
  1583. %                                                                             %
  1584. %                               Software Design                               %
  1585. %                                 John Cristy                                 %
  1586. %                                  July 1992                                  %
  1587. %                                                                             %
  1588. %                                                                             %
  1589. %  Copyright 1993 E. I. du Pont de Nemours & Company                          %
  1590. %                                                                             %
  1591. %  Permission to use, copy, modify, distribute, and sell this software and    %
  1592. %  its documentation for any purpose is hereby granted without fee,           %
  1593. %  provided that the above Copyright notice appear in all copies and that     %
  1594. %  both that Copyright notice and this permission notice appear in            %
  1595. %  supporting documentation, and that the name of E. I. du Pont de Nemours    %
  1596. %  & Company not be used in advertising or publicity pertaining to            %
  1597. %  distribution of the software without specific, written prior               %
  1598. %  permission.  E. I. du Pont de Nemours & Company makes no representations   %
  1599. %  about the suitability of this software for any purpose.  It is provided    %
  1600. %  "as is" without express or implied warranty.                               %
  1601. %                                                                             %
  1602. %  E. I. du Pont de Nemours & Company disclaims all warranties with regard    %
  1603. %  to this software, including all implied warranties of merchantability      %
  1604. %  and fitness, in no event shall E. I. du Pont de Nemours & Company be       %
  1605. %  liable for any special, indirect or consequential damages or any           %
  1606. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  1607. %  in an action of contract, negligence or other tortious action, arising     %
  1608. %  out of or in connection with the use or performance of this software.      %
  1609. %                                                                             %
  1610. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1611. %
  1612. %  Function RotateImage, XShearImage, and YShearImage is based on the paper
  1613. %  "A Fast Algorithm for General Raster Rotatation" by Alan W. Paeth,
  1614. %  Graphics Interface '86 (Vancouver).  RotateImage is adapted from a similiar
  1615. %  routine based on the Paeth paper written by Michael Halle of the Spatial
  1616. %  Imaging Group, MIT Media Lab.
  1617. %
  1618. %
  1619. */
  1620. X
  1621. /*
  1622. X  Include declarations.
  1623. */
  1624. #include "display.h"
  1625. #include "image.h"
  1626. X
  1627. /*
  1628. X  External declarations.
  1629. */
  1630. extern char
  1631. X  *client_name;
  1632. X
  1633. /*
  1634. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1635. %                                                                             %
  1636. %                                                                             %
  1637. %                                                                             %
  1638. %   C l i p S h e a r I m a g e                                               %
  1639. %                                                                             %
  1640. %                                                                             %
  1641. %                                                                             %
  1642. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1643. %
  1644. %  Function ClipShearImage clips the sheared image as determined by the
  1645. %  bounding box as defined by width and height and shearing angles.
  1646. %
  1647. %  The format of the ClipShearImage routine is:
  1648. %
  1649. %      ClipShearImage(image,x_shear,y_shear,width,height,clip)
  1650. %
  1651. %  A description of each parameter follows.
  1652. %
  1653. %    o image: The address of a structure of type Image.
  1654. %
  1655. %    o x_shear, y_shear, width, height: Defines a region of the image to clip.
  1656. %
  1657. %    o clip: A value other than zero clips the corners of the rotated
  1658. %      image and retains the original image size.
  1659. %
  1660. %
  1661. */
  1662. static Image *ClipShearImage(image,x_shear,y_shear,width,height,clip)
  1663. Image
  1664. X  *image;
  1665. X
  1666. double
  1667. X  x_shear,
  1668. X  y_shear;
  1669. X
  1670. unsigned int
  1671. X  width,
  1672. X  height,
  1673. X  clip;
  1674. {
  1675. X  typedef struct Point
  1676. X  {
  1677. X    double
  1678. X      x,
  1679. X      y;
  1680. X  } Point;
  1681. X
  1682. X  double
  1683. X    x_max,
  1684. X    x_min,
  1685. X    y_max,
  1686. X    y_min;
  1687. X
  1688. X  Image
  1689. X    *clipped_image;
  1690. X
  1691. X  Point
  1692. X    corners[4];
  1693. X
  1694. X  RectangleInfo
  1695. X    clip_info;
  1696. X
  1697. X  register int
  1698. X    i;
  1699. X
  1700. X  /*
  1701. X    Calculate the rotated image size.
  1702. X  */
  1703. X  clip_info.width=width;
  1704. X  clip_info.height=height;
  1705. X  corners[0].x=(-((int) clip_info.width)/2.0);
  1706. X  corners[0].y=(-((int) clip_info.height)/2.0);
  1707. X  corners[1].x=((int) clip_info.width)/2.0;
  1708. X  corners[1].y=(-((int) clip_info.height)/2.0);
  1709. X  corners[2].x=(-((int) clip_info.width)/2.0);
  1710. X  corners[2].y=((int) clip_info.height)/2.0;
  1711. X  corners[3].x=((int) clip_info.width)/2.0;
  1712. X  corners[3].y=((int) clip_info.height)/2.0;
  1713. X  for (i=0; i < 4; i++)
  1714. X  {
  1715. X    corners[i].x+=x_shear*corners[i].y;
  1716. X    corners[i].y+=y_shear*corners[i].x;
  1717. X    corners[i].x+=x_shear*corners[i].y;
  1718. X    corners[i].x+=(image->columns-1)/2.0;
  1719. SHAR_EOF
  1720. true || echo 'restore of ImageMagick/shear.c failed'
  1721. fi
  1722. echo 'End of ImageMagick part 12'
  1723. echo 'File ImageMagick/shear.c is continued in part 13'
  1724. echo 13 > _shar_seq_.tmp
  1725. exit 0
  1726.  
  1727. exit 0 # Just in case...
  1728. -- 
  1729.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  1730. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  1731.  "It's intuitively obvious to the |
  1732.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  1733.