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

2014-11-23 23:36:45 · 作者: · 浏览: 21
f(temp_str2,"对应量化表ID【%d】",i);
itoa((int)Q_table,temp_str1,10);
priv->dlg->AppendBInfo("SOF0",temp_str2,temp_str1,"颜色分量信息:第三个字节代表这个分量对应的量化表ID,例如,Y对应的量化表ID索引值为00,而UV对应的量化表ID都为01,即它们共用一张量化表。");
//-------------
#if TRACE_PARAM
fprintf(param_trace,"Component:%d factor:%dx%d Quantization table:%d\n",
cid, c->Hfactor, c->Hfactor, Q_table );
fflush(param_trace);
#endif
}
priv->width = width;
priv->height = height;
#if TRACE_PARAM
fprintf(param_trace,"< SOF marker\n");
fflush(param_trace);
#endif
return 0;
}
parse_DHT()用于解析DHT标签:
[cpp]
//解析DHT表
static int parse_DHT(struct jdec_private *priv, const unsigned char *stream)
{
unsigned int count, i,j;
unsigned char huff_bits[17];
int length, index;
//------------------------------------------
char *temp;
FILE *fp;
//------------------------------------------
length = be16_to_cpu(stream) - 2;
//跳过length字段
stream += 2; /* Skip length */
#if TRACE_PARAM
fprintf(param_trace,"> DHT marker (length=%d)\n", length);
fflush(param_trace);
#endif
while (length>0) {
//跳过第1字节:
//Huffman 表ID号和类型,高 4 位为表的类型,0:DC 直流;1:AC交流
//低四位为 Huffman 表 ID。
index = *stream++;
/* We need to calculate the number of bytes 'vals' will takes */
huff_bits[0] = 0;
count = 0;
//不同长度 Huffman 的码字数量:固定为 16 个字节,每个字节代表从长度为 1到长度为 16 的码字的个数
for (i=1; i<17; i++) {
huff_bits[i] = *stream++;
//count记录码字的个数
count += huff_bits[i];
}
#if SANITY_CHECK
if (count >= HUFFMAN_BITS_SIZE)
snprintf(error_string, sizeof(error_string),"No more than %d bytes is allowed to describe a huffman table", HUFFMAN_BITS_SIZE);
if ( (index &0xf) >= HUFFMAN_TABLES)
snprintf(error_string, sizeof(error_string),"No more than %d Huffman tables is supported (got %d)\n", HUFFMAN_TABLES, index&0xf);
#if TRACE_PARAM
fprintf(param_trace,"Huffman table %s[%d] length=%d\n", (index&0xf0) "AC":"DC", index&0xf, count);
fflush(param_trace);
#endif
#endif
if (index & 0xf0 ){
//---------------------
char temp_str1[MAX_URL_LENGTH]={0};
char temp_str2[MAX_URL_LENGTH]={0};
temp=(char *)stream;
//fp = fopen("DHT.txt", "a+");
//fwrite(temp, 16, 1, fp);
for(j=0;j<16;j++){
//fprintf(fp,"%d ",temp[j]);
sprintf(temp_str2,"%d ",temp[j]);
strcat(temp_str1,temp_str2);
}
//fprintf(fp,"\n-----------------------\n");
//fclose(fp);
//-----------------------------------------------------
priv->dlg->AppendBInfo("DHT","定义霍夫曼表【交流系数表】",temp_str1,"Huffman表ID号和类型:1字节,高4位为表的类型,0:DC直流;1:AC交流 可以看出这里是直流表;低四位为Huffman表ID");
//-----------------------------------------------------
//交流霍夫曼表
build_huffman_table(huff_bits, stream, &priv->HTAC[index&0xf]);
}
else{
//---------------------
char temp_str1[MAX_URL_LENGTH]={0};
char temp_str2[MAX_URL_LENGTH]={0};
temp=(char *)stream;
//fp = fopen("DHT.txt", "a+");
//fwrite(temp, 16, 1, fp);
for(j=0;j<16;j++){
//fprintf(fp,"%d ",temp[j]);
sprintf(temp_str2,"%d ",temp[j]);
strcat(temp_str1,temp_str2);
}
//fprintf(fp,"\n-----------------------\n");
//fclose(fp);
//-----------------------------------------------------
priv->dlg->AppendBInfo("DHT","定义霍夫曼表【直流系数表】",temp_str1,"Huffman表ID号和类型:1字节,高4位为表的类型,0:DC直流;1:AC交流 可以看出这里是直流表;低四位为Huffman表ID");
//------------------------------------------------