]> Creatis software - gdcm.git/commitdiff
ENH: Remove unecesseray file, were not in CMakeLists.txt. Also ease comparison with...
authormalaterre <malaterre>
Fri, 1 Oct 2004 21:48:32 +0000 (21:48 +0000)
committermalaterre <malaterre>
Fri, 1 Oct 2004 21:48:32 +0000 (21:48 +0000)
24 files changed:
src/jpeg/libijg/CMakeLists.txt
src/jpeg/libijg8/CMakeLists.txt
src/jpeg/libijg8/cderror.h [deleted file]
src/jpeg/libijg8/cdjpeg.c [deleted file]
src/jpeg/libijg8/cdjpeg.h [deleted file]
src/jpeg/libijg8/jmemansi.c [deleted file]
src/jpeg/libijg8/jmemdos.c [deleted file]
src/jpeg/libijg8/jmemmac.c [deleted file]
src/jpeg/libijg8/jmemname.c [deleted file]
src/jpeg/libijg8/rdbmp.c [deleted file]
src/jpeg/libijg8/rdcolmap.c [deleted file]
src/jpeg/libijg8/rdgif.c [deleted file]
src/jpeg/libijg8/rdjpgcom.c [deleted file]
src/jpeg/libijg8/rdppm.c [deleted file]
src/jpeg/libijg8/rdrle.c [deleted file]
src/jpeg/libijg8/rdswitch.c [deleted file]
src/jpeg/libijg8/rdtarga.c [deleted file]
src/jpeg/libijg8/transupp.c [deleted file]
src/jpeg/libijg8/transupp.h [deleted file]
src/jpeg/libijg8/wrbmp.c [deleted file]
src/jpeg/libijg8/wrgif.c [deleted file]
src/jpeg/libijg8/wrppm.c [deleted file]
src/jpeg/libijg8/wrrle.c [deleted file]
src/jpeg/libijg8/wrtarga.c [deleted file]

index a16baf92843a7c34170453964d2a9c233979b491..484dc0a22c8bf9d94e4d04e92a63c8e11a70952f 100644 (file)
@@ -1,8 +1,4 @@
-#LTVERSION = 0:1:0
-
-#lib_LTLIBRARIES = libgdcmijpeg8.la
-
-##CXXFLAGS = @CXXFLAGS@
+# JPEG 8 bits project
 
 SET(libgdcmijpeg8_la_SOURCES
 jcapimin.c 
@@ -20,7 +16,7 @@ jccolor.c
 jcsample.c 
 jchuff.c 
 jcphuff.c 
-jcdctmgr.c # where commented out till here
+jcdctmgr.c # were commented out till here
 jfdctfst.c 
 jfdctflt.c 
 jfdctint.c 
@@ -51,10 +47,8 @@ jutils.c
 jerror.c 
 jmemmgr.c 
 jmemnobs.c 
-# rdrle.c
 )
 
-#libgdcmijpeg8includedir = $(includedir)
 SET(libgdcmijpeg8include_HEADERS
 jchuff.h  
 jconfig.h  
@@ -69,10 +63,6 @@ jpeglib.h
 jversion.h 
 )
 
-#EXTRA_DIST = \
-#   jconfig.linux \
-#   jconfig.vc
-
 ADD_LIBRARY(gdcmijpeg8 ${libgdcmijpeg8_la_SOURCES})
 
 #INSTALL_FILES(/include "\\.h$")
index a16baf92843a7c34170453964d2a9c233979b491..484dc0a22c8bf9d94e4d04e92a63c8e11a70952f 100644 (file)
@@ -1,8 +1,4 @@
-#LTVERSION = 0:1:0
-
-#lib_LTLIBRARIES = libgdcmijpeg8.la
-
-##CXXFLAGS = @CXXFLAGS@
+# JPEG 8 bits project
 
 SET(libgdcmijpeg8_la_SOURCES
 jcapimin.c 
@@ -20,7 +16,7 @@ jccolor.c
 jcsample.c 
 jchuff.c 
 jcphuff.c 
-jcdctmgr.c # where commented out till here
+jcdctmgr.c # were commented out till here
 jfdctfst.c 
 jfdctflt.c 
 jfdctint.c 
@@ -51,10 +47,8 @@ jutils.c
 jerror.c 
 jmemmgr.c 
 jmemnobs.c 
-# rdrle.c
 )
 
-#libgdcmijpeg8includedir = $(includedir)
 SET(libgdcmijpeg8include_HEADERS
 jchuff.h  
 jconfig.h  
@@ -69,10 +63,6 @@ jpeglib.h
 jversion.h 
 )
 
-#EXTRA_DIST = \
-#   jconfig.linux \
-#   jconfig.vc
-
 ADD_LIBRARY(gdcmijpeg8 ${libgdcmijpeg8_la_SOURCES})
 
 #INSTALL_FILES(/include "\\.h$")
diff --git a/src/jpeg/libijg8/cderror.h b/src/jpeg/libijg8/cderror.h
deleted file mode 100644 (file)
index 70435e1..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * cderror.h
- *
- * Copyright (C) 1994-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file defines the error and message codes for the cjpeg/djpeg
- * applications.  These strings are not needed as part of the JPEG library
- * proper.
- * Edit this file to add new codes, or to translate the message strings to
- * some other language.
- */
-
-/*
- * To define the enum list of message codes, include this file without
- * defining macro JMESSAGE.  To create a message string table, include it
- * again with a suitable JMESSAGE definition (see jerror.c for an example).
- */
-#ifndef JMESSAGE
-#ifndef CDERROR_H
-#define CDERROR_H
-/* First time through, define the enum list */
-#define JMAKE_ENUM_LIST
-#else
-/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */
-#define JMESSAGE(code,string)
-#endif /* CDERROR_H */
-#endif /* JMESSAGE */
-
-#ifdef JMAKE_ENUM_LIST
-
-typedef enum {
-
-#define JMESSAGE(code,string)  code ,
-
-#endif /* JMAKE_ENUM_LIST */
-
-JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */
-
-#ifdef BMP_SUPPORTED
-JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
-JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported")
-JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
-JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
-JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
-JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
-JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
-JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image")
-JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
-JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image")
-JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
-#endif /* BMP_SUPPORTED */
-
-#ifdef GIF_SUPPORTED
-JMESSAGE(JERR_GIF_BUG, "GIF output got confused")
-JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d")
-JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB")
-JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
-JMESSAGE(JERR_GIF_NOT, "Not a GIF file")
-JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")
-JMESSAGE(JTRC_GIF_BADVERSION,
-        "Warning: unexpected GIF version number '%c%c%c'")
-JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x")
-JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input")
-JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file")
-JMESSAGE(JWRN_GIF_CHAR, "Bogus char 0x%02x in GIF file, ignoring")
-JMESSAGE(JWRN_GIF_ENDCODE, "Premature end of GIF image")
-JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits")
-#endif /* GIF_SUPPORTED */
-
-#ifdef PPM_SUPPORTED
-JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB")
-JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file")
-JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file")
-JMESSAGE(JTRC_PGM, "%ux%u PGM image")
-JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image")
-JMESSAGE(JTRC_PPM, "%ux%u PPM image")
-JMESSAGE(JTRC_PPM_TEXT, "%ux%u text PPM image")
-#endif /* PPM_SUPPORTED */
-
-#ifdef RLE_SUPPORTED
-JMESSAGE(JERR_RLE_BADERROR, "Bogus error code from RLE library")
-JMESSAGE(JERR_RLE_COLORSPACE, "RLE output must be grayscale or RGB")
-JMESSAGE(JERR_RLE_DIMENSIONS, "Image dimensions (%ux%u) too large for RLE")
-JMESSAGE(JERR_RLE_EMPTY, "Empty RLE file")
-JMESSAGE(JERR_RLE_EOF, "Premature EOF in RLE header")
-JMESSAGE(JERR_RLE_MEM, "Insufficient memory for RLE header")
-JMESSAGE(JERR_RLE_NOT, "Not an RLE file")
-JMESSAGE(JERR_RLE_TOOMANYCHANNELS, "Cannot handle %d output channels for RLE")
-JMESSAGE(JERR_RLE_UNSUPPORTED, "Cannot handle this RLE setup")
-JMESSAGE(JTRC_RLE, "%ux%u full-color RLE file")
-JMESSAGE(JTRC_RLE_FULLMAP, "%ux%u full-color RLE file with map of length %d")
-JMESSAGE(JTRC_RLE_GRAY, "%ux%u grayscale RLE file")
-JMESSAGE(JTRC_RLE_MAPGRAY, "%ux%u grayscale RLE file with map of length %d")
-JMESSAGE(JTRC_RLE_MAPPED, "%ux%u colormapped RLE file with map of length %d")
-#endif /* RLE_SUPPORTED */
-
-#ifdef TARGA_SUPPORTED
-JMESSAGE(JERR_TGA_BADCMAP, "Unsupported Targa colormap format")
-JMESSAGE(JERR_TGA_BADPARMS, "Invalid or unsupported Targa file")
-JMESSAGE(JERR_TGA_COLORSPACE, "Targa output must be grayscale or RGB")
-JMESSAGE(JTRC_TGA, "%ux%u RGB Targa image")
-JMESSAGE(JTRC_TGA_GRAY, "%ux%u grayscale Targa image")
-JMESSAGE(JTRC_TGA_MAPPED, "%ux%u colormapped Targa image")
-#else
-JMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled")
-#endif /* TARGA_SUPPORTED */
-
-JMESSAGE(JERR_BAD_CMAP_FILE,
-        "Color map file is invalid or of unsupported format")
-JMESSAGE(JERR_TOO_MANY_COLORS,
-        "Output file format cannot handle %d colormap entries")
-JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed")
-#ifdef TARGA_SUPPORTED
-JMESSAGE(JERR_UNKNOWN_FORMAT,
-        "Unrecognized input file format --- perhaps you need -targa")
-#else
-JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format")
-#endif
-JMESSAGE(JERR_UNSUPPORTED_FORMAT, "Unsupported output file format")
-
-#ifdef JMAKE_ENUM_LIST
-
-  JMSG_LASTADDONCODE
-} ADDON_MESSAGE_CODE;
-
-#undef JMAKE_ENUM_LIST
-#endif /* JMAKE_ENUM_LIST */
-
-/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */
-#undef JMESSAGE
diff --git a/src/jpeg/libijg8/cdjpeg.c b/src/jpeg/libijg8/cdjpeg.c
deleted file mode 100644 (file)
index b6250ff..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * cdjpeg.c
- *
- * Copyright (C) 1991-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains common support routines used by the IJG application
- * programs (cjpeg, djpeg, jpegtran).
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-#include <ctype.h>             /* to declare isupper(), tolower() */
-#ifdef NEED_SIGNAL_CATCHER
-#include <signal.h>            /* to declare signal() */
-#endif
-#ifdef USE_SETMODE
-#include <fcntl.h>             /* to declare setmode()'s parameter macros */
-/* If you have setmode() but not <io.h>, just delete this line: */
-#include <io.h>                        /* to declare setmode() */
-#endif
-
-
-/*
- * Signal catcher to ensure that temporary files are removed before aborting.
- * NB: for Amiga Manx C this is actually a global routine named _abort();
- * we put "#define signal_catcher _abort" in jconfig.h.  Talk about bogus...
- */
-
-#ifdef NEED_SIGNAL_CATCHER
-
-static j_common_ptr sig_cinfo;
-
-void                           /* must be global for Manx C */
-signal_catcher (int signum)
-{
-  if (sig_cinfo != NULL) {
-    if (sig_cinfo->err != NULL) /* turn off trace output */
-      sig_cinfo->err->trace_level = 0;
-    jpeg_destroy(sig_cinfo);   /* clean up memory allocation & temp files */
-  }
-  exit(EXIT_FAILURE);
-}
-
-
-GLOBAL(void)
-enable_signal_catcher (j_common_ptr cinfo)
-{
-  sig_cinfo = cinfo;
-#ifdef SIGINT                  /* not all systems have SIGINT */
-  signal(SIGINT, signal_catcher);
-#endif
-#ifdef SIGTERM                 /* not all systems have SIGTERM */
-  signal(SIGTERM, signal_catcher);
-#endif
-}
-
-#endif
-
-
-/*
- * Optional progress monitor: display a percent-done figure on stderr.
- */
-
-#ifdef PROGRESS_REPORT
-
-METHODDEF(void)
-progress_monitor (j_common_ptr cinfo)
-{
-  cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;
-  int total_passes = prog->pub.total_passes + prog->total_extra_passes;
-  int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit);
-
-  if (percent_done != prog->percent_done) {
-    prog->percent_done = percent_done;
-    if (total_passes > 1) {
-      fprintf(stderr, "\rPass %d/%d: %3d%% ",
-             prog->pub.completed_passes + prog->completed_extra_passes + 1,
-             total_passes, percent_done);
-    } else {
-      fprintf(stderr, "\r %3d%% ", percent_done);
-    }
-    fflush(stderr);
-  }
-}
-
-
-GLOBAL(void)
-start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)
-{
-  /* Enable progress display, unless trace output is on */
-  if (cinfo->err->trace_level == 0) {
-    progress->pub.progress_monitor = progress_monitor;
-    progress->completed_extra_passes = 0;
-    progress->total_extra_passes = 0;
-    progress->percent_done = -1;
-    cinfo->progress = &progress->pub;
-  }
-}
-
-
-GLOBAL(void)
-end_progress_monitor (j_common_ptr cinfo)
-{
-  /* Clear away progress display */
-  if (cinfo->err->trace_level == 0) {
-    fprintf(stderr, "\r                \r");
-    fflush(stderr);
-  }
-}
-
-#endif
-
-
-/*
- * Case-insensitive matching of possibly-abbreviated keyword switches.
- * keyword is the constant keyword (must be lower case already),
- * minchars is length of minimum legal abbreviation.
- */
-
-GLOBAL(boolean)
-keymatch (char * arg, const char * keyword, int minchars)
-{
-  register int ca, ck;
-  register int nmatched = 0;
-
-  while ((ca = *arg++) != '\0') {
-    if ((ck = *keyword++) == '\0')
-      return FALSE;            /* arg longer than keyword, no good */
-    if (isupper(ca))           /* force arg to lcase (assume ck is already) */
-      ca = tolower(ca);
-    if (ca != ck)
-      return FALSE;            /* no good */
-    nmatched++;                        /* count matched characters */
-  }
-  /* reached end of argument; fail if it's too short for unique abbrev */
-  if (nmatched < minchars)
-    return FALSE;
-  return TRUE;                 /* A-OK */
-}
-
-
-/*
- * Routines to establish binary I/O mode for stdin and stdout.
- * Non-Unix systems often require some hacking to get out of text mode.
- */
-
-GLOBAL(FILE *)
-read_stdin (void)
-{
-  FILE * input_file = stdin;
-
-#ifdef USE_SETMODE             /* need to hack file mode? */
-  setmode(fileno(stdin), O_BINARY);
-#endif
-#ifdef USE_FDOPEN              /* need to re-open in binary mode? */
-  if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
-    fprintf(stderr, "Cannot reopen stdin\n");
-    exit(EXIT_FAILURE);
-  }
-#endif
-  return input_file;
-}
-
-
-GLOBAL(FILE *)
-write_stdout (void)
-{
-  FILE * output_file = stdout;
-
-#ifdef USE_SETMODE             /* need to hack file mode? */
-  setmode(fileno(stdout), O_BINARY);
-#endif
-#ifdef USE_FDOPEN              /* need to re-open in binary mode? */
-  if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
-    fprintf(stderr, "Cannot reopen stdout\n");
-    exit(EXIT_FAILURE);
-  }
-#endif
-  return output_file;
-}
diff --git a/src/jpeg/libijg8/cdjpeg.h b/src/jpeg/libijg8/cdjpeg.h
deleted file mode 100644 (file)
index 2b387b6..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * cdjpeg.h
- *
- * Copyright (C) 1994-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains common declarations for the sample applications
- * cjpeg and djpeg.  It is NOT used by the core JPEG library.
- */
-
-#define JPEG_CJPEG_DJPEG       /* define proper options in jconfig.h */
-#define JPEG_INTERNAL_OPTIONS  /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
-#include "jinclude.h"
-#include "jpeglib.h"
-#include "jerror.h"            /* get library error codes too */
-#include "cderror.h"           /* get application-specific error codes */
-
-
-/*
- * Object interface for cjpeg's source file decoding modules
- */
-
-typedef struct cjpeg_source_struct * cjpeg_source_ptr;
-
-struct cjpeg_source_struct {
-  JMETHOD(void, start_input, (j_compress_ptr cinfo,
-                             cjpeg_source_ptr sinfo));
-  JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
-                                      cjpeg_source_ptr sinfo));
-  JMETHOD(void, finish_input, (j_compress_ptr cinfo,
-                              cjpeg_source_ptr sinfo));
-
-  FILE *input_file;
-
-  JSAMPARRAY buffer;
-  JDIMENSION buffer_height;
-};
-
-
-/*
- * Object interface for djpeg's output file encoding modules
- */
-
-typedef struct djpeg_dest_struct * djpeg_dest_ptr;
-
-struct djpeg_dest_struct {
-  /* start_output is called after jpeg_start_decompress finishes.
-   * The color map will be ready at this time, if one is needed.
-   */
-  JMETHOD(void, start_output, (j_decompress_ptr cinfo,
-                              djpeg_dest_ptr dinfo));
-  /* Emit the specified number of pixel rows from the buffer. */
-  JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo,
-                                djpeg_dest_ptr dinfo,
-                                JDIMENSION rows_supplied));
-  /* Finish up at the end of the image. */
-  JMETHOD(void, finish_output, (j_decompress_ptr cinfo,
-                               djpeg_dest_ptr dinfo));
-
-  /* Target file spec; filled in by djpeg.c after object is created. */
-  FILE * output_file;
-
-  /* Output pixel-row buffer.  Created by module init or start_output.
-   * Width is cinfo->output_width * cinfo->output_components;
-   * height is buffer_height.
-   */
-  JSAMPARRAY buffer;
-  JDIMENSION buffer_height;
-};
-
-
-/*
- * cjpeg/djpeg may need to perform extra passes to convert to or from
- * the source/destination file format.  The JPEG library does not know
- * about these passes, but we'd like them to be counted by the progress
- * monitor.  We use an expanded progress monitor object to hold the
- * additional pass count.
- */
-
-struct cdjpeg_progress_mgr {
-  struct jpeg_progress_mgr pub;        /* fields known to JPEG library */
-  int completed_extra_passes;  /* extra passes completed */
-  int total_extra_passes;      /* total extra */
-  /* last printed percentage stored here to avoid multiple printouts */
-  int percent_done;
-};
-
-typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
-
-
-/* Short forms of external names for systems with brain-damaged linkers. */
-
-#ifdef NEED_SHORT_EXTERNAL_NAMES
-#define jinit_read_bmp         jIRdBMP
-#define jinit_write_bmp                jIWrBMP
-#define jinit_read_gif         jIRdGIF
-#define jinit_write_gif                jIWrGIF
-#define jinit_read_ppm         jIRdPPM
-#define jinit_write_ppm                jIWrPPM
-#define jinit_read_rle         jIRdRLE
-#define jinit_write_rle                jIWrRLE
-#define jinit_read_targa       jIRdTarga
-#define jinit_write_targa      jIWrTarga
-#define read_quant_tables      RdQTables
-#define read_scan_script       RdScnScript
-#define set_quant_slots                SetQSlots
-#define set_sample_factors     SetSFacts
-#define read_color_map         RdCMap
-#define enable_signal_catcher  EnSigCatcher
-#define start_progress_monitor StProgMon
-#define end_progress_monitor   EnProgMon
-#define read_stdin             RdStdin
-#define write_stdout           WrStdout
-#endif /* NEED_SHORT_EXTERNAL_NAMES */
-
-/* Module selection routines for I/O modules. */
-
-EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo));
-EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
-                                           boolean is_os2));
-EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));
-EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo));
-EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
-EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));
-EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
-EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo));
-EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo));
-EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));
-
-/* cjpeg support routines (in rdswitch.c) */
-
-EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
-                                   int scale_factor, boolean force_baseline));
-EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename));
-EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
-EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
-
-/* djpeg support routines (in rdcolmap.c) */
-
-EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
-
-/* common support routines (in cdjpeg.c) */
-
-EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo));
-EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo,
-                                        cd_progress_ptr progress));
-EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo));
-EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars));
-EXTERN(FILE *) read_stdin JPP((void));
-EXTERN(FILE *) write_stdout JPP((void));
-
-/* miscellaneous useful macros */
-
-#ifdef DONT_USE_B_MODE         /* define mode parameters for fopen() */
-#define READ_BINARY    "r"
-#define WRITE_BINARY   "w"
-#else
-#ifdef VMS                     /* VMS is very nonstandard */
-#define READ_BINARY    "rb", "ctx=stm"
-#define WRITE_BINARY   "wb", "ctx=stm"
-#else                          /* standard ANSI-compliant case */
-#define READ_BINARY    "rb"
-#define WRITE_BINARY   "wb"
-#endif
-#endif
-
-#ifndef EXIT_FAILURE           /* define exit() codes if not provided */
-#define EXIT_FAILURE  1
-#endif
-#ifndef EXIT_SUCCESS
-#ifdef VMS
-#define EXIT_SUCCESS  1                /* VMS is very nonstandard */
-#else
-#define EXIT_SUCCESS  0
-#endif
-#endif
-#ifndef EXIT_WARNING
-#ifdef VMS
-#define EXIT_WARNING  1                /* VMS is very nonstandard */
-#else
-#define EXIT_WARNING  2
-#endif
-#endif
diff --git a/src/jpeg/libijg8/jmemansi.c b/src/jpeg/libijg8/jmemansi.c
deleted file mode 100644 (file)
index 2d93e49..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * jmemansi.c
- *
- * Copyright (C) 1992-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file provides a simple generic implementation of the system-
- * dependent portion of the JPEG memory manager.  This implementation
- * assumes that you have the ANSI-standard library routine tmpfile().
- * Also, the problem of determining the amount of memory available
- * is shoved onto the user.
- */
-
-#define JPEG_INTERNALS
-#include "jinclude.h"
-#include "jpeglib.h"
-#include "jmemsys.h"           /* import the system-dependent declarations */
-
-#ifndef HAVE_STDLIB_H          /* <stdlib.h> should declare malloc(),free() */
-extern void * malloc JPP((size_t size));
-extern void free JPP((void *ptr));
-#endif
-
-#ifndef SEEK_SET               /* pre-ANSI systems may not define this; */
-#define SEEK_SET  0            /* if not, assume 0 is correct */
-#endif
-
-
-/*
- * Memory allocation and freeing are controlled by the regular library
- * routines malloc() and free().
- */
-
-GLOBAL(void *)
-jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
-{
-  return (void *) malloc(sizeofobject);
-}
-
-GLOBAL(void)
-jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
-{
-  free(object);
-}
-
-
-/*
- * "Large" objects are treated the same as "small" ones.
- * NB: although we include FAR keywords in the routine declarations,
- * this file won't actually work in 80x86 small/medium model; at least,
- * you probably won't be able to process useful-size images in only 64KB.
- */
-
-GLOBAL(void FAR *)
-jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
-{
-  return (void FAR *) malloc(sizeofobject);
-}
-
-GLOBAL(void)
-jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
-{
-  free(object);
-}
-
-
-/*
- * This routine computes the total memory space available for allocation.
- * It's impossible to do this in a portable way; our current solution is
- * to make the user tell us (with a default value set at compile time).
- * If you can actually get the available space, it's a good idea to subtract
- * a slop factor of 5% or so.
- */
-
-#ifndef DEFAULT_MAX_MEM                /* so can override from makefile */
-#define DEFAULT_MAX_MEM                1000000L /* default: one megabyte */
-#endif
-
-GLOBAL(long)
-jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
-                   long max_bytes_needed, long already_allocated)
-{
-  return cinfo->mem->max_memory_to_use - already_allocated;
-}
-
-
-/*
- * Backing store (temporary file) management.
- * Backing store objects are only used when the value returned by
- * jpeg_mem_available is less than the total space needed.  You can dispense
- * with these routines if you have plenty of virtual memory; see jmemnobs.c.
- */
-
-
-METHODDEF(void)
-read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
-                   void FAR * buffer_address,
-                   long file_offset, long byte_count)
-{
-  if (fseek(info->temp_file, file_offset, SEEK_SET))
-    ERREXIT(cinfo, JERR_TFILE_SEEK);
-  if (JFREAD(info->temp_file, buffer_address, byte_count)
-      != (size_t) byte_count)
-    ERREXIT(cinfo, JERR_TFILE_READ);
-}
-
-
-METHODDEF(void)
-write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
-                    void FAR * buffer_address,
-                    long file_offset, long byte_count)
-{
-  if (fseek(info->temp_file, file_offset, SEEK_SET))
-    ERREXIT(cinfo, JERR_TFILE_SEEK);
-  if (JFWRITE(info->temp_file, buffer_address, byte_count)
-      != (size_t) byte_count)
-    ERREXIT(cinfo, JERR_TFILE_WRITE);
-}
-
-
-METHODDEF(void)
-close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
-{
-  fclose(info->temp_file);
-  /* Since this implementation uses tmpfile() to create the file,
-   * no explicit file deletion is needed.
-   */
-}
-
-
-/*
- * Initial opening of a backing-store object.
- *
- * This version uses tmpfile(), which constructs a suitable file name
- * behind the scenes.  We don't have to use info->temp_name[] at all;
- * indeed, we can't even find out the actual name of the temp file.
- */
-
-GLOBAL(void)
-jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
-                        long total_bytes_needed)
-{
-  if ((info->temp_file = tmpfile()) == NULL)
-    ERREXITS(cinfo, JERR_TFILE_CREATE, "");
-  info->read_backing_store = read_backing_store;
-  info->write_backing_store = write_backing_store;
-  info->close_backing_store = close_backing_store;
-}
-
-
-/*
- * These routines take care of any system-dependent initialization and
- * cleanup required.
- */
-
-GLOBAL(long)
-jpeg_mem_init (j_common_ptr cinfo)
-{
-  return DEFAULT_MAX_MEM;      /* default for max_memory_to_use */
-}
-
-GLOBAL(void)
-jpeg_mem_term (j_common_ptr cinfo)
-{
-  /* no work */
-}
diff --git a/src/jpeg/libijg8/jmemdos.c b/src/jpeg/libijg8/jmemdos.c
deleted file mode 100644 (file)
index 60b45c6..0000000
+++ /dev/null
@@ -1,638 +0,0 @@
-/*
- * jmemdos.c
- *
- * Copyright (C) 1992-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file provides an MS-DOS-compatible implementation of the system-
- * dependent portion of the JPEG memory manager.  Temporary data can be
- * stored in extended or expanded memory as well as in regular DOS files.
- *
- * If you use this file, you must be sure that NEED_FAR_POINTERS is defined
- * if you compile in a small-data memory model; it should NOT be defined if
- * you use a large-data memory model.  This file is not recommended if you
- * are using a flat-memory-space 386 environment such as DJGCC or Watcom C.
- * Also, this code will NOT work if struct fields are aligned on greater than
- * 2-byte boundaries.
- *
- * Based on code contributed by Ge' Weijers.
- */
-
-/*
- * If you have both extended and expanded memory, you may want to change the
- * order in which they are tried in jopen_backing_store.  On a 286 machine
- * expanded memory is usually faster, since extended memory access involves
- * an expensive protected-mode-and-back switch.  On 386 and better, extended
- * memory is usually faster.  As distributed, the code tries extended memory
- * first (what? not everyone has a 386? :-).
- *
- * You can disable use of extended/expanded memory entirely by altering these
- * definitions or overriding them from the Makefile (eg, -DEMS_SUPPORTED=0).
- */
-
-#ifndef XMS_SUPPORTED
-#define XMS_SUPPORTED  1
-#endif
-#ifndef EMS_SUPPORTED
-#define EMS_SUPPORTED  1
-#endif
-
-
-#define JPEG_INTERNALS
-#include "jinclude.h"
-#include "jpeglib.h"
-#include "jmemsys.h"           /* import the system-dependent declarations */
-
-#ifndef HAVE_STDLIB_H          /* <stdlib.h> should declare these */
-extern void * malloc JPP((size_t size));
-extern void free JPP((void *ptr));
-extern char * getenv JPP((const char * name));
-#endif
-
-#ifdef NEED_FAR_POINTERS
-
-#ifdef __TURBOC__
-/* These definitions work for Borland C (Turbo C) */
-#include <alloc.h>             /* need farmalloc(), farfree() */
-#define far_malloc(x)  farmalloc(x)
-#define far_free(x)    farfree(x)
-#else
-/* These definitions work for Microsoft C and compatible compilers */
-#include <malloc.h>            /* need _fmalloc(), _ffree() */
-#define far_malloc(x)  _fmalloc(x)
-#define far_free(x)    _ffree(x)
-#endif
-
-#else /* not NEED_FAR_POINTERS */
-
-#define far_malloc(x)  malloc(x)
-#define far_free(x)    free(x)
-
-#endif /* NEED_FAR_POINTERS */
-
-#ifdef DONT_USE_B_MODE         /* define mode parameters for fopen() */
-#define READ_BINARY    "r"
-#else
-#define READ_BINARY    "rb"
-#endif
-
-#ifndef USE_MSDOS_MEMMGR       /* make sure user got configuration right */
-  You forgot to define USE_MSDOS_MEMMGR in jconfig.h. /* deliberate syntax error */
-#endif
-
-#if MAX_ALLOC_CHUNK >= 65535L  /* make sure jconfig.h got this right */
-  MAX_ALLOC_CHUNK should be less than 64K. /* deliberate syntax error */
-#endif
-
-
-/*
- * Declarations for assembly-language support routines (see jmemdosa.asm).
- *
- * The functions are declared "far" as are all their pointer arguments;
- * this ensures the assembly source code will work regardless of the
- * compiler memory model.  We assume "short" is 16 bits, "long" is 32.
- */
-
-typedef void far * XMSDRIVER;  /* actually a pointer to code */
-typedef struct {               /* registers for calling XMS driver */
-       unsigned short ax, dx, bx;
-       void far * ds_si;
-      } XMScontext;
-typedef struct {               /* registers for calling EMS driver */
-       unsigned short ax, dx, bx;
-       void far * ds_si;
-      } EMScontext;
-
-extern short far jdos_open JPP((short far * handle, char far * filename));
-extern short far jdos_close JPP((short handle));
-extern short far jdos_seek JPP((short handle, long offset));
-extern short far jdos_read JPP((short handle, void far * buffer,
-                               unsigned short count));
-extern short far jdos_write JPP((short handle, void far * buffer,
-                                unsigned short count));
-extern void far jxms_getdriver JPP((XMSDRIVER far *));
-extern void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *));
-extern short far jems_available JPP((void));
-extern void far jems_calldriver JPP((EMScontext far *));
-
-
-/*
- * Selection of a file name for a temporary file.
- * This is highly system-dependent, and you may want to customize it.
- */
-
-static int next_file_num;      /* to distinguish among several temp files */
-
-LOCAL(void)
-select_file_name (char * fname)
-{
-  const char * env;
-  char * ptr;
-  FILE * tfile;
-
-  /* Keep generating file names till we find one that's not in use */
-  for (;;) {
-    /* Get temp directory name from environment TMP or TEMP variable;
-     * if none, use "."
-     */
-    if ((env = (const char *) getenv("TMP")) == NULL)
-      if ((env = (const char *) getenv("TEMP")) == NULL)
-       env = ".";
-    if (*env == '\0')          /* null string means "." */
-      env = ".";
-    ptr = fname;               /* copy name to fname */
-    while (*env != '\0')
-      *ptr++ = *env++;
-    if (ptr[-1] != '\\' && ptr[-1] != '/')
-      *ptr++ = '\\';           /* append backslash if not in env variable */
-    /* Append a suitable file name */
-    next_file_num++;           /* advance counter */
-    sprintf(ptr, "JPG%03d.TMP", next_file_num);
-    /* Probe to see if file name is already in use */
-    if ((tfile = fopen(fname, READ_BINARY)) == NULL)
-      break;
-    fclose(tfile);             /* oops, it's there; close tfile & try again */
-  }
-}
-
-
-/*
- * Near-memory allocation and freeing are controlled by the regular library
- * routines malloc() and free().
- */
-
-GLOBAL(void *)
-jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
-{
-  return (void *) malloc(sizeofobject);
-}
-
-GLOBAL(void)
-jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
-{
-  free(object);
-}
-
-
-/*
- * "Large" objects are allocated in far memory, if possible
- */
-
-GLOBAL(void FAR *)
-jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
-{
-  return (void FAR *) far_malloc(sizeofobject);
-}
-
-GLOBAL(void)
-jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
-{
-  far_free(object);
-}
-
-
-/*
- * This routine computes the total memory space available for allocation.
- * It's impossible to do this in a portable way; our current solution is
- * to make the user tell us (with a default value set at compile time).
- * If you can actually get the available space, it's a good idea to subtract
- * a slop factor of 5% or so.
- */
-
-#ifndef DEFAULT_MAX_MEM                /* so can override from makefile */
-#define DEFAULT_MAX_MEM                300000L /* for total usage about 450K */
-#endif
-
-GLOBAL(long)
-jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
-                   long max_bytes_needed, long already_allocated)
-{
-  return cinfo->mem->max_memory_to_use - already_allocated;
-}
-
-
-/*
- * Backing store (temporary file) management.
- * Backing store objects are only used when the value returned by
- * jpeg_mem_available is less than the total space needed.  You can dispense
- * with these routines if you have plenty of virtual memory; see jmemnobs.c.
- */
-
-/*
- * For MS-DOS we support three types of backing storage:
- *   1. Conventional DOS files.  We access these by direct DOS calls rather
- *      than via the stdio package.  This provides a bit better performance,
- *      but the real reason is that the buffers to be read or written are FAR.
- *      The stdio library for small-data memory models can't cope with that.
- *   2. Extended memory, accessed per the XMS V2.0 specification.
- *   3. Expanded memory, accessed per the LIM/EMS 4.0 specification.
- * You'll need copies of those specs to make sense of the related code.
- * The specs are available by Internet FTP from the SIMTEL archives 
- * (oak.oakland.edu and its various mirror sites).  See files
- * pub/msdos/microsoft/xms20.arc and pub/msdos/info/limems41.zip.
- */
-
-
-/*
- * Access methods for a DOS file.
- */
-
-
-METHODDEF(void)
-read_file_store (j_common_ptr cinfo, backing_store_ptr info,
-                void FAR * buffer_address,
-                long file_offset, long byte_count)
-{
-  if (jdos_seek(info->handle.file_handle, file_offset))
-    ERREXIT(cinfo, JERR_TFILE_SEEK);
-  /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
-  if (byte_count > 65535L)     /* safety check */
-    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
-  if (jdos_read(info->handle.file_handle, buffer_address,
-               (unsigned short) byte_count))
-    ERREXIT(cinfo, JERR_TFILE_READ);
-}
-
-
-METHODDEF(void)
-write_file_store (j_common_ptr cinfo, backing_store_ptr info,
-                 void FAR * buffer_address,
-                 long file_offset, long byte_count)
-{
-  if (jdos_seek(info->handle.file_handle, file_offset))
-    ERREXIT(cinfo, JERR_TFILE_SEEK);
-  /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
-  if (byte_count > 65535L)     /* safety check */
-    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
-  if (jdos_write(info->handle.file_handle, buffer_address,
-                (unsigned short) byte_count))
-    ERREXIT(cinfo, JERR_TFILE_WRITE);
-}
-
-
-METHODDEF(void)
-close_file_store (j_common_ptr cinfo, backing_store_ptr info)
-{
-  jdos_close(info->handle.file_handle);        /* close the file */
-  remove(info->temp_name);     /* delete the file */
-/* If your system doesn't have remove(), try unlink() instead.
- * remove() is the ANSI-standard name for this function, but
- * unlink() was more common in pre-ANSI systems.
- */
-  TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);
-}
-
-
-LOCAL(boolean)
-open_file_store (j_common_ptr cinfo, backing_store_ptr info,
-                long total_bytes_needed)
-{
-  short handle;
-
-  select_file_name(info->temp_name);
-  if (jdos_open((short far *) & handle, (char far *) info->temp_name)) {
-    /* might as well exit since jpeg_open_backing_store will fail anyway */
-    ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
-    return FALSE;
-  }
-  info->handle.file_handle = handle;
-  info->read_backing_store = read_file_store;
-  info->write_backing_store = write_file_store;
-  info->close_backing_store = close_file_store;
-  TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
-  return TRUE;                 /* succeeded */
-}
-
-
-/*
- * Access methods for extended memory.
- */
-
-#if XMS_SUPPORTED
-
-static XMSDRIVER xms_driver;   /* saved address of XMS driver */
-
-typedef union {                        /* either long offset or real-mode pointer */
-       long offset;
-       void far * ptr;
-      } XMSPTR;
-
-typedef struct {               /* XMS move specification structure */
-       long length;
-       XMSH src_handle;
-       XMSPTR src;
-       XMSH dst_handle;
-       XMSPTR dst;
-      } XMSspec;
-
-#define ODD(X) (((X) & 1L) != 0)
-
-
-METHODDEF(void)
-read_xms_store (j_common_ptr cinfo, backing_store_ptr info,
-               void FAR * buffer_address,
-               long file_offset, long byte_count)
-{
-  XMScontext ctx;
-  XMSspec spec;
-  char endbuffer[2];
-
-  /* The XMS driver can't cope with an odd length, so handle the last byte
-   * specially if byte_count is odd.  We don't expect this to be common.
-   */
-
-  spec.length = byte_count & (~ 1L);
-  spec.src_handle = info->handle.xms_handle;
-  spec.src.offset = file_offset;
-  spec.dst_handle = 0;
-  spec.dst.ptr = buffer_address;
-  
-  ctx.ds_si = (void far *) & spec;
-  ctx.ax = 0x0b00;             /* EMB move */
-  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
-  if (ctx.ax != 1)
-    ERREXIT(cinfo, JERR_XMS_READ);
-
-  if (ODD(byte_count)) {
-    read_xms_store(cinfo, info, (void FAR *) endbuffer,
-                  file_offset + byte_count - 1L, 2L);
-    ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0];
-  }
-}
-
-
-METHODDEF(void)
-write_xms_store (j_common_ptr cinfo, backing_store_ptr info,
-                void FAR * buffer_address,
-                long file_offset, long byte_count)
-{
-  XMScontext ctx;
-  XMSspec spec;
-  char endbuffer[2];
-
-  /* The XMS driver can't cope with an odd length, so handle the last byte
-   * specially if byte_count is odd.  We don't expect this to be common.
-   */
-
-  spec.length = byte_count & (~ 1L);
-  spec.src_handle = 0;
-  spec.src.ptr = buffer_address;
-  spec.dst_handle = info->handle.xms_handle;
-  spec.dst.offset = file_offset;
-
-  ctx.ds_si = (void far *) & spec;
-  ctx.ax = 0x0b00;             /* EMB move */
-  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
-  if (ctx.ax != 1)
-    ERREXIT(cinfo, JERR_XMS_WRITE);
-
-  if (ODD(byte_count)) {
-    read_xms_store(cinfo, info, (void FAR *) endbuffer,
-                  file_offset + byte_count - 1L, 2L);
-    endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L];
-    write_xms_store(cinfo, info, (void FAR *) endbuffer,
-                   file_offset + byte_count - 1L, 2L);
-  }
-}
-
-
-METHODDEF(void)
-close_xms_store (j_common_ptr cinfo, backing_store_ptr info)
-{
-  XMScontext ctx;
-
-  ctx.dx = info->handle.xms_handle;
-  ctx.ax = 0x0a00;
-  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
-  TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle);
-  /* we ignore any error return from the driver */
-}
-
-
-LOCAL(boolean)
-open_xms_store (j_common_ptr cinfo, backing_store_ptr info,
-               long total_bytes_needed)
-{
-  XMScontext ctx;
-
-  /* Get address of XMS driver */
-  jxms_getdriver((XMSDRIVER far *) & xms_driver);
-  if (xms_driver == NULL)
-    return FALSE;              /* no driver to be had */
-
-  /* Get version number, must be >= 2.00 */
-  ctx.ax = 0x0000;
-  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
-  if (ctx.ax < (unsigned short) 0x0200)
-    return FALSE;
-
-  /* Try to get space (expressed in kilobytes) */
-  ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10);
-  ctx.ax = 0x0900;
-  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
-  if (ctx.ax != 1)
-    return FALSE;
-
-  /* Succeeded, save the handle and away we go */
-  info->handle.xms_handle = ctx.dx;
-  info->read_backing_store = read_xms_store;
-  info->write_backing_store = write_xms_store;
-  info->close_backing_store = close_xms_store;
-  TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx);
-  return TRUE;                 /* succeeded */
-}
-
-#endif /* XMS_SUPPORTED */
-
-
-/*
- * Access methods for expanded memory.
- */
-
-#if EMS_SUPPORTED
-
-/* The EMS move specification structure requires word and long fields aligned
- * at odd byte boundaries.  Some compilers will align struct fields at even
- * byte boundaries.  While it's usually possible to force byte alignment,
- * that causes an overall performance penalty and may pose problems in merging
- * JPEG into a larger application.  Instead we accept some rather dirty code
- * here.  Note this code would fail if the hardware did not allow odd-byte
- * word & long accesses, but all 80x86 CPUs do.
- */
-
-typedef void far * EMSPTR;
-
-typedef union {                        /* EMS move specification structure */
-       long length;            /* It's easy to access first 4 bytes */
-       char bytes[18];         /* Misaligned fields in here! */
-      } EMSspec;
-
-/* Macros for accessing misaligned fields */
-#define FIELD_AT(spec,offset,type)  (*((type *) &(spec.bytes[offset])))
-#define SRC_TYPE(spec)         FIELD_AT(spec,4,char)
-#define SRC_HANDLE(spec)       FIELD_AT(spec,5,EMSH)
-#define SRC_OFFSET(spec)       FIELD_AT(spec,7,unsigned short)
-#define SRC_PAGE(spec)         FIELD_AT(spec,9,unsigned short)
-#define SRC_PTR(spec)          FIELD_AT(spec,7,EMSPTR)
-#define DST_TYPE(spec)         FIELD_AT(spec,11,char)
-#define DST_HANDLE(spec)       FIELD_AT(spec,12,EMSH)
-#define DST_OFFSET(spec)       FIELD_AT(spec,14,unsigned short)
-#define DST_PAGE(spec)         FIELD_AT(spec,16,unsigned short)
-#define DST_PTR(spec)          FIELD_AT(spec,14,EMSPTR)
-
-#define EMSPAGESIZE    16384L  /* gospel, see the EMS specs */
-
-#define HIBYTE(W)  (((W) >> 8) & 0xFF)
-#define LOBYTE(W)  ((W) & 0xFF)
-
-
-METHODDEF(void)
-read_ems_store (j_common_ptr cinfo, backing_store_ptr info,
-               void FAR * buffer_address,
-               long file_offset, long byte_count)
-{
-  EMScontext ctx;
-  EMSspec spec;
-
-  spec.length = byte_count;
-  SRC_TYPE(spec) = 1;
-  SRC_HANDLE(spec) = info->handle.ems_handle;
-  SRC_PAGE(spec)   = (unsigned short) (file_offset / EMSPAGESIZE);
-  SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
-  DST_TYPE(spec) = 0;
-  DST_HANDLE(spec) = 0;
-  DST_PTR(spec)    = buffer_address;
-  
-  ctx.ds_si = (void far *) & spec;
-  ctx.ax = 0x5700;             /* move memory region */
-  jems_calldriver((EMScontext far *) & ctx);
-  if (HIBYTE(ctx.ax) != 0)
-    ERREXIT(cinfo, JERR_EMS_READ);
-}
-
-
-METHODDEF(void)
-write_ems_store (j_common_ptr cinfo, backing_store_ptr info,
-                void FAR * buffer_address,
-                long file_offset, long byte_count)
-{
-  EMScontext ctx;
-  EMSspec spec;
-
-  spec.length = byte_count;
-  SRC_TYPE(spec) = 0;
-  SRC_HANDLE(spec) = 0;
-  SRC_PTR(spec)    = buffer_address;
-  DST_TYPE(spec) = 1;
-  DST_HANDLE(spec) = info->handle.ems_handle;
-  DST_PAGE(spec)   = (unsigned short) (file_offset / EMSPAGESIZE);
-  DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
-  
-  ctx.ds_si = (void far *) & spec;
-  ctx.ax = 0x5700;             /* move memory region */
-  jems_calldriver((EMScontext far *) & ctx);
-  if (HIBYTE(ctx.ax) != 0)
-    ERREXIT(cinfo, JERR_EMS_WRITE);
-}
-
-
-METHODDEF(void)
-close_ems_store (j_common_ptr cinfo, backing_store_ptr info)
-{
-  EMScontext ctx;
-
-  ctx.ax = 0x4500;
-  ctx.dx = info->handle.ems_handle;
-  jems_calldriver((EMScontext far *) & ctx);
-  TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle);
-  /* we ignore any error return from the driver */
-}
-
-
-LOCAL(boolean)
-open_ems_store (j_common_ptr cinfo, backing_store_ptr info,
-               long total_bytes_needed)
-{
-  EMScontext ctx;
-
-  /* Is EMS driver there? */
-  if (! jems_available())
-    return FALSE;
-
-  /* Get status, make sure EMS is OK */
-  ctx.ax = 0x4000;
-  jems_calldriver((EMScontext far *) & ctx);
-  if (HIBYTE(ctx.ax) != 0)
-    return FALSE;
-
-  /* Get version, must be >= 4.0 */
-  ctx.ax = 0x4600;
-  jems_calldriver((EMScontext far *) & ctx);
-  if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40)
-    return FALSE;
-
-  /* Try to allocate requested space */
-  ctx.ax = 0x4300;
-  ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE);
-  jems_calldriver((EMScontext far *) & ctx);
-  if (HIBYTE(ctx.ax) != 0)
-    return FALSE;
-
-  /* Succeeded, save the handle and away we go */
-  info->handle.ems_handle = ctx.dx;
-  info->read_backing_store = read_ems_store;
-  info->write_backing_store = write_ems_store;
-  info->close_backing_store = close_ems_store;
-  TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx);
-  return TRUE;                 /* succeeded */
-}
-
-#endif /* EMS_SUPPORTED */
-
-
-/*
- * Initial opening of a backing-store object.
- */
-
-GLOBAL(void)
-jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
-                        long total_bytes_needed)
-{
-  /* Try extended memory, then expanded memory, then regular file. */
-#if XMS_SUPPORTED
-  if (open_xms_store(cinfo, info, total_bytes_needed))
-    return;
-#endif
-#if EMS_SUPPORTED
-  if (open_ems_store(cinfo, info, total_bytes_needed))
-    return;
-#endif
-  if (open_file_store(cinfo, info, total_bytes_needed))
-    return;
-  ERREXITS(cinfo, JERR_TFILE_CREATE, "");
-}
-
-
-/*
- * These routines take care of any system-dependent initialization and
- * cleanup required.
- */
-
-GLOBAL(long)
-jpeg_mem_init (j_common_ptr cinfo)
-{
-  next_file_num = 0;           /* initialize temp file name generator */
-  return DEFAULT_MAX_MEM;      /* default for max_memory_to_use */
-}
-
-GLOBAL(void)
-jpeg_mem_term (j_common_ptr cinfo)
-{
-  /* Microsoft C, at least in v6.00A, will not successfully reclaim freed
-   * blocks of size > 32Kbytes unless we give it a kick in the rear, like so:
-   */
-#ifdef NEED_FHEAPMIN
-  _fheapmin();
-#endif
-}
diff --git a/src/jpeg/libijg8/jmemmac.c b/src/jpeg/libijg8/jmemmac.c
deleted file mode 100644 (file)
index 106f9be..0000000
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * jmemmac.c
- *
- * Copyright (C) 1992-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * jmemmac.c provides an Apple Macintosh implementation of the system-
- * dependent portion of the JPEG memory manager.
- *
- * If you use jmemmac.c, then you must define USE_MAC_MEMMGR in the
- * JPEG_INTERNALS part of jconfig.h.
- *
- * jmemmac.c uses the Macintosh toolbox routines NewPtr and DisposePtr
- * instead of malloc and free.  It accurately determines the amount of
- * memory available by using CompactMem.  Notice that if left to its
- * own devices, this code can chew up all available space in the
- * application's zone, with the exception of the rather small "slop"
- * factor computed in jpeg_mem_available().  The application can ensure
- * that more space is left over by reducing max_memory_to_use.
- *
- * Large images are swapped to disk using temporary files and System 7.0+'s
- * temporary folder functionality.
- *
- * Note that jmemmac.c depends on two features of MacOS that were first
- * introduced in System 7: FindFolder and the FSSpec-based calls.
- * If your application uses jmemmac.c and is run under System 6 or earlier,
- * and the jpeg library decides it needs a temporary file, it will abort,
- * printing error messages about requiring System 7.  (If no temporary files
- * are created, it will run fine.)
- *
- * If you want to use jmemmac.c in an application that might be used with
- * System 6 or earlier, then you should remove dependencies on FindFolder
- * and the FSSpec calls.  You will need to replace FindFolder with some
- * other mechanism for finding a place to put temporary files, and you
- * should replace the FSSpec calls with their HFS equivalents:
- *
- *     FSpDelete     ->  HDelete
- *     FSpGetFInfo   ->  HGetFInfo
- *     FSpCreate     ->  HCreate
- *     FSpOpenDF     ->  HOpen      *** Note: not HOpenDF ***
- *     FSMakeFSSpec  ->  (fill in spec by hand.)
- *
- * (Use HOpen instead of HOpenDF.  HOpen is just a glue-interface to PBHOpen,
- * which is on all HFS macs.  HOpenDF is a System 7 addition which avoids the
- * ages-old problem of names starting with a period.)
- *
- * Contributed by Sam Bushell (jsam@iagu.on.net) and
- * Dan Gildor (gyld@in-touch.com).
- */
-
-#define JPEG_INTERNALS
-#include "jinclude.h"
-#include "jpeglib.h"
-#include "jmemsys.h"    /* import the system-dependent declarations */
-
-#ifndef USE_MAC_MEMMGR /* make sure user got configuration right */
-  You forgot to define USE_MAC_MEMMGR in jconfig.h. /* deliberate syntax error */
-#endif
-
-#include <Memory.h>     /* we use the MacOS memory manager */
-#include <Files.h>      /* we use the MacOS File stuff */
-#include <Folders.h>    /* we use the MacOS HFS stuff */
-#include <Script.h>     /* for smSystemScript */
-#include <Gestalt.h>    /* we use Gestalt to test for specific functionality */
-
-#ifndef TEMP_FILE_NAME         /* can override from jconfig.h or Makefile */
-#define TEMP_FILE_NAME  "JPG%03d.TMP"
-#endif
-
-static int next_file_num;      /* to distinguish among several temp files */
-
-
-/*
- * Memory allocation and freeing are controlled by the MacOS library
- * routines NewPtr() and DisposePtr(), which allocate fixed-address
- * storage.  Unfortunately, the IJG library isn't smart enough to cope
- * with relocatable storage.
- */
-
-GLOBAL(void *)
-jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
-{
-  return (void *) NewPtr(sizeofobject);
-}
-
-GLOBAL(void)
-jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
-{
-  DisposePtr((Ptr) object);
-}
-
-
-/*
- * "Large" objects are treated the same as "small" ones.
- * NB: we include FAR keywords in the routine declarations simply for
- * consistency with the rest of the IJG code; FAR should expand to empty
- * on rational architectures like the Mac.
- */
-
-GLOBAL(void FAR *)
-jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
-{
-  return (void FAR *) NewPtr(sizeofobject);
-}
-
-GLOBAL(void)
-jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
-{
-  DisposePtr((Ptr) object);
-}
-
-
-/*
- * This routine computes the total memory space available for allocation.
- */
-
-GLOBAL(long)
-jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
-                   long max_bytes_needed, long already_allocated)
-{
-  long limit = cinfo->mem->max_memory_to_use - already_allocated;
-  long slop, mem;
-
-  /* Don't ask for more than what application has told us we may use */
-  if (max_bytes_needed > limit && limit > 0)
-    max_bytes_needed = limit;
-  /* Find whether there's a big enough free block in the heap.
-   * CompactMem tries to create a contiguous block of the requested size,
-   * and then returns the size of the largest free block (which could be
-   * much more or much less than we asked for).
-   * We add some slop to ensure we don't use up all available memory.
-   */
-  slop = max_bytes_needed / 16 + 32768L;
-  mem = CompactMem(max_bytes_needed + slop) - slop;
-  if (mem < 0)
-    mem = 0;                   /* sigh, couldn't even get the slop */
-  /* Don't take more than the application says we can have */
-  if (mem > limit && limit > 0)
-    mem = limit;
-  return mem;
-}
-
-
-/*
- * Backing store (temporary file) management.
- * Backing store objects are only used when the value returned by
- * jpeg_mem_available is less than the total space needed.  You can dispense
- * with these routines if you have plenty of virtual memory; see jmemnobs.c.
- */
-
-
-METHODDEF(void)
-read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
-                   void FAR * buffer_address,
-                   long file_offset, long byte_count)
-{
-  long bytes = byte_count;
-  long retVal;
-
-  if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr )
-    ERREXIT(cinfo, JERR_TFILE_SEEK);
-
-  retVal = FSRead ( info->temp_file, &bytes,
-                   (unsigned char *) buffer_address );
-  if ( retVal != noErr || bytes != byte_count )
-    ERREXIT(cinfo, JERR_TFILE_READ);
-}
-
-
-METHODDEF(void)
-write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
-                    void FAR * buffer_address,
-                    long file_offset, long byte_count)
-{
-  long bytes = byte_count;
-  long retVal;
-
-  if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr )
-    ERREXIT(cinfo, JERR_TFILE_SEEK);
-
-  retVal = FSWrite ( info->temp_file, &bytes,
-                    (unsigned char *) buffer_address );
-  if ( retVal != noErr || bytes != byte_count )
-    ERREXIT(cinfo, JERR_TFILE_WRITE);
-}
-
-
-METHODDEF(void)
-close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
-{
-  FSClose ( info->temp_file );
-  FSpDelete ( &(info->tempSpec) );
-}
-
-
-/*
- * Initial opening of a backing-store object.
- *
- * This version uses FindFolder to find the Temporary Items folder,
- * and puts the temporary file in there.
- */
-
-GLOBAL(void)
-jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
-                        long total_bytes_needed)
-{
-  short         tmpRef, vRefNum;
-  long          dirID;
-  FInfo         finderInfo;
-  FSSpec        theSpec;
-  Str255        fName;
-  OSErr         osErr;
-  long          gestaltResponse = 0;
-
-  /* Check that FSSpec calls are available. */
-  osErr = Gestalt( gestaltFSAttr, &gestaltResponse );
-  if ( ( osErr != noErr )
-       || !( gestaltResponse & (1<<gestaltHasFSSpecCalls) ) )
-    ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required");
-  /* TO DO: add a proper error message to jerror.h. */
-
-  /* Check that FindFolder is available. */
-  osErr = Gestalt( gestaltFindFolderAttr, &gestaltResponse );
-  if ( ( osErr != noErr )
-       || !( gestaltResponse & (1<<gestaltFindFolderPresent) ) )
-    ERREXITS(cinfo, JERR_TFILE_CREATE, "- System 7.0 or later required.");
-  /* TO DO: add a proper error message to jerror.h. */
-
-  osErr = FindFolder ( kOnSystemDisk, kTemporaryFolderType, kCreateFolder,
-                       &vRefNum, &dirID );
-  if ( osErr != noErr )
-    ERREXITS(cinfo, JERR_TFILE_CREATE, "- temporary items folder unavailable");
-  /* TO DO: Try putting the temp files somewhere else. */
-
-  /* Keep generating file names till we find one that's not in use */
-  for (;;) {
-    next_file_num++;           /* advance counter */
-
-    sprintf(info->temp_name, TEMP_FILE_NAME, next_file_num);
-    strcpy ( (Ptr)fName+1, info->temp_name );
-    *fName = strlen (info->temp_name);
-    osErr = FSMakeFSSpec ( vRefNum, dirID, fName, &theSpec );
-
-    if ( (osErr = FSpGetFInfo ( &theSpec, &finderInfo ) ) != noErr )
-      break;
-  }
-
-  osErr = FSpCreate ( &theSpec, '????', '????', smSystemScript );
-  if ( osErr != noErr )
-    ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
-
-  osErr = FSpOpenDF ( &theSpec, fsRdWrPerm, &(info->temp_file) );
-  if ( osErr != noErr )
-    ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
-
-  info->tempSpec = theSpec;
-
-  info->read_backing_store = read_backing_store;
-  info->write_backing_store = write_backing_store;
-  info->close_backing_store = close_backing_store;
-  TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
-}
-
-
-/*
- * These routines take care of any system-dependent initialization and
- * cleanup required.
- */
-
-GLOBAL(long)
-jpeg_mem_init (j_common_ptr cinfo)
-{
-  next_file_num = 0;
-
-  /* max_memory_to_use will be initialized to FreeMem()'s result;
-   * the calling application might later reduce it, for example
-   * to leave room to invoke multiple JPEG objects.
-   * Note that FreeMem returns the total number of free bytes;
-   * it may not be possible to allocate a single block of this size.
-   */
-  return FreeMem();
-}
-
-GLOBAL(void)
-jpeg_mem_term (j_common_ptr cinfo)
-{
-  /* no work */
-}
diff --git a/src/jpeg/libijg8/jmemname.c b/src/jpeg/libijg8/jmemname.c
deleted file mode 100644 (file)
index ed96dee..0000000
+++ /dev/null
@@ -1,276 +0,0 @@
-/*
- * jmemname.c
- *
- * Copyright (C) 1992-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file provides a generic implementation of the system-dependent
- * portion of the JPEG memory manager.  This implementation assumes that
- * you must explicitly construct a name for each temp file.
- * Also, the problem of determining the amount of memory available
- * is shoved onto the user.
- */
-
-#define JPEG_INTERNALS
-#include "jinclude.h"
-#include "jpeglib.h"
-#include "jmemsys.h"           /* import the system-dependent declarations */
-
-#ifndef HAVE_STDLIB_H          /* <stdlib.h> should declare malloc(),free() */
-extern void * malloc JPP((size_t size));
-extern void free JPP((void *ptr));
-#endif
-
-#ifndef SEEK_SET               /* pre-ANSI systems may not define this; */
-#define SEEK_SET  0            /* if not, assume 0 is correct */
-#endif
-
-#ifdef DONT_USE_B_MODE         /* define mode parameters for fopen() */
-#define READ_BINARY    "r"
-#define RW_BINARY      "w+"
-#else
-#ifdef VMS                     /* VMS is very nonstandard */
-#define READ_BINARY    "rb", "ctx=stm"
-#define RW_BINARY      "w+b", "ctx=stm"
-#else                          /* standard ANSI-compliant case */
-#define READ_BINARY    "rb"
-#define RW_BINARY      "w+b"
-#endif
-#endif
-
-
-/*
- * Selection of a file name for a temporary file.
- * This is system-dependent!
- *
- * The code as given is suitable for most Unix systems, and it is easily
- * modified for most non-Unix systems.  Some notes:
- *  1.  The temp file is created in the directory named by TEMP_DIRECTORY.
- *      The default value is /usr/tmp, which is the conventional place for
- *      creating large temp files on Unix.  On other systems you'll probably
- *      want to change the file location.  You can do this by editing the
- *      #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h.
- *
- *  2.  If you need to change the file name as well as its location,
- *      you can override the TEMP_FILE_NAME macro.  (Note that this is
- *      actually a printf format string; it must contain %s and %d.)
- *      Few people should need to do this.
- *
- *  3.  mktemp() is used to ensure that multiple processes running
- *      simultaneously won't select the same file names.  If your system
- *      doesn't have mktemp(), define NO_MKTEMP to do it the hard way.
- *      (If you don't have <errno.h>, also define NO_ERRNO_H.)
- *
- *  4.  You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c
- *      will cause the temp files to be removed if you stop the program early.
- */
-
-#ifndef TEMP_DIRECTORY         /* can override from jconfig.h or Makefile */
-#define TEMP_DIRECTORY  "/usr/tmp/" /* recommended setting for Unix */
-#endif
-
-static int next_file_num;      /* to distinguish among several temp files */
-
-#ifdef NO_MKTEMP
-
-#ifndef TEMP_FILE_NAME         /* can override from jconfig.h or Makefile */
-#define TEMP_FILE_NAME  "%sJPG%03d.TMP"
-#endif
-
-#ifndef NO_ERRNO_H
-#include <errno.h>             /* to define ENOENT */
-#endif
-
-/* ANSI C specifies that errno is a macro, but on older systems it's more
- * likely to be a plain int variable.  And not all versions of errno.h
- * bother to declare it, so we have to in order to be most portable.  Thus:
- */
-#ifndef errno
-extern int errno;
-#endif
-
-
-LOCAL(void)
-select_file_name (char * fname)
-{
-  FILE * tfile;
-
-  /* Keep generating file names till we find one that's not in use */
-  for (;;) {
-    next_file_num++;           /* advance counter */
-    sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);
-    if ((tfile = fopen(fname, READ_BINARY)) == NULL) {
-      /* fopen could have failed for a reason other than the file not
-       * being there; for example, file there but unreadable.
-       * If <errno.h> isn't available, then we cannot test the cause.
-       */
-#ifdef ENOENT
-      if (errno != ENOENT)
-       continue;
-#endif
-      break;
-    }
-    fclose(tfile);             /* oops, it's there; close tfile & try again */
-  }
-}
-
-#else /* ! NO_MKTEMP */
-
-/* Note that mktemp() requires the initial filename to end in six X's */
-#ifndef TEMP_FILE_NAME         /* can override from jconfig.h or Makefile */
-#define TEMP_FILE_NAME  "%sJPG%dXXXXXX"
-#endif
-
-LOCAL(void)
-select_file_name (char * fname)
-{
-  next_file_num++;             /* advance counter */
-  sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);
-  mktemp(fname);               /* make sure file name is unique */
-  /* mktemp replaces the trailing XXXXXX with a unique string of characters */
-}
-
-#endif /* NO_MKTEMP */
-
-
-/*
- * Memory allocation and freeing are controlled by the regular library
- * routines malloc() and free().
- */
-
-GLOBAL(void *)
-jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
-{
-  return (void *) malloc(sizeofobject);
-}
-
-GLOBAL(void)
-jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
-{
-  free(object);
-}
-
-
-/*
- * "Large" objects are treated the same as "small" ones.
- * NB: although we include FAR keywords in the routine declarations,
- * this file won't actually work in 80x86 small/medium model; at least,
- * you probably won't be able to process useful-size images in only 64KB.
- */
-
-GLOBAL(void FAR *)
-jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
-{
-  return (void FAR *) malloc(sizeofobject);
-}
-
-GLOBAL(void)
-jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
-{
-  free(object);
-}
-
-
-/*
- * This routine computes the total memory space available for allocation.
- * It's impossible to do this in a portable way; our current solution is
- * to make the user tell us (with a default value set at compile time).
- * If you can actually get the available space, it's a good idea to subtract
- * a slop factor of 5% or so.
- */
-
-#ifndef DEFAULT_MAX_MEM                /* so can override from makefile */
-#define DEFAULT_MAX_MEM                1000000L /* default: one megabyte */
-#endif
-
-GLOBAL(long)
-jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
-                   long max_bytes_needed, long already_allocated)
-{
-  return cinfo->mem->max_memory_to_use - already_allocated;
-}
-
-
-/*
- * Backing store (temporary file) management.
- * Backing store objects are only used when the value returned by
- * jpeg_mem_available is less than the total space needed.  You can dispense
- * with these routines if you have plenty of virtual memory; see jmemnobs.c.
- */
-
-
-METHODDEF(void)
-read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
-                   void FAR * buffer_address,
-                   long file_offset, long byte_count)
-{
-  if (fseek(info->temp_file, file_offset, SEEK_SET))
-    ERREXIT(cinfo, JERR_TFILE_SEEK);
-  if (JFREAD(info->temp_file, buffer_address, byte_count)
-      != (size_t) byte_count)
-    ERREXIT(cinfo, JERR_TFILE_READ);
-}
-
-
-METHODDEF(void)
-write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
-                    void FAR * buffer_address,
-                    long file_offset, long byte_count)
-{
-  if (fseek(info->temp_file, file_offset, SEEK_SET))
-    ERREXIT(cinfo, JERR_TFILE_SEEK);
-  if (JFWRITE(info->temp_file, buffer_address, byte_count)
-      != (size_t) byte_count)
-    ERREXIT(cinfo, JERR_TFILE_WRITE);
-}
-
-
-METHODDEF(void)
-close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
-{
-  fclose(info->temp_file);     /* close the file */
-  unlink(info->temp_name);     /* delete the file */
-/* If your system doesn't have unlink(), use remove() instead.
- * remove() is the ANSI-standard name for this function, but if
- * your system was ANSI you'd be using jmemansi.c, right?
- */
-  TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);
-}
-
-
-/*
- * Initial opening of a backing-store object.
- */
-
-GLOBAL(void)
-jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
-                        long total_bytes_needed)
-{
-  select_file_name(info->temp_name);
-  if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL)
-    ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
-  info->read_backing_store = read_backing_store;
-  info->write_backing_store = write_backing_store;
-  info->close_backing_store = close_backing_store;
-  TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
-}
-
-
-/*
- * These routines take care of any system-dependent initialization and
- * cleanup required.
- */
-
-GLOBAL(long)
-jpeg_mem_init (j_common_ptr cinfo)
-{
-  next_file_num = 0;           /* initialize temp file name generator */
-  return DEFAULT_MAX_MEM;      /* default for max_memory_to_use */
-}
-
-GLOBAL(void)
-jpeg_mem_term (j_common_ptr cinfo)
-{
-  /* no work */
-}
diff --git a/src/jpeg/libijg8/rdbmp.c b/src/jpeg/libijg8/rdbmp.c
deleted file mode 100644 (file)
index b05fe2a..0000000
+++ /dev/null
@@ -1,439 +0,0 @@
-/*
- * rdbmp.c
- *
- * Copyright (C) 1994-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to read input images in Microsoft "BMP"
- * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors).
- * Currently, only 8-bit and 24-bit images are supported, not 1-bit or
- * 4-bit (feeding such low-depth images into JPEG would be silly anyway).
- * Also, we don't support RLE-compressed files.
- *
- * These routines may need modification for non-Unix environments or
- * specialized applications.  As they stand, they assume input from
- * an ordinary stdio stream.  They further assume that reading begins
- * at the start of the file; start_input may need work if the
- * user interface has already read some data (e.g., to determine that
- * the file is indeed BMP format).
- *
- * This code contributed by James Arthur Boucher.
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef BMP_SUPPORTED
-
-
-/* Macros to deal with unsigned chars as efficiently as compiler allows */
-
-#ifdef HAVE_UNSIGNED_CHAR
-typedef unsigned char U_CHAR;
-#define UCH(x) ((int) (x))
-#else /* !HAVE_UNSIGNED_CHAR */
-#ifdef CHAR_IS_UNSIGNED
-typedef char U_CHAR;
-#define UCH(x) ((int) (x))
-#else
-typedef char U_CHAR;
-#define UCH(x) ((int) (x) & 0xFF)
-#endif
-#endif /* HAVE_UNSIGNED_CHAR */
-
-
-#define        ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
-
-
-/* Private version of data source object */
-
-typedef struct _bmp_source_struct * bmp_source_ptr;
-
-typedef struct _bmp_source_struct {
-  struct cjpeg_source_struct pub; /* public fields */
-
-  j_compress_ptr cinfo;                /* back link saves passing separate parm */
-
-  JSAMPARRAY colormap;         /* BMP colormap (converted to my format) */
-
-  jvirt_sarray_ptr whole_image;        /* Needed to reverse row order */
-  JDIMENSION source_row;       /* Current source row number */
-  JDIMENSION row_width;                /* Physical width of scanlines in file */
-
-  int bits_per_pixel;          /* remembers 8- or 24-bit format */
-} bmp_source_struct;
-
-
-LOCAL(int)
-read_byte (bmp_source_ptr sinfo)
-/* Read next byte from BMP file */
-{
-  register FILE *infile = sinfo->pub.input_file;
-  register int c;
-
-  if ((c = getc(infile)) == EOF)
-    ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
-  return c;
-}
-
-
-LOCAL(void)
-read_colormap (bmp_source_ptr sinfo, int cmaplen, int mapentrysize)
-/* Read the colormap from a BMP file */
-{
-  int i;
-
-  switch (mapentrysize) {
-  case 3:
-    /* BGR format (occurs in OS/2 files) */
-    for (i = 0; i < cmaplen; i++) {
-      sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);
-      sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);
-      sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);
-    }
-    break;
-  case 4:
-    /* BGR0 format (occurs in MS Windows files) */
-    for (i = 0; i < cmaplen; i++) {
-      sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);
-      sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);
-      sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);
-      (void) read_byte(sinfo);
-    }
-    break;
-  default:
-    ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP);
-    break;
-  }
-}
-
-
-/*
- * Read one row of pixels.
- * The image has been read into the whole_image array, but is otherwise
- * unprocessed.  We must read it out in top-to-bottom row order, and if
- * it is an 8-bit image, we must expand colormapped pixels to 24bit format.
- */
-
-METHODDEF(JDIMENSION)
-get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading 8-bit colormap indexes */
-{
-  bmp_source_ptr source = (bmp_source_ptr) sinfo;
-  register JSAMPARRAY colormap = source->colormap;
-  JSAMPARRAY image_ptr;
-  register int t;
-  register JSAMPROW inptr, outptr;
-  register JDIMENSION col;
-
-  /* Fetch next row from virtual array */
-  source->source_row--;
-  image_ptr = (*cinfo->mem->access_virt_sarray)
-    ((j_common_ptr) cinfo, source->whole_image,
-     source->source_row, (JDIMENSION) 1, FALSE);
-
-  /* Expand the colormap indexes to real data */
-  inptr = image_ptr[0];
-  outptr = source->pub.buffer[0];
-  for (col = cinfo->image_width; col > 0; col--) {
-    t = GETJSAMPLE(*inptr++);
-    *outptr++ = colormap[0][t];        /* can omit GETJSAMPLE() safely */
-    *outptr++ = colormap[1][t];
-    *outptr++ = colormap[2][t];
-  }
-
-  return 1;
-}
-
-
-METHODDEF(JDIMENSION)
-get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading 24-bit pixels */
-{
-  bmp_source_ptr source = (bmp_source_ptr) sinfo;
-  JSAMPARRAY image_ptr;
-  register JSAMPROW inptr, outptr;
-  register JDIMENSION col;
-
-  /* Fetch next row from virtual array */
-  source->source_row--;
-  image_ptr = (*cinfo->mem->access_virt_sarray)
-    ((j_common_ptr) cinfo, source->whole_image,
-     source->source_row, (JDIMENSION) 1, FALSE);
-
-  /* Transfer data.  Note source values are in BGR order
-   * (even though Microsoft's own documents say the opposite).
-   */
-  inptr = image_ptr[0];
-  outptr = source->pub.buffer[0];
-  for (col = cinfo->image_width; col > 0; col--) {
-    outptr[2] = *inptr++;      /* can omit GETJSAMPLE() safely */
-    outptr[1] = *inptr++;
-    outptr[0] = *inptr++;
-    outptr += 3;
-  }
-
-  return 1;
-}
-
-
-/*
- * This method loads the image into whole_image during the first call on
- * get_pixel_rows.  The get_pixel_rows pointer is then adjusted to call
- * get_8bit_row or get_24bit_row on subsequent calls.
- */
-
-METHODDEF(JDIMENSION)
-preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  bmp_source_ptr source = (bmp_source_ptr) sinfo;
-  register FILE *infile = source->pub.input_file;
-  register int c;
-  register JSAMPROW out_ptr;
-  JSAMPARRAY image_ptr;
-  JDIMENSION row, col;
-  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
-
-  /* Read the data into a virtual array in input-file row order. */
-  for (row = 0; row < cinfo->image_height; row++) {
-    if (progress != NULL) {
-      progress->pub.pass_counter = (long) row;
-      progress->pub.pass_limit = (long) cinfo->image_height;
-      (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
-    }
-    image_ptr = (*cinfo->mem->access_virt_sarray)
-      ((j_common_ptr) cinfo, source->whole_image,
-       row, (JDIMENSION) 1, TRUE);
-    out_ptr = image_ptr[0];
-    for (col = source->row_width; col > 0; col--) {
-      /* inline copy of read_byte() for speed */
-      if ((c = getc(infile)) == EOF)
-       ERREXIT(cinfo, JERR_INPUT_EOF);
-      *out_ptr++ = (JSAMPLE) c;
-    }
-  }
-  if (progress != NULL)
-    progress->completed_extra_passes++;
-
-  /* Set up to read from the virtual array in top-to-bottom order */
-  switch (source->bits_per_pixel) {
-  case 8:
-    source->pub.get_pixel_rows = get_8bit_row;
-    break;
-  case 24:
-    source->pub.get_pixel_rows = get_24bit_row;
-    break;
-  default:
-    ERREXIT(cinfo, JERR_BMP_BADDEPTH);
-  }
-  source->source_row = cinfo->image_height;
-
-  /* And read the first row */
-  return (*source->pub.get_pixel_rows) (cinfo, sinfo);
-}
-
-
-/*
- * Read the file header; return image size and component count.
- */
-
-METHODDEF(void)
-start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  bmp_source_ptr source = (bmp_source_ptr) sinfo;
-  U_CHAR bmpfileheader[14];
-  U_CHAR bmpinfoheader[64];
-#define GET_2B(array,offset)  ((unsigned int) UCH(array[offset]) + \
-                              (((unsigned int) UCH(array[offset+1])) << 8))
-#define GET_4B(array,offset)  ((INT32) UCH(array[offset]) + \
-                              (((INT32) UCH(array[offset+1])) << 8) + \
-                              (((INT32) UCH(array[offset+2])) << 16) + \
-                              (((INT32) UCH(array[offset+3])) << 24))
-  INT32 bfOffBits;
-  INT32 headerSize;
-  INT32 biWidth = 0;           /* initialize to avoid compiler warning */
-  INT32 biHeight = 0;
-  unsigned int biPlanes;
-  INT32 biCompression;
-  INT32 biXPelsPerMeter,biYPelsPerMeter;
-  INT32 biClrUsed = 0;
-  int mapentrysize = 0;                /* 0 indicates no colormap */
-  INT32 bPad;
-  JDIMENSION row_width;
-
-  /* Read and verify the bitmap file header */
-  if (! ReadOK(source->pub.input_file, bmpfileheader, 14))
-    ERREXIT(cinfo, JERR_INPUT_EOF);
-  if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */
-    ERREXIT(cinfo, JERR_BMP_NOT);
-  bfOffBits = (INT32) GET_4B(bmpfileheader,10);
-  /* We ignore the remaining fileheader fields */
-
-  /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows),
-   * or 64 bytes (OS/2 2.x).  Check the first 4 bytes to find out which.
-   */
-  if (! ReadOK(source->pub.input_file, bmpinfoheader, 4))
-    ERREXIT(cinfo, JERR_INPUT_EOF);
-  headerSize = (INT32) GET_4B(bmpinfoheader,0);
-  if (headerSize < 12 || headerSize > 64)
-    ERREXIT(cinfo, JERR_BMP_BADHEADER);
-  if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4))
-    ERREXIT(cinfo, JERR_INPUT_EOF);
-
-  switch ((int) headerSize) {
-  case 12:
-    /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */
-    biWidth = (INT32) GET_2B(bmpinfoheader,4);
-    biHeight = (INT32) GET_2B(bmpinfoheader,6);
-    biPlanes = GET_2B(bmpinfoheader,8);
-    source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10);
-
-    switch (source->bits_per_pixel) {
-    case 8:                    /* colormapped image */
-      mapentrysize = 3;                /* OS/2 uses RGBTRIPLE colormap */
-      TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight);
-      break;
-    case 24:                   /* RGB image */
-      TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight);
-      break;
-    default:
-      ERREXIT(cinfo, JERR_BMP_BADDEPTH);
-      break;
-    }
-    if (biPlanes != 1)
-      ERREXIT(cinfo, JERR_BMP_BADPLANES);
-    break;
-  case 40:
-  case 64:
-    /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */
-    /* or OS/2 2.x header, which has additional fields that we ignore */
-    biWidth = GET_4B(bmpinfoheader,4);
-    biHeight = GET_4B(bmpinfoheader,8);
-    biPlanes = GET_2B(bmpinfoheader,12);
-    source->bits_per_pixel = (int) GET_2B(bmpinfoheader,14);
-    biCompression = GET_4B(bmpinfoheader,16);
-    biXPelsPerMeter = GET_4B(bmpinfoheader,24);
-    biYPelsPerMeter = GET_4B(bmpinfoheader,28);
-    biClrUsed = GET_4B(bmpinfoheader,32);
-    /* biSizeImage, biClrImportant fields are ignored */
-
-    switch (source->bits_per_pixel) {
-    case 8:                    /* colormapped image */
-      mapentrysize = 4;                /* Windows uses RGBQUAD colormap */
-      TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight);
-      break;
-    case 24:                   /* RGB image */
-      TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight);
-      break;
-    default:
-      ERREXIT(cinfo, JERR_BMP_BADDEPTH);
-      break;
-    }
-    if (biPlanes != 1)
-      ERREXIT(cinfo, JERR_BMP_BADPLANES);
-    if (biCompression != 0)
-      ERREXIT(cinfo, JERR_BMP_COMPRESSED);
-
-    if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) {
-      /* Set JFIF density parameters from the BMP data */
-      cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */
-      cinfo->Y_density = (UINT16) (biYPelsPerMeter/100);
-      cinfo->density_unit = 2; /* dots/cm */
-    }
-    break;
-  default:
-    ERREXIT(cinfo, JERR_BMP_BADHEADER);
-    break;
-  }
-
-  /* Compute distance to bitmap data --- will adjust for colormap below */
-  bPad = bfOffBits - (headerSize + 14);
-
-  /* Read the colormap, if any */
-  if (mapentrysize > 0) {
-    if (biClrUsed <= 0)
-      biClrUsed = 256;         /* assume it's 256 */
-    else if (biClrUsed > 256)
-      ERREXIT(cinfo, JERR_BMP_BADCMAP);
-    /* Allocate space to store the colormap */
-    source->colormap = (*cinfo->mem->alloc_sarray)
-      ((j_common_ptr) cinfo, JPOOL_IMAGE,
-       (JDIMENSION) biClrUsed, (JDIMENSION) 3);
-    /* and read it from the file */
-    read_colormap(source, (int) biClrUsed, mapentrysize);
-    /* account for size of colormap */
-    bPad -= biClrUsed * mapentrysize;
-  }
-
-  /* Skip any remaining pad bytes */
-  if (bPad < 0)                        /* incorrect bfOffBits value? */
-    ERREXIT(cinfo, JERR_BMP_BADHEADER);
-  while (--bPad >= 0) {
-    (void) read_byte(source);
-  }
-
-  /* Compute row width in file, including padding to 4-byte boundary */
-  if (source->bits_per_pixel == 24)
-    row_width = (JDIMENSION) (biWidth * 3);
-  else
-    row_width = (JDIMENSION) biWidth;
-  while ((row_width & 3) != 0) row_width++;
-  source->row_width = row_width;
-
-  /* Allocate space for inversion array, prepare for preload pass */
-  source->whole_image = (*cinfo->mem->request_virt_sarray)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
-     row_width, (JDIMENSION) biHeight, (JDIMENSION) 1);
-  source->pub.get_pixel_rows = preload_image;
-  if (cinfo->progress != NULL) {
-    cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
-    progress->total_extra_passes++; /* count file input as separate pass */
-  }
-
-  /* Allocate one-row buffer for returned data */
-  source->pub.buffer = (*cinfo->mem->alloc_sarray)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE,
-     (JDIMENSION) (biWidth * 3), (JDIMENSION) 1);
-  source->pub.buffer_height = 1;
-
-  cinfo->in_color_space = JCS_RGB;
-  cinfo->input_components = 3;
-  cinfo->data_precision = 8;
-  cinfo->image_width = (JDIMENSION) biWidth;
-  cinfo->image_height = (JDIMENSION) biHeight;
-}
-
-
-/*
- * Finish up at the end of the file.
- */
-
-METHODDEF(void)
-finish_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  /* no work */
-}
-
-
-/*
- * The module selection routine for BMP format input.
- */
-
-GLOBAL(cjpeg_source_ptr)
-jinit_read_bmp (j_compress_ptr cinfo)
-{
-  bmp_source_ptr source;
-
-  /* Create module interface object */
-  source = (bmp_source_ptr)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                 SIZEOF(bmp_source_struct));
-  source->cinfo = cinfo;       /* make back link for subroutines */
-  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
-  source->pub.start_input = start_input_bmp;
-  source->pub.finish_input = finish_input_bmp;
-
-  return (cjpeg_source_ptr) source;
-}
-
-#endif /* BMP_SUPPORTED */
diff --git a/src/jpeg/libijg8/rdcolmap.c b/src/jpeg/libijg8/rdcolmap.c
deleted file mode 100644 (file)
index 42b3437..0000000
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * rdcolmap.c
- *
- * Copyright (C) 1994-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file implements djpeg's "-map file" switch.  It reads a source image
- * and constructs a colormap to be supplied to the JPEG decompressor.
- *
- * Currently, these file formats are supported for the map file:
- *   GIF: the contents of the GIF's global colormap are used.
- *   PPM (either text or raw flavor): the entire file is read and
- *      each unique pixel value is entered in the map.
- * Note that reading a large PPM file will be horrendously slow.
- * Typically, a PPM-format map file should contain just one pixel
- * of each desired color.  Such a file can be extracted from an
- * ordinary image PPM file with ppmtomap(1).
- *
- * Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not
- * currently implemented.
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef QUANT_2PASS_SUPPORTED   /* otherwise can't quantize to supplied map */
-
-/* Portions of this code are based on the PBMPLUS library, which is:
-**
-** Copyright (C) 1988 by Jef Poskanzer.
-**
-** Permission to use, copy, modify, and distribute this software and its
-** documentation for any purpose and without fee is hereby granted, provided
-** that the above copyright notice appear in all copies and that both that
-** copyright notice and this permission notice appear in supporting
-** documentation.  This software is provided "as is" without express or
-** implied warranty.
-*/
-
-
-/*
- * Add a (potentially) new color to the color map.
- */
-
-LOCAL(void)
-add_map_entry (j_decompress_ptr cinfo, int R, int G, int B)
-{
-  JSAMPROW colormap0 = cinfo->colormap[0];
-  JSAMPROW colormap1 = cinfo->colormap[1];
-  JSAMPROW colormap2 = cinfo->colormap[2];
-  int ncolors = cinfo->actual_number_of_colors;
-  int index;
-
-  /* Check for duplicate color. */
-  for (index = 0; index < ncolors; index++) {
-    if (GETJSAMPLE(colormap0[index]) == R &&
-       GETJSAMPLE(colormap1[index]) == G &&
-       GETJSAMPLE(colormap2[index]) == B)
-      return;                  /* color is already in map */
-  }
-
-  /* Check for map overflow. */
-  if (ncolors >= (MAXJSAMPLE+1))
-    ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1));
-
-  /* OK, add color to map. */
-  colormap0[ncolors] = (JSAMPLE) R;
-  colormap1[ncolors] = (JSAMPLE) G;
-  colormap2[ncolors] = (JSAMPLE) B;
-  cinfo->actual_number_of_colors++;
-}
-
-
-/*
- * Extract color map from a GIF file.
- */
-
-LOCAL(void)
-read_gif_map (j_decompress_ptr cinfo, FILE * infile)
-{
-  int header[13];
-  int i, colormaplen;
-  int R, G, B;
-
-  /* Initial 'G' has already been read by read_color_map */
-  /* Read the rest of the GIF header and logical screen descriptor */
-  for (i = 1; i < 13; i++) {
-    if ((header[i] = getc(infile)) == EOF)
-      ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-  }
-
-  /* Verify GIF Header */
-  if (header[1] != 'I' || header[2] != 'F')
-    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-
-  /* There must be a global color map. */
-  if ((header[10] & 0x80) == 0)
-    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-
-  /* OK, fetch it. */
-  colormaplen = 2 << (header[10] & 0x07);
-
-  for (i = 0; i < colormaplen; i++) {
-    R = getc(infile);
-    G = getc(infile);
-    B = getc(infile);
-    if (R == EOF || G == EOF || B == EOF)
-      ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-    add_map_entry(cinfo,
-                 R << (BITS_IN_JSAMPLE-8),
-                 G << (BITS_IN_JSAMPLE-8),
-                 B << (BITS_IN_JSAMPLE-8));
-  }
-}
-
-
-/* Support routines for reading PPM */
-
-
-LOCAL(int)
-pbm_getc (FILE * infile)
-/* Read next char, skipping over any comments */
-/* A comment/newline sequence is returned as a newline */
-{
-  register int ch;
-  
-  ch = getc(infile);
-  if (ch == '#') {
-    do {
-      ch = getc(infile);
-    } while (ch != '\n' && ch != EOF);
-  }
-  return ch;
-}
-
-
-LOCAL(unsigned int)
-read_pbm_integer (j_decompress_ptr cinfo, FILE * infile)
-/* Read an unsigned decimal integer from the PPM file */
-/* Swallows one trailing character after the integer */
-/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
-/* This should not be a problem in practice. */
-{
-  register int ch;
-  register unsigned int val;
-  
-  /* Skip any leading whitespace */
-  do {
-    ch = pbm_getc(infile);
-    if (ch == EOF)
-      ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
-  
-  if (ch < '0' || ch > '9')
-    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-  
-  val = ch - '0';
-  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
-    val *= 10;
-    val += ch - '0';
-  }
-  return val;
-}
-
-
-/*
- * Extract color map from a PPM file.
- */
-
-LOCAL(void)
-read_ppm_map (j_decompress_ptr cinfo, FILE * infile)
-{
-  int c;
-  unsigned int w, h, maxval, row, col;
-  int R, G, B;
-
-  /* Initial 'P' has already been read by read_color_map */
-  c = getc(infile);            /* save format discriminator for a sec */
-
-  /* while we fetch the remaining header info */
-  w = read_pbm_integer(cinfo, infile);
-  h = read_pbm_integer(cinfo, infile);
-  maxval = read_pbm_integer(cinfo, infile);
-
-  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
-    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-
-  /* For now, we don't support rescaling from an unusual maxval. */
-  if (maxval != (unsigned int) MAXJSAMPLE)
-    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-
-  switch (c) {
-  case '3':                    /* it's a text-format PPM file */
-    for (row = 0; row < h; row++) {
-      for (col = 0; col < w; col++) {
-       R = read_pbm_integer(cinfo, infile);
-       G = read_pbm_integer(cinfo, infile);
-       B = read_pbm_integer(cinfo, infile);
-       add_map_entry(cinfo, R, G, B);
-      }
-    }
-    break;
-
-  case '6':                    /* it's a raw-format PPM file */
-    for (row = 0; row < h; row++) {
-      for (col = 0; col < w; col++) {
-       R = getc(infile);
-       G = getc(infile);
-       B = getc(infile);
-       if (R == EOF || G == EOF || B == EOF)
-         ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-       add_map_entry(cinfo, R, G, B);
-      }
-    }
-    break;
-
-  default:
-    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-    break;
-  }
-}
-
-
-/*
- * Main entry point from djpeg.c.
- *  Input: opened input file (from file name argument on command line).
- *  Output: colormap and actual_number_of_colors fields are set in cinfo.
- */
-
-GLOBAL(void)
-read_color_map (j_decompress_ptr cinfo, FILE * infile)
-{
-  /* Allocate space for a color map of maximum supported size. */
-  cinfo->colormap = (*cinfo->mem->alloc_sarray)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE,
-     (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3);
-  cinfo->actual_number_of_colors = 0; /* initialize map to empty */
-
-  /* Read first byte to determine file format */
-  switch (getc(infile)) {
-  case 'G':
-    read_gif_map(cinfo, infile);
-    break;
-  case 'P':
-    read_ppm_map(cinfo, infile);
-    break;
-  default:
-    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
-    break;
-  }
-}
-
-#endif /* QUANT_2PASS_SUPPORTED */
diff --git a/src/jpeg/libijg8/rdgif.c b/src/jpeg/libijg8/rdgif.c
deleted file mode 100644 (file)
index b27c167..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * rdgif.c
- *
- * Copyright (C) 1991-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to read input images in GIF format.
- *
- *****************************************************************************
- * NOTE: to avoid entanglements with Unisys' patent on LZW compression,      *
- * the ability to read GIF files has been removed from the IJG distribution. *
- * Sorry about that.                                                         *
- *****************************************************************************
- *
- * We are required to state that
- *    "The Graphics Interchange Format(c) is the Copyright property of
- *    CompuServe Incorporated. GIF(sm) is a Service Mark property of
- *    CompuServe Incorporated."
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef GIF_SUPPORTED
-
-/*
- * The module selection routine for GIF format input.
- */
-
-GLOBAL(cjpeg_source_ptr)
-jinit_read_gif (j_compress_ptr cinfo)
-{
-  fprintf(stderr, "GIF input is unsupported for legal reasons.  Sorry.\n");
-  exit(EXIT_FAILURE);
-  return NULL;                 /* keep compiler happy */
-}
-
-#endif /* GIF_SUPPORTED */
diff --git a/src/jpeg/libijg8/rdjpgcom.c b/src/jpeg/libijg8/rdjpgcom.c
deleted file mode 100644 (file)
index ffe6fc6..0000000
+++ /dev/null
@@ -1,496 +0,0 @@
-/*
- * rdjpgcom.c
- *
- * Copyright (C) 1994-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains a very simple stand-alone application that displays
- * the text in COM (comment) markers in a JFIF file.
- * This may be useful as an example of the minimum logic needed to parse
- * JPEG markers.
- */
-
-#define JPEG_CJPEG_DJPEG       /* to get the command-line config symbols */
-#include "jinclude.h"          /* get auto-config symbols, <stdio.h> */
-
-#include <ctype.h>             /* to declare isupper(), tolower() */
-#ifdef USE_SETMODE
-#include <fcntl.h>             /* to declare setmode()'s parameter macros */
-/* If you have setmode() but not <io.h>, just delete this line: */
-#include <io.h>                        /* to declare setmode() */
-#endif
-
-#ifdef USE_CCOMMAND            /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h>              /* Metrowerks needs this */
-#include <console.h>           /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h>           /* Think declares it here */
-#endif
-#endif
-
-#ifdef DONT_USE_B_MODE         /* define mode parameters for fopen() */
-#define READ_BINARY    "r"
-#else
-#ifdef VMS                     /* VMS is very nonstandard */
-#define READ_BINARY    "rb", "ctx=stm"
-#else                          /* standard ANSI-compliant case */
-#define READ_BINARY    "rb"
-#endif
-#endif
-
-#ifndef EXIT_FAILURE           /* define exit() codes if not provided */
-#define EXIT_FAILURE  1
-#endif
-#ifndef EXIT_SUCCESS
-#ifdef VMS
-#define EXIT_SUCCESS  1                /* VMS is very nonstandard */
-#else
-#define EXIT_SUCCESS  0
-#endif
-#endif
-
-
-/*
- * These macros are used to read the input file.
- * To reuse this code in another application, you might need to change these.
- */
-
-static FILE * infile;          /* input JPEG file */
-
-/* Return next input byte, or EOF if no more */
-#define NEXTBYTE()  getc(infile)
-
-
-/* Error exit handler */
-#define ERREXIT(msg)  (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE))
-
-
-/* Read one byte, testing for EOF */
-static int
-read_1_byte (void)
-{
-  int c;
-
-  c = NEXTBYTE();
-  if (c == EOF)
-    ERREXIT("Premature EOF in JPEG file");
-  return c;
-}
-
-/* Read 2 bytes, convert to unsigned int */
-/* All 2-byte quantities in JPEG markers are MSB first */
-static unsigned int
-read_2_bytes (void)
-{
-  int c1, c2;
-
-  c1 = NEXTBYTE();
-  if (c1 == EOF)
-    ERREXIT("Premature EOF in JPEG file");
-  c2 = NEXTBYTE();
-  if (c2 == EOF)
-    ERREXIT("Premature EOF in JPEG file");
-  return (((unsigned int) c1) << 8) + ((unsigned int) c2);
-}
-
-
-/*
- * JPEG markers consist of one or more 0xFF bytes, followed by a marker
- * code byte (which is not an FF).  Here are the marker codes of interest
- * in this program.  (See jdmarker.c for a more complete list.)
- */
-
-#define M_SOF0  0xC0           /* Start Of Frame N */
-#define M_SOF1  0xC1           /* N indicates which compression process */
-#define M_SOF2  0xC2           /* Only SOF0-SOF2 are now in common use */
-#define M_SOF3  0xC3
-#define M_SOF5  0xC5           /* NB: codes C4 and CC are NOT SOF markers */
-#define M_SOF6  0xC6
-#define M_SOF7  0xC7
-#define M_SOF9  0xC9
-#define M_SOF10 0xCA
-#define M_SOF11 0xCB
-#define M_SOF13 0xCD
-#define M_SOF14 0xCE
-#define M_SOF15 0xCF
-#define M_SOI   0xD8           /* Start Of Image (beginning of datastream) */
-#define M_EOI   0xD9           /* End Of Image (end of datastream) */
-#define M_SOS   0xDA           /* Start Of Scan (begins compressed data) */
-#define M_APP0 0xE0            /* Application-specific marker, type N */
-#define M_APP12        0xEC            /* (we don't bother to list all 16 APPn's) */
-#define M_COM   0xFE           /* COMment */
-
-
-/*
- * Find the next JPEG marker and return its marker code.
- * We expect at least one FF byte, possibly more if the compressor used FFs
- * to pad the file.
- * There could also be non-FF garbage between markers.  The treatment of such
- * garbage is unspecified; we choose to skip over it but emit a warning msg.
- * NB: this routine must not be used after seeing SOS marker, since it will
- * not deal correctly with FF/00 sequences in the compressed image data...
- */
-
-static int
-next_marker (void)
-{
-  int c;
-  int discarded_bytes = 0;
-
-  /* Find 0xFF byte; count and skip any non-FFs. */
-  c = read_1_byte();
-  while (c != 0xFF) {
-    discarded_bytes++;
-    c = read_1_byte();
-  }
-  /* Get marker code byte, swallowing any duplicate FF bytes.  Extra FFs
-   * are legal as pad bytes, so don't count them in discarded_bytes.
-   */
-  do {
-    c = read_1_byte();
-  } while (c == 0xFF);
-
-  if (discarded_bytes != 0) {
-    fprintf(stderr, "Warning: garbage data found in JPEG file\n");
-  }
-
-  return c;
-}
-
-
-/*
- * Read the initial marker, which should be SOI.
- * For a JFIF file, the first two bytes of the file should be literally
- * 0xFF M_SOI.  To be more general, we could use next_marker, but if the
- * input file weren't actually JPEG at all, next_marker might read the whole
- * file and then return a misleading error message...
- */
-
-static int
-first_marker (void)
-{
-  int c1, c2;
-
-  c1 = NEXTBYTE();
-  c2 = NEXTBYTE();
-  if (c1 != 0xFF || c2 != M_SOI)
-    ERREXIT("Not a JPEG file");
-  return c2;
-}
-
-
-/*
- * Most types of marker are followed by a variable-length parameter segment.
- * This routine skips over the parameters for any marker we don't otherwise
- * want to process.
- * Note that we MUST skip the parameter segment explicitly in order not to
- * be fooled by 0xFF bytes that might appear within the parameter segment;
- * such bytes do NOT introduce new markers.
- */
-
-static void
-skip_variable (void)
-/* Skip over an unknown or uninteresting variable-length marker */
-{
-  unsigned int length;
-
-  /* Get the marker parameter length count */
-  length = read_2_bytes();
-  /* Length includes itself, so must be at least 2 */
-  if (length < 2)
-    ERREXIT("Erroneous JPEG marker length");
-  length -= 2;
-  /* Skip over the remaining bytes */
-  while (length > 0) {
-    (void) read_1_byte();
-    length--;
-  }
-}
-
-
-/*
- * Process a COM marker.
- * We want to print out the marker contents as legible text;
- * we must guard against non-text junk and varying newline representations.
- */
-
-static void
-process_COM (void)
-{
-  unsigned int length;
-  int ch;
-  int lastch = 0;
-
-  /* Get the marker parameter length count */
-  length = read_2_bytes();
-  /* Length includes itself, so must be at least 2 */
-  if (length < 2)
-    ERREXIT("Erroneous JPEG marker length");
-  length -= 2;
-
-  while (length > 0) {
-    ch = read_1_byte();
-    /* Emit the character in a readable form.
-     * Nonprintables are converted to \nnn form,
-     * while \ is converted to \\.
-     * Newlines in CR, CR/LF, or LF form will be printed as one newline.
-     */
-    if (ch == '\r') {
-      printf("\n");
-    } else if (ch == '\n') {
-      if (lastch != '\r')
-       printf("\n");
-    } else if (ch == '\\') {
-      printf("\\\\");
-    } else if (isprint(ch)) {
-      putc(ch, stdout);
-    } else {
-      printf("\\%03o", ch);
-    }
-    lastch = ch;
-    length--;
-  }
-  printf("\n");
-}
-
-
-/*
- * Process a SOFn marker.
- * This code is only needed if you want to know the image dimensions...
- */
-
-static void
-process_SOFn (int marker)
-{
-  unsigned int length;
-  unsigned int image_height, image_width;
-  int data_precision, num_components;
-  const char * process;
-  int ci;
-
-  length = read_2_bytes();     /* usual parameter length count */
-
-  data_precision = read_1_byte();
-  image_height = read_2_bytes();
-  image_width = read_2_bytes();
-  num_components = read_1_byte();
-
-  switch (marker) {
-  case M_SOF0: process = "Baseline";  break;
-  case M_SOF1: process = "Extended sequential";  break;
-  case M_SOF2: process = "Progressive";  break;
-  case M_SOF3: process = "Lossless";  break;
-  case M_SOF5: process = "Differential sequential";  break;
-  case M_SOF6: process = "Differential progressive";  break;
-  case M_SOF7: process = "Differential lossless";  break;
-  case M_SOF9: process = "Extended sequential, arithmetic coding";  break;
-  case M_SOF10:        process = "Progressive, arithmetic coding";  break;
-  case M_SOF11:        process = "Lossless, arithmetic coding";  break;
-  case M_SOF13:        process = "Differential sequential, arithmetic coding";  break;
-  case M_SOF14:        process = "Differential progressive, arithmetic coding"; break;
-  case M_SOF15:        process = "Differential lossless, arithmetic coding";  break;
-  default:     process = "Unknown";  break;
-  }
-
-  printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n",
-        image_width, image_height, num_components, data_precision);
-  printf("JPEG process: %s\n", process);
-
-  if (length != (unsigned int) (8 + num_components * 3))
-    ERREXIT("Bogus SOF marker length");
-
-  for (ci = 0; ci < num_components; ci++) {
-    (void) read_1_byte();      /* Component ID code */
-    (void) read_1_byte();      /* H, V sampling factors */
-    (void) read_1_byte();      /* Quantization table number */
-  }
-}
-
-
-/*
- * Parse the marker stream until SOS or EOI is seen;
- * display any COM markers.
- * While the companion program wrjpgcom will always insert COM markers before
- * SOFn, other implementations might not, so we scan to SOS before stopping.
- * If we were only interested in the image dimensions, we would stop at SOFn.
- * (Conversely, if we only cared about COM markers, there would be no need
- * for special code to handle SOFn; we could treat it like other markers.)
- */
-
-static int
-scan_JPEG_header (int verbose)
-{
-  int marker;
-
-  /* Expect SOI at start of file */
-  if (first_marker() != M_SOI)
-    ERREXIT("Expected SOI marker first");
-
-  /* Scan miscellaneous markers until we reach SOS. */
-  for (;;) {
-    marker = next_marker();
-    switch (marker) {
-      /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
-       * treated as SOFn.  C4 in particular is actually DHT.
-       */
-    case M_SOF0:               /* Baseline */
-    case M_SOF1:               /* Extended sequential, Huffman */
-    case M_SOF2:               /* Progressive, Huffman */
-    case M_SOF3:               /* Lossless, Huffman */
-    case M_SOF5:               /* Differential sequential, Huffman */
-    case M_SOF6:               /* Differential progressive, Huffman */
-    case M_SOF7:               /* Differential lossless, Huffman */
-    case M_SOF9:               /* Extended sequential, arithmetic */
-    case M_SOF10:              /* Progressive, arithmetic */
-    case M_SOF11:              /* Lossless, arithmetic */
-    case M_SOF13:              /* Differential sequential, arithmetic */
-    case M_SOF14:              /* Differential progressive, arithmetic */
-    case M_SOF15:              /* Differential lossless, arithmetic */
-      if (verbose)
-       process_SOFn(marker);
-      else
-       skip_variable();
-      break;
-
-    case M_SOS:                        /* stop before hitting compressed data */
-      return marker;
-
-    case M_EOI:                        /* in case it's a tables-only JPEG stream */
-      return marker;
-
-    case M_COM:
-      process_COM();
-      break;
-
-    case M_APP12:
-      /* Some digital camera makers put useful textual information into
-       * APP12 markers, so we print those out too when in -verbose mode.
-       */
-      if (verbose) {
-       printf("APP12 contains:\n");
-       process_COM();
-      } else
-       skip_variable();
-      break;
-
-    default:                   /* Anything else just gets skipped */
-      skip_variable();         /* we assume it has a parameter count... */
-      break;
-    }
-  } /* end loop */
-}
-
-
-/* Command line parsing code */
-
-static const char * progname;  /* program name for error messages */
-
-
-static void
-usage (void)
-/* complain about bad command line */
-{
-  fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n");
-
-  fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname);
-
-  fprintf(stderr, "Switches (names may be abbreviated):\n");
-  fprintf(stderr, "  -verbose    Also display dimensions of JPEG image\n");
-
-  exit(EXIT_FAILURE);
-}
-
-
-static int
-keymatch (char * arg, const char * keyword, int minchars)
-/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
-/* keyword is the constant keyword (must be lower case already), */
-/* minchars is length of minimum legal abbreviation. */
-{
-  register int ca, ck;
-  register int nmatched = 0;
-
-  while ((ca = *arg++) != '\0') {
-    if ((ck = *keyword++) == '\0')
-      return 0;                        /* arg longer than keyword, no good */
-    if (isupper(ca))           /* force arg to lcase (assume ck is already) */
-      ca = tolower(ca);
-    if (ca != ck)
-      return 0;                        /* no good */
-    nmatched++;                        /* count matched characters */
-  }
-  /* reached end of argument; fail if it's too short for unique abbrev */
-  if (nmatched < minchars)
-    return 0;
-  return 1;                    /* A-OK */
-}
-
-
-/*
- * The main program.
- */
-
-int
-main (int argc, char **argv)
-{
-  int argn;
-  char * arg;
-  int verbose = 0;
-
-  /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
-  argc = ccommand(&argv);
-#endif
-
-  progname = argv[0];
-  if (progname == NULL || progname[0] == 0)
-    progname = "rdjpgcom";     /* in case C library doesn't provide it */
-
-  /* Parse switches, if any */
-  for (argn = 1; argn < argc; argn++) {
-    arg = argv[argn];
-    if (arg[0] != '-')
-      break;                   /* not switch, must be file name */
-    arg++;                     /* advance over '-' */
-    if (keymatch(arg, "verbose", 1)) {
-      verbose++;
-    } else
-      usage();
-  }
-
-  /* Open the input file. */
-  /* Unix style: expect zero or one file name */
-  if (argn < argc-1) {
-    fprintf(stderr, "%s: only one input file\n", progname);
-    usage();
-  }
-  if (argn < argc) {
-    if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
-      fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
-      exit(EXIT_FAILURE);
-    }
-  } else {
-    /* default input file is stdin */
-#ifdef USE_SETMODE             /* need to hack file mode? */
-    setmode(fileno(stdin), O_BINARY);
-#endif
-#ifdef USE_FDOPEN              /* need to re-open in binary mode? */
-    if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
-      fprintf(stderr, "%s: can't open stdin\n", progname);
-      exit(EXIT_FAILURE);
-    }
-#else
-    infile = stdin;
-#endif
-  }
-
-  /* Scan the JPEG headers. */
-  (void) scan_JPEG_header(verbose);
-
-  /* All done. */
-  exit(EXIT_SUCCESS);
-  return 0;                    /* suppress no-return-value warnings */
-}
diff --git a/src/jpeg/libijg8/rdppm.c b/src/jpeg/libijg8/rdppm.c
deleted file mode 100644 (file)
index 1df35c1..0000000
+++ /dev/null
@@ -1,458 +0,0 @@
-/*
- * rdppm.c
- *
- * Copyright (C) 1991-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to read input images in PPM/PGM format.
- * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
- * The PBMPLUS library is NOT required to compile this software
- * (but it is highly useful as a set of PPM image manipulation programs).
- *
- * These routines may need modification for non-Unix environments or
- * specialized applications.  As they stand, they assume input from
- * an ordinary stdio stream.  They further assume that reading begins
- * at the start of the file; start_input may need work if the
- * user interface has already read some data (e.g., to determine that
- * the file is indeed PPM format).
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef PPM_SUPPORTED
-
-
-/* Portions of this code are based on the PBMPLUS library, which is:
-**
-** Copyright (C) 1988 by Jef Poskanzer.
-**
-** Permission to use, copy, modify, and distribute this software and its
-** documentation for any purpose and without fee is hereby granted, provided
-** that the above copyright notice appear in all copies and that both that
-** copyright notice and this permission notice appear in supporting
-** documentation.  This software is provided "as is" without express or
-** implied warranty.
-*/
-
-
-/* Macros to deal with unsigned chars as efficiently as compiler allows */
-
-#ifdef HAVE_UNSIGNED_CHAR
-typedef unsigned char U_CHAR;
-#define UCH(x) ((int) (x))
-#else /* !HAVE_UNSIGNED_CHAR */
-#ifdef CHAR_IS_UNSIGNED
-typedef char U_CHAR;
-#define UCH(x) ((int) (x))
-#else
-typedef char U_CHAR;
-#define UCH(x) ((int) (x) & 0xFF)
-#endif
-#endif /* HAVE_UNSIGNED_CHAR */
-
-
-#define        ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
-
-
-/*
- * On most systems, reading individual bytes with getc() is drastically less
- * efficient than buffering a row at a time with fread().  On PCs, we must
- * allocate the buffer in near data space, because we are assuming small-data
- * memory model, wherein fread() can't reach far memory.  If you need to
- * process very wide images on a PC, you might have to compile in large-memory
- * model, or else replace fread() with a getc() loop --- which will be much
- * slower.
- */
-
-
-/* Private version of data source object */
-
-typedef struct {
-  struct cjpeg_source_struct pub; /* public fields */
-
-  U_CHAR *iobuffer;            /* non-FAR pointer to I/O buffer */
-  JSAMPROW pixrow;             /* FAR pointer to same */
-  size_t buffer_width;         /* width of I/O buffer */
-  JSAMPLE *rescale;            /* => maxval-remapping array, or NULL */
-} ppm_source_struct;
-
-typedef ppm_source_struct * ppm_source_ptr;
-
-
-LOCAL(int)
-pbm_getc (FILE * infile)
-/* Read next char, skipping over any comments */
-/* A comment/newline sequence is returned as a newline */
-{
-  register int ch;
-
-  ch = getc(infile);
-  if (ch == '#') {
-    do {
-      ch = getc(infile);
-    } while (ch != '\n' && ch != EOF);
-  }
-  return ch;
-}
-
-
-LOCAL(unsigned int)
-read_pbm_integer (j_compress_ptr cinfo, FILE * infile)
-/* Read an unsigned decimal integer from the PPM file */
-/* Swallows one trailing character after the integer */
-/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
-/* This should not be a problem in practice. */
-{
-  register int ch;
-  register unsigned int val;
-
-  /* Skip any leading whitespace */
-  do {
-    ch = pbm_getc(infile);
-    if (ch == EOF)
-      ERREXIT(cinfo, JERR_INPUT_EOF);
-  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
-
-  if (ch < '0' || ch > '9')
-    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
-
-  val = ch - '0';
-  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
-    val *= 10;
-    val += ch - '0';
-  }
-  return val;
-}
-
-
-/*
- * Read one row of pixels.
- *
- * We provide several different versions depending on input file format.
- * In all cases, input is scaled to the size of JSAMPLE.
- *
- * A really fast path is provided for reading byte/sample raw files with
- * maxval = MAXJSAMPLE, which is the normal case for 8-bit data.
- */
-
-
-METHODDEF(JDIMENSION)
-get_text_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading text-format PGM files with any maxval */
-{
-  ppm_source_ptr source = (ppm_source_ptr) sinfo;
-  FILE * infile = source->pub.input_file;
-  register JSAMPROW ptr;
-  register JSAMPLE *rescale = source->rescale;
-  JDIMENSION col;
-
-  ptr = source->pub.buffer[0];
-  for (col = cinfo->image_width; col > 0; col--) {
-    *ptr++ = rescale[read_pbm_integer(cinfo, infile)];
-  }
-  return 1;
-}
-
-
-METHODDEF(JDIMENSION)
-get_text_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading text-format PPM files with any maxval */
-{
-  ppm_source_ptr source = (ppm_source_ptr) sinfo;
-  FILE * infile = source->pub.input_file;
-  register JSAMPROW ptr;
-  register JSAMPLE *rescale = source->rescale;
-  JDIMENSION col;
-
-  ptr = source->pub.buffer[0];
-  for (col = cinfo->image_width; col > 0; col--) {
-    *ptr++ = rescale[read_pbm_integer(cinfo, infile)];
-    *ptr++ = rescale[read_pbm_integer(cinfo, infile)];
-    *ptr++ = rescale[read_pbm_integer(cinfo, infile)];
-  }
-  return 1;
-}
-
-
-METHODDEF(JDIMENSION)
-get_scaled_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading raw-byte-format PGM files with any maxval */
-{
-  ppm_source_ptr source = (ppm_source_ptr) sinfo;
-  register JSAMPROW ptr;
-  register U_CHAR * bufferptr;
-  register JSAMPLE *rescale = source->rescale;
-  JDIMENSION col;
-
-  if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
-    ERREXIT(cinfo, JERR_INPUT_EOF);
-  ptr = source->pub.buffer[0];
-  bufferptr = source->iobuffer;
-  for (col = cinfo->image_width; col > 0; col--) {
-    *ptr++ = rescale[UCH(*bufferptr++)];
-  }
-  return 1;
-}
-
-
-METHODDEF(JDIMENSION)
-get_scaled_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading raw-byte-format PPM files with any maxval */
-{
-  ppm_source_ptr source = (ppm_source_ptr) sinfo;
-  register JSAMPROW ptr;
-  register U_CHAR * bufferptr;
-  register JSAMPLE *rescale = source->rescale;
-  JDIMENSION col;
-
-  if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
-    ERREXIT(cinfo, JERR_INPUT_EOF);
-  ptr = source->pub.buffer[0];
-  bufferptr = source->iobuffer;
-  for (col = cinfo->image_width; col > 0; col--) {
-    *ptr++ = rescale[UCH(*bufferptr++)];
-    *ptr++ = rescale[UCH(*bufferptr++)];
-    *ptr++ = rescale[UCH(*bufferptr++)];
-  }
-  return 1;
-}
-
-
-METHODDEF(JDIMENSION)
-get_raw_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading raw-byte-format files with maxval = MAXJSAMPLE.
- * In this case we just read right into the JSAMPLE buffer!
- * Note that same code works for PPM and PGM files.
- */
-{
-  ppm_source_ptr source = (ppm_source_ptr) sinfo;
-
-  if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
-    ERREXIT(cinfo, JERR_INPUT_EOF);
-  return 1;
-}
-
-
-METHODDEF(JDIMENSION)
-get_word_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading raw-word-format PGM files with any maxval */
-{
-  ppm_source_ptr source = (ppm_source_ptr) sinfo;
-  register JSAMPROW ptr;
-  register U_CHAR * bufferptr;
-  register JSAMPLE *rescale = source->rescale;
-  JDIMENSION col;
-
-  if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
-    ERREXIT(cinfo, JERR_INPUT_EOF);
-  ptr = source->pub.buffer[0];
-  bufferptr = source->iobuffer;
-  for (col = cinfo->image_width; col > 0; col--) {
-    register int temp;
-    temp  = UCH(*bufferptr++);
-    temp |= UCH(*bufferptr++) << 8;
-    *ptr++ = rescale[temp];
-  }
-  return 1;
-}
-
-
-METHODDEF(JDIMENSION)
-get_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading raw-word-format PPM files with any maxval */
-{
-  ppm_source_ptr source = (ppm_source_ptr) sinfo;
-  register JSAMPROW ptr;
-  register U_CHAR * bufferptr;
-  register JSAMPLE *rescale = source->rescale;
-  JDIMENSION col;
-
-  if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
-    ERREXIT(cinfo, JERR_INPUT_EOF);
-  ptr = source->pub.buffer[0];
-  bufferptr = source->iobuffer;
-  for (col = cinfo->image_width; col > 0; col--) {
-    register int temp;
-    temp  = UCH(*bufferptr++);
-    temp |= UCH(*bufferptr++) << 8;
-    *ptr++ = rescale[temp];
-    temp  = UCH(*bufferptr++);
-    temp |= UCH(*bufferptr++) << 8;
-    *ptr++ = rescale[temp];
-    temp  = UCH(*bufferptr++);
-    temp |= UCH(*bufferptr++) << 8;
-    *ptr++ = rescale[temp];
-  }
-  return 1;
-}
-
-
-/*
- * Read the file header; return image size and component count.
- */
-
-METHODDEF(void)
-start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  ppm_source_ptr source = (ppm_source_ptr) sinfo;
-  int c;
-  unsigned int w, h, maxval;
-  boolean need_iobuffer, use_raw_buffer, need_rescale;
-
-  if (getc(source->pub.input_file) != 'P')
-    ERREXIT(cinfo, JERR_PPM_NOT);
-
-  c = getc(source->pub.input_file); /* subformat discriminator character */
-
-  /* detect unsupported variants (ie, PBM) before trying to read header */
-  switch (c) {
-  case '2':                    /* it's a text-format PGM file */
-  case '3':                    /* it's a text-format PPM file */
-  case '5':                    /* it's a raw-format PGM file */
-  case '6':                    /* it's a raw-format PPM file */
-    break;
-  default:
-    ERREXIT(cinfo, JERR_PPM_NOT);
-    break;
-  }
-
-  /* fetch the remaining header info */
-  w = read_pbm_integer(cinfo, source->pub.input_file);
-  h = read_pbm_integer(cinfo, source->pub.input_file);
-  maxval = read_pbm_integer(cinfo, source->pub.input_file);
-
-  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
-    ERREXIT(cinfo, JERR_PPM_NOT);
-
-  cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
-  cinfo->image_width = (JDIMENSION) w;
-  cinfo->image_height = (JDIMENSION) h;
-
-  /* initialize flags to most common settings */
-  need_iobuffer = TRUE;                /* do we need an I/O buffer? */
-  use_raw_buffer = FALSE;      /* do we map input buffer onto I/O buffer? */
-  need_rescale = TRUE;         /* do we need a rescale array? */
-
-  switch (c) {
-  case '2':                    /* it's a text-format PGM file */
-    cinfo->input_components = 1;
-    cinfo->in_color_space = JCS_GRAYSCALE;
-    TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h);
-    source->pub.get_pixel_rows = get_text_gray_row;
-    need_iobuffer = FALSE;
-    break;
-
-  case '3':                    /* it's a text-format PPM file */
-    cinfo->input_components = 3;
-    cinfo->in_color_space = JCS_RGB;
-    TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h);
-    source->pub.get_pixel_rows = get_text_rgb_row;
-    need_iobuffer = FALSE;
-    break;
-
-  case '5':                    /* it's a raw-format PGM file */
-    cinfo->input_components = 1;
-    cinfo->in_color_space = JCS_GRAYSCALE;
-    TRACEMS2(cinfo, 1, JTRC_PGM, w, h);
-    if (maxval > 255) {
-      source->pub.get_pixel_rows = get_word_gray_row;
-    } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) {
-      source->pub.get_pixel_rows = get_raw_row;
-      use_raw_buffer = TRUE;
-      need_rescale = FALSE;
-    } else {
-      source->pub.get_pixel_rows = get_scaled_gray_row;
-    }
-    break;
-
-  case '6':                    /* it's a raw-format PPM file */
-    cinfo->input_components = 3;
-    cinfo->in_color_space = JCS_RGB;
-    TRACEMS2(cinfo, 1, JTRC_PPM, w, h);
-    if (maxval > 255) {
-      source->pub.get_pixel_rows = get_word_rgb_row;
-    } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) {
-      source->pub.get_pixel_rows = get_raw_row;
-      use_raw_buffer = TRUE;
-      need_rescale = FALSE;
-    } else {
-      source->pub.get_pixel_rows = get_scaled_rgb_row;
-    }
-    break;
-  }
-
-  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
-  if (need_iobuffer) {
-    source->buffer_width = (size_t) w * cinfo->input_components *
-      ((maxval<=255) ? SIZEOF(U_CHAR) : (2*SIZEOF(U_CHAR)));
-    source->iobuffer = (U_CHAR *)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                 source->buffer_width);
-  }
-
-  /* Create compressor input buffer. */
-  if (use_raw_buffer) {
-    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
-    /* Synthesize a JSAMPARRAY pointer structure */
-    /* Cast here implies near->far pointer conversion on PCs */
-    source->pixrow = (JSAMPROW) source->iobuffer;
-    source->pub.buffer = & source->pixrow;
-    source->pub.buffer_height = 1;
-  } else {
-    /* Need to translate anyway, so make a separate sample buffer. */
-    source->pub.buffer = (*cinfo->mem->alloc_sarray)
-      ((j_common_ptr) cinfo, JPOOL_IMAGE,
-       (JDIMENSION) w * cinfo->input_components, (JDIMENSION) 1);
-    source->pub.buffer_height = 1;
-  }
-
-  /* Compute the rescaling array if required. */
-  if (need_rescale) {
-    INT32 val, half_maxval;
-
-    /* On 16-bit-int machines we have to be careful of maxval = 65535 */
-    source->rescale = (JSAMPLE *)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                 (size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE)));
-    half_maxval = maxval / 2;
-    for (val = 0; val <= (INT32) maxval; val++) {
-      /* The multiplication here must be done in 32 bits to avoid overflow */
-      source->rescale[val] = (JSAMPLE) ((val*MAXJSAMPLE + half_maxval)/maxval);
-    }
-  }
-}
-
-
-/*
- * Finish up at the end of the file.
- */
-
-METHODDEF(void)
-finish_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  /* no work */
-}
-
-
-/*
- * The module selection routine for PPM format input.
- */
-
-GLOBAL(cjpeg_source_ptr)
-jinit_read_ppm (j_compress_ptr cinfo)
-{
-  ppm_source_ptr source;
-
-  /* Create module interface object */
-  source = (ppm_source_ptr)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                 SIZEOF(ppm_source_struct));
-  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
-  source->pub.start_input = start_input_ppm;
-  source->pub.finish_input = finish_input_ppm;
-
-  return (cjpeg_source_ptr) source;
-}
-
-#endif /* PPM_SUPPORTED */
diff --git a/src/jpeg/libijg8/rdrle.c b/src/jpeg/libijg8/rdrle.c
deleted file mode 100644 (file)
index 542bc37..0000000
+++ /dev/null
@@ -1,387 +0,0 @@
-/*
- * rdrle.c
- *
- * Copyright (C) 1991-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to read input images in Utah RLE format.
- * The Utah Raster Toolkit library is required (version 3.1 or later).
- *
- * These routines may need modification for non-Unix environments or
- * specialized applications.  As they stand, they assume input from
- * an ordinary stdio stream.  They further assume that reading begins
- * at the start of the file; start_input may need work if the
- * user interface has already read some data (e.g., to determine that
- * the file is indeed RLE format).
- *
- * Based on code contributed by Mike Lijewski,
- * with updates from Robert Hutchinson.
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef RLE_SUPPORTED
-
-/* rle.h is provided by the Utah Raster Toolkit. */
-
-#include <rle.h>
-
-/*
- * We assume that JSAMPLE has the same representation as rle_pixel,
- * to wit, "unsigned char".  Hence we can't cope with 12- or 16-bit samples.
- */
-
-#if BITS_IN_JSAMPLE != 8
-  Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
-#endif
-
-/*
- * We support the following types of RLE files:
- *   
- *   GRAYSCALE   - 8 bits, no colormap
- *   MAPPEDGRAY  - 8 bits, 1 channel colomap
- *   PSEUDOCOLOR - 8 bits, 3 channel colormap
- *   TRUECOLOR   - 24 bits, 3 channel colormap
- *   DIRECTCOLOR - 24 bits, no colormap
- *
- * For now, we ignore any alpha channel in the image.
- */
-
-typedef enum
-  { GRAYSCALE, MAPPEDGRAY, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind;
-
-
-/*
- * Since RLE stores scanlines bottom-to-top, we have to invert the image
- * to conform to JPEG's top-to-bottom order.  To do this, we read the
- * incoming image into a virtual array on the first get_pixel_rows call,
- * then fetch the required row from the virtual array on subsequent calls.
- */
-
-typedef struct _rle_source_struct * rle_source_ptr;
-
-typedef struct _rle_source_struct {
-  struct cjpeg_source_struct pub; /* public fields */
-
-  rle_kind visual;              /* actual type of input file */
-  jvirt_sarray_ptr image;       /* virtual array to hold the image */
-  JDIMENSION row;              /* current row # in the virtual array */
-  rle_hdr header;               /* Input file information */
-  rle_pixel** rle_row;          /* holds a row returned by rle_getrow() */
-
-} rle_source_struct;
-
-
-/*
- * Read the file header; return image size and component count.
- */
-
-METHODDEF(void)
-start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  rle_source_ptr source = (rle_source_ptr) sinfo;
-  JDIMENSION width, height;
-#ifdef PROGRESS_REPORT
-  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
-#endif
-
-  /* Use RLE library routine to get the header info */
-  source->header = *rle_hdr_init(NULL);
-  source->header.rle_file = source->pub.input_file;
-  switch (rle_get_setup(&(source->header))) {
-  case RLE_SUCCESS:
-    /* A-OK */
-    break;
-  case RLE_NOT_RLE:
-    ERREXIT(cinfo, JERR_RLE_NOT);
-    break;
-  case RLE_NO_SPACE:
-    ERREXIT(cinfo, JERR_RLE_MEM);
-    break;
-  case RLE_EMPTY:
-    ERREXIT(cinfo, JERR_RLE_EMPTY);
-    break;
-  case RLE_EOF:
-    ERREXIT(cinfo, JERR_RLE_EOF);
-    break;
-  default:
-    ERREXIT(cinfo, JERR_RLE_BADERROR);
-    break;
-  }
-
-  /* Figure out what we have, set private vars and return values accordingly */
-  
-  width  = source->header.xmax - source->header.xmin + 1;
-  height = source->header.ymax - source->header.ymin + 1;
-  source->header.xmin = 0;             /* realign horizontally */
-  source->header.xmax = width-1;
-
-  cinfo->image_width      = width;
-  cinfo->image_height     = height;
-  cinfo->data_precision   = 8;  /* we can only handle 8 bit data */
-
-  if (source->header.ncolors == 1 && source->header.ncmap == 0) {
-    source->visual     = GRAYSCALE;
-    TRACEMS2(cinfo, 1, JTRC_RLE_GRAY, width, height);
-  } else if (source->header.ncolors == 1 && source->header.ncmap == 1) {
-    source->visual     = MAPPEDGRAY;
-    TRACEMS3(cinfo, 1, JTRC_RLE_MAPGRAY, width, height,
-             1 << source->header.cmaplen);
-  } else if (source->header.ncolors == 1 && source->header.ncmap == 3) {
-    source->visual     = PSEUDOCOLOR;
-    TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height,
-            1 << source->header.cmaplen);
-  } else if (source->header.ncolors == 3 && source->header.ncmap == 3) {
-    source->visual     = TRUECOLOR;
-    TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height,
-            1 << source->header.cmaplen);
-  } else if (source->header.ncolors == 3 && source->header.ncmap == 0) {
-    source->visual     = DIRECTCOLOR;
-    TRACEMS2(cinfo, 1, JTRC_RLE, width, height);
-  } else
-    ERREXIT(cinfo, JERR_RLE_UNSUPPORTED);
-  
-  if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) {
-    cinfo->in_color_space   = JCS_GRAYSCALE;
-    cinfo->input_components = 1;
-  } else {
-    cinfo->in_color_space   = JCS_RGB;
-    cinfo->input_components = 3;
-  }
-
-  /*
-   * A place to hold each scanline while it's converted.
-   * (GRAYSCALE scanlines don't need converting)
-   */
-  if (source->visual != GRAYSCALE) {
-    source->rle_row = (rle_pixel**) (*cinfo->mem->alloc_sarray)
-      ((j_common_ptr) cinfo, JPOOL_IMAGE,
-       (JDIMENSION) width, (JDIMENSION) cinfo->input_components);
-  }
-
-  /* request a virtual array to hold the image */
-  source->image = (*cinfo->mem->request_virt_sarray)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
-     (JDIMENSION) (width * source->header.ncolors),
-     (JDIMENSION) height, (JDIMENSION) 1);
-
-#ifdef PROGRESS_REPORT
-  if (progress != NULL) {
-    /* count file input as separate pass */
-    progress->total_extra_passes++;
-  }
-#endif
-
-  source->pub.buffer_height = 1;
-}
-
-
-/*
- * Read one row of pixels.
- * Called only after load_image has read the image into the virtual array.
- * Used for GRAYSCALE, MAPPEDGRAY, TRUECOLOR, and DIRECTCOLOR images.
- */
-
-METHODDEF(JDIMENSION)
-get_rle_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  rle_source_ptr source = (rle_source_ptr) sinfo;
-
-  source->row--;
-  source->pub.buffer = (*cinfo->mem->access_virt_sarray)
-    ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE);
-
-  return 1;
-}
-
-/*
- * Read one row of pixels.
- * Called only after load_image has read the image into the virtual array.
- * Used for PSEUDOCOLOR images.
- */
-
-METHODDEF(JDIMENSION)
-get_pseudocolor_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  rle_source_ptr source = (rle_source_ptr) sinfo;
-  JSAMPROW src_row, dest_row;
-  JDIMENSION col;
-  rle_map *colormap;
-  int val;
-
-  colormap = source->header.cmap;
-  dest_row = source->pub.buffer[0];
-  source->row--;
-  src_row = * (*cinfo->mem->access_virt_sarray)
-    ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE);
-
-  for (col = cinfo->image_width; col > 0; col--) {
-    val = GETJSAMPLE(*src_row++);
-    *dest_row++ = (JSAMPLE) (colormap[val      ] >> 8);
-    *dest_row++ = (JSAMPLE) (colormap[val + 256] >> 8);
-    *dest_row++ = (JSAMPLE) (colormap[val + 512] >> 8);
-  }
-
-  return 1;
-}
-
-
-/*
- * Load the image into a virtual array.  We have to do this because RLE
- * files start at the lower left while the JPEG standard has them starting
- * in the upper left.  This is called the first time we want to get a row
- * of input.  What we do is load the RLE data into the array and then call
- * the appropriate routine to read one row from the array.  Before returning,
- * we set source->pub.get_pixel_rows so that subsequent calls go straight to
- * the appropriate row-reading routine.
- */
-
-METHODDEF(JDIMENSION)
-load_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  rle_source_ptr source = (rle_source_ptr) sinfo;
-  JDIMENSION row, col;
-  JSAMPROW  scanline, red_ptr, green_ptr, blue_ptr;
-  rle_pixel **rle_row;
-  rle_map *colormap;
-  char channel;
-#ifdef PROGRESS_REPORT
-  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
-#endif
-
-  colormap = source->header.cmap;
-  rle_row = source->rle_row;
-
-  /* Read the RLE data into our virtual array.
-   * We assume here that (a) rle_pixel is represented the same as JSAMPLE,
-   * and (b) we are not on a machine where FAR pointers differ from regular.
-   */
-  RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */
-
-#ifdef PROGRESS_REPORT
-  if (progress != NULL) {
-    progress->pub.pass_limit = cinfo->image_height;
-    progress->pub.pass_counter = 0;
-    (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
-  }
-#endif
-
-  switch (source->visual) {
-
-  case GRAYSCALE:
-  case PSEUDOCOLOR:
-    for (row = 0; row < cinfo->image_height; row++) {
-      rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)
-         ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
-      rle_getrow(&source->header, rle_row);
-#ifdef PROGRESS_REPORT
-      if (progress != NULL) {
-        progress->pub.pass_counter++;
-        (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
-      }
-#endif
-    }
-    break;
-
-  case MAPPEDGRAY:
-  case TRUECOLOR:
-    for (row = 0; row < cinfo->image_height; row++) {
-      scanline = * (*cinfo->mem->access_virt_sarray)
-        ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
-      rle_row = source->rle_row;
-      rle_getrow(&source->header, rle_row);
-
-      for (col = 0; col < cinfo->image_width; col++) {
-        for (channel = 0; channel < source->header.ncolors; channel++) {
-          *scanline++ = (JSAMPLE)
-            (colormap[GETJSAMPLE(rle_row[channel][col]) + 256 * channel] >> 8);
-        }
-      }
-
-#ifdef PROGRESS_REPORT
-      if (progress != NULL) {
-        progress->pub.pass_counter++;
-        (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
-      }
-#endif
-    }
-    break;
-
-  case DIRECTCOLOR:
-    for (row = 0; row < cinfo->image_height; row++) {
-      scanline = * (*cinfo->mem->access_virt_sarray)
-        ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);
-      rle_getrow(&source->header, rle_row);
-
-      red_ptr   = rle_row[0];
-      green_ptr = rle_row[1];
-      blue_ptr  = rle_row[2];
-
-      for (col = cinfo->image_width; col > 0; col--) {
-        *scanline++ = *red_ptr++;
-        *scanline++ = *green_ptr++;
-        *scanline++ = *blue_ptr++;
-      }
-
-#ifdef PROGRESS_REPORT
-      if (progress != NULL) {
-        progress->pub.pass_counter++;
-        (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
-      }
-#endif
-    }
-  }
-
-#ifdef PROGRESS_REPORT
-  if (progress != NULL)
-    progress->completed_extra_passes++;
-#endif
-
-  /* Set up to call proper row-extraction routine in future */
-  if (source->visual == PSEUDOCOLOR) {
-    source->pub.buffer = source->rle_row;
-    source->pub.get_pixel_rows = get_pseudocolor_row;
-  } else {
-    source->pub.get_pixel_rows = get_rle_row;
-  }
-  source->row = cinfo->image_height;
-
-  /* And fetch the topmost (bottommost) row */
-  return (*source->pub.get_pixel_rows) (cinfo, sinfo);   
-}
-
-
-/*
- * Finish up at the end of the file.
- */
-
-METHODDEF(void)
-finish_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  /* no work */
-}
-
-
-/*
- * The module selection routine for RLE format input.
- */
-
-GLOBAL(cjpeg_source_ptr)
-jinit_read_rle (j_compress_ptr cinfo)
-{
-  rle_source_ptr source;
-
-  /* Create module interface object */
-  source = (rle_source_ptr)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                  SIZEOF(rle_source_struct));
-  /* Fill in method ptrs */
-  source->pub.start_input = start_input_rle;
-  source->pub.finish_input = finish_input_rle;
-  source->pub.get_pixel_rows = load_image;
-
-  return (cjpeg_source_ptr) source;
-}
-
-#endif /* RLE_SUPPORTED */
diff --git a/src/jpeg/libijg8/rdswitch.c b/src/jpeg/libijg8/rdswitch.c
deleted file mode 100644 (file)
index 4f4bb4f..0000000
+++ /dev/null
@@ -1,332 +0,0 @@
-/*
- * rdswitch.c
- *
- * Copyright (C) 1991-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to process some of cjpeg's more complicated
- * command-line switches.  Switches processed here are:
- *     -qtables file           Read quantization tables from text file
- *     -scans file             Read scan script from text file
- *     -qslots N[,N,...]       Set component quantization table selectors
- *     -sample HxV[,HxV,...]   Set component sampling factors
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-#include <ctype.h>             /* to declare isdigit(), isspace() */
-
-
-LOCAL(int)
-text_getc (FILE * file)
-/* Read next char, skipping over any comments (# to end of line) */
-/* A comment/newline sequence is returned as a newline */
-{
-  register int ch;
-  
-  ch = getc(file);
-  if (ch == '#') {
-    do {
-      ch = getc(file);
-    } while (ch != '\n' && ch != EOF);
-  }
-  return ch;
-}
-
-
-LOCAL(boolean)
-read_text_integer (FILE * file, long * result, int * termchar)
-/* Read an unsigned decimal integer from a file, store it in result */
-/* Reads one trailing character after the integer; returns it in termchar */
-{
-  register int ch;
-  register long val;
-  
-  /* Skip any leading whitespace, detect EOF */
-  do {
-    ch = text_getc(file);
-    if (ch == EOF) {
-      *termchar = ch;
-      return FALSE;
-    }
-  } while (isspace(ch));
-  
-  if (! isdigit(ch)) {
-    *termchar = ch;
-    return FALSE;
-  }
-
-  val = ch - '0';
-  while ((ch = text_getc(file)) != EOF) {
-    if (! isdigit(ch))
-      break;
-    val *= 10;
-    val += ch - '0';
-  }
-  *result = val;
-  *termchar = ch;
-  return TRUE;
-}
-
-
-GLOBAL(boolean)
-read_quant_tables (j_compress_ptr cinfo, char * filename,
-                  int scale_factor, boolean force_baseline)
-/* Read a set of quantization tables from the specified file.
- * The file is plain ASCII text: decimal numbers with whitespace between.
- * Comments preceded by '#' may be included in the file.
- * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values.
- * The tables are implicitly numbered 0,1,etc.
- * NOTE: does not affect the qslots mapping, which will default to selecting
- * table 0 for luminance (or primary) components, 1 for chrominance components.
- * You must use -qslots if you want a different component->table mapping.
- */
-{
-  FILE * fp;
-  int tblno, i, termchar;
-  long val;
-  unsigned int table[DCTSIZE2];
-
-  if ((fp = fopen(filename, "r")) == NULL) {
-    fprintf(stderr, "Can't open table file %s\n", filename);
-    return FALSE;
-  }
-  tblno = 0;
-
-  while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */
-    if (tblno >= NUM_QUANT_TBLS) {
-      fprintf(stderr, "Too many tables in file %s\n", filename);
-      fclose(fp);
-      return FALSE;
-    }
-    table[0] = (unsigned int) val;
-    for (i = 1; i < DCTSIZE2; i++) {
-      if (! read_text_integer(fp, &val, &termchar)) {
-       fprintf(stderr, "Invalid table data in file %s\n", filename);
-       fclose(fp);
-       return FALSE;
-      }
-      table[i] = (unsigned int) val;
-    }
-    jpeg_add_quant_table(cinfo, tblno, table, scale_factor, force_baseline);
-    tblno++;
-  }
-
-  if (termchar != EOF) {
-    fprintf(stderr, "Non-numeric data in file %s\n", filename);
-    fclose(fp);
-    return FALSE;
-  }
-
-  fclose(fp);
-  return TRUE;
-}
-
-
-#ifdef C_MULTISCAN_FILES_SUPPORTED
-
-LOCAL(boolean)
-read_scan_integer (FILE * file, long * result, int * termchar)
-/* Variant of read_text_integer that always looks for a non-space termchar;
- * this simplifies parsing of punctuation in scan scripts.
- */
-{
-  register int ch;
-
-  if (! read_text_integer(file, result, termchar))
-    return FALSE;
-  ch = *termchar;
-  while (ch != EOF && isspace(ch))
-    ch = text_getc(file);
-  if (isdigit(ch)) {           /* oops, put it back */
-    if (ungetc(ch, file) == EOF)
-      return FALSE;
-    ch = ' ';
-  } else {
-    /* Any separators other than ';' and ':' are ignored;
-     * this allows user to insert commas, etc, if desired.
-     */
-    if (ch != EOF && ch != ';' && ch != ':')
-      ch = ' ';
-  }
-  *termchar = ch;
-  return TRUE;
-}
-
-
-GLOBAL(boolean)
-read_scan_script (j_compress_ptr cinfo, char * filename)
-/* Read a scan script from the specified text file.
- * Each entry in the file defines one scan to be emitted.
- * Entries are separated by semicolons ';'.
- * An entry contains one to four component indexes,
- * optionally followed by a colon ':' and four progressive-JPEG parameters.
- * The component indexes denote which component(s) are to be transmitted
- * in the current scan.  The first component has index 0.
- * Sequential JPEG is used if the progressive-JPEG parameters are omitted.
- * The file is free format text: any whitespace may appear between numbers
- * and the ':' and ';' punctuation marks.  Also, other punctuation (such
- * as commas or dashes) can be placed between numbers if desired.
- * Comments preceded by '#' may be included in the file.
- * Note: we do very little validity checking here;
- * jcmaster.c will validate the script parameters.
- */
-{
-  FILE * fp;
-  int scanno, ncomps, termchar;
-  long val;
-  jpeg_scan_info * scanptr;
-#define MAX_SCANS  100         /* quite arbitrary limit */
-  jpeg_scan_info scans[MAX_SCANS];
-
-  if ((fp = fopen(filename, "r")) == NULL) {
-    fprintf(stderr, "Can't open scan definition file %s\n", filename);
-    return FALSE;
-  }
-  scanptr = scans;
-  scanno = 0;
-
-  while (read_scan_integer(fp, &val, &termchar)) {
-    if (scanno >= MAX_SCANS) {
-      fprintf(stderr, "Too many scans defined in file %s\n", filename);
-      fclose(fp);
-      return FALSE;
-    }
-    scanptr->component_index[0] = (int) val;
-    ncomps = 1;
-    while (termchar == ' ') {
-      if (ncomps >= MAX_COMPS_IN_SCAN) {
-       fprintf(stderr, "Too many components in one scan in file %s\n",
-               filename);
-       fclose(fp);
-       return FALSE;
-      }
-      if (! read_scan_integer(fp, &val, &termchar))
-       goto bogus;
-      scanptr->component_index[ncomps] = (int) val;
-      ncomps++;
-    }
-    scanptr->comps_in_scan = ncomps;
-    if (termchar == ':') {
-      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
-       goto bogus;
-      scanptr->Ss = (int) val;
-      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
-       goto bogus;
-      scanptr->Se = (int) val;
-      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
-       goto bogus;
-      scanptr->Ah = (int) val;
-      if (! read_scan_integer(fp, &val, &termchar))
-       goto bogus;
-      scanptr->Al = (int) val;
-    } else {
-      /* set non-progressive parameters */
-      scanptr->Ss = 0;
-      scanptr->Se = DCTSIZE2-1;
-      scanptr->Ah = 0;
-      scanptr->Al = 0;
-    }
-    if (termchar != ';' && termchar != EOF) {
-bogus:
-      fprintf(stderr, "Invalid scan entry format in file %s\n", filename);
-      fclose(fp);
-      return FALSE;
-    }
-    scanptr++, scanno++;
-  }
-
-  if (termchar != EOF) {
-    fprintf(stderr, "Non-numeric data in file %s\n", filename);
-    fclose(fp);
-    return FALSE;
-  }
-
-  if (scanno > 0) {
-    /* Stash completed scan list in cinfo structure.
-     * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data,
-     * but if you want to compress multiple images you'd want JPOOL_PERMANENT.
-     */
-    scanptr = (jpeg_scan_info *)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                 scanno * SIZEOF(jpeg_scan_info));
-    MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info));
-    cinfo->scan_info = scanptr;
-    cinfo->num_scans = scanno;
-  }
-
-  fclose(fp);
-  return TRUE;
-}
-
-#endif /* C_MULTISCAN_FILES_SUPPORTED */
-
-
-GLOBAL(boolean)
-set_quant_slots (j_compress_ptr cinfo, char *arg)
-/* Process a quantization-table-selectors parameter string, of the form
- *     N[,N,...]
- * If there are more components than parameters, the last value is replicated.
- */
-{
-  int val = 0;                 /* default table # */
-  int ci;
-  char ch;
-
-  for (ci = 0; ci < MAX_COMPONENTS; ci++) {
-    if (*arg) {
-      ch = ',';                        /* if not set by sscanf, will be ',' */
-      if (sscanf(arg, "%d%c", &val, &ch) < 1)
-       return FALSE;
-      if (ch != ',')           /* syntax check */
-       return FALSE;
-      if (val < 0 || val >= NUM_QUANT_TBLS) {
-       fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
-               NUM_QUANT_TBLS-1);
-       return FALSE;
-      }
-      cinfo->comp_info[ci].quant_tbl_no = val;
-      while (*arg && *arg++ != ',') /* advance to next segment of arg string */
-       ;
-    } else {
-      /* reached end of parameter, set remaining components to last table */
-      cinfo->comp_info[ci].quant_tbl_no = val;
-    }
-  }
-  return TRUE;
-}
-
-
-GLOBAL(boolean)
-set_sample_factors (j_compress_ptr cinfo, char *arg)
-/* Process a sample-factors parameter string, of the form
- *     HxV[,HxV,...]
- * If there are more components than parameters, "1x1" is assumed for the rest.
- */
-{
-  int ci, val1, val2;
-  char ch1, ch2;
-
-  for (ci = 0; ci < MAX_COMPONENTS; ci++) {
-    if (*arg) {
-      ch2 = ',';               /* if not set by sscanf, will be ',' */
-      if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
-       return FALSE;
-      if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */
-       return FALSE;
-      if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) {
-       fprintf(stderr, "JPEG sampling factors must be 1..4\n");
-       return FALSE;
-      }
-      cinfo->comp_info[ci].h_samp_factor = val1;
-      cinfo->comp_info[ci].v_samp_factor = val2;
-      while (*arg && *arg++ != ',') /* advance to next segment of arg string */
-       ;
-    } else {
-      /* reached end of parameter, set remaining components to 1x1 sampling */
-      cinfo->comp_info[ci].h_samp_factor = 1;
-      cinfo->comp_info[ci].v_samp_factor = 1;
-    }
-  }
-  return TRUE;
-}
diff --git a/src/jpeg/libijg8/rdtarga.c b/src/jpeg/libijg8/rdtarga.c
deleted file mode 100644 (file)
index 4c2cd26..0000000
+++ /dev/null
@@ -1,500 +0,0 @@
-/*
- * rdtarga.c
- *
- * Copyright (C) 1991-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to read input images in Targa format.
- *
- * These routines may need modification for non-Unix environments or
- * specialized applications.  As they stand, they assume input from
- * an ordinary stdio stream.  They further assume that reading begins
- * at the start of the file; start_input may need work if the
- * user interface has already read some data (e.g., to determine that
- * the file is indeed Targa format).
- *
- * Based on code contributed by Lee Daniel Crocker.
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef TARGA_SUPPORTED
-
-
-/* Macros to deal with unsigned chars as efficiently as compiler allows */
-
-#ifdef HAVE_UNSIGNED_CHAR
-typedef unsigned char U_CHAR;
-#define UCH(x) ((int) (x))
-#else /* !HAVE_UNSIGNED_CHAR */
-#ifdef CHAR_IS_UNSIGNED
-typedef char U_CHAR;
-#define UCH(x) ((int) (x))
-#else
-typedef char U_CHAR;
-#define UCH(x) ((int) (x) & 0xFF)
-#endif
-#endif /* HAVE_UNSIGNED_CHAR */
-
-
-#define        ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
-
-
-/* Private version of data source object */
-
-typedef struct _tga_source_struct * tga_source_ptr;
-
-typedef struct _tga_source_struct {
-  struct cjpeg_source_struct pub; /* public fields */
-
-  j_compress_ptr cinfo;                /* back link saves passing separate parm */
-
-  JSAMPARRAY colormap;         /* Targa colormap (converted to my format) */
-
-  jvirt_sarray_ptr whole_image;        /* Needed if funny input row order */
-  JDIMENSION current_row;      /* Current logical row number to read */
-
-  /* Pointer to routine to extract next Targa pixel from input file */
-  JMETHOD(void, read_pixel, (tga_source_ptr sinfo));
-
-  /* Result of read_pixel is delivered here: */
-  U_CHAR tga_pixel[4];
-
-  int pixel_size;              /* Bytes per Targa pixel (1 to 4) */
-
-  /* State info for reading RLE-coded pixels; both counts must be init to 0 */
-  int block_count;             /* # of pixels remaining in RLE block */
-  int dup_pixel_count;         /* # of times to duplicate previous pixel */
-
-  /* This saves the correct pixel-row-expansion method for preload_image */
-  JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
-                                      cjpeg_source_ptr sinfo));
-} tga_source_struct;
-
-
-/* For expanding 5-bit pixel values to 8-bit with best rounding */
-
-static const UINT8 c5to8bits[32] = {
-    0,   8,  16,  25,  33,  41,  49,  58,
-   66,  74,  82,  90,  99, 107, 115, 123,
-  132, 140, 148, 156, 165, 173, 181, 189,
-  197, 206, 214, 222, 230, 239, 247, 255
-};
-
-
-
-LOCAL(int)
-read_byte (tga_source_ptr sinfo)
-/* Read next byte from Targa file */
-{
-  register FILE *infile = sinfo->pub.input_file;
-  register int c;
-
-  if ((c = getc(infile)) == EOF)
-    ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
-  return c;
-}
-
-
-LOCAL(void)
-read_colormap (tga_source_ptr sinfo, int cmaplen, int mapentrysize)
-/* Read the colormap from a Targa file */
-{
-  int i;
-
-  /* Presently only handles 24-bit BGR format */
-  if (mapentrysize != 24)
-    ERREXIT(sinfo->cinfo, JERR_TGA_BADCMAP);
-
-  for (i = 0; i < cmaplen; i++) {
-    sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);
-    sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);
-    sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);
-  }
-}
-
-
-/*
- * read_pixel methods: get a single pixel from Targa file into tga_pixel[]
- */
-
-METHODDEF(void)
-read_non_rle_pixel (tga_source_ptr sinfo)
-/* Read one Targa pixel from the input file; no RLE expansion */
-{
-  register FILE *infile = sinfo->pub.input_file;
-  register int i;
-
-  for (i = 0; i < sinfo->pixel_size; i++) {
-    sinfo->tga_pixel[i] = (U_CHAR) getc(infile);
-  }
-}
-
-
-METHODDEF(void)
-read_rle_pixel (tga_source_ptr sinfo)
-/* Read one Targa pixel from the input file, expanding RLE data as needed */
-{
-  register FILE *infile = sinfo->pub.input_file;
-  register int i;
-
-  /* Duplicate previously read pixel? */
-  if (sinfo->dup_pixel_count > 0) {
-    sinfo->dup_pixel_count--;
-    return;
-  }
-
-  /* Time to read RLE block header? */
-  if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */
-    i = read_byte(sinfo);
-    if (i & 0x80) {            /* Start of duplicate-pixel block? */
-      sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */
-      sinfo->block_count = 0;  /* then read new block header */
-    } else {
-      sinfo->block_count = i & 0x7F; /* number of pixels after this one */
-    }
-  }
-
-  /* Read next pixel */
-  for (i = 0; i < sinfo->pixel_size; i++) {
-    sinfo->tga_pixel[i] = (U_CHAR) getc(infile);
-  }
-}
-
-
-/*
- * Read one row of pixels.
- *
- * We provide several different versions depending on input file format.
- */
-
-
-METHODDEF(JDIMENSION)
-get_8bit_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading 8-bit grayscale pixels */
-{
-  tga_source_ptr source = (tga_source_ptr) sinfo;
-  register JSAMPROW ptr;
-  register JDIMENSION col;
-  
-  ptr = source->pub.buffer[0];
-  for (col = cinfo->image_width; col > 0; col--) {
-    (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
-    *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]);
-  }
-  return 1;
-}
-
-METHODDEF(JDIMENSION)
-get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading 8-bit colormap indexes */
-{
-  tga_source_ptr source = (tga_source_ptr) sinfo;
-  register int t;
-  register JSAMPROW ptr;
-  register JDIMENSION col;
-  register JSAMPARRAY colormap = source->colormap;
-
-  ptr = source->pub.buffer[0];
-  for (col = cinfo->image_width; col > 0; col--) {
-    (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
-    t = UCH(source->tga_pixel[0]);
-    *ptr++ = colormap[0][t];
-    *ptr++ = colormap[1][t];
-    *ptr++ = colormap[2][t];
-  }
-  return 1;
-}
-
-METHODDEF(JDIMENSION)
-get_16bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading 16-bit pixels */
-{
-  tga_source_ptr source = (tga_source_ptr) sinfo;
-  register int t;
-  register JSAMPROW ptr;
-  register JDIMENSION col;
-  
-  ptr = source->pub.buffer[0];
-  for (col = cinfo->image_width; col > 0; col--) {
-    (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
-    t = UCH(source->tga_pixel[0]);
-    t += UCH(source->tga_pixel[1]) << 8;
-    /* We expand 5 bit data to 8 bit sample width.
-     * The format of the 16-bit (LSB first) input word is
-     *     xRRRRRGGGGGBBBBB
-     */
-    ptr[2] = (JSAMPLE) c5to8bits[t & 0x1F];
-    t >>= 5;
-    ptr[1] = (JSAMPLE) c5to8bits[t & 0x1F];
-    t >>= 5;
-    ptr[0] = (JSAMPLE) c5to8bits[t & 0x1F];
-    ptr += 3;
-  }
-  return 1;
-}
-
-METHODDEF(JDIMENSION)
-get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-/* This version is for reading 24-bit pixels */
-{
-  tga_source_ptr source = (tga_source_ptr) sinfo;
-  register JSAMPROW ptr;
-  register JDIMENSION col;
-  
-  ptr = source->pub.buffer[0];
-  for (col = cinfo->image_width; col > 0; col--) {
-    (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
-    *ptr++ = (JSAMPLE) UCH(source->tga_pixel[2]); /* change BGR to RGB order */
-    *ptr++ = (JSAMPLE) UCH(source->tga_pixel[1]);
-    *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]);
-  }
-  return 1;
-}
-
-/*
- * Targa also defines a 32-bit pixel format with order B,G,R,A.
- * We presently ignore the attribute byte, so the code for reading
- * these pixels is identical to the 24-bit routine above.
- * This works because the actual pixel length is only known to read_pixel.
- */
-
-#define get_32bit_row  get_24bit_row
-
-
-/*
- * This method is for re-reading the input data in standard top-down
- * row order.  The entire image has already been read into whole_image
- * with proper conversion of pixel format, but it's in a funny row order.
- */
-
-METHODDEF(JDIMENSION)
-get_memory_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  tga_source_ptr source = (tga_source_ptr) sinfo;
-  JDIMENSION source_row;
-
-  /* Compute row of source that maps to current_row of normal order */
-  /* For now, assume image is bottom-up and not interlaced. */
-  /* NEEDS WORK to support interlaced images! */
-  source_row = cinfo->image_height - source->current_row - 1;
-
-  /* Fetch that row from virtual array */
-  source->pub.buffer = (*cinfo->mem->access_virt_sarray)
-    ((j_common_ptr) cinfo, source->whole_image,
-     source_row, (JDIMENSION) 1, FALSE);
-
-  source->current_row++;
-  return 1;
-}
-
-
-/*
- * This method loads the image into whole_image during the first call on
- * get_pixel_rows.  The get_pixel_rows pointer is then adjusted to call
- * get_memory_row on subsequent calls.
- */
-
-METHODDEF(JDIMENSION)
-preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  tga_source_ptr source = (tga_source_ptr) sinfo;
-  JDIMENSION row;
-  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
-
-  /* Read the data into a virtual array in input-file row order. */
-  for (row = 0; row < cinfo->image_height; row++) {
-    if (progress != NULL) {
-      progress->pub.pass_counter = (long) row;
-      progress->pub.pass_limit = (long) cinfo->image_height;
-      (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
-    }
-    source->pub.buffer = (*cinfo->mem->access_virt_sarray)
-      ((j_common_ptr) cinfo, source->whole_image, row, (JDIMENSION) 1, TRUE);
-    (*source->get_pixel_rows) (cinfo, sinfo);
-  }
-  if (progress != NULL)
-    progress->completed_extra_passes++;
-
-  /* Set up to read from the virtual array in unscrambled order */
-  source->pub.get_pixel_rows = get_memory_row;
-  source->current_row = 0;
-  /* And read the first row */
-  return get_memory_row(cinfo, sinfo);
-}
-
-
-/*
- * Read the file header; return image size and component count.
- */
-
-METHODDEF(void)
-start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  tga_source_ptr source = (tga_source_ptr) sinfo;
-  U_CHAR targaheader[18];
-  int idlen, cmaptype, subtype, flags, interlace_type, components;
-  unsigned int width, height, maplen;
-  boolean is_bottom_up;
-
-#define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \
-                        (((unsigned int) UCH(targaheader[offset+1])) << 8))
-
-  if (! ReadOK(source->pub.input_file, targaheader, 18))
-    ERREXIT(cinfo, JERR_INPUT_EOF);
-
-  /* Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway */
-  if (targaheader[16] == 15)
-    targaheader[16] = 16;
-
-  idlen = UCH(targaheader[0]);
-  cmaptype = UCH(targaheader[1]);
-  subtype = UCH(targaheader[2]);
-  maplen = GET_2B(5);
-  width = GET_2B(12);
-  height = GET_2B(14);
-  source->pixel_size = UCH(targaheader[16]) >> 3;
-  flags = UCH(targaheader[17]);        /* Image Descriptor byte */
-
-  is_bottom_up = ((flags & 0x20) == 0);        /* bit 5 set => top-down */
-  interlace_type = flags >> 6; /* bits 6/7 are interlace code */
-
-  if (cmaptype > 1 ||          /* cmaptype must be 0 or 1 */
-      source->pixel_size < 1 || source->pixel_size > 4 ||
-      (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */
-      interlace_type != 0)     /* currently don't allow interlaced image */
-    ERREXIT(cinfo, JERR_TGA_BADPARMS);
-  
-  if (subtype > 8) {
-    /* It's an RLE-coded file */
-    source->read_pixel = read_rle_pixel;
-    source->block_count = source->dup_pixel_count = 0;
-    subtype -= 8;
-  } else {
-    /* Non-RLE file */
-    source->read_pixel = read_non_rle_pixel;
-  }
-
-  /* Now should have subtype 1, 2, or 3 */
-  components = 3;              /* until proven different */
-  cinfo->in_color_space = JCS_RGB;
-
-  switch (subtype) {
-  case 1:                      /* Colormapped image */
-    if (source->pixel_size == 1 && cmaptype == 1)
-      source->get_pixel_rows = get_8bit_row;
-    else
-      ERREXIT(cinfo, JERR_TGA_BADPARMS);
-    TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height);
-    break;
-  case 2:                      /* RGB image */
-    switch (source->pixel_size) {
-    case 2:
-      source->get_pixel_rows = get_16bit_row;
-      break;
-    case 3:
-      source->get_pixel_rows = get_24bit_row;
-      break;
-    case 4:
-      source->get_pixel_rows = get_32bit_row;
-      break;
-    default:
-      ERREXIT(cinfo, JERR_TGA_BADPARMS);
-      break;
-    }
-    TRACEMS2(cinfo, 1, JTRC_TGA, width, height);
-    break;
-  case 3:                      /* Grayscale image */
-    components = 1;
-    cinfo->in_color_space = JCS_GRAYSCALE;
-    if (source->pixel_size == 1)
-      source->get_pixel_rows = get_8bit_gray_row;
-    else
-      ERREXIT(cinfo, JERR_TGA_BADPARMS);
-    TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height);
-    break;
-  default:
-    ERREXIT(cinfo, JERR_TGA_BADPARMS);
-    break;
-  }
-
-  if (is_bottom_up) {
-    /* Create a virtual array to buffer the upside-down image. */
-    source->whole_image = (*cinfo->mem->request_virt_sarray)
-      ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
-       (JDIMENSION) width * components, (JDIMENSION) height, (JDIMENSION) 1);
-    if (cinfo->progress != NULL) {
-      cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
-      progress->total_extra_passes++; /* count file input as separate pass */
-    }
-    /* source->pub.buffer will point to the virtual array. */
-    source->pub.buffer_height = 1; /* in case anyone looks at it */
-    source->pub.get_pixel_rows = preload_image;
-  } else {
-    /* Don't need a virtual array, but do need a one-row input buffer. */
-    source->whole_image = NULL;
-    source->pub.buffer = (*cinfo->mem->alloc_sarray)
-      ((j_common_ptr) cinfo, JPOOL_IMAGE,
-       (JDIMENSION) width * components, (JDIMENSION) 1);
-    source->pub.buffer_height = 1;
-    source->pub.get_pixel_rows = source->get_pixel_rows;
-  }
-  
-  while (idlen--)              /* Throw away ID field */
-    (void) read_byte(source);
-
-  if (maplen > 0) {
-    if (maplen > 256 || GET_2B(3) != 0)
-      ERREXIT(cinfo, JERR_TGA_BADCMAP);
-    /* Allocate space to store the colormap */
-    source->colormap = (*cinfo->mem->alloc_sarray)
-      ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3);
-    /* and read it from the file */
-    read_colormap(source, (int) maplen, UCH(targaheader[7]));
-  } else {
-    if (cmaptype)              /* but you promised a cmap! */
-      ERREXIT(cinfo, JERR_TGA_BADPARMS);
-    source->colormap = NULL;
-  }
-
-  cinfo->input_components = components;
-  cinfo->data_precision = 8;
-  cinfo->image_width = width;
-  cinfo->image_height = height;
-}
-
-
-/*
- * Finish up at the end of the file.
- */
-
-METHODDEF(void)
-finish_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
-{
-  /* no work */
-}
-
-
-/*
- * The module selection routine for Targa format input.
- */
-
-GLOBAL(cjpeg_source_ptr)
-jinit_read_targa (j_compress_ptr cinfo)
-{
-  tga_source_ptr source;
-
-  /* Create module interface object */
-  source = (tga_source_ptr)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                 SIZEOF(tga_source_struct));
-  source->cinfo = cinfo;       /* make back link for subroutines */
-  /* Fill in method ptrs, except get_pixel_rows which start_input sets */
-  source->pub.start_input = start_input_tga;
-  source->pub.finish_input = finish_input_tga;
-
-  return (cjpeg_source_ptr) source;
-}
-
-#endif /* TARGA_SUPPORTED */
diff --git a/src/jpeg/libijg8/transupp.c b/src/jpeg/libijg8/transupp.c
deleted file mode 100644 (file)
index e5ec564..0000000
+++ /dev/null
@@ -1,928 +0,0 @@
-/*
- * transupp.c
- *
- * Copyright (C) 1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains image transformation routines and other utility code
- * used by the jpegtran sample application.  These are NOT part of the core
- * JPEG library.  But we keep these routines separate from jpegtran.c to
- * ease the task of maintaining jpegtran-like programs that have other user
- * interfaces.
- */
-
-/* Although this file really shouldn't have access to the library internals,
- * it's helpful to let it call jround_up() and jcopy_block_row().
- */
-#define JPEG_INTERNALS
-
-#include "jinclude.h"
-#include "jpeglib.h"
-#include "transupp.h"          /* My own external interface */
-
-
-#if TRANSFORMS_SUPPORTED
-
-/*
- * Lossless image transformation routines.  These routines work on DCT
- * coefficient arrays and thus do not require any lossy decompression
- * or recompression of the image.
- * Thanks to Guido Vollbeding for the initial design and code of this feature.
- *
- * Horizontal flipping is done in-place, using a single top-to-bottom
- * pass through the virtual source array.  It will thus be much the
- * fastest option for images larger than main memory.
- *
- * The other routines require a set of destination virtual arrays, so they
- * need twice as much memory as jpegtran normally does.  The destination
- * arrays are always written in normal scan order (top to bottom) because
- * the virtual array manager expects this.  The source arrays will be scanned
- * in the corresponding order, which means multiple passes through the source
- * arrays for most of the transforms.  That could result in much thrashing
- * if the image is larger than main memory.
- *
- * Some notes about the operating environment of the individual transform
- * routines:
- * 1. Both the source and destination virtual arrays are allocated from the
- *    source JPEG object, and therefore should be manipulated by calling the
- *    source's memory manager.
- * 2. The destination's component count should be used.  It may be smaller
- *    than the source's when forcing to grayscale.
- * 3. Likewise the destination's sampling factors should be used.  When
- *    forcing to grayscale the destination's sampling factors will be all 1,
- *    and we may as well take that as the effective iMCU size.
- * 4. When "trim" is in effect, the destination's dimensions will be the
- *    trimmed values but the source's will be untrimmed.
- * 5. All the routines assume that the source and destination buffers are
- *    padded out to a full iMCU boundary.  This is true, although for the
- *    source buffer it is an undocumented property of jdcoefct.c.
- * Notes 2,3,4 boil down to this: generally we should use the destination's
- * dimensions and ignore the source's.
- */
-
-
-LOCAL(void)
-do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-          jvirt_barray_ptr *src_coef_arrays)
-/* Horizontal flip; done in-place, so no separate dest array is required */
-{
-  JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
-  int ci, k, offset_y;
-  JBLOCKARRAY buffer;
-  JCOEFPTR ptr1, ptr2;
-  JCOEF temp1, temp2;
-  jpeg_component_info *compptr;
-
-  /* Horizontal mirroring of DCT blocks is accomplished by swapping
-   * pairs of blocks in-place.  Within a DCT block, we perform horizontal
-   * mirroring by changing the signs of odd-numbered columns.
-   * Partial iMCUs at the right edge are left untouched.
-   */
-  MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
-
-  for (ci = 0; ci < dstinfo->num_components; ci++) {
-    compptr = dstinfo->comp_info + ci;
-    comp_width = MCU_cols * compptr->h_samp_factor;
-    for (blk_y = 0; blk_y < compptr->height_in_blocks;
-        blk_y += compptr->v_samp_factor) {
-      buffer = (*srcinfo->mem->access_virt_barray)
-       ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
-        (JDIMENSION) compptr->v_samp_factor, TRUE);
-      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
-       for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
-         ptr1 = buffer[offset_y][blk_x];
-         ptr2 = buffer[offset_y][comp_width - blk_x - 1];
-         /* this unrolled loop doesn't need to know which row it's on... */
-         for (k = 0; k < DCTSIZE2; k += 2) {
-           temp1 = *ptr1;      /* swap even column */
-           temp2 = *ptr2;
-           *ptr1++ = temp2;
-           *ptr2++ = temp1;
-           temp1 = *ptr1;      /* swap odd column with sign change */
-           temp2 = *ptr2;
-           *ptr1++ = -temp2;
-           *ptr2++ = -temp1;
-         }
-       }
-      }
-    }
-  }
-}
-
-
-LOCAL(void)
-do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-          jvirt_barray_ptr *src_coef_arrays,
-          jvirt_barray_ptr *dst_coef_arrays)
-/* Vertical flip */
-{
-  JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
-  int ci, i, j, offset_y;
-  JBLOCKARRAY src_buffer, dst_buffer;
-  JBLOCKROW src_row_ptr, dst_row_ptr;
-  JCOEFPTR src_ptr, dst_ptr;
-  jpeg_component_info *compptr;
-
-  /* We output into a separate array because we can't touch different
-   * rows of the source virtual array simultaneously.  Otherwise, this
-   * is a pretty straightforward analog of horizontal flip.
-   * Within a DCT block, vertical mirroring is done by changing the signs
-   * of odd-numbered rows.
-   * Partial iMCUs at the bottom edge are copied verbatim.
-   */
-  MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
-
-  for (ci = 0; ci < dstinfo->num_components; ci++) {
-    compptr = dstinfo->comp_info + ci;
-    comp_height = MCU_rows * compptr->v_samp_factor;
-    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
-        dst_blk_y += compptr->v_samp_factor) {
-      dst_buffer = (*srcinfo->mem->access_virt_barray)
-       ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
-        (JDIMENSION) compptr->v_samp_factor, TRUE);
-      if (dst_blk_y < comp_height) {
-       /* Row is within the mirrorable area. */
-       src_buffer = (*srcinfo->mem->access_virt_barray)
-         ((j_common_ptr) srcinfo, src_coef_arrays[ci],
-          comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
-          (JDIMENSION) compptr->v_samp_factor, FALSE);
-      } else {
-       /* Bottom-edge blocks will be copied verbatim. */
-       src_buffer = (*srcinfo->mem->access_virt_barray)
-         ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
-          (JDIMENSION) compptr->v_samp_factor, FALSE);
-      }
-      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
-       if (dst_blk_y < comp_height) {
-         /* Row is within the mirrorable area. */
-         dst_row_ptr = dst_buffer[offset_y];
-         src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
-         for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
-              dst_blk_x++) {
-           dst_ptr = dst_row_ptr[dst_blk_x];
-           src_ptr = src_row_ptr[dst_blk_x];
-           for (i = 0; i < DCTSIZE; i += 2) {
-             /* copy even row */
-             for (j = 0; j < DCTSIZE; j++)
-               *dst_ptr++ = *src_ptr++;
-             /* copy odd row with sign change */
-             for (j = 0; j < DCTSIZE; j++)
-               *dst_ptr++ = - *src_ptr++;
-           }
-         }
-       } else {
-         /* Just copy row verbatim. */
-         jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
-                         compptr->width_in_blocks);
-       }
-      }
-    }
-  }
-}
-
-
-LOCAL(void)
-do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-             jvirt_barray_ptr *src_coef_arrays,
-             jvirt_barray_ptr *dst_coef_arrays)
-/* Transpose source into destination */
-{
-  JDIMENSION dst_blk_x, dst_blk_y;
-  int ci, i, j, offset_x, offset_y;
-  JBLOCKARRAY src_buffer, dst_buffer;
-  JCOEFPTR src_ptr, dst_ptr;
-  jpeg_component_info *compptr;
-
-  /* Transposing pixels within a block just requires transposing the
-   * DCT coefficients.
-   * Partial iMCUs at the edges require no special treatment; we simply
-   * process all the available DCT blocks for every component.
-   */
-  for (ci = 0; ci < dstinfo->num_components; ci++) {
-    compptr = dstinfo->comp_info + ci;
-    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
-        dst_blk_y += compptr->v_samp_factor) {
-      dst_buffer = (*srcinfo->mem->access_virt_barray)
-       ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
-        (JDIMENSION) compptr->v_samp_factor, TRUE);
-      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
-       for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
-            dst_blk_x += compptr->h_samp_factor) {
-         src_buffer = (*srcinfo->mem->access_virt_barray)
-           ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
-            (JDIMENSION) compptr->h_samp_factor, FALSE);
-         for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
-           src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
-           dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
-           for (i = 0; i < DCTSIZE; i++)
-             for (j = 0; j < DCTSIZE; j++)
-               dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
-         }
-       }
-      }
-    }
-  }
-}
-
-
-LOCAL(void)
-do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-          jvirt_barray_ptr *src_coef_arrays,
-          jvirt_barray_ptr *dst_coef_arrays)
-/* 90 degree rotation is equivalent to
- *   1. Transposing the image;
- *   2. Horizontal mirroring.
- * These two steps are merged into a single processing routine.
- */
-{
-  JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
-  int ci, i, j, offset_x, offset_y;
-  JBLOCKARRAY src_buffer, dst_buffer;
-  JCOEFPTR src_ptr, dst_ptr;
-  jpeg_component_info *compptr;
-
-  /* Because of the horizontal mirror step, we can't process partial iMCUs
-   * at the (output) right edge properly.  They just get transposed and
-   * not mirrored.
-   */
-  MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
-
-  for (ci = 0; ci < dstinfo->num_components; ci++) {
-    compptr = dstinfo->comp_info + ci;
-    comp_width = MCU_cols * compptr->h_samp_factor;
-    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
-        dst_blk_y += compptr->v_samp_factor) {
-      dst_buffer = (*srcinfo->mem->access_virt_barray)
-       ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
-        (JDIMENSION) compptr->v_samp_factor, TRUE);
-      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
-       for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
-            dst_blk_x += compptr->h_samp_factor) {
-         src_buffer = (*srcinfo->mem->access_virt_barray)
-           ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
-            (JDIMENSION) compptr->h_samp_factor, FALSE);
-         for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
-           src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
-           if (dst_blk_x < comp_width) {
-             /* Block is within the mirrorable area. */
-             dst_ptr = dst_buffer[offset_y]
-               [comp_width - dst_blk_x - offset_x - 1];
-             for (i = 0; i < DCTSIZE; i++) {
-               for (j = 0; j < DCTSIZE; j++)
-                 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
-               i++;
-               for (j = 0; j < DCTSIZE; j++)
-                 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
-             }
-           } else {
-             /* Edge blocks are transposed but not mirrored. */
-             dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
-             for (i = 0; i < DCTSIZE; i++)
-               for (j = 0; j < DCTSIZE; j++)
-                 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
-           }
-         }
-       }
-      }
-    }
-  }
-}
-
-
-LOCAL(void)
-do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-           jvirt_barray_ptr *src_coef_arrays,
-           jvirt_barray_ptr *dst_coef_arrays)
-/* 270 degree rotation is equivalent to
- *   1. Horizontal mirroring;
- *   2. Transposing the image.
- * These two steps are merged into a single processing routine.
- */
-{
-  JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
-  int ci, i, j, offset_x, offset_y;
-  JBLOCKARRAY src_buffer, dst_buffer;
-  JCOEFPTR src_ptr, dst_ptr;
-  jpeg_component_info *compptr;
-
-  /* Because of the horizontal mirror step, we can't process partial iMCUs
-   * at the (output) bottom edge properly.  They just get transposed and
-   * not mirrored.
-   */
-  MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
-
-  for (ci = 0; ci < dstinfo->num_components; ci++) {
-    compptr = dstinfo->comp_info + ci;
-    comp_height = MCU_rows * compptr->v_samp_factor;
-    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
-        dst_blk_y += compptr->v_samp_factor) {
-      dst_buffer = (*srcinfo->mem->access_virt_barray)
-       ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
-        (JDIMENSION) compptr->v_samp_factor, TRUE);
-      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
-       for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
-            dst_blk_x += compptr->h_samp_factor) {
-         src_buffer = (*srcinfo->mem->access_virt_barray)
-           ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
-            (JDIMENSION) compptr->h_samp_factor, FALSE);
-         for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
-           dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
-           if (dst_blk_y < comp_height) {
-             /* Block is within the mirrorable area. */
-             src_ptr = src_buffer[offset_x]
-               [comp_height - dst_blk_y - offset_y - 1];
-             for (i = 0; i < DCTSIZE; i++) {
-               for (j = 0; j < DCTSIZE; j++) {
-                 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
-                 j++;
-                 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
-               }
-             }
-           } else {
-             /* Edge blocks are transposed but not mirrored. */
-             src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
-             for (i = 0; i < DCTSIZE; i++)
-               for (j = 0; j < DCTSIZE; j++)
-                 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
-           }
-         }
-       }
-      }
-    }
-  }
-}
-
-
-LOCAL(void)
-do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-           jvirt_barray_ptr *src_coef_arrays,
-           jvirt_barray_ptr *dst_coef_arrays)
-/* 180 degree rotation is equivalent to
- *   1. Vertical mirroring;
- *   2. Horizontal mirroring.
- * These two steps are merged into a single processing routine.
- */
-{
-  JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
-  int ci, i, j, offset_y;
-  JBLOCKARRAY src_buffer, dst_buffer;
-  JBLOCKROW src_row_ptr, dst_row_ptr;
-  JCOEFPTR src_ptr, dst_ptr;
-  jpeg_component_info *compptr;
-
-  MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
-  MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
-
-  for (ci = 0; ci < dstinfo->num_components; ci++) {
-    compptr = dstinfo->comp_info + ci;
-    comp_width = MCU_cols * compptr->h_samp_factor;
-    comp_height = MCU_rows * compptr->v_samp_factor;
-    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
-        dst_blk_y += compptr->v_samp_factor) {
-      dst_buffer = (*srcinfo->mem->access_virt_barray)
-       ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
-        (JDIMENSION) compptr->v_samp_factor, TRUE);
-      if (dst_blk_y < comp_height) {
-       /* Row is within the vertically mirrorable area. */
-       src_buffer = (*srcinfo->mem->access_virt_barray)
-         ((j_common_ptr) srcinfo, src_coef_arrays[ci],
-          comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
-          (JDIMENSION) compptr->v_samp_factor, FALSE);
-      } else {
-       /* Bottom-edge rows are only mirrored horizontally. */
-       src_buffer = (*srcinfo->mem->access_virt_barray)
-         ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
-          (JDIMENSION) compptr->v_samp_factor, FALSE);
-      }
-      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
-       if (dst_blk_y < comp_height) {
-         /* Row is within the mirrorable area. */
-         dst_row_ptr = dst_buffer[offset_y];
-         src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
-         /* Process the blocks that can be mirrored both ways. */
-         for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
-           dst_ptr = dst_row_ptr[dst_blk_x];
-           src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
-           for (i = 0; i < DCTSIZE; i += 2) {
-             /* For even row, negate every odd column. */
-             for (j = 0; j < DCTSIZE; j += 2) {
-               *dst_ptr++ = *src_ptr++;
-               *dst_ptr++ = - *src_ptr++;
-             }
-             /* For odd row, negate every even column. */
-             for (j = 0; j < DCTSIZE; j += 2) {
-               *dst_ptr++ = - *src_ptr++;
-               *dst_ptr++ = *src_ptr++;
-             }
-           }
-         }
-         /* Any remaining right-edge blocks are only mirrored vertically. */
-         for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
-           dst_ptr = dst_row_ptr[dst_blk_x];
-           src_ptr = src_row_ptr[dst_blk_x];
-           for (i = 0; i < DCTSIZE; i += 2) {
-             for (j = 0; j < DCTSIZE; j++)
-               *dst_ptr++ = *src_ptr++;
-             for (j = 0; j < DCTSIZE; j++)
-               *dst_ptr++ = - *src_ptr++;
-           }
-         }
-       } else {
-         /* Remaining rows are just mirrored horizontally. */
-         dst_row_ptr = dst_buffer[offset_y];
-         src_row_ptr = src_buffer[offset_y];
-         /* Process the blocks that can be mirrored. */
-         for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
-           dst_ptr = dst_row_ptr[dst_blk_x];
-           src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
-           for (i = 0; i < DCTSIZE2; i += 2) {
-             *dst_ptr++ = *src_ptr++;
-             *dst_ptr++ = - *src_ptr++;
-           }
-         }
-         /* Any remaining right-edge blocks are only copied. */
-         for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
-           dst_ptr = dst_row_ptr[dst_blk_x];
-           src_ptr = src_row_ptr[dst_blk_x];
-           for (i = 0; i < DCTSIZE2; i++)
-             *dst_ptr++ = *src_ptr++;
-         }
-       }
-      }
-    }
-  }
-}
-
-
-LOCAL(void)
-do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-              jvirt_barray_ptr *src_coef_arrays,
-              jvirt_barray_ptr *dst_coef_arrays)
-/* Transverse transpose is equivalent to
- *   1. 180 degree rotation;
- *   2. Transposition;
- * or
- *   1. Horizontal mirroring;
- *   2. Transposition;
- *   3. Horizontal mirroring.
- * These steps are merged into a single processing routine.
- */
-{
-  JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
-  int ci, i, j, offset_x, offset_y;
-  JBLOCKARRAY src_buffer, dst_buffer;
-  JCOEFPTR src_ptr, dst_ptr;
-  jpeg_component_info *compptr;
-
-  MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
-  MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
-
-  for (ci = 0; ci < dstinfo->num_components; ci++) {
-    compptr = dstinfo->comp_info + ci;
-    comp_width = MCU_cols * compptr->h_samp_factor;
-    comp_height = MCU_rows * compptr->v_samp_factor;
-    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
-        dst_blk_y += compptr->v_samp_factor) {
-      dst_buffer = (*srcinfo->mem->access_virt_barray)
-       ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
-        (JDIMENSION) compptr->v_samp_factor, TRUE);
-      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
-       for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
-            dst_blk_x += compptr->h_samp_factor) {
-         src_buffer = (*srcinfo->mem->access_virt_barray)
-           ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
-            (JDIMENSION) compptr->h_samp_factor, FALSE);
-         for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
-           if (dst_blk_y < comp_height) {
-             src_ptr = src_buffer[offset_x]
-               [comp_height - dst_blk_y - offset_y - 1];
-             if (dst_blk_x < comp_width) {
-               /* Block is within the mirrorable area. */
-               dst_ptr = dst_buffer[offset_y]
-                 [comp_width - dst_blk_x - offset_x - 1];
-               for (i = 0; i < DCTSIZE; i++) {
-                 for (j = 0; j < DCTSIZE; j++) {
-                   dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
-                   j++;
-                   dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
-                 }
-                 i++;
-                 for (j = 0; j < DCTSIZE; j++) {
-                   dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
-                   j++;
-                   dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
-                 }
-               }
-             } else {
-               /* Right-edge blocks are mirrored in y only */
-               dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
-               for (i = 0; i < DCTSIZE; i++) {
-                 for (j = 0; j < DCTSIZE; j++) {
-                   dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
-                   j++;
-                   dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
-                 }
-               }
-             }
-           } else {
-             src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
-             if (dst_blk_x < comp_width) {
-               /* Bottom-edge blocks are mirrored in x only */
-               dst_ptr = dst_buffer[offset_y]
-                 [comp_width - dst_blk_x - offset_x - 1];
-               for (i = 0; i < DCTSIZE; i++) {
-                 for (j = 0; j < DCTSIZE; j++)
-                   dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
-                 i++;
-                 for (j = 0; j < DCTSIZE; j++)
-                   dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
-               }
-             } else {
-               /* At lower right corner, just transpose, no mirroring */
-               dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
-               for (i = 0; i < DCTSIZE; i++)
-                 for (j = 0; j < DCTSIZE; j++)
-                   dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
-             }
-           }
-         }
-       }
-      }
-    }
-  }
-}
-
-
-/* Request any required workspace.
- *
- * We allocate the workspace virtual arrays from the source decompression
- * object, so that all the arrays (both the original data and the workspace)
- * will be taken into account while making memory management decisions.
- * Hence, this routine must be called after jpeg_read_header (which reads
- * the image dimensions) and before jpeg_read_coefficients (which realizes
- * the source's virtual arrays).
- */
-
-GLOBAL(void)
-jtransform_request_workspace (j_decompress_ptr srcinfo,
-                             jpeg_transform_info *info)
-{
-  jvirt_barray_ptr *coef_arrays = NULL;
-  jpeg_component_info *compptr;
-  int ci;
-
-  if (info->force_grayscale &&
-      srcinfo->jpeg_color_space == JCS_YCbCr &&
-      srcinfo->num_components == 3) {
-    /* We'll only process the first component */
-    info->num_components = 1;
-  } else {
-    /* Process all the components */
-    info->num_components = srcinfo->num_components;
-  }
-
-  switch (info->transform) {
-  case JXFORM_NONE:
-  case JXFORM_FLIP_H:
-    /* Don't need a workspace array */
-    break;
-  case JXFORM_FLIP_V:
-  case JXFORM_ROT_180:
-    /* Need workspace arrays having same dimensions as source image.
-     * Note that we allocate arrays padded out to the next iMCU boundary,
-     * so that transform routines need not worry about missing edge blocks.
-     */
-    coef_arrays = (jvirt_barray_ptr *)
-      (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
-       SIZEOF(jvirt_barray_ptr) * info->num_components);
-    for (ci = 0; ci < info->num_components; ci++) {
-      compptr = srcinfo->comp_info + ci;
-      coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
-       ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
-        (JDIMENSION) jround_up((long) compptr->width_in_blocks,
-                               (long) compptr->h_samp_factor),
-        (JDIMENSION) jround_up((long) compptr->height_in_blocks,
-                               (long) compptr->v_samp_factor),
-        (JDIMENSION) compptr->v_samp_factor);
-    }
-    break;
-  case JXFORM_TRANSPOSE:
-  case JXFORM_TRANSVERSE:
-  case JXFORM_ROT_90:
-  case JXFORM_ROT_270:
-    /* Need workspace arrays having transposed dimensions.
-     * Note that we allocate arrays padded out to the next iMCU boundary,
-     * so that transform routines need not worry about missing edge blocks.
-     */
-    coef_arrays = (jvirt_barray_ptr *)
-      (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
-       SIZEOF(jvirt_barray_ptr) * info->num_components);
-    for (ci = 0; ci < info->num_components; ci++) {
-      compptr = srcinfo->comp_info + ci;
-      coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
-       ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
-        (JDIMENSION) jround_up((long) compptr->height_in_blocks,
-                               (long) compptr->v_samp_factor),
-        (JDIMENSION) jround_up((long) compptr->width_in_blocks,
-                               (long) compptr->h_samp_factor),
-        (JDIMENSION) compptr->h_samp_factor);
-    }
-    break;
-  }
-  info->workspace_coef_arrays = coef_arrays;
-}
-
-
-/* Transpose destination image parameters */
-
-LOCAL(void)
-transpose_critical_parameters (j_compress_ptr dstinfo)
-{
-  int tblno, i, j, ci, itemp;
-  jpeg_component_info *compptr;
-  JQUANT_TBL *qtblptr;
-  JDIMENSION dtemp;
-  UINT16 qtemp;
-
-  /* Transpose basic image dimensions */
-  dtemp = dstinfo->image_width;
-  dstinfo->image_width = dstinfo->image_height;
-  dstinfo->image_height = dtemp;
-
-  /* Transpose sampling factors */
-  for (ci = 0; ci < dstinfo->num_components; ci++) {
-    compptr = dstinfo->comp_info + ci;
-    itemp = compptr->h_samp_factor;
-    compptr->h_samp_factor = compptr->v_samp_factor;
-    compptr->v_samp_factor = itemp;
-  }
-
-  /* Transpose quantization tables */
-  for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
-    qtblptr = dstinfo->quant_tbl_ptrs[tblno];
-    if (qtblptr != NULL) {
-      for (i = 0; i < DCTSIZE; i++) {
-       for (j = 0; j < i; j++) {
-         qtemp = qtblptr->quantval[i*DCTSIZE+j];
-         qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
-         qtblptr->quantval[j*DCTSIZE+i] = qtemp;
-       }
-      }
-    }
-  }
-}
-
-
-/* Trim off any partial iMCUs on the indicated destination edge */
-
-LOCAL(void)
-trim_right_edge (j_compress_ptr dstinfo)
-{
-  int ci, max_h_samp_factor;
-  JDIMENSION MCU_cols;
-
-  /* We have to compute max_h_samp_factor ourselves,
-   * because it hasn't been set yet in the destination
-   * (and we don't want to use the source's value).
-   */
-  max_h_samp_factor = 1;
-  for (ci = 0; ci < dstinfo->num_components; ci++) {
-    int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
-    max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
-  }
-  MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
-  if (MCU_cols > 0)            /* can't trim to 0 pixels */
-    dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
-}
-
-LOCAL(void)
-trim_bottom_edge (j_compress_ptr dstinfo)
-{
-  int ci, max_v_samp_factor;
-  JDIMENSION MCU_rows;
-
-  /* We have to compute max_v_samp_factor ourselves,
-   * because it hasn't been set yet in the destination
-   * (and we don't want to use the source's value).
-   */
-  max_v_samp_factor = 1;
-  for (ci = 0; ci < dstinfo->num_components; ci++) {
-    int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
-    max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
-  }
-  MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
-  if (MCU_rows > 0)            /* can't trim to 0 pixels */
-    dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
-}
-
-
-/* Adjust output image parameters as needed.
- *
- * This must be called after jpeg_copy_critical_parameters()
- * and before jpeg_write_coefficients().
- *
- * The return value is the set of virtual coefficient arrays to be written
- * (either the ones allocated by jtransform_request_workspace, or the
- * original source data arrays).  The caller will need to pass this value
- * to jpeg_write_coefficients().
- */
-
-GLOBAL(jvirt_barray_ptr *)
-jtransform_adjust_parameters (j_decompress_ptr srcinfo,
-                             j_compress_ptr dstinfo,
-                             jvirt_barray_ptr *src_coef_arrays,
-                             jpeg_transform_info *info)
-{
-  /* If force-to-grayscale is requested, adjust destination parameters */
-  if (info->force_grayscale) {
-    /* We use jpeg_set_colorspace to make sure subsidiary settings get fixed
-     * properly.  Among other things, the target h_samp_factor & v_samp_factor
-     * will get set to 1, which typically won't match the source.
-     * In fact we do this even if the source is already grayscale; that
-     * provides an easy way of coercing a grayscale JPEG with funny sampling
-     * factors to the customary 1,1.  (Some decoders fail on other factors.)
-     */
-    if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
-        dstinfo->num_components == 3) ||
-       (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
-        dstinfo->num_components == 1)) {
-      /* We have to preserve the source's quantization table number. */
-      int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
-      jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
-      dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
-    } else {
-      /* Sorry, can't do it */
-      ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
-    }
-  }
-
-  /* Correct the destination's image dimensions etc if necessary */
-  switch (info->transform) {
-  case JXFORM_NONE:
-    /* Nothing to do */
-    break;
-  case JXFORM_FLIP_H:
-    if (info->trim)
-      trim_right_edge(dstinfo);
-    break;
-  case JXFORM_FLIP_V:
-    if (info->trim)
-      trim_bottom_edge(dstinfo);
-    break;
-  case JXFORM_TRANSPOSE:
-    transpose_critical_parameters(dstinfo);
-    /* transpose does NOT have to trim anything */
-    break;
-  case JXFORM_TRANSVERSE:
-    transpose_critical_parameters(dstinfo);
-    if (info->trim) {
-      trim_right_edge(dstinfo);
-      trim_bottom_edge(dstinfo);
-    }
-    break;
-  case JXFORM_ROT_90:
-    transpose_critical_parameters(dstinfo);
-    if (info->trim)
-      trim_right_edge(dstinfo);
-    break;
-  case JXFORM_ROT_180:
-    if (info->trim) {
-      trim_right_edge(dstinfo);
-      trim_bottom_edge(dstinfo);
-    }
-    break;
-  case JXFORM_ROT_270:
-    transpose_critical_parameters(dstinfo);
-    if (info->trim)
-      trim_bottom_edge(dstinfo);
-    break;
-  }
-
-  /* Return the appropriate output data set */
-  if (info->workspace_coef_arrays != NULL)
-    return info->workspace_coef_arrays;
-  return src_coef_arrays;
-}
-
-
-/* Execute the actual transformation, if any.
- *
- * This must be called *after* jpeg_write_coefficients, because it depends
- * on jpeg_write_coefficients to have computed subsidiary values such as
- * the per-component width and height fields in the destination object.
- *
- * Note that some transformations will modify the source data arrays!
- */
-
-GLOBAL(void)
-jtransform_execute_transformation (j_decompress_ptr srcinfo,
-                                  j_compress_ptr dstinfo,
-                                  jvirt_barray_ptr *src_coef_arrays,
-                                  jpeg_transform_info *info)
-{
-  jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
-
-  switch (info->transform) {
-  case JXFORM_NONE:
-    break;
-  case JXFORM_FLIP_H:
-    do_flip_h(srcinfo, dstinfo, src_coef_arrays);
-    break;
-  case JXFORM_FLIP_V:
-    do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
-    break;
-  case JXFORM_TRANSPOSE:
-    do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
-    break;
-  case JXFORM_TRANSVERSE:
-    do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
-    break;
-  case JXFORM_ROT_90:
-    do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
-    break;
-  case JXFORM_ROT_180:
-    do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
-    break;
-  case JXFORM_ROT_270:
-    do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
-    break;
-  }
-}
-
-#endif /* TRANSFORMS_SUPPORTED */
-
-
-/* Setup decompression object to save desired markers in memory.
- * This must be called before jpeg_read_header() to have the desired effect.
- */
-
-GLOBAL(void)
-jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
-{
-#ifdef SAVE_MARKERS_SUPPORTED
-  int m;
-
-  /* Save comments except under NONE option */
-  if (option != JCOPYOPT_NONE) {
-    jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
-  }
-  /* Save all types of APPn markers iff ALL option */
-  if (option == JCOPYOPT_ALL) {
-    for (m = 0; m < 16; m++)
-      jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
-  }
-#endif /* SAVE_MARKERS_SUPPORTED */
-}
-
-/* Copy markers saved in the given source object to the destination object.
- * This should be called just after jpeg_start_compress() or
- * jpeg_write_coefficients().
- * Note that those routines will have written the SOI, and also the
- * JFIF APP0 or Adobe APP14 markers if selected.
- */
-
-GLOBAL(void)
-jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-                      JCOPY_OPTION option)
-{
-  jpeg_saved_marker_ptr marker;
-
-  /* In the current implementation, we don't actually need to examine the
-   * option flag here; we just copy everything that got saved.
-   * But to avoid confusion, we do not output JFIF and Adobe APP14 markers
-   * if the encoder library already wrote one.
-   */
-  for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
-    if (dstinfo->write_JFIF_header &&
-       marker->marker == JPEG_APP0 &&
-       marker->data_length >= 5 &&
-       GETJOCTET(marker->data[0]) == 0x4A &&
-       GETJOCTET(marker->data[1]) == 0x46 &&
-       GETJOCTET(marker->data[2]) == 0x49 &&
-       GETJOCTET(marker->data[3]) == 0x46 &&
-       GETJOCTET(marker->data[4]) == 0)
-      continue;                        /* reject duplicate JFIF */
-    if (dstinfo->write_Adobe_marker &&
-       marker->marker == JPEG_APP0+14 &&
-       marker->data_length >= 5 &&
-       GETJOCTET(marker->data[0]) == 0x41 &&
-       GETJOCTET(marker->data[1]) == 0x64 &&
-       GETJOCTET(marker->data[2]) == 0x6F &&
-       GETJOCTET(marker->data[3]) == 0x62 &&
-       GETJOCTET(marker->data[4]) == 0x65)
-      continue;                        /* reject duplicate Adobe */
-#ifdef NEED_FAR_POINTERS
-    /* We could use jpeg_write_marker if the data weren't FAR... */
-    {
-      unsigned int i;
-      jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
-      for (i = 0; i < marker->data_length; i++)
-       jpeg_write_m_byte(dstinfo, marker->data[i]);
-    }
-#else
-    jpeg_write_marker(dstinfo, marker->marker,
-                     marker->data, marker->data_length);
-#endif
-  }
-}
diff --git a/src/jpeg/libijg8/transupp.h b/src/jpeg/libijg8/transupp.h
deleted file mode 100644 (file)
index 5c2d32a..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * transupp.h
- *
- * Copyright (C) 1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains declarations for image transformation routines and
- * other utility code used by the jpegtran sample application.  These are
- * NOT part of the core JPEG library.  But we keep these routines separate
- * from jpegtran.c to ease the task of maintaining jpegtran-like programs
- * that have other user interfaces.
- *
- * NOTE: all the routines declared here have very specific requirements
- * about when they are to be executed during the reading and writing of the
- * source and destination files.  See the comments in transupp.c, or see
- * jpegtran.c for an example of correct usage.
- */
-
-/* If you happen not to want the image transform support, disable it here */
-#ifndef TRANSFORMS_SUPPORTED
-#define TRANSFORMS_SUPPORTED 1         /* 0 disables transform code */
-#endif
-
-/* Short forms of external names for systems with brain-damaged linkers. */
-
-#ifdef NEED_SHORT_EXTERNAL_NAMES
-#define jtransform_request_workspace           jTrRequest
-#define jtransform_adjust_parameters           jTrAdjust
-#define jtransform_execute_transformation      jTrExec
-#define jcopy_markers_setup                    jCMrkSetup
-#define jcopy_markers_execute                  jCMrkExec
-#endif /* NEED_SHORT_EXTERNAL_NAMES */
-
-
-/*
- * Codes for supported types of image transformations.
- */
-
-typedef enum {
-       JXFORM_NONE,            /* no transformation */
-       JXFORM_FLIP_H,          /* horizontal flip */
-       JXFORM_FLIP_V,          /* vertical flip */
-       JXFORM_TRANSPOSE,       /* transpose across UL-to-LR axis */
-       JXFORM_TRANSVERSE,      /* transpose across UR-to-LL axis */
-       JXFORM_ROT_90,          /* 90-degree clockwise rotation */
-       JXFORM_ROT_180,         /* 180-degree rotation */
-       JXFORM_ROT_270          /* 270-degree clockwise (or 90 ccw) */
-} JXFORM_CODE;
-
-/*
- * Although rotating and flipping data expressed as DCT coefficients is not
- * hard, there is an asymmetry in the JPEG format specification for images
- * whose dimensions aren't multiples of the iMCU size.  The right and bottom
- * image edges are padded out to the next iMCU boundary with junk data; but
- * no padding is possible at the top and left edges.  If we were to flip
- * the whole image including the pad data, then pad garbage would become
- * visible at the top and/or left, and real pixels would disappear into the
- * pad margins --- perhaps permanently, since encoders & decoders may not
- * bother to preserve DCT blocks that appear to be completely outside the
- * nominal image area.  So, we have to exclude any partial iMCUs from the
- * basic transformation.
- *
- * Transpose is the only transformation that can handle partial iMCUs at the
- * right and bottom edges completely cleanly.  flip_h can flip partial iMCUs
- * at the bottom, but leaves any partial iMCUs at the right edge untouched.
- * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
- * The other transforms are defined as combinations of these basic transforms
- * and process edge blocks in a way that preserves the equivalence.
- *
- * The "trim" option causes untransformable partial iMCUs to be dropped;
- * this is not strictly lossless, but it usually gives the best-looking
- * result for odd-size images.  Note that when this option is active,
- * the expected mathematical equivalences between the transforms may not hold.
- * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
- * followed by -rot 180 -trim trims both edges.)
- *
- * We also offer a "force to grayscale" option, which simply discards the
- * chrominance channels of a YCbCr image.  This is lossless in the sense that
- * the luminance channel is preserved exactly.  It's not the same kind of
- * thing as the rotate/flip transformations, but it's convenient to handle it
- * as part of this package, mainly because the transformation routines have to
- * be aware of the option to know how many components to work on.
- */
-
-typedef struct {
-  /* Options: set by caller */
-  JXFORM_CODE transform;       /* image transform operator */
-  boolean trim;                        /* if TRUE, trim partial MCUs as needed */
-  boolean force_grayscale;     /* if TRUE, convert color image to grayscale */
-
-  /* Internal workspace: caller should not touch these */
-  int num_components;          /* # of components in workspace */
-  jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
-} jpeg_transform_info;
-
-
-#if TRANSFORMS_SUPPORTED
-
-/* Request any required workspace */
-EXTERN(void) jtransform_request_workspace
-       JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
-/* Adjust output image parameters */
-EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
-       JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-            jvirt_barray_ptr *src_coef_arrays,
-            jpeg_transform_info *info));
-/* Execute the actual transformation, if any */
-EXTERN(void) jtransform_execute_transformation
-       JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-            jvirt_barray_ptr *src_coef_arrays,
-            jpeg_transform_info *info));
-
-#endif /* TRANSFORMS_SUPPORTED */
-
-
-/*
- * Support for copying optional markers from source to destination file.
- */
-
-typedef enum {
-       JCOPYOPT_NONE,          /* copy no optional markers */
-       JCOPYOPT_COMMENTS,      /* copy only comment (COM) markers */
-       JCOPYOPT_ALL            /* copy all optional markers */
-} JCOPY_OPTION;
-
-#define JCOPYOPT_DEFAULT  JCOPYOPT_COMMENTS    /* recommended default */
-
-/* Setup decompression object to save desired markers in memory */
-EXTERN(void) jcopy_markers_setup
-       JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
-/* Copy markers saved in the given source object to the destination object */
-EXTERN(void) jcopy_markers_execute
-       JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
-            JCOPY_OPTION option));
diff --git a/src/jpeg/libijg8/wrbmp.c b/src/jpeg/libijg8/wrbmp.c
deleted file mode 100644 (file)
index 3283b0f..0000000
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- * wrbmp.c
- *
- * Copyright (C) 1994-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to write output images in Microsoft "BMP"
- * format (MS Windows 3.x and OS/2 1.x flavors).
- * Either 8-bit colormapped or 24-bit full-color format can be written.
- * No compression is supported.
- *
- * These routines may need modification for non-Unix environments or
- * specialized applications.  As they stand, they assume output to
- * an ordinary stdio stream.
- *
- * This code contributed by James Arthur Boucher.
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef BMP_SUPPORTED
-
-
-/*
- * To support 12-bit JPEG data, we'd have to scale output down to 8 bits.
- * This is not yet implemented.
- */
-
-#if BITS_IN_JSAMPLE != 8
-  Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
-#endif
-
-/*
- * Since BMP stores scanlines bottom-to-top, we have to invert the image
- * from JPEG's top-to-bottom order.  To do this, we save the outgoing data
- * in a virtual array during put_pixel_row calls, then actually emit the
- * BMP file during finish_output.  The virtual array contains one JSAMPLE per
- * pixel if the output is grayscale or colormapped, three if it is full color.
- */
-
-/* Private version of data destination object */
-
-typedef struct {
-  struct djpeg_dest_struct pub;        /* public fields */
-
-  boolean is_os2;              /* saves the OS2 format request flag */
-
-  jvirt_sarray_ptr whole_image;        /* needed to reverse row order */
-  JDIMENSION data_width;       /* JSAMPLEs per row */
-  JDIMENSION row_width;                /* physical width of one row in the BMP file */
-  int pad_bytes;               /* number of padding bytes needed per row */
-  JDIMENSION cur_output_row;   /* next row# to write to virtual array */
-} bmp_dest_struct;
-
-typedef bmp_dest_struct * bmp_dest_ptr;
-
-
-/* Forward declarations */
-LOCAL(void) write_colormap
-       JPP((j_decompress_ptr cinfo, bmp_dest_ptr dest,
-            int map_colors, int map_entry_size));
-
-
-/*
- * Write some pixel data.
- * In this module rows_supplied will always be 1.
- */
-
-METHODDEF(void)
-put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-               JDIMENSION rows_supplied)
-/* This version is for writing 24-bit pixels */
-{
-  bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;
-  JSAMPARRAY image_ptr;
-  register JSAMPROW inptr, outptr;
-  register JDIMENSION col;
-  int pad;
-
-  /* Access next row in virtual array */
-  image_ptr = (*cinfo->mem->access_virt_sarray)
-    ((j_common_ptr) cinfo, dest->whole_image,
-     dest->cur_output_row, (JDIMENSION) 1, TRUE);
-  dest->cur_output_row++;
-
-  /* Transfer data.  Note destination values must be in BGR order
-   * (even though Microsoft's own documents say the opposite).
-   */
-  inptr = dest->pub.buffer[0];
-  outptr = image_ptr[0];
-  for (col = cinfo->output_width; col > 0; col--) {
-    outptr[2] = *inptr++;      /* can omit GETJSAMPLE() safely */
-    outptr[1] = *inptr++;
-    outptr[0] = *inptr++;
-    outptr += 3;
-  }
-
-  /* Zero out the pad bytes. */
-  pad = dest->pad_bytes;
-  while (--pad >= 0)
-    *outptr++ = 0;
-}
-
-METHODDEF(void)
-put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-              JDIMENSION rows_supplied)
-/* This version is for grayscale OR quantized color output */
-{
-  bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;
-  JSAMPARRAY image_ptr;
-  register JSAMPROW inptr, outptr;
-  register JDIMENSION col;
-  int pad;
-
-  /* Access next row in virtual array */
-  image_ptr = (*cinfo->mem->access_virt_sarray)
-    ((j_common_ptr) cinfo, dest->whole_image,
-     dest->cur_output_row, (JDIMENSION) 1, TRUE);
-  dest->cur_output_row++;
-
-  /* Transfer data. */
-  inptr = dest->pub.buffer[0];
-  outptr = image_ptr[0];
-  for (col = cinfo->output_width; col > 0; col--) {
-    *outptr++ = *inptr++;      /* can omit GETJSAMPLE() safely */
-  }
-
-  /* Zero out the pad bytes. */
-  pad = dest->pad_bytes;
-  while (--pad >= 0)
-    *outptr++ = 0;
-}
-
-
-/*
- * Startup: normally writes the file header.
- * In this module we may as well postpone everything until finish_output.
- */
-
-METHODDEF(void)
-start_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
-{
-  /* no work here */
-}
-
-
-/*
- * Finish up at the end of the file.
- *
- * Here is where we really output the BMP file.
- *
- * First, routines to write the Windows and OS/2 variants of the file header.
- */
-
-LOCAL(void)
-write_bmp_header (j_decompress_ptr cinfo, bmp_dest_ptr dest)
-/* Write a Windows-style BMP file header, including colormap if needed */
-{
-  char bmpfileheader[14];
-  char bmpinfoheader[40];
-#define PUT_2B(array,offset,value)  \
-       (array[offset] = (char) ((value) & 0xFF), \
-        array[offset+1] = (char) (((value) >> 8) & 0xFF))
-#define PUT_4B(array,offset,value)  \
-       (array[offset] = (char) ((value) & 0xFF), \
-        array[offset+1] = (char) (((value) >> 8) & 0xFF), \
-        array[offset+2] = (char) (((value) >> 16) & 0xFF), \
-        array[offset+3] = (char) (((value) >> 24) & 0xFF))
-  INT32 headersize, bfSize;
-  int bits_per_pixel, cmap_entries;
-
-  /* Compute colormap size and total file size */
-  if (cinfo->out_color_space == JCS_RGB) {
-    if (cinfo->quantize_colors) {
-      /* Colormapped RGB */
-      bits_per_pixel = 8;
-      cmap_entries = 256;
-    } else {
-      /* Unquantized, full color RGB */
-      bits_per_pixel = 24;
-      cmap_entries = 0;
-    }
-  } else {
-    /* Grayscale output.  We need to fake a 256-entry colormap. */
-    bits_per_pixel = 8;
-    cmap_entries = 256;
-  }
-  /* File size */
-  headersize = 14 + 40 + cmap_entries * 4; /* Header and colormap */
-  bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height;
-  
-  /* Set unused fields of header to 0 */
-  MEMZERO(bmpfileheader, SIZEOF(bmpfileheader));
-  MEMZERO(bmpinfoheader, SIZEOF(bmpinfoheader));
-
-  /* Fill the file header */
-  bmpfileheader[0] = 0x42;     /* first 2 bytes are ASCII 'B', 'M' */
-  bmpfileheader[1] = 0x4D;
-  PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
-  /* we leave bfReserved1 & bfReserved2 = 0 */
-  PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
-
-  /* Fill the info header (Microsoft calls this a BITMAPINFOHEADER) */
-  PUT_2B(bmpinfoheader, 0, 40);        /* biSize */
-  PUT_4B(bmpinfoheader, 4, cinfo->output_width); /* biWidth */
-  PUT_4B(bmpinfoheader, 8, cinfo->output_height); /* biHeight */
-  PUT_2B(bmpinfoheader, 12, 1);        /* biPlanes - must be 1 */
-  PUT_2B(bmpinfoheader, 14, bits_per_pixel); /* biBitCount */
-  /* we leave biCompression = 0, for none */
-  /* we leave biSizeImage = 0; this is correct for uncompressed data */
-  if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */
-    PUT_4B(bmpinfoheader, 24, (INT32) (cinfo->X_density*100)); /* XPels/M */
-    PUT_4B(bmpinfoheader, 28, (INT32) (cinfo->Y_density*100)); /* XPels/M */
-  }
-  PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */
-  /* we leave biClrImportant = 0 */
-
-  if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14)
-    ERREXIT(cinfo, JERR_FILE_WRITE);
-  if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t) 40)
-    ERREXIT(cinfo, JERR_FILE_WRITE);
-
-  if (cmap_entries > 0)
-    write_colormap(cinfo, dest, cmap_entries, 4);
-}
-
-
-LOCAL(void)
-write_os2_header (j_decompress_ptr cinfo, bmp_dest_ptr dest)
-/* Write an OS2-style BMP file header, including colormap if needed */
-{
-  char bmpfileheader[14];
-  char bmpcoreheader[12];
-  INT32 headersize, bfSize;
-  int bits_per_pixel, cmap_entries;
-
-  /* Compute colormap size and total file size */
-  if (cinfo->out_color_space == JCS_RGB) {
-    if (cinfo->quantize_colors) {
-      /* Colormapped RGB */
-      bits_per_pixel = 8;
-      cmap_entries = 256;
-    } else {
-      /* Unquantized, full color RGB */
-      bits_per_pixel = 24;
-      cmap_entries = 0;
-    }
-  } else {
-    /* Grayscale output.  We need to fake a 256-entry colormap. */
-    bits_per_pixel = 8;
-    cmap_entries = 256;
-  }
-  /* File size */
-  headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */
-  bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height;
-  
-  /* Set unused fields of header to 0 */
-  MEMZERO(bmpfileheader, SIZEOF(bmpfileheader));
-  MEMZERO(bmpcoreheader, SIZEOF(bmpcoreheader));
-
-  /* Fill the file header */
-  bmpfileheader[0] = 0x42;     /* first 2 bytes are ASCII 'B', 'M' */
-  bmpfileheader[1] = 0x4D;
-  PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
-  /* we leave bfReserved1 & bfReserved2 = 0 */
-  PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
-
-  /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */
-  PUT_2B(bmpcoreheader, 0, 12);        /* bcSize */
-  PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */
-  PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */
-  PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */
-  PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */
-
-  if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14)
-    ERREXIT(cinfo, JERR_FILE_WRITE);
-  if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t) 12)
-    ERREXIT(cinfo, JERR_FILE_WRITE);
-
-  if (cmap_entries > 0)
-    write_colormap(cinfo, dest, cmap_entries, 3);
-}
-
-
-/*
- * Write the colormap.
- * Windows uses BGR0 map entries; OS/2 uses BGR entries.
- */
-
-LOCAL(void)
-write_colormap (j_decompress_ptr cinfo, bmp_dest_ptr dest,
-               int map_colors, int map_entry_size)
-{
-  JSAMPARRAY colormap = cinfo->colormap;
-  int num_colors = cinfo->actual_number_of_colors;
-  FILE * outfile = dest->pub.output_file;
-  int i;
-
-  if (colormap != NULL) {
-    if (cinfo->out_color_components == 3) {
-      /* Normal case with RGB colormap */
-      for (i = 0; i < num_colors; i++) {
-       putc(GETJSAMPLE(colormap[2][i]), outfile);
-       putc(GETJSAMPLE(colormap[1][i]), outfile);
-       putc(GETJSAMPLE(colormap[0][i]), outfile);
-       if (map_entry_size == 4)
-         putc(0, outfile);
-      }
-    } else {
-      /* Grayscale colormap (only happens with grayscale quantization) */
-      for (i = 0; i < num_colors; i++) {
-       putc(GETJSAMPLE(colormap[0][i]), outfile);
-       putc(GETJSAMPLE(colormap[0][i]), outfile);
-       putc(GETJSAMPLE(colormap[0][i]), outfile);
-       if (map_entry_size == 4)
-         putc(0, outfile);
-      }
-    }
-  } else {
-    /* If no colormap, must be grayscale data.  Generate a linear "map". */
-    for (i = 0; i < 256; i++) {
-      putc(i, outfile);
-      putc(i, outfile);
-      putc(i, outfile);
-      if (map_entry_size == 4)
-       putc(0, outfile);
-    }
-  }
-  /* Pad colormap with zeros to ensure specified number of colormap entries */ 
-  if (i > map_colors)
-    ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i);
-  for (; i < map_colors; i++) {
-    putc(0, outfile);
-    putc(0, outfile);
-    putc(0, outfile);
-    if (map_entry_size == 4)
-      putc(0, outfile);
-  }
-}
-
-
-METHODDEF(void)
-finish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
-{
-  bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;
-  register FILE * outfile = dest->pub.output_file;
-  JSAMPARRAY image_ptr;
-  register JSAMPROW data_ptr;
-  JDIMENSION row;
-  register JDIMENSION col;
-  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
-
-  /* Write the header and colormap */
-  if (dest->is_os2)
-    write_os2_header(cinfo, dest);
-  else
-    write_bmp_header(cinfo, dest);
-
-  /* Write the file body from our virtual array */
-  for (row = cinfo->output_height; row > 0; row--) {
-    if (progress != NULL) {
-      progress->pub.pass_counter = (long) (cinfo->output_height - row);
-      progress->pub.pass_limit = (long) cinfo->output_height;
-      (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
-    }
-    image_ptr = (*cinfo->mem->access_virt_sarray)
-      ((j_common_ptr) cinfo, dest->whole_image, row-1, (JDIMENSION) 1, FALSE);
-    data_ptr = image_ptr[0];
-    for (col = dest->row_width; col > 0; col--) {
-      putc(GETJSAMPLE(*data_ptr), outfile);
-      data_ptr++;
-    }
-  }
-  if (progress != NULL)
-    progress->completed_extra_passes++;
-
-  /* Make sure we wrote the output file OK */
-  fflush(outfile);
-  if (ferror(outfile))
-    ERREXIT(cinfo, JERR_FILE_WRITE);
-}
-
-
-/*
- * The module selection routine for BMP format output.
- */
-
-GLOBAL(djpeg_dest_ptr)
-jinit_write_bmp (j_decompress_ptr cinfo, boolean is_os2)
-{
-  bmp_dest_ptr dest;
-  JDIMENSION row_width;
-
-  /* Create module interface object, fill in method pointers */
-  dest = (bmp_dest_ptr)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                 SIZEOF(bmp_dest_struct));
-  dest->pub.start_output = start_output_bmp;
-  dest->pub.finish_output = finish_output_bmp;
-  dest->is_os2 = is_os2;
-
-  if (cinfo->out_color_space == JCS_GRAYSCALE) {
-    dest->pub.put_pixel_rows = put_gray_rows;
-  } else if (cinfo->out_color_space == JCS_RGB) {
-    if (cinfo->quantize_colors)
-      dest->pub.put_pixel_rows = put_gray_rows;
-    else
-      dest->pub.put_pixel_rows = put_pixel_rows;
-  } else {
-    ERREXIT(cinfo, JERR_BMP_COLORSPACE);
-  }
-
-  /* Calculate output image dimensions so we can allocate space */
-  jpeg_calc_output_dimensions(cinfo);
-
-  /* Determine width of rows in the BMP file (padded to 4-byte boundary). */
-  row_width = cinfo->output_width * cinfo->output_components;
-  dest->data_width = row_width;
-  while ((row_width & 3) != 0) row_width++;
-  dest->row_width = row_width;
-  dest->pad_bytes = (int) (row_width - dest->data_width);
-
-  /* Allocate space for inversion array, prepare for write pass */
-  dest->whole_image = (*cinfo->mem->request_virt_sarray)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
-     row_width, cinfo->output_height, (JDIMENSION) 1);
-  dest->cur_output_row = 0;
-  if (cinfo->progress != NULL) {
-    cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
-    progress->total_extra_passes++; /* count file input as separate pass */
-  }
-
-  /* Create decompressor output buffer. */
-  dest->pub.buffer = (*cinfo->mem->alloc_sarray)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE, row_width, (JDIMENSION) 1);
-  dest->pub.buffer_height = 1;
-
-  return (djpeg_dest_ptr) dest;
-}
-
-#endif /* BMP_SUPPORTED */
diff --git a/src/jpeg/libijg8/wrgif.c b/src/jpeg/libijg8/wrgif.c
deleted file mode 100644 (file)
index 5fe8328..0000000
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * wrgif.c
- *
- * Copyright (C) 1991-1997, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to write output images in GIF format.
- *
- **************************************************************************
- * NOTE: to avoid entanglements with Unisys' patent on LZW compression,   *
- * this code has been modified to output "uncompressed GIF" files.        *
- * There is no trace of the LZW algorithm in this file.                   *
- **************************************************************************
- *
- * These routines may need modification for non-Unix environments or
- * specialized applications.  As they stand, they assume output to
- * an ordinary stdio stream.
- */
-
-/*
- * This code is loosely based on ppmtogif from the PBMPLUS distribution
- * of Feb. 1991.  That file contains the following copyright notice:
- *    Based on GIFENCODE by David Rowley <mgardi@watdscu.waterloo.edu>.
- *    Lempel-Ziv compression based on "compress" by Spencer W. Thomas et al.
- *    Copyright (C) 1989 by Jef Poskanzer.
- *    Permission to use, copy, modify, and distribute this software and its
- *    documentation for any purpose and without fee is hereby granted, provided
- *    that the above copyright notice appear in all copies and that both that
- *    copyright notice and this permission notice appear in supporting
- *    documentation.  This software is provided "as is" without express or
- *    implied warranty.
- *
- * We are also required to state that
- *    "The Graphics Interchange Format(c) is the Copyright property of
- *    CompuServe Incorporated. GIF(sm) is a Service Mark property of
- *    CompuServe Incorporated."
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef GIF_SUPPORTED
-
-
-/* Private version of data destination object */
-
-typedef struct {
-  struct djpeg_dest_struct pub;        /* public fields */
-
-  j_decompress_ptr cinfo;      /* back link saves passing separate parm */
-
-  /* State for packing variable-width codes into a bitstream */
-  int n_bits;                  /* current number of bits/code */
-  int maxcode;                 /* maximum code, given n_bits */
-  INT32 cur_accum;             /* holds bits not yet output */
-  int cur_bits;                        /* # of bits in cur_accum */
-
-  /* State for GIF code assignment */
-  int ClearCode;               /* clear code (doesn't change) */
-  int EOFCode;                 /* EOF code (ditto) */
-  int code_counter;            /* counts output symbols */
-
-  /* GIF data packet construction buffer */
-  int bytesinpkt;              /* # of bytes in current packet */
-  char packetbuf[256];         /* workspace for accumulating packet */
-
-} gif_dest_struct;
-
-typedef gif_dest_struct * gif_dest_ptr;
-
-/* Largest value that will fit in N bits */
-#define MAXCODE(n_bits)        ((1 << (n_bits)) - 1)
-
-
-/*
- * Routines to package finished data bytes into GIF data blocks.
- * A data block consists of a count byte (1..255) and that many data bytes.
- */
-
-LOCAL(void)
-flush_packet (gif_dest_ptr dinfo)
-/* flush any accumulated data */
-{
-  if (dinfo->bytesinpkt > 0) { /* never write zero-length packet */
-    dinfo->packetbuf[0] = (char) dinfo->bytesinpkt++;
-    if (JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt)
-       != (size_t) dinfo->bytesinpkt)
-      ERREXIT(dinfo->cinfo, JERR_FILE_WRITE);
-    dinfo->bytesinpkt = 0;
-  }
-}
-
-
-/* Add a character to current packet; flush to disk if necessary */
-#define CHAR_OUT(dinfo,c)  \
-       { (dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char) (c);  \
-           if ((dinfo)->bytesinpkt >= 255)  \
-             flush_packet(dinfo);  \
-       }
-
-
-/* Routine to convert variable-width codes into a byte stream */
-
-LOCAL(void)
-output (gif_dest_ptr dinfo, int code)
-/* Emit a code of n_bits bits */
-/* Uses cur_accum and cur_bits to reblock into 8-bit bytes */
-{
-  dinfo->cur_accum |= ((INT32) code) << dinfo->cur_bits;
-  dinfo->cur_bits += dinfo->n_bits;
-
-  while (dinfo->cur_bits >= 8) {
-    CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
-    dinfo->cur_accum >>= 8;
-    dinfo->cur_bits -= 8;
-  }
-}
-
-
-/* The pseudo-compression algorithm.
- *
- * In this module we simply output each pixel value as a separate symbol;
- * thus, no compression occurs.  In fact, there is expansion of one bit per
- * pixel, because we use a symbol width one bit wider than the pixel width.
- *
- * GIF ordinarily uses variable-width symbols, and the decoder will expect
- * to ratchet up the symbol width after a fixed number of symbols.
- * To simplify the logic and keep the expansion penalty down, we emit a
- * GIF Clear code to reset the decoder just before the width would ratchet up.
- * Thus, all the symbols in the output file will have the same bit width.
- * Note that emitting the Clear codes at the right times is a mere matter of
- * counting output symbols and is in no way dependent on the LZW patent.
- *
- * With a small basic pixel width (low color count), Clear codes will be
- * needed very frequently, causing the file to expand even more.  So this
- * simplistic approach wouldn't work too well on bilevel images, for example.
- * But for output of JPEG conversions the pixel width will usually be 8 bits
- * (129 to 256 colors), so the overhead added by Clear symbols is only about
- * one symbol in every 256.
- */
-
-LOCAL(void)
-compress_init (gif_dest_ptr dinfo, int i_bits)
-/* Initialize pseudo-compressor */
-{
-  /* init all the state variables */
-  dinfo->n_bits = i_bits;
-  dinfo->maxcode = MAXCODE(dinfo->n_bits);
-  dinfo->ClearCode = (1 << (i_bits - 1));
-  dinfo->EOFCode = dinfo->ClearCode + 1;
-  dinfo->code_counter = dinfo->ClearCode + 2;
-  /* init output buffering vars */
-  dinfo->bytesinpkt = 0;
-  dinfo->cur_accum = 0;
-  dinfo->cur_bits = 0;
-  /* GIF specifies an initial Clear code */
-  output(dinfo, dinfo->ClearCode);
-}
-
-
-LOCAL(void)
-compress_pixel (gif_dest_ptr dinfo, int c)
-/* Accept and "compress" one pixel value.
- * The given value must be less than n_bits wide.
- */
-{
-  /* Output the given pixel value as a symbol. */
-  output(dinfo, c);
-  /* Issue Clear codes often enough to keep the reader from ratcheting up
-   * its symbol size.
-   */
-  if (dinfo->code_counter < dinfo->maxcode) {
-    dinfo->code_counter++;
-  } else {
-    output(dinfo, dinfo->ClearCode);
-    dinfo->code_counter = dinfo->ClearCode + 2;        /* reset the counter */
-  }
-}
-
-
-LOCAL(void)
-compress_term (gif_dest_ptr dinfo)
-/* Clean up at end */
-{
-  /* Send an EOF code */
-  output(dinfo, dinfo->EOFCode);
-  /* Flush the bit-packing buffer */
-  if (dinfo->cur_bits > 0) {
-    CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
-  }
-  /* Flush the packet buffer */
-  flush_packet(dinfo);
-}
-
-
-/* GIF header construction */
-
-
-LOCAL(void)
-put_word (gif_dest_ptr dinfo, unsigned int w)
-/* Emit a 16-bit word, LSB first */
-{
-  putc(w & 0xFF, dinfo->pub.output_file);
-  putc((w >> 8) & 0xFF, dinfo->pub.output_file);
-}
-
-
-LOCAL(void)
-put_3bytes (gif_dest_ptr dinfo, int val)
-/* Emit 3 copies of same byte value --- handy subr for colormap construction */
-{
-  putc(val, dinfo->pub.output_file);
-  putc(val, dinfo->pub.output_file);
-  putc(val, dinfo->pub.output_file);
-}
-
-
-LOCAL(void)
-emit_header (gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap)
-/* Output the GIF file header, including color map */
-/* If colormap==NULL, synthesize a gray-scale colormap */
-{
-  int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte;
-  int cshift = dinfo->cinfo->data_precision - 8;
-  int i;
-
-  if (num_colors > 256)
-    ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors);
-  /* Compute bits/pixel and related values */
-  BitsPerPixel = 1;
-  while (num_colors > (1 << BitsPerPixel))
-    BitsPerPixel++;
-  ColorMapSize = 1 << BitsPerPixel;
-  if (BitsPerPixel <= 1)
-    InitCodeSize = 2;
-  else
-    InitCodeSize = BitsPerPixel;
-  /*
-   * Write the GIF header.
-   * Note that we generate a plain GIF87 header for maximum compatibility.
-   */
-  putc('G', dinfo->pub.output_file);
-  putc('I', dinfo->pub.output_file);
-  putc('F', dinfo->pub.output_file);
-  putc('8', dinfo->pub.output_file);
-  putc('7', dinfo->pub.output_file);
-  putc('a', dinfo->pub.output_file);
-  /* Write the Logical Screen Descriptor */
-  put_word(dinfo, (unsigned int) dinfo->cinfo->output_width);
-  put_word(dinfo, (unsigned int) dinfo->cinfo->output_height);
-  FlagByte = 0x80;             /* Yes, there is a global color table */
-  FlagByte |= (BitsPerPixel-1) << 4; /* color resolution */
-  FlagByte |= (BitsPerPixel-1);        /* size of global color table */
-  putc(FlagByte, dinfo->pub.output_file);
-  putc(0, dinfo->pub.output_file); /* Background color index */
-  putc(0, dinfo->pub.output_file); /* Reserved (aspect ratio in GIF89) */
-  /* Write the Global Color Map */
-  /* If the color map is more than 8 bits precision, */
-  /* we reduce it to 8 bits by shifting */
-  for (i=0; i < ColorMapSize; i++) {
-    if (i < num_colors) {
-      if (colormap != NULL) {
-       if (dinfo->cinfo->out_color_space == JCS_RGB) {
-         /* Normal case: RGB color map */
-         putc(GETJSAMPLE(colormap[0][i]) >> cshift, dinfo->pub.output_file);
-         putc(GETJSAMPLE(colormap[1][i]) >> cshift, dinfo->pub.output_file);
-         putc(GETJSAMPLE(colormap[2][i]) >> cshift, dinfo->pub.output_file);
-       } else {
-         /* Grayscale "color map": possible if quantizing grayscale image */
-         put_3bytes(dinfo, GETJSAMPLE(colormap[0][i]) >> cshift);
-       }
-      } else {
-       /* Create a gray-scale map of num_colors values, range 0..255 */
-       put_3bytes(dinfo, (i * 255 + (num_colors-1)/2) / (num_colors-1));
-      }
-    } else {
-      /* fill out the map to a power of 2 */
-      put_3bytes(dinfo, 0);
-    }
-  }
-  /* Write image separator and Image Descriptor */
-  putc(',', dinfo->pub.output_file); /* separator */
-  put_word(dinfo, 0);          /* left/top offset */
-  put_word(dinfo, 0);
-  put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); /* image size */
-  put_word(dinfo, (unsigned int) dinfo->cinfo->output_height);
-  /* flag byte: not interlaced, no local color map */
-  putc(0x00, dinfo->pub.output_file);
-  /* Write Initial Code Size byte */
-  putc(InitCodeSize, dinfo->pub.output_file);
-
-  /* Initialize for "compression" of image data */
-  compress_init(dinfo, InitCodeSize+1);
-}
-
-
-/*
- * Startup: write the file header.
- */
-
-METHODDEF(void)
-start_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
-{
-  gif_dest_ptr dest = (gif_dest_ptr) dinfo;
-
-  if (cinfo->quantize_colors)
-    emit_header(dest, cinfo->actual_number_of_colors, cinfo->colormap);
-  else
-    emit_header(dest, 256, (JSAMPARRAY) NULL);
-}
-
-
-/*
- * Write some pixel data.
- * In this module rows_supplied will always be 1.
- */
-
-METHODDEF(void)
-put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-               JDIMENSION rows_supplied)
-{
-  gif_dest_ptr dest = (gif_dest_ptr) dinfo;
-  register JSAMPROW ptr;
-  register JDIMENSION col;
-
-  ptr = dest->pub.buffer[0];
-  for (col = cinfo->output_width; col > 0; col--) {
-    compress_pixel(dest, GETJSAMPLE(*ptr++));
-  }
-}
-
-
-/*
- * Finish up at the end of the file.
- */
-
-METHODDEF(void)
-finish_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
-{
-  gif_dest_ptr dest = (gif_dest_ptr) dinfo;
-
-  /* Flush "compression" mechanism */
-  compress_term(dest);
-  /* Write a zero-length data block to end the series */
-  putc(0, dest->pub.output_file);
-  /* Write the GIF terminator mark */
-  putc(';', dest->pub.output_file);
-  /* Make sure we wrote the output file OK */
-  fflush(dest->pub.output_file);
-  if (ferror(dest->pub.output_file))
-    ERREXIT(cinfo, JERR_FILE_WRITE);
-}
-
-
-/*
- * The module selection routine for GIF format output.
- */
-
-GLOBAL(djpeg_dest_ptr)
-jinit_write_gif (j_decompress_ptr cinfo)
-{
-  gif_dest_ptr dest;
-
-  /* Create module interface object, fill in method pointers */
-  dest = (gif_dest_ptr)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                 SIZEOF(gif_dest_struct));
-  dest->cinfo = cinfo;         /* make back link for subroutines */
-  dest->pub.start_output = start_output_gif;
-  dest->pub.put_pixel_rows = put_pixel_rows;
-  dest->pub.finish_output = finish_output_gif;
-
-  if (cinfo->out_color_space != JCS_GRAYSCALE &&
-      cinfo->out_color_space != JCS_RGB)
-    ERREXIT(cinfo, JERR_GIF_COLORSPACE);
-
-  /* Force quantization if color or if > 8 bits input */
-  if (cinfo->out_color_space != JCS_GRAYSCALE || cinfo->data_precision > 8) {
-    /* Force quantization to at most 256 colors */
-    cinfo->quantize_colors = TRUE;
-    if (cinfo->desired_number_of_colors > 256)
-      cinfo->desired_number_of_colors = 256;
-  }
-
-  /* Calculate output image dimensions so we can allocate space */
-  jpeg_calc_output_dimensions(cinfo);
-
-  if (cinfo->output_components != 1) /* safety check: just one component? */
-    ERREXIT(cinfo, JERR_GIF_BUG);
-
-  /* Create decompressor output buffer. */
-  dest->pub.buffer = (*cinfo->mem->alloc_sarray)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE, cinfo->output_width, (JDIMENSION) 1);
-  dest->pub.buffer_height = 1;
-
-  return (djpeg_dest_ptr) dest;
-}
-
-#endif /* GIF_SUPPORTED */
diff --git a/src/jpeg/libijg8/wrppm.c b/src/jpeg/libijg8/wrppm.c
deleted file mode 100644 (file)
index 6c6d908..0000000
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * wrppm.c
- *
- * Copyright (C) 1991-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to write output images in PPM/PGM format.
- * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
- * The PBMPLUS library is NOT required to compile this software
- * (but it is highly useful as a set of PPM image manipulation programs).
- *
- * These routines may need modification for non-Unix environments or
- * specialized applications.  As they stand, they assume output to
- * an ordinary stdio stream.
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef PPM_SUPPORTED
-
-
-/*
- * For 12-bit JPEG data, we either downscale the values to 8 bits
- * (to write standard byte-per-sample PPM/PGM files), or output
- * nonstandard word-per-sample PPM/PGM files.  Downscaling is done
- * if PPM_NORAWWORD is defined (this can be done in the Makefile
- * or in jconfig.h).
- * (When the core library supports data precision reduction, a cleaner
- * implementation will be to ask for that instead.)
- */
-
-#if BITS_IN_JSAMPLE == 8
-#define PUTPPMSAMPLE(ptr,v)  *ptr++ = (char) (v)
-#define BYTESPERSAMPLE 1
-#define PPM_MAXVAL 255
-#else
-#ifdef PPM_NORAWWORD
-#define PUTPPMSAMPLE(ptr,v)  *ptr++ = (char) ((v) >> (BITS_IN_JSAMPLE-8))
-#define BYTESPERSAMPLE 1
-#define PPM_MAXVAL 255
-#else
-/* The word-per-sample format always puts the LSB first. */
-#define PUTPPMSAMPLE(ptr,v)                    \
-       { register int val_ = v;                \
-         *ptr++ = (char) (val_ & 0xFF);        \
-         *ptr++ = (char) ((val_ >> 8) & 0xFF); \
-       }
-#define BYTESPERSAMPLE 2
-#define PPM_MAXVAL ((1<<BITS_IN_JSAMPLE)-1)
-#endif
-#endif
-
-
-/*
- * When JSAMPLE is the same size as char, we can just fwrite() the
- * decompressed data to the PPM or PGM file.  On PCs, in order to make this
- * work the output buffer must be allocated in near data space, because we are
- * assuming small-data memory model wherein fwrite() can't reach far memory.
- * If you need to process very wide images on a PC, you might have to compile
- * in large-memory model, or else replace fwrite() with a putc() loop ---
- * which will be much slower.
- */
-
-
-/* Private version of data destination object */
-
-typedef struct {
-  struct djpeg_dest_struct pub;        /* public fields */
-
-  /* Usually these two pointers point to the same place: */
-  char *iobuffer;              /* fwrite's I/O buffer */
-  JSAMPROW pixrow;             /* decompressor output buffer */
-  size_t buffer_width;         /* width of I/O buffer */
-  JDIMENSION samples_per_row;  /* JSAMPLEs per output row */
-} ppm_dest_struct;
-
-typedef ppm_dest_struct * ppm_dest_ptr;
-
-
-/*
- * Write some pixel data.
- * In this module rows_supplied will always be 1.
- *
- * put_pixel_rows handles the "normal" 8-bit case where the decompressor
- * output buffer is physically the same as the fwrite buffer.
- */
-
-METHODDEF(void)
-put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-               JDIMENSION rows_supplied)
-{
-  ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
-
-  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
-}
-
-
-/*
- * This code is used when we have to copy the data and apply a pixel
- * format translation.  Typically this only happens in 12-bit mode.
- */
-
-METHODDEF(void)
-copy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-                JDIMENSION rows_supplied)
-{
-  ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
-  register char * bufferptr;
-  register JSAMPROW ptr;
-  register JDIMENSION col;
-
-  ptr = dest->pub.buffer[0];
-  bufferptr = dest->iobuffer;
-  for (col = dest->samples_per_row; col > 0; col--) {
-    PUTPPMSAMPLE(bufferptr, GETJSAMPLE(*ptr++));
-  }
-  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
-}
-
-
-/*
- * Write some pixel data when color quantization is in effect.
- * We have to demap the color index values to straight data.
- */
-
-METHODDEF(void)
-put_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-                 JDIMENSION rows_supplied)
-{
-  ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
-  register char * bufferptr;
-  register int pixval;
-  register JSAMPROW ptr;
-  register JSAMPROW color_map0 = cinfo->colormap[0];
-  register JSAMPROW color_map1 = cinfo->colormap[1];
-  register JSAMPROW color_map2 = cinfo->colormap[2];
-  register JDIMENSION col;
-
-  ptr = dest->pub.buffer[0];
-  bufferptr = dest->iobuffer;
-  for (col = cinfo->output_width; col > 0; col--) {
-    pixval = GETJSAMPLE(*ptr++);
-    PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map0[pixval]));
-    PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map1[pixval]));
-    PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map2[pixval]));
-  }
-  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
-}
-
-
-METHODDEF(void)
-put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-                  JDIMENSION rows_supplied)
-{
-  ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
-  register char * bufferptr;
-  register JSAMPROW ptr;
-  register JSAMPROW color_map = cinfo->colormap[0];
-  register JDIMENSION col;
-
-  ptr = dest->pub.buffer[0];
-  bufferptr = dest->iobuffer;
-  for (col = cinfo->output_width; col > 0; col--) {
-    PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map[GETJSAMPLE(*ptr++)]));
-  }
-  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
-}
-
-
-/*
- * Startup: write the file header.
- */
-
-METHODDEF(void)
-start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
-{
-  ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
-
-  /* Emit file header */
-  switch (cinfo->out_color_space) {
-  case JCS_GRAYSCALE:
-    /* emit header for raw PGM format */
-    fprintf(dest->pub.output_file, "P5\n%ld %ld\n%d\n",
-           (long) cinfo->output_width, (long) cinfo->output_height,
-           PPM_MAXVAL);
-    break;
-  case JCS_RGB:
-    /* emit header for raw PPM format */
-    fprintf(dest->pub.output_file, "P6\n%ld %ld\n%d\n",
-           (long) cinfo->output_width, (long) cinfo->output_height,
-           PPM_MAXVAL);
-    break;
-  default:
-    ERREXIT(cinfo, JERR_PPM_COLORSPACE);
-  }
-}
-
-
-/*
- * Finish up at the end of the file.
- */
-
-METHODDEF(void)
-finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
-{
-  /* Make sure we wrote the output file OK */
-  fflush(dinfo->output_file);
-  if (ferror(dinfo->output_file))
-    ERREXIT(cinfo, JERR_FILE_WRITE);
-}
-
-
-/*
- * The module selection routine for PPM format output.
- */
-
-GLOBAL(djpeg_dest_ptr)
-jinit_write_ppm (j_decompress_ptr cinfo)
-{
-  ppm_dest_ptr dest;
-
-  /* Create module interface object, fill in method pointers */
-  dest = (ppm_dest_ptr)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                 SIZEOF(ppm_dest_struct));
-  dest->pub.start_output = start_output_ppm;
-  dest->pub.finish_output = finish_output_ppm;
-
-  /* Calculate output image dimensions so we can allocate space */
-  jpeg_calc_output_dimensions(cinfo);
-
-  /* Create physical I/O buffer.  Note we make this near on a PC. */
-  dest->samples_per_row = cinfo->output_width * cinfo->out_color_components;
-  dest->buffer_width = dest->samples_per_row * (BYTESPERSAMPLE * SIZEOF(char));
-  dest->iobuffer = (char *) (*cinfo->mem->alloc_small)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width);
-
-  if (cinfo->quantize_colors || BITS_IN_JSAMPLE != 8 ||
-      SIZEOF(JSAMPLE) != SIZEOF(char)) {
-    /* When quantizing, we need an output buffer for colormap indexes
-     * that's separate from the physical I/O buffer.  We also need a
-     * separate buffer if pixel format translation must take place.
-     */
-    dest->pub.buffer = (*cinfo->mem->alloc_sarray)
-      ((j_common_ptr) cinfo, JPOOL_IMAGE,
-       cinfo->output_width * cinfo->output_components, (JDIMENSION) 1);
-    dest->pub.buffer_height = 1;
-    if (! cinfo->quantize_colors)
-      dest->pub.put_pixel_rows = copy_pixel_rows;
-    else if (cinfo->out_color_space == JCS_GRAYSCALE)
-      dest->pub.put_pixel_rows = put_demapped_gray;
-    else
-      dest->pub.put_pixel_rows = put_demapped_rgb;
-  } else {
-    /* We will fwrite() directly from decompressor output buffer. */
-    /* Synthesize a JSAMPARRAY pointer structure */
-    /* Cast here implies near->far pointer conversion on PCs */
-    dest->pixrow = (JSAMPROW) dest->iobuffer;
-    dest->pub.buffer = & dest->pixrow;
-    dest->pub.buffer_height = 1;
-    dest->pub.put_pixel_rows = put_pixel_rows;
-  }
-
-  return (djpeg_dest_ptr) dest;
-}
-
-#endif /* PPM_SUPPORTED */
diff --git a/src/jpeg/libijg8/wrrle.c b/src/jpeg/libijg8/wrrle.c
deleted file mode 100644 (file)
index a4e7337..0000000
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * wrrle.c
- *
- * Copyright (C) 1991-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to write output images in RLE format.
- * The Utah Raster Toolkit library is required (version 3.1 or later).
- *
- * These routines may need modification for non-Unix environments or
- * specialized applications.  As they stand, they assume output to
- * an ordinary stdio stream.
- *
- * Based on code contributed by Mike Lijewski,
- * with updates from Robert Hutchinson.
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef RLE_SUPPORTED
-
-/* rle.h is provided by the Utah Raster Toolkit. */
-
-#include <rle.h>
-
-/*
- * We assume that JSAMPLE has the same representation as rle_pixel,
- * to wit, "unsigned char".  Hence we can't cope with 12- or 16-bit samples.
- */
-
-#if BITS_IN_JSAMPLE != 8
-  Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
-#endif
-
-
-/*
- * Since RLE stores scanlines bottom-to-top, we have to invert the image
- * from JPEG's top-to-bottom order.  To do this, we save the outgoing data
- * in a virtual array during put_pixel_row calls, then actually emit the
- * RLE file during finish_output.
- */
-
-
-/*
- * For now, if we emit an RLE color map then it is always 256 entries long,
- * though not all of the entries need be used.
- */
-
-#define CMAPBITS       8
-#define CMAPLENGTH     (1<<(CMAPBITS))
-
-typedef struct {
-  struct djpeg_dest_struct pub; /* public fields */
-
-  jvirt_sarray_ptr image;      /* virtual array to store the output image */
-  rle_map *colormap;           /* RLE-style color map, or NULL if none */
-  rle_pixel **rle_row;         /* To pass rows to rle_putrow() */
-
-} rle_dest_struct;
-
-typedef rle_dest_struct * rle_dest_ptr;
-
-/* Forward declarations */
-METHODDEF(void) rle_put_pixel_rows
-    JPP((j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-        JDIMENSION rows_supplied));
-
-
-/*
- * Write the file header.
- *
- * In this module it's easier to wait till finish_output to write anything.
- */
-
-METHODDEF(void)
-start_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
-{
-  rle_dest_ptr dest = (rle_dest_ptr) dinfo;
-  size_t cmapsize;
-  int i, ci;
-#ifdef PROGRESS_REPORT
-  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
-#endif
-
-  /*
-   * Make sure the image can be stored in RLE format.
-   *
-   * - RLE stores image dimensions as *signed* 16 bit integers.  JPEG
-   *   uses unsigned, so we have to check the width.
-   *
-   * - Colorspace is expected to be grayscale or RGB.
-   *
-   * - The number of channels (components) is expected to be 1 (grayscale/
-   *   pseudocolor) or 3 (truecolor/directcolor).
-   *   (could be 2 or 4 if using an alpha channel, but we aren't)
-   */
-
-  if (cinfo->output_width > 32767 || cinfo->output_height > 32767)
-    ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width, 
-            cinfo->output_height);
-
-  if (cinfo->out_color_space != JCS_GRAYSCALE &&
-      cinfo->out_color_space != JCS_RGB)
-    ERREXIT(cinfo, JERR_RLE_COLORSPACE);
-
-  if (cinfo->output_components != 1 && cinfo->output_components != 3)
-    ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components);
-
-  /* Convert colormap, if any, to RLE format. */
-
-  dest->colormap = NULL;
-
-  if (cinfo->quantize_colors) {
-    /* Allocate storage for RLE-style cmap, zero any extra entries */
-    cmapsize = cinfo->out_color_components * CMAPLENGTH * SIZEOF(rle_map);
-    dest->colormap = (rle_map *) (*cinfo->mem->alloc_small)
-      ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize);
-    MEMZERO(dest->colormap, cmapsize);
-
-    /* Save away data in RLE format --- note 8-bit left shift! */
-    /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */
-    for (ci = 0; ci < cinfo->out_color_components; ci++) {
-      for (i = 0; i < cinfo->actual_number_of_colors; i++) {
-        dest->colormap[ci * CMAPLENGTH + i] =
-          GETJSAMPLE(cinfo->colormap[ci][i]) << 8;
-      }
-    }
-  }
-
-  /* Set the output buffer to the first row */
-  dest->pub.buffer = (*cinfo->mem->access_virt_sarray)
-    ((j_common_ptr) cinfo, dest->image, (JDIMENSION) 0, (JDIMENSION) 1, TRUE);
-  dest->pub.buffer_height = 1;
-
-  dest->pub.put_pixel_rows = rle_put_pixel_rows;
-
-#ifdef PROGRESS_REPORT
-  if (progress != NULL) {
-    progress->total_extra_passes++;  /* count file writing as separate pass */
-  }
-#endif
-}
-
-
-/*
- * Write some pixel data.
- *
- * This routine just saves the data away in a virtual array.
- */
-
-METHODDEF(void)
-rle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-                   JDIMENSION rows_supplied)
-{
-  rle_dest_ptr dest = (rle_dest_ptr) dinfo;
-
-  if (cinfo->output_scanline < cinfo->output_height) {
-    dest->pub.buffer = (*cinfo->mem->access_virt_sarray)
-      ((j_common_ptr) cinfo, dest->image,
-       cinfo->output_scanline, (JDIMENSION) 1, TRUE);
-  }
-}
-
-/*
- * Finish up at the end of the file.
- *
- * Here is where we really output the RLE file.
- */
-
-METHODDEF(void)
-finish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
-{
-  rle_dest_ptr dest = (rle_dest_ptr) dinfo;
-  rle_hdr header;              /* Output file information */
-  rle_pixel **rle_row, *red, *green, *blue;
-  JSAMPROW output_row;
-  char cmapcomment[80];
-  int row, col;
-  int ci;
-#ifdef PROGRESS_REPORT
-  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
-#endif
-
-  /* Initialize the header info */
-  header = *rle_hdr_init(NULL);
-  header.rle_file = dest->pub.output_file;
-  header.xmin     = 0;
-  header.xmax     = cinfo->output_width  - 1;
-  header.ymin     = 0;
-  header.ymax     = cinfo->output_height - 1;
-  header.alpha    = 0;
-  header.ncolors  = cinfo->output_components;
-  for (ci = 0; ci < cinfo->output_components; ci++) {
-    RLE_SET_BIT(header, ci);
-  }
-  if (cinfo->quantize_colors) {
-    header.ncmap   = cinfo->out_color_components;
-    header.cmaplen = CMAPBITS;
-    header.cmap    = dest->colormap;
-    /* Add a comment to the output image with the true colormap length. */
-    sprintf(cmapcomment, "color_map_length=%d", cinfo->actual_number_of_colors);
-    rle_putcom(cmapcomment, &header);
-  }
-
-  /* Emit the RLE header and color map (if any) */
-  rle_put_setup(&header);
-
-  /* Now output the RLE data from our virtual array.
-   * We assume here that (a) rle_pixel is represented the same as JSAMPLE,
-   * and (b) we are not on a machine where FAR pointers differ from regular.
-   */
-
-#ifdef PROGRESS_REPORT
-  if (progress != NULL) {
-    progress->pub.pass_limit = cinfo->output_height;
-    progress->pub.pass_counter = 0;
-    (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
-  }
-#endif
-
-  if (cinfo->output_components == 1) {
-    for (row = cinfo->output_height-1; row >= 0; row--) {
-      rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)
-        ((j_common_ptr) cinfo, dest->image,
-        (JDIMENSION) row, (JDIMENSION) 1, FALSE);
-      rle_putrow(rle_row, (int) cinfo->output_width, &header);
-#ifdef PROGRESS_REPORT
-      if (progress != NULL) {
-        progress->pub.pass_counter++;
-        (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
-      }
-#endif
-    }
-  } else {
-    for (row = cinfo->output_height-1; row >= 0; row--) {
-      rle_row = (rle_pixel **) dest->rle_row;
-      output_row = * (*cinfo->mem->access_virt_sarray)
-        ((j_common_ptr) cinfo, dest->image,
-        (JDIMENSION) row, (JDIMENSION) 1, FALSE);
-      red = rle_row[0];
-      green = rle_row[1];
-      blue = rle_row[2];
-      for (col = cinfo->output_width; col > 0; col--) {
-        *red++ = GETJSAMPLE(*output_row++);
-        *green++ = GETJSAMPLE(*output_row++);
-        *blue++ = GETJSAMPLE(*output_row++);
-      }
-      rle_putrow(rle_row, (int) cinfo->output_width, &header);
-#ifdef PROGRESS_REPORT
-      if (progress != NULL) {
-        progress->pub.pass_counter++;
-        (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
-      }
-#endif
-    }
-  }
-
-#ifdef PROGRESS_REPORT
-  if (progress != NULL)
-    progress->completed_extra_passes++;
-#endif
-
-  /* Emit file trailer */
-  rle_puteof(&header);
-  fflush(dest->pub.output_file);
-  if (ferror(dest->pub.output_file))
-    ERREXIT(cinfo, JERR_FILE_WRITE);
-}
-
-
-/*
- * The module selection routine for RLE format output.
- */
-
-GLOBAL(djpeg_dest_ptr)
-jinit_write_rle (j_decompress_ptr cinfo)
-{
-  rle_dest_ptr dest;
-
-  /* Create module interface object, fill in method pointers */
-  dest = (rle_dest_ptr)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                  SIZEOF(rle_dest_struct));
-  dest->pub.start_output = start_output_rle;
-  dest->pub.finish_output = finish_output_rle;
-
-  /* Calculate output image dimensions so we can allocate space */
-  jpeg_calc_output_dimensions(cinfo);
-
-  /* Allocate a work array for output to the RLE library. */
-  dest->rle_row = (*cinfo->mem->alloc_sarray)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE,
-     cinfo->output_width, (JDIMENSION) cinfo->output_components);
-
-  /* Allocate a virtual array to hold the image. */
-  dest->image = (*cinfo->mem->request_virt_sarray)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
-     (JDIMENSION) (cinfo->output_width * cinfo->output_components),
-     cinfo->output_height, (JDIMENSION) 1);
-
-  return (djpeg_dest_ptr) dest;
-}
-
-#endif /* RLE_SUPPORTED */
diff --git a/src/jpeg/libijg8/wrtarga.c b/src/jpeg/libijg8/wrtarga.c
deleted file mode 100644 (file)
index cf104d2..0000000
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * wrtarga.c
- *
- * Copyright (C) 1991-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains routines to write output images in Targa format.
- *
- * These routines may need modification for non-Unix environments or
- * specialized applications.  As they stand, they assume output to
- * an ordinary stdio stream.
- *
- * Based on code contributed by Lee Daniel Crocker.
- */
-
-#include "cdjpeg.h"            /* Common decls for cjpeg/djpeg applications */
-
-#ifdef TARGA_SUPPORTED
-
-
-/*
- * To support 12-bit JPEG data, we'd have to scale output down to 8 bits.
- * This is not yet implemented.
- */
-
-#if BITS_IN_JSAMPLE != 8
-  Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
-#endif
-
-/*
- * The output buffer needs to be writable by fwrite().  On PCs, we must
- * allocate the buffer in near data space, because we are assuming small-data
- * memory model, wherein fwrite() can't reach far memory.  If you need to
- * process very wide images on a PC, you might have to compile in large-memory
- * model, or else replace fwrite() with a putc() loop --- which will be much
- * slower.
- */
-
-
-/* Private version of data destination object */
-
-typedef struct {
-  struct djpeg_dest_struct pub;        /* public fields */
-
-  char *iobuffer;              /* physical I/O buffer */
-  JDIMENSION buffer_width;     /* width of one row */
-} tga_dest_struct;
-
-typedef tga_dest_struct * tga_dest_ptr;
-
-
-LOCAL(void)
-write_header (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, int num_colors)
-/* Create and write a Targa header */
-{
-  char targaheader[18];
-
-  /* Set unused fields of header to 0 */
-  MEMZERO(targaheader, SIZEOF(targaheader));
-
-  if (num_colors > 0) {
-    targaheader[1] = 1;                /* color map type 1 */
-    targaheader[5] = (char) (num_colors & 0xFF);
-    targaheader[6] = (char) (num_colors >> 8);
-    targaheader[7] = 24;       /* 24 bits per cmap entry */
-  }
-
-  targaheader[12] = (char) (cinfo->output_width & 0xFF);
-  targaheader[13] = (char) (cinfo->output_width >> 8);
-  targaheader[14] = (char) (cinfo->output_height & 0xFF);
-  targaheader[15] = (char) (cinfo->output_height >> 8);
-  targaheader[17] = 0x20;      /* Top-down, non-interlaced */
-
-  if (cinfo->out_color_space == JCS_GRAYSCALE) {
-    targaheader[2] = 3;                /* image type = uncompressed gray-scale */
-    targaheader[16] = 8;       /* bits per pixel */
-  } else {                     /* must be RGB */
-    if (num_colors > 0) {
-      targaheader[2] = 1;      /* image type = colormapped RGB */
-      targaheader[16] = 8;
-    } else {
-      targaheader[2] = 2;      /* image type = uncompressed RGB */
-      targaheader[16] = 24;
-    }
-  }
-
-  if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t) 18)
-    ERREXIT(cinfo, JERR_FILE_WRITE);
-}
-
-
-/*
- * Write some pixel data.
- * In this module rows_supplied will always be 1.
- */
-
-METHODDEF(void)
-put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-               JDIMENSION rows_supplied)
-/* used for unquantized full-color output */
-{
-  tga_dest_ptr dest = (tga_dest_ptr) dinfo;
-  register JSAMPROW inptr;
-  register char * outptr;
-  register JDIMENSION col;
-
-  inptr = dest->pub.buffer[0];
-  outptr = dest->iobuffer;
-  for (col = cinfo->output_width; col > 0; col--) {
-    outptr[0] = (char) GETJSAMPLE(inptr[2]); /* RGB to BGR order */
-    outptr[1] = (char) GETJSAMPLE(inptr[1]);
-    outptr[2] = (char) GETJSAMPLE(inptr[0]);
-    inptr += 3, outptr += 3;
-  }
-  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
-}
-
-METHODDEF(void)
-put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-              JDIMENSION rows_supplied)
-/* used for grayscale OR quantized color output */
-{
-  tga_dest_ptr dest = (tga_dest_ptr) dinfo;
-  register JSAMPROW inptr;
-  register char * outptr;
-  register JDIMENSION col;
-
-  inptr = dest->pub.buffer[0];
-  outptr = dest->iobuffer;
-  for (col = cinfo->output_width; col > 0; col--) {
-    *outptr++ = (char) GETJSAMPLE(*inptr++);
-  }
-  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
-}
-
-
-/*
- * Write some demapped pixel data when color quantization is in effect.
- * For Targa, this is only applied to grayscale data.
- */
-
-METHODDEF(void)
-put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
-                  JDIMENSION rows_supplied)
-{
-  tga_dest_ptr dest = (tga_dest_ptr) dinfo;
-  register JSAMPROW inptr;
-  register char * outptr;
-  register JSAMPROW color_map0 = cinfo->colormap[0];
-  register JDIMENSION col;
-
-  inptr = dest->pub.buffer[0];
-  outptr = dest->iobuffer;
-  for (col = cinfo->output_width; col > 0; col--) {
-    *outptr++ = (char) GETJSAMPLE(color_map0[GETJSAMPLE(*inptr++)]);
-  }
-  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
-}
-
-
-/*
- * Startup: write the file header.
- */
-
-METHODDEF(void)
-start_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
-{
-  tga_dest_ptr dest = (tga_dest_ptr) dinfo;
-  int num_colors, i;
-  FILE *outfile;
-
-  if (cinfo->out_color_space == JCS_GRAYSCALE) {
-    /* Targa doesn't have a mapped grayscale format, so we will */
-    /* demap quantized gray output.  Never emit a colormap. */
-    write_header(cinfo, dinfo, 0);
-    if (cinfo->quantize_colors)
-      dest->pub.put_pixel_rows = put_demapped_gray;
-    else
-      dest->pub.put_pixel_rows = put_gray_rows;
-  } else if (cinfo->out_color_space == JCS_RGB) {
-    if (cinfo->quantize_colors) {
-      /* We only support 8-bit colormap indexes, so only 256 colors */
-      num_colors = cinfo->actual_number_of_colors;
-      if (num_colors > 256)
-       ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, num_colors);
-      write_header(cinfo, dinfo, num_colors);
-      /* Write the colormap.  Note Targa uses BGR byte order */
-      outfile = dest->pub.output_file;
-      for (i = 0; i < num_colors; i++) {
-       putc(GETJSAMPLE(cinfo->colormap[2][i]), outfile);
-       putc(GETJSAMPLE(cinfo->colormap[1][i]), outfile);
-       putc(GETJSAMPLE(cinfo->colormap[0][i]), outfile);
-      }
-      dest->pub.put_pixel_rows = put_gray_rows;
-    } else {
-      write_header(cinfo, dinfo, 0);
-      dest->pub.put_pixel_rows = put_pixel_rows;
-    }
-  } else {
-    ERREXIT(cinfo, JERR_TGA_COLORSPACE);
-  }
-}
-
-
-/*
- * Finish up at the end of the file.
- */
-
-METHODDEF(void)
-finish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
-{
-  /* Make sure we wrote the output file OK */
-  fflush(dinfo->output_file);
-  if (ferror(dinfo->output_file))
-    ERREXIT(cinfo, JERR_FILE_WRITE);
-}
-
-
-/*
- * The module selection routine for Targa format output.
- */
-
-GLOBAL(djpeg_dest_ptr)
-jinit_write_targa (j_decompress_ptr cinfo)
-{
-  tga_dest_ptr dest;
-
-  /* Create module interface object, fill in method pointers */
-  dest = (tga_dest_ptr)
-      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                                 SIZEOF(tga_dest_struct));
-  dest->pub.start_output = start_output_tga;
-  dest->pub.finish_output = finish_output_tga;
-
-  /* Calculate output image dimensions so we can allocate space */
-  jpeg_calc_output_dimensions(cinfo);
-
-  /* Create I/O buffer.  Note we make this near on a PC. */
-  dest->buffer_width = cinfo->output_width * cinfo->output_components;
-  dest->iobuffer = (char *)
-    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                               (size_t) (dest->buffer_width * SIZEOF(char)));
-
-  /* Create decompressor output buffer. */
-  dest->pub.buffer = (*cinfo->mem->alloc_sarray)
-    ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width, (JDIMENSION) 1);
-  dest->pub.buffer_height = 1;
-
-  return (djpeg_dest_ptr) dest;
-}
-
-#endif /* TARGA_SUPPORTED */