00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #include <gtk/gtk.h>
00059 #include "config.h"
00060 #include "gxsm/plugin.h"
00061
00062
00063 static void smallconvol_init( void );
00064 static void smallconvol_about( void );
00065 static void smallconvol_configure( void );
00066 static void smallconvol_cleanup( void );
00067 static gboolean smallconvol_run( Scan *Src, Scan *Dest );
00068
00069 GxsmPlugin smallconvol_pi = {
00070 NULL,
00071 NULL,
00072 0,
00073 NULL,
00074 "Smallconvol-M1S-F1D",
00075 NULL,
00076 NULL,
00077 "Percy Zahl",
00078 "_Math/Filter _2D/",
00079 N_("Small Convol"),
00080 N_("Sorry, no help for smallconvol filter!"),
00081 "no more info",
00082 NULL,
00083 NULL,
00084 smallconvol_init,
00085 NULL,
00086 smallconvol_about,
00087 smallconvol_configure,
00088 NULL,
00089 smallconvol_cleanup
00090 };
00091
00092 GxsmMathOneSrcPlugin smallconvol_m1s_pi = {
00093 smallconvol_run
00094 };
00095
00096 static const char *about_text = N_("Gxsm Smallconvol Plugin\n\n"
00097 "Matrix Convolution PlugIn.");
00098
00099 GxsmPlugin *get_gxsm_plugin_info ( void ){
00100 smallconvol_pi.description = g_strdup_printf(N_("Gxsm MathOneArg smallconvol plugin %s"), VERSION);
00101 return &smallconvol_pi;
00102 }
00103
00104 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) {
00105 return &smallconvol_m1s_pi;
00106 }
00107
00108
00109
00110 #define SET_SMC_PROGRESS(P) { smallconvol_pi.app->SetProgress((gfloat)(P)); while (gtk_events_pending()) gtk_main_iteration(); }
00111
00112 double kernel[3][3];
00113
00114 static void smallconvol_init(void)
00115 {
00116 PI_DEBUG (DBG_L2, "Smallconvol Plugin Init");
00117
00118 kernel[0][0] = 1.0;
00119 kernel[0][1] = 1.0;
00120 kernel[0][2] = 1.0;
00121 kernel[1][0] = 1.0;
00122 kernel[1][1] = 1.0;
00123 kernel[1][2] = 1.0;
00124 kernel[2][0] = 1.0;
00125 kernel[2][1] = 1.0;
00126 kernel[2][2] = 1.0;
00127 }
00128
00129 static void smallconvol_about(void)
00130 {
00131 const gchar *authors[] = { smallconvol_pi.authors, NULL};
00132 gtk_widget_show(gnome_about_new ( smallconvol_pi.name,
00133 VERSION,
00134 N_("(C) 2000 the Free Software Foundation"),
00135 about_text,
00136 authors,
00137 NULL, NULL, NULL
00138 ));
00139 }
00140
00141 static void smallconvol_configure(void)
00142 {
00143 GtkWidget *dialog;
00144 GtkWidget *vbox;
00145 GtkWidget *hbox;
00146 GtkWidget *info;
00147 GtkWidget *input;
00148
00149 dialog = gnome_dialog_new(_("Small Convol Kernel Setup"),
00150 GNOME_STOCK_BUTTON_OK,
00151 NULL);
00152
00153 gnome_dialog_set_close(GNOME_DIALOG(dialog), FALSE);
00154 gnome_dialog_close_hides(GNOME_DIALOG(dialog), FALSE);
00155 gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
00156
00157 vbox = gtk_vbox_new (FALSE, 0);
00158 gtk_widget_show (vbox);
00159
00160 gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),
00161 vbox, TRUE, TRUE, GNOME_PAD);
00162
00163 info = gtk_label_new ("3x3 Kernel");
00164 gtk_widget_show (info);
00165 gtk_box_pack_start(GTK_BOX(vbox), info, TRUE, TRUE, GNOME_PAD);
00166
00167 input = smallconvol_pi.app->mygtk_create_input("1", vbox, hbox);
00168 Gtk_EntryControl ECvar11(smallconvol_pi.app->xsm->Unity, "Value out of range !", &kernel[0][0],
00169 -999, 999, ".0f", input);
00170 input = smallconvol_pi.app->mygtk_add_input(hbox);
00171 Gtk_EntryControl ECvar12(smallconvol_pi.app->xsm->Unity, "Value out of range !", &kernel[0][1],
00172 -999, 999, ".0f", input);
00173 input = smallconvol_pi.app->mygtk_add_input(hbox);
00174 Gtk_EntryControl ECvar13(smallconvol_pi.app->xsm->Unity, "Value out of range !", &kernel[0][2],
00175 -999, 999, ".0f", input);
00176
00177 input = smallconvol_pi.app->mygtk_create_input("2", vbox, hbox);
00178 Gtk_EntryControl ECvar21(smallconvol_pi.app->xsm->Unity, "Value out of range !", &kernel[1][0],
00179 -999, 999, ".0f", input);
00180 input = smallconvol_pi.app->mygtk_add_input(hbox);
00181 Gtk_EntryControl ECvar22(smallconvol_pi.app->xsm->Unity, "Value out of range !", &kernel[1][1],
00182 -999, 999, ".0f", input);
00183 input = smallconvol_pi.app->mygtk_add_input(hbox);
00184 Gtk_EntryControl ECvar23(smallconvol_pi.app->xsm->Unity, "Value out of range !", &kernel[1][2],
00185 -999, 999, ".0f", input);
00186
00187 input = smallconvol_pi.app->mygtk_create_input("3", vbox, hbox);
00188 Gtk_EntryControl ECvar31(smallconvol_pi.app->xsm->Unity, "Value out of range !", &kernel[2][0],
00189 -999, 999, ".0f", input);
00190 input = smallconvol_pi.app->mygtk_add_input(hbox);
00191 Gtk_EntryControl ECvar32(smallconvol_pi.app->xsm->Unity, "Value out of range !", &kernel[2][1],
00192 -999, 999, ".0f", input);
00193 input = smallconvol_pi.app->mygtk_add_input(hbox);
00194 Gtk_EntryControl ECvar33(smallconvol_pi.app->xsm->Unity, "Value out of range !", &kernel[2][2],
00195 -999, 999, ".0f", input);
00196
00197 gtk_widget_show(dialog);
00198
00199 gnome_dialog_run_and_close(GNOME_DIALOG(dialog));
00200 }
00201
00202 static void smallconvol_cleanup(void)
00203 {
00204 PI_DEBUG (DBG_L2, "Smallconvol Plugin Cleanup");
00205 }
00206
00207
00208 static gboolean smallconvol_run(Scan *Src, Scan *Dest)
00209 {
00210 int line, col;
00211 ZData *src;
00212
00213
00214
00215
00216 Dest->data.s.nx -= 2;
00217 Dest->data.s.ny -= 2;
00218 Dest->mem2d->Resize(Dest->data.s.nx, Dest->data.s.ny);
00219
00220
00221 double norm = 1. / (kernel[0][0] + kernel[0][1] + kernel[0][2] +
00222 kernel[1][0] + kernel[1][1] + kernel[1][2] +
00223 kernel[2][0] + kernel[2][1] + kernel[2][2]);
00224
00225 PI_DEBUG (DBG_L2, "Norm of Kernel is " << norm);
00226
00227
00228 src = Src->mem2d->data;
00229 for (line = 0; line < Dest->mem2d->GetNy(); ++line) {
00230 if(!(line%32)) SET_SMC_PROGRESS( line / Dest->mem2d->GetNy() );
00231 src->SetPtrTB(1, line+1);
00232 for (col = 0; col < Dest->mem2d->GetNx(); ++col) {
00233 Dest->mem2d->PutDataPkt
00234 ( norm *
00235 ( kernel[0][0] * src->GetThisLT() +
00236 kernel[1][0] * src->GetThisT() +
00237 kernel[2][0] * src->GetThisRT() +
00238
00239 kernel[0][1] * src->GetThisL() +
00240 kernel[1][1] * src->GetThis() +
00241 kernel[2][1] * src->GetThisR() +
00242
00243 kernel[0][2] * src->GetThisLB() +
00244 kernel[1][2] * src->GetThisB() +
00245 kernel[2][2] * src->GetThisRB()
00246 ), col, line );
00247 src->IncPtrTB();
00248 }
00249 }
00250 SET_SMC_PROGRESS( 0. );
00251 return MATH_OK;
00252 }