📄 pmpimage.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 "config.h"#include "fbv.h"static unsigned char *image = NULL;static unsigned char *alpha = NULL;struct image p_image;static screen_show_pos show_pos;static image_show_param show_param;static image_color_param color_param;#define PAN_STEPPING 20#define IMAGE_BUFFER_SIZE ((show_param.source_width)*(show_param.source_height))void image_update(){// clear_console(); if(p_image.width < show_param.screen_width) show_pos.x_offs = (show_param.screen_width - p_image.width)/2; else show_pos.x_offs = 0; if(p_image.height < show_param.screen_height) show_pos.y_offs = (show_param.screen_height - p_image.height)/2; else show_pos.y_offs = 0; fb_display(p_image.rgb, p_image.alpha, p_image.width, p_image.height, show_pos.x_pan, show_pos.y_pan, show_pos.x_offs, show_pos.y_offs);/* printf("image width = %d height = %d\n", p_image.width, p_image.height); printf("screen width = %d height = %d\n", show_param.screen_width, show_param.screen_height); printf("show x_pos = %d y_pos = %d\n", show_pos.x_offs, show_pos.y_offs); printf("pan x_pan = %d y_pan = %d\n", show_pos.x_pan, show_pos.y_pan); printf("show width = %d height = %d\n", show_param.show_width, show_param.show_height); printf("bright=%d contrast=%d saturation=%d\n", color_param.bright, color_param.contrast,color_param.saturation); printf("left_right=%d un_down=%d rotation=%d\n", show_param.left_right_dirtion, show_param.updown_direction, show_param.rotation_direction);*/} void image_SaturationChange_inc(){ color_param.saturation = color_param.saturation + 10; image_data_process(&p_image); image_dofresh(); image_update();}void image_SaturationChange_dec(){ color_param.saturation = color_param.saturation - 10; image_data_process(&p_image); image_dofresh(); image_update();}void image_ContrastChange_dec(){ color_param.contrast = color_param.contrast - 10; image_data_process(&p_image); image_dofresh(); image_update();}void image_ContrastChange_inc(){ color_param.contrast = color_param.contrast + 10; image_data_process(&p_image); image_dofresh(); image_update();}void image_BrightnessChange_dec(){ color_param.bright = color_param.bright - 10; image_data_process(&p_image); image_dofresh(); image_update(); }void image_BrightnessChange_inc(){ color_param.bright = color_param.bright + 10; image_data_process(&p_image); image_dofresh(); image_update(); }void image_RGBChange_inc(int red, int green, int blue){ color_param.RGB_red = color_param.RGB_red + red; color_param.RGB_green = color_param.RGB_green + green; color_param.RGB_blue = color_param.RGB_blue + blue; image_data_process(&p_image); image_dofresh(); image_update();}void image_RGBChange_dec(int red, int green, int blue){ color_param.RGB_red = color_param.RGB_red - red; color_param.RGB_green = color_param.RGB_green - green; color_param.RGB_blue = color_param.RGB_blue - blue; image_data_process(&p_image); image_dofresh(); image_update();}void image_reflect(){ color_param.reflect = !color_param.reflect; image_data_process(&p_image); image_dofresh(); image_update();}void image_Exposure(){ color_param.exposure = !color_param.exposure; image_data_process(&p_image); image_dofresh(); image_update();}void image_muzzy_dec(){ color_param.muzzy = color_param.muzzy + 1; image_data_process(&p_image); image_dofresh(); image_update();}void image_muzzy_inc(){ color_param.muzzy = color_param.muzzy - 1; if (color_param.muzzy < 0) color_param.muzzy = 0; image_data_process(&p_image); image_dofresh(); image_update();}void image_Sharpen_inc(){ color_param.sharpen = color_param.sharpen + 1; image_data_process(&p_image); image_dofresh(); image_update();}void image_Sharpen_dec(){ color_param.sharpen = color_param.sharpen - 1; image_data_process(&p_image); image_dofresh(); image_update();}void image_GrayAverage(){ color_param.GrayAverage = !color_param.GrayAverage; image_data_process(&p_image); image_dofresh(); image_update();}void image_GrayWeightAverage(){ color_param.GrayWeightAverage = !color_param.GrayWeightAverage; image_data_process(&p_image); image_dofresh(); image_update();}void image_Emboss(){ color_param.emboss = !color_param.emboss; image_data_process(&p_image); image_dofresh(); image_update();}void image_Engrave(){ color_param.engrave = !color_param.engrave; image_data_process(&p_image); image_dofresh(); image_update();} inline void do_image_resize(struct image *i, int img_width, int img_height){ unsigned char *p_img=NULL, *img=NULL, *rc=NULL; unsigned char *p = i->rgb; int image_width = i->width, image_height = i->height; int x_pos=0, y_pos=0, n=0, disp=0; img = (unsigned char *)malloc(img_width*img_height*3); assert(img); memset((void *)img, 0x00, img_width*img_height*3); p_img = img; for (y_pos=0; y_pos<img_height; y_pos++, p_img += img_width*3) { rc = p + (y_pos*image_height/img_height*image_width*3); for (x_pos=0, n=0; x_pos<img_width; x_pos++, n += 3) { disp = x_pos*image_width/img_width*3; *(p_img+n+0) = *(rc+disp+0); *(p_img+n+1) = *(rc+disp+1); *(p_img+n+2) = *(rc+disp+2); } } if (i->rgb != image) free(i->rgb); i->rgb = img; i->width = img_width; i->height = img_height;}inline void do_alpha_resize(struct image *i, int img_width, int img_height){ unsigned char *img_alpha=NULL, *pimg_alpha=NULL; unsigned char *p_tmp = NULL; unsigned char *p_source = i->alpha; int x_pos=0, y_pos=0, idex=0; int image_width = i->width; int image_height = i->height; img_alpha=(unsigned char*)malloc(img_width*img_height); pimg_alpha = img_alpha; for(y_pos=0; y_pos<img_height; y_pos++, pimg_alpha+=img_width) { p_tmp = p_source+(y_pos*image_height/img_height*image_width); for(x_pos=0,idex=0; x_pos<img_width; x_pos++) pimg_alpha[idex++] = p_tmp[x_pos*image_width/img_width]; } if (i->alpha != alpha) free(i->alpha); i->alpha = img_alpha; i->width = img_width; i->height = img_height;}void image_data_process(struct image *img){ if (p_image.rgb != image) free(p_image.rgb); p_image.rgb = image; p_image.width = show_param.source_width; p_image.height = show_param.source_height; do_image_comment(&p_image); do_image_resize(&p_image, show_param.show_width, show_param.show_height); if (p_image.alpha != NULL) { if (p_image.alpha != alpha) free(p_image.alpha); p_image.alpha = alpha; p_image.width = show_param.source_width; p_image.height = show_param.source_height; do_alpha_resize(&p_image, show_param.show_width, show_param.show_height); }}void save_bake_filename(char *psrc, char *bakefilename){ char *p = psrc; char *pend = strrchr(psrc, '.'); char *pdest = bakefilename; while(p != pend) *pdest++ = *p++; strcpy(pdest, "_bak.jpg");;}void do_restore_image(struct image *i, int ignoreaspect, int cal){ int nx_size = 0, ny_size = 0;; if (i->rgb != NULL) free(i->rgb); i->rgb = (unsigned char *)malloc(IMAGE_BUFFER_SIZE*3); memset(i->rgb, 0x00, IMAGE_BUFFER_SIZE*3); memcpy(i->rgb, image, IMAGE_BUFFER_SIZE*3); i->width = show_param.source_width; i->height = show_param.source_height; nx_size = i->width; ny_size = i->height; show_param.show_width = show_param.source_width; show_param.show_height = show_param.source_height; if(ignoreaspect) { if(i->width > show_param.screen_width) nx_size = show_param.screen_width; if(i->height > show_param.screen_height) ny_size = show_param.screen_height; } else { if((i->height * show_param.screen_width/i->width) <= show_param.screen_height) { nx_size = show_param.screen_width; ny_size = i->height * show_param.screen_width/i->width; } else { nx_size = i->width * show_param.screen_height/i->height; ny_size = show_param.screen_height; } } do_image_resize(i, show_param.source_width, show_param.source_height); if (i->alpha != NULL) { if (i->alpha != alpha) free(i->alpha); i->alpha = (unsigned char *)malloc(IMAGE_BUFFER_SIZE); memset(i->alpha, 0x00, IMAGE_BUFFER_SIZE); memcpy(i->alpha, alpha, IMAGE_BUFFER_SIZE); i->width = show_param.source_width; i->height = show_param.source_height; do_alpha_resize(i, show_param.source_width, show_param.source_height); }}inline void do_revolve_left(struct image *i){ unsigned char *img=NULL; int y_pos=0, x_pos=0; int image_width = i->width; int image_height = i->height; unsigned char *p = i->rgb; unsigned char *rc = NULL; unsigned char *p_img=NULL; img = (unsigned char *)malloc(image_width*image_height*3); assert(img); p_img = img; memset((void *)img, 0x00, image_width*image_height*3); for (y_pos = 0; y_pos < image_height; y_pos++) { for (x_pos = image_width-1; x_pos >=0; x_pos--) { rc = p + y_pos*image_width*3 + x_pos*3; *(p_img+0) = *(rc+0); *(p_img+1) = *(rc+1); *(p_img+2) = *(rc+2); p_img = p_img + 3; } } if (i->rgb != image) free(i->rgb); i->rgb = img;}inline void do_alpha_revolve_left(struct image *i){ unsigned char *img=NULL; int y_pos=0, x_pos=0; int image_width = i->width; int image_height = i->height; unsigned char *p = i->alpha; unsigned char *rc = NULL; unsigned char *p_img=NULL; img = (unsigned char *)malloc(image_width*image_height); assert(img); p_img = img; memset((void *)img, 0x00, image_width*image_height); for (y_pos = 0; y_pos < image_height; y_pos++) { for (x_pos = image_width-1; x_pos >=0; x_pos--) { rc = p + y_pos*image_width + x_pos; *p_img = *rc; p_img = p_img + 1; } } if (i->alpha != alpha) free(i->alpha); i->alpha = img;}inline void do_revolve_updown(struct image *i){ unsigned char *img=NULL; int y_pos=0, x_pos=0; int image_width = i->width; int image_height = i->height; unsigned char *p = i->rgb; unsigned char *rc = NULL; unsigned char *p_img = NULL; img = (unsigned char *)malloc(image_width*image_height*3); assert(img); p_img = img; memset((void *)img, 0x00, image_width*image_height*3); for (y_pos = image_height-1; y_pos >= 0; y_pos--) { rc = p + y_pos*image_width*3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -