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

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: cristy@eplrx7.es.duPont.com (John Cristy)
  4. Subject:  v34i051:  imagemagick - X11 image processing and display v2.2, Part23/26
  5. Message-ID: <1992Dec15.035843.23013@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: b8cbdf2b999822ad6117593054bf8eeb
  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:58:43 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 2096
  14.  
  15. Submitted-by: cristy@eplrx7.es.duPont.com (John Cristy)
  16. Posting-number: Volume 34, Issue 51
  17. Archive-name: imagemagick/part23
  18. Environment: UNIX, VMS, X11, SGI, DEC, Cray, Sun, Vax
  19.  
  20. #!/bin/sh
  21. # this is Part.23 (part 23 of a multipart archive)
  22. # do not concatenate these parts, unpack them in order with /bin/sh
  23. # file ImageMagick/alien.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" != 23; 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/alien.c'
  39. else
  40. echo 'x - continuing file ImageMagick/alien.c'
  41. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/alien.c' &&
  42. X      }
  43. X    *gray++=(JSAMPLE) p->red;
  44. X  }
  45. X  jpeg_image->packet=p;
  46. }
  47. X
  48. static void JPEGWriteRGB(jpeg_info,pixel_data)
  49. compress_info_ptr
  50. X  jpeg_info;
  51. X
  52. JSAMPARRAY
  53. X  pixel_data;
  54. {
  55. X  register int
  56. X    column;
  57. X
  58. X  register JSAMPROW
  59. X    blue,
  60. X    green,
  61. X    red;
  62. X
  63. X  register RunlengthPacket
  64. X    *p;
  65. X
  66. X  /*
  67. X    Convert run-length encoded MIFF packets to JPEG pixels.
  68. X  */
  69. X  red=pixel_data[0];
  70. X  green=pixel_data[1];
  71. X  blue=pixel_data[2];
  72. X  p=jpeg_image->packet;
  73. X  for (column=jpeg_info->image_width; column > 0; column--)
  74. X  {
  75. X    if (jpeg_image->runlength > 0)
  76. X      jpeg_image->runlength--;
  77. X    else
  78. X      {
  79. X        p++;
  80. X        jpeg_image->runlength=p->length;
  81. X      }
  82. X    *red++=(JSAMPLE) p->red;
  83. X    *green++=(JSAMPLE) p->green;
  84. X    *blue++=(JSAMPLE) p->blue;
  85. X  }
  86. X  jpeg_image->packet=p;
  87. }
  88. X
  89. static void JPEGSelectMethod(jpeg_info)
  90. compress_info_ptr
  91. X  jpeg_info;
  92. {
  93. X  jpeg_info->methods->get_input_row=JPEGWriteRGB;
  94. X  if (jpeg_info->in_color_space == CS_GRAYSCALE)
  95. X    {
  96. X      j_monochrome_default(jpeg_info);
  97. X      jpeg_info->methods->get_input_row=JPEGWriteGRAY;
  98. X    }
  99. }
  100. X
  101. static unsigned int WriteJPEGImage(image)
  102. Image
  103. X  *image;
  104. {
  105. X  struct Compress_info_struct
  106. X    jpeg_info;
  107. X
  108. X  struct Compress_methods_struct
  109. X    jpeg_methods;
  110. X
  111. X  struct External_methods_struct
  112. X    external_methods;
  113. X
  114. X  /*
  115. X    Open image file.
  116. X  */
  117. X  OpenImage(image,"w");
  118. X  if (image->file == (FILE *) NULL)
  119. X    {
  120. X      Warning("unable to open file",image->filename);
  121. X      return(False);
  122. X    }
  123. X  /*
  124. X    Initialize the JPEG system-dependent methods.
  125. X  */
  126. X  jpeg_image=image;
  127. X  jpeg_info.methods=(&jpeg_methods);
  128. X  jpeg_info.emethods=(&external_methods);
  129. X  jselerror(&external_methods);
  130. X  jselmemmgr(&external_methods);
  131. X  jpeg_info.methods->input_init=JPEGInitializeImage;
  132. X  jpeg_info.methods->input_term=JPEGInputTermMethod;
  133. X  jpeg_methods.c_ui_method_selection=JPEGSelectMethod;
  134. X  j_c_defaults(&jpeg_info,jpeg_image->quality,False);
  135. X  jpeg_info.optimize_coding=True;
  136. X  jpeg_info.restart_in_rows=1;
  137. X  if ((image->class == PseudoClass) && (image->colors <= 256))
  138. X    jpeg_info.smoothing_factor=25;
  139. X  /*
  140. X    Write a JFIF JPEG file.
  141. X  */
  142. X  jpeg_info.input_file=(FILE *) NULL;
  143. X  jpeg_info.output_file=image->file;
  144. X  jselwjfif(&jpeg_info);
  145. X  jpeg_compress(&jpeg_info);
  146. X  CloseImage(image);
  147. X  return(True);
  148. }
  149. #else
  150. static unsigned int WriteJPEGImage(image)
  151. Image
  152. X  *image;
  153. {
  154. X  Warning("JPEG library is not available",image->filename);
  155. X  return(WriteImage(image));
  156. }
  157. #endif
  158. X
  159. /*
  160. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  161. %                                                                             %
  162. %                                                                             %
  163. %                                                                             %
  164. %   W r i t e M T V I m a g e                                                 %
  165. %                                                                             %
  166. %                                                                             %
  167. %                                                                             %
  168. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  169. %
  170. %  Function WriteMTVImage writes an image to a file on disk in red, green,
  171. %  blue rasterfile format.
  172. %
  173. %  The format of the WriteMTVImage routine is:
  174. %
  175. %      status=WriteMTVImage(image)
  176. %
  177. %  A description of each parameter follows.
  178. %
  179. %    o status: Function WriteImage return True if the image is written.
  180. %      False is returned is there is a memory shortage or if the image file
  181. %      fails to write.
  182. %
  183. %    o image:  A pointer to a Image structure.
  184. %
  185. %
  186. */
  187. static unsigned int WriteMTVImage(image)
  188. Image
  189. X  *image;
  190. {
  191. X  register int
  192. X    i,
  193. X    j;
  194. X
  195. X  register RunlengthPacket
  196. X    *p;
  197. X
  198. X  register unsigned char
  199. X    *q;
  200. X
  201. X  unsigned char
  202. X    *pixels;
  203. X
  204. X  /*
  205. X    Open output image file.
  206. X  */
  207. X  OpenImage(image,"w");
  208. X  if (image->file == (FILE *) NULL)
  209. X    {
  210. X      Warning("unable to open file",image->filename);
  211. X      return(False);
  212. X    }
  213. X  /*
  214. X    Convert MIFF to MTV raster pixels.
  215. X  */
  216. X  pixels=(unsigned char *)
  217. X    malloc(3*image->columns*image->rows*sizeof(unsigned char));
  218. X  if (pixels == (unsigned char *) NULL)
  219. X    {
  220. X      Warning("unable to allocate memory",(char *) NULL);
  221. X      return(False);
  222. X    }
  223. X  p=image->pixels;
  224. X  q=pixels;
  225. X  for (i=0; i < image->packets; i++)
  226. X  {
  227. X    for (j=0; j <= ((int) p->length); j++)
  228. X    {
  229. X      *q++=p->red;
  230. X      *q++=p->green;
  231. X      *q++=p->blue;
  232. X    }
  233. X    p++;
  234. X  }
  235. X  (void) fprintf(image->file,"%u %u",image->columns,image->rows);
  236. X  (void) fwrite((char *) pixels,sizeof(unsigned char),
  237. X    (int) (3*image->columns*image->rows),image->file);
  238. X  (void) free((char *) pixels);
  239. X  CloseImage(image);
  240. X  return(True);
  241. }
  242. X
  243. /*
  244. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  245. %                                                                             %
  246. %                                                                             %
  247. %                                                                             %
  248. %   W r i t e P N M I m a g e                                                 %
  249. %                                                                             %
  250. %                                                                             %
  251. %                                                                             %
  252. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  253. %
  254. %  Procedure WritePNMImage writes an image to a file on disk in PNM
  255. %  rasterfile format.
  256. %
  257. %  The format of the WritePNMImage routine is:
  258. %
  259. %      status=WritePNMImage(image)
  260. %
  261. %  A description of each parameter follows.
  262. %
  263. %    o status: Function WriteImage return True if the image is written.
  264. %      False is returned is there is a memory shortage or if the image file
  265. %      fails to write.
  266. %
  267. %    o image:  A pointer to a Image structure.
  268. %
  269. %
  270. */
  271. static unsigned int WritePNMImage(image)
  272. Image
  273. X  *image;
  274. {
  275. X  int
  276. X    count;
  277. X
  278. X  register int
  279. X    i,
  280. X    j;
  281. X
  282. X  register RunlengthPacket
  283. X    *p;
  284. X
  285. X  register unsigned char
  286. X    *q;
  287. X
  288. X  unsigned char
  289. X    format,
  290. X    *pixels;
  291. X
  292. X  unsigned int
  293. X    packets;
  294. X
  295. X  /*
  296. X    Open output image file.
  297. X  */
  298. X  OpenImage(image,"w");
  299. X  if (image->file == (FILE *) NULL)
  300. X    {
  301. X      Warning("unable to open file",image->filename);
  302. X      return(False);
  303. X    }
  304. X  /*
  305. X    Write PNM file header.
  306. X  */
  307. X  packets=image->columns*image->rows;
  308. X  if ((image->class == DirectClass) || (image->colors > 256))
  309. X    {
  310. X      format='6';
  311. X      packets*=3;
  312. X    }
  313. X  else
  314. X    {
  315. X      /*
  316. X        Determine if image is gray scale.
  317. X      */
  318. X      format='5';
  319. X      if (image->colors == 2)
  320. X        {
  321. X          format='4';
  322. X          packets/=8;
  323. X        }
  324. X      for (i=0; i < image->colors; i++)
  325. X        if ((image->colormap[i].red != image->colormap[i].green) ||
  326. X            (image->colormap[i].green != image->colormap[i].blue))
  327. X          {
  328. X            format='6';
  329. X            packets*=3;
  330. X            break;
  331. X          }
  332. X    }
  333. X  (void) fprintf(image->file,"P%c\n# created by ImageMagick\n%u %u\n",
  334. X    format,image->columns,image->rows);
  335. X  /*
  336. X    Convert MIFF to PNM raster pixels.
  337. X  */
  338. X  pixels=(unsigned char *) malloc(packets*sizeof(unsigned char));
  339. X  if (pixels == (unsigned char *) NULL)
  340. X    {
  341. X      Warning("unable to allocate memory",(char *) NULL);
  342. X      return(False);
  343. X    }
  344. X  p=image->pixels;
  345. X  q=pixels;
  346. X  switch (format)
  347. X  {
  348. X    case '4':
  349. X    {
  350. X      register unsigned char
  351. X        bit,
  352. X        byte,
  353. X        polarity;
  354. X
  355. X      unsigned int
  356. X        x;
  357. X
  358. X      /*
  359. X        Convert image to a PBM image.
  360. X      */
  361. X      polarity=(Intensity(image->colormap[0]) <
  362. X        Intensity(image->colormap[1]) ? 0 : 1);
  363. X      bit=0;
  364. X      byte=0;
  365. X      x=0;
  366. X      for (i=0; i < image->packets; i++)
  367. X      {
  368. X        for (j=0; j <= (int) p->length; j++)
  369. X        {
  370. X          byte<<=1;
  371. X          if (p->index == polarity)
  372. X            byte|=0x01;
  373. X          bit++;
  374. X          if (bit == 8)
  375. X            {
  376. X              *q++=byte;
  377. X              bit=0;
  378. X              byte=0;
  379. X            }
  380. X          x++;
  381. X          if (x == image->columns)
  382. X            {
  383. X              /*
  384. X                Advance to the next scanline.
  385. X              */
  386. X              if (bit > 0)
  387. X                *q++=byte << (8-bit);
  388. X              bit=0;
  389. X              byte=0;
  390. X              x=0;
  391. X           }
  392. X        }
  393. X        p++;
  394. X      }
  395. X      break;
  396. X    }
  397. X    case '5':
  398. X    {
  399. X      /*
  400. X        Convert image to a PGM image.
  401. X      */
  402. X      (void) fprintf(image->file,"%d\n",MaxRGB);
  403. X      for (i=0; i < image->packets; i++)
  404. X      {
  405. X        for (j=0; j <= ((int) p->length); j++)
  406. X          *q++=image->colormap[p->index].red;
  407. X        p++;
  408. X      }
  409. X      break;
  410. X    }
  411. X    case '6':
  412. X    {
  413. X      /*
  414. X        Convert image to a PNM image.
  415. X      */
  416. X      (void) fprintf(image->file,"%d\n",MaxRGB);
  417. X      for (i=0; i < image->packets; i++)
  418. X      {
  419. X        for (j=0; j <= ((int) p->length); j++)
  420. X        {
  421. X          *q++=p->red;
  422. X          *q++=p->green;
  423. X          *q++=p->blue;
  424. X        }
  425. X        p++;
  426. X      }
  427. X      break;
  428. X    }
  429. X  }
  430. X  count=fwrite((char *) pixels,1,(int) packets,image->file);
  431. X  if (count != packets)
  432. X    {
  433. X      Warning("unable to write image","file write error");
  434. X      return(False);
  435. X    }
  436. X  (void) free((char *) pixels);
  437. X  CloseImage(image);
  438. X  return(True);
  439. }
  440. X
  441. /*
  442. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  443. %                                                                             %
  444. %                                                                             %
  445. %                                                                             %
  446. %   W r i t e R G B I m a g e                                                 %
  447. %                                                                             %
  448. %                                                                             %
  449. %                                                                             %
  450. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  451. %
  452. %  Function WriteRGBImage writes an image to a file on disk in red, green,
  453. %  blue rasterfile format.
  454. %
  455. %  The format of the WriteRGBImage routine is:
  456. %
  457. %      status=WriteRGBImage(image)
  458. %
  459. %  A description of each parameter follows.
  460. %
  461. %    o status: Function WriteImage return True if the image is written.
  462. %      False is returned is there is a memory shortage or if the image file
  463. %      fails to write.
  464. %
  465. %    o image:  A pointer to a Image structure.
  466. %
  467. %
  468. */
  469. static unsigned int WriteRGBImage(image)
  470. Image
  471. X  *image;
  472. {
  473. X  register int
  474. X    i,
  475. X    j;
  476. X
  477. X  register RunlengthPacket
  478. X    *p;
  479. X
  480. X  register unsigned char
  481. X    *q;
  482. X
  483. X  unsigned char
  484. X    *pixels;
  485. X
  486. X  /*
  487. X    Open output image file.
  488. X  */
  489. X  OpenImage(image,"w");
  490. X  if (image->file == (FILE *) NULL)
  491. X    {
  492. X      Warning("unable to open file",image->filename);
  493. X      return(False);
  494. X    }
  495. X  /*
  496. X    Convert MIFF to RGB raster pixels.
  497. X  */
  498. X  pixels=(unsigned char *)
  499. X    malloc(3*image->columns*image->rows*sizeof(unsigned char));
  500. X  if (pixels == (unsigned char *) NULL)
  501. X    {
  502. X      Warning("unable to allocate memory",(char *) NULL);
  503. X      return(False);
  504. X    }
  505. X  p=image->pixels;
  506. X  q=pixels;
  507. X  for (i=0; i < image->packets; i++)
  508. X  {
  509. X    for (j=0; j <= ((int) p->length); j++)
  510. X    {
  511. X      *q++=p->red;
  512. X      *q++=p->green;
  513. X      *q++=p->blue;
  514. X    }
  515. X    p++;
  516. X  }
  517. X  (void) fwrite((char *) pixels,sizeof(unsigned char),
  518. X    (int) (3*image->columns*image->rows),image->file);
  519. X  (void) free((char *) pixels);
  520. X  CloseImage(image);
  521. X  return(True);
  522. }
  523. X
  524. #ifdef AlienTIFF
  525. /*
  526. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  527. %                                                                             %
  528. %                                                                             %
  529. %                                                                             %
  530. %   W r i t e T I F F I m a g e                                               %
  531. %                                                                             %
  532. %                                                                             %
  533. %                                                                             %
  534. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  535. %
  536. %  Function WriteTIFFImage writes a TIFF image to a file.
  537. %
  538. %  The format of the WriteTIFFImage routine is:
  539. %
  540. %      status=WriteTIFFImage(image,verbose)
  541. %
  542. %  A description of each parameter follows:
  543. %
  544. %    o status:  Function WriteTIFFImage return True if the image is written.
  545. %      False is returned is there is of a memory shortage or if the image
  546. %      file cannot be opened for writing.
  547. %
  548. %    o image:  A pointer to a Image structure.
  549. %
  550. %    o  verbose:  A value greater than zero prints detailed information about
  551. %       the image.
  552. %
  553. %
  554. */
  555. static unsigned int WriteTIFFImage(image,verbose)
  556. Image
  557. X  *image;
  558. X
  559. unsigned int
  560. X  verbose;
  561. {
  562. X  register RunlengthPacket
  563. X    *p;
  564. X
  565. X  register int
  566. X    i,
  567. X    j,
  568. X    x,
  569. X    y;
  570. X
  571. X  register unsigned char
  572. X    *q;
  573. X
  574. X  TIFF
  575. X    *file;
  576. X
  577. X  unsigned char
  578. X    *scanline;
  579. X
  580. X  unsigned short
  581. X    photometric,
  582. X    rows_per_strip;
  583. X
  584. X  /*
  585. X    Open TIFF file.
  586. X  */
  587. X  file=TIFFOpen(image->filename,"w");
  588. X  if (file == (TIFF *) NULL)
  589. X    return(False);
  590. X  /*
  591. X    Initialize TIFF fields.
  592. X  */
  593. X  TIFFSetField(file,TIFFTAG_DOCUMENTNAME,image->filename);
  594. X  TIFFSetField(file,TIFFTAG_SOFTWARE,"ImageMagick");
  595. X  if (image->comments != (char *) NULL)
  596. X    TIFFSetField(file,TIFFTAG_IMAGEDESCRIPTION,image->comments);
  597. X  if ((image->class == DirectClass) || (image->colors > 256))
  598. X    {
  599. X      photometric=PHOTOMETRIC_RGB;
  600. X      TIFFSetField(file,TIFFTAG_BITSPERSAMPLE,8);
  601. X      TIFFSetField(file,TIFFTAG_SAMPLESPERPIXEL,(image->alpha ? 4 : 3));
  602. X    }
  603. X  else
  604. X    {
  605. X      /*
  606. X        Determine if image is gray scale.
  607. X      */
  608. X      photometric=PHOTOMETRIC_MINISBLACK;
  609. X      for (i=0; i < image->colors; i++)
  610. X        if ((image->colormap[i].red != image->colormap[i].green) ||
  611. X            (image->colormap[i].green != image->colormap[i].blue))
  612. X          {
  613. X            photometric=PHOTOMETRIC_PALETTE;
  614. X            break;
  615. X          }
  616. X      if ((image->colors == 2) && (photometric == PHOTOMETRIC_MINISBLACK))
  617. X        TIFFSetField(file,TIFFTAG_BITSPERSAMPLE,1);
  618. X      else
  619. X        TIFFSetField(file,TIFFTAG_BITSPERSAMPLE,8);
  620. X      TIFFSetField(file,TIFFTAG_SAMPLESPERPIXEL,1);
  621. X    }
  622. X  TIFFSetField(file,TIFFTAG_PHOTOMETRIC,photometric);
  623. X  TIFFSetField(file,TIFFTAG_IMAGELENGTH,image->rows);
  624. X  TIFFSetField(file,TIFFTAG_IMAGEWIDTH,image->columns);
  625. X  TIFFSetField(file,TIFFTAG_FILLORDER,FILLORDER_MSB2LSB);
  626. X  TIFFSetField(file,TIFFTAG_ORIENTATION,ORIENTATION_TOPLEFT);
  627. X  TIFFSetField(file,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);
  628. X  TIFFSetField(file,TIFFTAG_COMPRESSION,COMPRESSION_LZW);
  629. X  if (image->compression == NoCompression)
  630. X    TIFFSetField(file,TIFFTAG_COMPRESSION,COMPRESSION_NONE);
  631. X  rows_per_strip=8192/TIFFScanlineSize(file);
  632. X  if (rows_per_strip == 0)
  633. X    rows_per_strip=1;
  634. X  TIFFSetField(file,TIFFTAG_ROWSPERSTRIP,rows_per_strip);
  635. X  scanline=(unsigned char *) malloc(TIFFScanlineSize(file));
  636. X  if (scanline == (unsigned char *) NULL)
  637. X    {
  638. X      Warning("memory allocation error",(char *) NULL);
  639. X      return(False);
  640. X    }
  641. X  p=image->pixels;
  642. X  q=scanline;
  643. X  x=0;
  644. X  y=0;
  645. X  if (photometric == PHOTOMETRIC_RGB)
  646. X    for (i=0; i < image->packets; i++)
  647. X    {
  648. X      for (j=0; j <= (int) p->length; j++)
  649. X      {
  650. X        /*
  651. X          Convert DirectClass packets to contiguous RGB scanlines.
  652. X        */
  653. X        *q++=p->red;
  654. X        *q++=p->green;
  655. X        *q++=p->blue;
  656. X        if (image->alpha)
  657. X          *q++=(unsigned char) p->index;
  658. X        x++;
  659. X        if (x == image->columns)
  660. X          {
  661. X            if (TIFFWriteScanline(file,scanline,y,0) < 0)
  662. X              break;
  663. X            q=scanline;
  664. X            x=0;
  665. X            y++;
  666. X          }
  667. X      }
  668. X      p++;
  669. X    }
  670. X  else
  671. X    if (photometric == PHOTOMETRIC_PALETTE)
  672. X      {
  673. X        unsigned short
  674. X          blue[256],
  675. X          green[256],
  676. X          red[256];
  677. X
  678. X        /*
  679. X          Initialize TIFF colormap.
  680. X        */
  681. X        for (i=0; i < image->colors; i++)
  682. X        {
  683. X          red[i]=(unsigned short)
  684. X            ((image->colormap[i].red*65535)/(unsigned int) MaxRGB);
  685. X          green[i]=(unsigned short)
  686. X            ((image->colormap[i].green*65535)/(unsigned int) MaxRGB);
  687. X          blue[i]=(unsigned short)
  688. X            ((image->colormap[i].blue*65535)/(unsigned int) MaxRGB);
  689. X        }
  690. X        TIFFSetField(file,TIFFTAG_COLORMAP,red,green,blue);
  691. X        /*
  692. X          Convert PseudoClass packets to contiguous colormap indexed scanlines.
  693. X        */
  694. X        for (i=0; i < image->packets; i++)
  695. X        {
  696. X          for (j=0; j <= (int) p->length; j++)
  697. X          {
  698. X            *q++=(unsigned char) p->index;
  699. X            x++;
  700. X            if (x == image->columns)
  701. X              {
  702. X                if (TIFFWriteScanline(file,scanline,y,0) < 0)
  703. X                  break;
  704. X                q=scanline;
  705. X                x=0;
  706. X                y++;
  707. X              }
  708. X          }
  709. X          p++;
  710. X        }
  711. X      }
  712. X    else
  713. X      if (image->colors > 2)
  714. X        for (i=0; i < image->packets; i++)
  715. X        {
  716. X          for (j=0; j <= (int) p->length; j++)
  717. X          {
  718. X            /*
  719. X              Convert PseudoClass packets to contiguous grayscale scanlines.
  720. X            */
  721. X            *q++=(unsigned char) image->colormap[p->index].red;
  722. X            x++;
  723. X            if (x == image->columns)
  724. X              {
  725. X                if (TIFFWriteScanline(file,scanline,y,0) < 0)
  726. X                  break;
  727. X                q=scanline;
  728. X                x=0;
  729. X                y++;
  730. X              }
  731. X          }
  732. X          p++;
  733. X        }
  734. X      else
  735. X        {
  736. X          register unsigned char
  737. X            bit,
  738. X            byte,
  739. X            polarity;
  740. X
  741. X          /*
  742. X            Convert PseudoClass packets to contiguous monochrome scanlines.
  743. X          */
  744. X          polarity=(Intensity(image->colormap[0]) >
  745. X            Intensity(image->colormap[1]) ? 0 : 1);
  746. X          bit=0;
  747. X          byte=0;
  748. X          x=0;
  749. X          for (i=0; i < image->packets; i++)
  750. X          {
  751. X            for (j=0; j <= (int) p->length; j++)
  752. X            {
  753. X              byte<<=1;
  754. X              if (p->index == polarity)
  755. X                byte|=0x01;
  756. X              bit++;
  757. X              if (bit == 8)
  758. X                {
  759. X                  *q++=byte;
  760. X                  bit=0;
  761. X                  byte=0;
  762. X                }
  763. X              x++;
  764. X              if (x == image->columns)
  765. X                {
  766. X                  /*
  767. X                    Advance to the next scanline.
  768. X                  */
  769. X                  if (bit > 0)
  770. X                    *q++=byte << (8-bit);
  771. X                  if (TIFFWriteScanline(file,scanline,y,0) < 0)
  772. X                    break;
  773. X                  q=scanline;
  774. X                  bit=0;
  775. X                  byte=0;
  776. X                  x=0;
  777. X                  y++;
  778. X               }
  779. X            }
  780. X            p++;
  781. X          }
  782. X        }
  783. X  (void) free((char *) scanline);
  784. X  (void) TIFFFlushData(file);
  785. X  if (verbose)
  786. X    TIFFPrintDirectory(file,stderr,False);
  787. X  (void) TIFFClose(file);
  788. X  return(True);
  789. }
  790. #else
  791. static unsigned int WriteTIFFImage(image,verbose)
  792. Image
  793. X  *image;
  794. X
  795. unsigned int
  796. X  verbose;
  797. {
  798. X  Warning("TIFF library is not available",image->filename);
  799. X  return(WriteImage(image));
  800. }
  801. #endif
  802. X
  803. /*
  804. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  805. %                                                                             %
  806. %                                                                             %
  807. %                                                                             %
  808. %   W r i t e S U N I m a g e                                                 %
  809. %                                                                             %
  810. %                                                                             %
  811. %                                                                             %
  812. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  813. %
  814. %  Function WriteSUNImage writes an image to a file on disk in SUN
  815. %  rasterfile format.
  816. %
  817. %  The format of the WriteSUNImage routine is:
  818. %
  819. %      status=WriteSUNImage(image)
  820. %
  821. %  A description of each parameter follows.
  822. %
  823. %    o status: Function WriteImage return True if the image is written.
  824. %      False is returned is there is a memory shortage or if the image file
  825. %      fails to write.
  826. %
  827. %    o image:  A pointer to a Image structure.
  828. %
  829. %
  830. */
  831. static unsigned int WriteSUNImage(image)
  832. Image
  833. X  *image;
  834. {
  835. #define RMT_EQUAL_RGB  1
  836. #define RMT_NONE  0
  837. #define RMT_RAW  2
  838. #define RT_STANDARD  1
  839. #define RT_FORMAT_RGB  3
  840. X
  841. X  typedef struct SUN
  842. X  {
  843. X    int
  844. X      magic,
  845. X      width,
  846. X      height,
  847. X      depth,
  848. X      length,
  849. X      type,
  850. X      maptype,
  851. X      maplength;
  852. X  } SUN;
  853. X
  854. X  SUN
  855. X    sun_header;
  856. X
  857. X  register int
  858. X    i,
  859. X    j,
  860. X    x;
  861. X
  862. X  register RunlengthPacket
  863. X    *p;
  864. X
  865. X  register unsigned char
  866. X    *q;
  867. X
  868. X  unsigned char
  869. X    *sun_pixels;
  870. X
  871. X  unsigned int
  872. X    grayscale;
  873. X
  874. X  unsigned long
  875. X    lsb_first;
  876. X
  877. X  /*
  878. X    Open output image file.
  879. X  */
  880. X  OpenImage(image,"w");
  881. X  if (image->file == (FILE *) NULL)
  882. X    {
  883. X      Warning("unable to open file",image->filename);
  884. X      return(False);
  885. X    }
  886. X  /*
  887. X    Initialize SUN raster file header.
  888. X  */
  889. X  sun_header.magic=0x59a66a95;
  890. X  sun_header.width=image->columns;
  891. X  sun_header.height=image->rows;
  892. X  sun_header.type=(image->class == DirectClass ? RT_FORMAT_RGB : RT_STANDARD);
  893. X  sun_header.maptype=RMT_NONE;
  894. X  sun_header.maplength=0;
  895. X  if ((image->class == DirectClass) || (image->colors > 256))
  896. X    {
  897. X      /*
  898. X        Full color sun raster.
  899. X      */
  900. X      sun_header.depth=(image->alpha ? 32 : 24);
  901. X      sun_header.length=image->columns*image->rows*(image->alpha ? 4 : 3);
  902. X      sun_header.length+=image->columns % 2 ? image->rows : 0;
  903. X    }
  904. X  else
  905. X    {
  906. X      /*
  907. X        Determine if image is grayscale.
  908. X      */
  909. X      grayscale=True;
  910. X      for (i=0; i < image->colors; i++)
  911. X        if ((image->colormap[i].red != image->colormap[i].green) ||
  912. X            (image->colormap[i].green != image->colormap[i].blue))
  913. X          {
  914. X            grayscale=False;
  915. X            break;
  916. X          }
  917. X      if ((image->colors > 2) || !grayscale)
  918. X        {
  919. X          /*
  920. X            Colormapped sun raster.
  921. X          */
  922. X          sun_header.depth=8;
  923. X          sun_header.length=image->columns*image->rows;
  924. X          sun_header.maptype=RMT_EQUAL_RGB;
  925. X          sun_header.maplength=image->colors*3;
  926. X          sun_header.length+=image->columns % 2 ? image->rows : 0;
  927. X        }
  928. X      else
  929. X        {
  930. X          /*
  931. X            Monochrome sun raster.
  932. X          */
  933. X          sun_header.depth=1;
  934. X          sun_header.length=((image->columns+7) >> 3)*image->rows;
  935. X          sun_header.length+=((image->columns/8)+(image->columns % 8 ? 1 : 0)) %
  936. X            2 ? image->rows : 0;
  937. X        }
  938. X    }
  939. X  /*
  940. X    Ensure the SUN raster header byte-order is most-significant byte first.
  941. X  */
  942. X  lsb_first=1;
  943. X  if ((*(char *) &lsb_first) == 0)
  944. X    (void) fwrite((char *) &sun_header,sizeof(sun_header),1,image->file);
  945. X  else
  946. X    {
  947. X      SUN
  948. X        reverse_header;
  949. X
  950. X      reverse_header=sun_header;
  951. X      MSBFirstOrderLong((char *) &reverse_header,sizeof(reverse_header));
  952. X      (void) fwrite((char *) &reverse_header,sizeof(reverse_header),1,
  953. X        image->file);
  954. X    }
  955. X  /*
  956. X    Convert MIFF to SUN raster pixels.
  957. X  */
  958. X  sun_pixels=(unsigned char *) malloc(sun_header.length*sizeof(unsigned char));
  959. X  if (sun_pixels == (unsigned char *) NULL)
  960. X    {
  961. X      Warning("unable to allocate memory",(char *) NULL);
  962. X      return(False);
  963. X    }
  964. X  p=image->pixels;
  965. X  q=sun_pixels;
  966. X  x=0;
  967. X  if ((image->class == DirectClass) || (image->colors > 256))
  968. X    {
  969. X      /*
  970. X        Convert DirectClass packet to SUN RGB pixel.
  971. X      */
  972. X      for (i=0; i < image->packets; i++)
  973. X      {
  974. X        for (j=0; j <= (int) p->length; j++)
  975. X        {
  976. X          if (image->alpha)
  977. X            *q++=(unsigned char) p->index;
  978. X          *q++=p->red;
  979. X          *q++=p->green;
  980. X          *q++=p->blue;
  981. X          x++;
  982. X          if (x == image->columns)
  983. X            {
  984. X              if ((image->columns % 2) != 0)
  985. X                q++;  /* pad scanline */
  986. X              x=0;
  987. X            }
  988. X        }
  989. X        p++;
  990. X      }
  991. X    }
  992. X  else
  993. X    if ((image->colors > 2) || !grayscale)
  994. X      {
  995. X        unsigned char
  996. X          *sun_colormap;
  997. X
  998. X        /*
  999. X           Dump colormap to file.
  1000. X        */
  1001. X        sun_colormap=(unsigned char *)
  1002. X          malloc(sun_header.maplength*sizeof(unsigned char));
  1003. X        if (sun_colormap == (unsigned char *) NULL)
  1004. X          {
  1005. X            Warning("unable to allocate memory",(char *) NULL);
  1006. X            return(False);
  1007. X          }
  1008. X        q=sun_colormap;
  1009. X        for (i=0; i < image->colors; i++)
  1010. X          *q++=image->colormap[i].red;
  1011. X        for (i=0; i < image->colors; i++)
  1012. X          *q++=image->colormap[i].green;
  1013. X        for (i=0; i < image->colors; i++)
  1014. X          *q++=image->colormap[i].blue;
  1015. X        (void) fwrite((char *) sun_colormap,sizeof(char),sun_header.maplength,
  1016. X          image->file);
  1017. X        (void) free((char *) sun_colormap);
  1018. X        /*
  1019. X          Convert PseudoClass packet to SUN colormapped pixel.
  1020. X        */
  1021. X        q=sun_pixels;
  1022. X        for (i=0; i < image->packets; i++)
  1023. X        {
  1024. X          for (j=0; j <= (int) p->length; j++)
  1025. X          {
  1026. X            *q++=p->index;
  1027. X            x++;
  1028. X            if (x == image->columns)
  1029. X              {
  1030. X                if ((image->columns % 2) != 0)
  1031. X                  q++;  /* pad scanline */
  1032. X                x=0;
  1033. X              }
  1034. X          }
  1035. X          p++;
  1036. X        }
  1037. X      }
  1038. X    else
  1039. X      {
  1040. X        register unsigned char
  1041. X          bit,
  1042. X          byte,
  1043. X          polarity;
  1044. X
  1045. X        /*
  1046. X          Convert PseudoClass image to a SUN monochrome image.
  1047. X        */
  1048. X        polarity=(Intensity(image->colormap[0]) <
  1049. X          Intensity(image->colormap[1]) ? 0 : 1);
  1050. X        bit=0;
  1051. X        byte=0;
  1052. X        for (i=0; i < image->packets; i++)
  1053. X        {
  1054. X          for (j=0; j <= (int) p->length; j++)
  1055. X          {
  1056. X            byte<<=1;
  1057. X            if (p->index == polarity)
  1058. X              byte|=0x01;
  1059. X            bit++;
  1060. X            if (bit == 8)
  1061. X              {
  1062. X                *q++=byte;
  1063. X                bit=0;
  1064. X                byte=0;
  1065. X              }
  1066. X            x++;
  1067. X            if (x == image->columns)
  1068. X              {
  1069. X                /*
  1070. X                  Advance to the next scanline.
  1071. X                */
  1072. X                if (bit > 0)
  1073. X                  *q++=byte << (8-bit);
  1074. X                if ((((image->columns/8)+
  1075. X                    (image->columns % 8 ? 1 : 0)) % 2) != 0)
  1076. X                  q++;  /* pad scanline */
  1077. X                bit=0;
  1078. X                byte=0;
  1079. X                x=0;
  1080. X             }
  1081. X          }
  1082. X          p++;
  1083. X        }
  1084. X      }
  1085. X  (void) fwrite((char *) sun_pixels,sizeof(char),sun_header.length,image->file);
  1086. X  (void) free((char *) sun_pixels);
  1087. X  CloseImage(image);
  1088. X  return(True);
  1089. }
  1090. X
  1091. /*
  1092. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1093. %                                                                             %
  1094. %                                                                             %
  1095. %                                                                             %
  1096. %   W r i t e X B M I m a g e                                                 %
  1097. %                                                                             %
  1098. %                                                                             %
  1099. %                                                                             %
  1100. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1101. %
  1102. %  Procedure WriteXBMImage writes an image to a file on disk in X
  1103. %  bitmap format.
  1104. %
  1105. %  The format of the WriteXBMImage routine is:
  1106. %
  1107. %      status=WriteXBMImage(image)
  1108. %
  1109. %  A description of each parameter follows.
  1110. %
  1111. %    o status: Function WriteImage return True if the image is written.
  1112. %      False is returned is there is a memory shortage or if the image file
  1113. %      fails to write.
  1114. %
  1115. %    o image:  A pointer to a Image structure.
  1116. %
  1117. %
  1118. */
  1119. static unsigned int WriteXBMImage(image)
  1120. Image
  1121. X  *image;
  1122. {
  1123. X  char
  1124. X    name[2048];
  1125. X
  1126. X  register int
  1127. X    i,
  1128. X    j,
  1129. X    x;
  1130. X
  1131. X  register char
  1132. X    *q;
  1133. X
  1134. X  register RunlengthPacket
  1135. X    *p;
  1136. X
  1137. X  register unsigned char
  1138. X    bit,
  1139. X    byte;
  1140. X
  1141. X  register unsigned short
  1142. X    polarity;
  1143. X
  1144. X  unsigned int
  1145. X    count;
  1146. X
  1147. X  /*
  1148. X    Open output image file.
  1149. X  */
  1150. X  OpenImage(image,"w");
  1151. X  if (image->file == (FILE *) NULL)
  1152. X    {
  1153. X      Warning("unable to open file",image->filename);
  1154. X      return(False);
  1155. X    }
  1156. X  /*
  1157. X    Write X bitmap header.
  1158. X  */
  1159. X  (void) strcpy(name,image->filename);
  1160. X  q=name;
  1161. X  while ((*q != '.') && (*q != '\0'))
  1162. X    q++;
  1163. X  if (*q == '.')
  1164. X    *q='\0';
  1165. X  (void) fprintf(image->file,"#define %s_width %u\n",name,image->columns);
  1166. X  (void) fprintf(image->file,"#define %s_height %u\n",name,image->rows);
  1167. X  (void) fprintf(image->file,"static char %s_bits[] = {\n",name);
  1168. X  (void) fprintf(image->file," ");
  1169. X  /*
  1170. X    Convert MIFF to X bitmap pixels.
  1171. X  */
  1172. X  QuantizeImage(image,2,8,False,GRAYColorspace,True);
  1173. X  p=image->pixels;
  1174. X  polarity=(Intensity(image->colormap[0]) >
  1175. X    Intensity(image->colormap[1]) ? 0 : 1);
  1176. X  bit=0;
  1177. X  byte=0;
  1178. X  count=0;
  1179. X  x=0;
  1180. X  (void) fprintf(image->file," ");
  1181. X  for (i=0; i < image->packets; i++)
  1182. X  {
  1183. X    for (j=0; j <= ((int) p->length); j++)
  1184. X    {
  1185. X      byte>>=1;
  1186. X      if (p->index == polarity)
  1187. X        byte|=0x80;
  1188. X      bit++;
  1189. X      if (bit == 8)
  1190. X        {
  1191. X          /*
  1192. X            Write a bitmap byte to the image file.
  1193. X          */
  1194. X          (void) fprintf(image->file,"0x%02x, ",~byte & 0xff);
  1195. X          count++;
  1196. X          if (count == 12)
  1197. X            {
  1198. X              (void) fprintf(image->file,"\n  ");
  1199. X              count=0;
  1200. X            };
  1201. X          bit=0;
  1202. X          byte=0;
  1203. X        }
  1204. X      x++;
  1205. X      if (x == image->columns)
  1206. X        {
  1207. X          if (bit > 0)
  1208. X            {
  1209. X              /*
  1210. X                Write a bitmap byte to the image file.
  1211. X              */
  1212. X              byte>>=(8-bit);
  1213. X              (void) fprintf(image->file,"0x%02x, ",~byte & 0xff);
  1214. X              count++;
  1215. X              if (count == 12)
  1216. X                {
  1217. X                  (void) fprintf(image->file,"\n  ");
  1218. X                  count=0;
  1219. X                };
  1220. X              bit=0;
  1221. X              byte=0;
  1222. X            };
  1223. X          x=0;
  1224. X        }
  1225. X    }
  1226. X    p++;
  1227. X  }
  1228. X  (void) fprintf(image->file,"};\n");
  1229. X  CloseImage(image);
  1230. X  return(True);
  1231. }
  1232. X
  1233. /*
  1234. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1235. %                                                                             %
  1236. %                                                                             %
  1237. %                                                                             %
  1238. %   W r i t e Y U V I m a g e                                                 %
  1239. %                                                                             %
  1240. %                                                                             %
  1241. %                                                                             %
  1242. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1243. %
  1244. %  Function WriteYUVImage writes an image to a file on disk in Y, U, and V
  1245. %  rasterfile format.  U and V, normally -0.5 through 0.5, is normalized to
  1246. %  the range 0 through 255 to fit within a byte.
  1247. %
  1248. %  The format of the WriteYUVImage routine is:
  1249. %
  1250. %      status=WriteYUVImage(image)
  1251. %
  1252. %  A description of each parameter follows.
  1253. %
  1254. %    o status: Function WriteImage return True if the image is written.
  1255. %      False is returned is there is a memory shortage or if the image file
  1256. %      fails to write.
  1257. %
  1258. %    o image:  A pointer to a Image structure.
  1259. %
  1260. %
  1261. */
  1262. static unsigned int WriteYUVImage(image)
  1263. Image
  1264. X  *image;
  1265. {
  1266. X  register int
  1267. X    i,
  1268. X    j;
  1269. X
  1270. X  register RunlengthPacket
  1271. X    *p;
  1272. X
  1273. X  register unsigned char
  1274. X    *q;
  1275. X
  1276. X  unsigned char
  1277. X    *pixels;
  1278. X
  1279. X  /*
  1280. X    Open output image file.
  1281. X  */
  1282. X  OpenImage(image,"w");
  1283. X  if (image->file == (FILE *) NULL)
  1284. X    {
  1285. X      Warning("unable to open file",image->filename);
  1286. X      return(False);
  1287. X    }
  1288. X  /*
  1289. X    Convert MIFF to YUV raster pixels.
  1290. X  */
  1291. X  pixels=(unsigned char *)
  1292. X    malloc(3*image->columns*image->rows*sizeof(unsigned char));
  1293. X  if (pixels == (unsigned char *) NULL)
  1294. X    {
  1295. X      Warning("unable to allocate memory",(char *) NULL);
  1296. X      return(False);
  1297. X    }
  1298. X  RGBTransformImage(image,YUVColorspace);
  1299. X  p=image->pixels;
  1300. X  q=pixels;
  1301. X  for (i=0; i < image->packets; i++)
  1302. X  {
  1303. X    for (j=0; j <= ((int) p->length); j++)
  1304. X    {
  1305. X      *q++=p->red;
  1306. X      *q++=p->green;
  1307. X      *q++=p->blue;
  1308. X    }
  1309. X    p++;
  1310. X  }
  1311. X  (void) fwrite((char *) pixels,sizeof(unsigned char),
  1312. X    (int) (3*image->columns*image->rows),image->file);
  1313. X  (void) free((char *) pixels);
  1314. X  TransformRGBImage(image,YUVColorspace);
  1315. X  CloseImage(image);
  1316. X  return(True);
  1317. }
  1318. X
  1319. /*
  1320. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1321. %                                                                             %
  1322. %                                                                             %
  1323. %                                                                             %
  1324. %   W r i t e X W D I m a g e                                                 %
  1325. %                                                                             %
  1326. %                                                                             %
  1327. %                                                                             %
  1328. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1329. %
  1330. %  Function WriteXWDImage writes an image to a file on disk in XWD
  1331. %  rasterfile format.
  1332. %
  1333. %  The format of the WriteXWDImage routine is:
  1334. %
  1335. %      status=WriteXWDImage(image)
  1336. %
  1337. %  A description of each parameter follows.
  1338. %
  1339. %    o status: Function WriteImage return True if the image is written.
  1340. %      False is returned is there is a memory shortage or if the image file
  1341. %      fails to write.
  1342. %
  1343. %    o image:  A pointer to a Image structure.
  1344. %
  1345. %
  1346. */
  1347. static unsigned int WriteXWDImage(image)
  1348. Image
  1349. X  *image;
  1350. {
  1351. #include "XWDFile.h"
  1352. X
  1353. X  int
  1354. X    x;
  1355. X
  1356. X  register int
  1357. X    i,
  1358. X    j;
  1359. X
  1360. X  register RunlengthPacket
  1361. X    *p;
  1362. X
  1363. X  register unsigned char
  1364. X    *q;
  1365. X
  1366. X  unsigned char
  1367. X    *xwd_pixels;
  1368. X
  1369. X  unsigned int
  1370. X    scanline_pad;
  1371. X
  1372. X  unsigned long
  1373. X    lsb_first,
  1374. X    packets;
  1375. X
  1376. X  XWDFileHeader
  1377. X    xwd_header;
  1378. X
  1379. X  /*
  1380. X    Open output image file.
  1381. X  */
  1382. X  OpenImage(image,"w");
  1383. X  if (image->file == (FILE *) NULL)
  1384. X    {
  1385. X      Warning("unable to open file",image->filename);
  1386. X      return(False);
  1387. X    }
  1388. X  /*
  1389. X    Initialize XWD file header.
  1390. X  */
  1391. X  xwd_header.header_size=sizeof(xwd_header)+strlen(image->filename)+1;
  1392. X  xwd_header.file_version=(unsigned long) XWD_FILE_VERSION;
  1393. X  xwd_header.pixmap_format=(unsigned long) ZPixmap;
  1394. X  xwd_header.pixmap_depth=(unsigned long)
  1395. X    (image->class == DirectClass ? 24 : 8);
  1396. X  xwd_header.pixmap_width=(unsigned long) image->columns;
  1397. X  xwd_header.pixmap_height=(unsigned long) image->rows;
  1398. X  xwd_header.xoffset=(unsigned long) 0;
  1399. X  xwd_header.byte_order=(unsigned long) MSBFirst;
  1400. X  xwd_header.bitmap_unit=(unsigned long) (image->class == DirectClass ? 32 : 8);
  1401. X  xwd_header.bitmap_bit_order=(unsigned long) MSBFirst;
  1402. X  xwd_header.bitmap_pad=(unsigned long) (image->class == DirectClass ? 32 : 8);
  1403. X  xwd_header.bits_per_pixel=(unsigned long)
  1404. X    (image->class == DirectClass ? 24 : 8);
  1405. X  xwd_header.bytes_per_line=(unsigned long) ((((xwd_header.bits_per_pixel*
  1406. X    xwd_header.pixmap_width)+((xwd_header.bitmap_pad)-1))/
  1407. X    (xwd_header.bitmap_pad))*((xwd_header.bitmap_pad) >> 3));
  1408. X  xwd_header.visual_class=(unsigned long)
  1409. X    (image->class == DirectClass ? DirectColor : PseudoColor);
  1410. X  xwd_header.red_mask=(unsigned long)
  1411. X    (image->class == DirectClass ? 0xff0000 : 0);
  1412. X  xwd_header.green_mask=(unsigned long)
  1413. X    (image->class == DirectClass ? 0xff00 : 0);
  1414. X  xwd_header.blue_mask=(unsigned long) (image->class == DirectClass ? 0xff : 0);
  1415. X  xwd_header.bits_per_rgb=(unsigned long)
  1416. X    (image->class == DirectClass ? 24 : 8);
  1417. X  xwd_header.colormap_entries=(unsigned long)
  1418. X    (image->class == DirectClass ? 256 : image->colors);
  1419. X  xwd_header.ncolors=(image->class == DirectClass ? 0 : image->colors);
  1420. X  xwd_header.window_width=(unsigned long) image->columns;
  1421. X  xwd_header.window_height=(unsigned long) image->rows;
  1422. X  xwd_header.window_x=0;
  1423. X  xwd_header.window_y=0;
  1424. X  xwd_header.window_bdrwidth=(unsigned long) 0;
  1425. X  /*
  1426. X    Ensure the xwd_header byte-order is most-significant byte first.
  1427. X  */
  1428. X  lsb_first=1;
  1429. X  if (*(char *) &lsb_first)
  1430. X    MSBFirstOrderLong((char *) &xwd_header,sizeof(xwd_header));
  1431. X  (void) fwrite((char *) &xwd_header,sizeof(xwd_header),1,image->file);
  1432. X  (void) fwrite((char *) image->filename,1,strlen(image->filename)+1,
  1433. X    image->file);
  1434. X  if (image->class == PseudoClass)
  1435. X    {
  1436. X      XColor
  1437. X        *colors;
  1438. X
  1439. X      /*
  1440. X         Dump colormap to file.
  1441. X      */
  1442. X      colors=(XColor *) malloc(image->colors*sizeof(XColor));
  1443. X      if (colors == (XColor *) NULL)
  1444. X        {
  1445. X          Warning("unable to allocate memory",(char *) NULL);
  1446. X          return(False);
  1447. X        }
  1448. X      for (i=0; i < image->colors; i++)
  1449. X      {
  1450. X        colors[i].pixel=i;
  1451. X        colors[i].red=image->colormap[i].red << 8;
  1452. X        colors[i].green=image->colormap[i].green << 8;
  1453. X        colors[i].blue=image->colormap[i].blue << 8;
  1454. X        colors[i].flags=DoRed | DoGreen | DoBlue;
  1455. X        colors[i].pad=0;
  1456. X        if (*(char *) &lsb_first)
  1457. X          {
  1458. X            MSBFirstOrderLong((char *) &colors[i].pixel,sizeof(long));
  1459. X            MSBFirstOrderShort((char *) &colors[i].red,3*sizeof(short));
  1460. X          }
  1461. X      }
  1462. X      (void) fwrite((char *) colors,sizeof(XColor),(int) image->colors,
  1463. X        image->file);
  1464. X      (void) free((char *) colors);
  1465. X    }
  1466. X  /*
  1467. X    Convert MIFF to XWD raster pixels.
  1468. X  */
  1469. X  packets=xwd_header.bytes_per_line*xwd_header.pixmap_height;
  1470. X  xwd_pixels=(unsigned char *)
  1471. X    malloc((unsigned int) packets*sizeof(unsigned char));
  1472. X  if (xwd_pixels == (unsigned char *) NULL)
  1473. X    {
  1474. X      Warning("unable to allocate memory",(char *) NULL);
  1475. X      return(False);
  1476. X    }
  1477. X  scanline_pad=(unsigned int) (xwd_header.bytes_per_line-
  1478. X    ((xwd_header.pixmap_width*xwd_header.bits_per_pixel) >> 3));
  1479. X  x=0;
  1480. X  p=image->pixels;
  1481. X  q=xwd_pixels;
  1482. X  for (i=0; i < image->packets; i++)
  1483. X  {
  1484. X    for (j=0; j <= ((int) p->length); j++)
  1485. X    {
  1486. X      if (image->class == PseudoClass)
  1487. X        *q++=p->index;
  1488. X      else
  1489. X        {
  1490. X          *q++=p->red;
  1491. X          *q++=p->green;
  1492. X          *q++=p->blue;
  1493. X        }
  1494. X      x++;
  1495. X      if (x == image->columns)
  1496. X        {
  1497. X          q+=scanline_pad;
  1498. X          x=0;
  1499. X        }
  1500. X    }
  1501. X    p++;
  1502. X  }
  1503. X  /*
  1504. X    Dump pixels to file.
  1505. X  */
  1506. X  (void) fwrite((char *) xwd_pixels,sizeof(char),(int) packets,image->file);
  1507. X  (void) free((char *) xwd_pixels);
  1508. X  CloseImage(image);
  1509. X  return(True);
  1510. }
  1511. X
  1512. /*
  1513. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1514. %                                                                             %
  1515. %                                                                             %
  1516. %                                                                             %
  1517. %   G e t A l i e n I n f o                                                   %
  1518. %                                                                             %
  1519. %                                                                             %
  1520. %                                                                             %
  1521. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1522. %
  1523. %  Function GetAlienInfo initializes the AlienInfo structure.
  1524. %
  1525. %  The format of the GetAlienInfo routine is:
  1526. %
  1527. %      GetAlienInfo(alien_info)
  1528. %
  1529. %  A description of each parameter follows:
  1530. %
  1531. %    o alien_info: Specifies a pointer to a AlienInfo structure.
  1532. %
  1533. %
  1534. */
  1535. void GetAlienInfo(alien_info)
  1536. AlienInfo
  1537. X  *alien_info;
  1538. {
  1539. X  alien_info->server_name=(char *) NULL;
  1540. X  alien_info->font=(char *) NULL;
  1541. X  alien_info->geometry=(char *) NULL;
  1542. X  alien_info->density=(char *) NULL;
  1543. X  alien_info->verbose=False;
  1544. }
  1545. X
  1546. /*
  1547. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1548. %                                                                             %
  1549. %                                                                             %
  1550. %                                                                             %
  1551. %   R e a d A l i e n I m a g e                                               %
  1552. %                                                                             %
  1553. %                                                                             %
  1554. %                                                                             %
  1555. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1556. %
  1557. %  Function ReadAlienImage reads an image and returns it.  It allocates
  1558. %  the memory necessary for the new Image structure and returns a pointer to
  1559. %  the new image.  By default, the image format is determined by its magic
  1560. %  number. To specify a particular image format, precede the filename with an
  1561. %  explicit image format name and a colon (i.e.  mtv:image) or as the filename
  1562. %  suffix  (i.e. image.mtv).
  1563. %
  1564. %  The format of the ReadAlienImage routine is:
  1565. %
  1566. %      image=ReadAlienImage(alien_info)
  1567. %
  1568. %  A description of each parameter follows:
  1569. %
  1570. %    o image: Function ReadAlienImage returns a pointer to the image after
  1571. %      reading.  A null image is returned if there is a a memory shortage or
  1572. %      if the image cannot be read.
  1573. %
  1574. %    o alien_info: Specifies a pointer to an AlienInfo structure.
  1575. %
  1576. %
  1577. */
  1578. Image *ReadAlienImage(alien_info)
  1579. AlienInfo
  1580. X  *alien_info;
  1581. {
  1582. X  char
  1583. X    magick[12],
  1584. X    magic_number[12],
  1585. X    *p;
  1586. X
  1587. X  Image
  1588. X    alien_image,
  1589. X    *image;
  1590. X
  1591. X  register char
  1592. X    c,
  1593. X    *q;
  1594. X
  1595. X  register int
  1596. X    i;
  1597. X
  1598. X  unsigned int
  1599. X    temporary_file;
  1600. X
  1601. X  /*
  1602. X    Look for explicit 'format:image' in filename.
  1603. X  */
  1604. X  *magick='\0';
  1605. X  (void) strcpy(alien_image.filename,alien_info->filename);
  1606. X  p=alien_image.filename;
  1607. X  while ((*p != ':') && (*p != '\0'))
  1608. X    p++;
  1609. X  if ((*p == ':') && ((p-alien_image.filename) < sizeof(magic_number)))
  1610. X    {
  1611. X      /*
  1612. X        User specified alien image format.
  1613. X      */
  1614. X      (void) strncpy(magic_number,alien_image.filename,p-alien_image.filename);
  1615. X      magic_number[p-alien_image.filename]='\0';
  1616. X      for (q=magic_number; *q != '\0'; q++)
  1617. X      {
  1618. X        c=(*q);
  1619. X        if (isascii(c) && islower(c))
  1620. X          *q=toupper(c);
  1621. X      }
  1622. X      for (i=0; AlienTypes[i] != (char *) NULL; i++)
  1623. X        if (strcmp(magic_number,AlienTypes[i]) == 0)
  1624. X          {
  1625. X            /*
  1626. X              Strip off image format prefix.
  1627. X            */
  1628. X            p++;
  1629. X            (void) strcpy(alien_image.filename,p);
  1630. X            (void) strcpy(magick,magic_number);
  1631. X            break;
  1632. X          }
  1633. X    }
  1634. X  temporary_file=False;
  1635. X  if (*magick == '\0')
  1636. X    {
  1637. X      /*
  1638. X        Look for 'image.format' in filename.
  1639. X      */
  1640. X      (void) strcpy(magick,"MIFF");
  1641. X      p=alien_image.filename+strlen(alien_image.filename)-1;
  1642. X      while ((*p != '.') && (p > alien_image.filename))
  1643. X        p--;
  1644. X      if ((*p == '.') && (strlen(p) < sizeof(magic_number)))
  1645. X        {
  1646. X          /*
  1647. X            File specified alien image format?
  1648. X          */
  1649. X          (void) strcpy(magic_number,p+1);
  1650. X          for (q=magic_number; *q != '\0'; q++)
  1651. X          {
  1652. X            c=(*q);
  1653. X            if (isascii(c) && islower(c))
  1654. X              *q=toupper(c);
  1655. X          }
  1656. X          for (i=0; AlienTypes[i] != (char *) NULL; i++)
  1657. X            if (strcmp(magic_number,AlienTypes[i]) == 0)
  1658. X              {
  1659. X                (void) strcpy(magick,magic_number);
  1660. X                break;
  1661. X              }
  1662. X        }
  1663. X      /*
  1664. X        Determine type from image magic number.
  1665. X      */
  1666. X      temporary_file=(*alien_image.filename == '-');
  1667. X      if (temporary_file)
  1668. X        {
  1669. X          char
  1670. X            *directory;
  1671. X
  1672. X          int
  1673. X            c;
  1674. X
  1675. X          /*
  1676. X            Copy standard input to temporary file.
  1677. X          */
  1678. X          directory=(char *) getenv("TMPDIR");
  1679. X          if (directory == (char *) NULL)
  1680. X            directory="/tmp";
  1681. X          (void) sprintf(alien_image.filename,"%s/magickXXXXXX",directory);
  1682. X          (void) mktemp(alien_image.filename);
  1683. X          alien_image.file=fopen(alien_image.filename,"w");
  1684. X          if (alien_image.file == (FILE *) NULL)
  1685. X            return((Image *) NULL);
  1686. X          c=getchar();
  1687. X          while (c != EOF)
  1688. X          {
  1689. X            (void) putc(c,alien_image.file);
  1690. X            c=getchar();
  1691. X          }
  1692. X          (void) fclose(alien_image.file);
  1693. X        }
  1694. X      /*
  1695. X        Open image file.
  1696. X      */
  1697. X      *magic_number='\0';
  1698. X      OpenImage(&alien_image,"r");
  1699. X      if (alien_image.file != (FILE *) NULL)
  1700. X        {
  1701. X          /*
  1702. X            Read magic number.
  1703. X          */
  1704. X          (void) ReadData(magic_number,sizeof(char),sizeof(magic_number),
  1705. X            alien_image.file);
  1706. X          CloseImage(&alien_image);
  1707. X        }
  1708. X      /*
  1709. X        Determine the image format.
  1710. X      */
  1711. X      if (strncmp(magic_number,"GIF8",4) == 0)
  1712. X        (void) strcpy(magick,"GIF");
  1713. X      if (strncmp(magic_number,"\377\330\377",3) == 0)
  1714. X        (void) strcpy(magick,"JPEG");
  1715. X      else
  1716. X        if ((strcmp(magick,"JPEG") == 0) || (strcmp(magick,"JPG") == 0))
  1717. X          (void) strcpy(magick,"MIFF");
  1718. X      if ((*magic_number == 'P') && isdigit(magic_number[1]))
  1719. X        (void) strcpy(magick,"PNM");
  1720. X      if (strncmp(magic_number,"%!",2) == 0)
  1721. X        (void) strcpy(magick,"PS");
  1722. X      if (strncmp(magic_number,"\131\246\152\225",4) == 0)
  1723. X        (void) strcpy(magick,"SUN");
  1724. X      if ((strncmp(magic_number,"\115\115",2) == 0) ||
  1725. X          (strncmp(magic_number,"\111\111",2) == 0))
  1726. X        (void) strcpy(magick,"TIFF");
  1727. X      if (strncmp(magic_number,"\122\314",2) == 0)
  1728. X        (void) strcpy(magick,"RLE");
  1729. X      if ((strncmp(magic_number,"LBLSIZE",7) == 0) ||
  1730. X         (strncmp(magic_number,"NJPL1I",6) == 0))
  1731. X        (void) strcpy(magick,"VICAR");
  1732. X      if (strncmp(magic_number,"#define",7) == 0)
  1733. X        (void) strcpy(magick,"XBM");
  1734. X      if (strncmp(magic_number,"\000\000\000\110\000\000\000\007",8) == 0)
  1735. X        (void) strcpy(magick,"XWD");
  1736. X    }
  1737. X  /*
  1738. X    Call appropriate image reader based on image type.
  1739. X  */
  1740. X  (void) strcpy(alien_info->filename,alien_image.filename);
  1741. X  switch (*magick)
  1742. X  {
  1743. X    case 'A':
  1744. X    {
  1745. X      image=ReadAVSImage(alien_info);
  1746. X      break;
  1747. X    }
  1748. X    case 'C':
  1749. X    {
  1750. X      image=ReadCMYKImage(alien_info);
  1751. X      break;
  1752. X    }
  1753. X    case 'F':
  1754. X    {
  1755. X      Warning("Cannot read FAX images",alien_info->filename);
  1756. X      image=ReadImage(alien_info->filename);
  1757. X      break;
  1758. X    }
  1759. X    case 'G':
  1760. X    {
  1761. X      if (strcmp(magick,"GIF") == 0)
  1762. X        image=ReadGIFImage(alien_info);
  1763. X      else
  1764. X        image=
  1765. X          ReadGRAYImage(alien_info);
  1766. X      break;
  1767. X    }
  1768. X    case 'J':
  1769. X    {
  1770. X      image=ReadJPEGImage(alien_info);
  1771. X      break;
  1772. X    }
  1773. X    case 'M':
  1774. X    {
  1775. X      if (strcmp(magick,"MIFF") == 0)
  1776. X        image=ReadImage(alien_info->filename);
  1777. X      else
  1778. X        image=ReadMTVImage(alien_info);
  1779. X      break;
  1780. X    }
  1781. X    case 'P':
  1782. X    {
  1783. X      if (strcmp(magick,"PNM") == 0)
  1784. X        image=ReadPNMImage(alien_info);
  1785. X      else
  1786. X        image=ReadPSImage(alien_info);
  1787. X      break;
  1788. X    }
  1789. X    case 'R':
  1790. X    {
  1791. X      if (strcmp(magick,"RGB") == 0)
  1792. X        image=ReadRGBImage(alien_info);
  1793. X      else
  1794. X        image=ReadRLEImage(alien_info);
  1795. X      break;
  1796. X    }
  1797. X    case 'S':
  1798. X    {
  1799. X      image=ReadSUNImage(alien_info);
  1800. X      break;
  1801. X    }
  1802. X    case 'T':
  1803. X    {
  1804. X      if (strcmp(magick,"TIFF") == 0)
  1805. X        image=ReadTIFFImage(alien_info);
  1806. X      else
  1807. X        image=ReadTEXTImage(alien_info->filename,alien_info->server_name,
  1808. X          alien_info->font,alien_info->density);
  1809. X      break;
  1810. X    }
  1811. X    case 'V':
  1812. X    {
  1813. X      image=ReadVICARImage(alien_info);
  1814. X      break;
  1815. X    }
  1816. X    case 'Y':
  1817. X    {
  1818. X      image=ReadYUVImage(alien_info);
  1819. X      break;
  1820. X    }
  1821. X    case 'X':
  1822. X    {
  1823. X      if (strcmp(magick,"X") == 0)
  1824. X        image=ReadXImage(alien_info->filename,alien_info->server_name,False,
  1825. X          True,False);
  1826. X      else
  1827. X        if (strcmp(magick,"XC") == 0)
  1828. X          image=ReadXCImage(alien_info->filename,alien_info->server_name,
  1829. X            alien_info->geometry);
  1830. X        else
  1831. X          if (strcmp(magick,"XBM") == 0)
  1832. X            image=ReadXBMImage(alien_info);
  1833. X          else
  1834. X            image=ReadXWDImage(alien_info);
  1835. X      break;
  1836. X    }
  1837. X    default:
  1838. X      image=ReadImage(alien_info->filename);
  1839. X  }
  1840. X  if (temporary_file)
  1841. X    (void) unlink(alien_info->filename);
  1842. X  return(image);
  1843. }
  1844. X
  1845. /*
  1846. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1847. %                                                                             %
  1848. %                                                                             %
  1849. %                                                                             %
  1850. %   W r i t e A l i e n I m a g e                                             %
  1851. %                                                                             %
  1852. %                                                                             %
  1853. %                                                                             %
  1854. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1855. %
  1856. %  Function WriteAlienImage writes an image to a file.  You can specify a
  1857. %  particular image format by prefixing the file with the image type and a
  1858. %  colon (i.e. mtv:image) or specify the image type as the filename suffix
  1859. %  (i.e. image.mtv).
  1860. %
  1861. %  The format of the WriteAlienImage routine is:
  1862. %
  1863. %      status=WriteAlienImage(image)
  1864. %
  1865. %  A description of each parameter follows:
  1866. %
  1867. %    o status: Function WriteAlienImage return True if the image is written.
  1868. %      False is returned is there is a memory shortage or if the image file
  1869. %      fails to write.
  1870. %
  1871. %    o image: A pointer to a Image structure.
  1872. %
  1873. %
  1874. */
  1875. unsigned int WriteAlienImage(image)
  1876. Image
  1877. X  *image;
  1878. {
  1879. X  char
  1880. X    magick[12],
  1881. X    *p;
  1882. X
  1883. X  Image
  1884. X    alien_image;
  1885. X
  1886. X  register char
  1887. X    c,
  1888. X    *q;
  1889. X
  1890. X  register int
  1891. X    i;
  1892. X
  1893. X  unsigned int
  1894. X    status;
  1895. X
  1896. X  /*
  1897. X    Look for 'image.format' in filename.
  1898. X  */
  1899. X  alien_image=(*image);
  1900. X  p=alien_image.filename+strlen(alien_image.filename)-1;
  1901. X  while ((*p != '.') && (p > alien_image.filename))
  1902. X    p--;
  1903. X  if ((*p == '.') && (strlen(p) < sizeof(magick)))
  1904. X    {
  1905. X      /*
  1906. X        User specified alien image format.
  1907. X      */
  1908. X      (void) strcpy(magick,p+1);
  1909. X      for (q=magick; *q != '\0'; q++)
  1910. X      {
  1911. X        c=(*q);
  1912. X        if (isascii(c) && islower(c))
  1913. X          *q=toupper(c);
  1914. X      }
  1915. X      for (i=0; AlienTypes[i] != (char *) NULL; i++)
  1916. X        if (strcmp(magick,AlienTypes[i]) == 0)
  1917. X          {
  1918. X            (void) strcpy(alien_image.magick,magick);
  1919. X            break;
  1920. X          }
  1921. X    }
  1922. X  /*
  1923. X    Look for explicit 'format:image' in filename.
  1924. X  */
  1925. X  p=alien_image.filename;
  1926. X  while ((*p != ':') && (*p != '\0'))
  1927. X    p++;
  1928. X  if ((*p == ':') && ((p-alien_image.filename) < sizeof(magick)))
  1929. X    {
  1930. X      /*
  1931. X        User specified alien image format.
  1932. X      */
  1933. X      (void) strncpy(magick,alien_image.filename,p-alien_image.filename);
  1934. X      magick[p-alien_image.filename]='\0';
  1935. X      for (q=magick; *q != '\0'; q++)
  1936. X      {
  1937. X        c=(*q);
  1938. X        if (isascii(c) && islower(c))
  1939. X          *q=toupper(c);
  1940. X      }
  1941. X      for (i=0; AlienTypes[i] != (char *) NULL; i++)
  1942. X        if (strcmp(magick,AlienTypes[i]) == 0)
  1943. X          {
  1944. X            /*
  1945. X              Strip off image format prefix.
  1946. X            */
  1947. X            p++;
  1948. X            (void) strcpy(alien_image.filename,p);
  1949. X            (void) strcpy(alien_image.magick,magick);
  1950. X            break;
  1951. X          }
  1952. X    }
  1953. X  /*
  1954. X    Call appropriate image writer based on image type.
  1955. X  */
  1956. X  switch (*alien_image.magick)
  1957. X  {
  1958. X    case 'A':
  1959. X    {
  1960. X      status=WriteAVSImage(&alien_image);
  1961. X      break;
  1962. X    }
  1963. X    case 'C':
  1964. X    {
  1965. X      status=WriteCMYKImage(&alien_image);
  1966. X      break;
  1967. X    }
  1968. X    case 'F':
  1969. X    {
  1970. X      status=WriteFAXImage(&alien_image);
  1971. X      break;
  1972. X    }
  1973. X    case 'G':
  1974. X    {
  1975. X      if (strcmp(alien_image.magick,"GIF") == 0)
  1976. X        status=WriteGIFImage(&alien_image);
  1977. X      else
  1978. X        status=WriteGRAYImage(&alien_image);
  1979. X      break;
  1980. X    }
  1981. X    case 'J':
  1982. X    {
  1983. X      status=WriteJPEGImage(&alien_image);
  1984. X      break;
  1985. X    }
  1986. X    case 'M':
  1987. X    {
  1988. X      if (strcmp(alien_image.magick,"MTV") == 0)
  1989. X        status=WriteMTVImage(&alien_image);
  1990. X      else
  1991. X        status=WriteImage(&alien_image);
  1992. X      break;
  1993. X    }
  1994. X    case 'P':
  1995. X    {
  1996. X      if (strcmp(alien_image.magick,"PNM") == 0)
  1997. X        status=WritePNMImage(&alien_image);
  1998. X      else
  1999. X        status=PrintImage(&alien_image,"+0+0");
  2000. X      break;
  2001. X    }
  2002. X    case 'R':
  2003. X    {
  2004. X      if (strcmp(alien_image.magick,"RGB") == 0)
  2005. X        status=WriteRGBImage(&alien_image);
  2006. X      else
  2007. X        {
  2008. X          Warning("Cannot write RLE images",alien_image.filename);
  2009. X          status=WriteImage(&alien_image);
  2010. X        }
  2011. X      break;
  2012. X    }
  2013. X    case 'S':
  2014. X    {
  2015. X      status=WriteSUNImage(&alien_image);
  2016. X      break;
  2017. X    }
  2018. X    case 'T':
  2019. X    {
  2020. X      if (strcmp(alien_image.magick,"TIFF") == 0)
  2021. X        status=WriteTIFFImage(&alien_image,True);
  2022. X      else
  2023. X        {
  2024. X          Warning("Cannot write text images",alien_image.filename);
  2025. X          status=WriteImage(&alien_image);
  2026. X        }
  2027. X      break;
  2028. X    }
  2029. X    case 'V':
  2030. X    {
  2031. X      Warning("Cannot write VICAR images",alien_image.filename);
  2032. X      status=WriteImage(&alien_image);
  2033. X      break;
  2034. X    }
  2035. X    case 'Y':
  2036. X    {
  2037. X      status=WriteYUVImage(&alien_image);
  2038. X      break;
  2039. X    }
  2040. X    case 'X':
  2041. X    {
  2042. X      if (strcmp(alien_image.magick,"X") == 0)
  2043. X        status=WriteImage(&alien_image);
  2044. X      else
  2045. X        if (strcmp(alien_image.magick,"XBM") == 0)
  2046. X          status=WriteXBMImage(&alien_image);
  2047. X        else
  2048. X          if (strcmp(alien_image.magick,"XC") == 0)
  2049. X            {
  2050. X              Warning("Cannot write X constant images",alien_image.filename);
  2051. X              status=WriteImage(&alien_image);
  2052. X            }
  2053. X          else
  2054. X            status=WriteXWDImage(&alien_image);
  2055. X      break;
  2056. X    }
  2057. X    default:
  2058. X      status=WriteImage(&alien_image);
  2059. X  }
  2060. X  return(status);
  2061. }
  2062. SHAR_EOF
  2063. echo 'File ImageMagick/alien.c is complete' &&
  2064. chmod 0644 ImageMagick/alien.c ||
  2065. echo 'restore of ImageMagick/alien.c failed'
  2066. Wc_c="`wc -c < 'ImageMagick/alien.c'`"
  2067. test 191036 -eq "$Wc_c" ||
  2068.     echo 'ImageMagick/alien.c: original size 191036, current size' "$Wc_c"
  2069. rm -f _shar_wnt_.tmp
  2070. fi
  2071. # ============= ImageMagick/montage.man ==============
  2072. if test -f 'ImageMagick/montage.man' -a X"$1" != X"-c"; then
  2073.     echo 'x - skipping ImageMagick/montage.man (File already exists)'
  2074.     rm -f _shar_wnt_.tmp
  2075. else
  2076. > _shar_wnt_.tmp
  2077. echo 'x - extracting ImageMagick/montage.man (Text)'
  2078. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/montage.man' &&
  2079. .ad l
  2080. .nh
  2081. .TH MONTAGE 1 "10 October 1992" "ImageMagick"
  2082. .SH NAME
  2083. montage - creates a composite image by combining several separate images
  2084. .SH SYNOPSIS
  2085. .B "montage" [ \fIoptions\fP ...] \fIfile\fP
  2086. [ [ \fIoptions\fP ...] \fIfile\fP ...] \fIfile\fP
  2087. .SH DESCRIPTION
  2088. \fIMontage\fP creates a composite image by combining several separate images.
  2089. The images are tiled on the composite image with the name of the image
  2090. optionally appearing just below the individual tile.
  2091. X
  2092. The composite image is constructed in the following manner.  First,
  2093. each image specified on the command line, except for the last, is
  2094. scaled to fit the maximum tile size.  The maximum tile size by default
  2095. is 256x256.  It can be modified with the \fB-geometry\fP command line
  2096. argument or X resource.  See \fBOPTIONS\fP for more information on
  2097. command line arguments. See \fBX(1)\fP for more information on X
  2098. resources.  Note that the maximum tile size need not be a square.  The
  2099. original aspect ratio of each image is maintainted unless 
  2100. \fB\+aspect_ratio\fP is specified.
  2101. X
  2102. Next the composite image is initialized with the color specified by the
  2103. SHAR_EOF
  2104. true || echo 'restore of ImageMagick/montage.man failed'
  2105. fi
  2106. echo 'End of  part 23'
  2107. echo 'File ImageMagick/montage.man is continued in part 24'
  2108. echo 24 > _shar_seq_.tmp
  2109. exit 0
  2110. exit 0 # Just in case...
  2111.