// 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. static void emit_message(jpeg_common cinfo, int msg_level) { 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); // Create the message and Send it to Debug Console, adding a newline //Debug.WriteLine(cinfo.err.format_message(cinfo)); } } }
public static void ERREXIT2(jpeg_common cinfo, J_MESSAGE_CODE code, int p1, int p2) { cinfo.err.msg_parm[0] = p1; cinfo.err.msg_parm[1] = p2; cinfo.err.msg_code = (int)code; cinfo.err.error_exit(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. static string format_message(jpeg_common cinfo) { jpeg_error_mgr err = cinfo.err; int msg_code = err.msg_code; string msgtext = null; // 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[0] = msg_code; msgtext = err.jpeg_message_table[0]; } // Format the message into the passed buffer return(string.Format(msgtext, err.msg_parm)); }
public static void WARNMS2(jpeg_common cinfo, J_MESSAGE_CODE code, int p1, int p2) { cinfo.err.msg_parm[0] = p1; cinfo.err.msg_parm[1] = p2; cinfo.err.msg_code = (int)code; cinfo.err.emit_message(cinfo, -1); }
static void TRACEMS2(jpeg_common cinfo, int lvl, J_MESSAGE_CODE code, int p1, int p2) { cinfo.err.msg_parm[0] = p1; cinfo.err.msg_parm[1] = p2; cinfo.err.msg_code = (int)code; cinfo.err.emit_message(cinfo, lvl); }
// 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. // Most Windows applications will still prefer to override this routine, // but if they don't, it'll do something at least marginally useful. static void output_message(jpeg_common cinfo) { // Create the message string buffer = cinfo.err.format_message(cinfo); // Send it to stderr, adding a newline Console.Error.WriteLine(buffer); }
public static void ERREXIT3(jpeg_common cinfo, J_MESSAGE_CODE code, int p1, int p2, int p3) { object[] _mp = cinfo.err.msg_parm; _mp[0] = p1; _mp[1] = p2; _mp[2] = p3; cinfo.err.msg_code = (int)code; cinfo.err.error_exit(cinfo); }
static void TRACEMS3(jpeg_common cinfo, int lvl, J_MESSAGE_CODE code, int p1, int p2, int p3) { object[] _mp = cinfo.err.msg_parm; _mp[0] = p1; _mp[1] = p2; _mp[2] = p3; cinfo.err.msg_code = (int)code; cinfo.err.emit_message(cinfo, lvl); }
// 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 throw a more specific exception than Exception(). // 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. static void error_exit(jpeg_common cinfo) { // Always display the message cinfo.err.output_message(cinfo); // Let the memory manager delete any temp files before we die jpeg_destroy(cinfo); throw new Exception(); }
static void TRACEMS8(jpeg_common cinfo, int lvl, J_MESSAGE_CODE code, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { object[] _mp = cinfo.err.msg_parm; _mp[0] = p1; _mp[1] = p2; _mp[2] = p3; _mp[3] = p4; _mp[4] = p5; _mp[5] = p6; _mp[6] = p7; _mp[7] = p8; cinfo.err.msg_code = (int)code; cinfo.err.emit_message(cinfo, lvl); }
// Creation of 2-D difference arrays. // This is essentially the same as the code for sample arrays, above. // Allocate a 2-D difference array public static int[][] alloc_darray(jpeg_common cinfo, uint diffsperrow, uint numrows) { int[][] result=null; try { // Get space for row pointers result=new int[numrows][]; // Get the rows themselves uint currow=0; while(currow<numrows) result[currow++]=new int[diffsperrow]; } catch { ERREXIT1(cinfo, J_MESSAGE_CODE.JERR_OUT_OF_MEMORY, 4); } return result; }
// Creation of 2-D coefficient-block arrays. // This is essentially the same as the code for sample arrays, above. // Allocate a 2-D coefficient-block array public static short[][][] alloc_barray(jpeg_common cinfo, uint blocksperrow, uint numrows) { // Get space for row pointers short[][][] result=null; try { result=new short[numrows][][]; // Get the rows themselves for(uint currow=0; currow<numrows; currow++) { result[currow]=new short[blocksperrow][]; for(uint curblockinrow=0; curblockinrow<blocksperrow; curblockinrow++) result[currow][curblockinrow]=new short[DCTSIZE2]; } } catch { ERREXIT1(cinfo, J_MESSAGE_CODE.JERR_OUT_OF_MEMORY, 4); } return result; }
// Creation of 2-D difference arrays. // This is essentially the same as the code for sample arrays, above. // Allocate a 2-D difference array public static int[][] alloc_darray(jpeg_common cinfo, uint diffsperrow, uint numrows) { int[][] result = null; try { // Get space for row pointers result = new int[numrows][]; // Get the rows themselves uint currow = 0; while (currow < numrows) { result[currow++] = new int[diffsperrow]; } } catch { ERREXIT1(cinfo, J_MESSAGE_CODE.JERR_OUT_OF_MEMORY, 4); } return(result); }
// Creation of 2-D coefficient-block arrays. // This is essentially the same as the code for sample arrays, above. // Allocate a 2-D coefficient-block array public static short[][][] alloc_barray(jpeg_common cinfo, uint blocksperrow, uint numrows) { // Get space for row pointers short[][][] result = null; try { result = new short[numrows][][]; // Get the rows themselves for (uint currow = 0; currow < numrows; currow++) { result[currow] = new short[blocksperrow][]; for (uint curblockinrow = 0; curblockinrow < blocksperrow; curblockinrow++) { result[currow][curblockinrow] = new short[DCTSIZE2]; } } } catch { ERREXIT1(cinfo, J_MESSAGE_CODE.JERR_OUT_OF_MEMORY, 4); } return(result); }
// 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. static void reset_error_mgr(jpeg_common 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" }
// 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. static void emit_message(jpeg_common cinfo, int msg_level) { 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); // Create the message and Send it to Debug Console, adding a newline //Debug.WriteLine(cinfo.err.format_message(cinfo)); } } }
public static void ERREXIT4(jpeg_common cinfo, J_MESSAGE_CODE code, int p1, int p2, int p3, int p4) { object[] _mp=cinfo.err.msg_parm; _mp[0]=p1; _mp[1]=p2; _mp[2]=p3; _mp[3]=p4; cinfo.err.msg_code=(int)code; cinfo.err.error_exit(cinfo); }
public static void ERREXITS(jpeg_common cinfo, J_MESSAGE_CODE code, string str) { cinfo.err.msg_code = (int)code; cinfo.err.msg_parm[0] = str; cinfo.err.error_exit(cinfo); }
// 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. // Most Windows applications will still prefer to override this routine, // but if they don't, it'll do something at least marginally useful. static void output_message(jpeg_common cinfo) { // Create the message string buffer=cinfo.err.format_message(cinfo); // Send it to stderr, adding a newline Console.Error.WriteLine(buffer); }
public static void ERREXIT1(jpeg_common cinfo, J_MESSAGE_CODE code, STATE p1) { cinfo.err.msg_parm[0]=(int)p1; cinfo.err.msg_code=(int)code; cinfo.err.error_exit(cinfo); }
static void TRACEMS2(jpeg_common cinfo, int lvl, J_MESSAGE_CODE code, int p1, int p2) { cinfo.err.msg_parm[0]=p1; cinfo.err.msg_parm[1]=p2; cinfo.err.msg_code=(int)code; cinfo.err.emit_message(cinfo, lvl); }
// Informational/debugging messages #region TRACEMS, TRACEMS1, .. TRACEMSS static void TRACEMS(jpeg_common cinfo, int lvl, J_MESSAGE_CODE code) { cinfo.err.msg_code=(int)code; cinfo.err.emit_message(cinfo, lvl); }
public static void WARNMS2(jpeg_common cinfo, J_MESSAGE_CODE code, int p1, int p2) { cinfo.err.msg_parm[0]=p1; cinfo.err.msg_parm[1]=p2; cinfo.err.msg_code=(int)code; cinfo.err.emit_message(cinfo, -1); }
// Nonfatal errors (we can keep going, but the data is probably corrupt) #region WARNMS, WARNMS1, WARNMS2 public static void WARNMS(jpeg_common cinfo, J_MESSAGE_CODE code) { cinfo.err.msg_code=(int)code; cinfo.err.emit_message(cinfo, -1); }
public static void ERREXITS(jpeg_common cinfo, J_MESSAGE_CODE code, string str) { cinfo.err.msg_code=(int)code; cinfo.err.msg_parm[0]=str; cinfo.err.error_exit(cinfo); }
// Functions to simplify using the error and trace message stuff // Fatal errors (print message and exit) #region ERREXIT, ERREXIT1, .. ERREXITS public static void ERREXIT(jpeg_common cinfo, J_MESSAGE_CODE code) { cinfo.err.msg_code = (int)code; cinfo.err.error_exit(cinfo); }
public static void ERREXIT1(jpeg_common cinfo, J_MESSAGE_CODE code, STATE p1) { cinfo.err.msg_parm[0] = (int)p1; cinfo.err.msg_code = (int)code; cinfo.err.error_exit(cinfo); }
// This routine is invoked only for warning messages, // since error_exit does its own thing and trace_level // is never set > 0. static void TIFFjpeg_output_message(jpeg_common cinfo) { JPEGState sp=(JPEGState)cinfo.client_data; string buffer=cinfo.err.format_message(cinfo); TIFFWarningExt(sp.tif.tif_clientdata, "JPEGLib", buffer); }
// Functions to simplify using the error and trace message stuff // Fatal errors (print message and exit) #region ERREXIT, ERREXIT1, .. ERREXITS public static void ERREXIT(jpeg_common cinfo, J_MESSAGE_CODE code) { cinfo.err.msg_code=(int)code; cinfo.err.error_exit(cinfo); }
// Nonfatal errors (we can keep going, but the data is probably corrupt) #region WARNMS, WARNMS1, WARNMS2 public static void WARNMS(jpeg_common cinfo, J_MESSAGE_CODE code) { cinfo.err.msg_code = (int)code; cinfo.err.emit_message(cinfo, -1); }
// 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. static void reset_error_mgr(jpeg_common 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" }
// Informational/debugging messages #region TRACEMS, TRACEMS1, .. TRACEMSS static void TRACEMS(jpeg_common cinfo, int lvl, J_MESSAGE_CODE code) { cinfo.err.msg_code = (int)code; cinfo.err.emit_message(cinfo, lvl); }
// 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. static string format_message(jpeg_common cinfo) { jpeg_error_mgr err=cinfo.err; int msg_code=err.msg_code; string msgtext=null; // 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[0]=msg_code; msgtext=err.jpeg_message_table[0]; } // Format the message into the passed buffer return string.Format(msgtext, err.msg_parm); }
static void TRACEMS4(jpeg_common cinfo, int lvl, J_MESSAGE_CODE code, int p1, int p2, int p3, int p4) { object[] _mp=cinfo.err.msg_parm; _mp[0]=p1; _mp[1]=p2; _mp[2]=p3; _mp[3]=p4; cinfo.err.msg_code=(int)code; cinfo.err.emit_message(cinfo, lvl); }
public static void ERREXIT2(jpeg_common cinfo, J_MESSAGE_CODE code, int p1, int p2) { cinfo.err.msg_parm[0]=p1; cinfo.err.msg_parm[1]=p2; cinfo.err.msg_code=(int)code; cinfo.err.error_exit(cinfo); }
static void TRACEMSS(jpeg_common cinfo, int lvl, J_MESSAGE_CODE code, string str) { cinfo.err.msg_code = (int)code; cinfo.err.msg_parm[0] = str; cinfo.err.emit_message(cinfo, lvl); }
static void TRACEMS8(jpeg_common cinfo, int lvl, J_MESSAGE_CODE code, int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { object[] _mp=cinfo.err.msg_parm; _mp[0]=p1; _mp[1]=p2; _mp[2]=p3; _mp[3]=p4; _mp[4]=p5; _mp[5]=p6; _mp[6]=p7; _mp[7]=p8; cinfo.err.msg_code=(int)code; cinfo.err.emit_message(cinfo, lvl); }
static void TRACEMSS(jpeg_common cinfo, int lvl, J_MESSAGE_CODE code, string str) { cinfo.err.msg_code=(int)code; cinfo.err.msg_parm[0]=str; cinfo.err.emit_message(cinfo, lvl); }
// libjpeg interface layer. // // We use exceptions to return control to libtiff // when a fatal error is encountered within the JPEG // library. We also direct libjpeg error and warning // messages through the appropriate libtiff handlers. // Error handling routines (these replace corresponding // IJG routines from jerror.cs). These are used for both // compression and decompression. static void TIFFjpeg_error_exit(jpeg_common cinfo) { JPEGState sp=(JPEGState)cinfo.client_data; string buffer=cinfo.err.format_message(cinfo); TIFFErrorExt(sp.tif.tif_clientdata, "JPEGLib", buffer); // display the error message libjpeg.jpeg_abort(cinfo); // clean up libjpeg state throw new Exception("jpeg_error_exit"); // return to libtiff caller }