home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sources / misc / 4187 < prev    next >
Encoding:
Text File  |  1992-12-14  |  57.3 KB  |  1,648 lines

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: cristy@eplrx7.es.duPont.com (John Cristy)
  4. Subject:  v34i047:  imagemagick - X11 image processing and display v2.2, Part19/26
  5. Message-ID: <1992Dec15.035656.22715@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: 3cb5459905553228c1861db89866fa68
  8. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  9. Organization: Sterling Software
  10. References: <csm-v34i028=imagemagick.141926@sparky.IMD.Sterling.COM>
  11. Date: Tue, 15 Dec 1992 03:56:56 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 1633
  14.  
  15. Submitted-by: cristy@eplrx7.es.duPont.com (John Cristy)
  16. Posting-number: Volume 34, Issue 47
  17. Archive-name: imagemagick/part19
  18. Environment: UNIX, VMS, X11, SGI, DEC, Cray, Sun, Vax
  19.  
  20. #!/bin/sh
  21. # this is Part.19 (part 19 of a multipart archive)
  22. # do not concatenate these parts, unpack them in order with /bin/sh
  23. # file ImageMagick/animate.c continued
  24. #
  25. if test ! -r _shar_seq_.tmp; then
  26.     echo 'Please unpack part 1 first!'
  27.     exit 1
  28. fi
  29. (read Scheck
  30.  if test "$Scheck" != 19; then
  31.     echo Please unpack part "$Scheck" next!
  32.     exit 1
  33.  else
  34.     exit 0
  35.  fi
  36. ) < _shar_seq_.tmp || exit 1
  37. if test ! -f _shar_wnt_.tmp; then
  38.     echo 'x - still skipping ImageMagick/animate.c'
  39. else
  40. echo 'x - continuing file ImageMagick/animate.c'
  41. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/animate.c' &&
  42. X            XSetWindowBackgroundPixmap(display,window->icon.id,
  43. X              window->icon.pixmap);
  44. X            XClearWindow(display,window->icon.id);
  45. X            break;
  46. X          }
  47. X        break;
  48. X      }
  49. X      case MappingNotify:
  50. X      {
  51. X        XRefreshKeyboardMapping(&event.xmapping);
  52. X        break;
  53. X      }
  54. X      case ReparentNotify:
  55. X      {
  56. X        if (resource_info->debug)
  57. X          (void) fprintf(stderr,"Reparent Notify: 0x%lx=>0x%lx\n",
  58. X            event.xreparent.parent,event.xreparent.window);
  59. X        break;
  60. X      }
  61. X      case UnmapNotify:
  62. X      {
  63. X        if (resource_info->debug)
  64. X          (void) fprintf(stderr,"Unmap Notify: 0x%lx\n",event.xunmap.window);
  65. X        if (event.xunmap.window == window->info.id)
  66. X          {
  67. X            state&=(~InfoMappedState);
  68. X            break;
  69. X          }
  70. X        break;
  71. X      }
  72. X      default:
  73. X      {
  74. X        if (resource_info->debug)
  75. X          (void) fprintf(stderr,"Event type: %d\n",event.type);
  76. X        break;
  77. X      }
  78. X    }
  79. X  }
  80. X  while (!(state & ExitState));
  81. X  /*
  82. X    Free X resources.
  83. X  */
  84. X  (void) free((char *) window->image.name);
  85. X  (void) free((char *) window->image.icon_name);
  86. X  if (resource_info->backdrop)
  87. X    XFreeCursor(display,window->backdrop.cursor);
  88. X  XFreeGC(display,window->superclass.graphic_context);
  89. X  XFreeGC(display,window->superclass.highlight_context);
  90. X  XFreeFont(display,font_info);
  91. X  /*
  92. X    Destroy X windows.
  93. X  */
  94. X  for (i=0; i < number_windows; i++)
  95. X  {
  96. X    if (magick_windows[i]->id != (Window) NULL)
  97. X      XDestroyWindow(display,magick_windows[i]->id);
  98. X    if (magick_windows[i]->ximage != (XImage *) NULL)
  99. X      XDestroyImage(magick_windows[i]->ximage);
  100. X    if (magick_windows[i]->pixmap != (Pixmap) NULL)
  101. X      XFreePixmap(display,magick_windows[i]->pixmap);
  102. X  }
  103. X  for (scene=0; scene < number_scenes; scene++)
  104. X  {
  105. X    XFreePixmap(display,window->image.pixmaps[scene]);
  106. X    DestroyImage(images[scene]);
  107. X  }
  108. X  (void) free((char *) window->image.pixmaps);
  109. X  /*
  110. X    Free Standard Colormap.
  111. X  */
  112. X  if (resource_info->map_type == (char *) NULL)
  113. X    XFreeStandardColormap(display,visual_info,&pixel_info,map_info);
  114. X  XFreeCursor(display,arrow_cursor);
  115. X  XFreeCursor(display,watch_cursor);
  116. X  (void) free((void *) window);
  117. X  XFree((void *) manager_hints);
  118. X  XFree((void *) class_hint);
  119. X  XFree((void *) visual_info);
  120. X  XFree((void *) map_info);
  121. X  visual_info=(XVisualInfo *) NULL;
  122. X  XFlush(display);
  123. }
  124. X
  125. /*
  126. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  127. %                                                                             %
  128. %                                                                             %
  129. %                                                                             %
  130. %    M a i n                                                                  %
  131. %                                                                             %
  132. %                                                                             %
  133. %                                                                             %
  134. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  135. %
  136. %
  137. */
  138. int main(argc,argv)
  139. int
  140. X  argc;
  141. X
  142. char
  143. X  **argv;
  144. {
  145. X  AlienInfo
  146. X    alien_info;
  147. X
  148. X  char
  149. X    *clip_geometry,
  150. X    *option,
  151. X    *resource_value,
  152. X    *scale_geometry,
  153. X    *server_name;
  154. X
  155. X  Display
  156. X    *display;
  157. X
  158. X  double
  159. X    gamma;
  160. X
  161. X  Image
  162. X    **images;
  163. X
  164. X  int
  165. X    degrees,
  166. X    i,
  167. X    x;
  168. X
  169. X  unsigned int
  170. X    image_number,
  171. X    maximum_images,
  172. X    reflect,
  173. X    verbose;
  174. X
  175. X  XResourceInfo
  176. X    resource_info;
  177. X
  178. X  XrmDatabase
  179. X    resource_database,
  180. X    server_database;
  181. X
  182. X  /*
  183. X    Display usage profile if there are no command line arguments.
  184. X  */
  185. X  application_name=(*argv);
  186. X  if (argc < 2)
  187. X    Usage(True);
  188. X  /*
  189. X    Set defaults.
  190. X  */
  191. X  GetAlienInfo(&alien_info);
  192. X  clip_geometry=(char *) NULL;
  193. X  degrees=0;
  194. X  display=(Display *) NULL;
  195. X  gamma=0.0;
  196. X  reflect=False;
  197. X  scale_geometry=(char *) NULL;
  198. X  server_name=(char *) NULL;
  199. X  verbose=False;
  200. X  maximum_images=2048;
  201. X  images=(Image **) malloc(maximum_images*sizeof(Image *));
  202. X  if (images == (Image **) NULL)
  203. X    Error("unable to animate images","memory allocation failed");
  204. X  /*
  205. X    Check for server name specified on the command line.
  206. X  */
  207. X  for (i=1; i < argc; i++)
  208. X  {
  209. X    /*
  210. X      Check command line for server name.
  211. X    */
  212. X    option=argv[i];
  213. X    if (((int) strlen(option) > 1) && ((*option == '-') || (*option == '+')))
  214. X      if (strncmp("display",option+1,3) == 0)
  215. X        {
  216. X          /*
  217. X            User specified server name.
  218. X          */
  219. X          if (*option == '-')
  220. X            {
  221. X              i++;
  222. X              if (i == argc)
  223. X                Error("missing server name on -display",(char *) NULL);
  224. X              server_name=argv[i];
  225. X              break;
  226. X            }
  227. X        }
  228. X  }
  229. X  /*
  230. X    Open X server connection.
  231. X  */
  232. X  display=XOpenDisplay(server_name);
  233. X  if (display == (Display *) NULL)
  234. X    Error("unable to connect to X server",XDisplayName(server_name));
  235. X  /*
  236. X    Set our forgiving error handler.
  237. X  */
  238. X  XSetErrorHandler(XError);
  239. X  /*
  240. X    Initialize resource database.
  241. X  */
  242. X  XrmInitialize();
  243. X  resource_database=XrmGetDatabase(display);
  244. X  resource_value=XResourceManagerString(display);
  245. X  if (resource_value == (char *) NULL)
  246. X    resource_value="";
  247. X  server_database=XrmGetStringDatabase(resource_value);
  248. X  XrmMergeDatabases(server_database,&resource_database);
  249. X  /*
  250. X    Get user defaults from X resource database.
  251. X  */
  252. X  XGetResourceInfo(resource_database,application_name,&resource_info);
  253. X  clip_geometry=XGetResource(resource_database,application_name,"clipGeometry",
  254. X    "ClipGeometry",(char *) NULL);
  255. X  resource_value=XGetResource(resource_database,application_name,"gamma",
  256. X    (char *) NULL,"0.0");
  257. X  gamma=atof(resource_value);
  258. X  resource_value=XGetResource(resource_database,application_name,"reflect",
  259. X    (char *) NULL,"False");
  260. X  reflect=IsTrue(resource_value);
  261. X  resource_value=XGetResource(resource_database,application_name,"rotate",
  262. X    (char *) NULL,"0");
  263. X  degrees=atoi(resource_value);
  264. X  scale_geometry=XGetResource(resource_database,application_name,
  265. X    "scaleGeometry","ScaleGeometry",(char *) NULL);
  266. X  resource_value=XGetResource(resource_database,application_name,"verbose",
  267. X    (char *) NULL,"False");
  268. X  verbose=IsTrue(resource_value);
  269. X  /*
  270. X    Parse command line.
  271. X  */
  272. X  image_number=0;
  273. X  for (i=1; i < argc; i++)
  274. X  {
  275. X    option=argv[i];
  276. X    if (((int) strlen(option) > 1) && ((*option == '-') || (*option == '+')))
  277. X      switch (*(option+1))
  278. X      {
  279. X        case 'b':
  280. X        {
  281. X          if (strncmp("backdrop",option+1,5) == 0)
  282. X            {
  283. X              resource_info.backdrop=(*option == '-');
  284. X              break;
  285. X            }
  286. X          if (strncmp("background",option+1,5) == 0)
  287. X            {
  288. X              resource_info.background_color=(char *) NULL;
  289. X              if (*option == '-')
  290. X                {
  291. X                  i++;
  292. X                  if (i == argc)
  293. X                    Error("missing color on -background",(char *) NULL);
  294. X                  resource_info.background_color=argv[i];
  295. X                }
  296. X              break;
  297. X            }
  298. X          if (strncmp("bordercolor",option+1,7) == 0)
  299. X            {
  300. X              resource_info.border_color=(char *) NULL;
  301. X              if (*option == '-')
  302. X                {
  303. X                  i++;
  304. X                  if (i == argc)
  305. X                    Error("missing color on -bordercolor",(char *) NULL);
  306. X                  resource_info.border_color=argv[i];
  307. X                }
  308. X              break;
  309. X            }
  310. X          if (strncmp("borderwidth",option+1,7) == 0)
  311. X            {
  312. X              resource_info.border_width=0;
  313. X              if (*option == '-')
  314. X                {
  315. X                  i++;
  316. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  317. X                    Error("missing width on -borderwidth",(char *) NULL);
  318. X                  resource_info.border_width=atoi(argv[i]);
  319. X                }
  320. X              break;
  321. X            }
  322. X          Error("unrecognized option",option);
  323. X          break;
  324. X        }
  325. X        case 'c':
  326. X        {
  327. X          if (strncmp("clip",option+1,2) == 0)
  328. X            {
  329. X              clip_geometry=(char *) NULL;
  330. X              if (*option == '-')
  331. X                {
  332. X                  i++;
  333. X                  if (i == argc)
  334. X                    Error("missing geometry on -clip",(char *) NULL);
  335. X                  clip_geometry=argv[i];
  336. X                }
  337. X              break;
  338. X            }
  339. X          if (strncmp("colormap",option+1,6) == 0)
  340. X            {
  341. X              resource_info.colormap=PrivateColormap;
  342. X              if (*option == '-')
  343. X                {
  344. X                  i++;
  345. X                  if (i == argc)
  346. X                    Error("missing type on -colormap",(char *) NULL);
  347. X                  option=argv[i];
  348. X                  resource_info.colormap=UndefinedColormap;
  349. X                  if (Latin1Compare("private",option) == 0)
  350. X                    resource_info.colormap=PrivateColormap;
  351. X                  if (Latin1Compare("shared",option) == 0)
  352. X                    resource_info.colormap=SharedColormap;
  353. X                  if (resource_info.colormap == UndefinedColormap)
  354. X                    Error("invalid colormap type on -colormap",option);
  355. X                }
  356. X              break;
  357. X            }
  358. X          if (strncmp("colors",option+1,7) == 0)
  359. X            {
  360. X              resource_info.number_colors=0;
  361. X              if (*option == '-')
  362. X                {
  363. X                  i++;
  364. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  365. X                    Error("missing colors on -colors",(char *) NULL);
  366. X                  resource_info.number_colors=atoi(argv[i]);
  367. X                }
  368. X              break;
  369. X            }
  370. X          if (strncmp("colorspace",option+1,7) == 0)
  371. X            {
  372. X              resource_info.colorspace=RGBColorspace;
  373. X              if (*option == '-')
  374. X                {
  375. X                  i++;
  376. X                  if (i == argc)
  377. X                    Error("missing type on -colorspace",(char *) NULL);
  378. X                  option=argv[i];
  379. X                  resource_info.colorspace=UndefinedColorspace;
  380. X                  if (Latin1Compare("gray",option) == 0)
  381. X                    resource_info.colorspace=GRAYColorspace;
  382. X                  if (Latin1Compare("rgb",option) == 0)
  383. X                    resource_info.colorspace=RGBColorspace;
  384. X                  if (Latin1Compare("yiq",option) == 0)
  385. X                    resource_info.colorspace=YIQColorspace;
  386. X                  if (Latin1Compare("yuv",option) == 0)
  387. X                    resource_info.colorspace=YUVColorspace;
  388. X                  if (Latin1Compare("xyz",option) == 0)
  389. X                    resource_info.colorspace=XYZColorspace;
  390. X                  if (resource_info.colorspace == UndefinedColorspace)
  391. X                    Error("invalid colorspace type on -colorspace",option);
  392. X                }
  393. X              break;
  394. X            }
  395. X          Error("unrecognized option",option);
  396. X          break;
  397. X        }
  398. X        case 'd':
  399. X        {
  400. X          if (strncmp("debug",option+1,3) == 0)
  401. X            {
  402. X              resource_info.debug=(*option == '-');
  403. X              break;
  404. X            }
  405. X          if (strncmp("delay",option+1,3) == 0)
  406. X            {
  407. X              resource_info.delay=0;
  408. X              if (*option == '-')
  409. X                {
  410. X                  i++;
  411. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  412. X                    Error("missing seconds on -delay",(char *) NULL);
  413. X                  resource_info.delay=atoi(argv[i]);
  414. X                }
  415. X              break;
  416. X            }
  417. X          if (strncmp("density",option+1,3) == 0)
  418. X            {
  419. X              alien_info.density=(char *) NULL;
  420. X              if (*option == '-')
  421. X                {
  422. X                  i++;
  423. X                  if (i == argc)
  424. X                    Error("missing density on -density",(char *) NULL);
  425. X                  alien_info.density=argv[i];
  426. X                }
  427. X              break;
  428. X            }
  429. X          if (strncmp("display",option+1,3) == 0)
  430. X            {
  431. X              server_name=(char *) NULL;
  432. X              if (*option == '-')
  433. X                {
  434. X                  i++;
  435. X                  if (i == argc)
  436. X                    Error("missing server name on -display",(char *) NULL);
  437. X                  server_name=argv[i];
  438. X                }
  439. X              alien_info.server_name=server_name;
  440. X              break;
  441. X            }
  442. X          if (strncmp("dither",option+1,3) == 0)
  443. X            {
  444. X              resource_info.dither=(*option == '-');
  445. X              break;
  446. X            }
  447. X          Error("unrecognized option",option);
  448. X          break;
  449. X        }
  450. X        case 'f':
  451. X        {
  452. X          if (strncmp("font",option+1,3) == 0)
  453. X            {
  454. X              resource_info.font=(char *) NULL;
  455. X              if (*option == '-')
  456. X                {
  457. X                  i++;
  458. X                  if (i == argc)
  459. X                    Error("missing font name on -font",(char *) NULL);
  460. X                  resource_info.font=argv[i];
  461. X                }
  462. X              alien_info.font=resource_info.font;
  463. X              break;
  464. X            }
  465. X          if (strncmp("foreground",option+1,3) == 0)
  466. X            {
  467. X              resource_info.foreground_color=(char *) NULL;
  468. X              if (*option == '-')
  469. X                {
  470. X                  i++;
  471. X                  if (i == argc)
  472. X                    Error("missing foreground on -foreground",(char *) NULL);
  473. X                  resource_info.foreground_color=argv[i];
  474. X                }
  475. X              break;
  476. X            }
  477. X          Error("unrecognized option",option);
  478. X          break;
  479. X        }
  480. X        case 'g':
  481. X        {
  482. X          if (strncmp("gamma",option+1,2) == 0)
  483. X            {
  484. X              gamma=0.0;
  485. X              if (*option == '-')
  486. X                {
  487. X                  i++;
  488. X                  if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  489. X                    Error("missing gamma on -gamma",(char *) NULL);
  490. X                  gamma=atof(argv[i]);
  491. X                }
  492. X              break;
  493. X            }
  494. X          if (strncmp("geometry",option+1,2) == 0)
  495. X            {
  496. X              resource_info.image_geometry=(char *) NULL;
  497. X              if (*option == '-')
  498. X                {
  499. X                  i++;
  500. X                  if (i == argc)
  501. X                    Error("missing geometry on -geometry",(char *) NULL);
  502. X                  resource_info.image_geometry=argv[i];
  503. X                }
  504. X              alien_info.geometry=resource_info.image_geometry;
  505. X              break;
  506. X            }
  507. X          Error("unrecognized option",option);
  508. X          break;
  509. X        }
  510. X        case 'h':
  511. X        {
  512. X          Usage(True);
  513. X          break;
  514. X        }
  515. X        case 'i':
  516. X        {
  517. X          if (strncmp("iconGeometry",option+1,5) == 0)
  518. X            {
  519. X              resource_info.icon_geometry=(char *) NULL;
  520. X              if (*option == '-')
  521. X                {
  522. X                  i++;
  523. X                  if (i == argc)
  524. X                    Error("missing geometry on -iconGeometry",(char *) NULL);
  525. X                  resource_info.icon_geometry=argv[i];
  526. X                }
  527. X              break;
  528. X            }
  529. X          if (strncmp("iconic",option+1,5) == 0)
  530. X            {
  531. X              resource_info.iconic=(*option == '-');
  532. X              break;
  533. X            }
  534. X          Error("unrecognized option",option);
  535. X          break;
  536. X        }
  537. X        case 'm':
  538. X        {
  539. X          if (strncmp("map",option+1,3) == 0)
  540. X            {
  541. X              resource_info.map_type=(char *) NULL;
  542. X              if (*option == '-')
  543. X                {
  544. X                  i++;
  545. X                  if (i == argc)
  546. X                    Error("missing map type on -map",(char *) NULL);
  547. X                  resource_info.map_type=argv[i];
  548. X                }
  549. X              break;
  550. X            }
  551. X          if (strncmp("monochrome",option+1,2) == 0)
  552. X            {
  553. X              resource_info.monochrome=(*option == '-');
  554. X              break;
  555. X            }
  556. X          Error("unrecognized option",option);
  557. X          break;
  558. X        }
  559. X        case 'n':
  560. X        {
  561. X          resource_info.name=(char *) NULL;
  562. X          if (*option == '-')
  563. X            {
  564. X              i++;
  565. X              if (i == argc)
  566. X                Error("missing name on -name",(char *) NULL);
  567. X              resource_info.name=argv[i];
  568. X            }
  569. X          break;
  570. X        }
  571. X        case 'r':
  572. X        {
  573. X          if (strncmp("reflect",option+1,2) == 0)
  574. X            {
  575. X              reflect=(*option == '-');
  576. X              break;
  577. X            }
  578. X          if (strncmp("rotate",option+1,3) == 0)
  579. X            {
  580. X              degrees=0;
  581. X              if (*option == '-')
  582. X                {
  583. X                  i++;
  584. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  585. X                    Error("missing degrees on -rotate",(char *) NULL);
  586. X                  degrees=atoi(argv[i]);
  587. X                }
  588. X              break;
  589. X            }
  590. X          Error("unrecognized option",option);
  591. X          break;
  592. X        }
  593. X        case 's':
  594. X        {
  595. X          scale_geometry=(char *) NULL;
  596. X          if (*option == '-')
  597. X            {
  598. X              i++;
  599. X              if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  600. X                Error("missing scale geometry on -scale",(char *) NULL);
  601. X              scale_geometry=argv[i];
  602. X            }
  603. X          break;
  604. X        }
  605. X        case 't':
  606. X        {
  607. X          if (strncmp("title",option+1,2) == 0)
  608. X            {
  609. X              resource_info.title=(char *) NULL;
  610. X              if (*option == '-')
  611. X                {
  612. X                  i++;
  613. X                  if (i == argc)
  614. X                    Error("missing title on -title",(char *) NULL);
  615. X                  resource_info.title=argv[i];
  616. X                }
  617. X              break;
  618. X            }
  619. X          if (strncmp("treedepth",option+1,2) == 0)
  620. X            {
  621. X              resource_info.tree_depth=0;
  622. X              if (*option == '-')
  623. X                {
  624. X                  i++;
  625. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  626. X                    Error("missing depth on -treedepth",(char *) NULL);
  627. X                  resource_info.tree_depth=atoi(argv[i]);
  628. X                }
  629. X              break;
  630. X            }
  631. X          Error("unrecognized option",option);
  632. X          break;
  633. X        }
  634. X        case 'v':
  635. X        {
  636. X          if (strncmp("verbose",option+1,2) == 0)
  637. X            {
  638. X              verbose=(*option == '-');
  639. X              alien_info.verbose=verbose;
  640. X              break;
  641. X            }
  642. X          if (strncmp("visual",option+1,2) == 0)
  643. X            {
  644. X              resource_info.visual_type=(char *) NULL;
  645. X              if (*option == '-')
  646. X                {
  647. X                  i++;
  648. X                  if (i == argc)
  649. X                    Error("missing visual class on -visual",(char *) NULL);
  650. X                  resource_info.visual_type=argv[i];
  651. X                }
  652. X              break;
  653. X            }
  654. X          Error("unrecognized option",option);
  655. X          break;
  656. X        }
  657. X        default:
  658. X        {
  659. X          Error("unrecognized option",option);
  660. X          break;
  661. X        }
  662. X      }
  663. X    else
  664. X      {
  665. X        Image
  666. X          *image,
  667. X          info_image,
  668. X          *next_image;
  669. X
  670. X        time_t
  671. X          start_time;
  672. X
  673. X        unsigned long
  674. X          total_colors;
  675. X
  676. X        /*
  677. X          Option is a file name: begin by reading image from specified file.
  678. X        */
  679. X        start_time=time((time_t *) 0);
  680. X        (void) strcpy(alien_info.filename,option);
  681. X        image=ReadAlienImage(&alien_info);
  682. X        if (image == (Image *) NULL)
  683. X          if (*option == '-')
  684. X            break;
  685. X          else
  686. X            continue;
  687. X        do
  688. X        {
  689. X          info_image=(*image);
  690. X          /*
  691. X            Transform image as defined by the clip, image and scale geometries.
  692. X          */
  693. X          TransformImage(&image,clip_geometry,resource_info.image_geometry,
  694. X            scale_geometry);
  695. X          if (reflect)
  696. X            {
  697. X              Image
  698. X                *reflected_image;
  699. X
  700. X              /*
  701. X                Reverse image scanlines.
  702. X              */
  703. X              reflected_image=ReflectImage(image);
  704. X              if (reflected_image != (Image *) NULL)
  705. X                {
  706. X                  DestroyImage(image);
  707. X                  image=reflected_image;
  708. X                }
  709. X            }
  710. X          if ((degrees % 360) != 0)
  711. X            {
  712. X              Image
  713. X                *rotated_image;
  714. X
  715. X              /*
  716. X                Rotate image.
  717. X              */
  718. X              rotated_image=RotateImage(image,(double) degrees,False);
  719. X              if (rotated_image != (Image *) NULL)
  720. X                {
  721. X                  DestroyImage(image);
  722. X                  image=rotated_image;
  723. X                }
  724. X            }
  725. X          if (gamma > 0.0)
  726. X            GammaImage(image,gamma);
  727. X          if (verbose)
  728. X            {
  729. X              /*
  730. X                Initialize image error attributes.
  731. X              */
  732. X              if (image->class == DirectClass)
  733. X                image->colors=NumberColors(image);
  734. X              total_colors=image->colors;
  735. X            }
  736. X          if (resource_info.colorspace == GRAYColorspace)
  737. X            QuantizeImage(image,256,8,resource_info.dither,GRAYColorspace,True);
  738. X          if (resource_info.monochrome)
  739. X            QuantizeImage(image,2,8,resource_info.dither,GRAYColorspace,True);
  740. X          if (resource_info.number_colors > 0)
  741. X            if ((image->class == DirectClass) ||
  742. X                (image->colors > resource_info.number_colors))
  743. X              QuantizeImage(image,resource_info.number_colors,
  744. X                resource_info.tree_depth,resource_info.dither,
  745. X                resource_info.colorspace,True);
  746. X          if (verbose)
  747. X            {
  748. X              /*
  749. X                Display detailed info about the image.
  750. X              */
  751. X              (void) fprintf(stderr,"[%u] %s",
  752. X                image->scene == 0 ? image_number : image->scene,
  753. X                info_image.filename);
  754. X              (void) fprintf(stderr," %ux%u",info_image.columns,
  755. X                info_image.rows);
  756. X              if ((info_image.columns != image->columns) ||
  757. X                  (info_image.rows != image->rows))
  758. X                (void) fprintf(stderr,"=>%ux%u",image->columns,image->rows);
  759. X              if (image->class == DirectClass)
  760. X                (void) fprintf(stderr," DirectClass ");
  761. X              else
  762. X                (void) fprintf(stderr," PseudoClass ");
  763. X              if (total_colors != image->colors)
  764. X                (void) fprintf(stderr,"%lu=>",total_colors);
  765. X              (void) fprintf(stderr,"%uc",image->colors);
  766. X              if ((resource_info.number_colors > 0) || resource_info.monochrome)
  767. X                {
  768. X                  double
  769. X                    normalized_maximum_error,
  770. X                    normalized_mean_error;
  771. X
  772. X                  unsigned int
  773. X                    mean_error_per_pixel;
  774. X
  775. X                  /*
  776. X                    Measure quantization error.
  777. X                  */
  778. X                  QuantizationError(image,&mean_error_per_pixel,
  779. X                    &normalized_mean_error,&normalized_maximum_error);
  780. X                  (void) fprintf(stderr," %u/%.6f/%.6fe",mean_error_per_pixel,
  781. X                    normalized_mean_error,normalized_maximum_error);
  782. X                }
  783. X              (void) fprintf(stderr," %s %lds\n",image->magick,
  784. X                time((time_t *) 0)-start_time+1);
  785. X            }
  786. X          /*
  787. X            Pack image data to conserve memory (memory <=> speed).
  788. X          */
  789. X          image->alpha=False;
  790. X          (void) PackImage(image);
  791. X          (void) free((char *) image->pixels);
  792. X          image->pixels=(RunlengthPacket *) NULL;
  793. X          if (image_number == maximum_images)
  794. X            {
  795. X              /*
  796. X                Increase size of images array.
  797. X              */
  798. X              maximum_images<<=1;
  799. X              images=(Image **)
  800. X                realloc((char *) images,maximum_images*sizeof(Image *));
  801. X              if (images == (Image **) NULL)
  802. X                Error("unable to animate images","memory allocation failed");
  803. X            }
  804. X          images[image_number++]=image;
  805. X          next_image=image->next;
  806. X          if (next_image != (Image *) NULL)
  807. X            image=next_image;
  808. X        } while (next_image != (Image *) NULL);
  809. X      }
  810. X  }
  811. X  if (image_number == 0)
  812. X    Error("missing an image file name",(char *) NULL);
  813. X  XAnimateImage(display,&resource_info,argv,argc,images,image_number);
  814. X  (void) free((char *) images);
  815. X  XCloseDisplay(display);
  816. X  return(False);
  817. }
  818. SHAR_EOF
  819. echo 'File ImageMagick/animate.c is complete' &&
  820. chmod 0644 ImageMagick/animate.c ||
  821. echo 'restore of ImageMagick/animate.c failed'
  822. Wc_c="`wc -c < 'ImageMagick/animate.c'`"
  823. test 72608 -eq "$Wc_c" ||
  824.     echo 'ImageMagick/animate.c: original size 72608, current size' "$Wc_c"
  825. rm -f _shar_wnt_.tmp
  826. fi
  827. # ============= ImageMagick/miff.man ==============
  828. if test -f 'ImageMagick/miff.man' -a X"$1" != X"-c"; then
  829.     echo 'x - skipping ImageMagick/miff.man (File already exists)'
  830.     rm -f _shar_wnt_.tmp
  831. else
  832. > _shar_wnt_.tmp
  833. echo 'x - extracting ImageMagick/miff.man (Text)'
  834. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/miff.man' &&
  835. .ad l
  836. .nh
  837. .TH MIFF 5 "10 October 1992" "ImageMagick"
  838. .SH NAME
  839. MIFF - ImageMagick's file format for raster images.
  840. .SH SYNOPSIS
  841. .B #include <image.h>
  842. .SH DESCRIPTION
  843. .PP
  844. A MIFF image file consist of two sections.  The first section is
  845. composed of keywords describing the image in text form.  The next
  846. section is the binary image data.  The two sections are separated by a
  847. \fB:\fP character immediately followed by a \fInewline\fP.  Generally,
  848. the first section has a \fIform-feed\fP and \fInewline\fP proceeding
  849. the \fB:\fP character.   You can then list the image keywords with
  850. \fImore\fP, without printing the binary image that follows the \fB:\fP
  851. separator.
  852. .PP
  853. Each keyword must be separated by at least one space but can be
  854. separated with control characters such a \fIform-feed\fP or
  855. \fInewline\fP.
  856. .PP
  857. A list of valid keywords follows:
  858. .TP 5
  859. .B "alpha=\fITrue | False\fP"
  860. specifies whether a continuous-tone image also has alpha data.  Alpha data is
  861. generally useful for image compositing.
  862. X
  863. This keyword is optional.  If it is not specified, no alpha data is assumed.
  864. This keyword has no meaning for pseudo-color images.
  865. .TP 5
  866. .B "class=\fIDirectClass | PseudoClass\fP"
  867. identifies the type of binary image stored within the file.
  868. X
  869. This keyword is optional.  If it is not specified, a \fIDirectClass\fP
  870. image format is assumed.  An explanation of \fIDirectClass\fP and
  871. \fIPseudoClass\fP image data follows this list.
  872. .TP 5
  873. .B "colors=\fIvalue\fP"
  874. specifies the number of colors in the image, and for pseudo-color
  875. images the size of the colormap.
  876. X
  877. This keyword is optional.  However, if a colormap size is not
  878. specified, a linear colormap is assumed for pseudo-color images.
  879. .TP 5
  880. .B "columns=\fIvalue\fP"
  881. is a required keyword and specifies the number of columns, or width in
  882. pixels, of the image.
  883. .TP 5
  884. .B "compression=\fIQEncoded | RunlengthEncoded\fP"
  885. identifies how the image stored within the file is compressed.
  886. X
  887. This keyword is optional.  If it is not specified, the image is assumed
  888. to be uncompressed.  \fIQEncoded\fP has no meaning for pseudo-color
  889. images.  A detailed explanation of runlength-encoded and predictive
  890. arithmetic image compression follows this list.
  891. .TP 5
  892. .B "id=\fIImageMagick\fP"
  893. is a required keyword and identifies this file as a MIFF image.
  894. .TP 5
  895. .B "montage=\fI<width>x<height>{\+-}<x offset>{\+-}<y offset>\fP
  896. size and location of the individual tiles of a composite image.  See
  897. \fBX(1)\fP for details about the geometry specification.
  898. X
  899. Use this keyword when the image is a composite of a number of different
  900. tiles.  A tile consists of an image and optionally a border and a
  901. label.  \fI<width>\fP is the size in pixels of each individual tile in
  902. the horizonal direction and \fI<height>\fP is the size in the vertical
  903. direction.  Each tile must have an equal number of pixels in width and
  904. equal in height.  However, the width can differ from the height.  \fI<x
  905. offset>\fP is the offset in number of pixels from the vertical edge of
  906. the composite image where the first tile of a row begins and \fI<y
  907. offset>\fP is the offset from the horizonal edge where the first tile
  908. of a column begins.
  909. X
  910. If this keyword is specified, a directory of tile names must follow the
  911. image header.  The format of the directory is explained below.
  912. .TP 5
  913. .B "packets=\fIvalue\fP"
  914. specifies the number of compressed color packets in the image data
  915. section.
  916. X
  917. This keyword is optional, but recommended, for runlength-encoded image
  918. compression.  It is required for arithimetic encoded image compression.  A
  919. detailed explanation of image compression follows this list.
  920. .TP 5
  921. .B "rows=\fIvalue\fP"
  922. is a required keyword and specifies the number of rows, or height in pixels,
  923. of the image.
  924. .TP 5
  925. .B "scene=\fIvalue\fP"
  926. is an optional keyword and is a reference number for sequencing of
  927. images.
  928. X
  929. This keyword is typically useful for animating a sequence of images.
  930. .TP 5
  931. .B "signature=\fIvalue\fP"
  932. is an optional keyword and is a character string that uniquely identifies
  933. the image colormap.
  934. X
  935. A unique identifier for the colormap is useful for animating a sequence
  936. of \fIPseudoClass\fP images.  The default identifier is a digital
  937. signature computed from RSA's Data Security MD5 Digest Algorithm
  938. described in Internet draft [MD5], July 1992.  The colormap signature is
  939. usually computed for \fIPseudoClass\fP images.
  940. .PP
  941. Comments can be included in the keyword section.  Comments must begin with
  942. a \fB{\fP character and end with a \fI}\fP character.
  943. .PP
  944. An example keyword section follows:
  945. .PP
  946. X    {
  947. X      Rendered via Dore by Sandy Hause.
  948. X    }
  949. X    id=ImageMagick
  950. X    class=PseudoClass  colors=256  signature=d79e1c308aa5bbcdeea8ed63df412da9
  951. X    compression=RunlengthEncoded  packets=27601
  952. X    columns=1280  rows=1024
  953. X    scene=1  
  954. X    ^L
  955. X    :
  956. .PP
  957. If you specify \fImontage\fP in the image header, follow the header
  958. with a directory of image tiles.  This directory consists of a name for
  959. each tile of the composite image separated by a NEWLINE character.  The
  960. list is terminated with a NULL character.
  961. .PP
  962. The binary image data that follows the keyword text is stored in one of
  963. two binary classes as specified by the \fBclass\fP keyword:
  964. \fIDirectClass\fP or \fIPseudoClass\fP.
  965. .PP
  966. Use the \fIDirectClass\fP class to store continuous-tone images.
  967. \fIDirectClass\fP requires that the image pixels immediately follow the
  968. keyword text and be stored as binary red, green, and blue intensity
  969. values (and optional alpha value).  Each color component is stored as
  970. one binary byte (8 bit) and ranges from 0 through 255.  The total
  971. number of pixels expected is equal to the number of pixel columns times
  972. the number of pixel rows as specified by the \fBcolumns\fP and
  973. \fBrows\fP keywords.
  974. .PP
  975. If the \fBcompression\fP keyword is not specified, a red, green, and blue byte
  976. (and optional alpha byte) in that order is expected for each pixel of the
  977. image.
  978. .PP
  979. If \fBcompression\fP is \fIQEncoded\fP, each red, green, and blue byte
  980. intensity value (and optional alpha value) is encoded using the predictive
  981. arithmetic compression algorithm.  Use the \fBpackets\fP keyword to specify
  982. the total number of arithimetic encoded packets that comprise the image.
  983. Refer to "JPEG-9-R6 Working Draft for Development of JPEG CD", January
  984. 1992, for implementation specific details.
  985. .PP
  986. If \fBcompression\fP is \fIRunlengthEncoded\fP, each red, green, and
  987. blue byte intensity value (and optional alpha value) is followed by a
  988. count byte. This value specifies the number of horizonally contiguous
  989. pixels in the image of that color.  The count (0-255) is one less than
  990. the actual number of contiguous pixels; thus a single packet can
  991. represent from 1 up to 256 identical pixels.  The total number of
  992. pixels specified by the individual count bytes must add up to the
  993. number of pixel columns times the number of pixel rows as specified by
  994. the \fBcolumns\fP and \fBrows\fP keywords.  Use \fBpackets\fP to
  995. specify the total number of runlength-encoded packets that comprise the
  996. image.
  997. .PP
  998. Use the \fIPseudoClass\fP class to store pseudo-color images.
  999. \fIPseudoClass\fP requires that the image colormap and pseudo-color
  1000. pixels immediately follow the keyword text.  The colormap is stored as
  1001. contiguous red, green, and blue intensity values.  Each color component
  1002. is stored as one binary byte (8 bit) and ranges from 0 through 255. The
  1003. number of intensity values expected is determined by the \fBcolors\fP
  1004. keyword.  Note, an image colormap is restricted to at most 65535
  1005. entries.  The binary pseudo-color image is stored as indexes into the
  1006. colormap.  For colormaps of 256 colors or less, the indexes are stored
  1007. as one binary byte (8 bit) and ranges from 0 through 255.  If the
  1008. colormap size exceeds 256 entries, then each colormap index is two
  1009. bytes each with the most-significant-byte first.  The total number of
  1010. pixels expected is equal to the number of pixel columns times the
  1011. number of pixel rows as specified by the \fBcolumns\fP and \fBrows\fP
  1012. keywords.
  1013. .PP
  1014. If the \fBcompression\fP keyword is not specified, a colormap index is
  1015. expected for each pixel of the image.
  1016. .PP
  1017. If \fBcompression\fP is \fIRunlengthEncoded\fP, each colormap index
  1018. is followed by a count byte. This value  specifies the number of
  1019. horizonally contiguous pixels in the image of that color.  The count
  1020. (0-255) is one less than the actual number of contiguous pixels; thus a
  1021. single packet can represent from 1 up to 256 identical pixels.  The
  1022. total number of pixels specified by the individual count bytes must add
  1023. up to the number of pixels expected in the image as specified by the
  1024. \fBcolumns\fP and \fBrows\fP keywords.  Use \fBpackets\fP to specify the
  1025. total number of runlength-encoded packets that comprise the image.
  1026. .SH SEE ALSO
  1027. display(1), animate(1), import(1), montage(1), mogrify(1), 
  1028. convert(1), more(1), compress(1)
  1029. .SH COPYRIGHT
  1030. Copyright 1992 E. I. du Pont de Nemours & Company
  1031. .PP
  1032. Permission to use, copy, modify, distribute, and sell this software and
  1033. its documentation for any purpose is hereby granted without fee,
  1034. provided that the above copyright notice appear in all copies and that
  1035. both that copyright notice and this permission notice appear in
  1036. supporting documentation, and that the name of E. I. du Pont de Nemours
  1037. & Company not be used in advertising or publicity pertaining to
  1038. distribution of the software without specific, written prior
  1039. permission.  E. I. du Pont de Nemours & Company makes no representations
  1040. about the suitability of this software for any purpose.  It is provided
  1041. "as is" without express or implied warranty.
  1042. .PP
  1043. E. I. du Pont de Nemours & Company disclaims all warranties with regard
  1044. to this software, including all implied warranties of merchantability
  1045. and fitness, in no event shall E. I. du Pont de Nemours & Company be
  1046. liable for any special, indirect or consequential damages or any
  1047. damages whatsoever resulting from loss of use, data or profits, whether
  1048. in an action of contract, negligence or other tortious action, arising
  1049. out of or in connection with the use or performance of this software.
  1050. .SH AUTHORS
  1051. John Cristy, E.I. du Pont de Nemours & Company Incorporated
  1052. SHAR_EOF
  1053. chmod 0644 ImageMagick/miff.man ||
  1054. echo 'restore of ImageMagick/miff.man failed'
  1055. Wc_c="`wc -c < 'ImageMagick/miff.man'`"
  1056. test 10068 -eq "$Wc_c" ||
  1057.     echo 'ImageMagick/miff.man: original size 10068, current size' "$Wc_c"
  1058. rm -f _shar_wnt_.tmp
  1059. fi
  1060. # ============= ImageMagick/montage.c ==============
  1061. if test -f 'ImageMagick/montage.c' -a X"$1" != X"-c"; then
  1062.     echo 'x - skipping ImageMagick/montage.c (File already exists)'
  1063.     rm -f _shar_wnt_.tmp
  1064. else
  1065. > _shar_wnt_.tmp
  1066. echo 'x - extracting ImageMagick/montage.c (Text)'
  1067. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/montage.c' &&
  1068. /*
  1069. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1070. %                                                                             %
  1071. %                                                                             %
  1072. %                                                                             %
  1073. %             M   M   OOO   N   N  TTTTT   AAA    GGGG  EEEEE                 %
  1074. %             MM MM  O   O  NN  N    T    A   A  G      E                     %
  1075. %             M M M  O   O  N N N    T    AAAAA  G  GG  EEE                   %
  1076. %             M   M  O   O  N  NN    T    A   A  G   G  E                     %
  1077. %             M   M   OOO   N   N    T    A   A   GGGG  EEEEE                 %
  1078. %                                                                             %
  1079. %                                                                             %
  1080. %          Montage Machine Independent File Format Image via X11.             %
  1081. %                                                                             %
  1082. %                                                                             %
  1083. %                                                                             %
  1084. %                           Software Design                                   %
  1085. %                             John Cristy                                     %
  1086. %                              July 1992                                      %
  1087. %                                                                             %
  1088. %                                                                             %
  1089. %  Copyright 1992 E. I. du Pont de Nemours & Company                          %
  1090. %                                                                             %
  1091. %  Permission to use, copy, modify, distribute, and sell this software and    %
  1092. %  its documentation for any purpose is hereby granted without fee,           %
  1093. %  provided that the above Copyright notice appear in all copies and that     %
  1094. %  both that Copyright notice and this permission notice appear in            %
  1095. %  supporting documentation, and that the name of E. I. du Pont de Nemours    %
  1096. %  & Company not be used in advertising or publicity pertaining to            %
  1097. %  distribution of the software without specific, written prior               %
  1098. %  permission.  E. I. du Pont de Nemours & Company makes no representations   %
  1099. %  about the suitability of this software for any purpose.  It is provided    %
  1100. %  "as is" without express or implied warranty.                               %
  1101. %                                                                             %
  1102. %  E. I. du Pont de Nemours & Company disclaims all warranties with regard    %
  1103. %  to this software, including all implied warranties of merchantability      %
  1104. %  and fitness, in no event shall E. I. du Pont de Nemours & Company be       %
  1105. %  liable for any special, indirect or consequential damages or any           %
  1106. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  1107. %  in an action of contract, negligence or other tortious action, arising     %
  1108. %  out of or in connection with the use or performance of this software.      %
  1109. %                                                                             %
  1110. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1111. %
  1112. %  Montage creates a composite image by combining several separate
  1113. %  images.  The images are tiled on the composite image with the name of
  1114. %  the image appearing just above the individual tile.
  1115. %
  1116. %  The composite image is constructed in the following manner.  First,
  1117. %  each image specified on the command line, except for the last, is
  1118. %  scaled to fit the maximum tile size.  The maximum tile size by default
  1119. %  is 256x256.  It can be modified with the -geometry command line
  1120. %  argument or X resource.  Note that the maximum tile size need not be a
  1121. %  square.  The original aspect ratio of each image is maintainted unless
  1122. %  +aspect_ratio is specfified.
  1123. %
  1124. %  Next the composite image is initialized with the color specified by the
  1125. %  -background command line argument or X resource.  The width and height
  1126. %  of the composite image is determined by the maximum tile size, the
  1127. %  number of tiles per row, the tile border width and height, the image
  1128. %  border width, and the label height.  The number of tiles per row specifies
  1129. %  how many images are to appear in each row of the composite image.  The
  1130. %  default is to have an equal number of images in each row and column of the
  1131. %  composite.  This value can be specified with -tiles_per_row.  The tile
  1132. %  border width and height, and the image border width defaults to the value
  1133. %  of the X resource -borderwidth.  It can be changed with the -borderwidth or
  1134. %  -geometry command line argument or X resource.  The label height is
  1135. %  determined by the font you specify with the -font command line argument or
  1136. %  X resource.  If you do not specify a font, a font is choosen that allows
  1137. %  the name of the image to fit the maximum width of a tiled area.  The label
  1138. %  colors is determined by the -background and -foreground command line
  1139. %  argument or X resource.  Note, that if the background and foreground colors
  1140. %  are the same, labels will not appear.
  1141. %
  1142. %  Finally, each image is set onto the composite image, surrounded by its
  1143. %  border color, with its name centered just below it.  The individual images
  1144. %  are centered within the width of the tiled area.  The final argument on the
  1145. %  command line is the name assigned to the composite image.  The image is
  1146. %  written in the MIFF format and may by viewed or printed with `display'.
  1147. %
  1148. %  The Montage program command syntax is:
  1149. %
  1150. %  Usage: montage [options ...] file [ [options ...] file ...] file
  1151. %
  1152. %  Where options include:
  1153. %    -aspect_ratio         respect aspect ratio of the image
  1154. %    -clip geometry        preferred size and location of the clipped image
  1155. %    -colors value         preferred number of colors in the image
  1156. %    -colorspace type      GRAY, RGB, XYZ, YIQ, or YUV
  1157. %    -compose operator     composite operator
  1158. %    -compress type        RunlengthEncoded or QEncoded
  1159. %    -density geometry     vertical and horizonal density of the image
  1160. %    -display server       query fonts from this X server
  1161. %    -dither               apply Floyd/Steinberg error diffusion to image
  1162. %    -gamma value          level of gamma correction
  1163. %    -geometry geometry    preferred tile and border sizes
  1164. %    -gravity direction    which direction to gravitate towards
  1165. %    -monochrome           transform image to black and white
  1166. %    -rotate degrees       apply Paeth rotation to the image
  1167. %    -tiles_per_row value  number of image tiles per row
  1168. %    -treedepth value      depth of the color classification tree
  1169. %    -verbose              print detailed information about the image
  1170. %
  1171. %  In addition to those listed above, you can specify these standard X
  1172. %  resources as command line options:  -background, -bordercolor -borderwidth,
  1173. %  -font, -foreground, or -title.
  1174. %
  1175. %  Change '-' to '+' in any option above to reverse its effect.  For
  1176. %  example, specify +compress to store the image as uncompressed.
  1177. %
  1178. %  By default, the image format of `file' is determined by its magic
  1179. %  number.  To specify a particular image format, precede the filename
  1180. %  with an image format name and a colon (i.e. mtv:image) or specify the
  1181. %  image type as the filename suffix (i.e. image.mtv).  Specify 'file' as
  1182. %  '-' for standard input or output.
  1183. %
  1184. %
  1185. */
  1186. X
  1187. /*
  1188. X  Include declarations.
  1189. */
  1190. #include "display.h"
  1191. #include "image.h"
  1192. #include "alien.h"
  1193. #include "X.h"
  1194. X
  1195. /*
  1196. X  Global declarations.
  1197. */
  1198. char
  1199. X  *application_name;
  1200. X
  1201. /*
  1202. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1203. %                                                                             %
  1204. %                                                                             %
  1205. %                                                                             %
  1206. %   E r r o r                                                                 %
  1207. %                                                                             %
  1208. %                                                                             %
  1209. %                                                                             %
  1210. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1211. %
  1212. %  Function Error displays an error message and then terminates the program.
  1213. %
  1214. %  The format of the Error routine is:
  1215. %
  1216. %      Error(message,qualifier)
  1217. %
  1218. %  A description of each parameter follows:
  1219. %
  1220. %    o message: Specifies the message to display before terminating the
  1221. %      program.
  1222. %
  1223. %    o qualifier: Specifies any qualifier to the message.
  1224. %
  1225. %
  1226. */
  1227. void Error(message,qualifier)
  1228. char
  1229. X  *message,
  1230. X  *qualifier;
  1231. {
  1232. X  (void) fprintf(stderr,"%s: %s",application_name,message);
  1233. X  if (qualifier != (char *) NULL)
  1234. X    (void) fprintf(stderr," (%s)",qualifier);
  1235. X  (void) fprintf(stderr,".\n");
  1236. X  exit(1);
  1237. }
  1238. X
  1239. /*
  1240. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1241. %                                                                             %
  1242. %                                                                             %
  1243. %                                                                             %
  1244. %   M o n t a g e I m a g e                                                   %
  1245. %                                                                             %
  1246. %                                                                             %
  1247. %                                                                             %
  1248. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1249. %
  1250. %  Function MontageImage creates a composite image by combining several
  1251. %  separate images.
  1252. %
  1253. %  The format of the MontageImage routine is:
  1254. %
  1255. %      MontageImage(display,resource_info,compose,tiles_per_row,image,
  1256. %        number_tiles)
  1257. %
  1258. %  A description of each parameter follows:
  1259. %
  1260. %    o display: Specifies a connection to an X server;  returned from
  1261. %      XOpenDisplay.
  1262. %
  1263. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1264. %
  1265. %    o compose: Specifies an image composite operator.
  1266. %
  1267. %    o tiles_per_row: Specifies the number of arguments.
  1268. %
  1269. %    o image: Specifies a pointer to a Image structure; returned from
  1270. %      ReadImage.
  1271. %
  1272. %    o number_tiles: Specifies the number of tiles to tile.
  1273. %
  1274. %
  1275. */
  1276. static int LinearCompare(x,y)
  1277. void
  1278. X  *x,
  1279. X  *y;
  1280. {
  1281. X  Image
  1282. X    **image_1,
  1283. X    **image_2;
  1284. X
  1285. X  image_1=(Image **) x;
  1286. X  image_2=(Image **) y;
  1287. X  return((int) (*image_1)->scene-(int) (*image_2)->scene);
  1288. }
  1289. X
  1290. static Image *MontageImage(display,resource_info,compose,tiles_per_row,images,
  1291. X  number_tiles)
  1292. Display
  1293. X  *display;
  1294. X
  1295. XXResourceInfo
  1296. X  *resource_info;
  1297. X
  1298. unsigned int
  1299. X  compose,
  1300. X  tiles_per_row;
  1301. X
  1302. Image
  1303. X  **images;
  1304. X
  1305. unsigned int
  1306. X  number_tiles;
  1307. {
  1308. X  ColorPacket
  1309. X    border_color;
  1310. X
  1311. X  Image
  1312. X    *image,
  1313. X    *montage_image;
  1314. X
  1315. X  int
  1316. X    tile_border_height,
  1317. X    tile_border_width,
  1318. X    x,
  1319. X    y;
  1320. X
  1321. X  register char
  1322. X    *q;
  1323. X
  1324. X  register int
  1325. X    i;
  1326. X
  1327. X  register RunlengthPacket
  1328. X    *p;
  1329. X
  1330. X  unsigned int
  1331. X    border_width,
  1332. X    count,
  1333. X    status,
  1334. X    tile,
  1335. X    tile_height,
  1336. X    tile_width,
  1337. X    x_offset,
  1338. X    y_offset;
  1339. X
  1340. X  XAnnotateInfo
  1341. X    annotate_info;
  1342. X
  1343. X  XColor
  1344. X    background_color;
  1345. X
  1346. X  XWindowInfo
  1347. X    image_window;
  1348. X
  1349. X  /*
  1350. X    Determine tile sizes.
  1351. X  */
  1352. X  border_width=resource_info->border_width;
  1353. X  tile_border_width=resource_info->border_width;
  1354. X  tile_border_height=resource_info->border_width;
  1355. X  tile_width=256;
  1356. X  tile_height=256;
  1357. X  if (resource_info->image_geometry != (char *) NULL)
  1358. X    {
  1359. X      XParseGeometry(resource_info->image_geometry,&tile_border_width,
  1360. X        &tile_border_height,&tile_width,&tile_height);
  1361. X      if (tile_border_width < 0)
  1362. X        tile_border_width=0;
  1363. X      if (tile_border_height < 0)
  1364. X        tile_border_height=0;
  1365. X    }
  1366. X  if (tiles_per_row == 0)
  1367. X    {
  1368. X      /*
  1369. X        Compute tiles per row.
  1370. X      */
  1371. X      tiles_per_row=1;
  1372. X      while ((tiles_per_row*tiles_per_row) < number_tiles)
  1373. X        tiles_per_row++;
  1374. X    }
  1375. X  /*
  1376. X    Initialize tile colors.
  1377. X  */
  1378. X  background_color.red=0;
  1379. X  background_color.green=0;
  1380. X  background_color.blue=0;
  1381. X  border_color.red=0;
  1382. X  border_color.green=0;
  1383. X  border_color.blue=0;
  1384. X  XGetAnnotateInfo(&annotate_info);
  1385. X  if (display)
  1386. X    {
  1387. X      char
  1388. X        text[2048];
  1389. X
  1390. X      XFontStruct
  1391. X        *font_info;
  1392. X
  1393. X      XPixelInfo
  1394. X        pixel_info;
  1395. X
  1396. X      XStandardColormap
  1397. X        map_info;
  1398. X
  1399. X      XVisualInfo
  1400. X        *visual_info;
  1401. X
  1402. X      /*
  1403. X        Initialize visual info.
  1404. X      */
  1405. X      visual_info=XBestVisualInfo(display,"default",(char *) NULL,
  1406. X        (XStandardColormap *) NULL);
  1407. X      if (visual_info == (XVisualInfo *) NULL)
  1408. X         Error("unable to get visual",resource_info->visual_type);
  1409. X      /*
  1410. X        Initialize font info.
  1411. X      */
  1412. X      tile=0;
  1413. X      for (i=1; i < number_tiles; i++)
  1414. X        if ((int) strlen(images[i]->filename) >
  1415. X            (int) strlen(images[tile]->filename))
  1416. X          tile=i;
  1417. X      (void) strcpy(text,images[tile]->filename);
  1418. X      font_info=XBestFont(display,resource_info,text,tile_width);
  1419. X      if (font_info == (XFontStruct *) NULL)
  1420. X        Error("unable to load font",resource_info->font);
  1421. X      annotate_info.text=(char *) malloc(2048*sizeof(char));
  1422. X      if (annotate_info.text == (char *) NULL)
  1423. X        Error("unable to montage images","memory allocation failed");
  1424. X      annotate_info.font_info=font_info;
  1425. X      annotate_info.height=font_info->ascent+font_info->descent;
  1426. X      /*
  1427. X        Determine background, border, and foreground colors.
  1428. X      */
  1429. X      map_info.colormap=XDefaultColormap(display,visual_info->screen);
  1430. X      XGetPixelInfo(display,visual_info,&map_info,resource_info,(Image *) NULL,
  1431. X        &pixel_info);
  1432. X      background_color=pixel_info.background_color;
  1433. X      border_color.red=pixel_info.border_color.red >> 8;
  1434. X      border_color.green=pixel_info.border_color.green >> 8;
  1435. X      border_color.blue=pixel_info.border_color.blue >> 8;
  1436. X      /*
  1437. X        Window superclass.
  1438. X      */
  1439. X      image_window.id=XRootWindow(display,visual_info->screen);
  1440. X      image_window.screen=visual_info->screen;
  1441. X      image_window.depth=visual_info->depth;
  1442. X      image_window.visual_info=visual_info;
  1443. X      image_window.pixel_info=(&pixel_info);
  1444. X      image_window.font_info=font_info;
  1445. X    }
  1446. X  /*
  1447. X    Allocate image structure.
  1448. X  */
  1449. X  montage_image=AllocateImage("MIFF");
  1450. X  if (montage_image == (Image *) NULL)
  1451. X    Error("memory allocation error",(char *) NULL);
  1452. X  /*
  1453. X    Initialize Image structure.
  1454. X  */
  1455. X  montage_image->comments=(char *) malloc(2048*sizeof(char));
  1456. X  montage_image->columns=
  1457. X    (tile_width+(tile_border_width+border_width)*2)*tiles_per_row;
  1458. X  montage_image->rows=
  1459. X    (tile_height+(tile_border_height+border_width)*2+annotate_info.height+4)*
  1460. X    (number_tiles/tiles_per_row+((number_tiles % tiles_per_row) != 0))+
  1461. X    ((tile_border_height+border_width) >> 1);
  1462. X  if (resource_info->title != (char *) NULL)
  1463. X    montage_image->rows+=((annotate_info.height+4) << 1)+
  1464. X      (tile_border_height << 1);
  1465. X  montage_image->montage=(char *) malloc(2048*sizeof(char));
  1466. X  count=0;
  1467. X  for (tile=0; tile < number_tiles; tile++)
  1468. X    count+=strlen(images[tile]->filename)+1;
  1469. X  montage_image->directory=(char *) malloc(count*sizeof(char));
  1470. X  montage_image->packets=montage_image->columns*montage_image->rows;
  1471. X  montage_image->pixels=(RunlengthPacket *)
  1472. X    malloc((unsigned int) montage_image->packets*sizeof(RunlengthPacket));
  1473. X  if ((montage_image->comments == (char *) NULL) ||
  1474. X      (montage_image->montage == (char *) NULL) ||
  1475. X      (montage_image->directory == (char *) NULL) ||
  1476. X      (montage_image->pixels == (RunlengthPacket *) NULL))
  1477. X    Error("memory allocation error",(char *) NULL);
  1478. X  (void) sprintf(montage_image->comments,"\n  ImageMagick image montage.\n");
  1479. X  /*
  1480. X    Set montage geometry.
  1481. X  */
  1482. X  x_offset=0;
  1483. X  y_offset=((tile_border_height+border_width) >> 1);
  1484. X  if (resource_info->title != (char *) NULL)
  1485. X    y_offset+=((annotate_info.height+4) << 1)+(tile_border_height << 1);
  1486. X  *montage_image->directory='\0';
  1487. X  (void) sprintf(montage_image->montage,"%dx%d%+d%+d",
  1488. X    tile_width+(tile_border_width+border_width)*2,
  1489. X    (tile_height+(tile_border_height+border_width)*2+annotate_info.height+4),
  1490. X    x_offset,y_offset);
  1491. X  /*
  1492. X    Initialize montage image to background color.
  1493. X  */
  1494. X  p=montage_image->pixels;
  1495. X  for (i=0; i < montage_image->packets; i++)
  1496. X  {
  1497. X    p->red=background_color.red >> 8;
  1498. X    p->green=background_color.green >> 8;
  1499. X    p->blue=background_color.blue >> 8;
  1500. X    p->index=0;
  1501. X    p->length=0;
  1502. X    p++;
  1503. X  }
  1504. X  /*
  1505. X    Sort images by increasing tile number.
  1506. X  */
  1507. X  (void) qsort((void *) images,(int) number_tiles,sizeof(Image *),
  1508. X    LinearCompare);
  1509. X  if (display && (resource_info->title != (char *) NULL))
  1510. X    {
  1511. X      /*
  1512. X        Copy title to the composite image.
  1513. X      */
  1514. X      (void) strcpy(annotate_info.text,resource_info->title);
  1515. X      annotate_info.width=XTextWidth(image_window.font_info,annotate_info.text,
  1516. X        strlen(annotate_info.text));
  1517. X      if ((annotate_info.width << 1) > montage_image->columns)
  1518. X        {
  1519. X          /*
  1520. X            Label is too wide-- shorten.
  1521. X          */
  1522. X          q=annotate_info.text+strlen(annotate_info.text);
  1523. X          do
  1524. X          {
  1525. X            *--q='\0';
  1526. X            if ((int) strlen(annotate_info.text) > 2)
  1527. X              (void) strcpy(q-2,"...");
  1528. X            annotate_info.width=XTextWidth(image_window.font_info,
  1529. X              annotate_info.text,strlen(annotate_info.text));
  1530. X          } while ((annotate_info.width << 1) > montage_image->columns);
  1531. X        }
  1532. X      (void) sprintf(annotate_info.geometry,"%ux%u%+d%+d\0",
  1533. X        annotate_info.width << 1,annotate_info.height << 1,tile_border_width+
  1534. X        (int) (montage_image->columns >> 1)-(int) annotate_info.width,
  1535. X        tile_border_height+4);
  1536. X      (void) XAnnotateImage(display,&image_window,&annotate_info,True,
  1537. X        montage_image);
  1538. X    }
  1539. X  /*
  1540. X    Copy tile images to the composite image.
  1541. X  */
  1542. X  x_offset=tile_border_width;
  1543. X  y_offset=tile_border_height;
  1544. X  if (resource_info->title != (char *) NULL)
  1545. X    y_offset+=((annotate_info.height+4) << 1)+(tile_border_height << 1);
  1546. X  *montage_image->directory='\0';
  1547. X  for (tile=0; tile < number_tiles; tile++)
  1548. X  {
  1549. X    /*
  1550. X      Copy this tile to the composite image.
  1551. X    */
  1552. X    image=images[tile];
  1553. X    (void) strcat(montage_image->directory,image->filename);
  1554. X    (void) strcat(montage_image->directory,"\n");
  1555. X    status=UnpackImage(image);
  1556. X    if (status == False)
  1557. X      Error("unable to unpack image",(char *) NULL);
  1558. X    if (border_width > 0)
  1559. X      {
  1560. X        Image
  1561. X          *bordered_image;
  1562. X
  1563. X        /*
  1564. X          Put a border around the image.
  1565. X        */
  1566. X        bordered_image=
  1567. X          BorderImage(image,border_width,border_width,border_color);
  1568. X        if (bordered_image != (Image *) NULL)
  1569. X          {
  1570. X            DestroyImage(image);
  1571. X            image=bordered_image;
  1572. X          }
  1573. X      }
  1574. X    /*
  1575. X      Gravitate image as specified by the tile gravity.
  1576. X    */
  1577. X    switch (resource_info->gravity)
  1578. X    {
  1579. X      case NorthWestGravity:
  1580. X      {
  1581. X        x=0;
  1582. X        y=0;
  1583. X        break;
  1584. X      }
  1585. X      case NorthGravity:
  1586. X      {
  1587. X        x=((tile_width+border_width*2)-image->columns)/2;
  1588. X        y=0;
  1589. X        break;
  1590. X      }
  1591. X      case NorthEastGravity:
  1592. X      {
  1593. X        x=(tile_width+border_width*2)-image->columns;
  1594. X        y=0;
  1595. X        break;
  1596. X      }
  1597. X      case WestGravity:
  1598. X      {
  1599. X        x=0;
  1600. X        y=((tile_height+border_width*2)-image->rows)/2;
  1601. X        break;
  1602. X      }
  1603. X      case ForgetGravity:
  1604. X      case StaticGravity:
  1605. X      case CenterGravity:
  1606. X      {
  1607. X        x=((tile_width+border_width*2)-image->columns)/2;
  1608. X        y=((tile_height+border_width*2)-image->rows)/2;
  1609. X        break;
  1610. X      }
  1611. X      case EastGravity:
  1612. X      {
  1613. X        x=(tile_width+border_width*2)-image->columns;
  1614. X        y=((tile_height+border_width*2)-image->rows)/2;
  1615. X        break;
  1616. X      }
  1617. X      case SouthWestGravity:
  1618. X      {
  1619. X        x=0;
  1620. X        y=(tile_height+border_width*2)-image->rows;
  1621. X        break;
  1622. X      }
  1623. X      case SouthGravity:
  1624. X      {
  1625. X        x=((tile_width+border_width*2)-image->columns)/2;
  1626. X        y=(tile_height+border_width*2)-image->rows;
  1627. X        break;
  1628. X      }
  1629. X      case SouthEastGravity:
  1630. X      {
  1631. X        x=(tile_width+border_width*2)-image->columns;
  1632. X        y=(tile_height+border_width*2)-image->rows;
  1633. X        break;
  1634. X      }
  1635. X    }
  1636. X    /*
  1637. X      Composite background image with tile image.
  1638. X    */
  1639. X    CompositeImage(montage_image,compose,image,x_offset+x,y_offset+y);
  1640. SHAR_EOF
  1641. true || echo 'restore of ImageMagick/montage.c failed'
  1642. fi
  1643. echo 'End of  part 19'
  1644. echo 'File ImageMagick/montage.c is continued in part 20'
  1645. echo 20 > _shar_seq_.tmp
  1646. exit 0
  1647. exit 0 # Just in case...
  1648.