Tiny Jpeg Decoder (JPEG解码程序) 源代码分析 2:解码数据(二)
sh(param_trace);
#endif
} else if (priv->component_infos[cY].Vfactor == 2) {
decode_MCU = decode_mcu_table[3];
convert_to_pixfmt = colorspace_array_conv[3];
xstride_by_mcu = 16;
ystride_by_mcu = 16;
#if TRACE_PARAM
fprintf(param_trace,"Use decode 2x2 sampling\n");
fflush(param_trace);
#endif
} else {
decode_MCU = decode_mcu_table[2];
convert_to_pixfmt = colorspace_array_conv[2];
xstride_by_mcu = 16;
#if TRACE_PARAM
fprintf(param_trace,"Use decode 2x1 sampling\n");
fflush(param_trace);
#endif
}
resync(priv);
/* Don't forget to that block can be either 8 or 16 lines */
bytes_per_blocklines[0] *= ystride_by_mcu;
bytes_per_blocklines[1] *= ystride_by_mcu;
bytes_per_blocklines[2] *= ystride_by_mcu;
bytes_per_mcu[0] *= xstride_by_mcu/8;
bytes_per_mcu[1] *= xstride_by_mcu/8;
bytes_per_mcu[2] *= xstride_by_mcu/8;
/* Just the decode the image by macroblock (size is 8x8, 8x16, or 16x16) */
//纵向
for (y=0; y < priv->height/ystride_by_mcu; y++)
{
//trace("Decoding row %d\n", y);
priv->plane[0] = priv->components[0] + (y * bytes_per_blocklines[0]);
priv->plane[1] = priv->components[1] + (y * bytes_per_blocklines[1]);
priv->plane[2] = priv->components[2] + (y * bytes_per_blocklines[2]);
//横向(循环的写法还不一样?)
for (x=0; x < priv->width; x+=xstride_by_mcu)
{
decode_MCU(priv);
convert_to_pixfmt(priv);
//DCT系数-----------------------------------------------------------
//temp=(char *)priv->component_infos->DCT;
//if(y==4&&x==xstride_by_mcu*3){
if(priv->dlg->m_vijpgoutputdct.GetCheck()==1){
fp = fopen("DCT系数表.txt", "a+");
//fwrite(temp,64,1,fp);
fprintf(fp,"第%d行,第%d列\n",y,x/xstride_by_mcu);
for(j=0;j<64;j++){
fprintf(fp,"%d ",priv->component_infos[cY].DCT[j]);
}
fprintf(fp,"\n");
fclose(fp);
}
#if TRACE_PARAM
fprintf(param_trace,"\n第3行,第4列\n");
for(j=0;j<8;j++){
for(k=0;k<8;k++){
fprintf(param_trace,"%d ",priv->
component_infos[cY].DCT[j*8+k]);
}
fprintf(param_trace,"\n");
}
fprintf(fp,"\n-----------------------\n");
fflush(param_trace);
#endif
//}
//解码后系数(Y)---------------------------------------------------
//temp=(char *)priv->Y;
//if(y==4&&x==xstride_by_mcu*3){
if(priv->dlg->m_vijpgoutputy.GetCheck()==1){
fp = fopen("解码后Y系数表.txt", "a+");
//fwrite(temp,64*4,1,fp);
fprintf(fp,"第%d行,第%d列\n",y,x/xstride_by_mcu);
for(j=0;j<64*4;j++){
fprintf(fp,"%d ",priv->Y[j]);
}
fprintf(fp,"\n");
fclose(fp);
}
#if TRACE_PARAM
fprintf(param_trace,"第3行,第4列\n");
for(j=0;j<8;j++){
for(k=0;k<8;k++){
fprintf(param_trace,"%d ",priv->Y[j*8+k]);
}
fprintf(param_trace,"\n");
}
fprintf(fp,"\n-----------------------\n");
fflush(param_trace);
#endif
//}
//------------------------------------------------------------------
priv->plane[0] += bytes_per_mcu[0];
priv->plane[1] += bytes_per_mcu[1];
priv->plane[2] += bytes_per_mcu[2];
if (priv->restarts_to_go>0)
{
priv->restarts_to_go--;
if (priv->restarts_to_go == 0)
{
priv->stream -= (priv->nbits_in_reservoir/8);
resync(priv);
if (find_next_rst_marker(priv) < 0)
return -1;
}
}
}
}
#if TRACE_PARAM
fprintf(param_trace,"Input file size: %d\n", priv->stream_length+2);
fprintf(param_trace,"Input bytes actually read: %d\n", priv->stream - priv->stream_begin + 2);
fflush(param_trace);
#endif