home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume13 / imagemagic / part13 < prev    next >
Text File  |  1991-05-23  |  75KB  |  2,151 lines

  1. Path: uunet!uunet!cs.utexas.edu!sun-barr!newstop!exodus!dupont.com!cristy
  2. From: cristy@dupont.com
  3. Newsgroups: comp.sources.x
  4. Subject: v13i029: ImageMagick - Graphics display programs, Part13/21
  5. Message-ID: <13943@exodus.Eng.Sun.COM>
  6. Date: 24 May 91 03:19:19 GMT
  7. References: <csx-13i017:imagemagic@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 2139
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: cristy@dupont.com
  13. Posting-number: Volume 13, Issue 29
  14. Archive-name: imagemagic/part13
  15.  
  16. #!/bin/sh
  17. # this is img.13 (part 13 of ImageMagick)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file ImageMagick/filters/MIFFtoTIFF.c continued
  20. #
  21. if test ! -r _shar_seq_.tmp; then
  22.     echo 'Please unpack part 1 first!'
  23.     exit 1
  24. fi
  25. (read Scheck
  26.  if test "$Scheck" != 13; then
  27.     echo Please unpack part "$Scheck" next!
  28.     exit 1
  29.  else
  30.     exit 0
  31.  fi
  32. ) < _shar_seq_.tmp || exit 1
  33. if test ! -f _shar_wnt_.tmp; then
  34.     echo 'x - still skipping ImageMagick/filters/MIFFtoTIFF.c'
  35. else
  36. echo 'x - continuing file ImageMagick/filters/MIFFtoTIFF.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/filters/MIFFtoTIFF.c' &&
  38. %                                                                             %
  39. %                                                                             %
  40. %  Copyright 1991 E. I. Dupont de Nemours & Company                           %
  41. %                                                                             %
  42. %  Permission to use, copy, modify,distribute , and sell this software and    %
  43. %  its documentation for any purpose is hereby granted without fee,           %
  44. %  provided that the above Copyright notice appear in all copies and that     %
  45. %  both that Copyright notice and this permission notice appear in            %
  46. %  supporting documentation, and that the name of E. I. Dupont de Nemours     %
  47. %  & Company not be used in advertising or publicity pertaining to            %
  48. %  distribution of the software without specific, written prior               %
  49. %  permission.  E. I. Dupont de Nemours & Company makes no representations    %
  50. %  about the suitability of this software for any purpose.  It is provided    %
  51. %  "as is" without express or implied warranty.                               %
  52. %                                                                             %
  53. %  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
  54. %  to this software, including all implied warranties of merchantability      %
  55. %  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
  56. %  liable for any special, indirect or consequential damages or any           %
  57. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  58. %  in an action of contract, negligence or other tortious action, arising     %
  59. %  out of or in connection with the use or performance of this software.      %
  60. %                                                                             %
  61. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  62. %
  63. %  Command syntax:
  64. %
  65. %  export image.miff image.tiff
  66. %
  67. %  Specify 'image.miff' as '-' for standard input.  
  68. %  Specify 'image.tiff' as '-' for standard output.
  69. %
  70. %
  71. */
  72. X
  73. #include <string.h>
  74. #include "display.h"
  75. #include "image.h"
  76. X
  77. /*
  78. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  79. %                                                                             %
  80. %                                                                             %
  81. %                                                                             %
  82. %   E r r o r                                                                 %
  83. %                                                                             %
  84. %                                                                             %
  85. %                                                                             %
  86. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  87. %
  88. %  Function Error displays an error message and then terminates the program.
  89. %
  90. %  The format of the Error routine is:
  91. %
  92. %      Error(message,qualifier)
  93. %
  94. %  A description of each parameter follows:
  95. %
  96. %    o message:  Specifies the message to display before terminating the
  97. %      program.
  98. %
  99. %    o qualifier:  Specifies any qualifier to the message.
  100. %
  101. %
  102. */
  103. void Error(message,qualifier)
  104. char
  105. X  *message,
  106. X  *qualifier;
  107. {
  108. X  (void) fprintf(stderr,"%s: %s",application_name,message); 
  109. X  if (qualifier != (char *) NULL)
  110. X    (void) fprintf(stderr," %s",qualifier);
  111. X  (void) fprintf(stderr,".\n");
  112. X  exit(1);
  113. }
  114. /*
  115. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  116. %                                                                             %
  117. %                                                                             %
  118. %                                                                             %
  119. %   U s a g e                                                                 %
  120. %                                                                             %
  121. %                                                                             %
  122. %                                                                             %
  123. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  124. %
  125. %  Procedure Usage displays the program usage;
  126. %
  127. %  The format of the Usage routine is:
  128. %
  129. %      Usage(message)
  130. %
  131. %  A description of each parameter follows:
  132. %
  133. %    message:  Specifies a specific message to display to the user.
  134. %
  135. */
  136. static void Usage(message)
  137. char
  138. X  *message;
  139. {
  140. X  if (message != (char *) NULL)
  141. X    (void) fprintf(stderr,"Can't continue,%s\n\n",message);
  142. X  (void) fprintf(stderr,"Usage: %s image.miff image.tiff\n\n",application_name);
  143. X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
  144. X  (void) fprintf(stderr,"Specify 'image.tiff' as '-' for standard output.\n");
  145. X  exit(1);
  146. }
  147. X
  148. /*
  149. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  150. %                                                                             %
  151. %                                                                             %
  152. %                                                                             %
  153. %   W r i t e T i f f I m a g e                                               %
  154. %                                                                             %
  155. %                                                                             %
  156. %                                                                             %
  157. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  158. %
  159. %  Function WriteTiffImage writes a TIFF image to a file.
  160. %
  161. %  The format of the WriteTiffImage routine is:
  162. %
  163. %      status=WriteTiffImage(image,verbose)
  164. %
  165. %  A description of each parameter follows:
  166. %
  167. %    o status:  Function WriteTiffImage return True if the image is written.
  168. %      False is returned is there is of a memory shortage or if the image
  169. %      file cannot be opened for writing.
  170. %
  171. %    o image:  A pointer to a Image structure.
  172. %
  173. %    o  verbose:  A value greater than zero prints detailed information about
  174. %       the image.
  175. %
  176. %
  177. */
  178. static unsigned int WriteTiffImage(image,verbose)
  179. Image
  180. X  *image;
  181. X
  182. unsigned int
  183. X  verbose;
  184. {
  185. #include "tiffio.h"
  186. X
  187. X  register RunlengthPacket
  188. X    *p;
  189. X
  190. X  register int
  191. X    i,
  192. X    j,
  193. X    x,
  194. X    y;
  195. X
  196. X  register unsigned char
  197. X    *q;
  198. X
  199. X  TIFF
  200. X    *file;
  201. X
  202. X  unsigned char
  203. X    *scanline;
  204. X
  205. X  unsigned short
  206. X    rows_per_strip;
  207. X
  208. X  file=TIFFOpen(image->filename,"w");
  209. X  if (file == (TIFF *) NULL)
  210. X    exit(-1);
  211. X  /*
  212. X    Initialize TIFF fields.
  213. X  */
  214. X  TIFFSetField(file,TIFFTAG_BITSPERSAMPLE,8);
  215. X  TIFFSetField(file,TIFFTAG_COMPRESSION,COMPRESSION_NONE);
  216. X  TIFFSetField(file,TIFFTAG_DOCUMENTNAME,image->filename);
  217. X  TIFFSetField(file,TIFFTAG_IMAGEDESCRIPTION,"Converted from MIFF");
  218. X  TIFFSetField(file,TIFFTAG_IMAGELENGTH,image->rows);
  219. X  TIFFSetField(file,TIFFTAG_IMAGEWIDTH,image->columns);
  220. X  TIFFSetField(file,TIFFTAG_ORIENTATION,ORIENTATION_TOPLEFT);
  221. X  TIFFSetField(file,TIFFTAG_PHOTOMETRIC,
  222. X    (image->class == DirectClass ? PHOTOMETRIC_RGB : PHOTOMETRIC_PALETTE));
  223. X  TIFFSetField(file,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);
  224. X  TIFFSetField(file,TIFFTAG_SAMPLESPERPIXEL,
  225. X    (image->class == DirectClass ? 3 : 1));
  226. X  TIFFSetField(file,TIFFTAG_STRIPBYTECOUNTS,image->columns);
  227. X  rows_per_strip=8192/TIFFScanlineSize(file);
  228. X  if (rows_per_strip == 0)
  229. X    rows_per_strip=1;
  230. X  TIFFSetField(file,TIFFTAG_ROWSPERSTRIP,rows_per_strip);
  231. X  scanline=(unsigned char *) malloc((unsigned int) TIFFScanlineSize(file));
  232. X  if (scanline == (unsigned char *) NULL)
  233. X    Error("memory allocation error",(char *) NULL);
  234. X  if ((image->class == DirectClass) || (image->colors > 256))
  235. X    {
  236. X      /*
  237. X        Convert DirectClass packets to contiguous RGB scanlines.
  238. X      */
  239. X      p=image->pixels;
  240. X      q=scanline;
  241. X      x=0;
  242. X      y=0;
  243. X      for (i=0; i < image->packets; i++)
  244. X      {
  245. X        for (j=0; j <= p->length; j++)
  246. X        {
  247. X          *q++=p->red;
  248. X          *q++=p->green;
  249. X          *q++=p->blue;
  250. X          x++;
  251. X          if (x == image->columns)
  252. X            {
  253. X              if (TIFFWriteScanline(file,(char *) scanline,y) < 0)
  254. X                break;
  255. X              q=scanline;
  256. X              x=0;
  257. X              y++;
  258. X            }
  259. X
  260. X        }
  261. X        p++;
  262. X      }
  263. X    }
  264. X  else
  265. X    {
  266. X      unsigned short
  267. X        blue[256],
  268. X        green[256],
  269. X        red[256];
  270. X
  271. X      /*
  272. X        Initialize TIFF colormap.
  273. X      */
  274. X      for (i=0 ; i < image->colors; i++)
  275. X      {
  276. X        red[i]=(unsigned short) (image->colormap[i].red << 8);
  277. X        green[i]=(unsigned short) (image->colormap[i].green << 8);
  278. X        blue[i]=(unsigned short) (image->colormap[i].blue << 8);
  279. X      }
  280. X      TIFFSetField(file,TIFFTAG_COLORMAP,red,green,blue);
  281. X      /*
  282. X        Convert PseudoClass packets to contiguous colormap indexed scanlines.
  283. X      */
  284. X      p=image->pixels;
  285. X      q=scanline;
  286. X      x=0;
  287. X      y=0;
  288. X      for (i=0; i < image->packets; i++)
  289. X      {
  290. X        for (j=0; j <= p->length; j++)
  291. X        {
  292. X          *q++=(unsigned char) p->index;
  293. X          x++;
  294. X          if (x == image->columns)
  295. X            {
  296. X              if (TIFFWriteScanline(file,(char *) scanline,y) < 0)
  297. X                break;
  298. X              q=scanline;
  299. X              x=0;
  300. X              y++;
  301. X            }
  302. X        }
  303. X        p++;
  304. X      }
  305. X    }
  306. X  (void) free((char *) scanline);
  307. X  (void) TIFFFlushData(file);
  308. X  if (verbose)
  309. X    TIFFPrintDirectory(file,stderr,False,False,False);
  310. X  (void) TIFFClose(file);
  311. X  return(True);
  312. }
  313. X
  314. /*
  315. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  316. %                                                                             %
  317. %                                                                             %
  318. %                                                                             %
  319. %    M a i n                                                                  %
  320. %                                                                             %
  321. %                                                                             %
  322. %                                                                             %
  323. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  324. %
  325. %
  326. */
  327. int main(argc,argv)
  328. int
  329. X  argc;
  330. X
  331. char
  332. X  *argv[];
  333. {
  334. X  Image
  335. X    *image;
  336. X
  337. X  application_name=argv[0];
  338. X  if (argc < 3)
  339. X    Usage((char *) NULL);
  340. X  image=ReadImage(argv[1]);
  341. X  if (image == (Image *) NULL)
  342. X    exit(1);
  343. X  (void) strcpy(image->filename,argv[2]);
  344. X  WriteTiffImage(image,True);
  345. X  DestroyImage(image);
  346. }
  347. SHAR_EOF
  348. echo 'File ImageMagick/filters/MIFFtoTIFF.c is complete' &&
  349. chmod 0755 ImageMagick/filters/MIFFtoTIFF.c ||
  350. echo 'restore of ImageMagick/filters/MIFFtoTIFF.c failed'
  351. Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoTIFF.c'`"
  352. test 11939 -eq "$Wc_c" ||
  353.     echo 'ImageMagick/filters/MIFFtoTIFF.c: original size 11939, current size' "$Wc_c"
  354. rm -f _shar_wnt_.tmp
  355. fi
  356. # ============= ImageMagick/filters/MIFFtoSUN.c ==============
  357. if test -f 'ImageMagick/filters/MIFFtoSUN.c' -a X"$1" != X"-c"; then
  358.     echo 'x - skipping ImageMagick/filters/MIFFtoSUN.c (File already exists)'
  359.     rm -f _shar_wnt_.tmp
  360. else
  361. > _shar_wnt_.tmp
  362. echo 'x - extracting ImageMagick/filters/MIFFtoSUN.c (Text)'
  363. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoSUN.c' &&
  364. /*
  365. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  366. %                                                                             %
  367. %                                                                             %
  368. %                                                                             %
  369. %                 EEEEE  X   X  PPPP    OOO   RRRR    TTTTT                   %
  370. %                 E       X X   P   P  O   O  R   R     T                     %
  371. %                 EEE      X    PPPP   O   O  RRRR      T                     %
  372. %                 E       X X   P      O   O  R R       T                     %
  373. %                 EEEEE  X   X  P       OOO   R  R      T                     %
  374. %                                                                             %
  375. %                                                                             %
  376. %                  Export MIFF image to a SUN raster format.                  %
  377. %                                                                             %
  378. %                                                                             %
  379. %                                                                             %
  380. %                           Software Design                                   %
  381. %                             John Cristy                                     %
  382. %                            January  1991                                    %
  383. %                                                                             %
  384. %                                                                             %
  385. %  Copyright 1991 E. I. Dupont de Nemours & Company                           %
  386. %                                                                             %
  387. %  Permission to use, copy, modify, distribute, and sell this software and    %
  388. %  its documentation for any purpose is hereby granted without fee,           %
  389. %  provided that the above Copyright notice appear in all copies and that     %
  390. %  both that Copyright notice and this permission notice appear in            %
  391. %  supporting documentation, and that the name of E. I. Dupont de Nemours     %
  392. %  & Company not be used in advertising or publicity pertaining to            %
  393. %  distribution of the software without specific, written prior               %
  394. %  permission.  E. I. Dupont de Nemours & Company makes no representations    %
  395. %  about the suitability of this software for any purpose.  It is provided    %
  396. %  "as is" without express or implied warranty.                               %
  397. %                                                                             %
  398. %  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
  399. %  to this software, including all implied warranties of merchantability      %
  400. %  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
  401. %  liable for any special, indirect or consequential damages or any           %
  402. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  403. %  in an action of contract, negligence or other tortious action, arising     %
  404. %  out of or in connection with the use or performance of this software.      %
  405. %                                                                             %
  406. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  407. %
  408. %  Command syntax:
  409. %
  410. %  export image.miff image.sun
  411. %
  412. %  Specify 'image.miff' as '-' for standard input.  
  413. %  Specify 'image.sun' as '-' for standard output.
  414. %
  415. %
  416. */
  417. X
  418. #include <string.h>
  419. #include "display.h"
  420. #include "image.h"
  421. X
  422. /*
  423. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  424. %                                                                             %
  425. %                                                                             %
  426. %                                                                             %
  427. %   E r r o r                                                                 %
  428. %                                                                             %
  429. %                                                                             %
  430. %                                                                             %
  431. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  432. %
  433. %  Function Error displays an error message and then terminates the program.
  434. %
  435. %  The format of the Error routine is:
  436. %
  437. %      Error(message,qualifier)
  438. %
  439. %  A description of each parameter follows:
  440. %
  441. %    o message:  Specifies the message to display before terminating the
  442. %      program.
  443. %
  444. %    o qualifier:  Specifies any qualifier to the message.
  445. %
  446. %
  447. */
  448. void Error(message,qualifier)
  449. char
  450. X  *message,
  451. X  *qualifier;
  452. {
  453. X  (void) fprintf(stderr,"%s: %s",application_name,message); 
  454. X  if (qualifier != (char *) NULL)
  455. X    (void) fprintf(stderr," %s",qualifier);
  456. X  (void) fprintf(stderr,".\n");
  457. X  exit(1);
  458. }
  459. X
  460. /*
  461. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  462. %                                                                             %
  463. %                                                                             %
  464. %                                                                             %
  465. %  M S B F i r s t O r d e r                                                  %
  466. %                                                                             %
  467. %                                                                             %
  468. %                                                                             %
  469. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  470. %
  471. %  Function MSBFirstOrder converts a least-significant byte first buffer of
  472. %  integers to most-significant byte first.
  473. %
  474. %  The format of the MSBFirstOrder routine is:
  475. %
  476. %       MSBFirstOrder(p,length);
  477. %
  478. %  A description of each parameter follows.
  479. %
  480. %   o  p:  Specifies a pointer to a buffer of integers.
  481. %
  482. %   o  length:  Specifies the length of the buffer.
  483. %
  484. %
  485. */
  486. MSBFirstOrder(p,length)
  487. register char 
  488. X  *p;
  489. X
  490. register unsigned 
  491. X  length;
  492. {
  493. X  register char 
  494. X    c,
  495. X    *q,
  496. X    *sp;
  497. X
  498. X  q=p+length;
  499. X  while (p < q) 
  500. X  {
  501. X    sp=p+3;
  502. X    c=(*sp);
  503. X    *sp=(*p);
  504. X    *p++=c;
  505. X    sp=p+1;
  506. X    c=(*sp);
  507. X    *sp=(*p);
  508. X    *p++=c;
  509. X    p+=2;
  510. X  }
  511. }
  512. X
  513. /*
  514. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  515. %                                                                             %
  516. %                                                                             %
  517. %                                                                             %
  518. %   U s a g e                                                                 %
  519. %                                                                             %
  520. %                                                                             %
  521. %                                                                             %
  522. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  523. %
  524. %  Procedure Usage displays the program usage;
  525. %
  526. %  The format of the Usage routine is:
  527. %
  528. %      Usage(message)
  529. %
  530. %  A description of each parameter follows:
  531. %
  532. %    message:  Specifies a specific message to display to the user.
  533. %
  534. */
  535. static void Usage(message)
  536. char
  537. X  *message;
  538. {
  539. X  if (message != (char *) NULL)
  540. X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
  541. X  (void) fprintf(stderr,"Usage: %s image.miff image.sun\n\n",application_name);
  542. X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
  543. X  (void) fprintf(stderr,"Specify 'image.sun' as '-' for standard output.\n");
  544. X  exit(1);
  545. }
  546. X
  547. /*
  548. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  549. %                                                                             %
  550. %                                                                             %
  551. %                                                                             %
  552. %   W r i t e R a s t e r I m a g e                                           %
  553. %                                                                             %
  554. %                                                                             %
  555. %                                                                             %
  556. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  557. %
  558. %  Procedure WriteRasterImage writes an image to a file on disk in SUN 
  559. %  rasterfile format.
  560. %
  561. %  The format of the WriteRasterImage routine is:
  562. %
  563. %      WriteRasterImage(image)
  564. %
  565. %  A description of each parameter follows.
  566. %
  567. %    o image:  A pointer to a Image structure.
  568. %
  569. %
  570. */
  571. static void WriteRasterImage(image)
  572. Image
  573. X  *image;
  574. {
  575. #define RMT_EQUAL_RGB  1
  576. #define RMT_NONE  0
  577. #define RMT_RAW  2
  578. #define RT_STANDARD  1
  579. #define RT_FORMAT_RGB  3
  580. X
  581. X  typedef struct Raster
  582. X  {
  583. X    int
  584. X      magic,
  585. X      width,
  586. X      height,
  587. X      depth,
  588. X      length,
  589. X      type,
  590. X      maptype,
  591. X      maplength;
  592. X  } Raster;
  593. X
  594. X  Raster
  595. X    sun_header;
  596. X
  597. X  register int
  598. X    i,
  599. X    j,
  600. X    x;
  601. X
  602. X  register RunlengthPacket
  603. X    *p;
  604. X
  605. X  register unsigned char
  606. X    *q;
  607. X
  608. X  unsigned char
  609. X    *sun_pixels;
  610. X
  611. X  unsigned long
  612. X    lsb_first;
  613. X
  614. X  /*
  615. X    Open output image file.
  616. X  */
  617. X  if (*image->filename == '-')
  618. X    image->file=stdout;
  619. X  else
  620. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  621. X      image->file=fopen(image->filename,"w");
  622. X    else
  623. X      {
  624. X        char
  625. X          command[256];
  626. X
  627. X        /*
  628. X          Image file is compressed-- uncompress it.
  629. X        */
  630. X        (void) sprintf(command,"compress -c > %s",image->filename);
  631. X        image->file=(FILE *) popen(command,"w");
  632. X      }
  633. X  if (image->file == (FILE *) NULL)
  634. X    Error("unable to open file",image->filename);
  635. X  /*
  636. X    Initialize raster file sun_header.
  637. X  */
  638. X  sun_header.magic=0x59a66a95;
  639. X  sun_header.width=image->columns;
  640. X  sun_header.height=image->rows;
  641. X  sun_header.depth=(image->class == DirectClass ? 24 : 8);
  642. X  sun_header.length=image->columns*image->rows*(sun_header.depth >> 3)+
  643. X    (image->columns % 2 ? image->rows : 0);
  644. X  sun_header.type=RT_STANDARD;
  645. X  sun_header.maptype=(image->class == DirectClass ? RMT_NONE : RMT_EQUAL_RGB);
  646. X  sun_header.maplength=(image->class == DirectClass ? 0 : image->colors*3);
  647. X  /*
  648. X    Ensure the sun_header byte-order is most-significant byte first.
  649. X  */
  650. X  lsb_first=1;
  651. X  if ((*(char *) &lsb_first) == 0)
  652. X    (void) fwrite((char *) &sun_header,sizeof(sun_header),1,image->file);
  653. X  else
  654. X    {
  655. X      Raster
  656. X        reverse_header;
  657. X
  658. X      reverse_header=sun_header;
  659. X      MSBFirstOrder((char *) &reverse_header,sizeof(reverse_header));
  660. X      (void) fwrite((char *) &reverse_header,sizeof(reverse_header),1,
  661. X        image->file);
  662. X    }
  663. X  if (image->class == PseudoClass)
  664. X    {
  665. X      unsigned char
  666. X        *sun_colormap;
  667. X
  668. X      /*
  669. X         Dump colormap to file.
  670. X      */
  671. X      sun_colormap=(unsigned char *) 
  672. X        malloc((unsigned int) sun_header.maplength);
  673. X      if (sun_colormap == (unsigned char *) NULL)
  674. X        Error("unable to allocate memory",(char *) NULL);
  675. X      q=sun_colormap;
  676. X      for (i=0; i < image->colors; i++)
  677. X        *q++=image->colormap[i].red;
  678. X      for (i=0; i < image->colors; i++)
  679. X        *q++=image->colormap[i].green;
  680. X      for (i=0; i < image->colors; i++)
  681. X        *q++=image->colormap[i].blue;
  682. X      (void) fwrite((char *) sun_colormap,sizeof(char),sun_header.maplength,
  683. X        image->file);
  684. X      (void) free((char *) sun_colormap);
  685. X    }
  686. X  /*
  687. X    Convert MIFF to SUN raster pixels.
  688. X  */
  689. X  sun_pixels=(unsigned char *) malloc((unsigned int) sun_header.length);
  690. X  if (sun_pixels == (unsigned char *) NULL)
  691. X    Error("unable to allocate memory",(char *) NULL);
  692. X  p=image->pixels;
  693. X  q=sun_pixels;
  694. X  x=0;
  695. X  for (i=0; i < image->packets; i++)
  696. X  {
  697. X    for (j=0; j <= p->length; j++)
  698. X    {
  699. X      if (image->class == PseudoClass)
  700. X        *q++=p->index;
  701. X      else
  702. X        {
  703. X          *q++=p->blue;
  704. X          *q++=p->green;
  705. X          *q++=p->red;
  706. X        }
  707. X      if ((image->columns % 2) != 0)
  708. X        {
  709. X          x++;
  710. X          if ((x % image->columns) == 0)
  711. X            *q++;  /* pad scanline */
  712. X        }
  713. X    }
  714. X    p++;
  715. X  }
  716. X  (void) fwrite((char *) sun_pixels,sizeof(char),sun_header.length,image->file);
  717. X  (void) free((char *) sun_pixels);
  718. X  if (image->file != stdin)
  719. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  720. X      (void) fclose(image->file);
  721. X    else
  722. X      (void) pclose(image->file);
  723. }
  724. X
  725. /*
  726. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  727. %                                                                             %
  728. %                                                                             %
  729. %                                                                             %
  730. %    M a i n                                                                  %
  731. %                                                                             %
  732. %                                                                             %
  733. %                                                                             %
  734. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  735. %
  736. %
  737. */
  738. int main(argc,argv)
  739. int
  740. X  argc;
  741. X
  742. char
  743. X  *argv[];
  744. {
  745. X  Image
  746. X    *image;
  747. X
  748. X  application_name=argv[0];
  749. X  if (argc < 3)
  750. X    Usage((char *) NULL);
  751. X  image=ReadImage(argv[1]);
  752. X  if (image == (Image *) NULL)
  753. X    exit(1);
  754. X  (void) strcpy(image->filename,argv[2]);
  755. X  WriteRasterImage(image);
  756. X  (void) fprintf(stderr,"%s=> %s  %dx%d\n",argv[1],argv[2],image->columns,
  757. X    image->rows);
  758. X  return(False);
  759. }
  760. SHAR_EOF
  761. chmod 0755 ImageMagick/filters/MIFFtoSUN.c ||
  762. echo 'restore of ImageMagick/filters/MIFFtoSUN.c failed'
  763. Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoSUN.c'`"
  764. test 13529 -eq "$Wc_c" ||
  765.     echo 'ImageMagick/filters/MIFFtoSUN.c: original size 13529, current size' "$Wc_c"
  766. rm -f _shar_wnt_.tmp
  767. fi
  768. # ============= ImageMagick/filters/MIFFtoAVS.c ==============
  769. if test -f 'ImageMagick/filters/MIFFtoAVS.c' -a X"$1" != X"-c"; then
  770.     echo 'x - skipping ImageMagick/filters/MIFFtoAVS.c (File already exists)'
  771.     rm -f _shar_wnt_.tmp
  772. else
  773. > _shar_wnt_.tmp
  774. echo 'x - extracting ImageMagick/filters/MIFFtoAVS.c (Text)'
  775. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoAVS.c' &&
  776. /*
  777. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  778. %                                                                             %
  779. %                                                                             %
  780. %                                                                             %
  781. %                 EEEEE  X   X  PPPP    OOO   RRRR    TTTTT                   %
  782. %                 E       X X   P   P  O   O  R   R     T                     %
  783. %                 EEE      X    PPPP   O   O  RRRR      T                     %
  784. %                 E       X X   P      O   O  R R       T                     %
  785. %                 EEEEE  X   X  P       OOO   R  R      T                     %
  786. %                                                                             %
  787. %                                                                             %
  788. %                  Export MIFF image to a AVS raster format.                  %
  789. %                                                                             %
  790. %                                                                             %
  791. %                                                                             %
  792. %                           Software Design                                   %
  793. %                             John Cristy                                     %
  794. %                            January  1991                                    %
  795. %                                                                             %
  796. %                                                                             %
  797. %  Copyright 1991 E. I. Dupont de Nemours & Company                           %
  798. %                                                                             %
  799. %  Permission to use, copy, modify, distribute, and sell this software and    %
  800. %  its documentation for any purpose is hereby granted without fee,           %
  801. %  provided that the above Copyright notice appear in all copies and that     %
  802. %  both that Copyright notice and this permission notice appear in            %
  803. %  supporting documentation, and that the name of E. I. Dupont de Nemours     %
  804. %  & Company not be used in advertising or publicity pertaining to            %
  805. %  distribution of the software without specific, written prior               %
  806. %  permission.  E. I. Dupont de Nemours & Company makes no representations    %
  807. %  about the suitability of this software for any purpose.  It is provided    %
  808. %  "as is" without express or implied warranty.                               %
  809. %                                                                             %
  810. %  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
  811. %  to this software, including all implied warranties of merchantability      %
  812. %  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
  813. %  liable for any special, indirect or consequential damages or any           %
  814. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  815. %  in an action of contract, negligence or other tortious action, arising     %
  816. %  out of or in connection with the use or performance of this software.      %
  817. %                                                                             %
  818. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  819. %
  820. %  Command syntax:
  821. %
  822. %  export image.miff image.avs
  823. %
  824. %  Specify 'image.miff' as '-' for standard input.  
  825. %  Specify 'image.avs' as '-' for standard output.
  826. %
  827. %
  828. */
  829. X
  830. #include <string.h>
  831. #include "display.h"
  832. #include "image.h"
  833. X
  834. /*
  835. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  836. %                                                                             %
  837. %                                                                             %
  838. %                                                                             %
  839. %   E r r o r                                                                 %
  840. %                                                                             %
  841. %                                                                             %
  842. %                                                                             %
  843. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  844. %
  845. %  Function Error displays an error message and then terminates the program.
  846. %
  847. %  The format of the Error routine is:
  848. %
  849. %      Error(message,qualifier)
  850. %
  851. %  A description of each parameter follows:
  852. %
  853. %    o message:  Specifies the message to display before terminating the
  854. %      program.
  855. %
  856. %    o qualifier:  Specifies any qualifier to the message.
  857. %
  858. %
  859. */
  860. void Error(message,qualifier)
  861. char
  862. X  *message,
  863. X  *qualifier;
  864. {
  865. X  (void) fprintf(stderr,"%s: %s",application_name,message); 
  866. X  if (qualifier != (char *) NULL)
  867. X    (void) fprintf(stderr," %s",qualifier);
  868. X  (void) fprintf(stderr,".\n");
  869. X  exit(1);
  870. }
  871. X
  872. /*
  873. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  874. %                                                                             %
  875. %                                                                             %
  876. %                                                                             %
  877. %   U s a g e                                                                 %
  878. %                                                                             %
  879. %                                                                             %
  880. %                                                                             %
  881. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  882. %
  883. %  Procedure Usage displays the program usage;
  884. %
  885. %  The format of the Usage routine is:
  886. %
  887. %      Usage(message)
  888. %
  889. %  A description of each parameter follows:
  890. %
  891. %    message:  Specifies a specific message to display to the user.
  892. %
  893. */
  894. static void Usage(message)
  895. char
  896. X  *message;
  897. {
  898. X  if (message != (char *) NULL)
  899. X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
  900. X  (void) fprintf(stderr,"Usage: %s image.miff image.avs\n\n",application_name);
  901. X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
  902. X  (void) fprintf(stderr,"Specify 'image.avs' as '-' for standard output.\n");
  903. X  exit(1);
  904. }
  905. X
  906. /*
  907. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  908. %                                                                             %
  909. %                                                                             %
  910. %                                                                             %
  911. %   W r i t e A v s I m a g e                                                 %
  912. %                                                                             %
  913. %                                                                             %
  914. %                                                                             %
  915. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  916. %
  917. %  Procedure WriteAvsImage writes an image to a file on disk in AVS rasterfile
  918. %  format.
  919. %
  920. %  The format of the WriteAvsImage routine is:
  921. %
  922. %      WriteAvsImage(image)
  923. %
  924. %  A description of each parameter follows.
  925. %
  926. %    o image:  A pointer to a Image structure.
  927. %
  928. %
  929. */
  930. static void WriteAvsImage(image)
  931. Image
  932. X  *image;
  933. {
  934. X  typedef struct Raster
  935. X  {
  936. X    int
  937. X      width,
  938. X      height;
  939. X  } Raster;
  940. X
  941. X  Raster
  942. X    header;
  943. X
  944. X  register int
  945. X    i,
  946. X    j;
  947. X
  948. X  register RunlengthPacket
  949. X    *p;
  950. X
  951. X  register unsigned char
  952. X    *q;
  953. X
  954. X  unsigned char
  955. X    *avs_pixels;
  956. X
  957. X  /*
  958. X    Open output image file.
  959. X  */
  960. X  if (*image->filename == '-')
  961. X    image->file=stdout;
  962. X  else
  963. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  964. X      image->file=fopen(image->filename,"w");
  965. X    else
  966. X      {
  967. X        char
  968. X          command[256];
  969. X
  970. X        /*
  971. X          Image file is compressed-- uncompress it.
  972. X        */
  973. X        (void) sprintf(command,"compress -c > %s",image->filename);
  974. X        image->file=(FILE *) popen(command,"w");
  975. X      }
  976. X  if (image->file == (FILE *) NULL)
  977. X    Error("unable to open file",image->filename);
  978. X  /*
  979. X    Initialize raster file header.
  980. X  */
  981. X  header.width=image->columns;
  982. X  header.height=image->rows;
  983. X  avs_pixels=(unsigned char *) malloc(image->columns*image->rows*4);
  984. X  if (avs_pixels == (unsigned char *) NULL)
  985. X    Error("unable to allocate memory",(char *) NULL);
  986. X  (void) fwrite((char *) &header,sizeof(header),1,image->file);
  987. X  p=image->pixels;
  988. X  q=avs_pixels;
  989. X  for (i=0; i < image->packets; i++)
  990. X  {
  991. X    for (j=0; j <= p->length; j++)
  992. X    {
  993. X      *q++=0;
  994. X      *q++=p->red;
  995. X      *q++=p->green;
  996. X      *q++=p->blue;
  997. X    }
  998. X    p++;
  999. X  }
  1000. X  (void) fwrite((char *) avs_pixels,sizeof(char),(int) 
  1001. X    (image->columns*image->rows*4),image->file);
  1002. X  if (image->file != stdin)
  1003. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  1004. X      (void) fclose(image->file);
  1005. X    else
  1006. X      (void) pclose(image->file);
  1007. }
  1008. X
  1009. /*
  1010. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1011. %                                                                             %
  1012. %                                                                             %
  1013. %                                                                             %
  1014. %    M a i n                                                                  %
  1015. %                                                                             %
  1016. %                                                                             %
  1017. %                                                                             %
  1018. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1019. %
  1020. %
  1021. */
  1022. int main(argc,argv)
  1023. int
  1024. X  argc;
  1025. X
  1026. char
  1027. X  *argv[];
  1028. {
  1029. X  Image
  1030. X    *image;
  1031. X
  1032. X  application_name=argv[0];
  1033. X  if (argc < 3)
  1034. X    Usage((char *) NULL);
  1035. X  image=ReadImage(argv[1]);
  1036. X  if (image == (Image *) NULL)
  1037. X    exit(1);
  1038. X  (void) strcpy(image->filename,argv[2]);
  1039. X  WriteAvsImage(image);
  1040. X  (void) fprintf(stderr,"%s=> %s  %dx%d\n",argv[1],argv[2],image->columns,
  1041. X    image->rows);
  1042. X  DestroyImage(image);
  1043. X  return(False);
  1044. }
  1045. SHAR_EOF
  1046. chmod 0755 ImageMagick/filters/MIFFtoAVS.c ||
  1047. echo 'restore of ImageMagick/filters/MIFFtoAVS.c failed'
  1048. Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoAVS.c'`"
  1049. test 10081 -eq "$Wc_c" ||
  1050.     echo 'ImageMagick/filters/MIFFtoAVS.c: original size 10081, current size' "$Wc_c"
  1051. rm -f _shar_wnt_.tmp
  1052. fi
  1053. # ============= ImageMagick/filters/AVStoMIFF.c ==============
  1054. if test -f 'ImageMagick/filters/AVStoMIFF.c' -a X"$1" != X"-c"; then
  1055.     echo 'x - skipping ImageMagick/filters/AVStoMIFF.c (File already exists)'
  1056.     rm -f _shar_wnt_.tmp
  1057. else
  1058. > _shar_wnt_.tmp
  1059. echo 'x - extracting ImageMagick/filters/AVStoMIFF.c (Text)'
  1060. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/AVStoMIFF.c' &&
  1061. /*
  1062. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1063. %                                                                             %
  1064. %                                                                             %
  1065. %                                                                             %
  1066. %                 IIIII  M   M  PPPP    OOO   RRRR    TTTTT                   %
  1067. %                   I    MM MM  P   P  O   O  R   R     T                     %
  1068. %                   I    M M M  PPPP   O   O  RRRR      T                     %
  1069. %                   I    M   M  P      O   O  R R       T                     %
  1070. %                 IIIII  M   M  P       OOO   R  R      T                     % 
  1071. %                                                                             %
  1072. %                                                                             %
  1073. %                 Import AVS raster image to a MIFF format.                   %
  1074. %                                                                             %
  1075. %                                                                             %
  1076. %                                                                             %
  1077. %                           Software Design                                   %
  1078. %                             John Cristy                                     %
  1079. %                            January  1991                                    %
  1080. %                                                                             %
  1081. %                                                                             %
  1082. %  Copyright 1991 E. I. Dupont de Nemours & Company                           %
  1083. %                                                                             %
  1084. %  Permission to use, copy, modify, distribute, and sell this software and    %
  1085. %  its documentation for any purpose is hereby granted without fee,           %
  1086. %  provided that the above Copyright notice appear in all copies and that     %
  1087. %  both that Copyright notice and this permission notice appear in            %
  1088. %  supporting documentation, and that the name of E. I. Dupont de Nemours     %
  1089. %  & Company not be used in advertising or publicity pertaining to            %
  1090. %  distribution of the software without specific, written prior               %
  1091. %  permission.  E. I. Dupont de Nemours & Company makes no representations    %
  1092. %  about the suitability of this software for any purpose.  It is provided    %
  1093. %  "as is" without express or implied warranty.                               %
  1094. %                                                                             %
  1095. %  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
  1096. %  to this software, including all implied warranties of merchantability      %
  1097. %  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
  1098. %  liable for any special, indirect or consequential damages or any           %
  1099. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  1100. %  in an action of contract, negligence or other tortious action, arising     %
  1101. %  out of or in connection with the use or performance of this software.      %
  1102. %                                                                             %
  1103. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1104. %  Command syntax:
  1105. %
  1106. %  import [-scene #] image.AVS image.miff
  1107. %  
  1108. %  Specify 'image.AVS' as '-' for standard input.  
  1109. %  Specify 'image.miff' as '-' for standard output.
  1110. %  
  1111. %
  1112. */
  1113. X
  1114. #include "display.h"
  1115. #include "image.h"
  1116. X
  1117. /*
  1118. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1119. %                                                                             %
  1120. %                                                                             %
  1121. %                                                                             %
  1122. %   E r r o r                                                                 %
  1123. %                                                                             %
  1124. %                                                                             %
  1125. %                                                                             %
  1126. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1127. %
  1128. %  Function Error displays an error message and then terminates the program.
  1129. %
  1130. %  The format of the Error routine is:
  1131. %
  1132. %      Error(message,qualifier)
  1133. %
  1134. %  A description of each parameter follows:
  1135. %
  1136. %    o message:  Specifies the message to display before terminating the
  1137. %      program.
  1138. %
  1139. %    o qualifier:  Specifies any qualifier to the message.
  1140. %
  1141. %
  1142. */
  1143. void Error(message,qualifier)
  1144. char
  1145. X  *message,
  1146. X  *qualifier;
  1147. {
  1148. X  (void) fprintf(stderr,"%s: %s",application_name,message); 
  1149. X  if (qualifier != (char *) NULL)
  1150. X    (void) fprintf(stderr," %s",qualifier);
  1151. X  (void) fprintf(stderr,".\n");
  1152. X  exit(1);
  1153. }
  1154. X
  1155. /*
  1156. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1157. %                                                                             %
  1158. %                                                                             %
  1159. %                                                                             %
  1160. %  R e a d A v s I m a g e                                                    %
  1161. %                                                                             %
  1162. %                                                                             %
  1163. %                                                                             %
  1164. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1165. %
  1166. %  Function ReadAVSImage reads an image file and returns it.  It allocates the 
  1167. %  memory necessary for the new Image structure and returns a pointer to the 
  1168. %  new image.
  1169. %
  1170. %  The format of the ReadAVSImage routine is:
  1171. %
  1172. %      image=ReadAVSImage(filename)
  1173. %
  1174. %  A description of each parameter follows:
  1175. %
  1176. %    o image:  Function ReadAVSImage returns a pointer to the image after 
  1177. %      reading. A null image is returned if there is a a memory shortage or if 
  1178. %      the image cannot be read.
  1179. %
  1180. %    o filename:  Specifies the name of the image to read.
  1181. %
  1182. %
  1183. */
  1184. static Image *ReadAVSImage(filename)
  1185. char
  1186. X  *filename;
  1187. {
  1188. #define RT_STANDARD  1
  1189. #define RMT_NONE  0
  1190. #define RMT_EQUAL_RGB  1
  1191. X
  1192. X  typedef struct _Rasterfile
  1193. X  {
  1194. X    int
  1195. X      width,
  1196. X      height;
  1197. X  } Rasterfile;
  1198. X
  1199. X  Image
  1200. X    *image;
  1201. X
  1202. X  Rasterfile
  1203. X    avs_header;
  1204. X
  1205. X  register int
  1206. X    i;
  1207. X
  1208. X  register unsigned char
  1209. X    blue,
  1210. X    green,
  1211. X    *p,
  1212. X    red;
  1213. X
  1214. X  register RunlengthPacket
  1215. X    *q;
  1216. X
  1217. X  unsigned char
  1218. X    *avs_pixels;
  1219. X
  1220. X  /*
  1221. X    Allocate image structure.
  1222. X  */
  1223. X  image=(Image *) malloc(sizeof(Image));
  1224. X  if (image == (Image *) NULL)
  1225. X    Error("memory allocation error",(char *) NULL);
  1226. X  /*
  1227. X    Initialize Image structure.
  1228. X  */
  1229. X  image->id=UnknownId;
  1230. X  image->class=DirectClass;
  1231. X  image->compression=RunlengthEncodedCompression;
  1232. X  image->columns=0;
  1233. X  image->rows=0;
  1234. X  image->packets=0;
  1235. X  image->colors=0;
  1236. X  image->scene=0;
  1237. X  image->colormap=(ColorPacket *) NULL;
  1238. X  image->pixels=(RunlengthPacket *) NULL;
  1239. X  image->comments=(char *) NULL;
  1240. X  /*
  1241. X    Open image file.
  1242. X  */
  1243. X  (void) strcpy(image->filename,filename);
  1244. X  if (*image->filename == '-')
  1245. X    image->file=stdin;
  1246. X  else
  1247. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  1248. X      image->file=fopen(image->filename,"r");
  1249. X    else
  1250. X      {
  1251. X        char
  1252. X          command[256];
  1253. X
  1254. X        /*
  1255. X          Image file is compressed-- uncompress it.
  1256. X        */
  1257. X        (void) sprintf(command,"uncompress -c %s",image->filename);
  1258. X        image->file=(FILE *) popen(command,"r");
  1259. X      }
  1260. X  if (image->file == (FILE *) NULL)
  1261. X    {
  1262. X      Warning("unable to open file",image->filename);
  1263. X      (void) DestroyImage(image);
  1264. X      return((Image *) NULL);
  1265. X    }
  1266. X  /*
  1267. X    Read AVS image.
  1268. X  */
  1269. X  (void) ReadData((char *) &avs_header,1,sizeof(Rasterfile),image->file);
  1270. X  avs_pixels=(unsigned char *) 
  1271. X    malloc((unsigned int) avs_header.width*avs_header.height*4);
  1272. X  if (avs_pixels == (unsigned char *) NULL)
  1273. X    Error("memory allocation error",(char *) NULL);
  1274. X  (void) ReadData((char *) avs_pixels,1,avs_header.width*avs_header.height*4,
  1275. X    image->file);
  1276. X  /*
  1277. X    Create image.
  1278. X  */
  1279. X  image->comments=(char *) malloc((unsigned int) (strlen(image->filename)+256));
  1280. X  if (image->comments == (char *) NULL)
  1281. X    Error("memory allocation error",(char *) NULL);
  1282. X  (void) sprintf(image->comments,"\n  Imported from AVS raster image:  %s\n",
  1283. X    image->filename);
  1284. X  image->columns=avs_header.width;
  1285. X  image->rows=avs_header.height;
  1286. X  image->pixels=(RunlengthPacket *) 
  1287. X    malloc(image->columns*image->rows*sizeof(RunlengthPacket));
  1288. X  if (image->pixels == (RunlengthPacket *) NULL)
  1289. X    Error("memory allocation error",(char *) NULL);
  1290. X  /*
  1291. X    Convert AVS raster image to runlength-encoded packets.
  1292. X  */
  1293. X  p=avs_pixels;
  1294. X  image->packets=0;
  1295. X  q=image->pixels;
  1296. X  q->length=MaxRunlength;
  1297. X  for (i=0; i < (image->columns*image->rows); i++)
  1298. X  {
  1299. X    p++;
  1300. X    red=(*p++);
  1301. X    green=(*p++);
  1302. X    blue=(*p++);
  1303. X    if ((red == q->red) && (green == q->green) && (blue == q->blue) && 
  1304. X        (q->length < MaxRunlength))
  1305. X      q->length++;
  1306. X    else
  1307. X      {
  1308. X        if (image->packets > 0)
  1309. X          q++;
  1310. X        image->packets++;
  1311. X        q->red=red;
  1312. X        q->green=green;
  1313. X        q->blue=blue;
  1314. X        q->index=0;
  1315. X        q->length=0;
  1316. X      }
  1317. X  }
  1318. X  (void) free((char *) avs_pixels);
  1319. X  if (image->file != stdin)
  1320. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  1321. X      (void) fclose(image->file);
  1322. X    else
  1323. X      (void) pclose(image->file);
  1324. X  if (image->packets > ((image->columns*image->rows*3) >> 2))
  1325. X    image->compression=NoCompression;
  1326. X  image->pixels=(RunlengthPacket *)
  1327. X    realloc((char *) image->pixels,image->packets*sizeof(RunlengthPacket));
  1328. X  return(image);
  1329. }
  1330. X
  1331. /*
  1332. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1333. %                                                                             %
  1334. %                                                                             %
  1335. %                                                                             %
  1336. %   U s a g e                                                                 %
  1337. %                                                                             %
  1338. %                                                                             %
  1339. %                                                                             %
  1340. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1341. %
  1342. %  Procedure Usage displays the program usage;
  1343. %
  1344. %  The format of the Usage routine is:
  1345. %
  1346. %      Usage(message)
  1347. %
  1348. %  A description of each parameter follows:
  1349. %
  1350. %    message:  Specifies a specific message to display to the user.
  1351. %
  1352. */
  1353. static void Usage(message)
  1354. char
  1355. X  *message;
  1356. {
  1357. X  if (message != (char *) NULL)
  1358. X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
  1359. X  (void) fprintf(stderr,"Usage: %s [-scene #] image.avs image.miff\n\n",
  1360. X    application_name);
  1361. X  (void) fprintf(stderr,"Specify 'image.avs' as '-' for standard input. \n");
  1362. X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard output.\n");
  1363. X  exit(1);
  1364. }
  1365. X
  1366. /*
  1367. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1368. %                                                                             %
  1369. %                                                                             %
  1370. %                                                                             %
  1371. %  M a i n                                                                    %
  1372. %                                                                             %
  1373. %                                                                             %
  1374. %                                                                             %
  1375. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1376. %
  1377. %
  1378. */
  1379. int main(argc,argv)
  1380. int
  1381. X  argc;
  1382. X   
  1383. char
  1384. X  *argv[];
  1385. {
  1386. X  char
  1387. X    filename[256];
  1388. X
  1389. X  Image
  1390. X    *image;
  1391. X
  1392. X  int
  1393. X    i;
  1394. X
  1395. X  unsigned int
  1396. X    scene;
  1397. X
  1398. X  /*
  1399. X    Initialize program variables.
  1400. X  */
  1401. X  application_name=argv[0];
  1402. X  i=1;
  1403. X  scene=0;
  1404. X  if (argc < 3)
  1405. X    Usage((char *) NULL);
  1406. X  /*
  1407. X    Read image and convert to MIFF format.
  1408. X  */
  1409. X  if (strncmp(argv[i],"-scene",2) == 0)
  1410. X    {
  1411. X      i++;
  1412. X      scene=atoi(argv[i++]);
  1413. X    }
  1414. X  (void) strcpy(filename,argv[i++]);
  1415. X  image=ReadAVSImage(filename);
  1416. X  if (image == (Image *) NULL)
  1417. X    exit(1);
  1418. X  (void) strcpy(image->filename,argv[i++]);
  1419. X  image->scene=scene;
  1420. X  (void) WriteImage(image);
  1421. X  (void) fprintf(stderr,"%s => %s  %dx%d\n",filename,image->filename,
  1422. X    image->columns,image->rows);
  1423. X  DestroyImage(image);
  1424. X  return(False);
  1425. }
  1426. SHAR_EOF
  1427. chmod 0755 ImageMagick/filters/AVStoMIFF.c ||
  1428. echo 'restore of ImageMagick/filters/AVStoMIFF.c failed'
  1429. Wc_c="`wc -c < 'ImageMagick/filters/AVStoMIFF.c'`"
  1430. test 12689 -eq "$Wc_c" ||
  1431.     echo 'ImageMagick/filters/AVStoMIFF.c: original size 12689, current size' "$Wc_c"
  1432. rm -f _shar_wnt_.tmp
  1433. fi
  1434. # ============= ImageMagick/filters/XWDtoMIFF.c ==============
  1435. if test -f 'ImageMagick/filters/XWDtoMIFF.c' -a X"$1" != X"-c"; then
  1436.     echo 'x - skipping ImageMagick/filters/XWDtoMIFF.c (File already exists)'
  1437.     rm -f _shar_wnt_.tmp
  1438. else
  1439. > _shar_wnt_.tmp
  1440. echo 'x - extracting ImageMagick/filters/XWDtoMIFF.c (Text)'
  1441. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/XWDtoMIFF.c' &&
  1442. /*
  1443. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1444. %                                                                             %
  1445. %                                                                             %
  1446. %                                                                             %
  1447. %                 IIIII  M   M  PPPP    OOO   RRRR    TTTTT                   %
  1448. %                   I    MM MM  P   P  O   O  R   R     T                     %
  1449. %                   I    M M M  PPPP   O   O  RRRR      T                     %
  1450. %                   I    M   M  P      O   O  R R       T                     %
  1451. %                 IIIII  M   M  P       OOO   R  R      T                     %
  1452. %                                                                             %
  1453. %                                                                             %
  1454. %               Import X11 XWD raster image to a MIFF format.                 %
  1455. %                                                                             %
  1456. %                                                                             %
  1457. %                                                                             %
  1458. %                           Software Design                                   %
  1459. %                             John Cristy                                     %
  1460. %                            January  1991                                    %
  1461. %                                                                             %
  1462. %                                                                             %
  1463. %  Copyright 1991 E. I. Dupont de Nemours & Company                           %
  1464. %                                                                             %
  1465. %  Permission to use, copy, modify, distribute, and sell this software and    %
  1466. %  its documentation for any purpose is hereby granted without fee,           %
  1467. %  provided that the above Copyright notice appear in all copies and that     %
  1468. %  both that Copyright notice and this permission notice appear in            %
  1469. %  supporting documentation, and that the name of E. I. Dupont de Nemours     %
  1470. %  & Company not be used in advertising or publicity pertaining to            %
  1471. %  distribution of the software without specific, written prior               %
  1472. %  permission.  E. I. Dupont de Nemours & Company makes no representations    %
  1473. %  about the suitability of this software for any purpose.  It is provided    %
  1474. %  "as is" without express or implied warranty.                               %
  1475. %                                                                             %
  1476. %  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
  1477. %  to this software, including all implied warranties of merchantability      %
  1478. %  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
  1479. %  liable for any special, indirect or consequential damages or any           %
  1480. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  1481. %  in an action of contract, negligence or other tortious action, arising     %
  1482. %  out of or in connection with the use or performance of this software.      %
  1483. %                                                                             %
  1484. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1485. %
  1486. %  Command syntax:
  1487. %
  1488. %  import [-scene #] image.xwd image.miff
  1489. %
  1490. %  Specify 'image.xwd' as '-' for standard input.
  1491. %  Specify 'image.miff' as '-' for standard output.
  1492. %
  1493. %
  1494. */
  1495. X
  1496. #include "display.h"
  1497. #include "image.h"
  1498. #include "X.h"
  1499. X
  1500. /*
  1501. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1502. %                                                                             %
  1503. %                                                                             %
  1504. %                                                                             %
  1505. %   E r r o r                                                                 %
  1506. %                                                                             %
  1507. %                                                                             %
  1508. %                                                                             %
  1509. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1510. %
  1511. %  Function Error displays an error message and then terminates the program.
  1512. %
  1513. %  The format of the Error routine is:
  1514. %
  1515. %      Error(message,qualifier)
  1516. %
  1517. %  A description of each parameter follows:
  1518. %
  1519. %    o message:  Specifies the message to display before terminating the
  1520. %      program.
  1521. %
  1522. %    o qualifier:  Specifies any qualifier to the message.
  1523. %
  1524. %
  1525. */
  1526. void Error(message,qualifier)
  1527. char
  1528. X  *message,
  1529. X  *qualifier;
  1530. {
  1531. X  (void) fprintf(stderr,"%s: %s",application_name,message);
  1532. X  if (qualifier != (char *) NULL)
  1533. X    (void) fprintf(stderr," %s",qualifier);
  1534. X  (void) fprintf(stderr,".\n");
  1535. X  exit(1);
  1536. }
  1537. X
  1538. /*
  1539. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1540. %                                                                             %
  1541. %                                                                             %
  1542. %                                                                             %
  1543. %  M S B F i r s t O r d e r L o n g                                          %
  1544. %                                                                             %
  1545. %                                                                             %
  1546. %                                                                             %
  1547. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1548. %
  1549. %  Function MSBFirstOrderLong converts a least-significant byte first buffer
  1550. %  of long integers to most-significant byte first.
  1551. %
  1552. %  The format of the MSBFirstOrderLong routine is:
  1553. %
  1554. %       MSBFirstOrderLong(p,length);
  1555. %
  1556. %  A description of each parameter follows.
  1557. %
  1558. %   o  p:  Specifies a pointer to a buffer of integers.
  1559. %
  1560. %   o  length:  Specifies the length of the buffer.
  1561. %
  1562. %
  1563. */
  1564. MSBFirstOrderLong(p,length)
  1565. register char
  1566. X  *p;
  1567. X
  1568. register unsigned
  1569. X  length;
  1570. {
  1571. X  register char
  1572. X    c,
  1573. X    *q,
  1574. X    *sp;
  1575. X
  1576. X  q=p+length;
  1577. X  while (p < q)
  1578. X  {
  1579. X    sp=p+3;
  1580. X    c=(*sp);
  1581. X    *sp=(*p);
  1582. X    *p++=c;
  1583. X    sp=p+1;
  1584. X    c=(*sp);
  1585. X    *sp=(*p);
  1586. X    *p++=c;
  1587. X    p+=2;
  1588. X  }
  1589. }
  1590. X
  1591. /*
  1592. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1593. %                                                                             %
  1594. %                                                                             %
  1595. %                                                                             %
  1596. %  M S B F i r s t O r d e r S h o r t                                        %
  1597. %                                                                             %
  1598. %                                                                             %
  1599. %                                                                             %
  1600. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1601. %
  1602. %  Function MSBFirstOrderShort converts a least-significant byte first buffer
  1603. %  of short integers to most-significant byte first.
  1604. %
  1605. %  The format of the MSBFirstOrderShort routine is:
  1606. %
  1607. %       MSBFirstOrderShort(p,length);
  1608. %
  1609. %  A description of each parameter follows.
  1610. %
  1611. %   o  p:  Specifies a pointer to a buffer of integers.
  1612. %
  1613. %   o  length:  Specifies the length of the buffer.
  1614. %
  1615. %
  1616. */
  1617. MSBFirstOrderShort(p,length)
  1618. register char
  1619. X  *p;
  1620. X
  1621. register unsigned
  1622. X  length;
  1623. {
  1624. X  register char
  1625. X    c,
  1626. X    *q;
  1627. X
  1628. X  q=p+length;
  1629. X  while (p < q)
  1630. X  {
  1631. X    c=(*p);
  1632. X    *p=(*(p+1));
  1633. X    p++;
  1634. X    *p++=c;
  1635. X  }
  1636. }
  1637. X
  1638. /*
  1639. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1640. %                                                                             %
  1641. %                                                                             %
  1642. %                                                                             %
  1643. %  R e a d X W D I m a g e                                                    %
  1644. %                                                                             %
  1645. %                                                                             %
  1646. %                                                                             %
  1647. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1648. %
  1649. %  Function ReadXWDImage reads an image file and returns it.  It allocates the 
  1650. %  memory necessary for the new Image structure and returns a pointer to the 
  1651. %  new image.
  1652. %
  1653. %  The format of the ReadXWDImage routine is:
  1654. %
  1655. %      image=ReadXWDImage(filename)
  1656. %
  1657. %  A description of each parameter follows:
  1658. %
  1659. %    o image:  Function ReadXWDImage returns a pointer to the image after 
  1660. %      reading.  A null image is returned if there is a a memory shortage or 
  1661. %      if the image cannot be read.
  1662. %
  1663. %    o filename:  Specifies the name of the image to read.
  1664. %
  1665. %
  1666. */
  1667. static Image *ReadXWDImage(filename)
  1668. char
  1669. X  *filename;
  1670. {
  1671. #include <X11/XWDFile.h>
  1672. X
  1673. X  char
  1674. X    *window_name;
  1675. X
  1676. X  Image
  1677. X    *image;
  1678. X
  1679. X  int
  1680. X    status,
  1681. X    x,
  1682. X    y;
  1683. X
  1684. X  register int
  1685. X    i;
  1686. X
  1687. X  register RunlengthPacket
  1688. X    *p;
  1689. X
  1690. X  register unsigned long
  1691. X    pixel;
  1692. X
  1693. X  unsigned char
  1694. X    blue,
  1695. X    green,
  1696. X    red;
  1697. X
  1698. X  unsigned int
  1699. X    packets;
  1700. X
  1701. X  unsigned long
  1702. X    lsb_first;
  1703. X
  1704. X  XColor
  1705. X    *colors;
  1706. X
  1707. X  XImage
  1708. X    ximage;
  1709. X
  1710. X  XWDFileHeader
  1711. X    header;
  1712. X
  1713. X  /*
  1714. X    Allocate image structure.
  1715. X  */
  1716. X  image=(Image *) malloc(sizeof(Image));
  1717. X  if (image == (Image *) NULL)
  1718. X    Error("unable to allocate memory",(char *) NULL);
  1719. X  /*
  1720. X    Initialize Image structure.
  1721. X  */
  1722. X  image->id=UnknownId;
  1723. X  image->class=DirectClass;
  1724. X  image->compression=RunlengthEncodedCompression;
  1725. X  image->columns=0;
  1726. X  image->rows=0;
  1727. X  image->packets=0;
  1728. X  image->colors=0;
  1729. X  image->scene=0;
  1730. X  image->colormap=(ColorPacket *) NULL;
  1731. X  image->pixels=(RunlengthPacket *) NULL;
  1732. X  image->comments=(char *) NULL;
  1733. X  /*
  1734. X    Open image file.
  1735. X  */
  1736. X  (void) strcpy(image->filename,filename);
  1737. X  if (*image->filename == '-')
  1738. X    image->file=stdin;
  1739. X  else
  1740. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  1741. X      image->file=fopen(image->filename,"r");
  1742. X    else
  1743. X      {
  1744. X        char
  1745. X          command[256];
  1746. X
  1747. X        /*
  1748. X          Image file is compressed-- uncompress it.
  1749. X        */
  1750. X        (void) sprintf(command,"uncompress -c %s",image->filename);
  1751. X        image->file=(FILE *) popen(command,"r");
  1752. X      }
  1753. X  if (image->file == (FILE *) NULL)
  1754. X    Error("unable to open file",image->filename);
  1755. X  /*
  1756. X     Read in header information.
  1757. X  */
  1758. X  status=ReadData((char *) &header,sizeof(header),1,image->file);
  1759. X  if (status == False)
  1760. X    Error("Unable to read dump file header",image->filename);
  1761. X  /*
  1762. X    Ensure the header byte-order is most-significant byte first.
  1763. X  */
  1764. X  lsb_first=1;
  1765. X  if (*(char *) &lsb_first)
  1766. X    MSBFirstOrderLong((char *) &header,sizeof(header));
  1767. X  /*
  1768. X    Check to see if the dump file is in the proper format.
  1769. X  */
  1770. X  if (header.file_version != XWD_FILE_VERSION)
  1771. X    Error("XWD file format version mismatch",image->filename);
  1772. X  if (header.header_size < sizeof(header))
  1773. X    Error("XWD header size is too small",image->filename);
  1774. X  packets=(header.header_size-sizeof(header));
  1775. X  window_name=(char *) malloc((unsigned int) packets);
  1776. X  if (window_name == (char *) NULL)
  1777. X    Error("unable to allocate memory",(char *) NULL);
  1778. X  status=ReadData((char *) window_name,sizeof(char),(int) packets,image->file);
  1779. X  if (status == False)
  1780. X    Error("unable to read window name from dump file",image->filename);
  1781. X  /*
  1782. X    Initialize the X image.
  1783. X  */
  1784. X  ximage.width=(int) header.pixmap_width;
  1785. X  ximage.height=(int) header.pixmap_height;
  1786. X  ximage.xoffset=(int) header.xoffset;
  1787. X  ximage.format=(int) header.pixmap_format;
  1788. X  ximage.byte_order=(int) header.byte_order;
  1789. X  ximage.bitmap_unit=(int) header.bitmap_unit;
  1790. X  ximage.bitmap_bit_order=(int) header.bitmap_bit_order;
  1791. X  ximage.bitmap_pad=(int) header.bitmap_pad;
  1792. X  ximage.depth=(int) header.pixmap_depth;
  1793. X  ximage.bits_per_pixel=(int) header.bits_per_pixel;
  1794. X  ximage.bytes_per_line=(int) header.bytes_per_line;
  1795. X  ximage.red_mask=header.red_mask;
  1796. X  ximage.green_mask=header.green_mask;
  1797. X  ximage.blue_mask=header.blue_mask;
  1798. X  ximage.obdata=NULL;
  1799. X  _XInitImageFuncPtrs(&ximage);
  1800. X  /*
  1801. X    Read colormap.
  1802. X  */
  1803. X  if (header.ncolors > 0)
  1804. X    {
  1805. X      colors=(XColor *) malloc((unsigned) header.ncolors*sizeof(XColor));
  1806. X      if (colors == (XColor *) NULL)
  1807. X        Error("unable to allocate memory",(char *) NULL);
  1808. X      status=ReadData((char *) colors,sizeof(XColor),(int) header.ncolors,
  1809. X    image->file);
  1810. X      if (status == False)
  1811. X        Error("unable to read color map from dump file",image->filename);
  1812. X      /*
  1813. X        Ensure the header byte-order is most-significant byte first.
  1814. X      */
  1815. X      lsb_first=1;
  1816. X      if (*(char *) &lsb_first)
  1817. X        for (i=0; i < header.ncolors; i++)
  1818. X        {
  1819. X          MSBFirstOrderLong((char *) &colors[i].pixel,sizeof(unsigned long));
  1820. X          MSBFirstOrderShort((char *) &colors[i].red,3*sizeof(unsigned short));
  1821. X        }
  1822. X    }
  1823. X  /*
  1824. X    Allocate the pixel buffer.
  1825. X  */
  1826. X  if (ximage.format == ZPixmap)
  1827. X    packets=ximage.bytes_per_line*ximage.height;
  1828. X  else
  1829. X    packets=ximage.bytes_per_line*ximage.height*ximage.depth;
  1830. X  ximage.data=(char *) malloc((unsigned int) packets);
  1831. X  if (ximage.data == (char *) NULL)
  1832. X    Error("unable to allocate memory",(char *) NULL);
  1833. X  status=ReadData(ximage.data,sizeof(char),(int) packets,image->file);
  1834. X  if (status == False)
  1835. X    Error("unable to read dump pixmap",image->filename);
  1836. X  if (*image->filename != '-')
  1837. X    (void) fclose(image->file);
  1838. X  /*
  1839. X    Convert image to MIFF format.
  1840. X  */
  1841. X  image->columns=ximage.width;
  1842. X  image->rows=ximage.height;
  1843. X  /*
  1844. X    Initial image comment.
  1845. X  */
  1846. X  image->comments=(char *) 
  1847. X    malloc((unsigned int) (strlen(image->filename)+256));
  1848. X  if (image->comments == (char *) NULL)
  1849. X    Error("unable to allocate memory",(char *) NULL);
  1850. X  (void) sprintf(image->comments,"\n  Imported from X11 dump file:  %s\n\0",
  1851. X    image->filename);
  1852. X  if ((ximage.red_mask > 0) || (ximage.green_mask > 0) ||
  1853. X      (ximage.blue_mask > 0))
  1854. X    image->class=DirectClass;
  1855. X  else
  1856. X    image->class=PseudoClass;
  1857. X  image->colors=header.ncolors;
  1858. X  image->pixels=(RunlengthPacket *)
  1859. X    malloc(image->columns*image->rows*sizeof(RunlengthPacket));
  1860. X  if (image->pixels == (RunlengthPacket *) NULL)
  1861. X    Error("unable to allocate memory",(char *) NULL);
  1862. X  image->packets=0;
  1863. X  p=image->pixels;
  1864. X  p->length=MaxRunlength;
  1865. X  switch (image->class)
  1866. X  {
  1867. X    case DirectClass:
  1868. X    {
  1869. X      register unsigned long
  1870. X        color,
  1871. X        index;
  1872. X
  1873. X      unsigned long
  1874. X        blue_mask,
  1875. X        blue_shift,
  1876. X        green_mask,
  1877. X        green_shift,
  1878. X        red_mask,
  1879. X        red_shift;
  1880. X
  1881. X      /*
  1882. X        Determine shift and mask for red, green, and blue.
  1883. X      */
  1884. X      red_mask=ximage.red_mask;
  1885. X      red_shift=0;
  1886. X      while ((red_mask & 0x01) == 0)
  1887. X      {
  1888. X        red_mask>>=1;
  1889. X        red_shift++;
  1890. X      }
  1891. X      green_mask=ximage.green_mask;
  1892. X      green_shift=0;
  1893. X      while ((green_mask & 0x01) == 0)
  1894. X      {
  1895. X        green_mask>>=1;
  1896. X        green_shift++;
  1897. X      }
  1898. X      blue_mask=ximage.blue_mask;
  1899. X      blue_shift=0;
  1900. X      while ((blue_mask & 0x01) == 0)
  1901. X      {
  1902. X        blue_mask>>=1;
  1903. X        blue_shift++;
  1904. X      }
  1905. X      /*
  1906. X        Convert X image to DirectClass packets.
  1907. X      */
  1908. X      if (image->colors > 0)
  1909. X        for (y=0; y < image->rows; y++)
  1910. X        {
  1911. X          for (x=0; x < image->columns; x++)
  1912. X          {
  1913. X            pixel=XGetPixel(&ximage,x,y);
  1914. X            index=(pixel >> red_shift) & red_mask;
  1915. X            red=(unsigned char) (colors[index].red >> 8);
  1916. X            index=(pixel >> green_shift) & green_mask;
  1917. X            green=(unsigned char) (colors[index].green >> 8);
  1918. X            index=(pixel >> blue_shift) & blue_mask;
  1919. X            blue=(unsigned char) (colors[index].blue >> 8);
  1920. X            if ((red == p->red) && (green == p->green) && (blue == p->blue) &&
  1921. X                (p->length < MaxRunlength))
  1922. X                p->length++;
  1923. X              else
  1924. X                {
  1925. X                  if (image->packets > 0)
  1926. X                    p++;
  1927. X                  image->packets++;
  1928. X                  p->red=red;
  1929. X                  p->green=green;
  1930. X                  p->blue=blue;
  1931. X                  p->index=0;
  1932. X                  p->length=0;
  1933. X                }
  1934. X          }
  1935. X        }
  1936. X      else
  1937. X        for (y=0; y < image->rows; y++)
  1938. X          for (x=0; x < image->columns; x++)
  1939. X          {
  1940. X            pixel=XGetPixel(&ximage,x,y);
  1941. X            color=(pixel >> red_shift) & red_mask;
  1942. X            red=(unsigned char)
  1943. X              ((((unsigned long) color*65535)/red_mask) >> 8);
  1944. X            color=(pixel >> green_shift) & green_mask;
  1945. X            green=(unsigned char)
  1946. X              ((((unsigned long) color*65535)/green_mask) >> 8);
  1947. X            color=(pixel >> blue_shift) & blue_mask;
  1948. X            blue=(unsigned char)
  1949. X              ((((unsigned long) color*65535)/blue_mask) >> 8);
  1950. X            if ((red == p->red) && (green == p->green) && (blue == p->blue) &&
  1951. X                (p->length < MaxRunlength))
  1952. X                p->length++;
  1953. X              else
  1954. X                {
  1955. X                  if (image->packets > 0)
  1956. X                    p++;
  1957. X                  image->packets++;
  1958. X                  p->red=red;
  1959. X                  p->green=green;
  1960. X                  p->blue=blue;
  1961. X                  p->index=0;
  1962. X                  p->length=0;
  1963. X                }
  1964. X          }
  1965. X      break;
  1966. X    }
  1967. X    case PseudoClass:
  1968. X    {
  1969. X      /*
  1970. X        Convert X image to PseudoClass packets.
  1971. X      */
  1972. X      image->colormap=(ColorPacket *)
  1973. X        malloc((unsigned) (image->colors*sizeof(ColorPacket)));
  1974. X      if (image->colormap == (ColorPacket *) NULL)
  1975. X        Error("unable to allocate memory",(char *) NULL);
  1976. X      for (i=0; i < image->colors; i++)
  1977. X      {
  1978. X        image->colormap[i].red=colors[i].red >> 8;
  1979. X        image->colormap[i].green=colors[i].green >> 8;
  1980. X        image->colormap[i].blue=colors[i].blue >> 8;
  1981. X      }
  1982. X      for (y=0; y < image->rows; y++)
  1983. X        for (x=0; x < image->columns; x++)
  1984. X        {
  1985. X          pixel=XGetPixel(&ximage,x,y);
  1986. X          red=(unsigned char) (colors[pixel].red >> 8);
  1987. X          green=(unsigned char) (colors[pixel].green >> 8);
  1988. X          blue=(unsigned char) (colors[pixel].blue >> 8);
  1989. X          if ((red == p->red) && (green == p->green) && (blue == p->blue) &&
  1990. X              (p->length < MaxRunlength))
  1991. X              p->length++;
  1992. X            else
  1993. X              {
  1994. X                if (image->packets > 0)
  1995. X                  p++;
  1996. X                image->packets++;
  1997. X                p->red=red;
  1998. X                p->green=green;
  1999. X                p->blue=blue;
  2000. X                p->index=(unsigned short) pixel;
  2001. X                p->length=0;
  2002. X              }
  2003. X        }
  2004. X      break;
  2005. X    }
  2006. X  }
  2007. X  /*
  2008. X    Free image and colormap.
  2009. X  */
  2010. X  (void) free((char *) window_name);
  2011. X  if (header.ncolors > 0)
  2012. X    (void) free((char *) colors);
  2013. X  (void) free((char *) ximage.data);
  2014. X  if (image->file != stdin)
  2015. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  2016. X      (void) fclose(image->file);
  2017. X    else
  2018. X      (void) pclose(image->file);
  2019. X  if (image->packets > ((image->columns*image->rows*3) >> 2))
  2020. X    image->compression=NoCompression;
  2021. X  image->pixels=(RunlengthPacket *)
  2022. X    realloc((char *) image->pixels,image->packets*sizeof(RunlengthPacket));
  2023. X  return(image);
  2024. }
  2025. X
  2026. /*
  2027. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2028. %                                                                             %
  2029. %                                                                             %
  2030. %                                                                             %
  2031. %   U s a g e                                                                 %
  2032. %                                                                             %
  2033. %                                                                             %
  2034. %                                                                             %
  2035. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2036. %
  2037. %  Procedure Usage displays the program usage;
  2038. %
  2039. %  The format of the Usage routine is:
  2040. %
  2041. %      Usage(message)
  2042. %
  2043. %  A description of each parameter follows:
  2044. %
  2045. %    message:  Specifies a specific message to display to the user.
  2046. %
  2047. */
  2048. static void Usage(message)
  2049. char
  2050. X  *message;
  2051. {
  2052. X  if (message != (char *) NULL)
  2053. X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
  2054. X  (void) fprintf(stderr,"Usage: %s [-scene #] image.xwd image.miff\n\n",
  2055. X    application_name);
  2056. X  (void) fprintf(stderr,"Specify 'image.xwd' as '-' for standard input.\n");
  2057. X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard output.\n");
  2058. X  exit(1);
  2059. }
  2060. X
  2061. /*
  2062. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2063. %                                                                             %
  2064. %                                                                             %
  2065. %                                                                             %
  2066. %  M a i n                                                                    %
  2067. %                                                                             %
  2068. %                                                                             %
  2069. %                                                                             %
  2070. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2071. %
  2072. %
  2073. */
  2074. int main(argc,argv)
  2075. int
  2076. X  argc;
  2077. X   
  2078. char
  2079. X  *argv[];
  2080. {
  2081. X  char
  2082. X    filename[256];
  2083. X
  2084. X  Image
  2085. X    *image;
  2086. X
  2087. X  int
  2088. X    i;
  2089. X
  2090. X  unsigned int
  2091. X    scene;
  2092. X
  2093. X  /*
  2094. X    Initialize program variables.
  2095. X  */
  2096. X  application_name=argv[0];
  2097. X  i=1;
  2098. X  scene=0;
  2099. X  if (argc < 3)
  2100. X    Usage((char *) NULL);
  2101. X  /*
  2102. X    Read image and convert to MIFF format.
  2103. X  */
  2104. X  if (strncmp(argv[i],"-scene",2) == 0)
  2105. X    {
  2106. X      i++;
  2107. X      scene=atoi(argv[i++]);
  2108. X    }
  2109. X  (void) strcpy(filename,argv[i++]);
  2110. X  image=ReadXWDImage(filename);
  2111. X  if (image == (Image *) NULL)
  2112. X    exit(1);
  2113. X  (void) strcpy(image->filename,argv[i++]);
  2114. X  image->scene=scene;
  2115. X  (void) WriteImage(image);
  2116. X  (void) fprintf(stderr,"%s => %s  %dx%d\n",filename,image->filename,
  2117. X    image->columns,image->rows);
  2118. X  DestroyImage(image);
  2119. X  return(False);
  2120. }
  2121. SHAR_EOF
  2122. chmod 0755 ImageMagick/filters/XWDtoMIFF.c ||
  2123. echo 'restore of ImageMagick/filters/XWDtoMIFF.c failed'
  2124. Wc_c="`wc -c < 'ImageMagick/filters/XWDtoMIFF.c'`"
  2125. test 22134 -eq "$Wc_c" ||
  2126.     echo 'ImageMagick/filters/XWDtoMIFF.c: original size 22134, current size' "$Wc_c"
  2127. rm -f _shar_wnt_.tmp
  2128. fi
  2129. # ============= ImageMagick/filters/Imakefile ==============
  2130. if test -f 'ImageMagick/filters/Imakefile' -a X"$1" != X"-c"; then
  2131.     echo 'x - skipping ImageMagick/filters/Imakefile (File already exists)'
  2132.     rm -f _shar_wnt_.tmp
  2133. else
  2134. > _shar_wnt_.tmp
  2135. echo 'x - extracting ImageMagick/filters/Imakefile (Text)'
  2136. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/Imakefile' &&
  2137. EXTRA_INCLUDES= -I/usr/local/include -I..
  2138. SHAR_EOF
  2139. true || echo 'restore of ImageMagick/filters/Imakefile failed'
  2140. fi
  2141. echo 'End of ImageMagick part 13'
  2142. echo 'File ImageMagick/filters/Imakefile is continued in part 14'
  2143. echo 14 > _shar_seq_.tmp
  2144. exit 0
  2145. --
  2146. Dan Heller
  2147. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  2148. Senior Writer                President          comp-sources-x@uunet.uu.net
  2149. argv@ora.com                 argv@zipcode.com
  2150.