mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
50bc583645
--HG-- rename : media/libjpeg/config.h => media/libjpeg/jconfigint.h rename : media/libjpeg/simd/jcclrmmx.asm => media/libjpeg/simd/jccolext-mmx.asm rename : media/libjpeg/simd/jcclrss2-64.asm => media/libjpeg/simd/jccolext-sse2-64.asm rename : media/libjpeg/simd/jcclrss2.asm => media/libjpeg/simd/jccolext-sse2.asm rename : media/libjpeg/simd/jccolmmx.asm => media/libjpeg/simd/jccolor-mmx.asm rename : media/libjpeg/simd/jccolss2-64.asm => media/libjpeg/simd/jccolor-sse2-64.asm rename : media/libjpeg/simd/jccolss2.asm => media/libjpeg/simd/jccolor-sse2.asm rename : media/libjpeg/simd/jcgrammx.asm => media/libjpeg/simd/jcgray-mmx.asm rename : media/libjpeg/simd/jcgrass2-64.asm => media/libjpeg/simd/jcgray-sse2-64.asm rename : media/libjpeg/simd/jcgrass2.asm => media/libjpeg/simd/jcgray-sse2.asm rename : media/libjpeg/simd/jcgrymmx.asm => media/libjpeg/simd/jcgryext-mmx.asm rename : media/libjpeg/simd/jcgryss2-64.asm => media/libjpeg/simd/jcgryext-sse2-64.asm rename : media/libjpeg/simd/jcgryss2.asm => media/libjpeg/simd/jcgryext-sse2.asm rename : media/libjpeg/simd/jcsammmx.asm => media/libjpeg/simd/jcsample-mmx.asm rename : media/libjpeg/simd/jcsamss2-64.asm => media/libjpeg/simd/jcsample-sse2-64.asm rename : media/libjpeg/simd/jcsamss2.asm => media/libjpeg/simd/jcsample-sse2.asm rename : media/libjpeg/simd/jdclrmmx.asm => media/libjpeg/simd/jdcolext-mmx.asm rename : media/libjpeg/simd/jdclrss2-64.asm => media/libjpeg/simd/jdcolext-sse2-64.asm rename : media/libjpeg/simd/jdclrss2.asm => media/libjpeg/simd/jdcolext-sse2.asm rename : media/libjpeg/simd/jdcolmmx.asm => media/libjpeg/simd/jdcolor-mmx.asm rename : media/libjpeg/simd/jdcolss2-64.asm => media/libjpeg/simd/jdcolor-sse2-64.asm rename : media/libjpeg/simd/jdcolss2.asm => media/libjpeg/simd/jdcolor-sse2.asm rename : media/libjpeg/simd/jdmermmx.asm => media/libjpeg/simd/jdmerge-mmx.asm rename : media/libjpeg/simd/jdmerss2-64.asm => media/libjpeg/simd/jdmerge-sse2-64.asm rename : media/libjpeg/simd/jdmerss2.asm => media/libjpeg/simd/jdmerge-sse2.asm rename : media/libjpeg/simd/jdmrgmmx.asm => media/libjpeg/simd/jdmrgext-mmx.asm rename : media/libjpeg/simd/jdmrgss2-64.asm => media/libjpeg/simd/jdmrgext-sse2-64.asm rename : media/libjpeg/simd/jdmrgss2.asm => media/libjpeg/simd/jdmrgext-sse2.asm rename : media/libjpeg/simd/jdsammmx.asm => media/libjpeg/simd/jdsample-mmx.asm rename : media/libjpeg/simd/jdsamss2-64.asm => media/libjpeg/simd/jdsample-sse2-64.asm rename : media/libjpeg/simd/jdsamss2.asm => media/libjpeg/simd/jdsample-sse2.asm rename : media/libjpeg/simd/jf3dnflt.asm => media/libjpeg/simd/jfdctflt-3dn.asm rename : media/libjpeg/simd/jfsseflt-64.asm => media/libjpeg/simd/jfdctflt-sse-64.asm rename : media/libjpeg/simd/jfsseflt.asm => media/libjpeg/simd/jfdctflt-sse.asm rename : media/libjpeg/simd/jfmmxfst.asm => media/libjpeg/simd/jfdctfst-mmx.asm rename : media/libjpeg/simd/jfss2fst-64.asm => media/libjpeg/simd/jfdctfst-sse2-64.asm rename : media/libjpeg/simd/jfss2fst.asm => media/libjpeg/simd/jfdctfst-sse2.asm rename : media/libjpeg/simd/jfmmxint.asm => media/libjpeg/simd/jfdctint-mmx.asm rename : media/libjpeg/simd/jfss2int-64.asm => media/libjpeg/simd/jfdctint-sse2-64.asm rename : media/libjpeg/simd/jfss2int.asm => media/libjpeg/simd/jfdctint-sse2.asm rename : media/libjpeg/simd/ji3dnflt.asm => media/libjpeg/simd/jidctflt-3dn.asm rename : media/libjpeg/simd/jisseflt.asm => media/libjpeg/simd/jidctflt-sse.asm rename : media/libjpeg/simd/jiss2flt-64.asm => media/libjpeg/simd/jidctflt-sse2-64.asm rename : media/libjpeg/simd/jiss2flt.asm => media/libjpeg/simd/jidctflt-sse2.asm rename : media/libjpeg/simd/jimmxfst.asm => media/libjpeg/simd/jidctfst-mmx.asm rename : media/libjpeg/simd/jiss2fst-64.asm => media/libjpeg/simd/jidctfst-sse2-64.asm rename : media/libjpeg/simd/jiss2fst.asm => media/libjpeg/simd/jidctfst-sse2.asm rename : media/libjpeg/simd/jimmxint.asm => media/libjpeg/simd/jidctint-mmx.asm rename : media/libjpeg/simd/jiss2int-64.asm => media/libjpeg/simd/jidctint-sse2-64.asm rename : media/libjpeg/simd/jiss2int.asm => media/libjpeg/simd/jidctint-sse2.asm rename : media/libjpeg/simd/jimmxred.asm => media/libjpeg/simd/jidctred-mmx.asm rename : media/libjpeg/simd/jiss2red-64.asm => media/libjpeg/simd/jidctred-sse2-64.asm rename : media/libjpeg/simd/jiss2red.asm => media/libjpeg/simd/jidctred-sse2.asm rename : media/libjpeg/simd/jcqnt3dn.asm => media/libjpeg/simd/jquant-3dn.asm rename : media/libjpeg/simd/jcqntmmx.asm => media/libjpeg/simd/jquant-mmx.asm rename : media/libjpeg/simd/jcqntsse.asm => media/libjpeg/simd/jquant-sse.asm rename : media/libjpeg/simd/jcqnts2f-64.asm => media/libjpeg/simd/jquantf-sse2-64.asm rename : media/libjpeg/simd/jcqnts2f.asm => media/libjpeg/simd/jquantf-sse2.asm rename : media/libjpeg/simd/jcqnts2i-64.asm => media/libjpeg/simd/jquanti-sse2-64.asm rename : media/libjpeg/simd/jcqnts2i.asm => media/libjpeg/simd/jquanti-sse2.asm
251 lines
7.7 KiB
C
251 lines
7.7 KiB
C
/*
|
|
* jerror.c
|
|
*
|
|
* This file was part of the Independent JPEG Group's software:
|
|
* Copyright (C) 1991-1998, Thomas G. Lane.
|
|
* It was modified by The libjpeg-turbo Project to include only code relevant
|
|
* to libjpeg-turbo.
|
|
* For conditions of distribution and use, see the accompanying README file.
|
|
*
|
|
* This file contains simple error-reporting and trace-message routines.
|
|
* These are suitable for Unix-like systems and others where writing to
|
|
* stderr is the right thing to do. Many applications will want to replace
|
|
* some or all of these routines.
|
|
*
|
|
* If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile,
|
|
* you get a Windows-specific hack to display error messages in a dialog box.
|
|
* It ain't much, but it beats dropping error messages into the bit bucket,
|
|
* which is what happens to output to stderr under most Windows C compilers.
|
|
*
|
|
* These routines are used by both the compression and decompression code.
|
|
*/
|
|
|
|
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
|
|
#include "jinclude.h"
|
|
#include "jpeglib.h"
|
|
#include "jversion.h"
|
|
#include "jerror.h"
|
|
|
|
#ifdef USE_WINDOWS_MESSAGEBOX
|
|
#include <windows.h>
|
|
#endif
|
|
|
|
#ifndef EXIT_FAILURE /* define exit() codes if not provided */
|
|
#define EXIT_FAILURE 1
|
|
#endif
|
|
|
|
|
|
/*
|
|
* Create the message string table.
|
|
* We do this from the master message list in jerror.h by re-reading
|
|
* jerror.h with a suitable definition for macro JMESSAGE.
|
|
* The message table is made an external symbol just in case any applications
|
|
* want to refer to it directly.
|
|
*/
|
|
|
|
#define JMESSAGE(code,string) string ,
|
|
|
|
const char * const jpeg_std_message_table[] = {
|
|
#include "jerror.h"
|
|
NULL
|
|
};
|
|
|
|
|
|
/*
|
|
* Error exit handler: must not return to caller.
|
|
*
|
|
* Applications may override this if they want to get control back after
|
|
* an error. Typically one would longjmp somewhere instead of exiting.
|
|
* The setjmp buffer can be made a private field within an expanded error
|
|
* handler object. Note that the info needed to generate an error message
|
|
* is stored in the error object, so you can generate the message now or
|
|
* later, at your convenience.
|
|
* You should make sure that the JPEG object is cleaned up (with jpeg_abort
|
|
* or jpeg_destroy) at some point.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
error_exit (j_common_ptr cinfo)
|
|
{
|
|
/* Always display the message */
|
|
(*cinfo->err->output_message) (cinfo);
|
|
|
|
/* Let the memory manager delete any temp files before we die */
|
|
jpeg_destroy(cinfo);
|
|
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
|
|
/*
|
|
* Actual output of an error or trace message.
|
|
* Applications may override this method to send JPEG messages somewhere
|
|
* other than stderr.
|
|
*
|
|
* On Windows, printing to stderr is generally completely useless,
|
|
* so we provide optional code to produce an error-dialog popup.
|
|
* Most Windows applications will still prefer to override this routine,
|
|
* but if they don't, it'll do something at least marginally useful.
|
|
*
|
|
* NOTE: to use the library in an environment that doesn't support the
|
|
* C stdio library, you may have to delete the call to fprintf() entirely,
|
|
* not just not use this routine.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
output_message (j_common_ptr cinfo)
|
|
{
|
|
char buffer[JMSG_LENGTH_MAX];
|
|
|
|
/* Create the message */
|
|
(*cinfo->err->format_message) (cinfo, buffer);
|
|
|
|
#ifdef USE_WINDOWS_MESSAGEBOX
|
|
/* Display it in a message dialog box */
|
|
MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
|
|
MB_OK | MB_ICONERROR);
|
|
#else
|
|
/* Send it to stderr, adding a newline */
|
|
fprintf(stderr, "%s\n", buffer);
|
|
#endif
|
|
}
|
|
|
|
|
|
/*
|
|
* Decide whether to emit a trace or warning message.
|
|
* msg_level is one of:
|
|
* -1: recoverable corrupt-data warning, may want to abort.
|
|
* 0: important advisory messages (always display to user).
|
|
* 1: first level of tracing detail.
|
|
* 2,3,...: successively more detailed tracing messages.
|
|
* An application might override this method if it wanted to abort on warnings
|
|
* or change the policy about which messages to display.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
emit_message (j_common_ptr cinfo, int msg_level)
|
|
{
|
|
struct jpeg_error_mgr * err = cinfo->err;
|
|
|
|
if (msg_level < 0) {
|
|
/* It's a warning message. Since corrupt files may generate many warnings,
|
|
* the policy implemented here is to show only the first warning,
|
|
* unless trace_level >= 3.
|
|
*/
|
|
if (err->num_warnings == 0 || err->trace_level >= 3)
|
|
(*err->output_message) (cinfo);
|
|
/* Always count warnings in num_warnings. */
|
|
err->num_warnings++;
|
|
} else {
|
|
/* It's a trace message. Show it if trace_level >= msg_level. */
|
|
if (err->trace_level >= msg_level)
|
|
(*err->output_message) (cinfo);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Format a message string for the most recent JPEG error or message.
|
|
* The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
|
|
* characters. Note that no '\n' character is added to the string.
|
|
* Few applications should need to override this method.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
format_message (j_common_ptr cinfo, char * buffer)
|
|
{
|
|
struct jpeg_error_mgr * err = cinfo->err;
|
|
int msg_code = err->msg_code;
|
|
const char * msgtext = NULL;
|
|
const char * msgptr;
|
|
char ch;
|
|
boolean isstring;
|
|
|
|
/* Look up message string in proper table */
|
|
if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
|
|
msgtext = err->jpeg_message_table[msg_code];
|
|
} else if (err->addon_message_table != NULL &&
|
|
msg_code >= err->first_addon_message &&
|
|
msg_code <= err->last_addon_message) {
|
|
msgtext = err->addon_message_table[msg_code - err->first_addon_message];
|
|
}
|
|
|
|
/* Defend against bogus message number */
|
|
if (msgtext == NULL) {
|
|
err->msg_parm.i[0] = msg_code;
|
|
msgtext = err->jpeg_message_table[0];
|
|
}
|
|
|
|
/* Check for string parameter, as indicated by %s in the message text */
|
|
isstring = FALSE;
|
|
msgptr = msgtext;
|
|
while ((ch = *msgptr++) != '\0') {
|
|
if (ch == '%') {
|
|
if (*msgptr == 's') isstring = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Format the message into the passed buffer */
|
|
if (isstring)
|
|
sprintf(buffer, msgtext, err->msg_parm.s);
|
|
else
|
|
sprintf(buffer, msgtext,
|
|
err->msg_parm.i[0], err->msg_parm.i[1],
|
|
err->msg_parm.i[2], err->msg_parm.i[3],
|
|
err->msg_parm.i[4], err->msg_parm.i[5],
|
|
err->msg_parm.i[6], err->msg_parm.i[7]);
|
|
}
|
|
|
|
|
|
/*
|
|
* Reset error state variables at start of a new image.
|
|
* This is called during compression startup to reset trace/error
|
|
* processing to default state, without losing any application-specific
|
|
* method pointers. An application might possibly want to override
|
|
* this method if it has additional error processing state.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
reset_error_mgr (j_common_ptr cinfo)
|
|
{
|
|
cinfo->err->num_warnings = 0;
|
|
/* 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" */
|
|
}
|
|
|
|
|
|
/*
|
|
* Fill in the standard error-handling methods in a jpeg_error_mgr object.
|
|
* Typical call is:
|
|
* struct jpeg_compress_struct cinfo;
|
|
* struct jpeg_error_mgr err;
|
|
*
|
|
* cinfo.err = jpeg_std_error(&err);
|
|
* after which the application may override some of the methods.
|
|
*/
|
|
|
|
GLOBAL(struct jpeg_error_mgr *)
|
|
jpeg_std_error (struct jpeg_error_mgr * err)
|
|
{
|
|
err->error_exit = error_exit;
|
|
err->emit_message = emit_message;
|
|
err->output_message = output_message;
|
|
err->format_message = format_message;
|
|
err->reset_error_mgr = reset_error_mgr;
|
|
|
|
err->trace_level = 0; /* default = no tracing */
|
|
err->num_warnings = 0; /* no warnings emitted yet */
|
|
err->msg_code = 0; /* may be useful as a flag for "no error" */
|
|
|
|
/* Initialize message table pointers */
|
|
err->jpeg_message_table = jpeg_std_message_table;
|
|
err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
|
|
|
|
err->addon_message_table = NULL;
|
|
err->first_addon_message = 0; /* for safety */
|
|
err->last_addon_message = 0;
|
|
|
|
return err;
|
|
}
|