📄 main.c
字号:
/* fbv -- simple image viewer for the linux framebuffer Copyright (C) 2000, 2001, 2003, 2004 Mateusz 'mteg' 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 <stdio.h>#include <sys/time.h>#include <sys/types.h>#include <unistd.h>#include <getopt.h>#include <stdlib.h>#include <termios.h>#include <string.h>#include <signal.h>#include <assert.h>#include "fbv.h"extern struct image p_image;static unsigned char *image = NULL;static unsigned char *alpha = NULL;void sighandler(int s){ if (image != NULL) free(image); image = NULL; if (p_image.rgb != NULL) free(p_image.rgb); p_image.rgb = NULL; if (alpha != NULL) free(alpha); alpha = NULL; if (p_image.alpha != NULL) free(p_image.alpha); p_image.alpha = NULL; printf("\033[?25h"); fflush(stdout); setup_console(0); _exit(128 + s);}int clear_console(){ printf("\033[H\033[J"); fflush(stdout); return 1;}void setup_console(int t){ struct termios our_termios; static struct termios old_termios; if(t) { tcgetattr(0, &old_termios); memcpy(&our_termios, &old_termios, sizeof(struct termios)); our_termios.c_lflag &= !(ECHO | ICANON); tcsetattr(0, TCSANOW, &our_termios); } else tcsetattr(0, TCSANOW, &old_termios);}int show_image_refresh(struct image *pimage){ int ch = 0; while (1) { ch = getchar(); switch (ch) { case 'q': case 10: case 13: case EOF: goto done; case '>': case '.': case '<': case ',': goto done; case 'a': image_move_left(); break; case 'd': image_move_right(); break; case 'w': image_move_down(); break; case 'x': image_move_up(); break; case 'y': image_pan_enlarge(); break; case 'o': image_pan_little(); break; case 'l': image_restore(); break; case 'n': image_rotate_left(); break; case 'm': image_rotate_right(); break; case 'h': image_exchang_left_right(); break; case 'u': image_exchang_up_down(); break; case 'g': image_rotate_up_down(); break; case 'r': image_full_screen(); break; case 's': image_write_file(); break; case 'i': image_muzzy_inc(); break; case 'p': image_ContrastChange_inc(); break; case 'e': image_BrightnessChange_inc(); break; case 'f': image_RGBChange_inc(30, 30, 0); break; case 't': image_BrightnessChange_dec(); //image_reflect(); break; case 'b': image_ContrastChange_dec(); //image_Exposure(); break; case 'c': image_SaturationChange_dec(); break; case 'j': image_SaturationChange_inc(); break; case 'k': image_GrayAverage(); break; case 'z': image_Sharpen_inc(); //image_Engrave(); break; case 'v': //image_muzzy_dec(p_image.rgb, p_image.width*p_image.height.3, 10); //image_Brightness_adjust(p_image.rgb, p_image.width, p_image.height, -20); image_RGBChange_adjust(p_image.rgb, p_image.width, p_image.height, -10, 10, 0); //image_RGBChange_dec(0, 30, 30); break; } }done: clear_console(); image_cleanup(); return -1;}void set_signal_handle(){ signal(SIGHUP, sighandler); signal(SIGINT, sighandler); signal(SIGQUIT, sighandler); signal(SIGSEGV, sighandler); signal(SIGTERM, sighandler); signal(SIGABRT, sighandler);}int main(int argc, char **argv){ if(argc < 2) { fprintf(stderr, "Error: Required argument missing.\n"); return(1); } set_signal_handle(); setup_console(1); image_init(argv[1]); show_image_refresh(&p_image); setup_console(0); return(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -