File indexing completed on 2025-01-19 03:54:56

0001 /*****************************************************************************/
0002 // Copyright 2006-2019 Adobe Systems Incorporated
0003 // All Rights Reserved.
0004 //
0005 // NOTICE:  Adobe permits you to use, modify, and distribute this file in
0006 // accordance with the terms of the Adobe license agreement accompanying it.
0007 /*****************************************************************************/
0008 
0009 #include "dng_exceptions.h"
0010 
0011 #include "dng_flags.h"
0012 #include "dng_globals.h"
0013 
0014 /*****************************************************************************/
0015 
0016 #ifndef qDNGReportErrors
0017 // assuming this isn't enable on Win, because it's using printf, but an app can redirect that to console
0018 #define qDNGReportErrors ((qDNGDebug && qMacOS) || qDNGValidate)
0019 #endif
0020 
0021 /*****************************************************************************/
0022 
0023 void ReportWarning (const char *message,
0024                     const char *sub_message)
0025     {
0026 
0027     #if qDNGReportErrors
0028 
0029     #ifdef cr_logw
0030 
0031     cr_logs("report", 2, NULL, 0, cr_logfunc(), "%s %s\n", message, sub_message ? sub_message : "");
0032 
0033     #else
0034 
0035     if (sub_message)
0036         fprintf (stderr, "*** Warning: %s (%s) ***\n", message, sub_message);
0037     else
0038         fprintf (stderr, "*** Warning: %s ***\n", message);
0039 
0040     #endif
0041 
0042     #else
0043 
0044     (void) message;
0045     (void) sub_message;
0046 
0047     #endif
0048 
0049     }
0050 
0051 /*****************************************************************************/
0052 
0053 void ReportError (const char *message,
0054                   const char *sub_message)
0055     {
0056 
0057     #if qDNGReportErrors
0058 
0059     #ifdef cr_loge
0060 
0061     cr_logs("report", 3, NULL, 0, cr_logfunc(), "%s %s\n", message, sub_message ? sub_message : "");
0062 
0063     #else
0064 
0065     if (sub_message)
0066         fprintf (stderr, "*** Error: %s (%s) ***\n", message, sub_message);
0067     else
0068         fprintf (stderr, "*** Error: %s ***\n", message);
0069 
0070     #endif
0071 
0072     #else
0073 
0074     (void) message;
0075     (void) sub_message;
0076 
0077     #endif
0078 
0079     }
0080 
0081 /*****************************************************************************/
0082 
0083 void Throw_dng_error (dng_error_code err,
0084                       const char *message,
0085                       const char *sub_message,
0086                       bool silent)
0087     {
0088 
0089     #if qDNGReportErrors
0090 
0091         {
0092 
0093         if (!message)
0094             {
0095 
0096             switch (err)
0097                 {
0098 
0099                 case dng_error_none:
0100                 case dng_error_silent:
0101                 case dng_error_user_canceled:
0102                     {
0103                     break;
0104                     }
0105 
0106                 case dng_error_not_yet_implemented:
0107                     {
0108                     message = "Not yet implemented";
0109                     break;
0110                     }
0111 
0112                 case dng_error_host_insufficient:
0113                     {
0114                     message = "Host insufficient";
0115                     break;
0116                     }
0117 
0118                 case dng_error_memory:
0119                     {
0120                     message = "Unable to allocate memory";
0121                     break;
0122                     }
0123 
0124                 case dng_error_bad_format:
0125                     {
0126                     message = "File format is invalid";
0127                     break;
0128                     }
0129 
0130                 case dng_error_matrix_math:
0131                     {
0132                     message = "Matrix math error";
0133                     break;
0134                     }
0135 
0136                 case dng_error_open_file:
0137                     {
0138                     message = "Unable to open file";
0139                     break;
0140                     }
0141 
0142                 case dng_error_read_file:
0143                     {
0144                     message = "File read error";
0145                     break;
0146                     }
0147 
0148                 case dng_error_write_file:
0149                     {
0150                     message = "File write error";
0151                     break;
0152                     }
0153 
0154                 case dng_error_end_of_file:
0155                     {
0156                     message = "Unexpected end-of-file";
0157                     break;
0158                     }
0159 
0160                 case dng_error_file_is_damaged:
0161                     {
0162                     message = "File is damaged";
0163                     break;
0164                     }
0165 
0166                 case dng_error_image_too_big_dng:
0167                     {
0168                     message = "Image is too big to save as DNG";
0169                     break;
0170                     }
0171 
0172                 case dng_error_image_too_big_tiff:
0173                     {
0174                     message = "Image is too big to save as TIFF";
0175                     break;
0176                     }
0177 
0178                 case dng_error_unsupported_dng:
0179                     {
0180                     message = "DNG version is unsupported";
0181                     break;
0182                     }
0183 
0184                 case dng_error_overflow:
0185                     {
0186                     message = "Arithmetic overflow/underflow";
0187                     break;
0188                     }
0189 
0190                 default:
0191                     {
0192                     message = "Unknown error";
0193                     break;
0194                     }
0195 
0196                 }
0197 
0198             }
0199 
0200         if (message && !silent)
0201             {
0202             ReportError (message, sub_message);
0203             }
0204 
0205         }
0206 
0207     #else
0208 
0209     (void) message;
0210     (void) sub_message;
0211     (void) silent;
0212 
0213     #endif
0214 
0215     throw dng_exception (err);
0216 
0217     }
0218 
0219 /*****************************************************************************/