xref: /haiku/src/add-ons/translators/jpeg/be_jerror.cpp (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
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 #if 0
71 	/* show error message */
72 	(new BAlert("JPEG Library Error", buffer, "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
73 #endif
74 
75 	/* Let the memory manager delete any temp files before we die */
76 	jpeg_destroy(cinfo);
77 
78 	exit(B_ERROR);
79 }
80 
81 
82 /*
83  * Actual output of an error or trace message.
84  */
85 GLOBAL(void)
86 be_output_message (j_common_ptr cinfo)
87 {
88 	char buffer[JMSG_LENGTH_MAX];
89 
90 	/* Create the message */
91 	(*cinfo->err->format_message) (cinfo, buffer);
92 
93 #if 0
94 	/* If it's compressing or decompressing and user turned messages on */
95 	if (!cinfo->is_decompressor || cinfo->err->ShowReadWarnings)
96 		/* show warning message */
97 		(new BAlert("JPEG Library Warning", buffer, "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
98 #endif
99 }
100 
101 
102 /*
103  * Fill in the standard error-handling methods in a jpeg_error_mgr object.
104  * Since Translator doesn't use it's own error table, we can use error_mgr's
105  * variables to store some usefull data.
106  * last_addon_message (as ShowReadWarnings) is used for storing SETTINGS->ShowReadWarningBox value
107  */
108 
109 GLOBAL(struct jpeg_error_mgr *)
110 be_jpeg_std_error (struct jpeg_error_mgr * err, jpeg_settings *settings)
111 {
112 	jpeg_std_error(err);
113 
114 	err->error_exit = be_error_exit;
115 	err->output_message = be_output_message;
116 
117 	err->ShowReadWarnings = settings->ShowReadWarningBox;
118 
119 	return err;
120 }
121