zoukankan      html  css  js  c++  java
  • jpeg错误打印结构

     1 struct jpeg_error_mgr {
     2   /* Error exit handler: does not return to caller */
     3   JMETHOD(void, error_exit, (j_common_ptr cinfo));
     4   /* Conditionally emit a trace or warning message */
     5   JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
     6   /* Routine that actually outputs a trace or error message */
     7   JMETHOD(void, output_message, (j_common_ptr cinfo));
     8   /* Format a message string for the most recent JPEG error or message */
     9   JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
    10 #define JMSG_LENGTH_MAX  200    /* recommended size of format_message buffer */
    11   /* Reset error state variables at start of a new image */
    12   JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
    13   
    14   /* The message ID code and any parameters are saved here.
    15    * A message can have one string parameter or up to 8 int parameters.
    16    */
    17   int msg_code;//取之参考http://www.cnblogs.com/black-mamba/p/6754493.html
    18 #define JMSG_STR_PARM_MAX  80
    19   union {
    20     int i[8];
    21     char s[JMSG_STR_PARM_MAX];
    22   } msg_parm;
    23   
    24   /* Standard state variables for error facility */
    25   
    26   int trace_level;        /* max msg_level that will be displayed */
    27   
    28   /* For recoverable corrupt-data errors, we emit a warning message,
    29    * but keep going unless emit_message chooses to abort.  emit_message
    30    * should count warnings in num_warnings.  The surrounding application
    31    * can check for bad data by seeing if num_warnings is nonzero at the
    32    * end of processing.
    33    */
    34   long num_warnings;        /* number of corrupt-data warnings */
    35 
    36   /* These fields point to the table(s) of error message strings.
    37    * An application can change the table pointer to switch to a different
    38    * message list (typically, to change the language in which errors are
    39    * reported).  Some applications may wish to add additional error codes
    40    * that will be handled by the JPEG library error mechanism; the second
    41    * table pointer is used for this purpose.
    42    *
    43    * First table includes all errors generated by JPEG library itself.
    44    * Error code 0 is reserved for a "no such error string" message.
    45    */
    46   const char * const * jpeg_message_table; /* Library errors */
    47   int last_jpeg_message;    /* Table contains strings 0..last_jpeg_message */
    48   /* Second table can be added by application (see cjpeg/djpeg for example).
    49    * It contains strings numbered first_addon_message..last_addon_message.
    50    */
    51   const char * const * addon_message_table; /* Non-library errors */
    52   int first_addon_message;    /* code for first string in addon table */
    53   int last_addon_message;    /* code for last string in addon table */
    54 };

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

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

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

    1 #define ERREXIT1(cinfo,code,p1)  
    2   ((cinfo)->err->msg_code = (code), 
    3    (cinfo)->err->msg_parm.i[0] = (p1), 
    4    (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))

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

    1     cinfo.err = jpeg_std_error(&jerr);
    2     cinfo.global_state = 202;
    3     (&cinfo)->err->msg_code = (JERR_BAD_STATE);
    4     (&cinfo)->err->msg_parm.i[0] = ((&cinfo)->global_state);
    5     ((*(&cinfo)->err->error_exit)) ((j_common_ptr) (&cinfo));
    6 
    7     //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()有如此调用关系。

  • 相关阅读:
    R 画structure图
    perl ExtUtils::Manifest
    解决libstdc++.so.5问题
    R ggplot2 线性回归
    perl 计算方差中值平均数 Statistics::Descriptive;
    专题(十一)scp
    tcpdump的使用
    专题 (四) sed
    python 学习笔记(二)之 字符串操作
    redis 学习笔记之(二)主备高可用(热备)
  • 原文地址:https://www.cnblogs.com/black-mamba/p/6765256.html
Copyright © 2011-2022 走看看