error.h (1937B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #ifndef LIB_JPEGLI_ERROR_H_ 7 #define LIB_JPEGLI_ERROR_H_ 8 9 #include <stdarg.h> 10 #include <stdint.h> 11 12 #include "lib/jpegli/common.h" 13 #include "lib/jxl/base/compiler_specific.h" 14 15 namespace jpegli { 16 17 bool FormatString(char* buffer, const char* format, ...); 18 19 } // namespace jpegli 20 21 // `error_exit` should be no-return; but let's add some guarantees on our side. 22 #define JPEGLI_ERROR(format, ...) \ 23 jpegli::FormatString(cinfo->err->msg_parm.s, ("%s:%d: " format), __FILE__, \ 24 __LINE__, ##__VA_ARGS__), \ 25 (*cinfo->err->error_exit)(reinterpret_cast<j_common_ptr>(cinfo)), \ 26 JXL_CRASH() 27 28 #define JPEGLI_WARN(format, ...) \ 29 jpegli::FormatString(cinfo->err->msg_parm.s, ("%s:%d: " format), __FILE__, \ 30 __LINE__, ##__VA_ARGS__), \ 31 (*cinfo->err->emit_message)(reinterpret_cast<j_common_ptr>(cinfo), -1) 32 33 #define JPEGLI_TRACE(level, format, ...) \ 34 if (cinfo->err->trace_level >= (level)) \ 35 jpegli::FormatString(cinfo->err->msg_parm.s, ("%s:%d: " format), __FILE__, \ 36 __LINE__, ##__VA_ARGS__), \ 37 (*cinfo->err->emit_message)(reinterpret_cast<j_common_ptr>(cinfo), \ 38 (level)) 39 40 #define JPEGLI_CHECK(condition) \ 41 do { \ 42 if (!(condition)) { \ 43 JPEGLI_ERROR("JPEGLI_CHECK: %s", #condition); \ 44 } \ 45 } while (0) 46 47 #endif // LIB_JPEGLI_ERROR_H_