📄 jcmaster.c
字号:
tbidx0 = compptr->ac_tbl_no; tbidx0 = (tbidx0<<1) | compptr->dc_tbl_no; tbidx0 = (tbidx0<<2) | compptr->quant_tbl_no; tbidx0 = tbidx0 & 0xf; Comp_member = 0x0; tbidx = tbidx0; imginfo = (tbidx<<20) | (Comp_member&0xfffff); } else { /* Interleaved (multi-component) scan */ if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, MAX_COMPS_IN_SCAN); /* Overall image size in MCUs */ cinfo->MCUs_per_row = (JDIMENSION) jdiv_round_up((long) cinfo->image_width, (long) (cinfo->max_h_samp_factor*DCTSIZE)); cinfo->MCU_rows_in_scan = (JDIMENSION) jdiv_round_up((long) cinfo->image_height, (long) (cinfo->max_v_samp_factor*DCTSIZE)); cinfo->blocks_in_MCU = 0; for (ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[ci]; /* Sampling factors give # of blocks of component in each MCU */ compptr->MCU_width = compptr->h_samp_factor; compptr->MCU_height = compptr->v_samp_factor; compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE; #ifdef USE_INTERNAL_CPU pjevar->MCU_sample_width[ci] = compptr->MCU_width * DCTSIZE; #endif switch(MCU_comb){ case JCS_yuv420: if(ci==0){ //Y DMA_COMMAND_local[ 2+ci*4] = (0xF<<24) | (0x2<<20) | mDMASOffset(( (cinfo->MCUs_per_row * compptr->MCU_width)*2-3 )) | mDMASWidth(2); DMA_COMMAND_local[42+ci*4] = (0xF<<24) | (0x2<<20) | mDMASOffset(( (cinfo->MCUs_per_row * compptr->MCU_width)*2-3 )) | mDMASWidth(2); }else{ //U,V DMA_COMMAND_local[ 2+ci*4] = mDMASOffset(( (cinfo->MCUs_per_row * compptr->MCU_width)*2-1 )) | mDMASWidth(1); DMA_COMMAND_local[42+ci*4] = mDMASOffset(( (cinfo->MCUs_per_row * compptr->MCU_width)*2-1 )) | mDMASWidth(1); } break; case JCS_yuv422: if(ci==0){ //Y DMA_COMMAND_local[ 2+ci*4] = (0xF<<24) | (0x2<<20) | mDMASOffset((( cinfo->MCUs_per_row * compptr->MCU_width)*2-7)) | mDMASWidth(4); DMA_COMMAND_local[42+ci*4] = (0xF<<24) | (0x2<<20) | mDMASOffset((( cinfo->MCUs_per_row * compptr->MCU_width)*2-7)) | mDMASWidth(4); }else{ //U,V DMA_COMMAND_local[ 2+ci*4] = (0xF<<24) | (0x2<<20) | mDMASOffset((( cinfo->MCUs_per_row * compptr->MCU_width)*2-3)) | mDMASWidth(2); DMA_COMMAND_local[42+ci*4] = (0xF<<24) | (0x2<<20) | mDMASOffset((( cinfo->MCUs_per_row * compptr->MCU_width)*2-3)) | mDMASWidth(2); } break; case JCS_yuv211: if(ci==0){ //Y DMA_COMMAND_local[ 2+ci*4] = (0xF<<24) | (0x2<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-3)<<6) | mDMASWidth(2); // Sm Lo | Sm Bw | Lm Lo | Lm Bw; DMA_COMMAND_local[42+ci*4] = (0xF<<24) | (0x2<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-3)<<6) | mDMASWidth(2); }else{ //U,V DMA_COMMAND_local[ 2+ci*4] = (0x0<<24) | (0x0<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-1)<<6) | mDMASWidth(1); // Sm Lo | Sm Bw | Lm Lo | Lm Bw; DMA_COMMAND_local[42+ci*4] = (0x0<<24) | (0x0<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-1)<<6) | mDMASWidth(1); } break; case JCS_yuv333: DMA_COMMAND_local[ 2+ci*4] = (0xF<<24) | (0x2<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-5)<<6) | mDMASWidth(3); // Sm Lo | Sm Bw | Lm Lo | Lm Bw; DMA_COMMAND_local[42+ci*4] = (0xF<<24) | (0x2<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-5)<<6) | mDMASWidth(3); break; case JCS_yuv222: DMA_COMMAND_local[ 2+ci*4] = (0xF<<24) | (0x2<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-3)<<6) | 0x2; // Sm Lo | Sm Bw | Lm Lo | Lm Bw; DMA_COMMAND_local[42+ci*4] = (0xF<<24) | (0x2<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-3)<<6) | 0x2; break; case JCS_yuv111: DMA_COMMAND_local[ 2+ci*4] = (0x0<<24) | (0x0<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-1)<<6) | 0x1; // Sm Lo | Sm Bw | Lm Lo | Lm Bw; DMA_COMMAND_local[42+ci*4] = (0x0<<24) | (0x0<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-1)<<6) | 0x1; break; default: //JCS_yuv420 if(ci==0){ //Y DMA_COMMAND_local[ 2+ci*4] = (0xF<<24) | (0x2<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-3)<<6) | 0x2; // Sm Lo | Sm Bw | Lm Lo | Lm Bw; DMA_COMMAND_local[42+ci*4] = (0xF<<24) | (0x2<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-3)<<6) | 0x2; }else{ //U,V DMA_COMMAND_local[ 2+ci*4] = (0x0<<24) | (0x0<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-1)<<6) | 0x1; // Sm Lo | Sm Bw | Lm Lo | Lm Bw; DMA_COMMAND_local[42+ci*4] = (0x0<<24) | (0x0<<20) | ((( cinfo->MCUs_per_row * compptr->MCU_width)*2-1)<<6) | 0x1; } break; } /* Figure number of non-dummy blocks in last MCU column & row */ tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); if (tmp == 0) tmp = compptr->MCU_width; compptr->last_col_width = tmp; tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); if (tmp == 0) tmp = compptr->MCU_height; compptr->last_row_height = tmp; /* Prepare array describing MCU composition */ mcublks = compptr->MCU_blocks; mcublkn = mcublkn + compptr->MCU_blocks; //pwhsu++:20040108 if ( ci==0 ){ //pwhsu++:20040108 tbidx0 = compptr->ac_tbl_no; tbidx0 = (tbidx0<<1) | compptr->dc_tbl_no; tbidx0 = (tbidx0<<2) | compptr->quant_tbl_no; tbidx0 = tbidx0 & 0xf; }else if ( ci==1 ){ tbidx1 = compptr->ac_tbl_no; tbidx1 = (tbidx1<<1) | compptr->dc_tbl_no; tbidx1 = (tbidx1<<2) | compptr->quant_tbl_no; tbidx1 = tbidx1 & 0xf; }else if ( ci==2 ){ tbidx2 = compptr->ac_tbl_no; tbidx2 = (tbidx2<<1) | compptr->dc_tbl_no; tbidx2 = (tbidx2<<2) | compptr->quant_tbl_no; tbidx2 = tbidx2 & 0xf; } if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU) //pwhsu:20031016 C_MAX_BLOCKS_IN_MCU = 10 ERREXIT(cinfo, JERR_BAD_MCU_SIZE); while (mcublks-- > 0) { cinfo->MCU_membership[cinfo->blocks_in_MCU] = ci; //rinfo.MCU_membership[cinfo->blocks_in_MCU] = ci; //pwhsu++:20031023 Comp_member = Comp_member | ci << 2*icount; //pwhsu++:20040108 cinfo->blocks_in_MCU++; icount = icount + 1; } } tbidx = (tbidx2<<8) | (tbidx1<<4) | tbidx0; //pwhsu++:20040108 imginfo = (tbidx<<20) | (Comp_member&0xfffff); } //pwhsu++:20040108 //__asm { SET_MCUBR(mcublkn) SET_MCUTIR(imginfo) //} rinfo.mcublkn = mcublkn; /* Convert restart specified in rows to actual MCU count. */ /* Note that count must fit in 16 bits, so we provide limiting. */ if (cinfo->restart_in_rows > 0) { long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row; cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L); }}/* * Per-pass setup. * This is called at the beginning of each pass. We determine which modules * will be active during this pass and give them appropriate start_pass calls. * We also set is_last_pass to indicate whether any more passes will be * required. */METHODDEF(void)prepare_for_pass (j_compress_ptr cinfo){ my_master_ptr master = (my_master_ptr) cinfo->master; switch (master->pass_type) { case main_pass: /* Initial pass: will collect input data, and do either Huffman * optimization or data output for the first scan. */ select_scan_parameters(cinfo); per_scan_setup(cinfo); //pwhsu:20031016 setup the MCU number //(*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding); //pwhsu:20031009 start_pass_huff start_pass_huff1(cinfo); (*cinfo->coef->start_pass) (cinfo, (master->total_passes > 1 ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); //pwhsu:20031009 start_pass_coef (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); //pwhsu:20031009 start_pass_main// if (cinfo->optimize_coding) { /* No immediate data output; postpone writing frame/scan headers */// master->pub.call_pass_startup = FALSE;// } else { //pwhsu:20031009 The condition will execute this part /* Will write frame/scan headers at first jpeg_write_scanlines call */ master->pub.call_pass_startup = TRUE;// } break; default: ERREXIT(cinfo, JERR_NOT_COMPILED); } master->pub.is_last_pass = (master->pass_number == master->total_passes-1);}/* * Special start-of-pass hook. * This is called by jpeg_write_scanlines if call_pass_startup is TRUE. * In single-pass processing, we need this hook because we don't want to * write frame/scan headers during jpeg_start_compress; we want to let the * application write COM markers etc. between jpeg_start_compress and the * jpeg_write_scanlines loop. * In multi-pass processing, this routine is not used. */METHODDEF(void)pass_startup (j_compress_ptr cinfo){ int i; unsigned int *qptr; cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */ write_frame_header1(cinfo); write_scan_header1(cinfo); //add for write table for(i=0;i<64;i++){ //write quant table qptr = rinfo.QUTTBL[0]; //__asm{ //STR qptr[i], [qtbl0+i] //} qtbl0[i]=qptr[i]; } for(i=0;i<64;i++){ //write quant table qptr = rinfo.QUTTBL[1]; //__asm{ //STR qptr[i], [qtbl1+i] //} qtbl1[i]=qptr[i]; } for(i=0;i<64;i++){ //write quant table qptr = rinfo.QUTTBL[2]; //__asm{ //STR qptr[i], [qtbl2+i] //} qtbl2[i]=qptr[i]; } for(i=0;i<64;i++){ //write quant table qptr = rinfo.QUTTBL[3]; //__asm{ //STR qptr[i], [qtbl3+i] //} qtbl3[i]=qptr[i]; } //add for write table}/* * Finish up at end of pass. */METHODDEF(void)finish_pass_master (j_compress_ptr cinfo){ my_master_ptr master = (my_master_ptr) cinfo->master; /* The entropy coder always needs an end-of-pass call, * either to analyze statistics or to flush its output buffer. */ (*cinfo->entropy->finish_pass) (cinfo); //pwhsu:20031027 finish_pass_huff() /* Update state for next pass */ switch (master->pass_type) { case main_pass: /* next pass is either output of scan 0 (after optimization) * or output of scan 1 (if no optimization). */ master->pass_type = output_pass; if (! cinfo->optimize_coding) master->scan_number++; break; case huff_opt_pass: /* next pass is always output of current scan */ master->pass_type = output_pass; break; case output_pass: /* next pass is either optimization or output of next scan */ if (cinfo->optimize_coding) master->pass_type = huff_opt_pass; master->scan_number++; break; } master->pass_number++;}/* * Initialize master compression control. */GLOBAL(void)jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only){ my_master_ptr master; master = (my_master_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_comp_master)); cinfo->master = (struct jpeg_comp_master *) master; master->pub.prepare_for_pass = prepare_for_pass; master->pub.pass_startup = pass_startup; master->pub.finish_pass = finish_pass_master; master->pub.is_last_pass = FALSE; /* Validate parameters, determine derived values */ initial_setup(cinfo); if (cinfo->scan_info != NULL) {#ifdef C_MULTISCAN_FILES_SUPPORTED validate_script(cinfo);#else ERREXIT(cinfo, JERR_NOT_COMPILED);#endif } else { cinfo->progressive_mode = FALSE; cinfo->num_scans = 1; } master->pass_type = main_pass; master->scan_number = 0; master->pass_number = 0; master->total_passes = cinfo->num_scans;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -