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

📄 nxview.c

📁 PictureBrowser 是基于Altera 的DE2 开发板设计图像浏览器
💻 C
字号:
/* * Copyright (c) 2000, 2001 Greg Haerr <greg@censoft.com> * * nxview - Nano-X image viewer * * Autorecognizes and displays BMP, GIF, JPEG, PNG and XPM files */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <sys/time.h>#define MWINCLUDECOLORS#include "nano-X.h"intmain(int argc,char **argv){	GR_IMAGE_ID	image_id;	GR_WINDOW_ID	window_id;	GR_GC_ID	gc_id;	GR_SIZE		w = -1;	GR_SIZE		h = -1;	GR_EVENT	event;	GR_SCREEN_INFO	sinfo;	GR_IMAGE_INFO	info;	char		title[256];	//time_t begintime;             // use to find running time	//time_t endtime;	//time_t runtime;	//begintime = time (NULL);	struct timeval eval_time;  	struct timeval start_time;  	struct timeval end_time;  	gettimeofday(&start_time, NULL);	if (argc < 2) {		printf("Usage: nxview <image file> [stretch]\n");		exit(1);	}	if (GrOpen() < 0) {		fprintf(stderr, "cannot open graphics\n");		exit(1);	}		if (!(image_id = GrLoadImageFromFile(argv[1], 0))) {		fprintf(stderr, "Can't load image file: %s\n", argv[1]);		exit(1);	}	if(argc > 2) {		/* stretch to half screen size*/		GrGetScreenInfo(&sinfo);		printf("I am here");		w = sinfo.cols/2;		h = sinfo.rows/2;	} else {		GrGetImageInfo(image_id, &info);		w = info.width;		h = info.height;	}	sprintf(title, "nxview %s", argv[1]);	window_id = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, title,		GR_ROOT_WINDOW_ID, (640 - w)/2, (480 - h)/2, w, h, BLACK);	/*window_id = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, title,		GR_ROOT_WINDOW_ID, 0, 0, w, h, BLACK);*/	GrSelectEvents(window_id,		GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE);	GrMapWindow(window_id);	gc_id = GrNewGC();	//endtime = time(NULL);	gettimeofday(&end_time, NULL);  	int eval_secs = end_time.tv_sec - start_time.tv_sec;  	int eval_usecs = end_time.tv_usec - start_time.tv_usec;    	if (eval_usecs < 0) {		eval_secs -= 1;		eval_usecs += 1000000;	}  	int eval_msecs = eval_usecs/1000;  	printf("Runnig time: %d secs, %d msecs", eval_secs, eval_msecs);	//printf("Running time: %d seconds", endtime - begintime);	while (1) {		GrGetNextEvent(&event);		switch(event.type) {		case GR_EVENT_TYPE_CLOSE_REQ:			GrDestroyWindow(window_id);			GrDestroyGC(gc_id);			GrFreeImage(image_id);			GrClose();			exit(0);			/* no return*/		case GR_EVENT_TYPE_EXPOSURE:			GrDrawImageToFit(window_id, gc_id, 0,0, w,h, image_id);						break;		}	}		//endtime = time(NULL);		return 0;}

⌨️ 快捷键说明

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