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

📄 receive.c

📁 图像置乱代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/********************************************************************
 *
 * image cut tool
 *
 ********************************************************************/#include <tina/all_tina.h>#include "bmp.h"#include <stdio.h>#include <curses.h>static int SCRAM_n = 1;static int START_h = 0;static int START_w = 0;static int ORIG_height = 256;static int ORIG_width = 256;static int MCOUNT = 1;static Tv *tv = NULL;static Tv *tv1 = NULL;static Tv *tv2 = NULL;#define MAXPATHLEN 64static char directory_name[MAXPATHLEN];static char file_name[MAXPATHLEN];static char pathname[MAXPATHLEN];
static void *pdir=0, *pfile=0;static int scram_method = 0;static int cut_method = 0;static int repair_method = 0;static int image_choice = 0;static int show_choice = 0;//#define CUTPIX 254.56789#define CUTPIX 255static char filename[MAXPATHLEN];static Imrect *orig_im =NULL;static Imrect *contra_scram_im = NULL;static Imrect *repair_im = NULL;static int iminarg1,iminarg2;
#define IMAX(a,b) (iminarg1 = (a),iminarg2 = (b),(iminarg1) > (iminarg2) ? (iminarg1) : (iminarg2))static Imrect *adaptim = NULL;extern void nhwfm_proc(void);static void scram_choice_proc(int val)
{
	scram_method = val;
}static void cut_choice_proc(int val)
{
	cut_method = val;
}static void repair_choice_proc(int val){	repair_method = val;}static image_choice_proc(int val){	image_choice = val;}static show_choice_proc(int val){	show_choice = val;}static 	Imrect *read_image(void){	Imrect *srcIm;/*----------------Read the image---------------------------*/  	(void) strip_spaces(file_name);  	(void) strip_spaces(directory_name);  	(void) string_append(pathname, directory_name, "/", file_name, NULL);	switch( image_choice )	{		case 0:			srcIm = BmpToImrect(pathname);			break;		case 1:			srcIm = ReadGIF(pathname, 1);			break;		default:			break;	}/*------------------------------------------------*/	return(srcIm);}static void mypush_proc(void){	Imrect *srcIm,*srcIm0;	int width, height;
	Imregion *roi;	int i,j;	float pix;	srcIm = read_image();	width = srcIm->width;
    	height = srcIm->height;
	roi = srcIm->region;
	if (roi == NULL) return ;	orig_im = im_copy(srcIm);	tv_imrect2(tv, orig_im);	srcIm0 = im_alloc( height, width, roi, float_v );	for(i = 0;i < height; i ++)		for(j = 0;j < width; j++)		{			IM_PIX_GET(srcIm, i, j, pix);
			IM_PIX_SET(srcIm0, i, j, pix);		}	mono_image_set(srcIm0);
	stack_push(srcIm0, IMRECT, im_free);}static Imrect* mypop_proc(void){	Imrect *srcIm;	float pix;	int type;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("receive-client : wrong types on stack", warning);
		return;
	}	srcIm = (Imrect *) stack_pop(&type);	return srcIm;}static void mysave_proc(void){	int type;	int width, height;
	Imregion *roi;	Imrect *srcIm,*srcIm0;	int i,j;	float pix;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("receive-client : wrong types on stack", warning);
		return;
	}	srcIm = (Imrect *) stack_pop(&type);	width = srcIm->width;
    	height = srcIm->height;
	roi = srcIm->region;
	if (roi == NULL) return ;	srcIm0 = im_alloc( height, width, roi, float_v );	for(i = 0;i < height; i ++)		for(j = 0;j < width; j++)		{			IM_PIX_GET(srcIm, i, j, pix);
			IM_PIX_SET(srcIm0, i, j, pix);		}	//strcat(filename,".gif");	//gif_write_file(srcIm0,filename);	char filenamesave[64];	strcpy(filenamesave,filename);	strcat(filenamesave,".bmp");	ImrectToBMP8(srcIm0,filenamesave);	printf("saved the image :%s\n",filenamesave);	mono_image_set(srcIm0);
	stack_push(srcIm0, IMRECT, im_free);}static void reset_proc(void){	strcpy(filename,"result/receive/");	//strcat(filename,file_name);	mypop_proc();}static void myshow_proc(void){	Imrect *srcIm,*srcIm0;	int type;	int width, height;
	Imregion *roi;                                         	int i,j;	float pix;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("receive show : wrong types on stack", warning);
		return;
	}	srcIm = (Imrect *) stack_pop(&type);	width = srcIm->width;
    	height = srcIm->height;
	roi = srcIm->region;
	if (roi == NULL) return ;	srcIm0 = im_alloc( height, width, roi, float_v );	for(i = 0;i < height; i ++)		for(j = 0;j < width; j++)		{			IM_PIX_GET(srcIm, i, j, pix);
			IM_PIX_SET(srcIm0, i, j, pix);		}	orig_im = im_copy(srcIm);	tv_imrect2(tv, orig_im);	mono_image_set(srcIm0);
	stack_push(srcIm0, IMRECT, im_free);}static void rebuild_proc(void){	Imrect *srcIm,*rebuIm;	int type;	int width, height;
	Imregion *roi;	int i,j;	float pix;	int start_h,start_w;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("receive-client : wrong types on stack", warning);
		return;
	}	srcIm = (Imrect *) stack_pop(&type);	width = srcIm->width;
    	height = srcIm->height;
	roi = srcIm->region;
	if (roi == NULL) return ;	if((START_h+height>ORIG_height)||(START_w+width>ORIG_width))	{		printf("rebuild: out of the region!\n");		return ;	}	rebuIm = im_alloc( ORIG_height, ORIG_width, NULL, float_v );//	for(i = 0;i < ORIG_height;i ++)		for(j = 0;j < ORIG_width;j ++)			IM_PIX_SET(rebuIm, i, j, CUTPIX);	strcpy(filename,"result/receive/");	//strcat(filename,file_name);	char filename0[64];	strcpy(filename0,"rebuild_");	char string[25];/*------------------------------------------------*/    	switch( cut_method )
    	{
    		case 0:			start_h = 0;			start_w = ORIG_width/4;			strcat(filename0, "25%_");
			break;
    		case 1:
			start_h = ORIG_height/2;			start_w = 0;			strcat(filename0, "50%_");
			break;
    		case 2:
			start_h = 0;			start_w = 0;			strcat(filename0, "75%-L_up_");
			break;
    		case 3:
			start_h = 0;			start_w = ORIG_width/2;			strcat(filename0, "75%-R_up_");;
			break;
		case 4:
			start_h = ORIG_height/2;			start_w = 0;			strcat(filename0, "75%-L_down_");
			break;
    		case 5:			start_h = ORIG_height/2;			start_w = ORIG_width/2;			strcat(filename0, "75%-R_down_");
			break;
		case 6:			start_h = START_h ;			start_w = START_w ;			gcvt(START_h,5,string);			strcat(filename0, string);			strcat(filename0, "_");			gcvt(START_w,5,string);			strcat(filename0, string);			strcat(filename0, "_");
			break;
		default:
			break;
    }/*------------------------------------------------*/	for(i = 0;i < height; i ++)		for(j = 0;j < width; j++)		{			IM_PIX_GET(srcIm, i, j, pix);
			IM_PIX_SET(rebuIm, i+start_h, j+start_w, pix);		}	orig_im = im_copy(rebuIm);	tv_imrect2(tv, orig_im);	strcat(filename, filename0);	mono_image_set(rebuIm);
	stack_push(rebuIm, IMRECT, im_free);	printf("rebuild complete!\n");}static void Contra_Trans_proc(void){	Imrect *srcIm,*destIm,*tmpIm,*srcIm0;
	int width, height;
	Imregion *roi;	int i,j,k;	int type;
	float pix;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("Contra_Trans : wrong types on stack", warning);
		return;
	}	srcIm = (Imrect *) stack_pop(&type);
	width = srcIm->width;
    	height = srcIm->height;
	roi = srcIm->region;
	if (roi == NULL) return ;	orig_im = im_copy(srcIm);	tv_imrect2(tv, orig_im);	char filename0[64];	char string[25];	strcpy(filename0,"_C_");/*------------------------------------------------*/	int **trans_r, **trans_c;
	trans_r = int_matrix(height, width);
	trans_c = int_matrix(height, width);    	switch( scram_method )
    	{
    		case 0:
    			r_fibonacci_matrix(trans_r, trans_c, height, width);;			strcat(filename0, "f");
			break;
    		case 1:
    			r_arnold_matrix(trans_r, trans_c, height, width);			strcat(filename0, "a");
			break;
    		case 2:
    			r_qatlig_matrix(trans_r, trans_c, height, width);			strcat(filename0, "q");
			break;
    		case 3:
			r_hilbert_matrix(trans_r, trans_c, height, width);			strcat(filename0, "h");
			break;
		case 4:
			r_convey_matrix(trans_r, trans_c, height, width);			strcat(filename0, "c");
			break;
    		case 5:
			r_latin_matrix(trans_r, trans_c, height, width);			strcat(filename0, "la");
			break;
		case 6:/*
    			r_graycode_matrix(trans_r, trans_c, height, width);			strcat(filename0, "g");*/			r_zigzag_matrix(trans_r, trans_c, height, width);			strcat(filename0,"z");
			break;
		case 7:
    			r_baker_matrix(trans_r, trans_c, height, width);			strcat(filename0, "b");
			break;
		case 8:
    			r_logistic_matrix(trans_r, trans_c, height, width);			strcat(filename0, "lo");
			break;
		case 9:/*
			r_sampling_matrix(trans_r, trans_c, height, width);			strcat(filename0, "sa");*/			r_random_matrix(trans_r, trans_c, height, width);			strcat(filename0, "ra_");
			break;
		default:
			break;
    }/*------------------------------------------------*/
	printf("\n=== %sTransformation begin: ===\n",filename0);	destIm = im_alloc( height, width, roi, float_v );	srcIm0 = im_alloc( height, width, roi, float_v );	for(i = 0;i < height; i ++)		for(j = 0;j < width; j++)		{			IM_PIX_GET(srcIm, i, j, pix);
			IM_PIX_SET(srcIm0, i, j, pix);		}
	for( k = 0; k < SCRAM_n; k++)
	{			for (i = 0; i < height  ; i++)
		{
			for (j = 0; j< width ; j++)
			{								IM_PIX_GET(srcIm0, i, j, pix);
				IM_PIX_SET(destIm, trans_r[i][j], trans_c[i][j], pix);
			}
		}
 		tmpIm = srcIm0;
		srcIm0 = destIm;
		destIm = tmpIm;	}/*----------------------Save the image as .bmp--------------------------*/	gcvt(k,5,string);	printf("Contra_scrambled %s times\n",string);	strcat(filename0, string);	strcat(filename, filename0);	char filename1[64];	strcpy(filename1,filename);	strcat(filename1,".bmp");	ImrectToBMP8(srcIm0,filename1);/*------------------test------------------------------	Imrect *crackim;	crackim = im_alloc(128, 128, NULL, float_v );	int index = 0;

⌨️ 快捷键说明

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