home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: jpeg-info@uunet.uu.net (Independent JPEG Group)
- Subject: v29i018: jpeg - JPEG image compression, Part18/18
- Message-ID: <1992Mar25.145519.979@sparky.imd.sterling.com>
- X-Md4-Signature: 2094afb0b53294cbac3c8b123bf6bfcf
- Date: Wed, 25 Mar 1992 14:55:19 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: jpeg-info@uunet.uu.net (Independent JPEG Group)
- Posting-number: Volume 29, Issue 18
- Archive-name: jpeg/part18
- Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Cray
-
- #! /bin/sh
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # Contents: CHANGELOG codingrules jcexpand.c jcsample.c jutils.c
- # Wrapped by kent@sparky on Mon Mar 23 16:02:58 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 18 (of 18)."'
- if test -f 'CHANGELOG' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'CHANGELOG'\"
- else
- echo shar: Extracting \"'CHANGELOG'\" \(2869 characters\)
- sed "s/^X//" >'CHANGELOG' <<'END_OF_FILE'
- XCHANGELOG for Independent JPEG Group's JPEG software
- X
- XVersion 3 17-Mar-92
- X--------------------
- X
- XMemory manager is finally capable of swapping to temp files. There are
- Xseparate versions of jmemsys.c for no temp files (same behavior as older
- Xversions), simple temp files with or without tmpfile(), and a DOS-specific
- Xversion (including special code for EMS and XMS). This is probably much more
- Xsystem-dependent than any of the older code; some bugs may surface here.
- X
- XHooks added for user interface to install progress monitoring routine
- X(percent-done bar, etc). See comments with dummy progress_monitor
- Xroutines in jcdeflts.c, jddeflts.c.
- X
- XTwo-pass color quantization (finally!). This is now the default method when
- Xquantizing; say '-1' to djpeg for quick-and-ugly 1-pass method. There is
- Xa test file for checking 2-pass quantization and GIF output.
- X
- XFixed bug in jcopy_block_row that broke cjpeg -o option and djpeg -b option
- Xon MSDOS machines.
- X
- XMiscellaneous small speedups; notably, DCT computation rearranged so that
- XGCC "inline" feature is no longer needed for good code quality.
- X
- XFile config.c renamed ckconfig.c to avoid name conflict with /etc/config
- Xon Unix systems.
- X
- XAdded example.c to document usage of JPEG subroutines better.
- X
- XMemory manager now knows how to release all storage during error exit ---
- Xavoids memory leak when using JPEG as subroutines. This implies a couple
- Xsmall changes to the subroutine interface: the old free_defaults subroutines
- Xare no longer needed, but if you have a replacement error_exit method then it
- Xmust call the new free_all method. Also, jselvirtmem renamed to jselmemmgr.
- X
- XCode for reading Targa files with 32-bit pixels was incorrect.
- X
- XColorspace conversion slightly faster and more accurate; because of
- Xthis, old "test" files will no longer match bit-for-bit.
- X
- X
- XVersion 2 13-Dec-91
- X--------------------
- X
- XDocumentation improved a little --- there are man pages now.
- XInstallation instructions moved from README to a separate file SETUP.
- X
- XNew program config.c is provided to help you get the configuration options
- Xright. This should make installation a lot more foolproof.
- X
- XSense of djpeg -D switch reversed: dithering is now ON by default.
- X
- XRLE image file support added (thanks to Mike Lijewski).
- X
- XTarga image file support added (thanks to Lee Crocker).
- X
- XPPM input now accepts all PPM and PGM files.
- X
- XBug fix: on machines where 'int' is 16 bits, high-Q-setting JPEG files
- Xwere not decoded correctly.
- X
- XNumerous changes to improve portability. There should be few or no compiler
- Xwarnings now.
- X
- XMakefiles cleaned up; defaults now appropriate for production use rather than
- Xdebugging.
- X
- XSubroutine interface cleaned up. If you wrote code based on version 1's
- Xjcmain/jdmain, you'll need to change it, but it should get a little shorter
- Xand simpler.
- X
- X
- XVersion 1 7-Oct-91
- X--------------------
- X
- XInitial public release.
- END_OF_FILE
- if test 2869 -ne `wc -c <'CHANGELOG'`; then
- echo shar: \"'CHANGELOG'\" unpacked with wrong size!
- fi
- # end of 'CHANGELOG'
- fi
- if test -f 'codingrules' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'codingrules'\"
- else
- echo shar: Extracting \"'codingrules'\" \(3948 characters\)
- sed "s/^X//" >'codingrules' <<'END_OF_FILE'
- X
- X JPEG SYSTEM CODING RULES 27-SEP-91
- X
- XSince numerous people will be contributing code and bug fixes, it's important
- Xto establish a common coding style. The goal of using similar coding styles
- Xis much more important than the details of just what that style is.
- X
- XI suggest we follow the recommendations of "Recommended C Style and Coding
- XStandards" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and
- XBrader). I have placed a copy of this document in the jpeg FTP archive (see
- Xjpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl).
- X
- XUnless someone has a real strong objection, let's do block comments thusly:
- X
- X/*
- X * Block comments in this style.
- X */
- X
- Xand indent statements in K&R style, e.g.,
- X
- X if (test) {
- X then-part;
- X } else {
- X else-part;
- X }
- X
- XI suggest that multi-word names be written in the style multi_word_name
- Xrather than multiWordName, but I am open to argument on this.
- X
- X
- XI would like to use function prototypes everywhere, and rely on automatic
- Xsource code transformation to feed non-ANSI C compilers. The best tool
- XI have so far found for this is 'ansi2knr.c', which is part of Ghostscript.
- Xansi2knr is not very bright, so it imposes a format requirement on function
- Xdeclarations: the function name MUST BEGIN IN COLUMN 1. Thus all functions
- Xshould be written in the following style:
- X
- Xstatic int *
- Xfunction_name (int a, char *b)
- X{
- X code...
- X}
- X
- Xansi2knr won't help with method declarations (function pointers in structs).
- XI suggest we use a macro to declare method pointers, something like this:
- X
- X#ifdef PROTO
- X#define METHOD(type,methodname,arglist) type (*methodname) arglist
- X#else
- X#define METHOD(type,methodname,arglist) type (*methodname) ()
- X#endif
- X
- Xwhich is used like this:
- X
- Xstruct function_pointers {
- X METHOD(void, init_entropy_encoder, (functptrs fptrs, jparms *jp));
- X METHOD(void, term_entropy_encoder, (void));
- X};
- X
- XNote the set of parentheses surrounding the parameter list.
- X
- XA similar solution is used for external function declarations (see the PP
- Xmacro in jpegdata.h).
- X
- XIf the code is to work on non-ANSI compilers, you cannot rely on a prototype
- Xdeclaration to coerce actual parameters into the right types. Therefore, use
- Xexplicit casts on actual parameters whenever the actual parameter type is not
- Xidentical to the formal parameter. Beware of implicit conversions to "int".
- X
- XIt seems there are some non-ANSI compilers in which the sizeof() operator
- Xis defined to return int, while size_t is defined as long. Needless to say,
- Xthis is brain-damaged. Always use the SIZEOF() macro in place of sizeof(),
- Xso that the result is guaranteed to be of type size_t.
- X
- X
- XWe can expect that the JPEG compressor and decompressor will be incorporated
- Xinto larger programs. Therefore, the following rules are important:
- X
- X1. Avoid direct use of any file I/O, "malloc", error report printouts, etc;
- Xpass these through the common routines provided.
- X
- X2. Assume that the JPEG code may be invoked more than once per program run;
- Xtherefore, do not rely on static initialization of variables, and be careful
- Xto release all allocated storage at the end of processing.
- X
- X3. Minimize global namespace pollution. Functions should be declared static
- Xwherever possible. (Note that our method-based calling conventions help this
- Xa lot: in many modules only the method-selector function will ever need to be
- Xcalled directly, so only that function need be externally visible.) All
- Xglobal function names should begin with "j", and should be unique in the first
- Xsix characters for portability reasons.
- XDon't use global variables at all; anything that must be used in another
- Xmodule should be put into parameters (there'll be some large structs passed
- Xaround for this purpose).
- X
- X4. Source file names should also begin with "j"; remember to keep them to
- Xeight characters (plus ".c" or ".h", etc) to make life easy for MS-DOSers.
- XDo not put code for both compression and decompression into the same source
- Xfile.
- END_OF_FILE
- if test 3948 -ne `wc -c <'codingrules'`; then
- echo shar: \"'codingrules'\" unpacked with wrong size!
- fi
- # end of 'codingrules'
- fi
- if test -f 'jcexpand.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'jcexpand.c'\"
- else
- echo shar: Extracting \"'jcexpand.c'\" \(1947 characters\)
- sed "s/^X//" >'jcexpand.c' <<'END_OF_FILE'
- X/*
- X * jcexpand.c
- X *
- X * Copyright (C) 1991, 1992, Thomas G. Lane.
- X * This file is part of the Independent JPEG Group's software.
- X * For conditions of distribution and use, see the accompanying README file.
- X *
- X * This file contains image edge-expansion routines.
- X * These routines are invoked via the edge_expand method.
- X */
- X
- X#include "jinclude.h"
- X
- X
- X/*
- X * Expand an image so that it is a multiple of the MCU dimensions.
- X * This is to be accomplished by duplicating the rightmost column
- X * and/or bottommost row of pixels. The image has not yet been
- X * subsampled, so all components have the same dimensions.
- X */
- X
- XMETHODDEF void
- Xedge_expand (compress_info_ptr cinfo,
- X long input_cols, int input_rows,
- X long output_cols, int output_rows,
- X JSAMPIMAGE image_data)
- X{
- X /* Expand horizontally */
- X if (input_cols < output_cols) {
- X register JSAMPROW ptr;
- X register JSAMPLE pixval;
- X register long count;
- X register int row;
- X short ci;
- X long numcols = output_cols - input_cols;
- X
- X for (ci = 0; ci < cinfo->num_components; ci++) {
- X for (row = 0; row < input_rows; row++) {
- X ptr = image_data[ci][row] + (input_cols-1);
- X pixval = GETJSAMPLE(*ptr++);
- X for (count = numcols; count > 0; count--)
- X *ptr++ = pixval;
- X }
- X }
- X }
- X
- X /* Expand vertically */
- X /* This happens only once at the bottom of the image, */
- X /* so it needn't be super-efficient */
- X if (input_rows < output_rows) {
- X register int row;
- X short ci;
- X JSAMPARRAY this_component;
- X
- X for (ci = 0; ci < cinfo->num_components; ci++) {
- X this_component = image_data[ci];
- X for (row = input_rows; row < output_rows; row++) {
- X jcopy_sample_rows(this_component, input_rows-1, this_component, row,
- X 1, output_cols);
- X }
- X }
- X }
- X}
- X
- X
- X/*
- X * The method selection routine for edge expansion.
- X */
- X
- XGLOBAL void
- Xjselexpand (compress_info_ptr cinfo)
- X{
- X /* just one implementation for now */
- X cinfo->methods->edge_expand = edge_expand;
- X}
- END_OF_FILE
- if test 1947 -ne `wc -c <'jcexpand.c'`; then
- echo shar: \"'jcexpand.c'\" unpacked with wrong size!
- fi
- # end of 'jcexpand.c'
- fi
- if test -f 'jcsample.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'jcsample.c'\"
- else
- echo shar: Extracting \"'jcsample.c'\" \(3761 characters\)
- sed "s/^X//" >'jcsample.c' <<'END_OF_FILE'
- X/*
- X * jcsample.c
- X *
- X * Copyright (C) 1991, 1992, Thomas G. Lane.
- X * This file is part of the Independent JPEG Group's software.
- X * For conditions of distribution and use, see the accompanying README file.
- X *
- X * This file contains subsampling routines.
- X * These routines are invoked via the subsample and
- X * subsample_init/term methods.
- X */
- X
- X#include "jinclude.h"
- X
- X
- X/*
- X * Initialize for subsampling a scan.
- X */
- X
- XMETHODDEF void
- Xsubsample_init (compress_info_ptr cinfo)
- X{
- X /* no work for now */
- X}
- X
- X
- X/*
- X * Subsample pixel values of a single component.
- X * This version only handles integral sampling ratios.
- X */
- X
- XMETHODDEF void
- Xsubsample (compress_info_ptr cinfo, int which_component,
- X long input_cols, int input_rows,
- X long output_cols, int output_rows,
- X JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
- X JSAMPARRAY output_data)
- X{
- X jpeg_component_info * compptr = cinfo->cur_comp_info[which_component];
- X int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
- X long outcol;
- X JSAMPROW inptr, outptr;
- X INT32 outvalue;
- X
- X /* TEMP FOR DEBUGGING PIPELINE CONTROLLER */
- X if (output_rows != compptr->v_samp_factor ||
- X input_rows != cinfo->max_v_samp_factor ||
- X (output_cols % compptr->h_samp_factor) != 0 ||
- X (input_cols % cinfo->max_h_samp_factor) != 0 ||
- X input_cols*compptr->h_samp_factor != output_cols*cinfo->max_h_samp_factor)
- X ERREXIT(cinfo->emethods, "Bogus subsample parameters");
- X
- X h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
- X v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
- X numpix = h_expand * v_expand;
- X numpix2 = numpix/2;
- X
- X inrow = 0;
- X for (outrow = 0; outrow < output_rows; outrow++) {
- X outptr = output_data[outrow];
- X for (outcol = 0; outcol < output_cols; outcol++) {
- X outvalue = 0;
- X for (v = 0; v < v_expand; v++) {
- X inptr = input_data[inrow+v] + (outcol*h_expand);
- X for (h = 0; h < h_expand; h++) {
- X outvalue += (INT32) GETJSAMPLE(*inptr++);
- X }
- X }
- X *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
- X }
- X inrow += v_expand;
- X }
- X}
- X
- X
- X/*
- X * Subsample pixel values of a single component.
- X * This version handles the special case of a full-size component.
- X */
- X
- XMETHODDEF void
- Xfullsize_subsample (compress_info_ptr cinfo, int which_component,
- X long input_cols, int input_rows,
- X long output_cols, int output_rows,
- X JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
- X JSAMPARRAY output_data)
- X{
- X if (input_cols != output_cols || input_rows != output_rows) /* DEBUG */
- X ERREXIT(cinfo->emethods, "Pipeline controller messed up");
- X
- X jcopy_sample_rows(input_data, 0, output_data, 0, output_rows, output_cols);
- X}
- X
- X
- X/*
- X * Clean up after a scan.
- X */
- X
- XMETHODDEF void
- Xsubsample_term (compress_info_ptr cinfo)
- X{
- X /* no work for now */
- X}
- X
- X
- X
- X/*
- X * The method selection routine for subsampling.
- X * Note that we must select a routine for each component.
- X */
- X
- XGLOBAL void
- Xjselsubsample (compress_info_ptr cinfo)
- X{
- X short ci;
- X jpeg_component_info * compptr;
- X
- X if (cinfo->CCIR601_sampling)
- X ERREXIT(cinfo->emethods, "CCIR601 subsampling not implemented yet");
- X
- X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
- X compptr = cinfo->cur_comp_info[ci];
- X if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
- X compptr->v_samp_factor == cinfo->max_v_samp_factor)
- X cinfo->methods->subsample[ci] = fullsize_subsample;
- X else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
- X (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0)
- X cinfo->methods->subsample[ci] = subsample;
- X else
- X ERREXIT(cinfo->emethods, "Fractional subsampling not implemented yet");
- X }
- X
- X cinfo->methods->subsample_init = subsample_init;
- X cinfo->methods->subsample_term = subsample_term;
- X}
- END_OF_FILE
- if test 3761 -ne `wc -c <'jcsample.c'`; then
- echo shar: \"'jcsample.c'\" unpacked with wrong size!
- fi
- # end of 'jcsample.c'
- fi
- if test -f 'jutils.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'jutils.c'\"
- else
- echo shar: Extracting \"'jutils.c'\" \(2942 characters\)
- sed "s/^X//" >'jutils.c' <<'END_OF_FILE'
- X/*
- X * jutils.c
- X *
- X * Copyright (C) 1991, 1992, Thomas G. Lane.
- X * This file is part of the Independent JPEG Group's software.
- X * For conditions of distribution and use, see the accompanying README file.
- X *
- X * This file contains miscellaneous utility routines needed for both
- X * compression and decompression.
- X * Note we prefix all global names with "j" to minimize conflicts with
- X * a surrounding application.
- X */
- X
- X#include "jinclude.h"
- X
- X
- XGLOBAL long
- Xjround_up (long a, long b)
- X/* Compute a rounded up to next multiple of b; a >= 0, b > 0 */
- X{
- X a += b-1;
- X return a - (a % b);
- X}
- X
- X
- XGLOBAL void
- Xjcopy_sample_rows (JSAMPARRAY input_array, int source_row,
- X JSAMPARRAY output_array, int dest_row,
- X int num_rows, long num_cols)
- X/* Copy some rows of samples from one place to another.
- X * num_rows rows are copied from input_array[source_row++]
- X * to output_array[dest_row++]; these areas should not overlap.
- X * The source and destination arrays must be at least as wide as num_cols.
- X */
- X{
- X /* On normal machines we can use memcpy(). This won't work on 80x86 because
- X * the sample arrays are FAR and we're assuming a small-pointer memory model.
- X */
- X register JSAMPROW inptr, outptr;
- X#ifdef NEED_FAR_POINTERS
- X register long count;
- X#else
- X register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
- X#endif
- X register int row;
- X
- X input_array += source_row;
- X output_array += dest_row;
- X
- X for (row = num_rows; row > 0; row--) {
- X inptr = *input_array++;
- X outptr = *output_array++;
- X#ifdef NEED_FAR_POINTERS
- X for (count = num_cols; count > 0; count--)
- X *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
- X#else
- X memcpy((void *) outptr, (void *) inptr, count);
- X#endif
- X }
- X}
- X
- X
- XGLOBAL void
- Xjcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, long num_blocks)
- X/* Copy a row of coefficient blocks from one place to another. */
- X{
- X /* On normal machines we can use memcpy(). This won't work on 80x86 because
- X * the block arrays are FAR and we're assuming a small-pointer memory model.
- X */
- X#ifdef NEED_FAR_POINTERS
- X register JCOEFPTR inptr, outptr;
- X register long count;
- X
- X inptr = (JCOEFPTR) input_row;
- X outptr = (JCOEFPTR) output_row;
- X for (count = num_blocks * DCTSIZE2; count > 0; count--) {
- X *outptr++ = *inptr++;
- X }
- X#else
- X memcpy((void *) output_row, (void *) input_row,
- X (size_t) (num_blocks * (DCTSIZE2 * SIZEOF(JCOEF))));
- X#endif
- X}
- X
- X
- XGLOBAL void
- Xjzero_far (void FAR * target, size_t bytestozero)
- X/* Zero out a chunk of FAR memory. */
- X/* This might be sample-array data, block-array data, or alloc_medium data. */
- X{
- X /* On normal machines we can use MEMZERO(). This won't work on 80x86
- X * because we're assuming a small-pointer memory model.
- X */
- X#ifdef NEED_FAR_POINTERS
- X register char FAR * ptr = (char FAR *) target;
- X register size_t count;
- X
- X for (count = bytestozero; count > 0; count--) {
- X *ptr++ = 0;
- X }
- X#else
- X MEMZERO((void *) target, bytestozero);
- X#endif
- X}
- END_OF_FILE
- if test 2942 -ne `wc -c <'jutils.c'`; then
- echo shar: \"'jutils.c'\" unpacked with wrong size!
- fi
- # end of 'jutils.c'
- fi
- echo shar: End of archive 18 \(of 18\).
- cp /dev/null ark18isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 18 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-