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

📄 test.c~

📁 图像置乱代码
💻 C~
📖 第 1 页 / 共 2 页
字号:
/********************************************************************
 *
 *    test
 *
 ********************************************************************/#include <tina/all_tina.h>#include "bmp.h"static int SCRAM_n = 1;static Tv *tv = NULL;static Tv *tv1=NULL;#define R0  	2097151
#define LAMBDA  2045
#define MOD 	2097152#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 image_choice = 0;static char filename[MAXPATHLEN];static Imrect *orig_im =NULL;static Imrect *dest_im = NULL;extern void nhwfm_proc(void);static void scram_choice_proc(int val)
{
	scram_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);	//srcIm = ReadGIF(pathname, 1);	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;	//BYTE pix;	int pix;	srcIm = read_image();	width = srcIm->width;
    	height = srcIm->height;
	roi = srcIm->region;
	if (roi == NULL) return ;	srcIm0 = im_alloc( height, width, roi, int_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;	int pix;	int type;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("mixTransformation : 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;	int pix;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("mixTransformation : 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, int_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");	printf("saved the image :%s\n",filename);	gif_write_file(srcIm0,filename);	mono_image_set(srcIm0);
	stack_push(srcIm0, IMRECT, im_free);}static void reset_proc(void){	strcpy(filename,"result/test/");	strcat(filename,file_name);	mypop_proc();}static void *DrawRGB_proc(void){	int i,j;	Imrect *RGBIm,*srcIm;	int width, height;
	Imregion *roi;	RGBIm = im_alloc( 256, 256, NULL, int_v );	//green	for(i = 0;i < 256;i ++)		for(j = 0;j < 256;j ++)		{			IM_PIX_SET(RGBIm, i, j, 99);		}	//red	for(i = 0;i < 96;i ++)		for(j = 0;j < 96;j ++)		{			IM_PIX_SET(RGBIm, i, j, 49);			}	//gif_write_file_color(RGBIm,"RG.gif");	gif_write_file(RGBIm,"gRG.gif");	//return(RGBIm);	im_free(RGBIm);}static void draw_OrigRGB(Tv *tv){	int i,j;	Ipos pos1;	int t;	tv_set_color(tv, green);	for(i = 0;i < 256;i ++)		for(j = 0;j < 256;j ++)		{			pos1=ipos(i,j);			tv_point(tv,pos1);			}	tv_set_color(tv, red);	for(i = 0;i < 96;i ++)		for(j = 0;j < 96;j ++)		{			pos1=ipos(i,j);			tv_point(tv,pos1);			}	tv_set_color(tv, blue);	for(i = 1; i < 8;i ++)	{		t = i*32 - 1;		tv_linexy(tv, t, 0, t, 255);		tv_linexy(tv, 0, t,255,t);	}}static void show_tv_proc(void){		Tv *tvo=NULL;    	void *displayo;
    	displayo=(void *)display_tool(20,20,256,256);
    	tvo=(Tv *)tv_create("OrigRGB");
    	tv_install(tvo, displayo);
    	tv_set_fulldraw(tvo, draw_OrigRGB);
   	tv_repaint(tvo);}static void draw_DestRGB(void){	int type;	int width, height;
	Imregion *roi;	Imrect *srcIm,*srcIm0;	int i,j;	//BYTE pix;	int pix;	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("draw : wrong types on stack", warning);
		return;
	}	srcIm = (Imrect *) stack_pop(&type);	width = srcIm->width;
    	height = srcIm->height;
	roi = srcIm->region;
	if (roi == NULL) return ;	printf("pop ok!%d,%d",width,height);	srcIm0 = im_alloc( height, width, roi, int_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);		}	Ipos pos1;	int t;	int x,y;	tv_set_color(tv, green);	for(i = 0;i < 256;i ++)		for(j = 0;j < 256;j ++)		{			pos1=ipos(i,j);			tv_point(tv,pos1);			}	tv_set_color(tv, red);	for(i = 0;i < height; i ++)		for(j = 0;j < width; j++)		{			IM_PIX_GET(srcIm0, i, j, pix);			if(pix == 49)			{				for(x = 0 + i*32;x < 32 + i*32;x ++)					for(y = 0 + j*32;y < 32 + j*32;y ++)					{						pos1=ipos(x,y);						tv_point(tv,pos1);						}			}					}	tv_set_color(tv, blue);	for(i = 1; i < 8;i ++)	{		t = i*32 - 1;		tv_linexy(tv, t, 0, t, 255);		tv_linexy(tv, 0, t,255,t);	}	mono_image_set(srcIm0);
	stack_push(srcIm0, IMRECT, im_free);}static void Trans_proc(void){	Imrect *srcIm,*destIm,*tmpIm,*srcIm0;
	int width, height;
	Imregion *roi;	int i,j,k;	int type;
	//BYTE pix;	int pix;/*------------------------------------------------	if (stack_check_types(IMRECT, NULL) == false)
	{
		error("test : 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);/*------------------------------------------------*/	srcIm = im_alloc( 8, 8, NULL, int_v );	//green	for(i = 0;i < 8;i ++)		for(j = 0;j < 8;j ++)		{			IM_PIX_SET(srcIm, i, j, 99);		}	//red	for(i = 0;i < 3;i ++)		for(j = 0;j < 3;j ++)		{			IM_PIX_SET(srcIm, i, j, 49);			}	width = 8;
    	height = 8;	char filename0[64];	char string[25];	strcpy(filename0,"_test_");/*------------------------------------------------*/	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_");
			break;
    		case 1:
    			arnold_matrix(trans_r, trans_c, height, width);			strcat(filename0, "arnold_");
			break;
    		case 2:
    			qatlig_matrix(trans_r, trans_c, height, width);			strcat(filename0, "qatlig_");
			break;
    		case 3:
			hilbert_matrix(trans_r, trans_c, height, width);			strcat(filename0, "hilbert_");
			break;
		case 4:
			convey_matrix(trans_r, trans_c, height, width);			strcat(filename0, "convey_");
			break;
    		case 5:
			latin_matrix(trans_r, trans_c, height, width);			strcat(filename0, "latin_");
			break;
		case 6:
    			graycode_matrix(trans_r, trans_c, height, width);			strcat(filename0, "graycode_");
			break;
		case 7:
    			baker_matrix(trans_r, trans_c, height, width);			strcat(filename0, "baker_");
			break;
		case 8:
    			logistic_matrix(trans_r, trans_c, height, width);			strcat(filename0, "logistic_");
			break;
		case 9:
			sampling_matrix(trans_r, trans_c, height, width);			strcat(filename0, "sampling_");
			break;
		default:
			break;
    }/*------------------------------------------------*/
	printf("\n=== %sTransformation begin: ===\n",filename0);	int **dest_r, **dest_c;	dest_r = int_matrix(height, width);
	dest_c = int_matrix(height, width);	for(i = 0; i < height; i++)  //目标图象矩阵初始化
	{
		for(j = 0; j < width; j++)
		{
			dest_r[i][j] = i;
			dest_c[i][j] = j;
		}
	}	destIm = im_alloc( height, width, NULL, int_v );	srcIm0 = im_alloc( height, width, NULL, int_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;

⌨️ 快捷键说明

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