main.c.old
上传用户:hengzhunsh
上传日期:2013-09-07
资源大小:19k
文件大小:9k
- /*
- fbv -- simple image viewer for the linux framebuffer
- Copyright (C) 2000, 2001, 2003 Mateusz Golicz
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- #include "config.h"
- #include "fbv.h"
- #include <stdio.h>
- #include <termios.h>
- #include <sys/time.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <getopt.h>
- #include <stdlib.h>
- #include <string.h>
- #define min(a,b) ((a) < (b) ? (a) : (b))
- #define max(a,b) ((a) > (b) ? (a) : (b))
- #define SHOWDELAY 100000
- #define NEXT_IMG -3
- #define PREV_IMG -4
- extern unsigned char * simple_resize(unsigned char * orgin,int ox,int oy,int dx,int dy);
- extern unsigned char * alpha_resize(unsigned char * orgin,int ox,int oy,int dx,int dy);
- extern unsigned char * color_average_resize(unsigned char * orgin,int ox,int oy,int dx,int dy);
- int clear=1,delay=0,hide=1,dispinfo=1,allowstrech=0,opt_alpha = 0, allow_enlarging = 0, ignore_ratio = 0;
- struct formathandler *fh_root=NULL;
- struct termios oldtermios;
- struct termios ourtermios;
- int imm_getchar(int s,int us)
- {
- struct timeval tv;
- unsigned char c;
- fd_set fds;
- FD_ZERO(&fds);
- FD_SET(0,&fds);
- tv.tv_sec=s; tv.tv_usec=us;
- if(select(1,&fds,NULL,NULL,&tv))
- {
- read(0,&c,1);
- return((int) c);
- }
- else
- return(EOF);
- }
- void contoraw(void)
- {
- tcgetattr(0,&oldtermios);
- memcpy(&ourtermios,&oldtermios,sizeof(struct termios));
- ourtermios.c_lflag&=!(ECHO|ICANON);
- tcsetattr(0,TCSANOW,&ourtermios);
- }
- void connorm(void)
- {
- tcsetattr(0,TCSANOW,&oldtermios);
- }
- void add_format(int (*picsize)(char *,int *,int*),int (*picread)(char *,unsigned char *,unsigned char**,int,int), int (*id)(char*))
- {
- struct formathandler *fhn;
- fhn=(struct formathandler*) malloc(sizeof(struct formathandler));
- fhn->get_size=picsize; fhn->get_pic=picread; fhn->id_pic=id;
- fhn->next=fh_root; fh_root=fhn;
- }
- #ifdef FBV_SUPPORT_GIF
- extern int fh_gif_getsize(char *,int *,int*);
- extern int fh_gif_load(char *,unsigned char *,unsigned char **, int,int);
- extern int fh_gif_id(char *);
- #endif
- #ifdef FBV_SUPPORT_JPEG
- extern int fh_jpeg_getsize(char *,int *,int*);
- extern int fh_jpeg_load(char *,unsigned char *,unsigned char **, int,int);
- extern int fh_jpeg_id(char *);
- #endif
- #ifdef FBV_SUPPORT_PNG
- extern int fh_png_getsize(char *,int *,int*);
- extern int fh_png_load(char *,unsigned char *,unsigned char **,int,int);
- extern int fh_png_id(char *);
- #endif
- #ifdef FBV_SUPPORT_BMP
- extern int fh_bmp_getsize(char *,int *,int*);
- extern int fh_bmp_load(char *,unsigned char *,unsigned char **, int,int);
- extern int fh_bmp_id(char *);
- #endif
- void init_handlers(void)
- {
- #ifdef FBV_SUPPORT_GIF
- add_format(fh_gif_getsize,fh_gif_load,fh_gif_id);
- #endif
- #ifdef FBV_SUPPORT_JPEG
- add_format(fh_jpeg_getsize,fh_jpeg_load,fh_jpeg_id);
- #endif
- #ifdef FBV_SUPPORT_PNG
- add_format(fh_png_getsize,fh_png_load,fh_png_id);
- #endif
- #ifdef FBV_SUPPORT_BMP
- add_format(fh_bmp_getsize,fh_bmp_load,fh_bmp_id);
- #endif
- }
- struct formathandler * fh_getsize(char *name,int *x,int *y)
- {
- struct formathandler *fh;
- for(fh=fh_root;fh!=NULL;fh=fh->next)
- {
- if(fh->id_pic(name))
- if(fh->get_size(name,x,y)==FH_ERROR_OK) return(fh);
- }
- return(NULL);
- }
- int show_image(char *name)
- {
- int x,y,xs,ys,xpos,ypos,xdelta,ydelta,c,eol,xstep,ystep,rfrsh,imx,imy;
- unsigned char *buffer;
- unsigned char *alpha = NULL;
- struct formathandler *fh;
- eol=1;
- if((fh=fh_getsize(name,&x,&y)))
- {
- buffer=(unsigned char *) malloc(x*y*3);
- if(fh->get_pic(name,buffer,&alpha,x,y)==FH_ERROR_OK)
- {
- if(clear) { printf("