c - how to stop linux framebuffer to clear automatically while drawing multiple frames -
i writing gif decoder, image animated image.when write first frame, displays fine. when, display second frame, displays changed pixels. other pixels automatically changed black. don't know why?.
my first frame has complete picture. second frame has again pixel changed , contains rest of unchanged pixels.
now, when draw second buffer, redraws unchanged pixels also. , unchanged pixels drawn black ( or precisely in monitor see these unchanged pixels absent). that's when has draw second frame.it draws changed pixels( correct), re-draws unchanged pixel well. , unchanged pixel seen black ( no color). feel refreshing issue. or else. appreciated.
required: should redraw complete image. in short, snippet of function.
unfortunately, clears off previous display - linux framebuffer. want stop clearning linux framebuffer.
here complete file.
/** using direct fb calls here; , tightly coupled 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; /** clone linux frame buffer, , called 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); /** entry function initialize display **/ void display_init() { // open file reading , writing fbfd = open("/dev/fb0", o_rdwr); if (fbfd == -1) { perror("cannot open framebuffer device"); exit(1); } #ifdef debug printf("the framebuffer device opened successfully.\n"); #endif /** read screen information **/ if (ioctl(fbfd, fbioget_fscreeninfo, &finfo) == -1) { perror("driver error-- reading fixed information"); exit(1); } // 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 size of screen in bytes screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; // map device 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 mapped memory successfully.\n"); #endif printf("shreyas..display initialized..\r\n"); //munmap(fbp, screensize); //close(fbfd); } /** function called gif_read display 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 multiplication meet right output on display **/ usleep((frameinfo->interframedelay)*100000); if( frameinfo->disposalmethod == 2) { printf("set 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; // blue *(fbp_lc + location + 1) = green; // little green *(fbp_lc + location + 2) = red; // 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"); } /** windows version of display function, , works correctly. void display(framedata *frameinfo) { short int imagestartx=0; short int imagestarty=0; int index=0; displaycntrl=getdc(hwnd); printf("shreyas.. display init 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; } }
this windows version of same code.
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 %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; } }
since use local memory buffer local_display_mem
, doesn't matter if clear framebuffer - memcpy
overwrite every pixel.
this means condition frameinfo->frame[index] != frameinfo->transperencyindex
true
reason since cause algorithm set each pixel again instead of updating changed pixels.
Comments
Post a Comment