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

  1. Newsgroups: comp.sources.misc
  2. From: cristy@eplrx7.es.duPont.com (John Cristy)
  3. Subject:  v34i038:  imagemagick - X11 image processing and display v2.2, Part10/26
  4. Message-ID: <1992Dec13.202835.9982@sparky.imd.sterling.com>
  5. X-Md4-Signature: 21d89b01a7161aa8a07ccb13cadbf558
  6. Date: Sun, 13 Dec 1992 20:28:35 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: cristy@eplrx7.es.duPont.com (John Cristy)
  10. Posting-number: Volume 34, Issue 38
  11. Archive-name: imagemagick/part10
  12. Environment: UNIX, VMS, X11, SGI, DEC, Cray, Sun, Vax
  13.  
  14. #!/bin/sh
  15. # this is Part.10 (part 10 of a multipart archive)
  16. # do not concatenate these parts, unpack them in order with /bin/sh
  17. # file ImageMagick/rotate.c continued
  18. #
  19. if test ! -r _shar_seq_.tmp; then
  20.     echo 'Please unpack part 1 first!'
  21.     exit 1
  22. fi
  23. (read Scheck
  24.  if test "$Scheck" != 10; then
  25.     echo Please unpack part "$Scheck" next!
  26.     exit 1
  27.  else
  28.     exit 0
  29.  fi
  30. ) < _shar_seq_.tmp || exit 1
  31. if test ! -f _shar_wnt_.tmp; then
  32.     echo 'x - still skipping ImageMagick/rotate.c'
  33. else
  34. echo 'x - continuing file ImageMagick/rotate.c'
  35. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/rotate.c' &&
  36. X          rotated_image->columns,x_shear*
  37. X          (((double) i)-(rotated_image->rows-1)/2.0),background,range_limit);
  38. X        row++;
  39. X      }
  40. X      /*
  41. X        Shear the image columns.
  42. X      */
  43. X      column=(number_columns-y_width)/2;
  44. X      for (i=0; i < y_width; i++)
  45. X      {
  46. X        ColumnShear(rotated_pixels+number_columns,number_columns,column,
  47. X          y_offset,rotated_image->rows,y_shear*(((double) i)-(y_width-1)/2.0),
  48. X          background,range_limit);
  49. X        column++;
  50. X      }
  51. X      /*
  52. X        Shear the image rows again.
  53. X      */
  54. X      for (i=0; i < number_rows; i++)
  55. X        RowShear(rotated_pixels+number_columns,number_columns,(unsigned int) i,
  56. X          (number_columns-y_width)/2,y_width,x_shear*
  57. X          (((double) i)-(number_rows-1)/2.0),background,range_limit);
  58. X      (void) free((char *) range_table);
  59. X      /*
  60. X        Calculate the rotated image size.
  61. X      */
  62. X      corners[0].x=(-((int) rotated_image->columns)/2.0);
  63. X      corners[0].y=(-((int) rotated_image->rows)/2.0);
  64. X      corners[1].x=((int) rotated_image->columns)/2.0;
  65. X      corners[1].y=(-((int) rotated_image->rows)/2.0);
  66. X      corners[2].x=(-((int) rotated_image->columns)/2.0);
  67. X      corners[2].y=((int) rotated_image->rows)/2.0;
  68. X      corners[3].x=((int) rotated_image->columns)/2.0;
  69. X      corners[3].y=((int) rotated_image->rows)/2.0;
  70. X      for (i=0; i < 4; i++)
  71. X      {
  72. X        corners[i].x+=x_shear*corners[i].y;
  73. X        corners[i].y+=y_shear*corners[i].x;
  74. X        corners[i].x+=x_shear*corners[i].y;
  75. X        corners[i].x+=(number_columns-1)/2.0;
  76. X        corners[i].y+=(number_rows-1)/2.0;
  77. X      }
  78. X      x_min=corners[0].x;
  79. X      y_min=corners[0].y;
  80. X      x_max=corners[0].x;
  81. X      y_max=corners[0].y;
  82. X      for (i=1; i < 4; i++)
  83. X      {
  84. X        if (x_min > corners[i].x)
  85. X          x_min=corners[i].x;
  86. X        if (y_min > corners[i].y)
  87. X          y_min=corners[i].y;
  88. X        if (x_max < corners[i].x)
  89. X          x_max=corners[i].x;
  90. X        if (y_max < corners[i].y)
  91. X          y_max=corners[i].y;
  92. X      }
  93. X      x_min=floor((double) x_min);
  94. X      x_max=ceil((double) x_max);
  95. X      y_min=floor((double) y_min);
  96. X      y_max=ceil((double) y_max);
  97. X      if (!clip)
  98. X        {
  99. X          /*
  100. X            Rotated image is not clipped.
  101. X          */
  102. X          rotated_image->columns=(unsigned int) (x_max-x_min);
  103. X          rotated_image->rows=(unsigned int) (y_max-y_min);
  104. X        }
  105. X      x_offset=(int) x_min+((int) (x_max-x_min)-rotated_image->columns)/2;
  106. X      y_offset=(int) y_min+((int) (y_max-y_min)-rotated_image->rows)/2;
  107. X    }
  108. X  /*
  109. X    Convert the rectangular array of pixels to runlength packets.
  110. X  */
  111. X  rotated_image->packets=rotated_image->columns*rotated_image->rows;
  112. X  q=rotated_image->pixels;
  113. X  for (y=0; y < rotated_image->rows; y++)
  114. X  {
  115. X    p=rotated_pixels+number_columns+(y+y_offset)*number_columns+x_offset;
  116. X    for (x=0; x < rotated_image->columns; x++)
  117. X    {
  118. X      q->red=p->red;
  119. X      q->green=p->green;
  120. X      q->blue=p->blue;
  121. X      q->index=p->index;
  122. X      q->length=0;
  123. X      q++;
  124. X      p++;
  125. X    }
  126. X  }
  127. X  (void) free((char *) rotated_pixels);
  128. X  return(rotated_image);
  129. }
  130. SHAR_EOF
  131. echo 'File ImageMagick/rotate.c is complete' &&
  132. chmod 0644 ImageMagick/rotate.c ||
  133. echo 'restore of ImageMagick/rotate.c failed'
  134. Wc_c="`wc -c < 'ImageMagick/rotate.c'`"
  135. test 29802 -eq "$Wc_c" ||
  136.     echo 'ImageMagick/rotate.c: original size 29802, current size' "$Wc_c"
  137. rm -f _shar_wnt_.tmp
  138. fi
  139. # ============= ImageMagick/compress.c ==============
  140. if test -f 'ImageMagick/compress.c' -a X"$1" != X"-c"; then
  141.     echo 'x - skipping ImageMagick/compress.c (File already exists)'
  142.     rm -f _shar_wnt_.tmp
  143. else
  144. > _shar_wnt_.tmp
  145. echo 'x - extracting ImageMagick/compress.c (Text)'
  146. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/compress.c' &&
  147. /*
  148. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  149. %                                                                             %
  150. %                                                                             %
  151. %                                                                             %
  152. %           CCCC   OOO   M   M  PPPP   RRRR   EEEEE   SSSSS  SSSSS            %
  153. %          C      O   O  MM MM  P   P  R   R  E       SS     SS               %
  154. %          C      O   O  M M M  PPPP   RRRR   EEE      SSS    SSS             %
  155. %          C      O   O  M   M  P      R R    E          SS     SS            %
  156. %           CCCC   OOO   M   M  P      R  R   EEEEE   SSSSS  SSSSS            %
  157. %                                                                             %
  158. %                                                                             %
  159. %                      Image Compression Coders                               %
  160. %                                                                             %
  161. %                                                                             %
  162. %                                                                             %
  163. %                           Software Design                                   %
  164. %                             John Cristy                                     %
  165. %                              July 1992                                      %
  166. %                                                                             %
  167. %                                                                             %
  168. %  Copyright 1992 E. I. du Pont de Nemours & Company                          %
  169. %                                                                             %
  170. %  Permission to use, copy, modify, distribute, and sell this software and    %
  171. %  its documentation for any purpose is hereby granted without fee,           %
  172. %  provided that the above Copyright notice appear in all copies and that     %
  173. %  both that Copyright notice and this permission notice appear in            %
  174. %  supporting documentation, and that the name of E. I. du Pont de Nemours    %
  175. %  & Company not be used in advertising or publicity pertaining to            %
  176. %  distribution of the software without specific, written prior               %
  177. %  permission.  E. I. du Pont de Nemours & Company makes no representations   %
  178. %  about the suitability of this software for any purpose.  It is provided    %
  179. %  "as is" without express or implied warranty.                               %
  180. %                                                                             %
  181. %  E. I. du Pont de Nemours & Company disclaims all warranties with regard    %
  182. %  to this software, including all implied warranties of merchantability      %
  183. %  and fitness, in no event shall E. I. du Pont de Nemours & Company be       %
  184. %  liable for any special, indirect or consequential damages or any           %
  185. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  186. %  in an action of contract, negligence or other tortious action, arising     %
  187. %  out of or in connection with the use or performance of this software.      %
  188. %                                                                             %
  189. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  190. %
  191. %  Functions HuffmanEncodeImage is based on the CCITT T.4 format
  192. %  specifications.
  193. %
  194. %  Functions LZWEncodeImage and LZWDecodeImage is based on the GIF image
  195. %  format specifications.
  196. %
  197. %  Functions QEncodeImage and QDecodeImage is based on the document
  198. %  "JPEG-9-R6 Working Draft for Development of JPEG CD", January 1992.
  199. %  These routines only implement the lossless JPEG compression algorithm in
  200. %  a non-standard fashion.  They can only be used to code and decode MIFF
  201. %  images.
  202. %
  203. %  Images are compressed using a simple predictive method.  The predictor
  204. %  combines three neighboring samples (A, B, and C) to form a prediction
  205. %  of the sample X:
  206. %
  207. %    C B
  208. %    A X
  209. %
  210. %  The prediction formula is A + B - C.  The prediction is subtracted from
  211. %  from the actual sample X and the difference is encoded by an arithmetic
  212. %  entropy coding method.
  213. %
  214. %
  215. */
  216. X
  217. /*
  218. X  Include declarations.
  219. */
  220. #include "display.h"
  221. #include "image.h"
  222. /*
  223. X  Define declarations.
  224. */
  225. #define LowerBound  0
  226. #define MaxContextStates  121
  227. #define MinimumIntervalD  (unsigned short) 0xf000  /* ~-0.75 */
  228. #define MinimumIntervalE  (unsigned short) 0x1000  /* ~0.75 */
  229. #define No  0
  230. #define UpperBound  2
  231. #define Yes  1
  232. /*
  233. X  State classification.
  234. */
  235. #define ZeroState  0
  236. #define SmallPostitiveState  1
  237. #define SmallNegativeState  2
  238. #define LargePostitiveState  3
  239. #define LargeNegativeState  4
  240. /*
  241. X  Typedef declarations.
  242. */
  243. typedef struct _ScanlinePacket
  244. {
  245. X  unsigned char
  246. X    pixel;
  247. X
  248. X  int
  249. X    state;
  250. } ScanlinePacket;
  251. /*
  252. X  Initialized declarations.
  253. */
  254. static int decrement_less_probable[]=
  255. {
  256. X  0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2,
  257. X  2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2
  258. };
  259. X
  260. static int increment_more_probable[]=
  261. {
  262. X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  263. X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
  264. };
  265. X
  266. static int more_probable_exchange[]=
  267. {
  268. X  1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  269. X  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  270. };
  271. X
  272. static int statistics[][5]=
  273. {
  274. X   0,  4,  8, 12, 16,
  275. X  20, 24, 28, 32, 36,
  276. X  40, 44, 48, 52, 56,
  277. X  60, 64, 68, 72, 76,
  278. X  80, 84, 88, 92, 96,
  279. };
  280. X
  281. static unsigned short probability[]=
  282. {
  283. X  0x0ac1, 0x0a81, 0x0a01, 0x0901, 0x0701, 0x0681,
  284. X  0x0601, 0x0501, 0x0481, 0x0441, 0x0381, 0x0301,
  285. X  0x02c1, 0x0281, 0x0241, 0x0181, 0x0121, 0x00e1,
  286. X  0x00a1, 0x0071, 0x0059, 0x0053, 0x0027, 0x0017,
  287. X  0x0013, 0x000b, 0x0007, 0x0005, 0x0003, 0x0001
  288. };
  289. /*
  290. X  Declarations and initializations for predictive arithimetic coder.
  291. */
  292. static int
  293. X  code,
  294. X  less_probable[MaxContextStates],
  295. X  more_probable[MaxContextStates],
  296. X  probability_estimate[MaxContextStates];
  297. X
  298. static unsigned char
  299. X  *q;
  300. X
  301. static unsigned short
  302. X  interval;
  303. X
  304. /*
  305. X  External declarations.
  306. */
  307. extern char
  308. X  *application_name;
  309. X
  310. /*
  311. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  312. %                                                                             %
  313. %                                                                             %
  314. %                                                                             %
  315. %   D e c o d e                                                               %
  316. %                                                                             %
  317. %                                                                             %
  318. %                                                                             %
  319. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  320. %
  321. %  Function Decode uncompresses a string.
  322. %
  323. %  The format of the Decode routine is:
  324. %
  325. %      Decode(state,decision)
  326. %
  327. %  A description of each parameter follows:
  328. %
  329. %    o state:  An integer value representing the current state.
  330. %
  331. %    o decision:  A pointer to an integer.  The output of the binary
  332. %      decision (Yes/No) is returned in this value.
  333. %
  334. %
  335. */
  336. static void Decode(state,decision)
  337. register int
  338. X  state,
  339. X  *decision;
  340. {
  341. X  interval+=probability[probability_estimate[state]];
  342. X  if (((code >> 16) & 0xffff) < ((int) interval))
  343. X    {
  344. X      code-=(interval << 16);
  345. X      interval=(-probability[probability_estimate[state]]);
  346. X      *decision=less_probable[state];
  347. X    }
  348. X  else
  349. X    {
  350. X      *decision=more_probable[state];
  351. X      if (interval <= MinimumIntervalD)
  352. X        return;
  353. X    }
  354. X  do
  355. X  {
  356. X    if ((code & 0xff) == 0)
  357. X      {
  358. X        code&=0xffff0000;
  359. X        if ((*q++) == 0xff)
  360. X          code+=((int) (*q) << 9)+0x02;
  361. X        else
  362. X          code+=((int) (*q) << 8)+0x01;
  363. X      }
  364. X    interval<<=1;
  365. X    code<<=1;
  366. X  } while (interval > MinimumIntervalD);
  367. X  /*
  368. X    Update probability estimates.
  369. X  */
  370. X  if (*decision == more_probable[state])
  371. X    probability_estimate[state]+=
  372. X      increment_more_probable[probability_estimate[state]];
  373. X  else
  374. X    probability_estimate[state]-=
  375. X      decrement_less_probable[probability_estimate[state]];
  376. X  if (more_probable_exchange[probability_estimate[state]] != 0)
  377. X    {
  378. X      /*
  379. X        Exchange sense of most probable and least probable.
  380. X      */
  381. X      less_probable[state]=more_probable[state];
  382. X      more_probable[state]=1-more_probable[state];
  383. X    }
  384. }
  385. X
  386. /*
  387. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  388. %                                                                             %
  389. %                                                                             %
  390. %                                                                             %
  391. %   E n c o d e                                                               %
  392. %                                                                             %
  393. %                                                                             %
  394. %                                                                             %
  395. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  396. %
  397. %  Function Encode generate compressed data string by encoding yes-no decision
  398. %  given state s.
  399. %
  400. %  The format of the Encode routine is:
  401. %
  402. %      Encode(state,decision)
  403. %
  404. %  A description of each parameter follows:
  405. %
  406. %    o state:  An integer value representing the current state.
  407. %
  408. %    o decision:  An integer value representing a binary decision.
  409. %
  410. %
  411. */
  412. static void Encode(state,decision)
  413. register int
  414. X  state,
  415. X  decision;
  416. {
  417. X  /*
  418. X    Test on "most-probable-symbol" for state s(more_probable[state])
  419. X  */
  420. X  interval-=probability[probability_estimate[state]];
  421. X  if (more_probable[state] != decision)
  422. X    {
  423. X      code-=interval;
  424. X      interval=probability[probability_estimate[state]];
  425. X    }
  426. X  else
  427. X    if (interval >= MinimumIntervalE)
  428. X      return;
  429. X  /*
  430. X    Encoder renormalization.
  431. X  */
  432. X  do
  433. X  {
  434. X    interval<<=1;
  435. X    if (code >= 0)
  436. X      code<<=1;
  437. X    else
  438. X      {
  439. X        /*
  440. X          Shift unsigned char of data from Code register to compressed string.
  441. X        */
  442. X        code<<=1;
  443. X        if (code > 0)
  444. X          {
  445. X            /*
  446. X              Add eight bits from Code register to compressed data string.
  447. X            */
  448. X            (*q++)--;
  449. X            *q=(unsigned char) (code >> 16);
  450. X            code&=0x0000ffff;
  451. X            code|=0x01800000;
  452. X          }
  453. X        else
  454. X          {
  455. X            code&=0x01ffffff;
  456. X            if ((int) interval > code)
  457. X              {
  458. X                /*
  459. X                  Add eight bits from Code register to compressed data string.
  460. X                */
  461. X                (*q++)--;
  462. X                *q=0xff;
  463. X                code|=0x01810000;
  464. X              }
  465. X            else
  466. X              if ((*q++) == 0xff)
  467. X                {
  468. X                  /*
  469. X                    Add seven bits from Code register plus one stuffed bit to
  470. X                    compressed data string.
  471. X                  */
  472. X                  *q=(unsigned char) (code >> 17);
  473. X                  code&=0x0001ffff;
  474. X                  code|=0x03000000;
  475. X                }
  476. X              else
  477. X                {
  478. X                  /*
  479. X                    Add eight bits from Code register to compressed data string.
  480. X                  */
  481. X                  *q=(unsigned char) (code >> 16);
  482. X                  code&=0x0000ffff;
  483. X                  code|=0x01800000;
  484. X                }
  485. X          }
  486. X      }
  487. X  } while (interval < MinimumIntervalE);
  488. X  /*
  489. X    Update probability estimates
  490. X  */
  491. X  if (decision == more_probable[state])
  492. X    probability_estimate[state]+=
  493. X      increment_more_probable[probability_estimate[state]];
  494. X  else
  495. X    probability_estimate[state]-=
  496. X      decrement_less_probable[probability_estimate[state]];
  497. X  if (more_probable_exchange[probability_estimate[state]] != 0)
  498. X    more_probable[state]=1-more_probable[state];
  499. }
  500. X
  501. /*
  502. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  503. %                                                                             %
  504. %                                                                             %
  505. %                                                                             %
  506. %   F l u s h                                                                 %
  507. %                                                                             %
  508. %                                                                             %
  509. %                                                                             %
  510. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  511. %
  512. %  Function Flush flushes the final bits of data from the Code register to the
  513. %  compressed data string.
  514. %
  515. %  The format of the Flush routine is:
  516. %
  517. %      Flush()
  518. %
  519. %
  520. */
  521. static void Flush()
  522. {
  523. X  register int
  524. X    extra_bits;
  525. X
  526. X  code-=interval;
  527. X  extra_bits=24;
  528. X  extra_bits--;
  529. X  while (code >= 0)
  530. X  {
  531. X    code<<=1;
  532. X    extra_bits--;
  533. X  }
  534. X  code<<=1;
  535. X  if (code > 0)
  536. X    (*q)--;
  537. X  /*
  538. X    Add the final compressed data unsigned chars to the compressed data string.
  539. X  */
  540. X  do
  541. X  {
  542. X    if ((*q++) == 0xff)
  543. X      {
  544. X        /*
  545. X          Add seven bits of data plus one stuffed bit to the compressed data
  546. X          string during final Flush of Code register.
  547. X        */
  548. X        *q=(unsigned char) (code >> 17);
  549. X        code&=0x0001ffff;
  550. X        code<<=7;
  551. X        extra_bits-=7;
  552. X      }
  553. X    else
  554. X      {
  555. X        /*
  556. X           Add eight bits of data to the compressed data string during final
  557. X           flush of Code register.
  558. X        */
  559. X        *q=(unsigned char) (code >> 16);
  560. X        code&=0x0000ffff;
  561. X        code<<=8;
  562. X        extra_bits-=8;
  563. X      }
  564. X  } while (extra_bits > 0);
  565. X  q++;
  566. }
  567. X
  568. /*
  569. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  570. %                                                                             %
  571. %                                                                             %
  572. %                                                                             %
  573. %   H u f f m a n E n c o d e I m a g e                                       %
  574. %                                                                             %
  575. %                                                                             %
  576. %                                                                             %
  577. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  578. %
  579. %  Function HuffmanEncodeImage compresses an image via Huffman-coding.
  580. %
  581. %  The format of the HuffmanEncodeImage routine is:
  582. %
  583. %      status=HuffmanEncodeImage(image)
  584. %
  585. %  A description of each parameter follows:
  586. %
  587. %    o status:  Function HuffmanEncodeImage returns True if all the pixels are
  588. %      compressed without error, otherwise False.
  589. %
  590. %    o image: The address of a structure of type Image.
  591. %
  592. %
  593. */
  594. unsigned int HuffmanEncodeImage(image)
  595. Image
  596. X  *image;
  597. {
  598. #define HuffmanOutputCode(te)  \
  599. {  \
  600. X  mask=1 << (entry->length-1);  \
  601. X  while (mask)   \
  602. X  {  \
  603. X    if (entry->code & mask)  \
  604. X      OutputBit(1)  \
  605. X    else  \
  606. X      OutputBit(0);  \
  607. X    mask>>=1;  \
  608. X  }  \
  609. }
  610. X
  611. #define OutputBit(count)  \
  612. {  \
  613. X  if(count > 0)  \
  614. X    byte=byte | bit;  \
  615. X  bit>>=1;  \
  616. X  if ((bit & 0xff) == 0)   \
  617. X    {  \
  618. X      (void) fwrite((char *) &byte,1,1,image->file);  \
  619. X      byte=0;  \
  620. X      bit=0x80;  \
  621. X    }  \
  622. }
  623. X
  624. X  typedef struct HuffmanTable
  625. X  {
  626. X    int
  627. X      id,
  628. X      code,
  629. X      length,
  630. X      count;
  631. X  } HuffmanTable;
  632. X
  633. X  static HuffmanTable MBTable[]=
  634. X  {
  635. X    { 26, 0x0f, 10, 64 }, { 26, 0xc8, 12, 128 }, { 26, 0xc9, 12, 192 },
  636. X    { 26, 0x5b, 12, 256 }, { 26, 0x33, 12, 320 }, { 26, 0x34, 12, 384 },
  637. X    { 26, 0x35, 12, 448 }, { 26, 0x6c, 13, 512 }, { 26, 0x6d, 13, 576 },
  638. X    { 26, 0x4a, 13, 640 }, { 26, 0x4b, 13, 704 }, { 26, 0x4c, 13, 768 },
  639. X    { 26, 0x4d, 13, 832 }, { 26, 0x72, 13, 896 }, { 26, 0x73, 13, 960 },
  640. X    { 26, 0x74, 13, 1024 }, { 26, 0x75, 13, 1088 }, { 26, 0x76, 13, 1152 },
  641. X    { 26, 0x77, 13, 1216 }, { 26, 0x52, 13, 1280 }, { 26, 0x53, 13, 1344 },
  642. X    { 26, 0x54, 13, 1408 }, { 26, 0x55, 13, 1472 }, { 26, 0x5a, 13, 1536 },
  643. X    { 26, 0x5b, 13, 1600 }, { 26, 0x64, 13, 1664 }, { 26, 0x65, 13, 1728 },
  644. X  };
  645. X
  646. X  static HuffmanTable MWTable[]=
  647. X  {
  648. X    { 24, 0x1b, 5, 64 }, { 24, 0x12, 5, 128 }, { 24, 0x17, 6, 192 },
  649. X    { 24, 0x37, 7, 256 }, { 24, 0x36, 8, 320 }, { 24, 0x37, 8, 384 },
  650. X    { 24, 0x64, 8, 448 }, { 24, 0x65, 8, 512 }, { 24, 0x68, 8, 576 },
  651. X    { 24, 0x67, 8, 640 }, { 24, 0xcc, 9, 704 }, { 24, 0xcd, 9, 768 },
  652. X    { 24, 0xd2, 9, 832 }, { 24, 0xd3, 9, 896 }, { 24, 0xd4, 9, 960 },
  653. X    { 24, 0xd5, 9, 1024 }, { 24, 0xd6, 9, 1088 }, { 24, 0xd7, 9, 1152 },
  654. X    { 24, 0xd8, 9, 1216 }, { 24, 0xd9, 9, 1280 }, { 24, 0xda, 9, 1344 },
  655. X    { 24, 0xdb, 9, 1408 }, { 24, 0x98, 9, 1472 }, { 24, 0x99, 9, 1536 },
  656. X    { 24, 0x9a, 9, 1600 }, { 24, 0x18, 6, 1664 }, { 24, 0x9b, 9, 1728 },
  657. X  };
  658. X
  659. X  static HuffmanTable TBTable[]=
  660. X  {
  661. X    { 25, 0x37, 10, 0 }, { 25, 0x02, 3, 1 }, { 25, 0x03, 2, 2 },
  662. X    { 25, 0x02, 2, 3 }, { 25, 0x03, 3, 4 }, { 25, 0x03, 4, 5 },
  663. X    { 25, 0x02, 4, 6 }, { 25, 0x03, 5, 7 }, { 25, 0x05, 6, 8 },
  664. X    { 25, 0x04, 6, 9 }, { 25, 0x04, 7, 10 }, { 25, 0x05, 7, 11 },
  665. X    { 25, 0x07, 7, 12 }, { 25, 0x04, 8, 13 }, { 25, 0x07, 8, 14 },
  666. X    { 25, 0x18, 9, 15 }, { 25, 0x17, 10, 16 }, { 25, 0x18, 10, 17 },
  667. X    { 25, 0x8, 10, 18 }, { 25, 0x67, 11, 19 }, { 25, 0x68, 11, 20 },
  668. X    { 25, 0x6c, 11, 21 }, { 25, 0x37, 11, 22 }, { 25, 0x28, 11, 23 },
  669. X    { 25, 0x17, 11, 24 }, { 25, 0x18, 11, 25 }, { 25, 0xca, 12, 26 },
  670. X    { 25, 0xcb, 12, 27 }, { 25, 0xcc, 12, 28 }, { 25, 0xcd, 12, 29 },
  671. X    { 25, 0x68, 12, 30 }, { 25, 0x69, 12, 31 }, { 25, 0x6a, 12, 32 },
  672. X    { 25, 0x6b, 12, 33 }, { 25, 0xd2, 12, 34 }, { 25, 0xd3, 12, 35 },
  673. X    { 25, 0xd4, 12, 36 }, { 25, 0xd5, 12, 37 }, { 25, 0xd6, 12, 38 },
  674. X    { 25, 0xd7, 12, 39 }, { 25, 0x6c, 12, 40 }, { 25, 0x6d, 12, 41 },
  675. X    { 25, 0xda, 12, 42 }, { 25, 0xdb, 12, 43 }, { 25, 0x54, 12, 44 },
  676. X    { 25, 0x55, 12, 45 }, { 25, 0x56, 12, 46 }, { 25, 0x57, 12, 47 },
  677. X    { 25, 0x64, 12, 48 }, { 25, 0x65, 12, 49 }, { 25, 0x52, 12, 50 },
  678. X    { 25, 0x53, 12, 51 }, { 25, 0x24, 12, 52 }, { 25, 0x37, 12, 53 },
  679. X    { 25, 0x38, 12, 54 }, { 25, 0x27, 12, 55 }, { 25, 0x28, 12, 56 },
  680. X    { 25, 0x58, 12, 57 }, { 25, 0x59, 12, 58 }, { 25, 0x2b, 12, 59 },
  681. X    { 25, 0x2c, 12, 60 }, { 25, 0x5a, 12, 61 }, { 25, 0x66, 12, 62 },
  682. X    { 25, 0x67, 12, 63 },
  683. X  };
  684. X
  685. X  static HuffmanTable TWTable[]=
  686. X  {
  687. X    { 23, 0x35, 8, 0 }, { 23, 0x07, 6, 1 }, { 23, 0x07, 4, 2 },
  688. X    { 23, 0x08, 4, 3 }, { 23, 0x0b, 4, 4 }, { 23, 0x0c, 4, 5 },
  689. X    { 23, 0x0e, 4, 6 }, { 23, 0x0f, 4, 7 }, { 23, 0x13, 5, 8 },
  690. X    { 23, 0x14, 5, 9 }, { 23, 0x07, 5, 10 }, { 23, 0x08, 5, 11 },
  691. X    { 23, 0x08, 6, 12 }, { 23, 0x03, 6, 13 }, { 23, 0x34, 6, 14 },
  692. X    { 23, 0x35, 6, 15 }, { 23, 0x2a, 6, 16 }, { 23, 0x2b, 6, 17 },
  693. X    { 23, 0x27, 7, 18 }, { 23, 0x0c, 7, 19 }, { 23, 0x08, 7, 20 },
  694. X    { 23, 0x17, 7, 21 }, { 23, 0x03, 7, 22 }, { 23, 0x04, 7, 23 },
  695. X    { 23, 0x28, 7, 24 }, { 23, 0x2b, 7, 25 }, { 23, 0x13, 7, 26 },
  696. X    { 23, 0x24, 7, 27 }, { 23, 0x18, 7, 28 }, { 23, 0x02, 8, 29 },
  697. X    { 23, 0x03, 8, 30 }, { 23, 0x1a, 8, 31 }, { 23, 0x1b, 8, 32 },
  698. X    { 23, 0x12, 8, 33 }, { 23, 0x13, 8, 34 }, { 23, 0x14, 8, 35 },
  699. X    { 23, 0x15, 8, 36 }, { 23, 0x16, 8, 37 }, { 23, 0x17, 8, 38 },
  700. X    { 23, 0x28, 8, 39 }, { 23, 0x29, 8, 40 }, { 23, 0x2a, 8, 41 },
  701. X    { 23, 0x2b, 8, 42 }, { 23, 0x2c, 8, 43 }, { 23, 0x2d, 8, 44 },
  702. X    { 23, 0x04, 8, 45 }, { 23, 0x05, 8, 46 }, { 23, 0x0a, 8, 47 },
  703. X    { 23, 0x0b, 8, 48 }, { 23, 0x52, 8, 49 }, { 23, 0x53, 8, 50 },
  704. X    { 23, 0x54, 8, 51 }, { 23, 0x55, 8, 52 }, { 23, 0x24, 8, 53 },
  705. X    { 23, 0x25, 8, 54 }, { 23, 0x58, 8, 55 }, { 23, 0x59, 8, 56 },
  706. X    { 23, 0x5a, 8, 57 }, { 23, 0x5b, 8, 58 }, { 23, 0x4a, 8, 59 },
  707. X    { 23, 0x4b, 8, 60 }, { 23, 0x32, 8, 61 }, { 23, 0x33, 8, 62 },
  708. X    { 23, 0x34, 8, 63 },
  709. X  };
  710. X
  711. X  HuffmanTable*
  712. X    entry;
  713. X
  714. X  int
  715. X    c,
  716. X    k,
  717. X    n,
  718. X    x;
  719. X
  720. X  register int
  721. X    i,
  722. X    j;
  723. X
  724. X  register RunlengthPacket
  725. X    *p;
  726. X
  727. X  register unsigned char
  728. X    *q;
  729. X
  730. X  register unsigned short
  731. X    polarity;
  732. X
  733. X  unsigned int
  734. X    mask;
  735. X
  736. X  unsigned char
  737. X    bit,
  738. X    byte,
  739. X    *scanline;
  740. X
  741. X  /*
  742. X    Allocate scanline buffer.
  743. X  */
  744. X  scanline=(unsigned char *)
  745. X    malloc(Max(image->columns,1728)*sizeof(unsigned char));
  746. X  if (scanline == (unsigned char *) NULL)
  747. X    {
  748. X      Warning("unable to allocate memory",(char *) NULL);
  749. X      return(False);
  750. X    }
  751. X  /*
  752. X    Compress MIFF to 1D Huffman encoded pixels.
  753. X  */
  754. X  q=scanline;
  755. X  polarity=(Intensity(image->colormap[0]) >
  756. X    Intensity(image->colormap[1]) ? 0 : 1);
  757. X  for (i=0; i < Max(image->columns,1728); i++)
  758. X    *q++=polarity;
  759. X  byte=0;
  760. X  bit=0x80;
  761. X  p=image->pixels;
  762. X  q=scanline;
  763. X  x=0;
  764. X  for (i=0; i < image->packets; i++)
  765. X  {
  766. X    for (j=0; j <= ((int) p->length); j++)
  767. X    {
  768. X      if (p->index == polarity)
  769. X        *q++=(unsigned char) polarity;
  770. X       else
  771. X        *q++=(unsigned char) !polarity;
  772. X      x++;
  773. X      if (x == image->columns)
  774. X        {
  775. X          /*
  776. X            Huffman encode scanline.
  777. X          */
  778. X          q=scanline;
  779. X          n=Max(image->columns,1728);
  780. X          while (n > 0)
  781. X          {
  782. X            /*
  783. X              Find white run.
  784. X            */
  785. X            c=0;
  786. X            while((*q == polarity) && (n > 0))
  787. X            {
  788. X              q++;
  789. X              c++;
  790. X              n--;
  791. X            }
  792. X            /*
  793. X              Output white run.
  794. X            */
  795. X            if (c >= 64)
  796. X              {
  797. X                entry=MWTable+((c/64)-1);
  798. X                c-=entry->count;
  799. X                HuffmanOutputCode(entry);
  800. X              }
  801. X            entry=TWTable+c;
  802. X            HuffmanOutputCode(entry);
  803. X            c=0;
  804. X            if (n == 0)
  805. X              break;
  806. X            /*
  807. X              Find black run.
  808. X            */
  809. X            while ((*q != polarity) && (n > 0))
  810. X            {
  811. X              q++;
  812. X              c++;
  813. X              n--;
  814. X            }
  815. X            /*
  816. X              Output black run.
  817. X            */
  818. X            if (c >= 64)
  819. X              {
  820. X                entry=MBTable+((c/64)-1);
  821. X                c-=entry->count;
  822. X                HuffmanOutputCode(entry);
  823. X              }
  824. X            entry=TBTable+c;
  825. X            HuffmanOutputCode(entry);
  826. X            if (n == 0)
  827. X              break;
  828. X          }
  829. X          /*
  830. X            End of line.
  831. X          */
  832. X          for (k=0; k < 11; k++)
  833. X            OutputBit(0);
  834. X          OutputBit(1);
  835. X          x=0;
  836. X          q=scanline;
  837. X        }
  838. X    }
  839. X    p++;
  840. X  }
  841. X  /*
  842. X    End of page.
  843. X  */
  844. X  for (i=0; i < 6; i++)
  845. X  {
  846. X    /*
  847. X      End of line.
  848. X    */
  849. X    for (k=0; k < 11; k++)
  850. X      OutputBit(0);
  851. X    OutputBit(1);
  852. X  }
  853. X  /*
  854. X    Flush bits.
  855. X  */
  856. X  if (bit != 0x80)
  857. X    (void) fwrite((char *) &byte,1,1,image->file);
  858. X  (void) free((char *) scanline);
  859. X  return(True);
  860. }
  861. X
  862. /*
  863. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  864. %                                                                             %
  865. %                                                                             %
  866. %                                                                             %
  867. %   L Z W D e c o d e I m a g e                                               %
  868. %                                                                             %
  869. %                                                                             %
  870. %                                                                             %
  871. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  872. %
  873. %  Function LZWDecodeImage uncompresses an image via LZW-coding.
  874. %
  875. %  The format of the LZWDecodeImage routine is:
  876. %
  877. %      status=LZWDecodeImage(image)
  878. %
  879. %  A description of each parameter follows:
  880. %
  881. %    o status:  Function LZWDecodeImage returns True if all the pixels are
  882. %      uncompressed without error, otherwise False.
  883. %
  884. %    o image: The address of a structure of type Image.
  885. %
  886. %
  887. */
  888. unsigned int LZWDecodeImage(image)
  889. Image
  890. X  *image;
  891. {
  892. #define MaxStackSize  4096
  893. #define NullCode  (-1)
  894. X
  895. X  int
  896. X    available,
  897. X    clear,
  898. X    code_mask,
  899. X    code_size,
  900. X    end_of_information,
  901. X    in_code,
  902. X    old_code;
  903. X
  904. X  register int
  905. X    bits,
  906. X    code,
  907. X    count,
  908. X    i;
  909. X
  910. X  register RunlengthPacket
  911. X    *p;
  912. X
  913. X  register unsigned char
  914. X    *c;
  915. X
  916. X  register unsigned int
  917. X    datum;
  918. X
  919. X  short int
  920. X    *prefix;
  921. X
  922. X  unsigned char
  923. X    data_size,
  924. X    first,
  925. X    *packet,
  926. X    *pixel_stack,
  927. X    *suffix,
  928. X    *top_stack;
  929. X
  930. X  unsigned short
  931. X    index;
  932. X
  933. X  /*
  934. X    Allocate decoder tables.
  935. X  */
  936. X  packet=(unsigned char *) malloc(256*sizeof(unsigned char));
  937. X  prefix=(short int *) malloc(MaxStackSize*sizeof(short int));
  938. X  suffix=(unsigned char *) malloc(MaxStackSize*sizeof(unsigned char));
  939. X  pixel_stack=(unsigned char *) malloc(MaxStackSize*sizeof(unsigned char));
  940. X  if ((packet == (unsigned char *) NULL) ||
  941. X      (prefix == (short int *) NULL) ||
  942. X      (suffix == (unsigned char *) NULL) ||
  943. X      (pixel_stack == (unsigned char *) NULL))
  944. X    return(False);
  945. X  /*
  946. X    Initialize LZW data stream decoder.
  947. X  */
  948. X  (void) ReadData((char *) &data_size,1,1,image->file);
  949. X  clear=1 << data_size;
  950. X  end_of_information=clear+1;
  951. X  available=clear+2;
  952. X  old_code=NullCode;
  953. X  code_size=data_size+1;
  954. X  code_mask=(1 << code_size)-1;
  955. X  for (code=0; code < clear; code++)
  956. X  {
  957. X    prefix[code]=0;
  958. X    suffix[code]=code;
  959. X  }
  960. X  /*
  961. X    Decode LZW pixel stream.
  962. X  */
  963. X  datum=0;
  964. X  bits=0;
  965. X  count=0;
  966. X  top_stack=pixel_stack;
  967. X  p=image->pixels;
  968. X  for (i=0; i < image->packets; )
  969. X  {
  970. X    if (top_stack == pixel_stack)
  971. X      {
  972. X        if (bits < code_size)
  973. X          {
  974. X            /*
  975. X              Load bytes until there is enough bits for a code.
  976. X            */
  977. X            if (count == 0)
  978. X              {
  979. X                /*
  980. X                  Read a new data block.
  981. X                */
  982. X                count=ReadDataBlock((char *) packet,image->file);
  983. X                if (count <= 0)
  984. X                  break;
  985. X                c=packet;
  986. X              }
  987. X            datum+=(*c) << bits;
  988. X            bits+=8;
  989. X            c++;
  990. X            count--;
  991. X            continue;
  992. X          }
  993. X        /*
  994. X          Get the next code.
  995. X        */
  996. X        code=datum & code_mask;
  997. X        datum>>=code_size;
  998. X        bits-=code_size;
  999. X        /*
  1000. X          Interpret the code
  1001. X        */
  1002. X        if ((code > available) || (code == end_of_information))
  1003. X          break;
  1004. X        if (code == clear)
  1005. X          {
  1006. X            /*
  1007. X              Reset decoder.
  1008. X            */
  1009. X            code_size=data_size+1;
  1010. X            code_mask=(1 << code_size)-1;
  1011. X            available=clear+2;
  1012. X            old_code=NullCode;
  1013. X            continue;
  1014. X          }
  1015. X        if (old_code == NullCode)
  1016. X          {
  1017. X            *top_stack++=suffix[code];
  1018. X            old_code=code;
  1019. X            first=code;
  1020. X            continue;
  1021. X          }
  1022. X        in_code=code;
  1023. X        if (code == available)
  1024. X          {
  1025. X            *top_stack++=first;
  1026. X            code=old_code;
  1027. X          }
  1028. X        while (code > clear)
  1029. X        {
  1030. X          *top_stack++=suffix[code];
  1031. X          code=prefix[code];
  1032. X        }
  1033. X        first=suffix[code];
  1034. X        /*
  1035. X          Add a new string to the string table,
  1036. X        */
  1037. X        *top_stack++=first;
  1038. X        prefix[available]=old_code;
  1039. X        suffix[available]=first;
  1040. X        available++;
  1041. X        if (((available & code_mask) == 0) && (available < MaxStackSize))
  1042. X          {
  1043. X            code_size++;
  1044. X            code_mask+=available;
  1045. X          }
  1046. X        old_code=in_code;
  1047. X      }
  1048. X    /*
  1049. X      Pop a pixel off the pixel pixel_stack.
  1050. X    */
  1051. X    top_stack--;
  1052. X    index=(unsigned short) *top_stack;
  1053. X    p->red=image->colormap[index].red;
  1054. X    p->green=image->colormap[index].green;
  1055. X    p->blue=image->colormap[index].blue;
  1056. X    p->index=index;
  1057. X    p->length=0;
  1058. X    p++;
  1059. X    i++;
  1060. X  }
  1061. X  /*
  1062. X    Initialize any remaining color packets to a known color.
  1063. X  */
  1064. X  for ( ; i < image->packets; i++)
  1065. X  {
  1066. X    p->red=image->colormap[0].red;
  1067. X    p->green=image->colormap[0].green;
  1068. X    p->blue=image->colormap[0].blue;
  1069. X    p->index=0;
  1070. X    p->length=0;
  1071. X    p++;
  1072. X  }
  1073. X  /*
  1074. X    Free decoder memory.
  1075. X  */
  1076. X  (void) free((char *) pixel_stack);
  1077. X  (void) free((char *) suffix);
  1078. X  (void) free((char *) prefix);
  1079. X  (void) free((char *) packet);
  1080. X  return(True);
  1081. }
  1082. X
  1083. /*
  1084. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1085. %                                                                             %
  1086. %                                                                             %
  1087. %                                                                             %
  1088. %   L Z W E n c o d e I m a g e                                               %
  1089. %                                                                             %
  1090. %                                                                             %
  1091. %                                                                             %
  1092. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1093. %
  1094. %  Function LZWEncodeImage compresses an image via LZW-coding.
  1095. %
  1096. %  The format of the LZWEncodeImage routine is:
  1097. %
  1098. %      status=LZWEncodeImage(image,data_size)
  1099. %
  1100. %  A description of each parameter follows:
  1101. %
  1102. %    o status:  Function LZWEncodeImage returns True if all the pixels are
  1103. %      compressed without error, otherwise False.
  1104. %
  1105. %    o image: The address of a structure of type Image.
  1106. %
  1107. %
  1108. */
  1109. unsigned int LZWEncodeImage(image,data_size)
  1110. Image
  1111. X  *image;
  1112. X
  1113. unsigned int
  1114. X  data_size;
  1115. {
  1116. #define MaxCode(number_bits)  (((short int) (1 << (number_bits)))-1)
  1117. #define MaxHashTable  5003
  1118. #define MaxLZWBits  12
  1119. #define MaxLZWTable  ((short int) 1 << MaxLZWBits)
  1120. #define LZWOutputCode(code) \
  1121. { \
  1122. X  /*  \
  1123. X    Emit a code. \
  1124. X  */ \
  1125. X  if (bits > 0) \
  1126. X    datum|=((long int) code << bits); \
  1127. X  else \
  1128. X    datum=code; \
  1129. X  bits+=number_bits; \
  1130. X  while (bits >= 8)  \
  1131. X  { \
  1132. X    /*  \
  1133. X      Add a character to current packet. \
  1134. X    */ \
  1135. X    byte_count++; \
  1136. X    packet[byte_count]=(unsigned char) (datum & 0xff); \
  1137. X    if (byte_count >= 255) \
  1138. X      { \
  1139. X        packet[0]=(unsigned char) byte_count++; \
  1140. X        (void) fwrite((char *) packet,1,byte_count,image->file); \
  1141. X        byte_count=0; \
  1142. X      } \
  1143. X    datum>>=8; \
  1144. X    bits-=8; \
  1145. X  } \
  1146. X  if (free_code > max_code)  \
  1147. X    { \
  1148. X      number_bits++; \
  1149. X      if (number_bits == MaxLZWBits) \
  1150. X        max_code=MaxLZWTable; \
  1151. X      else \
  1152. X        max_code=MaxCode(number_bits); \
  1153. X    } \
  1154. }
  1155. X
  1156. X  int
  1157. X    bits,
  1158. X    byte_count,
  1159. X    next_pixel,
  1160. X    number_bits;
  1161. X
  1162. X  long int
  1163. X    datum;
  1164. X
  1165. X  register int
  1166. X    displacement,
  1167. X    i,
  1168. X    j,
  1169. X    k;
  1170. X
  1171. X  register RunlengthPacket
  1172. X    *p;
  1173. X
  1174. X  short int
  1175. X    clear_code,
  1176. X    end_of_information_code,
  1177. X    free_code,
  1178. X    *hash_code,
  1179. X    *hash_prefix,
  1180. X    max_code,
  1181. X    waiting_code;
  1182. X
  1183. X  unsigned char
  1184. X    *packet,
  1185. X    *hash_suffix;
  1186. X
  1187. X  /*
  1188. X    Allocate encoder tables.
  1189. X  */
  1190. X  packet=(unsigned char *) malloc(256*sizeof(unsigned char));
  1191. X  hash_code=(short int *) malloc(MaxHashTable*sizeof(short int));
  1192. X  hash_prefix=(short int *) malloc(MaxHashTable*sizeof(short int));
  1193. X  hash_suffix=(unsigned char *) malloc(MaxHashTable*sizeof(unsigned char));
  1194. X  if ((packet == (unsigned char *) NULL) || (hash_code == (short int *) NULL) ||
  1195. X      (hash_prefix == (short int *) NULL) ||
  1196. X      (hash_suffix == (unsigned char *) NULL))
  1197. X    return(False);
  1198. X  /*
  1199. X    Initialize LZW encoder.
  1200. X  */
  1201. X  number_bits=data_size;
  1202. X  max_code=MaxCode(number_bits);
  1203. X  clear_code=((short int) 1 << (data_size-1));
  1204. X  end_of_information_code=clear_code+1;
  1205. X  free_code=clear_code+2;
  1206. X  byte_count=0;
  1207. X  datum=0;
  1208. X  bits=0;
  1209. X  for (i=0; i < MaxHashTable; i++)
  1210. X    hash_code[i]=0;
  1211. X  LZWOutputCode(clear_code);
  1212. X  /*
  1213. X    Encode pixels.
  1214. X  */
  1215. X  p=image->pixels;
  1216. X  waiting_code=(short int) (p->index & 0xff);
  1217. X  for (i=0; i < image->packets; i++)
  1218. X  {
  1219. X    for (j=0; j <= ((int) p->length); j++)
  1220. X    {
  1221. X      /*
  1222. X        Probe hash table.
  1223. X      */
  1224. X      k=((int) (p->index) << (MaxLZWBits-8))+waiting_code;
  1225. X      if (k >= MaxHashTable)
  1226. X        k-=MaxHashTable;
  1227. X      if (hash_code[k] != 0)
  1228. X        {
  1229. X          if ((hash_prefix[k] == waiting_code) &&
  1230. X              (hash_suffix[k] == (unsigned char) (p->index & 0xff)))
  1231. X            {
  1232. X              waiting_code=hash_code[k];
  1233. X              continue;
  1234. X            }
  1235. X          if (k == 0)
  1236. X            displacement=1;
  1237. X          else
  1238. X            displacement=MaxHashTable-k;
  1239. X          next_pixel=False;
  1240. X          while (1)
  1241. X          {
  1242. X            k-=displacement;
  1243. X            if (k < 0)
  1244. X              k+=MaxHashTable;
  1245. X            if (hash_code[k] == 0)
  1246. X              break;
  1247. X            if ((hash_prefix[k] == waiting_code) &&
  1248. X                (hash_suffix[k] == (unsigned char) (p->index & 0xff)))
  1249. X              {
  1250. X                waiting_code=hash_code[k];
  1251. X                next_pixel=True;
  1252. X                break;
  1253. X              }
  1254. X          }
  1255. X          if (next_pixel == True)
  1256. X            continue;
  1257. X        }
  1258. X      LZWOutputCode(waiting_code);
  1259. X      if (free_code < MaxLZWTable)
  1260. X        {
  1261. X          hash_code[k]=free_code++;
  1262. X          hash_prefix[k]=waiting_code;
  1263. X          hash_suffix[k]=(unsigned char) (p->index & 0xff);
  1264. X        }
  1265. X      else
  1266. X        {
  1267. X          /*
  1268. X            Fill the hash table with empty entries.
  1269. X          */
  1270. X          for (k=0; k < MaxHashTable; k++)
  1271. X            hash_code[k]=0;
  1272. X          /*
  1273. X            Reset compressor and issue a clear code.
  1274. X          */
  1275. X          free_code=clear_code+2;
  1276. X          LZWOutputCode(clear_code);
  1277. X          number_bits=data_size;
  1278. X          max_code=MaxCode(number_bits);
  1279. X        }
  1280. X      waiting_code=(short int) (p->index & 0xff);
  1281. X    }
  1282. X    p++;
  1283. X  }
  1284. X  /*
  1285. X    Flush out the buffered code.
  1286. X  */
  1287. X  LZWOutputCode(waiting_code);
  1288. X  LZWOutputCode(end_of_information_code);
  1289. X  if (bits > 0)
  1290. X    {
  1291. X      /*
  1292. X        Add a character to current packet.
  1293. X      */
  1294. X      byte_count++;
  1295. X      packet[byte_count]=(unsigned char) (datum & 0xff);
  1296. X      if (byte_count >= 255)
  1297. X        {
  1298. X          packet[0]=(unsigned char) byte_count++;
  1299. X          (void) fwrite((char *) packet,1,byte_count,image->file);
  1300. X          byte_count=0;
  1301. X        }
  1302. X    }
  1303. X  /*
  1304. X    Flush accumulated data.
  1305. X  */
  1306. X  if (byte_count > 0)
  1307. X    {
  1308. X      packet[0]=(unsigned char) byte_count++;
  1309. X      (void) fwrite((char *) packet,1,byte_count,image->file);
  1310. X      byte_count=0;
  1311. X    }
  1312. X  /*
  1313. X    Free encoder memory.
  1314. X  */
  1315. X  (void) free((char *) hash_suffix);
  1316. X  (void) free((char *) hash_prefix);
  1317. X  (void) free((char *) hash_code);
  1318. X  (void) free((char *) packet);
  1319. X  if (i < image->packets)
  1320. X    return(False);
  1321. X  return(True);
  1322. }
  1323. X
  1324. /*
  1325. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1326. %                                                                             %
  1327. %                                                                             %
  1328. %                                                                             %
  1329. %   Q D e c o d e I m a g e                                                   %
  1330. %                                                                             %
  1331. %                                                                             %
  1332. %                                                                             %
  1333. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1334. %
  1335. %  Function QDecodeImage uncompresses an image via Q-coding.
  1336. %
  1337. %  The format of the QDecodeImage routine is:
  1338. %
  1339. %      count=QDecodeImage(compressed_pixels,pixels,number_columns,number_rows)
  1340. %
  1341. %  A description of each parameter follows:
  1342. %
  1343. %    o count:  The QDecodeImage routine returns this integer value.  It is
  1344. %      the actual number of pixels created by the decompression process.
  1345. %
  1346. %    o compressed_pixels:  The address of a byte (8 bits) array of compressed
  1347. %      pixel data.
  1348. %
  1349. %    o pixels:  The address of a byte (8 bits) array of pixel data created by
  1350. %      the uncompression process.  The number of bytes in this array
  1351. %      must be at least equal to the number columns times the number of rows
  1352. %      of the source pixels.
  1353. %
  1354. %    o number_columns:  An integer value that is the number of columns or
  1355. %      width in pixels of your source image.
  1356. %
  1357. %    o number_rows:  An integer value that is the number of rows or
  1358. %      heigth in pixels of your source image.
  1359. %
  1360. %
  1361. */
  1362. unsigned int QDecodeImage(compressed_pixels,pixels,number_columns,number_rows)
  1363. unsigned char
  1364. X  *compressed_pixels,
  1365. X  *pixels;
  1366. X
  1367. unsigned int
  1368. X  number_columns,
  1369. X  number_rows;
  1370. {
  1371. X  int
  1372. X    decision,
  1373. X    i,
  1374. X    prediction,
  1375. X    row;
  1376. X
  1377. X  register int
  1378. X    column,
  1379. X    magnitude,
  1380. X    sign,
  1381. X    state,
  1382. X    value;
  1383. X
  1384. X  register ScanlinePacket
  1385. X    *cs,
  1386. X    *ls;
  1387. X
  1388. X  register unsigned char
  1389. X    *p;
  1390. X
  1391. X  ScanlinePacket
  1392. X    *scanline;
  1393. X
  1394. X  for (i=0; i < MaxContextStates; i++)
  1395. X  {
  1396. X    probability_estimate[i]=0;
  1397. X    more_probable[i]=0;
  1398. X    less_probable[i]=1;
  1399. X  }
  1400. X  /*
  1401. X    Allocate scanline for row values and states
  1402. X  */
  1403. X  scanline=(ScanlinePacket *)
  1404. X    malloc((2*(number_columns+1)*sizeof(ScanlinePacket)));
  1405. X  if (scanline == (ScanlinePacket *) NULL)
  1406. X    {
  1407. X      Warning("unable to compress image, unable to allocate memory",
  1408. X        (char *) NULL);
  1409. X      exit(1);
  1410. X    }
  1411. X  cs=scanline;
  1412. X  for (i=0; i < 2*(number_columns+1); i++)
  1413. X  {
  1414. X    cs->pixel=0;
  1415. X    cs->state=ZeroState;
  1416. X    cs++;
  1417. X  }
  1418. X  interval=MinimumIntervalD;
  1419. X  p=pixels;
  1420. X  q=compressed_pixels+1;
  1421. X  /*
  1422. X    Add a new unsigned char of compressed data to the Code register.
  1423. X  */
  1424. X  code=(int) (*q) << 16;
  1425. X  if ((*q++) == 0xff)
  1426. X    code+=((int) (*q) << 9)+0x02;
  1427. X  else
  1428. X    code+=((*q) << 8)+0x01;
  1429. X  code<<=4;
  1430. X  code+=(interval << 16);
  1431. X  /*
  1432. X    Decode each image scanline.
  1433. X  */
  1434. X  for (row=0; row < number_rows; row++)
  1435. X  {
  1436. X    ls=scanline+(number_columns+1)*((row+0) % 2);
  1437. X    cs=scanline+(number_columns+1)*((row+1) % 2);
  1438. X    for (column=0; column < number_columns; column++)
  1439. X    {
  1440. X      prediction=(int) cs->pixel-(int) ls->pixel;
  1441. X      ls++;
  1442. X      prediction+=(int) ls->pixel;
  1443. X      state=statistics[cs->state][ls->state];
  1444. X      cs++;
  1445. X      cs->state=ZeroState;
  1446. X      /*
  1447. X        Branch for zero code value
  1448. X      */
  1449. X      Decode(state,&decision);
  1450. X      if (decision == No)
  1451. X        value=0;
  1452. X      else
  1453. X        {
  1454. X          /*
  1455. X            Decode sign information
  1456. X          */
  1457. X          state++;
  1458. X          Decode(state,&decision);
  1459. X          if (decision == Yes)
  1460. X            sign=(-1);
  1461. X          else
  1462. X            {
  1463. X              sign=1;
  1464. X              state++;
  1465. X            }
  1466. X          state++;
  1467. X          /*
  1468. X            Branch for value=+-1
  1469. X          */
  1470. X          Decode(state,&decision);
  1471. X          if (decision == No)
  1472. X            value=1;
  1473. X          else
  1474. X            {
  1475. X              /*
  1476. X                Establish magnitude of value.
  1477. X              */
  1478. X              magnitude=2;
  1479. X              state=100;
  1480. X              Decode(state,&decision);
  1481. X              while (decision != No)
  1482. X              {
  1483. X                if (state < 107)
  1484. X                  state++;
  1485. X                magnitude<<=1;
  1486. X                Decode(state,&decision);
  1487. X              }
  1488. X              /*
  1489. X                Code remaining bits.
  1490. X              */
  1491. X              state+=7;
  1492. X              value=1;
  1493. X              magnitude>>=2;
  1494. X              if (magnitude != 0)
  1495. X                {
  1496. X                  Decode(state,&decision);
  1497. X                  state+=6;
  1498. X                  value=(value << 1) | decision;
  1499. X                  magnitude>>=1;
  1500. X                  while (magnitude != 0)
  1501. X                  {
  1502. X                    Decode(state,&decision);
  1503. X                    value=(value << 1) | decision;
  1504. X                    magnitude>>=1;
  1505. X                  }
  1506. X                }
  1507. X              value++;
  1508. X            }
  1509. X          if (value > LowerBound)
  1510. X            if (value <= UpperBound)
  1511. X              cs->state=
  1512. X                (sign < ZeroState ? SmallPostitiveState : SmallNegativeState);
  1513. X            else
  1514. X              cs->state=
  1515. X                (sign < ZeroState ? LargePostitiveState : LargeNegativeState);
  1516. X          if (sign < 0)
  1517. X            value=(-value);
  1518. X        }
  1519. X      cs->pixel=(unsigned char) (value+prediction);
  1520. X      *p++=cs->pixel;
  1521. X    }
  1522. X  }
  1523. X  (void) free((char *) scanline);
  1524. X  return((unsigned int) (p-pixels));
  1525. }
  1526. X
  1527. /*
  1528. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1529. %                                                                             %
  1530. %                                                                             %
  1531. %                                                                             %
  1532. %   Q E n c o d e I m a g e                                                   %
  1533. %                                                                             %
  1534. %                                                                             %
  1535. %                                                                             %
  1536. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1537. %
  1538. %  Function QEncodeImage compresses an image via q-coding.
  1539. %
  1540. %  The format of the QEncodeImage routine is:
  1541. %
  1542. %      count=QEncodeImage(pixels,compressed_pixels,number_columns,
  1543. %        number_rows)
  1544. %
  1545. %  A description of each parameter follows:
  1546. %
  1547. %    o count:  The QEncodeImage routine returns this integer value.  It is
  1548. %      the actual number of compressed pixels created by the compression
  1549. %      process.
  1550. %
  1551. %    o pixels:  The address of a byte (8 bits) array of pixel data.
  1552. %
  1553. %    o compressed_pixels:  The address of a byte (8 bits) array of pixel data
  1554. %      created by the compression process.  The number of bytes in this array
  1555. %      must be at least equal to the number columns times the number of rows
  1556. %      of the source pixels to allow for the possibility that no compression
  1557. %      is possible.  The actual number of bytes used is reflected by the
  1558. %      count parameter.
  1559. %
  1560. %    o number_columns:  An integer value that is the number of columns or
  1561. %      width in pixels of your source image.
  1562. %
  1563. %    o number_rows:  An integer value that is the number of rows or
  1564. %      heigth in pixels of your source image.
  1565. %
  1566. %
  1567. %
  1568. */
  1569. unsigned int QEncodeImage(pixels,compressed_pixels,number_columns,number_rows)
  1570. unsigned char
  1571. X  *pixels,
  1572. X  *compressed_pixels;
  1573. X
  1574. unsigned int
  1575. X  number_columns,
  1576. X  number_rows;
  1577. {
  1578. X  int
  1579. X    i,
  1580. X    prediction,
  1581. X    row;
  1582. X
  1583. X  register int
  1584. X    column,
  1585. X    magnitude,
  1586. X    sign,
  1587. X    state,
  1588. X    value;
  1589. X
  1590. X  register ScanlinePacket
  1591. X    *cs,
  1592. X    *ls;
  1593. X
  1594. X  register unsigned char
  1595. X    *p;
  1596. X
  1597. X  ScanlinePacket
  1598. X    *scanline;
  1599. X
  1600. X  void
  1601. X    Flush();
  1602. X
  1603. X  for (i=0; i < MaxContextStates; i++)
  1604. X  {
  1605. X    probability_estimate[i]=0;
  1606. X    more_probable[i]=0;
  1607. X  }
  1608. X  /*
  1609. X    Allocate scanline for row values and states.
  1610. X  */
  1611. X  scanline=(ScanlinePacket *)
  1612. X    malloc((2*(number_columns+1)*sizeof(ScanlinePacket)));
  1613. X  if (scanline == (ScanlinePacket *) NULL)
  1614. X    {
  1615. X      Warning("unable to compress image, unable to allocate memory",
  1616. X        (char *) NULL);
  1617. X      exit(1);
  1618. X    }
  1619. X  cs=scanline;
  1620. X  for (i=0; i < 2*(number_columns+1); i++)
  1621. X  {
  1622. X    cs->pixel=0;
  1623. X    cs->state=ZeroState;
  1624. X    cs++;
  1625. X  }
  1626. X  interval=MinimumIntervalE;
  1627. X  p=pixels;
  1628. X  q=compressed_pixels;
  1629. X  (*q)++;
  1630. X  code=0x00180000;
  1631. X  /*
  1632. X    Encode each scanline.
  1633. X  */
  1634. X  for (row=0; row < number_rows; row++)
  1635. X  {
  1636. X    ls=scanline+(number_columns+1)*((row+0) % 2);
  1637. X    cs=scanline+(number_columns+1)*((row+1) % 2);
  1638. X    for (column=0; column < number_columns; column++)
  1639. X    {
  1640. X      prediction=(int) cs->pixel-(int) ls->pixel;
  1641. X      ls++;
  1642. X      prediction+=(int) ls->pixel;
  1643. X      state=statistics[cs->state][ls->state];
  1644. X      cs++;
  1645. X      cs->pixel=(*p++);
  1646. X      cs->state=ZeroState;
  1647. X      value=(int) cs->pixel-prediction;
  1648. X      Encode(state,(value == 0 ? No : Yes));
  1649. X      if (value != 0)
  1650. X        {
  1651. X          /*
  1652. X            Code sign information
  1653. X          */
  1654. X          state++;
  1655. X          sign=(value < 0 ? -1 : 1);
  1656. X          Encode(state,(sign >= 0 ? No : Yes));
  1657. X          if (sign < 0)
  1658. X            value=(-value);
  1659. X          else
  1660. X            state++;
  1661. X          state++;
  1662. X          value--;
  1663. X          /*
  1664. X            Branch for code=+-1
  1665. X          */
  1666. X          Encode(state,(value == 0 ? No : Yes));
  1667. X          if (value != 0)
  1668. X            {
  1669. X              /*
  1670. X                Establish magnitude of value.
  1671. X              */
  1672. X              state=100;
  1673. X              magnitude=2;
  1674. X              while (value >= magnitude)
  1675. X              {
  1676. X                Encode(state,Yes);
  1677. X                if (state < 107)
  1678. X                  state++;
  1679. X                magnitude<<=1;
  1680. X              }
  1681. X              Encode(state,No);
  1682. X              /*
  1683. X                Code remaining bits
  1684. X              */
  1685. X              state+=7;
  1686. X              magnitude>>=2;
  1687. X              if (magnitude != 0)
  1688. X                {
  1689. X                  Encode(state,((magnitude & value) == 0 ? No : Yes));
  1690. X                  state+=6;
  1691. X                  magnitude>>=1;
  1692. X                  while (magnitude != 0)
  1693. X                  {
  1694. X                    Encode(state,((magnitude & value) == 0 ? No : Yes));
  1695. X                    magnitude>>=1;
  1696. X                  }
  1697. X                }
  1698. X            }
  1699. X          if (value >= LowerBound)
  1700. X            if (value < UpperBound)
  1701. X              cs->state=
  1702. X                (sign < ZeroState ? SmallPostitiveState : SmallNegativeState);
  1703. X            else
  1704. X              cs->state=
  1705. X                (sign < ZeroState ? LargePostitiveState : LargeNegativeState);
  1706. X        }
  1707. X    }
  1708. X  }
  1709. X  Flush();
  1710. X  (void) free((char *) scanline);
  1711. X  return((unsigned int) (q-compressed_pixels));
  1712. }
  1713. SHAR_EOF
  1714. chmod 0644 ImageMagick/compress.c ||
  1715. echo 'restore of ImageMagick/compress.c failed'
  1716. Wc_c="`wc -c < 'ImageMagick/compress.c'`"
  1717. test 44946 -eq "$Wc_c" ||
  1718.     echo 'ImageMagick/compress.c: original size 44946, current size' "$Wc_c"
  1719. rm -f _shar_wnt_.tmp
  1720. fi
  1721. # ============= ImageMagick/image.h ==============
  1722. if test -f 'ImageMagick/image.h' -a X"$1" != X"-c"; then
  1723.     echo 'x - skipping ImageMagick/image.h (File already exists)'
  1724.     rm -f _shar_wnt_.tmp
  1725. else
  1726. > _shar_wnt_.tmp
  1727. echo 'x - extracting ImageMagick/image.h (Text)'
  1728. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/image.h' &&
  1729. /*
  1730. X  Image define declarations.
  1731. */
  1732. #define AbsoluteValue(x)  ((x) < 0 ? -(x) : (x))
  1733. #define Intensity(color)  (unsigned int)  \
  1734. X  ((unsigned int) ((color).red*77+(color).green*150+(color).blue*29) >> 8)
  1735. #define MaxColormapSize  65535
  1736. #define MaxImageSize  (4096*4096)
  1737. #define MaxRGB  255
  1738. #define MaxRunlength  255
  1739. X
  1740. /*
  1741. X  Image Id's
  1742. */
  1743. #define UndefinedId  0
  1744. #define ImageMagickId  1
  1745. /*
  1746. X  Image classes:
  1747. */
  1748. #define UndefinedClass  0
  1749. #define DirectClass  1
  1750. #define PseudoClass  2
  1751. /*
  1752. X  Image colorspaces:
  1753. */
  1754. #define UndefinedColorspace  0
  1755. #define RGBColorspace  1
  1756. #define GRAYColorspace 2
  1757. #define XYZColorspace  3
  1758. #define YIQColorspace  4
  1759. #define YUVColorspace  5
  1760. /*
  1761. X  Image compression algorithms:
  1762. */
  1763. #define UndefinedCompression  0
  1764. #define NoCompression  1
  1765. #define RunlengthEncodedCompression  2
  1766. #define QEncodedCompression  3
  1767. /*
  1768. X  Image compositing operations:
  1769. */
  1770. #define UndefinedCompositeOp  0
  1771. #define OverCompositeOp  1
  1772. #define InCompositeOp  2
  1773. #define OutCompositeOp  3
  1774. #define AtopCompositeOp  4
  1775. #define XorCompositeOp  5
  1776. #define PlusCompositeOp  6
  1777. #define MinusCompositeOp  7
  1778. #define AddCompositeOp  8
  1779. #define SubtractCompositeOp  9
  1780. #define DifferenceCompositeOp  10
  1781. #define ReplaceCompositeOp  11
  1782. X
  1783. /*
  1784. X  Typedef declarations for the Display program.
  1785. */
  1786. typedef struct _ColorPacket
  1787. {
  1788. X  unsigned char
  1789. X    red,
  1790. X    green,
  1791. X    blue,
  1792. X    flags;
  1793. X
  1794. X  unsigned short
  1795. X    index;
  1796. } ColorPacket;
  1797. X
  1798. typedef struct _RunlengthPacket
  1799. {
  1800. X  unsigned char
  1801. X    red,
  1802. X    green,
  1803. X    blue,
  1804. X    length;
  1805. X
  1806. X  unsigned short
  1807. X    index;
  1808. } RunlengthPacket;
  1809. X
  1810. typedef struct _Image
  1811. {
  1812. X  FILE
  1813. X    *file;
  1814. X
  1815. X  char
  1816. X    filename[2048],
  1817. X    magick[12],
  1818. X    *comments,
  1819. X    *label;
  1820. X
  1821. X  unsigned int
  1822. X    id,
  1823. X    class,
  1824. X    colorspace,
  1825. X    alpha,
  1826. X    compression,
  1827. X    columns,
  1828. X    rows,
  1829. X    colors,
  1830. X    scene,
  1831. X    quality;
  1832. X
  1833. X  char
  1834. X    *montage,
  1835. X    *directory;
  1836. X
  1837. X  ColorPacket
  1838. X    *colormap;
  1839. X
  1840. X  char
  1841. X    *signature;
  1842. X
  1843. X  RunlengthPacket
  1844. X    *pixels,
  1845. X    *packet;
  1846. X
  1847. X  unsigned long int
  1848. X    packets;
  1849. X
  1850. X  unsigned int
  1851. X    runlength,
  1852. X    packet_size;
  1853. X
  1854. X  unsigned char
  1855. X    *packed_pixels;
  1856. X
  1857. X  unsigned int
  1858. X    orphan;
  1859. X
  1860. X  struct _Image
  1861. X    *last,
  1862. X    *next;
  1863. } Image;
  1864. X
  1865. /*
  1866. X  Image utilities routines.
  1867. */
  1868. extern Image
  1869. X  *AllocateImage _Declare((char *)),
  1870. X  *BorderImage _Declare((Image *,unsigned int,unsigned int,ColorPacket)),
  1871. X  *ClipImage _Declare((Image *,int,int,unsigned int,unsigned int)),
  1872. X  *CopyImage _Declare((Image *,unsigned int,unsigned int,unsigned int)),
  1873. X  *EnhanceImage _Declare((Image *)),
  1874. X  *NoisyImage _Declare((Image *)),
  1875. X  *ReadImage _Declare((char *)),
  1876. X  *ReduceImage _Declare((Image *)),
  1877. X  *ReflectImage _Declare((Image *)),
  1878. X  *RotateImage _Declare((Image *,double,int)),
  1879. X  *ScaleImage _Declare((Image *,unsigned int,unsigned int)),
  1880. X  *StereoImage _Declare((Image *,Image *)),
  1881. X  *ZoomImage _Declare((Image *));
  1882. X
  1883. extern int
  1884. X  ReadDataBlock _Declare((char *,FILE *));
  1885. X
  1886. extern unsigned int
  1887. X  NumberColors _Declare((Image *)),
  1888. X  PackImage _Declare((Image *)),
  1889. X  PrintImage _Declare((Image *,char *)),
  1890. X  ReadData _Declare((char *,int,int,FILE *)),
  1891. X  UncompressImage _Declare((Image *)),
  1892. X  UnpackImage _Declare((Image *)),
  1893. X  WriteImage _Declare((Image *));
  1894. X
  1895. extern void
  1896. X  CloseImage _Declare((Image *)),
  1897. X  ColormapSignature _Declare((Image *)),
  1898. X  CompositeImage _Declare((Image *,unsigned int,Image *,int,int)),
  1899. X  CompressColormap _Declare((Image *)),
  1900. X  CompressImage _Declare((Image *)),
  1901. X  DestroyImage _Declare((Image *)),
  1902. X  DestroyImages _Declare((Image *)),
  1903. X  GammaImage _Declare((Image *,double)),
  1904. X  InverseImage _Declare((Image *)),
  1905. X  NormalizeImage _Declare((Image *)),
  1906. X  OpenImage _Declare((Image *,char *)),
  1907. X  QuantizationError _Declare((Image *,unsigned int *,double *,double *)),
  1908. X  QuantizeImage _Declare((Image *,unsigned int,unsigned int,unsigned int,
  1909. X    unsigned int,unsigned int)),
  1910. X  QuantizeImages _Declare((Image **,unsigned int,Image *,unsigned int,
  1911. X    unsigned int,unsigned int,unsigned int,unsigned int)),
  1912. X  RGBTransformImage _Declare((Image *,unsigned int)),
  1913. X  SortColormapByIntensity _Declare((Image *)),
  1914. X  TransformImage _Declare((Image **,char *,char *,char *)),
  1915. X  TransformRGBImage _Declare((Image *,unsigned int));
  1916. SHAR_EOF
  1917. chmod 0644 ImageMagick/image.h ||
  1918. echo 'restore of ImageMagick/image.h failed'
  1919. Wc_c="`wc -c < 'ImageMagick/image.h'`"
  1920. test 4107 -eq "$Wc_c" ||
  1921.     echo 'ImageMagick/image.h: original size 4107, current size' "$Wc_c"
  1922. rm -f _shar_wnt_.tmp
  1923. fi
  1924. # ============= ImageMagick/display.c ==============
  1925. if test -f 'ImageMagick/display.c' -a X"$1" != X"-c"; then
  1926.     echo 'x - skipping ImageMagick/display.c (File already exists)'
  1927.     rm -f _shar_wnt_.tmp
  1928. else
  1929. > _shar_wnt_.tmp
  1930. echo 'x - extracting ImageMagick/display.c (Text)'
  1931. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/display.c' &&
  1932. /*
  1933. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1934. %                                                                             %
  1935. %                                                                             %
  1936. %                                                                             %
  1937. %             DDDD   IIIII  SSSSS  PPPP   L       AAA   Y   Y                 %
  1938. %             D   D    I    SS     P   P  L      A   A   Y Y                  %
  1939. %             D   D    I     SSS   PPPP   L      AAAAA    Y                   %
  1940. %             D   D    I       SS  P      L      A   A    Y                   %
  1941. %             DDDD   IIIII  SSSSS  P      LLLLL  A   A    Y                   %
  1942. %                                                                             %
  1943. %                                                                             %
  1944. %          Display Machine Independent File Format Image via X11.             %
  1945. %                                                                             %
  1946. %                                                                             %
  1947. %                                                                             %
  1948. %                           Software Design                                   %
  1949. %                             John Cristy                                     %
  1950. %                              July 1992                                      %
  1951. %                                                                             %
  1952. %                                                                             %
  1953. %  Copyright 1992 E. I. du Pont de Nemours & Company                          %
  1954. %                                                                             %
  1955. %  Permission to use, copy, modify, distribute, and sell this software and    %
  1956. SHAR_EOF
  1957. true || echo 'restore of ImageMagick/display.c failed'
  1958. fi
  1959. echo 'End of  part 10'
  1960. echo 'File ImageMagick/display.c is continued in part 11'
  1961. echo 11 > _shar_seq_.tmp
  1962. exit 0
  1963. exit 0 # Just in case...
  1964.