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

  1. Newsgroups: comp.sources.x
  2. From: cristy@eplrx7.es.duPont.com (Cristy)
  3. Subject: v20i075:  imagemagic - X11 image processing and display, Part19/38
  4. Message-ID: <1993Jul14.175746.1880@sparky.sterling.com>
  5. X-Md4-Signature: ade494ab4486b420325968b41ed54ccb
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Wed, 14 Jul 1993 17:57:46 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: cristy@eplrx7.es.duPont.com (Cristy)
  12. Posting-number: Volume 20, Issue 75
  13. Archive-name: imagemagic/part19
  14. Environment: X11
  15. Supersedes: imagemagic: Volume 13, Issue 17-37
  16.  
  17. #!/bin/sh
  18. # this is magick.19 (part 19 of ImageMagick)
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file ImageMagick/animate.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" != 19; 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/animate.c'
  36. else
  37. echo 'x - continuing file ImageMagick/animate.c'
  38. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/animate.c' &&
  39. X  window->image.border_width=resource_info->border_width;
  40. X  window->image.immutable=False;
  41. X  window->image.attributes.event_mask=ButtonMotionMask | ButtonPressMask |
  42. X    ButtonReleaseMask | EnterWindowMask | ExposureMask | KeyPressMask |
  43. X    LeaveWindowMask | OwnerGrabButtonMask | StructureNotifyMask;
  44. X  XGetWindowInfo(display,visual_info,map_info,&pixel_info,font_info,
  45. X    resource_info,&window->backdrop);
  46. X  if (resource_info->backdrop)
  47. X    {
  48. X      /*
  49. X        Initialize backdrop window.
  50. X      */
  51. X      window->backdrop.cursor=XMakeInvisibleCursor(display,root_window);
  52. X      if (window->backdrop.cursor == (Cursor) NULL)
  53. X        Error("unable to create cursor",(char *) NULL);
  54. X      window->backdrop.name="ImageMagick Background";
  55. X      window->backdrop.flags=USSize | USPosition;
  56. X      window->backdrop.width=XDisplayWidth(display,visual_info->screen);
  57. X      window->backdrop.height=XDisplayHeight(display,visual_info->screen);
  58. X      window->backdrop.border_width=0;
  59. X      window->backdrop.immutable=True;
  60. X      window->backdrop.attributes.cursor=window->backdrop.cursor;
  61. X      window->backdrop.attributes.do_not_propagate_mask=
  62. X        ButtonPressMask | ButtonReleaseMask;
  63. X      window->backdrop.attributes.override_redirect=True;
  64. X      manager_hints->flags=IconWindowHint | InputHint | StateHint;
  65. X      manager_hints->icon_window=window->icon.id;
  66. X      manager_hints->input=True;
  67. X      manager_hints->initial_state=
  68. X        resource_info->iconic ? IconicState : NormalState;
  69. X      XMakeWindow(display,root_window,argv,argc,class_hint,manager_hints,
  70. X        delete_property,&window->backdrop);
  71. X      if (resource_info->debug)
  72. X        (void) fprintf(stderr,"Window id: 0x%lx (backdrop)\n",
  73. X          window->backdrop.id);
  74. X      XSetTransientForHint(display,window->backdrop.id,window->backdrop.id);
  75. X      XMapWindow(display,window->backdrop.id);
  76. X      /*
  77. X        Position image in the center the backdrop.
  78. X      */
  79. X      window->image.flags|=USPosition;
  80. X      window->image.x=XDisplayWidth(display,visual_info->screen)/2-
  81. X        window->image.width/2;
  82. X      window->image.y=XDisplayHeight(display,visual_info->screen)/2-
  83. X        window->image.height/2;
  84. X      window->image.attributes.event_mask|=FocusChangeMask;
  85. X    }
  86. X  manager_hints->flags=IconWindowHint | InputHint | StateHint;
  87. X  manager_hints->icon_window=window->icon.id;
  88. X  manager_hints->input=True;
  89. X  manager_hints->initial_state=
  90. X    resource_info->iconic ? IconicState : NormalState;
  91. X  XMakeWindow(display,(resource_info->backdrop ? window->backdrop.id :
  92. X    root_window),argv,argc,class_hint,manager_hints,delete_property,
  93. X    &window->image);
  94. X  if (resource_info->debug)
  95. X    (void) fprintf(stderr,"Window id: 0x%lx (image)\n",window->image.id);
  96. X  XMapWindow(display,window->image.id);
  97. X  window->image.x=0;
  98. X  window->image.y=0;
  99. X  /*
  100. X    Initialize image X image structure.
  101. X  */
  102. X  status=XMakeImage(display,resource_info,&window->image,images[0],
  103. X    images[0]->columns,images[0]->rows);
  104. X  status|=XMakePixmap(display,resource_info,&window->image);
  105. X  if (status == False)
  106. X    Error("unable to create X image",(char *) NULL);
  107. X  if (resource_info->debug)
  108. X    {
  109. X      (void) fprintf(stderr,"Image: [%u] %s %ux%u ",images[0]->scene,
  110. X        images[0]->filename,images[0]->columns,images[0]->rows);
  111. X      if (images[0]->colors != 0)
  112. X        (void) fprintf(stderr,"%uc ",images[0]->colors);
  113. X      (void) fprintf(stderr,"%s\n",images[0]->magick);
  114. X    }
  115. X  XRefreshWindow(display,&window->image,(XEvent *) NULL);
  116. X  /*
  117. X    Initialize popup window.
  118. X  */
  119. X  XGetWindowInfo(display,visual_info,map_info,&pixel_info,font_info,
  120. X    resource_info,&window->popup);
  121. X  window->popup.name="ImageMagick Popup";
  122. X  window->popup.flags=PSize | PPosition;
  123. X  window->popup.attributes.override_redirect=True;
  124. X  window->popup.attributes.save_under=True;
  125. X  window->popup.attributes.event_mask=ButtonMotionMask | ButtonPressMask |
  126. X    ButtonReleaseMask | EnterWindowMask | ExposureMask | LeaveWindowMask |
  127. X    OwnerGrabButtonMask;
  128. X  manager_hints->flags=InputHint | StateHint | WindowGroupHint;
  129. X  manager_hints->input=False;
  130. X  manager_hints->initial_state=NormalState;
  131. X  manager_hints->window_group=window->image.id;
  132. X  XMakeWindow(display,root_window,argv,argc,class_hint,manager_hints,
  133. X    delete_property,&window->popup);
  134. X  if (resource_info->debug)
  135. X    (void) fprintf(stderr,"Window id: 0x%lx (popup)\n",window->popup.id);
  136. X  XSetTransientForHint(display,window->popup.id,window->image.id);
  137. X  /*
  138. X    Initialize info window.
  139. X  */
  140. X  XGetWindowInfo(display,visual_info,map_info,&pixel_info,font_info,
  141. X    resource_info,&window->info);
  142. X  window->info.name="ImageMagick Info";
  143. X  window->info.flags=PSize | PPosition;
  144. X  window->info.x=2;
  145. X  window->info.y=2;
  146. X  window->info.attributes.win_gravity=UnmapGravity;
  147. X  window->info.attributes.event_mask=StructureNotifyMask;
  148. X  manager_hints->flags=InputHint | StateHint | WindowGroupHint;
  149. X  manager_hints->input=False;
  150. X  manager_hints->initial_state=NormalState;
  151. X  manager_hints->window_group=window->image.id;
  152. X  XMakeWindow(display,window->image.id,argv,argc,class_hint,manager_hints,
  153. X    delete_property,&window->info);
  154. X  if (resource_info->debug)
  155. X    (void) fprintf(stderr,"Window id: 0x%lx (info)\n",window->info.id);
  156. X  /*
  157. X    Initialize image pixmaps structure.
  158. X  */
  159. X  XDefineCursor(display,window->image.id,window->image.busy_cursor);
  160. X  XMapWindow(display,window->info.id);
  161. X  window->image.pixmaps=(Pixmap *) malloc(number_scenes*sizeof(Pixmap));
  162. X  if (window->image.pixmaps == (Pixmap *) NULL)
  163. X    Error("unable to animate images","memory allocation failed");
  164. X  window->image.pixmaps[0]=window->image.pixmap;
  165. X  scene_info.pixels=(unsigned long *) NULL;
  166. X  for (scene=1; scene < number_scenes; scene++)
  167. X  {
  168. X    /*
  169. X      Display information about the image in the info window.
  170. X    */
  171. X    (void) sprintf(text," [%u] %s %ux%u ",images[scene]->scene,
  172. X      images[scene]->filename,window->image.width,window->image.height);
  173. X    if (images[scene]->colors > 0)
  174. X      (void) sprintf(text,"%s%uc ",text,images[scene]->colors);
  175. X    XSetWindowExtents(display,&window->info,text);
  176. X    XDisplayInfoString(display,&window->info,text);
  177. X    XFlush(display);
  178. X    /*
  179. X      Create X image.
  180. X    */
  181. X    window->image.pixmap=(Pixmap) NULL;
  182. X    if (images[scene]->packed_pixels != (unsigned char *) NULL)
  183. X      {
  184. X        status=RunlengthDecodeImage(images[scene]);
  185. X        if (status == False)
  186. X          Error("unable to unpack image",(char *) NULL);
  187. X      }
  188. X    if ((resource_info->map_type != (char *) NULL) ||
  189. X        (visual_info->class == TrueColor) ||
  190. X        (visual_info->class == DirectColor))
  191. X      if (images[scene]->class == PseudoClass)
  192. X        {
  193. X          /*
  194. X            Get pixel info for this scene.
  195. X          */
  196. X          XGetPixelInfo(display,visual_info,map_info,resource_info,
  197. X            images[scene],&scene_info);
  198. X          window->image.pixel_info=(&scene_info);
  199. X        }
  200. X    status=XMakeImage(display,resource_info,&window->image,images[scene],
  201. X      images[scene]->columns,images[scene]->rows);
  202. X    status|=XMakePixmap(display,resource_info,&window->image);
  203. X    if (status == False)
  204. X      Error("unable to create X image",(char *) NULL);
  205. X    if (resource_info->debug)
  206. X      {
  207. X        (void) fprintf(stderr,"Image: [%u] %s %ux%u ",images[scene]->scene,
  208. X          images[scene]->filename,images[scene]->columns,images[scene]->rows);
  209. X        if (images[scene]->colors != 0)
  210. X          (void) fprintf(stderr,"%uc ",images[scene]->colors);
  211. X        (void) fprintf(stderr,"%s\n",images[scene]->magick);
  212. X      }
  213. X    /*
  214. X      Free image pixels.
  215. X    */
  216. X    if (scene_info.pixels != (unsigned long *) NULL)
  217. X      (void) free((char *) scene_info.pixels);
  218. X    (void) free((char *) images[scene]->pixels);
  219. X    images[scene]->pixels=(RunlengthPacket *) NULL;
  220. X    /*
  221. X      Refresh image window.
  222. X    */
  223. X    window->image.pixmaps[scene]=window->image.pixmap;
  224. X    XRefreshWindow(display,&window->image,(XEvent *) NULL);
  225. X    XSync(display,False);
  226. X  }
  227. X  window->image.pixel_info=(&pixel_info);
  228. X  XWithdrawWindow(display,window->info.id,window->info.screen);
  229. X  XDefineCursor(display,window->image.id,window->image.cursor);
  230. X  /*
  231. X    Respond to events.
  232. X  */
  233. X  image=images[0];
  234. X  state=DefaultState;
  235. X  scene=0;
  236. X  do
  237. X  {
  238. X    if (XEventsQueued(display,QueuedAfterFlush) == 0)
  239. X      if ((state & PlayAnimationState) || (state & StepAnimationState))
  240. X        {
  241. X          if (state & InfoMappedState)
  242. X            XWithdrawWindow(display,window->info.id,window->info.screen);
  243. X          /*
  244. X            Copy X pixmap to image window.
  245. X          */
  246. X          image=images[scene];
  247. X          window->image.pixmap=window->image.pixmaps[scene];
  248. X          XRefreshWindow(display,&window->image,(XEvent *) NULL);
  249. X          XSync(display,False);
  250. X          if (state & StepAnimationState)
  251. X            {
  252. X              state&=(~StepAnimationState);
  253. X              UserCommand(display,resource_info,window,XK_i,&images[scene],
  254. X                &state);
  255. X            }
  256. X          if (resource_info->delay != 0)
  257. X            Delay((unsigned long) resource_info->delay);
  258. X          if (state & ForwardAnimationState)
  259. X            {
  260. X              /*
  261. X                Forward animation:  increment scene number.
  262. X              */
  263. X              scene++;
  264. X              if (scene == number_scenes)
  265. X                if (state & AutoReverseAnimationState)
  266. X                  {
  267. X                    state&=(~ForwardAnimationState);
  268. X                    scene--;
  269. X                  }
  270. X                else
  271. X                  {
  272. X                    if (!(state & RepeatAnimationState))
  273. X                      state&=(~PlayAnimationState);
  274. X                    scene=0;
  275. X                  }
  276. X            }
  277. X          else
  278. X            {
  279. X              /*
  280. X                Reverse animation:  decrement scene number.
  281. X              */
  282. X              scene--;
  283. X              if (scene < 0)
  284. X                if (state & AutoReverseAnimationState)
  285. X                  {
  286. X                    state|=ForwardAnimationState;
  287. X                    scene=0;
  288. X                  }
  289. X                else
  290. X                  {
  291. X                    if (!(state & RepeatAnimationState))
  292. X                      state&=(~PlayAnimationState);
  293. X                    scene=number_scenes-1;
  294. X                  }
  295. X            }
  296. X          continue;
  297. X        }
  298. X    /*
  299. X      Handle a window event.
  300. X    */
  301. X    XNextEvent(display,&event);
  302. X    switch (event.type)
  303. X    {
  304. X      case ButtonPress:
  305. X      {
  306. X        if (event.xbutton.window == window->image.id)
  307. X          switch (event.xbutton.button)
  308. X          {
  309. X            case Button1:
  310. X            {
  311. X              char
  312. X                command[2048];
  313. X
  314. X              int
  315. X                command_number;
  316. X
  317. X              static char
  318. X                *MenuSelections[]=
  319. X                {
  320. X                  "Image Info",
  321. X                  "Play",
  322. X                  "Step",
  323. X                  "Repeat",
  324. X                  "Auto Reverse",
  325. X                  "Slower",
  326. X                  "Faster",
  327. X                  "Forward",
  328. X                  "Reverse",
  329. X                  "Quit"
  330. X                };
  331. X
  332. X              static KeySym
  333. X                MenuCommand[]=
  334. X                {
  335. X                  XK_i,
  336. X                  XK_p,
  337. X                  XK_s,
  338. X                  XK_period,
  339. X                  XK_a,
  340. X                  XK_less,
  341. X                  XK_greater,
  342. X                  XK_f,
  343. X                  XK_r,
  344. X                  XK_q
  345. X                };
  346. X
  347. X              /*
  348. X                Select a command from the pop-up menu.
  349. X              */
  350. X              command_number=XPopupMenu(display,&window->popup,
  351. X                event.xbutton.x_root,event.xbutton.y_root,"Commands",
  352. X                MenuSelections,sizeof(MenuSelections)/sizeof(char *),command);
  353. X              if (command_number >= 0)
  354. X                UserCommand(display,resource_info,window,
  355. X                  MenuCommand[command_number],&image,&state);
  356. X              break;
  357. X            }
  358. X            default:
  359. X              break;
  360. X          }
  361. X        break;
  362. X      }
  363. X      case ClientMessage:
  364. X      {
  365. X        /*
  366. X          If client window delete message, exit.
  367. X        */
  368. X        if (event.xclient.message_type == protocols_property)
  369. X          if (*event.xclient.data.l == delete_property)
  370. X            if (event.xclient.window == window->image.id)
  371. X              state|=ExitState;
  372. X            else
  373. X              XWithdrawWindow(display,event.xclient.window,visual_info->screen);
  374. X        break;
  375. X      }
  376. X      case ConfigureNotify:
  377. X      {
  378. X        if (resource_info->debug)
  379. X          (void) fprintf(stderr,"Configure Notify: 0x%lx %dx%d+%d+%d\n",
  380. X            event.xconfigure.window,event.xconfigure.width,
  381. X            event.xconfigure.height,event.xconfigure.x,event.xconfigure.y);
  382. X        if (event.xconfigure.window == window->image.id)
  383. X          {
  384. X            /*
  385. X              Image window has a new configuration.
  386. X            */
  387. X            window->image.width=event.xconfigure.width;
  388. X            window->image.height=event.xconfigure.height;
  389. X            break;
  390. X          }
  391. X        if (event.xconfigure.window == window->icon.id)
  392. X          {
  393. X            /*
  394. X              Icon window has a new configuration.
  395. X            */
  396. X            window->icon.width=event.xconfigure.width;
  397. X            window->icon.height=event.xconfigure.height;
  398. X            break;
  399. X          }
  400. X      }
  401. X      case EnterNotify:
  402. X      {
  403. X        /*
  404. X          Selectively install colormap.
  405. X        */
  406. X        if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
  407. X          if (event.xcrossing.mode != NotifyUngrab)
  408. X            XInductColormap(display,map_info->colormap);
  409. X        break;
  410. X      }
  411. X      case Expose:
  412. X      {
  413. X        if (resource_info->debug)
  414. X          (void) fprintf(stderr,"Expose: 0x%lx %dx%d+%d+%d\n",
  415. X            event.xexpose.window,event.xexpose.width,event.xexpose.height,
  416. X            event.xexpose.x,event.xexpose.y);
  417. X        /*
  418. X          Repaint windows that are now exposed.
  419. X        */
  420. X        if (event.xexpose.window == window->image.id)
  421. X          {
  422. X            window->image.pixmap=window->image.pixmaps[scene];
  423. X            XRefreshWindow(display,&window->image,&event);
  424. X            break;
  425. X          }
  426. X        break;
  427. X      }
  428. X      case FocusOut:
  429. X      {
  430. X        /*
  431. X          Set input focus for backdrop window.
  432. X        */
  433. X        if (resource_info->debug)
  434. X          (void) fprintf(stderr,"FocusOut Notify: 0x%lx\n",event.xfocus.window);
  435. X        if (event.xfocus.window == window->image.id)
  436. X          XSetInputFocus(display,window->image.id,RevertToNone,CurrentTime);
  437. X        break;
  438. X      }
  439. X      case KeyPress:
  440. X      {
  441. X        static char
  442. X          command[2048];
  443. X
  444. X        static KeySym
  445. X          key_symbol;
  446. X
  447. X        /*
  448. X          Respond to a user key press.
  449. X        */
  450. X        if (state & ConfigureWindowState)
  451. X          {
  452. X            XBell(display,0);
  453. X            break;
  454. X          }
  455. X        *command='\0';
  456. X        XLookupString((XKeyEvent *) &event.xkey,command,sizeof(command),
  457. X          &key_symbol,(XComposeStatus *) NULL);
  458. X        if (key_symbol == XK_Help)
  459. X          Usage(False);
  460. X        else
  461. X          if (!IsCursorKey(key_symbol))
  462. X            UserCommand(display,resource_info,window,key_symbol,&image,&state);
  463. X        break;
  464. X      }
  465. X      case LeaveNotify:
  466. X      {
  467. X        /*
  468. X          Selectively uninstall colormap.
  469. X        */
  470. X        if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
  471. X          if (event.xcrossing.mode != NotifyUngrab)
  472. X            XUninductColormap(display,map_info->colormap);
  473. X        break;
  474. X      }
  475. X      case MapNotify:
  476. X      {
  477. X        if (resource_info->debug)
  478. X          (void) fprintf(stderr,"Map Notify: 0x%lx\n",event.xmap.window);
  479. X        if (event.xmap.window == window->image.id)
  480. X          {
  481. X            state=ForwardAnimationState | PlayAnimationState;
  482. X            if (window->backdrop.id != (Window) NULL)
  483. X              {
  484. X                /*
  485. X                  Install colormap and set input focus for backdrop window.
  486. X                */
  487. X                XInstallColormap(display,map_info->colormap);
  488. X                XSetInputFocus(display,window->image.id,RevertToNone,
  489. X                  CurrentTime);
  490. X                break;
  491. X              }
  492. X            break;
  493. X          }
  494. X        if (event.xmap.window == window->info.id)
  495. X          {
  496. X            state|=InfoMappedState;
  497. X            break;
  498. X          }
  499. X        if (event.xmap.window == window->icon.id)
  500. X          {
  501. X            /*
  502. X              Create icon pixmap.
  503. X            */
  504. X            status=XMakeImage(display,resource_info,&window->icon,images[0],
  505. X              window->icon.width,window->icon.height);
  506. X            status|=XMakePixmap(display,resource_info,&window->icon);
  507. X            if (status == False)
  508. X              Error("unable to create icon image",(char *) NULL);
  509. X            XSetWindowBackgroundPixmap(display,window->icon.id,
  510. X              window->icon.pixmap);
  511. X            XClearWindow(display,window->icon.id);
  512. X            break;
  513. X          }
  514. X        break;
  515. X      }
  516. X      case MappingNotify:
  517. X      {
  518. X        XRefreshKeyboardMapping(&event.xmapping);
  519. X        break;
  520. X      }
  521. X      case ReparentNotify:
  522. X      {
  523. X        if (resource_info->debug)
  524. X          (void) fprintf(stderr,"Reparent Notify: 0x%lx=>0x%lx\n",
  525. X            event.xreparent.parent,event.xreparent.window);
  526. X        break;
  527. X      }
  528. X      case UnmapNotify:
  529. X      {
  530. X        if (resource_info->debug)
  531. X          (void) fprintf(stderr,"Unmap Notify: 0x%lx\n",event.xunmap.window);
  532. X        if (event.xunmap.window == window->info.id)
  533. X          {
  534. X            state&=(~InfoMappedState);
  535. X            break;
  536. X          }
  537. X        break;
  538. X      }
  539. X      default:
  540. X      {
  541. X        if (resource_info->debug)
  542. X          (void) fprintf(stderr,"Event type: %d\n",event.type);
  543. X        break;
  544. X      }
  545. X    }
  546. X  }
  547. X  while (!(state & ExitState));
  548. X  /*
  549. X    Free X resources.
  550. X  */
  551. X  (void) free((char *) window->image.name);
  552. X  (void) free((char *) window->image.icon_name);
  553. X  if (resource_info->backdrop)
  554. X    XFreeCursor(display,window->backdrop.cursor);
  555. X  XFreeGC(display,pixel_info.graphic_context);
  556. X  XFreeGC(display,pixel_info.highlight_context);
  557. X  XFreeFont(display,font_info);
  558. X  /*
  559. X    Destroy X windows.
  560. X  */
  561. X  for (i=0; i < number_windows; i++)
  562. X  {
  563. X    if (magick_windows[i]->id != (Window) NULL)
  564. X      XDestroyWindow(display,magick_windows[i]->id);
  565. X    if (magick_windows[i]->ximage != (XImage *) NULL)
  566. X      XDestroyImage(magick_windows[i]->ximage);
  567. X    if (magick_windows[i]->pixmap != (Pixmap) NULL)
  568. X      XFreePixmap(display,magick_windows[i]->pixmap);
  569. X    XFreeCursor(display,magick_windows[i]->cursor);
  570. X    XFreeCursor(display,magick_windows[i]->busy_cursor);
  571. X  }
  572. X  for (scene=0; scene < number_scenes; scene++)
  573. X  {
  574. X    XFreePixmap(display,window->image.pixmaps[scene]);
  575. X    DestroyImage(images[scene]);
  576. X  }
  577. X  (void) free((char *) window->image.pixmaps);
  578. X  /*
  579. X    Free Standard Colormap.
  580. X  */
  581. X  if (resource_info->map_type == (char *) NULL)
  582. X    XFreeStandardColormap(display,visual_info,&pixel_info,map_info);
  583. X  (void) free((void *) window);
  584. X  XFree((void *) manager_hints);
  585. X  XFree((void *) class_hint);
  586. X  XFree((void *) visual_info);
  587. X  XFree((void *) map_info);
  588. X  visual_info=(XVisualInfo *) NULL;
  589. X  XFlush(display);
  590. }
  591. X
  592. /*
  593. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  594. %                                                                             %
  595. %                                                                             %
  596. %                                                                             %
  597. %    M a i n                                                                  %
  598. %                                                                             %
  599. %                                                                             %
  600. %                                                                             %
  601. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  602. %
  603. %
  604. */
  605. int main(argc,argv)
  606. int
  607. X  argc;
  608. X
  609. char
  610. X  **argv;
  611. {
  612. X  char
  613. X    *clip_geometry,
  614. X    *density,
  615. X    *option,
  616. X    *resource_value,
  617. X    *scale_geometry,
  618. X    *server_name;
  619. X
  620. X  Display
  621. X    *display;
  622. X
  623. X  double
  624. X    gamma;
  625. X
  626. X  Image
  627. X    **images;
  628. X
  629. X  int
  630. X    degrees,
  631. X    i,
  632. X    x;
  633. X
  634. X  unsigned int
  635. X    image_number,
  636. X    interlace,
  637. X    maximum_images,
  638. X    reflect,
  639. X    verbose;
  640. X
  641. X  XResourceInfo
  642. X    resource_info;
  643. X
  644. X  XrmDatabase
  645. X    resource_database,
  646. X    server_database;
  647. X
  648. X  /*
  649. X    Display usage profile if there are no command line arguments.
  650. X  */
  651. X  client_name=(*argv);
  652. X  if (argc < 2)
  653. X    Usage(True);
  654. X  /*
  655. X    Set defaults.
  656. X  */
  657. X  display=(Display *) NULL;
  658. X  server_name=(char *) NULL;
  659. X  maximum_images=2048;
  660. X  images=(Image **) malloc(maximum_images*sizeof(Image *));
  661. X  if (images == (Image **) NULL)
  662. X    Error("unable to animate images","memory allocation failed");
  663. X  /*
  664. X    Check for server name specified on the command line.
  665. X  */
  666. X  for (i=1; i < argc; i++)
  667. X  {
  668. X    /*
  669. X      Check command line for server name.
  670. X    */
  671. X    option=argv[i];
  672. X    if (((int) strlen(option) > 1) && ((*option == '-') || (*option == '+')))
  673. X      if (strncmp("display",option+1,3) == 0)
  674. X        {
  675. X          /*
  676. X            User specified server name.
  677. X          */
  678. X          if (*option == '-')
  679. X            {
  680. X              i++;
  681. X              if (i == argc)
  682. X                Error("missing server name on -display",(char *) NULL);
  683. X              server_name=argv[i];
  684. X              break;
  685. X            }
  686. X        }
  687. X  }
  688. X  /*
  689. X    Open X server connection.
  690. X  */
  691. X  display=XOpenDisplay(server_name);
  692. X  if (display == (Display *) NULL)
  693. X    Error("unable to connect to X server",XDisplayName(server_name));
  694. X  /*
  695. X    Set our forgiving error handler.
  696. X  */
  697. X  XSetErrorHandler(XError);
  698. X  /*
  699. X    Initialize resource database.
  700. X  */
  701. X  XrmInitialize();
  702. X  resource_database=XrmGetDatabase(display);
  703. X  resource_value=XResourceManagerString(display);
  704. X  if (resource_value == (char *) NULL)
  705. X    resource_value="";
  706. X  server_database=XrmGetStringDatabase(resource_value);
  707. X  XrmMergeDatabases(server_database,&resource_database);
  708. X  /*
  709. X    Get user defaults from X resource database.
  710. X  */
  711. X  XGetResourceInfo(resource_database,client_name,&resource_info);
  712. X  clip_geometry=
  713. X    XGetResource(resource_database,client_name,"clipGeometry",(char *) NULL);
  714. X  resource_value=XGetResource(resource_database,client_name,"delay","8");
  715. X  resource_info.delay=atoi(resource_value);
  716. X  density=XGetResource(resource_database,client_name,"density",(char *) NULL);
  717. X  resource_value=XGetResource(resource_database,client_name,"gamma","0.0");
  718. X  gamma=atof(resource_value);
  719. X  resource_value=
  720. X    XGetResource(resource_database,client_name,"interlace","none");
  721. X  interlace=UndefinedInterlace;
  722. X  if (Latin1Compare("none",resource_value) == 0)
  723. X    interlace=NoneInterlace;
  724. X  if (Latin1Compare("line",resource_value) == 0)
  725. X    interlace=LineInterlace;
  726. X  if (Latin1Compare("plane",resource_value) == 0)
  727. X    interlace=PlaneInterlace;
  728. X  if (interlace == UndefinedInterlace)
  729. X    Warning("unrecognized interlace type",resource_value);
  730. X  resource_value=XGetResource(resource_database,client_name,"reflect","False");
  731. X  reflect=IsTrue(resource_value);
  732. X  resource_value=XGetResource(resource_database,client_name,"rotate","0");
  733. X  degrees=atoi(resource_value);
  734. X  scale_geometry=
  735. X    XGetResource(resource_database,client_name,"scaleGeometry",(char *) NULL);
  736. X  resource_value=XGetResource(resource_database,client_name,"verbose","False");
  737. X  verbose=IsTrue(resource_value);
  738. X  /*
  739. X    Parse command line.
  740. X  */
  741. X  image_number=0;
  742. X  for (i=1; i < argc; i++)
  743. X  {
  744. X    option=argv[i];
  745. X    if (((int) strlen(option) > 1) && ((*option == '-') || (*option == '+')))
  746. X      switch (*(option+1))
  747. X      {
  748. X        case 'b':
  749. X        {
  750. X          if (strncmp("backdrop",option+1,5) == 0)
  751. X            {
  752. X              resource_info.backdrop=(*option == '-');
  753. X              break;
  754. X            }
  755. X          if (strncmp("background",option+1,5) == 0)
  756. X            {
  757. X              resource_info.background_color=(char *) NULL;
  758. X              if (*option == '-')
  759. X                {
  760. X                  i++;
  761. X                  if (i == argc)
  762. X                    Error("missing color on -background",(char *) NULL);
  763. X                  resource_info.background_color=argv[i];
  764. X                }
  765. X              break;
  766. X            }
  767. X          if (strncmp("bordercolor",option+1,7) == 0)
  768. X            {
  769. X              resource_info.border_color=(char *) NULL;
  770. X              if (*option == '-')
  771. X                {
  772. X                  i++;
  773. X                  if (i == argc)
  774. X                    Error("missing color on -bordercolor",(char *) NULL);
  775. X                  resource_info.border_color=argv[i];
  776. X                }
  777. X              break;
  778. X            }
  779. X          if (strncmp("borderwidth",option+1,7) == 0)
  780. X            {
  781. X              resource_info.border_width=0;
  782. X              if (*option == '-')
  783. X                {
  784. X                  i++;
  785. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  786. X                    Error("missing width on -borderwidth",(char *) NULL);
  787. X                  resource_info.border_width=atoi(argv[i]);
  788. X                }
  789. X              break;
  790. X            }
  791. X          Error("unrecognized option",option);
  792. X          break;
  793. X        }
  794. X        case 'c':
  795. X        {
  796. X          if (strncmp("clip",option+1,2) == 0)
  797. X            {
  798. X              clip_geometry=(char *) NULL;
  799. X              if (*option == '-')
  800. X                {
  801. X                  i++;
  802. X                  if (i == argc)
  803. X                    Error("missing geometry on -clip",(char *) NULL);
  804. X                  clip_geometry=argv[i];
  805. X                }
  806. X              break;
  807. X            }
  808. X          if (strncmp("colormap",option+1,6) == 0)
  809. X            {
  810. X              resource_info.colormap=PrivateColormap;
  811. X              if (*option == '-')
  812. X                {
  813. X                  i++;
  814. X                  if (i == argc)
  815. X                    Error("missing type on -colormap",(char *) NULL);
  816. X                  option=argv[i];
  817. X                  resource_info.colormap=UndefinedColormap;
  818. X                  if (Latin1Compare("private",option) == 0)
  819. X                    resource_info.colormap=PrivateColormap;
  820. X                  if (Latin1Compare("shared",option) == 0)
  821. X                    resource_info.colormap=SharedColormap;
  822. X                  if (resource_info.colormap == UndefinedColormap)
  823. X                    Error("invalid colormap type on -colormap",option);
  824. X                }
  825. X              break;
  826. X            }
  827. X          if (strncmp("colors",option+1,7) == 0)
  828. X            {
  829. X              resource_info.number_colors=0;
  830. X              if (*option == '-')
  831. X                {
  832. X                  i++;
  833. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  834. X                    Error("missing colors on -colors",(char *) NULL);
  835. X                  resource_info.number_colors=atoi(argv[i]);
  836. X                }
  837. X              break;
  838. X            }
  839. X          if (strncmp("colorspace",option+1,7) == 0)
  840. X            {
  841. X              resource_info.colorspace=RGBColorspace;
  842. X              if (*option == '-')
  843. X                {
  844. X                  i++;
  845. X                  if (i == argc)
  846. X                    Error("missing type on -colorspace",(char *) NULL);
  847. X                  option=argv[i];
  848. X                  resource_info.colorspace=UndefinedColorspace;
  849. X                  if (Latin1Compare("gray",option) == 0)
  850. X                    resource_info.colorspace=GRAYColorspace;
  851. X                  if (Latin1Compare("rgb",option) == 0)
  852. X                    resource_info.colorspace=RGBColorspace;
  853. X                  if (Latin1Compare("xyz",option) == 0)
  854. X                    resource_info.colorspace=XYZColorspace;
  855. X                  if (Latin1Compare("ycbcr",option) == 0)
  856. X                    resource_info.colorspace=YCbCrColorspace;
  857. X                  if (Latin1Compare("yiq",option) == 0)
  858. X                    resource_info.colorspace=YIQColorspace;
  859. X                  if (Latin1Compare("yuv",option) == 0)
  860. X                    resource_info.colorspace=YUVColorspace;
  861. X                  if (resource_info.colorspace == UndefinedColorspace)
  862. X                    Error("invalid colorspace type on -colorspace",option);
  863. X                }
  864. X              break;
  865. X            }
  866. X          Error("unrecognized option",option);
  867. X          break;
  868. X        }
  869. X        case 'd':
  870. X        {
  871. X          if (strncmp("debug",option+1,3) == 0)
  872. X            {
  873. X              resource_info.debug=(*option == '-');
  874. X              break;
  875. X            }
  876. X          if (strncmp("delay",option+1,3) == 0)
  877. X            {
  878. X              resource_info.delay=0;
  879. X              if (*option == '-')
  880. X                {
  881. X                  i++;
  882. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  883. X                    Error("missing seconds on -delay",(char *) NULL);
  884. X                  resource_info.delay=atoi(argv[i]);
  885. X                }
  886. X              break;
  887. X            }
  888. X          if (strncmp("density",option+1,3) == 0)
  889. X            {
  890. X              density=(char *) NULL;
  891. X              if (*option == '-')
  892. X                {
  893. X                  i++;
  894. X                  if (i == argc)
  895. X                    Error("missing geometry on -density",(char *) NULL);
  896. X                  density=argv[i];
  897. X                }
  898. X              break;
  899. X            }
  900. X          if (strncmp("display",option+1,3) == 0)
  901. X            {
  902. X              server_name=(char *) NULL;
  903. X              if (*option == '-')
  904. X                {
  905. X                  i++;
  906. X                  if (i == argc)
  907. X                    Error("missing server name on -display",(char *) NULL);
  908. X                  server_name=argv[i];
  909. X                }
  910. X              break;
  911. X            }
  912. X          if (strncmp("dither",option+1,3) == 0)
  913. X            {
  914. X              resource_info.dither=(*option == '-');
  915. X              break;
  916. X            }
  917. X          Error("unrecognized option",option);
  918. X          break;
  919. X        }
  920. X        case 'f':
  921. X        {
  922. X          if (strncmp("font",option+1,3) == 0)
  923. X            {
  924. X              resource_info.font=(char *) NULL;
  925. X              if (*option == '-')
  926. X                {
  927. X                  i++;
  928. X                  if (i == argc)
  929. X                    Error("missing font name on -font",(char *) NULL);
  930. X                  resource_info.font=argv[i];
  931. X                }
  932. X              break;
  933. X            }
  934. X          if (strncmp("foreground",option+1,3) == 0)
  935. X            {
  936. X              resource_info.foreground_color=(char *) NULL;
  937. X              if (*option == '-')
  938. X                {
  939. X                  i++;
  940. X                  if (i == argc)
  941. X                    Error("missing foreground on -foreground",(char *) NULL);
  942. X                  resource_info.foreground_color=argv[i];
  943. X                }
  944. X              break;
  945. X            }
  946. X          Error("unrecognized option",option);
  947. X          break;
  948. X        }
  949. X        case 'g':
  950. X        {
  951. X          if (strncmp("gamma",option+1,2) == 0)
  952. X            {
  953. X              gamma=0.0;
  954. X              if (*option == '-')
  955. X                {
  956. X                  i++;
  957. X                  if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  958. X                    Error("missing gamma on -gamma",(char *) NULL);
  959. X                  gamma=atof(argv[i]);
  960. X                }
  961. X              break;
  962. X            }
  963. X          if (strncmp("geometry",option+1,2) == 0)
  964. X            {
  965. X              resource_info.image_geometry=(char *) NULL;
  966. X              if (*option == '-')
  967. X                {
  968. X                  i++;
  969. X                  if (i == argc)
  970. X                    Error("missing geometry on -geometry",(char *) NULL);
  971. X                  resource_info.image_geometry=argv[i];
  972. X                }
  973. X              break;
  974. X            }
  975. X          Error("unrecognized option",option);
  976. X          break;
  977. X        }
  978. X        case 'h':
  979. X        {
  980. X          Usage(True);
  981. X          break;
  982. X        }
  983. X        case 'i':
  984. X        {
  985. X          if (strncmp("iconGeometry",option+1,5) == 0)
  986. X            {
  987. X              resource_info.icon_geometry=(char *) NULL;
  988. X              if (*option == '-')
  989. X                {
  990. X                  i++;
  991. X                  if (i == argc)
  992. X                    Error("missing geometry on -iconGeometry",(char *) NULL);
  993. X                  resource_info.icon_geometry=argv[i];
  994. X                }
  995. X              break;
  996. X            }
  997. X          if (strncmp("iconic",option+1,5) == 0)
  998. X            {
  999. X              resource_info.iconic=(*option == '-');
  1000. X              break;
  1001. X            }
  1002. X          if (strncmp("interlace",option+1,3) == 0)
  1003. X            {
  1004. X              if (*option == '-')
  1005. X                {
  1006. X                  i++;
  1007. X                  if (i == argc)
  1008. X                    Error("missing type on -interlace",(char *) NULL);
  1009. X                  option=argv[i];
  1010. X                  interlace=UndefinedInterlace;
  1011. X                  if (Latin1Compare("none",option) == 0)
  1012. X                    interlace=NoneInterlace;
  1013. X                  if (Latin1Compare("line",option) == 0)
  1014. X                    interlace=LineInterlace;
  1015. X                  if (Latin1Compare("plane",option) == 0)
  1016. X                    interlace=PlaneInterlace;
  1017. X                  if (interlace == UndefinedInterlace)
  1018. X                    Error("invalid interlace type on -interlace",option);
  1019. X                }
  1020. X              break;
  1021. X            }
  1022. X          Error("unrecognized option",option);
  1023. X          break;
  1024. X        }
  1025. X        case 'm':
  1026. X        {
  1027. X          if (strncmp("map",option+1,3) == 0)
  1028. X            {
  1029. X              resource_info.map_type=(char *) NULL;
  1030. X              if (*option == '-')
  1031. X                {
  1032. X                  i++;
  1033. X                  if (i == argc)
  1034. X                    Error("missing map type on -map",(char *) NULL);
  1035. X                  resource_info.map_type=argv[i];
  1036. X                }
  1037. X              break;
  1038. X            }
  1039. X          if (strncmp("monochrome",option+1,2) == 0)
  1040. X            {
  1041. X              resource_info.monochrome=(*option == '-');
  1042. X              break;
  1043. X            }
  1044. X          Error("unrecognized option",option);
  1045. X          break;
  1046. X        }
  1047. X        case 'n':
  1048. X        {
  1049. X          resource_info.name=(char *) NULL;
  1050. X          if (*option == '-')
  1051. X            {
  1052. X              i++;
  1053. X              if (i == argc)
  1054. X                Error("missing name on -name",(char *) NULL);
  1055. X              resource_info.name=argv[i];
  1056. X            }
  1057. X          break;
  1058. X        }
  1059. X        case 'r':
  1060. X        {
  1061. X          if (strncmp("reflect",option+1,2) == 0)
  1062. X            {
  1063. X              reflect=(*option == '-');
  1064. X              break;
  1065. X            }
  1066. X          if (strncmp("rotate",option+1,3) == 0)
  1067. X            {
  1068. X              degrees=0;
  1069. X              if (*option == '-')
  1070. X                {
  1071. X                  i++;
  1072. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1073. X                    Error("missing degrees on -rotate",(char *) NULL);
  1074. X                  degrees=atoi(argv[i]);
  1075. X                }
  1076. X              break;
  1077. X            }
  1078. X          Error("unrecognized option",option);
  1079. X          break;
  1080. X        }
  1081. X        case 's':
  1082. X        {
  1083. X          scale_geometry=(char *) NULL;
  1084. X          if (*option == '-')
  1085. X            {
  1086. X              i++;
  1087. X              if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  1088. X                Error("missing scale geometry on -scale",(char *) NULL);
  1089. X              scale_geometry=argv[i];
  1090. X            }
  1091. X          break;
  1092. X        }
  1093. X        case 't':
  1094. X        {
  1095. X          if (strncmp("title",option+1,2) == 0)
  1096. X            {
  1097. X              resource_info.title=(char *) NULL;
  1098. X              if (*option == '-')
  1099. X                {
  1100. X                  i++;
  1101. X                  if (i == argc)
  1102. X                    Error("missing title on -title",(char *) NULL);
  1103. X                  resource_info.title=argv[i];
  1104. X                }
  1105. X              break;
  1106. X            }
  1107. X          if (strncmp("treedepth",option+1,2) == 0)
  1108. X            {
  1109. X              resource_info.tree_depth=0;
  1110. X              if (*option == '-')
  1111. X                {
  1112. X                  i++;
  1113. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1114. X                    Error("missing depth on -treedepth",(char *) NULL);
  1115. X                  resource_info.tree_depth=atoi(argv[i]);
  1116. X                }
  1117. X              break;
  1118. X            }
  1119. X          Error("unrecognized option",option);
  1120. X          break;
  1121. X        }
  1122. X        case 'v':
  1123. X        {
  1124. X          if (strncmp("verbose",option+1,2) == 0)
  1125. X            {
  1126. X              verbose=(*option == '-');
  1127. X              break;
  1128. X            }
  1129. X          if (strncmp("visual",option+1,2) == 0)
  1130. X            {
  1131. X              resource_info.visual_type=(char *) NULL;
  1132. X              if (*option == '-')
  1133. X                {
  1134. X                  i++;
  1135. X                  if (i == argc)
  1136. X                    Error("missing visual class on -visual",(char *) NULL);
  1137. X                  resource_info.visual_type=argv[i];
  1138. X                }
  1139. X              break;
  1140. X            }
  1141. X          Error("unrecognized option",option);
  1142. X          break;
  1143. X        }
  1144. X        default:
  1145. X        {
  1146. X          Error("unrecognized option",option);
  1147. X          break;
  1148. X        }
  1149. X      }
  1150. X    else
  1151. X      {
  1152. X        double
  1153. X          normalized_maximum_error,
  1154. X          normalized_mean_error;
  1155. X
  1156. X        Image
  1157. X          *image,
  1158. X          info_image,
  1159. X          *next_image;
  1160. X
  1161. X        ImageInfo
  1162. X          image_info;
  1163. X
  1164. X        time_t
  1165. X          start_time;
  1166. X
  1167. X        unsigned int
  1168. X          mean_error_per_pixel;
  1169. X
  1170. X        unsigned long
  1171. X          total_colors;
  1172. X
  1173. X        /*
  1174. X          Option is a file name: begin by reading image from specified file.
  1175. X        */
  1176. X        start_time=time((time_t *) NULL);
  1177. X        GetImageInfo(&image_info);
  1178. X        (void) strcpy(image_info.filename,option);
  1179. X        image_info.server_name=resource_info.server_name;
  1180. X        image_info.font=resource_info.font;
  1181. X        image_info.geometry=resource_info.image_geometry;
  1182. X        image_info.density=density;
  1183. X        image_info.border_color=resource_info.border_color;
  1184. X        image_info.interlace=interlace;
  1185. X        image_info.monochrome=resource_info.monochrome;
  1186. X        image_info.verbose=verbose;
  1187. X        image=ReadImage(&image_info);
  1188. X        if (image == (Image *) NULL)
  1189. X          if (*option == '-')
  1190. X            break;
  1191. X          else
  1192. X            continue;
  1193. X        do
  1194. X        {
  1195. X          info_image=(*image);
  1196. X          total_colors=0;
  1197. X          /*
  1198. X            Transform image as defined by the clip, image and scale geometries.
  1199. X          */
  1200. X          TransformImage(&image,clip_geometry,resource_info.image_geometry,
  1201. X            scale_geometry);
  1202. X          if (reflect)
  1203. X            {
  1204. X              Image
  1205. X                *reflected_image;
  1206. X
  1207. X              /*
  1208. X                Reverse image scanlines.
  1209. X              */
  1210. X              reflected_image=ReflectImage(image);
  1211. X              if (reflected_image != (Image *) NULL)
  1212. X                {
  1213. X                  DestroyImage(image);
  1214. X                  image=reflected_image;
  1215. X                }
  1216. X            }
  1217. X          if ((degrees % 360) != 0)
  1218. X            {
  1219. X              Image
  1220. X                *rotated_image;
  1221. X
  1222. X              /*
  1223. X                Rotate image.
  1224. X              */
  1225. X              rotated_image=RotateImage(image,(double) degrees,False);
  1226. X              if (rotated_image != (Image *) NULL)
  1227. X                {
  1228. X                  DestroyImage(image);
  1229. X                  image=rotated_image;
  1230. X                }
  1231. X            }
  1232. X          if (gamma > 0.0)
  1233. X            GammaImage(image,gamma);
  1234. X          if (resource_info.colorspace == GRAYColorspace)
  1235. X            QuantizeImage(image,256,8,resource_info.dither,GRAYColorspace,True);
  1236. X          if (resource_info.monochrome)
  1237. X            QuantizeImage(image,2,8,resource_info.dither,GRAYColorspace,True);
  1238. X          if (resource_info.number_colors != 0)
  1239. X            if ((image->class == DirectClass) ||
  1240. X                (image->colors > resource_info.number_colors))
  1241. X              {
  1242. X                /*
  1243. X                  Reduce the number of colors in the image.
  1244. X                */
  1245. X                QuantizeImage(image,resource_info.number_colors,
  1246. X                  resource_info.tree_depth,resource_info.dither,
  1247. X                  resource_info.colorspace,True);
  1248. X                if (verbose)
  1249. X                  {
  1250. X                    /*
  1251. X                      Measure quantization error.
  1252. X                    */
  1253. X                    QuantizationError(image,&mean_error_per_pixel,
  1254. X                      &normalized_mean_error,&normalized_maximum_error);
  1255. X                    total_colors=NumberColors(image,(FILE *) NULL);
  1256. X                  }
  1257. X                SyncImage(image);
  1258. X              }
  1259. X          if (verbose)
  1260. X            {
  1261. X              /*
  1262. X                Display detailed info about the image.
  1263. X              */
  1264. X              (void) fprintf(stderr,"[%u] %s",
  1265. X                image->scene == 0 ? image_number : image->scene,
  1266. X                info_image.filename);
  1267. X              (void) fprintf(stderr," %ux%u",info_image.columns,
  1268. X                info_image.rows);
  1269. X              if ((info_image.columns != image->columns) ||
  1270. X                  (info_image.rows != image->rows))
  1271. X                (void) fprintf(stderr,"=>%ux%u",image->columns,image->rows);
  1272. X              if (image->class == DirectClass)
  1273. X                (void) fprintf(stderr," DirectClass");
  1274. X              else
  1275. X                if (total_colors == 0)
  1276. X                  (void) fprintf(stderr," PseudoClass %uc",image->colors);
  1277. X                else
  1278. X                  {
  1279. X                    (void) fprintf(stderr," PseudoClass %lu=>%uc",total_colors,
  1280. X                      image->colors);
  1281. X                    (void) fprintf(stderr," %u/%.6f/%.6fe",mean_error_per_pixel,
  1282. X                      normalized_mean_error,normalized_maximum_error);
  1283. X                  }
  1284. X              (void) fprintf(stderr," %s %lds\n",image->magick,
  1285. X                time((time_t *) NULL)-start_time+1);
  1286. X            }
  1287. X          /*
  1288. X            Pack image data to conserve memory (memory <=> speed).
  1289. X          */
  1290. X          image->alpha=False;
  1291. X          (void) RunlengthEncodeImage(image);
  1292. X          (void) free((char *) image->pixels);
  1293. X          image->pixels=(RunlengthPacket *) NULL;
  1294. X          if (image_number == maximum_images)
  1295. X            {
  1296. X              /*
  1297. X                Increase size of images array.
  1298. X              */
  1299. X              maximum_images<<=1;
  1300. X              images=(Image **)
  1301. X                realloc((char *) images,maximum_images*sizeof(Image *));
  1302. X              if (images == (Image **) NULL)
  1303. X                Error("unable to animate images","memory allocation failed");
  1304. X            }
  1305. X          images[image_number++]=image;
  1306. X          next_image=image->next;
  1307. X          if (next_image != (Image *) NULL)
  1308. X            image=next_image;
  1309. X        } while (next_image != (Image *) NULL);
  1310. X      }
  1311. X  }
  1312. X  if (image_number == 0)
  1313. X    Error("missing an image file name",(char *) NULL);
  1314. X  XAnimateImage(display,&resource_info,argv,argc,images,image_number);
  1315. X  (void) free((char *) images);
  1316. X  XCloseDisplay(display);
  1317. X  return(False);
  1318. }
  1319. SHAR_EOF
  1320. echo 'File ImageMagick/animate.c is complete' &&
  1321. chmod 0644 ImageMagick/animate.c ||
  1322. echo 'restore of ImageMagick/animate.c failed'
  1323. Wc_c="`wc -c < 'ImageMagick/animate.c'`"
  1324. test 73391 -eq "$Wc_c" ||
  1325.     echo 'ImageMagick/animate.c: original size 73391, current size' "$Wc_c"
  1326. rm -f _shar_wnt_.tmp
  1327. fi
  1328. # ============= ImageMagick/animate.h ==============
  1329. if test -f 'ImageMagick/animate.h' -a X"$1" != X"-c"; then
  1330.     echo 'x - skipping ImageMagick/animate.h (File already exists)'
  1331.     rm -f _shar_wnt_.tmp
  1332. else
  1333. > _shar_wnt_.tmp
  1334. echo 'x - extracting ImageMagick/animate.h (Text)'
  1335. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/animate.h' &&
  1336. /*
  1337. X  Define declarations.
  1338. */
  1339. #ifdef SYSV
  1340. #include <poll.h>
  1341. poll((struct poll *) 0, (size_t) 0, usec / 1000);
  1342. #define Delay(milliseconds)  \
  1343. X  poll((struct poll *) 0,(size_t) 0,milliseconds/1000);
  1344. #else
  1345. #ifdef vms
  1346. #define Delay(milliseconds)
  1347. #else
  1348. #define Delay(milliseconds)  \
  1349. {  \
  1350. X  struct timeval  \
  1351. X    timeout;  \
  1352. X  \
  1353. X  timeout.tv_usec=(milliseconds % 1000)*1000;  \
  1354. X  timeout.tv_sec=milliseconds/1000;  \
  1355. X  select(0,(void *) 0,(void *) 0,(void *) 0,&timeout);  \
  1356. }
  1357. #endif
  1358. #endif
  1359. SHAR_EOF
  1360. chmod 0644 ImageMagick/animate.h ||
  1361. echo 'restore of ImageMagick/animate.h failed'
  1362. Wc_c="`wc -c < 'ImageMagick/animate.h'`"
  1363. test 485 -eq "$Wc_c" ||
  1364.     echo 'ImageMagick/animate.h: original size 485, current size' "$Wc_c"
  1365. rm -f _shar_wnt_.tmp
  1366. fi
  1367. # ============= ImageMagick/animate.man ==============
  1368. if test -f 'ImageMagick/animate.man' -a X"$1" != X"-c"; then
  1369.     echo 'x - skipping ImageMagick/animate.man (File already exists)'
  1370.     rm -f _shar_wnt_.tmp
  1371. else
  1372. > _shar_wnt_.tmp
  1373. echo 'x - extracting ImageMagick/animate.man (Text)'
  1374. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/animate.man' &&
  1375. .ad l
  1376. .nh
  1377. .TH animate 1 "10 October 1992" "ImageMagick"
  1378. .SH NAME
  1379. animate - display a sequence of images on any workstation running X
  1380. .SH SYNOPSIS
  1381. .B "animate" [ \fIoptions\fP ...] \fIfile\fP
  1382. [ [ \fIoptions\fP ...] \fIfile\fP ...]
  1383. .SH DESCRIPTION
  1384. \fBanimate\fP displays a sequence of images on any workstation display
  1385. running an X server.  \fBanimate\fP first determines the hardware
  1386. capabilities of the workstation.  If the number of unique colors in an
  1387. image is less than or equal to the number the workstation can support,
  1388. the image is displayed in an X window.  Otherwise the number of colors
  1389. in the image is first reduced to match the color resolution of the
  1390. workstation before it is displayed.
  1391. .PP
  1392. This means that a continuous-tone 24 bits-per-pixel image can display on a
  1393. 8 bit pseudo-color device or monochrome device.  In most instances the
  1394. reduced color image closely resembles the original.  Alternatively, a
  1395. monochrome or pseudo-color image sequence can display on a continuous-tone
  1396. 24 bits-per-pixel device.
  1397. .PP
  1398. To help prevent color flashing on X server visuals that have colormaps,
  1399. \fBanimate\fP creates a single colormap from the image sequence.  This can
  1400. be rather time consuming.  You can speed this operation up by reducing
  1401. the colors in the image before you `animate' them.  Use \fBmogrify\fP
  1402. to color reduce the images to a single colormap.  See \fBmogrify(1)\fP for
  1403. details.  Alternatively, you can use a Standard Colormap; or a static, direct,
  1404. or true color visual.  You can define a Standard Colormap with
  1405. \fIxstdcmap\fP.  See \fBXSTDCMAP(1)\fP for details.
  1406. .SH EXAMPLES
  1407. To animate a set of images of a cockatoo, use:
  1408. .PP
  1409. .B
  1410. X     animate cockatoo.*
  1411. .PP
  1412. To animate a cockatoo image sequence while using the Standard Colormap
  1413. "best", use:
  1414. .PP
  1415. .B
  1416. X     xstdcmap -best
  1417. .B
  1418. X     animate -map best cockatoo.*
  1419. .PP
  1420. To animate an image of a cockatoo without a border centered on a
  1421. backdrop, use:
  1422. .PP
  1423. .B
  1424. X     animate +borderwidth -backdrop cockatoo.*
  1425. .SH OPTIONS
  1426. .TP 5
  1427. .B "-backdrop"
  1428. display the image centered on a backdrop.
  1429. X
  1430. This backdrop covers the entire workstation screen and is useful for
  1431. hiding other X window activity while viewing the image sequence.   The color
  1432. of the backdrop is specified as the background color.  Refer to \fBX
  1433. RESOURCES\fP for details.
  1434. .TP 5
  1435. .B "-clip \fI<width>x<height>{\+-}<x offset>{\+-}<y offset>\fP"
  1436. preferred size and location of the clipped image.  See \fBX(1)\fP for details
  1437. about the geometry specification.
  1438. X
  1439. Use clipping to apply image processing options, or display, only a
  1440. particular area of an image.
  1441. X
  1442. The equivalent X resource for this option is \fBclipGeometry\fP
  1443. (class \fBClipGeometry\fP).  See \fBX RESOURCES\fP for details.
  1444. .TP 5
  1445. .B "-colormap \fItype\fP"
  1446. the type of colormap: \fBShared\fP or \fBPrivate\fP.
  1447. X
  1448. This option only applies when the default X server visual is
  1449. \fIPseudoColor\fP or \fIGrayScale\fP.  Refer to \fB-visual\fP for more
  1450. details.  By default, a shared colormap is allocated.  The image shares
  1451. colors with other X clients.  Some image colors could be approximated,
  1452. therefore your image may look very different than intended.  Choose
  1453. \fBPrivate\fP and the image colors appear exactly as they are
  1454. defined.  However, other clients may go "technicolor" when the image
  1455. colormap is installed.
  1456. .TP 5
  1457. .B "-colors \fIvalue\fP"
  1458. preferred number of colors in the image.
  1459. X
  1460. The actual number of colors in the image may be less than your request,
  1461. but never more.  Note, this is a color reduction option.  Images with
  1462. less unique colors than specified with this option will remain unchanged.
  1463. Refer to \fBquantize(9)\fP for more details.
  1464. X
  1465. Note, options \fB-dither\fP, \fB-colorspace\fP, and \fB-treedepth\fP affect
  1466. the color reduction algorithm.
  1467. .TP 5
  1468. .B "-colorspace \fIvalue\fP"
  1469. the type of colorspace: \fBGRAY\fP, \fBRGB\fP, \fBXYZ\fP, \fBYCbCr\fP,
  1470. \fBYIQ\fP, or \fBYUV\fP.
  1471. Color reduction, by default, takes place in the RGB color space.
  1472. Empirical evidence suggests that distances in color spaces such as YUV
  1473. or YIQ correspond to perceptual color differences more closely
  1474. than do distances in RGB space.  These color spaces may give better
  1475. results when color reducing an image.  Refer to \fBquantize(9)\fP for
  1476. more details.
  1477. X
  1478. The \fB-colors\fP or \fB-monochrome\fP option is required for this option
  1479. to take effect.
  1480. .TP 5
  1481. .B "-delay \fImilliseconds\fP"
  1482. display the next image after pausing.
  1483. X
  1484. This option is useful for regulating the display of the sequence of
  1485. images.  \fImilliseconds\fP milliseconds must expire before the display of
  1486. SHAR_EOF
  1487. true || echo 'restore of ImageMagick/animate.man failed'
  1488. fi
  1489. echo 'End of ImageMagick part 19'
  1490. echo 'File ImageMagick/animate.man is continued in part 20'
  1491. echo 20 > _shar_seq_.tmp
  1492. exit 0
  1493.  
  1494. exit 0 # Just in case...
  1495. -- 
  1496.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  1497. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  1498.  "It's intuitively obvious to the |
  1499.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  1500.