int binary_cb(void) { Image* tmp = gc.image; if (tmp != NULL){ IupSetfAttribute(gc.msgbar, "TITLE", "Grey scale image ..."); gc.image = imgGrey(tmp); repaint_cb(gc.canvas); /* repaint canvas */ imgDestroy(tmp); tmp = gc.image; gc.image = imgBinary(tmp); repaint_cb(gc.canvas); /* repaint canvas */ imgDestroy(tmp); IupSetfAttribute(gc.msgbar, "TITLE", "Binary image ..."); } return IUP_DEFAULT; }
int load_image_cb(void) { if(image_copy == NULL) { IupSetfAttribute(gc.msgbar, "TITLE", "There's no copy of image saved"); return IUP_DEFAULT; } gc.image = imgCopy(image_copy); repaint_cb(gc.canvas); IupSetfAttribute(gc.msgbar, "TITLE", "Last state saved is loaded"); return IUP_DEFAULT; }
int dilate_cb(void) { Image *tmp = gc.image; if(tmp == NULL || imgGetDimColorSpace(tmp) != 1) { IupSetfAttribute(gc.msgbar, "TITLE", "Image doesn't exist or not binary"); return IUP_DEFAULT; } IupSetfAttribute(gc.msgbar, "TITLE", "Image dilatating ..."); gc.image = imgDilatation(tmp); repaint_cb(gc.canvas); /* repaint canvas */ imgDestroy(tmp); IupSetfAttribute(gc.msgbar, "TITLE", "Image dilatated ..."); return IUP_DEFAULT; }
int change_cb(void) { Image *tmp = gc.image; if(tmp == NULL || imgGetDimColorSpace(tmp) != 1) { IupSetfAttribute(gc.msgbar, "TITLE", "Image doesn't exist or not binary"); return IUP_DEFAULT; } IupSetfAttribute(gc.msgbar, "TITLE", "Changing binary colors ..."); gc.image = imgChangeBinary(tmp); repaint_cb(gc.canvas); /* repaint canvas */ imgDestroy(tmp); IupSetfAttribute(gc.msgbar, "TITLE", "Binary colors changed ..."); return IUP_DEFAULT; }
/* function called in the event of changes in the width or in the height of the canvas */ int resize_cb(Ihandle *self, int new_width, int new_height) { IupGLMakeCurrent(self); /* Make the canvas current in OpenGL */ /* define the entire canvas as the viewport */ glViewport(0,0,new_width,new_height); /* transformation applied to each vertex */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* identity, i. e. no transformation */ /* projection transformation (orthographic in the xy plane) */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D (0.0, (GLsizei)(new_width), 0.0, (GLsizei)(new_height)); /* window of interest [0,w]x[0,h] */ /* update canvas size and repaint */ gc.width=new_width; gc.height=new_height; repaint_cb(gc.canvas); return IUP_DEFAULT; /* return to the IUP main loop */ }
int load_cb(void) { char* file_name = IupSelectFile("File Selection","*.bmp","Load a BMP file"); if (!file_name) { IupSetfAttribute(gc.msgbar, "TITLE", "Selection failed"); return IUP_DEFAULT; } if (gc.image!=NULL) imgDestroy(gc.image); gc.image=imgReadBMP(file_name); /* loads the image */ if (gc.image!=NULL) { gc.width = imgGetWidth(gc.image); gc.height = imgGetHeight(gc.image); IupCanvasResize(gc.canvas,gc.dialog,gc.width,gc.height); repaint_cb(gc.canvas); IupSetfAttribute(gc.msgbar, "TITLE", "%s", strip_path_from_filename(file_name)); } else IupSetfAttribute(gc.msgbar, "TITLE", "Can't open %s", strip_path_from_filename(file_name)); return IUP_DEFAULT; }
/* function called in the event of changes in the width or in the height of the canvas */ int resize_cb(Ihandle *self, int new_width, int new_height) { IupGLMakeCurrent(self); /* Make the canvas current in OpenGL */ /* define the entire canvas as the viewport */ glViewport(0,0,new_width,new_height); /* transformation applied to each vertex */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* identity, i. e. no transformation */ /* projection transformation (orthographic in the xy plane) */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60,4./3.,1.,15); gluLookAt(3,3,3, 0,0,0, 0,0,1); /* update canvas size and repaint */ width=new_width; height=new_height; repaint_cb(canvas); return IUP_DEFAULT; /* return to the IUP main loop */ }
int idle_cd(void) { t+=1; repaint_cb(canvas); return IUP_DEFAULT; /* return to the IUP main loop */ }