| 1 |
/*****************************************************************************/ |
| 2 |
// Copyright 2006-2019 Adobe Systems Incorporated |
| 3 |
// All Rights Reserved. |
| 4 |
// |
| 5 |
// NOTICE: Adobe permits you to use, modify, and distribute this file in |
| 6 |
// accordance with the terms of the Adobe license agreement accompanying it. |
| 7 |
/*****************************************************************************/ |
| 8 |
|
| 9 |
#include "dng_exceptions.h" |
| 10 |
|
| 11 |
#include "dng_flags.h" |
| 12 |
#include "dng_globals.h" |
| 13 |
|
| 14 |
/*****************************************************************************/ |
| 15 |
|
| 16 |
#ifndef qDNGReportErrors |
| 17 |
// assuming this isn't enable on Win, because it's using printf, but an app can redirect that to console |
| 18 |
#define qDNGReportErrors ((qDNGDebug && qMacOS) || qDNGValidate) |
| 19 |
#endif |
| 20 |
|
| 21 |
/*****************************************************************************/ |
| 22 |
|
| 23 |
void ReportWarning (const char *message, |
| 24 |
const char *sub_message) |
| 25 |
{ |
| 26 |
|
| 27 |
#if qDNGReportErrors |
| 28 |
|
| 29 |
#ifdef cr_logw |
| 30 |
|
| 31 |
cr_logs("report", 2, NULL, 0, cr_logfunc(), "%s %s\n", message, sub_message ? sub_message : ""); |
| 32 |
|
| 33 |
#else |
| 34 |
|
| 35 |
if (sub_message) |
| 36 |
fprintf (stderr, "*** Warning: %s (%s) ***\n", message, sub_message); |
| 37 |
else |
| 38 |
fprintf (stderr, "*** Warning: %s ***\n", message); |
| 39 |
|
| 40 |
#endif |
| 41 |
|
| 42 |
#else |
| 43 |
|
| 44 |
(void) message; |
| 45 |
(void) sub_message; |
| 46 |
|
| 47 |
#endif |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
/*****************************************************************************/ |
| 52 |
|
| 53 |
void ReportError (const char *message, |
| 54 |
const char *sub_message) |
| 55 |
{ |
| 56 |
|
| 57 |
#if qDNGReportErrors |
| 58 |
|
| 59 |
#ifdef cr_loge |
| 60 |
|
| 61 |
cr_logs("report", 3, NULL, 0, cr_logfunc(), "%s %s\n", message, sub_message ? sub_message : ""); |
| 62 |
|
| 63 |
#else |
| 64 |
|
| 65 |
if (sub_message) |
| 66 |
fprintf (stderr, "*** Error: %s (%s) ***\n", message, sub_message); |
| 67 |
else |
| 68 |
fprintf (stderr, "*** Error: %s ***\n", message); |
| 69 |
|
| 70 |
#endif |
| 71 |
|
| 72 |
#else |
| 73 |
|
| 74 |
(void) message; |
| 75 |
(void) sub_message; |
| 76 |
|
| 77 |
#endif |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
/*****************************************************************************/ |
| 82 |
|
| 83 |
void Throw_dng_error (dng_error_code err, |
| 84 |
const char *message, |
| 85 |
const char *sub_message, |
| 86 |
bool silent) |
| 87 |
{ |
| 88 |
|
| 89 |
#if qDNGReportErrors |
| 90 |
|
| 91 |
{ |
| 92 |
|
| 93 |
if (!message) |
| 94 |
{ |
| 95 |
|
| 96 |
switch (err) |
| 97 |
{ |
| 98 |
|
| 99 |
case dng_error_none: |
| 100 |
case dng_error_silent: |
| 101 |
case dng_error_user_canceled: |
| 102 |
{ |
| 103 |
break; |
| 104 |
} |
| 105 |
|
| 106 |
case dng_error_not_yet_implemented: |
| 107 |
{ |
| 108 |
message = "Not yet implemented"; |
| 109 |
break; |
| 110 |
} |
| 111 |
|
| 112 |
case dng_error_host_insufficient: |
| 113 |
{ |
| 114 |
message = "Host insufficient"; |
| 115 |
break; |
| 116 |
} |
| 117 |
|
| 118 |
case dng_error_memory: |
| 119 |
{ |
| 120 |
message = "Unable to allocate memory"; |
| 121 |
break; |
| 122 |
} |
| 123 |
|
| 124 |
case dng_error_bad_format: |
| 125 |
{ |
| 126 |
message = "File format is invalid"; |
| 127 |
break; |
| 128 |
} |
| 129 |
|
| 130 |
case dng_error_matrix_math: |
| 131 |
{ |
| 132 |
message = "Matrix math error"; |
| 133 |
break; |
| 134 |
} |
| 135 |
|
| 136 |
case dng_error_open_file: |
| 137 |
{ |
| 138 |
message = "Unable to open file"; |
| 139 |
break; |
| 140 |
} |
| 141 |
|
| 142 |
case dng_error_read_file: |
| 143 |
{ |
| 144 |
message = "File read error"; |
| 145 |
break; |
| 146 |
} |
| 147 |
|
| 148 |
case dng_error_write_file: |
| 149 |
{ |
| 150 |
message = "File write error"; |
| 151 |
break; |
| 152 |
} |
| 153 |
|
| 154 |
case dng_error_end_of_file: |
| 155 |
{ |
| 156 |
message = "Unexpected end-of-file"; |
| 157 |
break; |
| 158 |
} |
| 159 |
|
| 160 |
case dng_error_file_is_damaged: |
| 161 |
{ |
| 162 |
message = "File is damaged"; |
| 163 |
break; |
| 164 |
} |
| 165 |
|
| 166 |
case dng_error_image_too_big_dng: |
| 167 |
{ |
| 168 |
message = "Image is too big to save as DNG"; |
| 169 |
break; |
| 170 |
} |
| 171 |
|
| 172 |
case dng_error_image_too_big_tiff: |
| 173 |
{ |
| 174 |
message = "Image is too big to save as TIFF"; |
| 175 |
break; |
| 176 |
} |
| 177 |
|
| 178 |
case dng_error_unsupported_dng: |
| 179 |
{ |
| 180 |
message = "DNG version is unsupported"; |
| 181 |
break; |
| 182 |
} |
| 183 |
|
| 184 |
case dng_error_overflow: |
| 185 |
{ |
| 186 |
message = "Arithmetic overflow/underflow"; |
| 187 |
break; |
| 188 |
} |
| 189 |
|
| 190 |
default: |
| 191 |
{ |
| 192 |
message = "Unknown error"; |
| 193 |
break; |
| 194 |
} |
| 195 |
|
| 196 |
} |
| 197 |
|
| 198 |
} |
| 199 |
|
| 200 |
if (message && !silent) |
| 201 |
{ |
| 202 |
ReportError (message, sub_message); |
| 203 |
} |
| 204 |
|
| 205 |
} |
| 206 |
|
| 207 |
#else |
| 208 |
|
| 209 |
(void) message; |
| 210 |
(void) sub_message; |
| 211 |
(void) silent; |
| 212 |
|
| 213 |
#endif |
| 214 |
|
| 215 |
throw dng_exception (err); |
| 216 |
|
| 217 |
} |
| 218 |
|
| 219 |
/*****************************************************************************/ |