繁体   English   中英

如何在绘制多个框架时停止linux framebuffer自动清除

[英]how to stop linux framebuffer to clear automatically while drawing multiple frames

我正在编写gif解码器,此图像是动画图像。当我编写第一帧时,它显示得很好。 当我显示第二帧时,它仅显示更改的像素。 其他像素会自动变为黑色。 我不知道为什么?

我的第一帧有完整的图片。 第二帧再次仅改变了像素,并且包含其余未改变的像素。

现在,当我绘制第二个缓冲区时,它也会重新绘制未更改的像素。 并且未更改的像素被绘制为黑色(或者恰好在监视器中,我看到这些未更改的像素不存在)。 那是当它必须绘制第二帧时,它绘制更改的像素(这是正确的),但它也重新绘制未更改的像素。 并且此未更改的像素被视为黑色(无颜色)。 我觉得这是一个令人耳目一新的问题。 或者这可能是另外一回事。 感谢帮助。

必需:应重新绘制完整图像。 简而言之,这是我的功能片段。

不幸的是,它清除了以前的显示-linux framebuffer。 我想停止清除Linux帧缓冲区。

这是完整的文件。

/** This is using the Direct Fb calls here; and is tightly coupled with Linux Framebuffer **/
static int fbfd = 0;
static struct fb_var_screeninfo vinfo;
static struct fb_fix_screeninfo finfo;
static long int screensize = 0;
static char *fbp = 0;
static int x = 0, y = 0;
static long int location = 0;

/** This is a clone to linux Frame buffer, and will be called to dump on Framebuffer **/
char *local_display_mem;

/** local functions **/
static void SetBackground(FrameData *tempInfo);
static void SetPixel(char *fbp, unsigned int x, unsigned int y, Byte red, Byte green, Byte blue);


/** This is the entry function to initialize the display **/
void display_init()
{

    // Open the file for reading and writing
    fbfd = open("/dev/fb0", O_RDWR);
    if (fbfd == -1)
    {
        perror("cannot open framebuffer device");
        exit(1);
    }
    #ifdef DEBUG
    printf("The framebuffer device was opened successfully.\n");
    #endif

    /** Read the Screen Information **/
        if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1)
        {
          perror("Driver error-- reading fixed information");
          exit(1);
        }

    // Get variable screen information

    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1)
    {
        perror("Error reading variable information");
        exit(1);
    }

    #ifdef DEBUG
    printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
    #endif

      // Figure out the size of the screen in bytes
    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

    // Map the device to memory
    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);

    local_display_mem = (char*)malloc(screensize);

    if ((int)fbp == -1)
     {
        perror("Error: mmap failed\r\n");
        exit(1);
     }
    #ifdef DEBUG
    printf("The framebuffer device was mapped to memory successfully.\n");
    #endif

    printf("Shreyas..Display Initialized..\r\n");


   //munmap(fbp, screensize);
   //close(fbfd);

}

/** This function is called by gif_read to display the Image **/

void Display(FrameData *FrameInfo)
{

    short int ImageStartX = 0;
    short 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)
                {
                  SetPixel(local_display_mem,ImageStartX,ImageStartY,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Red,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Green,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Blue);

                }


                Index++;
                ImageStartX++;
            }


            ImageStartY++;


            ImageStartX=(FrameInfo->frameScreenInfo.LeftPosition);
        }

        printf("INFO:..Dumping Framebuffer\r\n");

        memcpy(fbp,local_display_mem,screensize);

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

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

     }


}

static void SetBackground(FrameData *tempInfo)
{

    unsigned int ImageStartX=0;
    unsigned int ImageStartY=0;


    ImageStartX=(tempInfo->frameScreenInfo.LeftPosition);
    ImageStartY=(tempInfo->frameScreenInfo.TopPosition);


    while(ImageStartY<(tempInfo->frameScreenInfo.ImageHeight))
    {

        while(ImageStartX<(tempInfo->frameScreenInfo.ImageWidth))
        {

           SetPixel(local_display_mem,ImageStartX,ImageStartY,255,255,255);

            ImageStartX++;
        }

        ImageStartX=(tempInfo->frameScreenInfo.LeftPosition);
        ImageStartY++;


    }



}

static void SetPixel(char *fbp_lc, unsigned int x, unsigned int y, Byte red, Byte green, Byte blue)
{
           //printf("Shreyas..set pixel called\r\n");
           location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
                       (y+vinfo.yoffset) * finfo.line_length;

            if (vinfo.bits_per_pixel == 32)
            {
                *(fbp_lc + location) =     blue;        // Some blue
                *(fbp_lc + location + 1) = green;     // A little green
                *(fbp_lc + location + 2) = red;    // A lot of red
                *(fbp_lc + location + 3) = 0;      // No transparency
                //location += 4;
            }
            else
            { //assume 16bpp
                unsigned short int t = red<<11 | green << 5 | blue;
                *((unsigned short int*)(fbp_lc + location)) = t;
            }

             //printf("Shreyas..set pixel exit called\r\n");

}







/** This is windows version of display function, and it works correctly.
void Display(FrameData *FrameInfo)
{


    short int ImageStartX=0;
    short int ImageStartY=0;
    int Index=0;



    DisplayCntrl=GetDC(hWnd);

        printf("Shreyas.. Display Init is called\r\n");

    //display_init();


    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)
                    SetPixel(DisplayCntrl,ImageStartX,ImageStartY,RGB(((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Red,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Green,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Blue));

                Index++;
                ImageStartX++;
            }


            ImageStartY++;


            ImageStartX=(FrameInfo->frameScreenInfo.LeftPosition);
        }



        Sleep((FrameInfo->InterFrameDelay*10));
        WaitForSingleObject(hWnd,10); 
         if(    FrameInfo->DisposalMethod==2)
        {

            SETBACKGROUND(FrameInfo);
        }
        FrameInfo=FrameInfo->Next;

    }



}

这是相同代码的Windows版本。

extern  hWnd;
HDC DisplayCntrl;



void SETBACKGROUND(FrameData *tempInfo)
{

    unsigned int ImageStartX=0;
    unsigned int ImageStartY=0;



    ImageStartX=(tempInfo->frameScreenInfo.LeftPosition);
    ImageStartY=(tempInfo->frameScreenInfo.TopPosition);


    while(ImageStartY<(tempInfo->frameScreenInfo.ImageHeight))
    {

        while(ImageStartX<(tempInfo->frameScreenInfo.ImageWidth))
        {



            SetPixel(DisplayCntrl,ImageStartX,ImageStartY,RGB(255,255,255));

            ImageStartX++;
        }

        ImageStartX=(tempInfo->frameScreenInfo.LeftPosition);
        ImageStartY++;


    }



}


void Display(FrameData *FrameInfo)
{



    short int ImageStartX=0;
    short int ImageStartY=0;
    int Index=0;



    DisplayCntrl=GetDC(hWnd);


     printf("the size of short int is %d",sizeof(short int));

    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)
                {
                    SetPixel(DisplayCntrl,ImageStartX,ImageStartY,RGB(((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Red,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Green,((FrameInfo->CMAP)+(FrameInfo->frame[Index]))->Blue));
                }

                Index++;
                ImageStartX++;
            }


            ImageStartY++;


            ImageStartX=(FrameInfo->frameScreenInfo.LeftPosition);
        }



        Sleep((FrameInfo->InterFrameDelay*10));
        WaitForSingleObject(hWnd,10); 
    if( FrameInfo->DisposalMethod==2)
        {

            SETBACKGROUND(FrameInfo);
        }
        FrameInfo=FrameInfo->Next;

    }



}

由于您使用本地内存缓冲区local_display_mem ,因此是否有人清除帧缓冲区并不重要memcpy将覆盖每个像素。

这意味着由于某些原因,条件FrameInfo->frame[Index] != FrameInfo->transperencyindex始终为true ,因为这将导致算法再次设置每个像素,而不是仅更新更改的像素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM