home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume34 / jpeg / part12 < prev    next >
Encoding:
Text File  |  1992-12-16  |  58.0 KB  |  1,612 lines

  1. Newsgroups: comp.sources.misc
  2. From: jpeg-info@uunet.uu.net (Independent JPEG Group)
  3. Subject:  v34i066:  jpeg - JPEG image compression, Part12/18
  4. Message-ID: <1992Dec17.164919.6583@sparky.imd.sterling.com>
  5. X-Md4-Signature: 5dd777d877402ce681bf090a3f822fb3
  6. Date: Thu, 17 Dec 1992 16:49:19 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jpeg-info@uunet.uu.net (Independent JPEG Group)
  10. Posting-number: Volume 34, Issue 66
  11. Archive-name: jpeg/part12
  12. Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
  13. Supersedes: jpeg: Volume 29, Issue 1-18
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # Contents:  USAGE jchuff.c jrevdct.c makefile.manx
  20. # Wrapped by kent@sparky on Wed Dec 16 20:52:29 1992
  21. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  22. echo If this archive is complete, you will see the following message:
  23. echo '          "shar: End of archive 12 (of 18)."'
  24. if test -f 'USAGE' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'USAGE'\"
  26. else
  27.   echo shar: Extracting \"'USAGE'\" \(14687 characters\)
  28.   sed "s/^X//" >'USAGE' <<'END_OF_FILE'
  29. XUSAGE instructions for the Independent JPEG Group's JPEG software
  30. X=================================================================
  31. X
  32. XINTRODUCTION
  33. X
  34. XThis distribution contains software to implement JPEG image compression and
  35. Xdecompression.  JPEG (pronounced "jay-peg") is a standardized compression
  36. Xmethod for full-color and gray-scale images.  JPEG is designed to handle
  37. X"real-world" scenes, for example scanned photographs.  Cartoons, line
  38. Xdrawings, and other non-realistic images are not JPEG's strong suit; on this
  39. Xsort of material you may get poor image quality and/or little compression.
  40. X
  41. XJPEG is lossy, meaning that the output image is not necessarily identical to
  42. Xthe input image.  Hence you should not use JPEG if you have to have identical
  43. Xoutput bits.  However, on typical real-world images, very good compression
  44. Xlevels can be obtained with no visible change, and amazingly high compression
  45. Xis possible if you can tolerate a low-quality image.  You can trade off image
  46. Xquality against file size by adjusting the compressor's "quality" setting.
  47. X
  48. XThis file describes usage of the standard programs "cjpeg" and "djpeg" that
  49. Xcan be built directly from the distributed C code.  See the README file for
  50. Xhints on incorporating the JPEG software into other programs.
  51. X
  52. XIf you are on a Unix machine you may prefer to read the Unix-style manual
  53. Xpages in files cjpeg.1 and djpeg.1.  But also see the HINTS section below,
  54. Xwhich is not present in either manual page.
  55. X
  56. XNOTE: the switch syntax has been redesigned since the v3 release of
  57. Xcjpeg/djpeg.  Switch names are now words instead of single letters.
  58. X
  59. X
  60. XGENERAL USAGE
  61. X
  62. XWe provide two programs, cjpeg to compress an image file into JPEG format,
  63. Xand djpeg to decompress a JPEG file back into a conventional image format.
  64. X
  65. XOn Unix-like systems, you say:
  66. X    cjpeg [switches] [imagefile] >jpegfile
  67. Xor
  68. X    djpeg [switches] [jpegfile]  >imagefile
  69. XThe programs read the specified input file, or standard input if none is
  70. Xnamed.  They always write to standard output (with trace/error messages to
  71. Xstandard error).  These conventions are handy for piping images between
  72. Xprograms.
  73. X
  74. XOn most non-Unix systems, you say:
  75. X    cjpeg [switches] imagefile jpegfile
  76. Xor
  77. X    djpeg [switches] jpegfile  imagefile
  78. Xi.e., both the input and output files are named on the command line.  This
  79. Xstyle is a little more foolproof, and it loses no functionality if you don't
  80. Xhave pipes.  (You can get this style on Unix too, if you prefer, by defining
  81. XTWO_FILE_COMMANDLINE when you compile the programs; see SETUP.)
  82. X
  83. XThe currently supported image file formats are: PPM (PBMPLUS color format),
  84. XPGM (PBMPLUS gray-scale format), GIF, Targa, and RLE (Utah Raster Toolkit
  85. Xformat).  (RLE is supported only if the URT library is available.)
  86. Xcjpeg recognizes the input image format automatically, with the exception
  87. Xof some Targa-format files.  You have to tell djpeg which format to generate.
  88. X
  89. XThe only JPEG file format currently supported is the JFIF format.  Support for
  90. Xthe TIFF 6.0 JPEG format will probably be added at some future date.
  91. X
  92. XAll switch names may be abbreviated; for example, -grayscale may be written
  93. X-gray or -gr.  Most of the "basic" switches can be abbreviated to as little as
  94. Xone letter.  Upper and lower case are equivalent (-GIF is the same as -gif).
  95. XBritish spellings are also accepted (e.g., -greyscale), though for brevity
  96. Xthese are not mentioned below.
  97. X
  98. X
  99. XCJPEG DETAILS
  100. X
  101. XThe basic command line switches for cjpeg are:
  102. X
  103. X    -quality N    Scale quantization tables to adjust image quality.
  104. X            Quality is 0 (worst) to 100 (best); default is 75.
  105. X            (See below for more info.)
  106. X
  107. X    -grayscale    Create monochrome JPEG file from color input.
  108. X            Be sure to use this switch when compressing a grayscale
  109. X            GIF file, because cjpeg isn't bright enough to notice
  110. X            whether a GIF file uses only shades of gray.  By
  111. X            saying -grayscale, you'll get a smaller JPEG file that
  112. X            takes less time to process.
  113. X
  114. X    -optimize    Perform optimization of entropy encoding parameters.
  115. X            Without this, default encoding parameters are used.
  116. X            -optimize usually makes the JPEG file a little smaller,
  117. X            but cjpeg runs somewhat slower and needs much more
  118. X            memory.  Image quality and speed of decompression are
  119. X            unaffected by -optimize.
  120. X
  121. X    -targa        Input file is Targa format.  Targa files that contain
  122. X            an "identification" field will not be automatically
  123. X            recognized by cjpeg; for such files you must specify
  124. X            -targa to make cjpeg treat the input as Targa format.
  125. X
  126. XThe -quality switch lets you trade off compressed file size against quality of
  127. Xthe reconstructed image: the higher the quality setting, the larger the JPEG
  128. Xfile, and the closer the output image will be to the original input.  Normally
  129. Xyou want to use the lowest quality setting (smallest file) that decompresses
  130. Xinto something visually indistinguishable from the original image.  For this
  131. Xpurpose the quality setting should be between 50 and 95; the default of 75 is
  132. Xoften about right.  If you see defects at -quality 75, then go up 5 or 10
  133. Xcounts at a time until you are happy with the output image.  (The optimal
  134. Xsetting will vary from one image to another.)
  135. X
  136. X-quality 100 will generate a quantization table of all 1's, eliminating loss
  137. Xin the quantization step (but there is still information loss in subsampling,
  138. Xas well as roundoff error).  This setting is mainly of interest for
  139. Xexperimental purposes.  Quality values above about 95 are NOT recommended for
  140. Xnormal use; the compressed file size goes up dramatically for hardly any gain
  141. Xin output image quality.
  142. X
  143. XIn the other direction, quality values below 50 will produce very small files
  144. Xof low image quality.  Settings around 5 to 10 might be useful in preparing an
  145. Xindex of a large image library, for example.  Try -quality 2 (or so) for some
  146. Xamusing Cubist effects.  (Note: quality values below about 25 generate 2-byte
  147. Xquantization tables, which are considered optional in the JPEG standard.
  148. Xcjpeg emits a warning message when you give such a quality value, because
  149. Xsome commercial JPEG programs may be unable to decode the resulting file.)
  150. X
  151. XSwitches for advanced users:
  152. X
  153. X    -maxmemory N    Set limit for amount of memory to use in processing
  154. X            large images.  Value is in thousands of bytes, or
  155. X            millions of bytes if "M" is attached to the number.
  156. X            For example, -max 4m selects 4000000 bytes.  If more
  157. X            space is needed, temporary files will be used.
  158. X
  159. X    -restart N    Emit a JPEG restart marker every N MCU rows, or every
  160. X            N MCU blocks if "B" is attached to the number.
  161. X            -restart 0 (the default) means no restart markers.
  162. X
  163. X    -smooth N    Smooth the input image to eliminate dithering noise.
  164. X            N, ranging from 1 to 100, indicates the strength of
  165. X            smoothing.  0 (the default) means no smoothing.
  166. X
  167. X    -verbose    Enable debug printout.  More -v's give more printout.
  168. X    or  -debug    Also, version information is printed at startup.
  169. X
  170. XThe -restart option inserts extra markers that allow a JPEG decoder to
  171. Xresynchronize after a transmission error.  Without restart markers, any damage
  172. Xto a compressed file will usually ruin the image from the point of the error
  173. Xto the end of the image; with restart markers, the damage is usually confined
  174. Xto the portion of the image up to the next restart marker.  Of course, the
  175. Xrestart markers occupy extra space.  We recommend -restart 1 for images that
  176. Xwill be transmitted across unreliable networks such as Usenet.
  177. X
  178. XThe -smooth option filters the input to eliminate fine-scale noise.  This is
  179. Xoften useful when converting GIF files to JPEG: a moderate smoothing factor of
  180. X10 to 50 gets rid of dithering patterns in the input file, resulting in a
  181. Xsmaller JPEG file and a better-looking image.  Too large a smoothing factor
  182. Xwill visibly blur the image, however.
  183. X
  184. XSwitches for wizards:
  185. X
  186. X    -arithmetic    Use arithmetic coding rather than Huffman coding.
  187. X            (Not currently supported for legal reasons.)
  188. X
  189. X    -nointerleave    Generate noninterleaved JPEG file (not yet supported).
  190. X
  191. X    -qtables file    Use the quantization tables given in the specified
  192. X            file.  The file should contain one to four tables
  193. X            (64 values each) as plain text.  Comments preceded by
  194. X            '#' may be included in the file.  The tables are
  195. X            implicitly numbered 0,1,etc.  If -quality N is also
  196. X            specified, the values in the file are scaled according
  197. X            to cjpeg's quality scaling curve.
  198. X
  199. X    -sample HxV[,...]    Set JPEG sampling factors.  If you specify
  200. X            fewer H/V pairs than there are components, the
  201. X            remaining components are set to 1x1 sampling.  The
  202. X            default setting is equivalent to "-sample 2x2".
  203. X
  204. XThe "wizard" switches are intended for experimentation with JPEG.  If you
  205. Xdon't know what you are doing, DON'T USE THEM.  You can easily produce files
  206. Xwith worse image quality and/or poorer compression than you'll get from the
  207. Xdefault settings.  Furthermore, these switches should not be used when making
  208. Xfiles intended for general use, because not all JPEG implementations will
  209. Xsupport unusual JPEG parameter settings.
  210. X
  211. X
  212. XDJPEG DETAILS
  213. X
  214. XThe basic command line switches for djpeg are:
  215. X
  216. X    -colors N    Reduce image to at most N colors.  This reduces the
  217. X    or -quantize N    number of colors used in the output image, so that it
  218. X            can be displayed on a colormapped display or stored in
  219. X            a colormapped file format.  For example, if you have
  220. X            an 8-bit display, you'd need to reduce to 256 or fewer
  221. X            colors.  (-colors is the recommended name, -quantize
  222. X            is provided only for backwards compatibility.)
  223. X
  224. X    -gif        Select GIF output format.  Since GIF does not support
  225. X            more than 256 colors, -colors 256 is assumed (unless
  226. X            you specify a smaller number of colors).
  227. X
  228. X    -pnm        Select PBMPLUS (PPM/PGM) output format (this is the
  229. X            default format).  PGM is emitted if the JPEG file is
  230. X            gray-scale or if -grayscale is specified; otherwise
  231. X            PPM is emitted.
  232. X
  233. X    -rle        Select RLE output format.  (Requires URT library.)
  234. X
  235. X    -targa        Select Targa output format.  Gray-scale format is
  236. X            emitted if the JPEG file is gray-scale or if
  237. X            -grayscale is specified; otherwise, colormapped format
  238. X            is emitted if -colors is specified; otherwise, 24-bit
  239. X            full-color format is emitted.
  240. X
  241. XSwitches for advanced users:
  242. X
  243. X    -blocksmooth    Perform cross-block smoothing.  This is quite
  244. X            memory-intensive and only seems to improve the image
  245. X            at very low quality settings (-quality 10 to 20 or so).
  246. X            At normal quality settings it may make things worse.
  247. X
  248. X    -grayscale    Force gray-scale output even if JPEG file is color.
  249. X            Useful for viewing on monochrome displays.
  250. X
  251. X    -maxmemory N    Set limit for amount of memory to use in processing
  252. X            large images.  Value is in thousands of bytes, or
  253. X            millions of bytes if "M" is attached to the number.
  254. X            For example, -max 4m selects 4000000 bytes.  If more
  255. X            space is needed, temporary files will be used.
  256. X
  257. X    -nodither    Do not use dithering in color quantization.
  258. X            By default, Floyd-Steinberg dithering is applied when
  259. X            quantizing colors, but on some images dithering may
  260. X            result in objectionable "graininess".  If that
  261. X            happens, you can turn off dithering with -nodither.
  262. X            -nodither is ignored unless you also say -colors N.
  263. X
  264. X    -onepass    Use one-pass instead of two-pass color quantization.
  265. X            The one-pass method is faster and needs less memory,
  266. X            but it produces a lower-quality image.  -onepass is
  267. X            ignored unless you also say -colors N.  Also,
  268. X            the one-pass method is always used for gray-scale
  269. X            output (the two-pass method is no improvement then).
  270. X
  271. X    -verbose    Enable debug printout.  More -v's give more printout.
  272. X    or  -debug    Also, version information is printed at startup.
  273. X
  274. X
  275. XHINTS
  276. X
  277. XColor GIF files are not the ideal input for JPEG; JPEG is really intended for
  278. Xcompressing full-color (24-bit) images.  In particular, don't try to convert
  279. Xcartoons, line drawings, and other images that have only a few distinct
  280. Xcolors.  GIF works great on these, JPEG does not.  If you want to convert a
  281. XGIF to JPEG, you should experiment with cjpeg's -quality and -smooth options
  282. Xto get a satisfactory conversion.  -smooth 10 or so is often helpful.
  283. X
  284. XAvoid running an image through a series of JPEG compression/decompression
  285. Xcycles.  Image quality loss will accumulate; after ten or so cycles the image
  286. Xmay be noticeably worse than it was after one cycle.  It's best to use a
  287. Xlossless format while manipulating an image, then convert to JPEG format when
  288. Xyou are ready to file the image away.
  289. X
  290. XThe -optimize option to cjpeg is worth using when you are making a "final"
  291. Xversion for posting or archiving.  It's also a win when you are using low
  292. Xquality settings to make very small JPEG files; the percentage improvement
  293. Xis often a lot more than it is on larger files.
  294. X
  295. XWhen making images to be posted on Usenet, we recommend using cjpeg's option
  296. X-restart 1.  This option limits the damage done to a compressed image by
  297. Xnetnews transmission errors.
  298. X
  299. XThe default memory usage limit (-maxmemory) is set when the software is
  300. Xcompiled.  If you get an "insufficient memory" error, try specifying a smaller
  301. X-maxmemory value, even -maxmemory 0 to use the absolute minimum space.  You
  302. Xmay want to recompile with a smaller default value if this happens often.
  303. X
  304. XOn machines that have "environment" variables, you can define the environment
  305. Xvariable JPEGMEM to set the default memory limit.  The value is specified as
  306. Xdescribed for the -maxmemory switch.  JPEGMEM overrides the default value
  307. Xspecified when the program was compiled, and itself is overridden by an
  308. Xexplicit -maxmemory switch.
  309. X
  310. XOn MS-DOS machines, -maxmemory is the amount of main (conventional) memory to
  311. Xuse.  (Extended or expanded memory is also used if available.)  Most
  312. XDOS-specific versions of this software do their own memory space estimation
  313. Xand do not need -maxmemory.
  314. X
  315. Xdjpeg with two-pass color quantization requires a good deal of memory; on
  316. XMS-DOS machines it may run out of memory even with -maxmemory 0.  In that case
  317. Xyou can still decompress, with some loss of image quality, by specifying
  318. X-onepass for one-pass quantization.
  319. X
  320. XIf more space is needed than will fit in the available main memory (as
  321. Xdetermined by -maxmemory), temporary files will be used.  (MS-DOS versions
  322. Xwill try to get extended or expanded memory first.)  The temporary files are
  323. Xoften rather large: in typical cases they occupy three bytes per pixel, for
  324. Xexample 3*800*600 = 1.44Mb for an 800x600 image.  If you don't have enough
  325. Xfree disk space, leave out -optimize (for cjpeg) or specify -onepass (for
  326. Xdjpeg).  On MS-DOS, the temporary files are created in the directory named by
  327. Xthe TMP or TEMP environment variable, or in the current directory if neither
  328. Xof those exist.  Amiga implementations put the temp files in the directory
  329. Xnamed by JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with
  330. Xadequate free space.
  331. END_OF_FILE
  332.   if test 14687 -ne `wc -c <'USAGE'`; then
  333.     echo shar: \"'USAGE'\" unpacked with wrong size!
  334.   fi
  335.   # end of 'USAGE'
  336. fi
  337. if test -f 'jchuff.c' -a "${1}" != "-c" ; then 
  338.   echo shar: Will not clobber existing file \"'jchuff.c'\"
  339. else
  340.   echo shar: Extracting \"'jchuff.c'\" \(20013 characters\)
  341.   sed "s/^X//" >'jchuff.c' <<'END_OF_FILE'
  342. X/*
  343. X * jchuff.c
  344. X *
  345. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  346. X * This file is part of the Independent JPEG Group's software.
  347. X * For conditions of distribution and use, see the accompanying README file.
  348. X *
  349. X * This file contains Huffman entropy encoding routines.
  350. X * These routines are invoked via the methods entropy_encode,
  351. X * entropy_encode_init/term, and entropy_optimize.
  352. X */
  353. X
  354. X#include "jinclude.h"
  355. X
  356. X
  357. X/* Static variables to avoid passing 'round extra parameters */
  358. X
  359. Xstatic compress_info_ptr cinfo;
  360. X
  361. Xstatic INT32 huff_put_buffer;    /* current bit-accumulation buffer */
  362. Xstatic int huff_put_bits;    /* # of bits now in it */
  363. X
  364. Xstatic char * output_buffer;    /* output buffer */
  365. Xstatic int bytes_in_buffer;
  366. X
  367. X
  368. X
  369. XLOCAL void
  370. Xfix_huff_tbl (HUFF_TBL * htbl)
  371. X/* Compute derived values for a Huffman table */
  372. X{
  373. X  int p, i, l, lastp, si;
  374. X  char huffsize[257];
  375. X  UINT16 huffcode[257];
  376. X  UINT16 code;
  377. X  
  378. X  /* Figure C.1: make table of Huffman code length for each symbol */
  379. X  /* Note that this is in code-length order. */
  380. X
  381. X  p = 0;
  382. X  for (l = 1; l <= 16; l++) {
  383. X    for (i = 1; i <= (int) htbl->bits[l]; i++)
  384. X      huffsize[p++] = (char) l;
  385. X  }
  386. X  huffsize[p] = 0;
  387. X  lastp = p;
  388. X  
  389. X  /* Figure C.2: generate the codes themselves */
  390. X  /* Note that this is in code-length order. */
  391. X  
  392. X  code = 0;
  393. X  si = huffsize[0];
  394. X  p = 0;
  395. X  while (huffsize[p]) {
  396. X    while (((int) huffsize[p]) == si) {
  397. X      huffcode[p++] = code;
  398. X      code++;
  399. X    }
  400. X    code <<= 1;
  401. X    si++;
  402. X  }
  403. X  
  404. X  /* Figure C.3: generate encoding tables */
  405. X  /* These are code and size indexed by symbol value */
  406. X
  407. X  /* Set any codeless symbols to have code length 0;
  408. X   * this allows emit_bits to detect any attempt to emit such symbols.
  409. X   */
  410. X  MEMZERO(htbl->ehufsi, SIZEOF(htbl->ehufsi));
  411. X
  412. X  for (p = 0; p < lastp; p++) {
  413. X    htbl->ehufco[htbl->huffval[p]] = huffcode[p];
  414. X    htbl->ehufsi[htbl->huffval[p]] = huffsize[p];
  415. X  }
  416. X  
  417. X  /* We don't bother to fill in the decoding tables mincode[], maxcode[], */
  418. X  /* and valptr[], since they are not used for encoding. */
  419. X}
  420. X
  421. X
  422. X/* Outputting bytes to the file */
  423. X
  424. XLOCAL void
  425. Xflush_bytes (void)
  426. X{
  427. X  if (bytes_in_buffer)
  428. X    (*cinfo->methods->entropy_output) (cinfo, output_buffer, bytes_in_buffer);
  429. X  bytes_in_buffer = 0;
  430. X}
  431. X
  432. X
  433. X#define emit_byte(val)  \
  434. X  MAKESTMT( if (bytes_in_buffer >= JPEG_BUF_SIZE) \
  435. X          flush_bytes(); \
  436. X        output_buffer[bytes_in_buffer++] = (char) (val); )
  437. X
  438. X
  439. X
  440. X/* Outputting bits to the file */
  441. X
  442. X/* Only the right 24 bits of huff_put_buffer are used; the valid bits are
  443. X * left-justified in this part.  At most 16 bits can be passed to emit_bits
  444. X * in one call, and we never retain more than 7 bits in huff_put_buffer
  445. X * between calls, so 24 bits are sufficient.
  446. X */
  447. X
  448. XINLINE
  449. XLOCAL void
  450. Xemit_bits (UINT16 code, int size)
  451. X{
  452. X  /* This routine is heavily used, so it's worth coding tightly. */
  453. X  register INT32 put_buffer = code;
  454. X  register int put_bits = huff_put_bits;
  455. X
  456. X  /* if size is 0, caller used an invalid Huffman table entry */
  457. X  if (size == 0)
  458. X    ERREXIT(cinfo->emethods, "Missing Huffman code table entry");
  459. X
  460. X  put_buffer &= (((INT32) 1) << size) - 1; /* Mask off any excess bits in code */
  461. X  
  462. X  put_bits += size;        /* new number of bits in buffer */
  463. X  
  464. X  put_buffer <<= 24 - put_bits; /* align incoming bits */
  465. X
  466. X  put_buffer |= huff_put_buffer; /* and merge with old buffer contents */
  467. X  
  468. X  while (put_bits >= 8) {
  469. X    int c = (int) ((put_buffer >> 16) & 0xFF);
  470. X    
  471. X    emit_byte(c);
  472. X    if (c == 0xFF) {        /* need to stuff a zero byte? */
  473. X      emit_byte(0);
  474. X    }
  475. X    put_buffer <<= 8;
  476. X    put_bits -= 8;
  477. X  }
  478. X
  479. X  huff_put_buffer = put_buffer;    /* Update global variables */
  480. X  huff_put_bits = put_bits;
  481. X}
  482. X
  483. X
  484. XLOCAL void
  485. Xflush_bits (void)
  486. X{
  487. X  emit_bits((UINT16) 0x7F, 7);    /* fill any partial byte with ones */
  488. X  huff_put_buffer = 0;        /* and reset bit-buffer to empty */
  489. X  huff_put_bits = 0;
  490. X}
  491. X
  492. X
  493. X
  494. X/* Encode a single block's worth of coefficients */
  495. X/* Note that the DC coefficient has already been converted to a difference */
  496. X
  497. XLOCAL void
  498. Xencode_one_block (JBLOCK block, HUFF_TBL *dctbl, HUFF_TBL *actbl)
  499. X{
  500. X  register int temp, temp2;
  501. X  register int nbits;
  502. X  register int k, r, i;
  503. X  
  504. X  /* Encode the DC coefficient difference per section F.1.2.1 */
  505. X  
  506. X  temp = temp2 = block[0];
  507. X
  508. X  if (temp < 0) {
  509. X    temp = -temp;        /* temp is abs value of input */
  510. X    /* For a negative input, want temp2 = bitwise complement of abs(input) */
  511. X    /* This code assumes we are on a two's complement machine */
  512. X    temp2--;
  513. X  }
  514. X  
  515. X  /* Find the number of bits needed for the magnitude of the coefficient */
  516. X  nbits = 0;
  517. X  while (temp) {
  518. X    nbits++;
  519. X    temp >>= 1;
  520. X  }
  521. X  
  522. X  /* Emit the Huffman-coded symbol for the number of bits */
  523. X  emit_bits(dctbl->ehufco[nbits], dctbl->ehufsi[nbits]);
  524. X
  525. X  /* Emit that number of bits of the value, if positive, */
  526. X  /* or the complement of its magnitude, if negative. */
  527. X  if (nbits)            /* emit_bits rejects calls with size 0 */
  528. X    emit_bits((UINT16) temp2, nbits);
  529. X  
  530. X  /* Encode the AC coefficients per section F.1.2.2 */
  531. X  
  532. X  r = 0;            /* r = run length of zeros */
  533. X  
  534. X  for (k = 1; k < DCTSIZE2; k++) {
  535. X    if ((temp = block[k]) == 0) {
  536. X      r++;
  537. X    } else {
  538. X      /* if run length > 15, must emit special run-length-16 codes (0xF0) */
  539. X      while (r > 15) {
  540. X    emit_bits(actbl->ehufco[0xF0], actbl->ehufsi[0xF0]);
  541. X    r -= 16;
  542. X      }
  543. X
  544. X      temp2 = temp;
  545. X      if (temp < 0) {
  546. X    temp = -temp;        /* temp is abs value of input */
  547. X    /* This code assumes we are on a two's complement machine */
  548. X    temp2--;
  549. X      }
  550. X      
  551. X      /* Find the number of bits needed for the magnitude of the coefficient */
  552. X      nbits = 1;        /* there must be at least one 1 bit */
  553. X      while (temp >>= 1)
  554. X    nbits++;
  555. X      
  556. X      /* Emit Huffman symbol for run length / number of bits */
  557. X      i = (r << 4) + nbits;
  558. X      emit_bits(actbl->ehufco[i], actbl->ehufsi[i]);
  559. X      
  560. X      /* Emit that number of bits of the value, if positive, */
  561. X      /* or the complement of its magnitude, if negative. */
  562. X      emit_bits((UINT16) temp2, nbits);
  563. X      
  564. X      r = 0;
  565. X    }
  566. X  }
  567. X
  568. X  /* If the last coef(s) were zero, emit an end-of-block code */
  569. X  if (r > 0)
  570. X    emit_bits(actbl->ehufco[0], actbl->ehufsi[0]);
  571. X}
  572. X
  573. X
  574. X
  575. X/*
  576. X * Initialize for a Huffman-compressed scan.
  577. X * This is invoked after writing the SOS marker.
  578. X * The pipeline controller must establish the entropy_output method pointer
  579. X * before calling this routine.
  580. X */
  581. X
  582. XMETHODDEF void
  583. Xhuff_init (compress_info_ptr xinfo)
  584. X{
  585. X  short ci;
  586. X  jpeg_component_info * compptr;
  587. X
  588. X  /* Initialize static variables */
  589. X  cinfo = xinfo;
  590. X  huff_put_buffer = 0;
  591. X  huff_put_bits = 0;
  592. X
  593. X  /* Initialize the output buffer */
  594. X  output_buffer = (char *) (*cinfo->emethods->alloc_small)
  595. X                ((size_t) JPEG_BUF_SIZE);
  596. X  bytes_in_buffer = 0;
  597. X
  598. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  599. X    compptr = cinfo->cur_comp_info[ci];
  600. X    /* Make sure requested tables are present */
  601. X    if (cinfo->dc_huff_tbl_ptrs[compptr->dc_tbl_no] == NULL ||
  602. X    cinfo->ac_huff_tbl_ptrs[compptr->ac_tbl_no] == NULL)
  603. X      ERREXIT(cinfo->emethods, "Use of undefined Huffman table");
  604. X    /* Compute derived values for Huffman tables */
  605. X    /* We may do this more than once for same table, but it's not a big deal */
  606. X    fix_huff_tbl(cinfo->dc_huff_tbl_ptrs[compptr->dc_tbl_no]);
  607. X    fix_huff_tbl(cinfo->ac_huff_tbl_ptrs[compptr->ac_tbl_no]);
  608. X    /* Initialize DC predictions to 0 */
  609. X    cinfo->last_dc_val[ci] = 0;
  610. X  }
  611. X
  612. X  /* Initialize restart stuff */
  613. X  cinfo->restarts_to_go = cinfo->restart_interval;
  614. X  cinfo->next_restart_num = 0;
  615. X}
  616. X
  617. X
  618. X/*
  619. X * Emit a restart marker & resynchronize predictions.
  620. X */
  621. X
  622. XLOCAL void
  623. Xemit_restart (compress_info_ptr cinfo)
  624. X{
  625. X  short ci;
  626. X
  627. X  flush_bits();
  628. X
  629. X  emit_byte(0xFF);
  630. X  emit_byte(RST0 + cinfo->next_restart_num);
  631. X
  632. X  /* Re-initialize DC predictions to 0 */
  633. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  634. X    cinfo->last_dc_val[ci] = 0;
  635. X
  636. X  /* Update restart state */
  637. X  cinfo->restarts_to_go = cinfo->restart_interval;
  638. X  cinfo->next_restart_num++;
  639. X  cinfo->next_restart_num &= 7;
  640. X}
  641. X
  642. X
  643. X/*
  644. X * Encode and output one MCU's worth of Huffman-compressed coefficients.
  645. X */
  646. X
  647. XMETHODDEF void
  648. Xhuff_encode (compress_info_ptr cinfo, JBLOCK *MCU_data)
  649. X{
  650. X  short blkn, ci;
  651. X  jpeg_component_info * compptr;
  652. X  JCOEF temp;
  653. X
  654. X  /* Account for restart interval, emit restart marker if needed */
  655. X  if (cinfo->restart_interval) {
  656. X    if (cinfo->restarts_to_go == 0)
  657. X      emit_restart(cinfo);
  658. X    cinfo->restarts_to_go--;
  659. X  }
  660. X
  661. X  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  662. X    ci = cinfo->MCU_membership[blkn];
  663. X    compptr = cinfo->cur_comp_info[ci];
  664. X    /* Convert DC value to difference, update last_dc_val */
  665. X    temp = MCU_data[blkn][0];
  666. X    MCU_data[blkn][0] -= cinfo->last_dc_val[ci];
  667. X    cinfo->last_dc_val[ci] = temp;
  668. X    encode_one_block(MCU_data[blkn],
  669. X             cinfo->dc_huff_tbl_ptrs[compptr->dc_tbl_no],
  670. X             cinfo->ac_huff_tbl_ptrs[compptr->ac_tbl_no]);
  671. X  }
  672. X}
  673. X
  674. X
  675. X/*
  676. X * Finish up at the end of a Huffman-compressed scan.
  677. X */
  678. X
  679. XMETHODDEF void
  680. Xhuff_term (compress_info_ptr cinfo)
  681. X{
  682. X  /* Flush out the last data */
  683. X  flush_bits();
  684. X  flush_bytes();
  685. X  /* Release the I/O buffer */
  686. X  (*cinfo->emethods->free_small) ((void *) output_buffer);
  687. X}
  688. X
  689. X
  690. X
  691. X
  692. X/*
  693. X * Huffman coding optimization.
  694. X *
  695. X * This actually is optimization, in the sense that we find the best possible
  696. X * Huffman table(s) for the given data.  We first scan the supplied data and
  697. X * count the number of uses of each symbol that is to be Huffman-coded.
  698. X * (This process must agree with the code above.)  Then we build an
  699. X * optimal Huffman coding tree for the observed counts.
  700. X */
  701. X
  702. X#ifdef ENTROPY_OPT_SUPPORTED
  703. X
  704. X
  705. X/* These are static so htest_one_block can find 'em */
  706. Xstatic long * dc_count_ptrs[NUM_HUFF_TBLS];
  707. Xstatic long * ac_count_ptrs[NUM_HUFF_TBLS];
  708. X
  709. X
  710. XLOCAL void
  711. Xgen_huff_coding (compress_info_ptr cinfo, HUFF_TBL *htbl, long freq[])
  712. X/* Generate the optimal coding for the given counts */
  713. X{
  714. X#define MAX_CLEN 32        /* assumed maximum initial code length */
  715. X  UINT8 bits[MAX_CLEN+1];    /* bits[k] = # of symbols with code length k */
  716. X  short codesize[257];        /* codesize[k] = code length of symbol k */
  717. X  short others[257];        /* next symbol in current branch of tree */
  718. X  int c1, c2;
  719. X  int p, i, j;
  720. X  long v;
  721. X
  722. X  /* This algorithm is explained in section K.2 of the JPEG standard */
  723. X
  724. X  MEMZERO(bits, SIZEOF(bits));
  725. X  MEMZERO(codesize, SIZEOF(codesize));
  726. X  for (i = 0; i < 257; i++)
  727. X    others[i] = -1;        /* init links to empty */
  728. X  
  729. X  freq[256] = 1;        /* make sure there is a nonzero count */
  730. X  /* including the pseudo-symbol 256 in the Huffman procedure guarantees
  731. X   * that no real symbol is given code-value of all ones, because 256
  732. X   * will be placed in the largest codeword category.
  733. X   */
  734. X
  735. X  /* Huffman's basic algorithm to assign optimal code lengths to symbols */
  736. X
  737. X  for (;;) {
  738. X    /* Find the smallest nonzero frequency, set c1 = its symbol */
  739. X    /* In case of ties, take the larger symbol number */
  740. X    c1 = -1;
  741. X    v = 1000000000L;
  742. X    for (i = 0; i <= 256; i++) {
  743. X      if (freq[i] && freq[i] <= v) {
  744. X    v = freq[i];
  745. X    c1 = i;
  746. X      }
  747. X    }
  748. X
  749. X    /* Find the next smallest nonzero frequency, set c2 = its symbol */
  750. X    /* In case of ties, take the larger symbol number */
  751. X    c2 = -1;
  752. X    v = 1000000000L;
  753. X    for (i = 0; i <= 256; i++) {
  754. X      if (freq[i] && freq[i] <= v && i != c1) {
  755. X    v = freq[i];
  756. X    c2 = i;
  757. X      }
  758. X    }
  759. X
  760. X    /* Done if we've merged everything into one frequency */
  761. X    if (c2 < 0)
  762. X      break;
  763. X    
  764. X    /* Else merge the two counts/trees */
  765. X    freq[c1] += freq[c2];
  766. X    freq[c2] = 0;
  767. X
  768. X    /* Increment the codesize of everything in c1's tree branch */
  769. X    codesize[c1]++;
  770. X    while (others[c1] >= 0) {
  771. X      c1 = others[c1];
  772. X      codesize[c1]++;
  773. X    }
  774. X    
  775. X    others[c1] = c2;        /* chain c2 onto c1's tree branch */
  776. X    
  777. X    /* Increment the codesize of everything in c2's tree branch */
  778. X    codesize[c2]++;
  779. X    while (others[c2] >= 0) {
  780. X      c2 = others[c2];
  781. X      codesize[c2]++;
  782. X    }
  783. X  }
  784. X
  785. X  /* Now count the number of symbols of each code length */
  786. X  for (i = 0; i <= 256; i++) {
  787. X    if (codesize[i]) {
  788. X      /* The JPEG standard seems to think that this can't happen, */
  789. X      /* but I'm paranoid... */
  790. X      if (codesize[i] > MAX_CLEN)
  791. X    ERREXIT(cinfo->emethods, "Huffman code size table overflow");
  792. X
  793. X      bits[codesize[i]]++;
  794. X    }
  795. X  }
  796. X
  797. X  /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure
  798. X   * Huffman procedure assigned any such lengths, we must adjust the coding.
  799. X   * Here is what the JPEG spec says about how this next bit works:
  800. X   * Since symbols are paired for the longest Huffman code, the symbols are
  801. X   * removed from this length category two at a time.  The prefix for the pair
  802. X   * (which is one bit shorter) is allocated to one of the pair; then,
  803. X   * skipping the BITS entry for that prefix length, a code word from the next
  804. X   * shortest nonzero BITS entry is converted into a prefix for two code words
  805. X   * one bit longer.
  806. X   */
  807. X  
  808. X  for (i = MAX_CLEN; i > 16; i--) {
  809. X    while (bits[i] > 0) {
  810. X      j = i - 2;        /* find length of new prefix to be used */
  811. X      while (bits[j] == 0)
  812. X    j--;
  813. X      
  814. X      bits[i] -= 2;        /* remove two symbols */
  815. X      bits[i-1]++;        /* one goes in this length */
  816. X      bits[j+1] += 2;        /* two new symbols in this length */
  817. X      bits[j]--;        /* symbol of this length is now a prefix */
  818. X    }
  819. X  }
  820. X
  821. X  /* Remove the count for the pseudo-symbol 256 from the largest codelength */
  822. X  while (bits[i] == 0)        /* find largest codelength still in use */
  823. X    i--;
  824. X  bits[i]--;
  825. X  
  826. X  /* Return final symbol counts (only for lengths 0..16) */
  827. X  MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  828. X  
  829. X  /* Return a list of the symbols sorted by code length */
  830. X  /* It's not real clear to me why we don't need to consider the codelength
  831. X   * changes made above, but the JPEG spec seems to think this works.
  832. X   */
  833. X  p = 0;
  834. X  for (i = 1; i <= MAX_CLEN; i++) {
  835. X    for (j = 0; j <= 255; j++) {
  836. X      if (codesize[j] == i) {
  837. X    htbl->huffval[p] = (UINT8) j;
  838. X    p++;
  839. X      }
  840. X    }
  841. X  }
  842. X}
  843. X
  844. X
  845. X/* Process a single block's worth of coefficients */
  846. X/* Note that the DC coefficient has already been converted to a difference */
  847. X
  848. XLOCAL void
  849. Xhtest_one_block (JBLOCK block, JCOEF block0,
  850. X         long dc_counts[], long ac_counts[])
  851. X{
  852. X  register INT32 temp;
  853. X  register int nbits;
  854. X  register int k, r;
  855. X  
  856. X  /* Encode the DC coefficient difference per section F.1.2.1 */
  857. X  
  858. X  /* Find the number of bits needed for the magnitude of the coefficient */
  859. X  temp = block0;
  860. X  if (temp < 0) temp = -temp;
  861. X  
  862. X  for (nbits = 0; temp; nbits++)
  863. X    temp >>= 1;
  864. X  
  865. X  /* Count the Huffman symbol for the number of bits */
  866. X  dc_counts[nbits]++;
  867. X  
  868. X  /* Encode the AC coefficients per section F.1.2.2 */
  869. X  
  870. X  r = 0;            /* r = run length of zeros */
  871. X  
  872. X  for (k = 1; k < DCTSIZE2; k++) {
  873. X    if ((temp = block[k]) == 0) {
  874. X      r++;
  875. X    } else {
  876. X      /* if run length > 15, must emit special run-length-16 codes (0xF0) */
  877. X      while (r > 15) {
  878. X    ac_counts[0xF0]++;
  879. X    r -= 16;
  880. X      }
  881. X      
  882. X      /* Find the number of bits needed for the magnitude of the coefficient */
  883. X      if (temp < 0) temp = -temp;
  884. X      
  885. X      for (nbits = 0; temp; nbits++)
  886. X    temp >>= 1;
  887. X      
  888. X      /* Count Huffman symbol for run length / number of bits */
  889. X      ac_counts[(r << 4) + nbits]++;
  890. X      
  891. X      r = 0;
  892. X    }
  893. X  }
  894. X
  895. X  /* If the last coef(s) were zero, emit an end-of-block code */
  896. X  if (r > 0)
  897. X    ac_counts[0]++;
  898. X}
  899. X
  900. X
  901. X
  902. X/*
  903. X * Trial-encode one MCU's worth of Huffman-compressed coefficients.
  904. X */
  905. X
  906. XLOCAL void
  907. Xhtest_encode (compress_info_ptr cinfo, JBLOCK *MCU_data)
  908. X{
  909. X  short blkn, ci;
  910. X  jpeg_component_info * compptr;
  911. X
  912. X  /* Take care of restart intervals if needed */
  913. X  if (cinfo->restart_interval) {
  914. X    if (cinfo->restarts_to_go == 0) {
  915. X      /* Re-initialize DC predictions to 0 */
  916. X      for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  917. X    cinfo->last_dc_val[ci] = 0;
  918. X      /* Update restart state */
  919. X      cinfo->restarts_to_go = cinfo->restart_interval;
  920. X    }
  921. X    cinfo->restarts_to_go--;
  922. X  }
  923. X
  924. X  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  925. X    ci = cinfo->MCU_membership[blkn];
  926. X    compptr = cinfo->cur_comp_info[ci];
  927. X    /* NB: unlike the real entropy encoder, we may not change the input data */
  928. X    htest_one_block(MCU_data[blkn],
  929. X            (JCOEF) (MCU_data[blkn][0] - cinfo->last_dc_val[ci]),
  930. X            dc_count_ptrs[compptr->dc_tbl_no],
  931. X            ac_count_ptrs[compptr->ac_tbl_no]);
  932. X    cinfo->last_dc_val[ci] = MCU_data[blkn][0];
  933. X  }
  934. X}
  935. X
  936. X
  937. X
  938. X/*
  939. X * Find the best coding parameters for a Huffman-coded scan.
  940. X * When called, the scan data has already been converted to a sequence of
  941. X * MCU groups of quantized coefficients, which are stored in a "big" array.
  942. X * The source_method knows how to iterate through that array.
  943. X * On return, the MCU data is unmodified, but the Huffman tables referenced
  944. X * by the scan components may have been altered.
  945. X */
  946. X
  947. XMETHODDEF void
  948. Xhuff_optimize (compress_info_ptr cinfo, MCU_output_caller_ptr source_method)
  949. X/* Optimize Huffman-coding parameters (Huffman symbol table) */
  950. X{
  951. X  int i, tbl;
  952. X  HUFF_TBL **htblptr;
  953. X
  954. X  /* Allocate and zero the count tables */
  955. X  /* Note that gen_huff_coding expects 257 entries in each table! */
  956. X
  957. X  for (i = 0; i < NUM_HUFF_TBLS; i++) {
  958. X    dc_count_ptrs[i] = NULL;
  959. X    ac_count_ptrs[i] = NULL;
  960. X  }
  961. X
  962. X  for (i = 0; i < cinfo->comps_in_scan; i++) {
  963. X    /* Create DC table */
  964. X    tbl = cinfo->cur_comp_info[i]->dc_tbl_no;
  965. X    if (dc_count_ptrs[tbl] == NULL) {
  966. X      dc_count_ptrs[tbl] = (long *) (*cinfo->emethods->alloc_small)
  967. X                    (257 * SIZEOF(long));
  968. X      MEMZERO(dc_count_ptrs[tbl], 257 * SIZEOF(long));
  969. X    }
  970. X    /* Create AC table */
  971. X    tbl = cinfo->cur_comp_info[i]->ac_tbl_no;
  972. X    if (ac_count_ptrs[tbl] == NULL) {
  973. X      ac_count_ptrs[tbl] = (long *) (*cinfo->emethods->alloc_small)
  974. X                    (257 * SIZEOF(long));
  975. X      MEMZERO(ac_count_ptrs[tbl], 257 * SIZEOF(long));
  976. X    }
  977. X  }
  978. X
  979. X  /* Initialize DC predictions to 0 */
  980. X  for (i = 0; i < cinfo->comps_in_scan; i++) {
  981. X    cinfo->last_dc_val[i] = 0;
  982. X  }
  983. X  /* Initialize restart stuff */
  984. X  cinfo->restarts_to_go = cinfo->restart_interval;
  985. X
  986. X  /* Scan the MCU data, count symbol uses */
  987. X  (*source_method) (cinfo, htest_encode);
  988. X
  989. X  /* Now generate optimal Huffman tables */
  990. X  for (tbl = 0; tbl < NUM_HUFF_TBLS; tbl++) {
  991. X    if (dc_count_ptrs[tbl] != NULL) {
  992. X      htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  993. X      if (*htblptr == NULL)
  994. X    *htblptr = (HUFF_TBL *) (*cinfo->emethods->alloc_small) (SIZEOF(HUFF_TBL));
  995. X      /* Set sent_table FALSE so updated table will be written to JPEG file. */
  996. X      (*htblptr)->sent_table = FALSE;
  997. X      /* Compute the optimal Huffman encoding */
  998. X      gen_huff_coding(cinfo, *htblptr, dc_count_ptrs[tbl]);
  999. X      /* Release the count table */
  1000. X      (*cinfo->emethods->free_small) ((void *) dc_count_ptrs[tbl]);
  1001. X    }
  1002. X    if (ac_count_ptrs[tbl] != NULL) {
  1003. X      htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  1004. X      if (*htblptr == NULL)
  1005. X    *htblptr = (HUFF_TBL *) (*cinfo->emethods->alloc_small) (SIZEOF(HUFF_TBL));
  1006. X      /* Set sent_table FALSE so updated table will be written to JPEG file. */
  1007. X      (*htblptr)->sent_table = FALSE;
  1008. X      /* Compute the optimal Huffman encoding */
  1009. X      gen_huff_coding(cinfo, *htblptr, ac_count_ptrs[tbl]);
  1010. X      /* Release the count table */
  1011. X      (*cinfo->emethods->free_small) ((void *) ac_count_ptrs[tbl]);
  1012. X    }
  1013. X  }
  1014. X}
  1015. X
  1016. X
  1017. X#endif /* ENTROPY_OPT_SUPPORTED */
  1018. X
  1019. X
  1020. X/*
  1021. X * The method selection routine for Huffman entropy encoding.
  1022. X */
  1023. X
  1024. XGLOBAL void
  1025. Xjselchuffman (compress_info_ptr cinfo)
  1026. X{
  1027. X  if (! cinfo->arith_code) {
  1028. X    cinfo->methods->entropy_encode_init = huff_init;
  1029. X    cinfo->methods->entropy_encode = huff_encode;
  1030. X    cinfo->methods->entropy_encode_term = huff_term;
  1031. X#ifdef ENTROPY_OPT_SUPPORTED
  1032. X    cinfo->methods->entropy_optimize = huff_optimize;
  1033. X    /* The standard Huffman tables are only valid for 8-bit data precision.
  1034. X     * If the precision is higher, force optimization on so that usable
  1035. X     * tables will be computed.  This test can be removed if default tables
  1036. X     * are supplied that are valid for the desired precision.
  1037. X     */
  1038. X    if (cinfo->data_precision > 8)
  1039. X      cinfo->optimize_coding = TRUE;
  1040. X    if (cinfo->optimize_coding)
  1041. X      cinfo->total_passes++;    /* one pass needed for entropy optimization */
  1042. X#endif
  1043. X  }
  1044. X}
  1045. END_OF_FILE
  1046.   if test 20013 -ne `wc -c <'jchuff.c'`; then
  1047.     echo shar: \"'jchuff.c'\" unpacked with wrong size!
  1048.   fi
  1049.   # end of 'jchuff.c'
  1050. fi
  1051. if test -f 'jrevdct.c' -a "${1}" != "-c" ; then 
  1052.   echo shar: Will not clobber existing file \"'jrevdct.c'\"
  1053. else
  1054.   echo shar: Extracting \"'jrevdct.c'\" \(14090 characters\)
  1055.   sed "s/^X//" >'jrevdct.c' <<'END_OF_FILE'
  1056. X/*
  1057. X * jrevdct.c
  1058. X *
  1059. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  1060. X * This file is part of the Independent JPEG Group's software.
  1061. X * For conditions of distribution and use, see the accompanying README file.
  1062. X *
  1063. X * This file contains the basic inverse-DCT transformation subroutine.
  1064. X *
  1065. X * This implementation is based on an algorithm described in
  1066. X *   C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
  1067. X *   Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
  1068. X *   Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
  1069. X * The primary algorithm described there uses 11 multiplies and 29 adds.
  1070. X * We use their alternate method with 12 multiplies and 32 adds.
  1071. X * The advantage of this method is that no data path contains more than one
  1072. X * multiplication; this allows a very simple and accurate implementation in
  1073. X * scaled fixed-point arithmetic, with a minimal number of shifts.
  1074. X */
  1075. X
  1076. X#include "jinclude.h"
  1077. X
  1078. X/*
  1079. X * This routine is specialized to the case DCTSIZE = 8.
  1080. X */
  1081. X
  1082. X#if DCTSIZE != 8
  1083. X  Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  1084. X#endif
  1085. X
  1086. X
  1087. X/*
  1088. X * A 2-D IDCT can be done by 1-D IDCT on each row followed by 1-D IDCT
  1089. X * on each column.  Direct algorithms are also available, but they are
  1090. X * much more complex and seem not to be any faster when reduced to code.
  1091. X *
  1092. X * The poop on this scaling stuff is as follows:
  1093. X *
  1094. X * Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
  1095. X * larger than the true IDCT outputs.  The final outputs are therefore
  1096. X * a factor of N larger than desired; since N=8 this can be cured by
  1097. X * a simple right shift at the end of the algorithm.  The advantage of
  1098. X * this arrangement is that we save two multiplications per 1-D IDCT,
  1099. X * because the y0 and y4 inputs need not be divided by sqrt(N).
  1100. X *
  1101. X * We have to do addition and subtraction of the integer inputs, which
  1102. X * is no problem, and multiplication by fractional constants, which is
  1103. X * a problem to do in integer arithmetic.  We multiply all the constants
  1104. X * by CONST_SCALE and convert them to integer constants (thus retaining
  1105. X * CONST_BITS bits of precision in the constants).  After doing a
  1106. X * multiplication we have to divide the product by CONST_SCALE, with proper
  1107. X * rounding, to produce the correct output.  This division can be done
  1108. X * cheaply as a right shift of CONST_BITS bits.  We postpone shifting
  1109. X * as long as possible so that partial sums can be added together with
  1110. X * full fractional precision.
  1111. X *
  1112. X * The outputs of the first pass are scaled up by PASS1_BITS bits so that
  1113. X * they are represented to better-than-integral precision.  These outputs
  1114. X * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
  1115. X * with the recommended scaling.  (To scale up 12-bit sample data further, an
  1116. X * intermediate INT32 array would be needed.)
  1117. X *
  1118. X * To avoid overflow of the 32-bit intermediate results in pass 2, we must
  1119. X * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26.  Error analysis
  1120. X * shows that the values given below are the most effective.
  1121. X */
  1122. X
  1123. X#ifdef EIGHT_BIT_SAMPLES
  1124. X#define CONST_BITS  13
  1125. X#define PASS1_BITS  2
  1126. X#else
  1127. X#define CONST_BITS  13
  1128. X#define PASS1_BITS  1        /* lose a little precision to avoid overflow */
  1129. X#endif
  1130. X
  1131. X#define ONE    ((INT32) 1)
  1132. X
  1133. X#define CONST_SCALE (ONE << CONST_BITS)
  1134. X
  1135. X/* Convert a positive real constant to an integer scaled by CONST_SCALE. */
  1136. X
  1137. X#define FIX(x)    ((INT32) ((x) * CONST_SCALE + 0.5))
  1138. X
  1139. X/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
  1140. X * causing a lot of useless floating-point operations at run time.
  1141. X * To get around this we use the following pre-calculated constants.
  1142. X * If you change CONST_BITS you may want to add appropriate values.
  1143. X * (With a reasonable C compiler, you can just rely on the FIX() macro...)
  1144. X */
  1145. X
  1146. X#if CONST_BITS == 13
  1147. X#define FIX_0_298631336  ((INT32)  2446)    /* FIX(0.298631336) */
  1148. X#define FIX_0_390180644  ((INT32)  3196)    /* FIX(0.390180644) */
  1149. X#define FIX_0_541196100  ((INT32)  4433)    /* FIX(0.541196100) */
  1150. X#define FIX_0_765366865  ((INT32)  6270)    /* FIX(0.765366865) */
  1151. X#define FIX_0_899976223  ((INT32)  7373)    /* FIX(0.899976223) */
  1152. X#define FIX_1_175875602  ((INT32)  9633)    /* FIX(1.175875602) */
  1153. X#define FIX_1_501321110  ((INT32)  12299)    /* FIX(1.501321110) */
  1154. X#define FIX_1_847759065  ((INT32)  15137)    /* FIX(1.847759065) */
  1155. X#define FIX_1_961570560  ((INT32)  16069)    /* FIX(1.961570560) */
  1156. X#define FIX_2_053119869  ((INT32)  16819)    /* FIX(2.053119869) */
  1157. X#define FIX_2_562915447  ((INT32)  20995)    /* FIX(2.562915447) */
  1158. X#define FIX_3_072711026  ((INT32)  25172)    /* FIX(3.072711026) */
  1159. X#else
  1160. X#define FIX_0_298631336  FIX(0.298631336)
  1161. X#define FIX_0_390180644  FIX(0.390180644)
  1162. X#define FIX_0_541196100  FIX(0.541196100)
  1163. X#define FIX_0_765366865  FIX(0.765366865)
  1164. X#define FIX_0_899976223  FIX(0.899976223)
  1165. X#define FIX_1_175875602  FIX(1.175875602)
  1166. X#define FIX_1_501321110  FIX(1.501321110)
  1167. X#define FIX_1_847759065  FIX(1.847759065)
  1168. X#define FIX_1_961570560  FIX(1.961570560)
  1169. X#define FIX_2_053119869  FIX(2.053119869)
  1170. X#define FIX_2_562915447  FIX(2.562915447)
  1171. X#define FIX_3_072711026  FIX(3.072711026)
  1172. X#endif
  1173. X
  1174. X
  1175. X/* Descale and correctly round an INT32 value that's scaled by N bits.
  1176. X * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
  1177. X * the fudge factor is correct for either sign of X.
  1178. X */
  1179. X
  1180. X#define DESCALE(x,n)  RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  1181. X
  1182. X/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
  1183. X * For 8-bit samples with the recommended scaling, all the variable
  1184. X * and constant values involved are no more than 16 bits wide, so a
  1185. X * 16x16->32 bit multiply can be used instead of a full 32x32 multiply;
  1186. X * this provides a useful speedup on many machines.
  1187. X * There is no way to specify a 16x16->32 multiply in portable C, but
  1188. X * some C compilers will do the right thing if you provide the correct
  1189. X * combination of casts.
  1190. X * NB: for 12-bit samples, a full 32-bit multiplication will be needed.
  1191. X */
  1192. X
  1193. X#ifdef EIGHT_BIT_SAMPLES
  1194. X#ifdef SHORTxSHORT_32        /* may work if 'int' is 32 bits */
  1195. X#define MULTIPLY(var,const)  (((INT16) (var)) * ((INT16) (const)))
  1196. X#endif
  1197. X#ifdef SHORTxLCONST_32        /* known to work with Microsoft C 6.0 */
  1198. X#define MULTIPLY(var,const)  (((INT16) (var)) * ((INT32) (const)))
  1199. X#endif
  1200. X#endif
  1201. X
  1202. X#ifndef MULTIPLY        /* default definition */
  1203. X#define MULTIPLY(var,const)  ((var) * (const))
  1204. X#endif
  1205. X
  1206. X
  1207. X/*
  1208. X * Perform the inverse DCT on one block of coefficients.
  1209. X */
  1210. X
  1211. XGLOBAL void
  1212. Xj_rev_dct (DCTBLOCK data)
  1213. X{
  1214. X  INT32 tmp0, tmp1, tmp2, tmp3;
  1215. X  INT32 tmp10, tmp11, tmp12, tmp13;
  1216. X  INT32 z1, z2, z3, z4, z5;
  1217. X  register DCTELEM *dataptr;
  1218. X  int rowctr;
  1219. X  SHIFT_TEMPS
  1220. X
  1221. X  /* Pass 1: process rows. */
  1222. X  /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
  1223. X  /* furthermore, we scale the results by 2**PASS1_BITS. */
  1224. X
  1225. X  dataptr = data;
  1226. X  for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
  1227. X    /* Due to quantization, we will usually find that many of the input
  1228. X     * coefficients are zero, especially the AC terms.  We can exploit this
  1229. X     * by short-circuiting the IDCT calculation for any row in which all
  1230. X     * the AC terms are zero.  In that case each output is equal to the
  1231. X     * DC coefficient (with scale factor as needed).
  1232. X     * With typical images and quantization tables, half or more of the
  1233. X     * row DCT calculations can be simplified this way.
  1234. X     */
  1235. X
  1236. X    if ((dataptr[1] | dataptr[2] | dataptr[3] | dataptr[4] |
  1237. X     dataptr[5] | dataptr[6] | dataptr[7]) == 0) {
  1238. X      /* AC terms all zero */
  1239. X      DCTELEM dcval = (DCTELEM) (dataptr[0] << PASS1_BITS);
  1240. X      
  1241. X      dataptr[0] = dcval;
  1242. X      dataptr[1] = dcval;
  1243. X      dataptr[2] = dcval;
  1244. X      dataptr[3] = dcval;
  1245. X      dataptr[4] = dcval;
  1246. X      dataptr[5] = dcval;
  1247. X      dataptr[6] = dcval;
  1248. X      dataptr[7] = dcval;
  1249. X      
  1250. X      dataptr += DCTSIZE;    /* advance pointer to next row */
  1251. X      continue;
  1252. X    }
  1253. X
  1254. X    /* Even part: reverse the even part of the forward DCT. */
  1255. X    /* The rotator is sqrt(2)*c(-6). */
  1256. X
  1257. X    z2 = (INT32) dataptr[2];
  1258. X    z3 = (INT32) dataptr[6];
  1259. X
  1260. X    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  1261. X    tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  1262. X    tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  1263. X
  1264. X    tmp0 = ((INT32) dataptr[0] + (INT32) dataptr[4]) << CONST_BITS;
  1265. X    tmp1 = ((INT32) dataptr[0] - (INT32) dataptr[4]) << CONST_BITS;
  1266. X
  1267. X    tmp10 = tmp0 + tmp3;
  1268. X    tmp13 = tmp0 - tmp3;
  1269. X    tmp11 = tmp1 + tmp2;
  1270. X    tmp12 = tmp1 - tmp2;
  1271. X    
  1272. X    /* Odd part per figure 8; the matrix is unitary and hence its
  1273. X     * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.
  1274. X     */
  1275. X
  1276. X    tmp0 = (INT32) dataptr[7];
  1277. X    tmp1 = (INT32) dataptr[5];
  1278. X    tmp2 = (INT32) dataptr[3];
  1279. X    tmp3 = (INT32) dataptr[1];
  1280. X
  1281. X    z1 = tmp0 + tmp3;
  1282. X    z2 = tmp1 + tmp2;
  1283. X    z3 = tmp0 + tmp2;
  1284. X    z4 = tmp1 + tmp3;
  1285. X    z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  1286. X    
  1287. X    tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  1288. X    tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  1289. X    tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  1290. X    tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  1291. X    z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  1292. X    z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  1293. X    z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  1294. X    z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  1295. X    
  1296. X    z3 += z5;
  1297. X    z4 += z5;
  1298. X    
  1299. X    tmp0 += z1 + z3;
  1300. X    tmp1 += z2 + z4;
  1301. X    tmp2 += z2 + z3;
  1302. X    tmp3 += z1 + z4;
  1303. X
  1304. X    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  1305. X
  1306. X    dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  1307. X    dataptr[7] = (DCTELEM) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  1308. X    dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  1309. X    dataptr[6] = (DCTELEM) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  1310. X    dataptr[2] = (DCTELEM) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  1311. X    dataptr[5] = (DCTELEM) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  1312. X    dataptr[3] = (DCTELEM) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  1313. X    dataptr[4] = (DCTELEM) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  1314. X
  1315. X    dataptr += DCTSIZE;        /* advance pointer to next row */
  1316. X  }
  1317. X
  1318. X  /* Pass 2: process columns. */
  1319. X  /* Note that we must descale the results by a factor of 8 == 2**3, */
  1320. X  /* and also undo the PASS1_BITS scaling. */
  1321. X
  1322. X  dataptr = data;
  1323. X  for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
  1324. X    /* Columns of zeroes can be exploited in the same way as we did with rows.
  1325. X     * However, the row calculation has created many nonzero AC terms, so the
  1326. X     * simplification applies less often (typically 5% to 10% of the time).
  1327. X     * On machines with very fast multiplication, it's possible that the
  1328. X     * test takes more time than it's worth.  In that case this section
  1329. X     * may be commented out.
  1330. X     */
  1331. X
  1332. X#ifndef NO_ZERO_COLUMN_TEST
  1333. X    if ((dataptr[DCTSIZE*1] | dataptr[DCTSIZE*2] | dataptr[DCTSIZE*3] |
  1334. X     dataptr[DCTSIZE*4] | dataptr[DCTSIZE*5] | dataptr[DCTSIZE*6] |
  1335. X     dataptr[DCTSIZE*7]) == 0) {
  1336. X      /* AC terms all zero */
  1337. X      DCTELEM dcval = (DCTELEM) DESCALE((INT32) dataptr[0], PASS1_BITS+3);
  1338. X      
  1339. X      dataptr[DCTSIZE*0] = dcval;
  1340. X      dataptr[DCTSIZE*1] = dcval;
  1341. X      dataptr[DCTSIZE*2] = dcval;
  1342. X      dataptr[DCTSIZE*3] = dcval;
  1343. X      dataptr[DCTSIZE*4] = dcval;
  1344. X      dataptr[DCTSIZE*5] = dcval;
  1345. X      dataptr[DCTSIZE*6] = dcval;
  1346. X      dataptr[DCTSIZE*7] = dcval;
  1347. X      
  1348. X      dataptr++;        /* advance pointer to next column */
  1349. X      continue;
  1350. X    }
  1351. X#endif
  1352. X
  1353. X    /* Even part: reverse the even part of the forward DCT. */
  1354. X    /* The rotator is sqrt(2)*c(-6). */
  1355. X
  1356. X    z2 = (INT32) dataptr[DCTSIZE*2];
  1357. X    z3 = (INT32) dataptr[DCTSIZE*6];
  1358. X
  1359. X    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  1360. X    tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  1361. X    tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  1362. X
  1363. X    tmp0 = ((INT32) dataptr[DCTSIZE*0] + (INT32) dataptr[DCTSIZE*4]) << CONST_BITS;
  1364. X    tmp1 = ((INT32) dataptr[DCTSIZE*0] - (INT32) dataptr[DCTSIZE*4]) << CONST_BITS;
  1365. X
  1366. X    tmp10 = tmp0 + tmp3;
  1367. X    tmp13 = tmp0 - tmp3;
  1368. X    tmp11 = tmp1 + tmp2;
  1369. X    tmp12 = tmp1 - tmp2;
  1370. X    
  1371. X    /* Odd part per figure 8; the matrix is unitary and hence its
  1372. X     * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.
  1373. X     */
  1374. X
  1375. X    tmp0 = (INT32) dataptr[DCTSIZE*7];
  1376. X    tmp1 = (INT32) dataptr[DCTSIZE*5];
  1377. X    tmp2 = (INT32) dataptr[DCTSIZE*3];
  1378. X    tmp3 = (INT32) dataptr[DCTSIZE*1];
  1379. X
  1380. X    z1 = tmp0 + tmp3;
  1381. X    z2 = tmp1 + tmp2;
  1382. X    z3 = tmp0 + tmp2;
  1383. X    z4 = tmp1 + tmp3;
  1384. X    z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  1385. X    
  1386. X    tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  1387. X    tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  1388. X    tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  1389. X    tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  1390. X    z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  1391. X    z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  1392. X    z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  1393. X    z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  1394. X    
  1395. X    z3 += z5;
  1396. X    z4 += z5;
  1397. X    
  1398. X    tmp0 += z1 + z3;
  1399. X    tmp1 += z2 + z4;
  1400. X    tmp2 += z2 + z3;
  1401. X    tmp3 += z1 + z4;
  1402. X
  1403. X    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
  1404. X
  1405. X    dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3,
  1406. X                       CONST_BITS+PASS1_BITS+3);
  1407. X    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3,
  1408. X                       CONST_BITS+PASS1_BITS+3);
  1409. X    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2,
  1410. X                       CONST_BITS+PASS1_BITS+3);
  1411. X    dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2,
  1412. X                       CONST_BITS+PASS1_BITS+3);
  1413. X    dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1,
  1414. X                       CONST_BITS+PASS1_BITS+3);
  1415. X    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1,
  1416. X                       CONST_BITS+PASS1_BITS+3);
  1417. X    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0,
  1418. X                       CONST_BITS+PASS1_BITS+3);
  1419. X    dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0,
  1420. X                       CONST_BITS+PASS1_BITS+3);
  1421. X    
  1422. X    dataptr++;            /* advance pointer to next column */
  1423. X  }
  1424. X}
  1425. END_OF_FILE
  1426.   if test 14090 -ne `wc -c <'jrevdct.c'`; then
  1427.     echo shar: \"'jrevdct.c'\" unpacked with wrong size!
  1428.   fi
  1429.   # end of 'jrevdct.c'
  1430. fi
  1431. if test -f 'makefile.manx' -a "${1}" != "-c" ; then 
  1432.   echo shar: Will not clobber existing file \"'makefile.manx'\"
  1433. else
  1434.   echo shar: Extracting \"'makefile.manx'\" \(6175 characters\)
  1435.   sed "s/^X//" >'makefile.manx' <<'END_OF_FILE'
  1436. X# Makefile for Independent JPEG Group's software
  1437. X
  1438. X# This makefile is for Amiga systems using Manx Aztec C ver 5.x.
  1439. X# Use jmemname.c as the system-dependent memory manager.
  1440. X# Thanks to D.J. James (djjames@cup.portal.com) for this version.
  1441. X
  1442. X# Read SETUP instructions before saying "make" !!
  1443. X
  1444. X# The name of your C compiler:
  1445. XCC= cc
  1446. X
  1447. X# You may need to adjust these cc options:
  1448. X# uncomment for generic 68000 code (will work on any Amiga)
  1449. XARCHFLAGS= -sn
  1450. X
  1451. X# uncomment for 68020/68030 code (faster, but won't run on 68000 CPU)
  1452. X#ARCHFLAGS= -c2
  1453. X
  1454. XCFLAGS= -MC -MD -DAMIGA -DTWO_FILE_COMMANDLINE -DNEED_SIGNAL_CATCHER \
  1455. X    -Dsignal_catcher=_abort -DSHORTxSHORT_32 $(ARCHFLAGS) -spfam -r4
  1456. X
  1457. X# Link-time cc options:
  1458. XLDFLAGS= -g
  1459. X
  1460. X# To link any special libraries, add the necessary -l commands here.
  1461. XLDLIBS= -lml -lcl
  1462. X
  1463. X# miscellaneous OS-dependent stuff
  1464. X# linker
  1465. XLN= ln
  1466. X# file deletion command
  1467. XRM= delete quiet
  1468. X# library (.lib) file creation command
  1469. XAR= lb
  1470. X
  1471. X
  1472. X# source files (independently compilable files)
  1473. XSOURCES= jbsmooth.c jcarith.c jccolor.c jcdeflts.c jcexpand.c jchuff.c \
  1474. X        jcmain.c jcmaster.c jcmcu.c jcpipe.c jcsample.c jdarith.c jdcolor.c \
  1475. X        jddeflts.c jdhuff.c jdmain.c jdmaster.c jdmcu.c jdpipe.c jdsample.c \
  1476. X        jerror.c jquant1.c jquant2.c jfwddct.c jrevdct.c jutils.c jmemmgr.c \
  1477. X        jrdjfif.c jrdgif.c jrdppm.c jrdrle.c jrdtarga.c jwrjfif.c jwrgif.c \
  1478. X        jwrppm.c jwrrle.c jwrtarga.c
  1479. X# virtual source files (not present in distribution file, see SETUP)
  1480. XVIRTSOURCES= jmemsys.c
  1481. X# system-dependent implementations of virtual source files
  1482. XSYSDEPFILES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemdos.h \
  1483. X        jmemdosa.asm
  1484. X# files included by source files
  1485. XINCLUDES= jinclude.h jconfig.h jpegdata.h jversion.h jmemsys.h
  1486. X# documentation, test, and support files
  1487. XDOCS= README SETUP USAGE CHANGELOG cjpeg.1 djpeg.1 architecture codingrules
  1488. XMAKEFILES= makefile.ansi makefile.unix makefile.manx makefile.sas \
  1489. X        makcjpeg.st makdjpeg.st makljpeg.st makefile.mc5 makefile.mc6 \
  1490. X        makefile.bcc makefile.mms makefile.vms makvms.opt
  1491. XOTHERFILES= ansi2knr.c ckconfig.c example.c
  1492. XTESTFILES= testorig.jpg testimg.ppm testimg.gif testimg.jpg
  1493. XDISTFILES= $(DOCS) $(MAKEFILES) $(SOURCES) $(SYSDEPFILES) $(INCLUDES) \
  1494. X        $(OTHERFILES) $(TESTFILES)
  1495. X# objectfiles common to cjpeg and djpeg
  1496. XCOMOBJECTS= jutils.o jerror.o jmemmgr.o jmemsys.o
  1497. X# compression objectfiles
  1498. XCLIBOBJECTS= jcmaster.o jcdeflts.o jcarith.o jccolor.o jcexpand.o jchuff.o \
  1499. X        jcmcu.o jcpipe.o jcsample.o jfwddct.o jwrjfif.o jrdgif.o jrdppm.o \
  1500. X        jrdrle.o jrdtarga.o
  1501. XCOBJECTS= jcmain.o $(CLIBOBJECTS) $(COMOBJECTS)
  1502. X# decompression objectfiles
  1503. XDLIBOBJECTS= jdmaster.o jddeflts.o jbsmooth.o jdarith.o jdcolor.o jdhuff.o \
  1504. X        jdmcu.o jdpipe.o jdsample.o jquant1.o jquant2.o jrevdct.o jrdjfif.o \
  1505. X        jwrgif.o jwrppm.o jwrrle.o jwrtarga.o
  1506. XDOBJECTS= jdmain.o $(DLIBOBJECTS) $(COMOBJECTS)
  1507. X# These objectfiles are included in libjpeg.lib
  1508. XLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
  1509. X
  1510. X
  1511. Xall: cjpeg djpeg
  1512. X# By default, libjpeg.lib is not built unless you explicitly request it.
  1513. X# You can add libjpeg.lib to the line above if you want it built by default.
  1514. X
  1515. X
  1516. Xcjpeg: $(COBJECTS)
  1517. X    $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) $(LDLIBS)
  1518. X
  1519. Xdjpeg: $(DOBJECTS)
  1520. X    $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) $(LDLIBS)
  1521. X
  1522. X# libjpeg.lib is useful if you are including the JPEG software in a larger
  1523. X# program; you'd include it in your link, rather than the individual modules.
  1524. Xlibjpeg.lib: $(LIBOBJECTS)
  1525. X    -$(RM) libjpeg.lib
  1526. X    $(AR) libjpeg.lib  $(LIBOBJECTS)
  1527. X
  1528. Xjmemsys.c:
  1529. X    echo You must select a system-dependent jmemsys.c file.
  1530. X    echo Please read the SETUP directions.
  1531. X    exit 1
  1532. X
  1533. Xclean:
  1534. X    -$(RM) *.o cjpeg djpeg libjpeg.lib core testout.*
  1535. X
  1536. Xdistribute:
  1537. X    -$(RM) jpegsrc.tar*
  1538. X    tar cvf jpegsrc.tar $(DISTFILES)
  1539. X    compress -v jpegsrc.tar
  1540. X
  1541. Xtest: cjpeg djpeg
  1542. X    -$(RM) testout.ppm testout.gif testout.jpg
  1543. X    djpeg testorig.jpg testout.ppm
  1544. X    djpeg -gif testorig.jpg testout.gif
  1545. X    cjpeg testimg.ppm testout.jpg
  1546. X    cmp testimg.ppm testout.ppm
  1547. X    cmp testimg.gif testout.gif
  1548. X    cmp testimg.jpg testout.jpg
  1549. X
  1550. X
  1551. Xjbsmooth.o : jbsmooth.c jinclude.h jconfig.h jpegdata.h 
  1552. Xjcarith.o : jcarith.c jinclude.h jconfig.h jpegdata.h 
  1553. Xjccolor.o : jccolor.c jinclude.h jconfig.h jpegdata.h 
  1554. Xjcdeflts.o : jcdeflts.c jinclude.h jconfig.h jpegdata.h 
  1555. Xjcexpand.o : jcexpand.c jinclude.h jconfig.h jpegdata.h 
  1556. Xjchuff.o : jchuff.c jinclude.h jconfig.h jpegdata.h 
  1557. Xjcmain.o : jcmain.c jinclude.h jconfig.h jpegdata.h jversion.h 
  1558. Xjcmaster.o : jcmaster.c jinclude.h jconfig.h jpegdata.h 
  1559. Xjcmcu.o : jcmcu.c jinclude.h jconfig.h jpegdata.h 
  1560. Xjcpipe.o : jcpipe.c jinclude.h jconfig.h jpegdata.h 
  1561. Xjcsample.o : jcsample.c jinclude.h jconfig.h jpegdata.h 
  1562. Xjdarith.o : jdarith.c jinclude.h jconfig.h jpegdata.h 
  1563. Xjdcolor.o : jdcolor.c jinclude.h jconfig.h jpegdata.h 
  1564. Xjddeflts.o : jddeflts.c jinclude.h jconfig.h jpegdata.h 
  1565. Xjdhuff.o : jdhuff.c jinclude.h jconfig.h jpegdata.h 
  1566. Xjdmain.o : jdmain.c jinclude.h jconfig.h jpegdata.h jversion.h 
  1567. Xjdmaster.o : jdmaster.c jinclude.h jconfig.h jpegdata.h 
  1568. Xjdmcu.o : jdmcu.c jinclude.h jconfig.h jpegdata.h 
  1569. Xjdpipe.o : jdpipe.c jinclude.h jconfig.h jpegdata.h 
  1570. Xjdsample.o : jdsample.c jinclude.h jconfig.h jpegdata.h 
  1571. Xjerror.o : jerror.c jinclude.h jconfig.h jpegdata.h 
  1572. Xjquant1.o : jquant1.c jinclude.h jconfig.h jpegdata.h 
  1573. Xjquant2.o : jquant2.c jinclude.h jconfig.h jpegdata.h 
  1574. Xjfwddct.o : jfwddct.c jinclude.h jconfig.h jpegdata.h 
  1575. Xjrevdct.o : jrevdct.c jinclude.h jconfig.h jpegdata.h 
  1576. Xjutils.o : jutils.c jinclude.h jconfig.h jpegdata.h 
  1577. Xjmemmgr.o : jmemmgr.c jinclude.h jconfig.h jpegdata.h jmemsys.h 
  1578. Xjrdjfif.o : jrdjfif.c jinclude.h jconfig.h jpegdata.h 
  1579. Xjrdgif.o : jrdgif.c jinclude.h jconfig.h jpegdata.h 
  1580. Xjrdppm.o : jrdppm.c jinclude.h jconfig.h jpegdata.h 
  1581. Xjrdrle.o : jrdrle.c jinclude.h jconfig.h jpegdata.h 
  1582. Xjrdtarga.o : jrdtarga.c jinclude.h jconfig.h jpegdata.h 
  1583. Xjwrjfif.o : jwrjfif.c jinclude.h jconfig.h jpegdata.h 
  1584. Xjwrgif.o : jwrgif.c jinclude.h jconfig.h jpegdata.h 
  1585. Xjwrppm.o : jwrppm.c jinclude.h jconfig.h jpegdata.h 
  1586. Xjwrrle.o : jwrrle.c jinclude.h jconfig.h jpegdata.h 
  1587. Xjwrtarga.o : jwrtarga.c jinclude.h jconfig.h jpegdata.h 
  1588. Xjmemsys.o : jmemsys.c jinclude.h jconfig.h jpegdata.h jmemsys.h 
  1589. END_OF_FILE
  1590.   if test 6175 -ne `wc -c <'makefile.manx'`; then
  1591.     echo shar: \"'makefile.manx'\" unpacked with wrong size!
  1592.   fi
  1593.   # end of 'makefile.manx'
  1594. fi
  1595. echo shar: End of archive 12 \(of 18\).
  1596. cp /dev/null ark12isdone
  1597. MISSING=""
  1598. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  1599.     if test ! -f ark${I}isdone ; then
  1600.     MISSING="${MISSING} ${I}"
  1601.     fi
  1602. done
  1603. if test "${MISSING}" = "" ; then
  1604.     echo You have unpacked all 18 archives.
  1605.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1606. else
  1607.     echo You still must unpack the following archives:
  1608.     echo "        " ${MISSING}
  1609. fi
  1610. exit 0
  1611. exit 0 # Just in case...
  1612.