/////////////////////////////////////////////////////////////////////////////////////////// //行压缩函数 //该函数是内部调用函数,如果你想要引用它,必须保证 //cinfo->inbuf填满有效数据 ,否则将不能得到正确的压缩数据 void jint_process_rows(jpeg_compress_info *cinfo) { int mn; //当前缓冲里的MCU JSAMPLE *mcu_start; int mcu_delta; JSAMPLE *pdata; //颜色转换选择调用(这里只做RGB到YCrCb的转换) if(cinfo->in_color_space==JCS_RGB) jutl_cc_rgb2ycc(cinfo->inbuf,cinfo->inbuf_width*cinfo->inbuf_height); //处理每个MCU数据,分割inbuf的数据到每个元件的dct表中,并降低每个元件的采样率 mcu_start=&cinfo->inbuf[0]; mcu_delta=cinfo->mcu_width*cinfo->num_comp*sizeof(JSAMPLE); for(mn=0;mn<cinfo->mcu_per_row;mn++) { //对于每个元件,降低采样率并保存到各个元件中 int cn;//元件计数器 for(cn=0;cn<cinfo->num_comp;cn++) { JSAMPLE *comp_start=(JSAMPLE*)(mcu_start+cn); //初始化采样间隔(sampledelta)数据指针 int h_samp_delta=cinfo->max_h_factor/cinfo->comp[cn].h_factor*cinfo->num_comp*sizeof(JSAMPLE); int v_samp_delta=cinfo->max_v_factor/cinfo->comp[cn].v_factor*cinfo->num_comp*sizeof(JSAMPLE)*cinfo->inbuf_width; //对于每个块(block) int bn;//块计数器 int pn;//数据指针 for(bn=0;bn<cinfo->comp[cn].num_dct_table;bn++) { //初始化块开始地址 JSAMPLE *block_start=(JSAMPLE*)(comp_start+(bn%cinfo->comp[cn].h_factor)*DCTSIZE*h_samp_delta+(bn/cinfo->comp[cn].v_factor)*DCTSIZE*v_samp_delta); DCTVAL *dct=(DCTVAL*)&cinfo->comp[cn].dct_table[bn];//dct表元素 for(pn=0;pn<DCTSIZE2;pn++)//对于每个元素 { if(pn%DCTSIZE==0)pdata=(JSAMPLE*)(pn/DCTSIZE*v_samp_delta+block_start); dct[pn]=*pdata; pdata+=h_samp_delta; } } }//颜色元件处理循环结束 mcu_start+=mcu_delta; jint_process_mcu(cinfo);//处理当前MCU数据 } }
void jint_process_rows(jpeg_compress_info *cinfo) { int mn; /* current mcu in buffer */ JSAMPLE *mcu_start; //jsample 压缩样本 int mcu_delta; JSAMPLE *pdata; // // JSAMPLE *pdata; /* Color convertion invoke select. * Note: We just implemente RGB -> YCrCb converte. */ //如果颜色空间为RGB格式,则通过加权平均值法转换为YUV格式 if(cinfo->in_color_space==JCS_RGB)//RGB到YUV的变换 jutl_cc_rgb2ycc(cinfo->inbuf,cinfo->inbuf_width*cinfo->inbuf_height); /* Process each of MCU data. * Separate the 'inbuf' data to each color component's dct table, * and 'Make' down sample for every component. */ mcu_start=&cinfo->inbuf[0]; mcu_delta=cinfo->mcu_width*cinfo->num_comp*sizeof(JSAMPLE); for(mn=0;mn<cinfo->mcu_per_row;mn++) { /* For every color component. * Down sample and save to each color component. */ int cn; /* component counter */ for (cn=0; cn<cinfo->num_comp; cn++) { JSAMPLE *comp_start = (JSAMPLE *)(mcu_start + cn); /* init data-point sample delta */ int h_samp_delta = cinfo->max_h_factor / cinfo->comp[cn].h_factor * cinfo->num_comp * sizeof(JSAMPLE); int v_samp_delta = cinfo->max_v_factor / cinfo->comp[cn].v_factor * cinfo->num_comp * sizeof(JSAMPLE) * cinfo->inbuf_width; /* for every block */ int bn; /* block counter */ int pn; /* point of data */ for (bn=0; bn<cinfo->comp[cn].num_dct_table; bn++) { /* init block start address */ JSAMPLE *block_start = (JSAMPLE *)(comp_start + (bn%cinfo->comp[cn].h_factor)*DCTSIZE*h_samp_delta + (bn/cinfo->comp[cn].v_factor)*DCTSIZE*v_samp_delta); /* dct table element */ DCTVAL *dct = (DCTVAL *)&cinfo->comp[cn].dct_table[bn]; /* for each element */ for (pn=0; pn<DCTSIZE2; pn++) { if (pn % DCTSIZE == 0) { pdata = (JSAMPLE *)(pn/DCTSIZE * v_samp_delta + block_start); } dct[pn] = *pdata; pdata += h_samp_delta; } } } /* End of color component loop */ mcu_start += mcu_delta; /* Process current MCU data. */ jint_process_mcu(cinfo); /* for example : call jint_process_mcu(cinfo) */ } }