Tiny Jpeg Decoder (JPEG解码程序) 源代码分析 1:解码文件头(五)

2014-11-23 23:36:45 · 作者: · 浏览: 19
-----
//直流霍夫曼表
build_huffman_table(huff_bits, stream, &priv->HTDC[index&0xf]);
}
length -= 1;
length -= 16;
length -= count;
stream += count;
}
#if TRACE_PARAM
fprintf(param_trace,"< DHT marker\n");
fflush(param_trace);
#endif
return 0;
}
parse_DQT()用于解析DQT标签:
[cpp]
//解析Define quantization table
static int parse_DQT(struct jdec_private *priv, const unsigned char *stream)
{
int qi;
float *table;
const unsigned char *dqt_block_end;
//------------------------------------------------
int j,k;
char *temp;
FILE *fp;
//------------------------------------------------
#if TRACE_PARAM
fprintf(param_trace,"> DQT marker\n");
fflush(param_trace);
#endif
//该Segment末尾
dqt_block_end = stream + be16_to_cpu(stream);
//跳过标签length(2字节)
stream += 2; /* Skip length */
//没到末尾
while (stream < dqt_block_end)
{
//跳过该Segment的第1个字节,QT信息
//precision: 00 (Higher 4 bit)
//index: 00 (Lower 4 bit)
//qi取1,第1张量化表(例如,亮度表),取2,第2张量化表(例如,色度表)
qi = *stream++;
#if SANITY_CHECK
if (qi>>4)
snprintf(error_string, sizeof(error_string),"16 bits quantization table is not supported\n");
if (qi>4)
snprintf(error_string, sizeof(error_string),"No more 4 quantization table is supported (got %d)\n", qi);
#endif
//table指向jdec_private的Q_tables数组,为了在其中写入数据
table = priv->Q_tables[qi];
//注意:一次搞定整张!写入
//需要对数值进行变换!cos(k*PI/16) * sqrt(2)
//这样才能得到离散余弦变换的系数
build_quantization_table(table, stream);
//----------------------------------------------------------
temp=(char *)stream;
//fp = fopen("DQT.txt", "a+");
//fwrite(temp, 64, 1, fp);
char temp_str1[MAX_URL_LENGTH]={0};
char temp_str2[MAX_URL_LENGTH]={0};
for(j=0;j<64;j++){
sprintf(temp_str2,"%d ",temp[j]);
strcat(temp_str1,temp_str2);
//fprintf(fp,"%d ",temp[j]);
}
//计数
char temp_str3[MAX_URL_LENGTH]={0};
sprintf(temp_str3,"量化表【%d】",priv->DQT_table_num);
priv->dlg->AppendBInfo("DQT",temp_str3,temp_str1,"JPEG格式文件的量化表,一般来说第一张是亮度的,后面是色度的");
priv->DQT_table_num++;
//fprintf(fp,"\n-----------------------\n");
//fclose(fp);
#if TRACE_PARAM
for(j=0;j<8;j++){
for(k=0;k<8;k++){
fprintf(param_trace,"%d ",temp[j*8+k]);
}
fprintf(param_trace,"\n");
}
fprintf(fp,"\n-----------------------\n");
fflush(param_trace);
#endif
//----------------------------------------------------------
//完事了!
stream += 64;
}
#if TRACE_PARAM
fprintf(param_trace,"< DQT marker\n");
fflush(param_trace);
#endif
return 0;
}
其他标签的解析不一一列举。
待续未完。。。