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

  1. Newsgroups: comp.sources.misc
  2. From: jpeg-info@uunet.uu.net (Independent JPEG Group)
  3. Subject:  v34i063:  jpeg - JPEG image compression, Part09/18
  4. Message-ID: <1992Dec17.041849.23699@sparky.imd.sterling.com>
  5. X-Md4-Signature: 31715189cae6a7e3a9a26e8d63e5ad16
  6. Date: Thu, 17 Dec 1992 04:18:49 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 63
  11. Archive-name: jpeg/part09
  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:  SETUP architecture.A jinclude.h
  20. # Wrapped by kent@sparky on Wed Dec 16 20:52:28 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 9 (of 18)."'
  24. if test -f 'SETUP' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'SETUP'\"
  26. else
  27.   echo shar: Extracting \"'SETUP'\" \(26242 characters\)
  28.   sed "s/^X//" >'SETUP' <<'END_OF_FILE'
  29. XSETUP instructions for the Independent JPEG Group's JPEG software
  30. X=================================================================
  31. X
  32. XThis file explains how to configure and compile the JPEG software.  We have
  33. Xtried to make this software extremely portable and flexible, so that it can be
  34. Xadapted to almost any environment.  The downside of this decision is that the
  35. Xinstallation process is not very automatic; you will need at least a little
  36. Xfamiliarity with C programming and program build procedures for your system.
  37. X
  38. XThis file contains general instructions, then sections of specific hints for
  39. Xcertain systems.  You may save yourself considerable time if you scan the
  40. Xwhole file before starting to do anything.
  41. X
  42. XBefore installing the software you must unpack the distributed source code.
  43. XSince you are reading this file, you have probably already succeeded in this
  44. Xtask.  However, there is one potential trap if you are on a non-Unix system:
  45. Xyou may need to convert these files to the local standard text file format
  46. X(for example, if you are on MS-DOS you probably have to convert LF end-of-line
  47. Xto CR/LF).  If so, apply the conversion to all the files EXCEPT those whose
  48. Xnames begin with "test".  The test files contain binary data; if you change
  49. Xthem in any way then the self-test will give bad results.
  50. X
  51. X
  52. XSTEP 1: PREPARE A MAKEFILE
  53. X==========================
  54. X
  55. XFirst, select a makefile and copy it to "Makefile" (or whatever your version
  56. Xof make uses as the default makefile name; for example, "makefile.mak" for
  57. Xold versions of Borland C).  We include several standard makefiles in the
  58. Xdistribution:
  59. X
  60. X    makefile.ansi:    for Unix systems with ANSI-compatible C compilers.
  61. X    makefile.unix:    for Unix systems with non-ANSI C compilers.
  62. X    makefile.mc5:    for Microsoft C 5.x under MS-DOS.
  63. X    makefile.mc6:    for Microsoft C 6.x and up under MS-DOS.
  64. X    makefile.bcc:    for Borland C (Turbo C) under MS-DOS.
  65. X    makefile.manx:    for Manx Aztec C on Amigas.
  66. X    makefile.sas:    for SAS C on Amigas.
  67. X    makcjpeg.st:    project file for Atari ST/STE/TT Pure C or Turbo C.
  68. X    makdjpeg.st:    project file for Atari ST/STE/TT Pure C or Turbo C.
  69. X    makljpeg.st:    project file for Atari ST/STE/TT Pure C or Turbo C.
  70. X    makefile.mms:    for VAX/VMS systems with MMS.
  71. X    makefile.vms:    for VAX/VMS systems without MMS.
  72. X
  73. XIf you don't see a makefile for your system, we recommend starting from either
  74. Xmakefile.ansi or makefile.unix, depending on whether your compiler accepts
  75. XANSI C or not.  Actually you should start with makefile.ansi whenever your
  76. Xcompiler supports ANSI-style function definitions; you don't need full ANSI
  77. Xcompatibility.  The difference between the two makefiles is that makefile.unix
  78. Xpreprocesses the source code to convert function definitions to old-style C.
  79. X(Our thanks to Peter Deutsch of Aladdin Enterprises for the ansi2knr program.)
  80. X
  81. XIf you don't know whether your compiler supports ANSI-style function
  82. Xdefinitions, then take a look at ckconfig.c.  It is a test program that will
  83. Xhelp you figure out this fact, as well as some other facts you'll need in
  84. Xlater steps.  You must compile and execute ckconfig.c by hand; the makefiles
  85. Xdon't provide any support for this.  ckconfig.c may not compile the first try
  86. X(in fact, the whole idea is for it to fail if anything is going to).  If you
  87. Xget compile errors, fix them by editing ckconfig.c according to the directions
  88. Xgiven in ckconfig.c.  Once you get it to run, select a makefile according to
  89. Xthe advice it prints out, and make any other changes it recommends.
  90. X
  91. XLook over the selected Makefile and adjust options as needed.  In particular
  92. Xyou may want to change the CC and CFLAGS definitions.  For instance, if you
  93. Xare using GCC, set CC=gcc.  If you had to use any compiler switches to get
  94. Xckconfig.c to work, make sure the same switches are in CFLAGS.
  95. X
  96. XIf you are on a system that doesn't use makefiles, you'll need to set up
  97. Xproject files (or whatever you do use) to compile all the source files and
  98. Xlink them into executable files cjpeg and djpeg.  See the file lists in any of
  99. Xthe makefiles to find out which files go into each program.  As a last resort,
  100. Xyou can make a batch script that just compiles everything and links it all
  101. Xtogether; makefile.vms is an example of this (it's for VMS systems that have
  102. Xno make-like utility).
  103. X
  104. X
  105. XSTEP 2: EDIT JCONFIG.H
  106. X======================
  107. X
  108. XLook over jconfig.h and adjust #defines to reflect the properties of your
  109. Xsystem and C compiler.  If you prefer, you can usually leave jconfig.h
  110. Xunmodified and add -Dsymbol switches to the Makefile's CFLAGS definition.
  111. X(This is already done if you used a compiler-specific makefile in step 1.)
  112. XHowever, putting the switches in the Makefile is a bad idea if you are going
  113. Xto incorporate the JPEG software into other programs --- you'd need to include
  114. Xthe same -D switches in the other programs' Makefiles.  Better to change
  115. Xjconfig.h.
  116. X
  117. XIf you have an ANSI-compliant C compiler, no changes should be necessary
  118. Xexcept perhaps for RIGHT_SHIFT_IS_UNSIGNED and TWO_FILE_COMMANDLINE.  For
  119. Xolder compilers other changes may be needed, depending on what ANSI features
  120. Xare supported.
  121. X
  122. XIf you don't know enough about C programming to understand the questions in
  123. Xjconfig.h, then use ckconfig.c to figure out what to change.  (See description
  124. Xof ckconfig.c in step 1.)
  125. X
  126. XA note about TWO_FILE_COMMANDLINE: defining this selects the command line
  127. Xsyntax in which the input and output files are both named on the command line.
  128. XIf it's not defined, the output image goes to standard output, and the input
  129. Xcan optionally come from standard input.  You MUST use two-file style on any
  130. Xsystem that doesn't cope well with binary data fed through stdin/stdout; this
  131. Xis true for most MS-DOS compilers, for example.  If you're not on a Unix
  132. Xsystem, it's probably safest to assume you need two-file style.
  133. X
  134. X
  135. XSTEP 3: SELECT SYSTEM-DEPENDENT FILES
  136. X=====================================
  137. X
  138. XA few places in the JPEG software are so system-dependent that we have to
  139. Xprovide several different implementations and let you select the one you need.
  140. X
  141. XThe only system-dependent file in the current version is jmemsys.c.  This file
  142. Xcontrols use of temporary files for big images that won't fit in main memory.
  143. XYou'll notice there is no file named jmemsys.c in the distribution; you must
  144. Xselect one of the provided versions and copy, rename, or link it to jmemsys.c.
  145. XHere are the provided versions:
  146. X
  147. X    jmemansi.c    This is a reasonably portable version that should
  148. X            work on most ANSI and near-ANSI C compilers.  It uses
  149. X            the ANSI-standard library routine tmpfile(), which not
  150. X            all non-ANSI systems have.  On some systems tmpfile()
  151. X            may put the temporary file in a non-optimal location;
  152. X            if you don't like what it does, use jmemname.c.
  153. X
  154. X    jmemname.c    This version constructs the temp file name by itself.
  155. X            For anything except a Unix machine, you'll need to
  156. X            configure the select_file_name() routine appropriately;
  157. X            see the comments near the head of jmemname.c.
  158. X            If you use this version, define NEED_SIGNAL_CATCHER
  159. X            in jconfig.h or in the Makefile to make sure the temp
  160. X            files are removed if the program is aborted.
  161. X
  162. X    jmemnobs.c    (That stands for No Backing Store :-).  This will
  163. X            compile on almost any system, but it assumes you
  164. X            have enough main memory or virtual memory to hold
  165. X            the biggest images you need to work with.
  166. X
  167. X    jmemdos.c    This should be used in most MS-DOS installations; see
  168. X            the system-specific notes about MS-DOS for more info.
  169. X            IMPORTANT: if you use this, also copy jmemdos.h to
  170. X            jmemsys.h, replacing the standard version.  ALSO,
  171. X            include the assembly file jmemdosa.asm in the programs.
  172. X            (This last is already done if you used one of the
  173. X            supplied MS-DOS-specific makefiles.)
  174. X
  175. XIf you have plenty of (real or virtual) main memory, just use jmemnobs.c.
  176. X"Plenty" means at least ten bytes for every pixel in the largest images
  177. Xyou plan to process, so a lot of systems don't meet this criterion.
  178. XIf yours doesn't, try jmemansi.c first.  If that doesn't compile, you'll have
  179. Xto use jmemname.c; be sure to adjust select_file_name() for local conditions.
  180. XYou may also need to change unlink() to remove() in close_backing_store().
  181. X
  182. XExcept with jmemnobs.c, you need to adjust the #define DEFAULT_MAX_MEM to a
  183. Xreasonable value for your system (either by editing jmemsys.c, or by adding
  184. Xa -D switch to the Makefile).  This value limits the amount of data space the
  185. Xprogram will attempt to allocate.  Code and static data space isn't counted,
  186. Xso the actual memory needs for cjpeg or djpeg are typically 100 to 150Kb more
  187. Xthan the max-memory setting.  Larger max-memory settings reduce the amount of
  188. XI/O needed to process a large image, but too large a value can result in
  189. X"insufficient memory" failures.  On most Unix machines (and other systems with
  190. Xvirtual memory), just set DEFAULT_MAX_MEM to several million and forget it.
  191. XAt the other end of the spectrum, for MS-DOS machines you probably can't go
  192. Xmuch above 300K to 400K.  (On MS-DOS the value refers to conventional memory;
  193. Xextended/expanded memory is handled separately by jmemdos.c.)
  194. X
  195. X
  196. XSTEP 4: MAKE
  197. X============
  198. X
  199. XNow you should be able to "make" the software.
  200. X
  201. XIf you have trouble with missing system include files or inclusion of the
  202. Xwrong ones, look at jinclude.h (or use ckconfig.c, if you are not a C expert).
  203. X
  204. XIf your compiler complains about big_sarray_control and big_barray_control
  205. Xbeing undefined structures, you should be able to shut it up by adding
  206. X-DINCOMPLETE_TYPES_BROKEN to CFLAGS (or add #define INCOMPLETE_TYPES_BROKEN
  207. Xto jconfig.h).  If you don't have a getenv() library routine, define NO_GETENV.
  208. X
  209. XThere are a fair number of routines that do not use all of their parameters;
  210. Xsome compilers will issue warnings about this, which you can ignore.  Any
  211. Xother warning deserves investigation.
  212. X
  213. X
  214. XSTEP 5: TEST
  215. X============
  216. X
  217. XAs a quick test of functionality we've included a small sample image in
  218. Xseveral forms:
  219. X    testorig.jpg    A reduced section of the well-known Lenna picture.
  220. X    testimg.ppm    The output of djpeg testorig.jpg
  221. X    testimg.gif    The output of djpeg -gif testorig.jpg
  222. X    testimg.jpg    The output of cjpeg testimg.ppm
  223. X(The two .jpg files aren't identical since JPEG is lossy.)  If you can
  224. Xgenerate duplicates of the testimg.* files then you probably have working
  225. Xprograms.
  226. X
  227. XWith most of the makefiles, "make test" will perform the necessary
  228. Xcomparisons.  If you're using a makefile that doesn't provide this option, run
  229. Xdjpeg and cjpeg to generate testout.ppm, testout.gif, and testout.jpg, then
  230. Xcompare these to testimg.* with whatever binary file comparison tool you have.
  231. XThe files should be bit-for-bit identical.
  232. X
  233. XIf the cjpeg test run fails with "Missing Huffman code table entry", it's a
  234. Xgood bet that you needed to define RIGHT_SHIFT_IS_UNSIGNED.  Go back to step 2
  235. Xand run ckconfig.c.  (This is a good plan for any other test failure, too.)
  236. X
  237. XIf your choice of jmemsys.c was anything other than jmemnobs.c, you should
  238. Xtest that temporary-file usage works.  Try "djpeg -gif -max 0 testorig.jpg"
  239. Xand make sure its output matches testimg.gif.  If you have any really large
  240. Ximages handy, try compressing them with -optimize and/or decompressing with
  241. X-gif to make sure your DEFAULT_MAX_MEM setting is not too large.
  242. X
  243. XNOTE: this is far from an exhaustive test of the JPEG software; some modules,
  244. Xsuch as 1-pass color quantization, are not exercised at all.  It's just a quick
  245. Xtest to give you some confidence that you haven't missed something major.
  246. X
  247. X
  248. XSTEP 6: INSTALLATION
  249. X====================
  250. X
  251. XOnce you're done with the above steps, you can install the software by copying
  252. Xthe executable files (cjpeg and djpeg) to wherever you normally install
  253. Xprograms.  On Unix systems, you'll also want to put cjpeg.1 and djpeg.1 in the
  254. Xcorresponding manual directory.  (The makefiles don't support this step since
  255. Xthere's such a wide variety of installation procedures on different systems.)
  256. X
  257. XTo learn to use the programs, read the file USAGE (or manual pages cjpeg(1)
  258. Xand djpeg(1) on Unix).
  259. X
  260. X
  261. XOPTIMIZATION
  262. X============
  263. X
  264. XUnless you own a Cray, you'll probably be interested in making the JPEG
  265. Xsoftware go as fast as possible.  This section covers some machine-dependent
  266. Xoptimizations you may want to try.  We suggest that before trying any of this,
  267. Xyou first get the basic installation to pass the self-test (step 5 above).
  268. XRepeat the self-test after any optimization to make sure that you haven't
  269. Xbroken anything.
  270. X
  271. XThe JPEG DCT routines perform a lot of multiplications.  These multiplications
  272. Xmust yield 32-bit results, but none of their input values are more than 16
  273. Xbits wide.  On many machines, notably the 680x0 and 80x86 CPUs, a 16x16=>32
  274. Xbit multiply instruction is faster than a full 32x32=>32 bit multiply.
  275. XUnfortunately there is no portable way to specify such a multiplication in C,
  276. Xbut some compilers can generate one when you use the right combination of
  277. Xcasts.  See the MULTIPLY macro definitions in jfwddct.c and jrevdct.c.
  278. XIf your compiler makes "int" be 32 bits and "short" be 16 bits, defining
  279. XSHORTxSHORT_32 is fairly likely to work.  When experimenting with alternate
  280. Xdefinitions, be sure to test not only whether the code still works (use the
  281. Xself-test step), but also whether it is actually faster --- on some compilers,
  282. Xalternate definitions may compute the right answer, yet be slower than the
  283. Xdefault.  Timing cjpeg on a large PPM input file is the best way to check
  284. Xthis, as the DCT will be the largest fraction of the runtime in that mode.
  285. X(Note: some of the distributed compiler-specific makefiles already contain
  286. X-D switches to select an appropriate MULTIPLY definition.)
  287. X
  288. XIf access to "short" arrays is slow on your machine, it may be a win to define
  289. Xtype DCTELEM as int rather than as JCOEF (which is normally defined as short).
  290. XThis will cause the DCT routines to operate on int arrays instead of short
  291. Xarrays.  If shorts are slow and you have lots of memory to burn, you might
  292. Xeven make JCOEF itself be int.
  293. X
  294. XIf your compiler can compile function calls in-line, make sure the INLINE
  295. Xmacro in jconfig.h is defined as the keyword that marks a function
  296. Xinline-able.  Some compilers have a switch that tells the compiler to inline
  297. Xany function it thinks is profitable (e.g., -finline-functions for gcc).
  298. XEnabling such a switch is likely to make the compiled code bigger but faster.
  299. X
  300. XIn general, it's worth trying the maximum optimization level of your compiler,
  301. Xand experimenting with any optional optimizations such as loop unrolling.
  302. X(Unfortunately, far too many compilers have optimizer bugs ... be prepared to
  303. Xback off if the code fails self-test.)  If you do any experimentation along
  304. Xthese lines, please report the optimal settings to jpeg-info@uunet.uu.net so
  305. Xwe can mention them in future releases.  Be sure to specify your machine and
  306. Xcompiler version.
  307. X
  308. X
  309. XOPTIONAL STUFF
  310. X==============
  311. X
  312. XProgress monitor:
  313. X
  314. XIf you like, you can #define PROGRESS_REPORT (in jconfig.h or in the Makefile)
  315. Xto enable display of percent-done progress reports.  The routines provided in
  316. Xjcmain.c/jdmain.c merely print percentages to stderr, but you can customize
  317. Xthem to do something fancier.
  318. X
  319. XUtah RLE file format support:
  320. X
  321. XWe distribute the software with support for RLE image files (Utah Raster
  322. XToolkit format) disabled, because the RLE support won't compile without the
  323. XUtah library.  If you have URT version 3.0, you can enable RLE support as
  324. Xfollows:
  325. X    1.  #define RLE_SUPPORTED in jconfig.h or in the Makefile.
  326. X    2.  Add a -I option to CFLAGS in the Makefile for the directory
  327. X        containing the URT .h files (typically the "include"
  328. X        subdirectory of the URT distribution).
  329. X    3.  Add -L... -lrle to LDLIBS in the Makefile, where ... specifies
  330. X        the directory containing the URT "librle.a" file (typically the
  331. X        "lib" subdirectory of the URT distribution).
  332. X
  333. XJPEG library:
  334. X
  335. XIf you want to incorporate the JPEG code as subroutines in a larger program,
  336. Xwe recommend that you make libjpeg.a, then link that into your surrounding
  337. Xprogram.  See file README for more info.
  338. X
  339. XCAUTION: When you use the JPEG code as subroutines, we recommend that you make
  340. Xany required configuration changes by modifying jconfig.h, not by adding -D
  341. Xswitches to the Makefile.  Otherwise you must be sure to provide the same -D
  342. Xswitches when compiling any program that includes the JPEG .h files, to ensure
  343. Xthat the parameter structures are interpreted the same way.  (This is only
  344. Xcritical for the first few symbols mentioned in jconfig.h, down through
  345. XNEED_FAR_POINTERS.)
  346. X
  347. XRemoving code:
  348. X
  349. XIf you need to make a smaller version of the JPEG software, some optional
  350. Xfunctions can be removed at compile time.  See the xxx_SUPPORTED #defines in
  351. Xjconfig.h.  If at all possible, we recommend that you leave in decoder support
  352. Xfor all valid JPEG files, to ensure that you can read anyone's output.
  353. XRestricting your encoder, or removing optional functions like block smoothing,
  354. Xwon't hurt compatibility.  Taking out support for image file formats that you
  355. Xdon't use is the most painless way to make the programs smaller.
  356. X
  357. X
  358. XNOTES FOR SPECIFIC SYSTEMS
  359. X==========================
  360. X
  361. XWe welcome reports on changes needed for systems not mentioned here.
  362. XSubmit 'em to jpeg-info@uunet.uu.net.  Also, if ckconfig.c is wrong about
  363. Xhow to configure the JPEG software for your system, please let us know.
  364. X
  365. X
  366. XAmiga:
  367. X
  368. XMakefiles are provided for Manx Aztec C and SAS C.  I have also heard from
  369. Xpeople who have compiled with the free DICE compiler, using makefile.ansi as a
  370. Xstarting point (set "CC= dcc" and "CFLAGS= -c -DAMIGA -DTWO_FILE_COMMANDLINE
  371. X-DNEED_SIGNAL_CATCHER" in the makefile).  For all compilers, we recommend you
  372. Xuse jmemname.c as the system-dependent memory manager.  Assuming you have
  373. X-DAMIGA in the makefile, jmemname.c will put temporary files in JPEGTMP:.
  374. XChange jmemname.c if you don't like this.
  375. X
  376. X
  377. XAtari:
  378. X
  379. XThe project files provided should work as-is with Pure C.  For Turbo C, change
  380. Xlibrary filenames "PC..." to "TC..." in the project files for cjpeg.ttp and
  381. Xdjpeg.ttp.  Don't forget to select a jmemsys.c file, see Step 3 (we recommend
  382. Xjmemansi.c).  Also adjust the DEFAULT_MAX_MEM setting --- you probably want it
  383. Xto be a couple hundred K less than your normal free memory.  Note that you
  384. Xmust make jpeg.lib before making cjpeg.ttp or cjpeg.ttp.  You'll have to
  385. Xperform the self-test (Step 5) by hand.
  386. X
  387. XThere is a bug in some older versions of the Turbo C library which causes the
  388. Xspace used by temporary files created with "tmpfile()" not to be freed after
  389. Xan abnormal program exit.  If you check your disk afterwards, you will find
  390. Xcluster chains that are allocated but not used by a file.  This should not
  391. Xhappen in cjpeg or djpeg, since we enable a signal catcher to explicitly close
  392. Xtemp files before exiting.  But if you use the JPEG library with your own
  393. Xcode, be sure to supply a signal catcher, or else use a different
  394. Xsystem-dependent memory manager.
  395. X
  396. X
  397. XCray:
  398. X
  399. XShould you be so fortunate as to be running JPEG on a Cray YMP, there is a
  400. Xcompiler bug in Cray's Standard C versions prior to 3.1.  You'll need to
  401. Xinsert a line reading "#pragma novector" just before the loop    
  402. X    for (i = 1; i <= (int) htbl->bits[l]; i++)
  403. X      huffsize[p++] = (char) l;
  404. Xin fix_huff_tbl (in V3, line 42 of jchuff.c and line 38 of jdhuff.c).  The
  405. Xusual symptom of not adding this line is a core-dump.  See Cray's SPR 48222.
  406. X
  407. X
  408. XHP/Apollo DOMAIN:
  409. X
  410. XWith system release 10.4 or later, makefile.ansi should work OK.  If you have
  411. Xversion 10.3.anything, you need to figure out whether you have the ANSI C
  412. Xcompiler (version 6.7 or later) and whether you've installed the ANSI C
  413. Xinclude files (if so, the first line of <stdio.h> will mention ANSI C).
  414. XIf you have the ANSI C compiler but not the ANSI C include files, use
  415. Xmakefile.ansi and add -DNONANSI_INCLUDES to CFLAGS.  If you have both,
  416. Xthen makefile.ansi should work as is.  If neither, use makefile.unix.
  417. X
  418. X
  419. XHP-UX:
  420. X
  421. XIf you have HP-UX 7.05 or later with the "software development" C compiler,
  422. Xthen you can use makefile.ansi.  Add "-Aa" to the CFLAGS line in the makefile
  423. Xto make the compiler work in ANSI mode.  If you have a pre-7.05 system, or if
  424. Xyou are using the non-ANSI C compiler delivered with a minimum HP-UX 8.0
  425. Xsystem, then you must use makefile.unix (and do NOT add -Aa).  Also, adding
  426. X"-lmalloc" to LDLIBS is recommended if you have libmalloc.a (it seems not to
  427. Xbe present in minimum 8.0).
  428. X
  429. XOn HP 9000 series 800 machines, the HP C compiler is buggy in revisions prior
  430. Xto A.08.07.  If you get complaints about "not a typedef name", you'll have to
  431. Xconvert the code to K&R style (i.e., use makefile.unix).
  432. X
  433. X
  434. XMacintosh MPW:
  435. X
  436. XWe don't directly support MPW in the current release, but Larry Rosenstein
  437. Xreports that the JPEG code can be ported without very much trouble.  There's
  438. Xuseful notes and conversion scripts in his kit for porting PBMPLUS to MPW.
  439. XYou can obtain the kit by FTP to ftp.apple.com, file /pub/lsr/pbmplus-port*.
  440. X
  441. X
  442. XMacintosh Think C:
  443. X
  444. XYou'll have to prepare project files for cjpeg and djpeg; we don't include
  445. Xthose in the distribution since they are not text files.  The COBJECTS and
  446. XDOBJECTS lists in makefile.unix show which files should be included in each
  447. Xproject.  Also add the ANSI and Unix C libraries in a separate segment.  You
  448. Xmay need to divide the JPEG files into more than one segment; you can do this
  449. Xpretty much as you please.
  450. X
  451. XIf you have Think C version 5.0 you need not modify jconfig.h; instead you
  452. Xshould turn on both the ANSI Settings and Language Extensions option buttons
  453. X(so that both __STDC__ and THINK_C are predefined).  With version 4.0 you must
  454. Xedit jconfig.h.  (You can #define HAVE_STDC to do the right thing for all
  455. Xoptions except const; you must also #define const.)
  456. X
  457. Xjcmain and jdmain are set up to provide the usual command-line interface
  458. Xby means of Think's ccommand() library routine.  A more Mac-like interface
  459. Xis in the works.
  460. X
  461. X
  462. XMS-DOS, generic comments:
  463. X
  464. XThe JPEG code is designed to be compiled with 80x86 "small" or "medium" memory
  465. Xmodels (i.e., data pointers are 16 bits unless explicitly declared "far"; code
  466. Xpointers can be either size).  You should be able to use small model to
  467. Xcompile cjpeg or djpeg by itself, but you will probably have to go to medium
  468. Xmodel if you include the JPEG code in a larger application.  This shouldn't
  469. Xhurt performance much.  You *will* take a noticeable performance hit if you
  470. Xcompile in a large-data memory model, and you should avoid "huge" model if at
  471. Xall possible.  Be sure that NEED_FAR_POINTERS is defined by jconfig.h or by
  472. Xthe Makefile if you use a small-data model; be sure it is NOT defined if you
  473. Xuse a large-data memory model.  (As distributed, jconfig.h defines
  474. XNEED_FAR_POINTERS if MSDOS is defined.)
  475. X
  476. XThe DOS-specific memory manager, jmemdos.c, should be used if possible.
  477. X(Be sure to install jmemdos.h and jmemdosa.asm along with it.)  If you
  478. Xcan't use jmemdos.c for some reason --- for example, because you don't have
  479. Xa Microsoft-compatible assembler to assemble jmemdosa.asm --- you'll have
  480. Xto fall back to jmemansi.c or jmemname.c.  IMPORTANT: if you use either of
  481. Xthe latter two files, you will have to compile in a large-data memory model
  482. Xin order to get the right stdio library.  Too bad.
  483. X
  484. XNone of the above advice applies if you are using a 386 flat-memory-space
  485. Xenvironment, such as DJGPP or Watcom C.  (And you should use one if you have
  486. Xit, as performance will be much better than 8086-compatible code!)  For
  487. Xflat-memory-space compilers, do NOT define NEED_FAR_POINTERS, and do NOT use
  488. Xjmemdos.c.  Use jmemnobs.c if the environment supplies adequate virtual
  489. Xmemory, otherwise use jmemansi.c or jmemname.c.
  490. X
  491. XMost MS-DOS compilers treat stdin/stdout as text files, so you must use
  492. Xtwo-file command line style.  But if your compiler has the setmode() library
  493. Xroutine, you can define USE_SETMODE to get one-file style.  (Don't forget to
  494. Xchange the "make test" script in the Makefile if you do so.)
  495. X
  496. XIf you add more switches to CFLAGS in the DOS-specific makefiles, you are
  497. Xlikely to run up against DOS' 128-byte command line length limit.  In that
  498. Xcase, remove some "-Dsymbol" switches from CFLAGS and instead put
  499. Xcorresponding "#define symbol" lines at the head of jinclude.h.
  500. X
  501. X
  502. XMS-DOS, Borland C:
  503. X
  504. XBe sure to convert all the source files to DOS text format (CR/LF newlines).
  505. XAlthough Borland C will often work OK with unmodified Unix (LF newlines)
  506. Xsource files, sometimes it will give bogus compile errors.
  507. X"Illegal character '#'" is the most common such error.
  508. X
  509. XSome versions of Borland's MAKE erroneously display the warning message about
  510. Xcreating jmemsys.c, even after you have done so.  If this happens to you,
  511. Xdelete the four lines beginning with "jmemsys.c:" from the Makefile.
  512. X
  513. X
  514. XMS-DOS, DJGPP:
  515. X
  516. XUse makefile.ansi and jmemnobs.c, and put "-UMSDOS" in CFLAGS to undo the
  517. Xcompiler's automatic definition of MSDOS.  Also put either "-DUSE_SETMODE" or
  518. X"-DTWO_FILE_COMMANDLINE" in CFLAGS, depending on whether you prefer one-file
  519. Xor two-file command line style.  (If you choose two-file style, change the
  520. X"make test" section of the Makefile accordingly.)  You'll also need to put the
  521. Xobject-file lists into response files in order to circumvent DOS's 128-byte
  522. Xcommand line length limit at the final linking step.
  523. X
  524. X
  525. XMS-DOS, Microsoft C:
  526. X
  527. XOld versions of MS C fail with an "out of macro expansion space" error
  528. Xbecause they can't cope with the macro TRACEMS8 (defined in jpegdata.h).
  529. XIf this happens to you, the easiest solution is to change TRACEMS8 to
  530. Xexpand to nothing.  You'll lose the ability to dump out JPEG coefficient
  531. Xtables with djpeg -debug -debug, but at least you can compile.
  532. X
  533. XOriginal MS C 6.0 is buggy; it compiles incorrect code unless you turn off
  534. Xoptimization (remove -O from CFLAGS).  That problem seems to have been fixed
  535. Xin 6.00A and later versions.  6.00A still generates a bogus "conditional
  536. Xexpression is constant" warning in jrdppm.c, but the emitted code seems OK.
  537. X
  538. X
  539. XSGI:
  540. X
  541. XUse makefile.ansi, but set "AR2= ar -ts" rather than "AR2= ranlib".  Also
  542. Xmake any changes recommended by ckconfig.c.
  543. X
  544. X
  545. XSun:
  546. X
  547. XDon't forget to add -DBSD to CFLAGS.  If you are using GCC on SunOS 4.0.1 or
  548. Xearlier, you will need to add -DNONANSI_INCLUDES to CFLAGS (your compiler may
  549. Xbe ANSI, but your system include files aren't).  I've gotten conflicting
  550. Xreports on whether this is still necessary on SunOS 4.1 or later.
  551. END_OF_FILE
  552.   if test 26242 -ne `wc -c <'SETUP'`; then
  553.     echo shar: \"'SETUP'\" unpacked with wrong size!
  554.   fi
  555.   # end of 'SETUP'
  556. fi
  557. if test -f 'architecture.A' -a "${1}" != "-c" ; then 
  558.   echo shar: Will not clobber existing file \"'architecture.A'\"
  559. else
  560.   echo shar: Extracting \"'architecture.A'\" \(26089 characters\)
  561.   sed "s/^X//" >'architecture.A' <<'END_OF_FILE'
  562. X
  563. X    JPEG SYSTEM ARCHITECTURE        1-DEC-92
  564. X
  565. X
  566. XThis file provides an overview of the "architecture" of the portable JPEG
  567. Xsoftware; that is, the functions of the various modules in the system and the
  568. Xinterfaces between modules.  For more precise details about any data structure
  569. Xor calling convention, see the header files.
  570. X
  571. XImportant note: when I say "module" I don't mean "a C function", which is what
  572. Xsome people seem to think the term means.  A separate C source file is closer
  573. Xto the mark.  Also, it is frequently the case that several different modules
  574. Xpresent a common interface to callers; the term "object" or "method" refers to
  575. Xthis common interface (see "Poor man's object-oriented programming", below).
  576. X
  577. XJPEG-specific terminology follows the JPEG standard:
  578. X  A "component" means a color channel, e.g., Red or Luminance.
  579. X  A "sample" is a pixel component value (i.e., one number in the image data).
  580. X  A "coefficient" is a frequency coefficient (a DCT transform output number).
  581. X  The term "block" refers to an 8x8 group of samples or coefficients.
  582. X  "MCU" (minimum coded unit) is the same as "MDU" of the R8 draft; i.e., an
  583. X    interleaved set of blocks of size determined by the sampling factors,
  584. X    or a single block in a noninterleaved scan.
  585. X
  586. X
  587. X*** System requirements ***
  588. X
  589. XWe must support compression and decompression of both Huffman and
  590. Xarithmetic-coded JPEG files.  Any set of compression parameters allowed by the
  591. XJPEG spec should be readable for decompression.  (We can be more restrictive
  592. Xabout what formats we can generate.)  (Note: for legal reasons no arithmetic
  593. Xcoding implementation is currently included in the publicly available sources.
  594. XHowever, the architecture still supports it.)
  595. X
  596. XWe need to be able to handle both raw JPEG files (more specifically, the JFIF
  597. Xformat) and JPEG-in-TIFF (C-cubed's format, and perhaps Kodak's).  Even if we
  598. Xdon't implement TIFF ourselves, other people will want to use our code for
  599. Xthat.  This means that generation and scanning of the file header has to be
  600. Xseparated out.
  601. X
  602. XPerhaps we should be prepared to support the JPEG lossless mode (also referred
  603. Xto in the spec as spatial DPCM coding).  A lot of people seem to believe they
  604. Xneed this... whether they really do is debatable, but the customer is always
  605. Xright.  On the other hand, there will not be much sharable code between the
  606. Xlossless and lossy modes!  At best, a lossless program could be derived from
  607. Xparts of the lossy version.  For now we will only worry about the lossy mode.
  608. X
  609. XI see no real value in supporting the JPEG progressive modes (note that
  610. Xspectral selection and successive approximation are two different progressive
  611. Xmodes).  These are only of interest when painting the decompressed image in
  612. Xreal-time, which nobody is going to do with a pure software implementation.
  613. X
  614. XThere is some value in supporting the hierarchical mode, which allows for
  615. Xsuccessive frames of higher resolution.  This could be of use for including
  616. X"thumbnail" representations.  However, this appears to add a lot more
  617. Xcomplexity than it is worth.
  618. X
  619. XA variety of uncompressed image file formats and user interfaces must be
  620. Xsupported.  These aspects therefore have to be kept separate from the rest of
  621. Xthe system.  A particularly important issue is whether color quantization of
  622. Xthe output is needed (i.e., whether a colormap is used).  We should be able to
  623. Xsupport both adaptive quantization (which requires two or more passes over the
  624. Ximage) and nonadaptive (quantization to a prespecified colormap, which can be
  625. Xdone in one pass).
  626. X
  627. XMemory usage is an important concern, since we will port this code to 80x86
  628. Xand other limited-memory machines.  For large intermediate structures, we
  629. Xshould be able to use either virtual memory or temporary files.
  630. X
  631. XIt should be possible to build programs that handle compression only,
  632. Xdecompression only, or both, without much duplicate or unused code in any
  633. Xversion.  (In particular, a decompression-only version should have no extra
  634. Xbaggage.)
  635. X
  636. X
  637. X*** Compression overview ***
  638. X
  639. XThe *logical* steps needed in (non-lossless) JPEG compression are:
  640. X
  641. X1. Conversion from incoming image format to a standardized internal form
  642. X   (either RGB or grayscale).
  643. X
  644. X2. Color space conversion (e.g., RGB to YCbCr).  This is a null step for
  645. X   grayscale (unless we support mapping color inputs to grayscale, which
  646. X   would most easily be done here).  Gamma adjustment may also be needed here.
  647. X
  648. X3. Downsampling (reduction of number of samples in some color components).
  649. X   This step operates independently on each color component.
  650. X
  651. X4. MCU extraction (creation of a single sequence of 8x8 sample blocks).
  652. X   This step and the following ones are performed once for each scan
  653. X   in the output JPEG file, i.e., once if making an interleaved file and more
  654. X   than once for a noninterleaved file.
  655. X   Note: both this step and the previous one must deal with edge conditions
  656. X   for pictures that aren't a multiple of the MCU dimensions.  Alternately,
  657. X   we could expand the picture to a multiple of an MCU before doing these
  658. X   two steps.  (The latter seems better and has been adopted below.)
  659. X
  660. X5. DCT transformation of each 8x8 block.
  661. X
  662. X6. Quantization scaling and zigzag reordering of the elements in each 8x8
  663. X   block.
  664. X
  665. X7. Huffman or arithmetic encoding of the transformed block sequence.
  666. X
  667. X8. Output of the JPEG file with whatever headers/markers are wanted.
  668. X
  669. XOf course, the actual implementation will combine some of these logical steps
  670. Xfor efficiency.  The trick is to keep these logical functions as separate as
  671. Xpossible without losing too much performance.
  672. X
  673. XIn addition to these logical pipeline steps, we need various modules that
  674. Xaren't part of the data pipeline.  These are:
  675. X
  676. XA. Overall control (sequencing of other steps & management of data passing).
  677. X
  678. XB. User interface; this will determine the input and output files, and supply
  679. X   values for some compression parameters.  Note that this module is highly
  680. X   platform-dependent.
  681. X
  682. XC. Compression parameter selection: some parameters should be chosen
  683. X   automatically rather than requiring the user to find a good value.
  684. X   The prototype only does this for the back-end (Huffman or arithmetic)
  685. X   parameters, but further in the future, more might be done.  A
  686. X   straightforward approach to selection is to try several values; this
  687. X   requires being able to repeatedly apply some portion of the pipeline and
  688. X   inspect the results (without actually outputting them).  Probably only
  689. X   entropy encoding parameters can reasonably be done this way; optimizing
  690. X   earlier steps would require too much data to be reprocessed (not to mention
  691. X   the problem of interactions between parameters for different steps).
  692. X   What other facilities do we need to support automatic parameter selection?
  693. X
  694. XD. A memory management module to deal with small-memory machines.  This must
  695. X   create the illusion of virtual memory for certain large data structures
  696. X   (e.g., the downsampled image or the transformed coefficients).
  697. X   The interface to this must be defined to minimize the overhead incurred,
  698. X   especially on virtual-memory machines where the module won't do much.
  699. X
  700. XIn many cases we can arrange things so that a data stream is produced in
  701. Xsegments by one module and consumed by another without the need to hold it all
  702. Xin (virtual) memory.  This is obviously not possible for any data that must be
  703. Xscanned more than once, so it won't work everywhere.
  704. X
  705. XThe major variable at this level of detail is whether the JPEG file is to be
  706. Xinterleaved or not; that affects the order of processing so fundamentally that
  707. Xthe central control module must know about it.  Some of the other modules may
  708. Xneed to know it too.  It would simplify life if we didn't need to support
  709. Xnoninterleaved images, but that is not reasonable.
  710. X
  711. XMany of these steps operate independently on each color component; the
  712. Xknowledge of how many components there are, and how they are interleaved,
  713. Xought to be confined to the central control module.  (Color space conversion
  714. Xand MCU extraction probably have to know it too.)
  715. X
  716. X
  717. X*** Decompression overview ***
  718. X
  719. XDecompression is roughly the inverse process from compression, but there are
  720. Xsome additional steps needed to produce a good output image.
  721. X
  722. XThe *logical* steps needed in (non-lossless) JPEG decompression are:
  723. X
  724. X1. Scanning of the JPEG file, decoding of headers/markers etc.
  725. X
  726. X2. Huffman or arithmetic decoding of the coefficient sequence.
  727. X
  728. X3. Quantization descaling and zigzag reordering of the elements in each 8x8
  729. X   block.
  730. X
  731. X4. MCU disassembly (conversion of a possibly interleaved sequence of 8x8
  732. X   blocks back to separate components in pixel map order).
  733. X
  734. X5. (Optional)  Cross-block smoothing per JPEG section K.8 or a similar
  735. X   algorithm.  (Steps 5-8 operate independently on each component.)
  736. X
  737. X6. Inverse DCT transformation of each 8x8 block.
  738. X
  739. X7. Upsampling.  At this point a pixel image of the original dimensions
  740. X   has been recreated.
  741. X
  742. X8. Post-upsampling smoothing.  This can be combined with upsampling,
  743. X   by using a convolution-like calculation to generate each output pixel
  744. X   directly from one or more input pixels.
  745. X
  746. X9. Cropping to the original pixel dimensions (throwing away duplicated
  747. X   pixels at the edges).  It is most convenient to do this now, as the
  748. X   preceding steps are simplified by not having to worry about odd picture
  749. X   sizes.
  750. X
  751. X10. Color space reconversion (e.g., YCbCr to RGB).  This is a null step for
  752. X    grayscale.  (Note that mapping a color JPEG to grayscale output is most
  753. X    easily done in this step.)  Gamma adjustment may also be needed here.
  754. X
  755. X11. Color quantization (only if a colormapped output format is requested).
  756. X    NOTE: it is probably preferable to perform quantization in the internal
  757. X    (JPEG) colorspace rather than the output colorspace.  Doing it that way,
  758. X    color conversion need only be applied to the colormap entries, not to
  759. X    every pixel; and quantization gets to operate in a non-gamma-corrected
  760. X    space.  But the internal space may not be suitable for some algorithms.
  761. X    The system design is such that only the color quantizer module knows
  762. X    whether color conversion happens before or after quantization.
  763. X
  764. X12. Writing of the desired image format.
  765. X
  766. XAs before, some of these will be combined into single steps.  When dealing
  767. Xwith a noninterleaved JPEG file, steps 2-9 will be performed once for each
  768. Xscan; the resulting data will need to be buffered up so that steps 10-12 can
  769. Xprocess all the color components together.
  770. X
  771. XThe same auxiliary modules are needed as before, except for compression
  772. Xparameter selection.  Note that rerunning a pipeline stage should never be
  773. Xneeded during decompression.  This may allow a simpler control module.  The
  774. Xuser interface might also be simpler since it need not supply any compression
  775. Xparameters.
  776. X
  777. XAs before, not all of these steps require the whole image to be stored.
  778. XActually, two-pass color quantization is the only step that logically requires
  779. Xthis; everything else could be done a few raster lines at a time (at least for
  780. Xinterleaved images).  We might want to make color quantization be a separate
  781. Xprogram because of this fact.
  782. X
  783. XAgain, many of the steps should be able to work on one color component in
  784. Xignorance of the other components.
  785. X
  786. X
  787. X*** Implications of noninterleaved formats ***
  788. X
  789. XMuch of the work can be done in a single pass if an interleaved JPEG file
  790. Xformat is used.  With a noninterleaved JPEG file, separating or recombining
  791. Xthe components will force use of virtual memory (on a small-memory machine,
  792. Xwe probably would want one temp file per color component).
  793. X
  794. XIf any of the image formats we read or write are noninterleaved, the opposite
  795. Xcondition might apply: processing a noninterleaved JPEG file would be more
  796. Xefficient.  Offhand, though, I can't think of any popular image formats that
  797. Xwork that way; besides the win would only come if the same color space were
  798. Xused in JPEG and non-JPEG files.  It's not worth the complexity to make the
  799. Xsystem design accommodate that case efficiently.
  800. X
  801. XAn argument against interleaving is that it makes the decompressor need more
  802. Xmemory for cross-block smoothing (since the minimum processable chunk of the
  803. Ximage gets bigger).  With images more than 1000 pixels across, 80x86 machines
  804. Xare likely to have difficulty in handling this feature.
  805. X
  806. XAnother argument against interleaving is that the noninterleaved format allows
  807. Xa wider range of sampling factors, since the limit of ten blocks per MCU no
  808. Xlonger applies.  We could get around this by blithely ignoring the spec's
  809. Xlimit of ten blocks, but that seems like a bad idea (especially since it makes
  810. Xthe above problem worse).
  811. X
  812. XThe upshot is that we need to support both interleaved and noninterleaved JPEG
  813. Xformats, since for any given machine and picture size one may be much more
  814. Xefficient than the other.  However, the non-JPEG format we convert to or from
  815. Xwill be assumed to be an interleaved format (i.e., it produces or stores all
  816. Xthe components of a pixel together).
  817. X
  818. XI do not think it is necessary for the compressor to be able to output
  819. Xpartially-interleaved formats (multiple scans, some of which interleave a
  820. Xsubset of the components).  However, the decompressor must be able to read
  821. Xsuch files to conform to the spec.
  822. X
  823. X
  824. X*** Data formats ***
  825. X
  826. XPipeline steps that work on pixel sample values will use the following data
  827. Xstructure:
  828. X
  829. X    typedef something JSAMPLE;        a pixel component value, 0..MAXJSAMPLE
  830. X    typedef JSAMPLE *JSAMPROW;        ptr to a row of samples
  831. X    typedef JSAMPROW *JSAMPARRAY;    ptr to a list of rows
  832. X    typedef JSAMPARRAY *JSAMPIMAGE;    ptr to a list of color-component arrays
  833. X
  834. XThe basic element type JSAMPLE will be one of unsigned char, (signed) char, or
  835. Xunsigned short.  Unsigned short will be used if samples wider than 8 bits are
  836. Xto be supported (this is a compile-time option).  Otherwise, unsigned char is
  837. Xused if possible.  If the compiler only supports signed chars, then it is
  838. Xnecessary to mask off the value when reading.  Thus, all reads of sample
  839. Xvalues should be coded as "GETJSAMPLE(value)", where the macro will be defined
  840. Xas "((value)&0xFF)" on signed-char machines and "(value)" elsewhere.
  841. X
  842. XWith these conventions, JSAMPLE values can be assumed to be >= 0.  This should
  843. Xsimplify correct rounding during downsampling, etc.  The JPEG draft's
  844. Xspecification that sample values run from -128..127 will be accommodated by
  845. Xsubtracting 128 just as the sample value is copied into the source array for
  846. Xthe DCT step (this will be an array of signed shorts or longs).  Similarly,
  847. Xduring decompression the output of the IDCT step will be immediately shifted
  848. Xback to 0..255.  (NB: different values are required when 12-bit samples are in
  849. Xuse.  The code should be written in terms of MAXJSAMPLE and CENTERJSAMPLE,
  850. Xwhich will be #defined as 255 and 128 respectively in an 8-bit implementation,
  851. Xand as 4095 and 2048 in a 12-bit implementation.)
  852. X
  853. XOn compilers that don't support "unsigned short", signed short can be used for
  854. Xa 12-bit implementation.  To support lossless coding (which allows up to
  855. X16-bit data precision) masking with 0xFFFF in GETJSAMPLE might be necessary.
  856. X(But if "int" is 16 bits then using "unsigned int" is the best solution.)
  857. X
  858. XNotice that we use a pointer per row, rather than a two-dimensional JSAMPLE
  859. Xarray.  This choice costs only a small amount of memory and has several
  860. Xbenefits:
  861. X
  862. X* Code using the data structure doesn't need to know the allocated width of
  863. Xthe rows.  This will simplify edge expansion/compression, since we can work
  864. Xin an array that's wider than the logical picture width.
  865. X
  866. X* The rows forming a component array may be allocated at different times
  867. Xwithout extra copying.  This will simplify working a few scanlines at a time,
  868. Xespecially in smoothing steps that need access to the previous and next rows.
  869. X
  870. X* Indexing doesn't require multiplication; this is a performance win on many
  871. Xmachines.
  872. X
  873. XNote that each color component is stored in a separate array; we don't use the
  874. Xtraditional structure in which the components of a pixel are stored together.
  875. XThis simplifies coding of steps that work on each component independently,
  876. Xbecause they don't need to know how many components there are.  Furthermore,
  877. Xwe can read or write each component to a temp file independently, which is
  878. Xhelpful when dealing with noninterleaved JPEG files.
  879. X
  880. XA specific sample value will be accessed by code such as
  881. X    GETJSAMPLE(image[colorcomponent][row][col])
  882. Xwhere col is measured from the image left edge, but row is measured from the
  883. Xfirst sample row currently in memory.  Either of the first two indexings can
  884. Xbe precomputed by copying the relevant pointer.
  885. X
  886. X
  887. XPipeline steps that work on frequency-coefficient values will use the
  888. Xfollowing data structure:
  889. X
  890. X    typedef short JCOEF;        a 16-bit signed integer
  891. X    typedef JCOEF JBLOCK[64];        an 8x8 block of coefficients
  892. X    typedef JBLOCK *JBLOCKROW;        ptr to one horizontal row of 8x8 blocks
  893. X    typedef JBLOCKROW *JBLOCKARRAY;    ptr to a list of such rows
  894. X    typedef JBLOCKARRAY *JBLOCKIMAGE;    ptr to a list of color component arrays
  895. X
  896. XThe underlying type is always a 16-bit signed integer (this is "short" on all
  897. Xmachines of interest, but let's use the typedef name anyway).  These are
  898. Xgrouped into 8x8 blocks (we should use #defines DCTSIZE and DCTSIZE2 rather
  899. Xthan "8" and "64").  The contents of a block may be either in "natural" or
  900. Xzigzagged order, and may be true values or divided by the quantization
  901. Xcoefficients, depending on where the block is in the pipeline.
  902. X
  903. XNotice that the allocation unit is now a row of 8x8 blocks, corresponding to
  904. Xeight rows of samples.  Otherwise the structure is much the same as for
  905. Xsamples, and for the same reasons.
  906. X
  907. XOn machines where malloc() can't handle a request bigger than 64Kb, this data
  908. Xstructure limits us to rows of less than 512 JBLOCKs, which would be a picture
  909. Xwidth of 4000 pixels.  This seems an acceptable restriction.
  910. X
  911. X
  912. XOn 80x86 machines, the bottom-level pointer types (JSAMPROW and JBLOCKROW)
  913. Xmust be declared as "far" pointers, but the upper levels can be "near"
  914. X(implying that the pointer lists are allocated in the DS segment).
  915. XTo simplify sharing code, we'll have a #define symbol FAR, which expands to
  916. Xthe "far" keyword when compiling on 80x86 machines and to nothing elsewhere.
  917. X
  918. X
  919. XThe data arrays used as input and output of the DCT transform subroutine will
  920. Xbe declared using a separate typedef; they could be arrays of "short", "int"
  921. Xor "long" independently of the above choices.  This would depend on what is
  922. Xneeded to make the compiler generate correct and efficient multiply/add code
  923. Xin the DCT inner loops.  No significant speed or memory penalty will be paid
  924. Xto have a different representation than is used in the main image storage
  925. Xarrays, since some additional value-by-value processing is done at the time of
  926. Xcreation or extraction of the DCT data anyway (e.g., add/subtract 128).
  927. X
  928. X
  929. X*** Poor man's object-oriented programming ***
  930. X
  931. XIt should be pretty clear by now that we have a lot of quasi-independent
  932. Xsteps, many of which have several possible behaviors.  To avoid cluttering the
  933. Xcode with lots of switch statements, we'll use a simple form of object-style
  934. Xprogramming to separate out the different possibilities.
  935. X
  936. XFor example, Huffman and arithmetic coding will be implemented as two separate
  937. Xmodules that present the same external interface; at runtime, the calling code
  938. Xwill access the proper module indirectly through an "object".
  939. X
  940. XWe can get the limited features we need while staying within portable C.  The
  941. Xbasic tool is a function pointer.  An "object" is just a struct containing one
  942. Xor more function pointer fields, each of which corresponds to a method name in
  943. Xreal object-oriented languages.  During initialization we fill in the function
  944. Xpointers with references to whichever module we have determined we need to use
  945. Xin this run.  Then invocation of the module is done by indirecting through a
  946. Xfunction pointer; on most architectures this is no more expensive (and
  947. Xpossibly cheaper) than a switch, which would be the only other way of making
  948. Xthe required run-time choice.  The really significant benefit, of course, is
  949. Xkeeping the source code clean and well structured.
  950. X
  951. XFor example, the interface for entropy decoding (Huffman or arithmetic
  952. Xdecoding) might look like this:
  953. X
  954. X    struct function_ptr_struct {
  955. X        ...
  956. X        /* Entropy decoding methods */
  957. X        void (*prepare_for_scan) ();
  958. X        void (*get_next_mcu) ();
  959. X        ...
  960. X        };
  961. X
  962. X    typedef struct function_ptr_struct * function_ptrs;
  963. X
  964. XThe struct pointer is what will actually be passed around.  A call site might
  965. Xlook like this:
  966. X
  967. X    some_function (function_ptrs fptrs)
  968. X        {
  969. X        ...
  970. X        (*fptrs->get_next_mcu) (...);
  971. X        ...
  972. X        }
  973. X
  974. X(It might be worth inventing some specialized macros to hide the rather ugly
  975. Xsyntax for method definition and call.)  Note that the caller doesn't know how
  976. Xmany different get_next_mcu procedures there are, what their real names are,
  977. Xnor how to choose which one to call.
  978. X
  979. XAn important benefit of this scheme is that it is easy to provide multiple
  980. Xversions of any method, each tuned to a particular case.  While a lot of
  981. Xprecalculation might be done to select an optimal implementation of a method,
  982. Xthe cost per invocation is constant.  For example, the MCU extraction step
  983. Xmight have a "generic" method, plus one or more "hardwired" methods for the
  984. Xmost popular sampling factors; the hardwired methods would be faster because
  985. Xthey'd use straight-line code instead of for-loops.  The cost to determine
  986. Xwhich method to use is paid only once, at startup, and the selection criteria
  987. Xare hidden from the callers of the method.
  988. X
  989. XThis plan differs a little bit from usual object-oriented structures, in that
  990. Xonly one instance of each object class will exist during execution.  The
  991. Xreason for having the class structure is that on different runs we may create
  992. Xdifferent instances (choose to execute different modules).
  993. X
  994. XTo minimize the number of object pointers that have to be passed around, it
  995. Xwill be easiest to have just a few big structs containing all the method
  996. Xpointers.  We'll actually use two such structs, one for "system-dependent"
  997. Xmethods (memory allocation and error handling) and one for everything else.
  998. X
  999. XBecause of this choice, it's best not to think of an "object" as a specific
  1000. Xdata structure.  Rather, an "object" is just a group of related methods.
  1001. XThere would typically be one or more C modules (source files) providing
  1002. Xconcrete implementations of those methods.  You can think of the term
  1003. X"method" as denoting the common interface presented by some set of functions,
  1004. Xand "object" as denoting a group of common method interfaces, or the total
  1005. Xshared interface behavior of a group of modules.
  1006. X
  1007. X
  1008. X*** Data chunk sizes ***
  1009. X
  1010. XTo make the cost of this object-oriented style really minimal, we should make
  1011. Xsure that each method call does a fair amount of computation.  To do that we
  1012. Xshould pass large chunks of data around; for example, the colorspace
  1013. Xconversion method should process much more than one pixel per call.
  1014. X
  1015. XFor many steps, the most natural unit of data seems to be an "MCU row".
  1016. XThis consists of one complete horizontal strip of the image, as high as an
  1017. XMCU.  In a noninterleaved scan, an MCU row is always eight samples high (when
  1018. Xlooking at samples) or one 8x8 block high (when looking at coefficients).  In
  1019. Xan interleaved scan, an MCU row consists of all the data for one horizontal
  1020. Xrow of MCUs; this may be from one to four blocks high (eight to thirty-two
  1021. Xsamples) depending on the sampling factors.  The height and width of an MCU
  1022. Xrow may be different in each component.  (Note that the height and width of an
  1023. XMCU row changes at the downsampling and upsampling steps.  An unsubsampled
  1024. Ximage has the same size in each component.  The preceding statements apply to
  1025. Xthe downsampled dimensions.)
  1026. X
  1027. XFor example, consider a 1024-pixel-wide image using (2h:2v)(1h:1v)(1h:1v)
  1028. Xsubsampling.  In the noninterleaved case, an MCU row of Y would contain 8x1024
  1029. Xsamples or the same number of frequency coefficients, so it would occupy
  1030. X8K bytes (samples) or 16K bytes (coefficients).  An MCU row of Cb or Cr would
  1031. Xcontain 8x512 samples and occupy half as much space.  In the interleaved case,
  1032. Xan MCU row would contain 16x1024 Y samples, 8x512 Cb and 8x512 Cr samples, so
  1033. Xa total of 24K (samples) or 48K (coefficients) would be needed.  This is a
  1034. Xreasonable amount of data to expect to retain in memory at one time.  (Bear in
  1035. Xmind that we'll usually need to have several MCU rows resident in memory at
  1036. Xonce, at the inputs and outputs to various pipeline steps.)
  1037. X
  1038. XThe worst case is probably (2h:4v)(1h:1v)(1h:1v) interleaving (this uses 10
  1039. Xblocks per MCU, which is the maximum allowed by the spec).  An MCU will then
  1040. Xcontain 32 sample rows worth of Y, so it would occupy 40K or 80K bytes for a
  1041. X1024-pixel-wide image.  The most memory-intensive step is probably cross-block
  1042. Xsmoothing, for which we'd need 3 MCU rows of coefficients as input and another
  1043. Xone as output; that would be 320K of working storage.  Anything much larger
  1044. Xwould not fit in an 80x86 machine.  (To decompress wider pictures on an 80x86,
  1045. Xwe'll have to skip cross-block smoothing or else use temporary files.)
  1046. X
  1047. XThis unit is thus a reasonable-sized chunk for passing through the pipeline.
  1048. XOf course, its major advantage is that it is a natural chunk size for the MCU
  1049. Xassembly and disassembly steps to work with.
  1050. X
  1051. XFor the entropy (Huffman or arithmetic) encoding/decoding steps, the most
  1052. Xconvenient chunk is a single MCU: one 8x8 block if not interleaved, three to
  1053. Xten such blocks if interleaved.  The advantage of this is that when handling
  1054. Xinterleaved data, the blocks have the same sequence of component membership on
  1055. Xeach call.  (For example, Y,Y,Y,Y,Cb,Cr when using (2h:2v)(1h:1v)(1h:1v)
  1056. Xsubsampling.)  The code needs to know component membership so that it can
  1057. Xapply the right set of compression coefficients to each block.  A prebuilt
  1058. Xarray describing this membership can be used during each call.  This chunk
  1059. Xsize also makes it easy to handle restart intervals: just count off one MCU
  1060. Xper call and reinitialize when the count reaches zero (restart intervals are
  1061. Xspecified in numbers of MCU).
  1062. END_OF_FILE
  1063.   if test 26089 -ne `wc -c <'architecture.A'`; then
  1064.     echo shar: \"'architecture.A'\" unpacked with wrong size!
  1065.   elif test -f 'architecture.B'; then
  1066.     echo shar: Combining  \"'architecture'\" \(66550 characters\)
  1067.     cat 'architecture.A' 'architecture.B' > 'architecture'
  1068.     if test 66550 -ne `wc -c <'architecture'`; then
  1069.       echo shar: \"'architecture'\" combined with wrong size!
  1070.     else
  1071.       rm architecture.A architecture.B
  1072.     fi
  1073.   fi
  1074.   # end of 'architecture.A'
  1075. fi
  1076. if test -f 'jinclude.h' -a "${1}" != "-c" ; then 
  1077.   echo shar: Will not clobber existing file \"'jinclude.h'\"
  1078. else
  1079.   echo shar: Extracting \"'jinclude.h'\" \(3902 characters\)
  1080.   sed "s/^X//" >'jinclude.h' <<'END_OF_FILE'
  1081. X/*
  1082. X * jinclude.h
  1083. X *
  1084. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  1085. X * This file is part of the Independent JPEG Group's software.
  1086. X * For conditions of distribution and use, see the accompanying README file.
  1087. X *
  1088. X * This is the central file that's #include'd by all the JPEG .c files.
  1089. X * Its purpose is to provide a single place to fix any problems with
  1090. X * including the wrong system include files.
  1091. X * You can edit these declarations if you use a system with nonstandard
  1092. X * system include files.
  1093. X */
  1094. X
  1095. X
  1096. X/*
  1097. X * Normally the __STDC__ macro can be taken as indicating that the system
  1098. X * include files conform to the ANSI C standard.  However, if you are running
  1099. X * GCC on a machine with non-ANSI system include files, that is not the case.
  1100. X * In that case change the following, or add -DNONANSI_INCLUDES to your CFLAGS.
  1101. X */
  1102. X
  1103. X#ifdef __STDC__
  1104. X#ifndef NONANSI_INCLUDES
  1105. X#define INCLUDES_ARE_ANSI    /* this is what's tested before including */
  1106. X#endif
  1107. X#endif
  1108. X
  1109. X/*
  1110. X * <stdio.h> is included to get the FILE typedef and NULL macro.
  1111. X * Note that the core portable-JPEG files do not actually do any I/O
  1112. X * using the stdio library; only the user interface, error handler,
  1113. X * and file reading/writing modules invoke any stdio functions.
  1114. X * (Well, we did cheat a bit in jmemmgr.c, but only if MEM_STATS is defined.)
  1115. X */
  1116. X
  1117. X#include <stdio.h>
  1118. X
  1119. X/*
  1120. X * We need the size_t typedef, which defines the parameter type of malloc().
  1121. X * In an ANSI-conforming implementation this is provided by <stdio.h>,
  1122. X * but on non-ANSI systems it's more likely to be in <sys/types.h>.
  1123. X * On some not-quite-ANSI systems you may find it in <stddef.h>.
  1124. X */
  1125. X
  1126. X#ifndef INCLUDES_ARE_ANSI    /* shouldn't need this if ANSI C */
  1127. X#include <sys/types.h>
  1128. X#endif
  1129. X#ifdef __SASC            /* Amiga SAS C provides it in stddef.h. */
  1130. X#include <stddef.h>
  1131. X#endif
  1132. X
  1133. X/*
  1134. X * In ANSI C, and indeed any rational implementation, size_t is also the
  1135. X * type returned by sizeof().  However, it seems there are some irrational
  1136. X * implementations out there, in which sizeof() returns an int even though
  1137. X * size_t is defined as long or unsigned long.  To ensure consistent results
  1138. X * we always use this SIZEOF() macro in place of using sizeof() directly.
  1139. X */
  1140. X
  1141. X#undef SIZEOF            /* in case you included X11/xmd.h */
  1142. X#define SIZEOF(object)    ((size_t) sizeof(object))
  1143. X
  1144. X/*
  1145. X * fread() and fwrite() are always invoked through these macros.
  1146. X * On some systems you may need to twiddle the argument casts.
  1147. X * CAUTION: argument order is different from underlying functions!
  1148. X */
  1149. X
  1150. X#define JFREAD(file,buf,sizeofbuf)  \
  1151. X  ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  1152. X#define JFWRITE(file,buf,sizeofbuf)  \
  1153. X  ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  1154. X
  1155. X/*
  1156. X * We need the memcpy() and strcmp() functions, plus memory zeroing.
  1157. X * ANSI and System V implementations declare these in <string.h>.
  1158. X * BSD doesn't have the mem() functions, but it does have bcopy()/bzero().
  1159. X * Some systems may declare memset and memcpy in <memory.h>.
  1160. X *
  1161. X * NOTE: we assume the size parameters to these functions are of type size_t.
  1162. X * Change the casts in these macros if not!
  1163. X */
  1164. X
  1165. X#ifdef INCLUDES_ARE_ANSI
  1166. X#include <string.h>
  1167. X#define MEMZERO(target,size)    memset((void *)(target), 0, (size_t)(size))
  1168. X#define MEMCOPY(dest,src,size)    memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  1169. X#else /* not ANSI */
  1170. X#ifdef BSD
  1171. X#include <strings.h>
  1172. X#define MEMZERO(target,size)    bzero((void *)(target), (size_t)(size))
  1173. X#define MEMCOPY(dest,src,size)    bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  1174. X#else /* not BSD, assume Sys V or compatible */
  1175. X#include <string.h>
  1176. X#define MEMZERO(target,size)    memset((void *)(target), 0, (size_t)(size))
  1177. X#define MEMCOPY(dest,src,size)    memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  1178. X#endif /* BSD */
  1179. X#endif /* ANSI */
  1180. X
  1181. X
  1182. X/* Now include the portable JPEG definition files. */
  1183. X
  1184. X#include "jconfig.h"
  1185. X
  1186. X#include "jpegdata.h"
  1187. END_OF_FILE
  1188.   if test 3902 -ne `wc -c <'jinclude.h'`; then
  1189.     echo shar: \"'jinclude.h'\" unpacked with wrong size!
  1190.   fi
  1191.   # end of 'jinclude.h'
  1192. fi
  1193. echo shar: End of archive 9 \(of 18\).
  1194. cp /dev/null ark9isdone
  1195. MISSING=""
  1196. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  1197.     if test ! -f ark${I}isdone ; then
  1198.     MISSING="${MISSING} ${I}"
  1199.     fi
  1200. done
  1201. if test "${MISSING}" = "" ; then
  1202.     echo You have unpacked all 18 archives.
  1203.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1204. else
  1205.     echo You still must unpack the following archives:
  1206.     echo "        " ${MISSING}
  1207. fi
  1208. exit 0
  1209. exit 0 # Just in case...
  1210.