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

📄 mga_vmga.c

📁 linux下显示各种格式图片
💻 C
字号:
#include "../mga_view.h"#include "mga_vmga.h"voidwrite_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb){	uint8_t *dest;	uint32_t bespitch,h,w;	dest = mga_vid_base;	bespitch = (config.src_width + 31) & ~31;	for(h=0; h < config.src_height; h++) 	{		memcpy(dest, y, config.src_width);		y += config.src_width;		dest += bespitch;	}	for(h=0; h < config.src_height/2; h++) 	{		for(w=0; w < config.src_width/2; w++) 		{			*dest++ = *cb++;			*dest++ = *cr++;		}		dest += bespitch - config.src_width;	}}voidwrite_frame_g400(uint8_t *y,uint8_t *cr, uint8_t *cb){	uint8_t *dest;	uint32_t bespitch,h;	dest = mga_vid_base;	bespitch = (config.src_width + 31) & ~31;	for(h=0; h < config.src_height; h++) 	{		memcpy(dest, y, config.src_width);		y += config.src_width;		dest += bespitch;	}	for(h=0; h < config.src_height/2; h++) 	{		memcpy(dest, cb, config.src_width/2);		cb += config.src_width/2;		dest += bespitch/2;	}	for(h=0; h < config.src_height/2; h++) 	{		memcpy(dest, cr, config.src_width/2);		cr += config.src_width/2;		dest += bespitch/2;	}}void write_frame(uint8_t *y,uint8_t *cr, uint8_t *cb){	if(is_g400)		write_frame_g400(y,cr,cb);	else		write_frame_g200(y,cr,cb);}void mga_size(){    int forc;    int xxx,yyy;	if (ori==1) {	    rotate_img();	    }	    	dodajx=0;dodajy=0;	scale_x=1;scale_y=1;		if (image_x !=(image_x/2)*2) {        image_x++;	    dodajx++;	}	if (image_y !=(image_y/2)*2) {	    image_y++;	    dodajy++;	}	xxx=image_x-dodajx;	yyy=image_y-dodajy;	if ((image_x<100) && (image_y<100) && (zoom==1)) {	    scale_x=3;	    scale_y=3;	fprintf(stderr,"Zooming to      : %ix%i\n",image_x*3,image_y*3);	}	if ((image_x>tx) || (image_y>ty)) {	    hx=xxx-tx;	    hy=yyy-ty;	    if (hx>hy) {	    scale=xxx;	    scale_x=(tx)/scale;	    scale_y=scale_x;	    } else {	    scale=yyy;	    scale_y=(ty)/scale;	    scale_x=scale_y;	    }	fprintf(stderr,"Scaling to      : %ix%i",(int)(scale_x*xxx),(int)(scale_y*yyy));	    if ( ((image_x>=tx) || (image_y>ty))){	    fprintf(stderr,"\x1B[1;30m (software)\x1B[0;0m\n");	    i=0;j=0;	    for (y=0;y<image_y-dodajy;y++) {		for (x=0;x<image_x-dodajx;x++) {		tabr[(int)((x*scale_x)+j)]=(tabr[i]+tabr[i+1])/2;		tabg[(int)((x*scale_x)+j)]=(tabg[i]+tabg[i+1])/2;		tabb[(int)((x*scale_x)+j)]=(tabb[i]+tabb[i+1])/2;		i++;		}		j=j+(int)(scale_x*xxx);		}	    image_x=(int)(scale_x*xxx);	    i=0;	    for (y=0;y<image_y-dodajy;y++) {		for (x=0;x<image_x;x++) {		    tabr[x+((int)(y*scale_x))*image_x]=(tabr[i]+tabr[i+1])/2;		    tabg[x+((int)(y*scale_x))*image_x]=(tabg[i]+tabg[i+1])/2;		    tabb[x+((int)(y*scale_x))*image_x]=(tabb[i]+tabb[i+1])/2;		    i++;		}		}	    image_y=(int)(scale_y*yyy);	dodajx=0;dodajy=0;	if (image_x !=(image_x/2)*2) {	    image_x++;	    dodajx=1;        }	if (image_y !=(image_y/2)*2) {	    image_y++;	    dodajy=1;	}	    scale_x=1;	    scale_y=1;//	    fprintf(stderr,"%i %i %i %i \n",dodajx,dodajy,image_x,image_y);	    } else fprintf(stderr,"\x1B[1;30m (hardware)\x1B[0;0m\n");	}// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#warning if image size >=1024x768 program crash ...	if ((image_x>=980) && (image_y>=682) && (tx>=1024) && (ty>=768)) {	    scale=image_y;	    forc=image_y-682;	    scale_y=(ty-forc)/scale;	    scale_x=1;	    i=0;	    for (y=0;y<image_y-dodajy;y++) {		for (x=0;x<image_x;x++) {		    tabr[x+((int)(y*scale_x))*image_x]=(tabr[i]+tabr[i+1])/2;		    tabg[x+((int)(y*scale_x))*image_x]=(tabg[i]+tabg[i+1])/2;		    tabb[x+((int)(y*scale_x))*image_x]=(tabb[i]+tabb[i+1])/2;		    i++;		}		}	    image_y=(int)(scale_y*image_y);	if (image_y !=(image_y/2)*2) {	    image_y++;	    dodajy=1;	}	    scale_x=1;	    scale_y=scale/(ty-forc);	    	    fprintf(stderr,"#fixme (y>681)  : force scale\n");#warning ... force scale to 1024x682 and hardware scale to 1024x768	    }// trzeba zoptymalizowac}void mga_init(){		config.version = MGA_VID_VERSION;	config.src_width = image_x;	config.src_height= image_y;	config.dest_width = image_x*scale_x;	config.dest_height = image_y*scale_y;	config.x_org= (tx-image_x*scale_x)/2;	config.y_org= (ty-image_y*scale_y)/2;	config.colkey_on = trans;        config.format = MGA_VID_FORMAT_YV12;	config.frame_size=image_x*image_y*2;	config.num_frames=1;	if (ioctl(f,MGA_VID_CONFIG,&config))	{		perror("Error in config ioctl\n");	}	if (config.card_type == MGA_G200) 	{	  is_g400 = 0;	    jaka=200;	}	else	{	    jaka=400;	  is_g400 = 1;	}		ioctl(f,MGA_VID_ON,0);	mga_vid_base = (uint8_t*)mmap(0,256 * 4096,PROT_WRITE,MAP_SHARED,f,0);//		fprintf(stderr,"MGA G%i with %d MB RAM\n",jaka, config.ram_size);	x_org=config.dest_width;	y_org=config.dest_height;}void mga_grey(){	uint8_t *dest;	uint32_t bespitch,h,w,i;	if (grey==0) grey++; else grey=0;	if (grey==0) {	    if (zmgm==3) zmgm=1;	    if (zmgm==4) zmgm=2;	    }	if (grey==1) {	    if (zmgm==1) zmgm=3;	    if (zmgm==2) zmgm=4;	    }	dest = mga_vid_base;	bespitch = (config.src_width + 31) & ~31;	for(h=0; h < config.src_height; h++) 	{		dest += bespitch;	}	i=0;	for(h=0; h < config.src_height/2; h++) 	{		for(w=0; w < config.src_width/2; w++) 		{	if (grey==1) {			*dest++ =-127;			*dest++ =-127;	}	if (grey==0) {			*dest++ =cb_image[i];			*dest++ =cr_image[i++];	}		}		dest += bespitch - config.src_width;	}		if (ioctl(f,MGA_VID_CONFIG,&config))	{		perror("Error in config ioctl\n");	}	if (config.card_type == MGA_G200) 	{	  is_g400 = 0;	    jaka=200;	}	else	{	    jaka=400;	  is_g400 = 1;	}		ioctl(f,MGA_VID_ON,0);	mga_vid_base = (uint8_t*)mmap(0,256 * 4096,PROT_WRITE,MAP_SHARED,f,0);}void mga_fs(){    float xx,yy;	if ((fullscr<2) && (fullscr!=4)) fullscr++; else if (fullscr!=4) fullscr=0;	if (fullscr==1) {	xx=(float)tx/image_x;	yy=(float)ty/image_y;	if (xx<yy) yy=xx; else xx=yy;	if (xx<=1) fullscr++;	config.dest_width = (int)(image_x*xx);	config.dest_height = (int)(image_y*yy);		config.x_org= (tx-(int)(image_x*xx))/2;	config.y_org= (ty-(int)(image_y*yy))/2;	}	if (fullscr==2) {	config.dest_width = tx;	config.dest_height = ty;	config.x_org= 0;	config.y_org= 0;	if ((image_x>=tx) && (image_y>=ty)) fullscr=0;	}	if (fullscr==0) {	config.dest_width = image_x*scale_x;	config.dest_height = image_y*scale_y;	config.x_org= (tx-image_x*scale_x)/2;	config.y_org= (ty-image_y*scale_y)/2;	}	if (fullscr==4) {	fullscr=0;	xx=(float)(tx-200)/image_x;	yy=(float)(ty-150)/image_y;	if (xx<yy) yy=xx; else xx=yy;//	if (xx<=1) fullscr++;	config.dest_width = (int)(image_x*xx);	config.dest_height = (int)(image_y*yy);		config.x_org= (tx-(int)(image_x*xx))/2;	config.y_org= (ty-(int)(image_y*yy))/2;	}		config.version = MGA_VID_VERSION;	config.src_width = image_x;	config.src_height= image_y;	config.colkey_on = trans;        config.format = MGA_VID_FORMAT_YV12;	config.frame_size=image_x*image_y*2;	config.num_frames=1;	if (ioctl(f,MGA_VID_CONFIG,&config))	{		perror("Error in config ioctl\n");	}	if (config.card_type == MGA_G200) 	{	  is_g400 = 0;	    jaka=200;	}	else	{	    jaka=400;	  is_g400 = 1;	}		ioctl(f,MGA_VID_ON,0);	mga_vid_base = (uint8_t*)mmap(0,256 * 4096,PROT_WRITE,MAP_SHARED,f,0);}void mga_transp(){	config.version = MGA_VID_VERSION;	if (trans==0) trans=1; else trans=0;	config.colkey_on = trans;	if (ioctl(f,MGA_VID_CONFIG,&config))	{		perror("Error in config ioctl\n");	}	if (config.card_type == MGA_G200) 	{	  is_g400 = 0;	    jaka=200;	}	else	{	    jaka=400;	  is_g400 = 1;	}	ioctl(f,MGA_VID_ON,0);	mga_vid_base = (uint8_t*)mmap(0,256 * 4096,PROT_WRITE,MAP_SHARED,f,0);}void mga_uninit(){	ioctl(f,MGA_VID_OFF,0);	close(f);}

⌨️ 快捷键说明

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