Tiny Jpeg Decoder (JPEG解码程序) 源代码分析 1:解码文件头(三)
r!=1)
|| (priv->component_infos[cCb].Vfactor!=1)
|| (priv->component_infos[cCr].Vfactor!=1))
snprintf(error_string, sizeof(error_string),"Sampling other than 1x1 for Cr and Cb is not supported");
#endif
return 0;
bogus_jpeg_format:
#if TRACE_PARAM
fprintf(param_trace,"Bogus jpeg format\n");
fflush(param_trace);
#endif
return -1;
}
parse_SOF()用于解析SOF标签:
注意:其中包含了部分自己写的代码,形如:
[cpp]
itoa(width,temp_str1,10);
priv->dlg->AppendBInfo("SOF0","宽",temp_str1,"图像的宽度");
这些代码主要用于在解码过程中提取一些信息,比如图像宽,高,颜色分量数等等
[cpp]
static int parse_SOF(struct jdec_private *priv, const unsigned char *stream)
{
int i, width, height, nr_components, cid, sampling_factor;
int Q_table;
struct component *c;
#if TRACE_PARAM
fprintf(param_trace,"> SOF marker\n");
fflush(param_trace);
#endif
print_SOF(stream);
height = be16_to_cpu(stream+3);
width = be16_to_cpu(stream+5);
nr_components = stream[7];
#if SANITY_CHECK
if (stream[2] != 8)
snprintf(error_string, sizeof(error_string),"Precision other than 8 is not supported\n");
if (width>JPEG_MAX_WIDTH || height>JPEG_MAX_HEIGHT)
snprintf(error_string, sizeof(error_string),"Width and Height (%dx%d) seems suspicious\n", width, height);
if (nr_components != 3)
snprintf(error_string, sizeof(error_string),"We only support YUV images\n");
if (height%16)
snprintf(error_string, sizeof(error_string),"Height need to be a multiple of 16 (current height is %d)\n", height);
snprintf(error_string, sizeof(error_string),"Width need to be a multiple of 16 (current Width is %d)\n", width);
#endif
char temp_str1[MAX_URL_LENGTH]={0};
itoa(width,temp_str1,10);
priv->dlg->AppendBInfo("SOF0","宽",temp_str1,"图像的宽度");
itoa(height,temp_str1,10);
priv->dlg->AppendBInfo("SOF0","高",temp_str1,"图像的高度");
itoa(nr_components,temp_str1,10);
priv->dlg->AppendBInfo("SOF0","颜色分量数",temp_str1,"图像的颜色分量数。一个字节,例如03,代表有三个分量,YCrCb");
itoa(stream[2],temp_str1,10);
priv->dlg->AppendBInfo("SOF0","精度",temp_str1,"图像的精度。一个字节,例如08,即精度为一个字节。");
stream += 8;
for (i=0; i
cid = *stream++;
sampling_factor = *stream++;
Q_table = *stream++;
c = &priv->component_infos[i];
#if SANITY_CHECK
c->cid = cid;
if (Q_table >= COMPONENTS)
snprintf(error_string, sizeof(error_string),"Bad Quantization table index (got %d, max allowed %d)\n", Q_table, COMPONENTS-1);
#endif
c->Vfactor = sampling_factor&0xf;
c->Hfactor = sampling_factor>>4;
c->Q_table = priv->Q_tables[Q_table];
//------------
char temp_str2[MAX_URL_LENGTH]={0};
sprintf(temp_str2,"垂直采样因子【%d】",i);
itoa(c->Hfactor,temp_str1,10);
priv->dlg->AppendBInfo("SOF0",temp_str2,temp_str1,"颜色分量信息:每个分量有三个字节,第一个为分量的ID,01:Y 02:U 03:V;第二个字节高位为水平采样因子,低位为垂直采样因子。");
sprintf(temp_str2,"水平采样因子【%d】",i);
itoa(c->Hfactor,temp_str1,10);
priv->dlg->AppendBInfo("SOF0",temp_str2,temp_str1,"颜色分量信息:每个分量有三个字节,第一个为分量的ID,01:Y 02:U 03:V;第二个字节高位为水平采样因子,低位为垂直采样因子。");
sprint