--- GREYCstoration-2.9-src.old/src/greycstoration4gimp.cpp +++ GREYCstoration-2.9-src/src/greycstoration4gimp.cpp @@ -84,8 +84,6 @@ // Define static plug-in parameters //---------------------------------- -// Comment the line below if you don't want to use preview with zoom (zoom feature needs GIMP >= 2.3.4) -#define ZOOMPREVIEW // Uncomment this line to get a rough estimate of how long the plug-in takes to run // #define TIMER @@ -138,7 +136,6 @@ gint interp; // Interpolation type bool fast_approx; // Use fast approximation for regularization gint iterations; // Number of regularization iterations - gboolean update_preview; }; const Parameters defaults_parameters = { @@ -158,7 +155,6 @@ 0, // interp true, // fast_approx 1, // iterations - true // default is to update the preview }; const gint nb_parameters = 19; // Number of parameters + 2 @@ -177,12 +173,10 @@ static void callback_response(GtkWidget *widget, gint response_id, gpointer data); static void run_greycstoration(CImg& img, const gboolean show_progress); static gboolean dialog(GimpDrawable *drawable); -static void update_preview(GimpPreview *preview); // Plug-in global variables static gboolean runflag = FALSE; static Parameters params = defaults_parameters; -GtkWidget *preview; GtkObject* adj_amplitude; GtkObject* adj_sharpness; GtkObject* adj_anisotropy; @@ -267,7 +261,7 @@ switch (run_mode) { case GIMP_RUN_INTERACTIVE: - gimp_get_data ("plug_in_greycstoration", ¶ms); // Reset default values show preview unmodified + gimp_get_data ("plug_in_greycstoration", ¶ms); // Reset default values if (!dialog(drawable)) return; break; case GIMP_RUN_NONINTERACTIVE: @@ -408,46 +402,6 @@ } //---------------------- -// Update image preview -//---------------------- -static void update_preview(GimpPreview *preview) { - -#ifdef ZOOMPREVIEW - // Zoomable style preview - //------------------------- - gint width, height, bytes; - guchar *src, *row_ptr; - if (img.greycstoration_is_running()) img.greycstoration_stop(); - src = gimp_zoom_preview_get_source(GIMP_ZOOM_PREVIEW(preview),&width,&height,&bytes); - const gint channels = (bytes<3)?1:3; - img.assign(width,height,1,channels,0); - row_ptr = src; - cimg_forY(img,y) { cimg_forX(img,x) { cimg_forV(img,k) img(x,y,k) = row_ptr[k]; row_ptr += bytes; }} - run_greycstoration(img,false); - row_ptr = src; - cimg_forY(img,y) { cimg_forX(img,x) { cimg_forV(img,k) row_ptr[k] = img(x,y,k); row_ptr += bytes; }} - gimp_preview_draw_buffer(preview,src,width*bytes); - g_free(src); - -#else - // Old style preview (without zoom) - //---------------------------------- - GimpDrawable *drawable; - gint x, y, width, height; - GimpPixelRgn srcPR, destPR; - drawable = gimp_drawable_preview_get_drawable(GIMP_DRAWABLE_PREVIEW(preview)); - gimp_pixel_rgn_init(&srcPR,drawable,0,0,drawable->width,drawable->height,false,false); - gimp_pixel_rgn_init(&destPR,drawable,0,0,drawable->width,drawable->height,true,true); - gimp_preview_get_position(preview,&x,&y); - gimp_preview_get_size(preview,&width,&height); - if(img.greycstoration_is_running()) img.greycstoration_stop(); - process(&srcPR,&destPR,drawable->bpp,x,x+width,y,y+height,false); - gimp_pixel_rgn_init(&destPR,drawable,x,y,width,height,false,true); - gimp_drawable_preview_draw_region(GIMP_DRAWABLE_PREVIEW(preview),&destPR); -#endif -} - -//---------------------- // Define dialog window //---------------------- static gboolean dialog (GimpDrawable *drawable) { @@ -465,11 +419,7 @@ GIMP_STOCK_RESET,RESPONSE_RESET,GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,GTK_STOCK_OK,GTK_RESPONSE_OK,NULL); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog),RESPONSE_RESET,GTK_RESPONSE_OK,GTK_RESPONSE_CANCEL,-1); -#ifdef ZOOMPREVIEW - gimp_window_set_transient(GTK_WINDOW (dialog)); -#endif - - g_signal_connect(dialog,"response",G_CALLBACK(callback_response),preview); + g_signal_connect(dialog,"response",G_CALLBACK(callback_response),0); g_signal_connect(dialog, "destroy",G_CALLBACK(gtk_main_quit),0); main_vbox = gtk_vbox_new(false,12); @@ -477,114 +427,89 @@ gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),main_vbox); gtk_widget_show(main_vbox); -#ifdef ZOOMPREVIEW - preview = gimp_zoom_preview_new(drawable); -#else - preview = gimp_drawable_preview_new(drawable,¶ms.update_preview); -#endif - - gtk_box_pack_start(GTK_BOX(main_vbox),preview,true,true,0); - gtk_widget_show(preview); - g_signal_connect(preview,"invalidated",G_CALLBACK(update_preview),0); - table = gtk_table_new(3,3,false); gtk_table_set_col_spacings(GTK_TABLE(table),6); gtk_table_set_row_spacings(GTK_TABLE(table),6); - gtk_box_pack_start(GTK_BOX(main_vbox),table,false,false,0); + gtk_box_pack_start(GTK_BOX(main_vbox),table,true,true,0); gtk_widget_show(table); // 'Amplitude' slider adj_amplitude = gimp_scale_entry_new(GTK_TABLE(table),0,0,"_Strength :",SCALE_WIDTH,ENTRY_WIDTH, params.amplitude,0.0,200.0,1,10,1,true,0,0,0,0); g_signal_connect(adj_amplitude,"value_changed",G_CALLBACK(gimp_double_adjustment_update),¶ms.amplitude); - g_signal_connect_swapped(adj_amplitude,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Sharpness' slider adj_sharpness = gimp_scale_entry_new(GTK_TABLE(table),0,1,"Contour preser_vation :",SCALE_WIDTH,ENTRY_WIDTH, params.sharpness,0.0,5.0,0.05,0.5,2,true,0,0,0,0); g_signal_connect(adj_sharpness,"value_changed",G_CALLBACK(gimp_double_adjustment_update),¶ms.sharpness); - g_signal_connect_swapped(adj_sharpness,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Anisotropy' slider adj_anisotropy = gimp_scale_entry_new(GTK_TABLE(table),0,2,"_Anisotropy :",SCALE_WIDTH,ENTRY_WIDTH, params.anisotropy,0.0,1.0,0.05,0.5,2,true,0,0,0,0); g_signal_connect(adj_anisotropy,"value_changed",G_CALLBACK(gimp_double_adjustment_update),¶ms.anisotropy); - g_signal_connect_swapped(adj_anisotropy,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Alpha' slider adj_alpha = gimp_scale_entry_new(GTK_TABLE(table),0,3,"_Noise scale :",SCALE_WIDTH,ENTRY_WIDTH, params.alpha,0.0,16.0,0.1,0.5, 1,true,0,0,0,0); g_signal_connect(adj_alpha,"value_changed",G_CALLBACK(gimp_double_adjustment_update),¶ms.alpha); - g_signal_connect_swapped(adj_alpha,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Sigma' slider adj_sigma = gimp_scale_entry_new(GTK_TABLE(table),0,4,"Geometry _regularity :",SCALE_WIDTH,ENTRY_WIDTH, params.sigma,0,8.0,0.1,0.5,2,true,0,0,0,0); g_signal_connect(adj_sigma,"value_changed",G_CALLBACK(gimp_double_adjustment_update),¶ms.sigma); - g_signal_connect_swapped(adj_sigma,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Spatial step' slider adj_dl = gimp_scale_entry_new(GTK_TABLE (table),0,5,"Spatial step :",SCALE_WIDTH,ENTRY_WIDTH, params.dl,0.1,1.0,0.01,0.1,2,true,0,0,0,0); g_signal_connect(adj_dl,"value_changed",G_CALLBACK(gimp_double_adjustment_update),¶ms.dl); - g_signal_connect_swapped(adj_dl,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Angular step' slider adj_da = gimp_scale_entry_new(GTK_TABLE(table),0,6,"Angu_lar step :",SCALE_WIDTH,ENTRY_WIDTH, params.da,1.0,90.0,1.0,10.0,1,true,0,0,0,0); g_signal_connect(adj_da,"value_changed",G_CALLBACK(gimp_double_adjustment_update),¶ms.da); - g_signal_connect_swapped(adj_da,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Interpolation' choice combo_interp = gimp_int_combo_box_new("Nearest neighbor",0,"Linear",1,"Runge-Kutta",2,NULL); gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(combo_interp),params.interp); gimp_table_attach_aligned(GTK_TABLE(table),0,8,"Interpolation _type :",0.0,0.5,combo_interp,2,false); g_signal_connect(combo_interp,"changed",G_CALLBACK(gimp_int_combo_box_get_active),¶ms.interp); - g_signal_connect_swapped(combo_interp,"changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Patch-based' button button_patch_based = gtk_check_button_new_with_mnemonic("_Patch-based"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_patch_based),params.patch_based); gimp_table_attach_aligned(GTK_TABLE(table),0,9,"Patch-based :",0.0,0.5,button_patch_based,2,false); g_signal_connect(button_patch_based,"toggled",G_CALLBACK(gimp_toggle_button_update),¶ms.patch_based); - g_signal_connect_swapped(button_patch_based,"toggled",G_CALLBACK(gimp_preview_invalidate),preview); // 'Patch size' slider adj_patch_size = gimp_scale_entry_new(GTK_TABLE(table),0,10,"Patch size :",SCALE_WIDTH,ENTRY_WIDTH, params.patch_size,1.0,9.0,1.0,1.0,0,true,0,0,0,0); g_signal_connect(adj_patch_size,"value_changed",G_CALLBACK(gimp_int_adjustment_update),¶ms.patch_size); - g_signal_connect_swapped(adj_patch_size,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Sigma_p' slider adj_sigma_p = gimp_scale_entry_new(GTK_TABLE(table),0,11,"_Sigma-p :",SCALE_WIDTH,ENTRY_WIDTH, params.sigma_p,0.0,30.0,0.1,0.5,1,true,0,0,0,0); g_signal_connect(adj_sigma_p,"value_changed",G_CALLBACK(gimp_double_adjustment_update),¶ms.sigma_p); - g_signal_connect_swapped(adj_sigma_p,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Sigma_s' slider adj_sigma_s = gimp_scale_entry_new(GTK_TABLE(table),0,12,"_Sigma-s :",SCALE_WIDTH,ENTRY_WIDTH, params.sigma_s,0.0,30.0,0.1,0.5,1,true,0,0,0,0); g_signal_connect(adj_sigma_s,"value_changed",G_CALLBACK(gimp_double_adjustment_update),¶ms.sigma_s); - g_signal_connect_swapped(adj_sigma_s,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Lookup size' slider adj_lookup_size = gimp_scale_entry_new(GTK_TABLE(table),0,13,"Lookup size :",SCALE_WIDTH,ENTRY_WIDTH, params.lookup_size,1.0,40.0,1.0,1.0,0,true,0,0,0,0); g_signal_connect(adj_lookup_size,"value_changed",G_CALLBACK(gimp_int_adjustment_update),¶ms.lookup_size); - g_signal_connect_swapped(adj_lookup_size,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // 'Fast approximation' button button_fast_approx = gtk_check_button_new_with_mnemonic("_Enable"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_fast_approx),params.fast_approx); gimp_table_attach_aligned(GTK_TABLE(table),0,14,"Approximation :",0.0,0.5,button_fast_approx,2,false); g_signal_connect(button_fast_approx,"toggled",G_CALLBACK(gimp_toggle_button_update),¶ms.fast_approx); - g_signal_connect_swapped(button_fast_approx,"toggled",G_CALLBACK(gimp_preview_invalidate),preview); // 'Number of iterations' slider adj_iterations = gimp_scale_entry_new(GTK_TABLE(table),0,15,"Number of _iterations :",SCALE_WIDTH,ENTRY_WIDTH, params.iterations,1.0,30.0,1.0,1.0,0,true,0,0,0,0); g_signal_connect(adj_iterations,"value_changed",G_CALLBACK(gimp_int_adjustment_update),¶ms.iterations); - g_signal_connect_swapped(adj_iterations,"value_changed",G_CALLBACK(gimp_preview_invalidate),preview); // Show dialog window gtk_widget_show (dialog); @@ -608,7 +533,6 @@ gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_iterations), params.iterations); gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(combo_interp), params.interp); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_fast_approx), params.fast_approx); - gimp_preview_invalidate((GimpPreview*)preview); break; case GTK_RESPONSE_OK: runflag = TRUE;