📄 myprogram.txt
字号:
{
(0-0) // stride
}
};
//myprintf("begin to draw...\n");
format.shape.x = imagewidth - 1; // width
format.shape.y = imageheight - 1;// height
format.stride[0] = (format.shape.x + 1) * 32;// stride in bits
hImage.pBits = pImage;
//imageSize = imagewidth * imageheight * 4;
if (TM_OK != (errcode = tmhwDrawWaitBusy(pDraw)))
{
#ifdef PRNT_ERRINFO
myprintf("The Device is busy,waiting failed.\n");
#endif
return ERR_RETURN;
}
// clearBox(pDraw, pPal, rect);
if (TM_OK != (errcode = tmhwDrawCreate(&pSrc, &format, &hImage)))
{
#ifdef PRNT_ERRINFO
myprintf("Creating Drawable failed.\n");
#endif
return ERR_RETURN;
}
else
{
#ifdef PRNT_DEBUGINFO
// myprintf("Creating Source Drawable Succeed.\n");
#endif
}
dstRect.ul.x = dstXY.x; //图像显示的起始位置x坐标
dstRect.ul.y = dstXY.y; //图像显示的起始位置y坐标
dstRect.lr.x = dstRect.ul.x + format.shape.x;
dstRect.lr.y = dstRect.ul.y + format.shape.y;
#ifdef PRNT_DEBUGINFO
{
// myprintf("dstRect.ul.x = %d\n",dstRect.ul.x);
// myprintf("dstRect.ul.y = %d\n",dstRect.ul.y);
}
#endif
if(
TM_OK != (
errcode = tmhwDrawBlt3Op(
pDraw,
&dstRect,
pSrc,
&srcPoint,
0,
1,
bltFlags
)
)
)
{
#ifdef PRNT_ERRINFO
myprintf("Drawable Blt3op failed.\n");
#endif
return ERR_RETURN;
}
else
{
#ifdef PRNT_DEBUGINFO
// myprintf("Drawable Blt3op Succeed.\n");
#endif
return SUCCESS_RETURN;
}
tmhwDrawDestroy(pSrc);
}
//------------------------------------------------------------------------------------------------------
//函数名: AntimateOp
//输 入: pDraw, dstXY, plinkhead, TimeDelay, pImage, opflg
//输 出: ERR_RETURN 或 SUCCESS_RETURN
//完成人: nxf
//完成日期: 2005-5-26
//描 述: 完成动画图像全部帧的显示。
//参数说明:
// 1. plinkhead - 指定图像的链表
// 2. TimeDelay - 帧间延时(ms)
// 3. opflg =
// 0: 终止动画
// 1: 启动动画
//------------------------------------------------------------------------------------------------------
int AntimateOp(
tmhwDrawable_t *pDraw, tmXY_t dstXY,
Imagelist *plinkhead, UInt32 TimeDelay,
UInt8 opflg//UInt32 *pImage,
)
{
Imagelist *p_tmp=NULL;
if((!plinkhead) || (!pDraw) || (TimeDelay < 0) ||\
dstXY.x > pDraw->shape.x || dstXY.y > pDraw->shape.y)
{
#ifdef PRNT_ERRINFO
myprintf("one or serveral input parameters maybe wrong.\n");
#endif
#ifdef PRNT_DEBUGINFO
{
if(pDraw)
{
myprintf("shape.x is %d\n",pDraw->shape.x);
myprintf("shape.y is %d\n",pDraw->shape.y);
}
else
myprintf("Drawable is NULL\n");
}
#endif
return ERR_RETURN;
}
p_tmp = plinkhead;
while(opflg)
{
if(SUCCESS_RETURN != AntimateCacheDisplay(pDraw,dstXY,\
p_tmp->imagewidth,p_tmp->imageheight, p_tmp->pData))
{
#ifdef PRNT_ERRINFO
myprintf("AntimateCacheDisplay failed.\n \
------------INFO------------\n \
Picture name is : %s \n \
Image_ID is : %d \n",p_tmp->pName,p_tmp->Image_ID);
#endif
return ERR_RETURN;
}
microsleep(1000*TimeDelay); //ms
p_tmp = p_tmp->pNext;
}
return SUCCESS_RETURN;
}
//------------------------------------------------------------------------------------------------------
//函数名: GetPicINFO
//输 入: plinkhead
//输 出: 函数返回图像名称
//完成人: nxf
//完成日期: 2005-5-26
//描 述: 返回指定链表头对应的图像名称。
//------------------------------------------------------------------------------------------------------
char *GetPicName(Imagelist *plinkhead)
{
return plinkhead->pName;
}
//--------------------------------GIF DECODER-----------------------------------------------------------//
BOOL initStrTable(STRING_TABLE_ENTRY* strTable,UINT rootSize)
{ UINT i;
unsigned char *cc;
for(i=0;i<rootSize;i++)
{ if((cc = (unsigned char *)malloc(2*sizeof(unsigned char))) == NULL)//if((cc = new unsigned char[2]) == NULL)
goto error;
cc[0] = i,cc[1] = 0;
strTable[i].p = cc;
strTable[i].len = 1;
}
return TRUE;
error:
for(i=0;i<rootSize;i++)
if(strTable[i].p != NULL)
{ free(strTable[i].p);//delete[] strTable[i].p;
strTable[i].p = NULL;
}
return FALSE;
}
BOOL addStrTable(STRING_TABLE_ENTRY* strTable,UINT addIdx,UINT idx,unsigned char c)
{ unsigned char *cc;
int i;
UINT l = strTable[idx].len;
if(addIdx >= 4096)
return FALSE;
if((cc = (unsigned char *)malloc((l+2)*sizeof(unsigned char))) == NULL)//if((cc = new unsigned char[l+2]) == NULL)
return FALSE;
for(i=0;i<l;i++)
cc[i] = strTable[idx].p[i];
cc[l] = c;
cc[l+1] = 0;
strTable[addIdx].p = cc;
strTable[addIdx].len = strTable[idx].len +1;
return TRUE;
}
BOOL extractData(FRAME* f,UInt8 *pOffs)
{
/*
STRING_TABLE_ENTRY *strTable;
UINT codeSize,rootSize,tableIndex,codeSizeBK;
int remainInBuf = 0,i;
UINT bufIndex = 0,outIndex = 0;
UINT bitIndex = 0;
DWORD code,oldCode;
BYTE be,*outP;
BYTE buf[262];
BOOL readOK = FALSE;
UINT bufLen = f->imageWidth*f->imageHeight;
UINT xx=0;
//初始化字符串表,共4096个入口条目
if((strTable = (STRING_TABLE_ENTRY *)malloc(4096 * sizeof(STRING_TABLE_ENTRY))) == NULL)//if((strTable = new STRING_TABLE_ENTRY[4096]) == NULL)
return FALSE;
ZeroMemory(strTable,4096*sizeof(STRING_TABLE_ENTRY));
outP = f->dataBuf = (BYTE *)malloc(bufLen * sizeof(BYTE));//outP = f->dataBuf = new BYTE[bufLen];
if(f->dataBuf == NULL)
{
free(strTable);
myprintf("malloc databuf failed.\n");
return FALSE;
}
//ZeroMemory(outP,bufLen*sizeof(BYTE));
be = *(pOffs++);//lzw编码位数
codeSizeBK = codeSize = be+1;
rootSize = 1;
rootSize <<= be; //rootsize = 2^(lzw编码位数)
tableIndex = rootSize+2;
if(!initStrTable(strTable,rootSize))
goto error;
//-------编码数据-------------//
//0x02, //LZW编码长度
//
//0x04, 0x94, 0x8f, 0xa9,
//0x58,
//
//0x00, 0x3b
//--------------------------//
begin:
if(remainInBuf<=4 && !readOK)
{
for(i=0;i<remainInBuf;i++)
buf[i] = buf[bufIndex+i];
bufIndex = 0;
be = *(pOffs++); //ifs.read((char*)&be,1);
if(be != 0)
{
for(i=0;i<be;i++)//ifs.read((char*)(buf+remainInBuf),be);
{
buf[remainInBuf + i] = *(pOffs++);
myprintf("buf[reamainInBuf + %d] is %x\n",i,buf[remainInBuf + i]);
}
remainInBuf += be;
}
else
readOK = TRUE;
}
if(remainInBuf<=4)
{
if(remainInBuf<=0 || codeSize > (remainInBuf*8-bitIndex))
{
myprintf("go to done.\n");
goto done;
}
}
code = *((DWORD*)(buf+bufIndex));
code <<= 32-codeSize-bitIndex;
code >>= 32-codeSize;
myprintf("code is %x\n",code);
bitIndex += codeSize;
bufIndex += bitIndex/8;
myprintf("bufIndex is %x\n",bufIndex);
remainInBuf -= bitIndex/8;
myprintf("remainInBuf is %x\n",remainInBuf);
bitIndex %= 8;
myprintf("bitIndex is %x\n",bitIndex);
if(code >= rootSize+1)
{
myprintf("goto error\n");
goto error;
}
if(code == rootSize)
{
myprintf("goto begin\n");
goto begin;
}
else
{
myprintf("enter else\n");
myprintf("before : outIndex is %d\n",outIndex);
outP[outIndex++] = *strTable[code].p;
myprintf("value : *strTable[%d].p = %x\n",code,(*strTable[code].p));
myprintf("after : outIndex is %d\n",outIndex);
for(i=0;i < outIndex;i++)
myprintf("outP[outIndex + %d] is %x\n",i,outP[i]);
oldCode = code;
}
for(;;)
{
if(remainInBuf<=4 && !readOK)
{
myprintf("now enter for cycel\n");
for(i=0;i<remainInBuf;i++)
{
buf[i] = buf[bufIndex+i];
myprintf("buf[%d] is %d\n",i,buf[bufIndex + i]);
}
bufIndex = 0;
be = *(pOffs++); //ifs.read((char*)&be,1);
myprintf("be is %d\n",be);
if(be != 0)
{
for(i=0;i<be;i++)//ifs.read((char*)(buf+remainInBuf),be);
buf[remainInBuf + i] = *(pOffs++);
remainInBuf += be;
}
else
readOK = TRUE;
}
myprintf("#-----remainInBuf is ------------%d\n",remainInBuf);
myprintf("#-----------begin------------------#\n");
for(i=0;i<remainInBuf;i++)
myprintf("buf[%d] is %d\n",i,buf[i]);
myprintf("#------------end-------------------#\n");
if(remainInBuf<=4)
if(remainInBuf<=0 || codeSize > (remainInBuf*8-bitIndex))
break;
code = *((DWORD*)(buf+bufIndex));
code <<= 32-codeSize-bitIndex;
code >>= 32-codeSize;
myprintf("codesize is %x\n",codeSize);
myprintf("code2 is %x\n",code);
bitIndex += codeSize;
bufIndex += bitIndex/8;
myprintf("bufIndex2 is %x\n",bufIndex);
remainInBuf -= bitIndex/8;
myprintf("remainInBuf2 is %x\n",remainInBuf);
bitIndex %= 8;
myprintf("bitIndex2 is %x\n",bitIndex);
if(code == rootSize)
{ codeSize = codeSizeBK;
for(i=rootSize;i<4096;i++)
if(strTable[i].p != NULL)
{ free(strTable[i].p);//delete strTable[i].p;
strTable[i].p = NULL;
strTable[i].len = 0;
}
tableIndex = rootSize+2;
myprintf("goto begin2\n");
goto begin;
}
else if(code == rootSize+1)
break;
else
{
unsigned char *p = strTable[code].p;
int l = strTable[code].len;
unsigned char c;
if(p != NULL)
{ c = *p;
if(outIndex+l <= bufLen)
for(i=0;i<l;i++)
outP[outIndex++] = *(p++);
else
{
myprintf("goto error2\n");
goto error;
}
if(!addStrTable(strTable,tableIndex++,oldCode,c))
{
myprintf("goto error3\n");
goto error;
}
oldCode = code;
}
else
{ p = strTable[oldCode].p;
l = strTable[oldCode].len;
c = *p;
if(outIndex+l+1 <= bufLen)
{ for(i=0;i<l;i++)
outP[outIndex++] = *(p++);
outP[outIndex++] = c;
}
else
{
myprintf("goto error4\n");
goto error;
}
if(!addStrTable(strTable,tableIndex++,oldCode,c))
{
myprintf("goto error5\n");
goto error;
}
oldCode = code;
}
if(tableIndex == (((UINT)1)<<codeSize) && codeSize != 12)
codeSize++;
}
}
done:
for(i=0;i<4096;i++)
if(strTable[i].p != NULL)
{ free(strTable[i].p);//delete strTable[i].p;
strTable[i].p = NULL;
}
free(strTable);//delete[] strTable;
return TRUE;
error:
for(i=0;i<4096;i++)
if(strTable[i].p != NULL)
{ free(strTable[i].p);//delete strTable[i].p;
strTable[i].p = NULL;
}
free(strTable);//delete[] strTable;
free(f->dataBuf);//delete[] f->dataBuf;
f->dataBuf = NULL;
return FALSE;
*/
STRING_TABLE_ENTRY *strTable;
// STRING_TABLE_ENTRY strTable[4096]={0};
UINT codeSize,rootSize,tableIndex,codeSizeBK;
int remainInBuf = 0,i;
UINT bufIndex = 0,outIndex = 0;
UINT bitIndex = 0;
DWORD code,oldCode;
BYTE be,*outP;
BYTE buf[262];
BOOL readOK = FALSE;
UINT bufLen = f->imageWidth*f->imageHeight;
// BYTE buff[36]={0};
if((strTable =(STRING_TABLE_ENTRY *)malloc(4096*sizeof(STRING_TABLE_ENTRY))) == NULL)
return FALSE;
ZeroMemory(strTable,sizeof(STRING_TABLE_ENTRY)*4096);
outP = f->dataBuf =(BYTE *)malloc(bufLen*sizeof(BYTE));
//ZeroMemory(f->dataBuf,bufLen*sizeof(BYTE));
// f->dataBuf = outP;
//outP = f->dataBuf = buff;
if(f->dataBuf == NULL)
{ free(strTable);
return FALSE;
}
//ifs.read((char*)&be,1);
be = (*(pOffs++));
/*-------------------------------------------------*/
myprintf("be1 in the extractdata is %x\n",be);
/*-------------------------------------------------*/
codeSizeBK = codeSize = be+1;
rootSize = 1;
rootSize <<= be;
tableIndex = rootSize+2;
if(!initStrTable(strTable,rootSize))
goto error;
begin:
if(remainInBuf<=4 && !readOK)
{ for(i=0;i<remainInBuf;i++)
buf[i] = buf[bufIndex+i];
bufIndex = 0;
be = (*(pOffs++));
/*-------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -