send.c~

来自「图像置乱代码」· C~ 代码 · 共 624 行 · 第 1/2 页

C~
624
字号
	scram_im = im_copy(srcIm0);	tv_imrect2(tv1, scram_im);	mono_image_set(srcIm0);
	stack_push(srcIm0, IMRECT, im_free);	im_free(destIm);	free_int_matrix(trans_r, height);
	free_int_matrix(trans_c, height);	printf("=== %stransformatioin complete! ===\n",filename0);	}static void cut_proc(void){	Imrect *srcIm,*destIm;
	int width, height;
	Imregion *roi;	int i,j;	int type;
	//BYTE pix;	float pix;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("cut : wrong types on stack", warning);
		return;
	}	srcIm = (Imrect *) stack_pop(&type);
	width = srcIm->width;
    	height = srcIm->height;
	roi = srcIm->region;
	if (roi == NULL) return ;	destIm = im_alloc( height, width, roi, float_v );	for(i = 0;i < height;i ++)		for(j = 0;j < width;j ++)			IM_PIX_SET(destIm, i, j, CUTPIX);	char filename0[64];	//strcpy(filename0,"_send_");	strcpy(filename0,"_");	int h2,w2,h4,w4;	h2 = height/2;	w2 = width/2;	h4 = height/4;	w4 = width/4;	Imrect *cutIm;	char string[25];	int cut_height,cut_width;/*------------------------------------------------*/    	switch( cut_method )
    	{
    		case 0:			cut_height = height;			cut_width = width -w4;			cutIm = im_alloc( cut_height, cut_width, NULL, float_v );
			for(i = 0;i < height;i ++)				for(j = w4;j < width;j ++)				{					IM_PIX_GET(srcIm, i, j, pix);					IM_PIX_SET(destIm, i, j, pix);					IM_PIX_SET(cutIm, i, j-w4, pix);				}			strcat(filename0, "25%_");
			break;
    		case 1:
			cut_height = height - h2;			cut_width = width;			cutIm = im_alloc( cut_height, cut_width, NULL, float_v );
			for(i = h2;i < height;i ++)				for(j = 0;j < width;j ++)				{					IM_PIX_GET(srcIm, i, j, pix);					IM_PIX_SET(destIm, i, j, pix);					IM_PIX_SET(cutIm, i-h2, j, pix);				}			strcat(filename0, "50%_");
			break;
    		case 2:
			cut_height = h2;			cut_width = w2;			cutIm = im_alloc( cut_height, cut_width, NULL, float_v );
			for(i = 0;i < h2;i ++)				for(j = 0;j < w2;j ++)				{					IM_PIX_GET(srcIm, i, j, pix);					IM_PIX_SET(destIm, i, j, pix);					IM_PIX_SET(cutIm, i, j, pix);				}			strcat(filename0, "75%-L_up_");
			break;
    		case 3:
			cut_height = h2;			cut_width = width - w2;			cutIm = im_alloc( cut_height, cut_width, NULL, float_v );
			for(i = 0;i < h2;i ++)				for(j = w2;j < width;j ++)				{					IM_PIX_GET(srcIm, i, j, pix);					IM_PIX_SET(destIm, i, j, pix);					IM_PIX_SET(cutIm, i, j-w2, pix);				}			strcat(filename0, "75%-R_up_");;
			break;
		case 4:
			cut_height = height - h2;			cut_width = w2;			cutIm = im_alloc( cut_height, cut_width, NULL, float_v );
			for(i = h2;i < height;i ++)				for(j = 0;j < w2;j ++)				{					IM_PIX_GET(srcIm, i, j, pix);					IM_PIX_SET(destIm, i, j, pix);					IM_PIX_SET(cutIm, i-h2, j, pix);				}			strcat(filename0, "75%-L_down_");
			break;
    		case 5:
			cut_height = height - h2;			cut_width = width - w2;			cutIm = im_alloc( cut_height, cut_width, NULL, float_v );
			for(i = h2;i < height;i ++)				for(j = w2;j < width;j ++)				{					IM_PIX_GET(srcIm, i, j, pix);					IM_PIX_SET(destIm, i, j, pix);					IM_PIX_SET(cutIm, i-h2, j-w2, pix);				}			strcat(filename0, "75%-R_down_");
			break;
		case 6:
			cut_height = CUT_height;			cut_width = CUT_width;			if ((START_h + CUT_height > height)||(START_w + CUT_width > width))
			{
				printf("send-client : cut out of the image!!!\n");
				return;
			}			cutIm = im_alloc( cut_height, cut_width, NULL, float_v );
			for(i = START_h;i < START_h + CUT_height;i ++)				for(j = START_w;j < START_w + CUT_width;j ++)				{					IM_PIX_GET(srcIm, i, j, pix);					IM_PIX_SET(destIm, i, j, pix);					IM_PIX_SET(cutIm, i-START_h, j-START_w, pix);				}			//strcat(filename0, "specify_");			gcvt(START_h,5,string);			strcat(filename0, string);			strcat(filename0, "_");			gcvt(START_w,5,string);			strcat(filename0, string);			strcat(filename0, "_");
			break;
		default:
			break;
    }/*------------------------------------------------*/	gcvt(height,5,string);	strcat(filename0, string);	strcat(filename0, "x");	gcvt(width,5,string);	strcat(filename0, string);	char filenamecut[64];	//strcpy(filenamecut,"result/send/");	//strcat(filenamecut, filename0);	strcpy(filenamecut,filename);	strcat(filenamecut, filename0);	//strcat(filenamecut, ".gif");
	//gif_write_file(cutIm,filenamecut);	strcat(filenamecut,".bmp");	ImrectToBMP8(cutIm,filenamecut);	printf("save the image :%s\n",filename);/*----------------------------------------------*/	strcat(filename, filename0);	//gif_write_file(destIm,filename);	//ImrectToBMP8(destIm,filename);/*------------------------------------------------*/	cut_im = im_copy(destIm);	tv_imrect2(tv2, cut_im);/*----------------------------------------------	mono_image_set(destIm);
	stack_push(destIm, IMRECT, im_free);	im_free(cutIm);/*----------------------------------------------*/	mono_image_set(cutIm);
	stack_push(cutIm, IMRECT, im_free);	im_free(destIm);/*----------------------------------------------*/	printf("\n=== %s complete! ===\n",filename0);		}static void fulldraw(Tv *tv){     tv_imrect2(tv, orig_im);}static void fulldraw1(Tv *tv){     tv_imrect2(tv, scram_im);}static void fulldraw2(Tv *tv){     tv_imrect2(tv, cut_im);}static void tv_choice_proc(choice)
int     choice;
{
    switch (choice)
    	{
    	case 0: tv_set_next(tv);//original
		break;
    	case 1: tv_set_next(tv1);//transformation
		break;    	case 2: tv_set_next(tv2);//cut
		break;
    	default:error("tv_choice_proc: unknown choice\n", warning);
		break;
    	}}static void scan_proc(void){    scan_files(directory_name,file_name);    tw_sglobal_reset(pdir);    tw_sglobal_reset(pfile);}static void tool_proc(void)
{
    static int x = 0, y = 0;
    static int xr = 0, yr = 0;

    tv_tool(x+xr, y+yr);
    xr += 275;
    yr += 0;
    if (x+xr>780)
    {
       xr = yr = 0;
       y += 50;
    }
    if (y>400) y = 200;
}

/********** Tool creation **********/
void            send_client_tool(int x, int y)
{
	static void *tool = NULL;	if (tool)
	{
		tw_show_tool(tool);
		return;
	}
	tool = (void *)tw_tool("send-client tool", x, y);
    	/* Initialise pathname from environment variable (or #define) */    	(void) environ_pathname_get(directory_name, file_name,				"TINA_IMAGE_DEFAULT",				"/home/wzz/newimscramdegree/result/send/Lena.bmp");	tv = tv_create("send-client original");
     	tv1 = tv_create("send-client scrambled");     	tv2 = tv_create("send-client cut");	tw_choice("Tv choice", tv_choice_proc, 0, "original","scrambled","cut", NULL);	tv_set_fulldraw(tv, fulldraw);	tv_set_fulldraw(tv1,fulldraw1);	tv_set_fulldraw(tv2,fulldraw2);	/*---------------------------*/  	tw_newrow();
	tw_label("Display");
	tw_button("New Tvtool", tool_proc, NULL);	/*---------------------------*/ 	tw_newrow();  	pdir = (void *) tw_sglobal("Directory:", directory_name, 32);    	tw_button("scan", scan_proc, NULL);  	tw_newrow();  	pfile = (void*) tw_sglobal("File:", file_name, 32);  	tw_newrow();	/*---------------------------*/        tw_choice("input image choice", image_choice_proc, 0, "BMP","GIF", NULL);   	tw_label("              ");	tw_button("push",mypush_proc,NULL);	tw_button("pop",mypop_proc,NULL);	tw_button("show",myshow_proc,NULL);
	tw_button("save",mysave_proc,NULL);	tw_newrow();	strcpy(filename,"result/send/");	//strcat(filename,file_name);
	tw_choice("Scrambling Method:", scram_choice_proc, 0,\
              "Fibonacci", "Arnold", "QATLIG", "Hilbert", "Convey", "Latin", "Zigzag", "Baker", "Logistic", "Random",  NULL);
	tw_newrow();	tw_iglobal("Scrambling times = ", &SCRAM_n, 5);	tw_newrow();	tw_button("Transformation",Trans_proc,NULL);   	tw_label("              ");	tw_button("reset",reset_proc,NULL);	tw_newrow();   	tw_label("-----------------------------------------------------------------------");	tw_newrow();	tw_choice("Cut %", cut_choice_proc, 0,\
              "25%", "50%", "75%-L_up", "75%-R_up", "75%-L_down", "75%-R_down", "specify",  NULL);	tw_newrow();	tw_iglobal("start point:h  = ", &START_h, 5);	tw_iglobal("w = ", &START_w, 5);	tw_iglobal("height  = ", &CUT_height, 5);	tw_iglobal("width  = ", &CUT_width, 5);	tw_newrow();	tw_button("cut",cut_proc,NULL);	tw_newrow();
	tw_end_tool();
}

⌨️ 快捷键说明

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