home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume34 / imagemagick / part19 < prev    next >
Encoding:
Text File  |  1992-12-14  |  57.1 KB  |  1,642 lines

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