📄 jpeg_enc.c
字号:
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications *///#include "jpeglib.h"#include "jversion.h" /* for version message */#include "jpeg_enc.h"#ifdef USE_INTERNAL_CPU //#ifdef FPGA_demo //#include "intercpucode_fpga.h" //#else //#include "intercpucode_rtl.h" //#endif #include "intercpucode.h"#endif#define CKR_RATIO 0struct Compress_recon rinfo; //yuv420 =0//yuv422 =1//yuv211 =2//yuv333 =3//yuv222 =4//yuv111 =5unsigned int YUVsampling = 0;unsigned int img_qual = 90; //usually set 75 < qual <100, if qual<50 the quality of image is very poorunsigned int rst_interval = 7; //default value is 0unsigned int img_width = 192;unsigned int img_height = 128;unsigned int comp_num = 3;unsigned int qtbl_no = 1; //If the value is one, it will be the default table //If the value is zero, it will be the another one tableunsigned int hufftbl_no = 1; //If the value is one, it will be the default table //If the value is zero, it will be the another one table/* Create the add-on message string table. */#define JMESSAGE(code,string) string ,static const char * const cdjpeg_message_table[] = {#include "cderror.h" NULL};//--------------- Bank0 ---------------------//// storing the qcoeff and vlc output in MCUunsigned short *qcoef_b0; // = (unsigned short *) (0x0+BASE_ADDRESS); //0000 -- 0500 (10 bolcks)// DMA_commandunsigned int *DMA_COMMAND_local;// = (unsigned int *) (0x500+BASE_ADDRESS); //0500 -- 0700#ifdef USE_INTERNAL_CPU unsigned int *DMA_COMMAND_cpu;#endif// vlc outputunsigned int *Vlcout; // = (unsigned int *) (0xc00+BASE_ADDRESS);//--------------- Bank1 ---------------------//// storing the pointer of each block in MCU (double buffer)/*unsigned char *cur_b0 = (unsigned char *) (0x4000+BASE_ADDRESS); //4000 -- 4280unsigned char *cur_b1 = (unsigned char *) (0x4040+BASE_ADDRESS); //4000 -- 4280unsigned char *cur_b2 = (unsigned char *) (0x4080+BASE_ADDRESS); //4000 -- 4280unsigned char *cur_b3 = (unsigned char *) (0x40c0+BASE_ADDRESS); //4000 -- 4280unsigned char *cur_b4 = (unsigned char *) (0x4100+BASE_ADDRESS); //4000 -- 4280unsigned char *cur_b5 = (unsigned char *) (0x4140+BASE_ADDRESS); //4000 -- 4280unsigned char *cur_b6 = (unsigned char *) (0x4180+BASE_ADDRESS); //4000 -- 4280unsigned char *cur_b7 = (unsigned char *) (0x41c0+BASE_ADDRESS); //4000 -- 4280unsigned char *cur_b8 = (unsigned char *) (0x4200+BASE_ADDRESS); //4000 -- 4280unsigned char *cur_b9 = (unsigned char *) (0x4240+BASE_ADDRESS); //4000 -- 4280*/#ifdef Internal_CPU//------For internal CPU------// //20041227unsigned char *cur_b0 = (unsigned char *) (0x14000); //4000 -- 4280unsigned char *cur_b1 = (unsigned char *) (0x14040); //4000 -- 4280unsigned char *cur_b2 = (unsigned char *) (0x14080); //4000 -- 4280unsigned char *cur_b3 = (unsigned char *) (0x140c0); //4000 -- 4280unsigned char *cur_b4 = (unsigned char *) (0x14100); //4000 -- 4280unsigned char *cur_b5 = (unsigned char *) (0x14140); //4000 -- 4280unsigned char *cur_b6 = (unsigned char *) (0x14180); //4000 -- 4280unsigned char *cur_b7 = (unsigned char *) (0x141c0); //4000 -- 4280unsigned char *cur_b8 = (unsigned char *) (0x14200); //4000 -- 4280unsigned char *cur_b9 = (unsigned char *) (0x14240); //4000 -- 4280const int stride_MCU = 0x280;const int stride_blk = 0x40;//For DMA LM_addrunsigned char *cur_b0_div2 = (unsigned char *) (0xa000); //4000 -- 4280unsigned char *cur_b1_div2 = (unsigned char *) (0xa020); //4000 -- 4280unsigned char *cur_b2_div2 = (unsigned char *) (0xa040); //4000 -- 4280unsigned char *cur_b3_div2 = (unsigned char *) (0xa060); //4000 -- 4280unsigned char *cur_b4_div2 = (unsigned char *) (0xa080); //4000 -- 4280unsigned char *cur_b5_div2 = (unsigned char *) (0xa0a0); //4000 -- 4280unsigned char *cur_b6_div2 = (unsigned char *) (0xa0c0); //4000 -- 4280unsigned char *cur_b7_div2 = (unsigned char *) (0xa0e0); //4000 -- 4280unsigned char *cur_b8_div2 = (unsigned char *) (0xa100); //4000 -- 4280unsigned char *cur_b9_div2 = (unsigned char *) (0xa120); //4000 -- 4280const int stride_MCU_div2 = 0x140;//------For internal CPU------// //20041227#elseunsigned char *cur_b0 = (unsigned char *) (0x4000); //4000 -- 4280unsigned char *cur_b1 = (unsigned char *) (0x4040); //4000 -- 4280unsigned char *cur_b2 = (unsigned char *) (0x4080); //4000 -- 4280unsigned char *cur_b3 = (unsigned char *) (0x40c0); //4000 -- 4280unsigned char *cur_b4 = (unsigned char *) (0x4100); //4000 -- 4280unsigned char *cur_b5 = (unsigned char *) (0x4140); //4000 -- 4280unsigned char *cur_b6 = (unsigned char *) (0x4180); //4000 -- 4280unsigned char *cur_b7 = (unsigned char *) (0x41c0); //4000 -- 4280unsigned char *cur_b8 = (unsigned char *) (0x4200); //4000 -- 4280unsigned char *cur_b9 = (unsigned char *) (0x4240); //4000 -- 4280const int stride_MCU = 0x280;const int stride_blk = 0x40;#endif//--------------- Qtable ---------------------//// storing the qval and invqval in local mem (31k~32k)unsigned int *qtbl0;// = (unsigned int *) (0x7c00+BASE_ADDRESS); //7c00 -- 7cffunsigned int *qtbl1;// = (unsigned int *) (0x7d00+BASE_ADDRESS); //7d00 -- 7dff unsigned int *qtbl2;// = (unsigned int *) (0x7e00+BASE_ADDRESS); //7e00 -- 7effunsigned int *qtbl3;// = (unsigned int *) (0x7f00+BASE_ADDRESS); //7f00 -- 7fff//--------------- Bank2,3 ---------------------//// storing the huffman table in local mem (32k~36k)unsigned int *huftbl0_ac;// = (unsigned int *) (0x8000+BASE_ADDRESS); //8000 -- 8400unsigned int *huftbl1_ac;// = (unsigned int *) (0x8400+BASE_ADDRESS); //8400 -- 8800unsigned int *huftbl0_dc;// = (unsigned int *) (0x8800+BASE_ADDRESS); //8800 -- 8c00unsigned int *huftbl1_dc;// = (unsigned int *) (0x8c00+BASE_ADDRESS); //8c00 -- 9000//--------- Output bitstream pointer -----------//unsigned int *outbitstr;// = (unsigned int *) 0x500000;//----------------------------------------------////unsigned int *DMA_COMMAND_system;unsigned int mcctrl; //pwhsu++:20040109unsigned int *pbufaddr; //pwhsu++:20040109//int imgbwidth;//pwhsu++:20040119int h_sampf[3];int v_sampf[3];int cMCUrow;unsigned int outfsize; //pwhsu++:20040128//unsigned char* cury ;//unsigned char* curu ;//unsigned char* curv ;unsigned char* curdata[3];//unsigned char* outbits;unsigned int sreg; //pwhsu++:20040115unsigned int vldreg; //pwhsu++:20040218unsigned int lmadr; //pwhsu++:20040219unsigned int smadr; //pwhsu++:20040219unsigned int bitslen; //pwhsu++:20040219unsigned int dmactrl;unsigned int comp_width[3];unsigned int mcu_height[3];unsigned int CCATmp0;unsigned int CCATmp1;#ifdef USE_INTERNAL_CPU volatile JPG_ENC_VAR *pjevar;#endif//DMA_MALLOC_PTR pfnDmaMalloc;//DMA_FREE_PTR pfnDmaFree;void * pfnDmaMalloc;void * pfnDmaFree;struct jpeg_compress_struct cinfo;struct jpeg_error_mgr jerr; //pwhsu: 20031008 error reportunsigned int BASE_ADDRESS;void * FJpegEncCreate(FJPEG_ENC_PARAM * ptParam){ unsigned int tmpbits; int i; //int status, i, j; //unsigned char *pucrtlout; //unsigned int *vpe_stop = (unsigned int *) (VPE); unsigned int qarval; #ifdef USE_INTERNAL_CPU volatile MDMA *pmdma; #endif /***************************************************************************** * Command line parsing ****************************************************************************/ //__rt_lib_init(0x50000, 0x200000); //__rt_lib_init(0x50000, 0x08000000); //_fp_init(); // to set the related encoder parameters BASE_ADDRESS=(unsigned int)ptParam->pu32BaseAddr; pfnDmaMalloc=(void *)ptParam->pfnDmaMalloc; pfnDmaFree=(void *)ptParam->pfnDmaFree; #ifdef USE_INTERNAL_CPU pmdma = MDMA1; // only put here can the BASE_ADDRESS is available. pjevar = ((volatile JPG_ENC_VAR *)(0x8000 + BASE_ADDRESS)); #endif qcoef_b0 = (unsigned short *) (0x0000); //0000 -- 0500 (10 bolcks) #ifdef Internal_CPU //qcoef_b0 = (unsigned short *) (0x10000+BASE_ADDRESS); //0000 -- 0500 (10 bolcks) DMA_COMMAND_local = (unsigned int *) (0x10500+BASE_ADDRESS); //0500 -- 0700 #define DMA_COMMAND_local_OFF (0x10500) #ifdef USE_INTERNAL_CPU DMA_COMMAND_cpu = (unsigned int *) (0x10800+BASE_ADDRESS); #endif Vlcout = (unsigned int *) (0x10c00); //Vlcout = (unsigned int *) (0x10c00+BASE_ADDRESS); qtbl0 = (unsigned int *) (0x17c00+BASE_ADDRESS); //7c00 -- 7cff qtbl1 = (unsigned int *) (0x17d00+BASE_ADDRESS); //7d00 -- 7dff qtbl2 = (unsigned int *) (0x17e00+BASE_ADDRESS); //7e00 -- 7eff qtbl3 = (unsigned int *) (0x17f00+BASE_ADDRESS); //7f00 -- 7fff huftbl0_ac = (unsigned int *) (0x18000+BASE_ADDRESS); //8000 -- 8400 huftbl1_ac = (unsigned int *) (0x18400+BASE_ADDRESS); //8400 -- 8800 huftbl0_dc = (unsigned int *) (0x18800+BASE_ADDRESS); //8800 -- 8c00 huftbl1_dc = (unsigned int *) (0x18c00+BASE_ADDRESS); //8c00 -- 9000 #else //qcoef_b0 = (unsigned short *) (0x0+BASE_ADDRESS); //0000 -- 0500 (10 bolcks) DMA_COMMAND_local = (unsigned int *) (0x500+BASE_ADDRESS); //0500 -- 0700 #define DMA_COMMAND_local_OFF (0x500) #ifdef USE_INTERNAL_CPU DMA_COMMAND_cpu = (unsigned int *) (0x800+BASE_ADDRESS); #endif Vlcout = (unsigned int *) (0xc00);//Vlcout = (unsigned int *) (0xc00+BASE_ADDRESS); qtbl0 = (unsigned int *) (0x7c00+BASE_ADDRESS); //7c00 -- 7cff qtbl1 = (unsigned int *) (0x7d00+BASE_ADDRESS); //7d00 -- 7dff qtbl2 = (unsigned int *) (0x7e00+BASE_ADDRESS); //7e00 -- 7eff qtbl3 = (unsigned int *) (0x7f00+BASE_ADDRESS); //7f00 -- 7fff huftbl0_ac = (unsigned int *) (0x8000+BASE_ADDRESS); //8000 -- 8400 huftbl1_ac = (unsigned int *) (0x8400+BASE_ADDRESS); //8400 -- 8800 huftbl0_dc = (unsigned int *) (0x8800+BASE_ADDRESS); //8800 -- 8c00 huftbl1_dc = (unsigned int *) (0x8c00+BASE_ADDRESS); //8c00 -- 9000 #endif img_qual=ptParam->u32ImageQuality; rst_interval=ptParam->u32RestartInterval; img_width=ptParam->u32ImageWidth; img_height=ptParam->u32ImageHeight; comp_num=ptParam->u8NumComponents; if(comp_num==1) { YUVsampling=5; // means YUV111 , because it is gray so we must set it to YUV111 curdata[0]=ptParam->pu8YUVAddr[0]; } else { // see 'jcparam.c' file unsigned int samp_encod=0; for(i=0;i<comp_num;i++) { samp_encod <<= 4; samp_encod |= ptParam->rgComponentInfo[i].m_u8HSamplingFrequency; samp_encod <<= 4; samp_encod |= ptParam->rgComponentInfo[i].m_u8VSamplingFrequency; curdata[i]=ptParam->pu8YUVAddr[i]; } switch(samp_encod) { case 0x00221111: YUVsampling=0; // JCS_yuv420 break; case 0x00412121: YUVsampling=1; // JCS_yuv422 break; case 0x00211111: YUVsampling=2; // JCS_yuv211 break; case 0x00313131: YUVsampling=3; // JCS_yuv333 break; case 0x00212121: YUVsampling=4; // JCS_yuv222 break; case 0x00111111: YUVsampling=5; // JCS_yuv111 break; default: YUVsampling=0; // JCS_yuv420 break; } } outbitstr=ptParam->pu8BitstreamAddr; tmpbits = (unsigned int)outbitstr; qarval = ((unsigned int)qcoef_b0 & 0xffff)<<16 | ((unsigned int)qcoef_b0 & 0xffff); //__asm{ SET_VLDCTL(1<<5) //stop autobuffer in case previous firmware program did not terminate normally SET_PYDCR(0) SET_PUVDCR(0) SET_CKR(CKR_RATIO) //SET_QAR(qcoef_b0) SET_QAR(qarval) SET_VADR(Vlcout) SET_BADR(0) SET_BALR(0) SET_ABADR(tmpbits | 1) //SET_VLDCTL(16) //ABF start SET_VLDCTL(80) //ABF start & change endian //} /* Initialize the JPEG compression object with default error handling. */ cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); //pwhsu:20031008 starting compression //pwhsu++:20031013 cinfo->global_state = CSTATE_START //pwhsu:20031013 error message /* Add some application-specific error messages (from cderror.h) */ jerr.addon_message_table = cdjpeg_message_table; jerr.first_addon_message = JMSG_FIRSTADDONCODE; jerr.last_addon_message = JMSG_LASTADDONCODE; /* Initialize JPEG parameters. * Much of this may be overridden later. * In particular, we don't yet know the input file's color space, * but we need to provide some value for jpeg_set_defaults() to work. */ cinfo.in_color_space = JCS_RGB; /* arbitrary guess */ jpeg_set_defaults(&cinfo); //pwhsu:20031013 for default setting of jpeg files #ifdef USE_INTERNAL_CPU pmdma->Status = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -