CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Animated GIF

  1. #1
    Join Date
    Sep 1999
    Posts
    4

    Animated GIF

    Hello,

    I've to write an application that display animated GIF, HOW should I Proceed ?
    Is there MFC base class that handle this ??

    Thank...




  2. #2
    Join Date
    Sep 1999
    Location
    Manchester, UK
    Posts
    4

    Re: Animated GIF

    I have a class that you could have. Send me your email address and I'll forward it on.


  3. #3
    Join Date
    Apr 1999
    Posts
    70

    Re: Animated GIF

    I want to display a gif animation in a dialogbox how do i do this??


  4. #4
    Join Date
    Jun 1999
    Location
    Miami, FL
    Posts
    972

    Re: Animated GIF

    Please consider taking a bit of time to submit your class to CodeGuru. I'm sure some of use would love to use it!

    Thanks,
    Alvaro


  5. #5
    Join Date
    Apr 1999
    Location
    Michigan, USA
    Posts
    115

    Re: Animated GIF

    In the "ATL, COM, ActiveX" section of this site George Tersaakov has a control (with source code) for
    displaying an animated GIF.


  6. #6
    Join Date
    Sep 1999
    Posts
    4

    Re: Animated GIF

    I'Ve try the class of "Gary Grant" it's working but it's seem hard to handle correctly the transparent color. Send me your e-mail and I'll forward the Gary's Class to you ... :-)



  7. #7
    Join Date
    Sep 1999
    Location
    Manchester, UK
    Posts
    4

    Re: Animated GIF

    The class I have is basically from George Tersaakov. I took out (most of) the ActiveX stuff so I could use it more easily.
    It doesn't handle transparent GIFs. Also any bugs from George's class will be in this one also.
    There is some of the original ActiveX code in here still, but you can ignore this.
    Anyway, here is the code I use

    Header File GIF89.H

    #if !defined(AFX_GIF89_H__2B971083_F709_11D2_A159_00105A568B09__INCLUDED_)
    #define AFX_GIF89_H__2B971083_F709_11D2_A159_00105A568B09__INCLUDED_

    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // Gif89.h : header file
    //

    #define DISPOSAL_NO 0
    #define DISPOSAL_NOT 4
    #define DISPOSAL_RESTBACK 8
    #define DISPOSAL_RESTORE 12

    typedef struct
    {
    BYTE bit;
    WORD previouscode;
    WORD nextcode;
    } GIFTABLE;


    /////////////////////////////////////////////////////////////////////////////
    // CGif89 window

    class CGif89 : public CButton
    {
    // Construction
    public:
    CGif89();

    // Attributes
    public:

    protected:
    BOOL m_bAutoStart;
    BOOL m_bEmbed;
    BYTE m_cCurentByte,m_cPackedField;
    UINT m_uBitSize,m_uPrimaryBitSize;
    UINT m_uRemain,m_uReadByte,m_uBlockSize;
    int m_iWidth,m_iHeight;
    int m_iTop,m_iLeft;
    int m_iFinishCode,m_iResetCode;
    int m_iPass,m_iRow;
    int m_iWidth1;
    int m_iBackgroundColor;
    int m_iGifSize;
    int m_x,m_y;
    int m_iGlobalColorSize;
    int m_iDisposalMethod;
    BOOL m_bTransparentIndex;
    int m_iTransparentIndex;
    int m_iDelayTime;
    int m_iTotalReadByte;
    int m_iMaxByte;
    DWORD m_dwSpeed;
    COLORREF m_TransparentColor;
    HDC m_hDC;
    BYTE* m_pcGlobalColorTable;
    BYTE* m_pcBitmap;
    BYTE* m_pcGif;
    BYTE* m_pcGifTrack;
    BOOL m_bGlass;
    volatile int m_EndRun;
    HBITMAP m_hRedrawBitmap;
    int m_iGifWidth,m_iGifHeight;
    volatile BOOL m_bLockBitmap;
    TCHAR filename[_MAX_PATH];
    int flag;
    BOOL m_bRunMode;
    BOOL m_bAutoSize1;

    // Operations
    public:

    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CGif89)
    public:
    virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
    //}}AFX_VIRTUAL

    // Implementation
    public:
    void Stop();
    void Play();
    HBITMAP FirstImage(void);
    HBITMAP TakeIt(void);
    HBITMAP NextImage(void);
    BOOL Play1(void);
    BOOL Load(LPCTSTR name);
    virtual ~CGif89();

    protected:
    void Output(BYTE bit)
    {
    int tmp;
    if(m_cPackedField&0x40)
    {
    if(m_x==m_iWidth)
    {
    m_x=0;
    if(m_iPass==1)m_iRow+=8;
    if(m_iPass==2)m_iRow+=8;
    if(m_iPass==3)m_iRow+=4;
    if(m_iPass==4)m_iRow+=2;
    if(m_iRow>=m_iHeight){m_iPass+=1;m_iRow=16>>m_iPass;}
    }
    tmp=m_iRow*m_iWidth1+m_x;
    m_pcBitmap[tmp]=bit;
    m_x++;
    }
    else
    {
    if(m_x==m_iWidth){m_x=0;m_y++;}
    tmp=m_y*m_iWidth1+m_x;
    m_x++;
    }
    if(tmp>m_iMaxByte)return;
    m_pcBitmap[tmp]=bit;
    }

    BYTE GetByte(void)
    {
    if(m_uReadByte>=m_uBlockSize)
    {
    m_uBlockSize=*m_pcGifTrack++;
    m_uReadByte=0;
    m_iTotalReadByte+=m_uBlockSize+1;
    if(m_iTotalReadByte>m_iGifSize){m_iTotalReadByte-=m_uBlockSize+1;return 0xFF;}
    if(m_uBlockSize==0){m_pcGifTrack--;m_iTotalReadByte--;return 0xFF;}
    }
    m_uReadByte++;
    return *m_pcGifTrack++;
    }

    WORD GetCode(void)
    {
    UINT tmp1;
    BYTE tmp;
    tmp=1;
    if(m_uRemain>=m_uBitSize)
    {
    tmp<<=m_uBitSize;
    tmp--;
    tmp1=m_cCurentByte&tmp;
    m_cCurentByte>>=m_uBitSize;
    m_uRemain-=m_uBitSize;
    }
    else
    {
    tmp<<=m_uRemain;
    tmp--;
    tmp1=m_cCurentByte;
    m_cCurentByte=GetByte();
    tmp=1;
    if(8>=(m_uBitSize-m_uRemain))
    {
    tmp<<=(m_uBitSize-m_uRemain);
    tmp--;
    tmp1=(((UINT)(m_cCurentByte&tmp))<<m_uRemain)+tmp1;
    m_cCurentByte>>=(m_uBitSize-m_uRemain);
    m_uRemain=8-(m_uBitSize-m_uRemain);
    }
    else
    {
    tmp1=(((UINT)(m_cCurentByte))<<m_uRemain)+tmp1;
    m_cCurentByte=GetByte();
    tmp<<=m_uBitSize-m_uRemain-8;
    tmp--;
    tmp1=(((UINT)(m_cCurentByte&tmp))<<(m_uRemain+8))+tmp1;
    m_cCurentByte>>=m_uBitSize-m_uRemain-8;
    m_uRemain=8-(m_uBitSize-m_uRemain-8);
    }
    }
    return tmp1;
    }


    // Generated message map functions
    protected:
    //{{AFX_MSG(CGif89)
    // NOTE - the ClassWizard will add and remove member functions here.
    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()
    };

    /////////////////////////////////////////////////////////////////////////////

    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.

    #endif // !defined(AFX_GIF89_H__2B971083_F709_11D2_A159_00105A568B09__INCLUDED_)





    C++ File


    // Gif89.cpp : implementation file
    //

    #include "stdafx.h"
    #include "Gif89.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    /////////////////////////////////////////////////////////////////////////////
    // CGif89

    CGif89::CGif89()
    {
    m_bAutoStart=TRUE;
    m_bAutoSize1=TRUE;
    m_bEmbed=FALSE;
    m_pcGlobalColorTable=0;
    m_pcGif=0;
    m_iGifSize=0;
    m_iGlobalColorSize=0;
    m_bTransparentIndex=FALSE;
    m_iDelayTime=0;
    m_EndRun=0;
    m_dwSpeed=50;
    m_hRedrawBitmap=0;
    m_bLockBitmap=FALSE;
    flag=0;
    strcpy(filename,_T(""));
    // m_bWindowOnly=TRUE;
    // m_bNegotiatedWnd=FALSE;
    // m_bWndLess=FALSE;
    m_bRunMode=1;
    // m_bResizeNatural=TRUE;
    // m_bRecomposeOnResize=TRUE;
    m_bGlass=FALSE;
    }

    CGif89::~CGif89()
    {
    Stop();
    if(m_hRedrawBitmap!=0)
    DeleteObject(m_hRedrawBitmap);
    if(m_pcGlobalColorTable!=NULL)
    delete[] m_pcGlobalColorTable;
    if(m_pcGif!=NULL)
    delete[] m_pcGif;
    }


    BEGIN_MESSAGE_MAP(CGif89, CButton)
    //{{AFX_MSG_MAP(CGif89)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    /////////////////////////////////////////////////////////////////////////////
    // CGif89 message handlers

    BOOL CGif89::Load(LPCTSTR filename)
    {
    HANDLE hFile;
    DWORD size,size1,readbyte;
    BYTE temp[13];

    if(m_bEmbed)
    return FALSE;
    //free memory from previous image
    Stop();
    if(m_pcGlobalColorTable!=NULL)
    delete[] m_pcGlobalColorTable;
    if(m_pcGif!=NULL)
    delete[] m_pcGif;
    if(m_hRedrawBitmap!=0)
    {
    DeleteObject(m_hRedrawBitmap);
    m_hRedrawBitmap=0;
    };
    m_pcGlobalColorTable=m_pcGif=0;
    m_iTotalReadByte=0;
    m_iGifSize=m_iGlobalColorSize=0;

    hFile=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL);
    if(INVALID_HANDLE_VALUE==hFile)
    return FALSE;
    size=GetFileSize(hFile,&size1);
    if(size==0xFFFFFFFF)
    {
    CloseHandle(hFile);
    return FALSE;
    }
    ReadFile(hFile,temp,13,&readbyte,NULL);
    if((readbyte!=13)||((temp[0]!='G')||(temp[1]!='I')||(temp[2]!='F')||(temp[3]!='8')||((temp[4]!='7')&&(temp[4]!='9'))||(temp[5]!='a')))
    {
    CloseHandle(hFile);
    return FALSE;
    }
    m_iGifWidth=*(WORD*)(temp+6);
    m_iGifHeight=*(WORD*)(temp+8);
    m_iBackgroundColor=temp[11];
    if(temp[10]&0x80)
    {
    m_iGlobalColorSize=0x01<<((temp[10]&0x07)+1);
    m_pcGlobalColorTable=new BYTE[3*m_iGlobalColorSize];
    ReadFile(hFile,m_pcGlobalColorTable,3*m_iGlobalColorSize,&readbyte,NULL);
    if(readbyte!=3*m_iGlobalColorSize)
    {
    delete[] m_pcGlobalColorTable;
    m_pcGlobalColorTable=0;
    m_iGlobalColorSize=0;
    CloseHandle(hFile);
    return FALSE;
    }
    }

    m_iGifSize=size-3*m_iGlobalColorSize-12;
    m_pcGifTrack=m_pcGif=new BYTE[m_iGifSize];
    ReadFile(hFile,m_pcGif,m_iGifSize,&readbyte,NULL);
    CloseHandle(hFile);
    return TRUE;

    }

    BOOL CGif89::Play1()
    {
    HDC hDC,hMemDC,hMemDC1;
    HBITMAP hOldBitmap,hOldBitmap1,hBitmap,hPreviousBitmap;
    DWORD systimer1,systimer2,speed;
    hDC=::GetDC(m_hWnd);
    hMemDC=::CreateCompatibleDC(hDC);
    hMemDC1=::CreateCompatibleDC(hDC);
    m_hDC=hDC;
    hPreviousBitmap=0;
    while(m_bLockBitmap)
    continue;
    m_bLockBitmap=TRUE;
    if(m_hRedrawBitmap!=0)
    DeleteObject(m_hRedrawBitmap);
    m_hRedrawBitmap=::CreateCompatibleBitmap(hDC,m_iGifWidth,m_iGifHeight);
    hOldBitmap1=(HBITMAP)SelectObject(hMemDC1,m_hRedrawBitmap);
    ::BitBlt(hMemDC1,0,0,m_iGifWidth,m_iGifHeight,hDC,0,0,SRCCOPY);
    SelectObject(hMemDC1,hOldBitmap1);
    m_bLockBitmap=FALSE;
    m_iDisposalMethod=DISPOSAL_NOT;
    while(m_EndRun!=1)
    {
    systimer2=systimer1=GetTickCount();
    while(m_bLockBitmap)
    continue;

    m_bLockBitmap=TRUE;
    hOldBitmap1=(HBITMAP)SelectObject(hMemDC1,m_hRedrawBitmap);
    //****************************************************
    //Restore Background
    switch(m_iDisposalMethod)
    {
    case DISPOSAL_NO:
    break;
    case DISPOSAL_NOT:
    break;
    case DISPOSAL_RESTBACK:
    case DISPOSAL_RESTORE:
    hOldBitmap=(HBITMAP)SelectObject(hMemDC,hPreviousBitmap);
    ::BitBlt(hMemDC1,m_iLeft,m_iTop,m_iWidth,m_iHeight,hMemDC,0,0,SRCCOPY);
    SelectObject(hMemDC,hOldBitmap);
    DeleteObject(hPreviousBitmap);
    hPreviousBitmap=0;
    break;
    }

    m_iDisposalMethod=DISPOSAL_NO;
    //***************************************************
    //Start Output Image
    hBitmap=NextImage();
    switch(m_iDisposalMethod)
    {
    case DISPOSAL_NO:
    break;
    case DISPOSAL_NOT:
    break;
    case DISPOSAL_RESTBACK:
    // break;
    case DISPOSAL_RESTORE:
    hPreviousBitmap=::CreateCompatibleBitmap(hDC,m_iWidth,m_iHeight);
    hOldBitmap=(HBITMAP)SelectObject(hMemDC,hPreviousBitmap);
    ::BitBlt(hMemDC,0,0,m_iWidth,m_iHeight,hMemDC1,m_iLeft,m_iTop,SRCCOPY);
    SelectObject(hMemDC,hOldBitmap);
    break;
    }
    hOldBitmap=(HBITMAP)SelectObject(hMemDC,hBitmap);
    if(m_bTransparentIndex)
    {
    HBITMAP bmAndBack, bmAndObject;
    HBITMAP bmBackOld, bmObjectOld;
    HDC hdcBack, hdcObject;
    COLORREF cColor;

    hdcBack=::CreateCompatibleDC(hDC);
    hdcObject=::CreateCompatibleDC(hDC);
    bmAndBack=CreateBitmap(m_iWidth,m_iHeight,1,1,NULL);
    bmAndObject=CreateBitmap(m_iWidth,m_iHeight,1,1,NULL);
    bmBackOld=(HBITMAP)SelectObject(hdcBack,bmAndBack);
    bmObjectOld=(HBITMAP)SelectObject(hdcObject,bmAndObject);
    cColor=SetBkColor(hMemDC,m_TransparentColor);
    ::BitBlt(hdcObject,0,0,m_iWidth,m_iHeight,hMemDC,0,0,SRCCOPY);
    SetBkColor(hMemDC,cColor);
    ::BitBlt(hdcBack,0,0,m_iWidth,m_iHeight,hdcObject,0,0,NOTSRCCOPY);
    ::BitBlt(hMemDC1,m_iLeft,m_iTop,m_iWidth,m_iHeight,hdcObject,0,0,SRCAND);
    ::BitBlt(hMemDC,0,0,m_iWidth,m_iHeight,hdcBack,0,0,SRCAND);
    ::BitBlt(hMemDC1,m_iLeft,m_iTop,m_iWidth,m_iHeight,hMemDC,0,0,SRCPAINT);
    DeleteObject(SelectObject(hdcBack,bmBackOld));
    DeleteObject(SelectObject(hdcObject,bmObjectOld));
    DeleteDC(hdcBack);
    DeleteDC(hdcObject);
    }
    else
    {
    ::BitBlt(hMemDC1,m_iLeft,m_iTop,m_iWidth,m_iHeight,hMemDC,0,0,SRCCOPY);
    }
    SelectObject(hMemDC,hOldBitmap);
    DeleteObject(hBitmap);
    ::BitBlt(hDC,0,0,m_iGifWidth,m_iGifHeight,hMemDC1,0,0,SRCCOPY);
    SelectObject(hMemDC1,hOldBitmap1);
    m_bLockBitmap=FALSE;
    if(m_iDelayTime!=0)
    speed=m_iDelayTime*10;
    else
    speed=m_dwSpeed;
    while((m_EndRun!=1) && (speed>systimer2-systimer1))
    {
    Sleep(10);
    systimer2=GetTickCount();
    }
    }
    if(hPreviousBitmap!=0)
    DeleteObject(hPreviousBitmap);
    DeleteDC(hMemDC);
    DeleteDC(hMemDC1);
    ::ReleaseDC(m_hWnd,hDC);
    m_EndRun=2;
    return TRUE;

    }

    HBITMAP CGif89::FirstImage()
    {
    m_pcGifTrack=m_pcGif;
    m_iTotalReadByte=0;
    return NextImage();
    }

    void CGif89:rawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    {
    while(m_bLockBitmap);
    m_bLockBitmap=TRUE;
    HBITMAP old;
    // HBRUSH br;
    // OLE_COLOR backcolor;
    RECT& rc = lpDrawItemStruct->rcItem;
    // COLORREF cl;
    HDC dc=::CreateCompatibleDC(lpDrawItemStruct->hDC);
    old=(HBITMAP)::SelectObject(dc,m_hRedrawBitmap);
    ::BitBlt(lpDrawItemStruct->hDC,0,0,m_iGifWidth,m_iGifHeight,dc,0,0,SRCCOPY);
    ::SelectObject(dc,old);
    m_bLockBitmap=FALSE;
    DeleteDC(dc);
    }

    DWORD WINAPI ThreadFunc(CGif89* ptr)
    {
    ptr->Play1();
    return 0;
    }


    void CGif89::Play()
    {
    HANDLE hThread;
    DWORD ThreadId;
    if(m_hWnd==0)
    return ;
    if(m_pcGif==0)
    return ;
    if(m_EndRun==5)
    return ;

    m_pcGifTrack=m_pcGif;
    m_iTotalReadByte=0;
    m_EndRun=5;
    hThread=CreateThread(NULL,0,(unsigned long(_stdcall*)(void*))ThreadFunc,this,0,&ThreadId);

    CloseHandle(hThread);
    }

    void CGif89::Stop()
    {
    if(m_EndRun!=5)
    return ;
    m_EndRun=1;
    while(m_EndRun!=2)
    continue;
    }

    HBITMAP CGif89::NextImage(void)
    {
    if(m_pcGif==NULL)
    return 0;
    l1: if(m_iTotalReadByte>m_iGifSize)
    {
    m_pcGifTrack=m_pcGif;
    m_iTotalReadByte=0;
    return 0;
    }
    m_iTotalReadByte++;
    switch(*m_pcGifTrack++)
    {
    case 0x2C:
    return TakeIt();
    break;
    case 0x21:
    BYTE cSize;
    m_iTotalReadByte++;
    switch(*m_pcGifTrack++)
    {
    case 0xF9:
    m_pcGifTrack++;//block size
    m_iDisposalMethod=(*m_pcGifTrack)&28;
    m_bTransparentIndex=(*m_pcGifTrack++)&1;
    m_iDelayTime=*(WORD*)m_pcGifTrack;
    m_pcGifTrack+=2;
    m_iTransparentIndex=*m_pcGifTrack++;
    m_iTotalReadByte+=5;
    break;
    case 0xFE:
    while((cSize=*m_pcGifTrack)!=0){m_pcGifTrack+=cSize+1;m_iTotalReadByte+=cSize+1;if(m_iTotalReadByte>m_iGifSize)return 0;}
    break;
    case 0x01:
    m_pcGifTrack+=13;
    m_iTotalReadByte+=13;
    while((cSize=*m_pcGifTrack)!=0){m_pcGifTrack+=cSize+1;m_iTotalReadByte+=cSize+1;if(m_iTotalReadByte>m_iGifSize)return 0;}
    break;
    case 0xFF:
    m_pcGifTrack+=12;
    m_iTotalReadByte+=12;
    while((cSize=*m_pcGifTrack)!=0){m_pcGifTrack+=cSize+1;m_iTotalReadByte+=cSize+1;if(m_iTotalReadByte>m_iGifSize)return 0;}
    break;
    default:
    return FALSE;
    }
    m_pcGifTrack++;
    m_iTotalReadByte++;
    if(m_iTotalReadByte>m_iGifSize)return 0;
    goto l1;
    break;
    case 0x3B:
    m_pcGifTrack=m_pcGif;
    m_iTotalReadByte=0;
    goto l1;
    case 0:
    m_pcGifTrack=m_pcGif;
    m_iTotalReadByte=0;
    goto l1;
    default:
    return FALSE;
    }
    }

    HBITMAP CGif89::TakeIt(void)
    {
    UINT uLocalColorTableSize;
    WORD code,oldcode,code1;
    int iFinishCode,iResetCode;
    int iPrimaryTableSize,iTableSize;
    BITMAPINFOHEADER *bitmapheader;
    BYTE *pcColorTable;
    BYTE *pcInfo;
    GIFTABLE *pcGifTable;
    HBITMAP hBitmap;
    m_iLeft=*(WORD*)m_pcGifTrack;
    m_pcGifTrack+=2;
    m_iTop=*(WORD*)m_pcGifTrack;
    m_pcGifTrack+=2;
    m_iWidth=*(WORD*)m_pcGifTrack;
    m_pcGifTrack+=2;
    m_iWidth1=((m_iWidth-1)|0x3)+1;
    m_iHeight=*(WORD*)m_pcGifTrack;
    m_pcGifTrack+=2;
    m_cPackedField=*m_pcGifTrack++;
    m_iTotalReadByte+=9;
    m_iMaxByte=m_iWidth1*m_iHeight;
    pcInfo=new BYTE[256*sizeof(RGBQUAD)+sizeof(BITMAPINFOHEADER)+m_iMaxByte+sizeof(GIFTABLE)*4096];
    //1-BITMAPINFOHEADER
    //2-COLORTABLE
    //3-Bitmap bits
    //4-GIFTABLE;
    bitmapheader=(BITMAPINFOHEADER*)pcInfo;
    pcColorTable=pcInfo+sizeof(BITMAPINFOHEADER);
    m_pcBitmap=pcColorTable+256*sizeof(RGBQUAD);
    pcGifTable=(GIFTABLE*)(m_pcBitmap+m_iMaxByte);
    for(int i=0;i<4096;i++)pcGifTable[i].previouscode=pcGifTable[i].nextcode=0;
    bitmapheader->biSize=sizeof(BITMAPINFOHEADER);
    bitmapheader->biWidth=m_iWidth;
    bitmapheader->biHeight=-m_iHeight;
    bitmapheader->biPlanes=1;
    bitmapheader->biBitCount=8;
    bitmapheader->biCompression=BI_RGB;
    bitmapheader->biSizeImage=0;
    bitmapheader->biXPelsPerMeter=0;
    bitmapheader->biYPelsPerMeter=0;
    bitmapheader->biClrUsed=256;
    bitmapheader->biClrImportant=256;

    if(m_cPackedField&0x80)
    {
    uLocalColorTableSize=1;
    uLocalColorTableSize<<=(m_cPackedField&7)+1;
    if(m_bTransparentIndex)
    {
    m_TransparentColor=RGB(m_pcGifTrack[m_iTransparentIndex*3],m_pcGifTrack[m_iTransparentIndex*3+1],m_pcGifTrack[m_iTransparentIndex*3+2]);
    }
    m_iTotalReadByte+=uLocalColorTableSize*3;
    for(UINT i=0;i<uLocalColorTableSize;i++)
    {
    pcColorTable[2]=*m_pcGifTrack++;
    pcColorTable[1]=*m_pcGifTrack++;
    pcColorTable[0]=*m_pcGifTrack++;
    pcColorTable[3]=0;
    pcColorTable+=4;
    }

    }
    else
    {
    BYTE *pcGlobalColor=m_pcGlobalColorTable;
    if(m_bTransparentIndex)
    {
    m_TransparentColor=RGB(pcGlobalColor[m_iTransparentIndex*3],pcGlobalColor[m_iTransparentIndex*3+1],pcGlobalColor[m_iTransparentIndex*3+2]);
    }
    for(int i=0;i<m_iGlobalColorSize;i++)
    {
    pcColorTable[2]=*pcGlobalColor++;
    pcColorTable[1]=*pcGlobalColor++;
    pcColorTable[0]=*pcGlobalColor++;
    pcColorTable[3]=0;
    pcColorTable+=4;
    }
    }
    m_uPrimaryBitSize=m_uBitSize=(*m_pcGifTrack++);
    m_iTotalReadByte++;
    iPrimaryTableSize=iTableSize=(1<<m_uBitSize)+2;
    iFinishCode=iTableSize-1;
    iResetCode=iFinishCode-1;

    m_uPrimaryBitSize++;
    m_uBitSize++;
    m_uRemain=0;
    m_cCurentByte=0;
    m_uBlockSize=0;
    m_uReadByte=1;
    m_x=m_y=0;
    m_iPass=1;m_iRow=0;
    while((code=GetCode())!=iFinishCode)
    {
    if(code==iResetCode)
    {
    m_uBitSize=m_uPrimaryBitSize;
    iTableSize=iPrimaryTableSize;
    oldcode=GetCode();
    if(oldcode>iTableSize){delete[] pcInfo;return 0;}
    Output((BYTE)oldcode);
    continue;
    }
    if(code<iTableSize) //<code> exist in the string pcGifTable
    {
    code1=code;
    WORD code2=0;
    while(code1>=iPrimaryTableSize)
    {
    pcGifTable[code1].nextcode=code2;
    code2=code1;
    code1=pcGifTable[code1].previouscode;
    if(code1>=code2){delete[] pcInfo;return 0;}
    }
    Output((BYTE)code1);
    while(code2!=0)
    {
    Output(pcGifTable[code2].bit);
    code2=pcGifTable[code2].nextcode;
    }
    pcGifTable[iTableSize].bit=(BYTE)code1;
    pcGifTable[iTableSize].previouscode=oldcode;
    iTableSize++;
    if(iTableSize==(0x0001<<m_uBitSize))m_uBitSize++;
    if(m_uBitSize>12)m_uBitSize=12;
    oldcode=code;
    }
    else //<code> doesn't exist in the string pcGifTable
    {
    code1=oldcode;
    WORD code2=0;
    while(code1>=iPrimaryTableSize)
    {
    pcGifTable[code1].nextcode=code2;
    code2=code1;
    code1=pcGifTable[code1].previouscode;
    if(code1>=code2){delete[] pcInfo;return 0;}
    }
    Output((BYTE)code1);
    while(code2!=0)
    {
    Output(pcGifTable[code2].bit);
    code2=pcGifTable[code2].nextcode;
    }
    Output((BYTE)code1);
    pcGifTable[iTableSize].bit=(BYTE)code1;
    pcGifTable[iTableSize].previouscode=oldcode;
    iTableSize++;
    if(iTableSize==(0x0001<<m_uBitSize))m_uBitSize++;
    if(m_uBitSize>12)m_uBitSize=12;
    oldcode=code;
    }
    }

    hBitmap=CreateDIBitmap(m_hDC,bitmapheader,CBM_INIT,m_pcBitmap,(BITMAPINFO*)pcInfo,DIB_RGB_COLORS);
    m_pcGifTrack++;
    m_iTotalReadByte++;
    delete[] pcInfo;
    return hBitmap;
    }







  8. #8
    Guest

    Re: Animated GIF

    My Id: [email protected]
    Thankx for the Reply..


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured