struct jpeg_error_mgr {
/* Error exit handler: does not return to caller */
JMETHOD(void, error_exit, (j_common_ptr cinfo));
/* Conditionally emit a trace or warning message */
JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
/* Routine that actually outputs a trace or error message */
JMETHOD(void, output_message, (j_common_ptr cinfo));
/* Format a message string for the most recent JPEG error or message */
JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
#define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
/* Reset error state variables at start of a new image */
JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo)); /* The message ID code and any parameters are saved here.
* A message can have one string parameter or up to 8 int parameters.
*/
int msg_code;//取之参考http://www.cnblogs.com/black-mamba/p/6754493.html
#define JMSG_STR_PARM_MAX 80
union {
int i[];
char s[JMSG_STR_PARM_MAX];
} msg_parm; /* Standard state variables for error facility */ int trace_level; /* max msg_level that will be displayed */ /* For recoverable corrupt-data errors, we emit a warning message,
* but keep going unless emit_message chooses to abort. emit_message
* should count warnings in num_warnings. The surrounding application
* can check for bad data by seeing if num_warnings is nonzero at the
* end of processing.
*/
long num_warnings; /* number of corrupt-data warnings */ /* These fields point to the table(s) of error message strings.
* An application can change the table pointer to switch to a different
* message list (typically, to change the language in which errors are
* reported). Some applications may wish to add additional error codes
* that will be handled by the JPEG library error mechanism; the second
* table pointer is used for this purpose.
*
* First table includes all errors generated by JPEG library itself.
* Error code 0 is reserved for a "no such error string" message.
*/
const char * const * jpeg_message_table; /* Library errors */
int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
/* Second table can be added by application (see cjpeg/djpeg for example).
* It contains strings numbered first_addon_message..last_addon_message.
*/
const char * const * addon_message_table; /* Non-library errors */
int first_addon_message; /* code for first string in addon table */
int last_addon_message; /* code for last string in addon table */
};

jpeg_error_mgr结构体中的函数指针是在调用jpeg_std_error()后被初始化的。可自定义这些函数指针也可使用默认函数。

注意msg_parm支持一个字符串或8个int参数。

jerror.h中包含了一些错误打印宏,下面以ERREXIT1为例进行说明:

 #define ERREXIT1(cinfo,code,p1)  \
((cinfo)->err->msg_code = (code), \
(cinfo)->err->msg_parm.i[] = (p1), \
(*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))

实际应用中遇到了这么个打印“Improper call to JPEG library in state 202”,那么,这句话是怎么打印出来的呢?

     cinfo.err = jpeg_std_error(&jerr);
cinfo.global_state = ;
(&cinfo)->err->msg_code = (JERR_BAD_STATE);
(&cinfo)->err->msg_parm.i[] = ((&cinfo)->global_state);
((*(&cinfo)->err->error_exit)) ((j_common_ptr) (&cinfo)); //ERREXIT1(&cinfo, JERR_BAD_STATE, (&cinfo)->global_state);

line3~5是line7的展开式。第5行中的*间接访问操作符可以不用(http://www.cnblogs.com/black-mamba/p/6765231.html)

<jpegint.h>中包含global_state的值:

/* Values of global_state field (jdapi.c has some dependencies on ordering!) */
#define CSTATE_START 100 /* after create_compress */
#define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
#define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
#define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
#define DSTATE_START 200 /* after create_decompress */
#define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
#define DSTATE_READY 202 /* found SOS, ready for start_decompress */
#define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
#define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
#define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
#define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
#define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
#define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
#define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
#define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */

<jerror.c>

该文件中error_exit()->output_message()->format_message()有如此调用关系。

最新文章

  1. mac上执行sed的编辑 -i命令报错sed: 1: &quot;test.txt&quot;: undefined label ‘est.txt’或sed: 1: &quot;2a\test\&quot;: extra characters after \ at the end of a command
  2. bzoj2200: [Usaco2011 Jan]道路和航线
  3. 你的项目真的需要Session吗?
  4. 让Qt的无边框窗口支持拖拽、Aero Snap、窗口阴影等特性
  5. 【leetcode❤python】 257. Binary Tree Paths
  6. C# DataGridView的初始化
  7. ElasticSearch和Kibana 5.X集群的安装
  8. SLAM入门之视觉里程计(2):相机模型(内参数,外参数)
  9. 二叉查找树(Binary Sort Tree)(转)
  10. BZOJ 2741: 【FOTILE模拟赛】L [分块 可持久化Trie]
  11. 除了使用URLSearchParams处理axios发送的数据,但是兼容性不好,其他的兼容方法
  12. 原创分享!SharePoint母版页修改(实战)
  13. Taurus.MVC 2.3 开源发布:增强属性Require验证功能,自带WebAPI文档生成功能
  14. JAVA算术运算符
  15. url rewrite导致的500.19 0x8007000d
  16. 宏基4752g 开机进度条卡到75%左右,解决办法
  17. vs下C# WinForm 解决方案里面生成的文件都是什么作用?干什么的?
  18. 最简单的图文教程,几步完成Git的公私钥配置
  19. SQL 全角半角转换-(摘抄)
  20. Azure 10月新公布

热门文章

  1. AOJ 2266 Cache Strategy(费用流)
  2. [AGC025E]Walking on a Tree
  3. Asp.Net MVC part6 WebAPI
  4. ORACLE查看并修改最大连接数的具体步骤
  5. Linux下使用GDB进行调试
  6. 一起來玩鳥 Starling Framework(5)Multi-Touch
  7. scrapy-splash抓取动态数据例子十
  8. Druid对比Vertica
  9. VScode格式化vue文件
  10. ngrinder安装