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

  1. Path: uunet!uunet!elroy.jpl.nasa.gov!usc!apple!sun-barr!newstop!exodus!dupont.com!cristy
  2. From: cristy@dupont.com
  3. Newsgroups: comp.sources.x
  4. Subject: v13i032: ImageMagick - Graphics display programs, Part16/21
  5. Message-ID: <13946@exodus.Eng.Sun.COM>
  6. Date: 24 May 91 03:19:55 GMT
  7. References: <csx-13i017:imagemagic@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 2114
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: cristy@dupont.com
  13. Posting-number: Volume 13, Issue 32
  14. Archive-name: imagemagic/part16
  15.  
  16. #!/bin/sh
  17. # this is img.16 (part 16 of ImageMagick)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file ImageMagick/filters/MIFFtoMTV.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" != 16; 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/MIFFtoMTV.c'
  35. else
  36. echo 'x - continuing file ImageMagick/filters/MIFFtoMTV.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/filters/MIFFtoMTV.c' &&
  38. X    exit(1);
  39. X  (void) strcpy(image->filename,argv[2]);
  40. X  WriteMTVImage(image);
  41. X  (void) fprintf(stderr,"%s=> %s  %dx%d\n",argv[1],argv[2],image->columns,
  42. X    image->rows);
  43. X  return(False);
  44. }
  45. SHAR_EOF
  46. echo 'File ImageMagick/filters/MIFFtoMTV.c is complete' &&
  47. chmod 0755 ImageMagick/filters/MIFFtoMTV.c ||
  48. echo 'restore of ImageMagick/filters/MIFFtoMTV.c failed'
  49. Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoMTV.c'`"
  50. test 9938 -eq "$Wc_c" ||
  51.     echo 'ImageMagick/filters/MIFFtoMTV.c: original size 9938, current size' "$Wc_c"
  52. rm -f _shar_wnt_.tmp
  53. fi
  54. # ============= ImageMagick/filters/MIFFtoRGB.c ==============
  55. if test -f 'ImageMagick/filters/MIFFtoRGB.c' -a X"$1" != X"-c"; then
  56.     echo 'x - skipping ImageMagick/filters/MIFFtoRGB.c (File already exists)'
  57.     rm -f _shar_wnt_.tmp
  58. else
  59. > _shar_wnt_.tmp
  60. echo 'x - extracting ImageMagick/filters/MIFFtoRGB.c (Text)'
  61. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoRGB.c' &&
  62. /*
  63. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  64. %                                                                             %
  65. %                                                                             %
  66. %                                                                             %
  67. %                 EEEEE  X   X  PPPP    OOO   RRRR    TTTTT                   %
  68. %                 E       X X   P   P  O   O  R   R     T                     %
  69. %                 EEE      X    PPPP   O   O  RRRR      T                     %
  70. %                 E       X X   P      O   O  R R       T                     %
  71. %                 EEEEE  X   X  P       OOO   R  R      T                     %
  72. %                                                                             %
  73. %                                                                             %
  74. %                  Export MIFF image to a RGB raster format.                  %
  75. %                                                                             %
  76. %                                                                             %
  77. %                                                                             %
  78. %                           Software Design                                   %
  79. %                             John Cristy                                     %
  80. %                            January  1991                                    %
  81. %                                                                             %
  82. %                                                                             %
  83. %  Copyright 1991 E. I. Dupont de Nemours & Company                           %
  84. %                                                                             %
  85. %  Permission to use, copy, modify, distribute, and sell this software and    %
  86. %  its documentation for any purpose is hereby granted without fee,           %
  87. %  provided that the above Copyright notice appear in all copies and that     %
  88. %  both that Copyright notice and this permission notice appear in            %
  89. %  supporting documentation, and that the name of E. I. Dupont de Nemours     %
  90. %  & Company not be used in advertising or publicity pertaining to            %
  91. %  distribution of the software without specific, written prior               %
  92. %  permission.  E. I. Dupont de Nemours & Company makes no representations    %
  93. %  about the suitability of this software for any purpose.  It is provided    %
  94. %  "as is" without express or implied warranty.                               %
  95. %                                                                             %
  96. %  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
  97. %  to this software, including all implied warranties of merchantability      %
  98. %  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
  99. %  liable for any special, indirect or consequential damages or any           %
  100. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  101. %  in an action of contract, negligence or other tortious action, arising     %
  102. %  out of or in connection with the use or performance of this software.      %
  103. %                                                                             %
  104. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  105. %
  106. %  Command syntax:
  107. %
  108. %  export image.miff image.rgb
  109. %
  110. %  Specify 'image.miff' as '-' for standard input.  
  111. %  Specify 'image.rgb' as '-' for standard output.
  112. %
  113. %
  114. */
  115. X
  116. #include "display.h"
  117. #include "image.h"
  118. X
  119. /*
  120. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  121. %                                                                             %
  122. %                                                                             %
  123. %                                                                             %
  124. %   E r r o r                                                                 %
  125. %                                                                             %
  126. %                                                                             %
  127. %                                                                             %
  128. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  129. %
  130. %  Function Error displays an error message and then terminates the program.
  131. %
  132. %  The format of the Error routine is:
  133. %
  134. %      Error(message,qualifier)
  135. %
  136. %  A description of each parameter follows:
  137. %
  138. %    o message:  Specifies the message to display before terminating the
  139. %      program.
  140. %
  141. %    o qualifier:  Specifies any qualifier to the message.
  142. %
  143. %
  144. */
  145. static void Error(message,qualifier)
  146. char
  147. X  *message,
  148. X  *qualifier;
  149. {
  150. X  (void) fprintf(stderr,"%s: %s",application_name,message); 
  151. X  if (qualifier != (char *) NULL)
  152. X    (void) fprintf(stderr," %s",qualifier);
  153. X  (void) fprintf(stderr,".\n");
  154. X  exit(1);
  155. }
  156. X
  157. /*
  158. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  159. %                                                                             %
  160. %                                                                             %
  161. %                                                                             %
  162. %   U s a g e                                                                 %
  163. %                                                                             %
  164. %                                                                             %
  165. %                                                                             %
  166. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  167. %
  168. %  Procedure Usage displays the program usage;
  169. %
  170. %  The format of the Usage routine is:
  171. %
  172. %      Usage(message)
  173. %
  174. %  A description of each parameter follows:
  175. %
  176. %    message:  Specifies a specific message to display to the user.
  177. %
  178. */
  179. static void Usage(message)
  180. char
  181. X  *message;
  182. {
  183. X  if (message != (char *) NULL)
  184. X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
  185. X  (void) fprintf(stderr,"Usage: %s image.miff image.rgb\n\n",application_name);
  186. X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
  187. X  (void) fprintf(stderr,"Specify 'image.rgb' as '-' for standard output.\n");
  188. X  exit(1);
  189. }
  190. X
  191. /*
  192. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  193. %                                                                             %
  194. %                                                                             %
  195. %                                                                             %
  196. %   W r i t e R G B I m a g e                                                 %
  197. %                                                                             %
  198. %                                                                             %
  199. %                                                                             %
  200. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  201. %
  202. %  Procedure WriteRGBImage writes an image to a file on disk in red, green,
  203. %  blue rasterfile format.
  204. %
  205. %  The format of the WriteRGBImage routine is:
  206. %
  207. %      WriteRGBImage(image)
  208. %
  209. %  A description of each parameter follows.
  210. %
  211. %    o image:  A pointer to a Image structure.
  212. %
  213. %
  214. */
  215. static void WriteRGBImage(image)
  216. Image
  217. X  *image;
  218. {
  219. X  register int
  220. X    i,
  221. X    j;
  222. X
  223. X  register RunlengthPacket
  224. X    *p;
  225. X
  226. X  register unsigned char
  227. X    *q;
  228. X
  229. X  unsigned char
  230. X    *pixels;
  231. X
  232. X  /*
  233. X    Open output image file.
  234. X  */
  235. X  if (*image->filename == '-')
  236. X    image->file=stdout;
  237. X  else
  238. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  239. X      image->file=fopen(image->filename,"w");
  240. X    else
  241. X      {
  242. X        char
  243. X          command[256];
  244. X
  245. X        /*
  246. X          Image file is compressed-- uncompress it.
  247. X        */
  248. X        (void) sprintf(command,"compress -c > %s",image->filename);
  249. X        image->file=(FILE *) popen(command,"w");
  250. X      }
  251. X  if (image->file == (FILE *) NULL)
  252. X    Error("unable to open file",image->filename);
  253. X  /*
  254. X    Convert MIFF to RGB raster pixels.
  255. X  */
  256. X  pixels=(unsigned char *) 
  257. X    malloc(3*image->columns*image->rows*sizeof(unsigned char));
  258. X  if (pixels == (unsigned char *) NULL)
  259. X    Error("unable to allocate memory",(char *) NULL);
  260. X  p=image->pixels;
  261. X  q=pixels;
  262. X  for (i=0; i < image->packets; i++)
  263. X  {
  264. X    for (j=0; j <= p->length; j++)
  265. X    {
  266. X      *q++=p->red;
  267. X      *q++=p->green;
  268. X      *q++=p->blue;
  269. X    }
  270. X    p++;
  271. X  }
  272. X  (void) fwrite((char *) pixels,sizeof(unsigned char),
  273. X    (int) 3*image->columns*image->rows,image->file);
  274. X  (void) free((char *) pixels);
  275. X  if (image->file != stdin)
  276. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  277. X      (void) fclose(image->file);
  278. X    else
  279. X      (void) pclose(image->file);
  280. }
  281. X
  282. /*
  283. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  284. %                                                                             %
  285. %                                                                             %
  286. %                                                                             %
  287. %    M a i n                                                                  %
  288. %                                                                             %
  289. %                                                                             %
  290. %                                                                             %
  291. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  292. %
  293. %
  294. */
  295. int main(argc,argv)
  296. int
  297. X  argc;
  298. X
  299. char
  300. X  *argv[];
  301. {
  302. X  Image
  303. X    *image;
  304. X
  305. X  application_name=argv[0];
  306. X  if (argc < 3)
  307. X    Usage((char *) NULL);
  308. X  image=ReadImage(argv[1]);
  309. X  if (image == (Image *) NULL)
  310. X    exit(1);
  311. X  (void) strcpy(image->filename,argv[2]);
  312. X  WriteRGBImage(image);
  313. X  (void) fprintf(stderr,"%s=> %s  %dx%d\n",argv[1],argv[2],image->columns,
  314. X    image->rows);
  315. X  return(False);
  316. }
  317. SHAR_EOF
  318. chmod 0755 ImageMagick/filters/MIFFtoRGB.c ||
  319. echo 'restore of ImageMagick/filters/MIFFtoRGB.c failed'
  320. Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoRGB.c'`"
  321. test 9872 -eq "$Wc_c" ||
  322.     echo 'ImageMagick/filters/MIFFtoRGB.c: original size 9872, current size' "$Wc_c"
  323. rm -f _shar_wnt_.tmp
  324. fi
  325. # ============= ImageMagick/filters/MIFFtoXWD.c ==============
  326. if test -f 'ImageMagick/filters/MIFFtoXWD.c' -a X"$1" != X"-c"; then
  327.     echo 'x - skipping ImageMagick/filters/MIFFtoXWD.c (File already exists)'
  328.     rm -f _shar_wnt_.tmp
  329. else
  330. > _shar_wnt_.tmp
  331. echo 'x - extracting ImageMagick/filters/MIFFtoXWD.c (Text)'
  332. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoXWD.c' &&
  333. /*
  334. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  335. %                                                                             %
  336. %                                                                             %
  337. %                                                                             %
  338. %                 EEEEE  X   X  PPPP    OOO   RRRR    TTTTT                   %
  339. %                 E       X X   P   P  O   O  R   R     T                     %
  340. %                 EEE      X    PPPP   O   O  RRRR      T                     %
  341. %                 E       X X   P      O   O  R R       T                     %
  342. %                 EEEEE  X   X  P       OOO   R  R      T                     %
  343. %                                                                             %
  344. %                                                                             %
  345. %                  Export MIFF image to a XWD raster format.                  %
  346. %                                                                             %
  347. %                                                                             %
  348. %                                                                             %
  349. %                           Software Design                                   %
  350. %                             John Cristy                                     %
  351. %                            January  1991                                    %
  352. %                                                                             %
  353. %                                                                             %
  354. %  Copyright 1991 E. I. Dupont de Nemours & Company                           %
  355. %                                                                             %
  356. %  Permission to use, copy, modify, distribute, and sell this software and    %
  357. %  its documentation for any purpose is hereby granted without fee,           %
  358. %  provided that the above Copyright notice appear in all copies and that     %
  359. %  both that Copyright notice and this permission notice appear in            %
  360. %  supporting documentation, and that the name of E. I. Dupont de Nemours     %
  361. %  & Company not be used in advertising or publicity pertaining to            %
  362. %  distribution of the software without specific, written prior               %
  363. %  permission.  E. I. Dupont de Nemours & Company makes no representations    %
  364. %  about the suitability of this software for any purpose.  It is provided    %
  365. %  "as is" without express or implied warranty.                               %
  366. %                                                                             %
  367. %  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
  368. %  to this software, including all implied warranties of merchantability      %
  369. %  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
  370. %  liable for any special, indirect or consequential damages or any           %
  371. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  372. %  in an action of contract, negligence or other tortious action, arising     %
  373. %  out of or in connection with the use or performance of this software.      %
  374. %                                                                             %
  375. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  376. %
  377. %  Command syntax:
  378. %
  379. %  export image.miff image.xwd
  380. %
  381. %  Specify 'image.miff' as '-' for standard input.  
  382. %  Specify 'image.xwd' as '-' for standard output.
  383. %
  384. %
  385. */
  386. X
  387. #include "display.h"
  388. #include "image.h"
  389. #include "X.h"
  390. #include "X11/XWDFile.h"
  391. X
  392. /*
  393. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  394. %                                                                             %
  395. %                                                                             %
  396. %                                                                             %
  397. %   E r r o r                                                                 %
  398. %                                                                             %
  399. %                                                                             %
  400. %                                                                             %
  401. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  402. %
  403. %  Function Error displays an error message and then terminates the program.
  404. %
  405. %  The format of the Error routine is:
  406. %
  407. %      Error(message,qualifier)
  408. %
  409. %  A description of each parameter follows:
  410. %
  411. %    o message:  Specifies the message to display before terminating the
  412. %      program.
  413. %
  414. %    o qualifier:  Specifies any qualifier to the message.
  415. %
  416. %
  417. */
  418. static void Error(message,qualifier)
  419. char
  420. X  *message,
  421. X  *qualifier;
  422. {
  423. X  (void) fprintf(stderr,"%s: %s",application_name,message); 
  424. X  if (qualifier != (char *) NULL)
  425. X    (void) fprintf(stderr," %s",qualifier);
  426. X  (void) fprintf(stderr,".\n");
  427. X  exit(1);
  428. }
  429. X
  430. /*
  431. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  432. %                                                                             %
  433. %                                                                             %
  434. %                                                                             %
  435. %  M S B F i r s t O r d e r L o n g                                          %
  436. %                                                                             %
  437. %                                                                             %
  438. %                                                                             %
  439. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  440. %
  441. %  Function MSBFirstOrderLong converts a least-significant byte first buffer
  442. %  of long integers to most-significant byte first.
  443. %
  444. %  The format of the MSBFirstOrderLong routine is:
  445. %
  446. %       MSBFirstOrderLong(p,length);
  447. %
  448. %  A description of each parameter follows.
  449. %
  450. %   o  p:  Specifies a pointer to a buffer of integers.
  451. %
  452. %   o  length:  Specifies the length of the buffer.
  453. %
  454. %
  455. */
  456. MSBFirstOrderLong(p,length)
  457. register char
  458. X  *p;
  459. X
  460. register unsigned
  461. X  length;
  462. {
  463. X  register char
  464. X    c,
  465. X    *q,
  466. X    *sp;
  467. X
  468. X  q=p+length;
  469. X  while (p < q)
  470. X  {
  471. X    sp=p+3;
  472. X    c=(*sp);
  473. X    *sp=(*p);
  474. X    *p++=c;
  475. X    sp=p+1;
  476. X    c=(*sp);
  477. X    *sp=(*p);
  478. X    *p++=c;
  479. X    p+=2;
  480. X  }
  481. }
  482. X
  483. /*
  484. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  485. %                                                                             %
  486. %                                                                             %
  487. %                                                                             %
  488. %  M S B F i r s t O r d e r S h o r t                                        %
  489. %                                                                             %
  490. %                                                                             %
  491. %                                                                             %
  492. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  493. %
  494. %  Function MSBFirstOrderShort converts a least-significant byte first buffer
  495. %  of short integers to most-significant byte first.
  496. %
  497. %  The format of the MSBFirstOrderShort routine is:
  498. %
  499. %       MSBFirstOrderShort(p,length);
  500. %
  501. %  A description of each parameter follows.
  502. %
  503. %   o  p:  Specifies a pointer to a buffer of integers.
  504. %
  505. %   o  length:  Specifies the length of the buffer.
  506. %
  507. %
  508. */
  509. MSBFirstOrderShort(p,length)
  510. register char
  511. X  *p;
  512. X
  513. register unsigned
  514. X  length;
  515. {
  516. X  register char
  517. X    c,
  518. X    *q;
  519. X
  520. X  q=p+length;
  521. X  while (p < q)
  522. X  {
  523. X    c=(*p);
  524. X    *p=(*(p+1));
  525. X    p++;
  526. X    *p++=c;
  527. X  }
  528. }
  529. X
  530. /*
  531. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  532. %                                                                             %
  533. %                                                                             %
  534. %                                                                             %
  535. %   U s a g e                                                                 %
  536. %                                                                             %
  537. %                                                                             %
  538. %                                                                             %
  539. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  540. %
  541. %  Procedure Usage displays the program usage;
  542. %
  543. %  The format of the Usage routine is:
  544. %
  545. %      Usage(message)
  546. %
  547. %  A description of each parameter follows:
  548. %
  549. %    message:  Specifies a specific message to display to the user.
  550. %
  551. */
  552. static void Usage(message)
  553. char
  554. X  *message;
  555. {
  556. X  if (message != (char *) NULL)
  557. X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
  558. X  (void) fprintf(stderr,"Usage: %s image.miff image.xwd\n\n",application_name);
  559. X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
  560. X  (void) fprintf(stderr,"Specify 'image.xwd' as '-' for standard output.\n");
  561. X  exit(1);
  562. }
  563. X
  564. /*
  565. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  566. %                                                                             %
  567. %                                                                             %
  568. %                                                                             %
  569. %   W r i t e R a s t e r I m a g e                                           %
  570. %                                                                             %
  571. %                                                                             %
  572. %                                                                             %
  573. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  574. %
  575. %  Procedure WriteXWDImage writes an image to a file on disk in XWD 
  576. %  rasterfile format.
  577. %
  578. %  The format of the WriteXWDImage routine is:
  579. %
  580. %      WriteXWDImage(image)
  581. %
  582. %  A description of each parameter follows.
  583. %
  584. %    o image:  A pointer to a Image structure.
  585. %
  586. %
  587. */
  588. static void WriteXWDImage(image)
  589. Image
  590. X  *image;
  591. {
  592. X  register int
  593. X    i,
  594. X    j,
  595. X    x;
  596. X
  597. X  register RunlengthPacket
  598. X    *p;
  599. X
  600. X  register unsigned char
  601. X    *q;
  602. X
  603. X  unsigned char
  604. X    *xwd_pixels;
  605. X
  606. X  unsigned long
  607. X    lsb_first;
  608. X
  609. X  XWDFileHeader
  610. X    xwd_header;
  611. X
  612. X  /*
  613. X    Open output image file.
  614. X  */
  615. X  if (*image->filename == '-')
  616. X    image->file=stdout;
  617. X  else
  618. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  619. X      image->file=fopen(image->filename,"w");
  620. X    else
  621. X      {
  622. X        char
  623. X          command[256];
  624. X
  625. X        /*
  626. X          Image file is compressed-- uncompress it.
  627. X        */
  628. X        (void) sprintf(command,"compress -c > %s",image->filename);
  629. X        image->file=(FILE *) popen(command,"w");
  630. X      }
  631. X  if (image->file == (FILE *) NULL)
  632. X    Error("unable to open file",image->filename);
  633. X  /*
  634. X    Initialize XWD file header.
  635. X  */
  636. X  xwd_header.header_size=sizeof(xwd_header)+strlen(image->filename)+1;
  637. X  xwd_header.file_version=(unsigned long) XWD_FILE_VERSION;
  638. X  xwd_header.pixmap_format=(unsigned long) ZPixmap;
  639. X  xwd_header.pixmap_depth=(unsigned long) 
  640. X    (image->class == DirectClass ? 24 : 8);
  641. X  xwd_header.pixmap_width=(unsigned long) image->columns;
  642. X  xwd_header.pixmap_height=(unsigned long) image->rows;
  643. X  xwd_header.xoffset=(unsigned long) 0;
  644. X  xwd_header.byte_order=(unsigned long) MSBFirst;
  645. X  xwd_header.bitmap_unit=(unsigned long) 
  646. X    (image->class == DirectClass ? 24 : 8);
  647. X  xwd_header.bitmap_bit_order=(unsigned long) MSBFirst;
  648. X  xwd_header.bitmap_pad=(unsigned long) 
  649. X    (image->class == DirectClass ? 24 : 8);
  650. X  xwd_header.bits_per_pixel=(unsigned long) 
  651. X    (image->class == DirectClass ? 24 : 8);
  652. X  xwd_header.bytes_per_line=(unsigned long) image->columns*
  653. X    (image->class == DirectClass ? 3 : 1);
  654. X  xwd_header.visual_class=(unsigned long) 
  655. X    (image->class == DirectClass ? DirectColor : PseudoColor);
  656. X  xwd_header.red_mask=(unsigned long) 
  657. X    (image->class == DirectClass ? 0xff0000 : 0);
  658. X  xwd_header.green_mask=(unsigned long) 
  659. X    (image->class == DirectClass ? 0xff00 : 0);
  660. X  xwd_header.blue_mask=(unsigned long) 
  661. X    (image->class == DirectClass ? 0xff : 0);
  662. X  xwd_header.bits_per_rgb=(unsigned long) 
  663. X    (image->class == DirectClass ? 24 : 8);
  664. X  xwd_header.colormap_entries=(unsigned long) 
  665. X    (image->class == DirectClass ? 256 : image->colors);
  666. X  xwd_header.ncolors=(image->class == DirectClass ? 0 : image->colors);
  667. X  xwd_header.window_width=(unsigned long) image->columns;
  668. X  xwd_header.window_height=(unsigned long) image->rows;
  669. X  xwd_header.window_x=0;
  670. X  xwd_header.window_y=0;
  671. X  xwd_header.window_bdrwidth=(unsigned long) 0;
  672. X  /*
  673. X    Ensure the xwd_header byte-order is most-significant byte first.
  674. X  */
  675. X  lsb_first=1;
  676. X  if (*(char *) &lsb_first)
  677. X    MSBFirstOrderLong((char *) &xwd_header,sizeof(xwd_header));
  678. X  (void) fwrite((char *) &xwd_header,sizeof(xwd_header),1,image->file);
  679. X  (void) fwrite((char *) image->filename,1,strlen(image->filename)+1,
  680. X    image->file);
  681. X  if (image->class == PseudoClass)
  682. X    {
  683. X      XColor
  684. X        *colors;
  685. X
  686. X      /*
  687. X         Dump colormap to file.
  688. X      */
  689. X      colors=(XColor *) malloc((unsigned int) image->colors*sizeof(XColor));
  690. X      if (colors == (XColor *) NULL)
  691. X        Error("unable to allocate memory",(char *) NULL);
  692. X      for (i=0; i < image->colors; i++)
  693. X      {
  694. X        colors[i].pixel=i;
  695. X        colors[i].red=image->colormap[i].red << 8;
  696. X        colors[i].green=image->colormap[i].green << 8;
  697. X        colors[i].blue=image->colormap[i].blue << 8;
  698. X        colors[i].flags=DoRed | DoGreen | DoBlue;
  699. X        colors[i].pad=0;
  700. X        if (*(char *) &lsb_first)
  701. X          {
  702. X            MSBFirstOrderLong((char *) &colors[i].pixel,sizeof(long));
  703. X            MSBFirstOrderShort((char *) &colors[i].red,3*sizeof(short));
  704. X          }
  705. X      }
  706. X      (void) fwrite((char *) colors,sizeof(XColor),image->colors,image->file);
  707. X      (void) free((char *) colors);
  708. X    }
  709. X  /*
  710. X    Convert MIFF to XWD raster pixels.
  711. X  */
  712. X  xwd_pixels=(unsigned char *) 
  713. X    malloc((unsigned int) xwd_header.bytes_per_line*xwd_header.pixmap_height);
  714. X  if (xwd_pixels == (unsigned char *) NULL)
  715. X    Error("unable to allocate memory",(char *) NULL);
  716. X  p=image->pixels;
  717. X  q=xwd_pixels;
  718. X  x=0;
  719. X  for (i=0; i < image->packets; i++)
  720. X  {
  721. X    for (j=0; j <= p->length; j++)
  722. X    {
  723. X      if (image->class == PseudoClass)
  724. X        *q++=p->index;
  725. X      else
  726. X        {
  727. X          *q++=p->red;
  728. X          *q++=p->green;
  729. X          *q++=p->blue;
  730. X        }
  731. X    }
  732. X    p++;
  733. X  }
  734. X  /*
  735. X    Dump pixels to file.
  736. X  */
  737. X  (void) fwrite((char *) xwd_pixels,sizeof(char),
  738. X    xwd_header.bytes_per_line*xwd_header.pixmap_height,image->file);
  739. X  (void) free((char *) xwd_pixels);
  740. X  if (image->file != stdin)
  741. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  742. X      (void) fclose(image->file);
  743. X    else
  744. X      (void) pclose(image->file);
  745. }
  746. X
  747. /*
  748. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  749. %                                                                             %
  750. %                                                                             %
  751. %                                                                             %
  752. %    M a i n                                                                  %
  753. %                                                                             %
  754. %                                                                             %
  755. %                                                                             %
  756. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  757. %
  758. %
  759. */
  760. int main(argc,argv)
  761. int
  762. X  argc;
  763. X
  764. char
  765. X  *argv[];
  766. {
  767. X  Image
  768. X    *image;
  769. X
  770. X  application_name=argv[0];
  771. X  if (argc < 3)
  772. X    Usage((char *) NULL);
  773. X  image=ReadImage(argv[1]);
  774. X  if (image == (Image *) NULL)
  775. X    exit(1);
  776. X  (void) strcpy(image->filename,argv[2]);
  777. X  WriteXWDImage(image);
  778. X  (void) fprintf(stderr,"%s=> %s  %dx%d\n",argv[1],argv[2],image->columns,
  779. X    image->rows);
  780. X  return(False);
  781. }
  782. SHAR_EOF
  783. chmod 0755 ImageMagick/filters/MIFFtoXWD.c ||
  784. echo 'restore of ImageMagick/filters/MIFFtoXWD.c failed'
  785. Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoXWD.c'`"
  786. test 15929 -eq "$Wc_c" ||
  787.     echo 'ImageMagick/filters/MIFFtoXWD.c: original size 15929, current size' "$Wc_c"
  788. rm -f _shar_wnt_.tmp
  789. fi
  790. # ============= ImageMagick/filters/README ==============
  791. if test -f 'ImageMagick/filters/README' -a X"$1" != X"-c"; then
  792.     echo 'x - skipping ImageMagick/filters/README (File already exists)'
  793.     rm -f _shar_wnt_.tmp
  794. else
  795. > _shar_wnt_.tmp
  796. echo 'x - extracting ImageMagick/filters/README (Text)'
  797. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/README' &&
  798. X  The X utilites read and write MIFF images.  You can find filters to
  799. X  convert to and from the MIFF format in this directory.  
  800. X
  801. X  To compile, type
  802. X
  803. X    xmkmf
  804. X    make
  805. X
  806. X  Two examples of using a filter follow:
  807. X
  808. X    GIFtoMIFF image.gif - | display -
  809. X
  810. X      or
  811. X
  812. X    TIFFtoMIFF image.tiff image.miff
  813. X    display image.miff
  814. X
  815. X  The TIFFtoMIFF and MIFFtoTIFF filters require Sam Leffler's TIFF
  816. X  software available via FTP as ucbvax.berkeley.edu:pub/tiff/v2.2.tar.Z.
  817. X
  818. X  The PPMtoMIFF and MIFFtoPPM filters require Jef Poskanzer's PBMPLUS
  819. X  software available via FTP as export.lcs.mit.edu:contrib/pbmplus.tar.Z.
  820. X
  821. X  To succesfully compile the PPMtoMIFF and MIFFtoPPM filters, first compile
  822. X  the pbmplus routines.  Next copy pbmplus.h, pbm/pbm.h, pgm/pgm.h, 
  823. X  ppm/ppm.h, and pnm/pnm.h to /usr/local/include.  Change
  824. X
  825. X    #include "../pbmplus.h"
  826. X
  827. X  to
  828. X
  829. X    #include "pbmplus.h"
  830. X
  831. X  in /usr/local/include/pbm.h.
  832. X
  833. X  Next copy pbm/libpbm.a, pgm/libpgm.a, ppm/libppm.a, and pnm/libpnm.a
  834. X  to /usr/local/lib.
  835. X
  836. X  Finally, type 
  837. X
  838. X    make PPMtoMIFF
  839. X    make MIFFtoPPM
  840. X
  841. SHAR_EOF
  842. chmod 0755 ImageMagick/filters/README ||
  843. echo 'restore of ImageMagick/filters/README failed'
  844. Wc_c="`wc -c < 'ImageMagick/filters/README'`"
  845. test 1055 -eq "$Wc_c" ||
  846.     echo 'ImageMagick/filters/README: original size 1055, current size' "$Wc_c"
  847. rm -f _shar_wnt_.tmp
  848. fi
  849. # ============= ImageMagick/filters/RGBtoMIFF.c ==============
  850. if test -f 'ImageMagick/filters/RGBtoMIFF.c' -a X"$1" != X"-c"; then
  851.     echo 'x - skipping ImageMagick/filters/RGBtoMIFF.c (File already exists)'
  852.     rm -f _shar_wnt_.tmp
  853. else
  854. > _shar_wnt_.tmp
  855. echo 'x - extracting ImageMagick/filters/RGBtoMIFF.c (Text)'
  856. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/RGBtoMIFF.c' &&
  857. /*
  858. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  859. %                                                                             %
  860. %                                                                             %
  861. %                                                                             %
  862. %                 IIIII  M   M  PPPP    OOO   RRRR    TTTTT                   %
  863. %                   I    MM MM  P   P  O   O  R   R     T                     %
  864. %                   I    M M M  PPPP   O   O  RRRR      T                     %
  865. %                   I    M   M  P      O   O  R R       T                     %
  866. %                 IIIII  M   M  P       OOO   R  R      T                     % 
  867. %                                                                             %
  868. %                                                                             %
  869. %                 Import RGB raster image to a MIFF format.                   %
  870. %                                                                             %
  871. %                                                                             %
  872. %                                                                             %
  873. %                           Software Design                                   %
  874. %                             John Cristy                                     %
  875. %                            January  1991                                    %
  876. %                                                                             %
  877. %                                                                             %
  878. %  Copyright 1991 E. I. Dupont de Nemours & Company                           %
  879. %                                                                             %
  880. %  Permission to use, copy, modify, distribute, and sell this software and    %
  881. %  its documentation for any purpose is hereby granted without fee,           %
  882. %  provided that the above Copyright notice appear in all copies and that     %
  883. %  both that Copyright notice and this permission notice appear in            %
  884. %  supporting documentation, and that the name of E. I. Dupont de Nemours     %
  885. %  & Company not be used in advertising or publicity pertaining to            %
  886. %  distribution of the software without specific, written prior               %
  887. %  permission.  E. I. Dupont de Nemours & Company makes no representations    %
  888. %  about the suitability of this software for any purpose.  It is provided    %
  889. %  "as is" without express or implied warranty.                               %
  890. %                                                                             %
  891. %  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
  892. %  to this software, including all implied warranties of merchantability      %
  893. %  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
  894. %  liable for any special, indirect or consequential damages or any           %
  895. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  896. %  in an action of contract, negligence or other tortious action, arising     %
  897. %  out of or in connection with the use or performance of this software.      %
  898. %                                                                             %
  899. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  900. %  Command syntax:
  901. %
  902. %  import width height image.rgb image.miff
  903. %  
  904. %  Specify 'image.rgb' as '-' for standard input.  
  905. %  Specify 'image.miff' as '-' for standard output.
  906. %  
  907. %
  908. */
  909. X
  910. #include <string.h>
  911. #include "display.h"
  912. #include "image.h"
  913. X
  914. /*
  915. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  916. %                                                                             %
  917. %                                                                             %
  918. %                                                                             %
  919. %   E r r o r                                                                 %
  920. %                                                                             %
  921. %                                                                             %
  922. %                                                                             %
  923. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  924. %
  925. %  Function Error displays an error message and then terminates the program.
  926. %
  927. %  The format of the Error routine is:
  928. %
  929. %      Error(message,qualifier)
  930. %
  931. %  A description of each parameter follows:
  932. %
  933. %    o message:  Specifies the message to display before terminating the
  934. %      program.
  935. %
  936. %    o qualifier:  Specifies any qualifier to the message.
  937. %
  938. %
  939. */
  940. static void Error(message,qualifier)
  941. char
  942. X  *message,
  943. X  *qualifier;
  944. {
  945. X  (void) fprintf(stderr,"%s: %s",application_name,message); 
  946. X  if (qualifier != (char *) NULL)
  947. X    (void) fprintf(stderr," %s",qualifier);
  948. X  (void) fprintf(stderr,".\n");
  949. X  exit(1);
  950. }
  951. X
  952. /*
  953. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  954. %                                                                             %
  955. %                                                                             %
  956. %                                                                             %
  957. %  R e a d R G B I m a g e                                                    %
  958. %                                                                             %
  959. %                                                                             %
  960. %                                                                             %
  961. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  962. %
  963. %  Function ReadRGBImage reads an image file and returns it.  It allocates the 
  964. %  memory necessary for the new Image structure and returns a pointer to the 
  965. %  new image.
  966. %
  967. %  The format of the ReadRGBImage routine is:
  968. %
  969. %      image=ReadRGBImage(filename,columns,rows)
  970. %
  971. %  A description of each parameter follows:
  972. %
  973. %    o image:  Function ReadRGBImage returns a pointer to the image after 
  974. %      reading.  A null image is returned if there is a a memory shortage or 
  975. %      if the image cannot be read.
  976. %
  977. %    o filename:  Specifies the name of the image to read.
  978. %
  979. %
  980. */
  981. static Image *ReadRGBImage(filename,columns,rows)
  982. char
  983. X  *filename;
  984. X
  985. unsigned int
  986. X  columns,
  987. X  rows;
  988. {
  989. X  Image
  990. X    *image;
  991. X
  992. X  register int
  993. X    i;
  994. X
  995. X  register RunlengthPacket
  996. X    *q;
  997. X
  998. X  register unsigned char
  999. X    blue,
  1000. X    green,
  1001. X    *p,
  1002. X    red;
  1003. X
  1004. X  unsigned char
  1005. X    *rgb_pixels;
  1006. X
  1007. X  /*
  1008. X    Allocate image structure.
  1009. X  */
  1010. X  image=(Image *) malloc(sizeof(Image));
  1011. X  if (image == (Image *) NULL)
  1012. X    Error("memory allocation error",(char *) NULL);
  1013. X  /*
  1014. X    Initialize Image structure.
  1015. X  */
  1016. X  image->id=UnknownId;
  1017. X  image->class=DirectClass;
  1018. X  image->compression=RunlengthEncodedCompression;
  1019. X  image->columns=columns;
  1020. X  image->rows=rows;
  1021. X  image->packets=0;
  1022. X  image->colors=0;
  1023. X  image->scene=0;
  1024. X  image->colormap=(ColorPacket *) NULL;
  1025. X  image->pixels=(RunlengthPacket *) NULL;
  1026. X  image->comments=(char *) NULL;
  1027. X  /*
  1028. X    Open image file.
  1029. X  */
  1030. X  (void) strcpy(image->filename,filename);
  1031. X  if (*image->filename == '-')
  1032. X    image->file=stdin;
  1033. X  else
  1034. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  1035. X      image->file=fopen(image->filename,"r");
  1036. X    else
  1037. X      {
  1038. X        char
  1039. X          command[256];
  1040. X
  1041. X        /*
  1042. X          Image file is compressed-- uncompress it.
  1043. X        */
  1044. X        (void) sprintf(command,"uncompress -c %s",image->filename);
  1045. X        image->file=(FILE *) popen(command,"r");
  1046. X      }
  1047. X  if (image->file == (FILE *) NULL)
  1048. X    Error("unable to open file",image->filename);
  1049. X  /*
  1050. X    Create image.
  1051. X  */
  1052. X  rgb_pixels=(unsigned char *) 
  1053. X    malloc(3*image->columns*image->rows*sizeof(unsigned char));
  1054. X  image->pixels=(RunlengthPacket *) 
  1055. X    malloc(image->columns*image->rows*sizeof(RunlengthPacket));
  1056. X  if ((rgb_pixels == (unsigned char *) NULL) ||
  1057. X      (image->pixels == (RunlengthPacket *) NULL))
  1058. X    Error("memory allocation error",(char *) NULL);
  1059. X  /*
  1060. X    Convert raster image to runlength-encoded packets.
  1061. X  */
  1062. X  (void) ReadData((char *) rgb_pixels,3,image->columns*image->rows,
  1063. X    image->file);
  1064. X  p=rgb_pixels;
  1065. X  image->packets=0;
  1066. X  q=image->pixels;
  1067. X  q->length=MaxRunlength;
  1068. X  for (i=0; i < (image->columns*image->rows); i++)
  1069. X  {
  1070. X    red=(*p++);
  1071. X    green=(*p++);
  1072. X    blue=(*p++);
  1073. X    if ((red == q->red) && (green == q->green) && (blue == q->blue) && 
  1074. X        (q->length < MaxRunlength))
  1075. X      q->length++;
  1076. X    else
  1077. X      {
  1078. X        if (image->packets > 0)
  1079. X          q++;
  1080. X        image->packets++;
  1081. X        q->red=red;
  1082. X        q->green=green;
  1083. X        q->blue=blue;
  1084. X        q->index=0;
  1085. X        q->length=0;
  1086. X      }
  1087. X  }
  1088. X  (void) free((char *) rgb_pixels);
  1089. X  if (image->file != stdin)
  1090. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  1091. X      (void) fclose(image->file);
  1092. X    else
  1093. X      (void) pclose(image->file);
  1094. X  if (image->packets > ((image->columns*image->rows*3) >> 2))
  1095. X    image->compression=NoCompression;
  1096. X  image->pixels=(RunlengthPacket *)
  1097. X    realloc((char *) image->pixels,image->packets*sizeof(RunlengthPacket));
  1098. X  return(image);
  1099. }
  1100. X
  1101. /*
  1102. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1103. %                                                                             %
  1104. %                                                                             %
  1105. %                                                                             %
  1106. %   U s a g e                                                                 %
  1107. %                                                                             %
  1108. %                                                                             %
  1109. %                                                                             %
  1110. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1111. %
  1112. %  Function Usage displays the program usage;
  1113. %
  1114. %  The format of the Usage routine is:
  1115. %
  1116. %      Usage(message)
  1117. %
  1118. %  A description of each parameter follows:
  1119. %
  1120. %    message:  Specifies a specific message to display to the user.
  1121. %
  1122. */
  1123. static void Usage(message)
  1124. char
  1125. X  *message;
  1126. {
  1127. X  if (message != (char *) NULL)
  1128. X    (void) fprintf(stderr,"Can't continue, %s\n\n",message);
  1129. X  (void) fprintf(stderr,
  1130. X    "Usage: %s [-scene] width height image.rgb image.miff\n",application_name);
  1131. X  (void) fprintf(stderr,"\nSpecify 'image.rgb' as '-' for standard input.\n");
  1132. X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard output.\n");
  1133. X  exit(1);
  1134. }
  1135. X
  1136. /*
  1137. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1138. %                                                                             %
  1139. %                                                                             %
  1140. %                                                                             %
  1141. %  M a i n                                                                    %
  1142. %                                                                             %
  1143. %                                                                             %
  1144. %                                                                             %
  1145. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1146. %
  1147. %
  1148. */
  1149. int main(argc,argv)
  1150. int
  1151. X  argc;
  1152. X   
  1153. char
  1154. X  *argv[];
  1155. {
  1156. X  char
  1157. X    filename[256];
  1158. X
  1159. X  Image
  1160. X    *image;
  1161. X
  1162. X  int
  1163. X    i;
  1164. X
  1165. X  unsigned int
  1166. X    columns,
  1167. X    rows,
  1168. X    scene;
  1169. X
  1170. X  /*
  1171. X    Initialize program variables.
  1172. X  */
  1173. X  application_name=argv[0];
  1174. X  i=1;
  1175. X  scene=0;
  1176. X  if (argc < 5)
  1177. X    Usage((char *) NULL);
  1178. X  /*
  1179. X    Read image and convert to MIFF format.
  1180. X  */
  1181. X  if (strncmp(argv[i],"-scene",2) == 0)
  1182. X    {
  1183. X      i++;
  1184. X      scene=atoi(argv[i++]);
  1185. X    }
  1186. X  columns=atoi(argv[i++]);
  1187. X  rows=atoi(argv[i++]);
  1188. X  (void) strcpy(filename,argv[i++]);
  1189. X  image=ReadRGBImage(filename,columns,rows);
  1190. X  if (image == (Image *) NULL)
  1191. X    exit(1);
  1192. X  (void) strcpy(image->filename,argv[i++]);
  1193. X  image->scene=scene;
  1194. X  (void) WriteImage(image);
  1195. X  (void) fprintf(stderr,"%s => %s  %dx%d\n",filename,image->filename,
  1196. X    image->columns,image->rows);
  1197. X  DestroyImage(image);
  1198. X  return(False);
  1199. }
  1200. SHAR_EOF
  1201. chmod 0755 ImageMagick/filters/RGBtoMIFF.c ||
  1202. echo 'restore of ImageMagick/filters/RGBtoMIFF.c failed'
  1203. Wc_c="`wc -c < 'ImageMagick/filters/RGBtoMIFF.c'`"
  1204. test 12104 -eq "$Wc_c" ||
  1205.     echo 'ImageMagick/filters/RGBtoMIFF.c: original size 12104, current size' "$Wc_c"
  1206. rm -f _shar_wnt_.tmp
  1207. fi
  1208. # ============= ImageMagick/filters/MIFFtoGIF.c ==============
  1209. if test -f 'ImageMagick/filters/MIFFtoGIF.c' -a X"$1" != X"-c"; then
  1210.     echo 'x - skipping ImageMagick/filters/MIFFtoGIF.c (File already exists)'
  1211.     rm -f _shar_wnt_.tmp
  1212. else
  1213. > _shar_wnt_.tmp
  1214. echo 'x - extracting ImageMagick/filters/MIFFtoGIF.c (Text)'
  1215. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/filters/MIFFtoGIF.c' &&
  1216. /*
  1217. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1218. %                                                                             %
  1219. %                                                                             %
  1220. %                                                                             %
  1221. %                 EEEEE  X   X  PPPP    OOO   RRRR    TTTTT                   %
  1222. %                 E       X X   P   P  O   O  R   R     T                     %
  1223. %                 EEE      X    PPPP   O   O  RRRR      T                     %
  1224. %                 E       X X   P      O   O  R R       T                     %
  1225. %                 EEEEE  X   X  P       OOO   R  R      T                     %
  1226. %                                                                             %
  1227. %                                                                             %
  1228. %                  Export MIFF image to a GIF raster format.                  %
  1229. %                                                                             %
  1230. %                                                                             %
  1231. %                                                                             %
  1232. %                           Software Design                                   %
  1233. %                             John Cristy                                     %
  1234. %                            January  1991                                    %
  1235. %                                                                             %
  1236. %                                                                             %
  1237. %  Copyright 1991 E. I. Dupont de Nemours & Company                           %
  1238. %                                                                             %
  1239. %  Permission to use, copy, modify, distribute, and sell this software and    %
  1240. %  its documentation for any purpose is hereby granted without fee,           %
  1241. %  provided that the above Copyright notice appear in all copies and that     %
  1242. %  both that Copyright notice and this permission notice appear in            %
  1243. %  supporting documentation, and that the name of E. I. Dupont de Nemours     %
  1244. %  & Company not be used in advertising or publicity pertaining to            %
  1245. %  distribution of the software without specific, written prior               %
  1246. %  permission.  E. I. Dupont de Nemours & Company makes no representations    %
  1247. %  about the suitability of this software for any purpose.  It is provided    %
  1248. %  "as is" without express or implied warranty.                               %
  1249. %                                                                             %
  1250. %  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
  1251. %  to this software, including all implied warranties of merchantability      %
  1252. %  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
  1253. %  liable for any special, indirect or consequential damages or any           %
  1254. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  1255. %  in an action of contract, negligence or other tortious action, arising     %
  1256. %  out of or in connection with the use or performance of this software.      %
  1257. %                                                                             %
  1258. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1259. %
  1260. %  Command syntax:
  1261. %
  1262. %  export image.miff image.gif
  1263. %
  1264. %  Specify 'image.miff' as '-' for standard input.  
  1265. %  Specify 'image.gif' as '-' for standard output.
  1266. %
  1267. %
  1268. */
  1269. X
  1270. #include "display.h"
  1271. #include "image.h"
  1272. X
  1273. /*
  1274. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1275. %                                                                             %
  1276. %                                                                             %
  1277. %                                                                             %
  1278. %   E r r o r                                                                 %
  1279. %                                                                             %
  1280. %                                                                             %
  1281. %                                                                             %
  1282. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1283. %
  1284. %  Function Error displays an error message and then terminates the program.
  1285. %
  1286. %  The format of the Error routine is:
  1287. %
  1288. %      Error(message,qualifier)
  1289. %
  1290. %  A description of each parameter follows:
  1291. %
  1292. %    o message:  Specifies the message to display before terminating the
  1293. %      program.
  1294. %
  1295. %    o qualifier:  Specifies any qualifier to the message.
  1296. %
  1297. %
  1298. */
  1299. void Error(message,qualifier)
  1300. char
  1301. X  *message,
  1302. X  *qualifier;
  1303. {
  1304. X  (void) fprintf(stderr,"%s: %s",application_name,message); 
  1305. X  if (qualifier != (char *) NULL)
  1306. X    (void) fprintf(stderr," %s",qualifier);
  1307. X  (void) fprintf(stderr,".\n");
  1308. X  exit(1);
  1309. }
  1310. X
  1311. /*
  1312. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1313. %                                                                             %
  1314. %                                                                             %
  1315. %                                                                             %
  1316. %   U s a g e                                                                 %
  1317. %                                                                             %
  1318. %                                                                             %
  1319. %                                                                             %
  1320. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1321. %
  1322. %  Procedure Usage displays the program usage;
  1323. %
  1324. %  The format of the Usage routine is:
  1325. %
  1326. %      Usage(message)
  1327. %
  1328. %  A description of each parameter follows:
  1329. %
  1330. %    message:  Specifies a specific message to display to the user.
  1331. %
  1332. */
  1333. static void Usage(message)
  1334. char
  1335. X  *message;
  1336. {
  1337. X  if (message != (char *) NULL)
  1338. X    (void) fprintf(stderr,"Can't continue,%s\n\n",message);
  1339. X  (void) fprintf(stderr,"Usage: %s image.miff image.gif\n\n",application_name);
  1340. X  (void) fprintf(stderr,"Specify 'image.miff' as '-' for standard input.\n");
  1341. X  (void) fprintf(stderr,"Specify 'image.gif' as '-' for standard output.\n");
  1342. X  exit(1);
  1343. }
  1344. X
  1345. /*
  1346. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1347. %                                                                             %
  1348. %                                                                             %
  1349. %                                                                             %
  1350. %   W r i t e G I F I m a g e                                                 %
  1351. %                                                                             %
  1352. %                                                                             %
  1353. %                                                                             %
  1354. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1355. %
  1356. %  Procedure WriteGIFImage writes an image to a file on disk in GIF 
  1357. %  rasterfile format.
  1358. %
  1359. %  The format of the WriteGIFImage routine is:
  1360. %
  1361. %      WriteGIFImage(image)
  1362. %
  1363. %  A description of each parameter follows.
  1364. %
  1365. %    o image:  A pointer to a Image structure.
  1366. %
  1367. %
  1368. */
  1369. static void WriteGIFImage(image)
  1370. Image
  1371. X  *image;
  1372. {
  1373. X  register int
  1374. X    i,
  1375. X    j,
  1376. X    x;
  1377. X
  1378. X  register RunlengthPacket
  1379. X    *p;
  1380. X
  1381. X  register unsigned char
  1382. X    *q;
  1383. X
  1384. X  unsigned char
  1385. X    Blue[256],
  1386. X    Green[256],
  1387. X    *pixels,
  1388. X    Red[256];
  1389. X
  1390. X /*
  1391. X    Open output image file.
  1392. X  */
  1393. X  if (*image->filename == '-')
  1394. X    image->file=stdout;
  1395. X  else
  1396. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  1397. X      image->file=fopen(image->filename,"w");
  1398. X    else
  1399. X      {
  1400. X        char
  1401. X          command[256];
  1402. X
  1403. X       /*
  1404. X          Image file is compressed-- uncompress it.
  1405. X        */
  1406. X        (void) sprintf(command,"compress -c > %s",image->filename);
  1407. X        image->file=(FILE *) popen(command,"w");
  1408. X      }
  1409. X  if (image->file == (FILE *) NULL)
  1410. X    Error("unable to open file",image->filename);
  1411. X /*
  1412. X    Image must be less than or equal to 256 colors.
  1413. X  */
  1414. X  if ((image->class == DirectClass) || (image->colors > 256))
  1415. X    QuantizeImage(image,256,0,False,True);
  1416. X  for (i=0; i < image->colors; i++)
  1417. X  {
  1418. X    Red[i]=image->colormap[i].red;
  1419. X    Green[i]=image->colormap[i].green;
  1420. X    Blue[i]=image->colormap[i].blue;
  1421. X  }
  1422. X /*
  1423. X    Convert runlength packets to a rectangular array of colormap indexes.
  1424. X  */
  1425. X  pixels=(unsigned char *) 
  1426. X    malloc(image->columns*image->rows*sizeof(unsigned char));
  1427. X  if (pixels == (unsigned char *) NULL)
  1428. X    Error("unable to allocate memory",(char *) NULL);
  1429. X  p=image->pixels;
  1430. X  q=pixels;
  1431. X  for (i=0; i < image->packets; i++)
  1432. X  {
  1433. X    for (j=0; j <= p->length; j++)
  1434. X      *q++=p->index;
  1435. X    p++;
  1436. X  }
  1437. X /*
  1438. X    Convert MIFF to GIF raster pixels.
  1439. X  */
  1440. X  WriteGIF(image->file,pixels,image->columns,image->rows,Red,Green,Blue,
  1441. X    image->colors,image->colors == 2 ? 2 : 0);
  1442. X  (void) free((char *) pixels);
  1443. X  if (image->file != stdin)
  1444. X    if (strcmp(image->filename+strlen(image->filename)-2,".Z") != 0)
  1445. X      (void) fclose(image->file);
  1446. X    else
  1447. X      (void) pclose(image->file);
  1448. }
  1449. X
  1450. /*****************************************************************
  1451. X * Portions of this code Copyright (C) 1989 by Michael Mauldin.
  1452. X * Permission is granted to use this file in whole or in part provided
  1453. X * that you do not sell it for profit and that this copyright notice
  1454. X * and the names of all authors are retained unchanged.
  1455. X *
  1456. X * Authors:  Michael Mauldin (mlm@cs.cmu.edu)
  1457. X *           David Rowley (mgardi@watdcsu.waterloo.edu)
  1458. X *
  1459. X * Based on: compress.c - File compression ala IEEE Computer,June 1984.
  1460. X *
  1461. X *  Spencer W. Thomas       (decvax!harpo!utah-cs!utah-gr!thomas)
  1462. X *  Jim McKie               (decvax!mcvax!jim)
  1463. X *  Steve Davies            (decvax!vax135!petsd!peora!srd)
  1464. X *  Ken Turkowski           (decvax!decwrl!turtlevax!ken)
  1465. X *  James A. Woods          (decvax!ihnp4!ames!jaw)
  1466. X *  Joe Orost               (decvax!vax135!petsd!joe)
  1467. X *****************************************************************/
  1468. X
  1469. typedef long int        count_int;
  1470. X
  1471. static int  Width,Height;
  1472. static int  curx,cury;
  1473. static long CountDown;
  1474. static int  Interlace;
  1475. static unsigned char bw[2]={0,0xff};
  1476. X
  1477. static void putword(),compress(),output(),cl_block(),cl_hash();
  1478. static void char_init(),char_out(),flush_char();
  1479. X
  1480. /*************************************************************/
  1481. int WriteGIF(fp,pic,w,h,rmap,gmap,bmap,numcols,colorstyle)
  1482. FILE *fp;
  1483. unsigned char *pic;
  1484. int   w,h;
  1485. unsigned char *rmap,*gmap,*bmap;
  1486. int   numcols,colorstyle;
  1487. {
  1488. X  int RWidth,RHeight;
  1489. X  int LeftOfs,TopOfs;
  1490. X  int Resolution,ColorMapSize,InitCodeSize,Background,BitsPerPixel;
  1491. X  int i,j;
  1492. X
  1493. X
  1494. X /* if writing B/W stipple... */
  1495. X  if (colorstyle==2) {
  1496. X    rmap=gmap=bmap=bw;
  1497. X    numcols=2;
  1498. X  }
  1499. X
  1500. X  Interlace=0;
  1501. X  Background=0;
  1502. X
  1503. X /* figure out 'BitsPerPixel' */
  1504. X  for (i=1; i<8; i++)
  1505. X    if ((1<<i) >= numcols) break;
  1506. X  
  1507. X  BitsPerPixel=i;
  1508. X
  1509. X  ColorMapSize=1 << BitsPerPixel;
  1510. X  
  1511. X  RWidth =Width =w;
  1512. X  RHeight=Height=h;
  1513. X  LeftOfs=TopOfs=0;
  1514. X  
  1515. X  Resolution=BitsPerPixel;
  1516. X
  1517. X  CountDown=w * h;   /* # of pixels we'll be doing */
  1518. X
  1519. X  if (BitsPerPixel <= 1) InitCodeSize=2;
  1520. X                    else InitCodeSize=BitsPerPixel;
  1521. X
  1522. X  curx=cury=0;
  1523. X
  1524. X  if (!fp) {
  1525. X    fprintf(stderr, "WriteGIF: file not open for writing\n");
  1526. X    return (1);
  1527. X  }
  1528. X
  1529. X  fwrite("GIF87a",1,6,fp);   /* the GIF magic number */
  1530. X
  1531. X  putword(RWidth,fp);          /* screen descriptor */
  1532. X  putword(RHeight,fp);
  1533. X
  1534. X  i=0x80;                  /* Yes,there is a color map */
  1535. X  i |= (8-1)<<4;                /* OR in the color resolution (hardwired 8) */
  1536. X  i |= (BitsPerPixel - 1);      /* OR in the # of bits per pixel */
  1537. X  fputc(i,fp);          
  1538. X
  1539. X  fputc(Background,fp);        /* background color */
  1540. X
  1541. X  fputc(0,fp);                 /* future expansion unsigned char */
  1542. X
  1543. X
  1544. X  if (colorstyle == 1) {        /* greyscale */
  1545. X    for (i=0; i<ColorMapSize; i++) {
  1546. X      j=(rmap[i]*77+gmap[i]*150+bmap[i]*29) >> 8;
  1547. X      fputc(j,fp);
  1548. X      fputc(j,fp);
  1549. X      fputc(j,fp);
  1550. X    }
  1551. X  }
  1552. X  else {
  1553. X    for (i=0; i<ColorMapSize; i++) {      /* write out Global colormap */
  1554. X      fputc(rmap[i],fp);
  1555. X      fputc(gmap[i],fp);
  1556. X      fputc(bmap[i],fp);
  1557. X    }
  1558. X  }
  1559. X
  1560. X  fputc(',',fp);             /* image separator */
  1561. X
  1562. X /* Write the Image header */
  1563. X  putword(LeftOfs,fp);
  1564. X  putword(TopOfs, fp);
  1565. X  putword(Width,  fp);
  1566. X  putword(Height, fp);
  1567. X  if (Interlace) fputc(0x40,fp);  /* Use Global Colormap,maybe Interlace */
  1568. X            else fputc(0x00,fp);
  1569. X
  1570. X  fputc(InitCodeSize,fp);
  1571. X  compress(InitCodeSize+1,fp,pic,w*h);
  1572. X
  1573. X  fputc(0,fp);                     /* Write out a Zero-length packet (EOF) */
  1574. X  fputc(';',fp);                   /* Write GIF file terminator */
  1575. X
  1576. X  return (0);
  1577. }
  1578. X
  1579. /******************************/
  1580. static void putword(w,fp)
  1581. int w;
  1582. FILE *fp;
  1583. {
  1584. X /* writes a 16-bit integer in GIF order (LSB first) */
  1585. X  fputc(w & 0xff,fp);
  1586. X  fputc((w>>8)&0xff,fp);
  1587. }
  1588. X
  1589. X
  1590. X
  1591. X
  1592. /***********************************************************************/
  1593. X
  1594. X
  1595. static unsigned long cur_accum=0;
  1596. static int           cur_bits=0;
  1597. X
  1598. X
  1599. #define min(a,b)        ((a>b) ? b : a)
  1600. X
  1601. #define BITS  12
  1602. #define MSDOS  1
  1603. X
  1604. #define HSIZE  5003           /* 80% occupancy */
  1605. X
  1606. typedef unsigned char   char_type;
  1607. X
  1608. X
  1609. static int n_bits;                  /* number of bits/code */
  1610. static int maxbits=BITS;          /* user settable max # bits/code */
  1611. static int maxcode;                 /* maximum code,given n_bits */
  1612. static int maxmaxcode=1 << BITS;  /* NEVER generate this */
  1613. X
  1614. #define MAXCODE(n_bits)     ((1 << (n_bits)) - 1)
  1615. X
  1616. static  count_int      htab [HSIZE];
  1617. static  unsigned short codetab [HSIZE];
  1618. #define HashTabOf(i)   htab[i]
  1619. #define CodeTabOf(i)   codetab[i]
  1620. X
  1621. static int hsize=HSIZE;           /* for dynamic table sizing */
  1622. X
  1623. /*
  1624. X * To save much memory,we overlay the table used by compress() with those
  1625. X * used by decompress().  The tab_prefix table is the same size and type
  1626. X * as the codetab.  The tab_suffix table needs 2**BITS characters.  We
  1627. X * get this from the beginning of htab.  The output stack uses the rest
  1628. X * of htab,and contains characters.  There is plenty of room for any
  1629. X * possible stack (stack used to be 8000 characters).
  1630. X */
  1631. X
  1632. #define tab_prefixof(i) CodeTabOf(i)
  1633. #define tab_suffixof(i)        ((char_type *)(htab))[i]
  1634. #define de_stack               ((char_type *)&tab_suffixof(1<<BITS))
  1635. X
  1636. static int free_ent=0;                 /* first unused entry */
  1637. X
  1638. /*
  1639. X * block compression parameters -- after all codes are used up,
  1640. X * and compression rate changes,start over.
  1641. X */
  1642. static int clear_flg=0;
  1643. X
  1644. static long int in_count=1;           /* length of input */
  1645. static long int out_count=0;          /* # of codes output (for debugging) */
  1646. X
  1647. /*
  1648. X * compress stdin to stdout
  1649. X *
  1650. X * Algorithm:  use open addressing double hashing (no chaining) on the 
  1651. X * prefix code/g next character combination.  We do a variant of Knuth's
  1652. X * algorithm D (vol. 3,sec. 6.4) along with G. Knott's relatively-prime
  1653. X * secondary probe.  Here,the modular division first probe is gives way
  1654. X * to a faster exclusive-or manipulation.  Also do block compression with
  1655. X * an adaptive reset,whereby the code table is cleared when the compression
  1656. X * ratio decreases,but after the table fills.  The variable-length output
  1657. X * codes are re-sized at this point,and a special CLEAR code is generated
  1658. X * for the decompressor.  Late addition:  construct the table according to
  1659. X * file size for noticeable speed improvement on small files.  Please direct
  1660. X * questions about this implementation to ames!jaw.
  1661. X */
  1662. X
  1663. static int g_init_bits;
  1664. static FILE *g_outfile;
  1665. X
  1666. static int ClearCode;
  1667. static int EOFCode;
  1668. X
  1669. X
  1670. /********************************************************/
  1671. static void compress(init_bits,outfile,data,len)
  1672. int   init_bits;
  1673. FILE *outfile;
  1674. unsigned char *data;
  1675. int   len;
  1676. {
  1677. X  register long fcode;
  1678. X  register int i=0;
  1679. X  register int c;
  1680. X  register int ent;
  1681. X  register int disp;
  1682. X  register int hsize_reg;
  1683. X  register int hshift;
  1684. X
  1685. X /*
  1686. X   * Set up the globals:  g_init_bits - initial number of bits
  1687. X   *                      g_outfile   - pointer to output file
  1688. X   */
  1689. X  g_init_bits=init_bits;
  1690. X  g_outfile  =outfile;
  1691. X
  1692. X /* initialize 'compress' globals */
  1693. X  maxbits=BITS;
  1694. X  maxmaxcode=1<<BITS;
  1695. X  memset((char *) htab,0,sizeof(htab));
  1696. X  memset((char *) codetab,0,sizeof(codetab));
  1697. X  hsize=HSIZE;
  1698. X  free_ent=0;
  1699. X  clear_flg=0;
  1700. X  in_count=1;
  1701. X  out_count=0;
  1702. X  cur_accum=0;
  1703. X  cur_bits=0;
  1704. X
  1705. X /*
  1706. X   * Set up the necessary values
  1707. X   */
  1708. X  out_count=0;
  1709. X  clear_flg=0;
  1710. X  in_count=1;
  1711. X  maxcode=MAXCODE(n_bits=g_init_bits);
  1712. X
  1713. X  ClearCode=(1 << (init_bits - 1));
  1714. X  EOFCode=ClearCode+1;
  1715. X  free_ent=ClearCode+2;
  1716. X
  1717. X  char_init();
  1718. X  ent=(*data++);  len--;
  1719. X
  1720. X  hshift=0;
  1721. X  for (fcode=(long) hsize;  fcode < 65536L; fcode *= 2L)
  1722. X    hshift++;
  1723. X  hshift=8 - hshift;               /* set hash code range bound */
  1724. X
  1725. X  hsize_reg=hsize;
  1726. X  cl_hash((count_int) hsize_reg);           /* clear hash table */
  1727. X
  1728. X  output(ClearCode);
  1729. X    
  1730. X  while (len) {
  1731. X    c=(*data++);  len--;
  1732. X    in_count++;
  1733. X
  1734. X    fcode=(long) (((long) c << maxbits)+ent);
  1735. X    i=(((int) c << hshift) ^ ent);   /* xor hashing */
  1736. X
  1737. X    if (HashTabOf (i) == fcode) {
  1738. X      ent=CodeTabOf (i);
  1739. X      continue;
  1740. X    }
  1741. X
  1742. X    else if ((long)HashTabOf (i) < 0)     /* empty slot */
  1743. X      goto nomatch;
  1744. X
  1745. X    disp=hsize_reg - i;          /* secondary hash (after G. Knott) */
  1746. X    if (i == 0)
  1747. X      disp=1;
  1748. X
  1749. probe:
  1750. X    if ((i -= disp) < 0)
  1751. X      i += hsize_reg;
  1752. X
  1753. X    if (HashTabOf (i) == fcode) {
  1754. X      ent=CodeTabOf (i);
  1755. X      continue;
  1756. X    }
  1757. X
  1758. X    if ((long)HashTabOf (i) > 0) 
  1759. X      goto probe;
  1760. X
  1761. nomatch:
  1762. X    output(ent);
  1763. X    out_count++;
  1764. X    ent=c;
  1765. X
  1766. X    if (free_ent < maxmaxcode) {
  1767. X      CodeTabOf (i)=free_ent++;/* code -> hashtable */
  1768. X      HashTabOf (i)=fcode;
  1769. X    }
  1770. X    else
  1771. X      cl_block();
  1772. X  }
  1773. X
  1774. X /* Put out the final code */
  1775. X  output(ent);
  1776. X  out_count++;
  1777. X  output(EOFCode);
  1778. }
  1779. X
  1780. X
  1781. /*****************************************************************
  1782. X * TAG(output)
  1783. X *
  1784. X * Output the given code.
  1785. X * Inputs:
  1786. X *      code:   A n_bits-bit integer.  If == -1,then EOF.  This assumes
  1787. X *              that n_bits =< (long)wordsize - 1.
  1788. X * Outputs:
  1789. X *      Outputs code to the file.
  1790. X * Assumptions:
  1791. X *      Chars are 8 bits long.
  1792. X * Algorithm:
  1793. X *      Maintain a BITS character long buffer (so that 8 codes will
  1794. X * fit in it exactly).  Use the VAX insv instruction to insert each
  1795. X * code in turn.  When the buffer fills up empty it and start over.
  1796. X */
  1797. X
  1798. static
  1799. unsigned long masks[]={ 0x0000,0x0001,0x0003,0x0007,0x000F,
  1800. X                                  0x001F,0x003F,0x007F,0x00FF,
  1801. X                                  0x01FF,0x03FF,0x07FF,0x0FFF,
  1802. X                                  0x1FFF,0x3FFF,0x7FFF,0xFFFF };
  1803. X
  1804. static void output(code)
  1805. int code;
  1806. {
  1807. X  cur_accum &= masks[cur_bits];
  1808. X
  1809. X  if (cur_bits > 0)
  1810. X    cur_accum |= ((long)code << cur_bits);
  1811. X  else
  1812. X    cur_accum=code;
  1813. X  
  1814. X  cur_bits += n_bits;
  1815. X
  1816. X  while(cur_bits >= 8) {
  1817. X    char_out((unsigned int) (cur_accum & 0xff));
  1818. X    cur_accum >>= 8;
  1819. X    cur_bits -= 8;
  1820. X  }
  1821. X
  1822. X /*
  1823. X   * If the next entry is going to be too big for the code size,
  1824. X   * then increase it,if possible.
  1825. X   */
  1826. X
  1827. X  if (free_ent > maxcode || clear_flg) {
  1828. X
  1829. X    if(clear_flg) {
  1830. X      maxcode=MAXCODE (n_bits=g_init_bits);
  1831. X      clear_flg=0;
  1832. X    }
  1833. X    else {
  1834. X      n_bits++;
  1835. X      if (n_bits == maxbits)
  1836. X  maxcode=maxmaxcode;
  1837. X      else
  1838. X  maxcode=MAXCODE(n_bits);
  1839. X    }
  1840. X  }
  1841. X  
  1842. X  if(code == EOFCode) {
  1843. X   /* At EOF,write the rest of the buffer */
  1844. X    while(cur_bits > 0) {
  1845. X      char_out((unsigned int)(cur_accum & 0xff));
  1846. X      cur_accum >>= 8;
  1847. X      cur_bits -= 8;
  1848. X    }
  1849. X
  1850. X    flush_char();
  1851. X  
  1852. X    fflush(g_outfile);
  1853. X
  1854. X    if(ferror(g_outfile))
  1855. X      Error("unable to write GIF file",(char *) NULL);
  1856. X  }
  1857. }
  1858. X
  1859. X
  1860. /********************************/
  1861. static void cl_block ()            /* table clear for block compress */
  1862. {
  1863. X /* Clear out the hash table */
  1864. X
  1865. X  cl_hash ((count_int) hsize);
  1866. X  free_ent=ClearCode+2;
  1867. X  clear_flg=1;
  1868. X
  1869. X  output(ClearCode);
  1870. }
  1871. X
  1872. X
  1873. /********************************/
  1874. static void cl_hash(hsize)         /* reset code table */
  1875. register count_int hsize;
  1876. {
  1877. X  register count_int *htab_p=htab+hsize;
  1878. X  register long i;
  1879. X  register long m1=(-1);
  1880. X
  1881. X  i=hsize - 16;
  1882. X  do {                           /* might use Sys V memset(3) here */
  1883. X    *(htab_p-16)=m1;
  1884. X    *(htab_p-15)=m1;
  1885. X    *(htab_p-14)=m1;
  1886. X    *(htab_p-13)=m1;
  1887. X    *(htab_p-12)=m1;
  1888. X    *(htab_p-11)=m1;
  1889. X    *(htab_p-10)=m1;
  1890. X    *(htab_p-9)=m1;
  1891. X    *(htab_p-8)=m1;
  1892. X    *(htab_p-7)=m1;
  1893. X    *(htab_p-6)=m1;
  1894. X    *(htab_p-5)=m1;
  1895. X    *(htab_p-4)=m1;
  1896. X    *(htab_p-3)=m1;
  1897. X    *(htab_p-2)=m1;
  1898. X    *(htab_p-1)=m1;
  1899. X    htab_p -= 16;
  1900. X  } while ((i -= 16) >= 0);
  1901. X
  1902. X  for (i += 16; i > 0; i--)
  1903. X    *--htab_p=m1;
  1904. }
  1905. X
  1906. X
  1907. /******************************************************************************
  1908. X *
  1909. X * GIF Specific routines
  1910. X *
  1911. X ******************************************************************************/
  1912. X
  1913. /*
  1914. X * Number of characters so far in this 'packet'
  1915. X */
  1916. static int a_count;
  1917. X
  1918. /*
  1919. X * Set up the 'unsigned char output' routine
  1920. X */
  1921. static void char_init()
  1922. {
  1923. X  a_count=0;
  1924. }
  1925. X
  1926. /*
  1927. X * Define the storage for the packet accumulator
  1928. X */
  1929. static char accum[256];
  1930. X
  1931. /*
  1932. X * Add a character to the end of the current packet,and if it is 254
  1933. X * characters,flush the packet to disk.
  1934. X */
  1935. static void char_out(c)
  1936. int c;
  1937. {
  1938. X  accum[a_count++]=c;
  1939. X  if(a_count >= 254) 
  1940. X    flush_char();
  1941. }
  1942. X
  1943. /*
  1944. X * Flush the packet to disk,and reset the accumulator
  1945. X */
  1946. static void flush_char()
  1947. {
  1948. X  if(a_count > 0) {
  1949. X    fputc(a_count,g_outfile);
  1950. X    fwrite(accum,1,a_count,g_outfile);
  1951. X    a_count=0;
  1952. X  }
  1953. }  
  1954. X
  1955. /*
  1956. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1957. %                                                                             %
  1958. %                                                                             %
  1959. %                                                                             %
  1960. %    M a i n                                                                  %
  1961. %                                                                             %
  1962. %                                                                             %
  1963. %                                                                             %
  1964. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1965. %
  1966. %
  1967. */
  1968. int main(argc,argv)
  1969. int
  1970. X  argc;
  1971. X
  1972. char
  1973. X  *argv[];
  1974. {
  1975. X  Image
  1976. X    *image;
  1977. X
  1978. X  application_name=argv[0];
  1979. X  if (argc < 3)
  1980. X    Usage((char *) NULL);
  1981. X  image=ReadImage(argv[1]);
  1982. X  if (image == (Image *) NULL)
  1983. X    exit(1);
  1984. X  (void) strcpy(image->filename,argv[2]);
  1985. X  WriteGIFImage(image);
  1986. X  (void) fprintf(stderr,"%s=> %s  %dx%d\n",argv[1],argv[2],image->columns,
  1987. X    image->rows);
  1988. X  return(False);
  1989. }
  1990. SHAR_EOF
  1991. chmod 0755 ImageMagick/filters/MIFFtoGIF.c ||
  1992. echo 'restore of ImageMagick/filters/MIFFtoGIF.c failed'
  1993. Wc_c="`wc -c < 'ImageMagick/filters/MIFFtoGIF.c'`"
  1994. test 22524 -eq "$Wc_c" ||
  1995.     echo 'ImageMagick/filters/MIFFtoGIF.c: original size 22524, current size' "$Wc_c"
  1996. rm -f _shar_wnt_.tmp
  1997. fi
  1998. # ============= ImageMagick/display.c ==============
  1999. if test -f 'ImageMagick/display.c' -a X"$1" != X"-c"; then
  2000.     echo 'x - skipping ImageMagick/display.c (File already exists)'
  2001.     rm -f _shar_wnt_.tmp
  2002. else
  2003. > _shar_wnt_.tmp
  2004. echo 'x - extracting ImageMagick/display.c (Text)'
  2005. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/display.c' &&
  2006. /*
  2007. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2008. %                                                                             %
  2009. %                                                                             %
  2010. %                                                                             %
  2011. %             DDDD   IIIII  SSSSS  PPPP   L       AAA   Y   Y                 %
  2012. %             D   D    I    SS     P   P  L      A   A   Y Y                  %
  2013. %             D   D    I     SSS   PPPP   L      AAAAA    Y                   %
  2014. %             D   D    I       SS  P      L      A   A    Y                   %
  2015. %             DDDD   IIIII  SSSSS  P      LLLLL  A   A    Y                   %
  2016. %                                                                             %
  2017. %                                                                             %
  2018. %          Display Machine Independent File Format Image via X11.             %
  2019. %                                                                             %
  2020. %                                                                             %
  2021. %                                                                             %
  2022. %                           Software Design                                   %
  2023. %                             John Cristy                                     %
  2024. %                            January  1991                                    %
  2025. %                                                                             %
  2026. %                                                                             %
  2027. %  Copyright 1991 E. I. Dupont de Nemours & Company                           %
  2028. %                                                                             %
  2029. %  Permission to use, copy, modify, distribute, and sell this software and    %
  2030. %  its documentation for any purpose is hereby granted without fee,           %
  2031. %  provided that the above Copyright notice appear in all copies and that     %
  2032. %  both that Copyright notice and this permission notice appear in            %
  2033. %  supporting documentation, and that the name of E. I. Dupont de Nemours     %
  2034. %  & Company not be used in advertising or publicity pertaining to            %
  2035. %  distribution of the software without specific, written prior               %
  2036. %  permission.  E. I. Dupont de Nemours & Company makes no representations    %
  2037. %  about the suitability of this software for any purpose.  It is provided    %
  2038. %  "as is" without express or implied warranty.                               %
  2039. %                                                                             %
  2040. %  E. I. Dupont de Nemours & Company disclaims all warranties with regard     %
  2041. %  to this software, including all implied warranties of merchantability      %
  2042. %  and fitness, in no event shall E. I. Dupont de Nemours & Company be        %
  2043. %  liable for any special, indirect or consequential damages or any           %
  2044. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  2045. %  in an action of contract, negligence or other tortious action, arising     %
  2046. %  out of or in connection with the use or performance of this software.      %
  2047. %                                                                             %
  2048. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2049. %
  2050. %  Display is a machine architecture independent image processing
  2051. %  and display program.  It can display any image in the MIFF format on
  2052. %  any workstation display running X.  Display first determines the
  2053. %  hardware capabilities of the workstation.  If the number of unique
  2054. %  colors in the image is less than or equal to the number the workstation
  2055. %  can support, the image is displayed in an X window.  Otherwise the
  2056. %  number of colors in the image is first reduced to match the color
  2057. %  resolution of the workstation before it is displayed.
  2058. %
  2059. %  This means that a continuous-tone 24 bits/pixel image can display on a
  2060. %  8 bit pseudo-color device or monochrome device.  In most instances the
  2061. %  reduced color image closely resembles the original.  Alternatively, a
  2062. %  monochrome or pseudo-color image can display on a continuous-tone 24
  2063. %  bits/pixels device.
  2064. %
  2065. %  The Display program command syntax is:
  2066. %
  2067. %  Usage: display [options ...] file [ [options ...] file ...]
  2068. %
  2069. %  Where options include:
  2070. %    -backdrop           display image centered on a backdrop
  2071. %    -clip geometry      preferred size and location of the clipped image
  2072. %    -colors value       preferred number of colors in the image
  2073. %    -compress type      compress image: RunlengthEncoded or QEncoded
  2074. %    -delay seconds      display the next image after pausing
  2075. %    -display server     display image to this X server
  2076. %    -dither             apply Floyd/Steinberg error diffusion to image
  2077. %    -enhance            apply a digital filter to enhance a noisy image
  2078. %    -gamma value        level of gamma correction
  2079. %    -geometry geometry  preferred size and location of the image window
  2080. %    -gray               transform image to gray scale colors
  2081. %    -inverse            apply color inversion to image
  2082. %    -magnify value      level of image magnification
  2083. %    -map type           display image using this Standard Colormap
  2084. %    -monochrome         transform image to black and white
  2085. %    -noise              reduce noise with a noise peak elimination filter
  2086. %    -normalize          tranform image to span the full the range of colors
  2087. %    -print file         write image as Postscript to a file
  2088. %    -reflect            reverse image scanlines
  2089. %    -root               display image on the root window
  2090. %    -rotate degrees     apply Paeth rotation to the image
  2091. %    -scale geometry     preferred size factors of the image
  2092. %    -scene number       image scene number
  2093. %    -treedepth value    depth of the color classification tree
  2094. %    -verbose            print detailed information about the image
  2095. %    -visual type        display image using this visual type
  2096. %    -write file         write image to a file
  2097. %
  2098. %  In addition to those listed above, you can specify these standard X
  2099. %  resources as command line options:  -background, -bordercolor,
  2100. %  -borderwidth, -font, -foreground, -iconGeometry, -iconic, -name, or
  2101. %  -title.
  2102. %
  2103. %  Change '-' to '+' in any option above to reverse its effect.  For
  2104. %  example, specify +compress to store the image as uncompressed.
  2105. %
  2106. %  Specify 'file' as '-' for standard input or output.
  2107. %
  2108. %  Buttons
  2109. %    Control-1
  2110. %         press and drag to pan the image
  2111. %    1    press and drag to select a command from a pop-up menu
  2112. %    2    press and drag to define a region of the image to clip
  2113. SHAR_EOF
  2114. true || echo 'restore of ImageMagick/display.c failed'
  2115. fi
  2116. echo 'End of ImageMagick part 16'
  2117. echo 'File ImageMagick/display.c is continued in part 17'
  2118. echo 17 > _shar_seq_.tmp
  2119. exit 0
  2120. --
  2121. Dan Heller
  2122. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  2123. Senior Writer                President          comp-sources-x@uunet.uu.net
  2124. argv@ora.com                 argv@zipcode.com
  2125.