diff options
-rw-r--r-- | Make.conf | 8 | ||||
-rw-r--r-- | bmp.c | 23 | ||||
-rw-r--r-- | fb_display.c | 14 | ||||
-rw-r--r-- | jpeg.c | 45 | ||||
-rw-r--r-- | main.c | 78 | ||||
-rw-r--r-- | png.c | 22 |
6 files changed, 94 insertions, 96 deletions
@@ -1,2 +1,6 @@ --e error: - @echo Please run ./configure first... +prefix = /usr/local +bindir = /usr/local/bin +mandir = /usr/local/man +infodir = /usr/local/info + +LIBS = -lpng -ljpeg @@ -27,27 +27,23 @@ 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); } + void fetch_pallete(int fd, struct color pallete[], int count) { unsigned char buff[4]; int i; lseek(fd, BMP_COLOR_OFFSET, SEEK_SET); - for (i=0; i<count; i++) { + for (i=0; i<count; i++) + { read(fd, buff, 4); pallete[i].red = buff[2]; pallete[i].green = buff[1]; @@ -56,6 +52,7 @@ void fetch_pallete(int fd, struct color pallete[], int count) return; } + int fh_bmp_load(char *name,unsigned char *buffer, unsigned char **alpha, int x,int y) { int fd, bpp, raster, i, j, k, skip; @@ -203,12 +200,8 @@ int fh_bmp_getsize(char *name,int *x,int *y) unsigned char size[4]; fd = open(name, O_RDONLY); - if (fd == -1) { - return(FH_ERROR_FILE); - } - if (lseek(fd, BMP_SIZE_OFFSET, SEEK_SET) == -1) { - return(FH_ERROR_FORMAT); - } + if (fd == -1) return(FH_ERROR_FILE); + if (lseek(fd, BMP_SIZE_OFFSET, SEEK_SET) == -1) return(FH_ERROR_FORMAT); read(fd, size, 4); *x = size[0] + (size[1]<<8) + (size[2]<<16) + (size[3]<<24); diff --git a/fb_display.c b/fb_display.c index a9b3752..27abde8 100644 --- a/fb_display.c +++ b/fb_display.c @@ -104,7 +104,7 @@ int openFB(const char *name) else name = DEFAULT_FRAMEBUFFER; } - if ((fh = open(name, O_RDWR)) == -1) + if((fh = open(name, O_RDWR)) == -1) { fprintf(stderr, "open %s: %s\n", name, strerror(errno)); exit(1); @@ -119,7 +119,7 @@ void closeFB(int fh) void getVarScreenInfo(int fh, struct fb_var_screeninfo *var) { - if (ioctl(fh, FBIOGET_VSCREENINFO, var)) + if(ioctl(fh, FBIOGET_VSCREENINFO, var)) { fprintf(stderr, "ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno)); exit(1); @@ -128,7 +128,7 @@ void getVarScreenInfo(int fh, struct fb_var_screeninfo *var) void setVarScreenInfo(int fh, struct fb_var_screeninfo *var) { - if (ioctl(fh, FBIOPUT_VSCREENINFO, var)) + if(ioctl(fh, FBIOPUT_VSCREENINFO, var)) { fprintf(stderr, "ioctl FBIOPUT_VSCREENINFO: %s\n", strerror(errno)); exit(1); @@ -137,9 +137,10 @@ void setVarScreenInfo(int fh, struct fb_var_screeninfo *var) void getFixScreenInfo(int fh, struct fb_fix_screeninfo *fix) { - if (ioctl(fh, FBIOGET_FSCREENINFO, fix)){ + if (ioctl(fh, FBIOGET_FSCREENINFO, fix)) + { fprintf(stderr, "ioctl FBIOGET_FSCREENINFO: %s\n", strerror(errno)); - exit(1); + exit(1); } } @@ -156,7 +157,8 @@ void make332map(struct fb_cmap *map) gs = 256 / (g - 1); bs = 256 / (b - 1); - for (i = 0; i < 256; i++) { + for (i = 0; i < 256; i++) + { map->red[i] = (rs * ((i / (g * b)) % r)) * 255; map->green[i] = (gs * ((i / b) % g)) * 255; map->blue[i] = (bs * ((i) % b)) * 255; @@ -2,13 +2,13 @@ #ifdef FBV_SUPPORT_JPEG #include <stdio.h> +#include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <jpeglib.h> #include <setjmp.h> #include <unistd.h> -#include <string.h> #include "fbv.h" struct r_jpeg_error_mgr @@ -34,9 +34,9 @@ int fh_jpeg_id(char *name) void jpeg_cb_error_exit(j_common_ptr cinfo) { struct r_jpeg_error_mgr *mptr; - mptr=(struct r_jpeg_error_mgr*) cinfo->err; + mptr = (struct r_jpeg_error_mgr*) cinfo->err; (*cinfo->err->output_message) (cinfo); - longjmp(mptr->envbuffer,1); + longjmp(mptr->envbuffer, 1); } int fh_jpeg_load(char *filename,unsigned char *buffer, unsigned char ** alpha, int x,int y) @@ -49,10 +49,10 @@ int fh_jpeg_load(char *filename,unsigned char *buffer, unsigned char ** alpha, i FILE *fh; JSAMPLE *lb; - ciptr=&cinfo; + ciptr = &cinfo; if(!(fh=fopen(filename,"rb"))) return(FH_ERROR_FILE); - ciptr->err=jpeg_std_error(&emgr.pub); - emgr.pub.error_exit=jpeg_cb_error_exit; + ciptr->err = jpeg_std_error(&emgr.pub); + emgr.pub.error_exit = jpeg_cb_error_exit; if(setjmp(emgr.envbuffer)==1) { // FATAL ERROR - Free the object and return... @@ -63,24 +63,23 @@ int fh_jpeg_load(char *filename,unsigned char *buffer, unsigned char ** alpha, i jpeg_create_decompress(ciptr); jpeg_stdio_src(ciptr,fh); - jpeg_read_header(ciptr,TRUE); - ciptr->out_color_space=JCS_RGB; + jpeg_read_header(ciptr, TRUE); + ciptr->out_color_space = JCS_RGB; jpeg_start_decompress(ciptr); - px=ciptr->output_width; - py=ciptr->output_height; - c=ciptr->output_components; - + px = ciptr->output_width; + py = ciptr->output_height; + c = ciptr->output_components; if(c==3) { - lb=(*ciptr->mem->alloc_small)((j_common_ptr) ciptr,JPOOL_PERMANENT,c*px); - bp=buffer; + lb = (*ciptr->mem->alloc_small)((j_common_ptr) ciptr,JPOOL_PERMANENT,c*px); + bp = buffer; while (ciptr->output_scanline < ciptr->output_height) { jpeg_read_scanlines(ciptr, &lb, 1); - memcpy(bp,lb,px*c); - bp+=px*c; + memcpy(bp, lb, px*c); + bp += px*c; } } jpeg_finish_decompress(ciptr); @@ -100,8 +99,8 @@ int fh_jpeg_getsize(char *filename, int *x, int *y) ciptr=&cinfo; if(!(fh=fopen(filename,"rb"))) return(FH_ERROR_FILE); - ciptr->err=jpeg_std_error(&emgr.pub); - emgr.pub.error_exit=jpeg_cb_error_exit; + ciptr->err = jpeg_std_error(&emgr.pub); + emgr.pub.error_exit = jpeg_cb_error_exit; if(setjmp(emgr.envbuffer)==1) { // FATAL ERROR - Free the object and return... @@ -113,13 +112,13 @@ int fh_jpeg_getsize(char *filename, int *x, int *y) jpeg_create_decompress(ciptr); jpeg_stdio_src(ciptr,fh); jpeg_read_header(ciptr,TRUE); - ciptr->out_color_space=JCS_RGB; + ciptr->out_color_space = JCS_RGB; jpeg_start_decompress(ciptr); - px=ciptr->output_width; - py=ciptr->output_height; + px = ciptr->output_width; + py = ciptr->output_height; c = ciptr->output_components; - *x=px; - *y=py; + *x = px; + *y = py; jpeg_destroy_decompress(ciptr); fclose(fh); return(FH_ERROR_OK); @@ -193,36 +193,36 @@ int show_image(char *filename) #ifdef FBV_SUPPORT_PNG if(fh_png_id(filename)) - if(fh_png_getsize(filename, &x_size, &y_size) == FH_ERROR_OK) - { - load = fh_png_load; - goto identified; - } + if(fh_png_getsize(filename, &x_size, &y_size) == FH_ERROR_OK) + { + load = fh_png_load; + goto identified; + } #endif #ifdef FBV_SUPPORT_JPEG if(fh_jpeg_id(filename)) - if(fh_jpeg_getsize(filename, &x_size, &y_size) == FH_ERROR_OK) - { - load = fh_jpeg_load; - goto identified; - } + if(fh_jpeg_getsize(filename, &x_size, &y_size) == FH_ERROR_OK) + { + load = fh_jpeg_load; + goto identified; + } #endif #ifdef FBV_SUPPORT_BMP if(fh_bmp_id(filename)) - if(fh_bmp_getsize(filename, &x_size, &y_size) == FH_ERROR_OK) - { - load = fh_bmp_load; - goto identified; - } + if(fh_bmp_getsize(filename, &x_size, &y_size) == FH_ERROR_OK) + { + load = fh_bmp_load; + goto identified; + } #endif fprintf(stderr, "%s: Unable to access file or file format unknown.\n", filename); return(1); identified: - if(!(image = (unsigned char*) malloc(x_size * y_size * 3))) + if(!(image = (unsigned char*)malloc(x_size * y_size * 3))) { fprintf(stderr, "%s: Out of memory.\n", filename); goto error_mem; @@ -240,8 +240,6 @@ identified: alpha = NULL; } - - getCurrentRes(&screen_width, &screen_height); i.do_free = 0; while(1) @@ -386,10 +384,8 @@ identified: transform_rotation -= 4; retransform = 1; break; - } - - } + }// while(1) done: if(opt_clear) @@ -407,34 +403,34 @@ error_mem: free(i.alpha); } return(ret); - } void help(char *name) { printf("Usage: %s [options] image1 image2 image3 ...\n\n" "Available options:\n" - " --help | -h : Show this help\n" - " --alpha | -a : Use the alpha channel (if applicable)\n" - " --dontclear | -c : Do not clear the screen before and after displaying the image\n" - " --donthide | -u : Do not hide the cursor before and after displaying the image\n" - " --noinfo | -i : Supress image information\n" - " --stretch | -f : Strech (using a simple resizing routine) the image to fit onto screen if necessary\n" - " --colorstretch| -k : Strech (using a 'color average' resizing routine) the image to fit onto screen if necessary\n" - " --enlarge | -e : Enlarge the image to fit the whole screen if necessary\n" + " --help | -h : Show this help\n" + " --alpha | -a : Use the alpha channel (if applicable)\n" + " --dontclear | -c : Do not clear the screen before and after displaying the image\n" + " --donthide | -u : Do not hide the cursor before and after displaying the image\n" + " --noinfo | -i : Supress image information\n" + " --stretch | -f : Strech (using a simple resizing routine) the image to fit onto screen if necessary\n" + " --colorstretch | -k : Strech (using a 'color average' resizing routine) the image to fit onto screen if necessary\n" + " --enlarge | -e : Enlarge the image to fit the whole screen if necessary\n" " --ignore-aspect| -r : Ignore the image aspect while resizing\n" - " --delay <d> | -s <delay> : Slideshow, 'delay' is the slideshow delay in tenths of seconds.\n\n" + " --delay <d> | -s <delay> : Slideshow, 'delay' is the slideshow delay in tenths of seconds.\n\n" "Keys:\n" - " r : Redraw the image\n" - " a, d, w, x : Pan the image\n" - " f : Toggle resizing on/off\n" - " k : Toggle resizing quality\n" - " e : Toggle enlarging on/off\n" - " i : Toggle respecting the image aspect on/off\n" - " n : Rotate the image 90 degrees left\n" - " m : Rotate the image 90 degrees right\n" - " p : Disable all transformations\n" - "Copyright (C) 2000 - 2004 Mateusz Golicz, Tomasz Sterna.\n", name); + " r : Redraw the image\n" + " a, d, w, x : Pan the image\n" + " f : Toggle resizing on/off\n" + " k : Toggle resizing quality\n" + " e : Toggle enlarging on/off\n" + " i : Toggle respecting the image aspect on/off\n" + " n : Rotate the image 90 degrees left\n" + " m : Rotate the image 90 degrees right\n" + " p : Disable all transformations\n" + " Copyright (C) 2000 - 2004 Mateusz Golicz, Tomasz Sterna.\n" + " Copyright (C) 2013 yanlin, godspeed1989@gitbub\n", name); } void sighandler(int s) @@ -19,8 +19,9 @@ int fh_png_id(char *name) { int fd; char id[4]; - fd=open(name,O_RDONLY); if(fd==-1) return(0); - read(fd,id,4); + fd = open(name, O_RDONLY); + if(fd==-1) return(0); + read(fd, id, 4); close(fd); if(id[1]=='P' && id[2]=='N' && id[3]=='G') return(1); return(0); @@ -40,7 +41,7 @@ int fh_png_load(char *name,unsigned char *buffer, unsigned char ** alpha,int x,i unsigned char *fbptr; FILE *fh; - if(!(fh=fopen(name,"rb"))) return(FH_ERROR_FILE); + if(!(fh = fopen(name,"rb"))) return(FH_ERROR_FILE); png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL); if (png_ptr == NULL) return(FH_ERROR_FORMAT); @@ -51,7 +52,7 @@ int fh_png_load(char *name,unsigned char *buffer, unsigned char ** alpha,int x,i fclose(fh); return(FH_ERROR_FORMAT); } - rp=0; + rp = 0; if (setjmp(png_ptr->jmpbuf)) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); @@ -125,7 +126,9 @@ int fh_png_load(char *name,unsigned char *buffer, unsigned char ** alpha,int x,i fclose(fh); return(FH_ERROR_OK); } -int fh_png_getsize(char *name,int *x,int *y) + + +int fh_png_getsize(char *name, int *x, int *y) { png_structp png_ptr; png_infop info_ptr; @@ -136,7 +139,7 @@ int fh_png_getsize(char *name,int *x,int *y) if(!(fh=fopen(name,"rb"))) return(FH_ERROR_FILE); - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL); + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) return(FH_ERROR_FORMAT); info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL) @@ -145,7 +148,7 @@ int fh_png_getsize(char *name,int *x,int *y) fclose(fh); return(FH_ERROR_FORMAT); } - rp=0; + rp = 0; if (setjmp(png_ptr->jmpbuf)) { png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); @@ -158,9 +161,10 @@ int fh_png_getsize(char *name,int *x,int *y) png_read_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,&interlace_type, NULL, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); - *x=width; - *y=height; + *x = width; + *y = height; fclose(fh); return(FH_ERROR_OK); } #endif /*FBV_SUPPORT_PNG*/ + |