📄 myprogram.txt
字号:
myprintf("be2 in the extractdata is %x\n",be);
/*-------------------------------------------------*/
if(be != 0)
{
/*#################################################################*/
for(i=0;i<be;i++)
buf[remainInBuf + i] = (*(pOffs++));
/*#################################################################*/
for(i=0;i<be;i++)
myprintf("buf+remaininBuf+%d is %x\n",i,*(buf+remainInBuf+i));
remainInBuf += be;
}
else
readOK = TRUE;
// if(!ifs.good())
// goto error;
}
if(remainInBuf<=4)
if(remainInBuf<=0 || codeSize > (remainInBuf*8-bitIndex))
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)
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;
//f->dataBuf[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;
//ifs.read((char*)&be,1);
be = (*(pOffs++));
myprintf("be is %d\n",be);
if(be != 0)
{
//ifs.read((char*)(buf+remainInBuf),be);
/*#################################################################*/
for(i=0;i<be;i++)
buf[remainInBuf + i] = (*(pOffs++));
/*#################################################################*/
remainInBuf += be;
}
else
readOK = TRUE;
// if(!ifs.good())
// goto error;
}
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;
myprintf("before code2: bufIndex is %d\n",bufIndex);
code = *((DWORD*)(buf+bufIndex));
myprintf("code2 is %x\n",code);
code <<= 32-codeSize-bitIndex;
code >>= 32-codeSize;
myprintf("codesize is %x\n",codeSize);
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);
strTable[i].p = NULL;
strTable[i].len = 0;
}
tableIndex = rootSize+2;
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++)
// f->dataBuf[outIndex++] = *p++;
outP[outIndex++] = *p++;
else
goto error;
if(!addStrTable(strTable,tableIndex++,oldCode,c))
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++)
//f->dataBuf[outIndex++] = *p++;
outP[outIndex++] = *p++;
outP[outIndex++] = c;
}
else
goto error;
if(!addStrTable(strTable,tableIndex++,oldCode,c))
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);
strTable[i].p = NULL;
}
free(strTable);
return TRUE;
error:
for(i=0;i<4096;i++)
if(strTable[i].p != NULL)
{ free(strTable[i].p);
strTable[i].p = NULL;
}
free(strTable);
free(f->dataBuf);
f->dataBuf = NULL;
return FALSE;
}
LPCFRAME getNextFrame(UInt8 *pOffs)
{
BYTE be;
int i;
BOOL fileEnd = FALSE;
if(curFrame.pColorTable != NULL)
{ free(curFrame.pColorTable);//delete[] curFrame.pColorTable;
curFrame.pColorTable = NULL;
}
if(curFrame.dataBuf != NULL)
{ free(curFrame.dataBuf);//delete[] curFrame.dataBuf;
curFrame.dataBuf = NULL;
}
ZeroMemory(&curFrame,sizeof(FRAME));
while(TRUE)
{
be = *(pOffs++);//ifs.read((char*)&be,1);
switch(be)
{
case 0x21:
be = *(pOffs++); //ifs.read((char*)&be,1);
switch(be)
{
case 0xf9:
while((*pOffs)!=0x3b)
{
be = *(pOffs++);//ifs.read((char*)&be,1);
if(be == 0)
break;
if(be == 4)
{
ctrlExt.active = TRUE;
be = *(pOffs++);//ifs.read((char*)&be,1);
ctrlExt.disposalMethod = (be&0x1c)>>2;
if((be&0x02) != 0)
ctrlExt.userInputFlag = TRUE;
else
ctrlExt.userInputFlag = FALSE;
if((be&0x01) != 0)
ctrlExt.trsFlag = TRUE;
else
ctrlExt.trsFlag = FALSE;
be = (*(pOffs++)) + ((*(pOffs++))<<8);//ifs.read((char*)&ctrlExt.delayTime,2);
be = *(pOffs++);//ifs.read((char*)&be,1);
ctrlExt.trsColorIndex = be;
}
else
pOffs = pOffs + be; //ifs.seekg(be,ios::cur);
}
break;
case 0xfe:
case 0x01:
case 0xff:
while((*pOffs)!=0x3b)
{
be = *(pOffs++);//ifs.read((char*)&be,1);
if(be == 0)
break;
pOffs = pOffs + be;//ifs.seekg(be,ios::cur);
}
break;
default:
goto error;
}
break;
case 0x2c:
{
BYTE bp;
myprintf("getNextFrame:now enter case0x2c : %x\n",(*pOffs));
//ifs.read((char*)&curFrame.imageLPos,2);
curFrame.imageLPos = (*(pOffs++)) + ((*(pOffs++))<<8);
//ifs.read((char*)&curFrame.imageTPos,2);
curFrame.imageTPos = (*(pOffs++)) + ((*(pOffs++))<<8);
//ifs.read((char*)&curFrame.imageWidth,2);
curFrame.imageWidth = (*(pOffs++)) + ((*(pOffs++))<<8);
//ifs.read((char*)&curFrame.imageHeight,2);
curFrame.imageHeight = (*(pOffs++)) + ((*(pOffs++))<<8);
bp = *(pOffs++);//ifs.read((char*)&bp,1);
if((bp&0x80) != 0)
curFrame.lFlag = TRUE;
if((bp&0x40) != 0)
curFrame.interlaceFlag = TRUE;
if((bp&0x20) != 0)
curFrame.sortFlag = TRUE;
curFrame.lSize = 1;
curFrame.lSize <<= ((bp&0x07)+1);
if((curFrame.pColorTable =(BYTE *)malloc(curFrame.lSize * 3 * sizeof(BYTE))) == NULL)//if((curFrame.pColorTable = new BYTE[curFrame.lSize*3]) == NULL)
goto error;
if(curFrame.lFlag)
{//ifs.read((char*)curFrame.pColorTable,curFrame.lSize*3);
for(i=0;i<curFrame.lSize*3;i++)
(*(curFrame.pColorTable + i)) = (*(pOffs++));
}
myprintf("pDataStart is %x : %x\n",dataStart,(*dataStart));
myprintf("pOffs is %x : %x\n",pOffs,(*pOffs));
myprintf("subval is %d\n",(pOffs-dataStart));
myprintf("开始调用extractdata函数,此时的*pOffs = %x\n",(*pOffs));
if(!extractData(&curFrame,pOffs))
{
myprintf("调用extractdata 失败。\n");
goto error;
}
curFrame.ctrlExt = ctrlExt;
if(ctrlExt.active == TRUE)
ctrlExt.active = FALSE;
myprintf("getNextFrame 从 0x2c返回\n");
return &curFrame;
}
case 0x3b:
myprintf("getNextFrame 进入case 0x3b\n");
pOffs = dataStart; //ifs.seekg(dataStart);
break;
case 0x00:
break;
default:
goto error;
}
}
myprintf("从getNextFrame中的while循环跳出到这里\n");
return &curFrame;
error:
if(curFrame.pColorTable != NULL)
{ free(curFrame.pColorTable);//delete[] curFrame.pColorTable;
curFrame.pColorTable = NULL;
}
if(curFrame.dataBuf != NULL)
{ free(curFrame.dataBuf);//delete[] curFrame.dataBuf;
curFrame.dataBuf = NULL;
}
return NULL;
}
//------------------------------------------------------------------------------------------------------
//函数名: checkFrames
//输 入: plinkhead
//输 出: 函数返回图像名称
//完成人: nxf
//完成日期: 2005-5-26
//描 述: 返回指定链表头对应的图像名称。
//------------------------------------------------------------------------------------------------------
//checkFrames中的入口指针为图像块开始指针,退出时指针复位到开始值
UINT checkFrames(UInt8* pCurrent)
{ UInt8 be;
BOOL fileEnd = FALSE;
UInt32 frames=0;
UInt8 *pSave;
UInt8 *pCheckEnd1;
UInt8 *pCheckEnd2;
pSave = pCurrent;
pCheckEnd1 = pCurrent;
pCheckEnd2 = pCurrent;
while(((*pCurrent)!=0x3b) && !fileEnd)
{
be = *(pCurrent++);//ifs.read((char*)&be,1);
switch(be)
{
case 0x21:
be = *(pCurrent++);//ifs.read((char*)&be,1);
switch(be)
{
case 0xf9:
case 0xfe:
case 0x01:
case 0xff:
while((*pCurrent)!=0x3b)
{ be = *(pCurrent++);//ifs.read((char*)&be,1);
if(be == 0)
break;
pCurrent= pCurrent + be ;//ifs.seekg(be,ios::cur);
}
break;
default:
return 0;
}
break;
case 0x2c:
{
BYTE bp;
BOOL lFlag=FALSE;
UINT lSize=1;
frames++;
pCurrent = pCurrent + 8 ;//ifs.seekg(8,ios::cur);
bp = *(pCurrent++); //ifs.read((char*)&bp,1);
if((bp&0x80) != 0)
lFlag = TRUE;
lSize <<= ((bp&0x07)+1);
if(lFlag)
pCurrent = pCurrent + 3*lSize;//ifs.seekg(lSize*3,ios::cur);
be = *(pCurrent++);//ifs.read((char*)&be,1);
while((*pCurrent)!=0x3b)
{ //ifs.read((char*)&be,1);
be = *(pCurrent++);
if(be == 0)
break;
pCurrent = pCurrent + be ;//ifs.seekg(be,ios::cur);
}
break;
}
case 0x3b:
fileEnd = TRUE;
break;
case 0x00:
break;
default:
return 0;
}
}
pCurrent = pSave; // ifs.seekg(pos);
return frames;
}
BOOL OpenGIF(UInt8 *pGIF)
{ char cc[4];
BYTE be;
int i;
BOOL fileEnd = FALSE;
allFrames = NULL;
curIndex = 0;
curFrame.pColorTable = NULL;
curFrame.dataBuf = NULL;
ctrlExt.active = FALSE;
if(opened)
return FALSE;
if(!pGIF)
return FALSE;
cc[0] = *(pGIF++); //ifs.read(cc,3);
cc[1] = *(pGIF++);
cc[2] = *(pGIF++);
cc[3] = 0;
if(strncmp(cc,"GIF",3) != 0)
goto error;
// ifs.read(version,3);
version[0] = *(pGIF++);
version[1] = *(pGIF++);
version[2] = *(pGIF++);
version[3] = 0;
if(strncmp(version,"89a",3) > 0)
{
myprintf("version is %s\n",version);
goto error;
}
//ifs.read((char*)&gInfo.scrWidth,2);
gInfo.scrWidth = (*(pGIF++)) + ((*(pGIF++))<<8);
myprintf("ginfo.scrwidth is %d\n",gInfo.scrWidth);
//ifs.read((char*)&gInfo.scrHeight,2);
gInfo.scrHeight = (*(pGIF++)) + ((*(pGIF++))<<8);
myprintf("ginfo.scrwidth is %d\n",gInfo.scrHeight);
be = *(pGIF++); //ifs.read((char*)&be,1);
if((be&0x80) != 0)
gInfo.gFlag = TRUE;
else
gInfo.gFlag = FALSE;
gInfo.colorRes = ((be&0x70)>>4)+1;
if(gInfo.gFlag)
{ if((be&0x08) != 0)
gInfo.gSort = TRUE;
else
gInfo.gSort = FALSE;
gInfo.gSize = 1;
gInfo.gSize <<= ((be&0x07)+1);
}
be = *(pGIF++); //ifs.read((char*)&be,1);
gInfo.BKColorIdx = be;
be = *(pGIF++); //ifs.read((char*)&be,1);
gInfo.pixelAspectRatio = be;
if(gInfo.gFlag)
{ //ifs.read((char*)gColorTable,gInfo.gSize*3);
for(i=0;i<gInfo.gSize*3;i++)
gColorTable[i] = (*(pGIF++));
gInfo.gColorTable = gColorTable;
}
else
gInfo.gColorTable = NULL;
dataStart = pGIF;
if((gInfo.frames = checkFrames(dataStart)) == 0)
go
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -