home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume34 / imagemagick / part23 < prev    next >
Text File  |  1992-12-14  |  58KB  |  2,105 lines

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