📄 tijpeg.c
字号:
#include "std.h"
#include "celljpegenc_ti.h"
#include "acpy2_6x1x.h"
#include "dman.h"
#include "chan.h"
#include "csl.h"
#include "csl_cache.h"
#include "ijpegenc.h"
#include "ijpegdec.h"
static ICC_Handle inputIcc;
static ICC_Handle outputIcc;
static ICELL_Obj cell = ICELL_DEFAULT;
static CHAN_Obj chan;
//static IJPEGENC_Params jpegencParams;
extern far IJPEGENC_Fxns JPEGENC_TI_IJPEGENC;
static int s_nWidth, s_nHeight;
static int s_nOutHeight;
#define HC 1600
#define VC 1200
#define H 1600
#define V 1200
IJPEGENC_Params IJPEGENC_PARAMS =
{
sizeof(IJPEGENC_Params),
8, /* unsigned int sample_prec; */
3, /* unsigned int num_comps; */
2, /* unsigned int num_qtables; */
0, /* unsigned int interleaved; */
0x01120112, /* unsigned int formatflag for 4:2:0; */
100, /* unsigned int quality; */
V, (V/2), (V/2), /* unsigned int num_lines 4:2:0; */
H, (H/2), (H/2), /* unsigned int num_samples; */
HC,(HC/2),(HC/2) /*unsigned int pitch;*/
};
/*
* ======== JPEGDEC_PARAMS ========
* This constant structure defines the default parameters for JPEGDEC objects
*/
IJPEGDEC_Params IJPEGDEC_PARAMS =
{
sizeof(IJPEGDEC_Params),
HC, (HC >>1), (HC >> 1)
};
/////////////////////////////////////////////////////////////////
void JPEG_init(int nWidth, int nHeight, int nIntHeapNum, int nExtHeapNum, unsigned int nQuality)
{
s_nWidth = nWidth;
s_nHeight = nHeight;
s_nOutHeight = nHeight & 0xFFFFFFF0;
IJPEGENC_PARAMS.quality = nQuality;
IJPEGENC_PARAMS.numLines[0] = s_nOutHeight;
IJPEGENC_PARAMS.numLines[1] = s_nOutHeight >> 1;
IJPEGENC_PARAMS.numLines[2] = s_nOutHeight >> 1;
IJPEGENC_PARAMS.numSamples[0] = s_nWidth;
IJPEGENC_PARAMS.numSamples[1] = s_nWidth >> 1;
IJPEGENC_PARAMS.numSamples[2] = s_nWidth >> 1;
IJPEGENC_PARAMS.pitch[0] = s_nWidth;
IJPEGENC_PARAMS.pitch[1] = s_nWidth >> 1;
IJPEGENC_PARAMS.pitch[2] = s_nWidth >> 1;
ACPY2_6X1X_init();
DMAN_init();
DMAN_setup(nIntHeapNum);
/* initialize RF5 modules */
CHAN_init(); //这个函数不执行任何操作
ICC_init(); //这个函数不执行任何操作
/* setup chan module Ratna - Modified */
CHAN_setup(nIntHeapNum, nExtHeapNum, nIntHeapNum, 1, NULL, NULL);
JPEGENC_TI_init();
// jpegencParams = IJPEGENC_PARAMS;
cell.name = "JPEGENC";
cell.cellFxns = &JPEGENC_CELLFXNS;
cell.algFxns = (IALG_Fxns *)&JPEGENC_TI_IJPEGENC;
cell.algParams = (IALG_Params *)&IJPEGENC_PARAMS;
cell.scrBucketIndex = 0;
//inputIcc->obj.buffer = NULL;
//inputIcc->obj.nmaus = 0;
//inputIcc->obj.objType = ICC_LINEAROBJ(1);
inputIcc = (ICC_Handle)ICC_linearCreate(NULL, 0);
//outputIcc->obj.buffer = NULL;
//outputIcc->obj.nmaus = 0;
//outputIcc->obj.objType = ICC_LINEAROBJ(1);
outputIcc = (ICC_Handle)ICC_linearCreate(NULL, 0);
CHAN_regCell(&cell, &inputIcc, 1, &outputIcc, 1);
cell.algParams = (IALG_Params *)&IJPEGENC_PARAMS;
CHAN_open(&chan, &cell, 1, NULL);
}
/////////////////////////////////////////////////////////////////
static void yuyv2yyyyuv(unsigned char *pYUYV, unsigned char *pY, unsigned char *pU, unsigned char *pV, int nWidth, int nHeight)
{
int i, j;
for(i = 0; i < nHeight; i += 2)
{
//y u
for(j = 0; j < nWidth; j += 4)
{
pY[0] = pYUYV[0];
pY[1] = pYUYV[2];
pY[2] = pYUYV[4];
pY[3] = pYUYV[6];
pU[0] = pYUYV[1];
pU[1] = pYUYV[5];
pYUYV += 8;
pY += 4;
pU += 2;
}
//y v
for(j = 0; j < nWidth; j += 4)
{
pY[0] = pYUYV[0];
pY[1] = pYUYV[2];
pY[2] = pYUYV[4];
pY[3] = pYUYV[6];
pV[0] = pYUYV[3];
pV[1] = pYUYV[7];
pYUYV += 8;
pY += 4;
pV += 2;
}
}
}
void JPEG_enc(char *pInput, char *pTemp, int *pLen)
{
void *inBuf[3];
void *outBuf[3];
static unsigned int framenum = 0;
framenum ++;
inBuf[0] = pTemp;
inBuf[1] = pTemp + s_nWidth * s_nHeight;
inBuf[2] = pTemp + (s_nWidth * s_nHeight * 5 >> 2);
CACHE_clean(CACHE_L2ALL, NULL, 0);
yuyv2yyyyuv((unsigned char *)pInput, (unsigned char *)inBuf[0], (unsigned char *)inBuf[1], (unsigned char *)inBuf[2], s_nWidth, s_nOutHeight);
chan.state = CHAN_ACTIVE;
ICC_setBuf(chan.cellSet[0].inputIcc[0], inBuf, sizeof(void *) * 3);
outBuf[0] = pLen;
outBuf[1] = pInput;
ICC_setBuf(chan.cellSet[0].outputIcc[0], outBuf, sizeof(Void *) * 2);
CACHE_clean(CACHE_L2ALL, NULL, 0);
CHAN_execute(&chan, framenum);
// chan.state = CHAN_INACTIVE;
}
void JPEG_control(int nWidth, int nHeight, unsigned int nQuality)
{
s_nWidth = nWidth;
s_nHeight = nHeight;
s_nOutHeight = s_nHeight & 0xFFFFFFF0;
if ((nQuality > 0) && (nQuality <= 100))
{
IJPEGENC_PARAMS.quality = nQuality;
IJPEGENC_PARAMS.numLines[0] = s_nOutHeight;
IJPEGENC_PARAMS.numLines[1] = s_nOutHeight >> 1;
IJPEGENC_PARAMS.numLines[2] = s_nOutHeight >> 1;
IJPEGENC_PARAMS.numSamples[0] = s_nWidth;
IJPEGENC_PARAMS.numSamples[1] = s_nWidth >> 1;
IJPEGENC_PARAMS.numSamples[2] = s_nWidth >> 1;
IJPEGENC_PARAMS.pitch[0] = s_nWidth;
IJPEGENC_PARAMS.pitch[1] = s_nWidth >> 1;
IJPEGENC_PARAMS.pitch[2] = s_nWidth >> 1;
cell.cellFxns->cellControl
(
&cell,
(IALG_Cmd)(IJPEG_SETSTATUS),
(IALG_Status *)(&IJPEGENC_PARAMS)
);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -