home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sources / misc / 4177 < prev    next >
Encoding:
Text File  |  1992-12-13  |  57.3 KB  |  1,970 lines

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