send.c~

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

C~
624
字号
/********************************************************************
 *
 * image cut tool
 *
 ********************************************************************/#include <tina/all_tina.h>#include "bmp.h"static int SCRAM_n = 1;static int START_h = 0;static int START_w = 0;static int CUT_height = 128;static int CUT_width = 128;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 image_choice = 0;#define CUTPIX 254.56789static char filename[MAXPATHLEN];static Imrect *orig_im =NULL;static Imrect *scram_im = NULL;static Imrect *cut_im = NULL;extern void ImrectToBMP8 (Imrect* im , const char* filename);extern void readBMP(const char *fileName);static void scram_choice_proc(int val)
{
	scram_method = val;
}static void cut_choice_proc(int val)
{
	cut_method = val;
}static image_choice_proc(int val){	image_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 = NULL,*srcIm0 = NULL;	int width, height;
	Imregion *roi;	int i,j;	//BYTE pix;	float pix;	srcIm = read_image();	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 Imrect* mypop_proc(void){	Imrect *srcIm;	//BYTE pix;	float pix;	int type;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("send-client : wrong types on stack", warning);
		return;
	}	srcIm = (Imrect *) stack_pop(&type);	return srcIm;}static void mysave_proc(void){	Imrect *srcIm = NULL,*srcIm0 = NULL;	int type;	int width, height;
	Imregion *roi;	int i,j;	//BYTE pix;	float pix;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("send-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 myshow_proc(void){	int type;	int width, height;
	Imregion *roi;	Imrect *srcIm,*srcIm0;	int i,j;	//BYTE pix;	float pix;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("send 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 reset_proc(void){	strcpy(filename,"result/send/");	//strcat(filename,file_name);	mypop_proc();}static void Trans_proc(void){	Imrect *srcIm,*destIm,*tmpIm,*srcIm0;
	int width, height;
	Imregion *roi;	int i,j,k;	int type;
	//BYTE pix;	float pix;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("send-client : wrong types on stack", warning);
		return;
	}	srcIm = (Imrect *) stack_pop(&type);	//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);	char filename0[64];	char string[25];	strcpy(filename0,"");/*------------------------------------------------*/	int **trans_r, **trans_c;
	trans_r = int_matrix(height, width);
	trans_c = int_matrix(height, width);    	switch( scram_method )
    	{
    		case 0:
    			fibonacci_matrix(trans_r, trans_c, height, width);			//strcat(filename0, "fibonacci_");			strcat(filename0, "f");
			break;
    		case 1:
    			arnold_matrix(trans_r, trans_c, height, width);			//strcat(filename0, "arnold_");			strcat(filename0, "a");
			break;
    		case 2:
    			qatlig_matrix(trans_r, trans_c, height, width);			//strcat(filename0, "qatlig_");			strcat(filename0, "q");
			break;
    		case 3:
			hilbert_matrix(trans_r, trans_c, height, width);			//strcat(filename0, "hilbert_");			strcat(filename0, "h");
			break;
		case 4:
			convey_matrix(trans_r, trans_c, height, width);			//strcat(filename0, "convey_");			strcat(filename0, "c");
			break;
    		case 5:
			latin_matrix(trans_r, trans_c, height, width);			//strcat(filename0, "latin_");			strcat(filename0, "la");
			break;
		case 6:
    			//graycode_matrix(trans_r, trans_c, height, width);			//strcat(filename0, "graycode_");			//strcat(filename0, "g");			zigzag_matrix(trans_r, trans_c, height, width);			strcat(filename0,"z");
			break;
		case 7:
    			baker_matrix(trans_r, trans_c, height, width);			//strcat(filename0, "baker_");			strcat(filename0, "b");
			break;
		case 8:
    			logistic_matrix(trans_r, trans_c, height, width);			//strcat(filename0, "logistic_");			strcat(filename0, "lo");
			break;
		case 9:/*
			sampling_matrix(trans_r, trans_c, height, width);			//strcat(filename0, "sampling_");			strcat(filename0, "sa");*/			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);			//printf("%f  ",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 .gif--------------------------*/	gcvt(k,5,string);	printf("scrambled %s times\n",string);	strcat(filename, filename0);	strcat(filename, string);/*------------------------------------------------*/

⌨️ 快捷键说明

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