⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jccoefct.c

📁 基于Linux的ffmepg decoder
💻 C
字号:
/* * jccoefct.c * * Copyright (C) 1994-1997, Thomas G. Lane. * This file is part of the Independent JPEG Group's software. * For conditions of distribution and use, see the accompanying README file. * * This file contains the coefficient buffer controller for compression. * This controller is the top level of the JPEG compressor proper. * The coefficient buffer lies between forward-DCT and entropy encoding steps. */#define JPEG_INTERNALS#include "jinclude.h"#include "jpeglib.h"#include "vpe_m.h"#include "local_mem.h"/* We use a full-image coefficient buffer when doing Huffman optimization, * and also for writing multiple-scan JPEG files.  In all cases, the DCT * step is run during the first pass, and subsequent passes need only read * the buffered coefficients. */#ifdef ENTROPY_OPT_SUPPORTED#define FULL_COEF_BUFFER_SUPPORTED#else#ifdef C_MULTISCAN_FILES_SUPPORTED#define FULL_COEF_BUFFER_SUPPORTED#endif#endif/* Private buffer controller object */typedef struct {  struct jpeg_c_coef_controller pub; /* public fields */  JDIMENSION iMCU_row_num;	/* iMCU row # within image */  JDIMENSION mcu_ctr;		/* counts MCUs processed in current row */  int MCU_vert_offset;		/* counts MCU rows within iMCU row */  int MCU_rows_per_iMCU_row;	/* number of such rows needed */  /* For single-pass compression, it's sufficient to buffer just one MCU   * (although this may prove a bit slow in practice).  We allocate a   * workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each   * MCU constructed and sent.  (On 80x86, the workspace is FAR even though   * it's not really very big; this is to keep the module interfaces unchanged   * when a large coefficient buffer is necessary.)   * In multi-pass modes, this array points to the current MCU's blocks   * within the virtual arrays.   */  JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];  /* In multi-pass modes, we need a virtual block array for each component. */  jvirt_barray_ptr whole_image[MAX_COMPONENTS];} my_coef_controller;typedef my_coef_controller * my_coef_ptr;LOCAL(void)start_iMCU_row (j_compress_ptr cinfo)/* Reset within-iMCU-row counters for a new row */{  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;  /* In an interleaved scan, an MCU row is the same as an iMCU row.   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.   * But at the bottom of the image, process only what's left.   */  if (cinfo->comps_in_scan > 1) {    coef->MCU_rows_per_iMCU_row = 1;  } else {    if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;    else      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;  }  coef->mcu_ctr = 0;  coef->MCU_vert_offset = 0;}/* * Initialize for a processing pass. */METHODDEF(void)start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode){  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;  coef->iMCU_row_num = 0;  start_iMCU_row(cinfo);}/* * Process some data in the single-pass case. * We process the equivalent of one fully interleaved MCU row ("iMCU" row) * per call, ie, v_samp_factor block rows for each component in the image. * Returns TRUE if the iMCU row is completed, FALSE if suspended. * * NB: input_buf contains a plane for each component in image, * which we index according to the component's SOF position. */boolean compress_data1 (j_compress_ptr cinfo){  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;  JDIMENSION MCU_col_num;	/* index of current MCU within row */  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;   //unsigned int DCT_col_num;   volatile MDMA *pmdma = MDMA1;  int i;     for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;	 MCU_col_num++) {		//pwhsu:20031017	For this case:0~14		 if(rinfo.nCount==0){						DMA_mcu(cinfo, MCU_col_num, last_MCU_col, rinfo.Dma_bnum);			while((pmdma->Status & 0x1) == 0){}			pmdma->SMaddr =			pmdma->CCA = (unsigned int)DMA_COMMAND_system_phy;//			pmdma->LMaddr = DMA_COMMAND_local+rinfo.Dma_bnum*40;			pmdma->LMaddr = DMA_COMMAND_local_OFF+rinfo.Dma_bnum*40 * 4;			pmdma->BlkWidth = 0;			pmdma->Control =  dmactrl;//0x4B00000 | (rinfo.mcublkn)*4;		//start DMA				rinfo.Dma_bnum =  (rinfo.Dma_bnum+1)&1;			mVpe_Indicator(0x90000000 | cMCUrow<<4 | MCU_col_num);	//pwhsu++:20040128						 if(rinfo.nCount==rinfo.MCUnum-1) {				mFa526DrainWrBuf ();				while((pmdma->Status & 0x1) == 0){}				mVpe_Indicator (0x90000000 | cMCUrow<<4 | MCU_col_num);	//pwhsu++:20040128				pbufaddr = (unsigned int *)(cur_b0 + rinfo.Coef_bnum * stride_MCU);			 				rinfo.Coef_bnum =  (rinfo.Coef_bnum+1)&1;  //switch the pixel buffer number				SET_MCCADDR(pbufaddr);				SET_MCCTL(mcctrl);				mFa526DrainWrBuf ();				do {					READ_VLDSTS(vldreg);				} while ((vldreg & 32) == 0);			}		 }else if (rinfo.nCount==1){			DMA_mcu(cinfo, MCU_col_num, last_MCU_col, rinfo.Dma_bnum);	//gen DMA command queue			while((pmdma->Status & 0x1) == 0)		//DMA process run			{}			pmdma->SMaddr =			pmdma->CCA = (unsigned int)DMA_COMMAND_system_phy;//			pmdma->LMaddr = DMA_COMMAND_local+rinfo.Dma_bnum*40;			pmdma->LMaddr = DMA_COMMAND_local_OFF+rinfo.Dma_bnum*40 * 4;			pmdma->BlkWidth = 0;			pmdma->Control =  dmactrl;//0x4B00000 | (rinfo.mcublkn)*4;		//start DMA				mVpe_Indicator (0x90000000 | cMCUrow<<4 | MCU_col_num);				rinfo.Dma_bnum =  (rinfo.Dma_bnum+1)&1;  			pbufaddr = (unsigned int *)(cur_b0 + rinfo.Coef_bnum * stride_MCU);		//MC_go			rinfo.Coef_bnum =  (rinfo.Coef_bnum+1)&1;			SET_MCCADDR(pbufaddr);			SET_MCCTL(mcctrl);			  			if(rinfo.nCount==rinfo.MCUnum-1){				mFa526DrainWrBuf ();				while((pmdma->Status & 0x1) == 0){}				mVpe_Indicator ( 0x90000000 | cMCUrow<<4 | MCU_col_num);	//pwhsu++:20040128				//Check VLC is done				do {					READ_CPSTS(sreg);				} while ((sreg & 32) == 0);				//pwhsu++:2040607	VAD found bug				Encode_mcu (cinfo);       				mFa526DrainWrBuf ();				//pwhsu++:2040607	VAD found bug				pbufaddr = (unsigned int *)(cur_b0 + rinfo.Coef_bnum * stride_MCU);			 				rinfo.Coef_bnum =  (rinfo.Coef_bnum+1)&1;  //switch the pixel buffer number				SET_MCCADDR(pbufaddr);				SET_MCCTL(mcctrl);				mFa526DrainWrBuf ();				do {					READ_CPSTS(sreg);				} while ((sreg & 32) == 0);			}		}else {			DMA_mcu(cinfo, MCU_col_num, last_MCU_col, rinfo.Dma_bnum);	//gen DMA command queue			mFa526DrainWrBuf ();			do {				READ_CPSTS(sreg);			} while ((sreg & 32) == 0);			Encode_mcu (cinfo);			while((pmdma->Status & 0x1) == 0)			//DMA process run				{}			pmdma->SMaddr =			pmdma->CCA = (unsigned int)DMA_COMMAND_system_phy;//			pmdma->LMaddr = DMA_COMMAND_local+rinfo.Dma_bnum*40;			pmdma->LMaddr = DMA_COMMAND_local_OFF+rinfo.Dma_bnum*40 * 4;			pmdma->BlkWidth = 0;			pmdma->Control =  dmactrl;//0x4B00000 | (rinfo.mcublkn)*4;		//start DMA				rinfo.Dma_bnum =  (rinfo.Dma_bnum+1)&1;			mVpe_Indicator ( 0x90000000 | cMCUrow<<4 | MCU_col_num);  			pbufaddr = (unsigned int *)(cur_b0 + rinfo.Coef_bnum * stride_MCU);		//MC_go			rinfo.Coef_bnum =  (rinfo.Coef_bnum+1)&1;			SET_MCCADDR(pbufaddr);			SET_MCCTL(mcctrl)	;						  			if(rinfo.nCount==rinfo.MCUnum-1){				mFa526DrainWrBuf ();				//while((pmdma->Status & 0x1) == 0){}				while((pmdma->Status & 0x1) == 0)			//DMA process run					{}				mVpe_Indicator (0x90000000 | cMCUrow<<4 | MCU_col_num);				do {					READ_CPSTS(sreg);				} while ((sreg & 32) == 0);				//pwhsu++:2040607	VAD found bug				Encode_mcu (cinfo);       				mFa526DrainWrBuf ();				//pwhsu++:2040607	VAD found bug				pbufaddr = (unsigned int *)(cur_b0 + rinfo.Coef_bnum * stride_MCU);			 				rinfo.Coef_bnum =  (rinfo.Coef_bnum+1)&1;  //switch the pixel buffer number				SET_MCCADDR(pbufaddr);				SET_MCCTL(mcctrl);				mFa526DrainWrBuf ();				do {					READ_CPSTS(sreg);				} while ((sreg & 32) == 0);			}		}		//pwhsu++:20031031		rinfo.nCount+=1;//pwhsu++:20031030	     }//end of for MCU_col_num  return TRUE;}/* * Initialize coefficient buffer controller. */GLOBAL(void)jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer){  my_coef_ptr coef;  coef = (my_coef_ptr)    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,				SIZEOF(my_coef_controller));  cinfo->coef = (struct jpeg_c_coef_controller *) coef;  coef->pub.start_pass = start_pass_coef;}voidDMA_mcu(j_compress_ptr cinfo,unsigned int MCU_col_num, 			unsigned int last_MCU_col, int dbnum){	int blkn, xpos, ypos, bi, ci, blockcnt, yindex;	jpeg_component_info *compptr;	int cmdidx;	unsigned char* puchexin, *pucdataptr;	unsigned int uintpos;	int sysdataidx;	blkn = 0;		sysdataidx = dbnum*40;	for (ci = 0; ci < cinfo->comps_in_scan; ci++) {		puchexin = curdata[ci];		compptr = cinfo->cur_comp_info[ci];		blockcnt = compptr->MCU_width;		xpos = MCU_col_num * compptr->MCU_sample_width;		ypos = 0;		for (yindex = 0; yindex < compptr->MCU_height; yindex++) {			uintpos = puchexin + (ypos+cMCUrow*mcu_height[ci])*comp_width[ci];			for (bi = 0; bi < blockcnt; bi++, xpos += DCTSIZE) {  								//DMA_access(ypos ,xpos, blkn, bi, dbnum, ci/*, cmdidx*/);								pucdataptr = uintpos + xpos;				//DMA_COMMAND_local[0+(blkn+bi)*4+dbnum*40] = (unsigned int) pucdataptr;				DMA_COMMAND_local[sysdataidx] = (unsigned int) pucdataptr;				//puchexin += (start_row + (cMCUrow*v_sampf[ci])*8) * (comp_width[ci]) + start_col;				//DMA_COMMAND_local[0+(blkn+bi)*4+dbnum*40] = (unsigned int) puchexin;				//move one block per comment  //BlkWidth				//DMA_COMMAND_local[2+(blkn+bi)*4+dbnum*40] = ((( cinfo->MCUs_per_row * blockcnt)*2-1)<<8) | 0x02;				sysdataidx += 4;					} //end of block num			xpos = MCU_col_num * compptr->MCU_sample_width;			blkn += compptr->MCU_width;			ypos += DCTSIZE;		}// end of yindex	}// end of ci}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -