1 /* 2 3 Copyright (c) 2002-2003, Marcin 'Shard' Konicki 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 9 * Redistributions of source code must retain the above copyright notice, 10 this list of conditions and the following disclaimer. 11 * Redistributions in binary form must reproduce the above copyright notice, 12 this list of conditions and the following disclaimer in the documentation and/or 13 other materials provided with the distribution. 14 * Name "Marcin Konicki", "Shard" or any combination of them, 15 must not be used to endorse or promote products derived from this 16 software without specific prior written permission from Marcin Konicki. 17 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 23 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 */ 31 32 33 /* 34 Modified jerror.c from libjpeg 35 to make it possible to turn on/off error dialog-box 36 only two functions modified, rest is used from original error handling code 37 */ 38 39 40 // Be headers 41 #include <Alert.h> 42 #include <stdio.h> 43 44 // JPEG headers 45 #include <jpeglib.h> 46 #include <jconfig.h> 47 #include <jerror.h> 48 49 // JPEGTtanslator settings header to get SETTINGS struct 50 #include "JPEGTranslator.h" 51 52 53 // Since Translator doesn't use it's own error table, we can use error_mgr's 54 // variables to store some usefull data. 55 // last_addon_message (as ShowReadWarnings) is used for storing SETTINGS->ShowReadWarningBox value 56 #define ShowReadWarnings last_addon_message 57 58 59 /* 60 * Error exit handler: must not return to caller. 61 */ 62 GLOBAL(void) 63 be_error_exit (j_common_ptr cinfo) 64 { 65 char buffer[JMSG_LENGTH_MAX]; 66 67 /* Create the message */ 68 (*cinfo->err->format_message) (cinfo, buffer); 69 70 fprintf(stderr, "JPEG Library Error: %s\n", buffer); 71 72 jmp_buf longJumpBuffer; 73 memcpy(&longJumpBuffer, &(cinfo->err->long_jump_buffer), sizeof(jmp_buf)); 74 75 /* Let the memory manager delete any temp files before we die */ 76 jpeg_destroy(cinfo); 77 78 // jump back directly to the high level function's "breakpoint" 79 longjmp(longJumpBuffer, 0); 80 } 81 82 83 /* 84 * Actual output of an error or trace message. 85 */ 86 GLOBAL(void) 87 be_output_message (j_common_ptr cinfo) 88 { 89 char buffer[JMSG_LENGTH_MAX]; 90 91 /* Create the message */ 92 (*cinfo->err->format_message) (cinfo, buffer); 93 94 cinfo->err->num_warnings++; 95 96 /* If it's compressing or decompressing and user turned messages on */ 97 if (!cinfo->is_decompressor || cinfo->err->ShowReadWarnings) { 98 /* show warning message */ 99 fprintf(stderr, "JPEG Library Warning: %s\n", buffer); 100 } 101 } 102 103 104 /* 105 * Fill in the standard error-handling methods in a jpeg_error_mgr object. 106 * Since Translator doesn't use it's own error table, we can use error_mgr's 107 * variables to store some usefull data. 108 * last_addon_message (as ShowReadWarnings) is used for storing SETTINGS->ShowReadWarningBox value 109 */ 110 111 GLOBAL(struct jpeg_error_mgr *) 112 be_jpeg_std_error (struct jpeg_error_mgr * err, jpeg_settings *settings, 113 const jmp_buf* longJumpBuffer) 114 { 115 jpeg_std_error(err); 116 117 err->error_exit = be_error_exit; 118 err->output_message = be_output_message; 119 120 err->ShowReadWarnings = settings->ShowReadWarningBox; 121 memcpy(&(err->long_jump_buffer), longJumpBuffer, sizeof(jmp_buf)); 122 123 return err; 124 } 125