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

📄 mymono_tool.c

📁 图像置乱代码
💻 C
字号:
/* mono_tool.c * * Modification: 16-Sep-99 by IH, DICOM button added *  * most basic tv_screen level code for managing mono resources and data * structures. *  * deals with file based i/o as well as display selection *  */#include <stdio.h>#include <sys/param.h>#include <string.h>#include <tina/sys.h>#include <tina/sysfuncs.h>#include <tina/math.h>#include <tina/mathfuncs.h>#include <tina/vision.h>#include <tina/visionfuncs.h>#include <tina/file.h>#include <tina/filefuncs.h>#include <tina/file_gen.h>#include <tina/tv.h>#include <tina/tvfuncs.h>#include <tina/toolsfuncs.h>#include <tina/tw_Xfuncs.h>/* EXTERNS  */extern void tw_show_tool();extern void *tw_tool();/*#define AIFF_FILE  0#define PGM_FILE   1#define RAD_FILE   2#define EDGE_FILE  3#define POLY_FILE  4#define CAMERA     5#define WISP       6#define RAS        7#define GIF        8#define RAW_FILE   9*//* STATIC GLOBALS */static char directory_name[MAXPATHLEN];static char base_name[MAXPATHLEN];static char file_name[MAXPATHLEN];static void *pdir=NULL, *pfile=NULL;static int file_type = 0;static void *pframe;static int fnum = 0;/* CALLBACK FUNCTIONS */static void    mono_draw(Tv *tv){    if(tv!=NULL)    {        tv_free_background(tv);        tv_repaint(tv);    }}static void tv_proc(void){    mono_tv_set(mono_tv_make());    tv_set_next(mono_tv());}/* Push / Pop callbacks */static void push_proc(void){    Imrect *im;    im = im_copy(mono_image());    stack_push((void *) im, IMRECT, im_free);    if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());    if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());    image_choice_reset();}static void pop_proc(void){    int     type;    if (stack_check_types(IMRECT, NULL) == false)        if (stack_check_types(EDGERECT, NULL) == false)	    error("pop_proc: wrong type on stack", warning);        else            mono_edges_set((Imrect *) stack_pop(&type));     else	mono_image_set((Imrect *) stack_pop(&type));    mono_draw(mono_tv_get());    if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());    if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());    image_choice_reset();}/* Mouse function callbacks */static void mono_mouse_proc(Tv_mouse(*func) ( /* ??? */ )){    tv_set_mouse(mono_tv(), (*func) ());    (void) tv_set_activity(mono_tv(), MOUSE);}/* Mono check callback */#define IMAGE_MASK  1#define EDGE_MASK   2#define CORNER_MASK 4#define STRING_MASK 8#define POLY_MASK   16#define OTHER_MASK  32static void mono_check_proc(int val){    mono_image_on((Bool) (val & IMAGE_MASK));    mono_edges_on((Bool) (val & EDGE_MASK));    mono_corners_on((Bool) (val & CORNER_MASK));    mono_strings_on((Bool) (val & STRING_MASK));    mono_poly_on((Bool) (val & POLY_MASK));}/* Choice item callbacks *//* File choice callback */static void file_choice_proc(int val){    file_type = val;}/* input / output callbacks */static void input_proc(void){    char  *pfname[1];        parse_fname(base_name, file_name, fnum);    *pfname = file_name;    if (strchr(file_name, '*') && !fname_resolve(directory_name, file_name, pfname))    {       error("mono input: no such file or filename", warning);       return;    }    mono_input(directory_name, *pfname, file_type);    mono_draw(mono_tv_get());}static void output_proc(void){    parse_fname(base_name, file_name, fnum);    if (strchr(file_name, '*'))    {      error("mono output: cannot output to wildcard name", warning);      return;    }    mono_output(directory_name, file_name, file_type);}/* Tv list choice proc *//* ARGSUSED quieten lint */static void tv_choice_proc(int val){    tv_set_next(mono_tv());}static void inc_fnum_proc(void){  fnum++;  tw_iglobal_reset(pframe);}static void dec_fnum_proc(void){  fnum--;  tw_iglobal_reset(pframe);}void scan_files(char *dir, char *file){   int i=0;   FILE *fp;   char temp[MAXPATHLEN], last[MAXPATHLEN];   (void) strip_spaces(file);   (void) strip_spaces(dir);   if (strcmp(file,"")==0)   {     sprintf(temp,"ls -d %s* > dirconts.tmp \n",dir);     system(temp);     if ((fp = fopen("dirconts.tmp", "r")) != NULL)     {       while (freadline(fp, temp)!=EOF)       {           format("%s \n",temp);           strcpy(last,temp);           i++;       }       fclose(fp);       if (i==1) strcpy(dir,last);     }   }   else   {     sprintf(temp,"ls %s* > dirconts.tmp \n",dir);     system(temp);     if ((fp = fopen("dirconts.tmp", "r")) != NULL)     {       while (freadline(fp, temp)!=EOF)       {           if (strncmp(temp,file, strlen(file))==0)           {             format("%s \n",temp);             strcpy(last,temp);             i++;           }       }       fclose(fp);       if (i==1) strcpy(file,last);     }   }   system("rm dirconts.tmp");}static void scan_proc(void){   scan_files(directory_name, base_name);   tw_sglobal_reset(pdir);   tw_sglobal_reset(pfile);}/* Tool creation */void    mono_tool(int x, int y){    Tv_mouse null_mouse();    Tv_mouse pos_mouse();    Tv_mouse mono_grey_mouse();    Tv_mouse pixel_mouse();    static void *tv_screen = NULL;    if (tv_screen)    {	tw_show_tool(tv_screen);	return;    }    /* Initialise pathname from environment variable (or #define) */    (void) environ_pathname_get(directory_name, base_name,				"TINA_IMAGE_DEFAULT",				"/home/wzz/newimscramdegree/result/Lena");    /* (void) strcat(base_name, ".l");  perhaps not */    tv_proc();    tv_screen = tw_tool("Mono Tool", x, y);    tw_choice("Tv : ", tv_choice_proc, 0, "mono", NULL);    tw_menubar("Mouse: ",	       "mono",	       "null", mono_mouse_proc, null_mouse,	       "pos", mono_mouse_proc, pos_mouse,	       "grey", mono_mouse_proc, mono_grey_mouse,	       "pixel", mono_mouse_proc, pixel_mouse,	       NULL,	       NULL);    tw_label("                   ");    tw_help_button("mono_tool");    tw_newrow();    tw_check("Mono:       ", mono_check_proc, 1,	     "image", "edges", "corner", "strings", "geom",	     NULL);    tw_newrow();    tw_choice("File:", file_choice_proc, 0,	      "AIFF", "PGM", "RAD", "EDGE", "POLY", "CAM", "WISP",	      "BMP", "GIF", "DICOM", NULL);    tw_newrow();    tw_button("input", input_proc, NULL);    tw_button("output", output_proc, NULL);    pframe = (void *)tw_iglobal(" Frame Number (#):", &fnum, 5);    tw_button("<", dec_fnum_proc, NULL);    tw_button(">", inc_fnum_proc, NULL);    tw_newrow();    pdir = (void *) tw_sglobal("Directory Name:", directory_name, 32);    tw_button("scan", scan_proc, NULL);    tw_newrow();    pfile = (void *) tw_sglobal("Base Name:     ", base_name, 32);    tw_newrow();    tw_button("push", push_proc, NULL);    tw_button("pop", pop_proc, NULL);    tw_end_tool();}

⌨️ 快捷键说明

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