Question

how to get GIF Transparency color in vc++ 6.0 and vc++ 2005 ?

Was it helpful?

Solution

See the GIF specification. GIFs have a palette of up to 256 possible colors. The palette index of the background color can be found at offset 11 from the beginning of the file, and consists of a single byte (value 0-255). To find the actual color that this corresponds to, look up that color in the Global Color Table. See the spec for more information on how to parse the Global Color Table.

OTHER TIPS

I just implemented the GIF decoder. Here are the details - In case the

if(Graphics_Render_Block->transperencyflag) FrameInfo->transperencyindex=Graph_Renderblk.Transp_Clr_Index; else FrameInfo->transperencyindex='\0';

The logic is simple. While rendering on to the display, if transperencyindex == the color at the point, then don't render it. In face, move to the next location.

Here is the snippet of my display code - I am using Linux Framebuffer, but the logic will work for Microsoft VC also. Note, here I am ignoring the logical screen descriptor.

void Display(FrameData *FrameInfo)
{

    /*short int ImageStartX = 0;
    short int ImageStartY = 0; */
    unsigned int ImageStartX = 0;
    unsigned int ImageStartY = 0;
    int Index = 0;

    printf("\r\n INFO: Display Called.\r\n");

    while(1)
    {

        Index = 0;
        ImageStartX = (FrameInfo->frameScreenInfo.LeftPosition);
        ImageStartY = (FrameInfo->frameScreenInfo.TopPosition);


        while(ImageStartY < ((FrameInfo->frameScreenInfo.ImageHeight)+(FrameInfo->frameScreenInfo.TopPosition)))
        {

            while(ImageStartX < ((FrameInfo->frameScreenInfo.ImageWidth)+(FrameInfo->frameScreenInfo.LeftPosition)))
            {
                if(FrameInfo->frame[Index] != FrameInfo->transperencyindex)
                {
                  #ifndef __DISPLAY_DISABLE
                  SetPixel(local_display_mem,ImageStartX,ImageStartY,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Red,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Green,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Blue);
                  #endif

                   #ifdef DEBUG
                   count++;
                   #endif

                }


                Index++;
                ImageStartX++;
            }


            ImageStartY++;


            ImageStartX=(FrameInfo->frameScreenInfo.LeftPosition);


        }

        #ifdef DEBUG
        printf("INFO:..Dumping Framebuffer\r\n");
        printf("Pixel hit=%d\r\n",count);
        count = 0;
        printf("the Frameinfo.leftposition=%d FrameInfo->frameScreenInfo.topposition=%d\r\n",FrameInfo->frameScreenInfo.LeftPosition,FrameInfo->frameScreenInfo.TopPosition);
        printf("the Frameinfo.ImageWidth=%d FrameInfo->frameScreenInfo.ImageHeight=%d\r\n",FrameInfo->frameScreenInfo.ImageWidth,FrameInfo->frameScreenInfo.ImageHeight);
        #endif


       #ifndef __DISPLAY_DISABLE
       memcpy(fbp,local_display_mem,screensize);
       #endif

        /** Tune this multiplication to meet the right output on the display **/
        usleep((FrameInfo->InterFrameDelay)*10000);

        if( FrameInfo->DisposalMethod == 2)
        {
            printf("set the Background\r\n");
            #ifndef __DISPLAY_DISABLE
            SetBackground(FrameInfo);
            #endif
        }
        FrameInfo = FrameInfo->Next;

     }


}

The design I use is that decode all the frames, and make a singly circular link list. Now, keep displaying the frames. You can download the decoder logic and details from the following link - http://www.tune2wizard.com/gif-decoder/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top