请问下面这个代码的功能是什么?int CGif::GetCode(FILE *fd, int code_size, int flag)
{
static BYTE buf[280];
static int curbit, lastbit, done, last_byte;
int i,j,ret;
BYTE count; if (flag) 
{
curbit=0;
lastbit=0;
done=FALSE;
return 0;
} if ((curbit+code_size) >=lastbit) 
{
if (done) 
{
if (curbit >=lastbit) 
{
//m_strGIFError="Ran off the end of my bits";
return 0;
}
return -1;
}
buf[0]=buf[last_byte-2];
buf[1]=buf[last_byte-1]; if ((count=GetDataBlock(fd,&buf[2]))==0)
done=TRUE; last_byte=2+count; curbit=(curbit - lastbit) + 16; lastbit = (2+count)*8;
}
ret=0;
for (i=curbit,j=0; j<code_size;++i,++j)
ret|=((buf[i/8]&(1<<(i% 8)))!=0)<<j; curbit+=code_size; return ret;
}

解决方案 »

  1.   


    在看一个对GIF图片文件进行读写的程序中看到的 不晓得什么意思 贴上来问问
      

  2.   

    上面那个代码在对GIF解压的时候会调用到:int CGif::LZWReadByte(FILE *fd, int flag, int input_code_size)
    {
    static int fresh=FALSE;
    int code, incode;
    static int code_size, set_code_size;
    static int max_code, max_code_size;
    static int firstcode, oldcode;
    static int clear_code, end_code; static unsigned short  next[1<<MAX_LZW_BITS];
    static BYTE  vals[1<<MAX_LZW_BITS];
    static BYTE  stack [1<<(MAX_LZW_BITS+1)];
    static BYTE  *sp;

    register int i; if (flag) 
    {
    set_code_size=input_code_size;
    code_size=set_code_size+1;
    clear_code=1<<set_code_size;
    end_code = clear_code+1;
    max_code = clear_code+2;
    max_code_size=2*clear_code; GetCode(fd,0,TRUE); fresh=TRUE;

    for(i=0;i<clear_code;++i) 
    {
    next[i]=0;
    vals[i]=i;
    } for (;i<(1<<MAX_LZW_BITS);++i)
    next[i]=vals[0]=0;

    sp=stack; return 0;

    else if (fresh) 
    {
    fresh=FALSE;
    do 
    {
    firstcode=oldcode=GetCode(fd,code_size,FALSE);
    } while (firstcode==clear_code);
    return firstcode;
    } if (sp > stack)
    return *--sp; while ((code= GetCode(fd,code_size,FALSE)) >=0) 
    {
    if (code==clear_code) 
    {
    for (i=0;i<clear_code;++i) 
    {
    next[i]=0;
    vals[i]=i;
    }
    for (;i<(1<<MAX_LZW_BITS);++i)
    next[i]=vals[i]=0;
    code_size=set_code_size+1;
    max_code_size=2*clear_code;
    max_code=clear_code+2;
    sp=stack;
    firstcode=oldcode=GetCode(fd,code_size,FALSE);
    return firstcode;

    else if (code==end_code) 
    {
    int count;
    BYTE buf[260];

    if (ZeroDataBlock)
    return -2; while ((count=GetDataBlock(fd,buf)) >0); if (count!=0)
    //AfxMessageBox("Missing EOD in GIF data stream (common occurrence)",MB_OK);
    return -2;
    } incode = code; if (code >= max_code) 
    {
    *sp++=firstcode;
    code=oldcode;
    } while (code >=clear_code) 
    {
    *sp++=vals[code];
    if (code==(int)next[code]) 
    {
    //m_strGIFError="Circular table entry, big GIF Error!";
    return -1;
    }
    code=next[code];
    } *sp++ = firstcode=vals[code]; if ((code=max_code) <(1<<MAX_LZW_BITS)) 
    {
    next[code]=oldcode;
    vals[code]=firstcode;
    ++max_code;
    if ((max_code >=max_code_size) &&
    (max_code_size < (1<<MAX_LZW_BITS))) 
    {
     max_code_size*=2;
    ++code_size;
    }
    } oldcode=incode; if (sp > stack)
    return *--sp;
    }
    return code;
    }   
      

  3.   

    应该和gif的文件格式有关
    gif的文件格式中有没有code之类的部分