//添加huffman表 void jint_add_huff_table(jpeg_compress_info *cinfo,u16 which_tbl,int what_tbl,const u8 *bits,const u8 *value) { JHUFF_TBL **hpp; int nsymbols,len; if(which_tbl>NUM_HUFF_TBLS)return; if(what_tbl==0)//直流分量表 hpp=cinfo->dc_huff_table; else if(what_tbl==1)hpp=cinfo->ac_huff_table;//交流分量表 else return ; hpp[which_tbl]=&JHUFF_TBL_4[which_tbl*2+what_tbl]; memcpy(hpp[which_tbl]->bits,bits,sizeof(hpp[which_tbl]->bits)); nsymbols=0;//计算huffval中标志的数量 for(len=1;len<=16;len++)nsymbols+=bits[len]; memcpy(hpp[which_tbl]->huffval,value,nsymbols*sizeof(u8));//set huffval //计算并设置huffman表&表长 memset(hpp[which_tbl]->ecode,0,sizeof(hpp[which_tbl]->ecode)); memset(hpp[which_tbl]->esize,0,sizeof(hpp[which_tbl]->esize)); jint_calc_huff_tbl(hpp[which_tbl]); }
void jint_add_huff_table ( jpeg_compress_info *cinfo, unsigned int which_tbl, int what_tbl, const UINT8 *bits, const UINT8 *value) { JHUFF_TBL **hpp; /* this value used to Left-Value */ int nsymbols, len; if (which_tbl > NUM_HUFF_TBLS)return; //exit(1); if (what_tbl == 0) /* DC table */ hpp = cinfo->dc_huff_table; else if (what_tbl == 1) /* AC table */ hpp = cinfo->ac_huff_table; else return ; //exit(1); /* set value of 'bits' */ hpp[which_tbl] = &JHUFF_TBL_4[which_tbl*2 + what_tbl];//(JHUFF_TBL *)malloc1;//(sizeof(JHUFF_TBL)); memcpy(hpp[which_tbl]->bits, bits, sizeof(hpp[which_tbl]->bits)); /* calculate # of symbols in huffval */ nsymbols = 0; for (len=1; len<=16; len++) { nsymbols += bits[len]; } /* set huffval */ memcpy(hpp[which_tbl]->huffval, value, nsymbols*sizeof(UINT8)); /* calculate and set huffman code & size table * across this we can use 'ECODE & ESIZE' table in huffman encoding. */ memset(hpp[which_tbl]->ecode, 0, sizeof(hpp[which_tbl]->ecode)); memset(hpp[which_tbl]->esize, 0, sizeof(hpp[which_tbl]->esize)); jint_calc_huff_tbl(hpp[which_tbl]); }