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

📄 pmpimage.c

📁 一个已经移植到嵌入式平台上的图象处理程序源代码,可以处理gif,bmp,jpg,png
💻 C
📖 第 1 页 / 共 3 页
字号:
		}	}#endif#ifdef FBV_SUPPORT_JPEG	if(fh_jpeg_id(filename))	{		if(fh_jpeg_getsize(filename, &x_image, &y_image) == FH_ERROR_OK)		{			load = fh_jpeg_load;			goto identified;		}	}#endif#ifdef FBV_SUPPORT_BMP	if(fh_bmp_id(filename))	{		if(fh_bmp_getsize(filename, &x_image, &y_image) == FH_ERROR_OK)		{			load = fh_bmp_load;			goto identified;		}	}#endif	fprintf(stderr, "%s: Unable to access file or file format unknown.\n", filename);	return -1;identified:	show_param.show_width = x_image;	show_param.show_height = y_image;	show_param.source_width = x_image;	show_param.source_height = y_image;	show_param.max_width = x_image*5;	show_param.max_height = y_image*5;	show_param.current_width = x_image;	show_param.current_height = y_image;	*x_size = x_image;	*y_size = y_image;	if (image != NULL)		free(image);	image = NULL;	if (alpha != NULL)		free(alpha);	alpha = NULL;	if(!(image = (unsigned char*) malloc(x_image * y_image * 3)))	{		fprintf(stderr, "%s: Out of memory.\n", filename);		return -1;	}	if(load(filename, image, &alpha, *x_size, *y_size) != FH_ERROR_OK)	{		fprintf(stderr, "%s: Image data is corrupt?\n", filename);		if (image != NULL)			free(image);		image = NULL;		if (alpha != NULL)			free(alpha);		alpha = NULL;		return -1;	}	return 1;}int image_init(char *filename){	int x_size=0, y_size=0;	int screen_width=0, screen_height=0;	show_pos.x_pan = 0;	show_pos.y_pan = 0;	show_pos.x_offs = 0;	show_pos.y_offs = 0;	memset(&p_image, 0x00, sizeof(struct image));	memset(&color_param, 0x00, sizeof(image_color_param));	if (load_image_comment(filename, &x_size, &y_size) == -1)		return -1;	getCurrentRes(&screen_width, &screen_height);		show_param.screen_width = screen_width;	show_param.screen_height = screen_height;	show_param.rotation_direction = DIRTION_SOURCE;	show_param.updown_direction = REVOLVE_UP_DIRTION;	show_param.left_right_dirtion = REVOLVE_LEFT_DIRTION;		p_image.width = x_size;	p_image.height = y_size;	memset(p_image.filename, 0x00, MAX_FILENAME_LENGTH);	save_bake_filename(filename, p_image.filename);	p_image.rgb = (unsigned char *)malloc(x_size*y_size*3);	memset(p_image.rgb, 0x00, x_size*y_size*3);	memcpy(p_image.rgb, image, x_size*y_size*3);		if (alpha != NULL)	{		p_image.alpha = (unsigned char *)malloc(x_size*y_size);		memset(p_image.alpha, 0x00, x_size*y_size);		memcpy(p_image.alpha, alpha, x_size*y_size);	}	else		p_image.alpha = NULL;	if(p_image.width < show_param.screen_width)		show_pos.x_offs = (show_param.screen_width - p_image.width)/2;	else		show_pos.x_offs = 0;	if(p_image.height < show_param.screen_height)		show_pos.y_offs = (show_param.screen_height - p_image.height)/2;	else		show_pos.y_offs = 0;	if ((show_param.source_width > show_param.screen_width) || (show_param.source_height > show_param.screen_height))	{		int img_width = p_image.width;		int img_height = p_image.height;		show_param.show_width = show_param.screen_width;		show_param.show_height = show_param.screen_height;		do_image_resize(&p_image, show_param.show_width, show_param.show_height);		if (p_image.alpha != NULL)		{			p_image.width = img_width;			p_image.height = img_height;			do_alpha_resize(&p_image, show_param.show_width, show_param.show_height);		}		do_image_full_screen(&p_image, 1);		image_update();			return 1;	}	else			fb_display(p_image.rgb, p_image.alpha, p_image.width, p_image.height, 							show_pos.x_pan, show_pos.y_pan, show_pos.x_offs, show_pos.y_offs);	return 1;}void  image_move_right(){	if(show_pos.x_pan == 0)		return; 	show_pos.x_pan -= p_image.width/PAN_STEPPING;	if(show_pos.x_pan < 0) 		show_pos.x_pan = 0;	image_update();}void	image_move_left(){	if(show_pos.x_offs) 		return;	if(show_pos.x_pan >= (p_image.width - show_param.screen_width)) 		return;	show_pos.x_pan += p_image.width/PAN_STEPPING;	if(show_pos.x_pan > (p_image.width - show_param.screen_width))		show_pos.x_pan = p_image.width - show_param.screen_width;	image_update();}void image_move_up(){	if(show_pos.y_offs) 		return;	if(show_pos.y_pan >= (p_image.height - show_param.screen_height)) 		return;	show_pos.y_pan += p_image.height/PAN_STEPPING;	if(show_pos.y_pan > (p_image.height - show_param.screen_height)) 		show_pos.y_pan = p_image.height - show_param.screen_height;	image_update();}void	image_move_down(){	if(show_pos.y_pan == 0) 		return;	show_pos.y_pan -= p_image.height/PAN_STEPPING;	if(show_pos.y_pan < 0) 		show_pos.y_pan = 0;	image_update();}void image_pan_enlarge(){	show_pos.y_pan = 0;	show_pos.x_pan = 0;	if ((p_image.width > show_param.source_width*10) || (p_image.width > show_param.screen_width*3))		return;	else		do_large_scale(&p_image);	image_data_process(&p_image);	image_dofresh();	image_update();}void	image_pan_little(){	show_pos.y_pan = 0;	show_pos.x_pan = 0;	if ((p_image.width < show_param.screen_width/30) || (p_image.width < show_param.source_width/20))		return;	else		do_little_scale(&p_image);	image_data_process(&p_image);	image_dofresh();	image_update();}void image_restore(){	show_pos.y_pan = 0;	show_pos.x_pan = 0;	show_param.rotation_direction = DIRTION_SOURCE;	show_param.left_right_dirtion = REVOLVE_LEFT_DIRTION;	show_param.updown_direction = REVOLVE_UP_DIRTION;					do_restore_image(&p_image, 1, 0);	memset(&color_param, 0x00, sizeof(image_color_param));		image_update();}void  image_rotate_left(){	int img_width = p_image.width;	int img_height = p_image.height;	int show_value = show_param.show_width;	show_pos.y_pan = 0;	show_pos.x_pan = 0;	show_param.rotation_direction = show_param.rotation_direction + 1;	if (show_param.rotation_direction > DIRTION_RIGHT)		show_param.rotation_direction = DIRTION_SOURCE;	show_param.show_width = show_param.show_height;	show_param.show_height = show_value;	do_rotate_clockwise_vertical(&p_image);	if (p_image.alpha != NULL)	{		p_image.width = img_width;		p_image.height = img_height;		do_alpha_rotate_clockwise_vertical(&p_image);	}	image_update();}void image_rotate_right(){	int img_width = p_image.width;	int	img_height = p_image.height;	int show_value = show_param.show_width;	show_pos.y_pan = 0;	show_pos.x_pan = 0;	show_param.rotation_direction = show_param.rotation_direction - 1;	if (show_param.rotation_direction < 0)		show_param.rotation_direction = DIRTION_RIGHT;	show_param.show_width = show_param.show_height;	show_param.show_height = show_value;	do_rotate_anti_clockwise_vertical(&p_image);	if (p_image.alpha != NULL)	{		p_image.width = img_width;		p_image.height = img_height;		do_alpha_rotate_anti_clockwise_vertical(&p_image);	}	image_update();}void image_exchang_left_right(){	int img_width = p_image.width;	int img_height = p_image.height;	show_pos.y_pan = 0;	show_pos.x_pan = 0;	if (show_param.left_right_dirtion == REVOLVE_LEFT_DIRTION)	{		show_param.left_right_dirtion = REVOLVE_RIGHT_DIRTION;		do_revolve_left(&p_image);		if (p_image.alpha != NULL)		{			p_image.width = img_width;			p_image.height = img_height;			do_alpha_revolve_left(&p_image);		}		image_update();		return;	}	if (show_param.left_right_dirtion == REVOLVE_RIGHT_DIRTION)	{		show_param.left_right_dirtion = REVOLVE_LEFT_DIRTION;		do_revolve_left(&p_image);		if (p_image.alpha != NULL)		{			p_image.width = img_width;			p_image.height = img_height;			do_alpha_revolve_left(&p_image);		}		image_update();		return;						}}void image_exchang_up_down(){	int img_width = p_image.width;	int img_height = p_image.height;	show_pos.y_pan = 0;	show_pos.x_pan = 0;	show_param.updown_direction = (show_param.updown_direction==REVOLVE_UP_DIRTION)? REVOLVE_DOWN_DIRTION:REVOLVE_UP_DIRTION;	do_revolve_updown(&p_image);	if (p_image.alpha != NULL)	{		p_image.width = img_width;		p_image.height = img_height;		do_alpha_revolve_updown(&p_image);	}	image_update();}void image_rotate_up_down(){	int img_width = p_image.width;	int img_height = p_image.height;	show_pos.y_pan = 0;	show_pos.x_pan = 0;		show_param.rotation_direction = show_param.rotation_direction + 2;	if (show_param.rotation_direction > DIRTION_RIGHT)		show_param.rotation_direction = show_param.rotation_direction - 4;	do_rotate_horizontal(&p_image);	if (p_image.alpha != NULL)	{			p_image.width = img_width;			p_image.height = img_height;			do_alpha_rotate_horizontal(&p_image);		}	image_update();}void  image_full_screen(){	show_pos.y_pan = 0;	show_pos.x_pan = 0;	do_image_full_screen(&p_image, 0);	image_data_process(&p_image);	image_dofresh();	image_update();}void	image_write_file(){	write_JPEG_file(&p_image);}void image_cleanup(){	if(p_image.rgb)	{		free(p_image.rgb);		p_image.rgb = NULL;	}	if(image)	{		free(image);		image = NULL;	}	if (p_image.alpha!=NULL)	{		free(p_image.alpha);		p_image.alpha = NULL;	}	if (alpha != NULL)	{		free(alpha);		alpha = NULL;	}}void	image_dofresh(){	int idex=0;	if ((color_param.RGB_red != 0) || (color_param.RGB_green != 0) || (color_param.RGB_blue != 0))		do_image_RGBChange(&p_image, color_param.RGB_red, color_param.RGB_green, color_param.RGB_blue, image);	if (color_param.bright != 0)		do_image_BrightnessChange(&p_image, color_param.bright, image);	if (color_param.contrast != 0)		do_image_ContrastChange(&p_image, color_param.contrast, image);	if (color_param.saturation != 0)		do_image_Saturation(&p_image, color_param.saturation, image);	if (color_param.sharpen > 0)		for (idex=0; idex < color_param.sharpen; idex++)			do_image_Sharpen(&p_image, image);	if (color_param.reflect != 0)		do_image_reflect(&p_image, image);	if (color_param.muzzy > 0)		for (idex=0; idex < color_param.muzzy; idex++)		do_image_muzzy(&p_image, image);		if (color_param.engrave != 0)		do_image_Engrave(&p_image, image);	if (color_param.emboss != 0)		do_image_Emboss(&p_image, image);			if (color_param.exposure != 0)		do_image_Exposure(&p_image, image);		if (color_param.GrayWeightAverage != 0)		do_image_GrayWeightAverage(&p_image, image);		if (color_param.GrayAverage != 0)		do_image_GrayAverage(&p_image, image);}void image_Brightness_adjust(unsigned char *pimg, int width, int heith, int step){	Brightness_adjust(pimg, width*heith, step);	image_update();}void	image_RGBChange_adjust(unsigned char *pimg, int width, int height, int red, int green, int blue){	RGBChange_adjust(pimg, width, height, red, green, blue);	image_update();}

⌨️ 快捷键说明

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