3 Copyright (c) 2002-2003, Marcin 'Shard' Konicki
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
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.
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.
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
40 #include "be_jerror.h"
51 // JPEGTtanslator settings header to get settings stuff
52 #include "JPEGTranslator.h"
53 #include "TranslatorSettings.h"
55 #undef B_TRANSLATION_CONTEXT
56 #define B_TRANSLATION_CONTEXT "be_jerror"
58 // Since Translator doesn't use it's own error table, we can use error_mgr's
59 // variables to store some usefull data.
60 // last_addon_message (as ShowReadWarnings) is used for storing SETTINGS->ShowReadWarningBox value
61 #define ShowReadWarnings last_addon_message
65 * Error exit handler: must not return to caller.
68 be_error_exit (j_common_ptr cinfo
)
70 char buffer
[JMSG_LENGTH_MAX
];
72 /* Create the message */
73 (*cinfo
->err
->format_message
) (cinfo
, buffer
);
75 fprintf(stderr
, B_TRANSLATE("JPEG Library Error: %s\n"), buffer
);
77 be_jpeg_error_mgr
* errorManager
78 = static_cast<be_jpeg_error_mgr
*>(cinfo
->err
);
79 jmp_buf longJumpBuffer
;
80 memcpy(&longJumpBuffer
, errorManager
->long_jump_buffer
, sizeof(jmp_buf));
82 /* Let the memory manager delete any temp files before we die */
85 // jump back directly to the high level function's "breakpoint"
86 longjmp(longJumpBuffer
, 0);
91 * Actual output of an error or trace message.
94 be_output_message (j_common_ptr cinfo
)
96 char buffer
[JMSG_LENGTH_MAX
];
98 /* Create the message */
99 (*cinfo
->err
->format_message
) (cinfo
, buffer
);
101 cinfo
->err
->num_warnings
++;
103 /* If it's compressing or decompressing and user turned messages on */
104 if (!cinfo
->is_decompressor
|| cinfo
->err
->ShowReadWarnings
) {
105 /* show warning message */
106 fprintf(stderr
, B_TRANSLATE("JPEG Library Warning: %s\n"), buffer
);
112 * Fill in the standard error-handling methods in a jpeg_error_mgr object.
113 * Since Translator doesn't use it's own error table, we can use error_mgr's
114 * variables to store some useful data.
115 * last_addon_message (as ShowReadWarnings) is used for storing SETTINGS->ShowReadWarningBox value
118 GLOBAL(struct jpeg_error_mgr
*)
119 be_jpeg_std_error(be_jpeg_error_mgr
* err
, TranslatorSettings
* settings
,
120 const jmp_buf* longJumpBuffer
)
125 err
->error_exit
= be_error_exit
;
126 err
->output_message
= be_output_message
;
128 err
->ShowReadWarnings
= settings
->SetGetBool(JPEG_SET_SHOWREADWARNING
, NULL
);
129 err
->long_jump_buffer
= longJumpBuffer
;