home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume29 / jpeg / part06 < prev    next >
Encoding:
Text File  |  1992-03-23  |  54.2 KB  |  1,183 lines

  1. Newsgroups: comp.sources.misc
  2. From: jpeg-info@uunet.uu.net (Independent JPEG Group)
  3. Subject:  v29i006:  jpeg - JPEG image compression, Part06/18
  4. Message-ID: <1992Mar24.144415.18233@sparky.imd.sterling.com>
  5. X-Md4-Signature: d57aff5041171c6dd059b5585e870ef2
  6. Date: Tue, 24 Mar 1992 14:44:15 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jpeg-info@uunet.uu.net (Independent JPEG Group)
  10. Posting-number: Volume 29, Issue 6
  11. Archive-name: jpeg/part06
  12. Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Cray
  13.  
  14. #! /bin/sh
  15. # into a shell via "sh file" or similar.  To overwrite existing files,
  16. # type "sh file -c".
  17. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  18. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  19. # Contents:  arch.b ckconfig.c jerror.c
  20. # Wrapped by kent@sparky on Mon Mar 23 16:02:43 1992
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. echo If this archive is complete, you will see the following message:
  23. echo '          "shar: End of archive 6 (of 18)."'
  24. if test -f 'arch.b' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'arch.b'\"
  26. else
  27.   echo shar: Extracting \"'arch.b'\" \(36460 characters\)
  28.   sed "s/^X//" >'arch.b' <<'END_OF_FILE'
  29. X2. Gamma and color space conversion.  This provides three methods:
  30. X    colorin_init: initialization.
  31. X    get_sample_rows: read, convert, and return a specified number of pixel
  32. X             rows (not more than remain in the picture).
  33. X    colorin_term: finish up at the end.
  34. X   The most efficient approach seems to be for this object to call
  35. X   get_input_row directly, rather than being passed the input data; that way,
  36. X   any intermediate storage required can be local to this object.
  37. X   (get_sample_rows might tell get_input_row to read directly into its own
  38. X   output area and then convert in place; or it may do something different.
  39. X   For example, conversion in place wouldn't work if it is changing the number
  40. X   of color components.)  The output of this step is in the standardized
  41. X   sample array format shown previously.
  42. X   (Hides all knowledge of color space semantics and conversion.  Remaining
  43. X   modules only need to know the number of JPEG components.)
  44. X
  45. X3. Edge expansion: needs only a single method.
  46. X    edge_expand: Given an NxM sample array, expand to a desired size (a
  47. X             multiple of the MCU dimensions) by duplicating the last
  48. X             row or column.  Repeat for each component.
  49. X   Expansion will occur in place, so the caller must have pre-allocated enough
  50. X   storage.  (I'm assuming that it is easier and faster to do this expansion
  51. X   than it is to worry about boundary conditions in the next two steps.
  52. X   Notice that vertical expansion will occur only once, at the bottom of the
  53. X   picture, so only horizontal expansion by a few pixels is speed-critical.)
  54. X   (This doesn't really hide any information, so maybe it could be a simple
  55. X   subroutine instead of a method.  Depends on whether we want to be able to
  56. X   use alternative, optimized methods.)
  57. X
  58. X4. Subsampling: this will be applied to one component at a time.
  59. X    subsample_init: initialize (precalculate convolution factors, for
  60. X            example).  This will be called once per scan.
  61. X    subsample: Given a sample array, reduce it to a smaller number of
  62. X           samples using specified sampling factors.
  63. X    subsample_term: clean up at the end of a scan.
  64. X   If the current component has vertical sampling factor Vk and the largest
  65. X   sampling factor is Vmax, then the input is always Vmax sample rows (whose
  66. X   width is a multiple of Hmax) and the output is always Vk sample rows.
  67. X   Vmax additional rows above and below the nominal input rows are also passed
  68. X   for use by partial-pixel-averaging sampling methods.  (Is this necessary?)
  69. X   At the top and bottom of the image, these extra rows are copies of the
  70. X   first or last actual input row.
  71. X   (This hides whether and how cross-pixel averaging occurs.)
  72. X
  73. X5. MCU extraction (creation of a single sequence of 8x8 sample blocks).
  74. X    extract_init: initialize as needed.  This will be called once per scan.
  75. X    extract_MCUs: convert a sample array to a sequence of MCUs.
  76. X    extract_term: clean up at the end of a scan.
  77. X   Given one or more MCU rows worth of image data, extract sample blocks in the
  78. X   appropriate order; pass these off to subsequent steps one MCU at a time.
  79. X   The input must be a multiple of the MCU dimensions.  It will probably be
  80. X   most convenient for the DCT transform, frequency quantization, and zigzag
  81. X   reordering of each block to be done as simple subroutines of this step.
  82. X   Once a transformed MCU has been completed, it'll be passed off to a
  83. X   method call, which will be passed as a parameter to extract_MCUs.
  84. X   That routine might either encode and output the MCU immediately, or buffer
  85. X   it up for later output if we want to do global optimization of the entropy
  86. X   encoding coefficients.  Note: when outputting a noninterleaved file this
  87. X   object will be called separately for each component.  Direct output could
  88. X   be done for the first component, but the others would have to be buffered.
  89. X   (Again, an object mainly on the grounds that multiple instantiations might
  90. X   be useful.)
  91. X
  92. X6. DCT transformation of each 8x8 block.  This probably doesn't have to be a
  93. X   full-fledged method, but just a plain subroutine that will be called by MCU
  94. X   extraction.  One 8x8 block will be processed per call.
  95. X
  96. X7. Quantization scaling and zigzag reordering of the elements in each 8x8
  97. X   block.  (This can probably be a plain subroutine called once per block by
  98. X   MCU extraction; hard to see a need for multiple instantiations here.)
  99. X
  100. X8. Entropy encoding (Huffman or arithmetic).
  101. X    entropy_encoder_init: prepare for one scan.
  102. X    entropy_encode: accepts an MCU's worth of quantized coefficients,
  103. X            encodes and outputs them.
  104. X    entropy_encoder_term: finish up at end of a scan (dump any buffered
  105. X                  bytes, for example).
  106. X   The data output by this module will be sent to the entropy_output method
  107. X   provided by the pipeline controller.  (It will probably be worth using
  108. X   buffering to pass multiple bytes per call of the output method.)  The
  109. X   output method could be just write_jpeg_data, but might also be a dummy
  110. X   routine that counts output bytes (for use during cut-and-try coefficient
  111. X   optimization).
  112. X   (This hides which entropy encoding method is in use.)
  113. X
  114. X9. JPEG file header construction.  This will provide these methods:
  115. X    write_file_header: output the initial header.
  116. X    write_scan_header: output scan header (called once per component
  117. X               if noninterleaved mode).
  118. X    write_jpeg_data: the actual data output method for the preceding step.
  119. X    write_scan_trailer: finish up after one scan.
  120. X    write_file_trailer: finish up at end of file.
  121. X   Note that compressed data is passed to the write_jpeg_data method, in case
  122. X   a simple fwrite isn't appropriate for some reason.
  123. X   (This hides which variant JPEG file format is being written.  Also, the
  124. X   actual mechanism for writing the file is private to this object and the
  125. X   user interface.)
  126. X
  127. X10. Pipeline control.  This object will provide the "main loop" that invokes
  128. X    all the pipeline objects.  Note that we will need several different main
  129. X    loops depending on the situation (interleaved output or not, global
  130. X    optimization of encoding parameters or not, etc).  This object will do
  131. X    most of the memory allocation, since it will provide the working buffers
  132. X    that are the inputs and outputs of the pipeline steps.
  133. X    (An object mostly to support multiple instantiations; however, overall
  134. X    memory management and sequencing of operations are known only here.)
  135. X
  136. X11. Overall control.  This module will provide at least two routines:
  137. X    jpeg_compress: the main entry point to the compressor.
  138. X    per_scan_method_selection: called by pipeline controllers for
  139. X                   secondary method selection passes.
  140. X    jpeg_compress is invoked from the user interface after the UI has selected
  141. X    the input and output files and obtained values for all compression
  142. X    parameters that aren't dynamically determined.  jpeg_compress performs
  143. X    basic initialization (e.g., calculating the size of MCUs), does the
  144. X    "global" method selection pass, and finally calls the selected pipeline
  145. X    control object.  (Per-scan method selections will be invoked by the
  146. X    pipeline controller.)
  147. X    Note that jpeg_compress can't be a method since it is invoked prior to
  148. X    method selection.
  149. X
  150. X12. User interface; this is the architecture's term for "the rest of the
  151. X    application program", i.e., that which invokes the JPEG compressor.  In a
  152. X    standalone JPEG compression program the UI need be little more than a C
  153. X    main() routine and argument parsing code; but we can expect that the JPEG
  154. X    compressor may be incorporated into complex graphics applications, wherein
  155. X    the UI is much more complex.  Much of the UI will need to be written
  156. X    afresh for each non-Unix-like platform the compressor is ported to.
  157. X    The UI is expected to supply input and output files and values for all
  158. X    non-automatically-chosen compression parameters.  (Hence defaults are
  159. X    determined by the UI; we should provide helpful routines to fill in
  160. X    the recommended defaults.)  The UI must also supply error handling
  161. X    routines and some mechanism for trace messages.
  162. X    (This module hides the user interface provided --- command line,
  163. X    interactive, etc.  Except for error/message handling, the UI calls the
  164. X    portable JPEG code, not the other way around.)
  165. X
  166. X13. (Optional) Compression parameter selection control.
  167. X    entropy_optimize: given an array of MCUs ready to be fed to entropy
  168. X              encoding, find optimal encoding parameters.
  169. X    The actual optimization algorithm ought to be separated out as an object,
  170. X    even though a special pipeline control method will be needed.  (The
  171. X    pipeline controller only has to understand that the output of extract_MCUs
  172. X    must be built up as a virtual array rather than fed directly to entropy
  173. X    encoding and output.  This pipeline behavior may also be useful for future
  174. X    implementation of hierarchical modes, etc.)
  175. X    To minimize the amount of control logic in the optimization module, the
  176. X    pipeline control doesn't actually hand over big-array pointers, but rather
  177. X    an "iterator": a function which knows how to scan the stored image.
  178. X    (This hides the details of the parameter optimization algorithm.)
  179. X
  180. X    The present design doesn't allow for multiple passes at earlier points
  181. X    in the pipeline, but allowing that would only require providing some
  182. X    new pipeline control methods; nothing else need change.
  183. X
  184. X14. A memory management object.  This will provide methods to allocate "small"
  185. X    things and "big" things.  Small things have to fit in memory and you get
  186. X    back direct pointers (this could be handled by direct calls to malloc, but
  187. X    it's cleaner not to assume malloc is the right routine).  "Big" things
  188. X    mean buffered images for multiple passes, noninterleaved output, etc.
  189. X    In this case the memory management object will give you room for a few MCU
  190. X    rows and you have to ask for access to the next few; dumping and reloading
  191. X    in a temporary file will go on behind the scenes.  (All big objects are
  192. X    image arrays containing either samples or coefficients, and will be
  193. X    scanned top-to-bottom some number of times, so we can apply this access
  194. X    model easily.)  On a platform with virtual memory, the memory manager can
  195. X    treat small and big things alike: just malloc up enough virtual memory for
  196. X    the whole image, and let the operating system worry about swapping the
  197. X    image to disk.
  198. X
  199. X    Most of the actual calls on the memory manager will be made from pipeline
  200. X    control objects; changing any data item from "small" to "big" status would
  201. X    require a new pipeline control object, since it will contain the logic to
  202. X    ask for a new chunk of a big thing.  Thus, one way in which pipeline
  203. X    controllers will vary is in which structures they treat as big.
  204. X
  205. X    The memory manager will need to be told roughly how much space is going to
  206. X    be requested overall, so that it can figure out how big a buffer is safe
  207. X    to allocate for a "big" object.  (If it happens that you are dealing with
  208. X    a small image, you'd like to decide to keep it all in memory!)  The most
  209. X    flexible way of doing this is to divide allocation of "big" objects into
  210. X    two steps.  First, there will be one or more "request" calls that indicate
  211. X    the desired object sizes; then an "instantiate" call causes the memory
  212. X    manager to actually construct the objects.  The instantiation must occur
  213. X    before the contents of any big object can be accessed.
  214. X
  215. X    For 80x86 CPUs, we would like the code to be compilable under small or
  216. X    medium model, meaning that pointers are 16 bits unless explicitly declared
  217. X    FAR.  Hence space allocated by the "small" allocator must fit into the
  218. X    64Kb default data segment, along with stack space and global/static data.
  219. X    For normal JPEG operations we seem to need only about 32Kb of such space,
  220. X    so we are within the target (and have a reasonable slop for the needs of
  221. X    a surrounding application program).  However, some color quantization
  222. X    algorithms need 64Kb or more of all-in-memory space in order to create
  223. X    color histograms.  For this purpose, we will also support "medium" size
  224. X    things.  These are semantically the same as "small" things but are
  225. X    referenced through FAR pointers.
  226. X
  227. X    The following methods will be needed:
  228. X    alloc_small:    allocate an object of given size; use for any random
  229. X            data that's not an image array.
  230. X    free_small:    release same.
  231. X    alloc_medium:    like alloc_small, but returns a FAR pointer.  Use for
  232. X            any object bigger than a couple kilobytes.
  233. X    free_medium:    release same.
  234. X    alloc_small_sarray: construct an all-in-memory image sample array.
  235. X    free_small_sarray:  release same.
  236. X    alloc_small_barray,
  237. X    free_small_barray:  ditto for block (coefficient) arrays.
  238. X    request_big_sarray:  request a virtual image sample array.  The size
  239. X                 of the in-memory buffer will be determined by the
  240. X                 memory manager, but it will always be a multiple
  241. X                 of the passed-in MCU height.
  242. X    request_big_barray:  ditto for block (coefficient) arrays.
  243. X    alloc_big_arrays:  instantiate all the big arrays previously requested.
  244. X               This call will also pass some info about future
  245. X               memory demands, so that the memory manager can
  246. X               figure out how much space to leave unallocated.
  247. X    access_big_sarray: obtain access to a specified portion of a virtual
  248. X               image sample array.
  249. X    free_big_sarray:   release a virtual sample array.
  250. X    access_big_barray,
  251. X    free_big_barray:   ditto for block (coefficient) arrays.
  252. X    free_all:       release any remaining storage.  This is called
  253. X               before normal or error termination; the main reason
  254. X               why it must exist is to ensure that any temporary
  255. X               files will be deleted upon error termination.
  256. X
  257. X    alloc_big_arrays will be called by the pipeline controller, which does
  258. X    most of the memory allocation anyway.  The only reason for having separate
  259. X    request calls is to allow some of the other modules to get big arrays.
  260. X    The pipeline controller is required to give an upper bound on total future
  261. X    small-array requests, so that this space can be discounted.  (A fairly
  262. X    conservative estimate will be adequate.)  Future small-object requests
  263. X    aren't counted; the memory manager has to use a slop factor for those.
  264. X    10K or so seems to be sufficient.  (In an 80x86, small objects aren't an
  265. X    issue anyway, since they don't compete for far-heap space.  "Medium"-size
  266. X    objects will have to be counted separately.)
  267. X
  268. X    The distinction between sample and coefficient array routines is annoying,
  269. X    but it has to be maintained for machines in which "char *" is represented
  270. X    differently from "int *".  On byte-addressable machines some of these
  271. X    methods could perhaps point to the same code.
  272. X
  273. X    The array routines will operate on only 2-D arrays (one component at a
  274. X    time), since different components may require different-size arrays.
  275. X
  276. X    (This object hides the knowledge of whether virtual memory is available,
  277. X    as well as the actual interface to OS and library support routines.)
  278. X
  279. XNote that any given implementation will presumably contain only one
  280. Xinstantiation of input file header reading, overall control, user interface,
  281. Xand memory management.  Thus these could be called as simple subroutines,
  282. Xwithout bothering with an object indirection.  This is essential for overall
  283. Xcontrol (which has to initialize the object structure); for consistency we
  284. Xwill impose objectness on the other three.
  285. X
  286. X
  287. X*** Decompression object structure ***
  288. X
  289. XI propose the following set of objects for decompression.  The general
  290. Xcomments at the top of the compression object section also apply here.
  291. X
  292. X1. JPEG file scanning.  This will provide these methods:
  293. X    read_file_header: read the file header, determine which variant
  294. X              JPEG format is in use, read everything through SOF.
  295. X    read_scan_header: read scan header (up through SOS).  This is called
  296. X              after read_file_header and again after each scan;
  297. X              it returns TRUE if it finds SOS, FALSE if EOI.
  298. X    read_jpeg_data: fetch data for entropy decoder.
  299. X    read_scan_trailer: finish up after one scan, prepare for another call
  300. X               of read_scan_header (may be a no-op).
  301. X    read_file_trailer: finish up at end of file (probably a no-op).
  302. X   The entropy decoder must deal with restart markers, but all other JPEG
  303. X   marker types will be handled in this object; useful data from the markers
  304. X   will be extracted into data structures available to subsequent routines.
  305. X   Note that on exit from read_file_header, only the SOF-marker data should be
  306. X   assumed valid (image size, component IDs, sampling factors); other data
  307. X   such as Huffman tables may not appear until after the SOF.  The overall
  308. X   image size and colorspace can be determined after read_file_header, but not
  309. X   whether or how the data is interleaved.  (This hides which variant JPEG
  310. X   file format is being read.  In particular, for JPEG-in-TIFF the read_header
  311. X   routines might not be scanning standard JPEG markers at all; they could
  312. X   extract the data from TIFF tags.  The user interface will already have
  313. X   opened the input file and possibly read part of the header before
  314. X   read_file_header is called.)
  315. X
  316. X   NOTE: for JFIF/raw-JPEG file format, the read_jpeg_data routine is actually
  317. X   supplied by the user interface; the jrdjfif module uses read_jpeg_data
  318. X   internally to scan the input stream.  This makes it possible for the user
  319. X   interface module to single-handedly implement special applications like
  320. X   reading from a non-stdio source.  For JPEG-in-TIFF format, the need for
  321. X   random access will make it impossible for this to work; hence the TIFF
  322. X   header module will override the UI-supplied read_jpeg_data routine.
  323. X   Non-stdio input from a TIFF file will require extensive surgery to the TIFF
  324. X   header module, if indeed it is practical at all.
  325. X
  326. X2. Entropy (Huffman or arithmetic) decoding of the coefficient sequence.
  327. X    entropy_decoder_init: prepare for one scan.
  328. X    entropy_decode: decodes and returns an MCU's worth of quantized
  329. X            coefficients per call.
  330. X    entropy_decoder_term: finish up after a scan (may be a no-op).
  331. X   This will read raw data by calling the read_jpeg_data method (I don't see
  332. X   any reason to provide a further level of indirection).
  333. X   (This hides which entropy encoding method is in use.)
  334. X
  335. X3. Quantization descaling and zigzag reordering of the elements in each 8x8
  336. X   block.  (This can probably be a plain subroutine called once per block;
  337. X   hard to see a need for multiple instantiations here.)
  338. X
  339. X4. MCU disassembly (conversion of a possibly interleaved sequence of 8x8
  340. X   blocks back to separate components in pixel map order).
  341. X    disassemble_init: initialize.  This will be called once per scan.
  342. X    disassemble_MCU:  Given an MCU's worth of dequantized blocks,
  343. X              distribute them into the proper locations in a
  344. X              coefficient image array.
  345. X    disassemble_term: clean up at the end of a scan.
  346. X   Probably this should be called once per MCU row and should call the
  347. X   preceding two objects repeatedly to obtain the row's data.  The output is
  348. X   always a multiple of an MCU's dimensions.
  349. X   (An object on the grounds that multiple instantiations might be useful.)
  350. X
  351. X5. Cross-block smoothing per JPEG section K.8 or a similar algorithm.
  352. X    smooth_coefficients: Given three block rows' worth of a single
  353. X                 component, emit a smoothed equivalent of the
  354. X                 middle row.  The "above" and "below" pointers
  355. X                 may be NULL if at top/bottom of image.
  356. X   The pipeline controller will do the necessary buffering to provide the
  357. X   above/below context.  Smoothing will be optional since a good deal of
  358. X   extra memory is needed to buffer the additional block rows.
  359. X   (This object hides the details of the smoothing algorithm.)
  360. X
  361. X6. Inverse DCT transformation of each 8x8 block.
  362. X    reverse_DCT: given an MCU row's worth of blocks, perform inverse
  363. X             DCT on each block and output the results into an array
  364. X             of samples.
  365. X   We put this method into the jdmcu module for symmetry with the division of
  366. X   labor in compression.  Note that the actual IDCT code is a separate source
  367. X   file.
  368. X
  369. X7. De-subsampling and smoothing: this will be applied to one component at a
  370. X   time.  Note that cross-pixel smoothing, which was a separate step in the
  371. X   prototype code, will now be performed simultaneously with expansion.
  372. X    unsubsample_init: initialize (precalculate convolution factors, for
  373. X              example).  This will be called once per scan.
  374. X    unsubsample: Given a sample array, enlarge it by specified sampling
  375. X             factors.
  376. X    unsubsample_term: clean up at the end of a scan.
  377. X   If the current component has vertical sampling factor Vk and the largest
  378. X   sampling factor is Vmax, then the input is always Vk sample rows (whose
  379. X   width is a multiple of Hk) and the output is always Vmax sample rows.
  380. X   Vk additional rows above and below the nominal input rows are also passed
  381. X   for use in cross-pixel smoothing.  At the top and bottom of the image,
  382. X   these extra rows are copies of the first or last actual input row.
  383. X   (This hides whether and how cross-pixel smoothing occurs.)
  384. X
  385. X8. Cropping to the original pixel dimensions (throwing away duplicated
  386. X   pixels at the edges).  This won't be a separate object, just an
  387. X   adjustment of the nominal image size in the pipeline controller.
  388. X
  389. X9. Color space reconversion and gamma adjustment.
  390. X    colorout_init: initialization.  This will be passed the component
  391. X               data from read_file_header, and will determine the
  392. X               number of output components.
  393. X    color_convert: convert a specified number of pixel rows.  Input and
  394. X               output are image arrays of same size but possibly
  395. X               different numbers of components.
  396. X    colorout_term: cleanup (probably a no-op except for memory dealloc).
  397. X   In practice will usually be given an MCU row's worth of pixel rows, except
  398. X   at the bottom where a smaller number of rows may be left over.  Note that
  399. X   this object works on all the components at once.
  400. X   When quantizing colors, color_convert may be applied to the colormap
  401. X   instead of actual pixel data.  color_convert is called by the color
  402. X   quantizer in this case; the pipeline controller calls color_convert
  403. X   directly only when not quantizing.
  404. X   (Hides all knowledge of color space semantics and conversion.  Remaining
  405. X   modules only need to know the number of JPEG and output components.)
  406. X
  407. X10. Color quantization (used only if a colormapped output format is requested).
  408. X    We use two different strategies depending on whether one-pass (on-the-fly)
  409. X    or two-pass quantization is requested.  Note that the two-pass interface
  410. X    is actually designed to let the quantizer make any number of passes.
  411. X    color_quant_init: initialization, allocate working memory.  In 1-pass
  412. X              quantization, should call put_color_map.
  413. X    color_quantize: convert a specified number of pixel rows.  Input
  414. X            and output are image arrays of same size, but input
  415. X            is N coefficients and output is only one.  (Used only
  416. X            in 1-pass quantization.)
  417. X    color_quant_prescan: prescan a specified number of pixel rows in
  418. X                 2-pass quantization.
  419. X    color_quant_doit: perform multi-pass color quantization.  Input is a
  420. X              "big" sample image, output is via put_color_map and
  421. X              put_pixel_rows.  (Used only in 2-pass quantization.)
  422. X    color_quant_term: cleanup (probably a no-op except for memory dealloc).
  423. X    The input to the color quantizer is always in the unconverted colorspace;
  424. X    its output colormap must be in the converted colorspace.  The quantizer
  425. X    has the choice of which space to work in internally.  It must call
  426. X    color_convert either on its input data or on the colormap it sends to the
  427. X    output module.
  428. X    For one-pass quantization the image is simply processed by color_quantize,
  429. X    a few rows at a time.  For two-pass quantization, the pipeline controller
  430. X    accumulates the output of steps 1-8 into a "big" sample image.  The
  431. X    color_quant_prescan method is invoked during this process so that the
  432. X    quantizer can accumulate statistics.  (If the input file has multiple
  433. X    scans, the prescan may be done during the final scan or as a separate
  434. X    pass.)  At the end of the image, color_quant_doit is called; it must
  435. X    create and output a colormap, then rescan the "big" image and pass mapped
  436. X    data to the output module.  Additional scans of the image could be made
  437. X    before the output pass is done (in fact, prescan could be a no-op).
  438. X    As with entropy parameter optimization, the pipeline controller actually
  439. X    passes an iterator function rather than direct access to the big image.
  440. X    (Hides color quantization algorithm.)
  441. X
  442. X11. Writing of the desired image format.
  443. X    output_init: produce the file header given data from read_file_header.
  444. X    put_color_map: output colormap, if any (called by color quantizer).
  445. X               If used, must be called before any pixel data is output.
  446. X    put_pixel_rows: output image data in desired format.
  447. X    output_term: finish up at the end.
  448. X    The actual timing of I/O may differ from that suggested by the routine
  449. X    names; for instance, writing of the file header may be delayed until
  450. X    put_color_map time if the actual number of colors is needed in the header.
  451. X    Also, the colormap is available to put_pixel_rows and output_term as well
  452. X    as put_color_map.
  453. X    Note that whether colormapping is needed will be determined by the user
  454. X    interface object prior to method selection.  In implementations that
  455. X    support multiple output formats, the actual output format will also be
  456. X    determined by the user interface.
  457. X    (Hides format of output image and mechanism used to write it.  Note that
  458. X    several other objects know the color model used by the output format.
  459. X    The actual mechanism for writing the file is private to this object and
  460. X    the user interface.)
  461. X
  462. X12. Pipeline control.  This object will provide the "main loop" that invokes
  463. X    all the pipeline objects.  Note that we will need several different main
  464. X    loops depending on the situation (interleaved input or not, whether to
  465. X    apply cross-block smoothing or not, etc).  We may want to divvy up the
  466. X    pipeline controllers into two levels, one that retains control over the
  467. X    whole file and one that is invoked per scan.
  468. X    This object will do most of the memory allocation, since it will provide
  469. X    the working buffers that are the inputs and outputs of the pipeline steps.
  470. X    (An object mostly to support multiple instantiations; however, overall
  471. X    memory management and sequencing of operations are known only here.)
  472. X
  473. X13. Overall control.  This module will provide at least two routines:
  474. X    jpeg_decompress: the main entry point to the decompressor.
  475. X    per_scan_method_selection: called by pipeline controllers for
  476. X                   secondary method selection passes.
  477. X    jpeg_decompress is invoked from the user interface after the UI has
  478. X    selected the input and output files and obtained values for all
  479. X    user-specified options (e.g., output file format, whether to do block
  480. X    smoothing).  jpeg_decompress calls read_file_header, performs basic
  481. X    initialization (e.g., calculating the size of MCUs), does the "global"
  482. X    method selection pass, and finally calls the selected pipeline control
  483. X    object.  (Per-scan method selections will be invoked by the pipeline
  484. X    controller.)
  485. X    Note that jpeg_decompress can't be a method since it is invoked prior to
  486. X    method selection.
  487. X
  488. X14. User interface; this is the architecture's term for "the rest of the
  489. X    application program", i.e., that which invokes the JPEG decompressor.
  490. X    The UI is expected to supply input and output files and values for all
  491. X    operational parameters.  The UI must also supply error handling routines.
  492. X    (This module hides the user interface provided --- command line,
  493. X    interactive, etc.  Except for error handling, the UI calls the portable
  494. X    JPEG code, not the other way around.)
  495. X
  496. X15. A memory management object.  This will be identical to the memory
  497. X    management for compression (and will be the same code, in combined
  498. X    programs).  See above for details.
  499. X
  500. X
  501. X*** Initial method selection ***
  502. X
  503. XThe main ugliness in this design is the portion of startup that will select
  504. Xwhich of several instantiations should be used for each of the objects.  (For
  505. Xexample, Huffman or arithmetic for entropy encoding; one of several pipeline
  506. Xcontrollers depending on interleaving, the size of the image, etc.)  It's not
  507. Xreally desirable to have a single chunk of code that knows the names of all
  508. Xthe possible instantiations and the conditions under which to select each one.
  509. X
  510. XThe best approach seems to be to provide a selector function for each object
  511. X(group of related method calls).  This function knows about each possible
  512. Xinstantiation of its object and how to choose the right one; but it doesn't
  513. Xknow about any other objects.
  514. X
  515. XNote that there will be several rounds of method selection: at initial startup,
  516. Xafter overall compression parameters are determined (after the file header is
  517. Xread, if decompressing), and one in preparation for each scan (this occurs
  518. Xmore than once if the file is noninterleaved).  Each object method will need
  519. Xto be clearly identified as to which round sets it up.
  520. X
  521. X
  522. X*** Implications of DNL marker ***
  523. X
  524. XSome JPEG files may use a DNL marker to postpone definition of the image
  525. Xheight (this would be useful for a fax-like scanner's output, for instance).
  526. XIn these files the SOF marker claims the image height is 0, and you only
  527. Xfind out the true image height at the end of the first scan.
  528. X
  529. XWe could handle these files as follows:
  530. X1. Upon seeing zero image height, replace it by 65535 (the maximum allowed).
  531. X2. When the DNL is found, update the image height in the global image
  532. X   descriptor.
  533. XThis implies that pipeline control objects must avoid making copies of the
  534. Ximage height, and must re-test for termination after each MCU row.  This is
  535. Xno big deal.
  536. X
  537. XIn situations where image-size data structures are allocated, this approach
  538. Xwill result in very inefficient use of virtual memory or
  539. Xmuch-larger-than-necessary temporary files.  This seems acceptable for
  540. Xsomething that probably won't be a mainstream usage.  People might have to
  541. Xforgo use of memory-hogging options (such as two-pass color quantization or
  542. Xnoninterleaved JPEG files) if they want efficient conversion of such files.
  543. X(One could improve efficiency by demanding a user-supplied upper bound for the
  544. Xheight, less than 65536; in most cases it could be much less.)
  545. X
  546. XAlternately, we could insist that DNL-using files be preprocessed by a
  547. Xseparate program that reads ahead to the DNL, then goes back and fixes the SOF
  548. Xmarker.  This is a much simpler solution and is probably far more efficient.
  549. XEven if one wants piped input, buffering the first scan of the JPEG file
  550. Xneeds a lot smaller temp file than is implied by the maximum-height method.
  551. XFor this approach we'd simply treat DNL as a no-op in the decompressor (at
  552. Xmost, check that it matches the SOF image height).
  553. X
  554. XWe will not worry about making the compressor capable of outputting DNL.
  555. XSomething similar to the first scheme above could be applied if anyone ever
  556. Xwants to make that work.
  557. X
  558. X
  559. X*** Memory manager internal structure ***
  560. X
  561. XThe memory manager contains the most potential for system dependencies.
  562. XTo isolate system dependencies as much as possible, we have broken the
  563. Xmemory manager into two parts.  There is a reasonably system-independent
  564. X"front end" (jmemmgr.c) and a "back end" that contains only the code
  565. Xlikely to change across systems.  All of the memory management methods
  566. Xoutlined above are implemented by the front end.  The back end provides
  567. Xthe following routines for use by the front end (none of these routines
  568. Xare known to the rest of the JPEG code):
  569. X
  570. Xjmem_init, jmem_term    system-dependent initialization/shutdown
  571. X
  572. Xjget_small, jfree_small    interface to malloc and free library routines
  573. X
  574. Xjget_large, jfree_large    interface to FAR malloc/free in MS-DOS machines;
  575. X            otherwise same as jget_small/jfree_small
  576. X
  577. Xjmem_available        estimate available memory
  578. X
  579. Xjopen_backing_store    create a backing-store object
  580. X
  581. Xread_backing_store,    manipulate a backing store object
  582. Xwrite_backing_store,
  583. Xclose_backing_store
  584. X
  585. XOn some systems there will be more than one type of backing-store object
  586. X(specifically, in MS-DOS a backing store file might be an area of extended
  587. Xmemory as well as a disk file).  jopen_backing_store is responsible for
  588. Xchoosing how to implement a given object.  The read/write/close routines
  589. Xare method pointers in the structure that describes a given object; this
  590. Xlets them be different for different object types.
  591. X
  592. XIt may be necessary to ensure that backing store objects are explicitly
  593. Xreleased upon abnormal program termination.  (For example, MS-DOS won't free
  594. Xextended memory by itself.)  To support this, we will expect the main program
  595. Xor surrounding application to arrange to call the free_all method upon
  596. Xabnormal termination; this may require a SIGINT signal handler, for instance.
  597. X(We don't want to have the system-dependent module install its own signal
  598. Xhandler, because that would pre-empt the surrounding application's ability
  599. Xto control signal handling.)
  600. X
  601. X
  602. X*** Notes for MS-DOS implementors ***
  603. X
  604. XThe standalone cjpeg and djpeg applications can be compiled in "small" memory
  605. Xmodel, at least at the moment; as the code grows we may be forced to switch to
  606. X"medium" model.  (Small = both code and data pointers are near by default;
  607. Xmedium = far code pointers, near data pointers.)  Medium model will slow down
  608. Xcalls through method pointers, but I don't think this will amount to any
  609. Xsignificant speed penalty.
  610. X
  611. XWhen integrating the JPEG code into a larger application, it's a good idea to
  612. Xstay with a small-data-space model if possible.  An 8K stack is much more than
  613. Xsufficient for the JPEG code, and its static data requirements are less than
  614. X1K.  When executed, it will typically malloc about 10K-20K worth of near heap
  615. Xspace (and lots of far heap, but that doesn't count in this calculation).
  616. XThis figure will vary depending on image size and other factors, but figuring
  617. X30K should be more than sufficient.  Thus you have about 25K available for
  618. Xother modules' static data and near heap requirements before you need to go to
  619. Xa larger memory model.  The C library's static data will account for several K
  620. Xof this, but that still leaves a good deal for your needs.  (If you are tight
  621. Xon space, you could reduce JPEG_BUF_SIZE from 4K to 1K to save 3K of near heap
  622. Xspace.)
  623. X
  624. XAs the code is improved, we will endeavor to hold the near data requirements
  625. Xto the range given above.  This does imply that certain data structures will
  626. Xbe allocated as FAR although they would fit in near space if we assumed the
  627. XJPEG code is stand-alone.  (The LZW tables in jrdgif/jwrgif are examples.)
  628. XTo make an optimal implementation, you might want to move these structures
  629. Xback to near heap if you know there is sufficient space.
  630. X
  631. XFAR data space may also be a tight resource when you are dealing with large
  632. Ximages.  The most memory-intensive case is decompression with two-pass color
  633. Xquantization.  This requires a 128Kb color histogram plus strip buffers
  634. Xamounting to about 150 bytes per column for typical sampling ratios (eg, about
  635. X96000 bytes for a 640-pixel-wide image).  You may not be able to process wide
  636. Ximages if you have large data structures of your own.
  637. X
  638. X
  639. X*** Potential optimizations ***
  640. X
  641. XFor colormapped input formats it might be worthwhile to merge the input file
  642. Xreading and the colorspace conversion steps; in other words, do the colorspace
  643. Xconversion by hacking up the colormap before inputting the image body, rather
  644. Xthan doing the conversion on each pixel independently.  Not clear if this is
  645. Xworth the uglification involved.  In the above design for the compressor, only
  646. Xthe colorspace conversion step ever sees the output of get_input_row, so this
  647. Xsort of thing could be done via private agreement between those two modules.
  648. X
  649. XLevel shift from 0..255 to -128..127 may be done either during colorspace
  650. Xconversion, or at the moment of converting an 8x8 sample block into the format
  651. Xused by the DCT step (which will be signed short or long int).  This could be
  652. Xselectable by a compile-time flag, so that the intermediate steps can work on
  653. Xeither signed or unsigned chars as samples, whichever is most easily handled
  654. Xby the platform.  However, making sure that rounding is done right will be a
  655. Xlot easier if we can assume positive values.  At the moment I think that
  656. Xbenefit is worth the overhead of "& 0xFF" when reading out sample values on
  657. Xsigned-char-only machines.
  658. END_OF_FILE
  659.   if test 36460 -ne `wc -c <'arch.b'`; then
  660.     echo shar: \"'arch.b'\" unpacked with wrong size!
  661.   elif [ -f arch.a ]; then
  662.     echo shar: Combining  \"'arch.a'\" and \"'arch.b'\" into \"'architecture'\"
  663.     cat arch.a arch.b > architecture
  664.     echo shar: Removing   \"'arch.a'\" and \"'arch.b'\"
  665.     rm arch.a arch.b
  666.   # end of 'arch.b'
  667.   fi
  668. fi
  669. if test -f 'ckconfig.c' -a "${1}" != "-c" ; then 
  670.   echo shar: Will not clobber existing file \"'ckconfig.c'\"
  671. else
  672.   echo shar: Extracting \"'ckconfig.c'\" \(12938 characters\)
  673.   sed "s/^X//" >'ckconfig.c' <<'END_OF_FILE'
  674. X/*
  675. X * ckconfig.c
  676. X *
  677. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  678. X * This file is part of the Independent JPEG Group's software.
  679. X * For conditions of distribution and use, see the accompanying README file.
  680. X */
  681. X
  682. X/*
  683. X * This program is intended to help you determine how to configure the JPEG
  684. X * software for installation on a particular system.  The idea is to try to
  685. X * compile and execute this program.  If your compiler fails to compile the
  686. X * program, make changes as indicated in the comments below.  Once you can
  687. X * compile the program, run it, and it will tell you how to set the various
  688. X * switches in jconfig.h and in your Makefile.
  689. X *
  690. X * This could all be done automatically if we could assume we were on a Unix
  691. X * system, but we don't want to assume that, so you'll have to edit and
  692. X * recompile this program until it works.
  693. X *
  694. X * As a general rule, each time you try to compile this program,
  695. X * pay attention only to the *first* error message you get from the compiler.
  696. X * Many C compilers will issue lots of spurious error messages once they
  697. X * have gotten confused.  Go to the line indicated in the first error message,
  698. X * and read the comments preceding that line to see what to change.
  699. X *
  700. X * Almost all of the edits you may need to make to this program consist of
  701. X * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL",
  702. X * or vice versa.  This is called defining or undefining that symbol.
  703. X */
  704. X
  705. X
  706. X/* First we must see if your system has the include files we need.
  707. X * We start out with the assumption that your system follows the ANSI
  708. X * conventions for include files.  If you get any error in the next dozen
  709. X * lines, undefine INCLUDES_ARE_ANSI.
  710. X */
  711. X
  712. X#define INCLUDES_ARE_ANSI    /* replace 'define' by 'undef' if error here */
  713. X
  714. X#ifdef INCLUDES_ARE_ANSI    /* this will be skipped if you undef... */
  715. X#include <stdio.h>        /* If you ain't got this, you ain't got C. */
  716. X#ifdef __SASC            /* Amiga SAS C provides size_t in stddef.h. */
  717. X#include <stddef.h>        /* (They are wrong...) */
  718. X#endif
  719. X#include <string.h>        /* size_t might be here too. */
  720. Xtypedef size_t my_size_t;    /* The payoff: do we have size_t now? */
  721. X#include <stdlib.h>        /* Check other ANSI includes we use. */
  722. X#endif
  723. X
  724. X
  725. X/* If your system doesn't follow the ANSI conventions, we have to figure out
  726. X * what it does follow.  If you didn't get an error before this line, you can
  727. X * ignore everything down to "#define HAVE_ANSI_DEFINITIONS".
  728. X */
  729. X
  730. X#ifndef INCLUDES_ARE_ANSI    /* skip these tests if INCLUDES_ARE_ANSI */
  731. X
  732. X#include <stdio.h>        /* If you ain't got this, you ain't got C. */
  733. X
  734. X/* jinclude.h will try to include <sys/types.h> if you don't set
  735. X * INCLUDES_ARE_ANSI.  We need to test whether that include file is provided.
  736. X * If you get an error here, undefine HAVE_TYPES_H.
  737. X */
  738. X
  739. X#define HAVE_TYPES_H
  740. X
  741. X#ifdef HAVE_TYPES_H
  742. X#include <sys/types.h>
  743. X#endif
  744. X
  745. X/* We have to see if your string functions are defined by
  746. X * strings.h (BSD convention) or string.h (everybody else).
  747. X * We try the non-BSD convention first; define BSD if the compiler
  748. X * says it can't find string.h.
  749. X */
  750. X
  751. X#undef BSD
  752. X
  753. X#ifdef BSD
  754. X#include <strings.h>
  755. X#else
  756. X#include <string.h>
  757. X#endif
  758. X
  759. X/* Usually size_t is defined in stdio.h, sys/types.h, and/or string.h.
  760. X * If not, you'll get an error on the "typedef size_t my_size_t;" line below.
  761. X * In that case, you'll have to search through your system library to
  762. X * figure out which include file defines "size_t".  Look for a line that
  763. X * says "typedef something-or-other size_t;" (stddef.h and stdlib.h are
  764. X * good places to look first).  Then, change the line below that says
  765. X * "#include <someincludefile.h>" to instead include the file
  766. X * you found size_t in, and define NEED_SPECIAL_INCLUDE.
  767. X */
  768. X
  769. X#undef NEED_SPECIAL_INCLUDE    /* assume we DON'T need it, for starters */
  770. X
  771. X#ifdef NEED_SPECIAL_INCLUDE
  772. X#include <someincludefile.h>
  773. X#endif
  774. X
  775. Xtypedef size_t my_size_t;    /* The payoff: do we have size_t now? */
  776. X
  777. X
  778. X#endif /* INCLUDES_ARE_ANSI */
  779. X
  780. X
  781. X
  782. X/* The next question is whether your compiler supports ANSI-style function
  783. X * definitions.  You need to know this in order to choose between using
  784. X * makefile.ansi and using makefile.unix.
  785. X * The #define line below is set to assume you have ANSI function definitions.
  786. X * If you get an error in this group of lines, undefine HAVE_ANSI_DEFINITIONS.
  787. X */
  788. X
  789. X#define HAVE_ANSI_DEFINITIONS
  790. X
  791. X#ifdef HAVE_ANSI_DEFINITIONS
  792. Xint testfunction (int arg1, int * arg2); /* check prototypes */
  793. X
  794. Xstruct methods_struct {        /* check method-pointer declarations */
  795. X  int (*error_exit) (char *msgtext);
  796. X  int (*trace_message) (char *msgtext);
  797. X  int (*another_method) (void);
  798. X};
  799. X
  800. Xint testfunction (int arg1, int * arg2) /* check definitions */
  801. X{
  802. X  return arg2[arg1];
  803. X}
  804. X
  805. Xint testfunction1 (void)    /* check void arg list */
  806. X{
  807. X  return 0;
  808. X}
  809. X#endif
  810. X
  811. X
  812. X/* Now we want to find out if your compiler knows what "unsigned char" means.
  813. X * If you get an error on the "unsigned char un_char;" line,
  814. X * then undefine HAVE_UNSIGNED_CHAR.
  815. X */
  816. X
  817. X#define HAVE_UNSIGNED_CHAR
  818. X
  819. X#ifdef HAVE_UNSIGNED_CHAR
  820. Xunsigned char un_char;
  821. X#endif
  822. X
  823. X
  824. X/* Now we want to find out if your compiler knows what "unsigned short" means.
  825. X * If you get an error on the "unsigned short un_short;" line,
  826. X * then undefine HAVE_UNSIGNED_SHORT.
  827. X */
  828. X
  829. X#define HAVE_UNSIGNED_SHORT
  830. X
  831. X#ifdef HAVE_UNSIGNED_SHORT
  832. Xunsigned short un_short;
  833. X#endif
  834. X
  835. X
  836. X/* Now we want to find out if your compiler understands type "void".
  837. X * If you get an error anywhere in here, undefine HAVE_VOID.
  838. X */
  839. X
  840. X#define HAVE_VOID
  841. X
  842. X#ifdef HAVE_VOID
  843. Xtypedef void * void_ptr;    /* check void * */
  844. Xtypedef void (*void_func) ();    /* check ptr to function returning void */
  845. X
  846. Xvoid testfunction2 (arg1, arg2)    /* check void function result */
  847. X     void_ptr arg1;
  848. X     void_func arg2;
  849. X{
  850. X  char * locptr = (char *) arg1; /* check casting to and from void * */
  851. X  arg1 = (void *) locptr;
  852. X  (*arg2) (1, 2);        /* check call of fcn returning void */
  853. X}
  854. X#endif
  855. X
  856. X
  857. X/* Now we want to find out if your compiler knows what "const" means.
  858. X * If you get an error here, undefine HAVE_CONST.
  859. X */
  860. X
  861. X#define HAVE_CONST
  862. X
  863. X#ifdef HAVE_CONST
  864. Xstatic const int carray[3] = {1, 2, 3};
  865. X
  866. Xint testfunction3 (arg1)
  867. X     const int arg1;
  868. X{
  869. X  return carray[arg1];
  870. X}
  871. X#endif
  872. X
  873. X
  874. X
  875. X/************************************************************************
  876. X *  OK, that's it.  You should not have to change anything beyond this
  877. X *  point in order to compile and execute this program.  (You might get
  878. X *  some warnings, but you can ignore them.)
  879. X *  When you run the program, it will make a couple more tests that it
  880. X *  can do automatically, and then it will print out a summary of the changes
  881. X *  that you need to make to the makefile and jconfig.h.
  882. X ************************************************************************
  883. X */
  884. X
  885. X
  886. Xstatic int any_changes = 0;
  887. X
  888. Xint new_change ()
  889. X{
  890. X  if (! any_changes) {
  891. X    printf("\nMost of the changes recommended by this program can be made either\n");
  892. X    printf("by editing jconfig.h, or by adding -Dsymbol switches to the CFLAGS\n");
  893. X    printf("line in your Makefile.  (Some PC compilers expect /Dsymbol instead.)\n");
  894. X    printf("The CFLAGS method is simpler, but if your system doesn't use makefiles,\n");
  895. X    printf("or if your compiler doesn't support -D, then you must change jconfig.h.\n");
  896. X    any_changes = 1;
  897. X  }
  898. X  printf("\n");            /* blank line before each problem report */
  899. X  return 0;
  900. X}
  901. X
  902. X
  903. Xint test_char_sign (arg)
  904. X     int arg;
  905. X{
  906. X  if (arg == 189) {        /* expected result for unsigned char */
  907. X    new_change();
  908. X    printf("You should add -DCHAR_IS_UNSIGNED to CFLAGS,\n");
  909. X    printf("or else remove the /* */ comment marks from the line\n");
  910. X    printf("/* #define CHAR_IS_UNSIGNED */  in jconfig.h.\n");
  911. X    printf("(Be sure to delete the space before the # character too.)\n");
  912. X  }
  913. X  else if (arg != -67) {    /* expected result for signed char */
  914. X    new_change();
  915. X    printf("Hmm, it seems 'char' is less than eight bits wide on your machine.\n");
  916. X    printf("I fear the JPEG software will not work at all.\n");
  917. X  }
  918. X  return 0;
  919. X}
  920. X
  921. X
  922. Xint test_shifting (arg)
  923. X     long arg;
  924. X/* See whether right-shift on a long is signed or not. */
  925. X{
  926. X  long res = arg >> 4;
  927. X
  928. X  if (res == 0x80817F4L) {    /* expected result for unsigned */
  929. X    new_change();
  930. X    printf("You must add -DRIGHT_SHIFT_IS_UNSIGNED to CFLAGS,\n");
  931. X    printf("or else remove the /* */ comment marks from the line\n");
  932. X    printf("/* #define RIGHT_SHIFT_IS_UNSIGNED */  in jconfig.h.\n");
  933. X  }
  934. X  else if (res != -0x7F7E80CL) { /* expected result for signed */
  935. X    new_change();
  936. X    printf("Right shift isn't acting as I expect it to.\n");
  937. X    printf("I fear the JPEG software will not work at all.\n");
  938. X  }
  939. X  return 0;
  940. X}
  941. X
  942. X
  943. Xint main (argc, argv)
  944. X     int argc;
  945. X     char ** argv;
  946. X{
  947. X  char signed_char_check = (char) (-67);
  948. X
  949. X  printf("Results of configuration check for Independent JPEG Group's software:\n");
  950. X  printf("\nIf there's not a specific makefile provided for your compiler,\n");
  951. X#ifdef HAVE_ANSI_DEFINITIONS
  952. X  printf("you should use makefile.ansi as the starting point for your Makefile.\n");
  953. X#else
  954. X  printf("you should use makefile.unix as the starting point for your Makefile.\n");
  955. X#endif
  956. X
  957. X  /* Check whether we have all the ANSI features, */
  958. X  /* and whether this agrees with __STDC__ being predefined. */
  959. X#ifdef __STDC__
  960. X#define HAVE_STDC    /* ANSI compilers won't allow redefining __STDC__ */
  961. X#endif
  962. X
  963. X#ifdef HAVE_ANSI_DEFINITIONS
  964. X#ifdef HAVE_UNSIGNED_CHAR
  965. X#ifdef HAVE_UNSIGNED_SHORT
  966. X#ifdef HAVE_CONST
  967. X#define HAVE_ALL_ANSI_FEATURES
  968. X#endif
  969. X#endif
  970. X#endif
  971. X#endif
  972. X
  973. X#ifdef HAVE_ALL_ANSI_FEATURES
  974. X#ifndef HAVE_STDC
  975. X  new_change();
  976. X  printf("Your compiler doesn't claim to be ANSI-compliant, but it is close enough\n");
  977. X  printf("for me.  Either add -DHAVE_STDC to CFLAGS, or add #define HAVE_STDC at the\n");
  978. X  printf("beginning of jconfig.h.\n");
  979. X#define HAVE_STDC
  980. X#endif
  981. X#else /* !HAVE_ALL_ANSI_FEATURES */
  982. X#ifdef HAVE_STDC
  983. X  new_change();
  984. X  printf("Your compiler claims to be ANSI-compliant, but it is lying!\n");
  985. X  printf("Delete the line  #define HAVE_STDC  near the beginning of jconfig.h.\n");
  986. X#undef HAVE_STDC
  987. X#endif
  988. X#endif /* HAVE_ALL_ANSI_FEATURES */
  989. X
  990. X#ifndef HAVE_STDC
  991. X
  992. X#ifdef HAVE_ANSI_DEFINITIONS
  993. X  new_change();
  994. X  printf("You should add -DPROTO to CFLAGS, or else take out the several\n");
  995. X  printf("#ifdef/#else/#endif lines surrounding #define PROTO in jconfig.h.\n");
  996. X  printf("(Leave only one #define PROTO line.)\n");
  997. X#endif
  998. X
  999. X#ifdef HAVE_UNSIGNED_CHAR
  1000. X#ifdef HAVE_UNSIGNED_SHORT
  1001. X  new_change();
  1002. X  printf("You should add -DHAVE_UNSIGNED_CHAR and -DHAVE_UNSIGNED_SHORT\n");
  1003. X  printf("to CFLAGS, or else take out the #ifdef HAVE_STDC/#endif lines\n");
  1004. X  printf("surrounding #define HAVE_UNSIGNED_CHAR and #define HAVE_UNSIGNED_SHORT\n");
  1005. X  printf("in jconfig.h.\n");
  1006. X#else /* only unsigned char */
  1007. X  new_change();
  1008. X  printf("You should add -DHAVE_UNSIGNED_CHAR to CFLAGS,\n");
  1009. X  printf("or else move #define HAVE_UNSIGNED_CHAR outside the\n");
  1010. X  printf("#ifdef HAVE_STDC/#endif lines surrounding it in jconfig.h.\n");
  1011. X#endif
  1012. X#else /* !HAVE_UNSIGNED_CHAR */
  1013. X#ifdef HAVE_UNSIGNED_SHORT
  1014. X  new_change();
  1015. X  printf("You should add -DHAVE_UNSIGNED_SHORT to CFLAGS,\n");
  1016. X  printf("or else move #define HAVE_UNSIGNED_SHORT outside the\n");
  1017. X  printf("#ifdef HAVE_STDC/#endif lines surrounding it in jconfig.h.\n");
  1018. X#endif
  1019. X#endif /* HAVE_UNSIGNED_CHAR */
  1020. X
  1021. X#ifdef HAVE_CONST
  1022. X  new_change();
  1023. X  printf("You should delete the  #define const  line from jconfig.h.\n");
  1024. X#endif
  1025. X
  1026. X#endif /* HAVE_STDC */
  1027. X
  1028. X  test_char_sign((int) signed_char_check);
  1029. X
  1030. X  test_shifting(-0x7F7E80B1L);
  1031. X
  1032. X#ifndef HAVE_VOID
  1033. X  new_change();
  1034. X  printf("You should add -Dvoid=char to CFLAGS,\n");
  1035. X  printf("or else remove the /* */ comment marks from the line\n");
  1036. X  printf("/* #define void char */  in jconfig.h.\n");
  1037. X  printf("(Be sure to delete the space before the # character too.)\n");
  1038. X#endif
  1039. X
  1040. X#ifdef INCLUDES_ARE_ANSI
  1041. X#ifndef __STDC__
  1042. X  new_change();
  1043. X  printf("You should add -DINCLUDES_ARE_ANSI to CFLAGS, or else add\n");
  1044. X  printf("#define INCLUDES_ARE_ANSI at the beginning of jinclude.h (NOT jconfig.h).\n");
  1045. X#endif
  1046. X#else /* !INCLUDES_ARE_ANSI */
  1047. X#ifdef __STDC__
  1048. X  new_change();
  1049. X  printf("You should add -DNONANSI_INCLUDES to CFLAGS, or else add\n");
  1050. X  printf("#define NONANSI_INCLUDES at the beginning of jinclude.h (NOT jconfig.h).\n");
  1051. X#endif
  1052. X#ifdef NEED_SPECIAL_INCLUDE
  1053. X  new_change();
  1054. X  printf("In jinclude.h, change the line reading #include <sys/types.h>\n");
  1055. X  printf("to instead include the file you found size_t in.\n");
  1056. X#else /* !NEED_SPECIAL_INCLUDE */
  1057. X#ifndef HAVE_TYPES_H
  1058. X  new_change();
  1059. X  printf("In jinclude.h, delete the line reading #include <sys/types.h>.\n");
  1060. X#endif
  1061. X#endif /* NEED_SPECIAL_INCLUDE */
  1062. X#ifdef BSD
  1063. X  new_change();
  1064. X  printf("You should add -DBSD to CFLAGS, or else add\n");
  1065. X  printf("#define BSD at the beginning of jinclude.h (NOT jconfig.h).\n");
  1066. X#endif
  1067. X#endif /* INCLUDES_ARE_ANSI */
  1068. X
  1069. X  if (any_changes) {
  1070. X    printf("\nI think that's everything...\n");
  1071. X  } else {
  1072. X    printf("\nI think jconfig.h is OK as distributed.\n");
  1073. X  }
  1074. X
  1075. X  return any_changes;
  1076. X}
  1077. END_OF_FILE
  1078.   if test 12938 -ne `wc -c <'ckconfig.c'`; then
  1079.     echo shar: \"'ckconfig.c'\" unpacked with wrong size!
  1080.   fi
  1081.   # end of 'ckconfig.c'
  1082. fi
  1083. if test -f 'jerror.c' -a "${1}" != "-c" ; then 
  1084.   echo shar: Will not clobber existing file \"'jerror.c'\"
  1085. else
  1086.   echo shar: Extracting \"'jerror.c'\" \(2205 characters\)
  1087.   sed "s/^X//" >'jerror.c' <<'END_OF_FILE'
  1088. X/*
  1089. X * jerror.c
  1090. X *
  1091. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  1092. X * This file is part of the Independent JPEG Group's software.
  1093. X * For conditions of distribution and use, see the accompanying README file.
  1094. X *
  1095. X * This file contains simple error-reporting and trace-message routines.
  1096. X * These are suitable for Unix-like systems and others where writing to
  1097. X * stderr is the right thing to do.  If the JPEG software is integrated
  1098. X * into a larger application, you may well need to replace these.
  1099. X *
  1100. X * The error_exit() routine should not return to its caller.  Within a
  1101. X * larger application, you might want to have it do a longjmp() to return
  1102. X * control to the outer user interface routine.  This should work since
  1103. X * the portable JPEG code doesn't use setjmp/longjmp.  You should make sure
  1104. X * that free_all is called either within error_exit or after the return to
  1105. X * the outer-level routine.
  1106. X *
  1107. X * These routines are used by both the compression and decompression code.
  1108. X */
  1109. X
  1110. X#include "jinclude.h"
  1111. X#ifdef INCLUDES_ARE_ANSI
  1112. X#include <stdlib.h>        /* to declare exit() */
  1113. X#endif
  1114. X
  1115. X#ifndef EXIT_FAILURE        /* define exit() codes if not provided */
  1116. X#define EXIT_FAILURE  1
  1117. X#endif
  1118. X
  1119. X
  1120. Xstatic external_methods_ptr methods; /* saved for access to message_parm, free_all */
  1121. X
  1122. X
  1123. XMETHODDEF void
  1124. Xtrace_message (const char *msgtext)
  1125. X{
  1126. X  fprintf(stderr, msgtext,
  1127. X      methods->message_parm[0], methods->message_parm[1],
  1128. X      methods->message_parm[2], methods->message_parm[3],
  1129. X      methods->message_parm[4], methods->message_parm[5],
  1130. X      methods->message_parm[6], methods->message_parm[7]);
  1131. X  fprintf(stderr, "\n");
  1132. X}
  1133. X
  1134. X
  1135. XMETHODDEF void
  1136. Xerror_exit (const char *msgtext)
  1137. X{
  1138. X  trace_message(msgtext);
  1139. X  (*methods->free_all) ();    /* clean up memory allocation */
  1140. X  exit(EXIT_FAILURE);
  1141. X}
  1142. X
  1143. X
  1144. X/*
  1145. X * The method selection routine for simple error handling.
  1146. X * The system-dependent setup routine should call this routine
  1147. X * to install the necessary method pointers in the supplied struct.
  1148. X */
  1149. X
  1150. XGLOBAL void
  1151. Xjselerror (external_methods_ptr emethods)
  1152. X{
  1153. X  methods = emethods;        /* save struct addr for later access */
  1154. X
  1155. X  emethods->error_exit = error_exit;
  1156. X  emethods->trace_message = trace_message;
  1157. X
  1158. X  emethods->trace_level = 0;    /* default = no tracing */
  1159. X}
  1160. END_OF_FILE
  1161.   if test 2205 -ne `wc -c <'jerror.c'`; then
  1162.     echo shar: \"'jerror.c'\" unpacked with wrong size!
  1163.   fi
  1164.   # end of 'jerror.c'
  1165. fi
  1166. echo shar: End of archive 6 \(of 18\).
  1167. cp /dev/null ark6isdone
  1168. MISSING=""
  1169. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  1170.     if test ! -f ark${I}isdone ; then
  1171.     MISSING="${MISSING} ${I}"
  1172.     fi
  1173. done
  1174. if test "${MISSING}" = "" ; then
  1175.     echo You have unpacked all 18 archives.
  1176.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1177. else
  1178.     echo You still must unpack the following archives:
  1179.     echo "        " ${MISSING}
  1180. fi
  1181. exit 0
  1182. exit 0 # Just in case...
  1183.