diff options
author | godspeed1989 <tongxinjichu@gmail.com> | 2013-05-03 21:36:42 +0800 |
---|---|---|
committer | godspeed1989 <tongxinjichu@gmail.com> | 2013-05-03 21:36:42 +0800 |
commit | c46fdfe136b16d5bcf6fc38f02bbc845a99b486a (patch) | |
tree | e1051b93362a9d16584ccb0740774d4869acd1eb | |
parent | e8878a882f0ce9c6bad2d0bf2f54d08e554946f2 (diff) | |
download | fbv-c46fdfe136b16d5bcf6fc38f02bbc845a99b486a.tar.gz fbv-c46fdfe136b16d5bcf6fc38f02bbc845a99b486a.zip |
fix console restore problem
-rw-r--r-- | bmp.c | 6 | ||||
-rw-r--r-- | fb_display.c | 14 | ||||
-rw-r--r-- | fbv.h | 18 | ||||
-rw-r--r-- | jpeg.c | 2 | ||||
-rw-r--r-- | main.c | 23 |
5 files changed, 38 insertions, 25 deletions
@@ -28,10 +28,10 @@ int fh_bmp_id(char *name) int fd; char id[2]; fd = open(name, O_RDONLY); - if (fd == -1) return(0); + if(fd == -1) return(0); read(fd, id, 2); close(fd); - if ( id[0]=='B' && id[1]=='M' ) return(1); + if(id[0]=='B' && id[1]=='M') return(1); return(0); } @@ -53,7 +53,7 @@ void fetch_pallete(int fd, struct color pallete[], int count) } -int fh_bmp_load(char *name,unsigned char *buffer, unsigned char **alpha, int x,int y) +int fh_bmp_load(char *name, unsigned char *buffer, unsigned char **alpha, int x,int y) { int fd, bpp, raster, i, j, k, skip; unsigned char buff[4]; diff --git a/fb_display.c b/fb_display.c index 27abde8..db45840 100644 --- a/fb_display.c +++ b/fb_display.c @@ -44,7 +44,7 @@ void blit2FB(int fh, void *fbbuff, unsigned char *alpha, unsigned int xoffs, unsigned int yoffs, int cpp); -void fb_display(unsigned char *rgbbuff, unsigned char * alpha, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs) +int fb_display(unsigned char *rgbbuff, unsigned char * alpha, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs) { struct fb_var_screeninfo var; struct fb_fix_screeninfo fix; @@ -54,6 +54,8 @@ void fb_display(unsigned char *rgbbuff, unsigned char * alpha, int x_size, int y /* get the framebuffer device handle */ fh = openFB(NULL); + if(fh == -1) + return -1; /* read current video mode */ getVarScreenInfo(fh, &var); @@ -79,17 +81,21 @@ void fb_display(unsigned char *rgbbuff, unsigned char * alpha, int x_size, int y /* close device */ closeFB(fh); + return 0; } -void getCurrentRes(int *x, int *y) +int getCurrentRes(int *x, int *y) { struct fb_var_screeninfo var; - int fh = -1; + int fh; fh = openFB(NULL); + if(fh == -1) + return -1; getVarScreenInfo(fh, &var); *x = var.xres; *y = var.yres; closeFB(fh); + return 0; } int openFB(const char *name) @@ -107,7 +113,7 @@ int openFB(const char *name) if((fh = open(name, O_RDWR)) == -1) { fprintf(stderr, "open %s: %s\n", name, strerror(errno)); - exit(1); + return -1; } return fh; } @@ -5,25 +5,26 @@ #define FH_ERROR_FILE 1 /* read/access error */ #define FH_ERROR_FORMAT 2 /* file format error */ -void fb_display(unsigned char *rgbbuff, unsigned char * alpha, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs); -void getCurrentRes(int *x, int *y); +int fb_display(unsigned char *rgbbuff, unsigned char * alpha, + int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs); +int getCurrentRes(int *x, int *y); #ifdef FBV_SUPPORT_BMP int fh_bmp_id(char *name); -int fh_bmp_load(char *name,unsigned char *buffer, unsigned char **alpha, int x,int y); -int fh_bmp_getsize(char *name,int *x,int *y); +int fh_bmp_load(char *name, unsigned char *buffer, unsigned char **alpha, int x,int y); +int fh_bmp_getsize(char *name, int *x, int *y); #endif #ifdef FBV_SUPPORT_JPEG int fh_jpeg_id(char *name); -int fh_jpeg_load(char *name,unsigned char *buffer, unsigned char **alpha, int x,int y); -int fh_jpeg_getsize(char *name,int *x,int *y); +int fh_jpeg_load(char *name, unsigned char *buffer, unsigned char **alpha, int x,int y); +int fh_jpeg_getsize(char *name, int *x, int *y); #endif #ifdef FBV_SUPPORT_PNG int fh_png_id(char *name); -int fh_png_load(char *name,unsigned char *buffer, unsigned char **alpha, int x,int y); -int fh_png_getsize(char *name,int *x,int *y); +int fh_png_load(char *name, unsigned char *buffer, unsigned char **alpha, int x,int y); +int fh_png_getsize(char *name, int *x, int *y); #endif struct image @@ -40,6 +41,7 @@ struct image #ifndef max #define max(a,b) ((a) > (b) ? (a) : (b)) #endif + unsigned char * simple_resize(unsigned char * orgin,int ox,int oy,int dx,int dy); unsigned char * alpha_resize(unsigned char * alpha,int ox,int oy,int dx,int dy); unsigned char * color_average_resize(unsigned char * orgin,int ox,int oy,int dx,int dy); @@ -39,7 +39,7 @@ void jpeg_cb_error_exit(j_common_ptr cinfo) longjmp(mptr->envbuffer, 1); } -int fh_jpeg_load(char *filename,unsigned char *buffer, unsigned char ** alpha, int x,int y) +int fh_jpeg_load(char *filename, unsigned char *buffer, unsigned char ** alpha, int x, int y) { struct jpeg_decompress_struct cinfo; struct jpeg_decompress_struct *ciptr; @@ -31,14 +31,17 @@ void setup_console(int t) if(t) { + printf("setup console\n"); tcgetattr(0, &old_termios); memcpy(&our_termios, &old_termios, sizeof(struct termios)); our_termios.c_lflag &= !(ECHO | ICANON); tcsetattr(0, TCSANOW, &our_termios); } else + { + printf("restore console\n"); tcsetattr(0, TCSANOW, &old_termios); - + } } static inline void do_rotate(struct image *i, int rot) @@ -186,8 +189,9 @@ int show_image(char *filename) int x_pan, y_pan, x_offs, y_offs, refresh = 1, c, ret = 1; int delay = opt_delay, retransform = 1; - int transform_stretch = opt_stretch, transform_enlarge = opt_enlarge, transform_cal = (opt_stretch == 2), - transform_iaspect = opt_ignore_aspect, transform_rotation = 0; + int transform_stretch = opt_stretch, transform_enlarge = opt_enlarge; + int transform_cal = (opt_stretch == 2), transform_iaspect = opt_ignore_aspect; + int transform_rotation = 0; struct image i; @@ -225,13 +229,13 @@ identified: if(!(image = (unsigned char*)malloc(x_size * y_size * 3))) { fprintf(stderr, "%s: Out of memory.\n", filename); - goto error_mem; + goto error; } if(load(filename, image, &alpha, x_size, y_size) != FH_ERROR_OK) { fprintf(stderr, "%s: Image data is corrupt?\n", filename); - goto error_mem; + goto error; } if(!opt_alpha) @@ -240,7 +244,8 @@ identified: alpha = NULL; } - getCurrentRes(&screen_width, &screen_height); + if(getCurrentRes(&screen_width, &screen_height)) + goto error; i.do_free = 0; while(1) { @@ -257,7 +262,6 @@ identified: i.alpha = alpha; i.do_free = 0; - if(transform_rotation) do_rotate(&i, transform_rotation); @@ -289,7 +293,8 @@ identified: else y_offs = 0; - fb_display(i.rgb, i.alpha, i.width, i.height, x_pan, y_pan, x_offs, y_offs); + if(fb_display(i.rgb, i.alpha, i.width, i.height, x_pan, y_pan, x_offs, y_offs)) + goto error; refresh = 0; } if(delay) @@ -394,7 +399,7 @@ done: fflush(stdout); } -error_mem: +error: free(image); free(alpha); if(i.do_free) |