⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mga_view.c

📁 linux下显示各种格式图片
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  MGA View - image viewer using Matrox or framebuffer device * * *  (C) Copyright 2002      by HelDoRe <tehace@konto.pl> * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License Version 2 as *  published by the Free Software Foundation. * *  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 "mga_view.h"#include "output/mga_vfb.h"#include "output/mga_vmga.h"#include "input/mga_lbm.h"#include "input/mga_bmp.h"#include "input/mga_tga.h"#include "input/mga_gif.h"#include "input/mga_tif.h"#include "input/mga_pcx.h"#include "input/mga_xwd.h"#include "input/mga_xpm.h"#include "input/mga_pxm.h"#include "input/mga_jpg.h"#include "input/mga_png.h"#include "input/mga_zmg.h"#include "input/mga_hrz.h"#include "input/mga_epa.h"#include "input/mga_pic.h"#include "input/mga_raw.h"#include "input/mga_pi2.h"#include "input/mga_mtv.h"#include "input/mga_pat.h"#include "input/mga_vst.h"#include "input/mga_pix.h"#include "input/mga_pi3.h"#include "input/mga_rgb.h"#include "input/mga_cut.h"#include "input/mga_rix.h"#include "input/mga_ras.h"#include "input/mga_ska.h"#include "input/mga_pi4.h"#include "input/mga_psd.h"#include "input/mga_mag.h"int check_image(int ix,int iy,int id){if ((ix>ogr_x) || (iy>ogr_y) || (id>32) || (ix<=0) || (iy<=0) || (id<=0)) {    return 3;}	ix++;	iy++;	if (ix*iy<256) ix=256;	tabr=(unsigned char*)malloc(ix*iy);	if (!tabr) fprintf(stderr,"Malloc error (tabr)\n");	tabg=(unsigned char*)malloc(ix*iy);	if (!tabg) fprintf(stderr,"Malloc error (tabg)\n");	tabb=(unsigned char*)malloc(ix*iy);	if (!tabb) fprintf(stderr,"Malloc error (tabb)\n");	tab2r=(unsigned char*)malloc(ix*iy);	if (!tab2r) fprintf(stderr,"Malloc error (tab2r)\n");	tab2g=(unsigned char*)malloc(ix*iy);	if (!tab2g) fprintf(stderr,"Malloc error (tab2g)\n");	tab2b=(unsigned char*)malloc(ix*iy);	if (!tab2b) fprintf(stderr,"Malloc error (tab2b)\n");return 0;}void keysy(char *name){ 	    fprintf(stderr,"Usage : \x1B[0;38m%s image_file \x1B[0;0m[*]\n\n",name);	    fprintf(stderr,"Available key commands :\n");	    fprintf(stderr,"          r - reload image\n");	    fprintf(stderr,"      SPACE - next image\n");	    fprintf(stderr,"  BACKSPACE - previous image\n");	    fprintf(stderr,"          f - fullscreen\n");	    fprintf(stderr,"          c - compress/uncompress ZMG\n");	    fprintf(stderr,"          g - grayscale/color\n");	    fprintf(stderr,"          s - save to TGA/ZMG\n");	    fprintf(stderr,"          p - rotate image\n");	    fprintf(stderr,"          [ ] - flip image\n");	    if (is_matrox==1) {	    fprintf(stderr,"          t - transparent display on/off\n");	    }	    fprintf(stderr,"\n  %s [-f|--formats] displays a list of supported file formats",name);	    fprintf(stderr,"\n  %s [-z|--zoom] displays image in fullscreen\n",name);	    fprintf(stderr,"\n");}void fory(){	help_bmp();	help_pic();	help_cut();	help_pi2();	help_epa();	help_gfl();	help_gif();	help_hrz();	help_jpg();	help_lbm();	help_mag();	help_mtv();	help_pat();	help_pcx();	help_pi3();	help_pi4();	help_pix();	help_png();	help_psd();	help_pxm();	help_ras();	help_raw();	help_rgb();	help_rix();	help_ska();	help_tga();	help_tiff();	help_vst();	help_xpm();	help_xwd();	help_zmg();	printf("\n(*) - read/write\n\n");}int long_help(char *name){	int dis;	char help[6] = "--help";	char help2[2] = "-h";	char forms[9] = "--formats";	char forms2[2] = "-f";        char zoom[2] = "-z";        char zoom2[6] = "--zoom";		dis=0;	for (x=0;x<6;x++) {	 if (mee[x]!=help[x]) dis =1;	 }	if (dis==0) {	keysy(name);	exit(0);	}	dis=0;	for (x=0;x<2;x++) {	 if (mee[x]!=help2[x]) dis =1;	 }	if (dis==0) {	keysy(name);	exit(0);	}	dis=0;	for (x=0;x<9;x++) {	 if (mee[x]!=forms[x]) dis =1;	 }	if (dis==0) {	fory();	exit(0);	}	dis=0;	for (x=0;x<2;x++) {	 if (mee[x]!=forms2[x]) dis =1;	 }	if (dis==0) {	fory();	exit(0);	}        start_zoom=1;	for (x=0;x<2;x++) {	 if (mee[x]!=zoom[x]) start_zoom =0;	 }        if (start_zoom!=1) 	{	 start_zoom = 1;	for (x=0;x<6;x++) {	 if (mee[x]!=zoom2[x]) start_zoom =0;	 }        }	if (dis==1) return 1;	return 0;}int set_raw(int t){	static struct termio tty ;	struct termio tmp ;	if (t) {		ioctl(0,TCGETA,&tty) ;		tmp = tty ;		tmp.c_lflag &= ~(ICANON|ECHO) ;		tmp.c_cc[VMIN] = 1 ;		tmp.c_cc[VTIME] = 0 ;		ioctl(0,TCSETA,&tmp) ;	}	else 		ioctl(0,TCSETA,&tty) ;	return 0;      }charkbhit() {	char tmp ;	if (read(0,&tmp,1) < 1)	   return -1 ;	return tmp ;     }void rgb_yuv(int SRC_IMAGE_WIDTH,int SRC_IMAGE_HEIGHT)	{	int xxx,yyy;			xxx=image_x-dodajx;	yyy=image_y-dodajy;	i=0;j=0;	for (y=0;y<SRC_IMAGE_HEIGHT;y++) 	    {	     for (x=0;x<SRC_IMAGE_WIDTH;x++)	         {                    y_image[i] = ((RY*(tabr[j])+GY*tabg[j]+BY*tabb[j])>>RGB2YUV_SHIFT)+16;		    i++;		    if (dodajx !=0 && x!=image_x-1) j++;		    if (dodajx==0) j++;		 }	    }	r=0;g=0;i=0;	for (y=0;y<SRC_IMAGE_HEIGHT/2;y++) 	    {	    r=0;	    for (x=0;x<SRC_IMAGE_WIDTH/2;x++)	        {		cr_image[i] = ((RV*((tabr[r+(g*xxx)]+tabr[r+1+(g*xxx)]+tabr[r+((g+1)*xxx)]+tabr[r+1+((g+1)*xxx)])/4)+				GV*((tabg[r+(g*xxx)]+tabg[r+1+(g*xxx)]+tabg[r+((g+1)*xxx)]+tabg[r+1+((g+1)*xxx)])/4)+				BV*((tabb[r+(g*xxx)]+tabb[r+1+(g*xxx)]+tabb[r+((g+1)*xxx)]+tabb[r+1+((g+1)*xxx)])/4))>>RGB2YUV_SHIFT)+128;		cb_image[i++] = ((RU*((tabr[r+(g*xxx)]+tabr[r+1+(g*xxx)]+tabr[r+((g+1)*xxx)]+tabr[r+1+((g+1)*xxx)])/4)+				  GU*((tabg[r+(g*xxx)]+tabg[r+1+(g*xxx)]+tabg[r+((g+1)*xxx)]+tabg[r+1+((g+1)*xxx)])/4)+				  BU*((tabb[r+(g*xxx)]+tabb[r+1+(g*xxx)]+tabb[r+((g+1)*xxx)]+tabb[r+1+((g+1)*xxx)])/4))>>RGB2YUV_SHIFT)+128;		r+=2;		}	    g+=2;	    }	} void yuv_rgb(int SRC_IMAGE_WIDTH,int SRC_IMAGE_HEIGHT)	{		int r,g,b;		int xxx,yyy;				xxx=image_x-dodajx;		yyy=image_y-dodajy;		i=0;		for (y=0;y<SRC_IMAGE_HEIGHT;y++) {		    for (x=0;x<SRC_IMAGE_WIDTH;x++) {		    g=(1.164*(y_image[i]-32)-0.391*(cb_image[(x/2)+((SRC_IMAGE_WIDTH/2)*(y/2))]-128)-0.813*(cr_image[(x/2)+((SRC_IMAGE_WIDTH/2)*(y/2))]-128));		    r=(1.164*(y_image[i]-32)+1.596*(cr_image[(x/2)+((SRC_IMAGE_WIDTH/2)*(y/2))]-128));		    b=(1.164*(y_image[i]-32)+2.018*(cb_image[(x/2)+((SRC_IMAGE_WIDTH/2)*(y/2))]-128));		    if (r<0) r=0;		    if (g<0) g=0;		    if (b<0) b=0;		    tabr[x+(y*image_x)]=r;		    tabg[x+(y*image_x)]=g;		    tabb[x+(y*image_x)]=b;		    i++;		    }		}}void draw_image(int SRC_IMAGE_WIDTH,int SRC_IMAGE_HEIGHT){	if (YU12==0) rgb_yuv(SRC_IMAGE_WIDTH,SRC_IMAGE_HEIGHT);		  	mga_init();	write_frame(y_image,cr_image,cb_image);}void rotate_img() {	    i=image_x;	    image_x=image_y;	    image_y=i;	    if ((YU12==0) || ((YU12==1) && (is_matrox==0))) {	    memcpy(tab2r,tabr,image_x*image_y);	    memcpy(tab2g,tabg,image_x*image_y);	    memcpy(tab2b,tabb,image_x*image_y);	    i=0;	    for (x=0;x<image_x;x++)		for (y=0;y<image_y;y++)		{		tabr[x+image_x*(image_y-y)]=tab2r[i];		tabg[x+image_x*(image_y-y)]=tab2g[i];		tabb[x+image_x*(image_y-y)]=tab2b[i++];		}	    } else {	    memcpy(tab2r,y_image,image_x*image_y);	    memcpy(tab2g,cr_image,image_x*image_y/2);	    memcpy(tab2b,cb_image,image_x*image_y/2);	    i=0;	    for (x=0;x<image_x;x++)		for (y=0;y<image_y;y++)		y_image[x+image_x*(image_y-y)]=tab2r[i++];	    i=0;	    for (x=0;x<image_x/2;x++)		for (y=0;y<image_y/2;y++) {		cr_image[x+(image_x/2)*((image_y/2)-y)]=tab2g[i];		cb_image[x+(image_x/2)*((image_y/2)-y)]=tab2b[i++];		}					    }	    }	    void flip_image_v(){int xxx,yyy;xxx=image_x-dodajx;yyy=image_y-dodajy;if ((YU12==0) || ((YU12==1) && (is_matrox==0))) {    for (y=0;y<yyy/2;y++) 	for (x=0;x<xxx;x++) {	    i=tabr[x+xxx*y];	    tabr[x+xxx*y]=tabr[x+xxx*(yyy-y-1)];	    tabr[x+xxx*(yyy-y-1)]=i;	    i=tabg[x+xxx*y];	    tabg[x+xxx*y]=tabg[x+xxx*(yyy-y-1)];	    tabg[x+xxx*(yyy-y-1)]=i;	    i=tabb[x+xxx*y];	    tabb[x+xxx*y]=tabb[x+xxx*(yyy-y-1)];	    tabb[x+xxx*(yyy-y-1)]=i;	}	if (is_matrox==1) draw_image(image_x,image_y); else draw_image_fb(0);	} else {    for (y=0;y<yyy/2;y++) 	for (x=0;x<xxx;x++) {	    i=y_image[x+xxx*y];	    y_image[x+xxx*y]=y_image[x+xxx*(yyy-y-1)];	    y_image[x+xxx*(yyy-y-1)]=i;	}	xxx=xxx/2;	yyy=yyy/2;    for (y=0;y<yyy/2;y++) 	for (x=0;x<xxx;x++) {	    i=cr_image[x+xxx*y];	    cr_image[x+xxx*y]=cr_image[x+xxx*(yyy-y-1)];	    cr_image[x+xxx*(yyy-y-1)]=i;	    i=cb_image[x+xxx*y];	    cb_image[x+xxx*y]=cb_image[x+xxx*(yyy-y-1)];	    cb_image[x+xxx*(yyy-y-1)]=i;	}			write_frame(y_image,cr_image,cb_image);	}}void flip_image_h(){int xxx,yyy;xxx=image_x-dodajx;yyy=image_y-dodajy;if ((YU12==0) || ((YU12==1) && (is_matrox==0))) {for (x=0;x<xxx/2;x++)     for (y=0;y<yyy;y++) {	i=tabr[x+xxx*y];	tabr[x+xxx*y]=tabr[xxx-x-1+xxx*y];	tabr[xxx-x-1+xxx*y]=i;	i=tabg[x+xxx*y];	tabg[x+xxx*y]=tabg[xxx-x-1+xxx*y];	tabg[xxx-x-1+xxx*y]=i;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -