Convert tabs to spaces in the libjpeg code and the SIMD code (TurboJPEG retains the use of tabs for historical reasons. They were annoying in the libjpeg code primarily because they were not consistently used and because they were used to format as well as indent the code. In the case of TurboJPEG, tabs are used just to indent the code, so even if the editor assumes a different tab width, the code will still be readable.)

git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/branches/1.3.x@1285 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
DRC
2014-05-11 09:36:25 +00:00
parent 393bac6de4
commit b775351012
164 changed files with 22475 additions and 22475 deletions

2
bmp.c
View File

@@ -98,7 +98,7 @@ static void pixelconvert(unsigned char *srcbuf, int srcpf, int srcbottomup,
} }
int loadbmp(char *filename, unsigned char **buf, int *w, int *h, int loadbmp(char *filename, unsigned char **buf, int *w, int *h,
int dstpf, int bottomup) int dstpf, int bottomup)
{ {
int retval=0, dstps, srcpf, tempc; int retval=0, dstps, srcpf, tempc;

View File

@@ -33,7 +33,7 @@
typedef enum { typedef enum {
#define JMESSAGE(code,string) code , #define JMESSAGE(code,string) code ,
#endif /* JMAKE_ENUM_LIST */ #endif /* JMAKE_ENUM_LIST */
@@ -62,7 +62,7 @@ JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
JMESSAGE(JERR_GIF_NOT, "Not a GIF file") JMESSAGE(JERR_GIF_NOT, "Not a GIF file")
JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image") JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")
JMESSAGE(JTRC_GIF_BADVERSION, JMESSAGE(JTRC_GIF_BADVERSION,
"Warning: unexpected GIF version number '%c%c%c'") "Warning: unexpected GIF version number '%c%c%c'")
JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x") JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x")
JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input") JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input")
JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file") JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file")
@@ -110,13 +110,13 @@ JMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled")
#endif /* TARGA_SUPPORTED */ #endif /* TARGA_SUPPORTED */
JMESSAGE(JERR_BAD_CMAP_FILE, JMESSAGE(JERR_BAD_CMAP_FILE,
"Color map file is invalid or of unsupported format") "Color map file is invalid or of unsupported format")
JMESSAGE(JERR_TOO_MANY_COLORS, JMESSAGE(JERR_TOO_MANY_COLORS,
"Output file format cannot handle %d colormap entries") "Output file format cannot handle %d colormap entries")
JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed") JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed")
#ifdef TARGA_SUPPORTED #ifdef TARGA_SUPPORTED
JMESSAGE(JERR_UNKNOWN_FORMAT, JMESSAGE(JERR_UNKNOWN_FORMAT,
"Unrecognized input file format --- perhaps you need -targa") "Unrecognized input file format --- perhaps you need -targa")
#else #else
JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format") JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format")
#endif #endif

View File

@@ -9,15 +9,15 @@
* programs (cjpeg, djpeg, jpegtran). * programs (cjpeg, djpeg, jpegtran).
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include <ctype.h> /* to declare isupper(), tolower() */ #include <ctype.h> /* to declare isupper(), tolower() */
#ifdef NEED_SIGNAL_CATCHER #ifdef NEED_SIGNAL_CATCHER
#include <signal.h> /* to declare signal() */ #include <signal.h> /* to declare signal() */
#endif #endif
#ifdef USE_SETMODE #ifdef USE_SETMODE
#include <fcntl.h> /* to declare setmode()'s parameter macros */ #include <fcntl.h> /* to declare setmode()'s parameter macros */
/* If you have setmode() but not <io.h>, just delete this line: */ /* If you have setmode() but not <io.h>, just delete this line: */
#include <io.h> /* to declare setmode() */ #include <io.h> /* to declare setmode() */
#endif #endif
@@ -31,13 +31,13 @@
static j_common_ptr sig_cinfo; static j_common_ptr sig_cinfo;
void /* must be global for Manx C */ void /* must be global for Manx C */
signal_catcher (int signum) signal_catcher (int signum)
{ {
if (sig_cinfo != NULL) { if (sig_cinfo != NULL) {
if (sig_cinfo->err != NULL) /* turn off trace output */ if (sig_cinfo->err != NULL) /* turn off trace output */
sig_cinfo->err->trace_level = 0; sig_cinfo->err->trace_level = 0;
jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */ jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */
} }
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@@ -47,10 +47,10 @@ GLOBAL(void)
enable_signal_catcher (j_common_ptr cinfo) enable_signal_catcher (j_common_ptr cinfo)
{ {
sig_cinfo = cinfo; sig_cinfo = cinfo;
#ifdef SIGINT /* not all systems have SIGINT */ #ifdef SIGINT /* not all systems have SIGINT */
signal(SIGINT, signal_catcher); signal(SIGINT, signal_catcher);
#endif #endif
#ifdef SIGTERM /* not all systems have SIGTERM */ #ifdef SIGTERM /* not all systems have SIGTERM */
signal(SIGTERM, signal_catcher); signal(SIGTERM, signal_catcher);
#endif #endif
} }
@@ -75,8 +75,8 @@ progress_monitor (j_common_ptr cinfo)
prog->percent_done = percent_done; prog->percent_done = percent_done;
if (total_passes > 1) { if (total_passes > 1) {
fprintf(stderr, "\rPass %d/%d: %3d%% ", fprintf(stderr, "\rPass %d/%d: %3d%% ",
prog->pub.completed_passes + prog->completed_extra_passes + 1, prog->pub.completed_passes + prog->completed_extra_passes + 1,
total_passes, percent_done); total_passes, percent_done);
} else { } else {
fprintf(stderr, "\r %3d%% ", percent_done); fprintf(stderr, "\r %3d%% ", percent_done);
} }
@@ -126,17 +126,17 @@ keymatch (char * arg, const char * keyword, int minchars)
while ((ca = *arg++) != '\0') { while ((ca = *arg++) != '\0') {
if ((ck = *keyword++) == '\0') if ((ck = *keyword++) == '\0')
return FALSE; /* arg longer than keyword, no good */ return FALSE; /* arg longer than keyword, no good */
if (isupper(ca)) /* force arg to lcase (assume ck is already) */ if (isupper(ca)) /* force arg to lcase (assume ck is already) */
ca = tolower(ca); ca = tolower(ca);
if (ca != ck) if (ca != ck)
return FALSE; /* no good */ return FALSE; /* no good */
nmatched++; /* count matched characters */ nmatched++; /* count matched characters */
} }
/* reached end of argument; fail if it's too short for unique abbrev */ /* reached end of argument; fail if it's too short for unique abbrev */
if (nmatched < minchars) if (nmatched < minchars)
return FALSE; return FALSE;
return TRUE; /* A-OK */ return TRUE; /* A-OK */
} }
@@ -150,10 +150,10 @@ read_stdin (void)
{ {
FILE * input_file = stdin; FILE * input_file = stdin;
#ifdef USE_SETMODE /* need to hack file mode? */ #ifdef USE_SETMODE /* need to hack file mode? */
setmode(fileno(stdin), O_BINARY); setmode(fileno(stdin), O_BINARY);
#endif #endif
#ifdef USE_FDOPEN /* need to re-open in binary mode? */ #ifdef USE_FDOPEN /* need to re-open in binary mode? */
if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) { if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
fprintf(stderr, "Cannot reopen stdin\n"); fprintf(stderr, "Cannot reopen stdin\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@@ -168,10 +168,10 @@ write_stdout (void)
{ {
FILE * output_file = stdout; FILE * output_file = stdout;
#ifdef USE_SETMODE /* need to hack file mode? */ #ifdef USE_SETMODE /* need to hack file mode? */
setmode(fileno(stdout), O_BINARY); setmode(fileno(stdout), O_BINARY);
#endif #endif
#ifdef USE_FDOPEN /* need to re-open in binary mode? */ #ifdef USE_FDOPEN /* need to re-open in binary mode? */
if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) { if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
fprintf(stderr, "Cannot reopen stdout\n"); fprintf(stderr, "Cannot reopen stdout\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

100
cdjpeg.h
View File

@@ -9,12 +9,12 @@
* cjpeg and djpeg. It is NOT used by the core JPEG library. * cjpeg and djpeg. It is NOT used by the core JPEG library.
*/ */
#define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */ #define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
#define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */ #define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jerror.h" /* get library error codes too */ #include "jerror.h" /* get library error codes too */
#include "cderror.h" /* get application-specific error codes */ #include "cderror.h" /* get application-specific error codes */
/* /*
@@ -25,11 +25,11 @@ typedef struct cjpeg_source_struct * cjpeg_source_ptr;
struct cjpeg_source_struct { struct cjpeg_source_struct {
JMETHOD(void, start_input, (j_compress_ptr cinfo, JMETHOD(void, start_input, (j_compress_ptr cinfo,
cjpeg_source_ptr sinfo)); cjpeg_source_ptr sinfo));
JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
cjpeg_source_ptr sinfo)); cjpeg_source_ptr sinfo));
JMETHOD(void, finish_input, (j_compress_ptr cinfo, JMETHOD(void, finish_input, (j_compress_ptr cinfo,
cjpeg_source_ptr sinfo)); cjpeg_source_ptr sinfo));
FILE *input_file; FILE *input_file;
@@ -49,14 +49,14 @@ struct djpeg_dest_struct {
* The color map will be ready at this time, if one is needed. * The color map will be ready at this time, if one is needed.
*/ */
JMETHOD(void, start_output, (j_decompress_ptr cinfo, JMETHOD(void, start_output, (j_decompress_ptr cinfo,
djpeg_dest_ptr dinfo)); djpeg_dest_ptr dinfo));
/* Emit the specified number of pixel rows from the buffer. */ /* Emit the specified number of pixel rows from the buffer. */
JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo, JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo,
djpeg_dest_ptr dinfo, djpeg_dest_ptr dinfo,
JDIMENSION rows_supplied)); JDIMENSION rows_supplied));
/* Finish up at the end of the image. */ /* Finish up at the end of the image. */
JMETHOD(void, finish_output, (j_decompress_ptr cinfo, JMETHOD(void, finish_output, (j_decompress_ptr cinfo,
djpeg_dest_ptr dinfo)); djpeg_dest_ptr dinfo));
/* Target file spec; filled in by djpeg.c after object is created. */ /* Target file spec; filled in by djpeg.c after object is created. */
FILE * output_file; FILE * output_file;
@@ -79,9 +79,9 @@ struct djpeg_dest_struct {
*/ */
struct cdjpeg_progress_mgr { struct cdjpeg_progress_mgr {
struct jpeg_progress_mgr pub; /* fields known to JPEG library */ struct jpeg_progress_mgr pub; /* fields known to JPEG library */
int completed_extra_passes; /* extra passes completed */ int completed_extra_passes; /* extra passes completed */
int total_extra_passes; /* total extra */ int total_extra_passes; /* total extra */
/* last printed percentage stored here to avoid multiple printouts */ /* last printed percentage stored here to avoid multiple printouts */
int percent_done; int percent_done;
}; };
@@ -92,34 +92,34 @@ typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
/* Short forms of external names for systems with brain-damaged linkers. */ /* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES #ifdef NEED_SHORT_EXTERNAL_NAMES
#define jinit_read_bmp jIRdBMP #define jinit_read_bmp jIRdBMP
#define jinit_write_bmp jIWrBMP #define jinit_write_bmp jIWrBMP
#define jinit_read_gif jIRdGIF #define jinit_read_gif jIRdGIF
#define jinit_write_gif jIWrGIF #define jinit_write_gif jIWrGIF
#define jinit_read_ppm jIRdPPM #define jinit_read_ppm jIRdPPM
#define jinit_write_ppm jIWrPPM #define jinit_write_ppm jIWrPPM
#define jinit_read_rle jIRdRLE #define jinit_read_rle jIRdRLE
#define jinit_write_rle jIWrRLE #define jinit_write_rle jIWrRLE
#define jinit_read_targa jIRdTarga #define jinit_read_targa jIRdTarga
#define jinit_write_targa jIWrTarga #define jinit_write_targa jIWrTarga
#define read_quant_tables RdQTables #define read_quant_tables RdQTables
#define read_scan_script RdScnScript #define read_scan_script RdScnScript
#define set_quality_ratings SetQRates #define set_quality_ratings SetQRates
#define set_quant_slots SetQSlots #define set_quant_slots SetQSlots
#define set_sample_factors SetSFacts #define set_sample_factors SetSFacts
#define read_color_map RdCMap #define read_color_map RdCMap
#define enable_signal_catcher EnSigCatcher #define enable_signal_catcher EnSigCatcher
#define start_progress_monitor StProgMon #define start_progress_monitor StProgMon
#define end_progress_monitor EnProgMon #define end_progress_monitor EnProgMon
#define read_stdin RdStdin #define read_stdin RdStdin
#define write_stdout WrStdout #define write_stdout WrStdout
#endif /* NEED_SHORT_EXTERNAL_NAMES */ #endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Module selection routines for I/O modules. */ /* Module selection routines for I/O modules. */
EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo)); EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo));
EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo, EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
boolean is_os2)); boolean is_os2));
EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo)); 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(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo));
EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo)); EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
@@ -132,10 +132,10 @@ EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));
/* cjpeg support routines (in rdswitch.c) */ /* cjpeg support routines (in rdswitch.c) */
EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename, EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
boolean force_baseline)); boolean force_baseline));
EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename)); EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename));
EXTERN(boolean) set_quality_ratings JPP((j_compress_ptr cinfo, char *arg, EXTERN(boolean) set_quality_ratings JPP((j_compress_ptr cinfo, char *arg,
boolean force_baseline)); boolean force_baseline));
EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg)); EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg)); EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
@@ -147,7 +147,7 @@ EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo)); EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo));
EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo, EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo,
cd_progress_ptr progress)); cd_progress_ptr progress));
EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo)); EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo));
EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars)); EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars));
EXTERN(FILE *) read_stdin JPP((void)); EXTERN(FILE *) read_stdin JPP((void));
@@ -155,32 +155,32 @@ EXTERN(FILE *) write_stdout JPP((void));
/* miscellaneous useful macros */ /* miscellaneous useful macros */
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
#define READ_BINARY "r" #define READ_BINARY "r"
#define WRITE_BINARY "w" #define WRITE_BINARY "w"
#else #else
#ifdef VMS /* VMS is very nonstandard */ #ifdef VMS /* VMS is very nonstandard */
#define READ_BINARY "rb", "ctx=stm" #define READ_BINARY "rb", "ctx=stm"
#define WRITE_BINARY "wb", "ctx=stm" #define WRITE_BINARY "wb", "ctx=stm"
#else /* standard ANSI-compliant case */ #else /* standard ANSI-compliant case */
#define READ_BINARY "rb" #define READ_BINARY "rb"
#define WRITE_BINARY "wb" #define WRITE_BINARY "wb"
#endif #endif
#endif #endif
#ifndef EXIT_FAILURE /* define exit() codes if not provided */ #ifndef EXIT_FAILURE /* define exit() codes if not provided */
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#endif #endif
#ifndef EXIT_SUCCESS #ifndef EXIT_SUCCESS
#ifdef VMS #ifdef VMS
#define EXIT_SUCCESS 1 /* VMS is very nonstandard */ #define EXIT_SUCCESS 1 /* VMS is very nonstandard */
#else #else
#define EXIT_SUCCESS 0 #define EXIT_SUCCESS 0
#endif #endif
#endif #endif
#ifndef EXIT_WARNING #ifndef EXIT_WARNING
#ifdef VMS #ifdef VMS
#define EXIT_WARNING 1 /* VMS is very nonstandard */ #define EXIT_WARNING 1 /* VMS is very nonstandard */
#else #else
#define EXIT_WARNING 2 #define EXIT_WARNING 2
#endif #endif

174
cjpeg.c
View File

@@ -13,8 +13,8 @@
* *
* Two different command line styles are permitted, depending on the * Two different command line styles are permitted, depending on the
* compile-time switch TWO_FILE_COMMANDLINE: * compile-time switch TWO_FILE_COMMANDLINE:
* cjpeg [options] inputfile outputfile * cjpeg [options] inputfile outputfile
* cjpeg [options] [inputfile] * cjpeg [options] [inputfile]
* In the second style, output is always to standard output, which you'd * In the second style, output is always to standard output, which you'd
* normally redirect to a file or pipe to some other program. Input is * normally redirect to a file or pipe to some other program. Input is
* either from a named file or from standard input (typically redirected). * either from a named file or from standard input (typically redirected).
@@ -22,28 +22,28 @@
* don't support pipes. Also, you MUST use the first style if your system * don't support pipes. Also, you MUST use the first style if your system
* doesn't do binary I/O to stdin/stdout. * doesn't do binary I/O to stdin/stdout.
* To simplify script writing, the "-outfile" switch is provided. The syntax * To simplify script writing, the "-outfile" switch is provided. The syntax
* cjpeg [options] -outfile outputfile inputfile * cjpeg [options] -outfile outputfile inputfile
* works regardless of which command line style is used. * works regardless of which command line style is used.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "jversion.h" /* for version message */ #include "jversion.h" /* for version message */
#include "jconfigint.h" #include "jconfigint.h"
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__ #ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */ #include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */ #include <console.h> /* ... and this */
#endif #endif
#ifdef THINK_C #ifdef THINK_C
#include <console.h> /* Think declares it here */ #include <console.h> /* Think declares it here */
#endif #endif
#endif #endif
/* Create the add-on message string table. */ /* Create the add-on message string table. */
#define JMESSAGE(code,string) string , #define JMESSAGE(code,string) string ,
static const char * const cdjpeg_message_table[] = { static const char * const cdjpeg_message_table[] = {
#include "cderror.h" #include "cderror.h"
@@ -77,7 +77,7 @@ static const char * const cdjpeg_message_table[] = {
* seldom-used ID field), so we provide a switch to force Targa input mode. * seldom-used ID field), so we provide a switch to force Targa input mode.
*/ */
static boolean is_targa; /* records user -targa switch */ static boolean is_targa; /* records user -targa switch */
LOCAL(cjpeg_source_ptr) LOCAL(cjpeg_source_ptr)
@@ -124,7 +124,7 @@ select_file_type (j_compress_ptr cinfo, FILE * infile)
break; break;
} }
return NULL; /* suppress compiler warnings */ return NULL; /* suppress compiler warnings */
} }
@@ -137,8 +137,8 @@ select_file_type (j_compress_ptr cinfo, FILE * infile)
*/ */
static const char * progname; /* program name for error messages */ static const char * progname; /* program name for error messages */
static char * outfilename; /* for -outfile switch */ static char * outfilename; /* for -outfile switch */
boolean memdst; /* for -memdst switch */ boolean memdst; /* for -memdst switch */
@@ -172,15 +172,15 @@ usage (void)
#endif #endif
#ifdef DCT_ISLOW_SUPPORTED #ifdef DCT_ISLOW_SUPPORTED
fprintf(stderr, " -dct int Use integer DCT method%s\n", fprintf(stderr, " -dct int Use integer DCT method%s\n",
(JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
#endif #endif
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
(JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
#endif #endif
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
fprintf(stderr, " -dct float Use floating-point DCT method%s\n", fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
(JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
#endif #endif
fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
#ifdef INPUT_SMOOTHING_SUPPORTED #ifdef INPUT_SMOOTHING_SUPPORTED
@@ -206,7 +206,7 @@ usage (void)
LOCAL(int) LOCAL(int)
parse_switches (j_compress_ptr cinfo, int argc, char **argv, parse_switches (j_compress_ptr cinfo, int argc, char **argv,
int last_file_arg_seen, boolean for_real) int last_file_arg_seen, boolean for_real)
/* Parse optional switches. /* Parse optional switches.
* Returns argv[] index of first file-name argument (== argc if none). * Returns argv[] index of first file-name argument (== argc if none).
* Any file names with indexes <= last_file_arg_seen are ignored; * Any file names with indexes <= last_file_arg_seen are ignored;
@@ -220,15 +220,15 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
char * arg; char * arg;
boolean force_baseline; boolean force_baseline;
boolean simple_progressive; boolean simple_progressive;
char * qualityarg = NULL; /* saves -quality parm if any */ char * qualityarg = NULL; /* saves -quality parm if any */
char * qtablefile = NULL; /* saves -qtables filename if any */ char * qtablefile = NULL; /* saves -qtables filename if any */
char * qslotsarg = NULL; /* saves -qslots parm if any */ char * qslotsarg = NULL; /* saves -qslots parm if any */
char * samplearg = NULL; /* saves -sample parm if any */ char * samplearg = NULL; /* saves -sample parm if any */
char * scansarg = NULL; /* saves -scans parm if any */ char * scansarg = NULL; /* saves -scans parm if any */
/* Set up default JPEG parameters. */ /* Set up default JPEG parameters. */
force_baseline = FALSE; /* by default, allow 16-bit quantizers */ force_baseline = FALSE; /* by default, allow 16-bit quantizers */
simple_progressive = FALSE; simple_progressive = FALSE;
is_targa = FALSE; is_targa = FALSE;
outfilename = NULL; outfilename = NULL;
@@ -242,12 +242,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
if (*arg != '-') { if (*arg != '-') {
/* Not a switch, must be a file name argument */ /* Not a switch, must be a file name argument */
if (argn <= last_file_arg_seen) { if (argn <= last_file_arg_seen) {
outfilename = NULL; /* -outfile applies to just one input file */ outfilename = NULL; /* -outfile applies to just one input file */
continue; /* ignore this name if previously processed */ continue; /* ignore this name if previously processed */
} }
break; /* else done parsing switches */ break; /* else done parsing switches */
} }
arg++; /* advance past switch marker character */ arg++; /* advance past switch marker character */
if (keymatch(arg, "arithmetic", 1)) { if (keymatch(arg, "arithmetic", 1)) {
/* Use arithmetic coding. */ /* Use arithmetic coding. */
@@ -255,7 +255,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
cinfo->arith_code = TRUE; cinfo->arith_code = TRUE;
#else #else
fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -265,16 +265,16 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "dct", 2)) { } else if (keymatch(arg, "dct", 2)) {
/* Select DCT algorithm. */ /* Select DCT algorithm. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "int", 1)) { if (keymatch(argv[argn], "int", 1)) {
cinfo->dct_method = JDCT_ISLOW; cinfo->dct_method = JDCT_ISLOW;
} else if (keymatch(argv[argn], "fast", 2)) { } else if (keymatch(argv[argn], "fast", 2)) {
cinfo->dct_method = JDCT_IFAST; cinfo->dct_method = JDCT_IFAST;
} else if (keymatch(argv[argn], "float", 2)) { } else if (keymatch(argv[argn], "float", 2)) {
cinfo->dct_method = JDCT_FLOAT; cinfo->dct_method = JDCT_FLOAT;
} else } else
usage(); usage();
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
/* Enable debug printouts. */ /* Enable debug printouts. */
@@ -282,12 +282,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
static boolean printed_version = FALSE; static boolean printed_version = FALSE;
if (! printed_version) { if (! printed_version) {
fprintf(stderr, "%s version %s (build %s)\n", fprintf(stderr, "%s version %s (build %s)\n",
PACKAGE_NAME, VERSION, BUILD); PACKAGE_NAME, VERSION, BUILD);
fprintf(stderr, "%s\n\n", JCOPYRIGHT); fprintf(stderr, "%s\n\n", JCOPYRIGHT);
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n", fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
JVERSION); JVERSION);
printed_version = TRUE; printed_version = TRUE;
} }
cinfo->err->trace_level++; cinfo->err->trace_level++;
@@ -304,12 +304,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
long lval; long lval;
char ch = 'x'; char ch = 'x';
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
usage(); usage();
if (ch == 'm' || ch == 'M') if (ch == 'm' || ch == 'M')
lval *= 1000L; lval *= 1000L;
cinfo->mem->max_memory_to_use = lval * 1000L; cinfo->mem->max_memory_to_use = lval * 1000L;
} else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
@@ -318,15 +318,15 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
cinfo->optimize_coding = TRUE; cinfo->optimize_coding = TRUE;
#else #else
fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n", fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
} else if (keymatch(arg, "outfile", 4)) { } else if (keymatch(arg, "outfile", 4)) {
/* Set output file name. */ /* Set output file name. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
outfilename = argv[argn]; /* save it away for later use */ outfilename = argv[argn]; /* save it away for later use */
} else if (keymatch(arg, "progressive", 1)) { } else if (keymatch(arg, "progressive", 1)) {
/* Select simple progressive mode. */ /* Select simple progressive mode. */
@@ -335,7 +335,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* We must postpone execution until num_components is known. */ /* We must postpone execution until num_components is known. */
#else #else
fprintf(stderr, "%s: sorry, progressive output was not compiled in\n", fprintf(stderr, "%s: sorry, progressive output was not compiled in\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -351,14 +351,14 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "quality", 1)) { } else if (keymatch(arg, "quality", 1)) {
/* Quality ratings (quantization table scaling factors). */ /* Quality ratings (quantization table scaling factors). */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
qualityarg = argv[argn]; qualityarg = argv[argn];
} else if (keymatch(arg, "qslots", 2)) { } else if (keymatch(arg, "qslots", 2)) {
/* Quantization table slot numbers. */ /* Quantization table slot numbers. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
qslotsarg = argv[argn]; qslotsarg = argv[argn];
/* Must delay setting qslots until after we have processed any /* Must delay setting qslots until after we have processed any
* colorspace-determining switches, since jpeg_set_colorspace sets * colorspace-determining switches, since jpeg_set_colorspace sets
@@ -367,8 +367,8 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "qtables", 2)) { } else if (keymatch(arg, "qtables", 2)) {
/* Quantization tables fetched from file. */ /* Quantization tables fetched from file. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
qtablefile = argv[argn]; qtablefile = argv[argn];
/* We postpone actually reading the file in case -quality comes later. */ /* We postpone actually reading the file in case -quality comes later. */
@@ -377,24 +377,24 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
long lval; long lval;
char ch = 'x'; char ch = 'x';
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
usage(); usage();
if (lval < 0 || lval > 65535L) if (lval < 0 || lval > 65535L)
usage(); usage();
if (ch == 'b' || ch == 'B') { if (ch == 'b' || ch == 'B') {
cinfo->restart_interval = (unsigned int) lval; cinfo->restart_interval = (unsigned int) lval;
cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
} else { } else {
cinfo->restart_in_rows = (int) lval; cinfo->restart_in_rows = (int) lval;
/* restart_interval will be computed during startup */ /* restart_interval will be computed during startup */
} }
} else if (keymatch(arg, "sample", 2)) { } else if (keymatch(arg, "sample", 2)) {
/* Set sampling factors. */ /* Set sampling factors. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
samplearg = argv[argn]; samplearg = argv[argn];
/* Must delay setting sample factors until after we have processed any /* Must delay setting sample factors until after we have processed any
* colorspace-determining switches, since jpeg_set_colorspace sets * colorspace-determining switches, since jpeg_set_colorspace sets
@@ -404,13 +404,13 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "scans", 4)) { } else if (keymatch(arg, "scans", 4)) {
/* Set scan script. */ /* Set scan script. */
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
scansarg = argv[argn]; scansarg = argv[argn];
/* We must postpone reading the file in case -progressive appears. */ /* We must postpone reading the file in case -progressive appears. */
#else #else
fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n", fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -418,12 +418,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* Set input smoothing factor. */ /* Set input smoothing factor. */
int val; int val;
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%d", &val) != 1) if (sscanf(argv[argn], "%d", &val) != 1)
usage(); usage();
if (val < 0 || val > 100) if (val < 0 || val > 100)
usage(); usage();
cinfo->smoothing_factor = val; cinfo->smoothing_factor = val;
} else if (keymatch(arg, "targa", 1)) { } else if (keymatch(arg, "targa", 1)) {
@@ -431,7 +431,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
is_targa = TRUE; is_targa = TRUE;
} else { } else {
usage(); /* bogus switch */ usage(); /* bogus switch */
} }
} }
@@ -441,35 +441,35 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* Set quantization tables for selected quality. */ /* Set quantization tables for selected quality. */
/* Some or all may be overridden if -qtables is present. */ /* Some or all may be overridden if -qtables is present. */
if (qualityarg != NULL) /* process -quality if it was present */ if (qualityarg != NULL) /* process -quality if it was present */
if (! set_quality_ratings(cinfo, qualityarg, force_baseline)) if (! set_quality_ratings(cinfo, qualityarg, force_baseline))
usage(); usage();
if (qtablefile != NULL) /* process -qtables if it was present */ if (qtablefile != NULL) /* process -qtables if it was present */
if (! read_quant_tables(cinfo, qtablefile, force_baseline)) if (! read_quant_tables(cinfo, qtablefile, force_baseline))
usage(); usage();
if (qslotsarg != NULL) /* process -qslots if it was present */ if (qslotsarg != NULL) /* process -qslots if it was present */
if (! set_quant_slots(cinfo, qslotsarg)) if (! set_quant_slots(cinfo, qslotsarg))
usage(); usage();
if (samplearg != NULL) /* process -sample if it was present */ if (samplearg != NULL) /* process -sample if it was present */
if (! set_sample_factors(cinfo, samplearg)) if (! set_sample_factors(cinfo, samplearg))
usage(); usage();
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
if (simple_progressive) /* process -progressive; -scans can override */ if (simple_progressive) /* process -progressive; -scans can override */
jpeg_simple_progression(cinfo); jpeg_simple_progression(cinfo);
#endif #endif
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED
if (scansarg != NULL) /* process -scans if it was present */ if (scansarg != NULL) /* process -scans if it was present */
if (! read_scan_script(cinfo, scansarg)) if (! read_scan_script(cinfo, scansarg))
usage(); usage();
#endif #endif
} }
return argn; /* return index of next arg (file name) */ return argn; /* return index of next arg (file name) */
} }
@@ -500,7 +500,7 @@ main (int argc, char **argv)
progname = argv[0]; progname = argv[0];
if (progname == NULL || progname[0] == 0) if (progname == NULL || progname[0] == 0)
progname = "cjpeg"; /* in case C library doesn't provide it */ progname = "cjpeg"; /* in case C library doesn't provide it */
/* Initialize the JPEG compression object with default error handling. */ /* Initialize the JPEG compression object with default error handling. */
cinfo.err = jpeg_std_error(&jerr); cinfo.err = jpeg_std_error(&jerr);
@@ -637,5 +637,5 @@ main (int argc, char **argv)
/* All done. */ /* All done. */
exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
return 0; /* suppress no-return-value warnings */ return 0; /* suppress no-return-value warnings */
} }

View File

@@ -21,11 +21,11 @@ Block comments should be laid out thusly:
*/ */
We indent statements in K&R style, e.g., We indent statements in K&R style, e.g.,
if (test) { if (test) {
then-part; then-part;
} else { } else {
else-part; else-part;
} }
with two spaces per indentation level. (This indentation convention is with two spaces per indentation level. (This indentation convention is
handled automatically by GNU Emacs and many other text editors.) handled automatically by GNU Emacs and many other text editors.)
@@ -57,16 +57,16 @@ keywords can be inserted for use in Windows DLLs.)
ansi2knr does not transform method declarations (function pointers in ansi2knr does not transform method declarations (function pointers in
structs). We handle these with a macro JMETHOD, defined as structs). We handle these with a macro JMETHOD, defined as
#ifdef HAVE_PROTOTYPES #ifdef HAVE_PROTOTYPES
#define JMETHOD(type,methodname,arglist) type (*methodname) arglist #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
#else #else
#define JMETHOD(type,methodname,arglist) type (*methodname) () #define JMETHOD(type,methodname,arglist) type (*methodname) ()
#endif #endif
which is used like this: which is used like this:
struct function_pointers { struct function_pointers {
JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp)); JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp));
JMETHOD(void, term_entropy_encoder, (void)); JMETHOD(void, term_entropy_encoder, (void));
}; };
Note the set of parentheses surrounding the parameter list. Note the set of parentheses surrounding the parameter list.
A similar solution is used for forward and external function declarations A similar solution is used for forward and external function declarations

198
djpeg.c
View File

@@ -12,8 +12,8 @@
* *
* Two different command line styles are permitted, depending on the * Two different command line styles are permitted, depending on the
* compile-time switch TWO_FILE_COMMANDLINE: * compile-time switch TWO_FILE_COMMANDLINE:
* djpeg [options] inputfile outputfile * djpeg [options] inputfile outputfile
* djpeg [options] [inputfile] * djpeg [options] [inputfile]
* In the second style, output is always to standard output, which you'd * In the second style, output is always to standard output, which you'd
* normally redirect to a file or pipe to some other program. Input is * normally redirect to a file or pipe to some other program. Input is
* either from a named file or from standard input (typically redirected). * either from a named file or from standard input (typically redirected).
@@ -21,30 +21,30 @@
* don't support pipes. Also, you MUST use the first style if your system * don't support pipes. Also, you MUST use the first style if your system
* doesn't do binary I/O to stdin/stdout. * doesn't do binary I/O to stdin/stdout.
* To simplify script writing, the "-outfile" switch is provided. The syntax * To simplify script writing, the "-outfile" switch is provided. The syntax
* djpeg [options] -outfile outputfile inputfile * djpeg [options] -outfile outputfile inputfile
* works regardless of which command line style is used. * works regardless of which command line style is used.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "jversion.h" /* for version message */ #include "jversion.h" /* for version message */
#include "jconfigint.h" #include "jconfigint.h"
#include <ctype.h> /* to declare isprint() */ #include <ctype.h> /* to declare isprint() */
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__ #ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */ #include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */ #include <console.h> /* ... and this */
#endif #endif
#ifdef THINK_C #ifdef THINK_C
#include <console.h> /* Think declares it here */ #include <console.h> /* Think declares it here */
#endif #endif
#endif #endif
/* Create the add-on message string table. */ /* Create the add-on message string table. */
#define JMESSAGE(code,string) string , #define JMESSAGE(code,string) string ,
static const char * const cdjpeg_message_table[] = { static const char * const cdjpeg_message_table[] = {
#include "cderror.h" #include "cderror.h"
@@ -60,17 +60,17 @@ static const char * const cdjpeg_message_table[] = {
*/ */
typedef enum { typedef enum {
FMT_BMP, /* BMP format (Windows flavor) */ FMT_BMP, /* BMP format (Windows flavor) */
FMT_GIF, /* GIF format */ FMT_GIF, /* GIF format */
FMT_OS2, /* BMP format (OS/2 flavor) */ FMT_OS2, /* BMP format (OS/2 flavor) */
FMT_PPM, /* PPM/PGM (PBMPLUS formats) */ FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
FMT_RLE, /* RLE format */ FMT_RLE, /* RLE format */
FMT_TARGA, /* Targa format */ FMT_TARGA, /* Targa format */
FMT_TIFF /* TIFF format */ FMT_TIFF /* TIFF format */
} IMAGE_FORMATS; } IMAGE_FORMATS;
#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */ #ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */
#define DEFAULT_FMT FMT_PPM #define DEFAULT_FMT FMT_PPM
#endif #endif
static IMAGE_FORMATS requested_fmt; static IMAGE_FORMATS requested_fmt;
@@ -85,8 +85,8 @@ static IMAGE_FORMATS requested_fmt;
*/ */
static const char * progname; /* program name for error messages */ static const char * progname; /* program name for error messages */
static char * outfilename; /* for -outfile switch */ static char * outfilename; /* for -outfile switch */
boolean memsrc; /* for -memsrc switch */ boolean memsrc; /* for -memsrc switch */
#define INPUT_BUF_SIZE 4096 #define INPUT_BUF_SIZE 4096
@@ -112,40 +112,40 @@ usage (void)
#endif #endif
#ifdef BMP_SUPPORTED #ifdef BMP_SUPPORTED
fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n", fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n",
(DEFAULT_FMT == FMT_BMP ? " (default)" : "")); (DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
#endif #endif
#ifdef GIF_SUPPORTED #ifdef GIF_SUPPORTED
fprintf(stderr, " -gif Select GIF output format%s\n", fprintf(stderr, " -gif Select GIF output format%s\n",
(DEFAULT_FMT == FMT_GIF ? " (default)" : "")); (DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
#endif #endif
#ifdef BMP_SUPPORTED #ifdef BMP_SUPPORTED
fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n", fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n",
(DEFAULT_FMT == FMT_OS2 ? " (default)" : "")); (DEFAULT_FMT == FMT_OS2 ? " (default)" : ""));
#endif #endif
#ifdef PPM_SUPPORTED #ifdef PPM_SUPPORTED
fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n", fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n",
(DEFAULT_FMT == FMT_PPM ? " (default)" : "")); (DEFAULT_FMT == FMT_PPM ? " (default)" : ""));
#endif #endif
#ifdef RLE_SUPPORTED #ifdef RLE_SUPPORTED
fprintf(stderr, " -rle Select Utah RLE output format%s\n", fprintf(stderr, " -rle Select Utah RLE output format%s\n",
(DEFAULT_FMT == FMT_RLE ? " (default)" : "")); (DEFAULT_FMT == FMT_RLE ? " (default)" : ""));
#endif #endif
#ifdef TARGA_SUPPORTED #ifdef TARGA_SUPPORTED
fprintf(stderr, " -targa Select Targa output format%s\n", fprintf(stderr, " -targa Select Targa output format%s\n",
(DEFAULT_FMT == FMT_TARGA ? " (default)" : "")); (DEFAULT_FMT == FMT_TARGA ? " (default)" : ""));
#endif #endif
fprintf(stderr, "Switches for advanced users:\n"); fprintf(stderr, "Switches for advanced users:\n");
#ifdef DCT_ISLOW_SUPPORTED #ifdef DCT_ISLOW_SUPPORTED
fprintf(stderr, " -dct int Use integer DCT method%s\n", fprintf(stderr, " -dct int Use integer DCT method%s\n",
(JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
#endif #endif
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
(JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
#endif #endif
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
fprintf(stderr, " -dct float Use floating-point DCT method%s\n", fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
(JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
#endif #endif
fprintf(stderr, " -dither fs Use F-S dithering (default)\n"); fprintf(stderr, " -dither fs Use F-S dithering (default)\n");
fprintf(stderr, " -dither none Don't use dithering in quantization\n"); fprintf(stderr, " -dither none Don't use dithering in quantization\n");
@@ -170,7 +170,7 @@ usage (void)
LOCAL(int) LOCAL(int)
parse_switches (j_decompress_ptr cinfo, int argc, char **argv, parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
int last_file_arg_seen, boolean for_real) int last_file_arg_seen, boolean for_real)
/* Parse optional switches. /* Parse optional switches.
* Returns argv[] index of first file-name argument (== argc if none). * Returns argv[] index of first file-name argument (== argc if none).
* Any file names with indexes <= last_file_arg_seen are ignored; * Any file names with indexes <= last_file_arg_seen are ignored;
@@ -184,7 +184,7 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
char * arg; char * arg;
/* Set up default JPEG parameters. */ /* Set up default JPEG parameters. */
requested_fmt = DEFAULT_FMT; /* set default output file format */ requested_fmt = DEFAULT_FMT; /* set default output file format */
outfilename = NULL; outfilename = NULL;
memsrc = FALSE; memsrc = FALSE;
cinfo->err->trace_level = 0; cinfo->err->trace_level = 0;
@@ -196,54 +196,54 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
if (*arg != '-') { if (*arg != '-') {
/* Not a switch, must be a file name argument */ /* Not a switch, must be a file name argument */
if (argn <= last_file_arg_seen) { if (argn <= last_file_arg_seen) {
outfilename = NULL; /* -outfile applies to just one input file */ outfilename = NULL; /* -outfile applies to just one input file */
continue; /* ignore this name if previously processed */ continue; /* ignore this name if previously processed */
} }
break; /* else done parsing switches */ break; /* else done parsing switches */
} }
arg++; /* advance past switch marker character */ arg++; /* advance past switch marker character */
if (keymatch(arg, "bmp", 1)) { if (keymatch(arg, "bmp", 1)) {
/* BMP output format. */ /* BMP output format. */
requested_fmt = FMT_BMP; requested_fmt = FMT_BMP;
} else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) || } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) { keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
/* Do color quantization. */ /* Do color quantization. */
int val; int val;
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%d", &val) != 1) if (sscanf(argv[argn], "%d", &val) != 1)
usage(); usage();
cinfo->desired_number_of_colors = val; cinfo->desired_number_of_colors = val;
cinfo->quantize_colors = TRUE; cinfo->quantize_colors = TRUE;
} else if (keymatch(arg, "dct", 2)) { } else if (keymatch(arg, "dct", 2)) {
/* Select IDCT algorithm. */ /* Select IDCT algorithm. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "int", 1)) { if (keymatch(argv[argn], "int", 1)) {
cinfo->dct_method = JDCT_ISLOW; cinfo->dct_method = JDCT_ISLOW;
} else if (keymatch(argv[argn], "fast", 2)) { } else if (keymatch(argv[argn], "fast", 2)) {
cinfo->dct_method = JDCT_IFAST; cinfo->dct_method = JDCT_IFAST;
} else if (keymatch(argv[argn], "float", 2)) { } else if (keymatch(argv[argn], "float", 2)) {
cinfo->dct_method = JDCT_FLOAT; cinfo->dct_method = JDCT_FLOAT;
} else } else
usage(); usage();
} else if (keymatch(arg, "dither", 2)) { } else if (keymatch(arg, "dither", 2)) {
/* Select dithering algorithm. */ /* Select dithering algorithm. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "fs", 2)) { if (keymatch(argv[argn], "fs", 2)) {
cinfo->dither_mode = JDITHER_FS; cinfo->dither_mode = JDITHER_FS;
} else if (keymatch(argv[argn], "none", 2)) { } else if (keymatch(argv[argn], "none", 2)) {
cinfo->dither_mode = JDITHER_NONE; cinfo->dither_mode = JDITHER_NONE;
} else if (keymatch(argv[argn], "ordered", 2)) { } else if (keymatch(argv[argn], "ordered", 2)) {
cinfo->dither_mode = JDITHER_ORDERED; cinfo->dither_mode = JDITHER_ORDERED;
} else } else
usage(); usage();
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
/* Enable debug printouts. */ /* Enable debug printouts. */
@@ -251,12 +251,12 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
static boolean printed_version = FALSE; static boolean printed_version = FALSE;
if (! printed_version) { if (! printed_version) {
fprintf(stderr, "%s version %s (build %s)\n", fprintf(stderr, "%s version %s (build %s)\n",
PACKAGE_NAME, VERSION, BUILD); PACKAGE_NAME, VERSION, BUILD);
fprintf(stderr, "%s\n\n", JCOPYRIGHT); fprintf(stderr, "%s\n\n", JCOPYRIGHT);
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n", fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
JVERSION); JVERSION);
printed_version = TRUE; printed_version = TRUE;
} }
cinfo->err->trace_level++; cinfo->err->trace_level++;
@@ -265,7 +265,7 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
cinfo->two_pass_quantize = FALSE; cinfo->two_pass_quantize = FALSE;
cinfo->dither_mode = JDITHER_ORDERED; cinfo->dither_mode = JDITHER_ORDERED;
if (! cinfo->quantize_colors) /* don't override an earlier -colors */ if (! cinfo->quantize_colors) /* don't override an earlier -colors */
cinfo->desired_number_of_colors = 216; cinfo->desired_number_of_colors = 216;
cinfo->dct_method = JDCT_FASTEST; cinfo->dct_method = JDCT_FASTEST;
cinfo->do_fancy_upsampling = FALSE; cinfo->do_fancy_upsampling = FALSE;
@@ -283,21 +283,21 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "map", 3)) { } else if (keymatch(arg, "map", 3)) {
/* Quantize to a color map taken from an input file. */ /* Quantize to a color map taken from an input file. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (for_real) { /* too expensive to do twice! */ if (for_real) { /* too expensive to do twice! */
#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
FILE * mapfile; FILE * mapfile;
if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) { if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
read_color_map(cinfo, mapfile); read_color_map(cinfo, mapfile);
fclose(mapfile); fclose(mapfile);
cinfo->quantize_colors = TRUE; cinfo->quantize_colors = TRUE;
#else #else
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif #endif
} }
@@ -306,12 +306,12 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
long lval; long lval;
char ch = 'x'; char ch = 'x';
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
usage(); usage();
if (ch == 'm' || ch == 'M') if (ch == 'm' || ch == 'M')
lval *= 1000L; lval *= 1000L;
cinfo->mem->max_memory_to_use = lval * 1000L; cinfo->mem->max_memory_to_use = lval * 1000L;
} else if (keymatch(arg, "nosmooth", 3)) { } else if (keymatch(arg, "nosmooth", 3)) {
@@ -328,9 +328,9 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "outfile", 4)) { } else if (keymatch(arg, "outfile", 4)) {
/* Set output file name. */ /* Set output file name. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
outfilename = argv[argn]; /* save it away for later use */ outfilename = argv[argn]; /* save it away for later use */
} else if (keymatch(arg, "memsrc", 2)) { } else if (keymatch(arg, "memsrc", 2)) {
/* Use in-memory source manager */ /* Use in-memory source manager */
@@ -352,22 +352,22 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
} else if (keymatch(arg, "scale", 1)) { } else if (keymatch(arg, "scale", 1)) {
/* Scale the output image by a fraction M/N. */ /* Scale the output image by a fraction M/N. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%d/%d", if (sscanf(argv[argn], "%d/%d",
&cinfo->scale_num, &cinfo->scale_denom) != 2) &cinfo->scale_num, &cinfo->scale_denom) != 2)
usage(); usage();
} else if (keymatch(arg, "targa", 1)) { } else if (keymatch(arg, "targa", 1)) {
/* Targa output format. */ /* Targa output format. */
requested_fmt = FMT_TARGA; requested_fmt = FMT_TARGA;
} else { } else {
usage(); /* bogus switch */ usage(); /* bogus switch */
} }
} }
return argn; /* return index of next arg (file name) */ return argn; /* return index of next arg (file name) */
} }
@@ -403,14 +403,14 @@ print_text_marker (j_decompress_ptr cinfo)
length = jpeg_getc(cinfo) << 8; length = jpeg_getc(cinfo) << 8;
length += jpeg_getc(cinfo); length += jpeg_getc(cinfo);
length -= 2; /* discount the length word itself */ length -= 2; /* discount the length word itself */
if (traceit) { if (traceit) {
if (cinfo->unread_marker == JPEG_COM) if (cinfo->unread_marker == JPEG_COM)
fprintf(stderr, "Comment, length %ld:\n", (long) length); fprintf(stderr, "Comment, length %ld:\n", (long) length);
else /* assume it is an APPn otherwise */ else /* assume it is an APPn otherwise */
fprintf(stderr, "APP%d, length %ld:\n", fprintf(stderr, "APP%d, length %ld:\n",
cinfo->unread_marker - JPEG_APP0, (long) length); cinfo->unread_marker - JPEG_APP0, (long) length);
} }
while (--length >= 0) { while (--length >= 0) {
@@ -422,16 +422,16 @@ print_text_marker (j_decompress_ptr cinfo)
* Newlines in CR, CR/LF, or LF form will be printed as one newline. * Newlines in CR, CR/LF, or LF form will be printed as one newline.
*/ */
if (ch == '\r') { if (ch == '\r') {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} else if (ch == '\n') { } else if (ch == '\n') {
if (lastch != '\r') if (lastch != '\r')
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} else if (ch == '\\') { } else if (ch == '\\') {
fprintf(stderr, "\\\\"); fprintf(stderr, "\\\\");
} else if (isprint(ch)) { } else if (isprint(ch)) {
putc(ch, stderr); putc(ch, stderr);
} else { } else {
fprintf(stderr, "\\%03o", ch); fprintf(stderr, "\\%03o", ch);
} }
lastch = ch; lastch = ch;
} }
@@ -471,7 +471,7 @@ main (int argc, char **argv)
progname = argv[0]; progname = argv[0];
if (progname == NULL || progname[0] == 0) if (progname == NULL || progname[0] == 0)
progname = "djpeg"; /* in case C library doesn't provide it */ progname = "djpeg"; /* in case C library doesn't provide it */
/* Initialize the JPEG decompression object with default error handling. */ /* Initialize the JPEG decompression object with default error handling. */
cinfo.err = jpeg_std_error(&jerr); cinfo.err = jpeg_std_error(&jerr);
@@ -510,14 +510,14 @@ main (int argc, char **argv)
if (outfilename == NULL) { if (outfilename == NULL) {
if (file_index != argc-2) { if (file_index != argc-2) {
fprintf(stderr, "%s: must name one input and one output file\n", fprintf(stderr, "%s: must name one input and one output file\n",
progname); progname);
usage(); usage();
} }
outfilename = argv[file_index+1]; outfilename = argv[file_index+1];
} else { } else {
if (file_index != argc-1) { if (file_index != argc-1) {
fprintf(stderr, "%s: must name one input and one output file\n", fprintf(stderr, "%s: must name one input and one output file\n",
progname); progname);
usage(); usage();
} }
} }
@@ -634,7 +634,7 @@ main (int argc, char **argv)
/* Process data */ /* Process data */
while (cinfo.output_scanline < cinfo.output_height) { while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
dest_mgr->buffer_height); dest_mgr->buffer_height);
(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
} }
@@ -668,5 +668,5 @@ main (int argc, char **argv)
/* All done. */ /* All done. */
exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
return 0; /* suppress no-return-value warnings */ return 0; /* suppress no-return-value warnings */
} }

View File

@@ -6,7 +6,7 @@
* conjunction with the documentation file libjpeg.txt. * conjunction with the documentation file libjpeg.txt.
* *
* This code will not do anything useful as-is, but it may be helpful as a * This code will not do anything useful as-is, but it may be helpful as a
* skeleton for constructing routines that call the JPEG library. * skeleton for constructing routines that call the JPEG library.
* *
* We present these routines in the same coding style used in the JPEG code * We present these routines in the same coding style used in the JPEG code
* (ANSI function definitions, etc); but you are of course free to code your * (ANSI function definitions, etc); but you are of course free to code your
@@ -58,9 +58,9 @@
* RGB color and is described by: * RGB color and is described by:
*/ */
extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */ extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
extern int image_height; /* Number of rows in image */ extern int image_height; /* Number of rows in image */
extern int image_width; /* Number of columns in image */ extern int image_width; /* Number of columns in image */
/* /*
@@ -88,9 +88,9 @@ write_JPEG_file (char * filename, int quality)
*/ */
struct jpeg_error_mgr jerr; struct jpeg_error_mgr jerr;
/* More stuff */ /* More stuff */
FILE * outfile; /* target file */ FILE * outfile; /* target file */
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
int row_stride; /* physical row width in image buffer */ int row_stride; /* physical row width in image buffer */
/* Step 1: allocate and initialize JPEG compression object */ /* Step 1: allocate and initialize JPEG compression object */
@@ -122,10 +122,10 @@ write_JPEG_file (char * filename, int quality)
/* First we supply a description of the input image. /* First we supply a description of the input image.
* Four fields of the cinfo struct must be filled in: * Four fields of the cinfo struct must be filled in:
*/ */
cinfo.image_width = image_width; /* image width and height, in pixels */ cinfo.image_width = image_width; /* image width and height, in pixels */
cinfo.image_height = image_height; cinfo.image_height = image_height;
cinfo.input_components = 3; /* # of color components per pixel */ cinfo.input_components = 3; /* # of color components per pixel */
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
/* Now use the library's routine to set default compression parameters. /* Now use the library's routine to set default compression parameters.
* (You must set at least cinfo.in_color_space before calling this, * (You must set at least cinfo.in_color_space before calling this,
* since the defaults depend on the source color space.) * since the defaults depend on the source color space.)
@@ -151,7 +151,7 @@ write_JPEG_file (char * filename, int quality)
* To keep things simple, we pass one scanline per call; you can pass * To keep things simple, we pass one scanline per call; you can pass
* more if you wish, though. * more if you wish, though.
*/ */
row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */ row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */
while (cinfo.next_scanline < cinfo.image_height) { while (cinfo.next_scanline < cinfo.image_height) {
/* jpeg_write_scanlines expects an array of pointers to scanlines. /* jpeg_write_scanlines expects an array of pointers to scanlines.
@@ -248,9 +248,9 @@ write_JPEG_file (char * filename, int quality)
*/ */
struct my_error_mgr { struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */ struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */ jmp_buf setjmp_buffer; /* for return to caller */
}; };
typedef struct my_error_mgr * my_error_ptr; typedef struct my_error_mgr * my_error_ptr;
@@ -293,9 +293,9 @@ read_JPEG_file (char * filename)
*/ */
struct my_error_mgr jerr; struct my_error_mgr jerr;
/* More stuff */ /* More stuff */
FILE * infile; /* source file */ FILE * infile; /* source file */
JSAMPARRAY buffer; /* Output row buffer */ JSAMPARRAY buffer; /* Output row buffer */
int row_stride; /* physical row width in output buffer */ int row_stride; /* physical row width in output buffer */
/* In this example we want to open the input file before doing anything else, /* In this example we want to open the input file before doing anything else,
* so that the setjmp() error recovery below can assume the file is open. * so that the setjmp() error recovery below can assume the file is open.
@@ -356,12 +356,12 @@ read_JPEG_file (char * filename)
* output image dimensions available, as well as the output colormap * output image dimensions available, as well as the output colormap
* if we asked for color quantization. * if we asked for color quantization.
* In this example, we need to make an output work buffer of the right size. * In this example, we need to make an output work buffer of the right size.
*/ */
/* JSAMPLEs per row in output buffer */ /* JSAMPLEs per row in output buffer */
row_stride = cinfo.output_width * cinfo.output_components; row_stride = cinfo.output_width * cinfo.output_components;
/* Make a one-row-high sample array that will go away when done with image */ /* Make a one-row-high sample array that will go away when done with image */
buffer = (*cinfo.mem->alloc_sarray) buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
/* Step 6: while (scan lines remain to be read) */ /* Step 6: while (scan lines remain to be read) */
/* jpeg_read_scanlines(...); */ /* jpeg_read_scanlines(...); */

View File

@@ -33,12 +33,12 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
int i; int i;
/* Guard against version mismatches between library and caller. */ /* Guard against version mismatches between library and caller. */
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
if (version != JPEG_LIB_VERSION) if (version != JPEG_LIB_VERSION)
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
if (structsize != SIZEOF(struct jpeg_compress_struct)) if (structsize != SIZEOF(struct jpeg_compress_struct))
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
(int) SIZEOF(struct jpeg_compress_struct), (int) structsize); (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
/* For debugging purposes, we zero the whole master structure. /* For debugging purposes, we zero the whole master structure.
* But the application has already set the err pointer, and may have set * But the application has already set the err pointer, and may have set
@@ -85,7 +85,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
cinfo->script_space = NULL; cinfo->script_space = NULL;
cinfo->input_gamma = 1.0; /* in case application forgets */ cinfo->input_gamma = 1.0; /* in case application forgets */
/* OK, I'm ready */ /* OK, I'm ready */
cinfo->global_state = CSTATE_START; cinfo->global_state = CSTATE_START;
@@ -173,15 +173,15 @@ jpeg_finish_compress (j_compress_ptr cinfo)
(*cinfo->master->prepare_for_pass) (cinfo); (*cinfo->master->prepare_for_pass) (cinfo);
for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) { for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) iMCU_row; cinfo->progress->pass_counter = (long) iMCU_row;
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows; cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
} }
/* We bypass the main controller and invoke coef controller directly; /* We bypass the main controller and invoke coef controller directly;
* all work is being done from the coefficient buffer. * all work is being done from the coefficient buffer.
*/ */
if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL)) if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND); ERREXIT(cinfo, JERR_CANT_SUSPEND);
} }
(*cinfo->master->finish_pass) (cinfo); (*cinfo->master->finish_pass) (cinfo);
} }
@@ -202,7 +202,7 @@ jpeg_finish_compress (j_compress_ptr cinfo)
GLOBAL(void) GLOBAL(void)
jpeg_write_marker (j_compress_ptr cinfo, int marker, jpeg_write_marker (j_compress_ptr cinfo, int marker,
const JOCTET *dataptr, unsigned int datalen) const JOCTET *dataptr, unsigned int datalen)
{ {
JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val)); JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
@@ -213,7 +213,7 @@ jpeg_write_marker (j_compress_ptr cinfo, int marker,
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen); (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */ write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
while (datalen--) { while (datalen--) {
(*write_marker_byte) (cinfo, *dataptr); (*write_marker_byte) (cinfo, *dataptr);
dataptr++; dataptr++;
@@ -248,14 +248,14 @@ jpeg_write_m_byte (j_compress_ptr cinfo, int val)
* To produce a pair of files containing abbreviated tables and abbreviated * To produce a pair of files containing abbreviated tables and abbreviated
* image data, one would proceed as follows: * image data, one would proceed as follows:
* *
* initialize JPEG object * initialize JPEG object
* set JPEG parameters * set JPEG parameters
* set destination to table file * set destination to table file
* jpeg_write_tables(cinfo); * jpeg_write_tables(cinfo);
* set destination to image file * set destination to image file
* jpeg_start_compress(cinfo, FALSE); * jpeg_start_compress(cinfo, FALSE);
* write data... * write data...
* jpeg_finish_compress(cinfo); * jpeg_finish_compress(cinfo);
* *
* jpeg_write_tables has the side effect of marking all tables written * jpeg_write_tables has the side effect of marking all tables written
* (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress

View File

@@ -41,7 +41,7 @@ jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (write_all_tables) if (write_all_tables)
jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */ jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
/* (Re)initialize error mgr and destination modules */ /* (Re)initialize error mgr and destination modules */
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
@@ -75,7 +75,7 @@ jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
JDIMENSION num_lines) JDIMENSION num_lines)
{ {
JDIMENSION row_ctr, rows_left; JDIMENSION row_ctr, rows_left;
@@ -118,7 +118,7 @@ jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION num_lines) JDIMENSION num_lines)
{ {
JDIMENSION lines_per_iMCU_row; JDIMENSION lines_per_iMCU_row;

346
jcarith.c
View File

@@ -34,8 +34,8 @@ typedef struct {
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */ int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
int next_restart_num; /* next restart number to write (0-7) */ int next_restart_num; /* next restart number to write (0-7) */
/* Pointers to statistics areas (these workspaces have image lifespan) */ /* Pointers to statistics areas (these workspaces have image lifespan) */
unsigned char * dc_stats[NUM_ARITH_TBLS]; unsigned char * dc_stats[NUM_ARITH_TBLS];
@@ -101,14 +101,14 @@ typedef arith_entropy_encoder * arith_entropy_ptr;
*/ */
#ifdef RIGHT_SHIFT_IS_UNSIGNED #ifdef RIGHT_SHIFT_IS_UNSIGNED
#define ISHIFT_TEMPS int ishift_temp; #define ISHIFT_TEMPS int ishift_temp;
#define IRIGHT_SHIFT(x,shft) \ #define IRIGHT_SHIFT(x,shft) \
((ishift_temp = (x)) < 0 ? \ ((ishift_temp = (x)) < 0 ? \
(ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \ (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
(ishift_temp >> (shft))) (ishift_temp >> (shft)))
#else #else
#define ISHIFT_TEMPS #define ISHIFT_TEMPS
#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
#endif #endif
@@ -149,11 +149,11 @@ finish_pass (j_compress_ptr cinfo)
/* One final overflow has to be handled */ /* One final overflow has to be handled */
if (e->buffer >= 0) { if (e->buffer >= 0) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
emit_byte(e->buffer + 1, cinfo); emit_byte(e->buffer + 1, cinfo);
if (e->buffer + 1 == 0xFF) if (e->buffer + 1 == 0xFF)
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} }
e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */ e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */
e->sc = 0; e->sc = 0;
@@ -162,17 +162,17 @@ finish_pass (j_compress_ptr cinfo)
++e->zc; ++e->zc;
else if (e->buffer >= 0) { else if (e->buffer >= 0) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
emit_byte(e->buffer, cinfo); emit_byte(e->buffer, cinfo);
} }
if (e->sc) { if (e->sc) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
do { do {
emit_byte(0xFF, cinfo); emit_byte(0xFF, cinfo);
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} while (--e->sc); } while (--e->sc);
} }
} }
@@ -187,7 +187,7 @@ finish_pass (j_compress_ptr cinfo)
if (e->c & 0x7F800L) { if (e->c & 0x7F800L) {
emit_byte((e->c >> 11) & 0xFF, cinfo); emit_byte((e->c >> 11) & 0xFF, cinfo);
if (((e->c >> 11) & 0xFF) == 0xFF) if (((e->c >> 11) & 0xFF) == 0xFF)
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} }
} }
} }
@@ -216,7 +216,7 @@ finish_pass (j_compress_ptr cinfo)
*/ */
LOCAL(void) LOCAL(void)
arith_encode (j_compress_ptr cinfo, unsigned char *st, int val) arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
{ {
register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy; register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
register unsigned char nl, nm; register unsigned char nl, nm;
@@ -227,9 +227,9 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
* Qe values and probability estimation state machine * Qe values and probability estimation state machine
*/ */
sv = *st; sv = *st;
qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */ qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */
nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */ nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */
nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */ nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */
/* Encode & estimation procedures per sections D.1.4 & D.1.5 */ /* Encode & estimation procedures per sections D.1.4 & D.1.5 */
e->a -= qe; e->a -= qe;
@@ -243,7 +243,7 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
e->c += e->a; e->c += e->a;
e->a = qe; e->a = qe;
} }
*st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
} else { } else {
/* Encode the more probable symbol */ /* Encode the more probable symbol */
if (e->a >= 0x8000L) if (e->a >= 0x8000L)
@@ -255,7 +255,7 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
e->c += e->a; e->c += e->a;
e->a = qe; e->a = qe;
} }
*st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
} }
/* Renormalization & data output per section D.1.6 */ /* Renormalization & data output per section D.1.6 */
@@ -266,43 +266,43 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
/* Another byte is ready for output */ /* Another byte is ready for output */
temp = e->c >> 19; temp = e->c >> 19;
if (temp > 0xFF) { if (temp > 0xFF) {
/* Handle overflow over all stacked 0xFF bytes */ /* Handle overflow over all stacked 0xFF bytes */
if (e->buffer >= 0) { if (e->buffer >= 0) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
emit_byte(e->buffer + 1, cinfo); emit_byte(e->buffer + 1, cinfo);
if (e->buffer + 1 == 0xFF) if (e->buffer + 1 == 0xFF)
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} }
e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */ e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */
e->sc = 0; e->sc = 0;
/* Note: The 3 spacer bits in the C register guarantee /* Note: The 3 spacer bits in the C register guarantee
* that the new buffer byte can't be 0xFF here * that the new buffer byte can't be 0xFF here
* (see page 160 in the P&M JPEG book). */ * (see page 160 in the P&M JPEG book). */
e->buffer = temp & 0xFF; /* new output byte, might overflow later */ e->buffer = temp & 0xFF; /* new output byte, might overflow later */
} else if (temp == 0xFF) { } else if (temp == 0xFF) {
++e->sc; /* stack 0xFF byte (which might overflow later) */ ++e->sc; /* stack 0xFF byte (which might overflow later) */
} else { } else {
/* Output all stacked 0xFF bytes, they will not overflow any more */ /* Output all stacked 0xFF bytes, they will not overflow any more */
if (e->buffer == 0) if (e->buffer == 0)
++e->zc; ++e->zc;
else if (e->buffer >= 0) { else if (e->buffer >= 0) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
emit_byte(e->buffer, cinfo); emit_byte(e->buffer, cinfo);
} }
if (e->sc) { if (e->sc) {
if (e->zc) if (e->zc)
do emit_byte(0x00, cinfo); do emit_byte(0x00, cinfo);
while (--e->zc); while (--e->zc);
do { do {
emit_byte(0xFF, cinfo); emit_byte(0xFF, cinfo);
emit_byte(0x00, cinfo); emit_byte(0x00, cinfo);
} while (--e->sc); } while (--e->sc);
} }
e->buffer = temp & 0xFF; /* new output byte (can still overflow) */ e->buffer = temp & 0xFF; /* new output byte (can still overflow) */
} }
e->c &= 0x7FFFFL; e->c &= 0x7FFFFL;
e->ct += 8; e->ct += 8;
@@ -398,45 +398,45 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.4: Encode_DC_DIFF */ /* Figure F.4: Encode_DC_DIFF */
if ((v = m - entropy->last_dc_val[ci]) == 0) { if ((v = m - entropy->last_dc_val[ci]) == 0) {
arith_encode(cinfo, st, 0); arith_encode(cinfo, st, 0);
entropy->dc_context[ci] = 0; /* zero diff category */ entropy->dc_context[ci] = 0; /* zero diff category */
} else { } else {
entropy->last_dc_val[ci] = m; entropy->last_dc_val[ci] = m;
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
/* Figure F.6: Encoding nonzero value v */ /* Figure F.6: Encoding nonzero value v */
/* Figure F.7: Encoding the sign of v */ /* Figure F.7: Encoding the sign of v */
if (v > 0) { if (v > 0) {
arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */ arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */
st += 2; /* Table F.4: SP = S0 + 2 */ st += 2; /* Table F.4: SP = S0 + 2 */
entropy->dc_context[ci] = 4; /* small positive diff category */ entropy->dc_context[ci] = 4; /* small positive diff category */
} else { } else {
v = -v; v = -v;
arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */ arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */
st += 3; /* Table F.4: SN = S0 + 3 */ st += 3; /* Table F.4: SN = S0 + 3 */
entropy->dc_context[ci] = 8; /* small negative diff category */ entropy->dc_context[ci] = 8; /* small negative diff category */
} }
/* Figure F.8: Encoding the magnitude category of v */ /* Figure F.8: Encoding the magnitude category of v */
m = 0; m = 0;
if (v -= 1) { if (v -= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m = 1; m = 1;
v2 = v; v2 = v;
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
while (v2 >>= 1) { while (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st += 1; st += 1;
} }
} }
arith_encode(cinfo, st, 0); arith_encode(cinfo, st, 0);
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
entropy->dc_context[ci] = 0; /* zero diff category */ entropy->dc_context[ci] = 0; /* zero diff category */
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
entropy->dc_context[ci] += 8; /* large diff category */ entropy->dc_context[ci] += 8; /* large diff category */
/* Figure F.9: Encoding the magnitude bit pattern of v */ /* Figure F.9: Encoding the magnitude bit pattern of v */
st += 14; st += 14;
while (m >>= 1) while (m >>= 1)
arith_encode(cinfo, st, (m & v) ? 1 : 0); arith_encode(cinfo, st, (m & v) ? 1 : 0);
} }
} }
@@ -491,21 +491,21 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.5: Encode_AC_Coefficients */ /* Figure F.5: Encode_AC_Coefficients */
for (k = cinfo->Ss; k <= ke; k++) { for (k = cinfo->Ss; k <= ke; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
arith_encode(cinfo, st, 0); /* EOB decision */ arith_encode(cinfo, st, 0); /* EOB decision */
for (;;) { for (;;) {
if ((v = (*block)[jpeg_natural_order[k]]) >= 0) { if ((v = (*block)[jpeg_natural_order[k]]) >= 0) {
if (v >>= cinfo->Al) { if (v >>= cinfo->Al) {
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
arith_encode(cinfo, entropy->fixed_bin, 0); arith_encode(cinfo, entropy->fixed_bin, 0);
break; break;
} }
} else { } else {
v = -v; v = -v;
if (v >>= cinfo->Al) { if (v >>= cinfo->Al) {
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
arith_encode(cinfo, entropy->fixed_bin, 1); arith_encode(cinfo, entropy->fixed_bin, 1);
break; break;
} }
} }
arith_encode(cinfo, st + 1, 0); st += 3; k++; arith_encode(cinfo, st + 1, 0); st += 3; k++;
} }
@@ -517,15 +517,15 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
m = 1; m = 1;
v2 = v; v2 = v;
if (v2 >>= 1) { if (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st = entropy->ac_stats[tbl] + st = entropy->ac_stats[tbl] +
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217); (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
while (v2 >>= 1) { while (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st += 1; st += 1;
} }
} }
} }
arith_encode(cinfo, st, 0); arith_encode(cinfo, st, 0);
@@ -566,7 +566,7 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
st = entropy->fixed_bin; /* use fixed probability estimation */ st = entropy->fixed_bin; /* use fixed probability estimation */
Al = cinfo->Al; Al = cinfo->Al;
/* Encode the MCU data blocks */ /* Encode the MCU data blocks */
@@ -635,29 +635,29 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
for (k = cinfo->Ss; k <= ke; k++) { for (k = cinfo->Ss; k <= ke; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
if (k > kex) if (k > kex)
arith_encode(cinfo, st, 0); /* EOB decision */ arith_encode(cinfo, st, 0); /* EOB decision */
for (;;) { for (;;) {
if ((v = (*block)[jpeg_natural_order[k]]) >= 0) { if ((v = (*block)[jpeg_natural_order[k]]) >= 0) {
if (v >>= cinfo->Al) { if (v >>= cinfo->Al) {
if (v >> 1) /* previously nonzero coef */ if (v >> 1) /* previously nonzero coef */
arith_encode(cinfo, st + 2, (v & 1)); arith_encode(cinfo, st + 2, (v & 1));
else { /* newly nonzero coef */ else { /* newly nonzero coef */
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
arith_encode(cinfo, entropy->fixed_bin, 0); arith_encode(cinfo, entropy->fixed_bin, 0);
} }
break; break;
} }
} else { } else {
v = -v; v = -v;
if (v >>= cinfo->Al) { if (v >>= cinfo->Al) {
if (v >> 1) /* previously nonzero coef */ if (v >> 1) /* previously nonzero coef */
arith_encode(cinfo, st + 2, (v & 1)); arith_encode(cinfo, st + 2, (v & 1));
else { /* newly nonzero coef */ else { /* newly nonzero coef */
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
arith_encode(cinfo, entropy->fixed_bin, 1); arith_encode(cinfo, entropy->fixed_bin, 1);
} }
break; break;
} }
} }
arith_encode(cinfo, st + 1, 0); st += 3; k++; arith_encode(cinfo, st + 1, 0); st += 3; k++;
} }
@@ -713,45 +713,45 @@ encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.4: Encode_DC_DIFF */ /* Figure F.4: Encode_DC_DIFF */
if ((v = (*block)[0] - entropy->last_dc_val[ci]) == 0) { if ((v = (*block)[0] - entropy->last_dc_val[ci]) == 0) {
arith_encode(cinfo, st, 0); arith_encode(cinfo, st, 0);
entropy->dc_context[ci] = 0; /* zero diff category */ entropy->dc_context[ci] = 0; /* zero diff category */
} else { } else {
entropy->last_dc_val[ci] = (*block)[0]; entropy->last_dc_val[ci] = (*block)[0];
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
/* Figure F.6: Encoding nonzero value v */ /* Figure F.6: Encoding nonzero value v */
/* Figure F.7: Encoding the sign of v */ /* Figure F.7: Encoding the sign of v */
if (v > 0) { if (v > 0) {
arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */ arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */
st += 2; /* Table F.4: SP = S0 + 2 */ st += 2; /* Table F.4: SP = S0 + 2 */
entropy->dc_context[ci] = 4; /* small positive diff category */ entropy->dc_context[ci] = 4; /* small positive diff category */
} else { } else {
v = -v; v = -v;
arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */ arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */
st += 3; /* Table F.4: SN = S0 + 3 */ st += 3; /* Table F.4: SN = S0 + 3 */
entropy->dc_context[ci] = 8; /* small negative diff category */ entropy->dc_context[ci] = 8; /* small negative diff category */
} }
/* Figure F.8: Encoding the magnitude category of v */ /* Figure F.8: Encoding the magnitude category of v */
m = 0; m = 0;
if (v -= 1) { if (v -= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m = 1; m = 1;
v2 = v; v2 = v;
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
while (v2 >>= 1) { while (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st += 1; st += 1;
} }
} }
arith_encode(cinfo, st, 0); arith_encode(cinfo, st, 0);
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
entropy->dc_context[ci] = 0; /* zero diff category */ entropy->dc_context[ci] = 0; /* zero diff category */
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
entropy->dc_context[ci] += 8; /* large diff category */ entropy->dc_context[ci] += 8; /* large diff category */
/* Figure F.9: Encoding the magnitude bit pattern of v */ /* Figure F.9: Encoding the magnitude bit pattern of v */
st += 14; st += 14;
while (m >>= 1) while (m >>= 1)
arith_encode(cinfo, st, (m & v) ? 1 : 0); arith_encode(cinfo, st, (m & v) ? 1 : 0);
} }
/* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */ /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
@@ -765,43 +765,43 @@ encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.5: Encode_AC_Coefficients */ /* Figure F.5: Encode_AC_Coefficients */
for (k = 1; k <= ke; k++) { for (k = 1; k <= ke; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
arith_encode(cinfo, st, 0); /* EOB decision */ arith_encode(cinfo, st, 0); /* EOB decision */
while ((v = (*block)[jpeg_natural_order[k]]) == 0) { while ((v = (*block)[jpeg_natural_order[k]]) == 0) {
arith_encode(cinfo, st + 1, 0); st += 3; k++; arith_encode(cinfo, st + 1, 0); st += 3; k++;
} }
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
/* Figure F.6: Encoding nonzero value v */ /* Figure F.6: Encoding nonzero value v */
/* Figure F.7: Encoding the sign of v */ /* Figure F.7: Encoding the sign of v */
if (v > 0) { if (v > 0) {
arith_encode(cinfo, entropy->fixed_bin, 0); arith_encode(cinfo, entropy->fixed_bin, 0);
} else { } else {
v = -v; v = -v;
arith_encode(cinfo, entropy->fixed_bin, 1); arith_encode(cinfo, entropy->fixed_bin, 1);
} }
st += 2; st += 2;
/* Figure F.8: Encoding the magnitude category of v */ /* Figure F.8: Encoding the magnitude category of v */
m = 0; m = 0;
if (v -= 1) { if (v -= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m = 1; m = 1;
v2 = v; v2 = v;
if (v2 >>= 1) { if (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st = entropy->ac_stats[tbl] + st = entropy->ac_stats[tbl] +
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217); (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
while (v2 >>= 1) { while (v2 >>= 1) {
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
m <<= 1; m <<= 1;
st += 1; st += 1;
} }
} }
} }
arith_encode(cinfo, st, 0); arith_encode(cinfo, st, 0);
/* Figure F.9: Encoding the magnitude bit pattern of v */ /* Figure F.9: Encoding the magnitude bit pattern of v */
st += 14; st += 14;
while (m >>= 1) while (m >>= 1)
arith_encode(cinfo, st, (m & v) ? 1 : 0); arith_encode(cinfo, st, (m & v) ? 1 : 0);
} }
/* Encode EOB decision only if k <= DCTSIZE2 - 1 */ /* Encode EOB decision only if k <= DCTSIZE2 - 1 */
if (k <= DCTSIZE2 - 1) { if (k <= DCTSIZE2 - 1) {
@@ -838,14 +838,14 @@ start_pass (j_compress_ptr cinfo, boolean gather_statistics)
if (cinfo->progressive_mode) { if (cinfo->progressive_mode) {
if (cinfo->Ah == 0) { if (cinfo->Ah == 0) {
if (cinfo->Ss == 0) if (cinfo->Ss == 0)
entropy->pub.encode_mcu = encode_mcu_DC_first; entropy->pub.encode_mcu = encode_mcu_DC_first;
else else
entropy->pub.encode_mcu = encode_mcu_AC_first; entropy->pub.encode_mcu = encode_mcu_AC_first;
} else { } else {
if (cinfo->Ss == 0) if (cinfo->Ss == 0)
entropy->pub.encode_mcu = encode_mcu_DC_refine; entropy->pub.encode_mcu = encode_mcu_DC_refine;
else else
entropy->pub.encode_mcu = encode_mcu_AC_refine; entropy->pub.encode_mcu = encode_mcu_AC_refine;
} }
} else } else
entropy->pub.encode_mcu = encode_mcu; entropy->pub.encode_mcu = encode_mcu;
@@ -857,10 +857,10 @@ start_pass (j_compress_ptr cinfo, boolean gather_statistics)
if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) { if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
tbl = compptr->dc_tbl_no; tbl = compptr->dc_tbl_no;
if (tbl < 0 || tbl >= NUM_ARITH_TBLS) if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
if (entropy->dc_stats[tbl] == NULL) if (entropy->dc_stats[tbl] == NULL)
entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS); ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS);
MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS); MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
/* Initialize DC predictions to 0 */ /* Initialize DC predictions to 0 */
entropy->last_dc_val[ci] = 0; entropy->last_dc_val[ci] = 0;
@@ -870,15 +870,15 @@ start_pass (j_compress_ptr cinfo, boolean gather_statistics)
if (cinfo->progressive_mode == 0 || cinfo->Se) { if (cinfo->progressive_mode == 0 || cinfo->Se) {
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
if (tbl < 0 || tbl >= NUM_ARITH_TBLS) if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
if (entropy->ac_stats[tbl] == NULL) if (entropy->ac_stats[tbl] == NULL)
entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS); ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS);
MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS); MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
#ifdef CALCULATE_SPECTRAL_CONDITIONING #ifdef CALCULATE_SPECTRAL_CONDITIONING
if (cinfo->progressive_mode) if (cinfo->progressive_mode)
/* Section G.1.3.2: Set appropriate arithmetic conditioning value Kx */ /* Section G.1.3.2: Set appropriate arithmetic conditioning value Kx */
cinfo->arith_ac_K[tbl] = cinfo->Ss + ((8 + cinfo->Se - cinfo->Ss) >> 4); cinfo->arith_ac_K[tbl] = cinfo->Ss + ((8 + cinfo->Se - cinfo->Ss) >> 4);
#endif #endif
} }
} }
@@ -909,7 +909,7 @@ jinit_arith_encoder (j_compress_ptr cinfo)
entropy = (arith_entropy_ptr) entropy = (arith_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(arith_entropy_encoder)); SIZEOF(arith_entropy_encoder));
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
entropy->pub.start_pass = start_pass; entropy->pub.start_pass = start_pass;
entropy->pub.finish_pass = finish_pass; entropy->pub.finish_pass = finish_pass;

View File

@@ -34,10 +34,10 @@
typedef struct { typedef struct {
struct jpeg_c_coef_controller pub; /* public fields */ struct jpeg_c_coef_controller pub; /* public fields */
JDIMENSION iMCU_row_num; /* iMCU row # within image */ JDIMENSION iMCU_row_num; /* iMCU row # within image */
JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
int MCU_vert_offset; /* counts MCU rows within iMCU row */ int MCU_vert_offset; /* counts MCU rows within iMCU row */
int MCU_rows_per_iMCU_row; /* number of such rows needed */ int MCU_rows_per_iMCU_row; /* number of such rows needed */
/* For single-pass compression, it's sufficient to buffer just one MCU /* For single-pass compression, it's sufficient to buffer just one MCU
* (although this may prove a bit slow in practice). We allocate a * (although this may prove a bit slow in practice). We allocate a
@@ -143,7 +143,7 @@ METHODDEF(boolean)
compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf) compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */ JDIMENSION MCU_col_num; /* index of current MCU within row */
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
int blkn, bi, ci, yindex, yoffset, blockcnt; int blkn, bi, ci, yindex, yoffset, blockcnt;
@@ -154,7 +154,7 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
yoffset++) { yoffset++) {
for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col; for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
MCU_col_num++) { MCU_col_num++) {
/* Determine where data comes from in input_buf and do the DCT thing. /* Determine where data comes from in input_buf and do the DCT thing.
* Each call on forward_DCT processes a horizontal row of DCT blocks * Each call on forward_DCT processes a horizontal row of DCT blocks
* as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
@@ -166,46 +166,46 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
*/ */
blkn = 0; blkn = 0;
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
: compptr->last_col_width; : compptr->last_col_width;
xpos = MCU_col_num * compptr->MCU_sample_width; xpos = MCU_col_num * compptr->MCU_sample_width;
ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */ ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
for (yindex = 0; yindex < compptr->MCU_height; yindex++) { for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
if (coef->iMCU_row_num < last_iMCU_row || if (coef->iMCU_row_num < last_iMCU_row ||
yoffset+yindex < compptr->last_row_height) { yoffset+yindex < compptr->last_row_height) {
(*cinfo->fdct->forward_DCT) (cinfo, compptr, (*cinfo->fdct->forward_DCT) (cinfo, compptr,
input_buf[compptr->component_index], input_buf[compptr->component_index],
coef->MCU_buffer[blkn], coef->MCU_buffer[blkn],
ypos, xpos, (JDIMENSION) blockcnt); ypos, xpos, (JDIMENSION) blockcnt);
if (blockcnt < compptr->MCU_width) { if (blockcnt < compptr->MCU_width) {
/* Create some dummy blocks at the right edge of the image. */ /* Create some dummy blocks at the right edge of the image. */
jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt], jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
(compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK)); (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
for (bi = blockcnt; bi < compptr->MCU_width; bi++) { for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0]; coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
} }
} }
} else { } else {
/* Create a row of dummy blocks at the bottom of the image. */ /* Create a row of dummy blocks at the bottom of the image. */
jzero_far((void FAR *) coef->MCU_buffer[blkn], jzero_far((void FAR *) coef->MCU_buffer[blkn],
compptr->MCU_width * SIZEOF(JBLOCK)); compptr->MCU_width * SIZEOF(JBLOCK));
for (bi = 0; bi < compptr->MCU_width; bi++) { for (bi = 0; bi < compptr->MCU_width; bi++) {
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0]; coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
} }
} }
blkn += compptr->MCU_width; blkn += compptr->MCU_width;
ypos += DCTSIZE; ypos += DCTSIZE;
} }
} }
/* Try to write the MCU. In event of a suspension failure, we will /* Try to write the MCU. In event of a suspension failure, we will
* re-DCT the MCU on restart (a bit inefficient, could be fixed...) * re-DCT the MCU on restart (a bit inefficient, could be fixed...)
*/ */
if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) { if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
coef->mcu_ctr = MCU_col_num; coef->mcu_ctr = MCU_col_num;
return FALSE; return FALSE;
} }
} }
/* Completed an MCU row, but perhaps not an iMCU row */ /* Completed an MCU row, but perhaps not an iMCU row */
@@ -280,17 +280,17 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (block_row = 0; block_row < block_rows; block_row++) { for (block_row = 0; block_row < block_rows; block_row++) {
thisblockrow = buffer[block_row]; thisblockrow = buffer[block_row];
(*cinfo->fdct->forward_DCT) (cinfo, compptr, (*cinfo->fdct->forward_DCT) (cinfo, compptr,
input_buf[ci], thisblockrow, input_buf[ci], thisblockrow,
(JDIMENSION) (block_row * DCTSIZE), (JDIMENSION) (block_row * DCTSIZE),
(JDIMENSION) 0, blocks_across); (JDIMENSION) 0, blocks_across);
if (ndummy > 0) { if (ndummy > 0) {
/* Create dummy blocks at the right edge of the image. */ /* Create dummy blocks at the right edge of the image. */
thisblockrow += blocks_across; /* => first dummy block */ thisblockrow += blocks_across; /* => first dummy block */
jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK)); jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
lastDC = thisblockrow[-1][0]; lastDC = thisblockrow[-1][0];
for (bi = 0; bi < ndummy; bi++) { for (bi = 0; bi < ndummy; bi++) {
thisblockrow[bi][0] = lastDC; thisblockrow[bi][0] = lastDC;
} }
} }
} }
/* If at end of image, create dummy block rows as needed. /* If at end of image, create dummy block rows as needed.
@@ -299,22 +299,22 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
* This squeezes a few more bytes out of the resulting file... * This squeezes a few more bytes out of the resulting file...
*/ */
if (coef->iMCU_row_num == last_iMCU_row) { if (coef->iMCU_row_num == last_iMCU_row) {
blocks_across += ndummy; /* include lower right corner */ blocks_across += ndummy; /* include lower right corner */
MCUs_across = blocks_across / h_samp_factor; MCUs_across = blocks_across / h_samp_factor;
for (block_row = block_rows; block_row < compptr->v_samp_factor; for (block_row = block_rows; block_row < compptr->v_samp_factor;
block_row++) { block_row++) {
thisblockrow = buffer[block_row]; thisblockrow = buffer[block_row];
lastblockrow = buffer[block_row-1]; lastblockrow = buffer[block_row-1];
jzero_far((void FAR *) thisblockrow, jzero_far((void FAR *) thisblockrow,
(size_t) (blocks_across * SIZEOF(JBLOCK))); (size_t) (blocks_across * SIZEOF(JBLOCK)));
for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) { for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
lastDC = lastblockrow[h_samp_factor-1][0]; lastDC = lastblockrow[h_samp_factor-1][0];
for (bi = 0; bi < h_samp_factor; bi++) { for (bi = 0; bi < h_samp_factor; bi++) {
thisblockrow[bi][0] = lastDC; thisblockrow[bi][0] = lastDC;
} }
thisblockrow += h_samp_factor; /* advance to next MCU in row */ thisblockrow += h_samp_factor; /* advance to next MCU in row */
lastblockrow += h_samp_factor; lastblockrow += h_samp_factor;
} }
} }
} }
} }
@@ -341,7 +341,7 @@ METHODDEF(boolean)
compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */ JDIMENSION MCU_col_num; /* index of current MCU within row */
int blkn, ci, xindex, yindex, yoffset; int blkn, ci, xindex, yindex, yoffset;
JDIMENSION start_col; JDIMENSION start_col;
JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
@@ -364,25 +364,25 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
yoffset++) { yoffset++) {
for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
MCU_col_num++) { MCU_col_num++) {
/* Construct list of pointers to DCT blocks belonging to this MCU */ /* Construct list of pointers to DCT blocks belonging to this MCU */
blkn = 0; /* index of current DCT block within MCU */ blkn = 0; /* index of current DCT block within MCU */
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
start_col = MCU_col_num * compptr->MCU_width; start_col = MCU_col_num * compptr->MCU_width;
for (yindex = 0; yindex < compptr->MCU_height; yindex++) { for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
buffer_ptr = buffer[ci][yindex+yoffset] + start_col; buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
for (xindex = 0; xindex < compptr->MCU_width; xindex++) { for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
coef->MCU_buffer[blkn++] = buffer_ptr++; coef->MCU_buffer[blkn++] = buffer_ptr++;
} }
} }
} }
/* Try to write the MCU. */ /* Try to write the MCU. */
if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) { if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
coef->mcu_ctr = MCU_col_num; coef->mcu_ctr = MCU_col_num;
return FALSE; return FALSE;
} }
} }
/* Completed an MCU row, but perhaps not an iMCU row */ /* Completed an MCU row, but perhaps not an iMCU row */
@@ -408,7 +408,7 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
coef = (my_coef_ptr) coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_coef_controller)); SIZEOF(my_coef_controller));
cinfo->coef = (struct jpeg_c_coef_controller *) coef; cinfo->coef = (struct jpeg_c_coef_controller *) coef;
coef->pub.start_pass = start_pass_coef; coef->pub.start_pass = start_pass_coef;
@@ -421,14 +421,14 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
jpeg_component_info *compptr; jpeg_component_info *compptr;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
(JDIMENSION) jround_up((long) compptr->width_in_blocks, (JDIMENSION) jround_up((long) compptr->width_in_blocks,
(long) compptr->h_samp_factor), (long) compptr->h_samp_factor),
(JDIMENSION) jround_up((long) compptr->height_in_blocks, (JDIMENSION) jround_up((long) compptr->height_in_blocks,
(long) compptr->v_samp_factor), (long) compptr->v_samp_factor),
(JDIMENSION) compptr->v_samp_factor); (JDIMENSION) compptr->v_samp_factor);
} }
#else #else
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
@@ -440,7 +440,7 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
buffer = (JBLOCKROW) buffer = (JBLOCKROW)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
coef->MCU_buffer[i] = buffer + i; coef->MCU_buffer[i] = buffer + i;
} }

View File

@@ -58,16 +58,16 @@ rgb_ycc_convert_internal (j_compress_ptr cinfo,
*/ */
/* Y */ /* Y */
outptr0[col] = (JSAMPLE) outptr0[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS); >> SCALEBITS);
/* Cb */ /* Cb */
outptr1[col] = (JSAMPLE) outptr1[col] = (JSAMPLE)
((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
>> SCALEBITS); >> SCALEBITS);
/* Cr */ /* Cr */
outptr2[col] = (JSAMPLE) outptr2[col] = (JSAMPLE)
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
>> SCALEBITS); >> SCALEBITS);
} }
} }
} }
@@ -108,8 +108,8 @@ rgb_gray_convert_internal (j_compress_ptr cinfo,
inptr += RGB_PIXELSIZE; inptr += RGB_PIXELSIZE;
/* Y */ /* Y */
outptr[col] = (JSAMPLE) outptr[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS); >> SCALEBITS);
} }
} }
} }

View File

@@ -24,7 +24,7 @@ typedef struct {
struct jpeg_color_converter pub; /* public fields */ struct jpeg_color_converter pub; /* public fields */
/* Private state for RGB->YCC conversion */ /* Private state for RGB->YCC conversion */
INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */ INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
} my_color_converter; } my_color_converter;
typedef my_color_converter * my_cconvert_ptr; typedef my_color_converter * my_cconvert_ptr;
@@ -36,9 +36,9 @@ typedef my_color_converter * my_cconvert_ptr;
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
* The conversion equations to be implemented are therefore * The conversion equations to be implemented are therefore
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
* Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
* Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
* Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2, * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
* rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
@@ -60,10 +60,10 @@ typedef my_color_converter * my_cconvert_ptr;
* in the tables to save adding them separately in the inner loop. * in the tables to save adding them separately in the inner loop.
*/ */
#define SCALEBITS 16 /* speediest right-shift on some machines */ #define SCALEBITS 16 /* speediest right-shift on some machines */
#define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS) #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
/* We allocate one big table and divide it up into eight parts, instead of /* We allocate one big table and divide it up into eight parts, instead of
* doing eight alloc_small requests. This lets us use a single table base * doing eight alloc_small requests. This lets us use a single table base
@@ -71,16 +71,16 @@ typedef my_color_converter * my_cconvert_ptr;
* machines (more than can hold all eight addresses, anyway). * machines (more than can hold all eight addresses, anyway).
*/ */
#define R_Y_OFF 0 /* offset to R => Y section */ #define R_Y_OFF 0 /* offset to R => Y section */
#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
#define R_CB_OFF (3*(MAXJSAMPLE+1)) #define R_CB_OFF (3*(MAXJSAMPLE+1))
#define G_CB_OFF (4*(MAXJSAMPLE+1)) #define G_CB_OFF (4*(MAXJSAMPLE+1))
#define B_CB_OFF (5*(MAXJSAMPLE+1)) #define B_CB_OFF (5*(MAXJSAMPLE+1))
#define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */ #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
#define G_CR_OFF (6*(MAXJSAMPLE+1)) #define G_CR_OFF (6*(MAXJSAMPLE+1))
#define B_CR_OFF (7*(MAXJSAMPLE+1)) #define B_CR_OFF (7*(MAXJSAMPLE+1))
#define TABLE_SIZE (8*(MAXJSAMPLE+1)) #define TABLE_SIZE (8*(MAXJSAMPLE+1))
/* Include inline routines for colorspace extensions */ /* Include inline routines for colorspace extensions */
@@ -202,7 +202,7 @@ rgb_ycc_start (j_compress_ptr cinfo)
/* Allocate and fill in the conversion tables. */ /* Allocate and fill in the conversion tables. */
cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *) cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(TABLE_SIZE * SIZEOF(INT32))); (TABLE_SIZE * SIZEOF(INT32)));
for (i = 0; i <= MAXJSAMPLE; i++) { for (i = 0; i <= MAXJSAMPLE; i++) {
rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i; rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
@@ -230,8 +230,8 @@ rgb_ycc_start (j_compress_ptr cinfo)
METHODDEF(void) METHODDEF(void)
rgb_ycc_convert (j_compress_ptr cinfo, rgb_ycc_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
switch (cinfo->in_color_space) { switch (cinfo->in_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@@ -279,8 +279,8 @@ rgb_ycc_convert (j_compress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
rgb_gray_convert (j_compress_ptr cinfo, rgb_gray_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
switch (cinfo->in_color_space) { switch (cinfo->in_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@@ -325,8 +325,8 @@ rgb_gray_convert (j_compress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
rgb_rgb_convert (j_compress_ptr cinfo, rgb_rgb_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
switch (cinfo->in_color_space) { switch (cinfo->in_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@@ -375,8 +375,8 @@ rgb_rgb_convert (j_compress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
cmyk_ycck_convert (j_compress_ptr cinfo, cmyk_ycck_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b; register int r, g, b;
@@ -398,7 +398,7 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
g = MAXJSAMPLE - GETJSAMPLE(inptr[1]); g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
b = MAXJSAMPLE - GETJSAMPLE(inptr[2]); b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
/* K passes through as-is */ /* K passes through as-is */
outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */ outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
inptr += 4; inptr += 4;
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
* must be too; we do not need an explicit range-limiting operation. * must be too; we do not need an explicit range-limiting operation.
@@ -407,16 +407,16 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
*/ */
/* Y */ /* Y */
outptr0[col] = (JSAMPLE) outptr0[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS); >> SCALEBITS);
/* Cb */ /* Cb */
outptr1[col] = (JSAMPLE) outptr1[col] = (JSAMPLE)
((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
>> SCALEBITS); >> SCALEBITS);
/* Cr */ /* Cr */
outptr2[col] = (JSAMPLE) outptr2[col] = (JSAMPLE)
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
>> SCALEBITS); >> SCALEBITS);
} }
} }
} }
@@ -430,8 +430,8 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
grayscale_convert (j_compress_ptr cinfo, grayscale_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr; register JSAMPROW outptr;
@@ -444,7 +444,7 @@ grayscale_convert (j_compress_ptr cinfo,
outptr = output_buf[0][output_row]; outptr = output_buf[0][output_row];
output_row++; output_row++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */ outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
inptr += instride; inptr += instride;
} }
} }
@@ -459,8 +459,8 @@ grayscale_convert (j_compress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
null_convert (j_compress_ptr cinfo, null_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr; register JSAMPROW outptr;
@@ -475,8 +475,8 @@ null_convert (j_compress_ptr cinfo,
inptr = *input_buf; inptr = *input_buf;
outptr = output_buf[ci][output_row]; outptr = output_buf[ci][output_row];
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */ outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
inptr += nc; inptr += nc;
} }
} }
input_buf++; input_buf++;
@@ -507,7 +507,7 @@ jinit_color_converter (j_compress_ptr cinfo)
cconvert = (my_cconvert_ptr) cconvert = (my_cconvert_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_color_converter)); SIZEOF(my_color_converter));
cinfo->cconvert = (struct jpeg_color_converter *) cconvert; cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
/* set start_pass to null method until we find out differently */ /* set start_pass to null method until we find out differently */
cconvert->pub.start_pass = null_method; cconvert->pub.start_pass = null_method;
@@ -545,7 +545,7 @@ jinit_color_converter (j_compress_ptr cinfo)
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
break; break;
default: /* JCS_UNKNOWN can be anything */ default: /* JCS_UNKNOWN can be anything */
if (cinfo->input_components < 1) if (cinfo->input_components < 1)
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
break; break;
@@ -652,9 +652,9 @@ jinit_color_converter (j_compress_ptr cinfo)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
default: /* allow null conversion of JCS_UNKNOWN */ default: /* allow null conversion of JCS_UNKNOWN */
if (cinfo->jpeg_color_space != cinfo->in_color_space || if (cinfo->jpeg_color_space != cinfo->in_color_space ||
cinfo->num_components != cinfo->input_components) cinfo->num_components != cinfo->input_components)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
cconvert->pub.color_convert = null_convert; cconvert->pub.color_convert = null_convert;
break; break;

View File

@@ -18,7 +18,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#include "jsimddct.h" #include "jsimddct.h"
@@ -44,7 +44,7 @@ typedef JMETHOD(void, float_quantize_method_ptr,
METHODDEF(void) quantize (JCOEFPTR, DCTELEM *, DCTELEM *); METHODDEF(void) quantize (JCOEFPTR, DCTELEM *, DCTELEM *);
typedef struct { typedef struct {
struct jpeg_forward_dct pub; /* public fields */ struct jpeg_forward_dct pub; /* public fields */
/* Pointer to the DCT routine actually in use */ /* Pointer to the DCT routine actually in use */
forward_DCT_method_ptr dct; forward_DCT_method_ptr dct;
@@ -147,7 +147,7 @@ flss (UINT16 val)
* *
* In order to allow SIMD implementations we also tweak the values to * In order to allow SIMD implementations we also tweak the values to
* allow the same calculation to be made at all times: * allow the same calculation to be made at all times:
* *
* dctbl[0] = f rounded to nearest integer * dctbl[0] = f rounded to nearest integer
* dctbl[1] = divisor / 2 (+ 1 if fractional part of f < 0.5) * dctbl[1] = divisor / 2 (+ 1 if fractional part of f < 0.5)
* dctbl[2] = 1 << ((word size) * 2 - r) * dctbl[2] = 1 << ((word size) * 2 - r)
@@ -221,7 +221,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
qtblno = compptr->quant_tbl_no; qtblno = compptr->quant_tbl_no;
/* Make sure specified quantization table is present */ /* Make sure specified quantization table is present */
if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
cinfo->quant_tbl_ptrs[qtblno] == NULL) cinfo->quant_tbl_ptrs[qtblno] == NULL)
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
qtbl = cinfo->quant_tbl_ptrs[qtblno]; qtbl = cinfo->quant_tbl_ptrs[qtblno];
/* Compute divisors for this quant table */ /* Compute divisors for this quant table */
@@ -233,91 +233,91 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
* coefficients multiplied by 8 (to counteract scaling). * coefficients multiplied by 8 (to counteract scaling).
*/ */
if (fdct->divisors[qtblno] == NULL) { if (fdct->divisors[qtblno] == NULL) {
fdct->divisors[qtblno] = (DCTELEM *) fdct->divisors[qtblno] = (DCTELEM *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(DCTSIZE2 * 4) * SIZEOF(DCTELEM)); (DCTSIZE2 * 4) * SIZEOF(DCTELEM));
} }
dtbl = fdct->divisors[qtblno]; dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
if(!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) if(!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i])
&& fdct->quantize == jsimd_quantize) && fdct->quantize == jsimd_quantize)
fdct->quantize = quantize; fdct->quantize = quantize;
} }
break; break;
#endif #endif
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
case JDCT_IFAST: case JDCT_IFAST:
{ {
/* For AA&N IDCT method, divisors are equal to quantization /* For AA&N IDCT method, divisors are equal to quantization
* coefficients scaled by scalefactor[row]*scalefactor[col], where * coefficients scaled by scalefactor[row]*scalefactor[col], where
* scalefactor[0] = 1 * scalefactor[0] = 1
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
* We apply a further scale factor of 8. * We apply a further scale factor of 8.
*/ */
#define CONST_BITS 14 #define CONST_BITS 14
static const INT16 aanscales[DCTSIZE2] = { static const INT16 aanscales[DCTSIZE2] = {
/* precomputed values scaled up by 14 bits */ /* precomputed values scaled up by 14 bits */
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
}; };
SHIFT_TEMPS SHIFT_TEMPS
if (fdct->divisors[qtblno] == NULL) { if (fdct->divisors[qtblno] == NULL) {
fdct->divisors[qtblno] = (DCTELEM *) fdct->divisors[qtblno] = (DCTELEM *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(DCTSIZE2 * 4) * SIZEOF(DCTELEM)); (DCTSIZE2 * 4) * SIZEOF(DCTELEM));
} }
dtbl = fdct->divisors[qtblno]; dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
if(!compute_reciprocal( if(!compute_reciprocal(
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
(INT32) aanscales[i]), (INT32) aanscales[i]),
CONST_BITS-3), &dtbl[i]) CONST_BITS-3), &dtbl[i])
&& fdct->quantize == jsimd_quantize) && fdct->quantize == jsimd_quantize)
fdct->quantize = quantize; fdct->quantize = quantize;
} }
} }
break; break;
#endif #endif
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
case JDCT_FLOAT: case JDCT_FLOAT:
{ {
/* For float AA&N IDCT method, divisors are equal to quantization /* For float AA&N IDCT method, divisors are equal to quantization
* coefficients scaled by scalefactor[row]*scalefactor[col], where * coefficients scaled by scalefactor[row]*scalefactor[col], where
* scalefactor[0] = 1 * scalefactor[0] = 1
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
* We apply a further scale factor of 8. * We apply a further scale factor of 8.
* What's actually stored is 1/divisor so that the inner loop can * What's actually stored is 1/divisor so that the inner loop can
* use a multiplication rather than a division. * use a multiplication rather than a division.
*/ */
FAST_FLOAT * fdtbl; FAST_FLOAT * fdtbl;
int row, col; int row, col;
static const double aanscalefactor[DCTSIZE] = { static const double aanscalefactor[DCTSIZE] = {
1.0, 1.387039845, 1.306562965, 1.175875602, 1.0, 1.387039845, 1.306562965, 1.175875602,
1.0, 0.785694958, 0.541196100, 0.275899379 1.0, 0.785694958, 0.541196100, 0.275899379
}; };
if (fdct->float_divisors[qtblno] == NULL) { if (fdct->float_divisors[qtblno] == NULL) {
fdct->float_divisors[qtblno] = (FAST_FLOAT *) fdct->float_divisors[qtblno] = (FAST_FLOAT *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
DCTSIZE2 * SIZEOF(FAST_FLOAT)); DCTSIZE2 * SIZEOF(FAST_FLOAT));
} }
fdtbl = fdct->float_divisors[qtblno]; fdtbl = fdct->float_divisors[qtblno];
i = 0; i = 0;
for (row = 0; row < DCTSIZE; row++) { for (row = 0; row < DCTSIZE; row++) {
for (col = 0; col < DCTSIZE; col++) { for (col = 0; col < DCTSIZE; col++) {
fdtbl[i] = (FAST_FLOAT) fdtbl[i] = (FAST_FLOAT)
(1.0 / (((double) qtbl->quantval[i] * (1.0 / (((double) qtbl->quantval[i] *
aanscalefactor[row] * aanscalefactor[col] * 8.0))); aanscalefactor[row] * aanscalefactor[col] * 8.0)));
i++; i++;
} }
} }
} }
break; break;
#endif #endif
@@ -344,7 +344,7 @@ convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, DCTELEM * workspace)
for (elemr = 0; elemr < DCTSIZE; elemr++) { for (elemr = 0; elemr < DCTSIZE; elemr++) {
elemptr = sample_data[elemr] + start_col; elemptr = sample_data[elemr] + start_col;
#if DCTSIZE == 8 /* unroll the inner loop */ #if DCTSIZE == 8 /* unroll the inner loop */
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE; *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
@@ -410,9 +410,9 @@ quantize (JCOEFPTR coef_block, DCTELEM * divisors, DCTELEM * workspace)
METHODDEF(void) METHODDEF(void)
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr, forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col, JDIMENSION start_row, JDIMENSION start_col,
JDIMENSION num_blocks) JDIMENSION num_blocks)
/* This version is used for integer DCT implementations. */ /* This version is used for integer DCT implementations. */
{ {
/* This routine is heavily used, so it's worth coding it tightly. */ /* This routine is heavily used, so it's worth coding it tightly. */
@@ -427,7 +427,7 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
quantize_method_ptr do_quantize = fdct->quantize; quantize_method_ptr do_quantize = fdct->quantize;
workspace = fdct->workspace; workspace = fdct->workspace;
sample_data += start_row; /* fold in the vertical offset once */ sample_data += start_row; /* fold in the vertical offset once */
for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) { for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
/* Load data into workspace, applying unsigned->signed conversion */ /* Load data into workspace, applying unsigned->signed conversion */
@@ -455,7 +455,7 @@ convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, FAST_FLOAT * works
workspaceptr = workspace; workspaceptr = workspace;
for (elemr = 0; elemr < DCTSIZE; elemr++) { for (elemr = 0; elemr < DCTSIZE; elemr++) {
elemptr = sample_data[elemr] + start_col; elemptr = sample_data[elemr] + start_col;
#if DCTSIZE == 8 /* unroll the inner loop */ #if DCTSIZE == 8 /* unroll the inner loop */
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE); *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
@@ -500,9 +500,9 @@ quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors, FAST_FLOAT * workspa
METHODDEF(void) METHODDEF(void)
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr, forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col, JDIMENSION start_row, JDIMENSION start_col,
JDIMENSION num_blocks) JDIMENSION num_blocks)
/* This version is used for floating-point DCT implementations. */ /* This version is used for floating-point DCT implementations. */
{ {
/* This routine is heavily used, so it's worth coding it tightly. */ /* This routine is heavily used, so it's worth coding it tightly. */
@@ -518,7 +518,7 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
float_quantize_method_ptr do_quantize = fdct->float_quantize; float_quantize_method_ptr do_quantize = fdct->float_quantize;
workspace = fdct->float_workspace; workspace = fdct->float_workspace;
sample_data += start_row; /* fold in the vertical offset once */ sample_data += start_row; /* fold in the vertical offset once */
for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) { for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
/* Load data into workspace, applying unsigned->signed conversion */ /* Load data into workspace, applying unsigned->signed conversion */
@@ -547,7 +547,7 @@ jinit_forward_dct (j_compress_ptr cinfo)
fdct = (my_fdct_ptr) fdct = (my_fdct_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_fdct_controller)); SIZEOF(my_fdct_controller));
cinfo->fdct = (struct jpeg_forward_dct *) fdct; cinfo->fdct = (struct jpeg_forward_dct *) fdct;
fdct->pub.start_pass = start_pass_fdctmgr; fdct->pub.start_pass = start_pass_fdctmgr;
@@ -626,12 +626,12 @@ jinit_forward_dct (j_compress_ptr cinfo)
if (cinfo->dct_method == JDCT_FLOAT) if (cinfo->dct_method == JDCT_FLOAT)
fdct->float_workspace = (FAST_FLOAT *) fdct->float_workspace = (FAST_FLOAT *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(FAST_FLOAT) * DCTSIZE2); SIZEOF(FAST_FLOAT) * DCTSIZE2);
else else
#endif #endif
fdct->workspace = (DCTELEM *) fdct->workspace = (DCTELEM *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(DCTELEM) * DCTSIZE2); SIZEOF(DCTELEM) * DCTSIZE2);
/* Mark divisor tables unallocated */ /* Mark divisor tables unallocated */
for (i = 0; i < NUM_QUANT_TBLS; i++) { for (i = 0; i < NUM_QUANT_TBLS; i++) {

202
jchuff.c
View File

@@ -19,7 +19,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jchuff.h" /* Declarations shared with jcphuff.c */ #include "jchuff.h" /* Declarations shared with jcphuff.c */
#include <limits.h> #include <limits.h>
static unsigned char jpeg_nbits_table[65536]; static unsigned char jpeg_nbits_table[65536];
@@ -37,8 +37,8 @@ static int jpeg_nbits_table_init = 0;
*/ */
typedef struct { typedef struct {
size_t put_buffer; /* current bit-accumulation buffer */ size_t put_buffer; /* current bit-accumulation buffer */
int put_bits; /* # of bits now in it */ int put_bits; /* # of bits now in it */
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
} savable_state; } savable_state;
@@ -52,12 +52,12 @@ typedef struct {
#else #else
#if MAX_COMPS_IN_SCAN == 4 #if MAX_COMPS_IN_SCAN == 4
#define ASSIGN_STATE(dest,src) \ #define ASSIGN_STATE(dest,src) \
((dest).put_buffer = (src).put_buffer, \ ((dest).put_buffer = (src).put_buffer, \
(dest).put_bits = (src).put_bits, \ (dest).put_bits = (src).put_bits, \
(dest).last_dc_val[0] = (src).last_dc_val[0], \ (dest).last_dc_val[0] = (src).last_dc_val[0], \
(dest).last_dc_val[1] = (src).last_dc_val[1], \ (dest).last_dc_val[1] = (src).last_dc_val[1], \
(dest).last_dc_val[2] = (src).last_dc_val[2], \ (dest).last_dc_val[2] = (src).last_dc_val[2], \
(dest).last_dc_val[3] = (src).last_dc_val[3]) (dest).last_dc_val[3] = (src).last_dc_val[3])
#endif #endif
#endif #endif
@@ -65,17 +65,17 @@ typedef struct {
typedef struct { typedef struct {
struct jpeg_entropy_encoder pub; /* public fields */ struct jpeg_entropy_encoder pub; /* public fields */
savable_state saved; /* Bit buffer & DC state at start of MCU */ savable_state saved; /* Bit buffer & DC state at start of MCU */
/* These fields are NOT loaded into local working state. */ /* These fields are NOT loaded into local working state. */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
int next_restart_num; /* next restart number to write (0-7) */ int next_restart_num; /* next restart number to write (0-7) */
/* Pointers to derived tables (these workspaces have image lifespan) */ /* Pointers to derived tables (these workspaces have image lifespan) */
c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]; c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS]; c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
#ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */ #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
long * dc_count_ptrs[NUM_HUFF_TBLS]; long * dc_count_ptrs[NUM_HUFF_TBLS];
long * ac_count_ptrs[NUM_HUFF_TBLS]; long * ac_count_ptrs[NUM_HUFF_TBLS];
#endif #endif
@@ -88,20 +88,20 @@ typedef huff_entropy_encoder * huff_entropy_ptr;
*/ */
typedef struct { typedef struct {
JOCTET * next_output_byte; /* => next byte to write in buffer */ JOCTET * next_output_byte; /* => next byte to write in buffer */
size_t free_in_buffer; /* # of byte spaces remaining in buffer */ size_t free_in_buffer; /* # of byte spaces remaining in buffer */
savable_state cur; /* Current bit buffer & DC state */ savable_state cur; /* Current bit buffer & DC state */
j_compress_ptr cinfo; /* dump_buffer needs access to this */ j_compress_ptr cinfo; /* dump_buffer needs access to this */
} working_state; } working_state;
/* Forward declarations */ /* Forward declarations */
METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo)); METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
#ifdef ENTROPY_OPT_SUPPORTED #ifdef ENTROPY_OPT_SUPPORTED
METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo)); METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
#endif #endif
@@ -140,29 +140,29 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
/* Check for invalid table indexes */ /* Check for invalid table indexes */
/* (make_c_derived_tbl does this in the other path) */ /* (make_c_derived_tbl does this in the other path) */
if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS) if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl); ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
if (actbl < 0 || actbl >= NUM_HUFF_TBLS) if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl); ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
/* Allocate and zero the statistics tables */ /* Allocate and zero the statistics tables */
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
if (entropy->dc_count_ptrs[dctbl] == NULL) if (entropy->dc_count_ptrs[dctbl] == NULL)
entropy->dc_count_ptrs[dctbl] = (long *) entropy->dc_count_ptrs[dctbl] = (long *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
257 * SIZEOF(long)); 257 * SIZEOF(long));
MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long)); MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
if (entropy->ac_count_ptrs[actbl] == NULL) if (entropy->ac_count_ptrs[actbl] == NULL)
entropy->ac_count_ptrs[actbl] = (long *) entropy->ac_count_ptrs[actbl] = (long *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
257 * SIZEOF(long)); 257 * SIZEOF(long));
MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long)); MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
#endif #endif
} else { } else {
/* Compute derived values for Huffman tables */ /* Compute derived values for Huffman tables */
/* We may do this more than once for a table, but it's not expensive */ /* We may do this more than once for a table, but it's not expensive */
jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl, jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
& entropy->dc_derived_tbls[dctbl]); & entropy->dc_derived_tbls[dctbl]);
jpeg_make_c_derived_tbl(cinfo, FALSE, actbl, jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
& entropy->ac_derived_tbls[actbl]); & entropy->ac_derived_tbls[actbl]);
} }
/* Initialize DC predictions to 0 */ /* Initialize DC predictions to 0 */
entropy->saved.last_dc_val[ci] = 0; entropy->saved.last_dc_val[ci] = 0;
@@ -187,7 +187,7 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
GLOBAL(void) GLOBAL(void)
jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno, jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
c_derived_tbl ** pdtbl) c_derived_tbl ** pdtbl)
{ {
JHUFF_TBL *htbl; JHUFF_TBL *htbl;
c_derived_tbl *dtbl; c_derived_tbl *dtbl;
@@ -212,22 +212,22 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
if (*pdtbl == NULL) if (*pdtbl == NULL)
*pdtbl = (c_derived_tbl *) *pdtbl = (c_derived_tbl *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(c_derived_tbl)); SIZEOF(c_derived_tbl));
dtbl = *pdtbl; dtbl = *pdtbl;
/* Figure C.1: make table of Huffman code length for each symbol */ /* Figure C.1: make table of Huffman code length for each symbol */
p = 0; p = 0;
for (l = 1; l <= 16; l++) { for (l = 1; l <= 16; l++) {
i = (int) htbl->bits[l]; i = (int) htbl->bits[l];
if (i < 0 || p + i > 256) /* protect against table overrun */ if (i < 0 || p + i > 256) /* protect against table overrun */
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
while (i--) while (i--)
huffsize[p++] = (char) l; huffsize[p++] = (char) l;
} }
huffsize[p] = 0; huffsize[p] = 0;
lastp = p; lastp = p;
/* Figure C.2: generate the codes themselves */ /* Figure C.2: generate the codes themselves */
/* We also validate that the counts represent a legal Huffman code tree. */ /* We also validate that the counts represent a legal Huffman code tree. */
@@ -247,7 +247,7 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
code <<= 1; code <<= 1;
si++; si++;
} }
/* Figure C.3: generate encoding tables */ /* Figure C.3: generate encoding tables */
/* These are code and size indexed by symbol value */ /* These are code and size indexed by symbol value */
@@ -287,10 +287,10 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
/* Emit a byte, taking 'action' if must suspend. */ /* Emit a byte, taking 'action' if must suspend. */
#define emit_byte(state,val,action) \ #define emit_byte(state,val,action) \
{ *(state)->next_output_byte++ = (JOCTET) (val); \ { *(state)->next_output_byte++ = (JOCTET) (val); \
if (--(state)->free_in_buffer == 0) \ if (--(state)->free_in_buffer == 0) \
if (! dump_buffer(state)) \ if (! dump_buffer(state)) \
{ action; } } { action; } }
LOCAL(boolean) LOCAL(boolean)
@@ -438,7 +438,7 @@ flush_bits (working_state * state)
PUT_BITS(0x7F, 7) PUT_BITS(0x7F, 7)
while (put_bits >= 8) EMIT_BYTE() while (put_bits >= 8) EMIT_BYTE()
state->cur.put_buffer = 0; /* and reset bit-buffer to empty */ state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
state->cur.put_bits = 0; state->cur.put_bits = 0;
STORE_BUFFER() STORE_BUFFER()
@@ -450,7 +450,7 @@ flush_bits (working_state * state)
LOCAL(boolean) LOCAL(boolean)
encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val, encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
c_derived_tbl *dctbl, c_derived_tbl *actbl) c_derived_tbl *dctbl, c_derived_tbl *actbl)
{ {
int temp, temp2, temp3; int temp, temp2, temp3;
int nbits; int nbits;
@@ -465,7 +465,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
LOAD_BUFFER() LOAD_BUFFER()
/* Encode the DC coefficient difference per section F.1.2.1 */ /* Encode the DC coefficient difference per section F.1.2.1 */
temp = temp2 = block[0] - last_dc_val; temp = temp2 = block[0] - last_dc_val;
/* This is a well-known technique for obtaining the absolute value without a /* This is a well-known technique for obtaining the absolute value without a
@@ -499,8 +499,8 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
CHECKBUF15() CHECKBUF15()
/* Encode the AC coefficients per section F.1.2.2 */ /* Encode the AC coefficients per section F.1.2.2 */
r = 0; /* r = run length of zeros */ r = 0; /* r = run length of zeros */
/* Manually unroll the k loop to eliminate the counter variable. This /* Manually unroll the k loop to eliminate the counter variable. This
* improves performance greatly on systems with a limited number of * improves performance greatly on systems with a limited number of
@@ -606,7 +606,7 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! emit_restart(&state, entropy->next_restart_num)) if (! emit_restart(&state, entropy->next_restart_num))
return FALSE; return FALSE;
} }
/* Encode the MCU data blocks */ /* Encode the MCU data blocks */
@@ -614,9 +614,9 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
ci = cinfo->MCU_membership[blkn]; ci = cinfo->MCU_membership[blkn];
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
if (! encode_one_block(&state, if (! encode_one_block(&state,
MCU_data[blkn][0], state.cur.last_dc_val[ci], MCU_data[blkn][0], state.cur.last_dc_val[ci],
entropy->dc_derived_tbls[compptr->dc_tbl_no], entropy->dc_derived_tbls[compptr->dc_tbl_no],
entropy->ac_derived_tbls[compptr->ac_tbl_no])) entropy->ac_derived_tbls[compptr->ac_tbl_no]))
return FALSE; return FALSE;
/* Update last_dc_val */ /* Update last_dc_val */
state.cur.last_dc_val[ci] = MCU_data[blkn][0][0]; state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
@@ -686,18 +686,18 @@ finish_pass_huff (j_compress_ptr cinfo)
LOCAL(void) LOCAL(void)
htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val, htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
long dc_counts[], long ac_counts[]) long dc_counts[], long ac_counts[])
{ {
register int temp; register int temp;
register int nbits; register int nbits;
register int k, r; register int k, r;
/* Encode the DC coefficient difference per section F.1.2.1 */ /* Encode the DC coefficient difference per section F.1.2.1 */
temp = block[0] - last_dc_val; temp = block[0] - last_dc_val;
if (temp < 0) if (temp < 0)
temp = -temp; temp = -temp;
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
nbits = 0; nbits = 0;
while (temp) { while (temp) {
@@ -712,36 +712,36 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
/* Count the Huffman symbol for the number of bits */ /* Count the Huffman symbol for the number of bits */
dc_counts[nbits]++; dc_counts[nbits]++;
/* Encode the AC coefficients per section F.1.2.2 */ /* Encode the AC coefficients per section F.1.2.2 */
r = 0; /* r = run length of zeros */ r = 0; /* r = run length of zeros */
for (k = 1; k < DCTSIZE2; k++) { for (k = 1; k < DCTSIZE2; k++) {
if ((temp = block[jpeg_natural_order[k]]) == 0) { if ((temp = block[jpeg_natural_order[k]]) == 0) {
r++; r++;
} else { } else {
/* if run length > 15, must emit special run-length-16 codes (0xF0) */ /* if run length > 15, must emit special run-length-16 codes (0xF0) */
while (r > 15) { while (r > 15) {
ac_counts[0xF0]++; ac_counts[0xF0]++;
r -= 16; r -= 16;
} }
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
if (temp < 0) if (temp < 0)
temp = -temp; temp = -temp;
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
nbits = 1; /* there must be at least one 1 bit */ nbits = 1; /* there must be at least one 1 bit */
while ((temp >>= 1)) while ((temp >>= 1))
nbits++; nbits++;
/* Check for out-of-range coefficient values */ /* Check for out-of-range coefficient values */
if (nbits > MAX_COEF_BITS) if (nbits > MAX_COEF_BITS)
ERREXIT(cinfo, JERR_BAD_DCT_COEF); ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count Huffman symbol for run length / number of bits */ /* Count Huffman symbol for run length / number of bits */
ac_counts[(r << 4) + nbits]++; ac_counts[(r << 4) + nbits]++;
r = 0; r = 0;
} }
} }
@@ -769,7 +769,7 @@ encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
if (entropy->restarts_to_go == 0) { if (entropy->restarts_to_go == 0) {
/* Re-initialize DC predictions to 0 */ /* Re-initialize DC predictions to 0 */
for (ci = 0; ci < cinfo->comps_in_scan; ci++) for (ci = 0; ci < cinfo->comps_in_scan; ci++)
entropy->saved.last_dc_val[ci] = 0; entropy->saved.last_dc_val[ci] = 0;
/* Update restart state */ /* Update restart state */
entropy->restarts_to_go = cinfo->restart_interval; entropy->restarts_to_go = cinfo->restart_interval;
} }
@@ -780,8 +780,8 @@ encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
ci = cinfo->MCU_membership[blkn]; ci = cinfo->MCU_membership[blkn];
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci], htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
entropy->dc_count_ptrs[compptr->dc_tbl_no], entropy->dc_count_ptrs[compptr->dc_tbl_no],
entropy->ac_count_ptrs[compptr->ac_tbl_no]); entropy->ac_count_ptrs[compptr->ac_tbl_no]);
entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0]; entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
} }
@@ -820,10 +820,10 @@ encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
GLOBAL(void) GLOBAL(void)
jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]) jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
{ {
#define MAX_CLEN 32 /* assumed maximum initial code length */ #define MAX_CLEN 32 /* assumed maximum initial code length */
UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */ UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
int codesize[257]; /* codesize[k] = code length of symbol k */ int codesize[257]; /* codesize[k] = code length of symbol k */
int others[257]; /* next symbol in current branch of tree */ int others[257]; /* next symbol in current branch of tree */
int c1, c2; int c1, c2;
int p, i, j; int p, i, j;
long v; long v;
@@ -833,9 +833,9 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
MEMZERO(bits, SIZEOF(bits)); MEMZERO(bits, SIZEOF(bits));
MEMZERO(codesize, SIZEOF(codesize)); MEMZERO(codesize, SIZEOF(codesize));
for (i = 0; i < 257; i++) for (i = 0; i < 257; i++)
others[i] = -1; /* init links to empty */ others[i] = -1; /* init links to empty */
freq[256] = 1; /* make sure 256 has a nonzero count */ freq[256] = 1; /* make sure 256 has a nonzero count */
/* Including the pseudo-symbol 256 in the Huffman procedure guarantees /* Including the pseudo-symbol 256 in the Huffman procedure guarantees
* that no real symbol is given code-value of all ones, because 256 * that no real symbol is given code-value of all ones, because 256
* will be placed last in the largest codeword category. * will be placed last in the largest codeword category.
@@ -850,8 +850,8 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
v = 1000000000L; v = 1000000000L;
for (i = 0; i <= 256; i++) { for (i = 0; i <= 256; i++) {
if (freq[i] && freq[i] <= v) { if (freq[i] && freq[i] <= v) {
v = freq[i]; v = freq[i];
c1 = i; c1 = i;
} }
} }
@@ -861,15 +861,15 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
v = 1000000000L; v = 1000000000L;
for (i = 0; i <= 256; i++) { for (i = 0; i <= 256; i++) {
if (freq[i] && freq[i] <= v && i != c1) { if (freq[i] && freq[i] <= v && i != c1) {
v = freq[i]; v = freq[i];
c2 = i; c2 = i;
} }
} }
/* Done if we've merged everything into one frequency */ /* Done if we've merged everything into one frequency */
if (c2 < 0) if (c2 < 0)
break; break;
/* Else merge the two counts/trees */ /* Else merge the two counts/trees */
freq[c1] += freq[c2]; freq[c1] += freq[c2];
freq[c2] = 0; freq[c2] = 0;
@@ -880,9 +880,9 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
c1 = others[c1]; c1 = others[c1];
codesize[c1]++; codesize[c1]++;
} }
others[c1] = c2; /* chain c2 onto c1's tree branch */ others[c1] = c2; /* chain c2 onto c1's tree branch */
/* Increment the codesize of everything in c2's tree branch */ /* Increment the codesize of everything in c2's tree branch */
codesize[c2]++; codesize[c2]++;
while (others[c2] >= 0) { while (others[c2] >= 0) {
@@ -897,7 +897,7 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
/* The JPEG standard seems to think that this can't happen, */ /* The JPEG standard seems to think that this can't happen, */
/* but I'm paranoid... */ /* but I'm paranoid... */
if (codesize[i] > MAX_CLEN) if (codesize[i] > MAX_CLEN)
ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW); ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
bits[codesize[i]]++; bits[codesize[i]]++;
} }
@@ -913,28 +913,28 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
* shortest nonzero BITS entry is converted into a prefix for two code words * shortest nonzero BITS entry is converted into a prefix for two code words
* one bit longer. * one bit longer.
*/ */
for (i = MAX_CLEN; i > 16; i--) { for (i = MAX_CLEN; i > 16; i--) {
while (bits[i] > 0) { while (bits[i] > 0) {
j = i - 2; /* find length of new prefix to be used */ j = i - 2; /* find length of new prefix to be used */
while (bits[j] == 0) while (bits[j] == 0)
j--; j--;
bits[i] -= 2; /* remove two symbols */ bits[i] -= 2; /* remove two symbols */
bits[i-1]++; /* one goes in this length */ bits[i-1]++; /* one goes in this length */
bits[j+1] += 2; /* two new symbols in this length */ bits[j+1] += 2; /* two new symbols in this length */
bits[j]--; /* symbol of this length is now a prefix */ bits[j]--; /* symbol of this length is now a prefix */
} }
} }
/* Remove the count for the pseudo-symbol 256 from the largest codelength */ /* Remove the count for the pseudo-symbol 256 from the largest codelength */
while (bits[i] == 0) /* find largest codelength still in use */ while (bits[i] == 0) /* find largest codelength still in use */
i--; i--;
bits[i]--; bits[i]--;
/* Return final symbol counts (only for lengths 0..16) */ /* Return final symbol counts (only for lengths 0..16) */
MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits)); MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
/* Return a list of the symbols sorted by code length */ /* Return a list of the symbols sorted by code length */
/* It's not real clear to me why we don't need to consider the codelength /* It's not real clear to me why we don't need to consider the codelength
* changes made above, but the JPEG spec seems to think this works. * changes made above, but the JPEG spec seems to think this works.
@@ -943,8 +943,8 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
for (i = 1; i <= MAX_CLEN; i++) { for (i = 1; i <= MAX_CLEN; i++) {
for (j = 0; j <= 255; j++) { for (j = 0; j <= 255; j++) {
if (codesize[j] == i) { if (codesize[j] == i) {
htbl->huffval[p] = (UINT8) j; htbl->huffval[p] = (UINT8) j;
p++; p++;
} }
} }
} }
@@ -981,14 +981,14 @@ finish_pass_gather (j_compress_ptr cinfo)
if (! did_dc[dctbl]) { if (! did_dc[dctbl]) {
htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl]; htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
if (*htblptr == NULL) if (*htblptr == NULL)
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]); jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
did_dc[dctbl] = TRUE; did_dc[dctbl] = TRUE;
} }
if (! did_ac[actbl]) { if (! did_ac[actbl]) {
htblptr = & cinfo->ac_huff_tbl_ptrs[actbl]; htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
if (*htblptr == NULL) if (*htblptr == NULL)
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]); jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
did_ac[actbl] = TRUE; did_ac[actbl] = TRUE;
} }
@@ -1011,7 +1011,7 @@ jinit_huff_encoder (j_compress_ptr cinfo)
entropy = (huff_entropy_ptr) entropy = (huff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(huff_entropy_encoder)); SIZEOF(huff_entropy_encoder));
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
entropy->pub.start_pass = start_pass_huff; entropy->pub.start_pass = start_pass_huff;

View File

@@ -25,23 +25,23 @@
/* Derived data constructed for each Huffman table */ /* Derived data constructed for each Huffman table */
typedef struct { typedef struct {
unsigned int ehufco[256]; /* code for each symbol */ unsigned int ehufco[256]; /* code for each symbol */
char ehufsi[256]; /* length of code for each symbol */ char ehufsi[256]; /* length of code for each symbol */
/* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */ /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */
} c_derived_tbl; } c_derived_tbl;
/* Short forms of external names for systems with brain-damaged linkers. */ /* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES #ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_make_c_derived_tbl jMkCDerived #define jpeg_make_c_derived_tbl jMkCDerived
#define jpeg_gen_optimal_table jGenOptTbl #define jpeg_gen_optimal_table jGenOptTbl
#endif /* NEED_SHORT_EXTERNAL_NAMES */ #endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Expand a Huffman table definition into the derived format */ /* Expand a Huffman table definition into the derived format */
EXTERN(void) jpeg_make_c_derived_tbl EXTERN(void) jpeg_make_c_derived_tbl
JPP((j_compress_ptr cinfo, boolean isDC, int tblno, JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
c_derived_tbl ** pdtbl)); c_derived_tbl ** pdtbl));
/* Generate an optimal table definition given the specified counts */ /* Generate an optimal table definition given the specified counts */
EXTERN(void) jpeg_gen_optimal_table EXTERN(void) jpeg_gen_optimal_table
JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])); JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));

View File

@@ -60,7 +60,7 @@ jinit_compress_master (j_compress_ptr cinfo)
/* Need a full-image coefficient buffer in any multi-pass mode. */ /* Need a full-image coefficient buffer in any multi-pass mode. */
jinit_c_coef_controller(cinfo, jinit_c_coef_controller(cinfo,
(boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding)); (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */); jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
jinit_marker_writer(cinfo); jinit_marker_writer(cinfo);

View File

@@ -28,10 +28,10 @@
typedef struct { typedef struct {
struct jpeg_c_main_controller pub; /* public fields */ struct jpeg_c_main_controller pub; /* public fields */
JDIMENSION cur_iMCU_row; /* number of current iMCU row */ JDIMENSION cur_iMCU_row; /* number of current iMCU row */
JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */ JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
boolean suspended; /* remember if we suspended output */ boolean suspended; /* remember if we suspended output */
J_BUF_MODE pass_mode; /* current operating mode */ J_BUF_MODE pass_mode; /* current operating mode */
/* If using just a strip buffer, this points to the entire set of buffers /* If using just a strip buffer, this points to the entire set of buffers
* (we allocate one for each component). In the full-image case, this * (we allocate one for each component). In the full-image case, this
@@ -52,12 +52,12 @@ typedef my_main_controller * my_main_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(void) process_data_simple_main METHODDEF(void) process_data_simple_main
JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)); JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
#ifdef FULL_MAIN_BUFFER_SUPPORTED #ifdef FULL_MAIN_BUFFER_SUPPORTED
METHODDEF(void) process_data_buffer_main METHODDEF(void) process_data_buffer_main
JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)); JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
#endif #endif
@@ -74,10 +74,10 @@ start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
if (cinfo->raw_data_in) if (cinfo->raw_data_in)
return; return;
main_ptr->cur_iMCU_row = 0; /* initialize counters */ main_ptr->cur_iMCU_row = 0; /* initialize counters */
main_ptr->rowgroup_ctr = 0; main_ptr->rowgroup_ctr = 0;
main_ptr->suspended = FALSE; main_ptr->suspended = FALSE;
main_ptr->pass_mode = pass_mode; /* save mode for use by process_data */ main_ptr->pass_mode = pass_mode; /* save mode for use by process_data */
switch (pass_mode) { switch (pass_mode) {
case JBUF_PASS_THRU: case JBUF_PASS_THRU:
@@ -111,8 +111,8 @@ start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
METHODDEF(void) METHODDEF(void)
process_data_simple_main (j_compress_ptr cinfo, process_data_simple_main (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
JDIMENSION in_rows_avail) JDIMENSION in_rows_avail)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
@@ -120,9 +120,9 @@ process_data_simple_main (j_compress_ptr cinfo,
/* Read input data if we haven't filled the main buffer yet */ /* Read input data if we haven't filled the main buffer yet */
if (main_ptr->rowgroup_ctr < DCTSIZE) if (main_ptr->rowgroup_ctr < DCTSIZE)
(*cinfo->prep->pre_process_data) (cinfo, (*cinfo->prep->pre_process_data) (cinfo,
input_buf, in_row_ctr, in_rows_avail, input_buf, in_row_ctr, in_rows_avail,
main_ptr->buffer, &main_ptr->rowgroup_ctr, main_ptr->buffer, &main_ptr->rowgroup_ctr,
(JDIMENSION) DCTSIZE); (JDIMENSION) DCTSIZE);
/* If we don't have a full iMCU row buffered, return to application for /* If we don't have a full iMCU row buffered, return to application for
* more data. Note that preprocessor will always pad to fill the iMCU row * more data. Note that preprocessor will always pad to fill the iMCU row
@@ -140,8 +140,8 @@ process_data_simple_main (j_compress_ptr cinfo,
* think we were done. * think we were done.
*/ */
if (! main_ptr->suspended) { if (! main_ptr->suspended) {
(*in_row_ctr)--; (*in_row_ctr)--;
main_ptr->suspended = TRUE; main_ptr->suspended = TRUE;
} }
return; return;
} }
@@ -167,8 +167,8 @@ process_data_simple_main (j_compress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
process_data_buffer_main (j_compress_ptr cinfo, process_data_buffer_main (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
JDIMENSION in_rows_avail) JDIMENSION in_rows_avail)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
int ci; int ci;
@@ -179,16 +179,16 @@ process_data_buffer_main (j_compress_ptr cinfo,
/* Realign the virtual buffers if at the start of an iMCU row. */ /* Realign the virtual buffers if at the start of an iMCU row. */
if (main_ptr->rowgroup_ctr == 0) { if (main_ptr->rowgroup_ctr == 0) {
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
main_ptr->buffer[ci] = (*cinfo->mem->access_virt_sarray) main_ptr->buffer[ci] = (*cinfo->mem->access_virt_sarray)
((j_common_ptr) cinfo, main_ptr->whole_image[ci], ((j_common_ptr) cinfo, main_ptr->whole_image[ci],
main_ptr->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE), main_ptr->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing); (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
} }
/* In a read pass, pretend we just read some source data. */ /* In a read pass, pretend we just read some source data. */
if (! writing) { if (! writing) {
*in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE; *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
main_ptr->rowgroup_ctr = DCTSIZE; main_ptr->rowgroup_ctr = DCTSIZE;
} }
} }
@@ -196,35 +196,35 @@ process_data_buffer_main (j_compress_ptr cinfo,
/* Note: preprocessor will pad if necessary to fill the last iMCU row. */ /* Note: preprocessor will pad if necessary to fill the last iMCU row. */
if (writing) { if (writing) {
(*cinfo->prep->pre_process_data) (cinfo, (*cinfo->prep->pre_process_data) (cinfo,
input_buf, in_row_ctr, in_rows_avail, input_buf, in_row_ctr, in_rows_avail,
main_ptr->buffer, &main_ptr->rowgroup_ctr, main_ptr->buffer, &main_ptr->rowgroup_ctr,
(JDIMENSION) DCTSIZE); (JDIMENSION) DCTSIZE);
/* Return to application if we need more data to fill the iMCU row. */ /* Return to application if we need more data to fill the iMCU row. */
if (main_ptr->rowgroup_ctr < DCTSIZE) if (main_ptr->rowgroup_ctr < DCTSIZE)
return; return;
} }
/* Emit data, unless this is a sink-only pass. */ /* Emit data, unless this is a sink-only pass. */
if (main_ptr->pass_mode != JBUF_SAVE_SOURCE) { if (main_ptr->pass_mode != JBUF_SAVE_SOURCE) {
if (! (*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) { if (! (*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) {
/* If compressor did not consume the whole row, then we must need to /* If compressor did not consume the whole row, then we must need to
* suspend processing and return to the application. In this situation * suspend processing and return to the application. In this situation
* we pretend we didn't yet consume the last input row; otherwise, if * we pretend we didn't yet consume the last input row; otherwise, if
* it happened to be the last row of the image, the application would * it happened to be the last row of the image, the application would
* think we were done. * think we were done.
*/ */
if (! main_ptr->suspended) { if (! main_ptr->suspended) {
(*in_row_ctr)--; (*in_row_ctr)--;
main_ptr->suspended = TRUE; main_ptr->suspended = TRUE;
} }
return; return;
} }
/* We did finish the row. Undo our little suspension hack if a previous /* We did finish the row. Undo our little suspension hack if a previous
* call suspended; then mark the main buffer empty. * call suspended; then mark the main buffer empty.
*/ */
if (main_ptr->suspended) { if (main_ptr->suspended) {
(*in_row_ctr)++; (*in_row_ctr)++;
main_ptr->suspended = FALSE; main_ptr->suspended = FALSE;
} }
} }
@@ -250,7 +250,7 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
main_ptr = (my_main_ptr) main_ptr = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_main_controller)); SIZEOF(my_main_controller));
cinfo->main = (struct jpeg_c_main_controller *) main_ptr; cinfo->main = (struct jpeg_c_main_controller *) main_ptr;
main_ptr->pub.start_pass = start_pass_main; main_ptr->pub.start_pass = start_pass_main;
@@ -266,13 +266,13 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
/* Allocate a full-image virtual array for each component */ /* Allocate a full-image virtual array for each component */
/* Note we pad the bottom to a multiple of the iMCU height */ /* Note we pad the bottom to a multiple of the iMCU height */
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
main_ptr->whole_image[ci] = (*cinfo->mem->request_virt_sarray) main_ptr->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
compptr->width_in_blocks * DCTSIZE, compptr->width_in_blocks * DCTSIZE,
(JDIMENSION) jround_up((long) compptr->height_in_blocks, (JDIMENSION) jround_up((long) compptr->height_in_blocks,
(long) compptr->v_samp_factor) * DCTSIZE, (long) compptr->v_samp_factor) * DCTSIZE,
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE)); (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
} }
#else #else
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
@@ -283,11 +283,11 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
#endif #endif
/* Allocate a strip buffer for each component */ /* Allocate a strip buffer for each component */
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray) main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
compptr->width_in_blocks * DCTSIZE, compptr->width_in_blocks * DCTSIZE,
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE)); (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
} }
} }
} }

View File

@@ -17,7 +17,7 @@
#include "jpegcomp.h" #include "jpegcomp.h"
typedef enum { /* JPEG marker codes */ typedef enum { /* JPEG marker codes */
M_SOF0 = 0xc0, M_SOF0 = 0xc0,
M_SOF1 = 0xc1, M_SOF1 = 0xc1,
M_SOF2 = 0xc2, M_SOF2 = 0xc2,
@@ -173,7 +173,7 @@ emit_dqt (j_compress_ptr cinfo, int index)
/* The table entries must be emitted in zigzag order. */ /* The table entries must be emitted in zigzag order. */
unsigned int qval = qtbl->quantval[jpeg_natural_order[i]]; unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
if (prec) if (prec)
emit_byte(cinfo, (int) (qval >> 8)); emit_byte(cinfo, (int) (qval >> 8));
emit_byte(cinfo, (int) (qval & 0xFF)); emit_byte(cinfo, (int) (qval & 0xFF));
} }
@@ -190,33 +190,33 @@ emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
{ {
JHUFF_TBL * htbl; JHUFF_TBL * htbl;
int length, i; int length, i;
if (is_ac) { if (is_ac) {
htbl = cinfo->ac_huff_tbl_ptrs[index]; htbl = cinfo->ac_huff_tbl_ptrs[index];
index += 0x10; /* output index has AC bit set */ index += 0x10; /* output index has AC bit set */
} else { } else {
htbl = cinfo->dc_huff_tbl_ptrs[index]; htbl = cinfo->dc_huff_tbl_ptrs[index];
} }
if (htbl == NULL) if (htbl == NULL)
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index); ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
if (! htbl->sent_table) { if (! htbl->sent_table) {
emit_marker(cinfo, M_DHT); emit_marker(cinfo, M_DHT);
length = 0; length = 0;
for (i = 1; i <= 16; i++) for (i = 1; i <= 16; i++)
length += htbl->bits[i]; length += htbl->bits[i];
emit_2bytes(cinfo, length + 2 + 1 + 16); emit_2bytes(cinfo, length + 2 + 1 + 16);
emit_byte(cinfo, index); emit_byte(cinfo, index);
for (i = 1; i <= 16; i++) for (i = 1; i <= 16; i++)
emit_byte(cinfo, htbl->bits[i]); emit_byte(cinfo, htbl->bits[i]);
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
emit_byte(cinfo, htbl->huffval[i]); emit_byte(cinfo, htbl->huffval[i]);
htbl->sent_table = TRUE; htbl->sent_table = TRUE;
} }
} }
@@ -258,12 +258,12 @@ emit_dac (j_compress_ptr cinfo)
for (i = 0; i < NUM_ARITH_TBLS; i++) { for (i = 0; i < NUM_ARITH_TBLS; i++) {
if (dc_in_use[i]) { if (dc_in_use[i]) {
emit_byte(cinfo, i); emit_byte(cinfo, i);
emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4)); emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
} }
if (ac_in_use[i]) { if (ac_in_use[i]) {
emit_byte(cinfo, i + 0x10); emit_byte(cinfo, i + 0x10);
emit_byte(cinfo, cinfo->arith_ac_K[i]); emit_byte(cinfo, cinfo->arith_ac_K[i]);
} }
} }
} }
@@ -276,8 +276,8 @@ emit_dri (j_compress_ptr cinfo)
/* Emit a DRI marker */ /* Emit a DRI marker */
{ {
emit_marker(cinfo, M_DRI); emit_marker(cinfo, M_DRI);
emit_2bytes(cinfo, 4); /* fixed length */ emit_2bytes(cinfo, 4); /* fixed length */
emit_2bytes(cinfo, (int) cinfo->restart_interval); emit_2bytes(cinfo, (int) cinfo->restart_interval);
} }
@@ -289,9 +289,9 @@ emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
{ {
int ci; int ci;
jpeg_component_info *compptr; jpeg_component_info *compptr;
emit_marker(cinfo, code); emit_marker(cinfo, code);
emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */ emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
/* Make sure image isn't bigger than SOF field can handle */ /* Make sure image isn't bigger than SOF field can handle */
@@ -320,13 +320,13 @@ emit_sos (j_compress_ptr cinfo)
{ {
int i, td, ta; int i, td, ta;
jpeg_component_info *compptr; jpeg_component_info *compptr;
emit_marker(cinfo, M_SOS); emit_marker(cinfo, M_SOS);
emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */ emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
emit_byte(cinfo, cinfo->comps_in_scan); emit_byte(cinfo, cinfo->comps_in_scan);
for (i = 0; i < cinfo->comps_in_scan; i++) { for (i = 0; i < cinfo->comps_in_scan; i++) {
compptr = cinfo->cur_comp_info[i]; compptr = cinfo->cur_comp_info[i];
emit_byte(cinfo, compptr->component_id); emit_byte(cinfo, compptr->component_id);
@@ -354,22 +354,22 @@ emit_jfif_app0 (j_compress_ptr cinfo)
/* Emit a JFIF-compliant APP0 marker */ /* Emit a JFIF-compliant APP0 marker */
{ {
/* /*
* Length of APP0 block (2 bytes) * Length of APP0 block (2 bytes)
* Block ID (4 bytes - ASCII "JFIF") * Block ID (4 bytes - ASCII "JFIF")
* Zero byte (1 byte to terminate the ID string) * Zero byte (1 byte to terminate the ID string)
* Version Major, Minor (2 bytes - major first) * Version Major, Minor (2 bytes - major first)
* Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm) * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
* Xdpu (2 bytes - dots per unit horizontal) * Xdpu (2 bytes - dots per unit horizontal)
* Ydpu (2 bytes - dots per unit vertical) * Ydpu (2 bytes - dots per unit vertical)
* Thumbnail X size (1 byte) * Thumbnail X size (1 byte)
* Thumbnail Y size (1 byte) * Thumbnail Y size (1 byte)
*/ */
emit_marker(cinfo, M_APP0); emit_marker(cinfo, M_APP0);
emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */ emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */ emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
emit_byte(cinfo, 0x46); emit_byte(cinfo, 0x46);
emit_byte(cinfo, 0x49); emit_byte(cinfo, 0x49);
emit_byte(cinfo, 0x46); emit_byte(cinfo, 0x46);
@@ -379,7 +379,7 @@ emit_jfif_app0 (j_compress_ptr cinfo)
emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */ emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
emit_2bytes(cinfo, (int) cinfo->X_density); emit_2bytes(cinfo, (int) cinfo->X_density);
emit_2bytes(cinfo, (int) cinfo->Y_density); emit_2bytes(cinfo, (int) cinfo->Y_density);
emit_byte(cinfo, 0); /* No thumbnail image */ emit_byte(cinfo, 0); /* No thumbnail image */
emit_byte(cinfo, 0); emit_byte(cinfo, 0);
} }
@@ -389,12 +389,12 @@ emit_adobe_app14 (j_compress_ptr cinfo)
/* Emit an Adobe APP14 marker */ /* Emit an Adobe APP14 marker */
{ {
/* /*
* Length of APP14 block (2 bytes) * Length of APP14 block (2 bytes)
* Block ID (5 bytes - ASCII "Adobe") * Block ID (5 bytes - ASCII "Adobe")
* Version Number (2 bytes - currently 100) * Version Number (2 bytes - currently 100)
* Flags0 (2 bytes - currently 0) * Flags0 (2 bytes - currently 0)
* Flags1 (2 bytes - currently 0) * Flags1 (2 bytes - currently 0)
* Color transform (1 byte) * Color transform (1 byte)
* *
* Although Adobe TN 5116 mentions Version = 101, all the Adobe files * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
* now in circulation seem to use Version = 100, so that's what we write. * now in circulation seem to use Version = 100, so that's what we write.
@@ -403,28 +403,28 @@ emit_adobe_app14 (j_compress_ptr cinfo)
* YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with
* whether the encoder performed a transformation, which is pretty useless. * whether the encoder performed a transformation, which is pretty useless.
*/ */
emit_marker(cinfo, M_APP14); emit_marker(cinfo, M_APP14);
emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */ emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */ emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
emit_byte(cinfo, 0x64); emit_byte(cinfo, 0x64);
emit_byte(cinfo, 0x6F); emit_byte(cinfo, 0x6F);
emit_byte(cinfo, 0x62); emit_byte(cinfo, 0x62);
emit_byte(cinfo, 0x65); emit_byte(cinfo, 0x65);
emit_2bytes(cinfo, 100); /* Version */ emit_2bytes(cinfo, 100); /* Version */
emit_2bytes(cinfo, 0); /* Flags0 */ emit_2bytes(cinfo, 0); /* Flags0 */
emit_2bytes(cinfo, 0); /* Flags1 */ emit_2bytes(cinfo, 0); /* Flags1 */
switch (cinfo->jpeg_color_space) { switch (cinfo->jpeg_color_space) {
case JCS_YCbCr: case JCS_YCbCr:
emit_byte(cinfo, 1); /* Color transform = 1 */ emit_byte(cinfo, 1); /* Color transform = 1 */
break; break;
case JCS_YCCK: case JCS_YCCK:
emit_byte(cinfo, 2); /* Color transform = 2 */ emit_byte(cinfo, 2); /* Color transform = 2 */
break; break;
default: default:
emit_byte(cinfo, 0); /* Color transform = 0 */ emit_byte(cinfo, 0); /* Color transform = 0 */
break; break;
} }
} }
@@ -442,12 +442,12 @@ METHODDEF(void)
write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen) write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
/* Emit an arbitrary marker header */ /* Emit an arbitrary marker header */
{ {
if (datalen > (unsigned int) 65533) /* safety check */ if (datalen > (unsigned int) 65533) /* safety check */
ERREXIT(cinfo, JERR_BAD_LENGTH); ERREXIT(cinfo, JERR_BAD_LENGTH);
emit_marker(cinfo, (JPEG_MARKER) marker); emit_marker(cinfo, (JPEG_MARKER) marker);
emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */ emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
} }
METHODDEF(void) METHODDEF(void)
@@ -474,12 +474,12 @@ write_file_header (j_compress_ptr cinfo)
{ {
my_marker_ptr marker = (my_marker_ptr) cinfo->marker; my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
emit_marker(cinfo, M_SOI); /* first the SOI */ emit_marker(cinfo, M_SOI); /* first the SOI */
/* SOI is defined to reset restart interval to 0 */ /* SOI is defined to reset restart interval to 0 */
marker->last_restart_interval = 0; marker->last_restart_interval = 0;
if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */ if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
emit_jfif_app0(cinfo); emit_jfif_app0(cinfo);
if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */ if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
emit_adobe_app14(cinfo); emit_adobe_app14(cinfo);
@@ -500,7 +500,7 @@ write_frame_header (j_compress_ptr cinfo)
int ci, prec; int ci, prec;
boolean is_baseline; boolean is_baseline;
jpeg_component_info *compptr; jpeg_component_info *compptr;
/* Emit DQT for each quantization table. /* Emit DQT for each quantization table.
* Note that emit_dqt() suppresses any duplicate tables. * Note that emit_dqt() suppresses any duplicate tables.
*/ */
@@ -520,9 +520,9 @@ write_frame_header (j_compress_ptr cinfo)
} else { } else {
is_baseline = TRUE; is_baseline = TRUE;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1) if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
is_baseline = FALSE; is_baseline = FALSE;
} }
if (prec && is_baseline) { if (prec && is_baseline) {
is_baseline = FALSE; is_baseline = FALSE;
@@ -539,11 +539,11 @@ write_frame_header (j_compress_ptr cinfo)
emit_sof(cinfo, M_SOF9); /* SOF code for sequential arithmetic */ emit_sof(cinfo, M_SOF9); /* SOF code for sequential arithmetic */
} else { } else {
if (cinfo->progressive_mode) if (cinfo->progressive_mode)
emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */ emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
else if (is_baseline) else if (is_baseline)
emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */ emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
else else
emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */ emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
} }
} }
@@ -575,10 +575,10 @@ write_scan_header (j_compress_ptr cinfo)
compptr = cinfo->cur_comp_info[i]; compptr = cinfo->cur_comp_info[i];
/* DC needs no table for refinement scan */ /* DC needs no table for refinement scan */
if (cinfo->Ss == 0 && cinfo->Ah == 0) if (cinfo->Ss == 0 && cinfo->Ah == 0)
emit_dht(cinfo, compptr->dc_tbl_no, FALSE); emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
/* AC needs no table when not present */ /* AC needs no table when not present */
if (cinfo->Se) if (cinfo->Se)
emit_dht(cinfo, compptr->ac_tbl_no, TRUE); emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
} }
} }
@@ -627,9 +627,9 @@ write_tables_only (j_compress_ptr cinfo)
if (! cinfo->arith_code) { if (! cinfo->arith_code) {
for (i = 0; i < NUM_HUFF_TBLS; i++) { for (i = 0; i < NUM_HUFF_TBLS; i++) {
if (cinfo->dc_huff_tbl_ptrs[i] != NULL) if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
emit_dht(cinfo, i, FALSE); emit_dht(cinfo, i, FALSE);
if (cinfo->ac_huff_tbl_ptrs[i] != NULL) if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
emit_dht(cinfo, i, TRUE); emit_dht(cinfo, i, TRUE);
} }
} }
@@ -649,7 +649,7 @@ jinit_marker_writer (j_compress_ptr cinfo)
/* Create the subobject */ /* Create the subobject */
marker = (my_marker_ptr) marker = (my_marker_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_marker_writer)); SIZEOF(my_marker_writer));
cinfo->marker = (struct jpeg_marker_writer *) marker; cinfo->marker = (struct jpeg_marker_writer *) marker;
/* Initialize method pointers */ /* Initialize method pointers */
marker->pub.write_file_header = write_file_header; marker->pub.write_file_header = write_file_header;

View File

@@ -10,7 +10,7 @@
* *
* This file contains master control logic for the JPEG compressor. * This file contains master control logic for the JPEG compressor.
* These routines are concerned with parameter validation, initial setup, * These routines are concerned with parameter validation, initial setup,
* and inter-pass control (determining the number of passes and the work * and inter-pass control (determining the number of passes and the work
* to be done in each pass). * to be done in each pass).
*/ */
@@ -23,20 +23,20 @@
/* Private state */ /* Private state */
typedef enum { typedef enum {
main_pass, /* input data, also do first output step */ main_pass, /* input data, also do first output step */
huff_opt_pass, /* Huffman code optimization pass */ huff_opt_pass, /* Huffman code optimization pass */
output_pass /* data output pass */ output_pass /* data output pass */
} c_pass_type; } c_pass_type;
typedef struct { typedef struct {
struct jpeg_comp_master pub; /* public fields */ struct jpeg_comp_master pub; /* public fields */
c_pass_type pass_type; /* the type of the current pass */ c_pass_type pass_type; /* the type of the current pass */
int pass_number; /* # of passes completed */ int pass_number; /* # of passes completed */
int total_passes; /* total # of passes needed */ int total_passes; /* total # of passes needed */
int scan_number; /* current index in scan_info[] */ int scan_number; /* current index in scan_info[] */
} my_comp_master; } my_comp_master;
typedef my_comp_master * my_master_ptr; typedef my_comp_master * my_master_ptr;
@@ -105,7 +105,7 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
/* Check that number of components won't exceed internal array sizes */ /* Check that number of components won't exceed internal array sizes */
if (cinfo->num_components > MAX_COMPONENTS) if (cinfo->num_components > MAX_COMPONENTS)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
MAX_COMPONENTS); MAX_COMPONENTS);
/* Compute maximum sampling factors; check factor validity */ /* Compute maximum sampling factors; check factor validity */
cinfo->max_h_samp_factor = 1; cinfo->max_h_samp_factor = 1;
@@ -113,12 +113,12 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
ERREXIT(cinfo, JERR_BAD_SAMPLING); ERREXIT(cinfo, JERR_BAD_SAMPLING);
cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
compptr->h_samp_factor); compptr->h_samp_factor);
cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
compptr->v_samp_factor); compptr->v_samp_factor);
} }
/* Compute dimensions of components */ /* Compute dimensions of components */
@@ -135,17 +135,17 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
/* Size in DCT blocks */ /* Size in DCT blocks */
compptr->width_in_blocks = (JDIMENSION) compptr->width_in_blocks = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor, jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor,
(long) (cinfo->max_h_samp_factor * DCTSIZE)); (long) (cinfo->max_h_samp_factor * DCTSIZE));
compptr->height_in_blocks = (JDIMENSION) compptr->height_in_blocks = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor, jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor,
(long) (cinfo->max_v_samp_factor * DCTSIZE)); (long) (cinfo->max_v_samp_factor * DCTSIZE));
/* Size in samples */ /* Size in samples */
compptr->downsampled_width = (JDIMENSION) compptr->downsampled_width = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor, jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor,
(long) cinfo->max_h_samp_factor); (long) cinfo->max_h_samp_factor);
compptr->downsampled_height = (JDIMENSION) compptr->downsampled_height = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor, jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor,
(long) cinfo->max_v_samp_factor); (long) cinfo->max_v_samp_factor);
/* Mark component needed (this flag isn't actually used for compression) */ /* Mark component needed (this flag isn't actually used for compression) */
compptr->component_needed = TRUE; compptr->component_needed = TRUE;
} }
@@ -155,7 +155,7 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
*/ */
cinfo->total_iMCU_rows = (JDIMENSION) cinfo->total_iMCU_rows = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_height, jdiv_round_up((long) cinfo->_jpeg_height,
(long) (cinfo->max_v_samp_factor*DCTSIZE)); (long) (cinfo->max_v_samp_factor*DCTSIZE));
} }
@@ -188,15 +188,15 @@ validate_script (j_compress_ptr cinfo)
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
cinfo->progressive_mode = TRUE; cinfo->progressive_mode = TRUE;
last_bitpos_ptr = & last_bitpos[0][0]; last_bitpos_ptr = & last_bitpos[0][0];
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
for (coefi = 0; coefi < DCTSIZE2; coefi++) for (coefi = 0; coefi < DCTSIZE2; coefi++)
*last_bitpos_ptr++ = -1; *last_bitpos_ptr++ = -1;
#else #else
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif #endif
} else { } else {
cinfo->progressive_mode = FALSE; cinfo->progressive_mode = FALSE;
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
component_sent[ci] = FALSE; component_sent[ci] = FALSE;
} }
@@ -208,10 +208,10 @@ validate_script (j_compress_ptr cinfo)
for (ci = 0; ci < ncomps; ci++) { for (ci = 0; ci < ncomps; ci++) {
thisi = scanptr->component_index[ci]; thisi = scanptr->component_index[ci];
if (thisi < 0 || thisi >= cinfo->num_components) if (thisi < 0 || thisi >= cinfo->num_components)
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
/* Components must appear in SOF order within each scan */ /* Components must appear in SOF order within each scan */
if (ci > 0 && thisi <= scanptr->component_index[ci-1]) if (ci > 0 && thisi <= scanptr->component_index[ci-1])
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
} }
/* Validate progression parameters */ /* Validate progression parameters */
Ss = scanptr->Ss; Ss = scanptr->Ss;
@@ -233,43 +233,43 @@ validate_script (j_compress_ptr cinfo)
#define MAX_AH_AL 13 #define MAX_AH_AL 13
#endif #endif
if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 || if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL) Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
if (Ss == 0) { if (Ss == 0) {
if (Se != 0) /* DC and AC together not OK */ if (Se != 0) /* DC and AC together not OK */
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
} else { } else {
if (ncomps != 1) /* AC scans must be for only one component */ if (ncomps != 1) /* AC scans must be for only one component */
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
} }
for (ci = 0; ci < ncomps; ci++) { for (ci = 0; ci < ncomps; ci++) {
last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0]; last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */ if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
for (coefi = Ss; coefi <= Se; coefi++) { for (coefi = Ss; coefi <= Se; coefi++) {
if (last_bitpos_ptr[coefi] < 0) { if (last_bitpos_ptr[coefi] < 0) {
/* first scan of this coefficient */ /* first scan of this coefficient */
if (Ah != 0) if (Ah != 0)
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
} else { } else {
/* not first scan */ /* not first scan */
if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1) if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
} }
last_bitpos_ptr[coefi] = Al; last_bitpos_ptr[coefi] = Al;
} }
} }
#endif #endif
} else { } else {
/* For sequential JPEG, all progression parameters must be these: */ /* For sequential JPEG, all progression parameters must be these: */
if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0) if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
/* Make sure components are not sent twice */ /* Make sure components are not sent twice */
for (ci = 0; ci < ncomps; ci++) { for (ci = 0; ci < ncomps; ci++) {
thisi = scanptr->component_index[ci]; thisi = scanptr->component_index[ci];
if (component_sent[thisi]) if (component_sent[thisi])
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
component_sent[thisi] = TRUE; component_sent[thisi] = TRUE;
} }
} }
} }
@@ -284,13 +284,13 @@ validate_script (j_compress_ptr cinfo)
*/ */
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
if (last_bitpos[ci][0] < 0) if (last_bitpos[ci][0] < 0)
ERREXIT(cinfo, JERR_MISSING_DATA); ERREXIT(cinfo, JERR_MISSING_DATA);
} }
#endif #endif
} else { } else {
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
if (! component_sent[ci]) if (! component_sent[ci])
ERREXIT(cinfo, JERR_MISSING_DATA); ERREXIT(cinfo, JERR_MISSING_DATA);
} }
} }
} }
@@ -313,7 +313,7 @@ select_scan_parameters (j_compress_ptr cinfo)
cinfo->comps_in_scan = scanptr->comps_in_scan; cinfo->comps_in_scan = scanptr->comps_in_scan;
for (ci = 0; ci < scanptr->comps_in_scan; ci++) { for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
cinfo->cur_comp_info[ci] = cinfo->cur_comp_info[ci] =
&cinfo->comp_info[scanptr->component_index[ci]]; &cinfo->comp_info[scanptr->component_index[ci]];
} }
cinfo->Ss = scanptr->Ss; cinfo->Ss = scanptr->Ss;
cinfo->Se = scanptr->Se; cinfo->Se = scanptr->Se;
@@ -326,7 +326,7 @@ select_scan_parameters (j_compress_ptr cinfo)
/* Prepare for single sequential-JPEG scan containing all components */ /* Prepare for single sequential-JPEG scan containing all components */
if (cinfo->num_components > MAX_COMPS_IN_SCAN) if (cinfo->num_components > MAX_COMPS_IN_SCAN)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
MAX_COMPS_IN_SCAN); MAX_COMPS_IN_SCAN);
cinfo->comps_in_scan = cinfo->num_components; cinfo->comps_in_scan = cinfo->num_components;
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci]; cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
@@ -346,16 +346,16 @@ per_scan_setup (j_compress_ptr cinfo)
{ {
int ci, mcublks, tmp; int ci, mcublks, tmp;
jpeg_component_info *compptr; jpeg_component_info *compptr;
if (cinfo->comps_in_scan == 1) { if (cinfo->comps_in_scan == 1) {
/* Noninterleaved (single-component) scan */ /* Noninterleaved (single-component) scan */
compptr = cinfo->cur_comp_info[0]; compptr = cinfo->cur_comp_info[0];
/* Overall image size in MCUs */ /* Overall image size in MCUs */
cinfo->MCUs_per_row = compptr->width_in_blocks; cinfo->MCUs_per_row = compptr->width_in_blocks;
cinfo->MCU_rows_in_scan = compptr->height_in_blocks; cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
/* For noninterleaved scan, always one block per MCU */ /* For noninterleaved scan, always one block per MCU */
compptr->MCU_width = 1; compptr->MCU_width = 1;
compptr->MCU_height = 1; compptr->MCU_height = 1;
@@ -368,28 +368,28 @@ per_scan_setup (j_compress_ptr cinfo)
tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
if (tmp == 0) tmp = compptr->v_samp_factor; if (tmp == 0) tmp = compptr->v_samp_factor;
compptr->last_row_height = tmp; compptr->last_row_height = tmp;
/* Prepare array describing MCU composition */ /* Prepare array describing MCU composition */
cinfo->blocks_in_MCU = 1; cinfo->blocks_in_MCU = 1;
cinfo->MCU_membership[0] = 0; cinfo->MCU_membership[0] = 0;
} else { } else {
/* Interleaved (multi-component) scan */ /* Interleaved (multi-component) scan */
if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
MAX_COMPS_IN_SCAN); MAX_COMPS_IN_SCAN);
/* Overall image size in MCUs */ /* Overall image size in MCUs */
cinfo->MCUs_per_row = (JDIMENSION) cinfo->MCUs_per_row = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_width, jdiv_round_up((long) cinfo->_jpeg_width,
(long) (cinfo->max_h_samp_factor*DCTSIZE)); (long) (cinfo->max_h_samp_factor*DCTSIZE));
cinfo->MCU_rows_in_scan = (JDIMENSION) cinfo->MCU_rows_in_scan = (JDIMENSION)
jdiv_round_up((long) cinfo->_jpeg_height, jdiv_round_up((long) cinfo->_jpeg_height,
(long) (cinfo->max_v_samp_factor*DCTSIZE)); (long) (cinfo->max_v_samp_factor*DCTSIZE));
cinfo->blocks_in_MCU = 0; cinfo->blocks_in_MCU = 0;
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
/* Sampling factors give # of blocks of component in each MCU */ /* Sampling factors give # of blocks of component in each MCU */
@@ -407,12 +407,12 @@ per_scan_setup (j_compress_ptr cinfo)
/* Prepare array describing MCU composition */ /* Prepare array describing MCU composition */
mcublks = compptr->MCU_blocks; mcublks = compptr->MCU_blocks;
if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU) if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
ERREXIT(cinfo, JERR_BAD_MCU_SIZE); ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
while (mcublks-- > 0) { while (mcublks-- > 0) {
cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
} }
} }
} }
/* Convert restart specified in rows to actual MCU count. */ /* Convert restart specified in rows to actual MCU count. */
@@ -452,8 +452,8 @@ prepare_for_pass (j_compress_ptr cinfo)
(*cinfo->fdct->start_pass) (cinfo); (*cinfo->fdct->start_pass) (cinfo);
(*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding); (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
(*cinfo->coef->start_pass) (cinfo, (*cinfo->coef->start_pass) (cinfo,
(master->total_passes > 1 ? (master->total_passes > 1 ?
JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
(*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
if (cinfo->optimize_coding) { if (cinfo->optimize_coding) {
/* No immediate data output; postpone writing frame/scan headers */ /* No immediate data output; postpone writing frame/scan headers */
@@ -581,7 +581,7 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
master = (my_master_ptr) master = (my_master_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_comp_master)); SIZEOF(my_comp_master));
cinfo->master = (struct jpeg_comp_master *) master; cinfo->master = (struct jpeg_comp_master *) master;
master->pub.prepare_for_pass = prepare_for_pass; master->pub.prepare_for_pass = prepare_for_pass;
master->pub.pass_startup = pass_startup; master->pub.pass_startup = pass_startup;
@@ -602,7 +602,7 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
cinfo->num_scans = 1; cinfo->num_scans = 1;
} }
if (cinfo->progressive_mode && !cinfo->arith_code) /* TEMPORARY HACK ??? */ if (cinfo->progressive_mode && !cinfo->arith_code) /* TEMPORARY HACK ??? */
cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */ cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
/* Initialize my private state */ /* Initialize my private state */

View File

@@ -72,8 +72,8 @@ jpeg_destroy (j_common_ptr cinfo)
/* NB: mem pointer is NULL if memory mgr failed to initialize. */ /* NB: mem pointer is NULL if memory mgr failed to initialize. */
if (cinfo->mem != NULL) if (cinfo->mem != NULL)
(*cinfo->mem->self_destruct) (cinfo); (*cinfo->mem->self_destruct) (cinfo);
cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */ cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
cinfo->global_state = 0; /* mark it destroyed */ cinfo->global_state = 0; /* mark it destroyed */
} }
@@ -89,7 +89,7 @@ jpeg_alloc_quant_table (j_common_ptr cinfo)
tbl = (JQUANT_TBL *) tbl = (JQUANT_TBL *)
(*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL)); (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
tbl->sent_table = FALSE; /* make sure this is false in any new table */ tbl->sent_table = FALSE; /* make sure this is false in any new table */
return tbl; return tbl;
} }
@@ -101,6 +101,6 @@ jpeg_alloc_huff_table (j_common_ptr cinfo)
tbl = (JHUFF_TBL *) tbl = (JHUFF_TBL *)
(*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL)); (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
tbl->sent_table = FALSE; /* make sure this is false in any new table */ tbl->sent_table = FALSE; /* make sure this is false in any new table */
return tbl; return tbl;
} }

View File

@@ -94,10 +94,10 @@
/* Define "boolean" as unsigned char, not int, on Windows systems. /* Define "boolean" as unsigned char, not int, on Windows systems.
*/ */
#ifdef _WIN32 #ifdef _WIN32
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean; typedef unsigned char boolean;
#endif #endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif #endif
@@ -130,11 +130,11 @@ typedef unsigned char boolean;
/* These defines indicate which image (non-JPEG) file formats are allowed. */ /* These defines indicate which image (non-JPEG) file formats are allowed. */
#define BMP_SUPPORTED /* BMP image file format */ #define BMP_SUPPORTED /* BMP image file format */
#define GIF_SUPPORTED /* GIF image file format */ #define GIF_SUPPORTED /* GIF image file format */
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
#undef RLE_SUPPORTED /* Utah RLE image file format */ #undef RLE_SUPPORTED /* Utah RLE image file format */
#define TARGA_SUPPORTED /* Targa image file format */ #define TARGA_SUPPORTED /* Targa image file format */
/* Define this if you want to name both input and output files on the command /* Define this if you want to name both input and output files on the command
* line, rather than using stdout and optionally stdin. You MUST do this if * line, rather than using stdout and optionally stdin. You MUST do this if

View File

@@ -24,8 +24,8 @@
GLOBAL(void) GLOBAL(void)
jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
const unsigned int *basic_table, const unsigned int *basic_table,
int scale_factor, boolean force_baseline) int scale_factor, boolean force_baseline)
/* Define a quantization table equal to the basic_table times /* Define a quantization table equal to the basic_table times
* a scale factor (given as a percentage). * a scale factor (given as a percentage).
* If force_baseline is TRUE, the computed quantization table entries * If force_baseline is TRUE, the computed quantization table entries
@@ -54,7 +54,7 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
if (temp <= 0L) temp = 1L; if (temp <= 0L) temp = 1L;
if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */ if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
if (force_baseline && temp > 255L) if (force_baseline && temp > 255L)
temp = 255L; /* limit to baseline range if requested */ temp = 255L; /* limit to baseline range if requested */
(*qtblptr)->quantval[i] = (UINT16) temp; (*qtblptr)->quantval[i] = (UINT16) temp;
} }
@@ -99,16 +99,16 @@ jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
{ {
/* Set up two quantization tables using the specified scaling */ /* Set up two quantization tables using the specified scaling */
jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
cinfo->q_scale_factor[0], force_baseline); cinfo->q_scale_factor[0], force_baseline);
jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
cinfo->q_scale_factor[1], force_baseline); cinfo->q_scale_factor[1], force_baseline);
} }
#endif #endif
GLOBAL(void) GLOBAL(void)
jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
boolean force_baseline) boolean force_baseline)
/* Set or change the 'quality' (quantization) setting, using default tables /* Set or change the 'quality' (quantization) setting, using default tables
* and a straight percentage-scaling quality scale. In most cases it's better * and a straight percentage-scaling quality scale. In most cases it's better
* to use jpeg_set_quality (below); this entry point is provided for * to use jpeg_set_quality (below); this entry point is provided for
@@ -117,9 +117,9 @@ jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
{ {
/* Set up two quantization tables using the specified scaling */ /* Set up two quantization tables using the specified scaling */
jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
scale_factor, force_baseline); scale_factor, force_baseline);
jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
scale_factor, force_baseline); scale_factor, force_baseline);
} }
@@ -301,12 +301,12 @@ jpeg_set_defaults (j_compress_ptr cinfo)
if (cinfo->comp_info == NULL) if (cinfo->comp_info == NULL)
cinfo->comp_info = (jpeg_component_info *) cinfo->comp_info = (jpeg_component_info *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
MAX_COMPONENTS * SIZEOF(jpeg_component_info)); MAX_COMPONENTS * SIZEOF(jpeg_component_info));
/* Initialize everything not dependent on the color space */ /* Initialize everything not dependent on the color space */
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
cinfo->scale_num = 1; /* 1:1 scaling */ cinfo->scale_num = 1; /* 1:1 scaling */
cinfo->scale_denom = 1; cinfo->scale_denom = 1;
#endif #endif
cinfo->data_precision = BITS_IN_JSAMPLE; cinfo->data_precision = BITS_IN_JSAMPLE;
@@ -371,8 +371,8 @@ jpeg_set_defaults (j_compress_ptr cinfo)
*/ */
cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */ cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
cinfo->JFIF_minor_version = 1; cinfo->JFIF_minor_version = 1;
cinfo->density_unit = 0; /* Pixel size is unknown by default */ cinfo->density_unit = 0; /* Pixel size is unknown by default */
cinfo->X_density = 1; /* Pixel aspect ratio is square by default */ cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
cinfo->Y_density = 1; cinfo->Y_density = 1;
/* Choose JPEG colorspace based on input space, set defaults accordingly */ /* Choose JPEG colorspace based on input space, set defaults accordingly */
@@ -498,7 +498,7 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
cinfo->num_components = cinfo->input_components; cinfo->num_components = cinfo->input_components;
if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS) if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
MAX_COMPONENTS); MAX_COMPONENTS);
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
SET_COMP(ci, ci, 1,1, 0, 0,0); SET_COMP(ci, ci, 1,1, 0, 0,0);
} }
@@ -513,7 +513,7 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
LOCAL(jpeg_scan_info *) LOCAL(jpeg_scan_info *)
fill_a_scan (jpeg_scan_info * scanptr, int ci, fill_a_scan (jpeg_scan_info * scanptr, int ci,
int Ss, int Se, int Ah, int Al) int Ss, int Se, int Ah, int Al)
/* Support routine: generate one scan for specified component */ /* Support routine: generate one scan for specified component */
{ {
scanptr->comps_in_scan = 1; scanptr->comps_in_scan = 1;
@@ -528,7 +528,7 @@ fill_a_scan (jpeg_scan_info * scanptr, int ci,
LOCAL(jpeg_scan_info *) LOCAL(jpeg_scan_info *)
fill_scans (jpeg_scan_info * scanptr, int ncomps, fill_scans (jpeg_scan_info * scanptr, int ncomps,
int Ss, int Se, int Ah, int Al) int Ss, int Se, int Ah, int Al)
/* Support routine: generate one scan for each component */ /* Support routine: generate one scan for each component */
{ {
int ci; int ci;
@@ -591,9 +591,9 @@ jpeg_simple_progression (j_compress_ptr cinfo)
} else { } else {
/* All-purpose script for other color spaces. */ /* All-purpose script for other color spaces. */
if (ncomps > MAX_COMPS_IN_SCAN) if (ncomps > MAX_COMPS_IN_SCAN)
nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */ nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
else else
nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */ nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
} }
/* Allocate space for script. /* Allocate space for script.
@@ -607,7 +607,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
cinfo->script_space_size = MAX(nscans, 10); cinfo->script_space_size = MAX(nscans, 10);
cinfo->script_space = (jpeg_scan_info *) cinfo->script_space = (jpeg_scan_info *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
cinfo->script_space_size * SIZEOF(jpeg_scan_info)); cinfo->script_space_size * SIZEOF(jpeg_scan_info));
} }
scanptr = cinfo->script_space; scanptr = cinfo->script_space;
cinfo->scan_info = scanptr; cinfo->scan_info = scanptr;

152
jcphuff.c
View File

@@ -15,7 +15,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jchuff.h" /* Declarations shared with jchuff.c */ #include "jchuff.h" /* Declarations shared with jchuff.c */
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
@@ -30,24 +30,24 @@ typedef struct {
/* Bit-level coding status. /* Bit-level coding status.
* next_output_byte/free_in_buffer are local copies of cinfo->dest fields. * next_output_byte/free_in_buffer are local copies of cinfo->dest fields.
*/ */
JOCTET * next_output_byte; /* => next byte to write in buffer */ JOCTET * next_output_byte; /* => next byte to write in buffer */
size_t free_in_buffer; /* # of byte spaces remaining in buffer */ size_t free_in_buffer; /* # of byte spaces remaining in buffer */
INT32 put_buffer; /* current bit-accumulation buffer */ INT32 put_buffer; /* current bit-accumulation buffer */
int put_bits; /* # of bits now in it */ int put_bits; /* # of bits now in it */
j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */ j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
/* Coding status for DC components */ /* Coding status for DC components */
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
/* Coding status for AC components */ /* Coding status for AC components */
int ac_tbl_no; /* the table number of the single component */ int ac_tbl_no; /* the table number of the single component */
unsigned int EOBRUN; /* run length of EOBs */ unsigned int EOBRUN; /* run length of EOBs */
unsigned int BE; /* # of buffered correction bits before MCU */ unsigned int BE; /* # of buffered correction bits before MCU */
char * bit_buffer; /* buffer for correction bits (1 per char) */ char * bit_buffer; /* buffer for correction bits (1 per char) */
/* packing correction bits tightly would save some space but cost time... */ /* packing correction bits tightly would save some space but cost time... */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
int next_restart_num; /* next restart number to write (0-7) */ int next_restart_num; /* next restart number to write (0-7) */
/* Pointers to derived tables (these workspaces have image lifespan). /* Pointers to derived tables (these workspaces have image lifespan).
* Since any one scan codes only DC or only AC, we only need one set * Since any one scan codes only DC or only AC, we only need one set
@@ -67,7 +67,7 @@ typedef phuff_entropy_encoder * phuff_entropy_ptr;
* The minimum safe size is 64 bits. * The minimum safe size is 64 bits.
*/ */
#define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */ #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32. /* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32.
* We assume that int right shift is unsigned if INT32 right shift is, * We assume that int right shift is unsigned if INT32 right shift is,
@@ -75,25 +75,25 @@ typedef phuff_entropy_encoder * phuff_entropy_ptr;
*/ */
#ifdef RIGHT_SHIFT_IS_UNSIGNED #ifdef RIGHT_SHIFT_IS_UNSIGNED
#define ISHIFT_TEMPS int ishift_temp; #define ISHIFT_TEMPS int ishift_temp;
#define IRIGHT_SHIFT(x,shft) \ #define IRIGHT_SHIFT(x,shft) \
((ishift_temp = (x)) < 0 ? \ ((ishift_temp = (x)) < 0 ? \
(ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \ (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
(ishift_temp >> (shft))) (ishift_temp >> (shft)))
#else #else
#define ISHIFT_TEMPS #define ISHIFT_TEMPS
#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
#endif #endif
/* Forward declarations */ /* Forward declarations */
METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo, METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo)); METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo)); METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
@@ -104,7 +104,7 @@ METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
METHODDEF(void) METHODDEF(void)
start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics) start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
boolean is_DC_band; boolean is_DC_band;
int ci, tbl; int ci, tbl;
@@ -130,9 +130,9 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
entropy->pub.encode_mcu = encode_mcu_AC_refine; entropy->pub.encode_mcu = encode_mcu_AC_refine;
/* AC refinement needs a correction bit buffer */ /* AC refinement needs a correction bit buffer */
if (entropy->bit_buffer == NULL) if (entropy->bit_buffer == NULL)
entropy->bit_buffer = (char *) entropy->bit_buffer = (char *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
MAX_CORR_BITS * SIZEOF(char)); MAX_CORR_BITS * SIZEOF(char));
} }
} }
if (gather_statistics) if (gather_statistics)
@@ -149,8 +149,8 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
entropy->last_dc_val[ci] = 0; entropy->last_dc_val[ci] = 0;
/* Get table index */ /* Get table index */
if (is_DC_band) { if (is_DC_band) {
if (cinfo->Ah != 0) /* DC refinement needs no table */ if (cinfo->Ah != 0) /* DC refinement needs no table */
continue; continue;
tbl = compptr->dc_tbl_no; tbl = compptr->dc_tbl_no;
} else { } else {
entropy->ac_tbl_no = tbl = compptr->ac_tbl_no; entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
@@ -163,15 +163,15 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
/* Allocate and zero the statistics tables */ /* Allocate and zero the statistics tables */
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */ /* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
if (entropy->count_ptrs[tbl] == NULL) if (entropy->count_ptrs[tbl] == NULL)
entropy->count_ptrs[tbl] = (long *) entropy->count_ptrs[tbl] = (long *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
257 * SIZEOF(long)); 257 * SIZEOF(long));
MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long)); MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
} else { } else {
/* Compute derived values for Huffman table */ /* Compute derived values for Huffman table */
/* We may do this more than once for a table, but it's not expensive */ /* We may do this more than once for a table, but it's not expensive */
jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl, jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
& entropy->derived_tbls[tbl]); & entropy->derived_tbls[tbl]);
} }
} }
@@ -196,9 +196,9 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
/* Emit a byte */ /* Emit a byte */
#define emit_byte(entropy,val) \ #define emit_byte(entropy,val) \
{ *(entropy)->next_output_byte++ = (JOCTET) (val); \ { *(entropy)->next_output_byte++ = (JOCTET) (val); \
if (--(entropy)->free_in_buffer == 0) \ if (--(entropy)->free_in_buffer == 0) \
dump_buffer(entropy); } dump_buffer(entropy); }
LOCAL(void) LOCAL(void)
@@ -236,21 +236,21 @@ emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE); ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
if (entropy->gather_statistics) if (entropy->gather_statistics)
return; /* do nothing if we're only getting stats */ return; /* do nothing if we're only getting stats */
put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */ put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
put_bits += size; /* new number of bits in buffer */ put_bits += size; /* new number of bits in buffer */
put_buffer <<= 24 - put_bits; /* align incoming bits */ put_buffer <<= 24 - put_bits; /* align incoming bits */
put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */ put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
while (put_bits >= 8) { while (put_bits >= 8) {
int c = (int) ((put_buffer >> 16) & 0xFF); int c = (int) ((put_buffer >> 16) & 0xFF);
emit_byte(entropy, c); emit_byte(entropy, c);
if (c == 0xFF) { /* need to stuff a zero byte? */ if (c == 0xFF) { /* need to stuff a zero byte? */
emit_byte(entropy, 0); emit_byte(entropy, 0);
} }
put_buffer <<= 8; put_buffer <<= 8;
@@ -293,10 +293,10 @@ emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
LOCAL(void) LOCAL(void)
emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart, emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
unsigned int nbits) unsigned int nbits)
{ {
if (entropy->gather_statistics) if (entropy->gather_statistics)
return; /* no real work */ return; /* no real work */
while (nbits > 0) { while (nbits > 0) {
emit_bits(entropy, (unsigned int) (*bufstart), 1); emit_bits(entropy, (unsigned int) (*bufstart), 1);
@@ -315,7 +315,7 @@ emit_eobrun (phuff_entropy_ptr entropy)
{ {
register int temp, nbits; register int temp, nbits;
if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */ if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
temp = entropy->EOBRUN; temp = entropy->EOBRUN;
nbits = 0; nbits = 0;
while ((temp >>= 1)) while ((temp >>= 1))
@@ -409,12 +409,12 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Encode the DC coefficient difference per section G.1.2.1 */ /* Encode the DC coefficient difference per section G.1.2.1 */
temp2 = temp; temp2 = temp;
if (temp < 0) { if (temp < 0) {
temp = -temp; /* temp is abs value of input */ temp = -temp; /* temp is abs value of input */
/* For a negative input, want temp2 = bitwise complement of abs(input) */ /* For a negative input, want temp2 = bitwise complement of abs(input) */
/* This code assumes we are on a two's complement machine */ /* This code assumes we are on a two's complement machine */
temp2--; temp2--;
} }
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
nbits = 0; nbits = 0;
while (temp) { while (temp) {
@@ -426,13 +426,13 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
if (nbits > MAX_COEF_BITS+1) if (nbits > MAX_COEF_BITS+1)
ERREXIT(cinfo, JERR_BAD_DCT_COEF); ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count/emit the Huffman-coded symbol for the number of bits */ /* Count/emit the Huffman-coded symbol for the number of bits */
emit_symbol(entropy, compptr->dc_tbl_no, nbits); emit_symbol(entropy, compptr->dc_tbl_no, nbits);
/* Emit that number of bits of the value, if positive, */ /* Emit that number of bits of the value, if positive, */
/* or the complement of its magnitude, if negative. */ /* or the complement of its magnitude, if negative. */
if (nbits) /* emit_bits rejects calls with size 0 */ if (nbits) /* emit_bits rejects calls with size 0 */
emit_bits(entropy, (unsigned int) temp2, nbits); emit_bits(entropy, (unsigned int) temp2, nbits);
} }
@@ -481,9 +481,9 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
block = MCU_data[0]; block = MCU_data[0];
/* Encode the AC coefficients per section G.1.2.2, fig. G.3 */ /* Encode the AC coefficients per section G.1.2.2, fig. G.3 */
r = 0; /* r = run length of zeros */ r = 0; /* r = run length of zeros */
for (k = cinfo->Ss; k <= Se; k++) { for (k = cinfo->Ss; k <= Se; k++) {
if ((temp = (*block)[jpeg_natural_order[k]]) == 0) { if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
r++; r++;
@@ -495,12 +495,12 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
* interwoven with finding the abs value (temp) and output bits (temp2). * interwoven with finding the abs value (temp) and output bits (temp2).
*/ */
if (temp < 0) { if (temp < 0) {
temp = -temp; /* temp is abs value of input */ temp = -temp; /* temp is abs value of input */
temp >>= Al; /* apply the point transform */ temp >>= Al; /* apply the point transform */
/* For a negative coef, want temp2 = bitwise complement of abs(coef) */ /* For a negative coef, want temp2 = bitwise complement of abs(coef) */
temp2 = ~temp; temp2 = ~temp;
} else { } else {
temp >>= Al; /* apply the point transform */ temp >>= Al; /* apply the point transform */
temp2 = temp; temp2 = temp;
} }
/* Watch out for case that nonzero coef is zero after point transform */ /* Watch out for case that nonzero coef is zero after point transform */
@@ -519,7 +519,7 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
nbits = 1; /* there must be at least one 1 bit */ nbits = 1; /* there must be at least one 1 bit */
while ((temp >>= 1)) while ((temp >>= 1))
nbits++; nbits++;
/* Check for out-of-range coefficient values */ /* Check for out-of-range coefficient values */
@@ -533,13 +533,13 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* or the complement of its magnitude, if negative. */ /* or the complement of its magnitude, if negative. */
emit_bits(entropy, (unsigned int) temp2, nbits); emit_bits(entropy, (unsigned int) temp2, nbits);
r = 0; /* reset zero run length */ r = 0; /* reset zero run length */
} }
if (r > 0) { /* If there are trailing zeroes, */ if (r > 0) { /* If there are trailing zeroes, */
entropy->EOBRUN++; /* count an EOB */ entropy->EOBRUN++; /* count an EOB */
if (entropy->EOBRUN == 0x7FFF) if (entropy->EOBRUN == 0x7FFF)
emit_eobrun(entropy); /* force it out to avoid overflow */ emit_eobrun(entropy); /* force it out to avoid overflow */
} }
cinfo->dest->next_output_byte = entropy->next_output_byte; cinfo->dest->next_output_byte = entropy->next_output_byte;
@@ -648,17 +648,17 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
* in C, we shift after obtaining the absolute value. * in C, we shift after obtaining the absolute value.
*/ */
if (temp < 0) if (temp < 0)
temp = -temp; /* temp is abs value of input */ temp = -temp; /* temp is abs value of input */
temp >>= Al; /* apply the point transform */ temp >>= Al; /* apply the point transform */
absvalues[k] = temp; /* save abs value for main pass */ absvalues[k] = temp; /* save abs value for main pass */
if (temp == 1) if (temp == 1)
EOB = k; /* EOB = index of last newly-nonzero coef */ EOB = k; /* EOB = index of last newly-nonzero coef */
} }
/* Encode the AC coefficients per section G.1.2.3, fig. G.7 */ /* Encode the AC coefficients per section G.1.2.3, fig. G.7 */
r = 0; /* r = run length of zeros */ r = 0; /* r = run length of zeros */
BR = 0; /* BR = count of buffered bits added now */ BR = 0; /* BR = count of buffered bits added now */
BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */ BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
for (k = cinfo->Ss; k <= Se; k++) { for (k = cinfo->Ss; k <= Se; k++) {
@@ -705,12 +705,12 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
emit_buffered_bits(entropy, BR_buffer, BR); emit_buffered_bits(entropy, BR_buffer, BR);
BR_buffer = entropy->bit_buffer; /* BE bits are gone now */ BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
BR = 0; BR = 0;
r = 0; /* reset zero run length */ r = 0; /* reset zero run length */
} }
if (r > 0 || BR > 0) { /* If there are trailing zeroes, */ if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
entropy->EOBRUN++; /* count an EOB */ entropy->EOBRUN++; /* count an EOB */
entropy->BE += BR; /* concat my correction bits to older ones */ entropy->BE += BR; /* concat my correction bits to older ones */
/* We force out the EOB if we risk either: /* We force out the EOB if we risk either:
* 1. overflow of the EOB counter; * 1. overflow of the EOB counter;
* 2. overflow of the correction bit buffer during the next MCU. * 2. overflow of the correction bit buffer during the next MCU.
@@ -742,7 +742,7 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
METHODDEF(void) METHODDEF(void)
finish_pass_phuff (j_compress_ptr cinfo) finish_pass_phuff (j_compress_ptr cinfo)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->next_output_byte = cinfo->dest->next_output_byte;
@@ -784,8 +784,8 @@ finish_pass_gather_phuff (j_compress_ptr cinfo)
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
if (is_DC_band) { if (is_DC_band) {
if (cinfo->Ah != 0) /* DC refinement needs no table */ if (cinfo->Ah != 0) /* DC refinement needs no table */
continue; continue;
tbl = compptr->dc_tbl_no; tbl = compptr->dc_tbl_no;
} else { } else {
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
@@ -816,7 +816,7 @@ jinit_phuff_encoder (j_compress_ptr cinfo)
entropy = (phuff_entropy_ptr) entropy = (phuff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(phuff_entropy_encoder)); SIZEOF(phuff_entropy_encoder));
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
entropy->pub.start_pass = start_pass_phuff; entropy->pub.start_pass = start_pass_phuff;
@@ -825,7 +825,7 @@ jinit_phuff_encoder (j_compress_ptr cinfo)
entropy->derived_tbls[i] = NULL; entropy->derived_tbls[i] = NULL;
entropy->count_ptrs[i] = NULL; entropy->count_ptrs[i] = NULL;
} }
entropy->bit_buffer = NULL; /* needed only in AC refinement scan */ entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
} }
#endif /* C_PROGRESSIVE_SUPPORTED */ #endif /* C_PROGRESSIVE_SUPPORTED */

View File

@@ -58,12 +58,12 @@ typedef struct {
*/ */
JSAMPARRAY color_buf[MAX_COMPONENTS]; JSAMPARRAY color_buf[MAX_COMPONENTS];
JDIMENSION rows_to_go; /* counts rows remaining in source image */ JDIMENSION rows_to_go; /* counts rows remaining in source image */
int next_buf_row; /* index of next row to store in color_buf */ int next_buf_row; /* index of next row to store in color_buf */
#ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */ #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
int this_row_group; /* starting row index of group to process */ int this_row_group; /* starting row index of group to process */
int next_buf_stop; /* downsample when we reach this index */ int next_buf_stop; /* downsample when we reach this index */
#endif #endif
} my_prep_controller; } my_prep_controller;
@@ -104,13 +104,13 @@ start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
LOCAL(void) LOCAL(void)
expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
int input_rows, int output_rows) int input_rows, int output_rows)
{ {
register int row; register int row;
for (row = input_rows; row < output_rows; row++) { for (row = input_rows; row < output_rows; row++) {
jcopy_sample_rows(image_data, input_rows-1, image_data, row, jcopy_sample_rows(image_data, input_rows-1, image_data, row,
1, num_cols); 1, num_cols);
} }
} }
@@ -126,10 +126,10 @@ expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
METHODDEF(void) METHODDEF(void)
pre_process_data (j_compress_ptr cinfo, pre_process_data (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
JDIMENSION in_rows_avail, JDIMENSION in_rows_avail,
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail) JDIMENSION out_row_groups_avail)
{ {
my_prep_ptr prep = (my_prep_ptr) cinfo->prep; my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
int numrows, ci; int numrows, ci;
@@ -137,32 +137,32 @@ pre_process_data (j_compress_ptr cinfo,
jpeg_component_info * compptr; jpeg_component_info * compptr;
while (*in_row_ctr < in_rows_avail && while (*in_row_ctr < in_rows_avail &&
*out_row_group_ctr < out_row_groups_avail) { *out_row_group_ctr < out_row_groups_avail) {
/* Do color conversion to fill the conversion buffer. */ /* Do color conversion to fill the conversion buffer. */
inrows = in_rows_avail - *in_row_ctr; inrows = in_rows_avail - *in_row_ctr;
numrows = cinfo->max_v_samp_factor - prep->next_buf_row; numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
numrows = (int) MIN((JDIMENSION) numrows, inrows); numrows = (int) MIN((JDIMENSION) numrows, inrows);
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
prep->color_buf, prep->color_buf,
(JDIMENSION) prep->next_buf_row, (JDIMENSION) prep->next_buf_row,
numrows); numrows);
*in_row_ctr += numrows; *in_row_ctr += numrows;
prep->next_buf_row += numrows; prep->next_buf_row += numrows;
prep->rows_to_go -= numrows; prep->rows_to_go -= numrows;
/* If at bottom of image, pad to fill the conversion buffer. */ /* If at bottom of image, pad to fill the conversion buffer. */
if (prep->rows_to_go == 0 && if (prep->rows_to_go == 0 &&
prep->next_buf_row < cinfo->max_v_samp_factor) { prep->next_buf_row < cinfo->max_v_samp_factor) {
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
prep->next_buf_row, cinfo->max_v_samp_factor); prep->next_buf_row, cinfo->max_v_samp_factor);
} }
prep->next_buf_row = cinfo->max_v_samp_factor; prep->next_buf_row = cinfo->max_v_samp_factor;
} }
/* If we've filled the conversion buffer, empty it. */ /* If we've filled the conversion buffer, empty it. */
if (prep->next_buf_row == cinfo->max_v_samp_factor) { if (prep->next_buf_row == cinfo->max_v_samp_factor) {
(*cinfo->downsample->downsample) (cinfo, (*cinfo->downsample->downsample) (cinfo,
prep->color_buf, (JDIMENSION) 0, prep->color_buf, (JDIMENSION) 0,
output_buf, *out_row_group_ctr); output_buf, *out_row_group_ctr);
prep->next_buf_row = 0; prep->next_buf_row = 0;
(*out_row_group_ctr)++; (*out_row_group_ctr)++;
} }
@@ -170,16 +170,16 @@ pre_process_data (j_compress_ptr cinfo,
* Note we assume the caller is providing a one-iMCU-height output buffer! * Note we assume the caller is providing a one-iMCU-height output buffer!
*/ */
if (prep->rows_to_go == 0 && if (prep->rows_to_go == 0 &&
*out_row_group_ctr < out_row_groups_avail) { *out_row_group_ctr < out_row_groups_avail) {
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
expand_bottom_edge(output_buf[ci], expand_bottom_edge(output_buf[ci],
compptr->width_in_blocks * DCTSIZE, compptr->width_in_blocks * DCTSIZE,
(int) (*out_row_group_ctr * compptr->v_samp_factor), (int) (*out_row_group_ctr * compptr->v_samp_factor),
(int) (out_row_groups_avail * compptr->v_samp_factor)); (int) (out_row_groups_avail * compptr->v_samp_factor));
} }
*out_row_group_ctr = out_row_groups_avail; *out_row_group_ctr = out_row_groups_avail;
break; /* can exit outer loop without test */ break; /* can exit outer loop without test */
} }
} }
} }
@@ -193,10 +193,10 @@ pre_process_data (j_compress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
pre_process_context (j_compress_ptr cinfo, pre_process_context (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
JDIMENSION in_rows_avail, JDIMENSION in_rows_avail,
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail) JDIMENSION out_row_groups_avail)
{ {
my_prep_ptr prep = (my_prep_ptr) cinfo->prep; my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
int numrows, ci; int numrows, ci;
@@ -210,19 +210,19 @@ pre_process_context (j_compress_ptr cinfo,
numrows = prep->next_buf_stop - prep->next_buf_row; numrows = prep->next_buf_stop - prep->next_buf_row;
numrows = (int) MIN((JDIMENSION) numrows, inrows); numrows = (int) MIN((JDIMENSION) numrows, inrows);
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr, (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
prep->color_buf, prep->color_buf,
(JDIMENSION) prep->next_buf_row, (JDIMENSION) prep->next_buf_row,
numrows); numrows);
/* Pad at top of image, if first time through */ /* Pad at top of image, if first time through */
if (prep->rows_to_go == cinfo->image_height) { if (prep->rows_to_go == cinfo->image_height) {
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
int row; int row;
for (row = 1; row <= cinfo->max_v_samp_factor; row++) { for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
jcopy_sample_rows(prep->color_buf[ci], 0, jcopy_sample_rows(prep->color_buf[ci], 0,
prep->color_buf[ci], -row, prep->color_buf[ci], -row,
1, cinfo->image_width); 1, cinfo->image_width);
} }
} }
} }
*in_row_ctr += numrows; *in_row_ctr += numrows;
prep->next_buf_row += numrows; prep->next_buf_row += numrows;
@@ -230,29 +230,29 @@ pre_process_context (j_compress_ptr cinfo,
} else { } else {
/* Return for more data, unless we are at the bottom of the image. */ /* Return for more data, unless we are at the bottom of the image. */
if (prep->rows_to_go != 0) if (prep->rows_to_go != 0)
break; break;
/* When at bottom of image, pad to fill the conversion buffer. */ /* When at bottom of image, pad to fill the conversion buffer. */
if (prep->next_buf_row < prep->next_buf_stop) { if (prep->next_buf_row < prep->next_buf_stop) {
for (ci = 0; ci < cinfo->num_components; ci++) { for (ci = 0; ci < cinfo->num_components; ci++) {
expand_bottom_edge(prep->color_buf[ci], cinfo->image_width, expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
prep->next_buf_row, prep->next_buf_stop); prep->next_buf_row, prep->next_buf_stop);
} }
prep->next_buf_row = prep->next_buf_stop; prep->next_buf_row = prep->next_buf_stop;
} }
} }
/* If we've gotten enough data, downsample a row group. */ /* If we've gotten enough data, downsample a row group. */
if (prep->next_buf_row == prep->next_buf_stop) { if (prep->next_buf_row == prep->next_buf_stop) {
(*cinfo->downsample->downsample) (cinfo, (*cinfo->downsample->downsample) (cinfo,
prep->color_buf, prep->color_buf,
(JDIMENSION) prep->this_row_group, (JDIMENSION) prep->this_row_group,
output_buf, *out_row_group_ctr); output_buf, *out_row_group_ctr);
(*out_row_group_ctr)++; (*out_row_group_ctr)++;
/* Advance pointers with wraparound as necessary. */ /* Advance pointers with wraparound as necessary. */
prep->this_row_group += cinfo->max_v_samp_factor; prep->this_row_group += cinfo->max_v_samp_factor;
if (prep->this_row_group >= buf_height) if (prep->this_row_group >= buf_height)
prep->this_row_group = 0; prep->this_row_group = 0;
if (prep->next_buf_row >= buf_height) if (prep->next_buf_row >= buf_height)
prep->next_buf_row = 0; prep->next_buf_row = 0;
prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor; prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
} }
} }
@@ -277,8 +277,8 @@ create_context_buffer (j_compress_ptr cinfo)
*/ */
fake_buffer = (JSAMPARRAY) fake_buffer = (JSAMPARRAY)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(cinfo->num_components * 5 * rgroup_height) * (cinfo->num_components * 5 * rgroup_height) *
SIZEOF(JSAMPROW)); SIZEOF(JSAMPROW));
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
@@ -289,11 +289,11 @@ create_context_buffer (j_compress_ptr cinfo)
true_buffer = (*cinfo->mem->alloc_sarray) true_buffer = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
(JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
cinfo->max_h_samp_factor) / compptr->h_samp_factor), cinfo->max_h_samp_factor) / compptr->h_samp_factor),
(JDIMENSION) (3 * rgroup_height)); (JDIMENSION) (3 * rgroup_height));
/* Copy true buffer row pointers into the middle of the fake row array */ /* Copy true buffer row pointers into the middle of the fake row array */
MEMCOPY(fake_buffer + rgroup_height, true_buffer, MEMCOPY(fake_buffer + rgroup_height, true_buffer,
3 * rgroup_height * SIZEOF(JSAMPROW)); 3 * rgroup_height * SIZEOF(JSAMPROW));
/* Fill in the above and below wraparound pointers */ /* Fill in the above and below wraparound pointers */
for (i = 0; i < rgroup_height; i++) { for (i = 0; i < rgroup_height; i++) {
fake_buffer[i] = true_buffer[2 * rgroup_height + i]; fake_buffer[i] = true_buffer[2 * rgroup_height + i];
@@ -318,12 +318,12 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
int ci; int ci;
jpeg_component_info * compptr; jpeg_component_info * compptr;
if (need_full_buffer) /* safety check */ if (need_full_buffer) /* safety check */
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
prep = (my_prep_ptr) prep = (my_prep_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_prep_controller)); SIZEOF(my_prep_controller));
cinfo->prep = (struct jpeg_c_prep_controller *) prep; cinfo->prep = (struct jpeg_c_prep_controller *) prep;
prep->pub.start_pass = start_pass_prep; prep->pub.start_pass = start_pass_prep;
@@ -343,12 +343,12 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
/* No context, just make it tall enough for one row group */ /* No context, just make it tall enough for one row group */
prep->pub.pre_process_data = pre_process_data; prep->pub.pre_process_data = pre_process_data;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
prep->color_buf[ci] = (*cinfo->mem->alloc_sarray) prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
(JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE * (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
cinfo->max_h_samp_factor) / compptr->h_samp_factor), cinfo->max_h_samp_factor) / compptr->h_samp_factor),
(JDIMENSION) cinfo->max_v_samp_factor); (JDIMENSION) cinfo->max_v_samp_factor);
} }
} }
} }

View File

@@ -54,13 +54,13 @@
/* Pointer to routine to downsample a single component */ /* Pointer to routine to downsample a single component */
typedef JMETHOD(void, downsample1_ptr, typedef JMETHOD(void, downsample1_ptr,
(j_compress_ptr cinfo, jpeg_component_info * compptr, (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data)); JSAMPARRAY input_data, JSAMPARRAY output_data));
/* Private subobject */ /* Private subobject */
typedef struct { typedef struct {
struct jpeg_downsampler pub; /* public fields */ struct jpeg_downsampler pub; /* public fields */
/* Downsampling method pointers, one per component */ /* Downsampling method pointers, one per component */
downsample1_ptr methods[MAX_COMPONENTS]; downsample1_ptr methods[MAX_COMPONENTS];
@@ -87,7 +87,7 @@ start_pass_downsample (j_compress_ptr cinfo)
LOCAL(void) LOCAL(void)
expand_right_edge (JSAMPARRAY image_data, int num_rows, expand_right_edge (JSAMPARRAY image_data, int num_rows,
JDIMENSION input_cols, JDIMENSION output_cols) JDIMENSION input_cols, JDIMENSION output_cols)
{ {
register JSAMPROW ptr; register JSAMPROW ptr;
register JSAMPLE pixval; register JSAMPLE pixval;
@@ -98,9 +98,9 @@ expand_right_edge (JSAMPARRAY image_data, int num_rows,
if (numcols > 0) { if (numcols > 0) {
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
ptr = image_data[row] + input_cols; ptr = image_data[row] + input_cols;
pixval = ptr[-1]; /* don't need GETJSAMPLE() here */ pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
for (count = numcols; count > 0; count--) for (count = numcols; count > 0; count--)
*ptr++ = pixval; *ptr++ = pixval;
} }
} }
} }
@@ -114,8 +114,8 @@ expand_right_edge (JSAMPARRAY image_data, int num_rows,
METHODDEF(void) METHODDEF(void)
sep_downsample (j_compress_ptr cinfo, sep_downsample (j_compress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION in_row_index, JSAMPIMAGE input_buf, JDIMENSION in_row_index,
JSAMPIMAGE output_buf, JDIMENSION out_row_group_index) JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
{ {
my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample; my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
int ci; int ci;
@@ -140,10 +140,10 @@ sep_downsample (j_compress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE; JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
JSAMPROW inptr, outptr; JSAMPROW inptr, outptr;
INT32 outvalue; INT32 outvalue;
@@ -158,19 +158,19 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
* efficient. * efficient.
*/ */
expand_right_edge(input_data, cinfo->max_v_samp_factor, expand_right_edge(input_data, cinfo->max_v_samp_factor,
cinfo->image_width, output_cols * h_expand); cinfo->image_width, output_cols * h_expand);
inrow = 0; inrow = 0;
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
outptr = output_data[outrow]; outptr = output_data[outrow];
for (outcol = 0, outcol_h = 0; outcol < output_cols; for (outcol = 0, outcol_h = 0; outcol < output_cols;
outcol++, outcol_h += h_expand) { outcol++, outcol_h += h_expand) {
outvalue = 0; outvalue = 0;
for (v = 0; v < v_expand; v++) { for (v = 0; v < v_expand; v++) {
inptr = input_data[inrow+v] + outcol_h; inptr = input_data[inrow+v] + outcol_h;
for (h = 0; h < h_expand; h++) { for (h = 0; h < h_expand; h++) {
outvalue += (INT32) GETJSAMPLE(*inptr++); outvalue += (INT32) GETJSAMPLE(*inptr++);
} }
} }
*outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix); *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
} }
@@ -187,14 +187,14 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
/* Copy the data */ /* Copy the data */
jcopy_sample_rows(input_data, 0, output_data, 0, jcopy_sample_rows(input_data, 0, output_data, 0,
cinfo->max_v_samp_factor, cinfo->image_width); cinfo->max_v_samp_factor, cinfo->image_width);
/* Edge-expand */ /* Edge-expand */
expand_right_edge(output_data, cinfo->max_v_samp_factor, expand_right_edge(output_data, cinfo->max_v_samp_factor,
cinfo->image_width, compptr->width_in_blocks * DCTSIZE); cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
} }
@@ -212,7 +212,7 @@ fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
int outrow; int outrow;
JDIMENSION outcol; JDIMENSION outcol;
@@ -225,16 +225,16 @@ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
* efficient. * efficient.
*/ */
expand_right_edge(input_data, cinfo->max_v_samp_factor, expand_right_edge(input_data, cinfo->max_v_samp_factor,
cinfo->image_width, output_cols * 2); cinfo->image_width, output_cols * 2);
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
outptr = output_data[outrow]; outptr = output_data[outrow];
inptr = input_data[outrow]; inptr = input_data[outrow];
bias = 0; /* bias = 0,1,0,1,... for successive samples */ bias = 0; /* bias = 0,1,0,1,... for successive samples */
for (outcol = 0; outcol < output_cols; outcol++) { for (outcol = 0; outcol < output_cols; outcol++) {
*outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1]) *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
+ bias) >> 1); + bias) >> 1);
bias ^= 1; /* 0=>1, 1=>0 */ bias ^= 1; /* 0=>1, 1=>0 */
inptr += 2; inptr += 2;
} }
} }
@@ -249,7 +249,7 @@ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
int inrow, outrow; int inrow, outrow;
JDIMENSION outcol; JDIMENSION outcol;
@@ -262,19 +262,19 @@ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
* efficient. * efficient.
*/ */
expand_right_edge(input_data, cinfo->max_v_samp_factor, expand_right_edge(input_data, cinfo->max_v_samp_factor,
cinfo->image_width, output_cols * 2); cinfo->image_width, output_cols * 2);
inrow = 0; inrow = 0;
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
outptr = output_data[outrow]; outptr = output_data[outrow];
inptr0 = input_data[inrow]; inptr0 = input_data[inrow];
inptr1 = input_data[inrow+1]; inptr1 = input_data[inrow+1];
bias = 1; /* bias = 1,2,1,2,... for successive samples */ bias = 1; /* bias = 1,2,1,2,... for successive samples */
for (outcol = 0; outcol < output_cols; outcol++) { for (outcol = 0; outcol < output_cols; outcol++) {
*outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]) GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
+ bias) >> 2); + bias) >> 2);
bias ^= 3; /* 1=>2, 2=>1 */ bias ^= 3; /* 1=>2, 2=>1 */
inptr0 += 2; inptr1 += 2; inptr0 += 2; inptr1 += 2;
} }
inrow += 2; inrow += 2;
@@ -292,7 +292,7 @@ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
int inrow, outrow; int inrow, outrow;
JDIMENSION colctr; JDIMENSION colctr;
@@ -305,7 +305,7 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
* efficient. * efficient.
*/ */
expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
cinfo->image_width, output_cols * 2); cinfo->image_width, output_cols * 2);
/* We don't bother to form the individual "smoothed" input pixel values; /* We don't bother to form the individual "smoothed" input pixel values;
* we can directly compute the output which is the average of the four * we can directly compute the output which is the average of the four
@@ -333,14 +333,14 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
/* Special case for first column: pretend column -1 is same as column 0 */ /* Special case for first column: pretend column -1 is same as column 0 */
membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) + GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]); GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
neighsum += neighsum; neighsum += neighsum;
neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) + neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]); GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
@@ -348,17 +348,17 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
for (colctr = output_cols - 2; colctr > 0; colctr--) { for (colctr = output_cols - 2; colctr > 0; colctr--) {
/* sum of pixels directly mapped to this output element */ /* sum of pixels directly mapped to this output element */
membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
/* sum of edge-neighbor pixels */ /* sum of edge-neighbor pixels */
neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) + GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]); GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
/* The edge-neighbors count twice as much as corner-neighbors */ /* The edge-neighbors count twice as much as corner-neighbors */
neighsum += neighsum; neighsum += neighsum;
/* Add in the corner-neighbors */ /* Add in the corner-neighbors */
neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) + neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]); GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
/* form final output scaled up by 2^16 */ /* form final output scaled up by 2^16 */
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
/* round, descale and output it */ /* round, descale and output it */
@@ -368,14 +368,14 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
/* Special case for last column */ /* Special case for last column */
membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) + membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]); GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) + neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) + GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) + GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]); GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
neighsum += neighsum; neighsum += neighsum;
neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) + neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]); GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr = (JSAMPLE) ((membersum + 32768) >> 16); *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
@@ -392,7 +392,7 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr, fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
JSAMPARRAY input_data, JSAMPARRAY output_data) JSAMPARRAY input_data, JSAMPARRAY output_data)
{ {
int outrow; int outrow;
JDIMENSION colctr; JDIMENSION colctr;
@@ -406,7 +406,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
* efficient. * efficient.
*/ */
expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
cinfo->image_width, output_cols); cinfo->image_width, output_cols);
/* Each of the eight neighbor pixels contributes a fraction SF to the /* Each of the eight neighbor pixels contributes a fraction SF to the
* smoothed pixel, while the main pixel contributes (1-8*SF). In order * smoothed pixel, while the main pixel contributes (1-8*SF). In order
@@ -425,10 +425,10 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
/* Special case for first column */ /* Special case for first column */
colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) + colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
GETJSAMPLE(*inptr); GETJSAMPLE(*inptr);
membersum = GETJSAMPLE(*inptr++); membersum = GETJSAMPLE(*inptr++);
nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
GETJSAMPLE(*inptr); GETJSAMPLE(*inptr);
neighsum = colsum + (colsum - membersum) + nextcolsum; neighsum = colsum + (colsum - membersum) + nextcolsum;
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
@@ -438,7 +438,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
membersum = GETJSAMPLE(*inptr++); membersum = GETJSAMPLE(*inptr++);
above_ptr++; below_ptr++; above_ptr++; below_ptr++;
nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) + nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
GETJSAMPLE(*inptr); GETJSAMPLE(*inptr);
neighsum = lastcolsum + (colsum - membersum) + nextcolsum; neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
membersum = membersum * memberscale + neighsum * neighscale; membersum = membersum * memberscale + neighsum * neighscale;
*outptr++ = (JSAMPLE) ((membersum + 32768) >> 16); *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
@@ -472,7 +472,7 @@ jinit_downsampler (j_compress_ptr cinfo)
downsample = (my_downsample_ptr) downsample = (my_downsample_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_downsampler)); SIZEOF(my_downsampler));
cinfo->downsample = (struct jpeg_downsampler *) downsample; cinfo->downsample = (struct jpeg_downsampler *) downsample;
downsample->pub.start_pass = start_pass_downsample; downsample->pub.start_pass = start_pass_downsample;
downsample->pub.downsample = sep_downsample; downsample->pub.downsample = sep_downsample;
@@ -485,35 +485,35 @@ jinit_downsampler (j_compress_ptr cinfo)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (compptr->h_samp_factor == cinfo->max_h_samp_factor && if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
compptr->v_samp_factor == cinfo->max_v_samp_factor) { compptr->v_samp_factor == cinfo->max_v_samp_factor) {
#ifdef INPUT_SMOOTHING_SUPPORTED #ifdef INPUT_SMOOTHING_SUPPORTED
if (cinfo->smoothing_factor) { if (cinfo->smoothing_factor) {
downsample->methods[ci] = fullsize_smooth_downsample; downsample->methods[ci] = fullsize_smooth_downsample;
downsample->pub.need_context_rows = TRUE; downsample->pub.need_context_rows = TRUE;
} else } else
#endif #endif
downsample->methods[ci] = fullsize_downsample; downsample->methods[ci] = fullsize_downsample;
} else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
compptr->v_samp_factor == cinfo->max_v_samp_factor) { compptr->v_samp_factor == cinfo->max_v_samp_factor) {
smoothok = FALSE; smoothok = FALSE;
if (jsimd_can_h2v1_downsample()) if (jsimd_can_h2v1_downsample())
downsample->methods[ci] = jsimd_h2v1_downsample; downsample->methods[ci] = jsimd_h2v1_downsample;
else else
downsample->methods[ci] = h2v1_downsample; downsample->methods[ci] = h2v1_downsample;
} else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
#ifdef INPUT_SMOOTHING_SUPPORTED #ifdef INPUT_SMOOTHING_SUPPORTED
if (cinfo->smoothing_factor) { if (cinfo->smoothing_factor) {
downsample->methods[ci] = h2v2_smooth_downsample; downsample->methods[ci] = h2v2_smooth_downsample;
downsample->pub.need_context_rows = TRUE; downsample->pub.need_context_rows = TRUE;
} else } else
#endif #endif
if (jsimd_can_h2v2_downsample()) if (jsimd_can_h2v2_downsample())
downsample->methods[ci] = jsimd_h2v2_downsample; downsample->methods[ci] = jsimd_h2v2_downsample;
else else
downsample->methods[ci] = h2v2_downsample; downsample->methods[ci] = h2v2_downsample;
} else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
(cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
smoothok = FALSE; smoothok = FALSE;
downsample->methods[ci] = int_downsample; downsample->methods[ci] = int_downsample;
} else } else

106
jctrans.c
View File

@@ -18,9 +18,9 @@
/* Forward declarations */ /* Forward declarations */
LOCAL(void) transencode_master_selection LOCAL(void) transencode_master_selection
JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
LOCAL(void) transencode_coef_controller LOCAL(void) transencode_coef_controller
JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
/* /*
@@ -48,7 +48,7 @@ jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
/* Perform master selection of active modules */ /* Perform master selection of active modules */
transencode_master_selection(cinfo, coef_arrays); transencode_master_selection(cinfo, coef_arrays);
/* Wait for jpeg_finish_compress() call */ /* Wait for jpeg_finish_compress() call */
cinfo->next_scanline = 0; /* so jpeg_write_marker works */ cinfo->next_scanline = 0; /* so jpeg_write_marker works */
cinfo->global_state = CSTATE_WRCOEFS; cinfo->global_state = CSTATE_WRCOEFS;
} }
@@ -62,7 +62,7 @@ jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
GLOBAL(void) GLOBAL(void)
jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
j_compress_ptr dstinfo) j_compress_ptr dstinfo)
{ {
JQUANT_TBL ** qtblptr; JQUANT_TBL ** qtblptr;
jpeg_component_info *incomp, *outcomp; jpeg_component_info *incomp, *outcomp;
@@ -96,10 +96,10 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
if (srcinfo->quant_tbl_ptrs[tblno] != NULL) { if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
qtblptr = & dstinfo->quant_tbl_ptrs[tblno]; qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
if (*qtblptr == NULL) if (*qtblptr == NULL)
*qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo); *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
MEMCOPY((*qtblptr)->quantval, MEMCOPY((*qtblptr)->quantval,
srcinfo->quant_tbl_ptrs[tblno]->quantval, srcinfo->quant_tbl_ptrs[tblno]->quantval,
SIZEOF((*qtblptr)->quantval)); SIZEOF((*qtblptr)->quantval));
(*qtblptr)->sent_table = FALSE; (*qtblptr)->sent_table = FALSE;
} }
} }
@@ -109,7 +109,7 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
dstinfo->num_components = srcinfo->num_components; dstinfo->num_components = srcinfo->num_components;
if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS) if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components, ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
MAX_COMPONENTS); MAX_COMPONENTS);
for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info; for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
ci < dstinfo->num_components; ci++, incomp++, outcomp++) { ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
outcomp->component_id = incomp->component_id; outcomp->component_id = incomp->component_id;
@@ -122,14 +122,14 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
*/ */
tblno = outcomp->quant_tbl_no; tblno = outcomp->quant_tbl_no;
if (tblno < 0 || tblno >= NUM_QUANT_TBLS || if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
srcinfo->quant_tbl_ptrs[tblno] == NULL) srcinfo->quant_tbl_ptrs[tblno] == NULL)
ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno); ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
slot_quant = srcinfo->quant_tbl_ptrs[tblno]; slot_quant = srcinfo->quant_tbl_ptrs[tblno];
c_quant = incomp->quant_table; c_quant = incomp->quant_table;
if (c_quant != NULL) { if (c_quant != NULL) {
for (coefi = 0; coefi < DCTSIZE2; coefi++) { for (coefi = 0; coefi < DCTSIZE2; coefi++) {
if (c_quant->quantval[coefi] != slot_quant->quantval[coefi]) if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno); ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
} }
} }
/* Note: we do not copy the source's Huffman table assignments; /* Note: we do not copy the source's Huffman table assignments;
@@ -163,7 +163,7 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
LOCAL(void) LOCAL(void)
transencode_master_selection (j_compress_ptr cinfo, transencode_master_selection (j_compress_ptr cinfo,
jvirt_barray_ptr * coef_arrays) jvirt_barray_ptr * coef_arrays)
{ {
/* Although we don't actually use input_components for transcoding, /* Although we don't actually use input_components for transcoding,
* jcmaster.c's initial_setup will complain if input_components is 0. * jcmaster.c's initial_setup will complain if input_components is 0.
@@ -219,10 +219,10 @@ transencode_master_selection (j_compress_ptr cinfo,
typedef struct { typedef struct {
struct jpeg_c_coef_controller pub; /* public fields */ struct jpeg_c_coef_controller pub; /* public fields */
JDIMENSION iMCU_row_num; /* iMCU row # within image */ JDIMENSION iMCU_row_num; /* iMCU row # within image */
JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
int MCU_vert_offset; /* counts MCU rows within iMCU row */ int MCU_vert_offset; /* counts MCU rows within iMCU row */
int MCU_rows_per_iMCU_row; /* number of such rows needed */ int MCU_rows_per_iMCU_row; /* number of such rows needed */
/* Virtual block array for each component. */ /* Virtual block array for each component. */
jvirt_barray_ptr * whole_image; jvirt_barray_ptr * whole_image;
@@ -289,7 +289,7 @@ METHODDEF(boolean)
compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */ JDIMENSION MCU_col_num; /* index of current MCU within row */
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
int blkn, ci, xindex, yindex, yoffset, blockcnt; int blkn, ci, xindex, yindex, yoffset, blockcnt;
@@ -312,44 +312,44 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
yoffset++) { yoffset++) {
for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
MCU_col_num++) { MCU_col_num++) {
/* Construct list of pointers to DCT blocks belonging to this MCU */ /* Construct list of pointers to DCT blocks belonging to this MCU */
blkn = 0; /* index of current DCT block within MCU */ blkn = 0; /* index of current DCT block within MCU */
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
start_col = MCU_col_num * compptr->MCU_width; start_col = MCU_col_num * compptr->MCU_width;
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
: compptr->last_col_width; : compptr->last_col_width;
for (yindex = 0; yindex < compptr->MCU_height; yindex++) { for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
if (coef->iMCU_row_num < last_iMCU_row || if (coef->iMCU_row_num < last_iMCU_row ||
yindex+yoffset < compptr->last_row_height) { yindex+yoffset < compptr->last_row_height) {
/* Fill in pointers to real blocks in this row */ /* Fill in pointers to real blocks in this row */
buffer_ptr = buffer[ci][yindex+yoffset] + start_col; buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
for (xindex = 0; xindex < blockcnt; xindex++) for (xindex = 0; xindex < blockcnt; xindex++)
MCU_buffer[blkn++] = buffer_ptr++; MCU_buffer[blkn++] = buffer_ptr++;
} else { } else {
/* At bottom of image, need a whole row of dummy blocks */ /* At bottom of image, need a whole row of dummy blocks */
xindex = 0; xindex = 0;
} }
/* Fill in any dummy blocks needed in this row. /* Fill in any dummy blocks needed in this row.
* Dummy blocks are filled in the same way as in jccoefct.c: * Dummy blocks are filled in the same way as in jccoefct.c:
* all zeroes in the AC entries, DC entries equal to previous * all zeroes in the AC entries, DC entries equal to previous
* block's DC value. The init routine has already zeroed the * block's DC value. The init routine has already zeroed the
* AC entries, so we need only set the DC entries correctly. * AC entries, so we need only set the DC entries correctly.
*/ */
for (; xindex < compptr->MCU_width; xindex++) { for (; xindex < compptr->MCU_width; xindex++) {
MCU_buffer[blkn] = coef->dummy_buffer[blkn]; MCU_buffer[blkn] = coef->dummy_buffer[blkn];
MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0]; MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
blkn++; blkn++;
} }
} }
} }
/* Try to write the MCU. */ /* Try to write the MCU. */
if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) { if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
coef->mcu_ctr = MCU_col_num; coef->mcu_ctr = MCU_col_num;
return FALSE; return FALSE;
} }
} }
/* Completed an MCU row, but perhaps not an iMCU row */ /* Completed an MCU row, but perhaps not an iMCU row */
@@ -372,7 +372,7 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
LOCAL(void) LOCAL(void)
transencode_coef_controller (j_compress_ptr cinfo, transencode_coef_controller (j_compress_ptr cinfo,
jvirt_barray_ptr * coef_arrays) jvirt_barray_ptr * coef_arrays)
{ {
my_coef_ptr coef; my_coef_ptr coef;
JBLOCKROW buffer; JBLOCKROW buffer;
@@ -380,7 +380,7 @@ transencode_coef_controller (j_compress_ptr cinfo,
coef = (my_coef_ptr) coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_coef_controller)); SIZEOF(my_coef_controller));
cinfo->coef = (struct jpeg_c_coef_controller *) coef; cinfo->coef = (struct jpeg_c_coef_controller *) coef;
coef->pub.start_pass = start_pass_coef; coef->pub.start_pass = start_pass_coef;
coef->pub.compress_data = compress_output; coef->pub.compress_data = compress_output;
@@ -391,7 +391,7 @@ transencode_coef_controller (j_compress_ptr cinfo,
/* Allocate and pre-zero space for dummy DCT blocks. */ /* Allocate and pre-zero space for dummy DCT blocks. */
buffer = (JBLOCKROW) buffer = (JBLOCKROW)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
coef->dummy_buffer[i] = buffer + i; coef->dummy_buffer[i] = buffer + i;

View File

@@ -32,12 +32,12 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
int i; int i;
/* Guard against version mismatches between library and caller. */ /* Guard against version mismatches between library and caller. */
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
if (version != JPEG_LIB_VERSION) if (version != JPEG_LIB_VERSION)
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
if (structsize != SIZEOF(struct jpeg_decompress_struct)) if (structsize != SIZEOF(struct jpeg_decompress_struct))
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
(int) SIZEOF(struct jpeg_decompress_struct), (int) structsize); (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
/* For debugging purposes, we zero the whole master structure. /* For debugging purposes, we zero the whole master structure.
* But the application has already set the err pointer, and may have set * But the application has already set the err pointer, and may have set
@@ -121,22 +121,22 @@ default_decompress_parms (j_decompress_ptr cinfo)
cinfo->jpeg_color_space = JCS_GRAYSCALE; cinfo->jpeg_color_space = JCS_GRAYSCALE;
cinfo->out_color_space = JCS_GRAYSCALE; cinfo->out_color_space = JCS_GRAYSCALE;
break; break;
case 3: case 3:
if (cinfo->saw_JFIF_marker) { if (cinfo->saw_JFIF_marker) {
cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
} else if (cinfo->saw_Adobe_marker) { } else if (cinfo->saw_Adobe_marker) {
switch (cinfo->Adobe_transform) { switch (cinfo->Adobe_transform) {
case 0: case 0:
cinfo->jpeg_color_space = JCS_RGB; cinfo->jpeg_color_space = JCS_RGB;
break; break;
case 1: case 1:
cinfo->jpeg_color_space = JCS_YCbCr; cinfo->jpeg_color_space = JCS_YCbCr;
break; break;
default: default:
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
break; break;
} }
} else { } else {
/* Saw no special markers, try to guess from the component IDs */ /* Saw no special markers, try to guess from the component IDs */
@@ -145,31 +145,31 @@ default_decompress_parms (j_decompress_ptr cinfo)
int cid2 = cinfo->comp_info[2].component_id; int cid2 = cinfo->comp_info[2].component_id;
if (cid0 == 1 && cid1 == 2 && cid2 == 3) if (cid0 == 1 && cid1 == 2 && cid2 == 3)
cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
else if (cid0 == 82 && cid1 == 71 && cid2 == 66) else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
else { else {
TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
} }
} }
/* Always guess RGB is proper output colorspace. */ /* Always guess RGB is proper output colorspace. */
cinfo->out_color_space = JCS_RGB; cinfo->out_color_space = JCS_RGB;
break; break;
case 4: case 4:
if (cinfo->saw_Adobe_marker) { if (cinfo->saw_Adobe_marker) {
switch (cinfo->Adobe_transform) { switch (cinfo->Adobe_transform) {
case 0: case 0:
cinfo->jpeg_color_space = JCS_CMYK; cinfo->jpeg_color_space = JCS_CMYK;
break; break;
case 2: case 2:
cinfo->jpeg_color_space = JCS_YCCK; cinfo->jpeg_color_space = JCS_YCCK;
break; break;
default: default:
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
break; break;
} }
} else { } else {
/* No special markers, assume straight CMYK. */ /* No special markers, assume straight CMYK. */
@@ -177,7 +177,7 @@ default_decompress_parms (j_decompress_ptr cinfo)
} }
cinfo->out_color_space = JCS_CMYK; cinfo->out_color_space = JCS_CMYK;
break; break;
default: default:
cinfo->jpeg_color_space = JCS_UNKNOWN; cinfo->jpeg_color_space = JCS_UNKNOWN;
cinfo->out_color_space = JCS_UNKNOWN; cinfo->out_color_space = JCS_UNKNOWN;
@@ -185,7 +185,7 @@ default_decompress_parms (j_decompress_ptr cinfo)
} }
/* Set defaults for other decompression parameters. */ /* Set defaults for other decompression parameters. */
cinfo->scale_num = 1; /* 1:1 scaling */ cinfo->scale_num = 1; /* 1:1 scaling */
cinfo->scale_denom = 1; cinfo->scale_denom = 1;
cinfo->output_gamma = 1.0; cinfo->output_gamma = 1.0;
cinfo->buffered_image = FALSE; cinfo->buffered_image = FALSE;
@@ -253,7 +253,7 @@ jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
retcode = JPEG_HEADER_OK; retcode = JPEG_HEADER_OK;
break; break;
case JPEG_REACHED_EOI: case JPEG_REACHED_EOI:
if (require_image) /* Complain if application wanted an image */ if (require_image) /* Complain if application wanted an image */
ERREXIT(cinfo, JERR_NO_IMAGE); ERREXIT(cinfo, JERR_NO_IMAGE);
/* Reset to start state; it would be safer to require the application to /* Reset to start state; it would be safer to require the application to
* call jpeg_abort, but we can't change it now for compatibility reasons. * call jpeg_abort, but we can't change it now for compatibility reasons.
@@ -385,7 +385,7 @@ jpeg_finish_decompress (j_decompress_ptr cinfo)
/* Read until EOI */ /* Read until EOI */
while (! cinfo->inputctl->eoi_reached) { while (! cinfo->inputctl->eoi_reached) {
if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
return FALSE; /* Suspend, come back later */ return FALSE; /* Suspend, come back later */
} }
/* Do final cleanup */ /* Do final cleanup */
(*cinfo->src->term_source) (cinfo); (*cinfo->src->term_source) (cinfo);

View File

@@ -55,24 +55,24 @@ jpeg_start_decompress (j_decompress_ptr cinfo)
if (cinfo->inputctl->has_multiple_scans) { if (cinfo->inputctl->has_multiple_scans) {
#ifdef D_MULTISCAN_FILES_SUPPORTED #ifdef D_MULTISCAN_FILES_SUPPORTED
for (;;) { for (;;) {
int retcode; int retcode;
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) if (cinfo->progress != NULL)
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
/* Absorb some more input */ /* Absorb some more input */
retcode = (*cinfo->inputctl->consume_input) (cinfo); retcode = (*cinfo->inputctl->consume_input) (cinfo);
if (retcode == JPEG_SUSPENDED) if (retcode == JPEG_SUSPENDED)
return FALSE; return FALSE;
if (retcode == JPEG_REACHED_EOI) if (retcode == JPEG_REACHED_EOI)
break; break;
/* Advance progress counter if appropriate */ /* Advance progress counter if appropriate */
if (cinfo->progress != NULL && if (cinfo->progress != NULL &&
(retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
/* jdmaster underestimated number of scans; ratchet up one scan */ /* jdmaster underestimated number of scans; ratchet up one scan */
cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
} }
} }
} }
#else #else
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
@@ -111,16 +111,16 @@ output_pass_setup (j_decompress_ptr cinfo)
JDIMENSION last_scanline; JDIMENSION last_scanline;
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) cinfo->output_scanline; cinfo->progress->pass_counter = (long) cinfo->output_scanline;
cinfo->progress->pass_limit = (long) cinfo->output_height; cinfo->progress->pass_limit = (long) cinfo->output_height;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
} }
/* Process some data */ /* Process some data */
last_scanline = cinfo->output_scanline; last_scanline = cinfo->output_scanline;
(*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL, (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
&cinfo->output_scanline, (JDIMENSION) 0); &cinfo->output_scanline, (JDIMENSION) 0);
if (cinfo->output_scanline == last_scanline) if (cinfo->output_scanline == last_scanline)
return FALSE; /* No progress made, must suspend */ return FALSE; /* No progress made, must suspend */
} }
/* Finish up dummy pass, and set up for another one */ /* Finish up dummy pass, and set up for another one */
(*cinfo->master->finish_output_pass) (cinfo); (*cinfo->master->finish_output_pass) (cinfo);
@@ -153,7 +153,7 @@ output_pass_setup (j_decompress_ptr cinfo)
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines, jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
JDIMENSION max_lines) JDIMENSION max_lines)
{ {
JDIMENSION row_ctr; JDIMENSION row_ctr;
@@ -186,7 +186,7 @@ jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
GLOBAL(JDIMENSION) GLOBAL(JDIMENSION)
jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data, jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION max_lines) JDIMENSION max_lines)
{ {
JDIMENSION lines_per_iMCU_row; JDIMENSION lines_per_iMCU_row;
@@ -211,7 +211,7 @@ jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
/* Decompress directly into user's buffer. */ /* Decompress directly into user's buffer. */
if (! (*cinfo->coef->decompress_data) (cinfo, data)) if (! (*cinfo->coef->decompress_data) (cinfo, data))
return 0; /* suspension forced, can do nothing more */ return 0; /* suspension forced, can do nothing more */
/* OK, we processed one iMCU row. */ /* OK, we processed one iMCU row. */
cinfo->output_scanline += lines_per_iMCU_row; cinfo->output_scanline += lines_per_iMCU_row;
@@ -267,9 +267,9 @@ jpeg_finish_output (j_decompress_ptr cinfo)
} }
/* Read markers looking for SOS or EOI */ /* Read markers looking for SOS or EOI */
while (cinfo->input_scan_number <= cinfo->output_scan_number && while (cinfo->input_scan_number <= cinfo->output_scan_number &&
! cinfo->inputctl->eoi_reached) { ! cinfo->inputctl->eoi_reached) {
if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
return FALSE; /* Suspend, come back later */ return FALSE; /* Suspend, come back later */
} }
cinfo->global_state = DSTATE_BUFIMAGE; cinfo->global_state = DSTATE_BUFIMAGE;
return TRUE; return TRUE;

298
jdarith.c
View File

@@ -32,7 +32,7 @@ typedef struct {
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */ int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
/* Pointers to statistics areas (these workspaces have image lifespan) */ /* Pointers to statistics areas (these workspaces have image lifespan) */
unsigned char * dc_stats[NUM_ARITH_TBLS]; unsigned char * dc_stats[NUM_ARITH_TBLS];
@@ -115,32 +115,32 @@ arith_decode (j_decompress_ptr cinfo, unsigned char *st)
if (--e->ct < 0) { if (--e->ct < 0) {
/* Need to fetch next data byte */ /* Need to fetch next data byte */
if (cinfo->unread_marker) if (cinfo->unread_marker)
data = 0; /* stuff zero data */ data = 0; /* stuff zero data */
else { else {
data = get_byte(cinfo); /* read next input byte */ data = get_byte(cinfo); /* read next input byte */
if (data == 0xFF) { /* zero stuff or marker code */ if (data == 0xFF) { /* zero stuff or marker code */
do data = get_byte(cinfo); do data = get_byte(cinfo);
while (data == 0xFF); /* swallow extra 0xFF bytes */ while (data == 0xFF); /* swallow extra 0xFF bytes */
if (data == 0) if (data == 0)
data = 0xFF; /* discard stuffed zero byte */ data = 0xFF; /* discard stuffed zero byte */
else { else {
/* Note: Different from the Huffman decoder, hitting /* Note: Different from the Huffman decoder, hitting
* a marker while processing the compressed data * a marker while processing the compressed data
* segment is legal in arithmetic coding. * segment is legal in arithmetic coding.
* The convention is to supply zero data * The convention is to supply zero data
* then until decoding is complete. * then until decoding is complete.
*/ */
cinfo->unread_marker = data; cinfo->unread_marker = data;
data = 0; data = 0;
} }
} }
} }
e->c = (e->c << 8) | data; /* insert data into C register */ e->c = (e->c << 8) | data; /* insert data into C register */
if ((e->ct += 8) < 0) /* update bit shift counter */ if ((e->ct += 8) < 0) /* update bit shift counter */
/* Need more initial bytes */ /* Need more initial bytes */
if (++e->ct == 0) if (++e->ct == 0)
/* Got 2 initial bytes -> re-init A and exit loop */ /* Got 2 initial bytes -> re-init A and exit loop */
e->a = 0x8000L; /* => e->a = 0x10000L after loop exit */ e->a = 0x8000L; /* => e->a = 0x10000L after loop exit */
} }
e->a <<= 1; e->a <<= 1;
} }
@@ -149,9 +149,9 @@ arith_decode (j_decompress_ptr cinfo, unsigned char *st)
* Qe values and probability estimation state machine * Qe values and probability estimation state machine
*/ */
sv = *st; sv = *st;
qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */ qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */
nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */ nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */
nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */ nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */
/* Decode & estimation procedures per sections D.2.4 & D.2.5 */ /* Decode & estimation procedures per sections D.2.4 & D.2.5 */
temp = e->a - qe; temp = e->a - qe;
@@ -162,19 +162,19 @@ arith_decode (j_decompress_ptr cinfo, unsigned char *st)
/* Conditional LPS (less probable symbol) exchange */ /* Conditional LPS (less probable symbol) exchange */
if (e->a < qe) { if (e->a < qe) {
e->a = qe; e->a = qe;
*st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
} else { } else {
e->a = qe; e->a = qe;
*st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
sv ^= 0x80; /* Exchange LPS/MPS */ sv ^= 0x80; /* Exchange LPS/MPS */
} }
} else if (e->a < 0x8000L) { } else if (e->a < 0x8000L) {
/* Conditional MPS (more probable symbol) exchange */ /* Conditional MPS (more probable symbol) exchange */
if (e->a < qe) { if (e->a < qe) {
*st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
sv ^= 0x80; /* Exchange LPS/MPS */ sv ^= 0x80; /* Exchange LPS/MPS */
} else { } else {
*st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
} }
} }
@@ -214,7 +214,7 @@ process_restart (j_decompress_ptr cinfo)
/* Reset arithmetic decoding variables */ /* Reset arithmetic decoding variables */
entropy->c = 0; entropy->c = 0;
entropy->a = 0; entropy->a = 0;
entropy->ct = -16; /* force reading 2 initial bytes to fill C */ entropy->ct = -16; /* force reading 2 initial bytes to fill C */
/* Reset restart counter */ /* Reset restart counter */
entropy->restarts_to_go = cinfo->restart_interval; entropy->restarts_to_go = cinfo->restart_interval;
@@ -253,7 +253,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
if (entropy->ct == -1) return TRUE; /* if error do nothing */ if (entropy->ct == -1) return TRUE; /* if error do nothing */
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@@ -277,28 +277,28 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
st += 2; st += sign; st += 2; st += sign;
/* Figure F.23: Decoding the magnitude category of v */ /* Figure F.23: Decoding the magnitude category of v */
if ((m = arith_decode(cinfo, st)) != 0) { if ((m = arith_decode(cinfo, st)) != 0) {
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == 0x8000) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
} }
st += 1; st += 1;
} }
} }
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
entropy->dc_context[ci] = 0; /* zero diff category */ entropy->dc_context[ci] = 0; /* zero diff category */
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */ entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */
else else
entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */ entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */
v = m; v = m;
/* Figure F.24: Decoding the magnitude bit pattern of v */ /* Figure F.24: Decoding the magnitude bit pattern of v */
st += 14; st += 14;
while (m >>= 1) while (m >>= 1)
if (arith_decode(cinfo, st)) v |= m; if (arith_decode(cinfo, st)) v |= m;
v += 1; if (sign) v = -v; v += 1; if (sign) v = -v;
entropy->last_dc_val[ci] += v; entropy->last_dc_val[ci] += v;
} }
@@ -332,7 +332,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
if (entropy->ct == -1) return TRUE; /* if error do nothing */ if (entropy->ct == -1) return TRUE; /* if error do nothing */
/* There is always only one block per MCU */ /* There is always only one block per MCU */
block = MCU_data[0]; block = MCU_data[0];
@@ -343,13 +343,13 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.20: Decode_AC_coefficients */ /* Figure F.20: Decode_AC_coefficients */
for (k = cinfo->Ss; k <= cinfo->Se; k++) { for (k = cinfo->Ss; k <= cinfo->Se; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
if (arith_decode(cinfo, st)) break; /* EOB flag */ if (arith_decode(cinfo, st)) break; /* EOB flag */
while (arith_decode(cinfo, st + 1) == 0) { while (arith_decode(cinfo, st + 1) == 0) {
st += 3; k++; st += 3; k++;
if (k > cinfo->Se) { if (k > cinfo->Se) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* spectral overflow */ entropy->ct = -1; /* spectral overflow */
return TRUE; return TRUE;
} }
} }
/* Figure F.21: Decoding nonzero value v */ /* Figure F.21: Decoding nonzero value v */
@@ -359,17 +359,17 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.23: Decoding the magnitude category of v */ /* Figure F.23: Decoding the magnitude category of v */
if ((m = arith_decode(cinfo, st)) != 0) { if ((m = arith_decode(cinfo, st)) != 0) {
if (arith_decode(cinfo, st)) { if (arith_decode(cinfo, st)) {
m <<= 1; m <<= 1;
st = entropy->ac_stats[tbl] + st = entropy->ac_stats[tbl] +
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217); (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == 0x8000) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
} }
st += 1; st += 1;
} }
} }
} }
v = m; v = m;
@@ -404,8 +404,8 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
st = entropy->fixed_bin; /* use fixed probability estimation */ st = entropy->fixed_bin; /* use fixed probability estimation */
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@@ -440,14 +440,14 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
if (entropy->ct == -1) return TRUE; /* if error do nothing */ if (entropy->ct == -1) return TRUE; /* if error do nothing */
/* There is always only one block per MCU */ /* There is always only one block per MCU */
block = MCU_data[0]; block = MCU_data[0];
tbl = cinfo->cur_comp_info[0]->ac_tbl_no; tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */ m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
/* Establish EOBx (previous stage end-of-block) index */ /* Establish EOBx (previous stage end-of-block) index */
for (kex = cinfo->Se; kex > 0; kex--) for (kex = cinfo->Se; kex > 0; kex--)
@@ -456,30 +456,30 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
for (k = cinfo->Ss; k <= cinfo->Se; k++) { for (k = cinfo->Ss; k <= cinfo->Se; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
if (k > kex) if (k > kex)
if (arith_decode(cinfo, st)) break; /* EOB flag */ if (arith_decode(cinfo, st)) break; /* EOB flag */
for (;;) { for (;;) {
thiscoef = *block + jpeg_natural_order[k]; thiscoef = *block + jpeg_natural_order[k];
if (*thiscoef) { /* previously nonzero coef */ if (*thiscoef) { /* previously nonzero coef */
if (arith_decode(cinfo, st + 2)) { if (arith_decode(cinfo, st + 2)) {
if (*thiscoef < 0) if (*thiscoef < 0)
*thiscoef += m1; *thiscoef += m1;
else else
*thiscoef += p1; *thiscoef += p1;
} }
break; break;
} }
if (arith_decode(cinfo, st + 1)) { /* newly nonzero coef */ if (arith_decode(cinfo, st + 1)) { /* newly nonzero coef */
if (arith_decode(cinfo, entropy->fixed_bin)) if (arith_decode(cinfo, entropy->fixed_bin))
*thiscoef = m1; *thiscoef = m1;
else else
*thiscoef = p1; *thiscoef = p1;
break; break;
} }
st += 3; k++; st += 3; k++;
if (k > cinfo->Se) { if (k > cinfo->Se) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* spectral overflow */ entropy->ct = -1; /* spectral overflow */
return TRUE; return TRUE;
} }
} }
} }
@@ -509,7 +509,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
entropy->restarts_to_go--; entropy->restarts_to_go--;
} }
if (entropy->ct == -1) return TRUE; /* if error do nothing */ if (entropy->ct == -1) return TRUE; /* if error do nothing */
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
@@ -535,28 +535,28 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
st += 2; st += sign; st += 2; st += sign;
/* Figure F.23: Decoding the magnitude category of v */ /* Figure F.23: Decoding the magnitude category of v */
if ((m = arith_decode(cinfo, st)) != 0) { if ((m = arith_decode(cinfo, st)) != 0) {
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == 0x8000) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
} }
st += 1; st += 1;
} }
} }
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
entropy->dc_context[ci] = 0; /* zero diff category */ entropy->dc_context[ci] = 0; /* zero diff category */
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */ entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */
else else
entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */ entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */
v = m; v = m;
/* Figure F.24: Decoding the magnitude bit pattern of v */ /* Figure F.24: Decoding the magnitude bit pattern of v */
st += 14; st += 14;
while (m >>= 1) while (m >>= 1)
if (arith_decode(cinfo, st)) v |= m; if (arith_decode(cinfo, st)) v |= m;
v += 1; if (sign) v = -v; v += 1; if (sign) v = -v;
entropy->last_dc_val[ci] += v; entropy->last_dc_val[ci] += v;
} }
@@ -570,14 +570,14 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Figure F.20: Decode_AC_coefficients */ /* Figure F.20: Decode_AC_coefficients */
for (k = 1; k <= DCTSIZE2 - 1; k++) { for (k = 1; k <= DCTSIZE2 - 1; k++) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * (k - 1);
if (arith_decode(cinfo, st)) break; /* EOB flag */ if (arith_decode(cinfo, st)) break; /* EOB flag */
while (arith_decode(cinfo, st + 1) == 0) { while (arith_decode(cinfo, st + 1) == 0) {
st += 3; k++; st += 3; k++;
if (k > DCTSIZE2 - 1) { if (k > DCTSIZE2 - 1) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* spectral overflow */ entropy->ct = -1; /* spectral overflow */
return TRUE; return TRUE;
} }
} }
/* Figure F.21: Decoding nonzero value v */ /* Figure F.21: Decoding nonzero value v */
/* Figure F.22: Decoding the sign of v */ /* Figure F.22: Decoding the sign of v */
@@ -585,25 +585,25 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
st += 2; st += 2;
/* Figure F.23: Decoding the magnitude category of v */ /* Figure F.23: Decoding the magnitude category of v */
if ((m = arith_decode(cinfo, st)) != 0) { if ((m = arith_decode(cinfo, st)) != 0) {
if (arith_decode(cinfo, st)) { if (arith_decode(cinfo, st)) {
m <<= 1; m <<= 1;
st = entropy->ac_stats[tbl] + st = entropy->ac_stats[tbl] +
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217); (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
while (arith_decode(cinfo, st)) { while (arith_decode(cinfo, st)) {
if ((m <<= 1) == 0x8000) { if ((m <<= 1) == 0x8000) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* magnitude overflow */ entropy->ct = -1; /* magnitude overflow */
return TRUE; return TRUE;
} }
st += 1; st += 1;
} }
} }
} }
v = m; v = m;
/* Figure F.24: Decoding the magnitude bit pattern of v */ /* Figure F.24: Decoding the magnitude bit pattern of v */
st += 14; st += 14;
while (m >>= 1) while (m >>= 1)
if (arith_decode(cinfo, st)) v |= m; if (arith_decode(cinfo, st)) v |= m;
v += 1; if (sign) v = -v; v += 1; if (sign) v = -v;
(*block)[jpeg_natural_order[k]] = (JCOEF) v; (*block)[jpeg_natural_order[k]] = (JCOEF) v;
} }
@@ -628,24 +628,24 @@ start_pass (j_decompress_ptr cinfo)
/* Validate progressive scan parameters */ /* Validate progressive scan parameters */
if (cinfo->Ss == 0) { if (cinfo->Ss == 0) {
if (cinfo->Se != 0) if (cinfo->Se != 0)
goto bad; goto bad;
} else { } else {
/* need not check Ss/Se < 0 since they came from unsigned bytes */ /* need not check Ss/Se < 0 since they came from unsigned bytes */
if (cinfo->Se < cinfo->Ss || cinfo->Se > DCTSIZE2 - 1) if (cinfo->Se < cinfo->Ss || cinfo->Se > DCTSIZE2 - 1)
goto bad; goto bad;
/* AC scans may have only one component */ /* AC scans may have only one component */
if (cinfo->comps_in_scan != 1) if (cinfo->comps_in_scan != 1)
goto bad; goto bad;
} }
if (cinfo->Ah != 0) { if (cinfo->Ah != 0) {
/* Successive approximation refinement scan: must have Al = Ah-1. */ /* Successive approximation refinement scan: must have Al = Ah-1. */
if (cinfo->Ah-1 != cinfo->Al) if (cinfo->Ah-1 != cinfo->Al)
goto bad; goto bad;
} }
if (cinfo->Al > 13) { /* need not check for < 0 */ if (cinfo->Al > 13) { /* need not check for < 0 */
bad: bad:
ERREXIT4(cinfo, JERR_BAD_PROGRESSION, ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
} }
/* Update progression status, and verify that scan order is legal. /* Update progression status, and verify that scan order is legal.
* Note that inter-scan inconsistencies are treated as warnings * Note that inter-scan inconsistencies are treated as warnings
@@ -655,32 +655,32 @@ start_pass (j_decompress_ptr cinfo)
int coefi, cindex = cinfo->cur_comp_info[ci]->component_index; int coefi, cindex = cinfo->cur_comp_info[ci]->component_index;
int *coef_bit_ptr = & cinfo->coef_bits[cindex][0]; int *coef_bit_ptr = & cinfo->coef_bits[cindex][0];
if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
if (cinfo->Ah != expected) if (cinfo->Ah != expected)
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
coef_bit_ptr[coefi] = cinfo->Al; coef_bit_ptr[coefi] = cinfo->Al;
} }
} }
/* Select MCU decoding routine */ /* Select MCU decoding routine */
if (cinfo->Ah == 0) { if (cinfo->Ah == 0) {
if (cinfo->Ss == 0) if (cinfo->Ss == 0)
entropy->pub.decode_mcu = decode_mcu_DC_first; entropy->pub.decode_mcu = decode_mcu_DC_first;
else else
entropy->pub.decode_mcu = decode_mcu_AC_first; entropy->pub.decode_mcu = decode_mcu_AC_first;
} else { } else {
if (cinfo->Ss == 0) if (cinfo->Ss == 0)
entropy->pub.decode_mcu = decode_mcu_DC_refine; entropy->pub.decode_mcu = decode_mcu_DC_refine;
else else
entropy->pub.decode_mcu = decode_mcu_AC_refine; entropy->pub.decode_mcu = decode_mcu_AC_refine;
} }
} else { } else {
/* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
* This ought to be an error condition, but we make it a warning. * This ought to be an error condition, but we make it a warning.
*/ */
if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 || if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 ||
(cinfo->Se < DCTSIZE2 && cinfo->Se != DCTSIZE2 - 1)) (cinfo->Se < DCTSIZE2 && cinfo->Se != DCTSIZE2 - 1))
WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
/* Select MCU decoding routine */ /* Select MCU decoding routine */
entropy->pub.decode_mcu = decode_mcu; entropy->pub.decode_mcu = decode_mcu;
@@ -692,10 +692,10 @@ start_pass (j_decompress_ptr cinfo)
if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) { if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
tbl = compptr->dc_tbl_no; tbl = compptr->dc_tbl_no;
if (tbl < 0 || tbl >= NUM_ARITH_TBLS) if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
if (entropy->dc_stats[tbl] == NULL) if (entropy->dc_stats[tbl] == NULL)
entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS); ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS);
MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS); MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
/* Initialize DC predictions to 0 */ /* Initialize DC predictions to 0 */
entropy->last_dc_val[ci] = 0; entropy->last_dc_val[ci] = 0;
@@ -704,10 +704,10 @@ start_pass (j_decompress_ptr cinfo)
if (! cinfo->progressive_mode || cinfo->Ss) { if (! cinfo->progressive_mode || cinfo->Ss) {
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
if (tbl < 0 || tbl >= NUM_ARITH_TBLS) if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
if (entropy->ac_stats[tbl] == NULL) if (entropy->ac_stats[tbl] == NULL)
entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS); ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS);
MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS); MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
} }
} }
@@ -715,7 +715,7 @@ start_pass (j_decompress_ptr cinfo)
/* Initialize arithmetic decoding variables */ /* Initialize arithmetic decoding variables */
entropy->c = 0; entropy->c = 0;
entropy->a = 0; entropy->a = 0;
entropy->ct = -16; /* force reading 2 initial bytes to fill C */ entropy->ct = -16; /* force reading 2 initial bytes to fill C */
/* Initialize restart counter */ /* Initialize restart counter */
entropy->restarts_to_go = cinfo->restart_interval; entropy->restarts_to_go = cinfo->restart_interval;
@@ -734,7 +734,7 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
entropy = (arith_entropy_ptr) entropy = (arith_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(arith_entropy_decoder)); SIZEOF(arith_entropy_decoder));
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
entropy->pub.start_pass = start_pass; entropy->pub.start_pass = start_pass;
@@ -752,10 +752,10 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
int *coef_bit_ptr, ci; int *coef_bit_ptr, ci;
cinfo->coef_bits = (int (*)[DCTSIZE2]) cinfo->coef_bits = (int (*)[DCTSIZE2])
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->num_components*DCTSIZE2*SIZEOF(int)); cinfo->num_components*DCTSIZE2*SIZEOF(int));
coef_bit_ptr = & cinfo->coef_bits[0][0]; coef_bit_ptr = & cinfo->coef_bits[0][0];
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
for (i = 0; i < DCTSIZE2; i++) for (i = 0; i < DCTSIZE2; i++)
*coef_bit_ptr++ = -1; *coef_bit_ptr++ = -1;
} }
} }

View File

@@ -22,13 +22,13 @@
#include "jpeglib.h" #include "jpeglib.h"
#include "jerror.h" #include "jerror.h"
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
extern void * malloc JPP((size_t size)); extern void * malloc JPP((size_t size));
extern void free JPP((void *ptr)); extern void free JPP((void *ptr));
#endif #endif
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ #define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
/* Expanded data destination object for memory output */ /* Expanded data destination object for memory output */
@@ -36,10 +36,10 @@ extern void free JPP((void *ptr));
typedef struct { typedef struct {
struct jpeg_destination_mgr pub; /* public fields */ struct jpeg_destination_mgr pub; /* public fields */
unsigned char ** outbuffer; /* target buffer */ unsigned char ** outbuffer; /* target buffer */
unsigned long * outsize; unsigned long * outsize;
unsigned char * newbuffer; /* newly allocated buffer */ unsigned char * newbuffer; /* newly allocated buffer */
JOCTET * buffer; /* start of buffer */ JOCTET * buffer; /* start of buffer */
size_t bufsize; size_t bufsize;
boolean alloc; boolean alloc;
} my_mem_destination_mgr; } my_mem_destination_mgr;
@@ -147,21 +147,21 @@ term_mem_destination (j_compress_ptr cinfo)
GLOBAL(void) GLOBAL(void)
jpeg_mem_dest_tj (j_compress_ptr cinfo, jpeg_mem_dest_tj (j_compress_ptr cinfo,
unsigned char ** outbuffer, unsigned long * outsize, unsigned char ** outbuffer, unsigned long * outsize,
boolean alloc) boolean alloc)
{ {
my_mem_dest_ptr dest; my_mem_dest_ptr dest;
if (outbuffer == NULL || outsize == NULL) /* sanity check */ if (outbuffer == NULL || outsize == NULL) /* sanity check */
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* The destination object is made permanent so that multiple JPEG images /* The destination object is made permanent so that multiple JPEG images
* can be written to the same buffer without re-executing jpeg_mem_dest. * can be written to the same buffer without re-executing jpeg_mem_dest.
*/ */
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_mem_destination_mgr)); SIZEOF(my_mem_destination_mgr));
dest = (my_mem_dest_ptr) cinfo->dest; dest = (my_mem_dest_ptr) cinfo->dest;
dest->newbuffer = NULL; dest->newbuffer = NULL;
} }

View File

@@ -22,7 +22,7 @@
#include "jpeglib.h" #include "jpeglib.h"
#include "jerror.h" #include "jerror.h"
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
extern void * malloc JPP((size_t size)); extern void * malloc JPP((size_t size));
extern void free JPP((void *ptr)); extern void free JPP((void *ptr));
#endif #endif
@@ -33,13 +33,13 @@ extern void free JPP((void *ptr));
typedef struct { typedef struct {
struct jpeg_destination_mgr pub; /* public fields */ struct jpeg_destination_mgr pub; /* public fields */
FILE * outfile; /* target stream */ FILE * outfile; /* target stream */
JOCTET * buffer; /* start of buffer */ JOCTET * buffer; /* start of buffer */
} my_destination_mgr; } my_destination_mgr;
typedef my_destination_mgr * my_dest_ptr; typedef my_destination_mgr * my_dest_ptr;
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ #define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED) #if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
@@ -48,10 +48,10 @@ typedef my_destination_mgr * my_dest_ptr;
typedef struct { typedef struct {
struct jpeg_destination_mgr pub; /* public fields */ struct jpeg_destination_mgr pub; /* public fields */
unsigned char ** outbuffer; /* target buffer */ unsigned char ** outbuffer; /* target buffer */
unsigned long * outsize; unsigned long * outsize;
unsigned char * newbuffer; /* newly allocated buffer */ unsigned char * newbuffer; /* newly allocated buffer */
JOCTET * buffer; /* start of buffer */ JOCTET * buffer; /* start of buffer */
size_t bufsize; size_t bufsize;
} my_mem_destination_mgr; } my_mem_destination_mgr;
@@ -72,7 +72,7 @@ init_destination (j_compress_ptr cinfo)
/* Allocate the output buffer --- it will be released when done with image */ /* Allocate the output buffer --- it will be released when done with image */
dest->buffer = (JOCTET *) dest->buffer = (JOCTET *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
OUTPUT_BUF_SIZE * SIZEOF(JOCTET)); OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
dest->pub.next_output_byte = dest->buffer; dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
@@ -213,10 +213,10 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
* manager serially with the same JPEG object, because their private object * manager serially with the same JPEG object, because their private object
* sizes may be different. Caveat programmer. * sizes may be different. Caveat programmer.
*/ */
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_destination_mgr)); SIZEOF(my_destination_mgr));
} }
dest = (my_dest_ptr) cinfo->dest; dest = (my_dest_ptr) cinfo->dest;
@@ -241,20 +241,20 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
GLOBAL(void) GLOBAL(void)
jpeg_mem_dest (j_compress_ptr cinfo, jpeg_mem_dest (j_compress_ptr cinfo,
unsigned char ** outbuffer, unsigned long * outsize) unsigned char ** outbuffer, unsigned long * outsize)
{ {
my_mem_dest_ptr dest; my_mem_dest_ptr dest;
if (outbuffer == NULL || outsize == NULL) /* sanity check */ if (outbuffer == NULL || outsize == NULL) /* sanity check */
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* The destination object is made permanent so that multiple JPEG images /* The destination object is made permanent so that multiple JPEG images
* can be written to the same buffer without re-executing jpeg_mem_dest. * can be written to the same buffer without re-executing jpeg_mem_dest.
*/ */
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_mem_destination_mgr)); SIZEOF(my_mem_destination_mgr));
} }
dest = (my_mem_dest_ptr) cinfo->dest; dest = (my_mem_dest_ptr) cinfo->dest;

View File

@@ -157,21 +157,21 @@ term_source (j_decompress_ptr cinfo)
GLOBAL(void) GLOBAL(void)
jpeg_mem_src_tj (j_decompress_ptr cinfo, jpeg_mem_src_tj (j_decompress_ptr cinfo,
unsigned char * inbuffer, unsigned long insize) unsigned char * inbuffer, unsigned long insize)
{ {
struct jpeg_source_mgr * src; struct jpeg_source_mgr * src;
if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */ if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */
ERREXIT(cinfo, JERR_INPUT_EMPTY); ERREXIT(cinfo, JERR_INPUT_EMPTY);
/* The source object is made permanent so that a series of JPEG images /* The source object is made permanent so that a series of JPEG images
* can be read from the same buffer by calling jpeg_mem_src only before * can be read from the same buffer by calling jpeg_mem_src only before
* the first one. * the first one.
*/ */
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *) cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(struct jpeg_source_mgr)); SIZEOF(struct jpeg_source_mgr));
} }
src = cinfo->src; src = cinfo->src;

View File

@@ -26,16 +26,16 @@
/* Expanded data source object for stdio input */ /* Expanded data source object for stdio input */
typedef struct { typedef struct {
struct jpeg_source_mgr pub; /* public fields */ struct jpeg_source_mgr pub; /* public fields */
FILE * infile; /* source stream */ FILE * infile; /* source stream */
JOCTET * buffer; /* start of buffer */ JOCTET * buffer; /* start of buffer */
boolean start_of_file; /* have we gotten any data yet? */ boolean start_of_file; /* have we gotten any data yet? */
} my_source_mgr; } my_source_mgr;
typedef my_source_mgr * my_src_ptr; typedef my_source_mgr * my_src_ptr;
#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */ #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
/* /*
@@ -106,7 +106,7 @@ fill_input_buffer (j_decompress_ptr cinfo)
nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE); nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
if (nbytes <= 0) { if (nbytes <= 0) {
if (src->start_of_file) /* Treat empty input file as fatal error */ if (src->start_of_file) /* Treat empty input file as fatal error */
ERREXIT(cinfo, JERR_INPUT_EMPTY); ERREXIT(cinfo, JERR_INPUT_EMPTY);
WARNMS(cinfo, JWRN_JPEG_EOF); WARNMS(cinfo, JWRN_JPEG_EOF);
/* Insert a fake EOI marker */ /* Insert a fake EOI marker */
@@ -224,14 +224,14 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
* This makes it unsafe to use this manager and a different source * This makes it unsafe to use this manager and a different source
* manager serially with the same JPEG object. Caveat programmer. * manager serially with the same JPEG object. Caveat programmer.
*/ */
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *) cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_source_mgr)); SIZEOF(my_source_mgr));
src = (my_src_ptr) cinfo->src; src = (my_src_ptr) cinfo->src;
src->buffer = (JOCTET *) src->buffer = (JOCTET *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
INPUT_BUF_SIZE * SIZEOF(JOCTET)); INPUT_BUF_SIZE * SIZEOF(JOCTET));
} }
src = (my_src_ptr) cinfo->src; src = (my_src_ptr) cinfo->src;
@@ -254,21 +254,21 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
GLOBAL(void) GLOBAL(void)
jpeg_mem_src (j_decompress_ptr cinfo, jpeg_mem_src (j_decompress_ptr cinfo,
unsigned char * inbuffer, unsigned long insize) unsigned char * inbuffer, unsigned long insize)
{ {
struct jpeg_source_mgr * src; struct jpeg_source_mgr * src;
if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */ if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */
ERREXIT(cinfo, JERR_INPUT_EMPTY); ERREXIT(cinfo, JERR_INPUT_EMPTY);
/* The source object is made permanent so that a series of JPEG images /* The source object is made permanent so that a series of JPEG images
* can be read from the same buffer by calling jpeg_mem_src only before * can be read from the same buffer by calling jpeg_mem_src only before
* the first one. * the first one.
*/ */
if (cinfo->src == NULL) { /* first time for this JPEG object? */ if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *) cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(struct jpeg_source_mgr)); SIZEOF(struct jpeg_source_mgr));
} }
src = cinfo->src; src = cinfo->src;

View File

@@ -33,9 +33,9 @@ typedef struct {
/* These variables keep track of the current location of the input side. */ /* These variables keep track of the current location of the input side. */
/* cinfo->input_iMCU_row is also used for this. */ /* cinfo->input_iMCU_row is also used for this. */
JDIMENSION MCU_ctr; /* counts MCUs processed in current row */ JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
int MCU_vert_offset; /* counts MCU rows within iMCU row */ int MCU_vert_offset; /* counts MCU rows within iMCU row */
int MCU_rows_per_iMCU_row; /* number of such rows needed */ int MCU_rows_per_iMCU_row; /* number of such rows needed */
/* The output side's location is represented by cinfo->output_iMCU_row. */ /* The output side's location is represented by cinfo->output_iMCU_row. */
@@ -61,7 +61,7 @@ typedef struct {
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
/* When doing block smoothing, we latch coefficient Al values here */ /* When doing block smoothing, we latch coefficient Al values here */
int * coef_bits_latch; int * coef_bits_latch;
#define SAVED_COEFS 6 /* we save coef_bits[0..5] */ #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
#endif #endif
} my_coef_controller; } my_coef_controller;
@@ -69,15 +69,15 @@ typedef my_coef_controller * my_coef_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(int) decompress_onepass METHODDEF(int) decompress_onepass
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
#ifdef D_MULTISCAN_FILES_SUPPORTED #ifdef D_MULTISCAN_FILES_SUPPORTED
METHODDEF(int) decompress_data METHODDEF(int) decompress_data
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
#endif #endif
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo)); LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
METHODDEF(int) decompress_smooth_data METHODDEF(int) decompress_smooth_data
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
#endif #endif
@@ -153,7 +153,7 @@ METHODDEF(int)
decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */ JDIMENSION MCU_col_num; /* index of current MCU within row */
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
int blkn, ci, xindex, yindex, yoffset, useful_width; int blkn, ci, xindex, yindex, yoffset, useful_width;
@@ -166,49 +166,49 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
yoffset++) { yoffset++) {
for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
MCU_col_num++) { MCU_col_num++) {
/* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
jzero_far((void FAR *) coef->MCU_buffer[0], jzero_far((void FAR *) coef->MCU_buffer[0],
(size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK))); (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
coef->MCU_ctr = MCU_col_num; coef->MCU_ctr = MCU_col_num;
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} }
/* Determine where data should go in output_buf and do the IDCT thing. /* Determine where data should go in output_buf and do the IDCT thing.
* We skip dummy blocks at the right and bottom edges (but blkn gets * We skip dummy blocks at the right and bottom edges (but blkn gets
* incremented past them!). Note the inner loop relies on having * incremented past them!). Note the inner loop relies on having
* allocated the MCU_buffer[] blocks sequentially. * allocated the MCU_buffer[] blocks sequentially.
*/ */
blkn = 0; /* index of current DCT block within MCU */ blkn = 0; /* index of current DCT block within MCU */
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
/* Don't bother to IDCT an uninteresting component. */ /* Don't bother to IDCT an uninteresting component. */
if (! compptr->component_needed) { if (! compptr->component_needed) {
blkn += compptr->MCU_blocks; blkn += compptr->MCU_blocks;
continue; continue;
} }
inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index]; inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
: compptr->last_col_width; : compptr->last_col_width;
output_ptr = output_buf[compptr->component_index] + output_ptr = output_buf[compptr->component_index] +
yoffset * compptr->_DCT_scaled_size; yoffset * compptr->_DCT_scaled_size;
start_col = MCU_col_num * compptr->MCU_sample_width; start_col = MCU_col_num * compptr->MCU_sample_width;
for (yindex = 0; yindex < compptr->MCU_height; yindex++) { for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
if (cinfo->input_iMCU_row < last_iMCU_row || if (cinfo->input_iMCU_row < last_iMCU_row ||
yoffset+yindex < compptr->last_row_height) { yoffset+yindex < compptr->last_row_height) {
output_col = start_col; output_col = start_col;
for (xindex = 0; xindex < useful_width; xindex++) { for (xindex = 0; xindex < useful_width; xindex++) {
(*inverse_DCT) (cinfo, compptr, (*inverse_DCT) (cinfo, compptr,
(JCOEFPTR) coef->MCU_buffer[blkn+xindex], (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
output_ptr, output_col); output_ptr, output_col);
output_col += compptr->_DCT_scaled_size; output_col += compptr->_DCT_scaled_size;
} }
} }
blkn += compptr->MCU_width; blkn += compptr->MCU_width;
output_ptr += compptr->_DCT_scaled_size; output_ptr += compptr->_DCT_scaled_size;
} }
} }
} }
/* Completed an MCU row, but perhaps not an iMCU row */ /* Completed an MCU row, but perhaps not an iMCU row */
@@ -233,7 +233,7 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
METHODDEF(int) METHODDEF(int)
dummy_consume_data (j_decompress_ptr cinfo) dummy_consume_data (j_decompress_ptr cinfo)
{ {
return JPEG_SUSPENDED; /* Always indicate nothing was done */ return JPEG_SUSPENDED; /* Always indicate nothing was done */
} }
@@ -250,7 +250,7 @@ METHODDEF(int)
consume_data (j_decompress_ptr cinfo) consume_data (j_decompress_ptr cinfo)
{ {
my_coef_ptr coef = (my_coef_ptr) cinfo->coef; my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
JDIMENSION MCU_col_num; /* index of current MCU within row */ JDIMENSION MCU_col_num; /* index of current MCU within row */
int blkn, ci, xindex, yindex, yoffset; int blkn, ci, xindex, yindex, yoffset;
JDIMENSION start_col; JDIMENSION start_col;
JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
@@ -274,25 +274,25 @@ consume_data (j_decompress_ptr cinfo)
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
yoffset++) { yoffset++) {
for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
MCU_col_num++) { MCU_col_num++) {
/* Construct list of pointers to DCT blocks belonging to this MCU */ /* Construct list of pointers to DCT blocks belonging to this MCU */
blkn = 0; /* index of current DCT block within MCU */ blkn = 0; /* index of current DCT block within MCU */
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
start_col = MCU_col_num * compptr->MCU_width; start_col = MCU_col_num * compptr->MCU_width;
for (yindex = 0; yindex < compptr->MCU_height; yindex++) { for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
buffer_ptr = buffer[ci][yindex+yoffset] + start_col; buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
for (xindex = 0; xindex < compptr->MCU_width; xindex++) { for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
coef->MCU_buffer[blkn++] = buffer_ptr++; coef->MCU_buffer[blkn++] = buffer_ptr++;
} }
} }
} }
/* Try to fetch the MCU. */ /* Try to fetch the MCU. */
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
coef->MCU_ctr = MCU_col_num; coef->MCU_ctr = MCU_col_num;
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} }
} }
/* Completed an MCU row, but perhaps not an iMCU row */ /* Completed an MCU row, but perhaps not an iMCU row */
@@ -333,8 +333,8 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
/* Force some input to be done if we are getting ahead of the input. */ /* Force some input to be done if we are getting ahead of the input. */
while (cinfo->input_scan_number < cinfo->output_scan_number || while (cinfo->input_scan_number < cinfo->output_scan_number ||
(cinfo->input_scan_number == cinfo->output_scan_number && (cinfo->input_scan_number == cinfo->output_scan_number &&
cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} }
@@ -365,10 +365,10 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
buffer_ptr = buffer[block_row]; buffer_ptr = buffer[block_row];
output_col = 0; output_col = 0;
for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) { for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr, (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
output_ptr, output_col); output_ptr, output_col);
buffer_ptr++; buffer_ptr++;
output_col += compptr->_DCT_scaled_size; output_col += compptr->_DCT_scaled_size;
} }
output_ptr += compptr->_DCT_scaled_size; output_ptr += compptr->_DCT_scaled_size;
} }
@@ -425,8 +425,8 @@ smoothing_ok (j_decompress_ptr cinfo)
if (coef->coef_bits_latch == NULL) if (coef->coef_bits_latch == NULL)
coef->coef_bits_latch = (int *) coef->coef_bits_latch = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->num_components * cinfo->num_components *
(SAVED_COEFS * SIZEOF(int))); (SAVED_COEFS * SIZEOF(int)));
coef_bits_latch = coef->coef_bits_latch; coef_bits_latch = coef->coef_bits_latch;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
@@ -436,11 +436,11 @@ smoothing_ok (j_decompress_ptr cinfo)
return FALSE; return FALSE;
/* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */ /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
if (qtable->quantval[0] == 0 || if (qtable->quantval[0] == 0 ||
qtable->quantval[Q01_POS] == 0 || qtable->quantval[Q01_POS] == 0 ||
qtable->quantval[Q10_POS] == 0 || qtable->quantval[Q10_POS] == 0 ||
qtable->quantval[Q20_POS] == 0 || qtable->quantval[Q20_POS] == 0 ||
qtable->quantval[Q11_POS] == 0 || qtable->quantval[Q11_POS] == 0 ||
qtable->quantval[Q02_POS] == 0) qtable->quantval[Q02_POS] == 0)
return FALSE; return FALSE;
/* DC values must be at least partly known for all components. */ /* DC values must be at least partly known for all components. */
coef_bits = cinfo->coef_bits[ci]; coef_bits = cinfo->coef_bits[ci];
@@ -450,7 +450,7 @@ smoothing_ok (j_decompress_ptr cinfo)
for (coefi = 1; coefi <= 5; coefi++) { for (coefi = 1; coefi <= 5; coefi++) {
coef_bits_latch[coefi] = coef_bits[coefi]; coef_bits_latch[coefi] = coef_bits[coefi];
if (coef_bits[coefi] != 0) if (coef_bits[coefi] != 0)
smoothing_useful = TRUE; smoothing_useful = TRUE;
} }
coef_bits_latch += SAVED_COEFS; coef_bits_latch += SAVED_COEFS;
} }
@@ -489,7 +489,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
/* Force some input to be done if we are getting ahead of the input. */ /* Force some input to be done if we are getting ahead of the input. */
while (cinfo->input_scan_number <= cinfo->output_scan_number && while (cinfo->input_scan_number <= cinfo->output_scan_number &&
! cinfo->inputctl->eoi_reached) { ! cinfo->inputctl->eoi_reached) {
if (cinfo->input_scan_number == cinfo->output_scan_number) { if (cinfo->input_scan_number == cinfo->output_scan_number) {
/* If input is working on current scan, we ordinarily want it to /* If input is working on current scan, we ordinarily want it to
* have completed the current row. But if input scan is DC, * have completed the current row. But if input scan is DC,
@@ -498,7 +498,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
*/ */
JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0; JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta) if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
break; break;
} }
if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
@@ -526,15 +526,15 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if (cinfo->output_iMCU_row > 0) { if (cinfo->output_iMCU_row > 0) {
access_rows += compptr->v_samp_factor; /* prior iMCU row too */ access_rows += compptr->v_samp_factor; /* prior iMCU row too */
buffer = (*cinfo->mem->access_virt_barray) buffer = (*cinfo->mem->access_virt_barray)
((j_common_ptr) cinfo, coef->whole_image[ci], ((j_common_ptr) cinfo, coef->whole_image[ci],
(cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
(JDIMENSION) access_rows, FALSE); (JDIMENSION) access_rows, FALSE);
buffer += compptr->v_samp_factor; /* point to current iMCU row */ buffer += compptr->v_samp_factor; /* point to current iMCU row */
first_row = FALSE; first_row = FALSE;
} else { } else {
buffer = (*cinfo->mem->access_virt_barray) buffer = (*cinfo->mem->access_virt_barray)
((j_common_ptr) cinfo, coef->whole_image[ci], ((j_common_ptr) cinfo, coef->whole_image[ci],
(JDIMENSION) 0, (JDIMENSION) access_rows, FALSE); (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
first_row = TRUE; first_row = TRUE;
} }
/* Fetch component-dependent info */ /* Fetch component-dependent info */
@@ -552,13 +552,13 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
for (block_row = 0; block_row < block_rows; block_row++) { for (block_row = 0; block_row < block_rows; block_row++) {
buffer_ptr = buffer[block_row]; buffer_ptr = buffer[block_row];
if (first_row && block_row == 0) if (first_row && block_row == 0)
prev_block_row = buffer_ptr; prev_block_row = buffer_ptr;
else else
prev_block_row = buffer[block_row-1]; prev_block_row = buffer[block_row-1];
if (last_row && block_row == block_rows-1) if (last_row && block_row == block_rows-1)
next_block_row = buffer_ptr; next_block_row = buffer_ptr;
else else
next_block_row = buffer[block_row+1]; next_block_row = buffer[block_row+1];
/* We fetch the surrounding DC values using a sliding-register approach. /* We fetch the surrounding DC values using a sliding-register approach.
* Initialize all nine here so as to do the right thing on narrow pics. * Initialize all nine here so as to do the right thing on narrow pics.
*/ */
@@ -568,102 +568,102 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
output_col = 0; output_col = 0;
last_block_column = compptr->width_in_blocks - 1; last_block_column = compptr->width_in_blocks - 1;
for (block_num = 0; block_num <= last_block_column; block_num++) { for (block_num = 0; block_num <= last_block_column; block_num++) {
/* Fetch current DCT block into workspace so we can modify it. */ /* Fetch current DCT block into workspace so we can modify it. */
jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1); jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
/* Update DC values */ /* Update DC values */
if (block_num < last_block_column) { if (block_num < last_block_column) {
DC3 = (int) prev_block_row[1][0]; DC3 = (int) prev_block_row[1][0];
DC6 = (int) buffer_ptr[1][0]; DC6 = (int) buffer_ptr[1][0];
DC9 = (int) next_block_row[1][0]; DC9 = (int) next_block_row[1][0];
} }
/* Compute coefficient estimates per K.8. /* Compute coefficient estimates per K.8.
* An estimate is applied only if coefficient is still zero, * An estimate is applied only if coefficient is still zero,
* and is not known to be fully accurate. * and is not known to be fully accurate.
*/ */
/* AC01 */ /* AC01 */
if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) { if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
num = 36 * Q00 * (DC4 - DC6); num = 36 * Q00 * (DC4 - DC6);
if (num >= 0) { if (num >= 0) {
pred = (int) (((Q01<<7) + num) / (Q01<<8)); pred = (int) (((Q01<<7) + num) / (Q01<<8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1; pred = (1<<Al)-1;
} else { } else {
pred = (int) (((Q01<<7) - num) / (Q01<<8)); pred = (int) (((Q01<<7) - num) / (Q01<<8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1; pred = (1<<Al)-1;
pred = -pred; pred = -pred;
} }
workspace[1] = (JCOEF) pred; workspace[1] = (JCOEF) pred;
} }
/* AC10 */ /* AC10 */
if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) { if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
num = 36 * Q00 * (DC2 - DC8); num = 36 * Q00 * (DC2 - DC8);
if (num >= 0) { if (num >= 0) {
pred = (int) (((Q10<<7) + num) / (Q10<<8)); pred = (int) (((Q10<<7) + num) / (Q10<<8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1; pred = (1<<Al)-1;
} else { } else {
pred = (int) (((Q10<<7) - num) / (Q10<<8)); pred = (int) (((Q10<<7) - num) / (Q10<<8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1; pred = (1<<Al)-1;
pred = -pred; pred = -pred;
} }
workspace[8] = (JCOEF) pred; workspace[8] = (JCOEF) pred;
} }
/* AC20 */ /* AC20 */
if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) { if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
num = 9 * Q00 * (DC2 + DC8 - 2*DC5); num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
if (num >= 0) { if (num >= 0) {
pred = (int) (((Q20<<7) + num) / (Q20<<8)); pred = (int) (((Q20<<7) + num) / (Q20<<8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1; pred = (1<<Al)-1;
} else { } else {
pred = (int) (((Q20<<7) - num) / (Q20<<8)); pred = (int) (((Q20<<7) - num) / (Q20<<8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1; pred = (1<<Al)-1;
pred = -pred; pred = -pred;
} }
workspace[16] = (JCOEF) pred; workspace[16] = (JCOEF) pred;
} }
/* AC11 */ /* AC11 */
if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) { if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9); num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
if (num >= 0) { if (num >= 0) {
pred = (int) (((Q11<<7) + num) / (Q11<<8)); pred = (int) (((Q11<<7) + num) / (Q11<<8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1; pred = (1<<Al)-1;
} else { } else {
pred = (int) (((Q11<<7) - num) / (Q11<<8)); pred = (int) (((Q11<<7) - num) / (Q11<<8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1; pred = (1<<Al)-1;
pred = -pred; pred = -pred;
} }
workspace[9] = (JCOEF) pred; workspace[9] = (JCOEF) pred;
} }
/* AC02 */ /* AC02 */
if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) { if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
num = 9 * Q00 * (DC4 + DC6 - 2*DC5); num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
if (num >= 0) { if (num >= 0) {
pred = (int) (((Q02<<7) + num) / (Q02<<8)); pred = (int) (((Q02<<7) + num) / (Q02<<8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1; pred = (1<<Al)-1;
} else { } else {
pred = (int) (((Q02<<7) - num) / (Q02<<8)); pred = (int) (((Q02<<7) - num) / (Q02<<8));
if (Al > 0 && pred >= (1<<Al)) if (Al > 0 && pred >= (1<<Al))
pred = (1<<Al)-1; pred = (1<<Al)-1;
pred = -pred; pred = -pred;
} }
workspace[2] = (JCOEF) pred; workspace[2] = (JCOEF) pred;
} }
/* OK, do the IDCT */ /* OK, do the IDCT */
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace, (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
output_ptr, output_col); output_ptr, output_col);
/* Advance for next column */ /* Advance for next column */
DC1 = DC2; DC2 = DC3; DC1 = DC2; DC2 = DC3;
DC4 = DC5; DC5 = DC6; DC4 = DC5; DC5 = DC6;
DC7 = DC8; DC8 = DC9; DC7 = DC8; DC8 = DC9;
buffer_ptr++, prev_block_row++, next_block_row++; buffer_ptr++, prev_block_row++, next_block_row++;
output_col += compptr->_DCT_scaled_size; output_col += compptr->_DCT_scaled_size;
} }
output_ptr += compptr->_DCT_scaled_size; output_ptr += compptr->_DCT_scaled_size;
} }
@@ -688,7 +688,7 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
coef = (my_coef_ptr) coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_coef_controller)); SIZEOF(my_coef_controller));
cinfo->coef = (struct jpeg_d_coef_controller *) coef; cinfo->coef = (struct jpeg_d_coef_controller *) coef;
coef->pub.start_input_pass = start_input_pass; coef->pub.start_input_pass = start_input_pass;
coef->pub.start_output_pass = start_output_pass; coef->pub.start_output_pass = start_output_pass;
@@ -706,20 +706,20 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
jpeg_component_info *compptr; jpeg_component_info *compptr;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
access_rows = compptr->v_samp_factor; access_rows = compptr->v_samp_factor;
#ifdef BLOCK_SMOOTHING_SUPPORTED #ifdef BLOCK_SMOOTHING_SUPPORTED
/* If block smoothing could be used, need a bigger window */ /* If block smoothing could be used, need a bigger window */
if (cinfo->progressive_mode) if (cinfo->progressive_mode)
access_rows *= 3; access_rows *= 3;
#endif #endif
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE, ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
(JDIMENSION) jround_up((long) compptr->width_in_blocks, (JDIMENSION) jround_up((long) compptr->width_in_blocks,
(long) compptr->h_samp_factor), (long) compptr->h_samp_factor),
(JDIMENSION) jround_up((long) compptr->height_in_blocks, (JDIMENSION) jround_up((long) compptr->height_in_blocks,
(long) compptr->v_samp_factor), (long) compptr->v_samp_factor),
(JDIMENSION) access_rows); (JDIMENSION) access_rows);
} }
coef->pub.consume_data = consume_data; coef->pub.consume_data = consume_data;
coef->pub.decompress_data = decompress_data; coef->pub.decompress_data = decompress_data;
@@ -734,7 +734,7 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
buffer = (JBLOCKROW) buffer = (JBLOCKROW)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
coef->MCU_buffer[i] = buffer + i; coef->MCU_buffer[i] = buffer + i;
} }

View File

@@ -58,8 +58,8 @@ ycc_rgb_convert_internal (j_decompress_ptr cinfo,
/* Range-limiting is essential due to noise introduced by DCT losses. */ /* Range-limiting is essential due to noise introduced by DCT losses. */
outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
outptr[RGB_GREEN] = range_limit[y + outptr[RGB_GREEN] = range_limit[y +
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))]; SCALEBITS))];
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
/* Set unused byte to 0xFF so it can be interpreted as an opaque */ /* Set unused byte to 0xFF so it can be interpreted as an opaque */
/* alpha channel value */ /* alpha channel value */

106
jdcolor.c
View File

@@ -25,13 +25,13 @@ typedef struct {
struct jpeg_color_deconverter pub; /* public fields */ struct jpeg_color_deconverter pub; /* public fields */
/* Private state for YCC->RGB conversion */ /* Private state for YCC->RGB conversion */
int * Cr_r_tab; /* => table for Cr to R conversion */ int * Cr_r_tab; /* => table for Cr to R conversion */
int * Cb_b_tab; /* => table for Cb to B conversion */ int * Cb_b_tab; /* => table for Cb to B conversion */
INT32 * Cr_g_tab; /* => table for Cr to G conversion */ INT32 * Cr_g_tab; /* => table for Cr to G conversion */
INT32 * Cb_g_tab; /* => table for Cb to G conversion */ INT32 * Cb_g_tab; /* => table for Cb to G conversion */
/* Private state for RGB->Y conversion */ /* Private state for RGB->Y conversion */
INT32 * rgb_y_tab; /* => table for RGB to Y conversion */ INT32 * rgb_y_tab; /* => table for RGB to Y conversion */
} my_color_deconverter; } my_color_deconverter;
typedef my_color_deconverter * my_cconvert_ptr; typedef my_color_deconverter * my_cconvert_ptr;
@@ -45,11 +45,11 @@ typedef my_color_deconverter * my_cconvert_ptr;
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
* The conversion equations to be implemented are therefore * The conversion equations to be implemented are therefore
* *
* R = Y + 1.40200 * Cr * R = Y + 1.40200 * Cr
* G = Y - 0.34414 * Cb - 0.71414 * Cr * G = Y - 0.34414 * Cb - 0.71414 * Cr
* B = Y + 1.77200 * Cb * B = Y + 1.77200 * Cb
* *
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
* *
* where Cb and Cr represent the incoming values less CENTERJSAMPLE. * where Cb and Cr represent the incoming values less CENTERJSAMPLE.
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
@@ -71,9 +71,9 @@ typedef my_color_deconverter * my_cconvert_ptr;
* together before rounding. * together before rounding.
*/ */
#define SCALEBITS 16 /* speediest right-shift on some machines */ #define SCALEBITS 16 /* speediest right-shift on some machines */
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
/* We allocate one big table for RGB->Y conversion and divide it up into /* We allocate one big table for RGB->Y conversion and divide it up into
* three parts, instead of doing three alloc_small requests. This lets us * three parts, instead of doing three alloc_small requests. This lets us
@@ -82,10 +82,10 @@ typedef my_color_deconverter * my_cconvert_ptr;
* anyway). * anyway).
*/ */
#define R_Y_OFF 0 /* offset to R => Y section */ #define R_Y_OFF 0 /* offset to R => Y section */
#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
#define TABLE_SIZE (3*(MAXJSAMPLE+1)) #define TABLE_SIZE (3*(MAXJSAMPLE+1))
/* Include inline routines for colorspace extensions */ /* Include inline routines for colorspace extensions */
@@ -215,26 +215,26 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
cconvert->Cr_r_tab = (int *) cconvert->Cr_r_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(int)); (MAXJSAMPLE+1) * SIZEOF(int));
cconvert->Cb_b_tab = (int *) cconvert->Cb_b_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(int)); (MAXJSAMPLE+1) * SIZEOF(int));
cconvert->Cr_g_tab = (INT32 *) cconvert->Cr_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * SIZEOF(INT32));
cconvert->Cb_g_tab = (INT32 *) cconvert->Cb_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * SIZEOF(INT32));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 1.40200 * x */ /* Cr=>R value is nearest int to 1.40200 * x */
cconvert->Cr_r_tab[i] = (int) cconvert->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 1.77200 * x */ /* Cb=>B value is nearest int to 1.77200 * x */
cconvert->Cb_b_tab[i] = (int) cconvert->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -0.71414 * x */ /* Cr=>G value is scaled-up -0.71414 * x */
cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
/* Cb=>G value is scaled-up -0.34414 * x */ /* Cb=>G value is scaled-up -0.34414 * x */
@@ -250,8 +250,8 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
METHODDEF(void) METHODDEF(void)
ycc_rgb_convert (j_decompress_ptr cinfo, ycc_rgb_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@@ -307,7 +307,7 @@ build_rgb_y_table (j_decompress_ptr cinfo)
/* Allocate and fill in the conversion tables. */ /* Allocate and fill in the conversion tables. */
cconvert->rgb_y_tab = rgb_y_tab = (INT32 *) cconvert->rgb_y_tab = rgb_y_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(TABLE_SIZE * SIZEOF(INT32))); (TABLE_SIZE * SIZEOF(INT32)));
for (i = 0; i <= MAXJSAMPLE; i++) { for (i = 0; i <= MAXJSAMPLE; i++) {
rgb_y_tab[i+R_Y_OFF] = FIX(0.29900) * i; rgb_y_tab[i+R_Y_OFF] = FIX(0.29900) * i;
@@ -323,8 +323,8 @@ build_rgb_y_table (j_decompress_ptr cinfo)
METHODDEF(void) METHODDEF(void)
rgb_gray_convert (j_decompress_ptr cinfo, rgb_gray_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b; register int r, g, b;
@@ -346,8 +346,8 @@ rgb_gray_convert (j_decompress_ptr cinfo,
b = GETJSAMPLE(inptr2[col]); b = GETJSAMPLE(inptr2[col]);
/* Y */ /* Y */
outptr[col] = (JSAMPLE) outptr[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS); >> SCALEBITS);
} }
} }
} }
@@ -360,8 +360,8 @@ rgb_gray_convert (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
null_convert (j_decompress_ptr cinfo, null_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
register JDIMENSION count; register JDIMENSION count;
@@ -374,8 +374,8 @@ null_convert (j_decompress_ptr cinfo,
inptr = input_buf[ci][input_row]; inptr = input_buf[ci][input_row];
outptr = output_buf[0] + ci; outptr = output_buf[0] + ci;
for (count = num_cols; count > 0; count--) { for (count = num_cols; count > 0; count--) {
*outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */ *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
outptr += num_components; outptr += num_components;
} }
} }
input_row++; input_row++;
@@ -392,11 +392,11 @@ null_convert (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
grayscale_convert (j_decompress_ptr cinfo, grayscale_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
num_rows, cinfo->output_width); num_rows, cinfo->output_width);
} }
@@ -406,8 +406,8 @@ grayscale_convert (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
gray_rgb_convert (j_decompress_ptr cinfo, gray_rgb_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@@ -452,8 +452,8 @@ gray_rgb_convert (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
rgb_rgb_convert (j_decompress_ptr cinfo, rgb_rgb_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@@ -501,8 +501,8 @@ rgb_rgb_convert (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
ycck_cmyk_convert (j_decompress_ptr cinfo, ycck_cmyk_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int y, cb, cr; register int y, cb, cr;
@@ -530,13 +530,13 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
cb = GETJSAMPLE(inptr1[col]); cb = GETJSAMPLE(inptr1[col]);
cr = GETJSAMPLE(inptr2[col]); cr = GETJSAMPLE(inptr2[col]);
/* Range-limiting is essential due to noise introduced by DCT losses. */ /* Range-limiting is essential due to noise introduced by DCT losses. */
outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS)))]; SCALEBITS)))];
outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */ outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
/* K passes through unchanged */ /* K passes through unchanged */
outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */ outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
outptr += 4; outptr += 4;
} }
} }
@@ -566,7 +566,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
cconvert = (my_cconvert_ptr) cconvert = (my_cconvert_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_color_deconverter)); SIZEOF(my_color_deconverter));
cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
cconvert->pub.start_pass = start_pass_dcolor; cconvert->pub.start_pass = start_pass_dcolor;
@@ -589,7 +589,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
break; break;
default: /* JCS_UNKNOWN can be anything */ default: /* JCS_UNKNOWN can be anything */
if (cinfo->num_components < 1) if (cinfo->num_components < 1)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
break; break;
@@ -604,11 +604,11 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
cinfo->out_color_components = 1; cinfo->out_color_components = 1;
if (cinfo->jpeg_color_space == JCS_GRAYSCALE || if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
cinfo->jpeg_color_space == JCS_YCbCr) { cinfo->jpeg_color_space == JCS_YCbCr) {
cconvert->pub.color_convert = grayscale_convert; cconvert->pub.color_convert = grayscale_convert;
/* For color->grayscale conversion, only the Y (0) component is needed */ /* For color->grayscale conversion, only the Y (0) component is needed */
for (ci = 1; ci < cinfo->num_components; ci++) for (ci = 1; ci < cinfo->num_components; ci++)
cinfo->comp_info[ci].component_needed = FALSE; cinfo->comp_info[ci].component_needed = FALSE;
} else if (cinfo->jpeg_color_space == JCS_RGB) { } else if (cinfo->jpeg_color_space == JCS_RGB) {
cconvert->pub.color_convert = rgb_gray_convert; cconvert->pub.color_convert = rgb_gray_convert;
build_rgb_y_table(cinfo); build_rgb_y_table(cinfo);
@@ -665,7 +665,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
if (cinfo->out_color_space == cinfo->jpeg_color_space) { if (cinfo->out_color_space == cinfo->jpeg_color_space) {
cinfo->out_color_components = cinfo->num_components; cinfo->out_color_components = cinfo->num_components;
cconvert->pub.color_convert = null_convert; cconvert->pub.color_convert = null_convert;
} else /* unsupported non-null conversion */ } else /* unsupported non-null conversion */
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
} }

104
jdct.h
View File

@@ -8,7 +8,7 @@
* This include file contains common declarations for the forward and * This include file contains common declarations for the forward and
* inverse DCT modules. These declarations are private to the DCT managers * inverse DCT modules. These declarations are private to the DCT managers
* (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms. * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.
* The individual DCT algorithms are kept in separate files to ease * The individual DCT algorithms are kept in separate files to ease
* machine-dependent tuning (e.g., assembly coding). * machine-dependent tuning (e.g., assembly coding).
*/ */
@@ -29,7 +29,7 @@
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
#ifndef WITH_SIMD #ifndef WITH_SIMD
typedef int DCTELEM; /* 16 or 32 bits is fine */ typedef int DCTELEM; /* 16 or 32 bits is fine */
typedef unsigned int UDCTELEM; typedef unsigned int UDCTELEM;
typedef unsigned long long UDCTELEM2; typedef unsigned long long UDCTELEM2;
#else #else
@@ -38,7 +38,7 @@ typedef unsigned short UDCTELEM;
typedef unsigned int UDCTELEM2; typedef unsigned int UDCTELEM2;
#endif #endif
#else #else
typedef INT32 DCTELEM; /* must have 32 bits */ typedef INT32 DCTELEM; /* must have 32 bits */
typedef UINT32 UDCTELEM; typedef UINT32 UDCTELEM;
typedef unsigned long long UDCTELEM2; typedef unsigned long long UDCTELEM2;
#endif #endif
@@ -64,10 +64,10 @@ typedef unsigned long long UDCTELEM2;
typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */ typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */ typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
#define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */ #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
#else #else
typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */ typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
#define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */ #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
#endif #endif
typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
@@ -89,27 +89,27 @@ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
/* Short forms of external names for systems with brain-damaged linkers. */ /* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES #ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_fdct_islow jFDislow #define jpeg_fdct_islow jFDislow
#define jpeg_fdct_ifast jFDifast #define jpeg_fdct_ifast jFDifast
#define jpeg_fdct_float jFDfloat #define jpeg_fdct_float jFDfloat
#define jpeg_idct_islow jRDislow #define jpeg_idct_islow jRDislow
#define jpeg_idct_ifast jRDifast #define jpeg_idct_ifast jRDifast
#define jpeg_idct_float jRDfloat #define jpeg_idct_float jRDfloat
#define jpeg_idct_7x7 jRD7x7 #define jpeg_idct_7x7 jRD7x7
#define jpeg_idct_6x6 jRD6x6 #define jpeg_idct_6x6 jRD6x6
#define jpeg_idct_5x5 jRD5x5 #define jpeg_idct_5x5 jRD5x5
#define jpeg_idct_4x4 jRD4x4 #define jpeg_idct_4x4 jRD4x4
#define jpeg_idct_3x3 jRD3x3 #define jpeg_idct_3x3 jRD3x3
#define jpeg_idct_2x2 jRD2x2 #define jpeg_idct_2x2 jRD2x2
#define jpeg_idct_1x1 jRD1x1 #define jpeg_idct_1x1 jRD1x1
#define jpeg_idct_9x9 jRD9x9 #define jpeg_idct_9x9 jRD9x9
#define jpeg_idct_10x10 jRD10x10 #define jpeg_idct_10x10 jRD10x10
#define jpeg_idct_11x11 jRD11x11 #define jpeg_idct_11x11 jRD11x11
#define jpeg_idct_12x12 jRD12x12 #define jpeg_idct_12x12 jRD12x12
#define jpeg_idct_13x13 jRD13x13 #define jpeg_idct_13x13 jRD13x13
#define jpeg_idct_14x14 jRD14x14 #define jpeg_idct_14x14 jRD14x14
#define jpeg_idct_15x15 jRD15x15 #define jpeg_idct_15x15 jRD15x15
#define jpeg_idct_16x16 jRD16x16 #define jpeg_idct_16x16 jRD16x16
#endif /* NEED_SHORT_EXTERNAL_NAMES */ #endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Extern declarations for the forward and inverse DCT routines. */ /* Extern declarations for the forward and inverse DCT routines. */
@@ -120,58 +120,58 @@ EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
EXTERN(void) jpeg_idct_islow EXTERN(void) jpeg_idct_islow
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_ifast EXTERN(void) jpeg_idct_ifast
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_float EXTERN(void) jpeg_idct_float
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_7x7 EXTERN(void) jpeg_idct_7x7
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_6x6 EXTERN(void) jpeg_idct_6x6
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_5x5 EXTERN(void) jpeg_idct_5x5
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_4x4 EXTERN(void) jpeg_idct_4x4
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_3x3 EXTERN(void) jpeg_idct_3x3
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_2x2 EXTERN(void) jpeg_idct_2x2
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_1x1 EXTERN(void) jpeg_idct_1x1
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_9x9 EXTERN(void) jpeg_idct_9x9
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_10x10 EXTERN(void) jpeg_idct_10x10
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_11x11 EXTERN(void) jpeg_idct_11x11
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_12x12 EXTERN(void) jpeg_idct_12x12
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_13x13 EXTERN(void) jpeg_idct_13x13
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_14x14 EXTERN(void) jpeg_idct_14x14
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_15x15 EXTERN(void) jpeg_idct_15x15
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
EXTERN(void) jpeg_idct_16x16 EXTERN(void) jpeg_idct_16x16
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
/* /*
@@ -184,7 +184,7 @@ EXTERN(void) jpeg_idct_16x16
* and may differ from one module to the next. * and may differ from one module to the next.
*/ */
#define ONE ((INT32) 1) #define ONE ((INT32) 1)
#define CONST_SCALE (ONE << CONST_BITS) #define CONST_SCALE (ONE << CONST_BITS)
/* Convert a positive real constant to an integer scaled by CONST_SCALE. /* Convert a positive real constant to an integer scaled by CONST_SCALE.
@@ -192,7 +192,7 @@ EXTERN(void) jpeg_idct_16x16
* thus causing a lot of useless floating-point operations at run time. * thus causing a lot of useless floating-point operations at run time.
*/ */
#define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5)) #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
/* Descale and correctly round an INT32 value that's scaled by N bits. /* Descale and correctly round an INT32 value that's scaled by N bits.
* We assume RIGHT_SHIFT rounds towards minus infinity, so adding * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
@@ -210,23 +210,23 @@ EXTERN(void) jpeg_idct_16x16
* correct combination of casts. * correct combination of casts.
*/ */
#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const))) #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
#endif #endif
#ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */ #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const))) #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
#endif #endif
#ifndef MULTIPLY16C16 /* default definition */ #ifndef MULTIPLY16C16 /* default definition */
#define MULTIPLY16C16(var,const) ((var) * (const)) #define MULTIPLY16C16(var,const) ((var) * (const))
#endif #endif
/* Same except both inputs are variables. */ /* Same except both inputs are variables. */
#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
#define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2))) #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
#endif #endif
#ifndef MULTIPLY16V16 /* default definition */ #ifndef MULTIPLY16V16 /* default definition */
#define MULTIPLY16V16(var1,var2) ((var1) * (var2)) #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
#endif #endif

View File

@@ -22,7 +22,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#include "jsimddct.h" #include "jsimddct.h"
#include "jpegcomp.h" #include "jpegcomp.h"
@@ -47,7 +47,7 @@
/* Private subobject for this module */ /* Private subobject for this module */
typedef struct { typedef struct {
struct jpeg_inverse_dct pub; /* public fields */ struct jpeg_inverse_dct pub; /* public fields */
/* This array contains the IDCT method code that each multiplier table /* This array contains the IDCT method code that each multiplier table
* is currently set up for, or -1 if it's not yet set up. * is currently set up for, or -1 if it's not yet set up.
@@ -108,104 +108,104 @@ start_pass (j_decompress_ptr cinfo)
#ifdef IDCT_SCALING_SUPPORTED #ifdef IDCT_SCALING_SUPPORTED
case 1: case 1:
method_ptr = jpeg_idct_1x1; method_ptr = jpeg_idct_1x1;
method = JDCT_ISLOW; /* jidctred uses islow-style table */ method = JDCT_ISLOW; /* jidctred uses islow-style table */
break; break;
case 2: case 2:
if (jsimd_can_idct_2x2()) if (jsimd_can_idct_2x2())
method_ptr = jsimd_idct_2x2; method_ptr = jsimd_idct_2x2;
else else
method_ptr = jpeg_idct_2x2; method_ptr = jpeg_idct_2x2;
method = JDCT_ISLOW; /* jidctred uses islow-style table */ method = JDCT_ISLOW; /* jidctred uses islow-style table */
break; break;
case 3: case 3:
method_ptr = jpeg_idct_3x3; method_ptr = jpeg_idct_3x3;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 4: case 4:
if (jsimd_can_idct_4x4()) if (jsimd_can_idct_4x4())
method_ptr = jsimd_idct_4x4; method_ptr = jsimd_idct_4x4;
else else
method_ptr = jpeg_idct_4x4; method_ptr = jpeg_idct_4x4;
method = JDCT_ISLOW; /* jidctred uses islow-style table */ method = JDCT_ISLOW; /* jidctred uses islow-style table */
break; break;
case 5: case 5:
method_ptr = jpeg_idct_5x5; method_ptr = jpeg_idct_5x5;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 6: case 6:
method_ptr = jpeg_idct_6x6; method_ptr = jpeg_idct_6x6;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 7: case 7:
method_ptr = jpeg_idct_7x7; method_ptr = jpeg_idct_7x7;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
#endif #endif
case DCTSIZE: case DCTSIZE:
switch (cinfo->dct_method) { switch (cinfo->dct_method) {
#ifdef DCT_ISLOW_SUPPORTED #ifdef DCT_ISLOW_SUPPORTED
case JDCT_ISLOW: case JDCT_ISLOW:
if (jsimd_can_idct_islow()) if (jsimd_can_idct_islow())
method_ptr = jsimd_idct_islow; method_ptr = jsimd_idct_islow;
else else
method_ptr = jpeg_idct_islow; method_ptr = jpeg_idct_islow;
method = JDCT_ISLOW; method = JDCT_ISLOW;
break; break;
#endif #endif
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
case JDCT_IFAST: case JDCT_IFAST:
if (jsimd_can_idct_ifast()) if (jsimd_can_idct_ifast())
method_ptr = jsimd_idct_ifast; method_ptr = jsimd_idct_ifast;
else else
method_ptr = jpeg_idct_ifast; method_ptr = jpeg_idct_ifast;
method = JDCT_IFAST; method = JDCT_IFAST;
break; break;
#endif #endif
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
case JDCT_FLOAT: case JDCT_FLOAT:
if (jsimd_can_idct_float()) if (jsimd_can_idct_float())
method_ptr = jsimd_idct_float; method_ptr = jsimd_idct_float;
else else
method_ptr = jpeg_idct_float; method_ptr = jpeg_idct_float;
method = JDCT_FLOAT; method = JDCT_FLOAT;
break; break;
#endif #endif
default: default:
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);
break; break;
} }
break; break;
case 9: case 9:
method_ptr = jpeg_idct_9x9; method_ptr = jpeg_idct_9x9;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 10: case 10:
method_ptr = jpeg_idct_10x10; method_ptr = jpeg_idct_10x10;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 11: case 11:
method_ptr = jpeg_idct_11x11; method_ptr = jpeg_idct_11x11;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 12: case 12:
method_ptr = jpeg_idct_12x12; method_ptr = jpeg_idct_12x12;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 13: case 13:
method_ptr = jpeg_idct_13x13; method_ptr = jpeg_idct_13x13;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 14: case 14:
method_ptr = jpeg_idct_14x14; method_ptr = jpeg_idct_14x14;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 15: case 15:
method_ptr = jpeg_idct_15x15; method_ptr = jpeg_idct_15x15;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
case 16: case 16:
method_ptr = jpeg_idct_16x16; method_ptr = jpeg_idct_16x16;
method = JDCT_ISLOW; /* jidctint uses islow-style table */ method = JDCT_ISLOW; /* jidctint uses islow-style table */
break; break;
default: default:
ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size); ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size);
@@ -222,81 +222,81 @@ start_pass (j_decompress_ptr cinfo)
if (! compptr->component_needed || idct->cur_method[ci] == method) if (! compptr->component_needed || idct->cur_method[ci] == method)
continue; continue;
qtbl = compptr->quant_table; qtbl = compptr->quant_table;
if (qtbl == NULL) /* happens if no data yet for component */ if (qtbl == NULL) /* happens if no data yet for component */
continue; continue;
idct->cur_method[ci] = method; idct->cur_method[ci] = method;
switch (method) { switch (method) {
#ifdef PROVIDE_ISLOW_TABLES #ifdef PROVIDE_ISLOW_TABLES
case JDCT_ISLOW: case JDCT_ISLOW:
{ {
/* For LL&M IDCT method, multipliers are equal to raw quantization /* For LL&M IDCT method, multipliers are equal to raw quantization
* coefficients, but are stored as ints to ensure access efficiency. * coefficients, but are stored as ints to ensure access efficiency.
*/ */
ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table; ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i]; ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
} }
} }
break; break;
#endif #endif
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
case JDCT_IFAST: case JDCT_IFAST:
{ {
/* For AA&N IDCT method, multipliers are equal to quantization /* For AA&N IDCT method, multipliers are equal to quantization
* coefficients scaled by scalefactor[row]*scalefactor[col], where * coefficients scaled by scalefactor[row]*scalefactor[col], where
* scalefactor[0] = 1 * scalefactor[0] = 1
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
* For integer operation, the multiplier table is to be scaled by * For integer operation, the multiplier table is to be scaled by
* IFAST_SCALE_BITS. * IFAST_SCALE_BITS.
*/ */
IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table; IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
#define CONST_BITS 14 #define CONST_BITS 14
static const INT16 aanscales[DCTSIZE2] = { static const INT16 aanscales[DCTSIZE2] = {
/* precomputed values scaled up by 14 bits */ /* precomputed values scaled up by 14 bits */
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
}; };
SHIFT_TEMPS SHIFT_TEMPS
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
ifmtbl[i] = (IFAST_MULT_TYPE) ifmtbl[i] = (IFAST_MULT_TYPE)
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
(INT32) aanscales[i]), (INT32) aanscales[i]),
CONST_BITS-IFAST_SCALE_BITS); CONST_BITS-IFAST_SCALE_BITS);
} }
} }
break; break;
#endif #endif
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
case JDCT_FLOAT: case JDCT_FLOAT:
{ {
/* For float AA&N IDCT method, multipliers are equal to quantization /* For float AA&N IDCT method, multipliers are equal to quantization
* coefficients scaled by scalefactor[row]*scalefactor[col], where * coefficients scaled by scalefactor[row]*scalefactor[col], where
* scalefactor[0] = 1 * scalefactor[0] = 1
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
*/ */
FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table; FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
int row, col; int row, col;
static const double aanscalefactor[DCTSIZE] = { static const double aanscalefactor[DCTSIZE] = {
1.0, 1.387039845, 1.306562965, 1.175875602, 1.0, 1.387039845, 1.306562965, 1.175875602,
1.0, 0.785694958, 0.541196100, 0.275899379 1.0, 0.785694958, 0.541196100, 0.275899379
}; };
i = 0; i = 0;
for (row = 0; row < DCTSIZE; row++) { for (row = 0; row < DCTSIZE; row++) {
for (col = 0; col < DCTSIZE; col++) { for (col = 0; col < DCTSIZE; col++) {
fmtbl[i] = (FLOAT_MULT_TYPE) fmtbl[i] = (FLOAT_MULT_TYPE)
((double) qtbl->quantval[i] * ((double) qtbl->quantval[i] *
aanscalefactor[row] * aanscalefactor[col]); aanscalefactor[row] * aanscalefactor[col]);
i++; i++;
} }
} }
} }
break; break;
#endif #endif
@@ -321,7 +321,7 @@ jinit_inverse_dct (j_decompress_ptr cinfo)
idct = (my_idct_ptr) idct = (my_idct_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_idct_controller)); SIZEOF(my_idct_controller));
cinfo->idct = (struct jpeg_inverse_dct *) idct; cinfo->idct = (struct jpeg_inverse_dct *) idct;
idct->pub.start_pass = start_pass; idct->pub.start_pass = start_pass;
@@ -330,7 +330,7 @@ jinit_inverse_dct (j_decompress_ptr cinfo)
/* Allocate and pre-zero a multiplier table for each component */ /* Allocate and pre-zero a multiplier table for each component */
compptr->dct_table = compptr->dct_table =
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(multiplier_table)); SIZEOF(multiplier_table));
MEMZERO(compptr->dct_table, SIZEOF(multiplier_table)); MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
/* Mark multiplier table not yet set up for any method */ /* Mark multiplier table not yet set up for any method */
idct->cur_method[ci] = -1; idct->cur_method[ci] = -1;

138
jdhuff.c
View File

@@ -19,7 +19,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdhuff.h" /* Declarations shared with jdphuff.c */ #include "jdhuff.h" /* Declarations shared with jdphuff.c */
#include "jpegcomp.h" #include "jpegcomp.h"
@@ -44,10 +44,10 @@ typedef struct {
#else #else
#if MAX_COMPS_IN_SCAN == 4 #if MAX_COMPS_IN_SCAN == 4
#define ASSIGN_STATE(dest,src) \ #define ASSIGN_STATE(dest,src) \
((dest).last_dc_val[0] = (src).last_dc_val[0], \ ((dest).last_dc_val[0] = (src).last_dc_val[0], \
(dest).last_dc_val[1] = (src).last_dc_val[1], \ (dest).last_dc_val[1] = (src).last_dc_val[1], \
(dest).last_dc_val[2] = (src).last_dc_val[2], \ (dest).last_dc_val[2] = (src).last_dc_val[2], \
(dest).last_dc_val[3] = (src).last_dc_val[3]) (dest).last_dc_val[3] = (src).last_dc_val[3])
#endif #endif
#endif #endif
@@ -58,11 +58,11 @@ typedef struct {
/* These fields are loaded into local variables at start of each MCU. /* These fields are loaded into local variables at start of each MCU.
* In case of suspension, we exit WITHOUT updating them. * In case of suspension, we exit WITHOUT updating them.
*/ */
bitread_perm_state bitstate; /* Bit buffer at start of MCU */ bitread_perm_state bitstate; /* Bit buffer at start of MCU */
savable_state saved; /* Other state at start of MCU */ savable_state saved; /* Other state at start of MCU */
/* These fields are NOT loaded into local working state. */ /* These fields are NOT loaded into local working state. */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
/* Pointers to derived tables (these workspaces have image lifespan) */ /* Pointers to derived tables (these workspaces have image lifespan) */
d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]; d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
@@ -107,9 +107,9 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
/* Compute derived values for Huffman tables */ /* Compute derived values for Huffman tables */
/* We may do this more than once for a table, but it's not expensive */ /* We may do this more than once for a table, but it's not expensive */
jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl, jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
& entropy->dc_derived_tbls[dctbl]); & entropy->dc_derived_tbls[dctbl]);
jpeg_make_d_derived_tbl(cinfo, FALSE, actbl, jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
& entropy->ac_derived_tbls[actbl]); & entropy->ac_derived_tbls[actbl]);
/* Initialize DC predictions to 0 */ /* Initialize DC predictions to 0 */
entropy->saved.last_dc_val[ci] = 0; entropy->saved.last_dc_val[ci] = 0;
} }
@@ -150,7 +150,7 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
GLOBAL(void) GLOBAL(void)
jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
d_derived_tbl ** pdtbl) d_derived_tbl ** pdtbl)
{ {
JHUFF_TBL *htbl; JHUFF_TBL *htbl;
d_derived_tbl *dtbl; d_derived_tbl *dtbl;
@@ -176,26 +176,26 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
if (*pdtbl == NULL) if (*pdtbl == NULL)
*pdtbl = (d_derived_tbl *) *pdtbl = (d_derived_tbl *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(d_derived_tbl)); SIZEOF(d_derived_tbl));
dtbl = *pdtbl; dtbl = *pdtbl;
dtbl->pub = htbl; /* fill in back link */ dtbl->pub = htbl; /* fill in back link */
/* Figure C.1: make table of Huffman code length for each symbol */ /* Figure C.1: make table of Huffman code length for each symbol */
p = 0; p = 0;
for (l = 1; l <= 16; l++) { for (l = 1; l <= 16; l++) {
i = (int) htbl->bits[l]; i = (int) htbl->bits[l];
if (i < 0 || p + i > 256) /* protect against table overrun */ if (i < 0 || p + i > 256) /* protect against table overrun */
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
while (i--) while (i--)
huffsize[p++] = (char) l; huffsize[p++] = (char) l;
} }
huffsize[p] = 0; huffsize[p] = 0;
numsymbols = p; numsymbols = p;
/* Figure C.2: generate the codes themselves */ /* Figure C.2: generate the codes themselves */
/* We also validate that the counts represent a legal Huffman code tree. */ /* We also validate that the counts represent a legal Huffman code tree. */
code = 0; code = 0;
si = huffsize[0]; si = huffsize[0];
p = 0; p = 0;
@@ -225,7 +225,7 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
p += htbl->bits[l]; p += htbl->bits[l];
dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */ dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
} else { } else {
dtbl->maxcode[l] = -1; /* -1 if no codes of this length */ dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
} }
} }
dtbl->valoffset[17] = 0; dtbl->valoffset[17] = 0;
@@ -248,8 +248,8 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
/* Generate left-justified code followed by all possible bit sequences */ /* Generate left-justified code followed by all possible bit sequences */
lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l); lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) { for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
dtbl->lookup[lookbits] = (l << HUFF_LOOKAHEAD) | htbl->huffval[p]; dtbl->lookup[lookbits] = (l << HUFF_LOOKAHEAD) | htbl->huffval[p];
lookbits++; lookbits++;
} }
} }
} }
@@ -264,7 +264,7 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
for (i = 0; i < numsymbols; i++) { for (i = 0; i < numsymbols; i++) {
int sym = htbl->huffval[i]; int sym = htbl->huffval[i];
if (sym < 0 || sym > 15) if (sym < 0 || sym > 15)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
} }
} }
} }
@@ -286,7 +286,7 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
*/ */
#ifdef SLOW_SHIFT_32 #ifdef SLOW_SHIFT_32
#define MIN_GET_BITS 15 /* minimum allowable value */ #define MIN_GET_BITS 15 /* minimum allowable value */
#else #else
#define MIN_GET_BITS (BIT_BUF_SIZE-7) #define MIN_GET_BITS (BIT_BUF_SIZE-7)
#endif #endif
@@ -294,8 +294,8 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
GLOBAL(boolean) GLOBAL(boolean)
jpeg_fill_bit_buffer (bitread_working_state * state, jpeg_fill_bit_buffer (bitread_working_state * state,
register bit_buf_type get_buffer, register int bits_left, register bit_buf_type get_buffer, register int bits_left,
int nbits) int nbits)
/* Load up the bit buffer to a depth of at least nbits */ /* Load up the bit buffer to a depth of at least nbits */
{ {
/* Copy heavily used state fields into locals (hopefully registers) */ /* Copy heavily used state fields into locals (hopefully registers) */
@@ -307,54 +307,54 @@ jpeg_fill_bit_buffer (bitread_working_state * state,
/* (It is assumed that no request will be for more than that many bits.) */ /* (It is assumed that no request will be for more than that many bits.) */
/* We fail to do so only if we hit a marker or are forced to suspend. */ /* We fail to do so only if we hit a marker or are forced to suspend. */
if (cinfo->unread_marker == 0) { /* cannot advance past a marker */ if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
while (bits_left < MIN_GET_BITS) { while (bits_left < MIN_GET_BITS) {
register int c; register int c;
/* Attempt to read a byte */ /* Attempt to read a byte */
if (bytes_in_buffer == 0) { if (bytes_in_buffer == 0) {
if (! (*cinfo->src->fill_input_buffer) (cinfo)) if (! (*cinfo->src->fill_input_buffer) (cinfo))
return FALSE; return FALSE;
next_input_byte = cinfo->src->next_input_byte; next_input_byte = cinfo->src->next_input_byte;
bytes_in_buffer = cinfo->src->bytes_in_buffer; bytes_in_buffer = cinfo->src->bytes_in_buffer;
} }
bytes_in_buffer--; bytes_in_buffer--;
c = GETJOCTET(*next_input_byte++); c = GETJOCTET(*next_input_byte++);
/* If it's 0xFF, check and discard stuffed zero byte */ /* If it's 0xFF, check and discard stuffed zero byte */
if (c == 0xFF) { if (c == 0xFF) {
/* Loop here to discard any padding FF's on terminating marker, /* Loop here to discard any padding FF's on terminating marker,
* so that we can save a valid unread_marker value. NOTE: we will * so that we can save a valid unread_marker value. NOTE: we will
* accept multiple FF's followed by a 0 as meaning a single FF data * accept multiple FF's followed by a 0 as meaning a single FF data
* byte. This data pattern is not valid according to the standard. * byte. This data pattern is not valid according to the standard.
*/ */
do { do {
if (bytes_in_buffer == 0) { if (bytes_in_buffer == 0) {
if (! (*cinfo->src->fill_input_buffer) (cinfo)) if (! (*cinfo->src->fill_input_buffer) (cinfo))
return FALSE; return FALSE;
next_input_byte = cinfo->src->next_input_byte; next_input_byte = cinfo->src->next_input_byte;
bytes_in_buffer = cinfo->src->bytes_in_buffer; bytes_in_buffer = cinfo->src->bytes_in_buffer;
} }
bytes_in_buffer--; bytes_in_buffer--;
c = GETJOCTET(*next_input_byte++); c = GETJOCTET(*next_input_byte++);
} while (c == 0xFF); } while (c == 0xFF);
if (c == 0) { if (c == 0) {
/* Found FF/00, which represents an FF data byte */ /* Found FF/00, which represents an FF data byte */
c = 0xFF; c = 0xFF;
} else { } else {
/* Oops, it's actually a marker indicating end of compressed data. /* Oops, it's actually a marker indicating end of compressed data.
* Save the marker code for later use. * Save the marker code for later use.
* Fine point: it might appear that we should save the marker into * Fine point: it might appear that we should save the marker into
* bitread working state, not straight into permanent state. But * bitread working state, not straight into permanent state. But
* once we have hit a marker, we cannot need to suspend within the * once we have hit a marker, we cannot need to suspend within the
* current MCU, because we will read no more bytes from the data * current MCU, because we will read no more bytes from the data
* source. So it is OK to update permanent state right away. * source. So it is OK to update permanent state right away.
*/ */
cinfo->unread_marker = c; cinfo->unread_marker = c;
/* See if we need to insert some fake zero bits. */ /* See if we need to insert some fake zero bits. */
goto no_more_bytes; goto no_more_bytes;
} }
} }
/* OK, load c into get_buffer */ /* OK, load c into get_buffer */
@@ -374,8 +374,8 @@ jpeg_fill_bit_buffer (bitread_working_state * state,
* appears per data segment. * appears per data segment.
*/ */
if (! cinfo->entropy->insufficient_data) { if (! cinfo->entropy->insufficient_data) {
WARNMS(cinfo, JWRN_HIT_MARKER); WARNMS(cinfo, JWRN_HIT_MARKER);
cinfo->entropy->insufficient_data = TRUE; cinfo->entropy->insufficient_data = TRUE;
} }
/* Fill the buffer with zero bits */ /* Fill the buffer with zero bits */
get_buffer <<= MIN_GET_BITS - bits_left; get_buffer <<= MIN_GET_BITS - bits_left;
@@ -444,8 +444,8 @@ jpeg_fill_bit_buffer (bitread_working_state * state,
GLOBAL(int) GLOBAL(int)
jpeg_huff_decode (bitread_working_state * state, jpeg_huff_decode (bitread_working_state * state,
register bit_buf_type get_buffer, register int bits_left, register bit_buf_type get_buffer, register int bits_left,
d_derived_tbl * htbl, int min_bits) d_derived_tbl * htbl, int min_bits)
{ {
register int l = min_bits; register int l = min_bits;
register INT32 code; register INT32 code;
@@ -474,7 +474,7 @@ jpeg_huff_decode (bitread_working_state * state,
if (l > 16) { if (l > 16) {
WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE); WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
return 0; /* fake a zero as the safest result */ return 0; /* fake a zero as the safest result */
} }
return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ]; return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
@@ -594,7 +594,7 @@ decode_mcu_slow (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
r = s >> 4; r = s >> 4;
s &= 15; s &= 15;
if (s) { if (s) {
k += r; k += r;
CHECK_BIT_BUFFER(br_state, s, return FALSE); CHECK_BIT_BUFFER(br_state, s, return FALSE);
@@ -683,7 +683,7 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
HUFF_DECODE_FAST(s, l, actbl); HUFF_DECODE_FAST(s, l, actbl);
r = s >> 4; r = s >> 4;
s &= 15; s &= 15;
if (s) { if (s) {
k += r; k += r;
FILL_BIT_BUFFER_FAST FILL_BIT_BUFFER_FAST
@@ -755,7 +755,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! process_restart(cinfo)) if (! process_restart(cinfo))
return FALSE; return FALSE;
usefast = 0; usefast = 0;
} }
@@ -797,7 +797,7 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
entropy = (huff_entropy_ptr) entropy = (huff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(huff_entropy_decoder)); SIZEOF(huff_entropy_decoder));
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
entropy->pub.start_pass = start_pass_huff_decoder; entropy->pub.start_pass = start_pass_huff_decoder;
entropy->pub.decode_mcu = decode_mcu; entropy->pub.decode_mcu = decode_mcu;

100
jdhuff.h
View File

@@ -15,21 +15,21 @@
/* Short forms of external names for systems with brain-damaged linkers. */ /* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES #ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_make_d_derived_tbl jMkDDerived #define jpeg_make_d_derived_tbl jMkDDerived
#define jpeg_fill_bit_buffer jFilBitBuf #define jpeg_fill_bit_buffer jFilBitBuf
#define jpeg_huff_decode jHufDecode #define jpeg_huff_decode jHufDecode
#endif /* NEED_SHORT_EXTERNAL_NAMES */ #endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Derived data constructed for each Huffman table */ /* Derived data constructed for each Huffman table */
#define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */ #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
typedef struct { typedef struct {
/* Basic tables: (element [0] of each array is unused) */ /* Basic tables: (element [0] of each array is unused) */
INT32 maxcode[18]; /* largest code of length k (-1 if none) */ INT32 maxcode[18]; /* largest code of length k (-1 if none) */
/* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */ /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */
INT32 valoffset[18]; /* huffval[] offset for codes of length k */ INT32 valoffset[18]; /* huffval[] offset for codes of length k */
/* valoffset[k] = huffval[] index of 1st symbol of code length k, less /* valoffset[k] = huffval[] index of 1st symbol of code length k, less
* the smallest code of length k; so given a code of length k, the * the smallest code of length k; so given a code of length k, the
* corresponding symbol is huffval[code + valoffset[k]] * corresponding symbol is huffval[code + valoffset[k]]
@@ -53,8 +53,8 @@ typedef struct {
/* Expand a Huffman table definition into the derived format */ /* Expand a Huffman table definition into the derived format */
EXTERN(void) jpeg_make_d_derived_tbl EXTERN(void) jpeg_make_d_derived_tbl
JPP((j_decompress_ptr cinfo, boolean isDC, int tblno, JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
d_derived_tbl ** pdtbl)); d_derived_tbl ** pdtbl));
/* /*
@@ -77,13 +77,13 @@ EXTERN(void) jpeg_make_d_derived_tbl
#if __WORDSIZE == 64 || defined(_WIN64) #if __WORDSIZE == 64 || defined(_WIN64)
typedef size_t bit_buf_type; /* type of bit-extraction buffer */ typedef size_t bit_buf_type; /* type of bit-extraction buffer */
#define BIT_BUF_SIZE 64 /* size of buffer in bits */ #define BIT_BUF_SIZE 64 /* size of buffer in bits */
#else #else
typedef INT32 bit_buf_type; /* type of bit-extraction buffer */ typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
#define BIT_BUF_SIZE 32 /* size of buffer in bits */ #define BIT_BUF_SIZE 32 /* size of buffer in bits */
#endif #endif
@@ -94,43 +94,43 @@ typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
* because not all machines measure sizeof in 8-bit bytes. * because not all machines measure sizeof in 8-bit bytes.
*/ */
typedef struct { /* Bitreading state saved across MCUs */ typedef struct { /* Bitreading state saved across MCUs */
bit_buf_type get_buffer; /* current bit-extraction buffer */ bit_buf_type get_buffer; /* current bit-extraction buffer */
int bits_left; /* # of unused bits in it */ int bits_left; /* # of unused bits in it */
} bitread_perm_state; } bitread_perm_state;
typedef struct { /* Bitreading working state within an MCU */ typedef struct { /* Bitreading working state within an MCU */
/* Current data source location */ /* Current data source location */
/* We need a copy, rather than munging the original, in case of suspension */ /* We need a copy, rather than munging the original, in case of suspension */
const JOCTET * next_input_byte; /* => next byte to read from source */ const JOCTET * next_input_byte; /* => next byte to read from source */
size_t bytes_in_buffer; /* # of bytes remaining in source buffer */ size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
/* Bit input buffer --- note these values are kept in register variables, /* Bit input buffer --- note these values are kept in register variables,
* not in this struct, inside the inner loops. * not in this struct, inside the inner loops.
*/ */
bit_buf_type get_buffer; /* current bit-extraction buffer */ bit_buf_type get_buffer; /* current bit-extraction buffer */
int bits_left; /* # of unused bits in it */ int bits_left; /* # of unused bits in it */
/* Pointer needed by jpeg_fill_bit_buffer. */ /* Pointer needed by jpeg_fill_bit_buffer. */
j_decompress_ptr cinfo; /* back link to decompress master record */ j_decompress_ptr cinfo; /* back link to decompress master record */
} bitread_working_state; } bitread_working_state;
/* Macros to declare and load/save bitread local variables. */ /* Macros to declare and load/save bitread local variables. */
#define BITREAD_STATE_VARS \ #define BITREAD_STATE_VARS \
register bit_buf_type get_buffer; \ register bit_buf_type get_buffer; \
register int bits_left; \ register int bits_left; \
bitread_working_state br_state bitread_working_state br_state
#define BITREAD_LOAD_STATE(cinfop,permstate) \ #define BITREAD_LOAD_STATE(cinfop,permstate) \
br_state.cinfo = cinfop; \ br_state.cinfo = cinfop; \
br_state.next_input_byte = cinfop->src->next_input_byte; \ br_state.next_input_byte = cinfop->src->next_input_byte; \
br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \ br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
get_buffer = permstate.get_buffer; \ get_buffer = permstate.get_buffer; \
bits_left = permstate.bits_left; bits_left = permstate.bits_left;
#define BITREAD_SAVE_STATE(cinfop,permstate) \ #define BITREAD_SAVE_STATE(cinfop,permstate) \
cinfop->src->next_input_byte = br_state.next_input_byte; \ cinfop->src->next_input_byte = br_state.next_input_byte; \
cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \ cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
permstate.get_buffer = get_buffer; \ permstate.get_buffer = get_buffer; \
permstate.bits_left = bits_left permstate.bits_left = bits_left
/* /*
* These macros provide the in-line portion of bit fetching. * These macros provide the in-line portion of bit fetching.
@@ -138,37 +138,37 @@ typedef struct { /* Bitreading working state within an MCU */
* before using GET_BITS, PEEK_BITS, or DROP_BITS. * before using GET_BITS, PEEK_BITS, or DROP_BITS.
* The variables get_buffer and bits_left are assumed to be locals, * The variables get_buffer and bits_left are assumed to be locals,
* but the state struct might not be (jpeg_huff_decode needs this). * but the state struct might not be (jpeg_huff_decode needs this).
* CHECK_BIT_BUFFER(state,n,action); * CHECK_BIT_BUFFER(state,n,action);
* Ensure there are N bits in get_buffer; if suspend, take action. * Ensure there are N bits in get_buffer; if suspend, take action.
* val = GET_BITS(n); * val = GET_BITS(n);
* Fetch next N bits. * Fetch next N bits.
* val = PEEK_BITS(n); * val = PEEK_BITS(n);
* Fetch next N bits without removing them from the buffer. * Fetch next N bits without removing them from the buffer.
* DROP_BITS(n); * DROP_BITS(n);
* Discard next N bits. * Discard next N bits.
* The value N should be a simple variable, not an expression, because it * The value N should be a simple variable, not an expression, because it
* is evaluated multiple times. * is evaluated multiple times.
*/ */
#define CHECK_BIT_BUFFER(state,nbits,action) \ #define CHECK_BIT_BUFFER(state,nbits,action) \
{ if (bits_left < (nbits)) { \ { if (bits_left < (nbits)) { \
if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \ if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
{ action; } \ { action; } \
get_buffer = (state).get_buffer; bits_left = (state).bits_left; } } get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
#define GET_BITS(nbits) \ #define GET_BITS(nbits) \
(((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1)) (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
#define PEEK_BITS(nbits) \ #define PEEK_BITS(nbits) \
(((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1)) (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
#define DROP_BITS(nbits) \ #define DROP_BITS(nbits) \
(bits_left -= (nbits)) (bits_left -= (nbits))
/* Load up the bit buffer to a depth of at least nbits */ /* Load up the bit buffer to a depth of at least nbits */
EXTERN(boolean) jpeg_fill_bit_buffer EXTERN(boolean) jpeg_fill_bit_buffer
JPP((bitread_working_state * state, register bit_buf_type get_buffer, JPP((bitread_working_state * state, register bit_buf_type get_buffer,
register int bits_left, int nbits)); register int bits_left, int nbits));
/* /*
@@ -204,7 +204,7 @@ EXTERN(boolean) jpeg_fill_bit_buffer
} else { \ } else { \
slowlabel: \ slowlabel: \
if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \ if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
{ failaction; } \ { failaction; } \
get_buffer = state.get_buffer; bits_left = state.bits_left; \ get_buffer = state.get_buffer; bits_left = state.bits_left; \
} \ } \
} }
@@ -231,5 +231,5 @@ slowlabel: \
/* Out-of-line case for Huffman code fetching */ /* Out-of-line case for Huffman code fetching */
EXTERN(int) jpeg_huff_decode EXTERN(int) jpeg_huff_decode
JPP((bitread_working_state * state, register bit_buf_type get_buffer, JPP((bitread_working_state * state, register bit_buf_type get_buffer,
register int bits_left, d_derived_tbl * htbl, int min_bits)); register int bits_left, d_derived_tbl * htbl, int min_bits));

View File

@@ -24,7 +24,7 @@
typedef struct { typedef struct {
struct jpeg_input_controller pub; /* public fields */ struct jpeg_input_controller pub; /* public fields */
boolean inheaders; /* TRUE until first SOS is reached */ boolean inheaders; /* TRUE until first SOS is reached */
} my_input_controller; } my_input_controller;
typedef my_input_controller * my_inputctl_ptr; typedef my_input_controller * my_inputctl_ptr;
@@ -57,7 +57,7 @@ initial_setup (j_decompress_ptr cinfo)
/* Check that number of components won't exceed internal array sizes */ /* Check that number of components won't exceed internal array sizes */
if (cinfo->num_components > MAX_COMPONENTS) if (cinfo->num_components > MAX_COMPONENTS)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
MAX_COMPONENTS); MAX_COMPONENTS);
/* Compute maximum sampling factors; check factor validity */ /* Compute maximum sampling factors; check factor validity */
cinfo->max_h_samp_factor = 1; cinfo->max_h_samp_factor = 1;
@@ -65,12 +65,12 @@ initial_setup (j_decompress_ptr cinfo)
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
ERREXIT(cinfo, JERR_BAD_SAMPLING); ERREXIT(cinfo, JERR_BAD_SAMPLING);
cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
compptr->h_samp_factor); compptr->h_samp_factor);
cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
compptr->v_samp_factor); compptr->v_samp_factor);
} }
#if JPEG_LIB_VERSION >=80 #if JPEG_LIB_VERSION >=80
@@ -100,10 +100,10 @@ initial_setup (j_decompress_ptr cinfo)
/* Size in DCT blocks */ /* Size in DCT blocks */
compptr->width_in_blocks = (JDIMENSION) compptr->width_in_blocks = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
(long) (cinfo->max_h_samp_factor * DCTSIZE)); (long) (cinfo->max_h_samp_factor * DCTSIZE));
compptr->height_in_blocks = (JDIMENSION) compptr->height_in_blocks = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
(long) (cinfo->max_v_samp_factor * DCTSIZE)); (long) (cinfo->max_v_samp_factor * DCTSIZE));
/* downsampled_width and downsampled_height will also be overridden by /* downsampled_width and downsampled_height will also be overridden by
* jdmaster.c if we are doing full decompression. The transcoder library * jdmaster.c if we are doing full decompression. The transcoder library
* doesn't use these values, but the calling application might. * doesn't use these values, but the calling application might.
@@ -111,10 +111,10 @@ initial_setup (j_decompress_ptr cinfo)
/* Size in samples */ /* Size in samples */
compptr->downsampled_width = (JDIMENSION) compptr->downsampled_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
(long) cinfo->max_h_samp_factor); (long) cinfo->max_h_samp_factor);
compptr->downsampled_height = (JDIMENSION) compptr->downsampled_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
(long) cinfo->max_v_samp_factor); (long) cinfo->max_v_samp_factor);
/* Mark component needed, until color conversion says otherwise */ /* Mark component needed, until color conversion says otherwise */
compptr->component_needed = TRUE; compptr->component_needed = TRUE;
/* Mark no quantization table yet saved for component */ /* Mark no quantization table yet saved for component */
@@ -124,7 +124,7 @@ initial_setup (j_decompress_ptr cinfo)
/* Compute number of fully interleaved MCU rows. */ /* Compute number of fully interleaved MCU rows. */
cinfo->total_iMCU_rows = (JDIMENSION) cinfo->total_iMCU_rows = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height, jdiv_round_up((long) cinfo->image_height,
(long) (cinfo->max_v_samp_factor*DCTSIZE)); (long) (cinfo->max_v_samp_factor*DCTSIZE));
/* Decide whether file contains multiple scans */ /* Decide whether file contains multiple scans */
if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode) if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
@@ -141,16 +141,16 @@ per_scan_setup (j_decompress_ptr cinfo)
{ {
int ci, mcublks, tmp; int ci, mcublks, tmp;
jpeg_component_info *compptr; jpeg_component_info *compptr;
if (cinfo->comps_in_scan == 1) { if (cinfo->comps_in_scan == 1) {
/* Noninterleaved (single-component) scan */ /* Noninterleaved (single-component) scan */
compptr = cinfo->cur_comp_info[0]; compptr = cinfo->cur_comp_info[0];
/* Overall image size in MCUs */ /* Overall image size in MCUs */
cinfo->MCUs_per_row = compptr->width_in_blocks; cinfo->MCUs_per_row = compptr->width_in_blocks;
cinfo->MCU_rows_in_scan = compptr->height_in_blocks; cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
/* For noninterleaved scan, always one block per MCU */ /* For noninterleaved scan, always one block per MCU */
compptr->MCU_width = 1; compptr->MCU_width = 1;
compptr->MCU_height = 1; compptr->MCU_height = 1;
@@ -163,28 +163,28 @@ per_scan_setup (j_decompress_ptr cinfo)
tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
if (tmp == 0) tmp = compptr->v_samp_factor; if (tmp == 0) tmp = compptr->v_samp_factor;
compptr->last_row_height = tmp; compptr->last_row_height = tmp;
/* Prepare array describing MCU composition */ /* Prepare array describing MCU composition */
cinfo->blocks_in_MCU = 1; cinfo->blocks_in_MCU = 1;
cinfo->MCU_membership[0] = 0; cinfo->MCU_membership[0] = 0;
} else { } else {
/* Interleaved (multi-component) scan */ /* Interleaved (multi-component) scan */
if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
MAX_COMPS_IN_SCAN); MAX_COMPS_IN_SCAN);
/* Overall image size in MCUs */ /* Overall image size in MCUs */
cinfo->MCUs_per_row = (JDIMENSION) cinfo->MCUs_per_row = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width, jdiv_round_up((long) cinfo->image_width,
(long) (cinfo->max_h_samp_factor*DCTSIZE)); (long) (cinfo->max_h_samp_factor*DCTSIZE));
cinfo->MCU_rows_in_scan = (JDIMENSION) cinfo->MCU_rows_in_scan = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height, jdiv_round_up((long) cinfo->image_height,
(long) (cinfo->max_v_samp_factor*DCTSIZE)); (long) (cinfo->max_v_samp_factor*DCTSIZE));
cinfo->blocks_in_MCU = 0; cinfo->blocks_in_MCU = 0;
for (ci = 0; ci < cinfo->comps_in_scan; ci++) { for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci]; compptr = cinfo->cur_comp_info[ci];
/* Sampling factors give # of blocks of component in each MCU */ /* Sampling factors give # of blocks of component in each MCU */
@@ -202,12 +202,12 @@ per_scan_setup (j_decompress_ptr cinfo)
/* Prepare array describing MCU composition */ /* Prepare array describing MCU composition */
mcublks = compptr->MCU_blocks; mcublks = compptr->MCU_blocks;
if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
ERREXIT(cinfo, JERR_BAD_MCU_SIZE); ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
while (mcublks-- > 0) { while (mcublks-- > 0) {
cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
} }
} }
} }
} }
@@ -248,12 +248,12 @@ latch_quant_tables (j_decompress_ptr cinfo)
/* Make sure specified quantization table is present */ /* Make sure specified quantization table is present */
qtblno = compptr->quant_tbl_no; qtblno = compptr->quant_tbl_no;
if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
cinfo->quant_tbl_ptrs[qtblno] == NULL) cinfo->quant_tbl_ptrs[qtblno] == NULL)
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
/* OK, save away the quantization table */ /* OK, save away the quantization table */
qtbl = (JQUANT_TBL *) qtbl = (JQUANT_TBL *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(JQUANT_TBL)); SIZEOF(JQUANT_TBL));
MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL)); MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
compptr->quant_table = qtbl; compptr->quant_table = qtbl;
} }
@@ -313,31 +313,31 @@ consume_markers (j_decompress_ptr cinfo)
val = (*cinfo->marker->read_markers) (cinfo); val = (*cinfo->marker->read_markers) (cinfo);
switch (val) { switch (val) {
case JPEG_REACHED_SOS: /* Found SOS */ case JPEG_REACHED_SOS: /* Found SOS */
if (inputctl->inheaders) { /* 1st SOS */ if (inputctl->inheaders) { /* 1st SOS */
initial_setup(cinfo); initial_setup(cinfo);
inputctl->inheaders = FALSE; inputctl->inheaders = FALSE;
/* Note: start_input_pass must be called by jdmaster.c /* Note: start_input_pass must be called by jdmaster.c
* before any more input can be consumed. jdapimin.c is * before any more input can be consumed. jdapimin.c is
* responsible for enforcing this sequencing. * responsible for enforcing this sequencing.
*/ */
} else { /* 2nd or later SOS marker */ } else { /* 2nd or later SOS marker */
if (! inputctl->pub.has_multiple_scans) if (! inputctl->pub.has_multiple_scans)
ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */ ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
start_input_pass(cinfo); start_input_pass(cinfo);
} }
break; break;
case JPEG_REACHED_EOI: /* Found EOI */ case JPEG_REACHED_EOI: /* Found EOI */
inputctl->pub.eoi_reached = TRUE; inputctl->pub.eoi_reached = TRUE;
if (inputctl->inheaders) { /* Tables-only datastream, apparently */ if (inputctl->inheaders) { /* Tables-only datastream, apparently */
if (cinfo->marker->saw_SOF) if (cinfo->marker->saw_SOF)
ERREXIT(cinfo, JERR_SOF_NO_SOS); ERREXIT(cinfo, JERR_SOF_NO_SOS);
} else { } else {
/* Prevent infinite loop in coef ctlr's decompress_data routine /* Prevent infinite loop in coef ctlr's decompress_data routine
* if user set output_scan_number larger than number of scans. * if user set output_scan_number larger than number of scans.
*/ */
if (cinfo->output_scan_number > cinfo->input_scan_number) if (cinfo->output_scan_number > cinfo->input_scan_number)
cinfo->output_scan_number = cinfo->input_scan_number; cinfo->output_scan_number = cinfo->input_scan_number;
} }
break; break;
case JPEG_SUSPENDED: case JPEG_SUSPENDED:
@@ -382,7 +382,7 @@ jinit_input_controller (j_decompress_ptr cinfo)
/* Create subobject in permanent pool */ /* Create subobject in permanent pool */
inputctl = (my_inputctl_ptr) inputctl = (my_inputctl_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_input_controller)); SIZEOF(my_input_controller));
cinfo->inputctl = (struct jpeg_input_controller *) inputctl; cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
/* Initialize method pointers */ /* Initialize method pointers */
inputctl->pub.consume_input = consume_markers; inputctl->pub.consume_input = consume_markers;

View File

@@ -120,39 +120,39 @@ typedef struct {
/* Pointer to allocated workspace (M or M+2 row groups). */ /* Pointer to allocated workspace (M or M+2 row groups). */
JSAMPARRAY buffer[MAX_COMPONENTS]; JSAMPARRAY buffer[MAX_COMPONENTS];
boolean buffer_full; /* Have we gotten an iMCU row from decoder? */ boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */ JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
/* Remaining fields are only used in the context case. */ /* Remaining fields are only used in the context case. */
/* These are the master pointers to the funny-order pointer lists. */ /* These are the master pointers to the funny-order pointer lists. */
JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */ JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
int whichptr; /* indicates which pointer set is now in use */ int whichptr; /* indicates which pointer set is now in use */
int context_state; /* process_data state machine status */ int context_state; /* process_data state machine status */
JDIMENSION rowgroups_avail; /* row groups available to postprocessor */ JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */ JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
} my_main_controller; } my_main_controller;
typedef my_main_controller * my_main_ptr; typedef my_main_controller * my_main_ptr;
/* context_state values: */ /* context_state values: */
#define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */ #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
#define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */ #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
#define CTX_POSTPONED_ROW 2 /* feeding postponed row group */ #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
/* Forward declarations */ /* Forward declarations */
METHODDEF(void) process_data_simple_main METHODDEF(void) process_data_simple_main
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
METHODDEF(void) process_data_context_main METHODDEF(void) process_data_context_main
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void) process_data_crank_post METHODDEF(void) process_data_crank_post
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf, JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)); JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
#endif #endif
@@ -173,7 +173,7 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
*/ */
main_ptr->xbuffer[0] = (JSAMPIMAGE) main_ptr->xbuffer[0] = (JSAMPIMAGE)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->num_components * 2 * SIZEOF(JSAMPARRAY)); cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components; main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
@@ -185,8 +185,8 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
*/ */
xbuf = (JSAMPARRAY) xbuf = (JSAMPARRAY)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW)); 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
xbuf += rgroup; /* want one row group at negative offsets */ xbuf += rgroup; /* want one row group at negative offsets */
main_ptr->xbuffer[0][ci] = xbuf; main_ptr->xbuffer[0][ci] = xbuf;
xbuf += rgroup * (M + 4); xbuf += rgroup * (M + 4);
main_ptr->xbuffer[1][ci] = xbuf; main_ptr->xbuffer[1][ci] = xbuf;
@@ -316,14 +316,14 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
if (cinfo->upsample->need_context_rows) { if (cinfo->upsample->need_context_rows) {
main_ptr->pub.process_data = process_data_context_main; main_ptr->pub.process_data = process_data_context_main;
make_funny_pointers(cinfo); /* Create the xbuffer[] lists */ make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
main_ptr->whichptr = 0; /* Read first iMCU row into xbuffer[0] */ main_ptr->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
main_ptr->context_state = CTX_PREPARE_FOR_IMCU; main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
main_ptr->iMCU_row_ctr = 0; main_ptr->iMCU_row_ctr = 0;
} else { } else {
/* Simple case with no context needed */ /* Simple case with no context needed */
main_ptr->pub.process_data = process_data_simple_main; main_ptr->pub.process_data = process_data_simple_main;
} }
main_ptr->buffer_full = FALSE; /* Mark buffer empty */ main_ptr->buffer_full = FALSE; /* Mark buffer empty */
main_ptr->rowgroup_ctr = 0; main_ptr->rowgroup_ctr = 0;
break; break;
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
@@ -346,8 +346,8 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
METHODDEF(void) METHODDEF(void)
process_data_simple_main (j_decompress_ptr cinfo, process_data_simple_main (j_decompress_ptr cinfo,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail) JDIMENSION out_rows_avail)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
JDIMENSION rowgroups_avail; JDIMENSION rowgroups_avail;
@@ -355,8 +355,8 @@ process_data_simple_main (j_decompress_ptr cinfo,
/* Read input data if we haven't filled the main buffer yet */ /* Read input data if we haven't filled the main buffer yet */
if (! main_ptr->buffer_full) { if (! main_ptr->buffer_full) {
if (! (*cinfo->coef->decompress_data) (cinfo, main_ptr->buffer)) if (! (*cinfo->coef->decompress_data) (cinfo, main_ptr->buffer))
return; /* suspension forced, can do nothing more */ return; /* suspension forced, can do nothing more */
main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
} }
/* There are always min_DCT_scaled_size row groups in an iMCU row. */ /* There are always min_DCT_scaled_size row groups in an iMCU row. */
@@ -368,8 +368,8 @@ process_data_simple_main (j_decompress_ptr cinfo,
/* Feed the postprocessor */ /* Feed the postprocessor */
(*cinfo->post->post_process_data) (cinfo, main_ptr->buffer, (*cinfo->post->post_process_data) (cinfo, main_ptr->buffer,
&main_ptr->rowgroup_ctr, rowgroups_avail, &main_ptr->rowgroup_ctr, rowgroups_avail,
output_buf, out_row_ctr, out_rows_avail); output_buf, out_row_ctr, out_rows_avail);
/* Has postprocessor consumed all the data yet? If so, mark buffer empty */ /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
if (main_ptr->rowgroup_ctr >= rowgroups_avail) { if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
@@ -386,18 +386,18 @@ process_data_simple_main (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
process_data_context_main (j_decompress_ptr cinfo, process_data_context_main (j_decompress_ptr cinfo,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail) JDIMENSION out_rows_avail)
{ {
my_main_ptr main_ptr = (my_main_ptr) cinfo->main; my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
/* Read input data if we haven't filled the main buffer yet */ /* Read input data if we haven't filled the main buffer yet */
if (! main_ptr->buffer_full) { if (! main_ptr->buffer_full) {
if (! (*cinfo->coef->decompress_data) (cinfo, if (! (*cinfo->coef->decompress_data) (cinfo,
main_ptr->xbuffer[main_ptr->whichptr])) main_ptr->xbuffer[main_ptr->whichptr]))
return; /* suspension forced, can do nothing more */ return; /* suspension forced, can do nothing more */
main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
main_ptr->iMCU_row_ctr++; /* count rows received */ main_ptr->iMCU_row_ctr++; /* count rows received */
} }
/* Postprocessor typically will not swallow all the input data it is handed /* Postprocessor typically will not swallow all the input data it is handed
@@ -409,13 +409,13 @@ process_data_context_main (j_decompress_ptr cinfo,
case CTX_POSTPONED_ROW: case CTX_POSTPONED_ROW:
/* Call postprocessor using previously set pointers for postponed row */ /* Call postprocessor using previously set pointers for postponed row */
(*cinfo->post->post_process_data) (cinfo, main_ptr->xbuffer[main_ptr->whichptr], (*cinfo->post->post_process_data) (cinfo, main_ptr->xbuffer[main_ptr->whichptr],
&main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail, &main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail,
output_buf, out_row_ctr, out_rows_avail); output_buf, out_row_ctr, out_rows_avail);
if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail) if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
return; /* Need to suspend */ return; /* Need to suspend */
main_ptr->context_state = CTX_PREPARE_FOR_IMCU; main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
if (*out_row_ctr >= out_rows_avail) if (*out_row_ctr >= out_rows_avail)
return; /* Postprocessor exactly filled output buf */ return; /* Postprocessor exactly filled output buf */
/*FALLTHROUGH*/ /*FALLTHROUGH*/
case CTX_PREPARE_FOR_IMCU: case CTX_PREPARE_FOR_IMCU:
/* Prepare to process first M-1 row groups of this iMCU row */ /* Prepare to process first M-1 row groups of this iMCU row */
@@ -431,15 +431,15 @@ process_data_context_main (j_decompress_ptr cinfo,
case CTX_PROCESS_IMCU: case CTX_PROCESS_IMCU:
/* Call postprocessor using previously set pointers */ /* Call postprocessor using previously set pointers */
(*cinfo->post->post_process_data) (cinfo, main_ptr->xbuffer[main_ptr->whichptr], (*cinfo->post->post_process_data) (cinfo, main_ptr->xbuffer[main_ptr->whichptr],
&main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail, &main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail,
output_buf, out_row_ctr, out_rows_avail); output_buf, out_row_ctr, out_rows_avail);
if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail) if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
return; /* Need to suspend */ return; /* Need to suspend */
/* After the first iMCU, change wraparound pointers to normal state */ /* After the first iMCU, change wraparound pointers to normal state */
if (main_ptr->iMCU_row_ctr == 1) if (main_ptr->iMCU_row_ctr == 1)
set_wraparound_pointers(cinfo); set_wraparound_pointers(cinfo);
/* Prepare to load new iMCU row using other xbuffer list */ /* Prepare to load new iMCU row using other xbuffer list */
main_ptr->whichptr ^= 1; /* 0=>1 or 1=>0 */ main_ptr->whichptr ^= 1; /* 0=>1 or 1=>0 */
main_ptr->buffer_full = FALSE; main_ptr->buffer_full = FALSE;
/* Still need to process last row group of this iMCU row, */ /* Still need to process last row group of this iMCU row, */
/* which is saved at index M+1 of the other xbuffer */ /* which is saved at index M+1 of the other xbuffer */
@@ -460,12 +460,12 @@ process_data_context_main (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
process_data_crank_post (j_decompress_ptr cinfo, process_data_crank_post (j_decompress_ptr cinfo,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail) JDIMENSION out_rows_avail)
{ {
(*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL, (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
(JDIMENSION *) NULL, (JDIMENSION) 0, (JDIMENSION *) NULL, (JDIMENSION) 0,
output_buf, out_row_ctr, out_rows_avail); output_buf, out_row_ctr, out_rows_avail);
} }
#endif /* QUANT_2PASS_SUPPORTED */ #endif /* QUANT_2PASS_SUPPORTED */
@@ -484,11 +484,11 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
main_ptr = (my_main_ptr) main_ptr = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_main_controller)); SIZEOF(my_main_controller));
cinfo->main = (struct jpeg_d_main_controller *) main_ptr; cinfo->main = (struct jpeg_d_main_controller *) main_ptr;
main_ptr->pub.start_pass = start_pass_main; main_ptr->pub.start_pass = start_pass_main;
if (need_full_buffer) /* shouldn't happen */ if (need_full_buffer) /* shouldn't happen */
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
/* Allocate the workspace. /* Allocate the workspace.
@@ -508,8 +508,8 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
cinfo->_min_DCT_scaled_size; /* height of a row group of component */ cinfo->_min_DCT_scaled_size; /* height of a row group of component */
main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray) main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
compptr->width_in_blocks * compptr->_DCT_scaled_size, compptr->width_in_blocks * compptr->_DCT_scaled_size,
(JDIMENSION) (rgroup * ngroups)); (JDIMENSION) (rgroup * ngroups));
} }
} }

View File

@@ -19,29 +19,29 @@
#include "jpeglib.h" #include "jpeglib.h"
typedef enum { /* JPEG marker codes */ typedef enum { /* JPEG marker codes */
M_SOF0 = 0xc0, M_SOF0 = 0xc0,
M_SOF1 = 0xc1, M_SOF1 = 0xc1,
M_SOF2 = 0xc2, M_SOF2 = 0xc2,
M_SOF3 = 0xc3, M_SOF3 = 0xc3,
M_SOF5 = 0xc5, M_SOF5 = 0xc5,
M_SOF6 = 0xc6, M_SOF6 = 0xc6,
M_SOF7 = 0xc7, M_SOF7 = 0xc7,
M_JPG = 0xc8, M_JPG = 0xc8,
M_SOF9 = 0xc9, M_SOF9 = 0xc9,
M_SOF10 = 0xca, M_SOF10 = 0xca,
M_SOF11 = 0xcb, M_SOF11 = 0xcb,
M_SOF13 = 0xcd, M_SOF13 = 0xcd,
M_SOF14 = 0xce, M_SOF14 = 0xce,
M_SOF15 = 0xcf, M_SOF15 = 0xcf,
M_DHT = 0xc4, M_DHT = 0xc4,
M_DAC = 0xcc, M_DAC = 0xcc,
M_RST0 = 0xd0, M_RST0 = 0xd0,
M_RST1 = 0xd1, M_RST1 = 0xd1,
M_RST2 = 0xd2, M_RST2 = 0xd2,
@@ -50,7 +50,7 @@ typedef enum { /* JPEG marker codes */
M_RST5 = 0xd5, M_RST5 = 0xd5,
M_RST6 = 0xd6, M_RST6 = 0xd6,
M_RST7 = 0xd7, M_RST7 = 0xd7,
M_SOI = 0xd8, M_SOI = 0xd8,
M_EOI = 0xd9, M_EOI = 0xd9,
M_SOS = 0xda, M_SOS = 0xda,
@@ -59,7 +59,7 @@ typedef enum { /* JPEG marker codes */
M_DRI = 0xdd, M_DRI = 0xdd,
M_DHP = 0xde, M_DHP = 0xde,
M_EXP = 0xdf, M_EXP = 0xdf,
M_APP0 = 0xe0, M_APP0 = 0xe0,
M_APP1 = 0xe1, M_APP1 = 0xe1,
M_APP2 = 0xe2, M_APP2 = 0xe2,
@@ -76,13 +76,13 @@ typedef enum { /* JPEG marker codes */
M_APP13 = 0xed, M_APP13 = 0xed,
M_APP14 = 0xee, M_APP14 = 0xee,
M_APP15 = 0xef, M_APP15 = 0xef,
M_JPG0 = 0xf0, M_JPG0 = 0xf0,
M_JPG13 = 0xfd, M_JPG13 = 0xfd,
M_COM = 0xfe, M_COM = 0xfe,
M_TEM = 0x01, M_TEM = 0x01,
M_ERROR = 0x100 M_ERROR = 0x100
} JPEG_MARKER; } JPEG_MARKER;
@@ -101,8 +101,8 @@ typedef struct {
unsigned int length_limit_APPn[16]; unsigned int length_limit_APPn[16];
/* Status of COM/APPn marker saving */ /* Status of COM/APPn marker saving */
jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */ jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
unsigned int bytes_read; /* data bytes read so far in marker */ unsigned int bytes_read; /* data bytes read so far in marker */
/* Note: cur_marker is not linked into marker_list until it's all read. */ /* Note: cur_marker is not linked into marker_list until it's all read. */
} my_marker_reader; } my_marker_reader;
@@ -119,49 +119,49 @@ typedef my_marker_reader * my_marker_ptr;
/* Declare and initialize local copies of input pointer/count */ /* Declare and initialize local copies of input pointer/count */
#define INPUT_VARS(cinfo) \ #define INPUT_VARS(cinfo) \
struct jpeg_source_mgr * datasrc = (cinfo)->src; \ struct jpeg_source_mgr * datasrc = (cinfo)->src; \
const JOCTET * next_input_byte = datasrc->next_input_byte; \ const JOCTET * next_input_byte = datasrc->next_input_byte; \
size_t bytes_in_buffer = datasrc->bytes_in_buffer size_t bytes_in_buffer = datasrc->bytes_in_buffer
/* Unload the local copies --- do this only at a restart boundary */ /* Unload the local copies --- do this only at a restart boundary */
#define INPUT_SYNC(cinfo) \ #define INPUT_SYNC(cinfo) \
( datasrc->next_input_byte = next_input_byte, \ ( datasrc->next_input_byte = next_input_byte, \
datasrc->bytes_in_buffer = bytes_in_buffer ) datasrc->bytes_in_buffer = bytes_in_buffer )
/* Reload the local copies --- used only in MAKE_BYTE_AVAIL */ /* Reload the local copies --- used only in MAKE_BYTE_AVAIL */
#define INPUT_RELOAD(cinfo) \ #define INPUT_RELOAD(cinfo) \
( next_input_byte = datasrc->next_input_byte, \ ( next_input_byte = datasrc->next_input_byte, \
bytes_in_buffer = datasrc->bytes_in_buffer ) bytes_in_buffer = datasrc->bytes_in_buffer )
/* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available. /* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available.
* Note we do *not* do INPUT_SYNC before calling fill_input_buffer, * Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
* but we must reload the local copies after a successful fill. * but we must reload the local copies after a successful fill.
*/ */
#define MAKE_BYTE_AVAIL(cinfo,action) \ #define MAKE_BYTE_AVAIL(cinfo,action) \
if (bytes_in_buffer == 0) { \ if (bytes_in_buffer == 0) { \
if (! (*datasrc->fill_input_buffer) (cinfo)) \ if (! (*datasrc->fill_input_buffer) (cinfo)) \
{ action; } \ { action; } \
INPUT_RELOAD(cinfo); \ INPUT_RELOAD(cinfo); \
} }
/* Read a byte into variable V. /* Read a byte into variable V.
* If must suspend, take the specified action (typically "return FALSE"). * If must suspend, take the specified action (typically "return FALSE").
*/ */
#define INPUT_BYTE(cinfo,V,action) \ #define INPUT_BYTE(cinfo,V,action) \
MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
bytes_in_buffer--; \ bytes_in_buffer--; \
V = GETJOCTET(*next_input_byte++); ) V = GETJOCTET(*next_input_byte++); )
/* As above, but read two bytes interpreted as an unsigned 16-bit integer. /* As above, but read two bytes interpreted as an unsigned 16-bit integer.
* V should be declared unsigned int or perhaps INT32. * V should be declared unsigned int or perhaps INT32.
*/ */
#define INPUT_2BYTES(cinfo,V,action) \ #define INPUT_2BYTES(cinfo,V,action) \
MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
bytes_in_buffer--; \ bytes_in_buffer--; \
V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \ V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
MAKE_BYTE_AVAIL(cinfo,action); \ MAKE_BYTE_AVAIL(cinfo,action); \
bytes_in_buffer--; \ bytes_in_buffer--; \
V += GETJOCTET(*next_input_byte++); ) V += GETJOCTET(*next_input_byte++); )
/* /*
@@ -200,7 +200,7 @@ get_soi (j_decompress_ptr cinfo)
/* Process an SOI marker */ /* Process an SOI marker */
{ {
int i; int i;
TRACEMS(cinfo, 1, JTRC_SOI); TRACEMS(cinfo, 1, JTRC_SOI);
if (cinfo->marker->saw_SOI) if (cinfo->marker->saw_SOI)
@@ -257,8 +257,8 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
length -= 8; length -= 8;
TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker, TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
(int) cinfo->image_width, (int) cinfo->image_height, (int) cinfo->image_width, (int) cinfo->image_height,
cinfo->num_components); cinfo->num_components);
if (cinfo->marker->saw_SOF) if (cinfo->marker->saw_SOF)
ERREXIT(cinfo, JERR_SOF_DUPLICATE); ERREXIT(cinfo, JERR_SOF_DUPLICATE);
@@ -273,11 +273,11 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
if (length != (cinfo->num_components * 3)) if (length != (cinfo->num_components * 3))
ERREXIT(cinfo, JERR_BAD_LENGTH); ERREXIT(cinfo, JERR_BAD_LENGTH);
if (cinfo->comp_info == NULL) /* do only once, even if suspend */ if (cinfo->comp_info == NULL) /* do only once, even if suspend */
cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small) cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->num_components * SIZEOF(jpeg_component_info)); cinfo->num_components * SIZEOF(jpeg_component_info));
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
compptr->component_index = ci; compptr->component_index = ci;
@@ -288,8 +288,8 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE); INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT, TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
compptr->component_id, compptr->h_samp_factor, compptr->component_id, compptr->h_samp_factor,
compptr->v_samp_factor, compptr->quant_tbl_no); compptr->v_samp_factor, compptr->quant_tbl_no);
} }
cinfo->marker->saw_SOF = TRUE; cinfo->marker->saw_SOF = TRUE;
@@ -330,12 +330,12 @@ get_sos (j_decompress_ptr cinfo)
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
INPUT_BYTE(cinfo, cc, return FALSE); INPUT_BYTE(cinfo, cc, return FALSE);
INPUT_BYTE(cinfo, c, return FALSE); INPUT_BYTE(cinfo, c, return FALSE);
for (ci = 0, compptr = cinfo->comp_info; for (ci = 0, compptr = cinfo->comp_info;
ci < cinfo->num_components && ci < MAX_COMPS_IN_SCAN; ci < cinfo->num_components && ci < MAX_COMPS_IN_SCAN;
ci++, compptr++) { ci++, compptr++) {
if (cc == compptr->component_id && !cinfo->cur_comp_info[ci]) if (cc == compptr->component_id && !cinfo->cur_comp_info[ci])
goto id_found; goto id_found;
} }
ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc); ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
@@ -345,9 +345,9 @@ get_sos (j_decompress_ptr cinfo)
cinfo->cur_comp_info[i] = compptr; cinfo->cur_comp_info[i] = compptr;
compptr->dc_tbl_no = (c >> 4) & 15; compptr->dc_tbl_no = (c >> 4) & 15;
compptr->ac_tbl_no = (c ) & 15; compptr->ac_tbl_no = (c ) & 15;
TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
compptr->dc_tbl_no, compptr->ac_tbl_no); compptr->dc_tbl_no, compptr->ac_tbl_no);
/* This CSi (cc) should differ from the previous CSi */ /* This CSi (cc) should differ from the previous CSi */
for (pi = 0; pi < i; pi++) { for (pi = 0; pi < i; pi++) {
@@ -367,7 +367,7 @@ get_sos (j_decompress_ptr cinfo)
cinfo->Al = (c ) & 15; cinfo->Al = (c ) & 15;
TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se, TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
cinfo->Ah, cinfo->Al); cinfo->Ah, cinfo->Al);
/* Prepare to scan data & restart markers */ /* Prepare to scan data & restart markers */
cinfo->marker->next_restart_num = 0; cinfo->marker->next_restart_num = 0;
@@ -392,7 +392,7 @@ get_dac (j_decompress_ptr cinfo)
INPUT_2BYTES(cinfo, length, return FALSE); INPUT_2BYTES(cinfo, length, return FALSE);
length -= 2; length -= 2;
while (length > 0) { while (length > 0) {
INPUT_BYTE(cinfo, index, return FALSE); INPUT_BYTE(cinfo, index, return FALSE);
INPUT_BYTE(cinfo, val, return FALSE); INPUT_BYTE(cinfo, val, return FALSE);
@@ -406,11 +406,11 @@ get_dac (j_decompress_ptr cinfo)
if (index >= NUM_ARITH_TBLS) { /* define AC table */ if (index >= NUM_ARITH_TBLS) { /* define AC table */
cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val; cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
} else { /* define DC table */ } else { /* define DC table */
cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F); cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
cinfo->arith_dc_U[index] = (UINT8) (val >> 4); cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index]) if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
ERREXIT1(cinfo, JERR_DAC_VALUE, val); ERREXIT1(cinfo, JERR_DAC_VALUE, val);
} }
} }
@@ -441,12 +441,12 @@ get_dht (j_decompress_ptr cinfo)
INPUT_2BYTES(cinfo, length, return FALSE); INPUT_2BYTES(cinfo, length, return FALSE);
length -= 2; length -= 2;
while (length > 16) { while (length > 16) {
INPUT_BYTE(cinfo, index, return FALSE); INPUT_BYTE(cinfo, index, return FALSE);
TRACEMS1(cinfo, 1, JTRC_DHT, index); TRACEMS1(cinfo, 1, JTRC_DHT, index);
bits[0] = 0; bits[0] = 0;
count = 0; count = 0;
for (i = 1; i <= 16; i++) { for (i = 1; i <= 16; i++) {
@@ -457,11 +457,11 @@ get_dht (j_decompress_ptr cinfo)
length -= 1 + 16; length -= 1 + 16;
TRACEMS8(cinfo, 2, JTRC_HUFFBITS, TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
bits[1], bits[2], bits[3], bits[4], bits[1], bits[2], bits[3], bits[4],
bits[5], bits[6], bits[7], bits[8]); bits[5], bits[6], bits[7], bits[8]);
TRACEMS8(cinfo, 2, JTRC_HUFFBITS, TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
bits[9], bits[10], bits[11], bits[12], bits[9], bits[10], bits[11], bits[12],
bits[13], bits[14], bits[15], bits[16]); bits[13], bits[14], bits[15], bits[16]);
/* Here we just do minimal validation of the counts to avoid walking /* Here we just do minimal validation of the counts to avoid walking
* off the end of our table space. jdhuff.c will check more carefully. * off the end of our table space. jdhuff.c will check more carefully.
@@ -476,12 +476,12 @@ get_dht (j_decompress_ptr cinfo)
length -= count; length -= count;
if (index & 0x10) { /* AC table definition */ if (index & 0x10) { /* AC table definition */
index -= 0x10; index -= 0x10;
if (index < 0 || index >= NUM_HUFF_TBLS) if (index < 0 || index >= NUM_HUFF_TBLS)
ERREXIT1(cinfo, JERR_DHT_INDEX, index); ERREXIT1(cinfo, JERR_DHT_INDEX, index);
htblptr = &cinfo->ac_huff_tbl_ptrs[index]; htblptr = &cinfo->ac_huff_tbl_ptrs[index];
} else { /* DC table definition */ } else { /* DC table definition */
if (index < 0 || index >= NUM_HUFF_TBLS) if (index < 0 || index >= NUM_HUFF_TBLS)
ERREXIT1(cinfo, JERR_DHT_INDEX, index); ERREXIT1(cinfo, JERR_DHT_INDEX, index);
htblptr = &cinfo->dc_huff_tbl_ptrs[index]; htblptr = &cinfo->dc_huff_tbl_ptrs[index];
@@ -489,7 +489,7 @@ get_dht (j_decompress_ptr cinfo)
if (*htblptr == NULL) if (*htblptr == NULL)
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits)); MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval)); MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
} }
@@ -524,27 +524,27 @@ get_dqt (j_decompress_ptr cinfo)
if (n >= NUM_QUANT_TBLS) if (n >= NUM_QUANT_TBLS)
ERREXIT1(cinfo, JERR_DQT_INDEX, n); ERREXIT1(cinfo, JERR_DQT_INDEX, n);
if (cinfo->quant_tbl_ptrs[n] == NULL) if (cinfo->quant_tbl_ptrs[n] == NULL)
cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo); cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
quant_ptr = cinfo->quant_tbl_ptrs[n]; quant_ptr = cinfo->quant_tbl_ptrs[n];
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
if (prec) if (prec)
INPUT_2BYTES(cinfo, tmp, return FALSE); INPUT_2BYTES(cinfo, tmp, return FALSE);
else else
INPUT_BYTE(cinfo, tmp, return FALSE); INPUT_BYTE(cinfo, tmp, return FALSE);
/* We convert the zigzag-order table to natural array order. */ /* We convert the zigzag-order table to natural array order. */
quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp; quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
} }
if (cinfo->err->trace_level >= 2) { if (cinfo->err->trace_level >= 2) {
for (i = 0; i < DCTSIZE2; i += 8) { for (i = 0; i < DCTSIZE2; i += 8) {
TRACEMS8(cinfo, 2, JTRC_QUANTVALS, TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
quant_ptr->quantval[i], quant_ptr->quantval[i+1], quant_ptr->quantval[i], quant_ptr->quantval[i+1],
quant_ptr->quantval[i+2], quant_ptr->quantval[i+3], quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
quant_ptr->quantval[i+4], quant_ptr->quantval[i+5], quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]); quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
} }
} }
@@ -569,7 +569,7 @@ get_dri (j_decompress_ptr cinfo)
INPUT_VARS(cinfo); INPUT_VARS(cinfo);
INPUT_2BYTES(cinfo, length, return FALSE); INPUT_2BYTES(cinfo, length, return FALSE);
if (length != 4) if (length != 4)
ERREXIT(cinfo, JERR_BAD_LENGTH); ERREXIT(cinfo, JERR_BAD_LENGTH);
@@ -591,14 +591,14 @@ get_dri (j_decompress_ptr cinfo)
* JFIF and Adobe markers, respectively. * JFIF and Adobe markers, respectively.
*/ */
#define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */ #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
#define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */ #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
#define APPN_DATA_LEN 14 /* Must be the largest of the above!! */ #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
LOCAL(void) LOCAL(void)
examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data, examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
unsigned int datalen, INT32 remaining) unsigned int datalen, INT32 remaining)
/* Examine first few bytes from an APP0. /* Examine first few bytes from an APP0.
* Take appropriate action if it is a JFIF marker. * Take appropriate action if it is a JFIF marker.
* datalen is # of bytes at data[], remaining is length of rest of marker data. * datalen is # of bytes at data[], remaining is length of rest of marker data.
@@ -627,18 +627,18 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
*/ */
if (cinfo->JFIF_major_version != 1) if (cinfo->JFIF_major_version != 1)
WARNMS2(cinfo, JWRN_JFIF_MAJOR, WARNMS2(cinfo, JWRN_JFIF_MAJOR,
cinfo->JFIF_major_version, cinfo->JFIF_minor_version); cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
/* Generate trace messages */ /* Generate trace messages */
TRACEMS5(cinfo, 1, JTRC_JFIF, TRACEMS5(cinfo, 1, JTRC_JFIF,
cinfo->JFIF_major_version, cinfo->JFIF_minor_version, cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
cinfo->X_density, cinfo->Y_density, cinfo->density_unit); cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
/* Validate thumbnail dimensions and issue appropriate messages */ /* Validate thumbnail dimensions and issue appropriate messages */
if (GETJOCTET(data[12]) | GETJOCTET(data[13])) if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
GETJOCTET(data[12]), GETJOCTET(data[13])); GETJOCTET(data[12]), GETJOCTET(data[13]));
totallen -= APP0_DATA_LEN; totallen -= APP0_DATA_LEN;
if (totallen != if (totallen !=
((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3)) ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen); TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
} else if (datalen >= 6 && } else if (datalen >= 6 &&
GETJOCTET(data[0]) == 0x4A && GETJOCTET(data[0]) == 0x4A &&
@@ -662,7 +662,7 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
break; break;
default: default:
TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION, TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
GETJOCTET(data[5]), (int) totallen); GETJOCTET(data[5]), (int) totallen);
break; break;
} }
} else { } else {
@@ -674,7 +674,7 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
LOCAL(void) LOCAL(void)
examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data, examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
unsigned int datalen, INT32 remaining) unsigned int datalen, INT32 remaining)
/* Examine first few bytes from an APP14. /* Examine first few bytes from an APP14.
* Take appropriate action if it is an Adobe marker. * Take appropriate action if it is an Adobe marker.
* datalen is # of bytes at data[], remaining is length of rest of marker data. * datalen is # of bytes at data[], remaining is length of rest of marker data.
@@ -766,19 +766,19 @@ save_marker (j_decompress_ptr cinfo)
/* begin reading a marker */ /* begin reading a marker */
INPUT_2BYTES(cinfo, length, return FALSE); INPUT_2BYTES(cinfo, length, return FALSE);
length -= 2; length -= 2;
if (length >= 0) { /* watch out for bogus length word */ if (length >= 0) { /* watch out for bogus length word */
/* figure out how much we want to save */ /* figure out how much we want to save */
unsigned int limit; unsigned int limit;
if (cinfo->unread_marker == (int) M_COM) if (cinfo->unread_marker == (int) M_COM)
limit = marker->length_limit_COM; limit = marker->length_limit_COM;
else else
limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0]; limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
if ((unsigned int) length < limit) if ((unsigned int) length < limit)
limit = (unsigned int) length; limit = (unsigned int) length;
/* allocate and initialize the marker item */ /* allocate and initialize the marker item */
cur_marker = (jpeg_saved_marker_ptr) cur_marker = (jpeg_saved_marker_ptr)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(struct jpeg_marker_struct) + limit); SIZEOF(struct jpeg_marker_struct) + limit);
cur_marker->next = NULL; cur_marker->next = NULL;
cur_marker->marker = (UINT8) cinfo->unread_marker; cur_marker->marker = (UINT8) cinfo->unread_marker;
cur_marker->original_length = (unsigned int) length; cur_marker->original_length = (unsigned int) length;
@@ -802,7 +802,7 @@ save_marker (j_decompress_ptr cinfo)
} }
while (bytes_read < data_length) { while (bytes_read < data_length) {
INPUT_SYNC(cinfo); /* move the restart point to here */ INPUT_SYNC(cinfo); /* move the restart point to here */
marker->bytes_read = bytes_read; marker->bytes_read = bytes_read;
/* If there's not at least one byte in buffer, suspend */ /* If there's not at least one byte in buffer, suspend */
MAKE_BYTE_AVAIL(cinfo, return FALSE); MAKE_BYTE_AVAIL(cinfo, return FALSE);
@@ -815,14 +815,14 @@ save_marker (j_decompress_ptr cinfo)
} }
/* Done reading what we want to read */ /* Done reading what we want to read */
if (cur_marker != NULL) { /* will be NULL if bogus length word */ if (cur_marker != NULL) { /* will be NULL if bogus length word */
/* Add new marker to end of list */ /* Add new marker to end of list */
if (cinfo->marker_list == NULL) { if (cinfo->marker_list == NULL) {
cinfo->marker_list = cur_marker; cinfo->marker_list = cur_marker;
} else { } else {
jpeg_saved_marker_ptr prev = cinfo->marker_list; jpeg_saved_marker_ptr prev = cinfo->marker_list;
while (prev->next != NULL) while (prev->next != NULL)
prev = prev->next; prev = prev->next;
prev->next = cur_marker; prev->next = cur_marker;
} }
/* Reset pointer & calc remaining data length */ /* Reset pointer & calc remaining data length */
@@ -842,12 +842,12 @@ save_marker (j_decompress_ptr cinfo)
break; break;
default: default:
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
(int) (data_length + length)); (int) (data_length + length));
break; break;
} }
/* skip any remaining data -- could be lots */ /* skip any remaining data -- could be lots */
INPUT_SYNC(cinfo); /* do before skip_input_data */ INPUT_SYNC(cinfo); /* do before skip_input_data */
if (length > 0) if (length > 0)
(*cinfo->src->skip_input_data) (cinfo, (long) length); (*cinfo->src->skip_input_data) (cinfo, (long) length);
@@ -866,10 +866,10 @@ skip_variable (j_decompress_ptr cinfo)
INPUT_2BYTES(cinfo, length, return FALSE); INPUT_2BYTES(cinfo, length, return FALSE);
length -= 2; length -= 2;
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length); TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
INPUT_SYNC(cinfo); /* do before skip_input_data */ INPUT_SYNC(cinfo); /* do before skip_input_data */
if (length > 0) if (length > 0)
(*cinfo->src->skip_input_data) (cinfo, (long) length); (*cinfo->src->skip_input_data) (cinfo, (long) length);
@@ -913,7 +913,7 @@ next_marker (j_decompress_ptr cinfo)
INPUT_BYTE(cinfo, c, return FALSE); INPUT_BYTE(cinfo, c, return FALSE);
} while (c == 0xFF); } while (c == 0xFF);
if (c != 0) if (c != 0)
break; /* found a valid marker, exit loop */ break; /* found a valid marker, exit loop */
/* Reach here if we found a stuffed-zero data sequence (FF/00). /* Reach here if we found a stuffed-zero data sequence (FF/00).
* Discard it and loop back to try again. * Discard it and loop back to try again.
*/ */
@@ -973,11 +973,11 @@ read_markers (j_decompress_ptr cinfo)
/* NB: first_marker() enforces the requirement that SOI appear first. */ /* NB: first_marker() enforces the requirement that SOI appear first. */
if (cinfo->unread_marker == 0) { if (cinfo->unread_marker == 0) {
if (! cinfo->marker->saw_SOI) { if (! cinfo->marker->saw_SOI) {
if (! first_marker(cinfo)) if (! first_marker(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} else { } else {
if (! next_marker(cinfo)) if (! next_marker(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
} }
} }
/* At this point cinfo->unread_marker contains the marker code and the /* At this point cinfo->unread_marker contains the marker code and the
@@ -987,74 +987,74 @@ read_markers (j_decompress_ptr cinfo)
switch (cinfo->unread_marker) { switch (cinfo->unread_marker) {
case M_SOI: case M_SOI:
if (! get_soi(cinfo)) if (! get_soi(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_SOF0: /* Baseline */ case M_SOF0: /* Baseline */
case M_SOF1: /* Extended sequential, Huffman */ case M_SOF1: /* Extended sequential, Huffman */
if (! get_sof(cinfo, FALSE, FALSE)) if (! get_sof(cinfo, FALSE, FALSE))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_SOF2: /* Progressive, Huffman */ case M_SOF2: /* Progressive, Huffman */
if (! get_sof(cinfo, TRUE, FALSE)) if (! get_sof(cinfo, TRUE, FALSE))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_SOF9: /* Extended sequential, arithmetic */ case M_SOF9: /* Extended sequential, arithmetic */
if (! get_sof(cinfo, FALSE, TRUE)) if (! get_sof(cinfo, FALSE, TRUE))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_SOF10: /* Progressive, arithmetic */ case M_SOF10: /* Progressive, arithmetic */
if (! get_sof(cinfo, TRUE, TRUE)) if (! get_sof(cinfo, TRUE, TRUE))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
/* Currently unsupported SOFn types */ /* Currently unsupported SOFn types */
case M_SOF3: /* Lossless, Huffman */ case M_SOF3: /* Lossless, Huffman */
case M_SOF5: /* Differential sequential, Huffman */ case M_SOF5: /* Differential sequential, Huffman */
case M_SOF6: /* Differential progressive, Huffman */ case M_SOF6: /* Differential progressive, Huffman */
case M_SOF7: /* Differential lossless, Huffman */ case M_SOF7: /* Differential lossless, Huffman */
case M_JPG: /* Reserved for JPEG extensions */ case M_JPG: /* Reserved for JPEG extensions */
case M_SOF11: /* Lossless, arithmetic */ case M_SOF11: /* Lossless, arithmetic */
case M_SOF13: /* Differential sequential, arithmetic */ case M_SOF13: /* Differential sequential, arithmetic */
case M_SOF14: /* Differential progressive, arithmetic */ case M_SOF14: /* Differential progressive, arithmetic */
case M_SOF15: /* Differential lossless, arithmetic */ case M_SOF15: /* Differential lossless, arithmetic */
ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker); ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
break; break;
case M_SOS: case M_SOS:
if (! get_sos(cinfo)) if (! get_sos(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
cinfo->unread_marker = 0; /* processed the marker */ cinfo->unread_marker = 0; /* processed the marker */
return JPEG_REACHED_SOS; return JPEG_REACHED_SOS;
case M_EOI: case M_EOI:
TRACEMS(cinfo, 1, JTRC_EOI); TRACEMS(cinfo, 1, JTRC_EOI);
cinfo->unread_marker = 0; /* processed the marker */ cinfo->unread_marker = 0; /* processed the marker */
return JPEG_REACHED_EOI; return JPEG_REACHED_EOI;
case M_DAC: case M_DAC:
if (! get_dac(cinfo)) if (! get_dac(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_DHT: case M_DHT:
if (! get_dht(cinfo)) if (! get_dht(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_DQT: case M_DQT:
if (! get_dqt(cinfo)) if (! get_dqt(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_DRI: case M_DRI:
if (! get_dri(cinfo)) if (! get_dri(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_APP0: case M_APP0:
case M_APP1: case M_APP1:
case M_APP2: case M_APP2:
@@ -1072,16 +1072,16 @@ read_markers (j_decompress_ptr cinfo)
case M_APP14: case M_APP14:
case M_APP15: case M_APP15:
if (! (*((my_marker_ptr) cinfo->marker)->process_APPn[ if (! (*((my_marker_ptr) cinfo->marker)->process_APPn[
cinfo->unread_marker - (int) M_APP0]) (cinfo)) cinfo->unread_marker - (int) M_APP0]) (cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break;
case M_COM:
if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo))
return JPEG_SUSPENDED;
break; break;
case M_RST0: /* these are all parameterless */ case M_COM:
if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo))
return JPEG_SUSPENDED;
break;
case M_RST0: /* these are all parameterless */
case M_RST1: case M_RST1:
case M_RST2: case M_RST2:
case M_RST3: case M_RST3:
@@ -1093,12 +1093,12 @@ read_markers (j_decompress_ptr cinfo)
TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker); TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
break; break;
case M_DNL: /* Ignore DNL ... perhaps the wrong thing */ case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
if (! skip_variable(cinfo)) if (! skip_variable(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
default: /* must be DHP, EXP, JPGn, or RESn */ default: /* must be DHP, EXP, JPGn, or RESn */
/* For now, we treat the reserved markers as fatal errors since they are /* For now, we treat the reserved markers as fatal errors since they are
* likely to be used to signal incompatible JPEG Part 3 extensions. * likely to be used to signal incompatible JPEG Part 3 extensions.
* Once the JPEG 3 version-number marker is well defined, this code * Once the JPEG 3 version-number marker is well defined, this code
@@ -1144,7 +1144,7 @@ read_restart_marker (j_decompress_ptr cinfo)
/* Uh-oh, the restart markers have been messed up. */ /* Uh-oh, the restart markers have been messed up. */
/* Let the data source manager determine how to resync. */ /* Let the data source manager determine how to resync. */
if (! (*cinfo->src->resync_to_restart) (cinfo, if (! (*cinfo->src->resync_to_restart) (cinfo,
cinfo->marker->next_restart_num)) cinfo->marker->next_restart_num))
return FALSE; return FALSE;
} }
@@ -1209,25 +1209,25 @@ jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
{ {
int marker = cinfo->unread_marker; int marker = cinfo->unread_marker;
int action = 1; int action = 1;
/* Always put up a warning. */ /* Always put up a warning. */
WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired); WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
/* Outer loop handles repeated decision after scanning forward. */ /* Outer loop handles repeated decision after scanning forward. */
for (;;) { for (;;) {
if (marker < (int) M_SOF0) if (marker < (int) M_SOF0)
action = 2; /* invalid marker */ action = 2; /* invalid marker */
else if (marker < (int) M_RST0 || marker > (int) M_RST7) else if (marker < (int) M_RST0 || marker > (int) M_RST7)
action = 3; /* valid non-restart marker */ action = 3; /* valid non-restart marker */
else { else {
if (marker == ((int) M_RST0 + ((desired+1) & 7)) || if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
marker == ((int) M_RST0 + ((desired+2) & 7))) marker == ((int) M_RST0 + ((desired+2) & 7)))
action = 3; /* one of the next two expected restarts */ action = 3; /* one of the next two expected restarts */
else if (marker == ((int) M_RST0 + ((desired-1) & 7)) || else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
marker == ((int) M_RST0 + ((desired-2) & 7))) marker == ((int) M_RST0 + ((desired-2) & 7)))
action = 2; /* a prior restart, so advance */ action = 2; /* a prior restart, so advance */
else else
action = 1; /* desired restart or too far away */ action = 1; /* desired restart or too far away */
} }
TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action); TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
switch (action) { switch (action) {
@@ -1238,7 +1238,7 @@ jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
case 2: case 2:
/* Scan to the next marker, and repeat the decision loop. */ /* Scan to the next marker, and repeat the decision loop. */
if (! next_marker(cinfo)) if (! next_marker(cinfo))
return FALSE; return FALSE;
marker = cinfo->unread_marker; marker = cinfo->unread_marker;
break; break;
case 3: case 3:
@@ -1259,10 +1259,10 @@ reset_marker_reader (j_decompress_ptr cinfo)
{ {
my_marker_ptr marker = (my_marker_ptr) cinfo->marker; my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
cinfo->comp_info = NULL; /* until allocated by get_sof */ cinfo->comp_info = NULL; /* until allocated by get_sof */
cinfo->input_scan_number = 0; /* no SOS seen yet */ cinfo->input_scan_number = 0; /* no SOS seen yet */
cinfo->unread_marker = 0; /* no pending marker */ cinfo->unread_marker = 0; /* no pending marker */
marker->pub.saw_SOI = FALSE; /* set internal state too */ marker->pub.saw_SOI = FALSE; /* set internal state too */
marker->pub.saw_SOF = FALSE; marker->pub.saw_SOF = FALSE;
marker->pub.discarded_bytes = 0; marker->pub.discarded_bytes = 0;
marker->cur_marker = NULL; marker->cur_marker = NULL;
@@ -1283,7 +1283,7 @@ jinit_marker_reader (j_decompress_ptr cinfo)
/* Create subobject in permanent pool */ /* Create subobject in permanent pool */
marker = (my_marker_ptr) marker = (my_marker_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_marker_reader)); SIZEOF(my_marker_reader));
cinfo->marker = (struct jpeg_marker_reader *) marker; cinfo->marker = (struct jpeg_marker_reader *) marker;
/* Initialize public method pointers */ /* Initialize public method pointers */
marker->pub.reset_marker_reader = reset_marker_reader; marker->pub.reset_marker_reader = reset_marker_reader;
@@ -1314,7 +1314,7 @@ jinit_marker_reader (j_decompress_ptr cinfo)
GLOBAL(void) GLOBAL(void)
jpeg_save_markers (j_decompress_ptr cinfo, int marker_code, jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
unsigned int length_limit) unsigned int length_limit)
{ {
my_marker_ptr marker = (my_marker_ptr) cinfo->marker; my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
long maxlength; long maxlength;
@@ -1363,7 +1363,7 @@ jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
GLOBAL(void) GLOBAL(void)
jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code, jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
jpeg_marker_parser_method routine) jpeg_marker_parser_method routine)
{ {
my_marker_ptr marker = (my_marker_ptr) cinfo->marker; my_marker_ptr marker = (my_marker_ptr) cinfo->marker;

View File

@@ -25,7 +25,7 @@
typedef struct { typedef struct {
struct jpeg_decomp_master pub; /* public fields */ struct jpeg_decomp_master pub; /* public fields */
int pass_number; /* # of passes completed */ int pass_number; /* # of passes completed */
boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */ boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
@@ -80,7 +80,7 @@ use_merged_upsample (j_decompress_ptr cinfo)
cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size) cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size)
return FALSE; return FALSE;
/* ??? also need to test for upsample-time rescaling, when & if supported */ /* ??? also need to test for upsample-time rescaling, when & if supported */
return TRUE; /* by golly, it'll work... */ return TRUE; /* by golly, it'll work... */
#else #else
return FALSE; return FALSE;
#endif #endif
@@ -292,10 +292,10 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
ci++, compptr++) { ci++, compptr++) {
int ssize = cinfo->_min_DCT_scaled_size; int ssize = cinfo->_min_DCT_scaled_size;
while (ssize < DCTSIZE && while (ssize < DCTSIZE &&
((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) % ((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) %
(compptr->h_samp_factor * ssize * 2) == 0) && (compptr->h_samp_factor * ssize * 2) == 0) &&
((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) % ((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) %
(compptr->v_samp_factor * ssize * 2) == 0)) { (compptr->v_samp_factor * ssize * 2) == 0)) {
ssize = ssize * 2; ssize = ssize * 2;
} }
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
@@ -313,12 +313,12 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
/* Size in samples, after IDCT scaling */ /* Size in samples, after IDCT scaling */
compptr->downsampled_width = (JDIMENSION) compptr->downsampled_width = (JDIMENSION)
jdiv_round_up((long) cinfo->image_width * jdiv_round_up((long) cinfo->image_width *
(long) (compptr->h_samp_factor * compptr->_DCT_scaled_size), (long) (compptr->h_samp_factor * compptr->_DCT_scaled_size),
(long) (cinfo->max_h_samp_factor * DCTSIZE)); (long) (cinfo->max_h_samp_factor * DCTSIZE));
compptr->downsampled_height = (JDIMENSION) compptr->downsampled_height = (JDIMENSION)
jdiv_round_up((long) cinfo->image_height * jdiv_round_up((long) cinfo->image_height *
(long) (compptr->v_samp_factor * compptr->_DCT_scaled_size), (long) (compptr->v_samp_factor * compptr->_DCT_scaled_size),
(long) (cinfo->max_v_samp_factor * DCTSIZE)); (long) (cinfo->max_v_samp_factor * DCTSIZE));
} }
#else /* !IDCT_SCALING_SUPPORTED */ #else /* !IDCT_SCALING_SUPPORTED */
@@ -358,12 +358,12 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
case JCS_YCCK: case JCS_YCCK:
cinfo->out_color_components = 4; cinfo->out_color_components = 4;
break; break;
default: /* else must be same colorspace as in file */ default: /* else must be same colorspace as in file */
cinfo->out_color_components = cinfo->num_components; cinfo->out_color_components = cinfo->num_components;
break; break;
} }
cinfo->output_components = (cinfo->quantize_colors ? 1 : cinfo->output_components = (cinfo->quantize_colors ? 1 :
cinfo->out_color_components); cinfo->out_color_components);
/* See if upsampler will want to emit more than one row at a time */ /* See if upsampler will want to emit more than one row at a time */
if (use_merged_upsample(cinfo)) if (use_merged_upsample(cinfo))
@@ -380,20 +380,20 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
* processes are inner loops and need to be as fast as possible. On most * processes are inner loops and need to be as fast as possible. On most
* machines, particularly CPUs with pipelines or instruction prefetch, * machines, particularly CPUs with pipelines or instruction prefetch,
* a (subscript-check-less) C table lookup * a (subscript-check-less) C table lookup
* x = sample_range_limit[x]; * x = sample_range_limit[x];
* is faster than explicit tests * is faster than explicit tests
* if (x < 0) x = 0; * if (x < 0) x = 0;
* else if (x > MAXJSAMPLE) x = MAXJSAMPLE; * else if (x > MAXJSAMPLE) x = MAXJSAMPLE;
* These processes all use a common table prepared by the routine below. * These processes all use a common table prepared by the routine below.
* *
* For most steps we can mathematically guarantee that the initial value * For most steps we can mathematically guarantee that the initial value
* of x is within MAXJSAMPLE+1 of the legal range, so a table running from * of x is within MAXJSAMPLE+1 of the legal range, so a table running from
* -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial
* limiting step (just after the IDCT), a wildly out-of-range value is * limiting step (just after the IDCT), a wildly out-of-range value is
* possible if the input data is corrupt. To avoid any chance of indexing * possible if the input data is corrupt. To avoid any chance of indexing
* off the end of memory and getting a bad-pointer trap, we perform the * off the end of memory and getting a bad-pointer trap, we perform the
* post-IDCT limiting thus: * post-IDCT limiting thus:
* x = range_limit[x & MASK]; * x = range_limit[x & MASK];
* where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
* samples. Under normal circumstances this is more than enough range and * samples. Under normal circumstances this is more than enough range and
* a correct output will be generated; with bogus input data the mask will * a correct output will be generated; with bogus input data the mask will
@@ -425,23 +425,23 @@ prepare_range_limit_table (j_decompress_ptr cinfo)
table = (JSAMPLE *) table = (JSAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE)); (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */ table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
cinfo->sample_range_limit = table; cinfo->sample_range_limit = table;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */ /* First segment of "simple" table: limit[x] = 0 for x < 0 */
MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE)); MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
/* Main part of "simple" table: limit[x] = x */ /* Main part of "simple" table: limit[x] = x */
for (i = 0; i <= MAXJSAMPLE; i++) for (i = 0; i <= MAXJSAMPLE; i++)
table[i] = (JSAMPLE) i; table[i] = (JSAMPLE) i;
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
/* End of simple table, rest of first half of post-IDCT table */ /* End of simple table, rest of first half of post-IDCT table */
for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++) for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
table[i] = MAXJSAMPLE; table[i] = MAXJSAMPLE;
/* Second half of post-IDCT table */ /* Second half of post-IDCT table */
MEMZERO(table + (2 * (MAXJSAMPLE+1)), MEMZERO(table + (2 * (MAXJSAMPLE+1)),
(2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE)); (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE), MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE)); cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
} }
@@ -629,24 +629,24 @@ prepare_for_output_pass (j_decompress_ptr cinfo)
if (cinfo->quantize_colors && cinfo->colormap == NULL) { if (cinfo->quantize_colors && cinfo->colormap == NULL) {
/* Select new quantization method */ /* Select new quantization method */
if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) { if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
cinfo->cquantize = master->quantizer_2pass; cinfo->cquantize = master->quantizer_2pass;
master->pub.is_dummy_pass = TRUE; master->pub.is_dummy_pass = TRUE;
} else if (cinfo->enable_1pass_quant) { } else if (cinfo->enable_1pass_quant) {
cinfo->cquantize = master->quantizer_1pass; cinfo->cquantize = master->quantizer_1pass;
} else { } else {
ERREXIT(cinfo, JERR_MODE_CHANGE); ERREXIT(cinfo, JERR_MODE_CHANGE);
} }
} }
(*cinfo->idct->start_pass) (cinfo); (*cinfo->idct->start_pass) (cinfo);
(*cinfo->coef->start_output_pass) (cinfo); (*cinfo->coef->start_output_pass) (cinfo);
if (! cinfo->raw_data_out) { if (! cinfo->raw_data_out) {
if (! master->using_merged_upsample) if (! master->using_merged_upsample)
(*cinfo->cconvert->start_pass) (cinfo); (*cinfo->cconvert->start_pass) (cinfo);
(*cinfo->upsample->start_pass) (cinfo); (*cinfo->upsample->start_pass) (cinfo);
if (cinfo->quantize_colors) if (cinfo->quantize_colors)
(*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass); (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
(*cinfo->post->start_pass) (cinfo, (*cinfo->post->start_pass) (cinfo,
(master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
(*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
} }
} }
@@ -655,7 +655,7 @@ prepare_for_output_pass (j_decompress_ptr cinfo)
if (cinfo->progress != NULL) { if (cinfo->progress != NULL) {
cinfo->progress->completed_passes = master->pass_number; cinfo->progress->completed_passes = master->pass_number;
cinfo->progress->total_passes = master->pass_number + cinfo->progress->total_passes = master->pass_number +
(master->pub.is_dummy_pass ? 2 : 1); (master->pub.is_dummy_pass ? 2 : 1);
/* In buffered-image mode, we assume one more output pass if EOI not /* In buffered-image mode, we assume one more output pass if EOI not
* yet reached, but no more passes if EOI has been reached. * yet reached, but no more passes if EOI has been reached.
*/ */
@@ -722,7 +722,7 @@ jinit_master_decompress (j_decompress_ptr cinfo)
master = (my_master_ptr) master = (my_master_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_decomp_master)); SIZEOF(my_decomp_master));
cinfo->master = (struct jpeg_decomp_master *) master; cinfo->master = (struct jpeg_decomp_master *) master;
master->pub.prepare_for_output_pass = prepare_for_output_pass; master->pub.prepare_for_output_pass = prepare_for_output_pass;
master->pub.finish_output_pass = finish_output_pass; master->pub.finish_output_pass = finish_output_pass;

View File

@@ -17,19 +17,19 @@
* (ie, box filtering), we can save some work in color conversion by * (ie, box filtering), we can save some work in color conversion by
* calculating all the output pixels corresponding to a pair of chroma * calculating all the output pixels corresponding to a pair of chroma
* samples at one time. In the conversion equations * samples at one time. In the conversion equations
* R = Y + K1 * Cr * R = Y + K1 * Cr
* G = Y + K2 * Cb + K3 * Cr * G = Y + K2 * Cb + K3 * Cr
* B = Y + K4 * Cb * B = Y + K4 * Cb
* only the Y term varies among the group of pixels corresponding to a pair * only the Y term varies among the group of pixels corresponding to a pair
* of chroma samples, so the rest of the terms can be calculated just once. * of chroma samples, so the rest of the terms can be calculated just once.
* At typical sampling ratios, this eliminates half or three-quarters of the * At typical sampling ratios, this eliminates half or three-quarters of the
* multiplications needed for color conversion. * multiplications needed for color conversion.
* *
* This file currently provides implementations for the following cases: * This file currently provides implementations for the following cases:
* YCbCr => RGB color conversion only. * YCbCr => RGB color conversion only.
* Sampling ratios of 2h1v or 2h2v. * Sampling ratios of 2h1v or 2h2v.
* No scaling needed at upsample time. * No scaling needed at upsample time.
* Corner-aligned (non-CCIR601) sampling alignment. * Corner-aligned (non-CCIR601) sampling alignment.
* Other special cases could be added, but in most applications these are * Other special cases could be added, but in most applications these are
* the only common cases. (For uncommon cases we fall back on the more * the only common cases. (For uncommon cases we fall back on the more
* general code in jdsample.c and jdcolor.c.) * general code in jdsample.c and jdcolor.c.)
@@ -47,18 +47,18 @@
/* Private subobject */ /* Private subobject */
typedef struct { typedef struct {
struct jpeg_upsampler pub; /* public fields */ struct jpeg_upsampler pub; /* public fields */
/* Pointer to routine to do actual upsampling/conversion of one row group */ /* Pointer to routine to do actual upsampling/conversion of one row group */
JMETHOD(void, upmethod, (j_decompress_ptr cinfo, JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf)); JSAMPARRAY output_buf));
/* Private state for YCC->RGB conversion */ /* Private state for YCC->RGB conversion */
int * Cr_r_tab; /* => table for Cr to R conversion */ int * Cr_r_tab; /* => table for Cr to R conversion */
int * Cb_b_tab; /* => table for Cb to B conversion */ int * Cb_b_tab; /* => table for Cb to B conversion */
INT32 * Cr_g_tab; /* => table for Cr to G conversion */ INT32 * Cr_g_tab; /* => table for Cr to G conversion */
INT32 * Cb_g_tab; /* => table for Cb to G conversion */ INT32 * Cb_g_tab; /* => table for Cb to G conversion */
/* For 2:1 vertical sampling, we produce two output rows at a time. /* For 2:1 vertical sampling, we produce two output rows at a time.
* We need a "spare" row buffer to hold the second output row if the * We need a "spare" row buffer to hold the second output row if the
@@ -66,17 +66,17 @@ typedef struct {
* to discard the dummy last row if the image height is odd. * to discard the dummy last row if the image height is odd.
*/ */
JSAMPROW spare_row; JSAMPROW spare_row;
boolean spare_full; /* T if spare buffer is occupied */ boolean spare_full; /* T if spare buffer is occupied */
JDIMENSION out_row_width; /* samples per output row */ JDIMENSION out_row_width; /* samples per output row */
JDIMENSION rows_to_go; /* counts rows remaining in image */ JDIMENSION rows_to_go; /* counts rows remaining in image */
} my_upsampler; } my_upsampler;
typedef my_upsampler * my_upsample_ptr; typedef my_upsampler * my_upsample_ptr;
#define SCALEBITS 16 /* speediest right-shift on some machines */ #define SCALEBITS 16 /* speediest right-shift on some machines */
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
/* Include inline routines for colorspace extensions */ /* Include inline routines for colorspace extensions */
@@ -195,26 +195,26 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
upsample->Cr_r_tab = (int *) upsample->Cr_r_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(int)); (MAXJSAMPLE+1) * SIZEOF(int));
upsample->Cb_b_tab = (int *) upsample->Cb_b_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(int)); (MAXJSAMPLE+1) * SIZEOF(int));
upsample->Cr_g_tab = (INT32 *) upsample->Cr_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * SIZEOF(INT32));
upsample->Cb_g_tab = (INT32 *) upsample->Cb_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * SIZEOF(INT32));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 1.40200 * x */ /* Cr=>R value is nearest int to 1.40200 * x */
upsample->Cr_r_tab[i] = (int) upsample->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 1.77200 * x */ /* Cb=>B value is nearest int to 1.77200 * x */
upsample->Cb_b_tab[i] = (int) upsample->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -0.71414 * x */ /* Cr=>G value is scaled-up -0.71414 * x */
upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x; upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
/* Cb=>G value is scaled-up -0.34414 * x */ /* Cb=>G value is scaled-up -0.34414 * x */
@@ -248,20 +248,20 @@ start_pass_merged_upsample (j_decompress_ptr cinfo)
METHODDEF(void) METHODDEF(void)
merged_2v_upsample (j_decompress_ptr cinfo, merged_2v_upsample (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail) JDIMENSION out_rows_avail)
/* 2:1 vertical sampling case: may need a spare row. */ /* 2:1 vertical sampling case: may need a spare row. */
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
JSAMPROW work_ptrs[2]; JSAMPROW work_ptrs[2];
JDIMENSION num_rows; /* number of rows returned to caller */ JDIMENSION num_rows; /* number of rows returned to caller */
if (upsample->spare_full) { if (upsample->spare_full) {
/* If we have a spare row saved from a previous cycle, just return it. */ /* If we have a spare row saved from a previous cycle, just return it. */
jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0, jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
1, upsample->out_row_width); 1, upsample->out_row_width);
num_rows = 1; num_rows = 1;
upsample->spare_full = FALSE; upsample->spare_full = FALSE;
} else { } else {
@@ -297,17 +297,17 @@ merged_2v_upsample (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
merged_1v_upsample (j_decompress_ptr cinfo, merged_1v_upsample (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail) JDIMENSION out_rows_avail)
/* 1:1 vertical sampling case: much easier, never need a spare row. */ /* 1:1 vertical sampling case: much easier, never need a spare row. */
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
/* Just do the upsampling. */ /* Just do the upsampling. */
(*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
output_buf + *out_row_ctr); output_buf + *out_row_ctr);
/* Adjust counts */ /* Adjust counts */
(*out_row_ctr)++; (*out_row_ctr)++;
(*in_row_group_ctr)++; (*in_row_group_ctr)++;
@@ -330,8 +330,8 @@ merged_1v_upsample (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
h2v1_merged_upsample (j_decompress_ptr cinfo, h2v1_merged_upsample (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@@ -376,8 +376,8 @@ h2v1_merged_upsample (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
h2v2_merged_upsample (j_decompress_ptr cinfo, h2v2_merged_upsample (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
JSAMPARRAY output_buf) JSAMPARRAY output_buf)
{ {
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_EXT_RGB: case JCS_EXT_RGB:
@@ -431,7 +431,7 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
upsample = (my_upsample_ptr) upsample = (my_upsample_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_upsampler)); SIZEOF(my_upsampler));
cinfo->upsample = (struct jpeg_upsampler *) upsample; cinfo->upsample = (struct jpeg_upsampler *) upsample;
upsample->pub.start_pass = start_pass_merged_upsample; upsample->pub.start_pass = start_pass_merged_upsample;
upsample->pub.need_context_rows = FALSE; upsample->pub.need_context_rows = FALSE;
@@ -447,7 +447,7 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
/* Allocate a spare row buffer */ /* Allocate a spare row buffer */
upsample->spare_row = (JSAMPROW) upsample->spare_row = (JSAMPROW)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(size_t) (upsample->out_row_width * SIZEOF(JSAMPLE))); (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
} else { } else {
upsample->pub.upsample = merged_1v_upsample; upsample->pub.upsample = merged_1v_upsample;
if (jsimd_can_h2v1_merged_upsample()) if (jsimd_can_h2v1_merged_upsample())

266
jdphuff.c
View File

@@ -17,7 +17,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdhuff.h" /* Declarations shared with jdhuff.c */ #include "jdhuff.h" /* Declarations shared with jdhuff.c */
#ifdef D_PROGRESSIVE_SUPPORTED #ifdef D_PROGRESSIVE_SUPPORTED
@@ -30,8 +30,8 @@
*/ */
typedef struct { typedef struct {
unsigned int EOBRUN; /* remaining EOBs in EOBRUN */ unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
} savable_state; } savable_state;
/* This macro is to work around compilers with missing or broken /* This macro is to work around compilers with missing or broken
@@ -44,11 +44,11 @@ typedef struct {
#else #else
#if MAX_COMPS_IN_SCAN == 4 #if MAX_COMPS_IN_SCAN == 4
#define ASSIGN_STATE(dest,src) \ #define ASSIGN_STATE(dest,src) \
((dest).EOBRUN = (src).EOBRUN, \ ((dest).EOBRUN = (src).EOBRUN, \
(dest).last_dc_val[0] = (src).last_dc_val[0], \ (dest).last_dc_val[0] = (src).last_dc_val[0], \
(dest).last_dc_val[1] = (src).last_dc_val[1], \ (dest).last_dc_val[1] = (src).last_dc_val[1], \
(dest).last_dc_val[2] = (src).last_dc_val[2], \ (dest).last_dc_val[2] = (src).last_dc_val[2], \
(dest).last_dc_val[3] = (src).last_dc_val[3]) (dest).last_dc_val[3] = (src).last_dc_val[3])
#endif #endif
#endif #endif
@@ -59,11 +59,11 @@ typedef struct {
/* These fields are loaded into local variables at start of each MCU. /* These fields are loaded into local variables at start of each MCU.
* In case of suspension, we exit WITHOUT updating them. * In case of suspension, we exit WITHOUT updating them.
*/ */
bitread_perm_state bitstate; /* Bit buffer at start of MCU */ bitread_perm_state bitstate; /* Bit buffer at start of MCU */
savable_state saved; /* Other state at start of MCU */ savable_state saved; /* Other state at start of MCU */
/* These fields are NOT loaded into local working state. */ /* These fields are NOT loaded into local working state. */
unsigned int restarts_to_go; /* MCUs left in this restart interval */ unsigned int restarts_to_go; /* MCUs left in this restart interval */
/* Pointers to derived tables (these workspaces have image lifespan) */ /* Pointers to derived tables (these workspaces have image lifespan) */
d_derived_tbl * derived_tbls[NUM_HUFF_TBLS]; d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
@@ -75,13 +75,13 @@ typedef phuff_entropy_decoder * phuff_entropy_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo, METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo, METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo, METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo, METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
/* /*
@@ -117,7 +117,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
if (cinfo->Al != cinfo->Ah-1) if (cinfo->Al != cinfo->Ah-1)
bad = TRUE; bad = TRUE;
} }
if (cinfo->Al > 13) /* need not check for < 0 */ if (cinfo->Al > 13) /* need not check for < 0 */
bad = TRUE; bad = TRUE;
/* Arguably the maximum Al value should be less than 13 for 8-bit precision, /* Arguably the maximum Al value should be less than 13 for 8-bit precision,
* but the spec doesn't say so, and we try to be liberal about what we * but the spec doesn't say so, and we try to be liberal about what we
@@ -127,7 +127,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
*/ */
if (bad) if (bad)
ERREXIT4(cinfo, JERR_BAD_PROGRESSION, ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
/* Update progression status, and verify that scan order is legal. /* Update progression status, and verify that scan order is legal.
* Note that inter-scan inconsistencies are treated as warnings * Note that inter-scan inconsistencies are treated as warnings
* not fatal errors ... not clear if this is right way to behave. * not fatal errors ... not clear if this is right way to behave.
@@ -140,7 +140,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
if (cinfo->Ah != expected) if (cinfo->Ah != expected)
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
coef_bit_ptr[coefi] = cinfo->Al; coef_bit_ptr[coefi] = cinfo->Al;
} }
} }
@@ -164,15 +164,15 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
* We may build same derived table more than once, but it's not expensive. * We may build same derived table more than once, but it's not expensive.
*/ */
if (is_DC_band) { if (is_DC_band) {
if (cinfo->Ah == 0) { /* DC refinement needs no table */ if (cinfo->Ah == 0) { /* DC refinement needs no table */
tbl = compptr->dc_tbl_no; tbl = compptr->dc_tbl_no;
jpeg_make_d_derived_tbl(cinfo, TRUE, tbl, jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
& entropy->derived_tbls[tbl]); & entropy->derived_tbls[tbl]);
} }
} else { } else {
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
jpeg_make_d_derived_tbl(cinfo, FALSE, tbl, jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
& entropy->derived_tbls[tbl]); & entropy->derived_tbls[tbl]);
/* remember the single active table */ /* remember the single active table */
entropy->ac_derived_tbl = entropy->derived_tbls[tbl]; entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
} }
@@ -264,7 +264,7 @@ process_restart (j_decompress_ptr cinfo)
/* /*
* Huffman MCU decoding. * Huffman MCU decoding.
* Each of these routines decodes and returns one MCU's worth of * Each of these routines decodes and returns one MCU's worth of
* Huffman-compressed coefficients. * Huffman-compressed coefficients.
* The coefficients are reordered from zigzag order into natural array order, * The coefficients are reordered from zigzag order into natural array order,
* but are not dequantized. * but are not dequantized.
* *
@@ -285,7 +285,7 @@ process_restart (j_decompress_ptr cinfo)
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
int Al = cinfo->Al; int Al = cinfo->Al;
register int s, r; register int s, r;
@@ -300,7 +300,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! process_restart(cinfo)) if (! process_restart(cinfo))
return FALSE; return FALSE;
} }
/* If we've run out of data, just leave the MCU set to zeroes. /* If we've run out of data, just leave the MCU set to zeroes.
@@ -325,9 +325,9 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Section F.2.2.1: decode the DC coefficient difference */ /* Section F.2.2.1: decode the DC coefficient difference */
HUFF_DECODE(s, br_state, tbl, return FALSE, label1); HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
if (s) { if (s) {
CHECK_BIT_BUFFER(br_state, s, return FALSE); CHECK_BIT_BUFFER(br_state, s, return FALSE);
r = GET_BITS(s); r = GET_BITS(s);
s = HUFF_EXTEND(r, s); s = HUFF_EXTEND(r, s);
} }
/* Convert DC difference to actual value, update last_dc_val */ /* Convert DC difference to actual value, update last_dc_val */
@@ -356,7 +356,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
int Se = cinfo->Se; int Se = cinfo->Se;
int Al = cinfo->Al; int Al = cinfo->Al;
@@ -370,7 +370,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! process_restart(cinfo)) if (! process_restart(cinfo))
return FALSE; return FALSE;
} }
/* If we've run out of data, just leave the MCU set to zeroes. /* If we've run out of data, just leave the MCU set to zeroes.
@@ -381,49 +381,49 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Load up working state. /* Load up working state.
* We can avoid loading/saving bitread state if in an EOB run. * We can avoid loading/saving bitread state if in an EOB run.
*/ */
EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */ EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
/* There is always only one block per MCU */ /* There is always only one block per MCU */
if (EOBRUN > 0) /* if it's a band of zeroes... */ if (EOBRUN > 0) /* if it's a band of zeroes... */
EOBRUN--; /* ...process it now (we do nothing) */ EOBRUN--; /* ...process it now (we do nothing) */
else { else {
BITREAD_LOAD_STATE(cinfo,entropy->bitstate); BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
block = MCU_data[0]; block = MCU_data[0];
tbl = entropy->ac_derived_tbl; tbl = entropy->ac_derived_tbl;
for (k = cinfo->Ss; k <= Se; k++) { for (k = cinfo->Ss; k <= Se; k++) {
HUFF_DECODE(s, br_state, tbl, return FALSE, label2); HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
r = s >> 4; r = s >> 4;
s &= 15; s &= 15;
if (s) { if (s) {
k += r; k += r;
CHECK_BIT_BUFFER(br_state, s, return FALSE); CHECK_BIT_BUFFER(br_state, s, return FALSE);
r = GET_BITS(s); r = GET_BITS(s);
s = HUFF_EXTEND(r, s); s = HUFF_EXTEND(r, s);
/* Scale and output coefficient in natural (dezigzagged) order */ /* Scale and output coefficient in natural (dezigzagged) order */
(*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al); (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
} else { } else {
if (r == 15) { /* ZRL */ if (r == 15) { /* ZRL */
k += 15; /* skip 15 zeroes in band */ k += 15; /* skip 15 zeroes in band */
} else { /* EOBr, run length is 2^r + appended bits */ } else { /* EOBr, run length is 2^r + appended bits */
EOBRUN = 1 << r; EOBRUN = 1 << r;
if (r) { /* EOBr, r > 0 */ if (r) { /* EOBr, r > 0 */
CHECK_BIT_BUFFER(br_state, r, return FALSE); CHECK_BIT_BUFFER(br_state, r, return FALSE);
r = GET_BITS(r); r = GET_BITS(r);
EOBRUN += r; EOBRUN += r;
} }
EOBRUN--; /* this band is processed at this moment */ EOBRUN--; /* this band is processed at this moment */
break; /* force end-of-band */ break; /* force end-of-band */
} }
} }
} }
BITREAD_SAVE_STATE(cinfo,entropy->bitstate); BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
} }
/* Completed MCU, so update state */ /* Completed MCU, so update state */
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */ entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
} }
/* Account for restart interval (no-op if not using restarts) */ /* Account for restart interval (no-op if not using restarts) */
@@ -441,9 +441,9 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
int blkn; int blkn;
JBLOCKROW block; JBLOCKROW block;
BITREAD_STATE_VARS; BITREAD_STATE_VARS;
@@ -452,7 +452,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! process_restart(cinfo)) if (! process_restart(cinfo))
return FALSE; return FALSE;
} }
/* Not worth the cycles to check insufficient_data here, /* Not worth the cycles to check insufficient_data here,
@@ -490,11 +490,11 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
int Se = cinfo->Se; int Se = cinfo->Se;
int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */ int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
register int s, k, r; register int s, k, r;
unsigned int EOBRUN; unsigned int EOBRUN;
JBLOCKROW block; JBLOCKROW block;
@@ -508,7 +508,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
if (! process_restart(cinfo)) if (! process_restart(cinfo))
return FALSE; return FALSE;
} }
/* If we've run out of data, don't modify the MCU. /* If we've run out of data, don't modify the MCU.
@@ -536,58 +536,58 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (EOBRUN == 0) { if (EOBRUN == 0) {
for (; k <= Se; k++) { for (; k <= Se; k++) {
HUFF_DECODE(s, br_state, tbl, goto undoit, label3); HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
r = s >> 4; r = s >> 4;
s &= 15; s &= 15;
if (s) { if (s) {
if (s != 1) /* size of new coef should always be 1 */ if (s != 1) /* size of new coef should always be 1 */
WARNMS(cinfo, JWRN_HUFF_BAD_CODE); WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
CHECK_BIT_BUFFER(br_state, 1, goto undoit); CHECK_BIT_BUFFER(br_state, 1, goto undoit);
if (GET_BITS(1)) if (GET_BITS(1))
s = p1; /* newly nonzero coef is positive */ s = p1; /* newly nonzero coef is positive */
else else
s = m1; /* newly nonzero coef is negative */ s = m1; /* newly nonzero coef is negative */
} else { } else {
if (r != 15) { if (r != 15) {
EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */ EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
if (r) { if (r) {
CHECK_BIT_BUFFER(br_state, r, goto undoit); CHECK_BIT_BUFFER(br_state, r, goto undoit);
r = GET_BITS(r); r = GET_BITS(r);
EOBRUN += r; EOBRUN += r;
} }
break; /* rest of block is handled by EOB logic */ break; /* rest of block is handled by EOB logic */
} }
/* note s = 0 for processing ZRL */ /* note s = 0 for processing ZRL */
} }
/* Advance over already-nonzero coefs and r still-zero coefs, /* Advance over already-nonzero coefs and r still-zero coefs,
* appending correction bits to the nonzeroes. A correction bit is 1 * appending correction bits to the nonzeroes. A correction bit is 1
* if the absolute value of the coefficient must be increased. * if the absolute value of the coefficient must be increased.
*/ */
do { do {
thiscoef = *block + jpeg_natural_order[k]; thiscoef = *block + jpeg_natural_order[k];
if (*thiscoef != 0) { if (*thiscoef != 0) {
CHECK_BIT_BUFFER(br_state, 1, goto undoit); CHECK_BIT_BUFFER(br_state, 1, goto undoit);
if (GET_BITS(1)) { if (GET_BITS(1)) {
if ((*thiscoef & p1) == 0) { /* do nothing if already set it */ if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
if (*thiscoef >= 0) if (*thiscoef >= 0)
*thiscoef += p1; *thiscoef += p1;
else else
*thiscoef += m1; *thiscoef += m1;
} }
} }
} else { } else {
if (--r < 0) if (--r < 0)
break; /* reached target zero coefficient */ break; /* reached target zero coefficient */
} }
k++; k++;
} while (k <= Se); } while (k <= Se);
if (s) { if (s) {
int pos = jpeg_natural_order[k]; int pos = jpeg_natural_order[k];
/* Output newly nonzero coefficient */ /* Output newly nonzero coefficient */
(*block)[pos] = (JCOEF) s; (*block)[pos] = (JCOEF) s;
/* Remember its position in case we have to suspend */ /* Remember its position in case we have to suspend */
newnz_pos[num_newnz++] = pos; newnz_pos[num_newnz++] = pos;
} }
} }
} }
@@ -598,18 +598,18 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
* if the absolute value of the coefficient must be increased. * if the absolute value of the coefficient must be increased.
*/ */
for (; k <= Se; k++) { for (; k <= Se; k++) {
thiscoef = *block + jpeg_natural_order[k]; thiscoef = *block + jpeg_natural_order[k];
if (*thiscoef != 0) { if (*thiscoef != 0) {
CHECK_BIT_BUFFER(br_state, 1, goto undoit); CHECK_BIT_BUFFER(br_state, 1, goto undoit);
if (GET_BITS(1)) { if (GET_BITS(1)) {
if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */ if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
if (*thiscoef >= 0) if (*thiscoef >= 0)
*thiscoef += p1; *thiscoef += p1;
else else
*thiscoef += m1; *thiscoef += m1;
} }
} }
} }
} }
/* Count one block completed in EOB run */ /* Count one block completed in EOB run */
EOBRUN--; EOBRUN--;
@@ -647,7 +647,7 @@ jinit_phuff_decoder (j_decompress_ptr cinfo)
entropy = (phuff_entropy_ptr) entropy = (phuff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(phuff_entropy_decoder)); SIZEOF(phuff_entropy_decoder));
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
entropy->pub.start_pass = start_pass_phuff_decoder; entropy->pub.start_pass = start_pass_phuff_decoder;
@@ -659,9 +659,9 @@ jinit_phuff_decoder (j_decompress_ptr cinfo)
/* Create progression status table */ /* Create progression status table */
cinfo->coef_bits = (int (*)[DCTSIZE2]) cinfo->coef_bits = (int (*)[DCTSIZE2])
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->num_components*DCTSIZE2*SIZEOF(int)); cinfo->num_components*DCTSIZE2*SIZEOF(int));
coef_bit_ptr = & cinfo->coef_bits[0][0]; coef_bit_ptr = & cinfo->coef_bits[0][0];
for (ci = 0; ci < cinfo->num_components; ci++) for (ci = 0; ci < cinfo->num_components; ci++)
for (i = 0; i < DCTSIZE2; i++) for (i = 0; i < DCTSIZE2; i++)
*coef_bit_ptr++ = -1; *coef_bit_ptr++ = -1;
} }

View File

@@ -31,12 +31,12 @@ typedef struct {
* For two-pass color quantization, we need a full-image buffer; * For two-pass color quantization, we need a full-image buffer;
* for one-pass operation, a strip buffer is sufficient. * for one-pass operation, a strip buffer is sufficient.
*/ */
jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */ jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */ JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
JDIMENSION strip_height; /* buffer size in rows */ JDIMENSION strip_height; /* buffer size in rows */
/* for two-pass mode only: */ /* for two-pass mode only: */
JDIMENSION starting_row; /* row # of first row in current strip */ JDIMENSION starting_row; /* row # of first row in current strip */
JDIMENSION next_row; /* index of next row to fill/empty in strip */ JDIMENSION next_row; /* index of next row to fill/empty in strip */
} my_post_controller; } my_post_controller;
typedef my_post_controller * my_post_ptr; typedef my_post_controller * my_post_ptr;
@@ -44,24 +44,24 @@ typedef my_post_controller * my_post_ptr;
/* Forward declarations */ /* Forward declarations */
METHODDEF(void) post_process_1pass METHODDEF(void) post_process_1pass
JPP((j_decompress_ptr cinfo, JPP((j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail)); JDIMENSION out_rows_avail));
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
METHODDEF(void) post_process_prepass METHODDEF(void) post_process_prepass
JPP((j_decompress_ptr cinfo, JPP((j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail)); JDIMENSION out_rows_avail));
METHODDEF(void) post_process_2pass METHODDEF(void) post_process_2pass
JPP((j_decompress_ptr cinfo, JPP((j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail)); JDIMENSION out_rows_avail));
#endif #endif
@@ -84,9 +84,9 @@ start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
* allocate a strip buffer. Use the virtual-array buffer as workspace. * allocate a strip buffer. Use the virtual-array buffer as workspace.
*/ */
if (post->buffer == NULL) { if (post->buffer == NULL) {
post->buffer = (*cinfo->mem->access_virt_sarray) post->buffer = (*cinfo->mem->access_virt_sarray)
((j_common_ptr) cinfo, post->whole_image, ((j_common_ptr) cinfo, post->whole_image,
(JDIMENSION) 0, post->strip_height, TRUE); (JDIMENSION) 0, post->strip_height, TRUE);
} }
} else { } else {
/* For single-pass processing without color quantization, /* For single-pass processing without color quantization,
@@ -124,10 +124,10 @@ start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
METHODDEF(void) METHODDEF(void)
post_process_1pass (j_decompress_ptr cinfo, post_process_1pass (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail) JDIMENSION out_rows_avail)
{ {
my_post_ptr post = (my_post_ptr) cinfo->post; my_post_ptr post = (my_post_ptr) cinfo->post;
JDIMENSION num_rows, max_rows; JDIMENSION num_rows, max_rows;
@@ -139,11 +139,11 @@ post_process_1pass (j_decompress_ptr cinfo,
max_rows = post->strip_height; max_rows = post->strip_height;
num_rows = 0; num_rows = 0;
(*cinfo->upsample->upsample) (cinfo, (*cinfo->upsample->upsample) (cinfo,
input_buf, in_row_group_ctr, in_row_groups_avail, input_buf, in_row_group_ctr, in_row_groups_avail,
post->buffer, &num_rows, max_rows); post->buffer, &num_rows, max_rows);
/* Quantize and emit data. */ /* Quantize and emit data. */
(*cinfo->cquantize->color_quantize) (cinfo, (*cinfo->cquantize->color_quantize) (cinfo,
post->buffer, output_buf + *out_row_ctr, (int) num_rows); post->buffer, output_buf + *out_row_ctr, (int) num_rows);
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
} }
@@ -156,10 +156,10 @@ post_process_1pass (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
post_process_prepass (j_decompress_ptr cinfo, post_process_prepass (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail) JDIMENSION out_rows_avail)
{ {
my_post_ptr post = (my_post_ptr) cinfo->post; my_post_ptr post = (my_post_ptr) cinfo->post;
JDIMENSION old_next_row, num_rows; JDIMENSION old_next_row, num_rows;
@@ -167,22 +167,22 @@ post_process_prepass (j_decompress_ptr cinfo,
/* Reposition virtual buffer if at start of strip. */ /* Reposition virtual buffer if at start of strip. */
if (post->next_row == 0) { if (post->next_row == 0) {
post->buffer = (*cinfo->mem->access_virt_sarray) post->buffer = (*cinfo->mem->access_virt_sarray)
((j_common_ptr) cinfo, post->whole_image, ((j_common_ptr) cinfo, post->whole_image,
post->starting_row, post->strip_height, TRUE); post->starting_row, post->strip_height, TRUE);
} }
/* Upsample some data (up to a strip height's worth). */ /* Upsample some data (up to a strip height's worth). */
old_next_row = post->next_row; old_next_row = post->next_row;
(*cinfo->upsample->upsample) (cinfo, (*cinfo->upsample->upsample) (cinfo,
input_buf, in_row_group_ctr, in_row_groups_avail, input_buf, in_row_group_ctr, in_row_groups_avail,
post->buffer, &post->next_row, post->strip_height); post->buffer, &post->next_row, post->strip_height);
/* Allow quantizer to scan new data. No data is emitted, */ /* Allow quantizer to scan new data. No data is emitted, */
/* but we advance out_row_ctr so outer loop can tell when we're done. */ /* but we advance out_row_ctr so outer loop can tell when we're done. */
if (post->next_row > old_next_row) { if (post->next_row > old_next_row) {
num_rows = post->next_row - old_next_row; num_rows = post->next_row - old_next_row;
(*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row, (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
(JSAMPARRAY) NULL, (int) num_rows); (JSAMPARRAY) NULL, (int) num_rows);
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
} }
@@ -200,10 +200,10 @@ post_process_prepass (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
post_process_2pass (j_decompress_ptr cinfo, post_process_2pass (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail) JDIMENSION out_rows_avail)
{ {
my_post_ptr post = (my_post_ptr) cinfo->post; my_post_ptr post = (my_post_ptr) cinfo->post;
JDIMENSION num_rows, max_rows; JDIMENSION num_rows, max_rows;
@@ -211,8 +211,8 @@ post_process_2pass (j_decompress_ptr cinfo,
/* Reposition virtual buffer if at start of strip. */ /* Reposition virtual buffer if at start of strip. */
if (post->next_row == 0) { if (post->next_row == 0) {
post->buffer = (*cinfo->mem->access_virt_sarray) post->buffer = (*cinfo->mem->access_virt_sarray)
((j_common_ptr) cinfo, post->whole_image, ((j_common_ptr) cinfo, post->whole_image,
post->starting_row, post->strip_height, FALSE); post->starting_row, post->strip_height, FALSE);
} }
/* Determine number of rows to emit. */ /* Determine number of rows to emit. */
@@ -227,8 +227,8 @@ post_process_2pass (j_decompress_ptr cinfo,
/* Quantize and emit data. */ /* Quantize and emit data. */
(*cinfo->cquantize->color_quantize) (cinfo, (*cinfo->cquantize->color_quantize) (cinfo,
post->buffer + post->next_row, output_buf + *out_row_ctr, post->buffer + post->next_row, output_buf + *out_row_ctr,
(int) num_rows); (int) num_rows);
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
/* Advance if we filled the strip. */ /* Advance if we filled the strip. */
@@ -253,11 +253,11 @@ jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
post = (my_post_ptr) post = (my_post_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_post_controller)); SIZEOF(my_post_controller));
cinfo->post = (struct jpeg_d_post_controller *) post; cinfo->post = (struct jpeg_d_post_controller *) post;
post->pub.start_pass = start_pass_dpost; post->pub.start_pass = start_pass_dpost;
post->whole_image = NULL; /* flag for no virtual arrays */ post->whole_image = NULL; /* flag for no virtual arrays */
post->buffer = NULL; /* flag for no strip buffer */ post->buffer = NULL; /* flag for no strip buffer */
/* Create the quantization buffer, if needed */ /* Create the quantization buffer, if needed */
if (cinfo->quantize_colors) { if (cinfo->quantize_colors) {
@@ -271,20 +271,20 @@ jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
/* We round up the number of rows to a multiple of the strip height. */ /* We round up the number of rows to a multiple of the strip height. */
#ifdef QUANT_2PASS_SUPPORTED #ifdef QUANT_2PASS_SUPPORTED
post->whole_image = (*cinfo->mem->request_virt_sarray) post->whole_image = (*cinfo->mem->request_virt_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
cinfo->output_width * cinfo->out_color_components, cinfo->output_width * cinfo->out_color_components,
(JDIMENSION) jround_up((long) cinfo->output_height, (JDIMENSION) jround_up((long) cinfo->output_height,
(long) post->strip_height), (long) post->strip_height),
post->strip_height); post->strip_height);
#else #else
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
#endif /* QUANT_2PASS_SUPPORTED */ #endif /* QUANT_2PASS_SUPPORTED */
} else { } else {
/* One-pass color quantization: just make a strip buffer. */ /* One-pass color quantization: just make a strip buffer. */
post->buffer = (*cinfo->mem->alloc_sarray) post->buffer = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->output_width * cinfo->out_color_components, cinfo->output_width * cinfo->out_color_components,
post->strip_height); post->strip_height);
} }
} }
} }

View File

@@ -30,13 +30,13 @@
/* Pointer to routine to upsample a single component */ /* Pointer to routine to upsample a single component */
typedef JMETHOD(void, upsample1_ptr, typedef JMETHOD(void, upsample1_ptr,
(j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
/* Private subobject */ /* Private subobject */
typedef struct { typedef struct {
struct jpeg_upsampler pub; /* public fields */ struct jpeg_upsampler pub; /* public fields */
/* Color conversion buffer. When using separate upsampling and color /* Color conversion buffer. When using separate upsampling and color
* conversion steps, this buffer holds one upsampled row group until it * conversion steps, this buffer holds one upsampled row group until it
@@ -50,8 +50,8 @@ typedef struct {
/* Per-component upsampling method pointers */ /* Per-component upsampling method pointers */
upsample1_ptr methods[MAX_COMPONENTS]; upsample1_ptr methods[MAX_COMPONENTS];
int next_row_out; /* counts rows emitted from color_buf */ int next_row_out; /* counts rows emitted from color_buf */
JDIMENSION rows_to_go; /* counts rows remaining in image */ JDIMENSION rows_to_go; /* counts rows remaining in image */
/* Height of an input row group for each component. */ /* Height of an input row group for each component. */
int rowgroup_height[MAX_COMPONENTS]; int rowgroup_height[MAX_COMPONENTS];
@@ -92,10 +92,10 @@ start_pass_upsample (j_decompress_ptr cinfo)
METHODDEF(void) METHODDEF(void)
sep_upsample (j_decompress_ptr cinfo, sep_upsample (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail) JDIMENSION out_rows_avail)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
int ci; int ci;
@@ -105,13 +105,13 @@ sep_upsample (j_decompress_ptr cinfo,
/* Fill the conversion buffer, if it's empty */ /* Fill the conversion buffer, if it's empty */
if (upsample->next_row_out >= cinfo->max_v_samp_factor) { if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
/* Invoke per-component upsample method. Notice we pass a POINTER /* Invoke per-component upsample method. Notice we pass a POINTER
* to color_buf[ci], so that fullsize_upsample can change it. * to color_buf[ci], so that fullsize_upsample can change it.
*/ */
(*upsample->methods[ci]) (cinfo, compptr, (*upsample->methods[ci]) (cinfo, compptr,
input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
upsample->color_buf + ci); upsample->color_buf + ci);
} }
upsample->next_row_out = 0; upsample->next_row_out = 0;
} }
@@ -123,7 +123,7 @@ sep_upsample (j_decompress_ptr cinfo,
/* Not more than the distance to the end of the image. Need this test /* Not more than the distance to the end of the image. Need this test
* in case the image height is not a multiple of max_v_samp_factor: * in case the image height is not a multiple of max_v_samp_factor:
*/ */
if (num_rows > upsample->rows_to_go) if (num_rows > upsample->rows_to_go)
num_rows = upsample->rows_to_go; num_rows = upsample->rows_to_go;
/* And not more than what the client can accept: */ /* And not more than what the client can accept: */
out_rows_avail -= *out_row_ctr; out_rows_avail -= *out_row_ctr;
@@ -131,9 +131,9 @@ sep_upsample (j_decompress_ptr cinfo,
num_rows = out_rows_avail; num_rows = out_rows_avail;
(*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf, (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
(JDIMENSION) upsample->next_row_out, (JDIMENSION) upsample->next_row_out,
output_buf + *out_row_ctr, output_buf + *out_row_ctr,
(int) num_rows); (int) num_rows);
/* Adjust counts */ /* Adjust counts */
*out_row_ctr += num_rows; *out_row_ctr += num_rows;
@@ -160,7 +160,7 @@ sep_upsample (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
{ {
*output_data_ptr = input_data; *output_data_ptr = input_data;
} }
@@ -173,9 +173,9 @@ fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
{ {
*output_data_ptr = NULL; /* safety check */ *output_data_ptr = NULL; /* safety check */
} }
@@ -192,7 +192,7 @@ noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
{ {
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
@@ -213,15 +213,15 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
outptr = output_data[outrow]; outptr = output_data[outrow];
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; /* don't need GETJSAMPLE() here */ invalue = *inptr++; /* don't need GETJSAMPLE() here */
for (h = h_expand; h > 0; h--) { for (h = h_expand; h > 0; h--) {
*outptr++ = invalue; *outptr++ = invalue;
} }
} }
/* Generate any additional output rows by duplicating the first one */ /* Generate any additional output rows by duplicating the first one */
if (v_expand > 1) { if (v_expand > 1) {
jcopy_sample_rows(output_data, outrow, output_data, outrow+1, jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
v_expand-1, cinfo->output_width); v_expand-1, cinfo->output_width);
} }
inrow++; inrow++;
outrow += v_expand; outrow += v_expand;
@@ -236,7 +236,7 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
@@ -249,7 +249,7 @@ h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
outptr = output_data[inrow]; outptr = output_data[inrow];
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; /* don't need GETJSAMPLE() here */ invalue = *inptr++; /* don't need GETJSAMPLE() here */
*outptr++ = invalue; *outptr++ = invalue;
*outptr++ = invalue; *outptr++ = invalue;
} }
@@ -264,7 +264,7 @@ h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
@@ -278,12 +278,12 @@ h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
outptr = output_data[outrow]; outptr = output_data[outrow];
outend = outptr + cinfo->output_width; outend = outptr + cinfo->output_width;
while (outptr < outend) { while (outptr < outend) {
invalue = *inptr++; /* don't need GETJSAMPLE() here */ invalue = *inptr++; /* don't need GETJSAMPLE() here */
*outptr++ = invalue; *outptr++ = invalue;
*outptr++ = invalue; *outptr++ = invalue;
} }
jcopy_sample_rows(output_data, outrow, output_data, outrow+1, jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
1, cinfo->output_width); 1, cinfo->output_width);
inrow++; inrow++;
outrow += 2; outrow += 2;
} }
@@ -307,7 +307,7 @@ h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr, outptr; register JSAMPROW inptr, outptr;
@@ -348,7 +348,7 @@ h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
METHODDEF(void) METHODDEF(void)
h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
{ {
JSAMPARRAY output_data = *output_data_ptr; JSAMPARRAY output_data = *output_data_ptr;
register JSAMPROW inptr0, inptr1, outptr; register JSAMPROW inptr0, inptr1, outptr;
@@ -365,10 +365,10 @@ h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
for (v = 0; v < 2; v++) { for (v = 0; v < 2; v++) {
/* inptr0 points to nearest input row, inptr1 points to next nearest */ /* inptr0 points to nearest input row, inptr1 points to next nearest */
inptr0 = input_data[inrow]; inptr0 = input_data[inrow];
if (v == 0) /* next nearest is row above */ if (v == 0) /* next nearest is row above */
inptr1 = input_data[inrow-1]; inptr1 = input_data[inrow-1];
else /* next nearest is row below */ else /* next nearest is row below */
inptr1 = input_data[inrow+1]; inptr1 = input_data[inrow+1];
outptr = output_data[outrow++]; outptr = output_data[outrow++];
/* Special case for first column */ /* Special case for first column */
@@ -379,12 +379,12 @@ h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
lastcolsum = thiscolsum; thiscolsum = nextcolsum; lastcolsum = thiscolsum; thiscolsum = nextcolsum;
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) { for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
/* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */ /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
/* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */ /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++); nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
*outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4); *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
*outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4); *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
lastcolsum = thiscolsum; thiscolsum = nextcolsum; lastcolsum = thiscolsum; thiscolsum = nextcolsum;
} }
/* Special case for last column */ /* Special case for last column */
@@ -411,13 +411,13 @@ jinit_upsampler (j_decompress_ptr cinfo)
upsample = (my_upsample_ptr) upsample = (my_upsample_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_upsampler)); SIZEOF(my_upsampler));
cinfo->upsample = (struct jpeg_upsampler *) upsample; cinfo->upsample = (struct jpeg_upsampler *) upsample;
upsample->pub.start_pass = start_pass_upsample; upsample->pub.start_pass = start_pass_upsample;
upsample->pub.upsample = sep_upsample; upsample->pub.upsample = sep_upsample;
upsample->pub.need_context_rows = FALSE; /* until we find out differently */ upsample->pub.need_context_rows = FALSE; /* until we find out differently */
if (cinfo->CCIR601_sampling) /* this isn't supported */ if (cinfo->CCIR601_sampling) /* this isn't supported */
ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
/* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
@@ -434,9 +434,9 @@ jinit_upsampler (j_decompress_ptr cinfo)
* are to be converted to max_h_samp_factor * max_v_samp_factor pixels. * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
*/ */
h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
cinfo->_min_DCT_scaled_size; cinfo->_min_DCT_scaled_size;
v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
cinfo->_min_DCT_scaled_size; cinfo->_min_DCT_scaled_size;
h_out_group = cinfo->max_h_samp_factor; h_out_group = cinfo->max_h_samp_factor;
v_out_group = cinfo->max_v_samp_factor; v_out_group = cinfo->max_v_samp_factor;
upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
@@ -450,36 +450,36 @@ jinit_upsampler (j_decompress_ptr cinfo)
upsample->methods[ci] = fullsize_upsample; upsample->methods[ci] = fullsize_upsample;
need_buffer = FALSE; need_buffer = FALSE;
} else if (h_in_group * 2 == h_out_group && } else if (h_in_group * 2 == h_out_group &&
v_in_group == v_out_group) { v_in_group == v_out_group) {
/* Special cases for 2h1v upsampling */ /* Special cases for 2h1v upsampling */
if (do_fancy && compptr->downsampled_width > 2) { if (do_fancy && compptr->downsampled_width > 2) {
if (jsimd_can_h2v1_fancy_upsample()) if (jsimd_can_h2v1_fancy_upsample())
upsample->methods[ci] = jsimd_h2v1_fancy_upsample; upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
else else
upsample->methods[ci] = h2v1_fancy_upsample; upsample->methods[ci] = h2v1_fancy_upsample;
} else { } else {
if (jsimd_can_h2v1_upsample()) if (jsimd_can_h2v1_upsample())
upsample->methods[ci] = jsimd_h2v1_upsample; upsample->methods[ci] = jsimd_h2v1_upsample;
else else
upsample->methods[ci] = h2v1_upsample; upsample->methods[ci] = h2v1_upsample;
} }
} else if (h_in_group * 2 == h_out_group && } else if (h_in_group * 2 == h_out_group &&
v_in_group * 2 == v_out_group) { v_in_group * 2 == v_out_group) {
/* Special cases for 2h2v upsampling */ /* Special cases for 2h2v upsampling */
if (do_fancy && compptr->downsampled_width > 2) { if (do_fancy && compptr->downsampled_width > 2) {
if (jsimd_can_h2v2_fancy_upsample()) if (jsimd_can_h2v2_fancy_upsample())
upsample->methods[ci] = jsimd_h2v2_fancy_upsample; upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
else else
upsample->methods[ci] = h2v2_fancy_upsample; upsample->methods[ci] = h2v2_fancy_upsample;
upsample->pub.need_context_rows = TRUE; upsample->pub.need_context_rows = TRUE;
} else { } else {
if (jsimd_can_h2v2_upsample()) if (jsimd_can_h2v2_upsample())
upsample->methods[ci] = jsimd_h2v2_upsample; upsample->methods[ci] = jsimd_h2v2_upsample;
else else
upsample->methods[ci] = h2v2_upsample; upsample->methods[ci] = h2v2_upsample;
} }
} else if ((h_out_group % h_in_group) == 0 && } else if ((h_out_group % h_in_group) == 0 &&
(v_out_group % v_in_group) == 0) { (v_out_group % v_in_group) == 0) {
/* Generic integral-factors upsampling method */ /* Generic integral-factors upsampling method */
upsample->methods[ci] = int_upsample; upsample->methods[ci] = int_upsample;
upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group); upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
@@ -488,10 +488,10 @@ jinit_upsampler (j_decompress_ptr cinfo)
ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
if (need_buffer) { if (need_buffer) {
upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray) upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
(JDIMENSION) jround_up((long) cinfo->output_width, (JDIMENSION) jround_up((long) cinfo->output_width,
(long) cinfo->max_h_samp_factor), (long) cinfo->max_h_samp_factor),
(JDIMENSION) cinfo->max_v_samp_factor); (JDIMENSION) cinfo->max_v_samp_factor);
} }
} }
} }

View File

@@ -55,20 +55,20 @@ jpeg_read_coefficients (j_decompress_ptr cinfo)
int retcode; int retcode;
/* Call progress monitor hook if present */ /* Call progress monitor hook if present */
if (cinfo->progress != NULL) if (cinfo->progress != NULL)
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
/* Absorb some more input */ /* Absorb some more input */
retcode = (*cinfo->inputctl->consume_input) (cinfo); retcode = (*cinfo->inputctl->consume_input) (cinfo);
if (retcode == JPEG_SUSPENDED) if (retcode == JPEG_SUSPENDED)
return NULL; return NULL;
if (retcode == JPEG_REACHED_EOI) if (retcode == JPEG_REACHED_EOI)
break; break;
/* Advance progress counter if appropriate */ /* Advance progress counter if appropriate */
if (cinfo->progress != NULL && if (cinfo->progress != NULL &&
(retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
/* startup underestimated number of scans; ratchet up one scan */ /* startup underestimated number of scans; ratchet up one scan */
cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
} }
} }
} }
/* Set state so that jpeg_finish_decompress does the right thing */ /* Set state so that jpeg_finish_decompress does the right thing */
@@ -84,7 +84,7 @@ jpeg_read_coefficients (j_decompress_ptr cinfo)
} }
/* Oops, improper usage */ /* Oops, improper usage */
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
return NULL; /* keep compiler happy */ return NULL; /* keep compiler happy */
} }

View File

@@ -28,7 +28,7 @@
#include <windows.h> #include <windows.h>
#endif #endif
#ifndef EXIT_FAILURE /* define exit() codes if not provided */ #ifndef EXIT_FAILURE /* define exit() codes if not provided */
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#endif #endif
@@ -42,10 +42,10 @@
*/ */
#ifdef NEED_SHORT_EXTERNAL_NAMES #ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_std_message_table jMsgTable #define jpeg_std_message_table jMsgTable
#endif #endif
#define JMESSAGE(code,string) string , #define JMESSAGE(code,string) string ,
const char * const jpeg_std_message_table[] = { const char * const jpeg_std_message_table[] = {
#include "jerror.h" #include "jerror.h"
@@ -105,7 +105,7 @@ output_message (j_common_ptr cinfo)
#ifdef USE_WINDOWS_MESSAGEBOX #ifdef USE_WINDOWS_MESSAGEBOX
/* Display it in a message dialog box */ /* Display it in a message dialog box */
MessageBox(GetActiveWindow(), buffer, "JPEG Library Error", MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
MB_OK | MB_ICONERROR); MB_OK | MB_ICONERROR);
#else #else
/* Send it to stderr, adding a newline */ /* Send it to stderr, adding a newline */
fprintf(stderr, "%s\n", buffer); fprintf(stderr, "%s\n", buffer);
@@ -167,8 +167,8 @@ format_message (j_common_ptr cinfo, char * buffer)
if (msg_code > 0 && msg_code <= err->last_jpeg_message) { if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
msgtext = err->jpeg_message_table[msg_code]; msgtext = err->jpeg_message_table[msg_code];
} else if (err->addon_message_table != NULL && } else if (err->addon_message_table != NULL &&
msg_code >= err->first_addon_message && msg_code >= err->first_addon_message &&
msg_code <= err->last_addon_message) { msg_code <= err->last_addon_message) {
msgtext = err->addon_message_table[msg_code - err->first_addon_message]; msgtext = err->addon_message_table[msg_code - err->first_addon_message];
} }
@@ -193,10 +193,10 @@ format_message (j_common_ptr cinfo, char * buffer)
sprintf(buffer, msgtext, err->msg_parm.s); sprintf(buffer, msgtext, err->msg_parm.s);
else else
sprintf(buffer, msgtext, sprintf(buffer, msgtext,
err->msg_parm.i[0], err->msg_parm.i[1], err->msg_parm.i[0], err->msg_parm.i[1],
err->msg_parm.i[2], err->msg_parm.i[3], err->msg_parm.i[2], err->msg_parm.i[3],
err->msg_parm.i[4], err->msg_parm.i[5], err->msg_parm.i[4], err->msg_parm.i[5],
err->msg_parm.i[6], err->msg_parm.i[7]); err->msg_parm.i[6], err->msg_parm.i[7]);
} }
@@ -213,17 +213,17 @@ reset_error_mgr (j_common_ptr cinfo)
{ {
cinfo->err->num_warnings = 0; cinfo->err->num_warnings = 0;
/* trace_level is not reset since it is an application-supplied parameter */ /* trace_level is not reset since it is an application-supplied parameter */
cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */ cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
} }
/* /*
* Fill in the standard error-handling methods in a jpeg_error_mgr object. * Fill in the standard error-handling methods in a jpeg_error_mgr object.
* Typical call is: * Typical call is:
* struct jpeg_compress_struct cinfo; * struct jpeg_compress_struct cinfo;
* struct jpeg_error_mgr err; * struct jpeg_error_mgr err;
* *
* cinfo.err = jpeg_std_error(&err); * cinfo.err = jpeg_std_error(&err);
* after which the application may override some of the methods. * after which the application may override some of the methods.
*/ */
@@ -236,16 +236,16 @@ jpeg_std_error (struct jpeg_error_mgr * err)
err->format_message = format_message; err->format_message = format_message;
err->reset_error_mgr = reset_error_mgr; err->reset_error_mgr = reset_error_mgr;
err->trace_level = 0; /* default = no tracing */ err->trace_level = 0; /* default = no tracing */
err->num_warnings = 0; /* no warnings emitted yet */ err->num_warnings = 0; /* no warnings emitted yet */
err->msg_code = 0; /* may be useful as a flag for "no error" */ err->msg_code = 0; /* may be useful as a flag for "no error" */
/* Initialize message table pointers */ /* Initialize message table pointers */
err->jpeg_message_table = jpeg_std_message_table; err->jpeg_message_table = jpeg_std_message_table;
err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1; err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
err->addon_message_table = NULL; err->addon_message_table = NULL;
err->first_addon_message = 0; /* for safety */ err->first_addon_message = 0; /* for safety */
err->last_addon_message = 0; err->last_addon_message = 0;
return err; return err;

View File

@@ -33,7 +33,7 @@
typedef enum { typedef enum {
#define JMESSAGE(code,string) code , #define JMESSAGE(code,string) code ,
#endif /* JMAKE_ENUM_LIST */ #endif /* JMAKE_ENUM_LIST */
@@ -42,7 +42,7 @@ JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
/* For maintenance convenience, list is alphabetical by message code name */ /* For maintenance convenience, list is alphabetical by message code name */
#if JPEG_LIB_VERSION < 70 #if JPEG_LIB_VERSION < 70
JMESSAGE(JERR_ARITH_NOTIMPL, JMESSAGE(JERR_ARITH_NOTIMPL,
"Sorry, arithmetic coding is not implemented") "Sorry, arithmetic coding is not implemented")
#endif #endif
JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix") JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix") JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
@@ -55,26 +55,26 @@ JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported") JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
JMESSAGE(JERR_BAD_DROP_SAMPLING, JMESSAGE(JERR_BAD_DROP_SAMPLING,
"Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c") "Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c")
#endif #endif
JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition") JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace") JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace") JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length") JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
JMESSAGE(JERR_BAD_LIB_VERSION, JMESSAGE(JERR_BAD_LIB_VERSION,
"Wrong JPEG library version: library is %d, caller expects %d") "Wrong JPEG library version: library is %d, caller expects %d")
JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan") JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d") JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d") JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
JMESSAGE(JERR_BAD_PROGRESSION, JMESSAGE(JERR_BAD_PROGRESSION,
"Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d") "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
JMESSAGE(JERR_BAD_PROG_SCRIPT, JMESSAGE(JERR_BAD_PROG_SCRIPT,
"Invalid progressive parameters at scan script entry %d") "Invalid progressive parameters at scan script entry %d")
JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors") JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d") JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d") JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
JMESSAGE(JERR_BAD_STRUCT_SIZE, JMESSAGE(JERR_BAD_STRUCT_SIZE,
"JPEG parameter struct mismatch: library thinks size is %u, caller expects %u") "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access") JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small") JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here") JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
@@ -98,7 +98,7 @@ JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
JMESSAGE(JERR_INPUT_EMPTY, "Empty input file") JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
JMESSAGE(JERR_INPUT_EOF, "Premature end of input file") JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
JMESSAGE(JERR_MISMATCHED_QUANT_TABLE, JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
"Cannot transcode due to multiple use of quantization table %d") "Cannot transcode due to multiple use of quantization table %d")
JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data") JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change") JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
JMESSAGE(JERR_NOTIMPL, "Not implemented yet") JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
@@ -113,7 +113,7 @@ JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x") JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)") JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
JMESSAGE(JERR_QUANT_COMPONENTS, JMESSAGE(JERR_QUANT_COMPONENTS,
"Cannot quantize more than %d color components") "Cannot quantize more than %d color components")
JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors") JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors") JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers") JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
@@ -125,7 +125,7 @@ JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file") JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file") JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
JMESSAGE(JERR_TFILE_WRITE, JMESSAGE(JERR_TFILE_WRITE,
"Write failed on temporary file --- out of disk space?") "Write failed on temporary file --- out of disk space?")
JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines") JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x") JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up") JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
@@ -135,9 +135,9 @@ JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT) JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
JMESSAGE(JMSG_VERSION, JVERSION) JMESSAGE(JMSG_VERSION, JVERSION)
JMESSAGE(JTRC_16BIT_TABLES, JMESSAGE(JTRC_16BIT_TABLES,
"Caution: quantization tables are too coarse for baseline JPEG") "Caution: quantization tables are too coarse for baseline JPEG")
JMESSAGE(JTRC_ADOBE, JMESSAGE(JTRC_ADOBE,
"Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d") "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u") JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u") JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x") JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
@@ -150,9 +150,9 @@ JMESSAGE(JTRC_EOI, "End Of Image")
JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d") JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d") JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE, JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
"Warning: thumbnail image size does not match data length %u") "Warning: thumbnail image size does not match data length %u")
JMESSAGE(JTRC_JFIF_EXTENSION, JMESSAGE(JTRC_JFIF_EXTENSION,
"JFIF extension marker: type 0x%02x, length %u") "JFIF extension marker: type 0x%02x, length %u")
JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image") JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u") JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x") JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
@@ -163,7 +163,7 @@ JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d") JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
JMESSAGE(JTRC_RST, "RST%d") JMESSAGE(JTRC_RST, "RST%d")
JMESSAGE(JTRC_SMOOTH_NOTIMPL, JMESSAGE(JTRC_SMOOTH_NOTIMPL,
"Smoothing not supported with nonstandard sampling ratios") "Smoothing not supported with nonstandard sampling ratios")
JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d") JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d") JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
JMESSAGE(JTRC_SOI, "Start of Image") JMESSAGE(JTRC_SOI, "Start of Image")
@@ -173,13 +173,13 @@ JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s") JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s") JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
JMESSAGE(JTRC_THUMB_JPEG, JMESSAGE(JTRC_THUMB_JPEG,
"JFIF extension marker: JPEG-compressed thumbnail image, length %u") "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
JMESSAGE(JTRC_THUMB_PALETTE, JMESSAGE(JTRC_THUMB_PALETTE,
"JFIF extension marker: palette thumbnail image, length %u") "JFIF extension marker: palette thumbnail image, length %u")
JMESSAGE(JTRC_THUMB_RGB, JMESSAGE(JTRC_THUMB_RGB,
"JFIF extension marker: RGB thumbnail image, length %u") "JFIF extension marker: RGB thumbnail image, length %u")
JMESSAGE(JTRC_UNKNOWN_IDS, JMESSAGE(JTRC_UNKNOWN_IDS,
"Unrecognized component IDs %d %d %d, assuming YCbCr") "Unrecognized component IDs %d %d %d, assuming YCbCr")
JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u") JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u") JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d") JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
@@ -187,15 +187,15 @@ JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code") JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
#endif #endif
JMESSAGE(JWRN_BOGUS_PROGRESSION, JMESSAGE(JWRN_BOGUS_PROGRESSION,
"Inconsistent progression sequence for component %d coefficient %d") "Inconsistent progression sequence for component %d coefficient %d")
JMESSAGE(JWRN_EXTRANEOUS_DATA, JMESSAGE(JWRN_EXTRANEOUS_DATA,
"Corrupt JPEG data: %u extraneous bytes before marker 0x%02x") "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment") JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code") JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d") JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file") JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
JMESSAGE(JWRN_MUST_RESYNC, JMESSAGE(JWRN_MUST_RESYNC,
"Corrupt JPEG data: found marker 0x%02x instead of RST%d") "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG") JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines") JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
#if JPEG_LIB_VERSION < 70 #if JPEG_LIB_VERSION < 70
@@ -255,7 +255,7 @@ JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
(*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
#define MAKESTMT(stuff) do { stuff } while (0) #define MAKESTMT(stuff) do { stuff } while (0)
/* Nonfatal errors (we can keep going, but the data is probably corrupt) */ /* Nonfatal errors (we can keep going, but the data is probably corrupt) */
#define WARNMS(cinfo,code) \ #define WARNMS(cinfo,code) \
@@ -286,26 +286,26 @@ JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
#define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \ #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
(cinfo)->err->msg_code = (code); \ (cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \ #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
(cinfo)->err->msg_code = (code); \ (cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
#define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \ #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
_mp[4] = (p5); \ _mp[4] = (p5); \
(cinfo)->err->msg_code = (code); \ (cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \ #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
_mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \ _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
(cinfo)->err->msg_code = (code); \ (cinfo)->err->msg_code = (code); \
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
#define TRACEMSS(cinfo,lvl,code,str) \ #define TRACEMSS(cinfo,lvl,code,str) \
((cinfo)->err->msg_code = (code), \ ((cinfo)->err->msg_code = (code), \
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \

View File

@@ -37,7 +37,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
@@ -76,24 +76,24 @@ jpeg_fdct_float (FAST_FLOAT * data)
tmp5 = dataptr[2] - dataptr[5]; tmp5 = dataptr[2] - dataptr[5];
tmp3 = dataptr[3] + dataptr[4]; tmp3 = dataptr[3] + dataptr[4];
tmp4 = dataptr[3] - dataptr[4]; tmp4 = dataptr[3] - dataptr[4];
/* Even part */ /* Even part */
tmp10 = tmp0 + tmp3; /* phase 2 */ tmp10 = tmp0 + tmp3; /* phase 2 */
tmp13 = tmp0 - tmp3; tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
dataptr[0] = tmp10 + tmp11; /* phase 3 */ dataptr[0] = tmp10 + tmp11; /* phase 3 */
dataptr[4] = tmp10 - tmp11; dataptr[4] = tmp10 - tmp11;
z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
dataptr[2] = tmp13 + z1; /* phase 5 */ dataptr[2] = tmp13 + z1; /* phase 5 */
dataptr[6] = tmp13 - z1; dataptr[6] = tmp13 - z1;
/* Odd part */ /* Odd part */
tmp10 = tmp4 + tmp5; /* phase 2 */ tmp10 = tmp4 + tmp5; /* phase 2 */
tmp11 = tmp5 + tmp6; tmp11 = tmp5 + tmp6;
tmp12 = tmp6 + tmp7; tmp12 = tmp6 + tmp7;
@@ -103,15 +103,15 @@ jpeg_fdct_float (FAST_FLOAT * data)
z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
z11 = tmp7 + z3; /* phase 5 */ z11 = tmp7 + z3; /* phase 5 */
z13 = tmp7 - z3; z13 = tmp7 - z3;
dataptr[5] = z13 + z2; /* phase 6 */ dataptr[5] = z13 + z2; /* phase 6 */
dataptr[3] = z13 - z2; dataptr[3] = z13 - z2;
dataptr[1] = z11 + z4; dataptr[1] = z11 + z4;
dataptr[7] = z11 - z4; dataptr[7] = z11 - z4;
dataptr += DCTSIZE; /* advance pointer to next row */ dataptr += DCTSIZE; /* advance pointer to next row */
} }
/* Pass 2: process columns. */ /* Pass 2: process columns. */
@@ -126,24 +126,24 @@ jpeg_fdct_float (FAST_FLOAT * data)
tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
/* Even part */ /* Even part */
tmp10 = tmp0 + tmp3; /* phase 2 */ tmp10 = tmp0 + tmp3; /* phase 2 */
tmp13 = tmp0 - tmp3; tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
dataptr[DCTSIZE*4] = tmp10 - tmp11; dataptr[DCTSIZE*4] = tmp10 - tmp11;
z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
dataptr[DCTSIZE*6] = tmp13 - z1; dataptr[DCTSIZE*6] = tmp13 - z1;
/* Odd part */ /* Odd part */
tmp10 = tmp4 + tmp5; /* phase 2 */ tmp10 = tmp4 + tmp5; /* phase 2 */
tmp11 = tmp5 + tmp6; tmp11 = tmp5 + tmp6;
tmp12 = tmp6 + tmp7; tmp12 = tmp6 + tmp7;
@@ -153,7 +153,7 @@ jpeg_fdct_float (FAST_FLOAT * data)
z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
z11 = tmp7 + z3; /* phase 5 */ z11 = tmp7 + z3; /* phase 5 */
z13 = tmp7 - z3; z13 = tmp7 - z3;
dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
@@ -161,7 +161,7 @@ jpeg_fdct_float (FAST_FLOAT * data)
dataptr[DCTSIZE*1] = z11 + z4; dataptr[DCTSIZE*1] = z11 + z4;
dataptr[DCTSIZE*7] = z11 - z4; dataptr[DCTSIZE*7] = z11 - z4;
dataptr++; /* advance pointer to next column */ dataptr++; /* advance pointer to next column */
} }
} }

View File

@@ -33,7 +33,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
@@ -76,10 +76,10 @@
*/ */
#if CONST_BITS == 8 #if CONST_BITS == 8
#define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */ #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
#define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */ #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
#define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */ #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
#define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */ #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
#else #else
#define FIX_0_382683433 FIX(0.382683433) #define FIX_0_382683433 FIX(0.382683433)
#define FIX_0_541196100 FIX(0.541196100) #define FIX_0_541196100 FIX(0.541196100)
@@ -132,24 +132,24 @@ jpeg_fdct_ifast (DCTELEM * data)
tmp5 = dataptr[2] - dataptr[5]; tmp5 = dataptr[2] - dataptr[5];
tmp3 = dataptr[3] + dataptr[4]; tmp3 = dataptr[3] + dataptr[4];
tmp4 = dataptr[3] - dataptr[4]; tmp4 = dataptr[3] - dataptr[4];
/* Even part */ /* Even part */
tmp10 = tmp0 + tmp3; /* phase 2 */ tmp10 = tmp0 + tmp3; /* phase 2 */
tmp13 = tmp0 - tmp3; tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
dataptr[0] = tmp10 + tmp11; /* phase 3 */ dataptr[0] = tmp10 + tmp11; /* phase 3 */
dataptr[4] = tmp10 - tmp11; dataptr[4] = tmp10 - tmp11;
z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
dataptr[2] = tmp13 + z1; /* phase 5 */ dataptr[2] = tmp13 + z1; /* phase 5 */
dataptr[6] = tmp13 - z1; dataptr[6] = tmp13 - z1;
/* Odd part */ /* Odd part */
tmp10 = tmp4 + tmp5; /* phase 2 */ tmp10 = tmp4 + tmp5; /* phase 2 */
tmp11 = tmp5 + tmp6; tmp11 = tmp5 + tmp6;
tmp12 = tmp6 + tmp7; tmp12 = tmp6 + tmp7;
@@ -159,15 +159,15 @@ jpeg_fdct_ifast (DCTELEM * data)
z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
z11 = tmp7 + z3; /* phase 5 */ z11 = tmp7 + z3; /* phase 5 */
z13 = tmp7 - z3; z13 = tmp7 - z3;
dataptr[5] = z13 + z2; /* phase 6 */ dataptr[5] = z13 + z2; /* phase 6 */
dataptr[3] = z13 - z2; dataptr[3] = z13 - z2;
dataptr[1] = z11 + z4; dataptr[1] = z11 + z4;
dataptr[7] = z11 - z4; dataptr[7] = z11 - z4;
dataptr += DCTSIZE; /* advance pointer to next row */ dataptr += DCTSIZE; /* advance pointer to next row */
} }
/* Pass 2: process columns. */ /* Pass 2: process columns. */
@@ -182,24 +182,24 @@ jpeg_fdct_ifast (DCTELEM * data)
tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
/* Even part */ /* Even part */
tmp10 = tmp0 + tmp3; /* phase 2 */ tmp10 = tmp0 + tmp3; /* phase 2 */
tmp13 = tmp0 - tmp3; tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
dataptr[DCTSIZE*4] = tmp10 - tmp11; dataptr[DCTSIZE*4] = tmp10 - tmp11;
z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
dataptr[DCTSIZE*6] = tmp13 - z1; dataptr[DCTSIZE*6] = tmp13 - z1;
/* Odd part */ /* Odd part */
tmp10 = tmp4 + tmp5; /* phase 2 */ tmp10 = tmp4 + tmp5; /* phase 2 */
tmp11 = tmp5 + tmp6; tmp11 = tmp5 + tmp6;
tmp12 = tmp6 + tmp7; tmp12 = tmp6 + tmp7;
@@ -209,7 +209,7 @@ jpeg_fdct_ifast (DCTELEM * data)
z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */ z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */ z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
z11 = tmp7 + z3; /* phase 5 */ z11 = tmp7 + z3; /* phase 5 */
z13 = tmp7 - z3; z13 = tmp7 - z3;
dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
@@ -217,7 +217,7 @@ jpeg_fdct_ifast (DCTELEM * data)
dataptr[DCTSIZE*1] = z11 + z4; dataptr[DCTSIZE*1] = z11 + z4;
dataptr[DCTSIZE*7] = z11 - z4; dataptr[DCTSIZE*7] = z11 - z4;
dataptr++; /* advance pointer to next column */ dataptr++; /* advance pointer to next column */
} }
} }

View File

@@ -26,7 +26,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_ISLOW_SUPPORTED #ifdef DCT_ISLOW_SUPPORTED
@@ -79,7 +79,7 @@
#define PASS1_BITS 2 #define PASS1_BITS 2
#else #else
#define CONST_BITS 13 #define CONST_BITS 13
#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
#endif #endif
/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
@@ -90,18 +90,18 @@
*/ */
#if CONST_BITS == 13 #if CONST_BITS == 13
#define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */ #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
#define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */ #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
#define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */ #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
#define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */ #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
#define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */ #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
#define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */ #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
#define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */ #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
#define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */ #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
#else #else
#define FIX_0_298631336 FIX(0.298631336) #define FIX_0_298631336 FIX(0.298631336)
#define FIX_0_390180644 FIX(0.390180644) #define FIX_0_390180644 FIX(0.390180644)
@@ -160,36 +160,36 @@ jpeg_fdct_islow (DCTELEM * data)
tmp5 = dataptr[2] - dataptr[5]; tmp5 = dataptr[2] - dataptr[5];
tmp3 = dataptr[3] + dataptr[4]; tmp3 = dataptr[3] + dataptr[4];
tmp4 = dataptr[3] - dataptr[4]; tmp4 = dataptr[3] - dataptr[4];
/* Even part per LL&M figure 1 --- note that published figure is faulty; /* Even part per LL&M figure 1 --- note that published figure is faulty;
* rotator "sqrt(2)*c1" should be "sqrt(2)*c6". * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
*/ */
tmp10 = tmp0 + tmp3; tmp10 = tmp0 + tmp3;
tmp13 = tmp0 - tmp3; tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS); dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS); dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
CONST_BITS-PASS1_BITS); CONST_BITS-PASS1_BITS);
dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
CONST_BITS-PASS1_BITS); CONST_BITS-PASS1_BITS);
/* Odd part per figure 8 --- note paper omits factor of sqrt(2). /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
* cK represents cos(K*pi/16). * cK represents cos(K*pi/16).
* i0..i3 in the paper are tmp4..tmp7 here. * i0..i3 in the paper are tmp4..tmp7 here.
*/ */
z1 = tmp4 + tmp7; z1 = tmp4 + tmp7;
z2 = tmp5 + tmp6; z2 = tmp5 + tmp6;
z3 = tmp4 + tmp6; z3 = tmp4 + tmp6;
z4 = tmp5 + tmp7; z4 = tmp5 + tmp7;
z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
@@ -198,16 +198,16 @@ jpeg_fdct_islow (DCTELEM * data)
z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
z3 += z5; z3 += z5;
z4 += z5; z4 += z5;
dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
dataptr += DCTSIZE; /* advance pointer to next row */ dataptr += DCTSIZE; /* advance pointer to next row */
} }
/* Pass 2: process columns. /* Pass 2: process columns.
@@ -225,36 +225,36 @@ jpeg_fdct_islow (DCTELEM * data)
tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
/* Even part per LL&M figure 1 --- note that published figure is faulty; /* Even part per LL&M figure 1 --- note that published figure is faulty;
* rotator "sqrt(2)*c1" should be "sqrt(2)*c6". * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
*/ */
tmp10 = tmp0 + tmp3; tmp10 = tmp0 + tmp3;
tmp13 = tmp0 - tmp3; tmp13 = tmp0 - tmp3;
tmp11 = tmp1 + tmp2; tmp11 = tmp1 + tmp2;
tmp12 = tmp1 - tmp2; tmp12 = tmp1 - tmp2;
dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
CONST_BITS+PASS1_BITS); CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
CONST_BITS+PASS1_BITS); CONST_BITS+PASS1_BITS);
/* Odd part per figure 8 --- note paper omits factor of sqrt(2). /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
* cK represents cos(K*pi/16). * cK represents cos(K*pi/16).
* i0..i3 in the paper are tmp4..tmp7 here. * i0..i3 in the paper are tmp4..tmp7 here.
*/ */
z1 = tmp4 + tmp7; z1 = tmp4 + tmp7;
z2 = tmp5 + tmp6; z2 = tmp5 + tmp6;
z3 = tmp4 + tmp6; z3 = tmp4 + tmp6;
z4 = tmp5 + tmp7; z4 = tmp5 + tmp7;
z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
@@ -263,20 +263,20 @@ jpeg_fdct_islow (DCTELEM * data)
z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
z3 += z5; z3 += z5;
z4 += z5; z4 += z5;
dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
CONST_BITS+PASS1_BITS); CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
CONST_BITS+PASS1_BITS); CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
CONST_BITS+PASS1_BITS); CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
CONST_BITS+PASS1_BITS); CONST_BITS+PASS1_BITS);
dataptr++; /* advance pointer to next column */ dataptr++; /* advance pointer to next column */
} }
} }

View File

@@ -39,7 +39,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
@@ -66,8 +66,8 @@
GLOBAL(void) GLOBAL(void)
jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col) JSAMPARRAY output_buf, JDIMENSION output_col)
{ {
FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
FAST_FLOAT tmp10, tmp11, tmp12, tmp13; FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
@@ -95,14 +95,14 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
* With typical images and quantization tables, half or more of the * With typical images and quantization tables, half or more of the
* column DCT calculations can be simplified this way. * column DCT calculations can be simplified this way.
*/ */
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
inptr[DCTSIZE*7] == 0) { inptr[DCTSIZE*7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE*0] = dcval;
wsptr[DCTSIZE*1] = dcval; wsptr[DCTSIZE*1] = dcval;
wsptr[DCTSIZE*2] = dcval; wsptr[DCTSIZE*2] = dcval;
@@ -111,13 +111,13 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
wsptr[DCTSIZE*5] = dcval; wsptr[DCTSIZE*5] = dcval;
wsptr[DCTSIZE*6] = dcval; wsptr[DCTSIZE*6] = dcval;
wsptr[DCTSIZE*7] = dcval; wsptr[DCTSIZE*7] = dcval;
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
wsptr++; wsptr++;
continue; continue;
} }
/* Even part */ /* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
@@ -125,17 +125,17 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
tmp10 = tmp0 + tmp2; /* phase 3 */ tmp10 = tmp0 + tmp2; /* phase 3 */
tmp11 = tmp0 - tmp2; tmp11 = tmp0 - tmp2;
tmp13 = tmp1 + tmp3; /* phases 5-3 */ tmp13 = tmp1 + tmp3; /* phases 5-3 */
tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */ tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
tmp0 = tmp10 + tmp13; /* phase 2 */ tmp0 = tmp10 + tmp13; /* phase 2 */
tmp3 = tmp10 - tmp13; tmp3 = tmp10 - tmp13;
tmp1 = tmp11 + tmp12; tmp1 = tmp11 + tmp12;
tmp2 = tmp11 - tmp12; tmp2 = tmp11 - tmp12;
/* Odd part */ /* Odd part */
tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
@@ -143,19 +143,19 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
z13 = tmp6 + tmp5; /* phase 6 */ z13 = tmp6 + tmp5; /* phase 6 */
z10 = tmp6 - tmp5; z10 = tmp6 - tmp5;
z11 = tmp4 + tmp7; z11 = tmp4 + tmp7;
z12 = tmp4 - tmp7; z12 = tmp4 - tmp7;
tmp7 = z11 + z13; /* phase 5 */ tmp7 = z11 + z13; /* phase 5 */
tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */ tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
tmp6 = tmp12 - tmp7; /* phase 2 */ tmp6 = tmp12 - tmp7; /* phase 2 */
tmp5 = tmp11 - tmp6; tmp5 = tmp11 - tmp6;
tmp4 = tmp10 + tmp5; tmp4 = tmp10 + tmp5;
@@ -168,11 +168,11 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
wsptr[DCTSIZE*4] = tmp3 + tmp4; wsptr[DCTSIZE*4] = tmp3 + tmp4;
wsptr[DCTSIZE*3] = tmp3 - tmp4; wsptr[DCTSIZE*3] = tmp3 - tmp4;
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
wsptr++; wsptr++;
} }
/* Pass 2: process rows from work array, store into output array. */ /* Pass 2: process rows from work array, store into output array. */
/* Note that we must descale the results by a factor of 8 == 2**3. */ /* Note that we must descale the results by a factor of 8 == 2**3. */
@@ -184,7 +184,7 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
* the simplification applies less often (typically 5% to 10% of the time). * the simplification applies less often (typically 5% to 10% of the time).
* And testing floats for zero is relatively expensive, so we don't bother. * And testing floats for zero is relatively expensive, so we don't bother.
*/ */
/* Even part */ /* Even part */
tmp10 = wsptr[0] + wsptr[4]; tmp10 = wsptr[0] + wsptr[4];
@@ -219,23 +219,23 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Final output stage: scale down by a factor of 8 and range-limit */ /* Final output stage: scale down by a factor of 8 and range-limit */
outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3) outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
& RANGE_MASK]; & RANGE_MASK];
outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3) outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
& RANGE_MASK]; & RANGE_MASK];
outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3) outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
& RANGE_MASK]; & RANGE_MASK];
outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3) outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
& RANGE_MASK]; & RANGE_MASK];
outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3) outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
& RANGE_MASK]; & RANGE_MASK];
outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3) outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
& RANGE_MASK]; & RANGE_MASK];
outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3) outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
& RANGE_MASK]; & RANGE_MASK];
outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3) outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
& RANGE_MASK]; & RANGE_MASK];
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
} }
} }

View File

@@ -35,7 +35,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef DCT_IFAST_SUPPORTED #ifdef DCT_IFAST_SUPPORTED
@@ -78,7 +78,7 @@
#define PASS1_BITS 2 #define PASS1_BITS 2
#else #else
#define CONST_BITS 8 #define CONST_BITS 8
#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
#endif #endif
/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
@@ -89,10 +89,10 @@
*/ */
#if CONST_BITS == 8 #if CONST_BITS == 8
#define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */ #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
#define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */ #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
#define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */ #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
#define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */ #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
#else #else
#define FIX_1_082392200 FIX(1.082392200) #define FIX_1_082392200 FIX(1.082392200)
#define FIX_1_414213562 FIX(1.414213562) #define FIX_1_414213562 FIX(1.414213562)
@@ -129,7 +129,7 @@
#define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval)) #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
#else #else
#define DEQUANTIZE(coef,quantval) \ #define DEQUANTIZE(coef,quantval) \
DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS) DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
#endif #endif
@@ -138,11 +138,11 @@
*/ */
#ifdef RIGHT_SHIFT_IS_UNSIGNED #ifdef RIGHT_SHIFT_IS_UNSIGNED
#define ISHIFT_TEMPS DCTELEM ishift_temp; #define ISHIFT_TEMPS DCTELEM ishift_temp;
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
#define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */ #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
#else #else
#define DCTELEMBITS 32 /* DCTELEM must be 32 bits */ #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
#endif #endif
#define IRIGHT_SHIFT(x,shft) \ #define IRIGHT_SHIFT(x,shft) \
((ishift_temp = (x)) < 0 ? \ ((ishift_temp = (x)) < 0 ? \
@@ -150,7 +150,7 @@
(ishift_temp >> (shft))) (ishift_temp >> (shft)))
#else #else
#define ISHIFT_TEMPS #define ISHIFT_TEMPS
#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
#endif #endif
#ifdef USE_ACCURATE_ROUNDING #ifdef USE_ACCURATE_ROUNDING
@@ -166,8 +166,8 @@
GLOBAL(void) GLOBAL(void)
jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col) JSAMPARRAY output_buf, JDIMENSION output_col)
{ {
DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
DCTELEM tmp10, tmp11, tmp12, tmp13; DCTELEM tmp10, tmp11, tmp12, tmp13;
@@ -178,9 +178,9 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPROW outptr; JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo); JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr; int ctr;
int workspace[DCTSIZE2]; /* buffers data between passes */ int workspace[DCTSIZE2]; /* buffers data between passes */
SHIFT_TEMPS /* for DESCALE */ SHIFT_TEMPS /* for DESCALE */
ISHIFT_TEMPS /* for IDESCALE */ ISHIFT_TEMPS /* for IDESCALE */
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array. */
@@ -196,11 +196,11 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
* With typical images and quantization tables, half or more of the * With typical images and quantization tables, half or more of the
* column DCT calculations can be simplified this way. * column DCT calculations can be simplified this way.
*/ */
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
inptr[DCTSIZE*7] == 0) { inptr[DCTSIZE*7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
@@ -212,13 +212,13 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
wsptr[DCTSIZE*5] = dcval; wsptr[DCTSIZE*5] = dcval;
wsptr[DCTSIZE*6] = dcval; wsptr[DCTSIZE*6] = dcval;
wsptr[DCTSIZE*7] = dcval; wsptr[DCTSIZE*7] = dcval;
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
wsptr++; wsptr++;
continue; continue;
} }
/* Even part */ /* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
@@ -226,17 +226,17 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
tmp10 = tmp0 + tmp2; /* phase 3 */ tmp10 = tmp0 + tmp2; /* phase 3 */
tmp11 = tmp0 - tmp2; tmp11 = tmp0 - tmp2;
tmp13 = tmp1 + tmp3; /* phases 5-3 */ tmp13 = tmp1 + tmp3; /* phases 5-3 */
tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */ tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
tmp0 = tmp10 + tmp13; /* phase 2 */ tmp0 = tmp10 + tmp13; /* phase 2 */
tmp3 = tmp10 - tmp13; tmp3 = tmp10 - tmp13;
tmp1 = tmp11 + tmp12; tmp1 = tmp11 + tmp12;
tmp2 = tmp11 - tmp12; tmp2 = tmp11 - tmp12;
/* Odd part */ /* Odd part */
tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
@@ -244,19 +244,19 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
z13 = tmp6 + tmp5; /* phase 6 */ z13 = tmp6 + tmp5; /* phase 6 */
z10 = tmp6 - tmp5; z10 = tmp6 - tmp5;
z11 = tmp4 + tmp7; z11 = tmp4 + tmp7;
z12 = tmp4 - tmp7; z12 = tmp4 - tmp7;
tmp7 = z11 + z13; /* phase 5 */ tmp7 = z11 + z13; /* phase 5 */
tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
tmp6 = tmp12 - tmp7; /* phase 2 */ tmp6 = tmp12 - tmp7; /* phase 2 */
tmp5 = tmp11 - tmp6; tmp5 = tmp11 - tmp6;
tmp4 = tmp10 + tmp5; tmp4 = tmp10 + tmp5;
@@ -269,11 +269,11 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4); wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4); wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
wsptr++; wsptr++;
} }
/* Pass 2: process rows from work array, store into output array. */ /* Pass 2: process rows from work array, store into output array. */
/* Note that we must descale the results by a factor of 8 == 2**3, */ /* Note that we must descale the results by a factor of 8 == 2**3, */
/* and also undo the PASS1_BITS scaling. */ /* and also undo the PASS1_BITS scaling. */
@@ -288,14 +288,14 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
* test takes more time than it's worth. In that case this section * test takes more time than it's worth. In that case this section
* may be commented out. * may be commented out.
*/ */
#ifndef NO_ZERO_ROW_TEST #ifndef NO_ZERO_ROW_TEST
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3) JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[0] = dcval; outptr[0] = dcval;
outptr[1] = dcval; outptr[1] = dcval;
outptr[2] = dcval; outptr[2] = dcval;
@@ -305,11 +305,11 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
outptr[6] = dcval; outptr[6] = dcval;
outptr[7] = dcval; outptr[7] = dcval;
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
continue; continue;
} }
#endif #endif
/* Even part */ /* Even part */
tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]); tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
@@ -317,7 +317,7 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]); tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562) tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
- tmp13; - tmp13;
tmp0 = tmp10 + tmp13; tmp0 = tmp10 + tmp13;
tmp3 = tmp10 - tmp13; tmp3 = tmp10 - tmp13;
@@ -331,37 +331,37 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7]; z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7]; z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
tmp7 = z11 + z13; /* phase 5 */ tmp7 = z11 + z13; /* phase 5 */
tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
tmp6 = tmp12 - tmp7; /* phase 2 */ tmp6 = tmp12 - tmp7; /* phase 2 */
tmp5 = tmp11 - tmp6; tmp5 = tmp11 - tmp6;
tmp4 = tmp10 + tmp5; tmp4 = tmp10 + tmp5;
/* Final output stage: scale down by a factor of 8 and range-limit */ /* Final output stage: scale down by a factor of 8 and range-limit */
outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3) outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3) outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3) outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3) outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3) outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3) outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3) outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3) outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -23,7 +23,7 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jdct.h" /* Private declarations for DCT subsystem */ #include "jdct.h" /* Private declarations for DCT subsystem */
#ifdef IDCT_SCALING_SUPPORTED #ifdef IDCT_SCALING_SUPPORTED
@@ -44,7 +44,7 @@
#define PASS1_BITS 2 #define PASS1_BITS 2
#else #else
#define CONST_BITS 13 #define CONST_BITS 13
#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
#endif #endif
/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
@@ -55,20 +55,20 @@
*/ */
#if CONST_BITS == 13 #if CONST_BITS == 13
#define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */ #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
#define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */ #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
#define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */ #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
#define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */ #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */ #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
#define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */ #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */ #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
#define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */ #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
#define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */ #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
#define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */ #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */ #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
#define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */ #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */ #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
#define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */ #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
#else #else
#define FIX_0_211164243 FIX(0.211164243) #define FIX_0_211164243 FIX(0.211164243)
#define FIX_0_509795579 FIX(0.509795579) #define FIX_0_509795579 FIX(0.509795579)
@@ -116,8 +116,8 @@
GLOBAL(void) GLOBAL(void)
jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col) JSAMPARRAY output_buf, JDIMENSION output_col)
{ {
INT32 tmp0, tmp2, tmp10, tmp12; INT32 tmp0, tmp2, tmp10, tmp12;
INT32 z1, z2, z3, z4; INT32 z1, z2, z3, z4;
@@ -127,7 +127,7 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPROW outptr; JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo); JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr; int ctr;
int workspace[DCTSIZE*4]; /* buffers data between passes */ int workspace[DCTSIZE*4]; /* buffers data between passes */
SHIFT_TEMPS SHIFT_TEMPS
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array. */
@@ -140,57 +140,57 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
if (ctr == DCTSIZE-4) if (ctr == DCTSIZE-4)
continue; continue;
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) { inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
/* AC terms all zero; we need not examine term 4 for 4x4 output */ /* AC terms all zero; we need not examine term 4 for 4x4 output */
int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE*0] = dcval;
wsptr[DCTSIZE*1] = dcval; wsptr[DCTSIZE*1] = dcval;
wsptr[DCTSIZE*2] = dcval; wsptr[DCTSIZE*2] = dcval;
wsptr[DCTSIZE*3] = dcval; wsptr[DCTSIZE*3] = dcval;
continue; continue;
} }
/* Even part */ /* Even part */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
tmp0 <<= (CONST_BITS+1); tmp0 <<= (CONST_BITS+1);
z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865); tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp12 = tmp0 - tmp2; tmp12 = tmp0 - tmp2;
/* Odd part */ /* Odd part */
z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */ tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
+ MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */ + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
+ MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */ + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
+ MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */ + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */ tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
+ MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */ + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
+ MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */ + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
+ MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */ + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
/* Final output stage */ /* Final output stage */
wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1); wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1); wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1); wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1); wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
} }
/* Pass 2: process 4 rows from work array, store into output array. */ /* Pass 2: process 4 rows from work array, store into output array. */
wsptr = workspace; wsptr = workspace;
@@ -200,64 +200,64 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
#ifndef NO_ZERO_ROW_TEST #ifndef NO_ZERO_ROW_TEST
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[0] = dcval; outptr[0] = dcval;
outptr[1] = dcval; outptr[1] = dcval;
outptr[2] = dcval; outptr[2] = dcval;
outptr[3] = dcval; outptr[3] = dcval;
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
continue; continue;
} }
#endif #endif
/* Even part */ /* Even part */
tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1); tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065) tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
+ MULTIPLY((INT32) wsptr[6], - FIX_0_765366865); + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp12 = tmp0 - tmp2; tmp12 = tmp0 - tmp2;
/* Odd part */ /* Odd part */
z1 = (INT32) wsptr[7]; z1 = (INT32) wsptr[7];
z2 = (INT32) wsptr[5]; z2 = (INT32) wsptr[5];
z3 = (INT32) wsptr[3]; z3 = (INT32) wsptr[3];
z4 = (INT32) wsptr[1]; z4 = (INT32) wsptr[1];
tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */ tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
+ MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */ + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
+ MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */ + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
+ MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */ + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */ tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
+ MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */ + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
+ MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */ + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
+ MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */ + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
/* Final output stage */ /* Final output stage */
outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2, outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
CONST_BITS+PASS1_BITS+3+1) CONST_BITS+PASS1_BITS+3+1)
& RANGE_MASK]; & RANGE_MASK];
outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2, outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
CONST_BITS+PASS1_BITS+3+1) CONST_BITS+PASS1_BITS+3+1)
& RANGE_MASK]; & RANGE_MASK];
outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0, outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
CONST_BITS+PASS1_BITS+3+1) CONST_BITS+PASS1_BITS+3+1)
& RANGE_MASK]; & RANGE_MASK];
outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0, outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
CONST_BITS+PASS1_BITS+3+1) CONST_BITS+PASS1_BITS+3+1)
& RANGE_MASK]; & RANGE_MASK];
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
} }
} }
@@ -269,8 +269,8 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
GLOBAL(void) GLOBAL(void)
jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col) JSAMPARRAY output_buf, JDIMENSION output_col)
{ {
INT32 tmp0, tmp10, z1; INT32 tmp0, tmp10, z1;
JCOEFPTR inptr; JCOEFPTR inptr;
@@ -279,7 +279,7 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JSAMPROW outptr; JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo); JSAMPLE *range_limit = IDCT_range_limit(cinfo);
int ctr; int ctr;
int workspace[DCTSIZE*2]; /* buffers data between passes */ int workspace[DCTSIZE*2]; /* buffers data between passes */
SHIFT_TEMPS SHIFT_TEMPS
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array. */
@@ -292,21 +292,21 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6) if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
continue; continue;
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 && if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) { inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
/* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */ /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */
int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE*0] = dcval;
wsptr[DCTSIZE*1] = dcval; wsptr[DCTSIZE*1] = dcval;
continue; continue;
} }
/* Even part */ /* Even part */
z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
tmp10 = z1 << (CONST_BITS+2); tmp10 = z1 << (CONST_BITS+2);
/* Odd part */ /* Odd part */
z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
@@ -319,11 +319,11 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
/* Final output stage */ /* Final output stage */
wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2); wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2); wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
} }
/* Pass 2: process 2 rows from work array, store into output array. */ /* Pass 2: process 2 rows from work array, store into output array. */
wsptr = workspace; wsptr = workspace;
@@ -335,37 +335,37 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) { if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3) JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
outptr[0] = dcval; outptr[0] = dcval;
outptr[1] = dcval; outptr[1] = dcval;
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
continue; continue;
} }
#endif #endif
/* Even part */ /* Even part */
tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2); tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
/* Odd part */ /* Odd part */
tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */ tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
+ MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */ + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
+ MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */ + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
+ MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */ + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
/* Final output stage */ /* Final output stage */
outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0, outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
CONST_BITS+PASS1_BITS+3+2) CONST_BITS+PASS1_BITS+3+2)
& RANGE_MASK]; & RANGE_MASK];
outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0, outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
CONST_BITS+PASS1_BITS+3+2) CONST_BITS+PASS1_BITS+3+2)
& RANGE_MASK]; & RANGE_MASK];
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
} }
} }
@@ -377,8 +377,8 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
GLOBAL(void) GLOBAL(void)
jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr, jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col) JSAMPARRAY output_buf, JDIMENSION output_col)
{ {
int dcval; int dcval;
ISLOW_MULT_TYPE * quantptr; ISLOW_MULT_TYPE * quantptr;

View File

@@ -17,8 +17,8 @@
/* Include auto-config file to find out which system include files we need. */ /* Include auto-config file to find out which system include files we need. */
#include "jconfig.h" /* auto configuration options */ #include "jconfig.h" /* auto configuration options */
#define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */ #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
/* /*
* We need the NULL macro and size_t typedef. * We need the NULL macro and size_t typedef.
@@ -58,14 +58,14 @@
#ifdef NEED_BSD_STRINGS #ifdef NEED_BSD_STRINGS
#include <strings.h> #include <strings.h>
#define MEMZERO(target,size) bzero((void *)(target), (size_t)(size)) #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
#define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size)) #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
#else /* not BSD, assume ANSI/SysV string lib */ #else /* not BSD, assume ANSI/SysV string lib */
#include <string.h> #include <string.h>
#define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size)) #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
#define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
#endif #endif
@@ -77,7 +77,7 @@
* we always use this SIZEOF() macro in place of using sizeof() directly. * we always use this SIZEOF() macro in place of using sizeof() directly.
*/ */
#define SIZEOF(object) ((size_t) sizeof(object)) #define SIZEOF(object) ((size_t) sizeof(object))
/* /*
* The modules that use fread() and fwrite() always invoke them through * The modules that use fread() and fwrite() always invoke them through

324
jmemmgr.c
View File

@@ -25,13 +25,13 @@
*/ */
#define JPEG_INTERNALS #define JPEG_INTERNALS
#define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */ #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jmemsys.h" /* import the system-dependent declarations */ #include "jmemsys.h" /* import the system-dependent declarations */
#ifndef NO_GETENV #ifndef NO_GETENV
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
extern char * getenv JPP((const char * name)); extern char * getenv JPP((const char * name));
#endif #endif
#endif #endif
@@ -78,7 +78,7 @@ round_up_pow2 (size_t a, size_t b)
* such a compiler. * such a compiler.
*/ */
#ifndef ALIGN_SIZE /* so can override from jconfig.h */ #ifndef ALIGN_SIZE /* so can override from jconfig.h */
#ifndef WITH_SIMD #ifndef WITH_SIMD
#define ALIGN_SIZE SIZEOF(double) #define ALIGN_SIZE SIZEOF(double)
#else #else
@@ -98,17 +98,17 @@ round_up_pow2 (size_t a, size_t b)
typedef struct small_pool_struct * small_pool_ptr; typedef struct small_pool_struct * small_pool_ptr;
typedef struct small_pool_struct { typedef struct small_pool_struct {
small_pool_ptr next; /* next in list of pools */ small_pool_ptr next; /* next in list of pools */
size_t bytes_used; /* how many bytes already used within pool */ size_t bytes_used; /* how many bytes already used within pool */
size_t bytes_left; /* bytes still available in this pool */ size_t bytes_left; /* bytes still available in this pool */
} small_pool_hdr; } small_pool_hdr;
typedef struct large_pool_struct FAR * large_pool_ptr; typedef struct large_pool_struct FAR * large_pool_ptr;
typedef struct large_pool_struct { typedef struct large_pool_struct {
large_pool_ptr next; /* next in list of pools */ large_pool_ptr next; /* next in list of pools */
size_t bytes_used; /* how many bytes already used within pool */ size_t bytes_used; /* how many bytes already used within pool */
size_t bytes_left; /* bytes still available in this pool */ size_t bytes_left; /* bytes still available in this pool */
} large_pool_hdr; } large_pool_hdr;
/* /*
@@ -116,7 +116,7 @@ typedef struct large_pool_struct {
*/ */
typedef struct { typedef struct {
struct jpeg_memory_mgr pub; /* public fields */ struct jpeg_memory_mgr pub; /* public fields */
/* Each pool identifier (lifetime class) names a linked list of pools. */ /* Each pool identifier (lifetime class) names a linked list of pools. */
small_pool_ptr small_list[JPOOL_NUMPOOLS]; small_pool_ptr small_list[JPOOL_NUMPOOLS];
@@ -136,7 +136,7 @@ typedef struct {
/* alloc_sarray and alloc_barray set this value for use by virtual /* alloc_sarray and alloc_barray set this value for use by virtual
* array routines. * array routines.
*/ */
JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */ JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
} my_memory_mgr; } my_memory_mgr;
typedef my_memory_mgr * my_mem_ptr; typedef my_memory_mgr * my_mem_ptr;
@@ -150,39 +150,39 @@ typedef my_memory_mgr * my_mem_ptr;
*/ */
struct jvirt_sarray_control { struct jvirt_sarray_control {
JSAMPARRAY mem_buffer; /* => the in-memory buffer */ JSAMPARRAY mem_buffer; /* => the in-memory buffer */
JDIMENSION rows_in_array; /* total virtual array height */ JDIMENSION rows_in_array; /* total virtual array height */
JDIMENSION samplesperrow; /* width of array (and of memory buffer) */ JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */ JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
JDIMENSION rows_in_mem; /* height of memory buffer */ JDIMENSION rows_in_mem; /* height of memory buffer */
JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */ JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
JDIMENSION cur_start_row; /* first logical row # in the buffer */ JDIMENSION cur_start_row; /* first logical row # in the buffer */
JDIMENSION first_undef_row; /* row # of first uninitialized row */ JDIMENSION first_undef_row; /* row # of first uninitialized row */
boolean pre_zero; /* pre-zero mode requested? */ boolean pre_zero; /* pre-zero mode requested? */
boolean dirty; /* do current buffer contents need written? */ boolean dirty; /* do current buffer contents need written? */
boolean b_s_open; /* is backing-store data valid? */ boolean b_s_open; /* is backing-store data valid? */
jvirt_sarray_ptr next; /* link to next virtual sarray control block */ jvirt_sarray_ptr next; /* link to next virtual sarray control block */
backing_store_info b_s_info; /* System-dependent control info */ backing_store_info b_s_info; /* System-dependent control info */
}; };
struct jvirt_barray_control { struct jvirt_barray_control {
JBLOCKARRAY mem_buffer; /* => the in-memory buffer */ JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
JDIMENSION rows_in_array; /* total virtual array height */ JDIMENSION rows_in_array; /* total virtual array height */
JDIMENSION blocksperrow; /* width of array (and of memory buffer) */ JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */ JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
JDIMENSION rows_in_mem; /* height of memory buffer */ JDIMENSION rows_in_mem; /* height of memory buffer */
JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */ JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
JDIMENSION cur_start_row; /* first logical row # in the buffer */ JDIMENSION cur_start_row; /* first logical row # in the buffer */
JDIMENSION first_undef_row; /* row # of first uninitialized row */ JDIMENSION first_undef_row; /* row # of first uninitialized row */
boolean pre_zero; /* pre-zero mode requested? */ boolean pre_zero; /* pre-zero mode requested? */
boolean dirty; /* do current buffer contents need written? */ boolean dirty; /* do current buffer contents need written? */
boolean b_s_open; /* is backing-store data valid? */ boolean b_s_open; /* is backing-store data valid? */
jvirt_barray_ptr next; /* link to next virtual barray control block */ jvirt_barray_ptr next; /* link to next virtual barray control block */
backing_store_info b_s_info; /* System-dependent control info */ backing_store_info b_s_info; /* System-dependent control info */
}; };
#ifdef MEM_STATS /* optional extra stuff for statistics */ #ifdef MEM_STATS /* optional extra stuff for statistics */
LOCAL(void) LOCAL(void)
print_mem_stats (j_common_ptr cinfo, int pool_id) print_mem_stats (j_common_ptr cinfo, int pool_id)
@@ -196,19 +196,19 @@ print_mem_stats (j_common_ptr cinfo, int pool_id)
* This is helpful because message parm array can't handle longs. * This is helpful because message parm array can't handle longs.
*/ */
fprintf(stderr, "Freeing pool %d, total space = %ld\n", fprintf(stderr, "Freeing pool %d, total space = %ld\n",
pool_id, mem->total_space_allocated); pool_id, mem->total_space_allocated);
for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL; for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
lhdr_ptr = lhdr_ptr->next) { lhdr_ptr = lhdr_ptr->next) {
fprintf(stderr, " Large chunk used %ld\n", fprintf(stderr, " Large chunk used %ld\n",
(long) lhdr_ptr->bytes_used); (long) lhdr_ptr->bytes_used);
} }
for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL; for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
shdr_ptr = shdr_ptr->next) { shdr_ptr = shdr_ptr->next) {
fprintf(stderr, " Small chunk used %ld free %ld\n", fprintf(stderr, " Small chunk used %ld free %ld\n",
(long) shdr_ptr->bytes_used, (long) shdr_ptr->bytes_used,
(long) shdr_ptr->bytes_left); (long) shdr_ptr->bytes_left);
} }
} }
@@ -221,7 +221,7 @@ out_of_memory (j_common_ptr cinfo, int which)
/* If we compiled MEM_STATS support, report alloc requests before dying */ /* If we compiled MEM_STATS support, report alloc requests before dying */
{ {
#ifdef MEM_STATS #ifdef MEM_STATS
cinfo->err->trace_level = 2; /* force self_destruct to report stats */ cinfo->err->trace_level = 2; /* force self_destruct to report stats */
#endif #endif
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which); ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
} }
@@ -244,19 +244,19 @@ out_of_memory (j_common_ptr cinfo, int which)
* adjustment. * adjustment.
*/ */
static const size_t first_pool_slop[JPOOL_NUMPOOLS] = static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
{ {
1600, /* first PERMANENT pool */ 1600, /* first PERMANENT pool */
16000 /* first IMAGE pool */ 16000 /* first IMAGE pool */
}; };
static const size_t extra_pool_slop[JPOOL_NUMPOOLS] = static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
{ {
0, /* additional PERMANENT pools */ 0, /* additional PERMANENT pools */
5000 /* additional IMAGE pools */ 5000 /* additional IMAGE pools */
}; };
#define MIN_SLOP 50 /* greater than 0 to avoid futile looping */ #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
METHODDEF(void *) METHODDEF(void *)
@@ -278,16 +278,16 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
/* Check for unsatisfiable request (do now to ensure no overflow below) */ /* Check for unsatisfiable request (do now to ensure no overflow below) */
if ((SIZEOF(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK) if ((SIZEOF(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK)
out_of_memory(cinfo, 1); /* request exceeds malloc's ability */ out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
/* See if space is available in any existing pool */ /* See if space is available in any existing pool */
if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS) if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
prev_hdr_ptr = NULL; prev_hdr_ptr = NULL;
hdr_ptr = mem->small_list[pool_id]; hdr_ptr = mem->small_list[pool_id];
while (hdr_ptr != NULL) { while (hdr_ptr != NULL) {
if (hdr_ptr->bytes_left >= sizeofobject) if (hdr_ptr->bytes_left >= sizeofobject)
break; /* found pool with enough space */ break; /* found pool with enough space */
prev_hdr_ptr = hdr_ptr; prev_hdr_ptr = hdr_ptr;
hdr_ptr = hdr_ptr->next; hdr_ptr = hdr_ptr->next;
} }
@@ -296,7 +296,7 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
if (hdr_ptr == NULL) { if (hdr_ptr == NULL) {
/* min_request is what we need now, slop is what will be leftover */ /* min_request is what we need now, slop is what will be leftover */
min_request = SIZEOF(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1; min_request = SIZEOF(small_pool_hdr) + sizeofobject + ALIGN_SIZE - 1;
if (prev_hdr_ptr == NULL) /* first pool in class? */ if (prev_hdr_ptr == NULL) /* first pool in class? */
slop = first_pool_slop[pool_id]; slop = first_pool_slop[pool_id];
else else
slop = extra_pool_slop[pool_id]; slop = extra_pool_slop[pool_id];
@@ -307,17 +307,17 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
for (;;) { for (;;) {
hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop); hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
if (hdr_ptr != NULL) if (hdr_ptr != NULL)
break; break;
slop /= 2; slop /= 2;
if (slop < MIN_SLOP) /* give up when it gets real small */ if (slop < MIN_SLOP) /* give up when it gets real small */
out_of_memory(cinfo, 2); /* jpeg_get_small failed */ out_of_memory(cinfo, 2); /* jpeg_get_small failed */
} }
mem->total_space_allocated += min_request + slop; mem->total_space_allocated += min_request + slop;
/* Success, initialize the new pool header and add to end of list */ /* Success, initialize the new pool header and add to end of list */
hdr_ptr->next = NULL; hdr_ptr->next = NULL;
hdr_ptr->bytes_used = 0; hdr_ptr->bytes_used = 0;
hdr_ptr->bytes_left = sizeofobject + slop; hdr_ptr->bytes_left = sizeofobject + slop;
if (prev_hdr_ptr == NULL) /* first pool in class? */ if (prev_hdr_ptr == NULL) /* first pool in class? */
mem->small_list[pool_id] = hdr_ptr; mem->small_list[pool_id] = hdr_ptr;
else else
prev_hdr_ptr->next = hdr_ptr; prev_hdr_ptr->next = hdr_ptr;
@@ -367,17 +367,17 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
/* Check for unsatisfiable request (do now to ensure no overflow below) */ /* Check for unsatisfiable request (do now to ensure no overflow below) */
if ((SIZEOF(large_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK) if ((SIZEOF(large_pool_hdr) + sizeofobject + ALIGN_SIZE - 1) > MAX_ALLOC_CHUNK)
out_of_memory(cinfo, 3); /* request exceeds malloc's ability */ out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
/* Always make a new pool */ /* Always make a new pool */
if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS) if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject + hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
SIZEOF(large_pool_hdr) + SIZEOF(large_pool_hdr) +
ALIGN_SIZE - 1); ALIGN_SIZE - 1);
if (hdr_ptr == NULL) if (hdr_ptr == NULL)
out_of_memory(cinfo, 4); /* jpeg_get_large failed */ out_of_memory(cinfo, 4); /* jpeg_get_large failed */
mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr) + ALIGN_SIZE - 1; mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr) + ALIGN_SIZE - 1;
/* Success, initialize the new pool header and add to list */ /* Success, initialize the new pool header and add to list */
@@ -417,7 +417,7 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
METHODDEF(JSAMPARRAY) METHODDEF(JSAMPARRAY)
alloc_sarray (j_common_ptr cinfo, int pool_id, alloc_sarray (j_common_ptr cinfo, int pool_id,
JDIMENSION samplesperrow, JDIMENSION numrows) JDIMENSION samplesperrow, JDIMENSION numrows)
/* Allocate a 2-D sample array */ /* Allocate a 2-D sample array */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
@@ -428,12 +428,12 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
/* Make sure each row is properly aligned */ /* Make sure each row is properly aligned */
if ((ALIGN_SIZE % SIZEOF(JSAMPLE)) != 0) if ((ALIGN_SIZE % SIZEOF(JSAMPLE)) != 0)
out_of_memory(cinfo, 5); /* safety check */ out_of_memory(cinfo, 5); /* safety check */
samplesperrow = (JDIMENSION)round_up_pow2(samplesperrow, (2 * ALIGN_SIZE) / SIZEOF(JSAMPLE)); samplesperrow = (JDIMENSION)round_up_pow2(samplesperrow, (2 * ALIGN_SIZE) / SIZEOF(JSAMPLE));
/* Calculate max # of rows allowed in one allocation chunk */ /* Calculate max # of rows allowed in one allocation chunk */
ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) / ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
((long) samplesperrow * SIZEOF(JSAMPLE)); ((long) samplesperrow * SIZEOF(JSAMPLE));
if (ltemp <= 0) if (ltemp <= 0)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
if (ltemp < (long) numrows) if (ltemp < (long) numrows)
@@ -444,15 +444,15 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
/* Get space for row pointers (small object) */ /* Get space for row pointers (small object) */
result = (JSAMPARRAY) alloc_small(cinfo, pool_id, result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
(size_t) (numrows * SIZEOF(JSAMPROW))); (size_t) (numrows * SIZEOF(JSAMPROW)));
/* Get the rows themselves (large objects) */ /* Get the rows themselves (large objects) */
currow = 0; currow = 0;
while (currow < numrows) { while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow); rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace = (JSAMPROW) alloc_large(cinfo, pool_id, workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
(size_t) ((size_t) rowsperchunk * (size_t) samplesperrow (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
* SIZEOF(JSAMPLE))); * SIZEOF(JSAMPLE)));
for (i = rowsperchunk; i > 0; i--) { for (i = rowsperchunk; i > 0; i--) {
result[currow++] = workspace; result[currow++] = workspace;
workspace += samplesperrow; workspace += samplesperrow;
@@ -470,7 +470,7 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
METHODDEF(JBLOCKARRAY) METHODDEF(JBLOCKARRAY)
alloc_barray (j_common_ptr cinfo, int pool_id, alloc_barray (j_common_ptr cinfo, int pool_id,
JDIMENSION blocksperrow, JDIMENSION numrows) JDIMENSION blocksperrow, JDIMENSION numrows)
/* Allocate a 2-D coefficient-block array */ /* Allocate a 2-D coefficient-block array */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
@@ -481,11 +481,11 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
/* Make sure each row is properly aligned */ /* Make sure each row is properly aligned */
if ((SIZEOF(JBLOCK) % ALIGN_SIZE) != 0) if ((SIZEOF(JBLOCK) % ALIGN_SIZE) != 0)
out_of_memory(cinfo, 6); /* safety check */ out_of_memory(cinfo, 6); /* safety check */
/* Calculate max # of rows allowed in one allocation chunk */ /* Calculate max # of rows allowed in one allocation chunk */
ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) / ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
((long) blocksperrow * SIZEOF(JBLOCK)); ((long) blocksperrow * SIZEOF(JBLOCK));
if (ltemp <= 0) if (ltemp <= 0)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
if (ltemp < (long) numrows) if (ltemp < (long) numrows)
@@ -496,15 +496,15 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
/* Get space for row pointers (small object) */ /* Get space for row pointers (small object) */
result = (JBLOCKARRAY) alloc_small(cinfo, pool_id, result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
(size_t) (numrows * SIZEOF(JBLOCKROW))); (size_t) (numrows * SIZEOF(JBLOCKROW)));
/* Get the rows themselves (large objects) */ /* Get the rows themselves (large objects) */
currow = 0; currow = 0;
while (currow < numrows) { while (currow < numrows) {
rowsperchunk = MIN(rowsperchunk, numrows - currow); rowsperchunk = MIN(rowsperchunk, numrows - currow);
workspace = (JBLOCKROW) alloc_large(cinfo, pool_id, workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
(size_t) ((size_t) rowsperchunk * (size_t) blocksperrow (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
* SIZEOF(JBLOCK))); * SIZEOF(JBLOCK)));
for (i = rowsperchunk; i > 0; i--) { for (i = rowsperchunk; i > 0; i--) {
result[currow++] = workspace; result[currow++] = workspace;
workspace += blocksperrow; workspace += blocksperrow;
@@ -554,8 +554,8 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
METHODDEF(jvirt_sarray_ptr) METHODDEF(jvirt_sarray_ptr)
request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero, request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
JDIMENSION samplesperrow, JDIMENSION numrows, JDIMENSION samplesperrow, JDIMENSION numrows,
JDIMENSION maxaccess) JDIMENSION maxaccess)
/* Request a virtual 2-D sample array */ /* Request a virtual 2-D sample array */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
@@ -563,18 +563,18 @@ request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
/* Only IMAGE-lifetime virtual arrays are currently supported */ /* Only IMAGE-lifetime virtual arrays are currently supported */
if (pool_id != JPOOL_IMAGE) if (pool_id != JPOOL_IMAGE)
ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
/* get control block */ /* get control block */
result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id, result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
SIZEOF(struct jvirt_sarray_control)); SIZEOF(struct jvirt_sarray_control));
result->mem_buffer = NULL; /* marks array not yet realized */ result->mem_buffer = NULL; /* marks array not yet realized */
result->rows_in_array = numrows; result->rows_in_array = numrows;
result->samplesperrow = samplesperrow; result->samplesperrow = samplesperrow;
result->maxaccess = maxaccess; result->maxaccess = maxaccess;
result->pre_zero = pre_zero; result->pre_zero = pre_zero;
result->b_s_open = FALSE; /* no associated backing-store object */ result->b_s_open = FALSE; /* no associated backing-store object */
result->next = mem->virt_sarray_list; /* add to list of virtual arrays */ result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
mem->virt_sarray_list = result; mem->virt_sarray_list = result;
@@ -584,8 +584,8 @@ request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
METHODDEF(jvirt_barray_ptr) METHODDEF(jvirt_barray_ptr)
request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero, request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
JDIMENSION blocksperrow, JDIMENSION numrows, JDIMENSION blocksperrow, JDIMENSION numrows,
JDIMENSION maxaccess) JDIMENSION maxaccess)
/* Request a virtual 2-D coefficient-block array */ /* Request a virtual 2-D coefficient-block array */
{ {
my_mem_ptr mem = (my_mem_ptr) cinfo->mem; my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
@@ -593,18 +593,18 @@ request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
/* Only IMAGE-lifetime virtual arrays are currently supported */ /* Only IMAGE-lifetime virtual arrays are currently supported */
if (pool_id != JPOOL_IMAGE) if (pool_id != JPOOL_IMAGE)
ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
/* get control block */ /* get control block */
result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id, result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
SIZEOF(struct jvirt_barray_control)); SIZEOF(struct jvirt_barray_control));
result->mem_buffer = NULL; /* marks array not yet realized */ result->mem_buffer = NULL; /* marks array not yet realized */
result->rows_in_array = numrows; result->rows_in_array = numrows;
result->blocksperrow = blocksperrow; result->blocksperrow = blocksperrow;
result->maxaccess = maxaccess; result->maxaccess = maxaccess;
result->pre_zero = pre_zero; result->pre_zero = pre_zero;
result->b_s_open = FALSE; /* no associated backing-store object */ result->b_s_open = FALSE; /* no associated backing-store object */
result->next = mem->virt_barray_list; /* add to list of virtual arrays */ result->next = mem->virt_barray_list; /* add to list of virtual arrays */
mem->virt_barray_list = result; mem->virt_barray_list = result;
@@ -631,26 +631,26 @@ realize_virt_arrays (j_common_ptr cinfo)
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
if (sptr->mem_buffer == NULL) { /* if not realized yet */ if (sptr->mem_buffer == NULL) { /* if not realized yet */
space_per_minheight += (long) sptr->maxaccess * space_per_minheight += (long) sptr->maxaccess *
(long) sptr->samplesperrow * SIZEOF(JSAMPLE); (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
maximum_space += (long) sptr->rows_in_array * maximum_space += (long) sptr->rows_in_array *
(long) sptr->samplesperrow * SIZEOF(JSAMPLE); (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
} }
} }
for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
if (bptr->mem_buffer == NULL) { /* if not realized yet */ if (bptr->mem_buffer == NULL) { /* if not realized yet */
space_per_minheight += (long) bptr->maxaccess * space_per_minheight += (long) bptr->maxaccess *
(long) bptr->blocksperrow * SIZEOF(JBLOCK); (long) bptr->blocksperrow * SIZEOF(JBLOCK);
maximum_space += (long) bptr->rows_in_array * maximum_space += (long) bptr->rows_in_array *
(long) bptr->blocksperrow * SIZEOF(JBLOCK); (long) bptr->blocksperrow * SIZEOF(JBLOCK);
} }
} }
if (space_per_minheight <= 0) if (space_per_minheight <= 0)
return; /* no unrealized arrays, no work */ return; /* no unrealized arrays, no work */
/* Determine amount of memory to actually use; this is system-dependent. */ /* Determine amount of memory to actually use; this is system-dependent. */
avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space, avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
mem->total_space_allocated); mem->total_space_allocated);
/* If the maximum space needed is available, make all the buffers full /* If the maximum space needed is available, make all the buffers full
* height; otherwise parcel it out with the same number of minheights * height; otherwise parcel it out with the same number of minheights
@@ -673,19 +673,19 @@ realize_virt_arrays (j_common_ptr cinfo)
if (sptr->mem_buffer == NULL) { /* if not realized yet */ if (sptr->mem_buffer == NULL) { /* if not realized yet */
minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L; minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
if (minheights <= max_minheights) { if (minheights <= max_minheights) {
/* This buffer fits in memory */ /* This buffer fits in memory */
sptr->rows_in_mem = sptr->rows_in_array; sptr->rows_in_mem = sptr->rows_in_array;
} else { } else {
/* It doesn't fit in memory, create backing store. */ /* It doesn't fit in memory, create backing store. */
sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess); sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
jpeg_open_backing_store(cinfo, & sptr->b_s_info, jpeg_open_backing_store(cinfo, & sptr->b_s_info,
(long) sptr->rows_in_array * (long) sptr->rows_in_array *
(long) sptr->samplesperrow * (long) sptr->samplesperrow *
(long) SIZEOF(JSAMPLE)); (long) SIZEOF(JSAMPLE));
sptr->b_s_open = TRUE; sptr->b_s_open = TRUE;
} }
sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE, sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
sptr->samplesperrow, sptr->rows_in_mem); sptr->samplesperrow, sptr->rows_in_mem);
sptr->rowsperchunk = mem->last_rowsperchunk; sptr->rowsperchunk = mem->last_rowsperchunk;
sptr->cur_start_row = 0; sptr->cur_start_row = 0;
sptr->first_undef_row = 0; sptr->first_undef_row = 0;
@@ -697,19 +697,19 @@ realize_virt_arrays (j_common_ptr cinfo)
if (bptr->mem_buffer == NULL) { /* if not realized yet */ if (bptr->mem_buffer == NULL) { /* if not realized yet */
minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L; minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
if (minheights <= max_minheights) { if (minheights <= max_minheights) {
/* This buffer fits in memory */ /* This buffer fits in memory */
bptr->rows_in_mem = bptr->rows_in_array; bptr->rows_in_mem = bptr->rows_in_array;
} else { } else {
/* It doesn't fit in memory, create backing store. */ /* It doesn't fit in memory, create backing store. */
bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess); bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
jpeg_open_backing_store(cinfo, & bptr->b_s_info, jpeg_open_backing_store(cinfo, & bptr->b_s_info,
(long) bptr->rows_in_array * (long) bptr->rows_in_array *
(long) bptr->blocksperrow * (long) bptr->blocksperrow *
(long) SIZEOF(JBLOCK)); (long) SIZEOF(JBLOCK));
bptr->b_s_open = TRUE; bptr->b_s_open = TRUE;
} }
bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE, bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
bptr->blocksperrow, bptr->rows_in_mem); bptr->blocksperrow, bptr->rows_in_mem);
bptr->rowsperchunk = mem->last_rowsperchunk; bptr->rowsperchunk = mem->last_rowsperchunk;
bptr->cur_start_row = 0; bptr->cur_start_row = 0;
bptr->first_undef_row = 0; bptr->first_undef_row = 0;
@@ -736,17 +736,17 @@ do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
rows = MIN(rows, (long) ptr->first_undef_row - thisrow); rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
/* Transfer no more than fits in file */ /* Transfer no more than fits in file */
rows = MIN(rows, (long) ptr->rows_in_array - thisrow); rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
if (rows <= 0) /* this chunk might be past end of file! */ if (rows <= 0) /* this chunk might be past end of file! */
break; break;
byte_count = rows * bytesperrow; byte_count = rows * bytesperrow;
if (writing) if (writing)
(*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info, (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
(void FAR *) ptr->mem_buffer[i], (void FAR *) ptr->mem_buffer[i],
file_offset, byte_count); file_offset, byte_count);
else else
(*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info, (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
(void FAR *) ptr->mem_buffer[i], (void FAR *) ptr->mem_buffer[i],
file_offset, byte_count); file_offset, byte_count);
file_offset += byte_count; file_offset += byte_count;
} }
} }
@@ -769,17 +769,17 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
rows = MIN(rows, (long) ptr->first_undef_row - thisrow); rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
/* Transfer no more than fits in file */ /* Transfer no more than fits in file */
rows = MIN(rows, (long) ptr->rows_in_array - thisrow); rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
if (rows <= 0) /* this chunk might be past end of file! */ if (rows <= 0) /* this chunk might be past end of file! */
break; break;
byte_count = rows * bytesperrow; byte_count = rows * bytesperrow;
if (writing) if (writing)
(*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info, (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
(void FAR *) ptr->mem_buffer[i], (void FAR *) ptr->mem_buffer[i],
file_offset, byte_count); file_offset, byte_count);
else else
(*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info, (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
(void FAR *) ptr->mem_buffer[i], (void FAR *) ptr->mem_buffer[i],
file_offset, byte_count); file_offset, byte_count);
file_offset += byte_count; file_offset += byte_count;
} }
} }
@@ -787,8 +787,8 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
METHODDEF(JSAMPARRAY) METHODDEF(JSAMPARRAY)
access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr, access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
JDIMENSION start_row, JDIMENSION num_rows, JDIMENSION start_row, JDIMENSION num_rows,
boolean writable) boolean writable)
/* Access the part of a virtual sample array starting at start_row */ /* Access the part of a virtual sample array starting at start_row */
/* and extending for num_rows rows. writable is true if */ /* and extending for num_rows rows. writable is true if */
/* caller intends to modify the accessed area. */ /* caller intends to modify the accessed area. */
@@ -826,7 +826,7 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
ltemp = (long) end_row - (long) ptr->rows_in_mem; ltemp = (long) end_row - (long) ptr->rows_in_mem;
if (ltemp < 0) if (ltemp < 0)
ltemp = 0; /* don't fall off front end of file */ ltemp = 0; /* don't fall off front end of file */
ptr->cur_start_row = (JDIMENSION) ltemp; ptr->cur_start_row = (JDIMENSION) ltemp;
} }
/* Read in the selected part of the array. /* Read in the selected part of the array.
@@ -841,9 +841,9 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
*/ */
if (ptr->first_undef_row < end_row) { if (ptr->first_undef_row < end_row) {
if (ptr->first_undef_row < start_row) { if (ptr->first_undef_row < start_row) {
if (writable) /* writer skipped over a section of array */ if (writable) /* writer skipped over a section of array */
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
undef_row = start_row; /* but reader is allowed to read ahead */ undef_row = start_row; /* but reader is allowed to read ahead */
} else { } else {
undef_row = ptr->first_undef_row; undef_row = ptr->first_undef_row;
} }
@@ -854,12 +854,12 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
end_row -= ptr->cur_start_row; end_row -= ptr->cur_start_row;
while (undef_row < end_row) { while (undef_row < end_row) {
jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow); jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
undef_row++; undef_row++;
} }
} else { } else {
if (! writable) /* reader looking at undefined data */ if (! writable) /* reader looking at undefined data */
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
} }
} }
/* Flag the buffer dirty if caller will write in it */ /* Flag the buffer dirty if caller will write in it */
@@ -872,8 +872,8 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
METHODDEF(JBLOCKARRAY) METHODDEF(JBLOCKARRAY)
access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr, access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
JDIMENSION start_row, JDIMENSION num_rows, JDIMENSION start_row, JDIMENSION num_rows,
boolean writable) boolean writable)
/* Access the part of a virtual block array starting at start_row */ /* Access the part of a virtual block array starting at start_row */
/* and extending for num_rows rows. writable is true if */ /* and extending for num_rows rows. writable is true if */
/* caller intends to modify the accessed area. */ /* caller intends to modify the accessed area. */
@@ -911,7 +911,7 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
ltemp = (long) end_row - (long) ptr->rows_in_mem; ltemp = (long) end_row - (long) ptr->rows_in_mem;
if (ltemp < 0) if (ltemp < 0)
ltemp = 0; /* don't fall off front end of file */ ltemp = 0; /* don't fall off front end of file */
ptr->cur_start_row = (JDIMENSION) ltemp; ptr->cur_start_row = (JDIMENSION) ltemp;
} }
/* Read in the selected part of the array. /* Read in the selected part of the array.
@@ -926,9 +926,9 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
*/ */
if (ptr->first_undef_row < end_row) { if (ptr->first_undef_row < end_row) {
if (ptr->first_undef_row < start_row) { if (ptr->first_undef_row < start_row) {
if (writable) /* writer skipped over a section of array */ if (writable) /* writer skipped over a section of array */
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
undef_row = start_row; /* but reader is allowed to read ahead */ undef_row = start_row; /* but reader is allowed to read ahead */
} else { } else {
undef_row = ptr->first_undef_row; undef_row = ptr->first_undef_row;
} }
@@ -939,12 +939,12 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
end_row -= ptr->cur_start_row; end_row -= ptr->cur_start_row;
while (undef_row < end_row) { while (undef_row < end_row) {
jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow); jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
undef_row++; undef_row++;
} }
} else { } else {
if (! writable) /* reader looking at undefined data */ if (! writable) /* reader looking at undefined data */
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS); ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
} }
} }
/* Flag the buffer dirty if caller will write in it */ /* Flag the buffer dirty if caller will write in it */
@@ -968,7 +968,7 @@ free_pool (j_common_ptr cinfo, int pool_id)
size_t space_freed; size_t space_freed;
if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS) if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */ ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
#ifdef MEM_STATS #ifdef MEM_STATS
if (cinfo->err->trace_level > 1) if (cinfo->err->trace_level > 1)
@@ -981,16 +981,16 @@ free_pool (j_common_ptr cinfo, int pool_id)
jvirt_barray_ptr bptr; jvirt_barray_ptr bptr;
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) { for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
if (sptr->b_s_open) { /* there may be no backing store */ if (sptr->b_s_open) { /* there may be no backing store */
sptr->b_s_open = FALSE; /* prevent recursive close if error */ sptr->b_s_open = FALSE; /* prevent recursive close if error */
(*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info); (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
} }
} }
mem->virt_sarray_list = NULL; mem->virt_sarray_list = NULL;
for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) { for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
if (bptr->b_s_open) { /* there may be no backing store */ if (bptr->b_s_open) { /* there may be no backing store */
bptr->b_s_open = FALSE; /* prevent recursive close if error */ bptr->b_s_open = FALSE; /* prevent recursive close if error */
(*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info); (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
} }
} }
mem->virt_barray_list = NULL; mem->virt_barray_list = NULL;
@@ -1003,8 +1003,8 @@ free_pool (j_common_ptr cinfo, int pool_id)
while (lhdr_ptr != NULL) { while (lhdr_ptr != NULL) {
large_pool_ptr next_lhdr_ptr = lhdr_ptr->next; large_pool_ptr next_lhdr_ptr = lhdr_ptr->next;
space_freed = lhdr_ptr->bytes_used + space_freed = lhdr_ptr->bytes_used +
lhdr_ptr->bytes_left + lhdr_ptr->bytes_left +
SIZEOF(large_pool_hdr); SIZEOF(large_pool_hdr);
jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed); jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
mem->total_space_allocated -= space_freed; mem->total_space_allocated -= space_freed;
lhdr_ptr = next_lhdr_ptr; lhdr_ptr = next_lhdr_ptr;
@@ -1017,8 +1017,8 @@ free_pool (j_common_ptr cinfo, int pool_id)
while (shdr_ptr != NULL) { while (shdr_ptr != NULL) {
small_pool_ptr next_shdr_ptr = shdr_ptr->next; small_pool_ptr next_shdr_ptr = shdr_ptr->next;
space_freed = shdr_ptr->bytes_used + space_freed = shdr_ptr->bytes_used +
shdr_ptr->bytes_left + shdr_ptr->bytes_left +
SIZEOF(small_pool_hdr); SIZEOF(small_pool_hdr);
jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed); jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
mem->total_space_allocated -= space_freed; mem->total_space_allocated -= space_freed;
shdr_ptr = next_shdr_ptr; shdr_ptr = next_shdr_ptr;
@@ -1046,9 +1046,9 @@ self_destruct (j_common_ptr cinfo)
/* Release the memory manager control block too. */ /* Release the memory manager control block too. */
jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr)); jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
cinfo->mem = NULL; /* ensures I will be called only once */ cinfo->mem = NULL; /* ensures I will be called only once */
jpeg_mem_term(cinfo); /* system-dependent cleanup */ jpeg_mem_term(cinfo); /* system-dependent cleanup */
} }
@@ -1065,7 +1065,7 @@ jinit_memory_mgr (j_common_ptr cinfo)
int pool; int pool;
size_t test_mac; size_t test_mac;
cinfo->mem = NULL; /* for safety if init fails */ cinfo->mem = NULL; /* for safety if init fails */
/* Check for configuration errors. /* Check for configuration errors.
* SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably
@@ -1092,7 +1092,7 @@ jinit_memory_mgr (j_common_ptr cinfo)
mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr)); mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
if (mem == NULL) { if (mem == NULL) {
jpeg_mem_term(cinfo); /* system-dependent cleanup */ jpeg_mem_term(cinfo); /* system-dependent cleanup */
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0); ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
} }
@@ -1140,9 +1140,9 @@ jinit_memory_mgr (j_common_ptr cinfo)
char ch = 'x'; char ch = 'x';
if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) { if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
if (ch == 'm' || ch == 'M') if (ch == 'm' || ch == 'M')
max_to_use *= 1000L; max_to_use *= 1000L;
mem->pub.max_memory_to_use = max_to_use * 1000L; mem->pub.max_memory_to_use = max_to_use * 1000L;
} }
} }
} }

View File

@@ -18,9 +18,9 @@
#define JPEG_INTERNALS #define JPEG_INTERNALS
#include "jinclude.h" #include "jinclude.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "jmemsys.h" /* import the system-dependent declarations */ #include "jmemsys.h" /* import the system-dependent declarations */
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
extern void * malloc JPP((size_t size)); extern void * malloc JPP((size_t size));
extern void free JPP((void *ptr)); extern void free JPP((void *ptr));
#endif #endif
@@ -71,7 +71,7 @@ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
GLOBAL(size_t) GLOBAL(size_t)
jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed, jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed,
size_t max_bytes_needed, size_t already_allocated) size_t max_bytes_needed, size_t already_allocated)
{ {
return max_bytes_needed; return max_bytes_needed;
} }
@@ -85,7 +85,7 @@ jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed,
GLOBAL(void) GLOBAL(void)
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
long total_bytes_needed) long total_bytes_needed)
{ {
ERREXIT(cinfo, JERR_NO_BACKING_STORE); ERREXIT(cinfo, JERR_NO_BACKING_STORE);
} }
@@ -99,7 +99,7 @@ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
GLOBAL(long) GLOBAL(long)
jpeg_mem_init (j_common_ptr cinfo) jpeg_mem_init (j_common_ptr cinfo)
{ {
return 0; /* just set max_memory_to_use to 0 */ return 0; /* just set max_memory_to_use to 0 */
} }
GLOBAL(void) GLOBAL(void)

View File

@@ -22,14 +22,14 @@
/* Short forms of external names for systems with brain-damaged linkers. */ /* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES #ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_get_small jGetSmall #define jpeg_get_small jGetSmall
#define jpeg_free_small jFreeSmall #define jpeg_free_small jFreeSmall
#define jpeg_get_large jGetLarge #define jpeg_get_large jGetLarge
#define jpeg_free_large jFreeLarge #define jpeg_free_large jFreeLarge
#define jpeg_mem_available jMemAvail #define jpeg_mem_available jMemAvail
#define jpeg_open_backing_store jOpenBackStore #define jpeg_open_backing_store jOpenBackStore
#define jpeg_mem_init jMemInit #define jpeg_mem_init jMemInit
#define jpeg_mem_term jMemTerm #define jpeg_mem_term jMemTerm
#endif /* NEED_SHORT_EXTERNAL_NAMES */ #endif /* NEED_SHORT_EXTERNAL_NAMES */
@@ -46,7 +46,7 @@
EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject)); EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object, EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
size_t sizeofobject)); size_t sizeofobject));
/* /*
* These two functions are used to allocate and release large chunks of * These two functions are used to allocate and release large chunks of
@@ -58,9 +58,9 @@ EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
*/ */
EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo, EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
size_t sizeofobject)); size_t sizeofobject));
EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object, EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
size_t sizeofobject)); size_t sizeofobject));
/* /*
* The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
@@ -74,7 +74,7 @@ EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
* size_t and will be a multiple of sizeof(align_type). * size_t and will be a multiple of sizeof(align_type).
*/ */
#ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */ #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
#define MAX_ALLOC_CHUNK 1000000000L #define MAX_ALLOC_CHUNK 1000000000L
#endif #endif
@@ -101,9 +101,9 @@ EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
*/ */
EXTERN(size_t) jpeg_mem_available JPP((j_common_ptr cinfo, EXTERN(size_t) jpeg_mem_available JPP((j_common_ptr cinfo,
size_t min_bytes_needed, size_t min_bytes_needed,
size_t max_bytes_needed, size_t max_bytes_needed,
size_t already_allocated)); size_t already_allocated));
/* /*
@@ -113,23 +113,23 @@ EXTERN(size_t) jpeg_mem_available JPP((j_common_ptr cinfo,
* are private to the system-dependent backing store routines. * are private to the system-dependent backing store routines.
*/ */
#define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */ #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
#ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */ #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
typedef unsigned short XMSH; /* type of extended-memory handles */ typedef unsigned short XMSH; /* type of extended-memory handles */
typedef unsigned short EMSH; /* type of expanded-memory handles */ typedef unsigned short EMSH; /* type of expanded-memory handles */
typedef union { typedef union {
short file_handle; /* DOS file handle if it's a temp file */ short file_handle; /* DOS file handle if it's a temp file */
XMSH xms_handle; /* handle if it's a chunk of XMS */ XMSH xms_handle; /* handle if it's a chunk of XMS */
EMSH ems_handle; /* handle if it's a chunk of EMS */ EMSH ems_handle; /* handle if it's a chunk of EMS */
} handle_union; } handle_union;
#endif /* USE_MSDOS_MEMMGR */ #endif /* USE_MSDOS_MEMMGR */
#ifdef USE_MAC_MEMMGR /* Mac-specific junk */ #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
#include <Files.h> #include <Files.h>
#endif /* USE_MAC_MEMMGR */ #endif /* USE_MAC_MEMMGR */
@@ -139,30 +139,30 @@ typedef struct backing_store_struct * backing_store_ptr;
typedef struct backing_store_struct { typedef struct backing_store_struct {
/* Methods for reading/writing/closing this backing-store object */ /* Methods for reading/writing/closing this backing-store object */
JMETHOD(void, read_backing_store, (j_common_ptr cinfo, JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
backing_store_ptr info, backing_store_ptr info,
void FAR * buffer_address, void FAR * buffer_address,
long file_offset, long byte_count)); long file_offset, long byte_count));
JMETHOD(void, write_backing_store, (j_common_ptr cinfo, JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
backing_store_ptr info, backing_store_ptr info,
void FAR * buffer_address, void FAR * buffer_address,
long file_offset, long byte_count)); long file_offset, long byte_count));
JMETHOD(void, close_backing_store, (j_common_ptr cinfo, JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
backing_store_ptr info)); backing_store_ptr info));
/* Private fields for system-dependent backing-store management */ /* Private fields for system-dependent backing-store management */
#ifdef USE_MSDOS_MEMMGR #ifdef USE_MSDOS_MEMMGR
/* For the MS-DOS manager (jmemdos.c), we need: */ /* For the MS-DOS manager (jmemdos.c), we need: */
handle_union handle; /* reference to backing-store storage object */ handle_union handle; /* reference to backing-store storage object */
char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
#else #else
#ifdef USE_MAC_MEMMGR #ifdef USE_MAC_MEMMGR
/* For the Mac manager (jmemmac.c), we need: */ /* For the Mac manager (jmemmac.c), we need: */
short temp_file; /* file reference number to temp file */ short temp_file; /* file reference number to temp file */
FSSpec tempSpec; /* the FSSpec for the temp file */ FSSpec tempSpec; /* the FSSpec for the temp file */
char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
#else #else
/* For a typical implementation with temp files, we need: */ /* For a typical implementation with temp files, we need: */
FILE * temp_file; /* stdio reference to temp file */ FILE * temp_file; /* stdio reference to temp file */
char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */ char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
#endif #endif
#endif #endif
@@ -178,8 +178,8 @@ typedef struct backing_store_struct {
*/ */
EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo, EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
backing_store_ptr info, backing_store_ptr info,
long total_bytes_needed)); long total_bytes_needed));
/* /*

View File

@@ -22,7 +22,7 @@
* We do not support run-time selection of data precision, sorry. * We do not support run-time selection of data precision, sorry.
*/ */
#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
/* /*
@@ -34,7 +34,7 @@
* bytes of storage, whether actually used in an image or not.) * bytes of storage, whether actually used in an image or not.)
*/ */
#define MAX_COMPONENTS 10 /* maximum number of image components */ #define MAX_COMPONENTS 10 /* maximum number of image components */
/* /*
@@ -72,8 +72,8 @@ typedef char JSAMPLE;
#endif /* HAVE_UNSIGNED_CHAR */ #endif /* HAVE_UNSIGNED_CHAR */
#define MAXJSAMPLE 255 #define MAXJSAMPLE 255
#define CENTERJSAMPLE 128 #define CENTERJSAMPLE 128
#endif /* BITS_IN_JSAMPLE == 8 */ #endif /* BITS_IN_JSAMPLE == 8 */
@@ -86,8 +86,8 @@ typedef char JSAMPLE;
typedef short JSAMPLE; typedef short JSAMPLE;
#define GETJSAMPLE(value) ((int) (value)) #define GETJSAMPLE(value) ((int) (value))
#define MAXJSAMPLE 4095 #define MAXJSAMPLE 4095
#define CENTERJSAMPLE 2048 #define CENTERJSAMPLE 2048
#endif /* BITS_IN_JSAMPLE == 12 */ #endif /* BITS_IN_JSAMPLE == 12 */
@@ -153,13 +153,13 @@ typedef unsigned int UINT16;
/* INT16 must hold at least the values -32768..32767. */ /* INT16 must hold at least the values -32768..32767. */
#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */ #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
typedef short INT16; typedef short INT16;
#endif #endif
/* INT32 must hold at least signed 32-bit values. */ /* INT32 must hold at least signed 32-bit values. */
#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */ #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
typedef long INT32; typedef long INT32;
#endif #endif
@@ -183,13 +183,13 @@ typedef unsigned int JDIMENSION;
*/ */
/* a function called through method pointers: */ /* a function called through method pointers: */
#define METHODDEF(type) static type #define METHODDEF(type) static type
/* a function used only in its module: */ /* a function used only in its module: */
#define LOCAL(type) static type #define LOCAL(type) static type
/* a function referenced thru EXTERNs: */ /* a function referenced thru EXTERNs: */
#define GLOBAL(type) type #define GLOBAL(type) type
/* a reference to a GLOBAL function: */ /* a reference to a GLOBAL function: */
#define EXTERN(type) extern type #define EXTERN(type) extern type
/* This macro is used to declare a "method", that is, a function pointer. /* This macro is used to declare a "method", that is, a function pointer.
@@ -231,11 +231,11 @@ typedef unsigned int JDIMENSION;
#ifndef HAVE_BOOLEAN #ifndef HAVE_BOOLEAN
typedef int boolean; typedef int boolean;
#endif #endif
#ifndef FALSE /* in case these macros already exist */ #ifndef FALSE /* in case these macros already exist */
#define FALSE 0 /* values of boolean */ #define FALSE 0 /* values of boolean */
#endif #endif
#ifndef TRUE #ifndef TRUE
#define TRUE 1 #define TRUE 1
#endif #endif
@@ -263,15 +263,15 @@ typedef int boolean;
/* Capability options common to encoder and decoder: */ /* Capability options common to encoder and decoder: */
#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */ #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */ #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */ #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
/* Encoder capability options: */ /* Encoder capability options: */
#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */ #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
/* Note: if you selected 12-bit data precision, it is dangerous to turn off /* Note: if you selected 12-bit data precision, it is dangerous to turn off
* ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
* precision, so jchuff.c normally uses entropy optimization to compute * precision, so jchuff.c normally uses entropy optimization to compute
@@ -285,14 +285,14 @@ typedef int boolean;
/* Decoder capability options: */ /* Decoder capability options: */
#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */ #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */ #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */ #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */ #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */ #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */ #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */ #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
/* more capability options later, no doubt */ /* more capability options later, no doubt */
@@ -312,10 +312,10 @@ typedef int boolean;
* can't use color quantization if you change that value. * can't use color quantization if you change that value.
*/ */
#define RGB_RED 0 /* Offset of Red in an RGB scanline element */ #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
#define RGB_GREEN 1 /* Offset of Green */ #define RGB_GREEN 1 /* Offset of Green */
#define RGB_BLUE 2 /* Offset of Blue */ #define RGB_BLUE 2 /* Offset of Blue */
#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */ #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
#define JPEG_NUMCS 16 #define JPEG_NUMCS 16
@@ -382,7 +382,7 @@ static const int rgb_pixelsize[JPEG_NUMCS] = {
#ifndef MULTIPLIER #ifndef MULTIPLIER
#ifndef WITH_SIMD #ifndef WITH_SIMD
#define MULTIPLIER int /* type for fastest integer multiply */ #define MULTIPLIER int /* type for fastest integer multiply */
#else #else
#define MULTIPLIER short /* prefer 16-bit with SIMD for parellelism */ #define MULTIPLIER short /* prefer 16-bit with SIMD for parellelism */
#endif #endif

260
jpegint.h
View File

@@ -14,30 +14,30 @@
/* Declarations for both compression & decompression */ /* Declarations for both compression & decompression */
typedef enum { /* Operating modes for buffer controllers */ typedef enum { /* Operating modes for buffer controllers */
JBUF_PASS_THRU, /* Plain stripwise operation */ JBUF_PASS_THRU, /* Plain stripwise operation */
/* Remaining modes require a full-image buffer to have been created */ /* Remaining modes require a full-image buffer to have been created */
JBUF_SAVE_SOURCE, /* Run source subobject only, save output */ JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */ JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
JBUF_SAVE_AND_PASS /* Run both subobjects, save output */ JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
} J_BUF_MODE; } J_BUF_MODE;
/* Values of global_state field (jdapi.c has some dependencies on ordering!) */ /* Values of global_state field (jdapi.c has some dependencies on ordering!) */
#define CSTATE_START 100 /* after create_compress */ #define CSTATE_START 100 /* after create_compress */
#define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */ #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
#define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */ #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
#define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */ #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
#define DSTATE_START 200 /* after create_decompress */ #define DSTATE_START 200 /* after create_decompress */
#define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */ #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
#define DSTATE_READY 202 /* found SOS, ready for start_decompress */ #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
#define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/ #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
#define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */ #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
#define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */ #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
#define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */ #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
#define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */ #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
#define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */ #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
#define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */ #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
#define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */ #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
/* Declarations for compression modules */ /* Declarations for compression modules */
@@ -49,54 +49,54 @@ struct jpeg_comp_master {
JMETHOD(void, finish_pass, (j_compress_ptr cinfo)); JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
/* State variables made visible to other modules */ /* State variables made visible to other modules */
boolean call_pass_startup; /* True if pass_startup must be called */ boolean call_pass_startup; /* True if pass_startup must be called */
boolean is_last_pass; /* True during last pass */ boolean is_last_pass; /* True during last pass */
}; };
/* Main buffer control (downsampled-data buffer) */ /* Main buffer control (downsampled-data buffer) */
struct jpeg_c_main_controller { struct jpeg_c_main_controller {
JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
JMETHOD(void, process_data, (j_compress_ptr cinfo, JMETHOD(void, process_data, (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
JDIMENSION in_rows_avail)); JDIMENSION in_rows_avail));
}; };
/* Compression preprocessing (downsampling input buffer control) */ /* Compression preprocessing (downsampling input buffer control) */
struct jpeg_c_prep_controller { struct jpeg_c_prep_controller {
JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
JMETHOD(void, pre_process_data, (j_compress_ptr cinfo, JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPARRAY input_buf,
JDIMENSION *in_row_ctr, JDIMENSION *in_row_ctr,
JDIMENSION in_rows_avail, JDIMENSION in_rows_avail,
JSAMPIMAGE output_buf, JSAMPIMAGE output_buf,
JDIMENSION *out_row_group_ctr, JDIMENSION *out_row_group_ctr,
JDIMENSION out_row_groups_avail)); JDIMENSION out_row_groups_avail));
}; };
/* Coefficient buffer control */ /* Coefficient buffer control */
struct jpeg_c_coef_controller { struct jpeg_c_coef_controller {
JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode)); JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
JMETHOD(boolean, compress_data, (j_compress_ptr cinfo, JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
JSAMPIMAGE input_buf)); JSAMPIMAGE input_buf));
}; };
/* Colorspace conversion */ /* Colorspace conversion */
struct jpeg_color_converter { struct jpeg_color_converter {
JMETHOD(void, start_pass, (j_compress_ptr cinfo)); JMETHOD(void, start_pass, (j_compress_ptr cinfo));
JMETHOD(void, color_convert, (j_compress_ptr cinfo, JMETHOD(void, color_convert, (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows)); JDIMENSION output_row, int num_rows));
}; };
/* Downsampling */ /* Downsampling */
struct jpeg_downsampler { struct jpeg_downsampler {
JMETHOD(void, start_pass, (j_compress_ptr cinfo)); JMETHOD(void, start_pass, (j_compress_ptr cinfo));
JMETHOD(void, downsample, (j_compress_ptr cinfo, JMETHOD(void, downsample, (j_compress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION in_row_index, JSAMPIMAGE input_buf, JDIMENSION in_row_index,
JSAMPIMAGE output_buf, JSAMPIMAGE output_buf,
JDIMENSION out_row_group_index)); JDIMENSION out_row_group_index));
boolean need_context_rows; /* TRUE if need rows above & below */ boolean need_context_rows; /* TRUE if need rows above & below */
}; };
/* Forward DCT (also controls coefficient quantization) */ /* Forward DCT (also controls coefficient quantization) */
@@ -104,10 +104,10 @@ struct jpeg_forward_dct {
JMETHOD(void, start_pass, (j_compress_ptr cinfo)); JMETHOD(void, start_pass, (j_compress_ptr cinfo));
/* perhaps this should be an array??? */ /* perhaps this should be an array??? */
JMETHOD(void, forward_DCT, (j_compress_ptr cinfo, JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
JDIMENSION start_row, JDIMENSION start_col, JDIMENSION start_row, JDIMENSION start_col,
JDIMENSION num_blocks)); JDIMENSION num_blocks));
}; };
/* Entropy encoding */ /* Entropy encoding */
@@ -127,7 +127,7 @@ struct jpeg_marker_writer {
/* These routines are exported to allow insertion of extra markers */ /* These routines are exported to allow insertion of extra markers */
/* Probably only COM and APPn markers should be written this way */ /* Probably only COM and APPn markers should be written this way */
JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker, JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
unsigned int datalen)); unsigned int datalen));
JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val)); JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
}; };
@@ -140,7 +140,7 @@ struct jpeg_decomp_master {
JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo)); JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
/* State variables made visible to other modules */ /* State variables made visible to other modules */
boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */ boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
}; };
/* Input control module */ /* Input control module */
@@ -151,16 +151,16 @@ struct jpeg_input_controller {
JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo)); JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
/* State variables made visible to other modules */ /* State variables made visible to other modules */
boolean has_multiple_scans; /* True if file has multiple scans */ boolean has_multiple_scans; /* True if file has multiple scans */
boolean eoi_reached; /* True when EOI has been consumed */ boolean eoi_reached; /* True when EOI has been consumed */
}; };
/* Main buffer control (downsampled-data buffer) */ /* Main buffer control (downsampled-data buffer) */
struct jpeg_d_main_controller { struct jpeg_d_main_controller {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
JMETHOD(void, process_data, (j_decompress_ptr cinfo, JMETHOD(void, process_data, (j_decompress_ptr cinfo,
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail)); JDIMENSION out_rows_avail));
}; };
/* Coefficient buffer control */ /* Coefficient buffer control */
@@ -169,7 +169,7 @@ struct jpeg_d_coef_controller {
JMETHOD(int, consume_data, (j_decompress_ptr cinfo)); JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo)); JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
JMETHOD(int, decompress_data, (j_decompress_ptr cinfo, JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
JSAMPIMAGE output_buf)); JSAMPIMAGE output_buf));
/* Pointer to array of coefficient virtual arrays, or NULL if none */ /* Pointer to array of coefficient virtual arrays, or NULL if none */
jvirt_barray_ptr *coef_arrays; jvirt_barray_ptr *coef_arrays;
}; };
@@ -178,12 +178,12 @@ struct jpeg_d_coef_controller {
struct jpeg_d_post_controller { struct jpeg_d_post_controller {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)); JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
JMETHOD(void, post_process_data, (j_decompress_ptr cinfo, JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail)); JDIMENSION out_rows_avail));
}; };
/* Marker reading & parsing */ /* Marker reading & parsing */
@@ -200,28 +200,28 @@ struct jpeg_marker_reader {
/* State of marker reader --- nominally internal, but applications /* State of marker reader --- nominally internal, but applications
* supplying COM or APPn handlers might like to know the state. * supplying COM or APPn handlers might like to know the state.
*/ */
boolean saw_SOI; /* found SOI? */ boolean saw_SOI; /* found SOI? */
boolean saw_SOF; /* found SOF? */ boolean saw_SOF; /* found SOF? */
int next_restart_num; /* next restart number expected (0-7) */ int next_restart_num; /* next restart number expected (0-7) */
unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */ unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
}; };
/* Entropy decoding */ /* Entropy decoding */
struct jpeg_entropy_decoder { struct jpeg_entropy_decoder {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
JBLOCKROW *MCU_data)); JBLOCKROW *MCU_data));
/* This is here to share code between baseline and progressive decoders; */ /* This is here to share code between baseline and progressive decoders; */
/* other modules probably should not use it */ /* other modules probably should not use it */
boolean insufficient_data; /* set TRUE after emitting warning */ boolean insufficient_data; /* set TRUE after emitting warning */
}; };
/* Inverse DCT (also performs dequantization) */ /* Inverse DCT (also performs dequantization) */
typedef JMETHOD(void, inverse_DCT_method_ptr, typedef JMETHOD(void, inverse_DCT_method_ptr,
(j_decompress_ptr cinfo, jpeg_component_info * compptr, (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col)); JSAMPARRAY output_buf, JDIMENSION output_col));
struct jpeg_inverse_dct { struct jpeg_inverse_dct {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
@@ -233,30 +233,30 @@ struct jpeg_inverse_dct {
struct jpeg_upsampler { struct jpeg_upsampler {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
JMETHOD(void, upsample, (j_decompress_ptr cinfo, JMETHOD(void, upsample, (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JSAMPIMAGE input_buf,
JDIMENSION *in_row_group_ctr, JDIMENSION *in_row_group_ctr,
JDIMENSION in_row_groups_avail, JDIMENSION in_row_groups_avail,
JSAMPARRAY output_buf, JSAMPARRAY output_buf,
JDIMENSION *out_row_ctr, JDIMENSION *out_row_ctr,
JDIMENSION out_rows_avail)); JDIMENSION out_rows_avail));
boolean need_context_rows; /* TRUE if need rows above & below */ boolean need_context_rows; /* TRUE if need rows above & below */
}; };
/* Colorspace conversion */ /* Colorspace conversion */
struct jpeg_color_deconverter { struct jpeg_color_deconverter {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
JMETHOD(void, color_convert, (j_decompress_ptr cinfo, JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)); JSAMPARRAY output_buf, int num_rows));
}; };
/* Color quantization or color precision reduction */ /* Color quantization or color precision reduction */
struct jpeg_color_quantizer { struct jpeg_color_quantizer {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan)); JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
JMETHOD(void, color_quantize, (j_decompress_ptr cinfo, JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPARRAY output_buf, JSAMPARRAY input_buf, JSAMPARRAY output_buf,
int num_rows)); int num_rows));
JMETHOD(void, finish_pass, (j_decompress_ptr cinfo)); JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
JMETHOD(void, new_color_map, (j_decompress_ptr cinfo)); JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
}; };
@@ -265,9 +265,9 @@ struct jpeg_color_quantizer {
/* Miscellaneous useful macros */ /* Miscellaneous useful macros */
#undef MAX #undef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b))
#undef MIN #undef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b))
/* We assume that right shift corresponds to signed division by 2 with /* We assume that right shift corresponds to signed division by 2 with
@@ -281,69 +281,69 @@ struct jpeg_color_quantizer {
*/ */
#ifdef RIGHT_SHIFT_IS_UNSIGNED #ifdef RIGHT_SHIFT_IS_UNSIGNED
#define SHIFT_TEMPS INT32 shift_temp; #define SHIFT_TEMPS INT32 shift_temp;
#define RIGHT_SHIFT(x,shft) \ #define RIGHT_SHIFT(x,shft) \
((shift_temp = (x)) < 0 ? \ ((shift_temp = (x)) < 0 ? \
(shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \ (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
(shift_temp >> (shft))) (shift_temp >> (shft)))
#else #else
#define SHIFT_TEMPS #define SHIFT_TEMPS
#define RIGHT_SHIFT(x,shft) ((x) >> (shft)) #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
#endif #endif
/* Short forms of external names for systems with brain-damaged linkers. */ /* Short forms of external names for systems with brain-damaged linkers. */
#ifdef NEED_SHORT_EXTERNAL_NAMES #ifdef NEED_SHORT_EXTERNAL_NAMES
#define jinit_compress_master jICompress #define jinit_compress_master jICompress
#define jinit_c_master_control jICMaster #define jinit_c_master_control jICMaster
#define jinit_c_main_controller jICMainC #define jinit_c_main_controller jICMainC
#define jinit_c_prep_controller jICPrepC #define jinit_c_prep_controller jICPrepC
#define jinit_c_coef_controller jICCoefC #define jinit_c_coef_controller jICCoefC
#define jinit_color_converter jICColor #define jinit_color_converter jICColor
#define jinit_downsampler jIDownsampler #define jinit_downsampler jIDownsampler
#define jinit_forward_dct jIFDCT #define jinit_forward_dct jIFDCT
#define jinit_huff_encoder jIHEncoder #define jinit_huff_encoder jIHEncoder
#define jinit_phuff_encoder jIPHEncoder #define jinit_phuff_encoder jIPHEncoder
#define jinit_arith_encoder jIAEncoder #define jinit_arith_encoder jIAEncoder
#define jinit_marker_writer jIMWriter #define jinit_marker_writer jIMWriter
#define jinit_master_decompress jIDMaster #define jinit_master_decompress jIDMaster
#define jinit_d_main_controller jIDMainC #define jinit_d_main_controller jIDMainC
#define jinit_d_coef_controller jIDCoefC #define jinit_d_coef_controller jIDCoefC
#define jinit_d_post_controller jIDPostC #define jinit_d_post_controller jIDPostC
#define jinit_input_controller jIInCtlr #define jinit_input_controller jIInCtlr
#define jinit_marker_reader jIMReader #define jinit_marker_reader jIMReader
#define jinit_huff_decoder jIHDecoder #define jinit_huff_decoder jIHDecoder
#define jinit_phuff_decoder jIPHDecoder #define jinit_phuff_decoder jIPHDecoder
#define jinit_arith_decoder jIADecoder #define jinit_arith_decoder jIADecoder
#define jinit_inverse_dct jIIDCT #define jinit_inverse_dct jIIDCT
#define jinit_upsampler jIUpsampler #define jinit_upsampler jIUpsampler
#define jinit_color_deconverter jIDColor #define jinit_color_deconverter jIDColor
#define jinit_1pass_quantizer jI1Quant #define jinit_1pass_quantizer jI1Quant
#define jinit_2pass_quantizer jI2Quant #define jinit_2pass_quantizer jI2Quant
#define jinit_merged_upsampler jIMUpsampler #define jinit_merged_upsampler jIMUpsampler
#define jinit_memory_mgr jIMemMgr #define jinit_memory_mgr jIMemMgr
#define jdiv_round_up jDivRound #define jdiv_round_up jDivRound
#define jround_up jRound #define jround_up jRound
#define jcopy_sample_rows jCopySamples #define jcopy_sample_rows jCopySamples
#define jcopy_block_row jCopyBlocks #define jcopy_block_row jCopyBlocks
#define jzero_far jZeroFar #define jzero_far jZeroFar
#define jpeg_zigzag_order jZIGTable #define jpeg_zigzag_order jZIGTable
#define jpeg_natural_order jZAGTable #define jpeg_natural_order jZAGTable
#define jpeg_aritab jAriTab #define jpeg_aritab jAriTab
#endif /* NEED_SHORT_EXTERNAL_NAMES */ #endif /* NEED_SHORT_EXTERNAL_NAMES */
/* Compression module initialization routines */ /* Compression module initialization routines */
EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo, EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
boolean transcode_only)); boolean transcode_only));
EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo, EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
boolean need_full_buffer)); boolean need_full_buffer));
EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo, EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
boolean need_full_buffer)); boolean need_full_buffer));
EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo, EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
boolean need_full_buffer)); boolean need_full_buffer));
EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
@@ -354,11 +354,11 @@ EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
/* Decompression module initialization routines */ /* Decompression module initialization routines */
EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo, EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
boolean need_full_buffer)); boolean need_full_buffer));
EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo, EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
boolean need_full_buffer)); boolean need_full_buffer));
EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo, EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
boolean need_full_buffer)); boolean need_full_buffer));
EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo)); EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
@@ -377,13 +377,13 @@ EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
EXTERN(long) jdiv_round_up JPP((long a, long b)); EXTERN(long) jdiv_round_up JPP((long a, long b));
EXTERN(long) jround_up JPP((long a, long b)); EXTERN(long) jround_up JPP((long a, long b));
EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row, EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
JSAMPARRAY output_array, int dest_row, JSAMPARRAY output_array, int dest_row,
int num_rows, JDIMENSION num_cols)); int num_rows, JDIMENSION num_cols));
EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row, EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
JDIMENSION num_blocks)); JDIMENSION num_blocks));
EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero)); EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
/* Constant tables in jutils.c */ /* Constant tables in jutils.c */
#if 0 /* This table is not actually needed in v6a */ #if 0 /* This table is not actually needed in v6a */
extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */ extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
#endif #endif
extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */ extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
@@ -394,7 +394,7 @@ extern const INT32 jpeg_aritab[];
/* Suppress undefined-structure complaints if necessary. */ /* Suppress undefined-structure complaints if necessary. */
#ifdef INCOMPLETE_TYPES_BROKEN #ifdef INCOMPLETE_TYPES_BROKEN
#ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */ #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
struct jvirt_sarray_control { long dummy; }; struct jvirt_sarray_control { long dummy; };
struct jvirt_barray_control { long dummy; }; struct jvirt_barray_control { long dummy; };
#endif #endif

676
jpeglib.h

File diff suppressed because it is too large Load Diff

View File

@@ -13,18 +13,18 @@
* provides some lossless and sort-of-lossless transformations of JPEG data. * provides some lossless and sort-of-lossless transformations of JPEG data.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include "transupp.h" /* Support routines for jpegtran */ #include "transupp.h" /* Support routines for jpegtran */
#include "jversion.h" /* for version message */ #include "jversion.h" /* for version message */
#include "jconfigint.h" #include "jconfigint.h"
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__ #ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */ #include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */ #include <console.h> /* ... and this */
#endif #endif
#ifdef THINK_C #ifdef THINK_C
#include <console.h> /* Think declares it here */ #include <console.h> /* Think declares it here */
#endif #endif
#endif #endif
@@ -38,9 +38,9 @@
*/ */
static const char * progname; /* program name for error messages */ static const char * progname; /* program name for error messages */
static char * outfilename; /* for -outfile switch */ static char * outfilename; /* for -outfile switch */
static JCOPY_OPTION copyoption; /* -copy switch */ static JCOPY_OPTION copyoption; /* -copy switch */
static jpeg_transform_info transformoption; /* image transformation options */ static jpeg_transform_info transformoption; /* image transformation options */
@@ -106,12 +106,12 @@ select_transform (JXFORM_CODE transform)
transformoption.transform = transform; transformoption.transform = transform;
} else { } else {
fprintf(stderr, "%s: can only do one image transformation at a time\n", fprintf(stderr, "%s: can only do one image transformation at a time\n",
progname); progname);
usage(); usage();
} }
#else #else
fprintf(stderr, "%s: sorry, image transformation was not compiled\n", fprintf(stderr, "%s: sorry, image transformation was not compiled\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
} }
@@ -119,7 +119,7 @@ select_transform (JXFORM_CODE transform)
LOCAL(int) LOCAL(int)
parse_switches (j_compress_ptr cinfo, int argc, char **argv, parse_switches (j_compress_ptr cinfo, int argc, char **argv,
int last_file_arg_seen, boolean for_real) int last_file_arg_seen, boolean for_real)
/* Parse optional switches. /* Parse optional switches.
* Returns argv[] index of first file-name argument (== argc if none). * Returns argv[] index of first file-name argument (== argc if none).
* Any file names with indexes <= last_file_arg_seen are ignored; * Any file names with indexes <= last_file_arg_seen are ignored;
@@ -132,7 +132,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
int argn; int argn;
char * arg; char * arg;
boolean simple_progressive; boolean simple_progressive;
char * scansarg = NULL; /* saves -scans parm if any */ char * scansarg = NULL; /* saves -scans parm if any */
/* Set up default JPEG parameters. */ /* Set up default JPEG parameters. */
simple_progressive = FALSE; simple_progressive = FALSE;
@@ -153,12 +153,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
if (*arg != '-') { if (*arg != '-') {
/* Not a switch, must be a file name argument */ /* Not a switch, must be a file name argument */
if (argn <= last_file_arg_seen) { if (argn <= last_file_arg_seen) {
outfilename = NULL; /* -outfile applies to just one input file */ outfilename = NULL; /* -outfile applies to just one input file */
continue; /* ignore this name if previously processed */ continue; /* ignore this name if previously processed */
} }
break; /* else done parsing switches */ break; /* else done parsing switches */
} }
arg++; /* advance past switch marker character */ arg++; /* advance past switch marker character */
if (keymatch(arg, "arithmetic", 1)) { if (keymatch(arg, "arithmetic", 1)) {
/* Use arithmetic coding. */ /* Use arithmetic coding. */
@@ -166,35 +166,35 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
cinfo->arith_code = TRUE; cinfo->arith_code = TRUE;
#else #else
fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
} else if (keymatch(arg, "copy", 2)) { } else if (keymatch(arg, "copy", 2)) {
/* Select which extra markers to copy. */ /* Select which extra markers to copy. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "none", 1)) { if (keymatch(argv[argn], "none", 1)) {
copyoption = JCOPYOPT_NONE; copyoption = JCOPYOPT_NONE;
} else if (keymatch(argv[argn], "comments", 1)) { } else if (keymatch(argv[argn], "comments", 1)) {
copyoption = JCOPYOPT_COMMENTS; copyoption = JCOPYOPT_COMMENTS;
} else if (keymatch(argv[argn], "all", 1)) { } else if (keymatch(argv[argn], "all", 1)) {
copyoption = JCOPYOPT_ALL; copyoption = JCOPYOPT_ALL;
} else } else
usage(); usage();
} else if (keymatch(arg, "crop", 2)) { } else if (keymatch(arg, "crop", 2)) {
/* Perform lossless cropping. */ /* Perform lossless cropping. */
#if TRANSFORMS_SUPPORTED #if TRANSFORMS_SUPPORTED
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (! jtransform_parse_crop_spec(&transformoption, argv[argn])) { if (! jtransform_parse_crop_spec(&transformoption, argv[argn])) {
fprintf(stderr, "%s: bogus -crop argument '%s'\n", fprintf(stderr, "%s: bogus -crop argument '%s'\n",
progname, argv[argn]); progname, argv[argn]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#else #else
select_transform(JXFORM_NONE); /* force an error */ select_transform(JXFORM_NONE); /* force an error */
#endif #endif
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
@@ -203,32 +203,32 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
static boolean printed_version = FALSE; static boolean printed_version = FALSE;
if (! printed_version) { if (! printed_version) {
fprintf(stderr, "%s version %s (build %s)\n", fprintf(stderr, "%s version %s (build %s)\n",
PACKAGE_NAME, VERSION, BUILD); PACKAGE_NAME, VERSION, BUILD);
fprintf(stderr, "%s\n\n", JCOPYRIGHT); fprintf(stderr, "%s\n\n", JCOPYRIGHT);
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n", fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
JVERSION); JVERSION);
printed_version = TRUE; printed_version = TRUE;
} }
cinfo->err->trace_level++; cinfo->err->trace_level++;
} else if (keymatch(arg, "flip", 1)) { } else if (keymatch(arg, "flip", 1)) {
/* Mirror left-right or top-bottom. */ /* Mirror left-right or top-bottom. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "horizontal", 1)) if (keymatch(argv[argn], "horizontal", 1))
select_transform(JXFORM_FLIP_H); select_transform(JXFORM_FLIP_H);
else if (keymatch(argv[argn], "vertical", 1)) else if (keymatch(argv[argn], "vertical", 1))
select_transform(JXFORM_FLIP_V); select_transform(JXFORM_FLIP_V);
else else
usage(); usage();
} else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) { } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) {
/* Force to grayscale. */ /* Force to grayscale. */
#if TRANSFORMS_SUPPORTED #if TRANSFORMS_SUPPORTED
transformoption.force_grayscale = TRUE; transformoption.force_grayscale = TRUE;
#else #else
select_transform(JXFORM_NONE); /* force an error */ select_transform(JXFORM_NONE); /* force an error */
#endif #endif
} else if (keymatch(arg, "maxmemory", 3)) { } else if (keymatch(arg, "maxmemory", 3)) {
@@ -236,12 +236,12 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
long lval; long lval;
char ch = 'x'; char ch = 'x';
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
usage(); usage();
if (ch == 'm' || ch == 'M') if (ch == 'm' || ch == 'M')
lval *= 1000L; lval *= 1000L;
cinfo->mem->max_memory_to_use = lval * 1000L; cinfo->mem->max_memory_to_use = lval * 1000L;
} else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
@@ -250,15 +250,15 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
cinfo->optimize_coding = TRUE; cinfo->optimize_coding = TRUE;
#else #else
fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
} else if (keymatch(arg, "outfile", 4)) { } else if (keymatch(arg, "outfile", 4)) {
/* Set output file name. */ /* Set output file name. */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
outfilename = argv[argn]; /* save it away for later use */ outfilename = argv[argn]; /* save it away for later use */
} else if (keymatch(arg, "perfect", 2)) { } else if (keymatch(arg, "perfect", 2)) {
/* Fail if there is any partial edge MCUs that the transform can't /* Fail if there is any partial edge MCUs that the transform can't
@@ -272,7 +272,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
/* We must postpone execution until num_components is known. */ /* We must postpone execution until num_components is known. */
#else #else
fprintf(stderr, "%s: sorry, progressive output was not compiled\n", fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -281,43 +281,43 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
long lval; long lval;
char ch = 'x'; char ch = 'x';
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
usage(); usage();
if (lval < 0 || lval > 65535L) if (lval < 0 || lval > 65535L)
usage(); usage();
if (ch == 'b' || ch == 'B') { if (ch == 'b' || ch == 'B') {
cinfo->restart_interval = (unsigned int) lval; cinfo->restart_interval = (unsigned int) lval;
cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
} else { } else {
cinfo->restart_in_rows = (int) lval; cinfo->restart_in_rows = (int) lval;
/* restart_interval will be computed during startup */ /* restart_interval will be computed during startup */
} }
} else if (keymatch(arg, "rotate", 2)) { } else if (keymatch(arg, "rotate", 2)) {
/* Rotate 90, 180, or 270 degrees (measured clockwise). */ /* Rotate 90, 180, or 270 degrees (measured clockwise). */
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
if (keymatch(argv[argn], "90", 2)) if (keymatch(argv[argn], "90", 2))
select_transform(JXFORM_ROT_90); select_transform(JXFORM_ROT_90);
else if (keymatch(argv[argn], "180", 3)) else if (keymatch(argv[argn], "180", 3))
select_transform(JXFORM_ROT_180); select_transform(JXFORM_ROT_180);
else if (keymatch(argv[argn], "270", 3)) else if (keymatch(argv[argn], "270", 3))
select_transform(JXFORM_ROT_270); select_transform(JXFORM_ROT_270);
else else
usage(); usage();
} else if (keymatch(arg, "scans", 1)) { } else if (keymatch(arg, "scans", 1)) {
/* Set scan script. */ /* Set scan script. */
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED
if (++argn >= argc) /* advance to next argument */ if (++argn >= argc) /* advance to next argument */
usage(); usage();
scansarg = argv[argn]; scansarg = argv[argn];
/* We must postpone reading the file in case -progressive appears. */ /* We must postpone reading the file in case -progressive appears. */
#else #else
fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
progname); progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
#endif #endif
@@ -334,7 +334,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
transformoption.trim = TRUE; transformoption.trim = TRUE;
} else { } else {
usage(); /* bogus switch */ usage(); /* bogus switch */
} }
} }
@@ -343,18 +343,18 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
if (for_real) { if (for_real) {
#ifdef C_PROGRESSIVE_SUPPORTED #ifdef C_PROGRESSIVE_SUPPORTED
if (simple_progressive) /* process -progressive; -scans can override */ if (simple_progressive) /* process -progressive; -scans can override */
jpeg_simple_progression(cinfo); jpeg_simple_progression(cinfo);
#endif #endif
#ifdef C_MULTISCAN_FILES_SUPPORTED #ifdef C_MULTISCAN_FILES_SUPPORTED
if (scansarg != NULL) /* process -scans if it was present */ if (scansarg != NULL) /* process -scans if it was present */
if (! read_scan_script(cinfo, scansarg)) if (! read_scan_script(cinfo, scansarg))
usage(); usage();
#endif #endif
} }
return argn; /* return index of next arg (file name) */ return argn; /* return index of next arg (file name) */
} }
@@ -386,7 +386,7 @@ main (int argc, char **argv)
progname = argv[0]; progname = argv[0];
if (progname == NULL || progname[0] == 0) if (progname == NULL || progname[0] == 0)
progname = "jpegtran"; /* in case C library doesn't provide it */ progname = "jpegtran"; /* in case C library doesn't provide it */
/* Initialize the JPEG decompression object with default error handling. */ /* Initialize the JPEG decompression object with default error handling. */
srcinfo.err = jpeg_std_error(&jsrcerr); srcinfo.err = jpeg_std_error(&jsrcerr);
@@ -419,14 +419,14 @@ main (int argc, char **argv)
if (outfilename == NULL) { if (outfilename == NULL) {
if (file_index != argc-2) { if (file_index != argc-2) {
fprintf(stderr, "%s: must name one input and one output file\n", fprintf(stderr, "%s: must name one input and one output file\n",
progname); progname);
usage(); usage();
} }
outfilename = argv[file_index+1]; outfilename = argv[file_index+1];
} else { } else {
if (file_index != argc-1) { if (file_index != argc-1) {
fprintf(stderr, "%s: must name one input and one output file\n", fprintf(stderr, "%s: must name one input and one output file\n",
progname); progname);
usage(); usage();
} }
} }
@@ -485,8 +485,8 @@ main (int argc, char **argv)
*/ */
#if TRANSFORMS_SUPPORTED #if TRANSFORMS_SUPPORTED
dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo, dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo,
src_coef_arrays, src_coef_arrays,
&transformoption); &transformoption);
#else #else
dst_coef_arrays = src_coef_arrays; dst_coef_arrays = src_coef_arrays;
#endif #endif
@@ -527,8 +527,8 @@ main (int argc, char **argv)
/* Execute image transformation, if any */ /* Execute image transformation, if any */
#if TRANSFORMS_SUPPORTED #if TRANSFORMS_SUPPORTED
jtransform_execute_transformation(&srcinfo, &dstinfo, jtransform_execute_transformation(&srcinfo, &dstinfo,
src_coef_arrays, src_coef_arrays,
&transformoption); &transformoption);
#endif #endif
/* Finish compression and release memory */ /* Finish compression and release memory */
@@ -547,5 +547,5 @@ main (int argc, char **argv)
/* All done. */ /* All done. */
exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS); exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS);
return 0; /* suppress no-return-value warnings */ return 0; /* suppress no-return-value warnings */
} }

256
jquant1.c
View File

@@ -70,9 +70,9 @@
* table in both directions. * table in both directions.
*/ */
#define ODITHER_SIZE 16 /* dimension of dither matrix */ #define ODITHER_SIZE 16 /* dimension of dither matrix */
/* NB: if ODITHER_SIZE is not a power of 2, ODITHER_MASK uses will break */ /* NB: if ODITHER_SIZE is not a power of 2, ODITHER_MASK uses will break */
#define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */ #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
#define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */ #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE]; typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
@@ -107,8 +107,8 @@ static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
* Errors are accumulated into the array fserrors[], at a resolution of * Errors are accumulated into the array fserrors[], at a resolution of
* 1/16th of a pixel count. The error at a given pixel is propagated * 1/16th of a pixel count. The error at a given pixel is propagated
* to its not-yet-processed neighbors using the standard F-S fractions, * to its not-yet-processed neighbors using the standard F-S fractions,
* ... (here) 7/16 * ... (here) 7/16
* 3/16 5/16 1/16 * 3/16 5/16 1/16
* We work left-to-right on even rows, right-to-left on odd rows. * We work left-to-right on even rows, right-to-left on odd rows.
* *
* We can get away with a single array (holding one row's worth of errors) * We can get away with a single array (holding one row's worth of errors)
@@ -127,43 +127,43 @@ static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
*/ */
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
typedef INT16 FSERROR; /* 16 bits should be enough */ typedef INT16 FSERROR; /* 16 bits should be enough */
typedef int LOCFSERROR; /* use 'int' for calculation temps */ typedef int LOCFSERROR; /* use 'int' for calculation temps */
#else #else
typedef INT32 FSERROR; /* may need more than 16 bits */ typedef INT32 FSERROR; /* may need more than 16 bits */
typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */ typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
#endif #endif
typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */ typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
/* Private subobject */ /* Private subobject */
#define MAX_Q_COMPS 4 /* max components I can handle */ #define MAX_Q_COMPS 4 /* max components I can handle */
typedef struct { typedef struct {
struct jpeg_color_quantizer pub; /* public fields */ struct jpeg_color_quantizer pub; /* public fields */
/* Initially allocated colormap is saved here */ /* Initially allocated colormap is saved here */
JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */ JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
int sv_actual; /* number of entries in use */ int sv_actual; /* number of entries in use */
JSAMPARRAY colorindex; /* Precomputed mapping for speed */ JSAMPARRAY colorindex; /* Precomputed mapping for speed */
/* colorindex[i][j] = index of color closest to pixel value j in component i, /* colorindex[i][j] = index of color closest to pixel value j in component i,
* premultiplied as described above. Since colormap indexes must fit into * premultiplied as described above. Since colormap indexes must fit into
* JSAMPLEs, the entries of this array will too. * JSAMPLEs, the entries of this array will too.
*/ */
boolean is_padded; /* is the colorindex padded for odither? */ boolean is_padded; /* is the colorindex padded for odither? */
int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */ int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
/* Variables for ordered dithering */ /* Variables for ordered dithering */
int row_index; /* cur row's vertical index in dither matrix */ int row_index; /* cur row's vertical index in dither matrix */
ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */ ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
/* Variables for Floyd-Steinberg dithering */ /* Variables for Floyd-Steinberg dithering */
FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */ FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
boolean on_odd_row; /* flag to remember which row we are on */ boolean on_odd_row; /* flag to remember which row we are on */
} my_cquantizer; } my_cquantizer;
typedef my_cquantizer * my_cquantize_ptr; typedef my_cquantizer * my_cquantize_ptr;
@@ -205,11 +205,11 @@ select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
iroot = 1; iroot = 1;
do { do {
iroot++; iroot++;
temp = iroot; /* set temp = iroot ** nc */ temp = iroot; /* set temp = iroot ** nc */
for (i = 1; i < nc; i++) for (i = 1; i < nc; i++)
temp *= iroot; temp *= iroot;
} while (temp <= (long) max_colors); /* repeat till iroot exceeds root */ } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
iroot--; /* now iroot = floor(root) */ iroot--; /* now iroot = floor(root) */
/* Must have at least 2 color values per component */ /* Must have at least 2 color values per component */
if (iroot < 2) if (iroot < 2)
@@ -233,10 +233,10 @@ select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i); j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
/* calculate new total_colors if Ncolors[j] is incremented */ /* calculate new total_colors if Ncolors[j] is incremented */
temp = total_colors / Ncolors[j]; temp = total_colors / Ncolors[j];
temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */ temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
if (temp > (long) max_colors) if (temp > (long) max_colors)
break; /* won't fit, done with this pass */ break; /* won't fit, done with this pass */
Ncolors[j]++; /* OK, apply the increment */ Ncolors[j]++; /* OK, apply the increment */
total_colors = (int) temp; total_colors = (int) temp;
changed = TRUE; changed = TRUE;
} }
@@ -278,8 +278,8 @@ LOCAL(void)
create_colormap (j_decompress_ptr cinfo) create_colormap (j_decompress_ptr cinfo)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
JSAMPARRAY colormap; /* Created colormap */ JSAMPARRAY colormap; /* Created colormap */
int total_colors; /* Number of distinct output colors */ int total_colors; /* Number of distinct output colors */
int i,j,k, nci, blksize, blkdist, ptr, val; int i,j,k, nci, blksize, blkdist, ptr, val;
/* Select number of colors for each component */ /* Select number of colors for each component */
@@ -288,8 +288,8 @@ create_colormap (j_decompress_ptr cinfo)
/* Report selected color counts */ /* Report selected color counts */
if (cinfo->out_color_components == 3) if (cinfo->out_color_components == 3)
TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS, TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
total_colors, cquantize->Ncolors[0], total_colors, cquantize->Ncolors[0],
cquantize->Ncolors[1], cquantize->Ncolors[2]); cquantize->Ncolors[1], cquantize->Ncolors[2]);
else else
TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors); TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
@@ -314,12 +314,12 @@ create_colormap (j_decompress_ptr cinfo)
val = output_value(cinfo, i, j, nci-1); val = output_value(cinfo, i, j, nci-1);
/* Fill in all colormap entries that have this value of this component */ /* Fill in all colormap entries that have this value of this component */
for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) { for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
/* fill in blksize entries beginning at ptr */ /* fill in blksize entries beginning at ptr */
for (k = 0; k < blksize; k++) for (k = 0; k < blksize; k++)
colormap[i][ptr+k] = (JSAMPLE) val; colormap[i][ptr+k] = (JSAMPLE) val;
} }
} }
blkdist = blksize; /* blksize of this color is blkdist of next */ blkdist = blksize; /* blksize of this color is blkdist of next */
} }
/* Save the colormap in private storage, /* Save the colormap in private storage,
@@ -377,16 +377,16 @@ create_colorindex (j_decompress_ptr cinfo)
val = 0; val = 0;
k = largest_input_value(cinfo, i, 0, nci-1); k = largest_input_value(cinfo, i, 0, nci-1);
for (j = 0; j <= MAXJSAMPLE; j++) { for (j = 0; j <= MAXJSAMPLE; j++) {
while (j > k) /* advance val if past boundary */ while (j > k) /* advance val if past boundary */
k = largest_input_value(cinfo, i, ++val, nci-1); k = largest_input_value(cinfo, i, ++val, nci-1);
/* premultiply so that no multiplication needed in main processing */ /* premultiply so that no multiplication needed in main processing */
indexptr[j] = (JSAMPLE) (val * blksize); indexptr[j] = (JSAMPLE) (val * blksize);
} }
/* Pad at both ends if necessary */ /* Pad at both ends if necessary */
if (pad) if (pad)
for (j = 1; j <= MAXJSAMPLE; j++) { for (j = 1; j <= MAXJSAMPLE; j++) {
indexptr[-j] = indexptr[0]; indexptr[-j] = indexptr[0];
indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE]; indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
} }
} }
} }
@@ -406,7 +406,7 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
odither = (ODITHER_MATRIX_PTR) odither = (ODITHER_MATRIX_PTR)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(ODITHER_MATRIX)); SIZEOF(ODITHER_MATRIX));
/* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1). /* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).
* Hence the dither value for the matrix cell with fill order f * Hence the dither value for the matrix cell with fill order f
* (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1). * (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).
@@ -416,7 +416,7 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
for (j = 0; j < ODITHER_SIZE; j++) { for (j = 0; j < ODITHER_SIZE; j++) {
for (k = 0; k < ODITHER_SIZE; k++) { for (k = 0; k < ODITHER_SIZE; k++) {
num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k]))) num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
* MAXJSAMPLE; * MAXJSAMPLE;
/* Ensure round towards zero despite C's lack of consistency /* Ensure round towards zero despite C's lack of consistency
* about rounding negative values in integer division... * about rounding negative values in integer division...
*/ */
@@ -429,7 +429,7 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
/* /*
* Create the ordered-dither tables. * Create the ordered-dither tables.
* Components having the same number of representative colors may * Components having the same number of representative colors may
* share a dither table. * share a dither table.
*/ */
@@ -442,14 +442,14 @@ create_odither_tables (j_decompress_ptr cinfo)
for (i = 0; i < cinfo->out_color_components; i++) { for (i = 0; i < cinfo->out_color_components; i++) {
nci = cquantize->Ncolors[i]; /* # of distinct values for this color */ nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
odither = NULL; /* search for matching prior component */ odither = NULL; /* search for matching prior component */
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
if (nci == cquantize->Ncolors[j]) { if (nci == cquantize->Ncolors[j]) {
odither = cquantize->odither[j]; odither = cquantize->odither[j];
break; break;
} }
} }
if (odither == NULL) /* need a new table? */ if (odither == NULL) /* need a new table? */
odither = make_odither_array(cinfo, nci); odither = make_odither_array(cinfo, nci);
cquantize->odither[i] = odither; cquantize->odither[i] = odither;
} }
@@ -462,7 +462,7 @@ create_odither_tables (j_decompress_ptr cinfo)
METHODDEF(void) METHODDEF(void)
color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf, color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* General case, no dithering */ /* General case, no dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
@@ -480,7 +480,7 @@ color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
pixcode = 0; pixcode = 0;
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]); pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
} }
*ptrout++ = (JSAMPLE) pixcode; *ptrout++ = (JSAMPLE) pixcode;
} }
@@ -490,7 +490,7 @@ color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
METHODDEF(void) METHODDEF(void)
color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf, color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* Fast path for out_color_components==3, no dithering */ /* Fast path for out_color_components==3, no dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
@@ -518,15 +518,15 @@ color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
METHODDEF(void) METHODDEF(void)
quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* General case, with ordered dithering */ /* General case, with ordered dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
register JSAMPROW input_ptr; register JSAMPROW input_ptr;
register JSAMPROW output_ptr; register JSAMPROW output_ptr;
JSAMPROW colorindex_ci; JSAMPROW colorindex_ci;
int * dither; /* points to active row of dither matrix */ int * dither; /* points to active row of dither matrix */
int row_index, col_index; /* current indexes into dither matrix */ int row_index, col_index; /* current indexes into dither matrix */
int nc = cinfo->out_color_components; int nc = cinfo->out_color_components;
int ci; int ci;
int row; int row;
@@ -536,7 +536,7 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */ /* Initialize output values to 0 so can process components separately */
jzero_far((void FAR *) output_buf[row], jzero_far((void FAR *) output_buf[row],
(size_t) (width * SIZEOF(JSAMPLE))); (size_t) (width * SIZEOF(JSAMPLE)));
row_index = cquantize->row_index; row_index = cquantize->row_index;
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci; input_ptr = input_buf[row] + ci;
@@ -546,17 +546,17 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
col_index = 0; col_index = 0;
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
/* Form pixel value + dither, range-limit to 0..MAXJSAMPLE, /* Form pixel value + dither, range-limit to 0..MAXJSAMPLE,
* select output value, accumulate into output code for this pixel. * select output value, accumulate into output code for this pixel.
* Range-limiting need not be done explicitly, as we have extended * Range-limiting need not be done explicitly, as we have extended
* the colorindex table to produce the right answers for out-of-range * the colorindex table to produce the right answers for out-of-range
* inputs. The maximum dither is +- MAXJSAMPLE; this sets the * inputs. The maximum dither is +- MAXJSAMPLE; this sets the
* required amount of padding. * required amount of padding.
*/ */
*output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]]; *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
input_ptr += nc; input_ptr += nc;
output_ptr++; output_ptr++;
col_index = (col_index + 1) & ODITHER_MASK; col_index = (col_index + 1) & ODITHER_MASK;
} }
} }
/* Advance row index for next row */ /* Advance row index for next row */
@@ -568,7 +568,7 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
METHODDEF(void) METHODDEF(void)
quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* Fast path for out_color_components==3, with ordered dithering */ /* Fast path for out_color_components==3, with ordered dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
@@ -578,10 +578,10 @@ quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPROW colorindex0 = cquantize->colorindex[0]; JSAMPROW colorindex0 = cquantize->colorindex[0];
JSAMPROW colorindex1 = cquantize->colorindex[1]; JSAMPROW colorindex1 = cquantize->colorindex[1];
JSAMPROW colorindex2 = cquantize->colorindex[2]; JSAMPROW colorindex2 = cquantize->colorindex[2];
int * dither0; /* points to active row of dither matrix */ int * dither0; /* points to active row of dither matrix */
int * dither1; int * dither1;
int * dither2; int * dither2;
int row_index, col_index; /* current indexes into dither matrix */ int row_index, col_index; /* current indexes into dither matrix */
int row; int row;
JDIMENSION col; JDIMENSION col;
JDIMENSION width = cinfo->output_width; JDIMENSION width = cinfo->output_width;
@@ -597,11 +597,11 @@ quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) + pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
dither0[col_index]]); dither0[col_index]]);
pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) + pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
dither1[col_index]]); dither1[col_index]]);
pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) + pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
dither2[col_index]]); dither2[col_index]]);
*output_ptr++ = (JSAMPLE) pixcode; *output_ptr++ = (JSAMPLE) pixcode;
col_index = (col_index + 1) & ODITHER_MASK; col_index = (col_index + 1) & ODITHER_MASK;
} }
@@ -613,24 +613,24 @@ quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
METHODDEF(void) METHODDEF(void)
quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf, quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
/* General case, with Floyd-Steinberg dithering */ /* General case, with Floyd-Steinberg dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
register LOCFSERROR cur; /* current error or pixel value */ register LOCFSERROR cur; /* current error or pixel value */
LOCFSERROR belowerr; /* error for pixel below cur */ LOCFSERROR belowerr; /* error for pixel below cur */
LOCFSERROR bpreverr; /* error for below/prev col */ LOCFSERROR bpreverr; /* error for below/prev col */
LOCFSERROR bnexterr; /* error for below/next col */ LOCFSERROR bnexterr; /* error for below/next col */
LOCFSERROR delta; LOCFSERROR delta;
register FSERRPTR errorptr; /* => fserrors[] at column before current */ register FSERRPTR errorptr; /* => fserrors[] at column before current */
register JSAMPROW input_ptr; register JSAMPROW input_ptr;
register JSAMPROW output_ptr; register JSAMPROW output_ptr;
JSAMPROW colorindex_ci; JSAMPROW colorindex_ci;
JSAMPROW colormap_ci; JSAMPROW colormap_ci;
int pixcode; int pixcode;
int nc = cinfo->out_color_components; int nc = cinfo->out_color_components;
int dir; /* 1 for left-to-right, -1 for right-to-left */ int dir; /* 1 for left-to-right, -1 for right-to-left */
int dirnc; /* dir * nc */ int dirnc; /* dir * nc */
int ci; int ci;
int row; int row;
JDIMENSION col; JDIMENSION col;
@@ -641,22 +641,22 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */ /* Initialize output values to 0 so can process components separately */
jzero_far((void FAR *) output_buf[row], jzero_far((void FAR *) output_buf[row],
(size_t) (width * SIZEOF(JSAMPLE))); (size_t) (width * SIZEOF(JSAMPLE)));
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci; input_ptr = input_buf[row] + ci;
output_ptr = output_buf[row]; output_ptr = output_buf[row];
if (cquantize->on_odd_row) { if (cquantize->on_odd_row) {
/* work right to left in this row */ /* work right to left in this row */
input_ptr += (width-1) * nc; /* so point to rightmost pixel */ input_ptr += (width-1) * nc; /* so point to rightmost pixel */
output_ptr += width-1; output_ptr += width-1;
dir = -1; dir = -1;
dirnc = -nc; dirnc = -nc;
errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */ errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
} else { } else {
/* work left to right in this row */ /* work left to right in this row */
dir = 1; dir = 1;
dirnc = nc; dirnc = nc;
errorptr = cquantize->fserrors[ci]; /* => entry before first column */ errorptr = cquantize->fserrors[ci]; /* => entry before first column */
} }
colorindex_ci = cquantize->colorindex[ci]; colorindex_ci = cquantize->colorindex[ci];
colormap_ci = cquantize->sv_colormap[ci]; colormap_ci = cquantize->sv_colormap[ci];
@@ -666,47 +666,47 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
belowerr = bpreverr = 0; belowerr = bpreverr = 0;
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
/* cur holds the error propagated from the previous pixel on the /* cur holds the error propagated from the previous pixel on the
* current line. Add the error propagated from the previous line * current line. Add the error propagated from the previous line
* to form the complete error correction term for this pixel, and * to form the complete error correction term for this pixel, and
* round the error term (which is expressed * 16) to an integer. * round the error term (which is expressed * 16) to an integer.
* RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
* for either sign of the error value. * for either sign of the error value.
* Note: errorptr points to *previous* column's array entry. * Note: errorptr points to *previous* column's array entry.
*/ */
cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4); cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE. /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
* The maximum error is +- MAXJSAMPLE; this sets the required size * The maximum error is +- MAXJSAMPLE; this sets the required size
* of the range_limit array. * of the range_limit array.
*/ */
cur += GETJSAMPLE(*input_ptr); cur += GETJSAMPLE(*input_ptr);
cur = GETJSAMPLE(range_limit[cur]); cur = GETJSAMPLE(range_limit[cur]);
/* Select output value, accumulate into output code for this pixel */ /* Select output value, accumulate into output code for this pixel */
pixcode = GETJSAMPLE(colorindex_ci[cur]); pixcode = GETJSAMPLE(colorindex_ci[cur]);
*output_ptr += (JSAMPLE) pixcode; *output_ptr += (JSAMPLE) pixcode;
/* Compute actual representation error at this pixel */ /* Compute actual representation error at this pixel */
/* Note: we can do this even though we don't have the final */ /* Note: we can do this even though we don't have the final */
/* pixel code, because the colormap is orthogonal. */ /* pixel code, because the colormap is orthogonal. */
cur -= GETJSAMPLE(colormap_ci[pixcode]); cur -= GETJSAMPLE(colormap_ci[pixcode]);
/* Compute error fractions to be propagated to adjacent pixels. /* Compute error fractions to be propagated to adjacent pixels.
* Add these into the running sums, and simultaneously shift the * Add these into the running sums, and simultaneously shift the
* next-line error sums left by 1 column. * next-line error sums left by 1 column.
*/ */
bnexterr = cur; bnexterr = cur;
delta = cur * 2; delta = cur * 2;
cur += delta; /* form error * 3 */ cur += delta; /* form error * 3 */
errorptr[0] = (FSERROR) (bpreverr + cur); errorptr[0] = (FSERROR) (bpreverr + cur);
cur += delta; /* form error * 5 */ cur += delta; /* form error * 5 */
bpreverr = belowerr + cur; bpreverr = belowerr + cur;
belowerr = bnexterr; belowerr = bnexterr;
cur += delta; /* form error * 7 */ cur += delta; /* form error * 7 */
/* At this point cur contains the 7/16 error value to be propagated /* At this point cur contains the 7/16 error value to be propagated
* to the next pixel on the current line, and all the errors for the * to the next pixel on the current line, and all the errors for the
* next line have been shifted over. We are therefore ready to move on. * next line have been shifted over. We are therefore ready to move on.
*/ */
input_ptr += dirnc; /* advance input ptr to next column */ input_ptr += dirnc; /* advance input ptr to next column */
output_ptr += dir; /* advance output ptr to next column */ output_ptr += dir; /* advance output ptr to next column */
errorptr += dir; /* advance errorptr to current column */ errorptr += dir; /* advance errorptr to current column */
} }
/* Post-loop cleanup: we must unload the final error value into the /* Post-loop cleanup: we must unload the final error value into the
* final fserrors[] entry. Note we need not unload belowerr because * final fserrors[] entry. Note we need not unload belowerr because
@@ -766,7 +766,7 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
cquantize->pub.color_quantize = quantize3_ord_dither; cquantize->pub.color_quantize = quantize3_ord_dither;
else else
cquantize->pub.color_quantize = quantize_ord_dither; cquantize->pub.color_quantize = quantize_ord_dither;
cquantize->row_index = 0; /* initialize state for ordered dither */ cquantize->row_index = 0; /* initialize state for ordered dither */
/* If user changed to ordered dither from another mode, /* If user changed to ordered dither from another mode,
* we must recreate the color index table with padding. * we must recreate the color index table with padding.
* This will cost extra space, but probably isn't very likely. * This will cost extra space, but probably isn't very likely.
@@ -829,13 +829,13 @@ jinit_1pass_quantizer (j_decompress_ptr cinfo)
cquantize = (my_cquantize_ptr) cquantize = (my_cquantize_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_cquantizer)); SIZEOF(my_cquantizer));
cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize; cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
cquantize->pub.start_pass = start_pass_1_quant; cquantize->pub.start_pass = start_pass_1_quant;
cquantize->pub.finish_pass = finish_pass_1_quant; cquantize->pub.finish_pass = finish_pass_1_quant;
cquantize->pub.new_color_map = new_color_map_1_quant; cquantize->pub.new_color_map = new_color_map_1_quant;
cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */ cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */ cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
/* Make sure my internal arrays won't overflow */ /* Make sure my internal arrays won't overflow */
if (cinfo->out_color_components > MAX_Q_COMPS) if (cinfo->out_color_components > MAX_Q_COMPS)

320
jquant2.c
View File

@@ -72,9 +72,9 @@
* probably need to change these scale factors. * probably need to change these scale factors.
*/ */
#define R_SCALE 2 /* scale R distances by this much */ #define R_SCALE 2 /* scale R distances by this much */
#define G_SCALE 3 /* scale G distances by this much */ #define G_SCALE 3 /* scale G distances by this much */
#define B_SCALE 1 /* and B by this much */ #define B_SCALE 1 /* and B by this much */
static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE}; static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE};
#define C0_SCALE c_scales[rgb_red[cinfo->out_color_space]] #define C0_SCALE c_scales[rgb_red[cinfo->out_color_space]]
@@ -112,9 +112,9 @@ static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE};
/* These will do the right thing for either R,G,B or B,G,R color order, /* These will do the right thing for either R,G,B or B,G,R color order,
* but you may not like the results for other color orders. * but you may not like the results for other color orders.
*/ */
#define HIST_C0_BITS 5 /* bits of precision in R/B histogram */ #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
#define HIST_C1_BITS 6 /* bits of precision in G histogram */ #define HIST_C1_BITS 6 /* bits of precision in G histogram */
#define HIST_C2_BITS 5 /* bits of precision in B/R histogram */ #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
/* Number of elements along histogram axes. */ /* Number of elements along histogram axes. */
#define HIST_C0_ELEMS (1<<HIST_C0_BITS) #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
@@ -127,13 +127,13 @@ static const int c_scales[3]={R_SCALE, G_SCALE, B_SCALE};
#define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS) #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */ typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
typedef histcell FAR * histptr; /* for pointers to histogram cells */ typedef histcell FAR * histptr; /* for pointers to histogram cells */
typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */ typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */ typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
typedef hist2d * hist3d; /* type for top-level pointer */ typedef hist2d * hist3d; /* type for top-level pointer */
/* Declarations for Floyd-Steinberg dithering. /* Declarations for Floyd-Steinberg dithering.
@@ -141,8 +141,8 @@ typedef hist2d * hist3d; /* type for top-level pointer */
* Errors are accumulated into the array fserrors[], at a resolution of * Errors are accumulated into the array fserrors[], at a resolution of
* 1/16th of a pixel count. The error at a given pixel is propagated * 1/16th of a pixel count. The error at a given pixel is propagated
* to its not-yet-processed neighbors using the standard F-S fractions, * to its not-yet-processed neighbors using the standard F-S fractions,
* ... (here) 7/16 * ... (here) 7/16
* 3/16 5/16 1/16 * 3/16 5/16 1/16
* We work left-to-right on even rows, right-to-left on odd rows. * We work left-to-right on even rows, right-to-left on odd rows.
* *
* We can get away with a single array (holding one row's worth of errors) * We can get away with a single array (holding one row's worth of errors)
@@ -161,14 +161,14 @@ typedef hist2d * hist3d; /* type for top-level pointer */
*/ */
#if BITS_IN_JSAMPLE == 8 #if BITS_IN_JSAMPLE == 8
typedef INT16 FSERROR; /* 16 bits should be enough */ typedef INT16 FSERROR; /* 16 bits should be enough */
typedef int LOCFSERROR; /* use 'int' for calculation temps */ typedef int LOCFSERROR; /* use 'int' for calculation temps */
#else #else
typedef INT32 FSERROR; /* may need more than 16 bits */ typedef INT32 FSERROR; /* may need more than 16 bits */
typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */ typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
#endif #endif
typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */ typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
/* Private subobject */ /* Private subobject */
@@ -177,18 +177,18 @@ typedef struct {
struct jpeg_color_quantizer pub; /* public fields */ struct jpeg_color_quantizer pub; /* public fields */
/* Space for the eventually created colormap is stashed here */ /* Space for the eventually created colormap is stashed here */
JSAMPARRAY sv_colormap; /* colormap allocated at init time */ JSAMPARRAY sv_colormap; /* colormap allocated at init time */
int desired; /* desired # of colors = size of colormap */ int desired; /* desired # of colors = size of colormap */
/* Variables for accumulating image statistics */ /* Variables for accumulating image statistics */
hist3d histogram; /* pointer to the histogram */ hist3d histogram; /* pointer to the histogram */
boolean needs_zeroed; /* TRUE if next pass must zero histogram */ boolean needs_zeroed; /* TRUE if next pass must zero histogram */
/* Variables for Floyd-Steinberg dithering */ /* Variables for Floyd-Steinberg dithering */
FSERRPTR fserrors; /* accumulated errors */ FSERRPTR fserrors; /* accumulated errors */
boolean on_odd_row; /* flag to remember which row we are on */ boolean on_odd_row; /* flag to remember which row we are on */
int * error_limiter; /* table for clamping the applied error */ int * error_limiter; /* table for clamping the applied error */
} my_cquantizer; } my_cquantizer;
typedef my_cquantizer * my_cquantize_ptr; typedef my_cquantizer * my_cquantize_ptr;
@@ -205,7 +205,7 @@ typedef my_cquantizer * my_cquantize_ptr;
METHODDEF(void) METHODDEF(void)
prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf, prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
register JSAMPROW ptr; register JSAMPROW ptr;
@@ -220,11 +220,11 @@ prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (col = width; col > 0; col--) { for (col = width; col > 0; col--) {
/* get pixel value and index into the histogram */ /* get pixel value and index into the histogram */
histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT] histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
[GETJSAMPLE(ptr[1]) >> C1_SHIFT] [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
[GETJSAMPLE(ptr[2]) >> C2_SHIFT]; [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
/* increment, check for overflow and undo increment if so. */ /* increment, check for overflow and undo increment if so. */
if (++(*histp) <= 0) if (++(*histp) <= 0)
(*histp)--; (*histp)--;
ptr += 3; ptr += 3;
} }
} }
@@ -312,67 +312,67 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
if (c0max > c0min) if (c0max > c0min)
for (c0 = c0min; c0 <= c0max; c0++) for (c0 = c0min; c0 <= c0max; c0++)
for (c1 = c1min; c1 <= c1max; c1++) { for (c1 = c1min; c1 <= c1max; c1++) {
histp = & histogram[c0][c1][c2min]; histp = & histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++) for (c2 = c2min; c2 <= c2max; c2++)
if (*histp++ != 0) { if (*histp++ != 0) {
boxp->c0min = c0min = c0; boxp->c0min = c0min = c0;
goto have_c0min; goto have_c0min;
} }
} }
have_c0min: have_c0min:
if (c0max > c0min) if (c0max > c0min)
for (c0 = c0max; c0 >= c0min; c0--) for (c0 = c0max; c0 >= c0min; c0--)
for (c1 = c1min; c1 <= c1max; c1++) { for (c1 = c1min; c1 <= c1max; c1++) {
histp = & histogram[c0][c1][c2min]; histp = & histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++) for (c2 = c2min; c2 <= c2max; c2++)
if (*histp++ != 0) { if (*histp++ != 0) {
boxp->c0max = c0max = c0; boxp->c0max = c0max = c0;
goto have_c0max; goto have_c0max;
} }
} }
have_c0max: have_c0max:
if (c1max > c1min) if (c1max > c1min)
for (c1 = c1min; c1 <= c1max; c1++) for (c1 = c1min; c1 <= c1max; c1++)
for (c0 = c0min; c0 <= c0max; c0++) { for (c0 = c0min; c0 <= c0max; c0++) {
histp = & histogram[c0][c1][c2min]; histp = & histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++) for (c2 = c2min; c2 <= c2max; c2++)
if (*histp++ != 0) { if (*histp++ != 0) {
boxp->c1min = c1min = c1; boxp->c1min = c1min = c1;
goto have_c1min; goto have_c1min;
} }
} }
have_c1min: have_c1min:
if (c1max > c1min) if (c1max > c1min)
for (c1 = c1max; c1 >= c1min; c1--) for (c1 = c1max; c1 >= c1min; c1--)
for (c0 = c0min; c0 <= c0max; c0++) { for (c0 = c0min; c0 <= c0max; c0++) {
histp = & histogram[c0][c1][c2min]; histp = & histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++) for (c2 = c2min; c2 <= c2max; c2++)
if (*histp++ != 0) { if (*histp++ != 0) {
boxp->c1max = c1max = c1; boxp->c1max = c1max = c1;
goto have_c1max; goto have_c1max;
} }
} }
have_c1max: have_c1max:
if (c2max > c2min) if (c2max > c2min)
for (c2 = c2min; c2 <= c2max; c2++) for (c2 = c2min; c2 <= c2max; c2++)
for (c0 = c0min; c0 <= c0max; c0++) { for (c0 = c0min; c0 <= c0max; c0++) {
histp = & histogram[c0][c1min][c2]; histp = & histogram[c0][c1min][c2];
for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS) for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
if (*histp != 0) { if (*histp != 0) {
boxp->c2min = c2min = c2; boxp->c2min = c2min = c2;
goto have_c2min; goto have_c2min;
} }
} }
have_c2min: have_c2min:
if (c2max > c2min) if (c2max > c2min)
for (c2 = c2max; c2 >= c2min; c2--) for (c2 = c2max; c2 >= c2min; c2--)
for (c0 = c0min; c0 <= c0max; c0++) { for (c0 = c0min; c0 <= c0max; c0++) {
histp = & histogram[c0][c1min][c2]; histp = & histogram[c0][c1min][c2];
for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS) for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
if (*histp != 0) { if (*histp != 0) {
boxp->c2max = c2max = c2; boxp->c2max = c2max = c2;
goto have_c2max; goto have_c2max;
} }
} }
have_c2max: have_c2max:
@@ -395,9 +395,9 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
for (c1 = c1min; c1 <= c1max; c1++) { for (c1 = c1min; c1 <= c1max; c1++) {
histp = & histogram[c0][c1][c2min]; histp = & histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++, histp++) for (c2 = c2min; c2 <= c2max; c2++, histp++)
if (*histp != 0) { if (*histp != 0) {
ccount++; ccount++;
} }
} }
boxp->colorcount = ccount; boxp->colorcount = ccount;
} }
@@ -405,7 +405,7 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
LOCAL(int) LOCAL(int)
median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes, median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
int desired_colors) int desired_colors)
/* Repeatedly select and split the largest box until we have enough boxes */ /* Repeatedly select and split the largest box until we have enough boxes */
{ {
int n,lb; int n,lb;
@@ -421,9 +421,9 @@ median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
} else { } else {
b1 = find_biggest_volume(boxlist, numboxes); b1 = find_biggest_volume(boxlist, numboxes);
} }
if (b1 == NULL) /* no splittable boxes left! */ if (b1 == NULL) /* no splittable boxes left! */
break; break;
b2 = &boxlist[numboxes]; /* where new box will go */ b2 = &boxlist[numboxes]; /* where new box will go */
/* Copy the color bounds to the new box. */ /* Copy the color bounds to the new box. */
b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max; b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min; b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
@@ -504,12 +504,12 @@ compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
for (c1 = c1min; c1 <= c1max; c1++) { for (c1 = c1min; c1 <= c1max; c1++) {
histp = & histogram[c0][c1][c2min]; histp = & histogram[c0][c1][c2min];
for (c2 = c2min; c2 <= c2max; c2++) { for (c2 = c2min; c2 <= c2max; c2++) {
if ((count = *histp++) != 0) { if ((count = *histp++) != 0) {
total += count; total += count;
c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count; c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count; c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count; c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
} }
} }
} }
@@ -628,7 +628,7 @@ select_colors (j_decompress_ptr cinfo, int desired_colors)
LOCAL(int) LOCAL(int)
find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2, find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
JSAMPLE colorlist[]) JSAMPLE colorlist[])
/* Locate the colormap entries close enough to an update box to be candidates /* Locate the colormap entries close enough to an update box to be candidates
* for the nearest entry to some cell(s) in the update box. The update box * for the nearest entry to some cell(s) in the update box. The update box
* is specified by the center coordinates of its first cell. The number of * is specified by the center coordinates of its first cell. The number of
@@ -643,7 +643,7 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
int centerc0, centerc1, centerc2; int centerc0, centerc1, centerc2;
int i, x, ncolors; int i, x, ncolors;
INT32 minmaxdist, min_dist, max_dist, tdist; INT32 minmaxdist, min_dist, max_dist, tdist;
INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */ INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
/* Compute true coordinates of update box's upper corner and center. /* Compute true coordinates of update box's upper corner and center.
* Actually we compute the coordinates of the center of the upper-corner * Actually we compute the coordinates of the center of the upper-corner
@@ -685,11 +685,11 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
/* within cell range so no contribution to min_dist */ /* within cell range so no contribution to min_dist */
min_dist = 0; min_dist = 0;
if (x <= centerc0) { if (x <= centerc0) {
tdist = (x - maxc0) * C0_SCALE; tdist = (x - maxc0) * C0_SCALE;
max_dist = tdist*tdist; max_dist = tdist*tdist;
} else { } else {
tdist = (x - minc0) * C0_SCALE; tdist = (x - minc0) * C0_SCALE;
max_dist = tdist*tdist; max_dist = tdist*tdist;
} }
} }
@@ -707,11 +707,11 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
} else { } else {
/* within cell range so no contribution to min_dist */ /* within cell range so no contribution to min_dist */
if (x <= centerc1) { if (x <= centerc1) {
tdist = (x - maxc1) * C1_SCALE; tdist = (x - maxc1) * C1_SCALE;
max_dist += tdist*tdist; max_dist += tdist*tdist;
} else { } else {
tdist = (x - minc1) * C1_SCALE; tdist = (x - minc1) * C1_SCALE;
max_dist += tdist*tdist; max_dist += tdist*tdist;
} }
} }
@@ -729,15 +729,15 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
} else { } else {
/* within cell range so no contribution to min_dist */ /* within cell range so no contribution to min_dist */
if (x <= centerc2) { if (x <= centerc2) {
tdist = (x - maxc2) * C2_SCALE; tdist = (x - maxc2) * C2_SCALE;
max_dist += tdist*tdist; max_dist += tdist*tdist;
} else { } else {
tdist = (x - minc2) * C2_SCALE; tdist = (x - minc2) * C2_SCALE;
max_dist += tdist*tdist; max_dist += tdist*tdist;
} }
} }
mindist[i] = min_dist; /* save away the results */ mindist[i] = min_dist; /* save away the results */
if (max_dist < minmaxdist) if (max_dist < minmaxdist)
minmaxdist = max_dist; minmaxdist = max_dist;
} }
@@ -757,7 +757,7 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
LOCAL(void) LOCAL(void)
find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2, find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[]) int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
/* Find the closest colormap entry for each cell in the update box, /* Find the closest colormap entry for each cell in the update box,
* given the list of candidate colors prepared by find_nearby_colors. * given the list of candidate colors prepared by find_nearby_colors.
* Return the indexes of the closest entries in the bestcolor[] array. * Return the indexes of the closest entries in the bestcolor[] array.
@@ -767,13 +767,13 @@ find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
{ {
int ic0, ic1, ic2; int ic0, ic1, ic2;
int i, icolor; int i, icolor;
register INT32 * bptr; /* pointer into bestdist[] array */ register INT32 * bptr; /* pointer into bestdist[] array */
JSAMPLE * cptr; /* pointer into bestcolor[] array */ JSAMPLE * cptr; /* pointer into bestcolor[] array */
INT32 dist0, dist1; /* initial distance values */ INT32 dist0, dist1; /* initial distance values */
register INT32 dist2; /* current distance in inner loop */ register INT32 dist2; /* current distance in inner loop */
INT32 xx0, xx1; /* distance increments */ INT32 xx0, xx1; /* distance increments */
register INT32 xx2; register INT32 xx2;
INT32 inc0, inc1, inc2; /* initial values for increments */ INT32 inc0, inc1, inc2; /* initial values for increments */
/* This array holds the distance to the nearest-so-far color for each cell */ /* This array holds the distance to the nearest-so-far color for each cell */
INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS]; INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
@@ -813,20 +813,20 @@ find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
dist1 = dist0; dist1 = dist0;
xx1 = inc1; xx1 = inc1;
for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) { for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
dist2 = dist1; dist2 = dist1;
xx2 = inc2; xx2 = inc2;
for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) { for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
if (dist2 < *bptr) { if (dist2 < *bptr) {
*bptr = dist2; *bptr = dist2;
*cptr = (JSAMPLE) icolor; *cptr = (JSAMPLE) icolor;
} }
dist2 += xx2; dist2 += xx2;
xx2 += 2 * STEP_C2 * STEP_C2; xx2 += 2 * STEP_C2 * STEP_C2;
bptr++; bptr++;
cptr++; cptr++;
} }
dist1 += xx1; dist1 += xx1;
xx1 += 2 * STEP_C1 * STEP_C1; xx1 += 2 * STEP_C1 * STEP_C1;
} }
dist0 += xx0; dist0 += xx0;
xx0 += 2 * STEP_C0 * STEP_C0; xx0 += 2 * STEP_C0 * STEP_C0;
@@ -843,13 +843,13 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
hist3d histogram = cquantize->histogram; hist3d histogram = cquantize->histogram;
int minc0, minc1, minc2; /* lower left corner of update box */ int minc0, minc1, minc2; /* lower left corner of update box */
int ic0, ic1, ic2; int ic0, ic1, ic2;
register JSAMPLE * cptr; /* pointer into bestcolor[] array */ register JSAMPLE * cptr; /* pointer into bestcolor[] array */
register histptr cachep; /* pointer into main cache array */ register histptr cachep; /* pointer into main cache array */
/* This array lists the candidate colormap indexes. */ /* This array lists the candidate colormap indexes. */
JSAMPLE colorlist[MAXNUMCOLORS]; JSAMPLE colorlist[MAXNUMCOLORS];
int numcolors; /* number of candidate colors */ int numcolors; /* number of candidate colors */
/* This array holds the actually closest colormap index for each cell. */ /* This array holds the actually closest colormap index for each cell. */
JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS]; JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
@@ -873,10 +873,10 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
/* Determine the actually nearest colors. */ /* Determine the actually nearest colors. */
find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist, find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
bestcolor); bestcolor);
/* Save the best color numbers (plus 1) in the main cache array */ /* Save the best color numbers (plus 1) in the main cache array */
c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */ c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
c1 <<= BOX_C1_LOG; c1 <<= BOX_C1_LOG;
c2 <<= BOX_C2_LOG; c2 <<= BOX_C2_LOG;
cptr = bestcolor; cptr = bestcolor;
@@ -884,7 +884,7 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) { for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
cachep = & histogram[c0+ic0][c1+ic1][c2]; cachep = & histogram[c0+ic0][c1+ic1][c2];
for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) { for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
*cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1); *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
} }
} }
} }
@@ -897,7 +897,7 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
METHODDEF(void) METHODDEF(void)
pass2_no_dither (j_decompress_ptr cinfo, pass2_no_dither (j_decompress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows) JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
/* This version performs no dithering */ /* This version performs no dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
@@ -921,7 +921,7 @@ pass2_no_dither (j_decompress_ptr cinfo,
/* If we have not seen this color before, find nearest colormap entry */ /* If we have not seen this color before, find nearest colormap entry */
/* and update the cache */ /* and update the cache */
if (*cachep == 0) if (*cachep == 0)
fill_inverse_cmap(cinfo, c0,c1,c2); fill_inverse_cmap(cinfo, c0,c1,c2);
/* Now emit the colormap index for this cell */ /* Now emit the colormap index for this cell */
*outptr++ = (JSAMPLE) (*cachep - 1); *outptr++ = (JSAMPLE) (*cachep - 1);
} }
@@ -931,20 +931,20 @@ pass2_no_dither (j_decompress_ptr cinfo,
METHODDEF(void) METHODDEF(void)
pass2_fs_dither (j_decompress_ptr cinfo, pass2_fs_dither (j_decompress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows) JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
/* This version performs Floyd-Steinberg dithering */ /* This version performs Floyd-Steinberg dithering */
{ {
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
hist3d histogram = cquantize->histogram; hist3d histogram = cquantize->histogram;
register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */ register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */ LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */ LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
register FSERRPTR errorptr; /* => fserrors[] at column before current */ register FSERRPTR errorptr; /* => fserrors[] at column before current */
JSAMPROW inptr; /* => current input pixel */ JSAMPROW inptr; /* => current input pixel */
JSAMPROW outptr; /* => current output pixel */ JSAMPROW outptr; /* => current output pixel */
histptr cachep; histptr cachep;
int dir; /* +1 or -1 depending on direction */ int dir; /* +1 or -1 depending on direction */
int dir3; /* 3*dir, for advancing inptr & errorptr */ int dir3; /* 3*dir, for advancing inptr & errorptr */
int row; int row;
JDIMENSION col; JDIMENSION col;
JDIMENSION width = cinfo->output_width; JDIMENSION width = cinfo->output_width;
@@ -960,7 +960,7 @@ pass2_fs_dither (j_decompress_ptr cinfo,
outptr = output_buf[row]; outptr = output_buf[row];
if (cquantize->on_odd_row) { if (cquantize->on_odd_row) {
/* work right to left in this row */ /* work right to left in this row */
inptr += (width-1) * 3; /* so point to rightmost pixel */ inptr += (width-1) * 3; /* so point to rightmost pixel */
outptr += width-1; outptr += width-1;
dir = -1; dir = -1;
dir3 = -3; dir3 = -3;
@@ -1012,14 +1012,14 @@ pass2_fs_dither (j_decompress_ptr cinfo,
/* If we have not seen this color before, find nearest colormap */ /* If we have not seen this color before, find nearest colormap */
/* entry and update the cache */ /* entry and update the cache */
if (*cachep == 0) if (*cachep == 0)
fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT); fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
/* Now emit the colormap index for this cell */ /* Now emit the colormap index for this cell */
{ register int pixcode = *cachep - 1; { register int pixcode = *cachep - 1;
*outptr = (JSAMPLE) pixcode; *outptr = (JSAMPLE) pixcode;
/* Compute representation error for this pixel */ /* Compute representation error for this pixel */
cur0 -= GETJSAMPLE(colormap0[pixcode]); cur0 -= GETJSAMPLE(colormap0[pixcode]);
cur1 -= GETJSAMPLE(colormap1[pixcode]); cur1 -= GETJSAMPLE(colormap1[pixcode]);
cur2 -= GETJSAMPLE(colormap2[pixcode]); cur2 -= GETJSAMPLE(colormap2[pixcode]);
} }
/* Compute error fractions to be propagated to adjacent pixels. /* Compute error fractions to be propagated to adjacent pixels.
* Add these into the running sums, and simultaneously shift the * Add these into the running sums, and simultaneously shift the
@@ -1027,29 +1027,29 @@ pass2_fs_dither (j_decompress_ptr cinfo,
*/ */
{ register LOCFSERROR bnexterr; { register LOCFSERROR bnexterr;
bnexterr = cur0; /* Process component 0 */ bnexterr = cur0; /* Process component 0 */
errorptr[0] = (FSERROR) (bpreverr0 + cur0 * 3); errorptr[0] = (FSERROR) (bpreverr0 + cur0 * 3);
bpreverr0 = belowerr0 + cur0 * 5; bpreverr0 = belowerr0 + cur0 * 5;
belowerr0 = bnexterr; belowerr0 = bnexterr;
cur0 *= 7; cur0 *= 7;
bnexterr = cur1; /* Process component 1 */ bnexterr = cur1; /* Process component 1 */
errorptr[1] = (FSERROR) (bpreverr1 + cur1 * 3); errorptr[1] = (FSERROR) (bpreverr1 + cur1 * 3);
bpreverr1 = belowerr1 + cur1 * 5; bpreverr1 = belowerr1 + cur1 * 5;
belowerr1 = bnexterr; belowerr1 = bnexterr;
cur1 *= 7; cur1 *= 7;
bnexterr = cur2; /* Process component 2 */ bnexterr = cur2; /* Process component 2 */
errorptr[2] = (FSERROR) (bpreverr2 + cur2 * 3); errorptr[2] = (FSERROR) (bpreverr2 + cur2 * 3);
bpreverr2 = belowerr2 + cur2 * 5; bpreverr2 = belowerr2 + cur2 * 5;
belowerr2 = bnexterr; belowerr2 = bnexterr;
cur2 *= 7; cur2 *= 7;
} }
/* At this point curN contains the 7/16 error value to be propagated /* At this point curN contains the 7/16 error value to be propagated
* to the next pixel on the current line, and all the errors for the * to the next pixel on the current line, and all the errors for the
* next line have been shifted over. We are therefore ready to move on. * next line have been shifted over. We are therefore ready to move on.
*/ */
inptr += dir3; /* Advance pixel pointers to next column */ inptr += dir3; /* Advance pixel pointers to next column */
outptr += dir; outptr += dir;
errorptr += dir3; /* advance errorptr to current column */ errorptr += dir3; /* advance errorptr to current column */
} }
/* Post-loop cleanup: we must unload the final error values into the /* Post-loop cleanup: we must unload the final error values into the
* final fserrors[] entry. Note we need not unload belowerrN because * final fserrors[] entry. Note we need not unload belowerrN because
@@ -1089,7 +1089,7 @@ init_error_limit (j_decompress_ptr cinfo)
table = (int *) (*cinfo->mem->alloc_small) table = (int *) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int)); ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */ table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
cquantize->error_limiter = table; cquantize->error_limiter = table;
#define STEPSIZE ((MAXJSAMPLE+1)/16) #define STEPSIZE ((MAXJSAMPLE+1)/16)
@@ -1172,16 +1172,16 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
if (cinfo->dither_mode == JDITHER_FS) { if (cinfo->dither_mode == JDITHER_FS) {
size_t arraysize = (size_t) ((cinfo->output_width + 2) * size_t arraysize = (size_t) ((cinfo->output_width + 2) *
(3 * SIZEOF(FSERROR))); (3 * SIZEOF(FSERROR)));
/* Allocate Floyd-Steinberg workspace if we didn't already. */ /* Allocate Floyd-Steinberg workspace if we didn't already. */
if (cquantize->fserrors == NULL) if (cquantize->fserrors == NULL)
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize); ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
/* Initialize the propagated errors to zero. */ /* Initialize the propagated errors to zero. */
jzero_far((void FAR *) cquantize->fserrors, arraysize); jzero_far((void FAR *) cquantize->fserrors, arraysize);
/* Make the error-limit table if we didn't already. */ /* Make the error-limit table if we didn't already. */
if (cquantize->error_limiter == NULL) if (cquantize->error_limiter == NULL)
init_error_limit(cinfo); init_error_limit(cinfo);
cquantize->on_odd_row = FALSE; cquantize->on_odd_row = FALSE;
} }
@@ -1190,7 +1190,7 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
if (cquantize->needs_zeroed) { if (cquantize->needs_zeroed) {
for (i = 0; i < HIST_C0_ELEMS; i++) { for (i = 0; i < HIST_C0_ELEMS; i++) {
jzero_far((void FAR *) histogram[i], jzero_far((void FAR *) histogram[i],
HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell)); HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
} }
cquantize->needs_zeroed = FALSE; cquantize->needs_zeroed = FALSE;
} }
@@ -1223,11 +1223,11 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
cquantize = (my_cquantize_ptr) cquantize = (my_cquantize_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_cquantizer)); SIZEOF(my_cquantizer));
cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize; cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
cquantize->pub.start_pass = start_pass_2_quant; cquantize->pub.start_pass = start_pass_2_quant;
cquantize->pub.new_color_map = new_color_map_2_quant; cquantize->pub.new_color_map = new_color_map_2_quant;
cquantize->fserrors = NULL; /* flag optional arrays not allocated */ cquantize->fserrors = NULL; /* flag optional arrays not allocated */
cquantize->error_limiter = NULL; cquantize->error_limiter = NULL;
/* Make sure jdmaster didn't give me a case I can't handle */ /* Make sure jdmaster didn't give me a case I can't handle */

View File

@@ -3,7 +3,7 @@
* *
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright 2011 D. R. Commander * Copyright 2011 D. R. Commander
* *
* Based on the x86 SIMD extension for IJG JPEG library, * Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru. * Copyright (C) 1999-2006, MIYASAKA Masaru.
* For conditions of distribution and use, see copyright notice in jsimdext.inc * For conditions of distribution and use, see copyright notice in jsimdext.inc

View File

@@ -3,7 +3,7 @@
* *
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright 2009-2011 D. R. Commander * Copyright 2009-2011 D. R. Commander
* *
* Based on the x86 SIMD extension for IJG JPEG library, * Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru. * Copyright (C) 1999-2006, MIYASAKA Masaru.
* For conditions of distribution and use, see copyright notice in jsimdext.inc * For conditions of distribution and use, see copyright notice in jsimdext.inc
@@ -95,7 +95,7 @@ jsimd_can_h2v1_upsample (void)
GLOBAL(void) GLOBAL(void)
jsimd_h2v2_upsample (j_decompress_ptr cinfo, jsimd_h2v2_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr) JSAMPARRAY * output_data_ptr)
{ {
@@ -103,7 +103,7 @@ jsimd_h2v2_upsample (j_decompress_ptr cinfo,
GLOBAL(void) GLOBAL(void)
jsimd_h2v1_upsample (j_decompress_ptr cinfo, jsimd_h2v1_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr) JSAMPARRAY * output_data_ptr)
{ {
@@ -123,7 +123,7 @@ jsimd_can_h2v1_fancy_upsample (void)
GLOBAL(void) GLOBAL(void)
jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo, jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr) JSAMPARRAY * output_data_ptr)
{ {
@@ -131,7 +131,7 @@ jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo,
GLOBAL(void) GLOBAL(void)
jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo, jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo,
jpeg_component_info * compptr, jpeg_component_info * compptr,
JSAMPARRAY input_data, JSAMPARRAY input_data,
JSAMPARRAY * output_data_ptr) JSAMPARRAY * output_data_ptr)
{ {

View File

@@ -2,7 +2,7 @@
* jsimddct.h * jsimddct.h
* *
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* *
* Based on the x86 SIMD extension for IJG JPEG library, * Based on the x86 SIMD extension for IJG JPEG library,
* Copyright (C) 1999-2006, MIYASAKA Masaru. * Copyright (C) 1999-2006, MIYASAKA Masaru.
* For conditions of distribution and use, see copyright notice in jsimdext.inc * For conditions of distribution and use, see copyright notice in jsimdext.inc

View File

@@ -21,7 +21,7 @@
* of a DCT block read in natural order (left to right, top to bottom). * of a DCT block read in natural order (left to right, top to bottom).
*/ */
#if 0 /* This table is not actually needed in v6a */ #if 0 /* This table is not actually needed in v6a */
const int jpeg_zigzag_order[DCTSIZE2] = { const int jpeg_zigzag_order[DCTSIZE2] = {
0, 1, 5, 6, 14, 15, 27, 28, 0, 1, 5, 6, 14, 15, 27, 28,
@@ -96,21 +96,21 @@ jround_up (long a, long b)
* is not all that great, because these routines aren't very heavily used.) * is not all that great, because these routines aren't very heavily used.)
*/ */
#ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */ #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size) #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
#define FMEMZERO(target,size) MEMZERO(target,size) #define FMEMZERO(target,size) MEMZERO(target,size)
#else /* 80x86 case, define if we can */ #else /* 80x86 case, define if we can */
#ifdef USE_FMEM #ifdef USE_FMEM
#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size)) #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size)) #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
#endif #endif
#endif #endif
GLOBAL(void) GLOBAL(void)
jcopy_sample_rows (JSAMPARRAY input_array, int source_row, jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
JSAMPARRAY output_array, int dest_row, JSAMPARRAY output_array, int dest_row,
int num_rows, JDIMENSION num_cols) int num_rows, JDIMENSION num_cols)
/* Copy some rows of samples from one place to another. /* Copy some rows of samples from one place to another.
* num_rows rows are copied from input_array[source_row++] * num_rows rows are copied from input_array[source_row++]
* to output_array[dest_row++]; these areas may overlap for duplication. * to output_array[dest_row++]; these areas may overlap for duplication.
@@ -135,7 +135,7 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
FMEMCOPY(outptr, inptr, count); FMEMCOPY(outptr, inptr, count);
#else #else
for (count = num_cols; count > 0; count--) for (count = num_cols; count > 0; count--)
*outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */ *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
#endif #endif
} }
} }
@@ -143,7 +143,7 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
GLOBAL(void) GLOBAL(void)
jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
JDIMENSION num_blocks) JDIMENSION num_blocks)
/* Copy a row of coefficient blocks from one place to another. */ /* Copy a row of coefficient blocks from one place to another. */
{ {
#ifdef FMEMCOPY #ifdef FMEMCOPY

View File

@@ -13,20 +13,20 @@
#if JPEG_LIB_VERSION >= 80 #if JPEG_LIB_VERSION >= 80
#define JVERSION "8d 15-Jan-2012" #define JVERSION "8d 15-Jan-2012"
#elif JPEG_LIB_VERSION >= 70 #elif JPEG_LIB_VERSION >= 70
#define JVERSION "7 27-Jun-2009" #define JVERSION "7 27-Jun-2009"
#else #else
#define JVERSION "6b 27-Mar-1998" #define JVERSION "6b 27-Mar-1998"
#endif #endif
#define JCOPYRIGHT "Copyright (C) 1991-2012 Thomas G. Lane, Guido Vollbeding\n" \ #define JCOPYRIGHT "Copyright (C) 1991-2012 Thomas G. Lane, Guido Vollbeding\n" \
"Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
"Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \ "Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \
"Copyright (C) 2009-2014 D. R. Commander\n" \ "Copyright (C) 2009-2014 D. R. Commander\n" \
"Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)" "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)"

File diff suppressed because it is too large Load Diff

64
rdbmp.c
View File

@@ -24,7 +24,7 @@
* This code contributed by James Arthur Boucher. * This code contributed by James Arthur Boucher.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef BMP_SUPPORTED #ifdef BMP_SUPPORTED
@@ -33,19 +33,19 @@
#ifdef HAVE_UNSIGNED_CHAR #ifdef HAVE_UNSIGNED_CHAR
typedef unsigned char U_CHAR; typedef unsigned char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else /* !HAVE_UNSIGNED_CHAR */ #else /* !HAVE_UNSIGNED_CHAR */
#ifdef __CHAR_UNSIGNED__ #ifdef __CHAR_UNSIGNED__
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else #else
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x) & 0xFF) #define UCH(x) ((int) (x) & 0xFF)
#endif #endif
#endif /* HAVE_UNSIGNED_CHAR */ #endif /* HAVE_UNSIGNED_CHAR */
#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) #define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
/* Private version of data source object */ /* Private version of data source object */
@@ -55,15 +55,15 @@ typedef struct _bmp_source_struct * bmp_source_ptr;
typedef struct _bmp_source_struct { typedef struct _bmp_source_struct {
struct cjpeg_source_struct pub; /* public fields */ struct cjpeg_source_struct pub; /* public fields */
j_compress_ptr cinfo; /* back link saves passing separate parm */ j_compress_ptr cinfo; /* back link saves passing separate parm */
JSAMPARRAY colormap; /* BMP colormap (converted to my format) */ JSAMPARRAY colormap; /* BMP colormap (converted to my format) */
jvirt_sarray_ptr whole_image; /* Needed to reverse row order */ jvirt_sarray_ptr whole_image; /* Needed to reverse row order */
JDIMENSION source_row; /* Current source row number */ JDIMENSION source_row; /* Current source row number */
JDIMENSION row_width; /* Physical width of scanlines in file */ JDIMENSION row_width; /* Physical width of scanlines in file */
int bits_per_pixel; /* remembers 8- or 24-bit format */ int bits_per_pixel; /* remembers 8- or 24-bit format */
} bmp_source_struct; } bmp_source_struct;
@@ -140,7 +140,7 @@ get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
outptr = source->pub.buffer[0]; outptr = source->pub.buffer[0];
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
t = GETJSAMPLE(*inptr++); t = GETJSAMPLE(*inptr++);
*outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */ *outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */
*outptr++ = colormap[1][t]; *outptr++ = colormap[1][t];
*outptr++ = colormap[2][t]; *outptr++ = colormap[2][t];
} }
@@ -170,7 +170,7 @@ get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
inptr = image_ptr[0]; inptr = image_ptr[0];
outptr = source->pub.buffer[0]; outptr = source->pub.buffer[0];
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */
outptr[1] = *inptr++; outptr[1] = *inptr++;
outptr[0] = *inptr++; outptr[0] = *inptr++;
outptr += 3; outptr += 3;
@@ -200,10 +200,10 @@ get_32bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
inptr = image_ptr[0]; inptr = image_ptr[0];
outptr = source->pub.buffer[0]; outptr = source->pub.buffer[0];
for (col = cinfo->image_width; col > 0; col--) { for (col = cinfo->image_width; col > 0; col--) {
outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */
outptr[1] = *inptr++; outptr[1] = *inptr++;
outptr[0] = *inptr++; outptr[0] = *inptr++;
inptr++; /* skip the 4th byte (Alpha channel) */ inptr++; /* skip the 4th byte (Alpha channel) */
outptr += 3; outptr += 3;
} }
@@ -280,11 +280,11 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
U_CHAR bmpfileheader[14]; U_CHAR bmpfileheader[14];
U_CHAR bmpinfoheader[64]; U_CHAR bmpinfoheader[64];
#define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \ #define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \
(((unsigned int) UCH(array[offset+1])) << 8)) (((unsigned int) UCH(array[offset+1])) << 8))
#define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \ #define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \
(((INT32) UCH(array[offset+1])) << 8) + \ (((INT32) UCH(array[offset+1])) << 8) + \
(((INT32) UCH(array[offset+2])) << 16) + \ (((INT32) UCH(array[offset+2])) << 16) + \
(((INT32) UCH(array[offset+3])) << 24)) (((INT32) UCH(array[offset+3])) << 24))
INT32 bfOffBits; INT32 bfOffBits;
INT32 headerSize; INT32 headerSize;
INT32 biWidth; INT32 biWidth;
@@ -293,7 +293,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
INT32 biCompression; INT32 biCompression;
INT32 biXPelsPerMeter,biYPelsPerMeter; INT32 biXPelsPerMeter,biYPelsPerMeter;
INT32 biClrUsed = 0; INT32 biClrUsed = 0;
int mapentrysize = 0; /* 0 indicates no colormap */ int mapentrysize = 0; /* 0 indicates no colormap */
INT32 bPad; INT32 bPad;
JDIMENSION row_width; JDIMENSION row_width;
@@ -325,11 +325,11 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10); source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10);
switch (source->bits_per_pixel) { switch (source->bits_per_pixel) {
case 8: /* colormapped image */ case 8: /* colormapped image */
mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */ mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */
TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight);
break; break;
case 24: /* RGB image */ case 24: /* RGB image */
TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight);
break; break;
default: default:
@@ -352,14 +352,14 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* biSizeImage, biClrImportant fields are ignored */ /* biSizeImage, biClrImportant fields are ignored */
switch (source->bits_per_pixel) { switch (source->bits_per_pixel) {
case 8: /* colormapped image */ case 8: /* colormapped image */
mapentrysize = 4; /* Windows uses RGBQUAD colormap */ mapentrysize = 4; /* Windows uses RGBQUAD colormap */
TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight);
break; break;
case 24: /* RGB image */ case 24: /* RGB image */
TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight);
break; break;
case 32: /* RGB image + Alpha channel */ case 32: /* RGB image + Alpha channel */
TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight);
break; break;
default: default:
@@ -373,7 +373,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* Set JFIF density parameters from the BMP data */ /* Set JFIF density parameters from the BMP data */
cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */ cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */
cinfo->Y_density = (UINT16) (biYPelsPerMeter/100); cinfo->Y_density = (UINT16) (biYPelsPerMeter/100);
cinfo->density_unit = 2; /* dots/cm */ cinfo->density_unit = 2; /* dots/cm */
} }
break; break;
default: default:
@@ -392,7 +392,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* Read the colormap, if any */ /* Read the colormap, if any */
if (mapentrysize > 0) { if (mapentrysize > 0) {
if (biClrUsed <= 0) if (biClrUsed <= 0)
biClrUsed = 256; /* assume it's 256 */ biClrUsed = 256; /* assume it's 256 */
else if (biClrUsed > 256) else if (biClrUsed > 256)
ERREXIT(cinfo, JERR_BMP_BADCMAP); ERREXIT(cinfo, JERR_BMP_BADCMAP);
/* Allocate space to store the colormap */ /* Allocate space to store the colormap */
@@ -406,7 +406,7 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} }
/* Skip any remaining pad bytes */ /* Skip any remaining pad bytes */
if (bPad < 0) /* incorrect bfOffBits value? */ if (bPad < 0) /* incorrect bfOffBits value? */
ERREXIT(cinfo, JERR_BMP_BADHEADER); ERREXIT(cinfo, JERR_BMP_BADHEADER);
while (--bPad >= 0) { while (--bPad >= 0) {
(void) read_byte(source); (void) read_byte(source);
@@ -469,8 +469,8 @@ jinit_read_bmp (j_compress_ptr cinfo)
/* Create module interface object */ /* Create module interface object */
source = (bmp_source_ptr) source = (bmp_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(bmp_source_struct)); SIZEOF(bmp_source_struct));
source->cinfo = cinfo; /* make back link for subroutines */ source->cinfo = cinfo; /* make back link for subroutines */
/* Fill in method ptrs, except get_pixel_rows which start_input sets */ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
source->pub.start_input = start_input_bmp; source->pub.start_input = start_input_bmp;
source->pub.finish_input = finish_input_bmp; source->pub.finish_input = finish_input_bmp;

View File

@@ -21,9 +21,9 @@
* currently implemented. * currently implemented.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ #ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
/* Portions of this code are based on the PBMPLUS library, which is: /* Portions of this code are based on the PBMPLUS library, which is:
** **
@@ -54,9 +54,9 @@ add_map_entry (j_decompress_ptr cinfo, int R, int G, int B)
/* Check for duplicate color. */ /* Check for duplicate color. */
for (index = 0; index < ncolors; index++) { for (index = 0; index < ncolors; index++) {
if (GETJSAMPLE(colormap0[index]) == R && if (GETJSAMPLE(colormap0[index]) == R &&
GETJSAMPLE(colormap1[index]) == G && GETJSAMPLE(colormap1[index]) == G &&
GETJSAMPLE(colormap2[index]) == B) GETJSAMPLE(colormap2[index]) == B)
return; /* color is already in map */ return; /* color is already in map */
} }
/* Check for map overflow. */ /* Check for map overflow. */
@@ -107,9 +107,9 @@ read_gif_map (j_decompress_ptr cinfo, FILE * infile)
if (R == EOF || G == EOF || B == EOF) if (R == EOF || G == EOF || B == EOF)
ERREXIT(cinfo, JERR_BAD_CMAP_FILE); ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
add_map_entry(cinfo, add_map_entry(cinfo,
R << (BITS_IN_JSAMPLE-8), R << (BITS_IN_JSAMPLE-8),
G << (BITS_IN_JSAMPLE-8), G << (BITS_IN_JSAMPLE-8),
B << (BITS_IN_JSAMPLE-8)); B << (BITS_IN_JSAMPLE-8));
} }
} }
@@ -123,7 +123,7 @@ pbm_getc (FILE * infile)
/* A comment/newline sequence is returned as a newline */ /* A comment/newline sequence is returned as a newline */
{ {
register int ch; register int ch;
ch = getc(infile); ch = getc(infile);
if (ch == '#') { if (ch == '#') {
do { do {
@@ -143,17 +143,17 @@ read_pbm_integer (j_decompress_ptr cinfo, FILE * infile)
{ {
register int ch; register int ch;
register unsigned int val; register unsigned int val;
/* Skip any leading whitespace */ /* Skip any leading whitespace */
do { do {
ch = pbm_getc(infile); ch = pbm_getc(infile);
if (ch == EOF) if (ch == EOF)
ERREXIT(cinfo, JERR_BAD_CMAP_FILE); ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
} while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
if (ch < '0' || ch > '9') if (ch < '0' || ch > '9')
ERREXIT(cinfo, JERR_BAD_CMAP_FILE); ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
val = ch - '0'; val = ch - '0';
while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
val *= 10; val *= 10;
@@ -175,7 +175,7 @@ read_ppm_map (j_decompress_ptr cinfo, FILE * infile)
int R, G, B; int R, G, B;
/* Initial 'P' has already been read by read_color_map */ /* Initial 'P' has already been read by read_color_map */
c = getc(infile); /* save format discriminator for a sec */ c = getc(infile); /* save format discriminator for a sec */
/* while we fetch the remaining header info */ /* while we fetch the remaining header info */
w = read_pbm_integer(cinfo, infile); w = read_pbm_integer(cinfo, infile);
@@ -190,26 +190,26 @@ read_ppm_map (j_decompress_ptr cinfo, FILE * infile)
ERREXIT(cinfo, JERR_BAD_CMAP_FILE); ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
switch (c) { switch (c) {
case '3': /* it's a text-format PPM file */ case '3': /* it's a text-format PPM file */
for (row = 0; row < h; row++) { for (row = 0; row < h; row++) {
for (col = 0; col < w; col++) { for (col = 0; col < w; col++) {
R = read_pbm_integer(cinfo, infile); R = read_pbm_integer(cinfo, infile);
G = read_pbm_integer(cinfo, infile); G = read_pbm_integer(cinfo, infile);
B = read_pbm_integer(cinfo, infile); B = read_pbm_integer(cinfo, infile);
add_map_entry(cinfo, R, G, B); add_map_entry(cinfo, R, G, B);
} }
} }
break; break;
case '6': /* it's a raw-format PPM file */ case '6': /* it's a raw-format PPM file */
for (row = 0; row < h; row++) { for (row = 0; row < h; row++) {
for (col = 0; col < w; col++) { for (col = 0; col < w; col++) {
R = getc(infile); R = getc(infile);
G = getc(infile); G = getc(infile);
B = getc(infile); B = getc(infile);
if (R == EOF || G == EOF || B == EOF) if (R == EOF || G == EOF || B == EOF)
ERREXIT(cinfo, JERR_BAD_CMAP_FILE); ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
add_map_entry(cinfo, R, G, B); add_map_entry(cinfo, R, G, B);
} }
} }
break; break;

View File

@@ -19,7 +19,7 @@
* CompuServe Incorporated." * CompuServe Incorporated."
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef GIF_SUPPORTED #ifdef GIF_SUPPORTED
@@ -32,7 +32,7 @@ jinit_read_gif (j_compress_ptr cinfo)
{ {
fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n"); fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
return NULL; /* keep compiler happy */ return NULL; /* keep compiler happy */
} }
#endif /* GIF_SUPPORTED */ #endif /* GIF_SUPPORTED */

View File

@@ -12,45 +12,45 @@
* JPEG markers. * JPEG markers.
*/ */
#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */ #define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
#include "jinclude.h" /* get auto-config symbols, <stdio.h> */ #include "jinclude.h" /* get auto-config symbols, <stdio.h> */
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
#include <locale.h> /* Bill Allombert: use locale for isprint */ #include <locale.h> /* Bill Allombert: use locale for isprint */
#endif #endif
#include <ctype.h> /* to declare isupper(), tolower() */ #include <ctype.h> /* to declare isupper(), tolower() */
#ifdef USE_SETMODE #ifdef USE_SETMODE
#include <fcntl.h> /* to declare setmode()'s parameter macros */ #include <fcntl.h> /* to declare setmode()'s parameter macros */
/* If you have setmode() but not <io.h>, just delete this line: */ /* If you have setmode() but not <io.h>, just delete this line: */
#include <io.h> /* to declare setmode() */ #include <io.h> /* to declare setmode() */
#endif #endif
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
#ifdef __MWERKS__ #ifdef __MWERKS__
#include <SIOUX.h> /* Metrowerks needs this */ #include <SIOUX.h> /* Metrowerks needs this */
#include <console.h> /* ... and this */ #include <console.h> /* ... and this */
#endif #endif
#ifdef THINK_C #ifdef THINK_C
#include <console.h> /* Think declares it here */ #include <console.h> /* Think declares it here */
#endif #endif
#endif #endif
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
#define READ_BINARY "r" #define READ_BINARY "r"
#else #else
#ifdef VMS /* VMS is very nonstandard */ #ifdef VMS /* VMS is very nonstandard */
#define READ_BINARY "rb", "ctx=stm" #define READ_BINARY "rb", "ctx=stm"
#else /* standard ANSI-compliant case */ #else /* standard ANSI-compliant case */
#define READ_BINARY "rb" #define READ_BINARY "rb"
#endif #endif
#endif #endif
#ifndef EXIT_FAILURE /* define exit() codes if not provided */ #ifndef EXIT_FAILURE /* define exit() codes if not provided */
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#endif #endif
#ifndef EXIT_SUCCESS #ifndef EXIT_SUCCESS
#ifdef VMS #ifdef VMS
#define EXIT_SUCCESS 1 /* VMS is very nonstandard */ #define EXIT_SUCCESS 1 /* VMS is very nonstandard */
#else #else
#define EXIT_SUCCESS 0 #define EXIT_SUCCESS 0
#endif #endif
@@ -62,7 +62,7 @@
* To reuse this code in another application, you might need to change these. * To reuse this code in another application, you might need to change these.
*/ */
static FILE * infile; /* input JPEG file */ static FILE * infile; /* input JPEG file */
/* Return next input byte, or EOF if no more */ /* Return next input byte, or EOF if no more */
#define NEXTBYTE() getc(infile) #define NEXTBYTE() getc(infile)
@@ -107,11 +107,11 @@ read_2_bytes (void)
* in this program. (See jdmarker.c for a more complete list.) * in this program. (See jdmarker.c for a more complete list.)
*/ */
#define M_SOF0 0xC0 /* Start Of Frame N */ #define M_SOF0 0xC0 /* Start Of Frame N */
#define M_SOF1 0xC1 /* N indicates which compression process */ #define M_SOF1 0xC1 /* N indicates which compression process */
#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ #define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
#define M_SOF3 0xC3 #define M_SOF3 0xC3
#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ #define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
#define M_SOF6 0xC6 #define M_SOF6 0xC6
#define M_SOF7 0xC7 #define M_SOF7 0xC7
#define M_SOF9 0xC9 #define M_SOF9 0xC9
@@ -120,12 +120,12 @@ read_2_bytes (void)
#define M_SOF13 0xCD #define M_SOF13 0xCD
#define M_SOF14 0xCE #define M_SOF14 0xCE
#define M_SOF15 0xCF #define M_SOF15 0xCF
#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ #define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
#define M_EOI 0xD9 /* End Of Image (end of datastream) */ #define M_EOI 0xD9 /* End Of Image (end of datastream) */
#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ #define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
#define M_APP0 0xE0 /* Application-specific marker, type N */ #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_APP12 0xEC /* (we don't bother to list all 16 APPn's) */
#define M_COM 0xFE /* COMment */ #define M_COM 0xFE /* COMment */
/* /*
@@ -253,7 +253,7 @@ process_COM (int raw)
printf("\n"); printf("\n");
} else if (ch == '\n') { } else if (ch == '\n') {
if (lastch != '\r') if (lastch != '\r')
printf("\n"); printf("\n");
} else if (ch == '\\') { } else if (ch == '\\') {
printf("\\\\"); printf("\\\\");
} else if (isprint(ch)) { } else if (isprint(ch)) {
@@ -287,7 +287,7 @@ process_SOFn (int marker)
const char * process; const char * process;
int ci; int ci;
length = read_2_bytes(); /* usual parameter length count */ length = read_2_bytes(); /* usual parameter length count */
data_precision = read_1_byte(); data_precision = read_1_byte();
image_height = read_2_bytes(); image_height = read_2_bytes();
@@ -295,33 +295,33 @@ process_SOFn (int marker)
num_components = read_1_byte(); num_components = read_1_byte();
switch (marker) { switch (marker) {
case M_SOF0: process = "Baseline"; break; case M_SOF0: process = "Baseline"; break;
case M_SOF1: process = "Extended sequential"; break; case M_SOF1: process = "Extended sequential"; break;
case M_SOF2: process = "Progressive"; break; case M_SOF2: process = "Progressive"; break;
case M_SOF3: process = "Lossless"; break; case M_SOF3: process = "Lossless"; break;
case M_SOF5: process = "Differential sequential"; break; case M_SOF5: process = "Differential sequential"; break;
case M_SOF6: process = "Differential progressive"; break; case M_SOF6: process = "Differential progressive"; break;
case M_SOF7: process = "Differential lossless"; break; case M_SOF7: process = "Differential lossless"; break;
case M_SOF9: process = "Extended sequential, arithmetic coding"; break; case M_SOF9: process = "Extended sequential, arithmetic coding"; break;
case M_SOF10: process = "Progressive, arithmetic coding"; break; case M_SOF10: process = "Progressive, arithmetic coding"; break;
case M_SOF11: process = "Lossless, arithmetic coding"; break; case M_SOF11: process = "Lossless, arithmetic coding"; break;
case M_SOF13: process = "Differential sequential, arithmetic coding"; break; case M_SOF13: process = "Differential sequential, arithmetic coding"; break;
case M_SOF14: process = "Differential progressive, arithmetic coding"; break; case M_SOF14: process = "Differential progressive, arithmetic coding"; break;
case M_SOF15: process = "Differential lossless, arithmetic coding"; break; case M_SOF15: process = "Differential lossless, arithmetic coding"; break;
default: process = "Unknown"; break; default: process = "Unknown"; break;
} }
printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n", printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n",
image_width, image_height, num_components, data_precision); image_width, image_height, num_components, data_precision);
printf("JPEG process: %s\n", process); printf("JPEG process: %s\n", process);
if (length != (unsigned int) (8 + num_components * 3)) if (length != (unsigned int) (8 + num_components * 3))
ERREXIT("Bogus SOF marker length"); ERREXIT("Bogus SOF marker length");
for (ci = 0; ci < num_components; ci++) { for (ci = 0; ci < num_components; ci++) {
(void) read_1_byte(); /* Component ID code */ (void) read_1_byte(); /* Component ID code */
(void) read_1_byte(); /* H, V sampling factors */ (void) read_1_byte(); /* H, V sampling factors */
(void) read_1_byte(); /* Quantization table number */ (void) read_1_byte(); /* Quantization table number */
} }
} }
@@ -352,29 +352,29 @@ scan_JPEG_header (int verbose, int raw)
/* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
* treated as SOFn. C4 in particular is actually DHT. * treated as SOFn. C4 in particular is actually DHT.
*/ */
case M_SOF0: /* Baseline */ case M_SOF0: /* Baseline */
case M_SOF1: /* Extended sequential, Huffman */ case M_SOF1: /* Extended sequential, Huffman */
case M_SOF2: /* Progressive, Huffman */ case M_SOF2: /* Progressive, Huffman */
case M_SOF3: /* Lossless, Huffman */ case M_SOF3: /* Lossless, Huffman */
case M_SOF5: /* Differential sequential, Huffman */ case M_SOF5: /* Differential sequential, Huffman */
case M_SOF6: /* Differential progressive, Huffman */ case M_SOF6: /* Differential progressive, Huffman */
case M_SOF7: /* Differential lossless, Huffman */ case M_SOF7: /* Differential lossless, Huffman */
case M_SOF9: /* Extended sequential, arithmetic */ case M_SOF9: /* Extended sequential, arithmetic */
case M_SOF10: /* Progressive, arithmetic */ case M_SOF10: /* Progressive, arithmetic */
case M_SOF11: /* Lossless, arithmetic */ case M_SOF11: /* Lossless, arithmetic */
case M_SOF13: /* Differential sequential, arithmetic */ case M_SOF13: /* Differential sequential, arithmetic */
case M_SOF14: /* Differential progressive, arithmetic */ case M_SOF14: /* Differential progressive, arithmetic */
case M_SOF15: /* Differential lossless, arithmetic */ case M_SOF15: /* Differential lossless, arithmetic */
if (verbose) if (verbose)
process_SOFn(marker); process_SOFn(marker);
else else
skip_variable(); skip_variable();
break; break;
case M_SOS: /* stop before hitting compressed data */ case M_SOS: /* stop before hitting compressed data */
return marker; return marker;
case M_EOI: /* in case it's a tables-only JPEG stream */ case M_EOI: /* in case it's a tables-only JPEG stream */
return marker; return marker;
case M_COM: case M_COM:
@@ -386,14 +386,14 @@ scan_JPEG_header (int verbose, int raw)
* APP12 markers, so we print those out too when in -verbose mode. * APP12 markers, so we print those out too when in -verbose mode.
*/ */
if (verbose) { if (verbose) {
printf("APP12 contains:\n"); printf("APP12 contains:\n");
process_COM(raw); process_COM(raw);
} else } else
skip_variable(); skip_variable();
break; break;
default: /* Anything else just gets skipped */ default: /* Anything else just gets skipped */
skip_variable(); /* we assume it has a parameter count... */ skip_variable(); /* we assume it has a parameter count... */
break; break;
} }
} /* end loop */ } /* end loop */
@@ -402,7 +402,7 @@ scan_JPEG_header (int verbose, int raw)
/* Command line parsing code */ /* Command line parsing code */
static const char * progname; /* program name for error messages */ static const char * progname; /* program name for error messages */
static void static void
@@ -432,17 +432,17 @@ keymatch (char * arg, const char * keyword, int minchars)
while ((ca = *arg++) != '\0') { while ((ca = *arg++) != '\0') {
if ((ck = *keyword++) == '\0') if ((ck = *keyword++) == '\0')
return 0; /* arg longer than keyword, no good */ return 0; /* arg longer than keyword, no good */
if (isupper(ca)) /* force arg to lcase (assume ck is already) */ if (isupper(ca)) /* force arg to lcase (assume ck is already) */
ca = tolower(ca); ca = tolower(ca);
if (ca != ck) if (ca != ck)
return 0; /* no good */ return 0; /* no good */
nmatched++; /* count matched characters */ nmatched++; /* count matched characters */
} }
/* reached end of argument; fail if it's too short for unique abbrev */ /* reached end of argument; fail if it's too short for unique abbrev */
if (nmatched < minchars) if (nmatched < minchars)
return 0; return 0;
return 1; /* A-OK */ return 1; /* A-OK */
} }
@@ -464,14 +464,14 @@ main (int argc, char **argv)
progname = argv[0]; progname = argv[0];
if (progname == NULL || progname[0] == 0) if (progname == NULL || progname[0] == 0)
progname = "rdjpgcom"; /* in case C library doesn't provide it */ progname = "rdjpgcom"; /* in case C library doesn't provide it */
/* Parse switches, if any */ /* Parse switches, if any */
for (argn = 1; argn < argc; argn++) { for (argn = 1; argn < argc; argn++) {
arg = argv[argn]; arg = argv[argn];
if (arg[0] != '-') if (arg[0] != '-')
break; /* not switch, must be file name */ break; /* not switch, must be file name */
arg++; /* advance over '-' */ arg++; /* advance over '-' */
if (keymatch(arg, "verbose", 1)) { if (keymatch(arg, "verbose", 1)) {
verbose++; verbose++;
} else if (keymatch(arg, "raw", 1)) { } else if (keymatch(arg, "raw", 1)) {
@@ -493,10 +493,10 @@ main (int argc, char **argv)
} }
} else { } else {
/* default input file is stdin */ /* default input file is stdin */
#ifdef USE_SETMODE /* need to hack file mode? */ #ifdef USE_SETMODE /* need to hack file mode? */
setmode(fileno(stdin), O_BINARY); setmode(fileno(stdin), O_BINARY);
#endif #endif
#ifdef USE_FDOPEN /* need to re-open in binary mode? */ #ifdef USE_FDOPEN /* need to re-open in binary mode? */
if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) { if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
fprintf(stderr, "%s: can't open stdin\n", progname); fprintf(stderr, "%s: can't open stdin\n", progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@@ -511,5 +511,5 @@ main (int argc, char **argv)
/* All done. */ /* All done. */
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
return 0; /* suppress no-return-value warnings */ return 0; /* suppress no-return-value warnings */
} }

46
rdppm.c
View File

@@ -19,7 +19,7 @@
* the file is indeed PPM format). * the file is indeed PPM format).
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef PPM_SUPPORTED #ifdef PPM_SUPPORTED
@@ -41,19 +41,19 @@
#ifdef HAVE_UNSIGNED_CHAR #ifdef HAVE_UNSIGNED_CHAR
typedef unsigned char U_CHAR; typedef unsigned char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else /* !HAVE_UNSIGNED_CHAR */ #else /* !HAVE_UNSIGNED_CHAR */
#ifdef __CHAR_UNSIGNED__ #ifdef __CHAR_UNSIGNED__
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else #else
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x) & 0xFF) #define UCH(x) ((int) (x) & 0xFF)
#endif #endif
#endif /* HAVE_UNSIGNED_CHAR */ #endif /* HAVE_UNSIGNED_CHAR */
#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) #define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
/* /*
@@ -72,10 +72,10 @@ typedef char U_CHAR;
typedef struct { typedef struct {
struct cjpeg_source_struct pub; /* public fields */ struct cjpeg_source_struct pub; /* public fields */
U_CHAR *iobuffer; /* non-FAR pointer to I/O buffer */ U_CHAR *iobuffer; /* non-FAR pointer to I/O buffer */
JSAMPROW pixrow; /* FAR pointer to same */ JSAMPROW pixrow; /* FAR pointer to same */
size_t buffer_width; /* width of I/O buffer */ size_t buffer_width; /* width of I/O buffer */
JSAMPLE *rescale; /* => maxval-remapping array, or NULL */ JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
} ppm_source_struct; } ppm_source_struct;
typedef ppm_source_struct * ppm_source_ptr; typedef ppm_source_struct * ppm_source_ptr;
@@ -308,10 +308,10 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* detect unsupported variants (ie, PBM) before trying to read header */ /* detect unsupported variants (ie, PBM) before trying to read header */
switch (c) { switch (c) {
case '2': /* it's a text-format PGM file */ case '2': /* it's a text-format PGM file */
case '3': /* it's a text-format PPM file */ case '3': /* it's a text-format PPM file */
case '5': /* it's a raw-format PGM file */ case '5': /* it's a raw-format PGM file */
case '6': /* it's a raw-format PPM file */ case '6': /* it's a raw-format PPM file */
break; break;
default: default:
ERREXIT(cinfo, JERR_PPM_NOT); ERREXIT(cinfo, JERR_PPM_NOT);
@@ -331,12 +331,12 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
cinfo->image_height = (JDIMENSION) h; cinfo->image_height = (JDIMENSION) h;
/* initialize flags to most common settings */ /* initialize flags to most common settings */
need_iobuffer = TRUE; /* do we need an I/O buffer? */ need_iobuffer = TRUE; /* do we need an I/O buffer? */
use_raw_buffer = FALSE; /* do we map input buffer onto 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? */ need_rescale = TRUE; /* do we need a rescale array? */
switch (c) { switch (c) {
case '2': /* it's a text-format PGM file */ case '2': /* it's a text-format PGM file */
cinfo->input_components = 1; cinfo->input_components = 1;
cinfo->in_color_space = JCS_GRAYSCALE; cinfo->in_color_space = JCS_GRAYSCALE;
TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h); TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h);
@@ -344,7 +344,7 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
need_iobuffer = FALSE; need_iobuffer = FALSE;
break; break;
case '3': /* it's a text-format PPM file */ case '3': /* it's a text-format PPM file */
cinfo->input_components = 3; cinfo->input_components = 3;
cinfo->in_color_space = JCS_RGB; cinfo->in_color_space = JCS_RGB;
TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h); TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h);
@@ -352,7 +352,7 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
need_iobuffer = FALSE; need_iobuffer = FALSE;
break; break;
case '5': /* it's a raw-format PGM file */ case '5': /* it's a raw-format PGM file */
cinfo->input_components = 1; cinfo->input_components = 1;
cinfo->in_color_space = JCS_GRAYSCALE; cinfo->in_color_space = JCS_GRAYSCALE;
TRACEMS2(cinfo, 1, JTRC_PGM, w, h); TRACEMS2(cinfo, 1, JTRC_PGM, w, h);
@@ -367,7 +367,7 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} }
break; break;
case '6': /* it's a raw-format PPM file */ case '6': /* it's a raw-format PPM file */
cinfo->input_components = 3; cinfo->input_components = 3;
cinfo->in_color_space = JCS_RGB; cinfo->in_color_space = JCS_RGB;
TRACEMS2(cinfo, 1, JTRC_PPM, w, h); TRACEMS2(cinfo, 1, JTRC_PPM, w, h);
@@ -389,7 +389,7 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
((maxval<=255) ? SIZEOF(U_CHAR) : (2*SIZEOF(U_CHAR))); ((maxval<=255) ? SIZEOF(U_CHAR) : (2*SIZEOF(U_CHAR)));
source->iobuffer = (U_CHAR *) source->iobuffer = (U_CHAR *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
source->buffer_width); source->buffer_width);
} }
/* Create compressor input buffer. */ /* Create compressor input buffer. */
@@ -415,7 +415,7 @@ start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* On 16-bit-int machines we have to be careful of maxval = 65535 */ /* On 16-bit-int machines we have to be careful of maxval = 65535 */
source->rescale = (JSAMPLE *) source->rescale = (JSAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE))); (size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE)));
half_maxval = maxval / 2; half_maxval = maxval / 2;
for (val = 0; val <= (INT32) maxval; val++) { for (val = 0; val <= (INT32) maxval; val++) {
/* The multiplication here must be done in 32 bits to avoid overflow */ /* The multiplication here must be done in 32 bits to avoid overflow */
@@ -448,7 +448,7 @@ jinit_read_ppm (j_compress_ptr cinfo)
/* Create module interface object */ /* Create module interface object */
source = (ppm_source_ptr) source = (ppm_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(ppm_source_struct)); SIZEOF(ppm_source_struct));
/* Fill in method ptrs, except get_pixel_rows which start_input sets */ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
source->pub.start_input = start_input_ppm; source->pub.start_input = start_input_ppm;
source->pub.finish_input = finish_input_ppm; source->pub.finish_input = finish_input_ppm;

18
rdrle.c
View File

@@ -19,7 +19,7 @@
* with updates from Robert Hutchinson. * with updates from Robert Hutchinson.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef RLE_SUPPORTED #ifdef RLE_SUPPORTED
@@ -38,7 +38,7 @@
/* /*
* We support the following types of RLE files: * We support the following types of RLE files:
* *
* GRAYSCALE - 8 bits, no colormap * GRAYSCALE - 8 bits, no colormap
* MAPPEDGRAY - 8 bits, 1 channel colomap * MAPPEDGRAY - 8 bits, 1 channel colomap
* PSEUDOCOLOR - 8 bits, 3 channel colormap * PSEUDOCOLOR - 8 bits, 3 channel colormap
@@ -66,7 +66,7 @@ typedef struct _rle_source_struct {
rle_kind visual; /* actual type of input file */ rle_kind visual; /* actual type of input file */
jvirt_sarray_ptr image; /* virtual array to hold the image */ jvirt_sarray_ptr image; /* virtual array to hold the image */
JDIMENSION row; /* current row # in the virtual array */ JDIMENSION row; /* current row # in the virtual array */
rle_hdr header; /* Input file information */ rle_hdr header; /* Input file information */
rle_pixel** rle_row; /* holds a row returned by rle_getrow() */ rle_pixel** rle_row; /* holds a row returned by rle_getrow() */
@@ -111,10 +111,10 @@ start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} }
/* Figure out what we have, set private vars and return values accordingly */ /* Figure out what we have, set private vars and return values accordingly */
width = source->header.xmax - source->header.xmin + 1; width = source->header.xmax - source->header.xmin + 1;
height = source->header.ymax - source->header.ymin + 1; height = source->header.ymax - source->header.ymin + 1;
source->header.xmin = 0; /* realign horizontally */ source->header.xmin = 0; /* realign horizontally */
source->header.xmax = width-1; source->header.xmax = width-1;
cinfo->image_width = width; cinfo->image_width = width;
@@ -131,17 +131,17 @@ start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} else if (source->header.ncolors == 1 && source->header.ncmap == 3) { } else if (source->header.ncolors == 1 && source->header.ncmap == 3) {
source->visual = PSEUDOCOLOR; source->visual = PSEUDOCOLOR;
TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height, TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height,
1 << source->header.cmaplen); 1 << source->header.cmaplen);
} else if (source->header.ncolors == 3 && source->header.ncmap == 3) { } else if (source->header.ncolors == 3 && source->header.ncmap == 3) {
source->visual = TRUECOLOR; source->visual = TRUECOLOR;
TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height, TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height,
1 << source->header.cmaplen); 1 << source->header.cmaplen);
} else if (source->header.ncolors == 3 && source->header.ncmap == 0) { } else if (source->header.ncolors == 3 && source->header.ncmap == 0) {
source->visual = DIRECTCOLOR; source->visual = DIRECTCOLOR;
TRACEMS2(cinfo, 1, JTRC_RLE, width, height); TRACEMS2(cinfo, 1, JTRC_RLE, width, height);
} else } else
ERREXIT(cinfo, JERR_RLE_UNSUPPORTED); ERREXIT(cinfo, JERR_RLE_UNSUPPORTED);
if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) { if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) {
cinfo->in_color_space = JCS_GRAYSCALE; cinfo->in_color_space = JCS_GRAYSCALE;
cinfo->input_components = 1; cinfo->input_components = 1;
@@ -348,7 +348,7 @@ load_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->row = cinfo->image_height; source->row = cinfo->image_height;
/* And fetch the topmost (bottommost) row */ /* And fetch the topmost (bottommost) row */
return (*source->pub.get_pixel_rows) (cinfo, sinfo); return (*source->pub.get_pixel_rows) (cinfo, sinfo);
} }

View File

@@ -9,15 +9,15 @@
* *
* This file contains routines to process some of cjpeg's more complicated * This file contains routines to process some of cjpeg's more complicated
* command-line switches. Switches processed here are: * command-line switches. Switches processed here are:
* -qtables file Read quantization tables from text file * -qtables file Read quantization tables from text file
* -scans file Read scan script from text file * -scans file Read scan script from text file
* -quality N[,N,...] Set quality ratings * -quality N[,N,...] Set quality ratings
* -qslots N[,N,...] Set component quantization table selectors * -qslots N[,N,...] Set component quantization table selectors
* -sample HxV[,HxV,...] Set component sampling factors * -sample HxV[,HxV,...] Set component sampling factors
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#include <ctype.h> /* to declare isdigit(), isspace() */ #include <ctype.h> /* to declare isdigit(), isspace() */
LOCAL(int) LOCAL(int)
@@ -26,7 +26,7 @@ text_getc (FILE * file)
/* A comment/newline sequence is returned as a newline */ /* A comment/newline sequence is returned as a newline */
{ {
register int ch; register int ch;
ch = getc(file); ch = getc(file);
if (ch == '#') { if (ch == '#') {
do { do {
@@ -44,7 +44,7 @@ read_text_integer (FILE * file, long * result, int * termchar)
{ {
register int ch; register int ch;
register long val; register long val;
/* Skip any leading whitespace, detect EOF */ /* Skip any leading whitespace, detect EOF */
do { do {
ch = text_getc(file); ch = text_getc(file);
@@ -53,7 +53,7 @@ read_text_integer (FILE * file, long * result, int * termchar)
return FALSE; return FALSE;
} }
} while (isspace(ch)); } while (isspace(ch));
if (! isdigit(ch)) { if (! isdigit(ch)) {
*termchar = ch; *termchar = ch;
return FALSE; return FALSE;
@@ -108,15 +108,15 @@ read_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline
table[0] = (unsigned int) val; table[0] = (unsigned int) val;
for (i = 1; i < DCTSIZE2; i++) { for (i = 1; i < DCTSIZE2; i++) {
if (! read_text_integer(fp, &val, &termchar)) { if (! read_text_integer(fp, &val, &termchar)) {
fprintf(stderr, "Invalid table data in file %s\n", filename); fprintf(stderr, "Invalid table data in file %s\n", filename);
fclose(fp); fclose(fp);
return FALSE; return FALSE;
} }
table[i] = (unsigned int) val; table[i] = (unsigned int) val;
} }
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno], jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno],
force_baseline); force_baseline);
#else #else
jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor[tblno], jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor[tblno],
force_baseline); force_baseline);
@@ -150,7 +150,7 @@ read_scan_integer (FILE * file, long * result, int * termchar)
ch = *termchar; ch = *termchar;
while (ch != EOF && isspace(ch)) while (ch != EOF && isspace(ch))
ch = text_getc(file); ch = text_getc(file);
if (isdigit(ch)) { /* oops, put it back */ if (isdigit(ch)) { /* oops, put it back */
if (ungetc(ch, file) == EOF) if (ungetc(ch, file) == EOF)
return FALSE; return FALSE;
ch = ' '; ch = ' ';
@@ -188,7 +188,7 @@ read_scan_script (j_compress_ptr cinfo, char * filename)
int scanno, ncomps, termchar; int scanno, ncomps, termchar;
long val; long val;
jpeg_scan_info * scanptr; jpeg_scan_info * scanptr;
#define MAX_SCANS 100 /* quite arbitrary limit */ #define MAX_SCANS 100 /* quite arbitrary limit */
jpeg_scan_info scans[MAX_SCANS]; jpeg_scan_info scans[MAX_SCANS];
if ((fp = fopen(filename, "r")) == NULL) { if ((fp = fopen(filename, "r")) == NULL) {
@@ -208,29 +208,29 @@ read_scan_script (j_compress_ptr cinfo, char * filename)
ncomps = 1; ncomps = 1;
while (termchar == ' ') { while (termchar == ' ') {
if (ncomps >= MAX_COMPS_IN_SCAN) { if (ncomps >= MAX_COMPS_IN_SCAN) {
fprintf(stderr, "Too many components in one scan in file %s\n", fprintf(stderr, "Too many components in one scan in file %s\n",
filename); filename);
fclose(fp); fclose(fp);
return FALSE; return FALSE;
} }
if (! read_scan_integer(fp, &val, &termchar)) if (! read_scan_integer(fp, &val, &termchar))
goto bogus; goto bogus;
scanptr->component_index[ncomps] = (int) val; scanptr->component_index[ncomps] = (int) val;
ncomps++; ncomps++;
} }
scanptr->comps_in_scan = ncomps; scanptr->comps_in_scan = ncomps;
if (termchar == ':') { if (termchar == ':') {
if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
goto bogus; goto bogus;
scanptr->Ss = (int) val; scanptr->Ss = (int) val;
if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
goto bogus; goto bogus;
scanptr->Se = (int) val; scanptr->Se = (int) val;
if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')
goto bogus; goto bogus;
scanptr->Ah = (int) val; scanptr->Ah = (int) val;
if (! read_scan_integer(fp, &val, &termchar)) if (! read_scan_integer(fp, &val, &termchar))
goto bogus; goto bogus;
scanptr->Al = (int) val; scanptr->Al = (int) val;
} else { } else {
/* set non-progressive parameters */ /* set non-progressive parameters */
@@ -261,7 +261,7 @@ bogus:
*/ */
scanptr = (jpeg_scan_info *) scanptr = (jpeg_scan_info *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
scanno * SIZEOF(jpeg_scan_info)); scanno * SIZEOF(jpeg_scan_info));
MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info)); MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info));
cinfo->scan_info = scanptr; cinfo->scan_info = scanptr;
cinfo->num_scans = scanno; cinfo->num_scans = scanno;
@@ -305,9 +305,9 @@ LOCAL(void)
jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline) jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
{ {
jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
q_scale_factor[0], force_baseline); q_scale_factor[0], force_baseline);
jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
q_scale_factor[1], force_baseline); q_scale_factor[1], force_baseline);
} }
#endif #endif
@@ -319,17 +319,17 @@ set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline)
* If there are more q-table slots than parameters, the last value is replicated. * If there are more q-table slots than parameters, the last value is replicated.
*/ */
{ {
int val = 75; /* default value */ int val = 75; /* default value */
int tblno; int tblno;
char ch; char ch;
for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
if (*arg) { if (*arg) {
ch = ','; /* if not set by sscanf, will be ',' */ ch = ','; /* if not set by sscanf, will be ',' */
if (sscanf(arg, "%d%c", &val, &ch) < 1) if (sscanf(arg, "%d%c", &val, &ch) < 1)
return FALSE; return FALSE;
if (ch != ',') /* syntax check */ if (ch != ',') /* syntax check */
return FALSE; return FALSE;
/* Convert user 0-100 rating to percentage scaling */ /* Convert user 0-100 rating to percentage scaling */
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);
@@ -337,7 +337,7 @@ set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline)
q_scale_factor[tblno] = jpeg_quality_scaling(val); q_scale_factor[tblno] = jpeg_quality_scaling(val);
#endif #endif
while (*arg && *arg++ != ',') /* advance to next segment of arg string */ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
; ;
} else { } else {
/* reached end of parameter, set remaining factors to last value */ /* reached end of parameter, set remaining factors to last value */
#if JPEG_LIB_VERSION >= 70 #if JPEG_LIB_VERSION >= 70
@@ -359,25 +359,25 @@ set_quant_slots (j_compress_ptr cinfo, char *arg)
* If there are more components than parameters, the last value is replicated. * If there are more components than parameters, the last value is replicated.
*/ */
{ {
int val = 0; /* default table # */ int val = 0; /* default table # */
int ci; int ci;
char ch; char ch;
for (ci = 0; ci < MAX_COMPONENTS; ci++) { for (ci = 0; ci < MAX_COMPONENTS; ci++) {
if (*arg) { if (*arg) {
ch = ','; /* if not set by sscanf, will be ',' */ ch = ','; /* if not set by sscanf, will be ',' */
if (sscanf(arg, "%d%c", &val, &ch) < 1) if (sscanf(arg, "%d%c", &val, &ch) < 1)
return FALSE; return FALSE;
if (ch != ',') /* syntax check */ if (ch != ',') /* syntax check */
return FALSE; return FALSE;
if (val < 0 || val >= NUM_QUANT_TBLS) { if (val < 0 || val >= NUM_QUANT_TBLS) {
fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n", fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
NUM_QUANT_TBLS-1); NUM_QUANT_TBLS-1);
return FALSE; return FALSE;
} }
cinfo->comp_info[ci].quant_tbl_no = val; cinfo->comp_info[ci].quant_tbl_no = val;
while (*arg && *arg++ != ',') /* advance to next segment of arg string */ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
; ;
} else { } else {
/* reached end of parameter, set remaining components to last table */ /* reached end of parameter, set remaining components to last table */
cinfo->comp_info[ci].quant_tbl_no = val; cinfo->comp_info[ci].quant_tbl_no = val;
@@ -399,19 +399,19 @@ set_sample_factors (j_compress_ptr cinfo, char *arg)
for (ci = 0; ci < MAX_COMPONENTS; ci++) { for (ci = 0; ci < MAX_COMPONENTS; ci++) {
if (*arg) { if (*arg) {
ch2 = ','; /* if not set by sscanf, will be ',' */ ch2 = ','; /* if not set by sscanf, will be ',' */
if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3) if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
return FALSE; return FALSE;
if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */ if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */
return FALSE; return FALSE;
if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) { if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) {
fprintf(stderr, "JPEG sampling factors must be 1..4\n"); fprintf(stderr, "JPEG sampling factors must be 1..4\n");
return FALSE; return FALSE;
} }
cinfo->comp_info[ci].h_samp_factor = val1; cinfo->comp_info[ci].h_samp_factor = val1;
cinfo->comp_info[ci].v_samp_factor = val2; cinfo->comp_info[ci].v_samp_factor = val2;
while (*arg && *arg++ != ',') /* advance to next segment of arg string */ while (*arg && *arg++ != ',') /* advance to next segment of arg string */
; ;
} else { } else {
/* reached end of parameter, set remaining components to 1x1 sampling */ /* reached end of parameter, set remaining components to 1x1 sampling */
cinfo->comp_info[ci].h_samp_factor = 1; cinfo->comp_info[ci].h_samp_factor = 1;

View File

@@ -17,7 +17,7 @@
* Based on code contributed by Lee Daniel Crocker. * Based on code contributed by Lee Daniel Crocker.
*/ */
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
#ifdef TARGA_SUPPORTED #ifdef TARGA_SUPPORTED
@@ -26,19 +26,19 @@
#ifdef HAVE_UNSIGNED_CHAR #ifdef HAVE_UNSIGNED_CHAR
typedef unsigned char U_CHAR; typedef unsigned char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else /* !HAVE_UNSIGNED_CHAR */ #else /* !HAVE_UNSIGNED_CHAR */
#ifdef __CHAR_UNSIGNED__ #ifdef __CHAR_UNSIGNED__
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x)) #define UCH(x) ((int) (x))
#else #else
typedef char U_CHAR; typedef char U_CHAR;
#define UCH(x) ((int) (x) & 0xFF) #define UCH(x) ((int) (x) & 0xFF)
#endif #endif
#endif /* HAVE_UNSIGNED_CHAR */ #endif /* HAVE_UNSIGNED_CHAR */
#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) #define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
/* Private version of data source object */ /* Private version of data source object */
@@ -48,12 +48,12 @@ typedef struct _tga_source_struct * tga_source_ptr;
typedef struct _tga_source_struct { typedef struct _tga_source_struct {
struct cjpeg_source_struct pub; /* public fields */ struct cjpeg_source_struct pub; /* public fields */
j_compress_ptr cinfo; /* back link saves passing separate parm */ j_compress_ptr cinfo; /* back link saves passing separate parm */
JSAMPARRAY colormap; /* Targa colormap (converted to my format) */ JSAMPARRAY colormap; /* Targa colormap (converted to my format) */
jvirt_sarray_ptr whole_image; /* Needed if funny input row order */ jvirt_sarray_ptr whole_image; /* Needed if funny input row order */
JDIMENSION current_row; /* Current logical row number to read */ JDIMENSION current_row; /* Current logical row number to read */
/* Pointer to routine to extract next Targa pixel from input file */ /* Pointer to routine to extract next Targa pixel from input file */
JMETHOD(void, read_pixel, (tga_source_ptr sinfo)); JMETHOD(void, read_pixel, (tga_source_ptr sinfo));
@@ -61,15 +61,15 @@ typedef struct _tga_source_struct {
/* Result of read_pixel is delivered here: */ /* Result of read_pixel is delivered here: */
U_CHAR tga_pixel[4]; U_CHAR tga_pixel[4];
int pixel_size; /* Bytes per Targa pixel (1 to 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 */ /* State info for reading RLE-coded pixels; both counts must be init to 0 */
int block_count; /* # of pixels remaining in RLE block */ int block_count; /* # of pixels remaining in RLE block */
int dup_pixel_count; /* # of times to duplicate previous pixel */ int dup_pixel_count; /* # of times to duplicate previous pixel */
/* This saves the correct pixel-row-expansion method for preload_image */ /* This saves the correct pixel-row-expansion method for preload_image */
JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
cjpeg_source_ptr sinfo)); cjpeg_source_ptr sinfo));
} tga_source_struct; } tga_source_struct;
@@ -148,9 +148,9 @@ read_rle_pixel (tga_source_ptr sinfo)
/* Time to read RLE block header? */ /* Time to read RLE block header? */
if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */ if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */
i = read_byte(sinfo); i = read_byte(sinfo);
if (i & 0x80) { /* Start of duplicate-pixel block? */ if (i & 0x80) { /* Start of duplicate-pixel block? */
sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */ sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */
sinfo->block_count = 0; /* then read new block header */ sinfo->block_count = 0; /* then read new block header */
} else { } else {
sinfo->block_count = i & 0x7F; /* number of pixels after this one */ sinfo->block_count = i & 0x7F; /* number of pixels after this one */
} }
@@ -338,8 +338,8 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
unsigned int width, height, maplen; unsigned int width, height, maplen;
boolean is_bottom_up; boolean is_bottom_up;
#define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \ #define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \
(((unsigned int) UCH(targaheader[offset+1])) << 8)) (((unsigned int) UCH(targaheader[offset+1])) << 8))
if (! ReadOK(source->pub.input_file, targaheader, 18)) if (! ReadOK(source->pub.input_file, targaheader, 18))
ERREXIT(cinfo, JERR_INPUT_EOF); ERREXIT(cinfo, JERR_INPUT_EOF);
@@ -355,15 +355,15 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
width = GET_2B(12); width = GET_2B(12);
height = GET_2B(14); height = GET_2B(14);
source->pixel_size = UCH(targaheader[16]) >> 3; source->pixel_size = UCH(targaheader[16]) >> 3;
flags = UCH(targaheader[17]); /* Image Descriptor byte */ flags = UCH(targaheader[17]); /* Image Descriptor byte */
is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */ is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */
interlace_type = flags >> 6; /* bits 6/7 are interlace code */ interlace_type = flags >> 6; /* bits 6/7 are interlace code */
if (cmaptype > 1 || /* cmaptype must be 0 or 1 */ if (cmaptype > 1 || /* cmaptype must be 0 or 1 */
source->pixel_size < 1 || source->pixel_size > 4 || source->pixel_size < 1 || source->pixel_size > 4 ||
(UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */ (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */
interlace_type != 0) /* currently don't allow interlaced image */ interlace_type != 0) /* currently don't allow interlaced image */
ERREXIT(cinfo, JERR_TGA_BADPARMS); ERREXIT(cinfo, JERR_TGA_BADPARMS);
if (subtype > 8) { if (subtype > 8) {
@@ -377,18 +377,18 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} }
/* Now should have subtype 1, 2, or 3 */ /* Now should have subtype 1, 2, or 3 */
components = 3; /* until proven different */ components = 3; /* until proven different */
cinfo->in_color_space = JCS_RGB; cinfo->in_color_space = JCS_RGB;
switch (subtype) { switch (subtype) {
case 1: /* Colormapped image */ case 1: /* Colormapped image */
if (source->pixel_size == 1 && cmaptype == 1) if (source->pixel_size == 1 && cmaptype == 1)
source->get_pixel_rows = get_8bit_row; source->get_pixel_rows = get_8bit_row;
else else
ERREXIT(cinfo, JERR_TGA_BADPARMS); ERREXIT(cinfo, JERR_TGA_BADPARMS);
TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height); TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height);
break; break;
case 2: /* RGB image */ case 2: /* RGB image */
switch (source->pixel_size) { switch (source->pixel_size) {
case 2: case 2:
source->get_pixel_rows = get_16bit_row; source->get_pixel_rows = get_16bit_row;
@@ -405,7 +405,7 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
} }
TRACEMS2(cinfo, 1, JTRC_TGA, width, height); TRACEMS2(cinfo, 1, JTRC_TGA, width, height);
break; break;
case 3: /* Grayscale image */ case 3: /* Grayscale image */
components = 1; components = 1;
cinfo->in_color_space = JCS_GRAYSCALE; cinfo->in_color_space = JCS_GRAYSCALE;
if (source->pixel_size == 1) if (source->pixel_size == 1)
@@ -441,7 +441,7 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
source->pub.get_pixel_rows = source->get_pixel_rows; source->pub.get_pixel_rows = source->get_pixel_rows;
} }
while (idlen--) /* Throw away ID field */ while (idlen--) /* Throw away ID field */
(void) read_byte(source); (void) read_byte(source);
if (maplen > 0) { if (maplen > 0) {
@@ -453,7 +453,7 @@ start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
/* and read it from the file */ /* and read it from the file */
read_colormap(source, (int) maplen, UCH(targaheader[7])); read_colormap(source, (int) maplen, UCH(targaheader[7]));
} else { } else {
if (cmaptype) /* but you promised a cmap! */ if (cmaptype) /* but you promised a cmap! */
ERREXIT(cinfo, JERR_TGA_BADPARMS); ERREXIT(cinfo, JERR_TGA_BADPARMS);
source->colormap = NULL; source->colormap = NULL;
} }
@@ -488,8 +488,8 @@ jinit_read_targa (j_compress_ptr cinfo)
/* Create module interface object */ /* Create module interface object */
source = (tga_source_ptr) source = (tga_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(tga_source_struct)); SIZEOF(tga_source_struct));
source->cinfo = cinfo; /* make back link for subroutines */ source->cinfo = cinfo; /* make back link for subroutines */
/* Fill in method ptrs, except get_pixel_rows which start_input sets */ /* Fill in method ptrs, except get_pixel_rows which start_input sets */
source->pub.start_input = start_input_tga; source->pub.start_input = start_input_tga;
source->pub.finish_input = finish_input_tga; source->pub.finish_input = finish_input_tga;

View File

@@ -58,7 +58,7 @@ libsimd_la_SOURCES = jsimd_arm.c jsimd_arm_neon.S
endif endif
AM_CPPFLAGS = -I$(top_srcdir) AM_CPPFLAGS = -I$(top_srcdir)
.asm.lo: .asm.lo:
$(LIBTOOL) --mode=compile --tag NASM $(srcdir)/nasm_lt.sh $(NASM) $(NAFLAGS) -I$(srcdir) -I. $< -o $@ $(LIBTOOL) --mode=compile --tag NASM $(srcdir)/nasm_lt.sh $(NASM) $(NAFLAGS) -I$(srcdir) -I. $< -o $@

View File

@@ -28,450 +28,450 @@
; JDIMENSION output_row, int num_rows); ; JDIMENSION output_row, int num_rows);
; ;
%define img_width(b) (b)+8 ; JDIMENSION img_width %define img_width(b) (b)+8 ; JDIMENSION img_width
%define input_buf(b) (b)+12 ; JSAMPARRAY input_buf %define input_buf(b) (b)+12 ; JSAMPARRAY input_buf
%define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf %define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf
%define output_row(b) (b)+20 ; JDIMENSION output_row %define output_row(b) (b)+20 ; JDIMENSION output_row
%define num_rows(b) (b)+24 ; int num_rows %define num_rows(b) (b)+24 ; int num_rows
%define original_ebp ebp+0 %define original_ebp ebp+0
%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM]
%define WK_NUM 8 %define WK_NUM 8
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr %define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16 align 16
global EXTN(jsimd_rgb_ycc_convert_mmx) global EXTN(jsimd_rgb_ycc_convert_mmx)
EXTN(jsimd_rgb_ycc_convert_mmx): EXTN(jsimd_rgb_ycc_convert_mmx):
push ebp push ebp
mov eax,esp ; eax = original ebp mov eax,esp ; eax = original ebp
sub esp, byte 4 sub esp, byte 4
and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
mov [esp],eax mov [esp],eax
mov ebp,esp ; ebp = aligned ebp mov ebp,esp ; ebp = aligned ebp
lea esp, [wk(0)] lea esp, [wk(0)]
pushpic eax ; make a room for GOT address pushpic eax ; make a room for GOT address
push ebx push ebx
; push ecx ; need not be preserved ; push ecx ; need not be preserved
; push edx ; need not be preserved ; push edx ; need not be preserved
push esi push esi
push edi push edi
get_GOT ebx ; get GOT address get_GOT ebx ; get GOT address
movpic POINTER [gotptr], ebx ; save GOT address movpic POINTER [gotptr], ebx ; save GOT address
mov ecx, JDIMENSION [img_width(eax)] ; num_cols mov ecx, JDIMENSION [img_width(eax)] ; num_cols
test ecx,ecx test ecx,ecx
jz near .return jz near .return
push ecx push ecx
mov esi, JSAMPIMAGE [output_buf(eax)] mov esi, JSAMPIMAGE [output_buf(eax)]
mov ecx, JDIMENSION [output_row(eax)] mov ecx, JDIMENSION [output_row(eax)]
mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY] mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY]
mov ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY] mov ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY]
mov edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY] mov edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY]
lea edi, [edi+ecx*SIZEOF_JSAMPROW] lea edi, [edi+ecx*SIZEOF_JSAMPROW]
lea ebx, [ebx+ecx*SIZEOF_JSAMPROW] lea ebx, [ebx+ecx*SIZEOF_JSAMPROW]
lea edx, [edx+ecx*SIZEOF_JSAMPROW] lea edx, [edx+ecx*SIZEOF_JSAMPROW]
pop ecx pop ecx
mov esi, JSAMPARRAY [input_buf(eax)] mov esi, JSAMPARRAY [input_buf(eax)]
mov eax, INT [num_rows(eax)] mov eax, INT [num_rows(eax)]
test eax,eax test eax,eax
jle near .return jle near .return
alignx 16,7 alignx 16,7
.rowloop: .rowloop:
pushpic eax pushpic eax
push edx push edx
push ebx push ebx
push edi push edi
push esi push esi
push ecx ; col push ecx ; col
mov esi, JSAMPROW [esi] ; inptr mov esi, JSAMPROW [esi] ; inptr
mov edi, JSAMPROW [edi] ; outptr0 mov edi, JSAMPROW [edi] ; outptr0
mov ebx, JSAMPROW [ebx] ; outptr1 mov ebx, JSAMPROW [ebx] ; outptr1
mov edx, JSAMPROW [edx] ; outptr2 mov edx, JSAMPROW [edx] ; outptr2
movpic eax, POINTER [gotptr] ; load GOT address (eax) movpic eax, POINTER [gotptr] ; load GOT address (eax)
cmp ecx, byte SIZEOF_MMWORD cmp ecx, byte SIZEOF_MMWORD
jae short .columnloop jae short .columnloop
alignx 16,7 alignx 16,7
%if RGB_PIXELSIZE == 3 ; --------------- %if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1: .column_ld1:
push eax push eax
push edx push edx
lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE test cl, SIZEOF_BYTE
jz short .column_ld2 jz short .column_ld2
sub ecx, byte SIZEOF_BYTE sub ecx, byte SIZEOF_BYTE
xor eax,eax xor eax,eax
mov al, BYTE [esi+ecx] mov al, BYTE [esi+ecx]
.column_ld2: .column_ld2:
test cl, SIZEOF_WORD test cl, SIZEOF_WORD
jz short .column_ld4 jz short .column_ld4
sub ecx, byte SIZEOF_WORD sub ecx, byte SIZEOF_WORD
xor edx,edx xor edx,edx
mov dx, WORD [esi+ecx] mov dx, WORD [esi+ecx]
shl eax, WORD_BIT shl eax, WORD_BIT
or eax,edx or eax,edx
.column_ld4: .column_ld4:
movd mmA,eax movd mmA,eax
pop edx pop edx
pop eax pop eax
test cl, SIZEOF_DWORD test cl, SIZEOF_DWORD
jz short .column_ld8 jz short .column_ld8
sub ecx, byte SIZEOF_DWORD sub ecx, byte SIZEOF_DWORD
movd mmG, DWORD [esi+ecx] movd mmG, DWORD [esi+ecx]
psllq mmA, DWORD_BIT psllq mmA, DWORD_BIT
por mmA,mmG por mmA,mmG
.column_ld8: .column_ld8:
test cl, SIZEOF_MMWORD test cl, SIZEOF_MMWORD
jz short .column_ld16 jz short .column_ld16
movq mmG,mmA movq mmG,mmA
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
mov ecx, SIZEOF_MMWORD mov ecx, SIZEOF_MMWORD
jmp short .rgb_ycc_cnv jmp short .rgb_ycc_cnv
.column_ld16: .column_ld16:
test cl, 2*SIZEOF_MMWORD test cl, 2*SIZEOF_MMWORD
mov ecx, SIZEOF_MMWORD mov ecx, SIZEOF_MMWORD
jz short .rgb_ycc_cnv jz short .rgb_ycc_cnv
movq mmF,mmA movq mmF,mmA
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmG, MMWORD [esi+1*SIZEOF_MMWORD] movq mmG, MMWORD [esi+1*SIZEOF_MMWORD]
jmp short .rgb_ycc_cnv jmp short .rgb_ycc_cnv
alignx 16,7 alignx 16,7
.columnloop: .columnloop:
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmG, MMWORD [esi+1*SIZEOF_MMWORD] movq mmG, MMWORD [esi+1*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+2*SIZEOF_MMWORD] movq mmF, MMWORD [esi+2*SIZEOF_MMWORD]
.rgb_ycc_cnv: .rgb_ycc_cnv:
; mmA=(00 10 20 01 11 21 02 12) ; mmA=(00 10 20 01 11 21 02 12)
; mmG=(22 03 13 23 04 14 24 05) ; mmG=(22 03 13 23 04 14 24 05)
; mmF=(15 25 06 16 26 07 17 27) ; mmF=(15 25 06 16 26 07 17 27)
movq mmD,mmA movq mmD,mmA
psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 10 20 01) psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 10 20 01)
psrlq mmD,4*BYTE_BIT ; mmD=(11 21 02 12 -- -- -- --) psrlq mmD,4*BYTE_BIT ; mmD=(11 21 02 12 -- -- -- --)
punpckhbw mmA,mmG ; mmA=(00 04 10 14 20 24 01 05) punpckhbw mmA,mmG ; mmA=(00 04 10 14 20 24 01 05)
psllq mmG,4*BYTE_BIT ; mmG=(-- -- -- -- 22 03 13 23) psllq mmG,4*BYTE_BIT ; mmG=(-- -- -- -- 22 03 13 23)
punpcklbw mmD,mmF ; mmD=(11 15 21 25 02 06 12 16) punpcklbw mmD,mmF ; mmD=(11 15 21 25 02 06 12 16)
punpckhbw mmG,mmF ; mmG=(22 26 03 07 13 17 23 27) punpckhbw mmG,mmF ; mmG=(22 26 03 07 13 17 23 27)
movq mmE,mmA movq mmE,mmA
psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 04 10 14) psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 04 10 14)
psrlq mmE,4*BYTE_BIT ; mmE=(20 24 01 05 -- -- -- --) psrlq mmE,4*BYTE_BIT ; mmE=(20 24 01 05 -- -- -- --)
punpckhbw mmA,mmD ; mmA=(00 02 04 06 10 12 14 16) punpckhbw mmA,mmD ; mmA=(00 02 04 06 10 12 14 16)
psllq mmD,4*BYTE_BIT ; mmD=(-- -- -- -- 11 15 21 25) psllq mmD,4*BYTE_BIT ; mmD=(-- -- -- -- 11 15 21 25)
punpcklbw mmE,mmG ; mmE=(20 22 24 26 01 03 05 07) punpcklbw mmE,mmG ; mmE=(20 22 24 26 01 03 05 07)
punpckhbw mmD,mmG ; mmD=(11 13 15 17 21 23 25 27) punpckhbw mmD,mmG ; mmD=(11 13 15 17 21 23 25 27)
pxor mmH,mmH pxor mmH,mmH
movq mmC,mmA movq mmC,mmA
punpcklbw mmA,mmH ; mmA=(00 02 04 06) punpcklbw mmA,mmH ; mmA=(00 02 04 06)
punpckhbw mmC,mmH ; mmC=(10 12 14 16) punpckhbw mmC,mmH ; mmC=(10 12 14 16)
movq mmB,mmE movq mmB,mmE
punpcklbw mmE,mmH ; mmE=(20 22 24 26) punpcklbw mmE,mmH ; mmE=(20 22 24 26)
punpckhbw mmB,mmH ; mmB=(01 03 05 07) punpckhbw mmB,mmH ; mmB=(01 03 05 07)
movq mmF,mmD movq mmF,mmD
punpcklbw mmD,mmH ; mmD=(11 13 15 17) punpcklbw mmD,mmH ; mmD=(11 13 15 17)
punpckhbw mmF,mmH ; mmF=(21 23 25 27) punpckhbw mmF,mmH ; mmF=(21 23 25 27)
%else ; RGB_PIXELSIZE == 4 ; ----------- %else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1: .column_ld1:
test cl, SIZEOF_MMWORD/8 test cl, SIZEOF_MMWORD/8
jz short .column_ld2 jz short .column_ld2
sub ecx, byte SIZEOF_MMWORD/8 sub ecx, byte SIZEOF_MMWORD/8
movd mmA, DWORD [esi+ecx*RGB_PIXELSIZE] movd mmA, DWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld2: .column_ld2:
test cl, SIZEOF_MMWORD/4 test cl, SIZEOF_MMWORD/4
jz short .column_ld4 jz short .column_ld4
sub ecx, byte SIZEOF_MMWORD/4 sub ecx, byte SIZEOF_MMWORD/4
movq mmF,mmA movq mmF,mmA
movq mmA, MMWORD [esi+ecx*RGB_PIXELSIZE] movq mmA, MMWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld4: .column_ld4:
test cl, SIZEOF_MMWORD/2 test cl, SIZEOF_MMWORD/2
mov ecx, SIZEOF_MMWORD mov ecx, SIZEOF_MMWORD
jz short .rgb_ycc_cnv jz short .rgb_ycc_cnv
movq mmD,mmA movq mmD,mmA
movq mmC,mmF movq mmC,mmF
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+1*SIZEOF_MMWORD] movq mmF, MMWORD [esi+1*SIZEOF_MMWORD]
jmp short .rgb_ycc_cnv jmp short .rgb_ycc_cnv
alignx 16,7 alignx 16,7
.columnloop: .columnloop:
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+1*SIZEOF_MMWORD] movq mmF, MMWORD [esi+1*SIZEOF_MMWORD]
movq mmD, MMWORD [esi+2*SIZEOF_MMWORD] movq mmD, MMWORD [esi+2*SIZEOF_MMWORD]
movq mmC, MMWORD [esi+3*SIZEOF_MMWORD] movq mmC, MMWORD [esi+3*SIZEOF_MMWORD]
.rgb_ycc_cnv: .rgb_ycc_cnv:
; mmA=(00 10 20 30 01 11 21 31) ; mmA=(00 10 20 30 01 11 21 31)
; mmF=(02 12 22 32 03 13 23 33) ; mmF=(02 12 22 32 03 13 23 33)
; mmD=(04 14 24 34 05 15 25 35) ; mmD=(04 14 24 34 05 15 25 35)
; mmC=(06 16 26 36 07 17 27 37) ; mmC=(06 16 26 36 07 17 27 37)
movq mmB,mmA movq mmB,mmA
punpcklbw mmA,mmF ; mmA=(00 02 10 12 20 22 30 32) punpcklbw mmA,mmF ; mmA=(00 02 10 12 20 22 30 32)
punpckhbw mmB,mmF ; mmB=(01 03 11 13 21 23 31 33) punpckhbw mmB,mmF ; mmB=(01 03 11 13 21 23 31 33)
movq mmG,mmD movq mmG,mmD
punpcklbw mmD,mmC ; mmD=(04 06 14 16 24 26 34 36) punpcklbw mmD,mmC ; mmD=(04 06 14 16 24 26 34 36)
punpckhbw mmG,mmC ; mmG=(05 07 15 17 25 27 35 37) punpckhbw mmG,mmC ; mmG=(05 07 15 17 25 27 35 37)
movq mmE,mmA movq mmE,mmA
punpcklwd mmA,mmD ; mmA=(00 02 04 06 10 12 14 16) punpcklwd mmA,mmD ; mmA=(00 02 04 06 10 12 14 16)
punpckhwd mmE,mmD ; mmE=(20 22 24 26 30 32 34 36) punpckhwd mmE,mmD ; mmE=(20 22 24 26 30 32 34 36)
movq mmH,mmB movq mmH,mmB
punpcklwd mmB,mmG ; mmB=(01 03 05 07 11 13 15 17) punpcklwd mmB,mmG ; mmB=(01 03 05 07 11 13 15 17)
punpckhwd mmH,mmG ; mmH=(21 23 25 27 31 33 35 37) punpckhwd mmH,mmG ; mmH=(21 23 25 27 31 33 35 37)
pxor mmF,mmF pxor mmF,mmF
movq mmC,mmA movq mmC,mmA
punpcklbw mmA,mmF ; mmA=(00 02 04 06) punpcklbw mmA,mmF ; mmA=(00 02 04 06)
punpckhbw mmC,mmF ; mmC=(10 12 14 16) punpckhbw mmC,mmF ; mmC=(10 12 14 16)
movq mmD,mmB movq mmD,mmB
punpcklbw mmB,mmF ; mmB=(01 03 05 07) punpcklbw mmB,mmF ; mmB=(01 03 05 07)
punpckhbw mmD,mmF ; mmD=(11 13 15 17) punpckhbw mmD,mmF ; mmD=(11 13 15 17)
movq mmG,mmE movq mmG,mmE
punpcklbw mmE,mmF ; mmE=(20 22 24 26) punpcklbw mmE,mmF ; mmE=(20 22 24 26)
punpckhbw mmG,mmF ; mmG=(30 32 34 36) punpckhbw mmG,mmF ; mmG=(30 32 34 36)
punpcklbw mmF,mmH punpcklbw mmF,mmH
punpckhbw mmH,mmH punpckhbw mmH,mmH
psrlw mmF,BYTE_BIT ; mmF=(21 23 25 27) psrlw mmF,BYTE_BIT ; mmF=(21 23 25 27)
psrlw mmH,BYTE_BIT ; mmH=(31 33 35 37) psrlw mmH,BYTE_BIT ; mmH=(31 33 35 37)
%endif ; RGB_PIXELSIZE ; --------------- %endif ; RGB_PIXELSIZE ; ---------------
; mm0=(R0 R2 R4 R6)=RE, mm2=(G0 G2 G4 G6)=GE, mm4=(B0 B2 B4 B6)=BE ; mm0=(R0 R2 R4 R6)=RE, mm2=(G0 G2 G4 G6)=GE, mm4=(B0 B2 B4 B6)=BE
; mm1=(R1 R3 R5 R7)=RO, mm3=(G1 G3 G5 G7)=GO, mm5=(B1 B3 B5 B7)=BO ; mm1=(R1 R3 R5 R7)=RO, mm3=(G1 G3 G5 G7)=GO, mm5=(B1 B3 B5 B7)=BO
; (Original) ; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
; ;
; (This implementation) ; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
movq MMWORD [wk(0)], mm0 ; wk(0)=RE movq MMWORD [wk(0)], mm0 ; wk(0)=RE
movq MMWORD [wk(1)], mm1 ; wk(1)=RO movq MMWORD [wk(1)], mm1 ; wk(1)=RO
movq MMWORD [wk(2)], mm4 ; wk(2)=BE movq MMWORD [wk(2)], mm4 ; wk(2)=BE
movq MMWORD [wk(3)], mm5 ; wk(3)=BO movq MMWORD [wk(3)], mm5 ; wk(3)=BO
movq mm6,mm1 movq mm6,mm1
punpcklwd mm1,mm3 punpcklwd mm1,mm3
punpckhwd mm6,mm3 punpckhwd mm6,mm3
movq mm7,mm1 movq mm7,mm1
movq mm4,mm6 movq mm4,mm6
pmaddwd mm1,[GOTOFF(eax,PW_F0299_F0337)] ; mm1=ROL*FIX(0.299)+GOL*FIX(0.337) pmaddwd mm1,[GOTOFF(eax,PW_F0299_F0337)] ; mm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=ROH*FIX(0.299)+GOH*FIX(0.337) pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=ROH*FIX(0.299)+GOH*FIX(0.337)
pmaddwd mm7,[GOTOFF(eax,PW_MF016_MF033)] ; mm7=ROL*-FIX(0.168)+GOL*-FIX(0.331) pmaddwd mm7,[GOTOFF(eax,PW_MF016_MF033)] ; mm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
pmaddwd mm4,[GOTOFF(eax,PW_MF016_MF033)] ; mm4=ROH*-FIX(0.168)+GOH*-FIX(0.331) pmaddwd mm4,[GOTOFF(eax,PW_MF016_MF033)] ; mm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
movq MMWORD [wk(4)], mm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337) movq MMWORD [wk(4)], mm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
movq MMWORD [wk(5)], mm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337) movq MMWORD [wk(5)], mm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
pxor mm1,mm1 pxor mm1,mm1
pxor mm6,mm6 pxor mm6,mm6
punpcklwd mm1,mm5 ; mm1=BOL punpcklwd mm1,mm5 ; mm1=BOL
punpckhwd mm6,mm5 ; mm6=BOH punpckhwd mm6,mm5 ; mm6=BOH
psrld mm1,1 ; mm1=BOL*FIX(0.500) psrld mm1,1 ; mm1=BOL*FIX(0.500)
psrld mm6,1 ; mm6=BOH*FIX(0.500) psrld mm6,1 ; mm6=BOH*FIX(0.500)
movq mm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm5=[PD_ONEHALFM1_CJ] movq mm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm5=[PD_ONEHALFM1_CJ]
paddd mm7,mm1 paddd mm7,mm1
paddd mm4,mm6 paddd mm4,mm6
paddd mm7,mm5 paddd mm7,mm5
paddd mm4,mm5 paddd mm4,mm5
psrld mm7,SCALEBITS ; mm7=CbOL psrld mm7,SCALEBITS ; mm7=CbOL
psrld mm4,SCALEBITS ; mm4=CbOH psrld mm4,SCALEBITS ; mm4=CbOH
packssdw mm7,mm4 ; mm7=CbO packssdw mm7,mm4 ; mm7=CbO
movq mm1, MMWORD [wk(2)] ; mm1=BE movq mm1, MMWORD [wk(2)] ; mm1=BE
movq mm6,mm0 movq mm6,mm0
punpcklwd mm0,mm2 punpcklwd mm0,mm2
punpckhwd mm6,mm2 punpckhwd mm6,mm2
movq mm5,mm0 movq mm5,mm0
movq mm4,mm6 movq mm4,mm6
pmaddwd mm0,[GOTOFF(eax,PW_F0299_F0337)] ; mm0=REL*FIX(0.299)+GEL*FIX(0.337) pmaddwd mm0,[GOTOFF(eax,PW_F0299_F0337)] ; mm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=REH*FIX(0.299)+GEH*FIX(0.337) pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=REH*FIX(0.299)+GEH*FIX(0.337)
pmaddwd mm5,[GOTOFF(eax,PW_MF016_MF033)] ; mm5=REL*-FIX(0.168)+GEL*-FIX(0.331) pmaddwd mm5,[GOTOFF(eax,PW_MF016_MF033)] ; mm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
pmaddwd mm4,[GOTOFF(eax,PW_MF016_MF033)] ; mm4=REH*-FIX(0.168)+GEH*-FIX(0.331) pmaddwd mm4,[GOTOFF(eax,PW_MF016_MF033)] ; mm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
movq MMWORD [wk(6)], mm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337) movq MMWORD [wk(6)], mm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
movq MMWORD [wk(7)], mm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337) movq MMWORD [wk(7)], mm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
pxor mm0,mm0 pxor mm0,mm0
pxor mm6,mm6 pxor mm6,mm6
punpcklwd mm0,mm1 ; mm0=BEL punpcklwd mm0,mm1 ; mm0=BEL
punpckhwd mm6,mm1 ; mm6=BEH punpckhwd mm6,mm1 ; mm6=BEH
psrld mm0,1 ; mm0=BEL*FIX(0.500) psrld mm0,1 ; mm0=BEL*FIX(0.500)
psrld mm6,1 ; mm6=BEH*FIX(0.500) psrld mm6,1 ; mm6=BEH*FIX(0.500)
movq mm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm1=[PD_ONEHALFM1_CJ] movq mm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm1=[PD_ONEHALFM1_CJ]
paddd mm5,mm0 paddd mm5,mm0
paddd mm4,mm6 paddd mm4,mm6
paddd mm5,mm1 paddd mm5,mm1
paddd mm4,mm1 paddd mm4,mm1
psrld mm5,SCALEBITS ; mm5=CbEL psrld mm5,SCALEBITS ; mm5=CbEL
psrld mm4,SCALEBITS ; mm4=CbEH psrld mm4,SCALEBITS ; mm4=CbEH
packssdw mm5,mm4 ; mm5=CbE packssdw mm5,mm4 ; mm5=CbE
psllw mm7,BYTE_BIT psllw mm7,BYTE_BIT
por mm5,mm7 ; mm5=Cb por mm5,mm7 ; mm5=Cb
movq MMWORD [ebx], mm5 ; Save Cb movq MMWORD [ebx], mm5 ; Save Cb
movq mm0, MMWORD [wk(3)] ; mm0=BO movq mm0, MMWORD [wk(3)] ; mm0=BO
movq mm6, MMWORD [wk(2)] ; mm6=BE movq mm6, MMWORD [wk(2)] ; mm6=BE
movq mm1, MMWORD [wk(1)] ; mm1=RO movq mm1, MMWORD [wk(1)] ; mm1=RO
movq mm4,mm0 movq mm4,mm0
punpcklwd mm0,mm3 punpcklwd mm0,mm3
punpckhwd mm4,mm3 punpckhwd mm4,mm3
movq mm7,mm0 movq mm7,mm0
movq mm5,mm4 movq mm5,mm4
pmaddwd mm0,[GOTOFF(eax,PW_F0114_F0250)] ; mm0=BOL*FIX(0.114)+GOL*FIX(0.250) pmaddwd mm0,[GOTOFF(eax,PW_F0114_F0250)] ; mm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BOH*FIX(0.114)+GOH*FIX(0.250) pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BOH*FIX(0.114)+GOH*FIX(0.250)
pmaddwd mm7,[GOTOFF(eax,PW_MF008_MF041)] ; mm7=BOL*-FIX(0.081)+GOL*-FIX(0.418) pmaddwd mm7,[GOTOFF(eax,PW_MF008_MF041)] ; mm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
pmaddwd mm5,[GOTOFF(eax,PW_MF008_MF041)] ; mm5=BOH*-FIX(0.081)+GOH*-FIX(0.418) pmaddwd mm5,[GOTOFF(eax,PW_MF008_MF041)] ; mm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
movq mm3,[GOTOFF(eax,PD_ONEHALF)] ; mm3=[PD_ONEHALF] movq mm3,[GOTOFF(eax,PD_ONEHALF)] ; mm3=[PD_ONEHALF]
paddd mm0, MMWORD [wk(4)] paddd mm0, MMWORD [wk(4)]
paddd mm4, MMWORD [wk(5)] paddd mm4, MMWORD [wk(5)]
paddd mm0,mm3 paddd mm0,mm3
paddd mm4,mm3 paddd mm4,mm3
psrld mm0,SCALEBITS ; mm0=YOL psrld mm0,SCALEBITS ; mm0=YOL
psrld mm4,SCALEBITS ; mm4=YOH psrld mm4,SCALEBITS ; mm4=YOH
packssdw mm0,mm4 ; mm0=YO packssdw mm0,mm4 ; mm0=YO
pxor mm3,mm3 pxor mm3,mm3
pxor mm4,mm4 pxor mm4,mm4
punpcklwd mm3,mm1 ; mm3=ROL punpcklwd mm3,mm1 ; mm3=ROL
punpckhwd mm4,mm1 ; mm4=ROH punpckhwd mm4,mm1 ; mm4=ROH
psrld mm3,1 ; mm3=ROL*FIX(0.500) psrld mm3,1 ; mm3=ROL*FIX(0.500)
psrld mm4,1 ; mm4=ROH*FIX(0.500) psrld mm4,1 ; mm4=ROH*FIX(0.500)
movq mm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm1=[PD_ONEHALFM1_CJ] movq mm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm1=[PD_ONEHALFM1_CJ]
paddd mm7,mm3 paddd mm7,mm3
paddd mm5,mm4 paddd mm5,mm4
paddd mm7,mm1 paddd mm7,mm1
paddd mm5,mm1 paddd mm5,mm1
psrld mm7,SCALEBITS ; mm7=CrOL psrld mm7,SCALEBITS ; mm7=CrOL
psrld mm5,SCALEBITS ; mm5=CrOH psrld mm5,SCALEBITS ; mm5=CrOH
packssdw mm7,mm5 ; mm7=CrO packssdw mm7,mm5 ; mm7=CrO
movq mm3, MMWORD [wk(0)] ; mm3=RE movq mm3, MMWORD [wk(0)] ; mm3=RE
movq mm4,mm6 movq mm4,mm6
punpcklwd mm6,mm2 punpcklwd mm6,mm2
punpckhwd mm4,mm2 punpckhwd mm4,mm2
movq mm1,mm6 movq mm1,mm6
movq mm5,mm4 movq mm5,mm4
pmaddwd mm6,[GOTOFF(eax,PW_F0114_F0250)] ; mm6=BEL*FIX(0.114)+GEL*FIX(0.250) pmaddwd mm6,[GOTOFF(eax,PW_F0114_F0250)] ; mm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BEH*FIX(0.114)+GEH*FIX(0.250) pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BEH*FIX(0.114)+GEH*FIX(0.250)
pmaddwd mm1,[GOTOFF(eax,PW_MF008_MF041)] ; mm1=BEL*-FIX(0.081)+GEL*-FIX(0.418) pmaddwd mm1,[GOTOFF(eax,PW_MF008_MF041)] ; mm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
pmaddwd mm5,[GOTOFF(eax,PW_MF008_MF041)] ; mm5=BEH*-FIX(0.081)+GEH*-FIX(0.418) pmaddwd mm5,[GOTOFF(eax,PW_MF008_MF041)] ; mm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
movq mm2,[GOTOFF(eax,PD_ONEHALF)] ; mm2=[PD_ONEHALF] movq mm2,[GOTOFF(eax,PD_ONEHALF)] ; mm2=[PD_ONEHALF]
paddd mm6, MMWORD [wk(6)] paddd mm6, MMWORD [wk(6)]
paddd mm4, MMWORD [wk(7)] paddd mm4, MMWORD [wk(7)]
paddd mm6,mm2 paddd mm6,mm2
paddd mm4,mm2 paddd mm4,mm2
psrld mm6,SCALEBITS ; mm6=YEL psrld mm6,SCALEBITS ; mm6=YEL
psrld mm4,SCALEBITS ; mm4=YEH psrld mm4,SCALEBITS ; mm4=YEH
packssdw mm6,mm4 ; mm6=YE packssdw mm6,mm4 ; mm6=YE
psllw mm0,BYTE_BIT psllw mm0,BYTE_BIT
por mm6,mm0 ; mm6=Y por mm6,mm0 ; mm6=Y
movq MMWORD [edi], mm6 ; Save Y movq MMWORD [edi], mm6 ; Save Y
pxor mm2,mm2 pxor mm2,mm2
pxor mm4,mm4 pxor mm4,mm4
punpcklwd mm2,mm3 ; mm2=REL punpcklwd mm2,mm3 ; mm2=REL
punpckhwd mm4,mm3 ; mm4=REH punpckhwd mm4,mm3 ; mm4=REH
psrld mm2,1 ; mm2=REL*FIX(0.500) psrld mm2,1 ; mm2=REL*FIX(0.500)
psrld mm4,1 ; mm4=REH*FIX(0.500) psrld mm4,1 ; mm4=REH*FIX(0.500)
movq mm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm0=[PD_ONEHALFM1_CJ] movq mm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; mm0=[PD_ONEHALFM1_CJ]
paddd mm1,mm2 paddd mm1,mm2
paddd mm5,mm4 paddd mm5,mm4
paddd mm1,mm0 paddd mm1,mm0
paddd mm5,mm0 paddd mm5,mm0
psrld mm1,SCALEBITS ; mm1=CrEL psrld mm1,SCALEBITS ; mm1=CrEL
psrld mm5,SCALEBITS ; mm5=CrEH psrld mm5,SCALEBITS ; mm5=CrEH
packssdw mm1,mm5 ; mm1=CrE packssdw mm1,mm5 ; mm1=CrE
psllw mm7,BYTE_BIT psllw mm7,BYTE_BIT
por mm1,mm7 ; mm1=Cr por mm1,mm7 ; mm1=Cr
movq MMWORD [edx], mm1 ; Save Cr movq MMWORD [edx], mm1 ; Save Cr
sub ecx, byte SIZEOF_MMWORD sub ecx, byte SIZEOF_MMWORD
add esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; inptr add esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; inptr
add edi, byte SIZEOF_MMWORD ; outptr0 add edi, byte SIZEOF_MMWORD ; outptr0
add ebx, byte SIZEOF_MMWORD ; outptr1 add ebx, byte SIZEOF_MMWORD ; outptr1
add edx, byte SIZEOF_MMWORD ; outptr2 add edx, byte SIZEOF_MMWORD ; outptr2
cmp ecx, byte SIZEOF_MMWORD cmp ecx, byte SIZEOF_MMWORD
jae near .columnloop jae near .columnloop
test ecx,ecx test ecx,ecx
jnz near .column_ld1 jnz near .column_ld1
pop ecx ; col pop ecx ; col
pop esi pop esi
pop edi pop edi
pop ebx pop ebx
pop edx pop edx
poppic eax poppic eax
add esi, byte SIZEOF_JSAMPROW ; input_buf add esi, byte SIZEOF_JSAMPROW ; input_buf
add edi, byte SIZEOF_JSAMPROW add edi, byte SIZEOF_JSAMPROW
add ebx, byte SIZEOF_JSAMPROW add ebx, byte SIZEOF_JSAMPROW
add edx, byte SIZEOF_JSAMPROW add edx, byte SIZEOF_JSAMPROW
dec eax ; num_rows dec eax ; num_rows
jg near .rowloop jg near .rowloop
emms ; empty MMX state emms ; empty MMX state
.return: .return:
pop edi pop edi
pop esi pop esi
; pop edx ; need not be preserved ; pop edx ; need not be preserved
; pop ecx ; need not be preserved ; pop ecx ; need not be preserved
pop ebx pop ebx
mov esp,ebp ; esp <- aligned ebp mov esp,ebp ; esp <- aligned ebp
pop esp ; esp <- original ebp pop esp ; esp <- original ebp
pop ebp pop ebp
ret ret
; For some reason, the OS X linker does not honor the request to align the ; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this. ; segment unless we do this.
align 16 align 16

View File

@@ -32,454 +32,454 @@
; r13 = JDIMENSION output_row ; r13 = JDIMENSION output_row
; r14 = int num_rows ; r14 = int num_rows
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] %define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 8 %define WK_NUM 8
align 16 align 16
global EXTN(jsimd_rgb_ycc_convert_sse2) global EXTN(jsimd_rgb_ycc_convert_sse2)
EXTN(jsimd_rgb_ycc_convert_sse2): EXTN(jsimd_rgb_ycc_convert_sse2):
push rbp push rbp
mov rax,rsp ; rax = original rbp mov rax,rsp ; rax = original rbp
sub rsp, byte 4 sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)] lea rsp, [wk(0)]
collect_args collect_args
push rbx push rbx
mov rcx, r10 mov rcx, r10
test rcx,rcx test rcx,rcx
jz near .return jz near .return
push rcx push rcx
mov rsi, r12 mov rsi, r12
mov rcx, r13 mov rcx, r13
mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY] mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
mov rbx, JSAMPARRAY [rsi+1*SIZEOF_JSAMPARRAY] mov rbx, JSAMPARRAY [rsi+1*SIZEOF_JSAMPARRAY]
mov rdx, JSAMPARRAY [rsi+2*SIZEOF_JSAMPARRAY] mov rdx, JSAMPARRAY [rsi+2*SIZEOF_JSAMPARRAY]
lea rdi, [rdi+rcx*SIZEOF_JSAMPROW] lea rdi, [rdi+rcx*SIZEOF_JSAMPROW]
lea rbx, [rbx+rcx*SIZEOF_JSAMPROW] lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
lea rdx, [rdx+rcx*SIZEOF_JSAMPROW] lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
pop rcx pop rcx
mov rsi, r11 mov rsi, r11
mov eax, r14d mov eax, r14d
test rax,rax test rax,rax
jle near .return jle near .return
.rowloop: .rowloop:
push rdx push rdx
push rbx push rbx
push rdi push rdi
push rsi push rsi
push rcx ; col push rcx ; col
mov rsi, JSAMPROW [rsi] ; inptr mov rsi, JSAMPROW [rsi] ; inptr
mov rdi, JSAMPROW [rdi] ; outptr0 mov rdi, JSAMPROW [rdi] ; outptr0
mov rbx, JSAMPROW [rbx] ; outptr1 mov rbx, JSAMPROW [rbx] ; outptr1
mov rdx, JSAMPROW [rdx] ; outptr2 mov rdx, JSAMPROW [rdx] ; outptr2
cmp rcx, byte SIZEOF_XMMWORD cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop jae near .columnloop
%if RGB_PIXELSIZE == 3 ; --------------- %if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1: .column_ld1:
push rax push rax
push rdx push rdx
lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE test cl, SIZEOF_BYTE
jz short .column_ld2 jz short .column_ld2
sub rcx, byte SIZEOF_BYTE sub rcx, byte SIZEOF_BYTE
movzx rax, BYTE [rsi+rcx] movzx rax, BYTE [rsi+rcx]
.column_ld2: .column_ld2:
test cl, SIZEOF_WORD test cl, SIZEOF_WORD
jz short .column_ld4 jz short .column_ld4
sub rcx, byte SIZEOF_WORD sub rcx, byte SIZEOF_WORD
movzx rdx, WORD [rsi+rcx] movzx rdx, WORD [rsi+rcx]
shl rax, WORD_BIT shl rax, WORD_BIT
or rax,rdx or rax,rdx
.column_ld4: .column_ld4:
movd xmmA,eax movd xmmA,eax
pop rdx pop rdx
pop rax pop rax
test cl, SIZEOF_DWORD test cl, SIZEOF_DWORD
jz short .column_ld8 jz short .column_ld8
sub rcx, byte SIZEOF_DWORD sub rcx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [rsi+rcx] movd xmmF, XMM_DWORD [rsi+rcx]
pslldq xmmA, SIZEOF_DWORD pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF por xmmA,xmmF
.column_ld8: .column_ld8:
test cl, SIZEOF_MMWORD test cl, SIZEOF_MMWORD
jz short .column_ld16 jz short .column_ld16
sub rcx, byte SIZEOF_MMWORD sub rcx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [rsi+rcx] movq xmmB, XMM_MMWORD [rsi+rcx]
pslldq xmmA, SIZEOF_MMWORD pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB por xmmA,xmmB
.column_ld16: .column_ld16:
test cl, SIZEOF_XMMWORD test cl, SIZEOF_XMMWORD
jz short .column_ld32 jz short .column_ld32
movdqa xmmF,xmmA movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
mov rcx, SIZEOF_XMMWORD mov rcx, SIZEOF_XMMWORD
jmp short .rgb_ycc_cnv jmp short .rgb_ycc_cnv
.column_ld32: .column_ld32:
test cl, 2*SIZEOF_XMMWORD test cl, 2*SIZEOF_XMMWORD
mov rcx, SIZEOF_XMMWORD mov rcx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv jz short .rgb_ycc_cnv
movdqa xmmB,xmmA movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv jmp short .rgb_ycc_cnv
.columnloop: .columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD] movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD]
.rgb_ycc_cnv: .rgb_ycc_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --) psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A) punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27) pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D) punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F) punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --) psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D) punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B) pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E) punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F) punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --) psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D) pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F) punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F) punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH pxor xmmH,xmmH
movdqa xmmC,xmmA movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E) punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E) punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E) punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F) punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F) punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F) punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; ----------- %else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1: .column_ld1:
test cl, SIZEOF_XMMWORD/16 test cl, SIZEOF_XMMWORD/16
jz short .column_ld2 jz short .column_ld2
sub rcx, byte SIZEOF_XMMWORD/16 sub rcx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE] movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld2: .column_ld2:
test cl, SIZEOF_XMMWORD/8 test cl, SIZEOF_XMMWORD/8
jz short .column_ld4 jz short .column_ld4
sub rcx, byte SIZEOF_XMMWORD/8 sub rcx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE] movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE por xmmA,xmmE
.column_ld4: .column_ld4:
test cl, SIZEOF_XMMWORD/4 test cl, SIZEOF_XMMWORD/4
jz short .column_ld8 jz short .column_ld8
sub rcx, byte SIZEOF_XMMWORD/4 sub rcx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE] movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld8: .column_ld8:
test cl, SIZEOF_XMMWORD/2 test cl, SIZEOF_XMMWORD/2
mov rcx, SIZEOF_XMMWORD mov rcx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv jz short .rgb_ycc_cnv
movdqa xmmF,xmmA movdqa xmmF,xmmA
movdqa xmmH,xmmE movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD] movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv jmp short .rgb_ycc_cnv
.columnloop: .columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD] movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD] movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD]
.rgb_ycc_cnv: .rgb_ycc_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35) punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37) punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D) punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F) punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C) punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D) punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E) punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F) punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E) punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F) punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F) punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF pxor xmmF,xmmF
movdqa xmmC,xmmA movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E) punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E) punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F) punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F) punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E) punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E) punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F) psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F) psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; --------------- %endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
; (Original) ; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
; ;
; (This implementation) ; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE
movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO
movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE
movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO
movdqa xmm6,xmm1 movdqa xmm6,xmm1
punpcklwd xmm1,xmm3 punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3 punpckhwd xmm6,xmm3
movdqa xmm7,xmm1 movdqa xmm7,xmm1
movdqa xmm4,xmm6 movdqa xmm4,xmm6
pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337) pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337) pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
pmaddwd xmm7,[rel PW_MF016_MF033] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331) pmaddwd xmm7,[rel PW_MF016_MF033] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331) pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337) movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337) movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
pxor xmm1,xmm1 pxor xmm1,xmm1
pxor xmm6,xmm6 pxor xmm6,xmm6
punpcklwd xmm1,xmm5 ; xmm1=BOL punpcklwd xmm1,xmm5 ; xmm1=BOL
punpckhwd xmm6,xmm5 ; xmm6=BOH punpckhwd xmm6,xmm5 ; xmm6=BOH
psrld xmm1,1 ; xmm1=BOL*FIX(0.500) psrld xmm1,1 ; xmm1=BOL*FIX(0.500)
psrld xmm6,1 ; xmm6=BOH*FIX(0.500) psrld xmm6,1 ; xmm6=BOH*FIX(0.500)
movdqa xmm5,[rel PD_ONEHALFM1_CJ] ; xmm5=[PD_ONEHALFM1_CJ] movdqa xmm5,[rel PD_ONEHALFM1_CJ] ; xmm5=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm1 paddd xmm7,xmm1
paddd xmm4,xmm6 paddd xmm4,xmm6
paddd xmm7,xmm5 paddd xmm7,xmm5
paddd xmm4,xmm5 paddd xmm4,xmm5
psrld xmm7,SCALEBITS ; xmm7=CbOL psrld xmm7,SCALEBITS ; xmm7=CbOL
psrld xmm4,SCALEBITS ; xmm4=CbOH psrld xmm4,SCALEBITS ; xmm4=CbOH
packssdw xmm7,xmm4 ; xmm7=CbO packssdw xmm7,xmm4 ; xmm7=CbO
movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE
movdqa xmm6,xmm0 movdqa xmm6,xmm0
punpcklwd xmm0,xmm2 punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2 punpckhwd xmm6,xmm2
movdqa xmm5,xmm0 movdqa xmm5,xmm0
movdqa xmm4,xmm6 movdqa xmm4,xmm6
pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337) pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337) pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
pmaddwd xmm5,[rel PW_MF016_MF033] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331) pmaddwd xmm5,[rel PW_MF016_MF033] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331) pmaddwd xmm4,[rel PW_MF016_MF033] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337) movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337) movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
pxor xmm0,xmm0 pxor xmm0,xmm0
pxor xmm6,xmm6 pxor xmm6,xmm6
punpcklwd xmm0,xmm1 ; xmm0=BEL punpcklwd xmm0,xmm1 ; xmm0=BEL
punpckhwd xmm6,xmm1 ; xmm6=BEH punpckhwd xmm6,xmm1 ; xmm6=BEH
psrld xmm0,1 ; xmm0=BEL*FIX(0.500) psrld xmm0,1 ; xmm0=BEL*FIX(0.500)
psrld xmm6,1 ; xmm6=BEH*FIX(0.500) psrld xmm6,1 ; xmm6=BEH*FIX(0.500)
movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ] movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm5,xmm0 paddd xmm5,xmm0
paddd xmm4,xmm6 paddd xmm4,xmm6
paddd xmm5,xmm1 paddd xmm5,xmm1
paddd xmm4,xmm1 paddd xmm4,xmm1
psrld xmm5,SCALEBITS ; xmm5=CbEL psrld xmm5,SCALEBITS ; xmm5=CbEL
psrld xmm4,SCALEBITS ; xmm4=CbEH psrld xmm4,SCALEBITS ; xmm4=CbEH
packssdw xmm5,xmm4 ; xmm5=CbE packssdw xmm5,xmm4 ; xmm5=CbE
psllw xmm7,BYTE_BIT psllw xmm7,BYTE_BIT
por xmm5,xmm7 ; xmm5=Cb por xmm5,xmm7 ; xmm5=Cb
movdqa XMMWORD [rbx], xmm5 ; Save Cb movdqa XMMWORD [rbx], xmm5 ; Save Cb
movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO
movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE
movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO
movdqa xmm4,xmm0 movdqa xmm4,xmm0
punpcklwd xmm0,xmm3 punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3 punpckhwd xmm4,xmm3
movdqa xmm7,xmm0 movdqa xmm7,xmm0
movdqa xmm5,xmm4 movdqa xmm5,xmm4
pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250) pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250) pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
pmaddwd xmm7,[rel PW_MF008_MF041] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418) pmaddwd xmm7,[rel PW_MF008_MF041] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418) pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF] movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF]
paddd xmm0, XMMWORD [wk(4)] paddd xmm0, XMMWORD [wk(4)]
paddd xmm4, XMMWORD [wk(5)] paddd xmm4, XMMWORD [wk(5)]
paddd xmm0,xmm3 paddd xmm0,xmm3
paddd xmm4,xmm3 paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO packssdw xmm0,xmm4 ; xmm0=YO
pxor xmm3,xmm3 pxor xmm3,xmm3
pxor xmm4,xmm4 pxor xmm4,xmm4
punpcklwd xmm3,xmm1 ; xmm3=ROL punpcklwd xmm3,xmm1 ; xmm3=ROL
punpckhwd xmm4,xmm1 ; xmm4=ROH punpckhwd xmm4,xmm1 ; xmm4=ROH
psrld xmm3,1 ; xmm3=ROL*FIX(0.500) psrld xmm3,1 ; xmm3=ROL*FIX(0.500)
psrld xmm4,1 ; xmm4=ROH*FIX(0.500) psrld xmm4,1 ; xmm4=ROH*FIX(0.500)
movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ] movdqa xmm1,[rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm3 paddd xmm7,xmm3
paddd xmm5,xmm4 paddd xmm5,xmm4
paddd xmm7,xmm1 paddd xmm7,xmm1
paddd xmm5,xmm1 paddd xmm5,xmm1
psrld xmm7,SCALEBITS ; xmm7=CrOL psrld xmm7,SCALEBITS ; xmm7=CrOL
psrld xmm5,SCALEBITS ; xmm5=CrOH psrld xmm5,SCALEBITS ; xmm5=CrOH
packssdw xmm7,xmm5 ; xmm7=CrO packssdw xmm7,xmm5 ; xmm7=CrO
movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE
movdqa xmm4,xmm6 movdqa xmm4,xmm6
punpcklwd xmm6,xmm2 punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2 punpckhwd xmm4,xmm2
movdqa xmm1,xmm6 movdqa xmm1,xmm6
movdqa xmm5,xmm4 movdqa xmm5,xmm4
pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250) pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250) pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
pmaddwd xmm1,[rel PW_MF008_MF041] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418) pmaddwd xmm1,[rel PW_MF008_MF041] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418) pmaddwd xmm5,[rel PW_MF008_MF041] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF] movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(6)] paddd xmm6, XMMWORD [wk(6)]
paddd xmm4, XMMWORD [wk(7)] paddd xmm4, XMMWORD [wk(7)]
paddd xmm6,xmm2 paddd xmm6,xmm2
paddd xmm4,xmm2 paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [rdi], xmm6 ; Save Y movdqa XMMWORD [rdi], xmm6 ; Save Y
pxor xmm2,xmm2 pxor xmm2,xmm2
pxor xmm4,xmm4 pxor xmm4,xmm4
punpcklwd xmm2,xmm3 ; xmm2=REL punpcklwd xmm2,xmm3 ; xmm2=REL
punpckhwd xmm4,xmm3 ; xmm4=REH punpckhwd xmm4,xmm3 ; xmm4=REH
psrld xmm2,1 ; xmm2=REL*FIX(0.500) psrld xmm2,1 ; xmm2=REL*FIX(0.500)
psrld xmm4,1 ; xmm4=REH*FIX(0.500) psrld xmm4,1 ; xmm4=REH*FIX(0.500)
movdqa xmm0,[rel PD_ONEHALFM1_CJ] ; xmm0=[PD_ONEHALFM1_CJ] movdqa xmm0,[rel PD_ONEHALFM1_CJ] ; xmm0=[PD_ONEHALFM1_CJ]
paddd xmm1,xmm2 paddd xmm1,xmm2
paddd xmm5,xmm4 paddd xmm5,xmm4
paddd xmm1,xmm0 paddd xmm1,xmm0
paddd xmm5,xmm0 paddd xmm5,xmm0
psrld xmm1,SCALEBITS ; xmm1=CrEL psrld xmm1,SCALEBITS ; xmm1=CrEL
psrld xmm5,SCALEBITS ; xmm5=CrEH psrld xmm5,SCALEBITS ; xmm5=CrEH
packssdw xmm1,xmm5 ; xmm1=CrE packssdw xmm1,xmm5 ; xmm1=CrE
psllw xmm7,BYTE_BIT psllw xmm7,BYTE_BIT
por xmm1,xmm7 ; xmm1=Cr por xmm1,xmm7 ; xmm1=Cr
movdqa XMMWORD [rdx], xmm1 ; Save Cr movdqa XMMWORD [rdx], xmm1 ; Save Cr
sub rcx, byte SIZEOF_XMMWORD sub rcx, byte SIZEOF_XMMWORD
add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add rdi, byte SIZEOF_XMMWORD ; outptr0 add rdi, byte SIZEOF_XMMWORD ; outptr0
add rbx, byte SIZEOF_XMMWORD ; outptr1 add rbx, byte SIZEOF_XMMWORD ; outptr1
add rdx, byte SIZEOF_XMMWORD ; outptr2 add rdx, byte SIZEOF_XMMWORD ; outptr2
cmp rcx, byte SIZEOF_XMMWORD cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop jae near .columnloop
test rcx,rcx test rcx,rcx
jnz near .column_ld1 jnz near .column_ld1
pop rcx ; col pop rcx ; col
pop rsi pop rsi
pop rdi pop rdi
pop rbx pop rbx
pop rdx pop rdx
add rsi, byte SIZEOF_JSAMPROW ; input_buf add rsi, byte SIZEOF_JSAMPROW ; input_buf
add rdi, byte SIZEOF_JSAMPROW add rdi, byte SIZEOF_JSAMPROW
add rbx, byte SIZEOF_JSAMPROW add rbx, byte SIZEOF_JSAMPROW
add rdx, byte SIZEOF_JSAMPROW add rdx, byte SIZEOF_JSAMPROW
dec rax ; num_rows dec rax ; num_rows
jg near .rowloop jg near .rowloop
.return: .return:
pop rbx pop rbx
uncollect_args uncollect_args
mov rsp,rbp ; rsp <- aligned rbp mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp pop rsp ; rsp <- original rbp
pop rbp pop rbp
ret ret
; For some reason, the OS X linker does not honor the request to align the ; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this. ; segment unless we do this.
align 16 align 16

View File

@@ -25,479 +25,479 @@
; JDIMENSION output_row, int num_rows); ; JDIMENSION output_row, int num_rows);
; ;
%define img_width(b) (b)+8 ; JDIMENSION img_width %define img_width(b) (b)+8 ; JDIMENSION img_width
%define input_buf(b) (b)+12 ; JSAMPARRAY input_buf %define input_buf(b) (b)+12 ; JSAMPARRAY input_buf
%define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf %define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf
%define output_row(b) (b)+20 ; JDIMENSION output_row %define output_row(b) (b)+20 ; JDIMENSION output_row
%define num_rows(b) (b)+24 ; int num_rows %define num_rows(b) (b)+24 ; int num_rows
%define original_ebp ebp+0 %define original_ebp ebp+0
%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 8 %define WK_NUM 8
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr %define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16 align 16
global EXTN(jsimd_rgb_ycc_convert_sse2) global EXTN(jsimd_rgb_ycc_convert_sse2)
EXTN(jsimd_rgb_ycc_convert_sse2): EXTN(jsimd_rgb_ycc_convert_sse2):
push ebp push ebp
mov eax,esp ; eax = original ebp mov eax,esp ; eax = original ebp
sub esp, byte 4 sub esp, byte 4
and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [esp],eax mov [esp],eax
mov ebp,esp ; ebp = aligned ebp mov ebp,esp ; ebp = aligned ebp
lea esp, [wk(0)] lea esp, [wk(0)]
pushpic eax ; make a room for GOT address pushpic eax ; make a room for GOT address
push ebx push ebx
; push ecx ; need not be preserved ; push ecx ; need not be preserved
; push edx ; need not be preserved ; push edx ; need not be preserved
push esi push esi
push edi push edi
get_GOT ebx ; get GOT address get_GOT ebx ; get GOT address
movpic POINTER [gotptr], ebx ; save GOT address movpic POINTER [gotptr], ebx ; save GOT address
mov ecx, JDIMENSION [img_width(eax)] mov ecx, JDIMENSION [img_width(eax)]
test ecx,ecx test ecx,ecx
jz near .return jz near .return
push ecx push ecx
mov esi, JSAMPIMAGE [output_buf(eax)] mov esi, JSAMPIMAGE [output_buf(eax)]
mov ecx, JDIMENSION [output_row(eax)] mov ecx, JDIMENSION [output_row(eax)]
mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY] mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY]
mov ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY] mov ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY]
mov edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY] mov edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY]
lea edi, [edi+ecx*SIZEOF_JSAMPROW] lea edi, [edi+ecx*SIZEOF_JSAMPROW]
lea ebx, [ebx+ecx*SIZEOF_JSAMPROW] lea ebx, [ebx+ecx*SIZEOF_JSAMPROW]
lea edx, [edx+ecx*SIZEOF_JSAMPROW] lea edx, [edx+ecx*SIZEOF_JSAMPROW]
pop ecx pop ecx
mov esi, JSAMPARRAY [input_buf(eax)] mov esi, JSAMPARRAY [input_buf(eax)]
mov eax, INT [num_rows(eax)] mov eax, INT [num_rows(eax)]
test eax,eax test eax,eax
jle near .return jle near .return
alignx 16,7 alignx 16,7
.rowloop: .rowloop:
pushpic eax pushpic eax
push edx push edx
push ebx push ebx
push edi push edi
push esi push esi
push ecx ; col push ecx ; col
mov esi, JSAMPROW [esi] ; inptr mov esi, JSAMPROW [esi] ; inptr
mov edi, JSAMPROW [edi] ; outptr0 mov edi, JSAMPROW [edi] ; outptr0
mov ebx, JSAMPROW [ebx] ; outptr1 mov ebx, JSAMPROW [ebx] ; outptr1
mov edx, JSAMPROW [edx] ; outptr2 mov edx, JSAMPROW [edx] ; outptr2
movpic eax, POINTER [gotptr] ; load GOT address (eax) movpic eax, POINTER [gotptr] ; load GOT address (eax)
cmp ecx, byte SIZEOF_XMMWORD cmp ecx, byte SIZEOF_XMMWORD
jae near .columnloop jae near .columnloop
alignx 16,7 alignx 16,7
%if RGB_PIXELSIZE == 3 ; --------------- %if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1: .column_ld1:
push eax push eax
push edx push edx
lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE test cl, SIZEOF_BYTE
jz short .column_ld2 jz short .column_ld2
sub ecx, byte SIZEOF_BYTE sub ecx, byte SIZEOF_BYTE
movzx eax, BYTE [esi+ecx] movzx eax, BYTE [esi+ecx]
.column_ld2: .column_ld2:
test cl, SIZEOF_WORD test cl, SIZEOF_WORD
jz short .column_ld4 jz short .column_ld4
sub ecx, byte SIZEOF_WORD sub ecx, byte SIZEOF_WORD
movzx edx, WORD [esi+ecx] movzx edx, WORD [esi+ecx]
shl eax, WORD_BIT shl eax, WORD_BIT
or eax,edx or eax,edx
.column_ld4: .column_ld4:
movd xmmA,eax movd xmmA,eax
pop edx pop edx
pop eax pop eax
test cl, SIZEOF_DWORD test cl, SIZEOF_DWORD
jz short .column_ld8 jz short .column_ld8
sub ecx, byte SIZEOF_DWORD sub ecx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [esi+ecx] movd xmmF, XMM_DWORD [esi+ecx]
pslldq xmmA, SIZEOF_DWORD pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF por xmmA,xmmF
.column_ld8: .column_ld8:
test cl, SIZEOF_MMWORD test cl, SIZEOF_MMWORD
jz short .column_ld16 jz short .column_ld16
sub ecx, byte SIZEOF_MMWORD sub ecx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [esi+ecx] movq xmmB, XMM_MMWORD [esi+ecx]
pslldq xmmA, SIZEOF_MMWORD pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB por xmmA,xmmB
.column_ld16: .column_ld16:
test cl, SIZEOF_XMMWORD test cl, SIZEOF_XMMWORD
jz short .column_ld32 jz short .column_ld32
movdqa xmmF,xmmA movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
mov ecx, SIZEOF_XMMWORD mov ecx, SIZEOF_XMMWORD
jmp short .rgb_ycc_cnv jmp short .rgb_ycc_cnv
.column_ld32: .column_ld32:
test cl, 2*SIZEOF_XMMWORD test cl, 2*SIZEOF_XMMWORD
mov ecx, SIZEOF_XMMWORD mov ecx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv jz short .rgb_ycc_cnv
movdqa xmmB,xmmA movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv jmp short .rgb_ycc_cnv
alignx 16,7 alignx 16,7
.columnloop: .columnloop:
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD] movdqu xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD]
.rgb_ycc_cnv: .rgb_ycc_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --) psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A) punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27) pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D) punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F) punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --) psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D) punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B) pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E) punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F) punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --) psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D) pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F) punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F) punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH pxor xmmH,xmmH
movdqa xmmC,xmmA movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E) punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E) punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E) punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F) punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F) punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F) punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; ----------- %else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1: .column_ld1:
test cl, SIZEOF_XMMWORD/16 test cl, SIZEOF_XMMWORD/16
jz short .column_ld2 jz short .column_ld2
sub ecx, byte SIZEOF_XMMWORD/16 sub ecx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE] movd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld2: .column_ld2:
test cl, SIZEOF_XMMWORD/8 test cl, SIZEOF_XMMWORD/8
jz short .column_ld4 jz short .column_ld4
sub ecx, byte SIZEOF_XMMWORD/8 sub ecx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE] movq xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE por xmmA,xmmE
.column_ld4: .column_ld4:
test cl, SIZEOF_XMMWORD/4 test cl, SIZEOF_XMMWORD/4
jz short .column_ld8 jz short .column_ld8
sub ecx, byte SIZEOF_XMMWORD/4 sub ecx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE] movdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld8: .column_ld8:
test cl, SIZEOF_XMMWORD/2 test cl, SIZEOF_XMMWORD/2
mov ecx, SIZEOF_XMMWORD mov ecx, SIZEOF_XMMWORD
jz short .rgb_ycc_cnv jz short .rgb_ycc_cnv
movdqa xmmF,xmmA movdqa xmmF,xmmA
movdqa xmmH,xmmE movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD] movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
jmp short .rgb_ycc_cnv jmp short .rgb_ycc_cnv
alignx 16,7 alignx 16,7
.columnloop: .columnloop:
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD] movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD] movdqu xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD]
.rgb_ycc_cnv: .rgb_ycc_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35) punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37) punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D) punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F) punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C) punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D) punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E) punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F) punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E) punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F) punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F) punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF pxor xmmF,xmmF
movdqa xmmC,xmmA movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E) punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E) punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F) punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F) punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E) punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E) punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F) psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F) psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; --------------- %endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
; (Original) ; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
; ;
; (This implementation) ; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE
movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO
movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE
movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO
movdqa xmm6,xmm1 movdqa xmm6,xmm1
punpcklwd xmm1,xmm3 punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3 punpckhwd xmm6,xmm3
movdqa xmm7,xmm1 movdqa xmm7,xmm1
movdqa xmm4,xmm6 movdqa xmm4,xmm6
pmaddwd xmm1,[GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337) pmaddwd xmm1,[GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337) pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
pmaddwd xmm7,[GOTOFF(eax,PW_MF016_MF033)] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331) pmaddwd xmm7,[GOTOFF(eax,PW_MF016_MF033)] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
pmaddwd xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331) pmaddwd xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337) movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337) movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
pxor xmm1,xmm1 pxor xmm1,xmm1
pxor xmm6,xmm6 pxor xmm6,xmm6
punpcklwd xmm1,xmm5 ; xmm1=BOL punpcklwd xmm1,xmm5 ; xmm1=BOL
punpckhwd xmm6,xmm5 ; xmm6=BOH punpckhwd xmm6,xmm5 ; xmm6=BOH
psrld xmm1,1 ; xmm1=BOL*FIX(0.500) psrld xmm1,1 ; xmm1=BOL*FIX(0.500)
psrld xmm6,1 ; xmm6=BOH*FIX(0.500) psrld xmm6,1 ; xmm6=BOH*FIX(0.500)
movdqa xmm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm5=[PD_ONEHALFM1_CJ] movdqa xmm5,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm5=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm1 paddd xmm7,xmm1
paddd xmm4,xmm6 paddd xmm4,xmm6
paddd xmm7,xmm5 paddd xmm7,xmm5
paddd xmm4,xmm5 paddd xmm4,xmm5
psrld xmm7,SCALEBITS ; xmm7=CbOL psrld xmm7,SCALEBITS ; xmm7=CbOL
psrld xmm4,SCALEBITS ; xmm4=CbOH psrld xmm4,SCALEBITS ; xmm4=CbOH
packssdw xmm7,xmm4 ; xmm7=CbO packssdw xmm7,xmm4 ; xmm7=CbO
movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE
movdqa xmm6,xmm0 movdqa xmm6,xmm0
punpcklwd xmm0,xmm2 punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2 punpckhwd xmm6,xmm2
movdqa xmm5,xmm0 movdqa xmm5,xmm0
movdqa xmm4,xmm6 movdqa xmm4,xmm6
pmaddwd xmm0,[GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337) pmaddwd xmm0,[GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337) pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
pmaddwd xmm5,[GOTOFF(eax,PW_MF016_MF033)] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331) pmaddwd xmm5,[GOTOFF(eax,PW_MF016_MF033)] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
pmaddwd xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331) pmaddwd xmm4,[GOTOFF(eax,PW_MF016_MF033)] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337) movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337) movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
pxor xmm0,xmm0 pxor xmm0,xmm0
pxor xmm6,xmm6 pxor xmm6,xmm6
punpcklwd xmm0,xmm1 ; xmm0=BEL punpcklwd xmm0,xmm1 ; xmm0=BEL
punpckhwd xmm6,xmm1 ; xmm6=BEH punpckhwd xmm6,xmm1 ; xmm6=BEH
psrld xmm0,1 ; xmm0=BEL*FIX(0.500) psrld xmm0,1 ; xmm0=BEL*FIX(0.500)
psrld xmm6,1 ; xmm6=BEH*FIX(0.500) psrld xmm6,1 ; xmm6=BEH*FIX(0.500)
movdqa xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ] movdqa xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm5,xmm0 paddd xmm5,xmm0
paddd xmm4,xmm6 paddd xmm4,xmm6
paddd xmm5,xmm1 paddd xmm5,xmm1
paddd xmm4,xmm1 paddd xmm4,xmm1
psrld xmm5,SCALEBITS ; xmm5=CbEL psrld xmm5,SCALEBITS ; xmm5=CbEL
psrld xmm4,SCALEBITS ; xmm4=CbEH psrld xmm4,SCALEBITS ; xmm4=CbEH
packssdw xmm5,xmm4 ; xmm5=CbE packssdw xmm5,xmm4 ; xmm5=CbE
psllw xmm7,BYTE_BIT psllw xmm7,BYTE_BIT
por xmm5,xmm7 ; xmm5=Cb por xmm5,xmm7 ; xmm5=Cb
movdqa XMMWORD [ebx], xmm5 ; Save Cb movdqa XMMWORD [ebx], xmm5 ; Save Cb
movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO
movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE
movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO
movdqa xmm4,xmm0 movdqa xmm4,xmm0
punpcklwd xmm0,xmm3 punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3 punpckhwd xmm4,xmm3
movdqa xmm7,xmm0 movdqa xmm7,xmm0
movdqa xmm5,xmm4 movdqa xmm5,xmm4
pmaddwd xmm0,[GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250) pmaddwd xmm0,[GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250) pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
pmaddwd xmm7,[GOTOFF(eax,PW_MF008_MF041)] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418) pmaddwd xmm7,[GOTOFF(eax,PW_MF008_MF041)] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
pmaddwd xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418) pmaddwd xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
movdqa xmm3,[GOTOFF(eax,PD_ONEHALF)] ; xmm3=[PD_ONEHALF] movdqa xmm3,[GOTOFF(eax,PD_ONEHALF)] ; xmm3=[PD_ONEHALF]
paddd xmm0, XMMWORD [wk(4)] paddd xmm0, XMMWORD [wk(4)]
paddd xmm4, XMMWORD [wk(5)] paddd xmm4, XMMWORD [wk(5)]
paddd xmm0,xmm3 paddd xmm0,xmm3
paddd xmm4,xmm3 paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO packssdw xmm0,xmm4 ; xmm0=YO
pxor xmm3,xmm3 pxor xmm3,xmm3
pxor xmm4,xmm4 pxor xmm4,xmm4
punpcklwd xmm3,xmm1 ; xmm3=ROL punpcklwd xmm3,xmm1 ; xmm3=ROL
punpckhwd xmm4,xmm1 ; xmm4=ROH punpckhwd xmm4,xmm1 ; xmm4=ROH
psrld xmm3,1 ; xmm3=ROL*FIX(0.500) psrld xmm3,1 ; xmm3=ROL*FIX(0.500)
psrld xmm4,1 ; xmm4=ROH*FIX(0.500) psrld xmm4,1 ; xmm4=ROH*FIX(0.500)
movdqa xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ] movdqa xmm1,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm1=[PD_ONEHALFM1_CJ]
paddd xmm7,xmm3 paddd xmm7,xmm3
paddd xmm5,xmm4 paddd xmm5,xmm4
paddd xmm7,xmm1 paddd xmm7,xmm1
paddd xmm5,xmm1 paddd xmm5,xmm1
psrld xmm7,SCALEBITS ; xmm7=CrOL psrld xmm7,SCALEBITS ; xmm7=CrOL
psrld xmm5,SCALEBITS ; xmm5=CrOH psrld xmm5,SCALEBITS ; xmm5=CrOH
packssdw xmm7,xmm5 ; xmm7=CrO packssdw xmm7,xmm5 ; xmm7=CrO
movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE
movdqa xmm4,xmm6 movdqa xmm4,xmm6
punpcklwd xmm6,xmm2 punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2 punpckhwd xmm4,xmm2
movdqa xmm1,xmm6 movdqa xmm1,xmm6
movdqa xmm5,xmm4 movdqa xmm5,xmm4
pmaddwd xmm6,[GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250) pmaddwd xmm6,[GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250) pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
pmaddwd xmm1,[GOTOFF(eax,PW_MF008_MF041)] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418) pmaddwd xmm1,[GOTOFF(eax,PW_MF008_MF041)] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
pmaddwd xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418) pmaddwd xmm5,[GOTOFF(eax,PW_MF008_MF041)] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
movdqa xmm2,[GOTOFF(eax,PD_ONEHALF)] ; xmm2=[PD_ONEHALF] movdqa xmm2,[GOTOFF(eax,PD_ONEHALF)] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(6)] paddd xmm6, XMMWORD [wk(6)]
paddd xmm4, XMMWORD [wk(7)] paddd xmm4, XMMWORD [wk(7)]
paddd xmm6,xmm2 paddd xmm6,xmm2
paddd xmm4,xmm2 paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [edi], xmm6 ; Save Y movdqa XMMWORD [edi], xmm6 ; Save Y
pxor xmm2,xmm2 pxor xmm2,xmm2
pxor xmm4,xmm4 pxor xmm4,xmm4
punpcklwd xmm2,xmm3 ; xmm2=REL punpcklwd xmm2,xmm3 ; xmm2=REL
punpckhwd xmm4,xmm3 ; xmm4=REH punpckhwd xmm4,xmm3 ; xmm4=REH
psrld xmm2,1 ; xmm2=REL*FIX(0.500) psrld xmm2,1 ; xmm2=REL*FIX(0.500)
psrld xmm4,1 ; xmm4=REH*FIX(0.500) psrld xmm4,1 ; xmm4=REH*FIX(0.500)
movdqa xmm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm0=[PD_ONEHALFM1_CJ] movdqa xmm0,[GOTOFF(eax,PD_ONEHALFM1_CJ)] ; xmm0=[PD_ONEHALFM1_CJ]
paddd xmm1,xmm2 paddd xmm1,xmm2
paddd xmm5,xmm4 paddd xmm5,xmm4
paddd xmm1,xmm0 paddd xmm1,xmm0
paddd xmm5,xmm0 paddd xmm5,xmm0
psrld xmm1,SCALEBITS ; xmm1=CrEL psrld xmm1,SCALEBITS ; xmm1=CrEL
psrld xmm5,SCALEBITS ; xmm5=CrEH psrld xmm5,SCALEBITS ; xmm5=CrEH
packssdw xmm1,xmm5 ; xmm1=CrE packssdw xmm1,xmm5 ; xmm1=CrE
psllw xmm7,BYTE_BIT psllw xmm7,BYTE_BIT
por xmm1,xmm7 ; xmm1=Cr por xmm1,xmm7 ; xmm1=Cr
movdqa XMMWORD [edx], xmm1 ; Save Cr movdqa XMMWORD [edx], xmm1 ; Save Cr
sub ecx, byte SIZEOF_XMMWORD sub ecx, byte SIZEOF_XMMWORD
add esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr add esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add edi, byte SIZEOF_XMMWORD ; outptr0 add edi, byte SIZEOF_XMMWORD ; outptr0
add ebx, byte SIZEOF_XMMWORD ; outptr1 add ebx, byte SIZEOF_XMMWORD ; outptr1
add edx, byte SIZEOF_XMMWORD ; outptr2 add edx, byte SIZEOF_XMMWORD ; outptr2
cmp ecx, byte SIZEOF_XMMWORD cmp ecx, byte SIZEOF_XMMWORD
jae near .columnloop jae near .columnloop
test ecx,ecx test ecx,ecx
jnz near .column_ld1 jnz near .column_ld1
pop ecx ; col pop ecx ; col
pop esi pop esi
pop edi pop edi
pop ebx pop ebx
pop edx pop edx
poppic eax poppic eax
add esi, byte SIZEOF_JSAMPROW ; input_buf add esi, byte SIZEOF_JSAMPROW ; input_buf
add edi, byte SIZEOF_JSAMPROW add edi, byte SIZEOF_JSAMPROW
add ebx, byte SIZEOF_JSAMPROW add ebx, byte SIZEOF_JSAMPROW
add edx, byte SIZEOF_JSAMPROW add edx, byte SIZEOF_JSAMPROW
dec eax ; num_rows dec eax ; num_rows
jg near .rowloop jg near .rowloop
.return: .return:
pop edi pop edi
pop esi pop esi
; pop edx ; need not be preserved ; pop edx ; need not be preserved
; pop ecx ; need not be preserved ; pop ecx ; need not be preserved
pop ebx pop ebx
mov esp,ebp ; esp <- aligned ebp mov esp,ebp ; esp <- aligned ebp
pop esp ; esp <- original ebp pop esp ; esp <- original ebp
pop ebp pop ebp
ret ret
; For some reason, the OS X linker does not honor the request to align the ; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this. ; segment unless we do this.
align 16 align 16

View File

@@ -21,38 +21,38 @@
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
%define SCALEBITS 16 %define SCALEBITS 16
F_0_081 equ 5329 ; FIX(0.08131) F_0_081 equ 5329 ; FIX(0.08131)
F_0_114 equ 7471 ; FIX(0.11400) F_0_114 equ 7471 ; FIX(0.11400)
F_0_168 equ 11059 ; FIX(0.16874) F_0_168 equ 11059 ; FIX(0.16874)
F_0_250 equ 16384 ; FIX(0.25000) F_0_250 equ 16384 ; FIX(0.25000)
F_0_299 equ 19595 ; FIX(0.29900) F_0_299 equ 19595 ; FIX(0.29900)
F_0_331 equ 21709 ; FIX(0.33126) F_0_331 equ 21709 ; FIX(0.33126)
F_0_418 equ 27439 ; FIX(0.41869) F_0_418 equ 27439 ; FIX(0.41869)
F_0_587 equ 38470 ; FIX(0.58700) F_0_587 equ 38470 ; FIX(0.58700)
F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000)
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_CONST SECTION SEG_CONST
alignz 16 alignz 16
global EXTN(jconst_rgb_ycc_convert_mmx) global EXTN(jconst_rgb_ycc_convert_mmx)
EXTN(jconst_rgb_ycc_convert_mmx): EXTN(jconst_rgb_ycc_convert_mmx):
PW_F0299_F0337 times 2 dw F_0_299, F_0_337 PW_F0299_F0337 times 2 dw F_0_299, F_0_337
PW_F0114_F0250 times 2 dw F_0_114, F_0_250 PW_F0114_F0250 times 2 dw F_0_114, F_0_250
PW_MF016_MF033 times 2 dw -F_0_168,-F_0_331 PW_MF016_MF033 times 2 dw -F_0_168,-F_0_331
PW_MF008_MF041 times 2 dw -F_0_081,-F_0_418 PW_MF008_MF041 times 2 dw -F_0_081,-F_0_418
PD_ONEHALFM1_CJ times 2 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS) PD_ONEHALFM1_CJ times 2 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS)
PD_ONEHALF times 2 dd (1 << (SCALEBITS-1)) PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
alignz 16 alignz 16
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 32 BITS 32
%include "jcclrmmx.asm" %include "jcclrmmx.asm"

View File

@@ -18,38 +18,38 @@
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
%define SCALEBITS 16 %define SCALEBITS 16
F_0_081 equ 5329 ; FIX(0.08131) F_0_081 equ 5329 ; FIX(0.08131)
F_0_114 equ 7471 ; FIX(0.11400) F_0_114 equ 7471 ; FIX(0.11400)
F_0_168 equ 11059 ; FIX(0.16874) F_0_168 equ 11059 ; FIX(0.16874)
F_0_250 equ 16384 ; FIX(0.25000) F_0_250 equ 16384 ; FIX(0.25000)
F_0_299 equ 19595 ; FIX(0.29900) F_0_299 equ 19595 ; FIX(0.29900)
F_0_331 equ 21709 ; FIX(0.33126) F_0_331 equ 21709 ; FIX(0.33126)
F_0_418 equ 27439 ; FIX(0.41869) F_0_418 equ 27439 ; FIX(0.41869)
F_0_587 equ 38470 ; FIX(0.58700) F_0_587 equ 38470 ; FIX(0.58700)
F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000)
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_CONST SECTION SEG_CONST
alignz 16 alignz 16
global EXTN(jconst_rgb_ycc_convert_sse2) global EXTN(jconst_rgb_ycc_convert_sse2)
EXTN(jconst_rgb_ycc_convert_sse2): EXTN(jconst_rgb_ycc_convert_sse2):
PW_F0299_F0337 times 4 dw F_0_299, F_0_337 PW_F0299_F0337 times 4 dw F_0_299, F_0_337
PW_F0114_F0250 times 4 dw F_0_114, F_0_250 PW_F0114_F0250 times 4 dw F_0_114, F_0_250
PW_MF016_MF033 times 4 dw -F_0_168,-F_0_331 PW_MF016_MF033 times 4 dw -F_0_168,-F_0_331
PW_MF008_MF041 times 4 dw -F_0_081,-F_0_418 PW_MF008_MF041 times 4 dw -F_0_081,-F_0_418
PD_ONEHALFM1_CJ times 4 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS) PD_ONEHALFM1_CJ times 4 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS)
PD_ONEHALF times 4 dd (1 << (SCALEBITS-1)) PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
alignz 16 alignz 16
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 64 BITS 64
%include "jcclrss2-64.asm" %include "jcclrss2-64.asm"

View File

@@ -18,38 +18,38 @@
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
%define SCALEBITS 16 %define SCALEBITS 16
F_0_081 equ 5329 ; FIX(0.08131) F_0_081 equ 5329 ; FIX(0.08131)
F_0_114 equ 7471 ; FIX(0.11400) F_0_114 equ 7471 ; FIX(0.11400)
F_0_168 equ 11059 ; FIX(0.16874) F_0_168 equ 11059 ; FIX(0.16874)
F_0_250 equ 16384 ; FIX(0.25000) F_0_250 equ 16384 ; FIX(0.25000)
F_0_299 equ 19595 ; FIX(0.29900) F_0_299 equ 19595 ; FIX(0.29900)
F_0_331 equ 21709 ; FIX(0.33126) F_0_331 equ 21709 ; FIX(0.33126)
F_0_418 equ 27439 ; FIX(0.41869) F_0_418 equ 27439 ; FIX(0.41869)
F_0_587 equ 38470 ; FIX(0.58700) F_0_587 equ 38470 ; FIX(0.58700)
F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000)
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_CONST SECTION SEG_CONST
alignz 16 alignz 16
global EXTN(jconst_rgb_ycc_convert_sse2) global EXTN(jconst_rgb_ycc_convert_sse2)
EXTN(jconst_rgb_ycc_convert_sse2): EXTN(jconst_rgb_ycc_convert_sse2):
PW_F0299_F0337 times 4 dw F_0_299, F_0_337 PW_F0299_F0337 times 4 dw F_0_299, F_0_337
PW_F0114_F0250 times 4 dw F_0_114, F_0_250 PW_F0114_F0250 times 4 dw F_0_114, F_0_250
PW_MF016_MF033 times 4 dw -F_0_168,-F_0_331 PW_MF016_MF033 times 4 dw -F_0_168,-F_0_331
PW_MF008_MF041 times 4 dw -F_0_081,-F_0_418 PW_MF008_MF041 times 4 dw -F_0_081,-F_0_418
PD_ONEHALFM1_CJ times 4 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS) PD_ONEHALFM1_CJ times 4 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS)
PD_ONEHALF times 4 dd (1 << (SCALEBITS-1)) PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
alignz 16 alignz 16
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 32 BITS 32
%include "jcclrss2.asm" %include "jcclrss2.asm"

View File

@@ -21,31 +21,31 @@
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
%define SCALEBITS 16 %define SCALEBITS 16
F_0_114 equ 7471 ; FIX(0.11400) F_0_114 equ 7471 ; FIX(0.11400)
F_0_250 equ 16384 ; FIX(0.25000) F_0_250 equ 16384 ; FIX(0.25000)
F_0_299 equ 19595 ; FIX(0.29900) F_0_299 equ 19595 ; FIX(0.29900)
F_0_587 equ 38470 ; FIX(0.58700) F_0_587 equ 38470 ; FIX(0.58700)
F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000)
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_CONST SECTION SEG_CONST
alignz 16 alignz 16
global EXTN(jconst_rgb_gray_convert_mmx) global EXTN(jconst_rgb_gray_convert_mmx)
EXTN(jconst_rgb_gray_convert_mmx): EXTN(jconst_rgb_gray_convert_mmx):
PW_F0299_F0337 times 2 dw F_0_299, F_0_337 PW_F0299_F0337 times 2 dw F_0_299, F_0_337
PW_F0114_F0250 times 2 dw F_0_114, F_0_250 PW_F0114_F0250 times 2 dw F_0_114, F_0_250
PD_ONEHALF times 2 dd (1 << (SCALEBITS-1)) PD_ONEHALF times 2 dd (1 << (SCALEBITS-1))
alignz 16 alignz 16
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 32 BITS 32
%include "jcgrymmx.asm" %include "jcgrymmx.asm"

View File

@@ -18,31 +18,31 @@
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
%define SCALEBITS 16 %define SCALEBITS 16
F_0_114 equ 7471 ; FIX(0.11400) F_0_114 equ 7471 ; FIX(0.11400)
F_0_250 equ 16384 ; FIX(0.25000) F_0_250 equ 16384 ; FIX(0.25000)
F_0_299 equ 19595 ; FIX(0.29900) F_0_299 equ 19595 ; FIX(0.29900)
F_0_587 equ 38470 ; FIX(0.58700) F_0_587 equ 38470 ; FIX(0.58700)
F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000)
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_CONST SECTION SEG_CONST
alignz 16 alignz 16
global EXTN(jconst_rgb_gray_convert_sse2) global EXTN(jconst_rgb_gray_convert_sse2)
EXTN(jconst_rgb_gray_convert_sse2): EXTN(jconst_rgb_gray_convert_sse2):
PW_F0299_F0337 times 4 dw F_0_299, F_0_337 PW_F0299_F0337 times 4 dw F_0_299, F_0_337
PW_F0114_F0250 times 4 dw F_0_114, F_0_250 PW_F0114_F0250 times 4 dw F_0_114, F_0_250
PD_ONEHALF times 4 dd (1 << (SCALEBITS-1)) PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
alignz 16 alignz 16
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 64 BITS 64
%include "jcgryss2-64.asm" %include "jcgryss2-64.asm"

View File

@@ -18,31 +18,31 @@
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
%define SCALEBITS 16 %define SCALEBITS 16
F_0_114 equ 7471 ; FIX(0.11400) F_0_114 equ 7471 ; FIX(0.11400)
F_0_250 equ 16384 ; FIX(0.25000) F_0_250 equ 16384 ; FIX(0.25000)
F_0_299 equ 19595 ; FIX(0.29900) F_0_299 equ 19595 ; FIX(0.29900)
F_0_587 equ 38470 ; FIX(0.58700) F_0_587 equ 38470 ; FIX(0.58700)
F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000)
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_CONST SECTION SEG_CONST
alignz 16 alignz 16
global EXTN(jconst_rgb_gray_convert_sse2) global EXTN(jconst_rgb_gray_convert_sse2)
EXTN(jconst_rgb_gray_convert_sse2): EXTN(jconst_rgb_gray_convert_sse2):
PW_F0299_F0337 times 4 dw F_0_299, F_0_337 PW_F0299_F0337 times 4 dw F_0_299, F_0_337
PW_F0114_F0250 times 4 dw F_0_114, F_0_250 PW_F0114_F0250 times 4 dw F_0_114, F_0_250
PD_ONEHALF times 4 dd (1 << (SCALEBITS-1)) PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
alignz 16 alignz 16
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 32 BITS 32
%include "jcgryss2.asm" %include "jcgryss2.asm"

View File

@@ -29,329 +29,329 @@
; JDIMENSION output_row, int num_rows); ; JDIMENSION output_row, int num_rows);
; ;
%define img_width(b) (b)+8 ; JDIMENSION img_width %define img_width(b) (b)+8 ; JDIMENSION img_width
%define input_buf(b) (b)+12 ; JSAMPARRAY input_buf %define input_buf(b) (b)+12 ; JSAMPARRAY input_buf
%define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf %define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf
%define output_row(b) (b)+20 ; JDIMENSION output_row %define output_row(b) (b)+20 ; JDIMENSION output_row
%define num_rows(b) (b)+24 ; int num_rows %define num_rows(b) (b)+24 ; int num_rows
%define original_ebp ebp+0 %define original_ebp ebp+0
%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM] %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM]
%define WK_NUM 2 %define WK_NUM 2
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr %define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16 align 16
global EXTN(jsimd_rgb_gray_convert_mmx) global EXTN(jsimd_rgb_gray_convert_mmx)
EXTN(jsimd_rgb_gray_convert_mmx): EXTN(jsimd_rgb_gray_convert_mmx):
push ebp push ebp
mov eax,esp ; eax = original ebp mov eax,esp ; eax = original ebp
sub esp, byte 4 sub esp, byte 4
and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
mov [esp],eax mov [esp],eax
mov ebp,esp ; ebp = aligned ebp mov ebp,esp ; ebp = aligned ebp
lea esp, [wk(0)] lea esp, [wk(0)]
pushpic eax ; make a room for GOT address pushpic eax ; make a room for GOT address
push ebx push ebx
; push ecx ; need not be preserved ; push ecx ; need not be preserved
; push edx ; need not be preserved ; push edx ; need not be preserved
push esi push esi
push edi push edi
get_GOT ebx ; get GOT address get_GOT ebx ; get GOT address
movpic POINTER [gotptr], ebx ; save GOT address movpic POINTER [gotptr], ebx ; save GOT address
mov ecx, JDIMENSION [img_width(eax)] ; num_cols mov ecx, JDIMENSION [img_width(eax)] ; num_cols
test ecx,ecx test ecx,ecx
jz near .return jz near .return
push ecx push ecx
mov esi, JSAMPIMAGE [output_buf(eax)] mov esi, JSAMPIMAGE [output_buf(eax)]
mov ecx, JDIMENSION [output_row(eax)] mov ecx, JDIMENSION [output_row(eax)]
mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY] mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY]
lea edi, [edi+ecx*SIZEOF_JSAMPROW] lea edi, [edi+ecx*SIZEOF_JSAMPROW]
pop ecx pop ecx
mov esi, JSAMPARRAY [input_buf(eax)] mov esi, JSAMPARRAY [input_buf(eax)]
mov eax, INT [num_rows(eax)] mov eax, INT [num_rows(eax)]
test eax,eax test eax,eax
jle near .return jle near .return
alignx 16,7 alignx 16,7
.rowloop: .rowloop:
pushpic eax pushpic eax
push edi push edi
push esi push esi
push ecx ; col push ecx ; col
mov esi, JSAMPROW [esi] ; inptr mov esi, JSAMPROW [esi] ; inptr
mov edi, JSAMPROW [edi] ; outptr0 mov edi, JSAMPROW [edi] ; outptr0
movpic eax, POINTER [gotptr] ; load GOT address (eax) movpic eax, POINTER [gotptr] ; load GOT address (eax)
cmp ecx, byte SIZEOF_MMWORD cmp ecx, byte SIZEOF_MMWORD
jae short .columnloop jae short .columnloop
alignx 16,7 alignx 16,7
%if RGB_PIXELSIZE == 3 ; --------------- %if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1: .column_ld1:
push eax push eax
push edx push edx
lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE test cl, SIZEOF_BYTE
jz short .column_ld2 jz short .column_ld2
sub ecx, byte SIZEOF_BYTE sub ecx, byte SIZEOF_BYTE
xor eax,eax xor eax,eax
mov al, BYTE [esi+ecx] mov al, BYTE [esi+ecx]
.column_ld2: .column_ld2:
test cl, SIZEOF_WORD test cl, SIZEOF_WORD
jz short .column_ld4 jz short .column_ld4
sub ecx, byte SIZEOF_WORD sub ecx, byte SIZEOF_WORD
xor edx,edx xor edx,edx
mov dx, WORD [esi+ecx] mov dx, WORD [esi+ecx]
shl eax, WORD_BIT shl eax, WORD_BIT
or eax,edx or eax,edx
.column_ld4: .column_ld4:
movd mmA,eax movd mmA,eax
pop edx pop edx
pop eax pop eax
test cl, SIZEOF_DWORD test cl, SIZEOF_DWORD
jz short .column_ld8 jz short .column_ld8
sub ecx, byte SIZEOF_DWORD sub ecx, byte SIZEOF_DWORD
movd mmG, DWORD [esi+ecx] movd mmG, DWORD [esi+ecx]
psllq mmA, DWORD_BIT psllq mmA, DWORD_BIT
por mmA,mmG por mmA,mmG
.column_ld8: .column_ld8:
test cl, SIZEOF_MMWORD test cl, SIZEOF_MMWORD
jz short .column_ld16 jz short .column_ld16
movq mmG,mmA movq mmG,mmA
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
mov ecx, SIZEOF_MMWORD mov ecx, SIZEOF_MMWORD
jmp short .rgb_gray_cnv jmp short .rgb_gray_cnv
.column_ld16: .column_ld16:
test cl, 2*SIZEOF_MMWORD test cl, 2*SIZEOF_MMWORD
mov ecx, SIZEOF_MMWORD mov ecx, SIZEOF_MMWORD
jz short .rgb_gray_cnv jz short .rgb_gray_cnv
movq mmF,mmA movq mmF,mmA
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmG, MMWORD [esi+1*SIZEOF_MMWORD] movq mmG, MMWORD [esi+1*SIZEOF_MMWORD]
jmp short .rgb_gray_cnv jmp short .rgb_gray_cnv
alignx 16,7 alignx 16,7
.columnloop: .columnloop:
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmG, MMWORD [esi+1*SIZEOF_MMWORD] movq mmG, MMWORD [esi+1*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+2*SIZEOF_MMWORD] movq mmF, MMWORD [esi+2*SIZEOF_MMWORD]
.rgb_gray_cnv: .rgb_gray_cnv:
; mmA=(00 10 20 01 11 21 02 12) ; mmA=(00 10 20 01 11 21 02 12)
; mmG=(22 03 13 23 04 14 24 05) ; mmG=(22 03 13 23 04 14 24 05)
; mmF=(15 25 06 16 26 07 17 27) ; mmF=(15 25 06 16 26 07 17 27)
movq mmD,mmA movq mmD,mmA
psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 10 20 01) psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 10 20 01)
psrlq mmD,4*BYTE_BIT ; mmD=(11 21 02 12 -- -- -- --) psrlq mmD,4*BYTE_BIT ; mmD=(11 21 02 12 -- -- -- --)
punpckhbw mmA,mmG ; mmA=(00 04 10 14 20 24 01 05) punpckhbw mmA,mmG ; mmA=(00 04 10 14 20 24 01 05)
psllq mmG,4*BYTE_BIT ; mmG=(-- -- -- -- 22 03 13 23) psllq mmG,4*BYTE_BIT ; mmG=(-- -- -- -- 22 03 13 23)
punpcklbw mmD,mmF ; mmD=(11 15 21 25 02 06 12 16) punpcklbw mmD,mmF ; mmD=(11 15 21 25 02 06 12 16)
punpckhbw mmG,mmF ; mmG=(22 26 03 07 13 17 23 27) punpckhbw mmG,mmF ; mmG=(22 26 03 07 13 17 23 27)
movq mmE,mmA movq mmE,mmA
psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 04 10 14) psllq mmA,4*BYTE_BIT ; mmA=(-- -- -- -- 00 04 10 14)
psrlq mmE,4*BYTE_BIT ; mmE=(20 24 01 05 -- -- -- --) psrlq mmE,4*BYTE_BIT ; mmE=(20 24 01 05 -- -- -- --)
punpckhbw mmA,mmD ; mmA=(00 02 04 06 10 12 14 16) punpckhbw mmA,mmD ; mmA=(00 02 04 06 10 12 14 16)
psllq mmD,4*BYTE_BIT ; mmD=(-- -- -- -- 11 15 21 25) psllq mmD,4*BYTE_BIT ; mmD=(-- -- -- -- 11 15 21 25)
punpcklbw mmE,mmG ; mmE=(20 22 24 26 01 03 05 07) punpcklbw mmE,mmG ; mmE=(20 22 24 26 01 03 05 07)
punpckhbw mmD,mmG ; mmD=(11 13 15 17 21 23 25 27) punpckhbw mmD,mmG ; mmD=(11 13 15 17 21 23 25 27)
pxor mmH,mmH pxor mmH,mmH
movq mmC,mmA movq mmC,mmA
punpcklbw mmA,mmH ; mmA=(00 02 04 06) punpcklbw mmA,mmH ; mmA=(00 02 04 06)
punpckhbw mmC,mmH ; mmC=(10 12 14 16) punpckhbw mmC,mmH ; mmC=(10 12 14 16)
movq mmB,mmE movq mmB,mmE
punpcklbw mmE,mmH ; mmE=(20 22 24 26) punpcklbw mmE,mmH ; mmE=(20 22 24 26)
punpckhbw mmB,mmH ; mmB=(01 03 05 07) punpckhbw mmB,mmH ; mmB=(01 03 05 07)
movq mmF,mmD movq mmF,mmD
punpcklbw mmD,mmH ; mmD=(11 13 15 17) punpcklbw mmD,mmH ; mmD=(11 13 15 17)
punpckhbw mmF,mmH ; mmF=(21 23 25 27) punpckhbw mmF,mmH ; mmF=(21 23 25 27)
%else ; RGB_PIXELSIZE == 4 ; ----------- %else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1: .column_ld1:
test cl, SIZEOF_MMWORD/8 test cl, SIZEOF_MMWORD/8
jz short .column_ld2 jz short .column_ld2
sub ecx, byte SIZEOF_MMWORD/8 sub ecx, byte SIZEOF_MMWORD/8
movd mmA, DWORD [esi+ecx*RGB_PIXELSIZE] movd mmA, DWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld2: .column_ld2:
test cl, SIZEOF_MMWORD/4 test cl, SIZEOF_MMWORD/4
jz short .column_ld4 jz short .column_ld4
sub ecx, byte SIZEOF_MMWORD/4 sub ecx, byte SIZEOF_MMWORD/4
movq mmF,mmA movq mmF,mmA
movq mmA, MMWORD [esi+ecx*RGB_PIXELSIZE] movq mmA, MMWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld4: .column_ld4:
test cl, SIZEOF_MMWORD/2 test cl, SIZEOF_MMWORD/2
mov ecx, SIZEOF_MMWORD mov ecx, SIZEOF_MMWORD
jz short .rgb_gray_cnv jz short .rgb_gray_cnv
movq mmD,mmA movq mmD,mmA
movq mmC,mmF movq mmC,mmF
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+1*SIZEOF_MMWORD] movq mmF, MMWORD [esi+1*SIZEOF_MMWORD]
jmp short .rgb_gray_cnv jmp short .rgb_gray_cnv
alignx 16,7 alignx 16,7
.columnloop: .columnloop:
movq mmA, MMWORD [esi+0*SIZEOF_MMWORD] movq mmA, MMWORD [esi+0*SIZEOF_MMWORD]
movq mmF, MMWORD [esi+1*SIZEOF_MMWORD] movq mmF, MMWORD [esi+1*SIZEOF_MMWORD]
movq mmD, MMWORD [esi+2*SIZEOF_MMWORD] movq mmD, MMWORD [esi+2*SIZEOF_MMWORD]
movq mmC, MMWORD [esi+3*SIZEOF_MMWORD] movq mmC, MMWORD [esi+3*SIZEOF_MMWORD]
.rgb_gray_cnv: .rgb_gray_cnv:
; mmA=(00 10 20 30 01 11 21 31) ; mmA=(00 10 20 30 01 11 21 31)
; mmF=(02 12 22 32 03 13 23 33) ; mmF=(02 12 22 32 03 13 23 33)
; mmD=(04 14 24 34 05 15 25 35) ; mmD=(04 14 24 34 05 15 25 35)
; mmC=(06 16 26 36 07 17 27 37) ; mmC=(06 16 26 36 07 17 27 37)
movq mmB,mmA movq mmB,mmA
punpcklbw mmA,mmF ; mmA=(00 02 10 12 20 22 30 32) punpcklbw mmA,mmF ; mmA=(00 02 10 12 20 22 30 32)
punpckhbw mmB,mmF ; mmB=(01 03 11 13 21 23 31 33) punpckhbw mmB,mmF ; mmB=(01 03 11 13 21 23 31 33)
movq mmG,mmD movq mmG,mmD
punpcklbw mmD,mmC ; mmD=(04 06 14 16 24 26 34 36) punpcklbw mmD,mmC ; mmD=(04 06 14 16 24 26 34 36)
punpckhbw mmG,mmC ; mmG=(05 07 15 17 25 27 35 37) punpckhbw mmG,mmC ; mmG=(05 07 15 17 25 27 35 37)
movq mmE,mmA movq mmE,mmA
punpcklwd mmA,mmD ; mmA=(00 02 04 06 10 12 14 16) punpcklwd mmA,mmD ; mmA=(00 02 04 06 10 12 14 16)
punpckhwd mmE,mmD ; mmE=(20 22 24 26 30 32 34 36) punpckhwd mmE,mmD ; mmE=(20 22 24 26 30 32 34 36)
movq mmH,mmB movq mmH,mmB
punpcklwd mmB,mmG ; mmB=(01 03 05 07 11 13 15 17) punpcklwd mmB,mmG ; mmB=(01 03 05 07 11 13 15 17)
punpckhwd mmH,mmG ; mmH=(21 23 25 27 31 33 35 37) punpckhwd mmH,mmG ; mmH=(21 23 25 27 31 33 35 37)
pxor mmF,mmF pxor mmF,mmF
movq mmC,mmA movq mmC,mmA
punpcklbw mmA,mmF ; mmA=(00 02 04 06) punpcklbw mmA,mmF ; mmA=(00 02 04 06)
punpckhbw mmC,mmF ; mmC=(10 12 14 16) punpckhbw mmC,mmF ; mmC=(10 12 14 16)
movq mmD,mmB movq mmD,mmB
punpcklbw mmB,mmF ; mmB=(01 03 05 07) punpcklbw mmB,mmF ; mmB=(01 03 05 07)
punpckhbw mmD,mmF ; mmD=(11 13 15 17) punpckhbw mmD,mmF ; mmD=(11 13 15 17)
movq mmG,mmE movq mmG,mmE
punpcklbw mmE,mmF ; mmE=(20 22 24 26) punpcklbw mmE,mmF ; mmE=(20 22 24 26)
punpckhbw mmG,mmF ; mmG=(30 32 34 36) punpckhbw mmG,mmF ; mmG=(30 32 34 36)
punpcklbw mmF,mmH punpcklbw mmF,mmH
punpckhbw mmH,mmH punpckhbw mmH,mmH
psrlw mmF,BYTE_BIT ; mmF=(21 23 25 27) psrlw mmF,BYTE_BIT ; mmF=(21 23 25 27)
psrlw mmH,BYTE_BIT ; mmH=(31 33 35 37) psrlw mmH,BYTE_BIT ; mmH=(31 33 35 37)
%endif ; RGB_PIXELSIZE ; --------------- %endif ; RGB_PIXELSIZE ; ---------------
; mm0=(R0 R2 R4 R6)=RE, mm2=(G0 G2 G4 G6)=GE, mm4=(B0 B2 B4 B6)=BE ; mm0=(R0 R2 R4 R6)=RE, mm2=(G0 G2 G4 G6)=GE, mm4=(B0 B2 B4 B6)=BE
; mm1=(R1 R3 R5 R7)=RO, mm3=(G1 G3 G5 G7)=GO, mm5=(B1 B3 B5 B7)=BO ; mm1=(R1 R3 R5 R7)=RO, mm3=(G1 G3 G5 G7)=GO, mm5=(B1 B3 B5 B7)=BO
; (Original) ; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
; ;
; (This implementation) ; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
movq mm6,mm1 movq mm6,mm1
punpcklwd mm1,mm3 punpcklwd mm1,mm3
punpckhwd mm6,mm3 punpckhwd mm6,mm3
pmaddwd mm1,[GOTOFF(eax,PW_F0299_F0337)] ; mm1=ROL*FIX(0.299)+GOL*FIX(0.337) pmaddwd mm1,[GOTOFF(eax,PW_F0299_F0337)] ; mm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=ROH*FIX(0.299)+GOH*FIX(0.337) pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=ROH*FIX(0.299)+GOH*FIX(0.337)
movq mm7, mm6 ; mm7=ROH*FIX(0.299)+GOH*FIX(0.337) movq mm7, mm6 ; mm7=ROH*FIX(0.299)+GOH*FIX(0.337)
movq mm6,mm0 movq mm6,mm0
punpcklwd mm0,mm2 punpcklwd mm0,mm2
punpckhwd mm6,mm2 punpckhwd mm6,mm2
pmaddwd mm0,[GOTOFF(eax,PW_F0299_F0337)] ; mm0=REL*FIX(0.299)+GEL*FIX(0.337) pmaddwd mm0,[GOTOFF(eax,PW_F0299_F0337)] ; mm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=REH*FIX(0.299)+GEH*FIX(0.337) pmaddwd mm6,[GOTOFF(eax,PW_F0299_F0337)] ; mm6=REH*FIX(0.299)+GEH*FIX(0.337)
movq MMWORD [wk(0)], mm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337) movq MMWORD [wk(0)], mm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337)
movq MMWORD [wk(1)], mm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337) movq MMWORD [wk(1)], mm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337)
movq mm0, mm5 ; mm0=BO movq mm0, mm5 ; mm0=BO
movq mm6, mm4 ; mm6=BE movq mm6, mm4 ; mm6=BE
movq mm4,mm0 movq mm4,mm0
punpcklwd mm0,mm3 punpcklwd mm0,mm3
punpckhwd mm4,mm3 punpckhwd mm4,mm3
pmaddwd mm0,[GOTOFF(eax,PW_F0114_F0250)] ; mm0=BOL*FIX(0.114)+GOL*FIX(0.250) pmaddwd mm0,[GOTOFF(eax,PW_F0114_F0250)] ; mm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BOH*FIX(0.114)+GOH*FIX(0.250) pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BOH*FIX(0.114)+GOH*FIX(0.250)
movq mm3,[GOTOFF(eax,PD_ONEHALF)] ; mm3=[PD_ONEHALF] movq mm3,[GOTOFF(eax,PD_ONEHALF)] ; mm3=[PD_ONEHALF]
paddd mm0, mm1 paddd mm0, mm1
paddd mm4, mm7 paddd mm4, mm7
paddd mm0,mm3 paddd mm0,mm3
paddd mm4,mm3 paddd mm4,mm3
psrld mm0,SCALEBITS ; mm0=YOL psrld mm0,SCALEBITS ; mm0=YOL
psrld mm4,SCALEBITS ; mm4=YOH psrld mm4,SCALEBITS ; mm4=YOH
packssdw mm0,mm4 ; mm0=YO packssdw mm0,mm4 ; mm0=YO
movq mm4,mm6 movq mm4,mm6
punpcklwd mm6,mm2 punpcklwd mm6,mm2
punpckhwd mm4,mm2 punpckhwd mm4,mm2
pmaddwd mm6,[GOTOFF(eax,PW_F0114_F0250)] ; mm6=BEL*FIX(0.114)+GEL*FIX(0.250) pmaddwd mm6,[GOTOFF(eax,PW_F0114_F0250)] ; mm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BEH*FIX(0.114)+GEH*FIX(0.250) pmaddwd mm4,[GOTOFF(eax,PW_F0114_F0250)] ; mm4=BEH*FIX(0.114)+GEH*FIX(0.250)
movq mm2,[GOTOFF(eax,PD_ONEHALF)] ; mm2=[PD_ONEHALF] movq mm2,[GOTOFF(eax,PD_ONEHALF)] ; mm2=[PD_ONEHALF]
paddd mm6, MMWORD [wk(0)] paddd mm6, MMWORD [wk(0)]
paddd mm4, MMWORD [wk(1)] paddd mm4, MMWORD [wk(1)]
paddd mm6,mm2 paddd mm6,mm2
paddd mm4,mm2 paddd mm4,mm2
psrld mm6,SCALEBITS ; mm6=YEL psrld mm6,SCALEBITS ; mm6=YEL
psrld mm4,SCALEBITS ; mm4=YEH psrld mm4,SCALEBITS ; mm4=YEH
packssdw mm6,mm4 ; mm6=YE packssdw mm6,mm4 ; mm6=YE
psllw mm0,BYTE_BIT psllw mm0,BYTE_BIT
por mm6,mm0 ; mm6=Y por mm6,mm0 ; mm6=Y
movq MMWORD [edi], mm6 ; Save Y movq MMWORD [edi], mm6 ; Save Y
sub ecx, byte SIZEOF_MMWORD sub ecx, byte SIZEOF_MMWORD
add esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; inptr add esi, byte RGB_PIXELSIZE*SIZEOF_MMWORD ; inptr
add edi, byte SIZEOF_MMWORD ; outptr0 add edi, byte SIZEOF_MMWORD ; outptr0
cmp ecx, byte SIZEOF_MMWORD cmp ecx, byte SIZEOF_MMWORD
jae near .columnloop jae near .columnloop
test ecx,ecx test ecx,ecx
jnz near .column_ld1 jnz near .column_ld1
pop ecx ; col pop ecx ; col
pop esi pop esi
pop edi pop edi
poppic eax poppic eax
add esi, byte SIZEOF_JSAMPROW ; input_buf add esi, byte SIZEOF_JSAMPROW ; input_buf
add edi, byte SIZEOF_JSAMPROW add edi, byte SIZEOF_JSAMPROW
dec eax ; num_rows dec eax ; num_rows
jg near .rowloop jg near .rowloop
emms ; empty MMX state emms ; empty MMX state
.return: .return:
pop edi pop edi
pop esi pop esi
; pop edx ; need not be preserved ; pop edx ; need not be preserved
; pop ecx ; need not be preserved ; pop ecx ; need not be preserved
pop ebx pop ebx
mov esp,ebp ; esp <- aligned ebp mov esp,ebp ; esp <- aligned ebp
pop esp ; esp <- original ebp pop esp ; esp <- original ebp
pop ebp pop ebp
ret ret
; For some reason, the OS X linker does not honor the request to align the ; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this. ; segment unless we do this.
align 16 align 16

View File

@@ -32,333 +32,333 @@
; r13 = JDIMENSION output_row ; r13 = JDIMENSION output_row
; r14 = int num_rows ; r14 = int num_rows
%define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] %define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2 %define WK_NUM 2
align 16 align 16
global EXTN(jsimd_rgb_gray_convert_sse2) global EXTN(jsimd_rgb_gray_convert_sse2)
EXTN(jsimd_rgb_gray_convert_sse2): EXTN(jsimd_rgb_gray_convert_sse2):
push rbp push rbp
mov rax,rsp ; rax = original rbp mov rax,rsp ; rax = original rbp
sub rsp, byte 4 sub rsp, byte 4
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [rsp],rax mov [rsp],rax
mov rbp,rsp ; rbp = aligned rbp mov rbp,rsp ; rbp = aligned rbp
lea rsp, [wk(0)] lea rsp, [wk(0)]
collect_args collect_args
push rbx push rbx
mov rcx, r10 mov rcx, r10
test rcx,rcx test rcx,rcx
jz near .return jz near .return
push rcx push rcx
mov rsi, r12 mov rsi, r12
mov rcx, r13 mov rcx, r13
mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY] mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
lea rdi, [rdi+rcx*SIZEOF_JSAMPROW] lea rdi, [rdi+rcx*SIZEOF_JSAMPROW]
pop rcx pop rcx
mov rsi, r11 mov rsi, r11
mov eax, r14d mov eax, r14d
test rax,rax test rax,rax
jle near .return jle near .return
.rowloop: .rowloop:
push rdi push rdi
push rsi push rsi
push rcx ; col push rcx ; col
mov rsi, JSAMPROW [rsi] ; inptr mov rsi, JSAMPROW [rsi] ; inptr
mov rdi, JSAMPROW [rdi] ; outptr0 mov rdi, JSAMPROW [rdi] ; outptr0
cmp rcx, byte SIZEOF_XMMWORD cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop jae near .columnloop
%if RGB_PIXELSIZE == 3 ; --------------- %if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1: .column_ld1:
push rax push rax
push rdx push rdx
lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE lea rcx,[rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE test cl, SIZEOF_BYTE
jz short .column_ld2 jz short .column_ld2
sub rcx, byte SIZEOF_BYTE sub rcx, byte SIZEOF_BYTE
movzx rax, BYTE [rsi+rcx] movzx rax, BYTE [rsi+rcx]
.column_ld2: .column_ld2:
test cl, SIZEOF_WORD test cl, SIZEOF_WORD
jz short .column_ld4 jz short .column_ld4
sub rcx, byte SIZEOF_WORD sub rcx, byte SIZEOF_WORD
movzx rdx, WORD [rsi+rcx] movzx rdx, WORD [rsi+rcx]
shl rax, WORD_BIT shl rax, WORD_BIT
or rax,rdx or rax,rdx
.column_ld4: .column_ld4:
movd xmmA,eax movd xmmA,eax
pop rdx pop rdx
pop rax pop rax
test cl, SIZEOF_DWORD test cl, SIZEOF_DWORD
jz short .column_ld8 jz short .column_ld8
sub rcx, byte SIZEOF_DWORD sub rcx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [rsi+rcx] movd xmmF, XMM_DWORD [rsi+rcx]
pslldq xmmA, SIZEOF_DWORD pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF por xmmA,xmmF
.column_ld8: .column_ld8:
test cl, SIZEOF_MMWORD test cl, SIZEOF_MMWORD
jz short .column_ld16 jz short .column_ld16
sub rcx, byte SIZEOF_MMWORD sub rcx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [rsi+rcx] movq xmmB, XMM_MMWORD [rsi+rcx]
pslldq xmmA, SIZEOF_MMWORD pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB por xmmA,xmmB
.column_ld16: .column_ld16:
test cl, SIZEOF_XMMWORD test cl, SIZEOF_XMMWORD
jz short .column_ld32 jz short .column_ld32
movdqa xmmF,xmmA movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
mov rcx, SIZEOF_XMMWORD mov rcx, SIZEOF_XMMWORD
jmp short .rgb_gray_cnv jmp short .rgb_gray_cnv
.column_ld32: .column_ld32:
test cl, 2*SIZEOF_XMMWORD test cl, 2*SIZEOF_XMMWORD
mov rcx, SIZEOF_XMMWORD mov rcx, SIZEOF_XMMWORD
jz short .rgb_gray_cnv jz short .rgb_gray_cnv
movdqa xmmB,xmmA movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_gray_cnv jmp short .rgb_gray_cnv
.columnloop: .columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD] movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD]
.rgb_gray_cnv: .rgb_gray_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --) psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A) punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27) pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D) punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F) punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --) psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D) punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B) pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E) punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F) punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --) psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D) pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F) punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F) punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH pxor xmmH,xmmH
movdqa xmmC,xmmA movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E) punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E) punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E) punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F) punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F) punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F) punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; ----------- %else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1: .column_ld1:
test cl, SIZEOF_XMMWORD/16 test cl, SIZEOF_XMMWORD/16
jz short .column_ld2 jz short .column_ld2
sub rcx, byte SIZEOF_XMMWORD/16 sub rcx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE] movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld2: .column_ld2:
test cl, SIZEOF_XMMWORD/8 test cl, SIZEOF_XMMWORD/8
jz short .column_ld4 jz short .column_ld4
sub rcx, byte SIZEOF_XMMWORD/8 sub rcx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE] movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE por xmmA,xmmE
.column_ld4: .column_ld4:
test cl, SIZEOF_XMMWORD/4 test cl, SIZEOF_XMMWORD/4
jz short .column_ld8 jz short .column_ld8
sub rcx, byte SIZEOF_XMMWORD/4 sub rcx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE] movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
.column_ld8: .column_ld8:
test cl, SIZEOF_XMMWORD/2 test cl, SIZEOF_XMMWORD/2
mov rcx, SIZEOF_XMMWORD mov rcx, SIZEOF_XMMWORD
jz short .rgb_gray_cnv jz short .rgb_gray_cnv
movdqa xmmF,xmmA movdqa xmmF,xmmA
movdqa xmmH,xmmE movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD] movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
jmp short .rgb_gray_cnv jmp short .rgb_gray_cnv
.columnloop: .columnloop:
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD] movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD] movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD]
.rgb_gray_cnv: .rgb_gray_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35) punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37) punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D) punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F) punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C) punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D) punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E) punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F) punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E) punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F) punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F) punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF pxor xmmF,xmmF
movdqa xmmC,xmmA movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E) punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E) punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F) punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F) punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E) punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E) punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F) psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F) psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; --------------- %endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
; (Original) ; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
; ;
; (This implementation) ; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
movdqa xmm6,xmm1 movdqa xmm6,xmm1
punpcklwd xmm1,xmm3 punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3 punpckhwd xmm6,xmm3
pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337) pmaddwd xmm1,[rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337) pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337) movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337)
movdqa xmm6,xmm0 movdqa xmm6,xmm0
punpcklwd xmm0,xmm2 punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2 punpckhwd xmm6,xmm2
pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337) pmaddwd xmm0,[rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337) pmaddwd xmm6,[rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337) movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337) movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337)
movdqa xmm0, xmm5 ; xmm0=BO movdqa xmm0, xmm5 ; xmm0=BO
movdqa xmm6, xmm4 ; xmm6=BE movdqa xmm6, xmm4 ; xmm6=BE
movdqa xmm4,xmm0 movdqa xmm4,xmm0
punpcklwd xmm0,xmm3 punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3 punpckhwd xmm4,xmm3
pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250) pmaddwd xmm0,[rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250) pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF] movdqa xmm3,[rel PD_ONEHALF] ; xmm3=[PD_ONEHALF]
paddd xmm0, xmm1 paddd xmm0, xmm1
paddd xmm4, xmm7 paddd xmm4, xmm7
paddd xmm0,xmm3 paddd xmm0,xmm3
paddd xmm4,xmm3 paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO packssdw xmm0,xmm4 ; xmm0=YO
movdqa xmm4,xmm6 movdqa xmm4,xmm6
punpcklwd xmm6,xmm2 punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2 punpckhwd xmm4,xmm2
pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250) pmaddwd xmm6,[rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250) pmaddwd xmm4,[rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF] movdqa xmm2,[rel PD_ONEHALF] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(0)] paddd xmm6, XMMWORD [wk(0)]
paddd xmm4, XMMWORD [wk(1)] paddd xmm4, XMMWORD [wk(1)]
paddd xmm6,xmm2 paddd xmm6,xmm2
paddd xmm4,xmm2 paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [rdi], xmm6 ; Save Y movdqa XMMWORD [rdi], xmm6 ; Save Y
sub rcx, byte SIZEOF_XMMWORD sub rcx, byte SIZEOF_XMMWORD
add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add rdi, byte SIZEOF_XMMWORD ; outptr0 add rdi, byte SIZEOF_XMMWORD ; outptr0
cmp rcx, byte SIZEOF_XMMWORD cmp rcx, byte SIZEOF_XMMWORD
jae near .columnloop jae near .columnloop
test rcx,rcx test rcx,rcx
jnz near .column_ld1 jnz near .column_ld1
pop rcx ; col pop rcx ; col
pop rsi pop rsi
pop rdi pop rdi
add rsi, byte SIZEOF_JSAMPROW ; input_buf add rsi, byte SIZEOF_JSAMPROW ; input_buf
add rdi, byte SIZEOF_JSAMPROW add rdi, byte SIZEOF_JSAMPROW
dec rax ; num_rows dec rax ; num_rows
jg near .rowloop jg near .rowloop
.return: .return:
pop rbx pop rbx
uncollect_args uncollect_args
mov rsp,rbp ; rsp <- aligned rbp mov rsp,rbp ; rsp <- aligned rbp
pop rsp ; rsp <- original rbp pop rsp ; rsp <- original rbp
pop rbp pop rbp
ret ret
; For some reason, the OS X linker does not honor the request to align the ; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this. ; segment unless we do this.
align 16 align 16

View File

@@ -26,358 +26,358 @@
; JDIMENSION output_row, int num_rows); ; JDIMENSION output_row, int num_rows);
; ;
%define img_width(b) (b)+8 ; JDIMENSION img_width %define img_width(b) (b)+8 ; JDIMENSION img_width
%define input_buf(b) (b)+12 ; JSAMPARRAY input_buf %define input_buf(b) (b)+12 ; JSAMPARRAY input_buf
%define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf %define output_buf(b) (b)+16 ; JSAMPIMAGE output_buf
%define output_row(b) (b)+20 ; JDIMENSION output_row %define output_row(b) (b)+20 ; JDIMENSION output_row
%define num_rows(b) (b)+24 ; int num_rows %define num_rows(b) (b)+24 ; int num_rows
%define original_ebp ebp+0 %define original_ebp ebp+0
%define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
%define WK_NUM 2 %define WK_NUM 2
%define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr %define gotptr wk(0)-SIZEOF_POINTER ; void * gotptr
align 16 align 16
global EXTN(jsimd_rgb_gray_convert_sse2) global EXTN(jsimd_rgb_gray_convert_sse2)
EXTN(jsimd_rgb_gray_convert_sse2): EXTN(jsimd_rgb_gray_convert_sse2):
push ebp push ebp
mov eax,esp ; eax = original ebp mov eax,esp ; eax = original ebp
sub esp, byte 4 sub esp, byte 4
and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
mov [esp],eax mov [esp],eax
mov ebp,esp ; ebp = aligned ebp mov ebp,esp ; ebp = aligned ebp
lea esp, [wk(0)] lea esp, [wk(0)]
pushpic eax ; make a room for GOT address pushpic eax ; make a room for GOT address
push ebx push ebx
; push ecx ; need not be preserved ; push ecx ; need not be preserved
; push edx ; need not be preserved ; push edx ; need not be preserved
push esi push esi
push edi push edi
get_GOT ebx ; get GOT address get_GOT ebx ; get GOT address
movpic POINTER [gotptr], ebx ; save GOT address movpic POINTER [gotptr], ebx ; save GOT address
mov ecx, JDIMENSION [img_width(eax)] mov ecx, JDIMENSION [img_width(eax)]
test ecx,ecx test ecx,ecx
jz near .return jz near .return
push ecx push ecx
mov esi, JSAMPIMAGE [output_buf(eax)] mov esi, JSAMPIMAGE [output_buf(eax)]
mov ecx, JDIMENSION [output_row(eax)] mov ecx, JDIMENSION [output_row(eax)]
mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY] mov edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY]
lea edi, [edi+ecx*SIZEOF_JSAMPROW] lea edi, [edi+ecx*SIZEOF_JSAMPROW]
pop ecx pop ecx
mov esi, JSAMPARRAY [input_buf(eax)] mov esi, JSAMPARRAY [input_buf(eax)]
mov eax, INT [num_rows(eax)] mov eax, INT [num_rows(eax)]
test eax,eax test eax,eax
jle near .return jle near .return
alignx 16,7 alignx 16,7
.rowloop: .rowloop:
pushpic eax pushpic eax
push edi push edi
push esi push esi
push ecx ; col push ecx ; col
mov esi, JSAMPROW [esi] ; inptr mov esi, JSAMPROW [esi] ; inptr
mov edi, JSAMPROW [edi] ; outptr0 mov edi, JSAMPROW [edi] ; outptr0
movpic eax, POINTER [gotptr] ; load GOT address (eax) movpic eax, POINTER [gotptr] ; load GOT address (eax)
cmp ecx, byte SIZEOF_XMMWORD cmp ecx, byte SIZEOF_XMMWORD
jae near .columnloop jae near .columnloop
alignx 16,7 alignx 16,7
%if RGB_PIXELSIZE == 3 ; --------------- %if RGB_PIXELSIZE == 3 ; ---------------
.column_ld1: .column_ld1:
push eax push eax
push edx push edx
lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE lea ecx,[ecx+ecx*2] ; imul ecx,RGB_PIXELSIZE
test cl, SIZEOF_BYTE test cl, SIZEOF_BYTE
jz short .column_ld2 jz short .column_ld2
sub ecx, byte SIZEOF_BYTE sub ecx, byte SIZEOF_BYTE
movzx eax, BYTE [esi+ecx] movzx eax, BYTE [esi+ecx]
.column_ld2: .column_ld2:
test cl, SIZEOF_WORD test cl, SIZEOF_WORD
jz short .column_ld4 jz short .column_ld4
sub ecx, byte SIZEOF_WORD sub ecx, byte SIZEOF_WORD
movzx edx, WORD [esi+ecx] movzx edx, WORD [esi+ecx]
shl eax, WORD_BIT shl eax, WORD_BIT
or eax,edx or eax,edx
.column_ld4: .column_ld4:
movd xmmA,eax movd xmmA,eax
pop edx pop edx
pop eax pop eax
test cl, SIZEOF_DWORD test cl, SIZEOF_DWORD
jz short .column_ld8 jz short .column_ld8
sub ecx, byte SIZEOF_DWORD sub ecx, byte SIZEOF_DWORD
movd xmmF, XMM_DWORD [esi+ecx] movd xmmF, XMM_DWORD [esi+ecx]
pslldq xmmA, SIZEOF_DWORD pslldq xmmA, SIZEOF_DWORD
por xmmA,xmmF por xmmA,xmmF
.column_ld8: .column_ld8:
test cl, SIZEOF_MMWORD test cl, SIZEOF_MMWORD
jz short .column_ld16 jz short .column_ld16
sub ecx, byte SIZEOF_MMWORD sub ecx, byte SIZEOF_MMWORD
movq xmmB, XMM_MMWORD [esi+ecx] movq xmmB, XMM_MMWORD [esi+ecx]
pslldq xmmA, SIZEOF_MMWORD pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmB por xmmA,xmmB
.column_ld16: .column_ld16:
test cl, SIZEOF_XMMWORD test cl, SIZEOF_XMMWORD
jz short .column_ld32 jz short .column_ld32
movdqa xmmF,xmmA movdqa xmmF,xmmA
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
mov ecx, SIZEOF_XMMWORD mov ecx, SIZEOF_XMMWORD
jmp short .rgb_gray_cnv jmp short .rgb_gray_cnv
.column_ld32: .column_ld32:
test cl, 2*SIZEOF_XMMWORD test cl, 2*SIZEOF_XMMWORD
mov ecx, SIZEOF_XMMWORD mov ecx, SIZEOF_XMMWORD
jz short .rgb_gray_cnv jz short .rgb_gray_cnv
movdqa xmmB,xmmA movdqa xmmB,xmmA
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
jmp short .rgb_gray_cnv jmp short .rgb_gray_cnv
alignx 16,7 alignx 16,7
.columnloop: .columnloop:
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
movdqu xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD] movdqu xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD]
.rgb_gray_cnv: .rgb_gray_cnv:
; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
movdqa xmmG,xmmA movdqa xmmG,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --) psrldq xmmG,8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A) punpckhbw xmmA,xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27) pslldq xmmF,8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D) punpcklbw xmmG,xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F) punpckhbw xmmF,xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
movdqa xmmD,xmmA movdqa xmmD,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --) psrldq xmmD,8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D) punpckhbw xmmA,xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B) pslldq xmmG,8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E) punpcklbw xmmD,xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F) punpckhbw xmmG,xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
movdqa xmmE,xmmA movdqa xmmE,xmmA
pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C) pslldq xmmA,8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --) psrldq xmmE,8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) punpckhbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D) pslldq xmmD,8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F) punpcklbw xmmE,xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F) punpckhbw xmmD,xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
pxor xmmH,xmmH pxor xmmH,xmmH
movdqa xmmC,xmmA movdqa xmmC,xmmA
punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E) punpcklbw xmmA,xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E) punpckhbw xmmC,xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmB,xmmE movdqa xmmB,xmmE
punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E) punpcklbw xmmE,xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F) punpckhbw xmmB,xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
movdqa xmmF,xmmD movdqa xmmF,xmmD
punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F) punpcklbw xmmD,xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F) punpckhbw xmmF,xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
%else ; RGB_PIXELSIZE == 4 ; ----------- %else ; RGB_PIXELSIZE == 4 ; -----------
.column_ld1: .column_ld1:
test cl, SIZEOF_XMMWORD/16 test cl, SIZEOF_XMMWORD/16
jz short .column_ld2 jz short .column_ld2
sub ecx, byte SIZEOF_XMMWORD/16 sub ecx, byte SIZEOF_XMMWORD/16
movd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE] movd xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld2: .column_ld2:
test cl, SIZEOF_XMMWORD/8 test cl, SIZEOF_XMMWORD/8
jz short .column_ld4 jz short .column_ld4
sub ecx, byte SIZEOF_XMMWORD/8 sub ecx, byte SIZEOF_XMMWORD/8
movq xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE] movq xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE]
pslldq xmmA, SIZEOF_MMWORD pslldq xmmA, SIZEOF_MMWORD
por xmmA,xmmE por xmmA,xmmE
.column_ld4: .column_ld4:
test cl, SIZEOF_XMMWORD/4 test cl, SIZEOF_XMMWORD/4
jz short .column_ld8 jz short .column_ld8
sub ecx, byte SIZEOF_XMMWORD/4 sub ecx, byte SIZEOF_XMMWORD/4
movdqa xmmE,xmmA movdqa xmmE,xmmA
movdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE] movdqu xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE]
.column_ld8: .column_ld8:
test cl, SIZEOF_XMMWORD/2 test cl, SIZEOF_XMMWORD/2
mov ecx, SIZEOF_XMMWORD mov ecx, SIZEOF_XMMWORD
jz short .rgb_gray_cnv jz short .rgb_gray_cnv
movdqa xmmF,xmmA movdqa xmmF,xmmA
movdqa xmmH,xmmE movdqa xmmH,xmmE
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD] movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
jmp short .rgb_gray_cnv jmp short .rgb_gray_cnv
alignx 16,7 alignx 16,7
.columnloop: .columnloop:
movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD] movdqu xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD] movdqu xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
movdqu xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD] movdqu xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD]
movdqu xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD] movdqu xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD]
.rgb_gray_cnv: .rgb_gray_cnv:
; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
movdqa xmmD,xmmA movdqa xmmD,xmmA
punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35) punpcklbw xmmA,xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37) punpckhbw xmmD,xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
movdqa xmmC,xmmF movdqa xmmC,xmmF
punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D) punpcklbw xmmF,xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F) punpckhbw xmmC,xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
movdqa xmmB,xmmA movdqa xmmB,xmmA
punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C) punpcklwd xmmA,xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D) punpckhwd xmmB,xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
movdqa xmmG,xmmD movdqa xmmG,xmmD
punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E) punpcklwd xmmD,xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F) punpckhwd xmmG,xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
movdqa xmmE,xmmA movdqa xmmE,xmmA
punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E) punpcklbw xmmA,xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E) punpckhbw xmmE,xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
movdqa xmmH,xmmB movdqa xmmH,xmmB
punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F) punpcklbw xmmB,xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F) punpckhbw xmmH,xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
pxor xmmF,xmmF pxor xmmF,xmmF
movdqa xmmC,xmmA movdqa xmmC,xmmA
punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E) punpcklbw xmmA,xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E) punpckhbw xmmC,xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
movdqa xmmD,xmmB movdqa xmmD,xmmB
punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F) punpcklbw xmmB,xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F) punpckhbw xmmD,xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
movdqa xmmG,xmmE movdqa xmmG,xmmE
punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E) punpcklbw xmmE,xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E) punpckhbw xmmG,xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
punpcklbw xmmF,xmmH punpcklbw xmmF,xmmH
punpckhbw xmmH,xmmH punpckhbw xmmH,xmmH
psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F) psrlw xmmF,BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F) psrlw xmmH,BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
%endif ; RGB_PIXELSIZE ; --------------- %endif ; RGB_PIXELSIZE ; ---------------
; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
; (Original) ; (Original)
; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
; ;
; (This implementation) ; (This implementation)
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
movdqa xmm6,xmm1 movdqa xmm6,xmm1
punpcklwd xmm1,xmm3 punpcklwd xmm1,xmm3
punpckhwd xmm6,xmm3 punpckhwd xmm6,xmm3
pmaddwd xmm1,[GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337) pmaddwd xmm1,[GOTOFF(eax,PW_F0299_F0337)] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337) pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337) movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337)
movdqa xmm6,xmm0 movdqa xmm6,xmm0
punpcklwd xmm0,xmm2 punpcklwd xmm0,xmm2
punpckhwd xmm6,xmm2 punpckhwd xmm6,xmm2
pmaddwd xmm0,[GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337) pmaddwd xmm0,[GOTOFF(eax,PW_F0299_F0337)] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337) pmaddwd xmm6,[GOTOFF(eax,PW_F0299_F0337)] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337) movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337)
movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337) movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337)
movdqa xmm0, xmm5 ; xmm0=BO movdqa xmm0, xmm5 ; xmm0=BO
movdqa xmm6, xmm4 ; xmm6=BE movdqa xmm6, xmm4 ; xmm6=BE
movdqa xmm4,xmm0 movdqa xmm4,xmm0
punpcklwd xmm0,xmm3 punpcklwd xmm0,xmm3
punpckhwd xmm4,xmm3 punpckhwd xmm4,xmm3
pmaddwd xmm0,[GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250) pmaddwd xmm0,[GOTOFF(eax,PW_F0114_F0250)] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250) pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
movdqa xmm3,[GOTOFF(eax,PD_ONEHALF)] ; xmm3=[PD_ONEHALF] movdqa xmm3,[GOTOFF(eax,PD_ONEHALF)] ; xmm3=[PD_ONEHALF]
paddd xmm0, xmm1 paddd xmm0, xmm1
paddd xmm4, xmm7 paddd xmm4, xmm7
paddd xmm0,xmm3 paddd xmm0,xmm3
paddd xmm4,xmm3 paddd xmm4,xmm3
psrld xmm0,SCALEBITS ; xmm0=YOL psrld xmm0,SCALEBITS ; xmm0=YOL
psrld xmm4,SCALEBITS ; xmm4=YOH psrld xmm4,SCALEBITS ; xmm4=YOH
packssdw xmm0,xmm4 ; xmm0=YO packssdw xmm0,xmm4 ; xmm0=YO
movdqa xmm4,xmm6 movdqa xmm4,xmm6
punpcklwd xmm6,xmm2 punpcklwd xmm6,xmm2
punpckhwd xmm4,xmm2 punpckhwd xmm4,xmm2
pmaddwd xmm6,[GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250) pmaddwd xmm6,[GOTOFF(eax,PW_F0114_F0250)] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250) pmaddwd xmm4,[GOTOFF(eax,PW_F0114_F0250)] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
movdqa xmm2,[GOTOFF(eax,PD_ONEHALF)] ; xmm2=[PD_ONEHALF] movdqa xmm2,[GOTOFF(eax,PD_ONEHALF)] ; xmm2=[PD_ONEHALF]
paddd xmm6, XMMWORD [wk(0)] paddd xmm6, XMMWORD [wk(0)]
paddd xmm4, XMMWORD [wk(1)] paddd xmm4, XMMWORD [wk(1)]
paddd xmm6,xmm2 paddd xmm6,xmm2
paddd xmm4,xmm2 paddd xmm4,xmm2
psrld xmm6,SCALEBITS ; xmm6=YEL psrld xmm6,SCALEBITS ; xmm6=YEL
psrld xmm4,SCALEBITS ; xmm4=YEH psrld xmm4,SCALEBITS ; xmm4=YEH
packssdw xmm6,xmm4 ; xmm6=YE packssdw xmm6,xmm4 ; xmm6=YE
psllw xmm0,BYTE_BIT psllw xmm0,BYTE_BIT
por xmm6,xmm0 ; xmm6=Y por xmm6,xmm0 ; xmm6=Y
movdqa XMMWORD [edi], xmm6 ; Save Y movdqa XMMWORD [edi], xmm6 ; Save Y
sub ecx, byte SIZEOF_XMMWORD sub ecx, byte SIZEOF_XMMWORD
add esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr add esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
add edi, byte SIZEOF_XMMWORD ; outptr0 add edi, byte SIZEOF_XMMWORD ; outptr0
cmp ecx, byte SIZEOF_XMMWORD cmp ecx, byte SIZEOF_XMMWORD
jae near .columnloop jae near .columnloop
test ecx,ecx test ecx,ecx
jnz near .column_ld1 jnz near .column_ld1
pop ecx ; col pop ecx ; col
pop esi pop esi
pop edi pop edi
poppic eax poppic eax
add esi, byte SIZEOF_JSAMPROW ; input_buf add esi, byte SIZEOF_JSAMPROW ; input_buf
add edi, byte SIZEOF_JSAMPROW add edi, byte SIZEOF_JSAMPROW
dec eax ; num_rows dec eax ; num_rows
jg near .rowloop jg near .rowloop
.return: .return:
pop edi pop edi
pop esi pop esi
; pop edx ; need not be preserved ; pop edx ; need not be preserved
; pop ecx ; need not be preserved ; pop ecx ; need not be preserved
pop ebx pop ebx
mov esp,ebp ; esp <- aligned ebp mov esp,ebp ; esp <- aligned ebp
pop esp ; esp <- original ebp pop esp ; esp <- original ebp
pop ebp pop ebp
ret ret
; For some reason, the OS X linker does not honor the request to align the ; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this. ; segment unless we do this.
align 16 align 16

View File

@@ -20,8 +20,8 @@
%include "jdct.inc" %include "jdct.inc"
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 32 BITS 32
; ;
; Load data into workspace, applying unsigned->signed conversion ; Load data into workspace, applying unsigned->signed conversion
; ;
@@ -30,98 +30,98 @@
; FAST_FLOAT * workspace); ; FAST_FLOAT * workspace);
; ;
%define sample_data ebp+8 ; JSAMPARRAY sample_data %define sample_data ebp+8 ; JSAMPARRAY sample_data
%define start_col ebp+12 ; JDIMENSION start_col %define start_col ebp+12 ; JDIMENSION start_col
%define workspace ebp+16 ; FAST_FLOAT * workspace %define workspace ebp+16 ; FAST_FLOAT * workspace
align 16 align 16
global EXTN(jsimd_convsamp_float_3dnow) global EXTN(jsimd_convsamp_float_3dnow)
EXTN(jsimd_convsamp_float_3dnow): EXTN(jsimd_convsamp_float_3dnow):
push ebp push ebp
mov ebp,esp mov ebp,esp
push ebx push ebx
; push ecx ; need not be preserved ; push ecx ; need not be preserved
; push edx ; need not be preserved ; push edx ; need not be preserved
push esi push esi
push edi push edi
pcmpeqw mm7,mm7 pcmpeqw mm7,mm7
psllw mm7,7 psllw mm7,7
packsswb mm7,mm7 ; mm7 = PB_CENTERJSAMPLE (0x808080..) packsswb mm7,mm7 ; mm7 = PB_CENTERJSAMPLE (0x808080..)
mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *) mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *)
mov eax, JDIMENSION [start_col] mov eax, JDIMENSION [start_col]
mov edi, POINTER [workspace] ; (DCTELEM *) mov edi, POINTER [workspace] ; (DCTELEM *)
mov ecx, DCTSIZE/2 mov ecx, DCTSIZE/2
alignx 16,7 alignx 16,7
.convloop: .convloop:
mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *)
mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *)
movq mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE] movq mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE]
movq mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE] movq mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE]
psubb mm0,mm7 ; mm0=(01234567) psubb mm0,mm7 ; mm0=(01234567)
psubb mm1,mm7 ; mm1=(89ABCDEF) psubb mm1,mm7 ; mm1=(89ABCDEF)
punpcklbw mm2,mm0 ; mm2=(*0*1*2*3) punpcklbw mm2,mm0 ; mm2=(*0*1*2*3)
punpckhbw mm0,mm0 ; mm0=(*4*5*6*7) punpckhbw mm0,mm0 ; mm0=(*4*5*6*7)
punpcklbw mm3,mm1 ; mm3=(*8*9*A*B) punpcklbw mm3,mm1 ; mm3=(*8*9*A*B)
punpckhbw mm1,mm1 ; mm1=(*C*D*E*F) punpckhbw mm1,mm1 ; mm1=(*C*D*E*F)
punpcklwd mm4,mm2 ; mm4=(***0***1) punpcklwd mm4,mm2 ; mm4=(***0***1)
punpckhwd mm2,mm2 ; mm2=(***2***3) punpckhwd mm2,mm2 ; mm2=(***2***3)
punpcklwd mm5,mm0 ; mm5=(***4***5) punpcklwd mm5,mm0 ; mm5=(***4***5)
punpckhwd mm0,mm0 ; mm0=(***6***7) punpckhwd mm0,mm0 ; mm0=(***6***7)
psrad mm4,(DWORD_BIT-BYTE_BIT) ; mm4=(01) psrad mm4,(DWORD_BIT-BYTE_BIT) ; mm4=(01)
psrad mm2,(DWORD_BIT-BYTE_BIT) ; mm2=(23) psrad mm2,(DWORD_BIT-BYTE_BIT) ; mm2=(23)
pi2fd mm4,mm4 pi2fd mm4,mm4
pi2fd mm2,mm2 pi2fd mm2,mm2
psrad mm5,(DWORD_BIT-BYTE_BIT) ; mm5=(45) psrad mm5,(DWORD_BIT-BYTE_BIT) ; mm5=(45)
psrad mm0,(DWORD_BIT-BYTE_BIT) ; mm0=(67) psrad mm0,(DWORD_BIT-BYTE_BIT) ; mm0=(67)
pi2fd mm5,mm5 pi2fd mm5,mm5
pi2fd mm0,mm0 pi2fd mm0,mm0
movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], mm4 movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], mm4
movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], mm2 movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], mm2
movq MMWORD [MMBLOCK(0,2,edi,SIZEOF_FAST_FLOAT)], mm5 movq MMWORD [MMBLOCK(0,2,edi,SIZEOF_FAST_FLOAT)], mm5
movq MMWORD [MMBLOCK(0,3,edi,SIZEOF_FAST_FLOAT)], mm0 movq MMWORD [MMBLOCK(0,3,edi,SIZEOF_FAST_FLOAT)], mm0
punpcklwd mm6,mm3 ; mm6=(***8***9) punpcklwd mm6,mm3 ; mm6=(***8***9)
punpckhwd mm3,mm3 ; mm3=(***A***B) punpckhwd mm3,mm3 ; mm3=(***A***B)
punpcklwd mm4,mm1 ; mm4=(***C***D) punpcklwd mm4,mm1 ; mm4=(***C***D)
punpckhwd mm1,mm1 ; mm1=(***E***F) punpckhwd mm1,mm1 ; mm1=(***E***F)
psrad mm6,(DWORD_BIT-BYTE_BIT) ; mm6=(89) psrad mm6,(DWORD_BIT-BYTE_BIT) ; mm6=(89)
psrad mm3,(DWORD_BIT-BYTE_BIT) ; mm3=(AB) psrad mm3,(DWORD_BIT-BYTE_BIT) ; mm3=(AB)
pi2fd mm6,mm6 pi2fd mm6,mm6
pi2fd mm3,mm3 pi2fd mm3,mm3
psrad mm4,(DWORD_BIT-BYTE_BIT) ; mm4=(CD) psrad mm4,(DWORD_BIT-BYTE_BIT) ; mm4=(CD)
psrad mm1,(DWORD_BIT-BYTE_BIT) ; mm1=(EF) psrad mm1,(DWORD_BIT-BYTE_BIT) ; mm1=(EF)
pi2fd mm4,mm4 pi2fd mm4,mm4
pi2fd mm1,mm1 pi2fd mm1,mm1
movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], mm6 movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], mm6
movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], mm3 movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], mm3
movq MMWORD [MMBLOCK(1,2,edi,SIZEOF_FAST_FLOAT)], mm4 movq MMWORD [MMBLOCK(1,2,edi,SIZEOF_FAST_FLOAT)], mm4
movq MMWORD [MMBLOCK(1,3,edi,SIZEOF_FAST_FLOAT)], mm1 movq MMWORD [MMBLOCK(1,3,edi,SIZEOF_FAST_FLOAT)], mm1
add esi, byte 2*SIZEOF_JSAMPROW add esi, byte 2*SIZEOF_JSAMPROW
add edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT add edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
dec ecx dec ecx
jnz near .convloop jnz near .convloop
femms ; empty MMX/3DNow! state femms ; empty MMX/3DNow! state
pop edi pop edi
pop esi pop esi
; pop edx ; need not be preserved ; pop edx ; need not be preserved
; pop ecx ; need not be preserved ; pop ecx ; need not be preserved
pop ebx pop ebx
pop ebp pop ebp
ret ret
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
@@ -133,101 +133,101 @@ EXTN(jsimd_convsamp_float_3dnow):
; FAST_FLOAT * workspace); ; FAST_FLOAT * workspace);
; ;
%define coef_block ebp+8 ; JCOEFPTR coef_block %define coef_block ebp+8 ; JCOEFPTR coef_block
%define divisors ebp+12 ; FAST_FLOAT * divisors %define divisors ebp+12 ; FAST_FLOAT * divisors
%define workspace ebp+16 ; FAST_FLOAT * workspace %define workspace ebp+16 ; FAST_FLOAT * workspace
align 16 align 16
global EXTN(jsimd_quantize_float_3dnow) global EXTN(jsimd_quantize_float_3dnow)
EXTN(jsimd_quantize_float_3dnow): EXTN(jsimd_quantize_float_3dnow):
push ebp push ebp
mov ebp,esp mov ebp,esp
; push ebx ; unused ; push ebx ; unused
; push ecx ; unused ; push ecx ; unused
; push edx ; need not be preserved ; push edx ; need not be preserved
push esi push esi
push edi push edi
mov eax, 0x4B400000 ; (float)0x00C00000 (rndint_magic) mov eax, 0x4B400000 ; (float)0x00C00000 (rndint_magic)
movd mm7,eax movd mm7,eax
punpckldq mm7,mm7 ; mm7={12582912.0F 12582912.0F} punpckldq mm7,mm7 ; mm7={12582912.0F 12582912.0F}
mov esi, POINTER [workspace] mov esi, POINTER [workspace]
mov edx, POINTER [divisors] mov edx, POINTER [divisors]
mov edi, JCOEFPTR [coef_block] mov edi, JCOEFPTR [coef_block]
mov eax, DCTSIZE2/16 mov eax, DCTSIZE2/16
alignx 16,7 alignx 16,7
.quantloop: .quantloop:
movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)] movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)]
movq mm1, MMWORD [MMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)] movq mm1, MMWORD [MMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)]
pfmul mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)] pfmul mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
pfmul mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)] pfmul mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)]
movq mm2, MMWORD [MMBLOCK(0,2,esi,SIZEOF_FAST_FLOAT)] movq mm2, MMWORD [MMBLOCK(0,2,esi,SIZEOF_FAST_FLOAT)]
movq mm3, MMWORD [MMBLOCK(0,3,esi,SIZEOF_FAST_FLOAT)] movq mm3, MMWORD [MMBLOCK(0,3,esi,SIZEOF_FAST_FLOAT)]
pfmul mm2, MMWORD [MMBLOCK(0,2,edx,SIZEOF_FAST_FLOAT)] pfmul mm2, MMWORD [MMBLOCK(0,2,edx,SIZEOF_FAST_FLOAT)]
pfmul mm3, MMWORD [MMBLOCK(0,3,edx,SIZEOF_FAST_FLOAT)] pfmul mm3, MMWORD [MMBLOCK(0,3,edx,SIZEOF_FAST_FLOAT)]
pfadd mm0,mm7 ; mm0=(00 ** 01 **) pfadd mm0,mm7 ; mm0=(00 ** 01 **)
pfadd mm1,mm7 ; mm1=(02 ** 03 **) pfadd mm1,mm7 ; mm1=(02 ** 03 **)
pfadd mm2,mm7 ; mm0=(04 ** 05 **) pfadd mm2,mm7 ; mm0=(04 ** 05 **)
pfadd mm3,mm7 ; mm1=(06 ** 07 **) pfadd mm3,mm7 ; mm1=(06 ** 07 **)
movq mm4,mm0 movq mm4,mm0
punpcklwd mm0,mm1 ; mm0=(00 02 ** **) punpcklwd mm0,mm1 ; mm0=(00 02 ** **)
punpckhwd mm4,mm1 ; mm4=(01 03 ** **) punpckhwd mm4,mm1 ; mm4=(01 03 ** **)
movq mm5,mm2 movq mm5,mm2
punpcklwd mm2,mm3 ; mm2=(04 06 ** **) punpcklwd mm2,mm3 ; mm2=(04 06 ** **)
punpckhwd mm5,mm3 ; mm5=(05 07 ** **) punpckhwd mm5,mm3 ; mm5=(05 07 ** **)
punpcklwd mm0,mm4 ; mm0=(00 01 02 03) punpcklwd mm0,mm4 ; mm0=(00 01 02 03)
punpcklwd mm2,mm5 ; mm2=(04 05 06 07) punpcklwd mm2,mm5 ; mm2=(04 05 06 07)
movq mm6, MMWORD [MMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)] movq mm6, MMWORD [MMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)]
movq mm1, MMWORD [MMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)] movq mm1, MMWORD [MMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)]
pfmul mm6, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)] pfmul mm6, MMWORD [MMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
pfmul mm1, MMWORD [MMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)] pfmul mm1, MMWORD [MMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)]
movq mm3, MMWORD [MMBLOCK(1,2,esi,SIZEOF_FAST_FLOAT)] movq mm3, MMWORD [MMBLOCK(1,2,esi,SIZEOF_FAST_FLOAT)]
movq mm4, MMWORD [MMBLOCK(1,3,esi,SIZEOF_FAST_FLOAT)] movq mm4, MMWORD [MMBLOCK(1,3,esi,SIZEOF_FAST_FLOAT)]
pfmul mm3, MMWORD [MMBLOCK(1,2,edx,SIZEOF_FAST_FLOAT)] pfmul mm3, MMWORD [MMBLOCK(1,2,edx,SIZEOF_FAST_FLOAT)]
pfmul mm4, MMWORD [MMBLOCK(1,3,edx,SIZEOF_FAST_FLOAT)] pfmul mm4, MMWORD [MMBLOCK(1,3,edx,SIZEOF_FAST_FLOAT)]
pfadd mm6,mm7 ; mm0=(10 ** 11 **) pfadd mm6,mm7 ; mm0=(10 ** 11 **)
pfadd mm1,mm7 ; mm4=(12 ** 13 **) pfadd mm1,mm7 ; mm4=(12 ** 13 **)
pfadd mm3,mm7 ; mm0=(14 ** 15 **) pfadd mm3,mm7 ; mm0=(14 ** 15 **)
pfadd mm4,mm7 ; mm4=(16 ** 17 **) pfadd mm4,mm7 ; mm4=(16 ** 17 **)
movq mm5,mm6 movq mm5,mm6
punpcklwd mm6,mm1 ; mm6=(10 12 ** **) punpcklwd mm6,mm1 ; mm6=(10 12 ** **)
punpckhwd mm5,mm1 ; mm5=(11 13 ** **) punpckhwd mm5,mm1 ; mm5=(11 13 ** **)
movq mm1,mm3 movq mm1,mm3
punpcklwd mm3,mm4 ; mm3=(14 16 ** **) punpcklwd mm3,mm4 ; mm3=(14 16 ** **)
punpckhwd mm1,mm4 ; mm1=(15 17 ** **) punpckhwd mm1,mm4 ; mm1=(15 17 ** **)
punpcklwd mm6,mm5 ; mm6=(10 11 12 13) punpcklwd mm6,mm5 ; mm6=(10 11 12 13)
punpcklwd mm3,mm1 ; mm3=(14 15 16 17) punpcklwd mm3,mm1 ; mm3=(14 15 16 17)
movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0 movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0
movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm2 movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm2
movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm6 movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm6
movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm3 movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm3
add esi, byte 16*SIZEOF_FAST_FLOAT add esi, byte 16*SIZEOF_FAST_FLOAT
add edx, byte 16*SIZEOF_FAST_FLOAT add edx, byte 16*SIZEOF_FAST_FLOAT
add edi, byte 16*SIZEOF_JCOEF add edi, byte 16*SIZEOF_JCOEF
dec eax dec eax
jnz near .quantloop jnz near .quantloop
femms ; empty MMX/3DNow! state femms ; empty MMX/3DNow! state
pop edi pop edi
pop esi pop esi
; pop edx ; need not be preserved ; pop edx ; need not be preserved
; pop ecx ; unused ; pop ecx ; unused
; pop ebx ; unused ; pop ebx ; unused
pop ebp pop ebp
ret ret
; For some reason, the OS X linker does not honor the request to align the ; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this. ; segment unless we do this.
align 16 align 16

View File

@@ -20,8 +20,8 @@
%include "jdct.inc" %include "jdct.inc"
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 32 BITS 32
; ;
; Load data into workspace, applying unsigned->signed conversion ; Load data into workspace, applying unsigned->signed conversion
; ;
@@ -30,92 +30,92 @@
; DCTELEM * workspace); ; DCTELEM * workspace);
; ;
%define sample_data ebp+8 ; JSAMPARRAY sample_data %define sample_data ebp+8 ; JSAMPARRAY sample_data
%define start_col ebp+12 ; JDIMENSION start_col %define start_col ebp+12 ; JDIMENSION start_col
%define workspace ebp+16 ; DCTELEM * workspace %define workspace ebp+16 ; DCTELEM * workspace
align 16 align 16
global EXTN(jsimd_convsamp_mmx) global EXTN(jsimd_convsamp_mmx)
EXTN(jsimd_convsamp_mmx): EXTN(jsimd_convsamp_mmx):
push ebp push ebp
mov ebp,esp mov ebp,esp
push ebx push ebx
; push ecx ; need not be preserved ; push ecx ; need not be preserved
; push edx ; need not be preserved ; push edx ; need not be preserved
push esi push esi
push edi push edi
pxor mm6,mm6 ; mm6=(all 0's) pxor mm6,mm6 ; mm6=(all 0's)
pcmpeqw mm7,mm7 pcmpeqw mm7,mm7
psllw mm7,7 ; mm7={0xFF80 0xFF80 0xFF80 0xFF80} psllw mm7,7 ; mm7={0xFF80 0xFF80 0xFF80 0xFF80}
mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *) mov esi, JSAMPARRAY [sample_data] ; (JSAMPROW *)
mov eax, JDIMENSION [start_col] mov eax, JDIMENSION [start_col]
mov edi, POINTER [workspace] ; (DCTELEM *) mov edi, POINTER [workspace] ; (DCTELEM *)
mov ecx, DCTSIZE/4 mov ecx, DCTSIZE/4
alignx 16,7 alignx 16,7
.convloop: .convloop:
mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) mov ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *)
mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) mov edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *)
movq mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE] ; mm0=(01234567) movq mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE] ; mm0=(01234567)
movq mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE] ; mm1=(89ABCDEF) movq mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE] ; mm1=(89ABCDEF)
mov ebx, JSAMPROW [esi+2*SIZEOF_JSAMPROW] ; (JSAMPLE *) mov ebx, JSAMPROW [esi+2*SIZEOF_JSAMPROW] ; (JSAMPLE *)
mov edx, JSAMPROW [esi+3*SIZEOF_JSAMPROW] ; (JSAMPLE *) mov edx, JSAMPROW [esi+3*SIZEOF_JSAMPROW] ; (JSAMPLE *)
movq mm2, MMWORD [ebx+eax*SIZEOF_JSAMPLE] ; mm2=(GHIJKLMN) movq mm2, MMWORD [ebx+eax*SIZEOF_JSAMPLE] ; mm2=(GHIJKLMN)
movq mm3, MMWORD [edx+eax*SIZEOF_JSAMPLE] ; mm3=(OPQRSTUV) movq mm3, MMWORD [edx+eax*SIZEOF_JSAMPLE] ; mm3=(OPQRSTUV)
movq mm4,mm0 movq mm4,mm0
punpcklbw mm0,mm6 ; mm0=(0123) punpcklbw mm0,mm6 ; mm0=(0123)
punpckhbw mm4,mm6 ; mm4=(4567) punpckhbw mm4,mm6 ; mm4=(4567)
movq mm5,mm1 movq mm5,mm1
punpcklbw mm1,mm6 ; mm1=(89AB) punpcklbw mm1,mm6 ; mm1=(89AB)
punpckhbw mm5,mm6 ; mm5=(CDEF) punpckhbw mm5,mm6 ; mm5=(CDEF)
paddw mm0,mm7 paddw mm0,mm7
paddw mm4,mm7 paddw mm4,mm7
paddw mm1,mm7 paddw mm1,mm7
paddw mm5,mm7 paddw mm5,mm7
movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_DCTELEM)], mm0 movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_DCTELEM)], mm0
movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_DCTELEM)], mm4 movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_DCTELEM)], mm4
movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_DCTELEM)], mm1 movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_DCTELEM)], mm1
movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_DCTELEM)], mm5 movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_DCTELEM)], mm5
movq mm0,mm2 movq mm0,mm2
punpcklbw mm2,mm6 ; mm2=(GHIJ) punpcklbw mm2,mm6 ; mm2=(GHIJ)
punpckhbw mm0,mm6 ; mm0=(KLMN) punpckhbw mm0,mm6 ; mm0=(KLMN)
movq mm4,mm3 movq mm4,mm3
punpcklbw mm3,mm6 ; mm3=(OPQR) punpcklbw mm3,mm6 ; mm3=(OPQR)
punpckhbw mm4,mm6 ; mm4=(STUV) punpckhbw mm4,mm6 ; mm4=(STUV)
paddw mm2,mm7 paddw mm2,mm7
paddw mm0,mm7 paddw mm0,mm7
paddw mm3,mm7 paddw mm3,mm7
paddw mm4,mm7 paddw mm4,mm7
movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_DCTELEM)], mm2 movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_DCTELEM)], mm2
movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_DCTELEM)], mm0 movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_DCTELEM)], mm0
movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_DCTELEM)], mm3 movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_DCTELEM)], mm3
movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_DCTELEM)], mm4 movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_DCTELEM)], mm4
add esi, byte 4*SIZEOF_JSAMPROW add esi, byte 4*SIZEOF_JSAMPROW
add edi, byte 4*DCTSIZE*SIZEOF_DCTELEM add edi, byte 4*DCTSIZE*SIZEOF_DCTELEM
dec ecx dec ecx
jnz short .convloop jnz short .convloop
emms ; empty MMX state emms ; empty MMX state
pop edi pop edi
pop esi pop esi
; pop edx ; need not be preserved ; pop edx ; need not be preserved
; pop ecx ; need not be preserved ; pop ecx ; need not be preserved
pop ebx pop ebx
pop ebp pop ebp
ret ret
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
; ;
@@ -135,140 +135,140 @@ EXTN(jsimd_convsamp_mmx):
%define SCALE(m,n,b) MMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM) %define SCALE(m,n,b) MMBLOCK(DCTSIZE*2+(m),(n),(b),SIZEOF_DCTELEM)
%define SHIFT(m,n,b) MMBLOCK(DCTSIZE*3+(m),(n),(b),SIZEOF_DCTELEM) %define SHIFT(m,n,b) MMBLOCK(DCTSIZE*3+(m),(n),(b),SIZEOF_DCTELEM)
%define coef_block ebp+8 ; JCOEFPTR coef_block %define coef_block ebp+8 ; JCOEFPTR coef_block
%define divisors ebp+12 ; DCTELEM * divisors %define divisors ebp+12 ; DCTELEM * divisors
%define workspace ebp+16 ; DCTELEM * workspace %define workspace ebp+16 ; DCTELEM * workspace
align 16 align 16
global EXTN(jsimd_quantize_mmx) global EXTN(jsimd_quantize_mmx)
EXTN(jsimd_quantize_mmx): EXTN(jsimd_quantize_mmx):
push ebp push ebp
mov ebp,esp mov ebp,esp
; push ebx ; unused ; push ebx ; unused
; push ecx ; unused ; push ecx ; unused
; push edx ; need not be preserved ; push edx ; need not be preserved
push esi push esi
push edi push edi
mov esi, POINTER [workspace] mov esi, POINTER [workspace]
mov edx, POINTER [divisors] mov edx, POINTER [divisors]
mov edi, JCOEFPTR [coef_block] mov edi, JCOEFPTR [coef_block]
mov ah, 2 mov ah, 2
alignx 16,7 alignx 16,7
.quantloop1: .quantloop1:
mov al, DCTSIZE2/8/2 mov al, DCTSIZE2/8/2
alignx 16,7 alignx 16,7
.quantloop2: .quantloop2:
movq mm2, MMWORD [MMBLOCK(0,0,esi,SIZEOF_DCTELEM)] movq mm2, MMWORD [MMBLOCK(0,0,esi,SIZEOF_DCTELEM)]
movq mm3, MMWORD [MMBLOCK(0,1,esi,SIZEOF_DCTELEM)] movq mm3, MMWORD [MMBLOCK(0,1,esi,SIZEOF_DCTELEM)]
movq mm0,mm2 movq mm0,mm2
movq mm1,mm3 movq mm1,mm3
psraw mm2,(WORD_BIT-1) ; -1 if value < 0, 0 otherwise psraw mm2,(WORD_BIT-1) ; -1 if value < 0, 0 otherwise
psraw mm3,(WORD_BIT-1) psraw mm3,(WORD_BIT-1)
pxor mm0,mm2 ; val = -val pxor mm0,mm2 ; val = -val
pxor mm1,mm3 pxor mm1,mm3
psubw mm0,mm2 psubw mm0,mm2
psubw mm1,mm3 psubw mm1,mm3
; ;
; MMX is an annoyingly crappy instruction set. It has two ; MMX is an annoyingly crappy instruction set. It has two
; misfeatures that are causing problems here: ; misfeatures that are causing problems here:
; ;
; - All multiplications are signed. ; - All multiplications are signed.
; ;
; - The second operand for the shifts is not treated as packed. ; - The second operand for the shifts is not treated as packed.
; ;
; ;
; We work around the first problem by implementing this algorithm: ; We work around the first problem by implementing this algorithm:
; ;
; unsigned long unsigned_multiply(unsigned short x, unsigned short y) ; unsigned long unsigned_multiply(unsigned short x, unsigned short y)
; { ; {
; enum { SHORT_BIT = 16 }; ; enum { SHORT_BIT = 16 };
; signed short sx = (signed short) x; ; signed short sx = (signed short) x;
; signed short sy = (signed short) y; ; signed short sy = (signed short) y;
; signed long sz; ; signed long sz;
; ;
; sz = (long) sx * (long) sy; /* signed multiply */ ; sz = (long) sx * (long) sy; /* signed multiply */
; ;
; if (sx < 0) sz += (long) sy << SHORT_BIT; ; if (sx < 0) sz += (long) sy << SHORT_BIT;
; if (sy < 0) sz += (long) sx << SHORT_BIT; ; if (sy < 0) sz += (long) sx << SHORT_BIT;
; ;
; return (unsigned long) sz; ; return (unsigned long) sz;
; } ; }
; ;
; (note that a negative sx adds _sy_ and vice versa) ; (note that a negative sx adds _sy_ and vice versa)
; ;
; For the second problem, we replace the shift by a multiplication. ; For the second problem, we replace the shift by a multiplication.
; Unfortunately that means we have to deal with the signed issue again. ; Unfortunately that means we have to deal with the signed issue again.
; ;
paddw mm0, MMWORD [CORRECTION(0,0,edx)] ; correction + roundfactor paddw mm0, MMWORD [CORRECTION(0,0,edx)] ; correction + roundfactor
paddw mm1, MMWORD [CORRECTION(0,1,edx)] paddw mm1, MMWORD [CORRECTION(0,1,edx)]
movq mm4,mm0 ; store current value for later movq mm4,mm0 ; store current value for later
movq mm5,mm1 movq mm5,mm1
pmulhw mm0, MMWORD [RECIPROCAL(0,0,edx)] ; reciprocal pmulhw mm0, MMWORD [RECIPROCAL(0,0,edx)] ; reciprocal
pmulhw mm1, MMWORD [RECIPROCAL(0,1,edx)] pmulhw mm1, MMWORD [RECIPROCAL(0,1,edx)]
paddw mm0,mm4 ; reciprocal is always negative (MSB=1), paddw mm0,mm4 ; reciprocal is always negative (MSB=1),
paddw mm1,mm5 ; so we always need to add the initial value paddw mm1,mm5 ; so we always need to add the initial value
; (input value is never negative as we ; (input value is never negative as we
; inverted it at the start of this routine) ; inverted it at the start of this routine)
; here it gets a bit tricky as both scale ; here it gets a bit tricky as both scale
; and mm0/mm1 can be negative ; and mm0/mm1 can be negative
movq mm6, MMWORD [SCALE(0,0,edx)] ; scale movq mm6, MMWORD [SCALE(0,0,edx)] ; scale
movq mm7, MMWORD [SCALE(0,1,edx)] movq mm7, MMWORD [SCALE(0,1,edx)]
movq mm4,mm0 movq mm4,mm0
movq mm5,mm1 movq mm5,mm1
pmulhw mm0,mm6 pmulhw mm0,mm6
pmulhw mm1,mm7 pmulhw mm1,mm7
psraw mm6,(WORD_BIT-1) ; determine if scale is negative psraw mm6,(WORD_BIT-1) ; determine if scale is negative
psraw mm7,(WORD_BIT-1) psraw mm7,(WORD_BIT-1)
pand mm6,mm4 ; and add input if it is pand mm6,mm4 ; and add input if it is
pand mm7,mm5 pand mm7,mm5
paddw mm0,mm6 paddw mm0,mm6
paddw mm1,mm7 paddw mm1,mm7
psraw mm4,(WORD_BIT-1) ; then check if negative input psraw mm4,(WORD_BIT-1) ; then check if negative input
psraw mm5,(WORD_BIT-1) psraw mm5,(WORD_BIT-1)
pand mm4, MMWORD [SCALE(0,0,edx)] ; and add scale if it is pand mm4, MMWORD [SCALE(0,0,edx)] ; and add scale if it is
pand mm5, MMWORD [SCALE(0,1,edx)] pand mm5, MMWORD [SCALE(0,1,edx)]
paddw mm0,mm4 paddw mm0,mm4
paddw mm1,mm5 paddw mm1,mm5
pxor mm0,mm2 ; val = -val pxor mm0,mm2 ; val = -val
pxor mm1,mm3 pxor mm1,mm3
psubw mm0,mm2 psubw mm0,mm2
psubw mm1,mm3 psubw mm1,mm3
movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_DCTELEM)], mm0 movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_DCTELEM)], mm0
movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_DCTELEM)], mm1 movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_DCTELEM)], mm1
add esi, byte 8*SIZEOF_DCTELEM add esi, byte 8*SIZEOF_DCTELEM
add edx, byte 8*SIZEOF_DCTELEM add edx, byte 8*SIZEOF_DCTELEM
add edi, byte 8*SIZEOF_JCOEF add edi, byte 8*SIZEOF_JCOEF
dec al dec al
jnz near .quantloop2 jnz near .quantloop2
dec ah dec ah
jnz near .quantloop1 ; to avoid branch misprediction jnz near .quantloop1 ; to avoid branch misprediction
emms ; empty MMX state emms ; empty MMX state
pop edi pop edi
pop esi pop esi
; pop edx ; need not be preserved ; pop edx ; need not be preserved
; pop ecx ; unused ; pop ecx ; unused
; pop ebx ; unused ; pop ebx ; unused
pop ebp pop ebp
ret ret
; For some reason, the OS X linker does not honor the request to align the ; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this. ; segment unless we do this.
align 16 align 16

View File

@@ -21,8 +21,8 @@
%include "jdct.inc" %include "jdct.inc"
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
SECTION SEG_TEXT SECTION SEG_TEXT
BITS 64 BITS 64
; ;
; Load data into workspace, applying unsigned->signed conversion ; Load data into workspace, applying unsigned->signed conversion
; ;
@@ -35,65 +35,65 @@
; r11 = JDIMENSION start_col ; r11 = JDIMENSION start_col
; r12 = FAST_FLOAT * workspace ; r12 = FAST_FLOAT * workspace
align 16 align 16
global EXTN(jsimd_convsamp_float_sse2) global EXTN(jsimd_convsamp_float_sse2)
EXTN(jsimd_convsamp_float_sse2): EXTN(jsimd_convsamp_float_sse2):
push rbp push rbp
mov rax,rsp mov rax,rsp
mov rbp,rsp mov rbp,rsp
collect_args collect_args
push rbx push rbx
pcmpeqw xmm7,xmm7 pcmpeqw xmm7,xmm7
psllw xmm7,7 psllw xmm7,7
packsswb xmm7,xmm7 ; xmm7 = PB_CENTERJSAMPLE (0x808080..) packsswb xmm7,xmm7 ; xmm7 = PB_CENTERJSAMPLE (0x808080..)
mov rsi, r10 mov rsi, r10
mov rax, r11 mov rax, r11
mov rdi, r12 mov rdi, r12
mov rcx, DCTSIZE/2 mov rcx, DCTSIZE/2
.convloop: .convloop:
mov rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *) mov rbx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; (JSAMPLE *)
mov rdx, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *) mov rdx, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; (JSAMPLE *)
movq xmm0, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE] movq xmm0, XMM_MMWORD [rbx+rax*SIZEOF_JSAMPLE]
movq xmm1, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE] movq xmm1, XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE]
psubb xmm0,xmm7 ; xmm0=(01234567) psubb xmm0,xmm7 ; xmm0=(01234567)
psubb xmm1,xmm7 ; xmm1=(89ABCDEF) psubb xmm1,xmm7 ; xmm1=(89ABCDEF)
punpcklbw xmm0,xmm0 ; xmm0=(*0*1*2*3*4*5*6*7) punpcklbw xmm0,xmm0 ; xmm0=(*0*1*2*3*4*5*6*7)
punpcklbw xmm1,xmm1 ; xmm1=(*8*9*A*B*C*D*E*F) punpcklbw xmm1,xmm1 ; xmm1=(*8*9*A*B*C*D*E*F)
punpcklwd xmm2,xmm0 ; xmm2=(***0***1***2***3) punpcklwd xmm2,xmm0 ; xmm2=(***0***1***2***3)
punpckhwd xmm0,xmm0 ; xmm0=(***4***5***6***7) punpckhwd xmm0,xmm0 ; xmm0=(***4***5***6***7)
punpcklwd xmm3,xmm1 ; xmm3=(***8***9***A***B) punpcklwd xmm3,xmm1 ; xmm3=(***8***9***A***B)
punpckhwd xmm1,xmm1 ; xmm1=(***C***D***E***F) punpckhwd xmm1,xmm1 ; xmm1=(***C***D***E***F)
psrad xmm2,(DWORD_BIT-BYTE_BIT) ; xmm2=(0123) psrad xmm2,(DWORD_BIT-BYTE_BIT) ; xmm2=(0123)
psrad xmm0,(DWORD_BIT-BYTE_BIT) ; xmm0=(4567) psrad xmm0,(DWORD_BIT-BYTE_BIT) ; xmm0=(4567)
cvtdq2ps xmm2,xmm2 ; xmm2=(0123) cvtdq2ps xmm2,xmm2 ; xmm2=(0123)
cvtdq2ps xmm0,xmm0 ; xmm0=(4567) cvtdq2ps xmm0,xmm0 ; xmm0=(4567)
psrad xmm3,(DWORD_BIT-BYTE_BIT) ; xmm3=(89AB) psrad xmm3,(DWORD_BIT-BYTE_BIT) ; xmm3=(89AB)
psrad xmm1,(DWORD_BIT-BYTE_BIT) ; xmm1=(CDEF) psrad xmm1,(DWORD_BIT-BYTE_BIT) ; xmm1=(CDEF)
cvtdq2ps xmm3,xmm3 ; xmm3=(89AB) cvtdq2ps xmm3,xmm3 ; xmm3=(89AB)
cvtdq2ps xmm1,xmm1 ; xmm1=(CDEF) cvtdq2ps xmm1,xmm1 ; xmm1=(CDEF)
movaps XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm2 movaps XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_FAST_FLOAT)], xmm2
movaps XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm0 movaps XMMWORD [XMMBLOCK(0,1,rdi,SIZEOF_FAST_FLOAT)], xmm0
movaps XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm3 movaps XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_FAST_FLOAT)], xmm3
movaps XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm1 movaps XMMWORD [XMMBLOCK(1,1,rdi,SIZEOF_FAST_FLOAT)], xmm1
add rsi, byte 2*SIZEOF_JSAMPROW add rsi, byte 2*SIZEOF_JSAMPROW
add rdi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT add rdi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
dec rcx dec rcx
jnz short .convloop jnz short .convloop
pop rbx pop rbx
uncollect_args uncollect_args
pop rbp pop rbp
ret ret
; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------
@@ -109,50 +109,50 @@ EXTN(jsimd_convsamp_float_sse2):
; r11 = FAST_FLOAT * divisors ; r11 = FAST_FLOAT * divisors
; r12 = FAST_FLOAT * workspace ; r12 = FAST_FLOAT * workspace
align 16 align 16
global EXTN(jsimd_quantize_float_sse2) global EXTN(jsimd_quantize_float_sse2)
EXTN(jsimd_quantize_float_sse2): EXTN(jsimd_quantize_float_sse2):
push rbp push rbp
mov rax,rsp mov rax,rsp
mov rbp,rsp mov rbp,rsp
collect_args collect_args
mov rsi, r12 mov rsi, r12
mov rdx, r11 mov rdx, r11
mov rdi, r10 mov rdi, r10
mov rax, DCTSIZE2/16 mov rax, DCTSIZE2/16
.quantloop: .quantloop:
movaps xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_FAST_FLOAT)] movaps xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm1, XMMWORD [XMMBLOCK(0,1,rsi,SIZEOF_FAST_FLOAT)] movaps xmm1, XMMWORD [XMMBLOCK(0,1,rsi,SIZEOF_FAST_FLOAT)]
mulps xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)] mulps xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_FAST_FLOAT)]
mulps xmm1, XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)] mulps xmm1, XMMWORD [XMMBLOCK(0,1,rdx,SIZEOF_FAST_FLOAT)]
movaps xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_FAST_FLOAT)] movaps xmm2, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_FAST_FLOAT)]
movaps xmm3, XMMWORD [XMMBLOCK(1,1,rsi,SIZEOF_FAST_FLOAT)] movaps xmm3, XMMWORD [XMMBLOCK(1,1,rsi,SIZEOF_FAST_FLOAT)]
mulps xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)] mulps xmm2, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_FAST_FLOAT)]
mulps xmm3, XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)] mulps xmm3, XMMWORD [XMMBLOCK(1,1,rdx,SIZEOF_FAST_FLOAT)]
cvtps2dq xmm0,xmm0 cvtps2dq xmm0,xmm0
cvtps2dq xmm1,xmm1 cvtps2dq xmm1,xmm1
cvtps2dq xmm2,xmm2 cvtps2dq xmm2,xmm2
cvtps2dq xmm3,xmm3 cvtps2dq xmm3,xmm3
packssdw xmm0,xmm1 packssdw xmm0,xmm1
packssdw xmm2,xmm3 packssdw xmm2,xmm3
movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_JCOEF)], xmm0 movdqa XMMWORD [XMMBLOCK(0,0,rdi,SIZEOF_JCOEF)], xmm0
movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_JCOEF)], xmm2 movdqa XMMWORD [XMMBLOCK(1,0,rdi,SIZEOF_JCOEF)], xmm2
add rsi, byte 16*SIZEOF_FAST_FLOAT add rsi, byte 16*SIZEOF_FAST_FLOAT
add rdx, byte 16*SIZEOF_FAST_FLOAT add rdx, byte 16*SIZEOF_FAST_FLOAT
add rdi, byte 16*SIZEOF_JCOEF add rdi, byte 16*SIZEOF_JCOEF
dec rax dec rax
jnz short .quantloop jnz short .quantloop
uncollect_args uncollect_args
pop rbp pop rbp
ret ret
; For some reason, the OS X linker does not honor the request to align the ; For some reason, the OS X linker does not honor the request to align the
; segment unless we do this. ; segment unless we do this.
align 16 align 16

Some files were not shown because too many files have changed in this diff Show More