home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume13 / imagemagic / part15 < prev    next >
Internet Message Format  |  1991-05-23  |  75KB

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