示例#1
0
void main(int argc, char** argv){
	init_window(argc, argv);
	other_init();
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutVisibilityFunc(visible);
	glutKeyboardFunc(keyboard);
	glutMouseFunc(mouse);
	glutIdleFunc(idle);
	glutMainLoop();

	getchar(); getchar();
}
示例#2
0
文件: capture.c 项目: alannet/example
	int main(int argc, char *argv[])
	{
		//FB设备的文件描述符
		int fd;
		int x, y;
		int c;
        	int lp;
		unsigned char ch;
		FILE *fp = fopen("screendump.xpm", "w");

		//结构
		struct fb_fix_screeninfo finfo;
		struct fb_var_screeninfo vinfo;

		//打开设备
		fd = open("/dev/fb0", O_RDWR);
		if (!fd) {
			printf("Cannot open framebuffer device.\n");
			exit(1);
		}

		//取得固定信息
		if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo)) {
			printf("Error reading fixed information.\n");
			exit(1);
		}
		if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo)) {
			printf("Error reading variable information.\n");
			exit(1);
		}

		//VGA16 模式
		if(vinfo.bits_per_pixel == 4){
			vga16_init(fd, &finfo, &vinfo);
			fprintf(fp, "/* XPM */\n");
			fprintf(fp, "static char *xxxx[] = {\n");
			fprintf(fp, "/* width height num_colors chars_per_pixel */\n");
			fprintf(fp, "\"    640    480       16            1\",\n");
			fprintf(fp, "/* colors */\n");
			fprintf(fp, "\"0	c #000000\",\n");
			fprintf(fp, "\"1	c #0000aa\",\n");
			fprintf(fp, "\"2	c #00aa00\",\n");
			fprintf(fp, "\"3	c #00aaaa\",\n");
			fprintf(fp, "\"4	c #aa0000\",\n");
			fprintf(fp, "\"5	c #aa00aa\",\n");
			fprintf(fp, "\"6	c #aaaa00\",\n");
			fprintf(fp, "\"7	c #aaaaaa\",\n");
			fprintf(fp, "\"8	c #555555\",\n");
			fprintf(fp, "\"9	c #5555ff\",\n");
			fprintf(fp, "\"a	c #55ff55\",\n");
			fprintf(fp, "\"b	c #55ffff\",\n");
			fprintf(fp, "\"c	c #ff5555\",\n");
			fprintf(fp, "\"d	c #ff55ff\",\n");
			fprintf(fp, "\"e	c #ffff55\",\n");
			fprintf(fp, "\"f	c #ffffff\",\n");
			for(y = 0; y < 480; y ++){
				fprintf(fp, "\"");
				for(x = 0; x < 640; x ++){
					c = vga16_read_pixel(x, y);
					fprintf(fp, "%x", c);
				}
				fprintf(fp, "\",\n");
			}
			fprintf(fp, "};\n");
		} else if(vinfo.bits_per_pixel == 8){	//256 色模式
	        	unsigned short g_red[256], g_green[256], g_blue[256];
		        struct fb_cmap cmap={ 0, 256, g_red, g_green, g_blue };

			other_init(fd, &finfo, &vinfo);

                        if (ioctl(fd,FBIOGETCMAP,&cmap) < 0) {
                                perror("ioctl FBIOGETCMAP");
                                exit(1);
                        }


			fprintf(fp, "/* XPM */\n");
			fprintf(fp, "static char *xxxx[] = {\n");
			fprintf(fp, "/* width height num_colors chars_per_pixel */\n");
			fprintf(fp, "\"    %d    %d       256            2\",\n",
				vinfo.xres, vinfo.yres);
			fprintf(fp, "/* colors */\n");
        		for(lp=0;lp<256;lp++){
                		fprintf(fp, "\"%02x	c #%02x%02x%02x\",\n", lp, 
					(unsigned char)(*(cmap.red+lp)), 
					(unsigned char)(*(cmap.green+lp)), 
					(unsigned char)(*(cmap.blue+lp)));
			}
			for(y = 0; y < vinfo.yres; y ++){
				fprintf(fp, "\"");
				for(x = 0; x < vinfo.xres; x ++){
					ch = other_read_pixel(x, y);
					fprintf(fp, "%02x", ch);
				}
				fprintf(fp, "\",\n");
			}
			fprintf(fp, "};\n");
		}
		fclose(fp);

		close(fd);
		return 0;
	}
示例#3
0
int main(int argc, char* argv[])
{
    bool segy;
    int i, i1, i2, n1, n2, n3, n, nt, len, nkey, row;
    sf_file in, out;
    int mem; /* for avoiding int to off_t typecast warning */
    off_t memsize;
    char *eq, *output, *key, *arg;
    float **ftra=NULL, **fbuf=NULL, **fst=NULL, d2, o2;
    int **itra=NULL, **ibuf=NULL, **ist=NULL;
    sf_datatype type;

    sf_init (argc,argv);
    in = sf_input ("in");
    out = sf_output ("out");

    sf_putint(out,"N",0);
    sf_putint(out,"T",1);
    sf_putint(out,"input",2);

    type = sf_gettype(in);

    if (SF_FLOAT != type && SF_INT != type) sf_error("Need float or int input");

    if (!sf_getbool("segy",&segy)) segy=true;
    /* if SEGY headers */

    if (!sf_histint(in,"n1",&n1)) n1=1;
    if (!sf_histint(in,"n2",&n2)) n2=1;
    n3 = sf_leftsize(in,2); /* left dimensions after the first two */

    if (segy) {
	segy_init(n1,in);
    } else {
	other_init(n1,in);
    }

    if (NULL != (key = sf_getstring("key"))) { 
	/* key to replace */
	row = segykey(key);
	free(key);
    } else {
	if (!sf_getint("nkey",&row)) row=-1;
	/* number of key to replace */
    }	
    if (row > n1) sf_error("nkey=%d is too large, need nkey <= %d",row,n1);
    
    if (n1 > 1) {
	if (n2 > 1) { /* input: many keys */
	    if (row < 0) sf_putint(out,"n1",1);
	} else { /* input: one key, arranged in n1 */
	    n2 = n1;
	    n1 = 1;
	}
    }


    for (i=0; i < n1; i++) {
	sf_putint(out,segykeyword(i),i+3);
    }

    for (i=1; i< argc; i++) { /* collect inputs */
	arg = argv[i];
	eq =  strchr(arg,'=');
	if (NULL == eq) continue; /* not a parameter */
	if (0 == strncmp(arg,"output",6) ||
	    0 == strncmp(arg,    "--",2)) continue; /* not a key */

	len = (size_t) (eq-arg);
	key = sf_charalloc(len+1);
	memcpy(key,arg,len);
	key[len]='\0';

	if (sf_getint(key,&nkey))
	    sf_putint(out,key,nkey+3);
	free(key);
    }
  
    if (!sf_histfloat(in,n1>1? "d2":"d1",&d2)) d2=1.;
    if (!sf_histfloat(in,n1>1? "o2":"o1",&o2)) o2=0.;

    if (NULL == (output = sf_getstring("output"))) sf_error("Need output=");
    /* Describes the output in a mathematical notation. */

    if (!sf_getint("memsize",&mem))
        mem=sf_memsize();
    /* Max amount of RAM (in Mb) to be used */
    memsize = mem * (1<<20); /* convert Mb to bytes */

    len = sf_math_parse (output,out,type);

    /* number of traces for optimal I/O */
    nt = SF_MAX(1,memsize/((2*n1+len+6)*sizeof(float)));

    if (SF_FLOAT == type) { /* float type */
	ftra = sf_floatalloc2(n1,nt);
	fbuf = sf_floatalloc2(nt,n1+3);
	fst  = sf_floatalloc2(nt,len+3);
    } else {               /* int type */
	itra = sf_intalloc2(n1,nt);
	ibuf = sf_intalloc2(nt,n1+3);
	ist  = sf_intalloc2(nt,len+3);
    }

    for (n=n2*n3; n > 0; n -= nt) {
	if (n < nt) nt=n;

	if (SF_FLOAT == type) { 
	    sf_floatread(ftra[0],n1*nt,in);
	} else {
	    sf_intread(itra[0],n1*nt,in);
	}

	for (i2=0; i2 < nt; i2++) {
	    if (SF_FLOAT == type) { 
		fbuf[0][i2]=(float) i2;  /* N */
		fbuf[1][i2]=o2+i2*d2;    /* T */
		fbuf[2][i2]=ftra[0][i2]; /* input */
	    } else {
		ibuf[0][i2]=i2;          /* N */
		ibuf[1][i2]=o2+i2*d2;    /* T */
		ibuf[2][i2]=itra[0][i2]; /* input */
	    }
	}
	for (i1=0; i1 < n1; i1++) {
	    for (i2=0; i2 < nt; i2++) {
		if (SF_FLOAT == type) { 
		    fbuf[i1+3][i2]=ftra[i2][i1];
		} else {
		    ibuf[i1+3][i2]=itra[i2][i1];
		}
	    }
	}
	
	if (SF_FLOAT == type) { 
	    sf_math_evaluate (len, nt, fbuf, fst);
	    if (row < 0) {
		sf_floatwrite(fst[1],nt,out);
	    } else {
		for (i2=0; i2 < nt; i2++) {
		    ftra[i2][row] = fst[1][i2];
		}
		sf_floatwrite(ftra[0],n1*nt,out);
	    }
	} else {
	    sf_int_math_evaluate (len, nt, ibuf, ist);
	    if (row < 0) {
		sf_intwrite(ist[1],nt,out);
	    } else {
		for (i2=0; i2 < nt; i2++) {
		    itra[i2][row] = ist[1][i2];
		}
		sf_intwrite(itra[0],n1*nt,out);
	    }
	}
    }

    exit(0);
}