示例#1
0
void *change_graph(void *arg)
/* 功能:改变显示的图形 */
{
	LCUI_Widget *widget = (LCUI_Widget *)arg;
	int i;
	LCUI_Graph frame, temp;
	Graph_Init(&frame);/* 初始化 */
	Load_Image("ring.png", &frame);/* 载入之 */  
	/* 居中显示图形 */
	Set_Widget_Align(widget, ALIGN_MIDDLE_CENTER, Pos(0, -20));
	Set_PictureBox_Size_Mode(widget, SIZE_MODE_CENTER);
	Show_Widget(widget);
	while(1)
	{
		Set_PictureBox_Image_From_Graph(widget, &frame);
		for(i=10; i<=360; i+=10)
		{
			Rotate_Graph(&frame, i, &temp);
			Set_PictureBox_Image_From_Graph(widget, &temp);
			usleep(20000);
		}
	}
	LCUI_Thread_Exit(NULL);
}
示例#2
0
int main(int argc, char *argv[])
{
	/* user parameters */
	static struct isp_node upipe;
	/* command line argument index */
	int opt_idx;

	if (argc == 1 || (argc == 2 && (!strcmp(argv[1], "?") ||
	!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))) {
		fprintf(stderr, "\nUSAGE: command <options>");
		opt_idx = get_option_index("-ifile",
			cmd_line, COUNT_OF(cmd_line));
		fprintf(stderr, " %s<input file>",
			cmd_line[opt_idx].o_symb);
		opt_idx = get_option_index("-ofile",
			cmd_line, COUNT_OF(cmd_line));
		fprintf(stderr, " %s<output file>\n",
			cmd_line[opt_idx].o_symb);
		print_options(cmd_line, COUNT_OF(cmd_line));

		/* Print additional help */
		printf("\nExamples:\n");

		printf("\nResize image: \n ");
		printf("reszhq -iw [in width] -ih [in height] "\
			"-ifile [input file] "\
			"-ow [out width] -oh [out height] "\
			"-ofile [output file]\n");

		exit(EXIT_FAILURE);
	}

	if (parse_prepare(argc, argv, cmd_line, COUNT_OF(cmd_line)))
		exit(errno);

	if (setup_user_parameters(&upipe, cmd_line, COUNT_OF(cmd_line)))
		exit(errno);

	/* index of input file name argument */
	opt_idx = get_option_index("-ifile", cmd_line, COUNT_OF(cmd_line));
	if (!cmd_line[opt_idx].o_dflt.v_char) {
		error(-1, ECANCELED, "Input file parameter missing.");
		exit(errno);
	}

	/* index of output file name argument */

	opt_idx = get_option_index("-ofile", cmd_line, COUNT_OF(cmd_line));
	if (!cmd_line[opt_idx].o_dflt.v_char) {
		error(-1, ECANCELED, "Output file parameter missing.");
		exit(errno);
	}

	int rz_fd;
	/* index of device name */
	opt_idx = get_option_index("-dev", cmd_line, COUNT_OF(cmd_line));
	rz_fd = open(cmd_line[opt_idx].o_dflt.v_char, O_RDWR);

	if (rz_fd < 0) {
		error(-1, ECANCELED, "Can't open device.");
		exit(errno);
	}
	printf(" Before  RSZ_S_PARAM : ");
	printf("%dx%d->", upipe.in.image.width, upipe.in.image.height);
	printf("%dx%d \n ", upipe.out.image.width, upipe.out.image.height);

	if (ioctl(rz_fd, RSZ_S_PARAM, &upipe) == -1) {
		error(-1, ECANCELED, "Invalid config parameters.");
		exit(errno);
	}

	printf(" After  RSZ_S_PARAM : ");
	printf("%dx%d->", upipe.in.image.width, upipe.in.image.height);
	printf("%dx%d \n ", upipe.out.image.width, upipe.out.image.height);

	/* V4L2 Buffer */
	struct v4l2_requestbuffers v4l2_req;
	/* user buffer source pointer */
	struct v4l2_buffer src_ubuf;
	struct v4l2_buffer dst_ubuf;

	/* clear buffers */
	memset(&v4l2_req, 0, sizeof(v4l2_req));
	memset(&src_ubuf, 0, sizeof(src_ubuf));
	memset(&dst_ubuf, 0, sizeof(dst_ubuf));
	void * inBuf;
	void * outBuf;

	/* V4L2 Memory map type */
	v4l2_req.memory	= V4L2_MEMORY_USERPTR;
	/* V4L2 The number of buffers requested */
	v4l2_req.count	= 1;
	/* V4L2 Buffer type */
	v4l2_req.type	= V4L2_BUF_TYPE_VIDEO_OUTPUT;

	if (ioctl(rz_fd, RSZ_REQBUF, &v4l2_req)) {
		error(-1, ECANCELED, "input: REQBUF failed.");
		exit(errno);
	}

	/* setup input buffer parameters */
	src_ubuf.index	= 0;
	src_ubuf.type	= V4L2_BUF_TYPE_VIDEO_OUTPUT;
	src_ubuf.memory	= v4l2_req.memory;
	/* calculate input buffer length */
	src_ubuf.length	= ALIGN(upipe.in.image.bytesperline *
					upipe.in.image.height, PAGE_SIZE);

	/* V4L2 - Query input buffer */
	if (ioctl(rz_fd, RSZ_QUERYBUF, &src_ubuf)) {
		error(-1, ECANCELED, "RSZ_QUERYBUF failed.");
		exit(errno);
	}

	/* allocate input data buffer */
	inBuf =  malloc(src_ubuf.length + PAGE_SIZE);
	if (inBuf == NULL ) {
		perror("input: Can't allocate memory");
		exit(errno);
	}

	src_ubuf.m.userptr = (unsigned long)(ALIGN(inBuf, PAGE_SIZE));

	if (!src_ubuf.m.userptr) {
		perror("input: Can't allocate memory");
		exit(errno);
	}


	/* V4L2 - Setup input buffer in queue */
	if (ioctl(rz_fd, RSZ_QUEUEBUF, &src_ubuf)) {
		error(-1, ECANCELED, "RSZ_QUEUEBUF failed.");
		exit(errno);
	}

	/* index of options for input file name */
	opt_idx = get_option_index("-ifile", cmd_line, COUNT_OF(cmd_line));
	/* load data buffer */
	if (Load_Image(cmd_line[opt_idx].o_dflt.v_char,
			(char *)src_ubuf.m.userptr, src_ubuf.length)) {
		error(-1, ECANCELED, "File load error.");
		exit(errno);
	}

	/* V4L2 Memory map type */
	v4l2_req.memory	= V4L2_MEMORY_USERPTR;
	/* V4L2 The number of buffers requested */
	v4l2_req.count	= 1;
	/* V4L2 Buffer type */
	v4l2_req.type	= V4L2_BUF_TYPE_VIDEO_CAPTURE;

	if (ioctl(rz_fd, RSZ_REQBUF, &v4l2_req)) {
		error(-1, ECANCELED, "RSZ_REQBUF failed.");
		exit(errno);
	}
	/* setup output buffer parameters */
	dst_ubuf.index	= 0;
	dst_ubuf.type	= V4L2_BUF_TYPE_VIDEO_CAPTURE;
	dst_ubuf.memory	= v4l2_req.memory;
	/* calculate buffer/buffers length */
	dst_ubuf.length	= ALIGN(upipe.out.image.bytesperline *
					upipe.out.image.height, PAGE_SIZE);

	/* V4L2 - Query output buffer */
	if (ioctl(rz_fd, RSZ_QUERYBUF, &dst_ubuf)) {
		error(-1, ECANCELED, "RSZ_QUERYBUF failed.");
		exit(errno);
	}
#if 0
	/* allocate output buffer */
	dst_ubuf.maddr = malloc(dst_ubuf.length);
	if (dst_ubuf.maddr == 0) {
		error(-1, ECANCELED, "Buffer allocation failed.");
		exit(errno);
	}
	/* align and setup ouput pointer */
	dst_ubuf.m.userptr = (unsigned long) (ALIGN(dst_ubuf.maddr, PAGE_SIZE));
#else
	/* allocate input data buffer */

	outBuf =  malloc(dst_ubuf.length + PAGE_SIZE);
	if (outBuf == NULL ) {
		perror("input: Can't allocate memory");
		exit(errno);
	}

	dst_ubuf.m.userptr = (unsigned long)(ALIGN(outBuf, PAGE_SIZE));

	if (!dst_ubuf.m.userptr) {
		perror("input: Can't allocate memory");
		exit(errno);
	}
#endif
	/* V4L2 - Setup output buffer in queue */
	if (ioctl(rz_fd, RSZ_QUEUEBUF, &dst_ubuf)) {
		error(-1, ECANCELED, "RSZ_QUEUEBUF failed.");
		exit(errno);
	}

#if !defined(NDEBUG)
	/* initialize start time */
	struct timeval beg_tv; gettimeofday(&beg_tv, NULL);
#endif

	/*
	 * Execute operation
	 */
	if (ioctl(rz_fd, RSZ_RESIZE, &upipe) == -1) {
		error(-1, ECANCELED, "RSZ_RESIZE error\n");
		exit(errno);
	}

#if !defined(NDEBUG)
	/* initialize end time */
	struct timeval end_tv; gettimeofday(&end_tv, NULL);
	fprintf(stderr, "\nOperation finished: %ld (usec)\n",
			(end_tv.tv_sec - beg_tv.tv_sec) * 1000000 +
			(end_tv.tv_usec - beg_tv.tv_usec)
	);
#endif

	/* index of options for output file name */
	opt_idx = get_option_index("-ofile", cmd_line, COUNT_OF(cmd_line));
	/* save image */
	if (Save_Image(cmd_line[opt_idx].o_dflt.v_char,
		(char *)dst_ubuf.m.userptr,
		upipe.out.image.bytesperline * upipe.out.image.height)) {
		error(-1, ECANCELED, "File save error");
		exit(errno);
	}

	/* release allocated buffers */
	if (src_ubuf.m.userptr)
		free(inBuf);

	if (dst_ubuf.m.userptr)
		free(outBuf);

	if (rz_fd)
		close(rz_fd);

	parse_release(cmd_line, COUNT_OF(cmd_line));

	return 0;
}
示例#3
0
文件: clock.c 项目: yydaor/LCUI
void update_clock(void *arg)
{
	time_t rawtime;
	struct tm * timeinfo;
	LCUI_Graph h_temp, m_temp, clock_bg, hour_pointer, minute_pointer;
	LCUI_Widget *widget;
	LCUI_Widget *bg, *hour, *minute; 
	int h_angle, m_angle;
	
	widget = (LCUI_Widget *)arg;
	/* 初始化图形数据结构 */
	Graph_Init(&clock_bg);
	Graph_Init(&minute_pointer);
	Graph_Init(&hour_pointer);
	Graph_Init(&h_temp);
	Graph_Init(&m_temp);
	/* 创建几个部件 */
	bg = Widget_New("picture_box");
	hour = Widget_New("picture_box");
	minute = Widget_New("picture_box");
	/* PictureBox部件居中显示图片 */
	PictureBox_SetSizeMode(bg, SIZE_MODE_CENTER);
	PictureBox_SetSizeMode(hour, SIZE_MODE_CENTER);
	PictureBox_SetSizeMode(minute, SIZE_MODE_CENTER);
	/* 载入图片,保存图形数据 */
	Load_Image("new_daytime_background.png", &clock_bg);
	Load_Image("new_daytime_hour.png", &hour_pointer);
	Load_Image("new_daytime_minute.png", &minute_pointer);
	/* 设定PictureBox部件显示的图形 */
	PictureBox_SetImage(bg, &clock_bg);
	PictureBox_SetImage(hour, &hour_pointer);
	PictureBox_SetImage(minute, &minute_pointer);
	/* 将这些部件添加至相应容器中 */
	Widget_Container_Add(bg, hour);
	Widget_Container_Add(bg, minute);
	/* 将部件添加至窗口客户区中 */
	Window_ClientArea_Add(widget, bg);
	/* 改变部件尺寸,使用固定的尺寸 */
	Widget_Resize(bg, Size(280, 280));
	Widget_Resize(hour, Size(120, 120));
	Widget_Resize(minute, Size(120, 120));
	/* 改变部件的布局方式,都是居中显示 */
	Widget_SetAlign(bg, ALIGN_MIDDLE_CENTER, Pos(0, 0));
	Widget_SetAlign(hour, ALIGN_MIDDLE_CENTER, Pos(0, 0));
	Widget_SetAlign(minute, ALIGN_MIDDLE_CENTER, Pos(0, 0));
	/* 显示 */
	Widget_Show(hour);
	Widget_Show(minute);
	Widget_Show(bg);
	
	while(1) {
	time ( &rawtime );
	timeinfo = localtime ( &rawtime ); /* 获取系统当前时间 */
	/* 计算时针分针的角度 */
	h_angle = 360*timeinfo->tm_hour / 12.0;
	m_angle = 360*timeinfo->tm_min / 60.0;
	h_angle += m_angle / 60;
	/* 根据这个角度来旋转图形 */
	Graph_Rotate(&hour_pointer, h_angle, &h_temp);
	Graph_Rotate(&minute_pointer, m_angle, &m_temp);
	/* 更改PictureBox部件显示的图形 */
	PictureBox_SetImage(hour, &h_temp);
	PictureBox_SetImage(minute, &m_temp);
	LCUI_Sleep(1);/* 暂停1秒 */
	}
	
	LCUIThread_Exit(NULL);
}
示例#4
0
//Main
int main(int argc, char *argv[]) {
	char                Path[128];
	unsigned int		Height, Width, Start, End, Epsilon = EPSILON, Cth = CTH, N;
	unsigned char 		*Frame, *WinMap;
	Cell                **BGM;
	Pixel               P,Ref_Pixel,Top, Side1, Side2;	// Pixels declarations for Center,Ref Pixel,top,either side of the reference pixel
	Point 				*MarkHistory = NULL;			// Marking list
	int 				Row, Col;						// Counter Variables
	int					Jump = 0;						// Flag used to set when to break;
	FILE				*Outfile;						// File Pointer

//File Input Check Statments
	if(argc !=4) {
		fprintf(stderr, "usage: %s seqdir start end\n", argv[0]);
		exit(1);
	}
// Create Output File Required for Grading
	Outfile = fopen("results.txt", "w"); // Change flag from w to a to obtain a complete results file for all test cases

//Input Parameter Check Statements

	if(sscanf(argv[2], "%d", &Start) != 1 || sscanf(argv[3], "%d", &End) != 1) {
		fprintf(stderr, "[%s:%s] are invalid start/end numbers\n", argv[2], argv[3]);
		exit(1);
	}
/*
Debug Statements controlled by flags set in mmm.h
*/
	if(DEBUG)
		printf("trial: Start= %d, End= %d, Epsilon= %d, Cth= %d ...\n", Start, End, Epsilon, Cth);

	sprintf(Path, "%s/%05d.jpg", argv[1], Start);
	if(DEBUG)
		printf("reading header of %s ...\n", Path);

	Read_Header(Path, &Width, &Height);
	if(DEBUG)
		printf("image size (%ux%u)\n", Width, Height);
//Allocate Memory for Frame
	Frame = (unsigned char *) malloc(3 * Width * Height * sizeof(unsigned char));
	if(Frame == NULL) {
		fprintf(stderr, "Unable to allocate image frame memory\n");
		exit (1);
	}
// Allocate Memory for Winmap
	WinMap = (unsigned char *) malloc(Width * Height * sizeof(unsigned char));
	if(Frame == NULL) {
		fprintf(stderr, "Unable to allocate image window map memory\n");
		exit (1);
	}
//Debug Statements
	if(DEBUG)
		printf("loading %s ...\n", Path);
//Create BGM for Image Processing
	Load_Image(Path, Frame);
	BGM = Create_Initial_BGM(Frame, Width, Height);

	// Store Frame 1 Data in Output File
	// -1 set as co-ordinates since the values are not used for grading.
	fprintf(Outfile, "%5d, %5d, %5d\n", 1, -1, -1); 

//Loop through frames given as user input

	for(N = Start + 1; N < End + 1; N++) 
	{
		Jump = 0; // Set Jump Flag which is used as break point to zero

		sprintf(Path, "%s/%05d.jpg", argv[1], N);
		if (DEBUG)
			printf("processing %s ...\n", Path);
//Load Image , Detect Forefround and Scan the image for Density Changes

		Load_Image(Path, Frame);
		Find_Foreground(BGM, Frame, Width, Height, Epsilon, Cth);
		Scan_Image_Density(Frame, Width, Height, WinMap, WINSIZE);
		Paint_Frame(Frame, Width, Height, WinMap);

//	Check From the center of the image	
// Find the center Pixel of the Frame, if it is yellow return -1 as this is not graded

		P = Pixel_Lookup(Frame, Width/2, Height/2, Width/2, Height/2);
		// Print Data For Frames where the ball is not found or
		if(Pixel_Tester(P))
		{
			fprintf(Outfile, "%5d, %5d, %5d\n", N, -1, -1);
			continue;
		}

// Go from Center to top and left to right of the image

		for(Col = (Height/2); Col >=0 ; Col--)	//Parses the Height of the Picture
		{
			for(Row =0; Row <= Width; Row++) 	// Parses the Width of the picture from left to right
			{
				Ref_Pixel = Pixel_Lookup(Frame, Row, Col, Height/2, Width); // Set Ref Pixel as temp Pixel from Parsing the Image
				
				// If the determined pixel is yellow check pixels around it
				
				if(Pixel_Tester(Ref_Pixel))
				{
					// Load pixels offset by the radius of 10 assuming a worst case diameter of 20 for the ball.
					Top = Pixel_Lookup(Frame, Row, Col - 10, Height/2, Width); 
					// Check for yellow on both sides of the Reference Pixel
					Side1 = Pixel_Lookup(Frame, Row - 10, Col - 10, Height/2, Width);
					Side2 = Pixel_Lookup(Frame, Row + 10, Col - 10, Height/2, Width);
					
					//Compare color information of the nearby Pixels to see if they are yellow
					if(Pixel_Tester(Top) || Pixel_Tester(Side1) || Pixel_Tester(Side2))
					{
						
						//MarkHistory = Add_Mark(MarkHistory, Frame, Row + 5, Col - 15, Width, Height); // Regmark commented to improve performace
						// Write coordnates to file
						fprintf(Outfile, "%5d, %5d, %5d\n", N, Row + 5 , Col - 10); // Offset the computed pixels so that the ball is towards the center
						
						
						//printf("%5d, %5d, %5d\n", N, Row + 5, Col - 20); //Debug Statement
						Jump = 1; // Set Jump Flag to break out of image loop.
						break;
					}
				}
			}
			if(Jump)
				break;// Break out of loop.
		}

		// Image information for frame where the ball was not found.
		if(!Jump)
		{
			fprintf(Outfile, "%5d, %5d, %5d\n", N, -1, -1); // Store cordinates as -1 since this part is either an error or not graded
			//printf("%5d, %5d, %5d\n", N, -1, -1); //Debug Statement
		}
//Sequence to store Output Image set to debug mode		

		if(DEBUG)
			printf("storing output sequence %s ...\n", Path);		
			sprintf(Path, "%sout/%05d.jpg", argv[1], N);
			//Store_Image(Frame, Path, Width, Height); // Store sequence commented out to improve performance
	}
	fclose(Outfile);// Close the result.txt file
	free(Frame);
	exit(0);
}