00001 /* Gnome gxsm - Gnome X Scanning Microscopy 00002 * universal STM/AFM/SARLS/SPALEED/... controlling and 00003 * data analysis software 00004 * 00005 * plugin_helper reports your answers as 00006 author =Percy Zahl 00007 pluginname =bggamma 00008 pluginmenuentry =Gamma 00009 menupath =Math/Background/ 00010 entryplace =Background 00011 shortentryplace =BG 00012 abouttext =This Plugin does a gamma scaling of the Data. 00013 smallhelp =Apply Gamma Korrection to Data 00014 longhelp =Apply Gamma 00015 * 00016 * Gxsm Plugin Name: bggamma.C 00017 * ======================================== 00018 * 00019 * Copyright (C) 1999 The Free Software Foundation 00020 * 00021 * Authors: Percy Zahl <zahl@fkp.uni-hannover.de> 00022 * additional features: Andreas Klust <klust@fkp.uni-hannover.de> 00023 * 00024 * This program is free software; you can redistribute it and/or modify 00025 * it under the terms of the GNU General Public License as published by 00026 * the Free Software Foundation; either version 2 of the License, or 00027 * (at your option) any later version. 00028 * 00029 * This program is distributed in the hope that it will be useful, 00030 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00031 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00032 * GNU General Public License for more details. 00033 * 00034 * You should have received a copy of the GNU General Public License 00035 * along with this program; if not, write to the Free Software 00036 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00037 */ 00038 00039 00040 /* Please do not change the Begin/End lines of this comment section! 00041 * this is a LaTeX style section used for auto generation of the PlugIn Manual 00042 * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks! 00043 * All "% PlugInXXX" commentary tags are mandatory 00044 * All "% OptPlugInXXX" tags are optional 00045 * -------------------------------------------------------------------------------- 00046 % BeginPlugInDocuSection 00047 % PlugInDocuCaption: Gamma correction 00048 % PlugInName: bggamma 00049 % PlugInAuthor: Percy Zahl 00050 % PlugInAuthorEmail: zahl@users.sf.net 00051 % PlugInMenuPath: Math/Background/Gamma 00052 00053 % PlugInDescription 00054 Applys a gamma correction as it is defined here: 00055 \[ Z_{\text{range}} := Z_{\text{minval}} - Z_{\text{maxval}}\] 00056 \[ Z_{\text{math}} = \frac{Z_{\text{range}} Z_{\text{active}}^{\gamma}} 00057 {Z_{\text{range}}^{\gamma}} \] 00058 00059 % PlugInUsage 00060 Call \GxsmMenu{Math/Background/Gamma} and give the gamma value 00061 $\gamma$ if prompted. 00062 00063 % OptPlugInSources 00064 The active channel is used as data source. 00065 00066 % OptPlugInDest 00067 The computation result is placed into an existing math channel, else 00068 into a new created math channel. 00069 00070 % EndPlugInDocuSection 00071 * -------------------------------------------------------------------------------- 00072 */ 00073 00074 00075 #include <gtk/gtk.h> 00076 #include "config.h" 00077 #include "gxsm/plugin.h" 00078 00079 // Plugin Prototypes 00080 static void bggamma_init( void ); 00081 static void bggamma_about( void ); 00082 static void bggamma_configure( void ); 00083 static void bggamma_cleanup( void ); 00084 00085 // Define Type of math plugin here, only one line should be commented in!! 00086 #define GXSM_ONE_SRC_PLUGIN__DEF 00087 // #define GXSM_TWO_SRC_PLUGIN__DEF 00088 00089 // Math-Run-Function, use only one of (automatically done :=) 00090 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00091 // "OneSrc" Prototype 00092 static gboolean bggamma_run( Scan *Src, Scan *Dest ); 00093 #else 00094 // "TwoSrc" Prototype 00095 static gboolean bggamma_run( Scan *Src1, Scan *Src2, Scan *Dest ); 00096 #endif 00097 00098 // Fill in the GxsmPlugin Description here 00099 GxsmPlugin bggamma_pi = { 00100 NULL, // filled in and used by Gxsm, don't touch ! 00101 NULL, // filled in and used by Gxsm, don't touch ! 00102 0, // filled in and used by Gxsm, don't touch ! 00103 NULL, // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 00104 // filled in here by Gxsm on Plugin load, 00105 // just after init() is called !!! 00106 // ---------------------------------------------------------------------- 00107 // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc 00108 "bggamma-" 00109 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00110 "M1S" 00111 #else 00112 "M2S" 00113 #endif 00114 "-BG", 00115 // Plugin's Category - used to autodecide on Pluginloading or ignoring 00116 // NULL: load, else 00117 // example: "+noHARD +STM +AFM" 00118 // load only, if "+noHARD: no hardware" and Instrument is STM or AFM 00119 // +/-xxxHARD und (+/-INST or ...) 00120 NULL, 00121 // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details) 00122 "Apply Gamma", 00123 // Author(s) 00124 "Percy Zahl", 00125 // Menupath to position where it is appendet to 00126 N_("_Math/_Background/"), 00127 // Menuentry 00128 N_("Gamma"), 00129 // help text shown on menu 00130 N_("Apply Gammatransformation to Data"), 00131 // more info... 00132 "Apply Gammatransformation to the Data", 00133 NULL, // error msg, plugin may put error status msg here later 00134 NULL, // Plugin Status, managed by Gxsm, plugin may manipulate it too 00135 // init-function pointer, can be "NULL", 00136 // called if present at plugin load 00137 bggamma_init, 00138 // query-function pointer, can be "NULL", 00139 // called if present after plugin init to let plugin manage it install itself 00140 NULL, // query should be "NULL" for Gxsm-Math-Plugin !!! 00141 // about-function, can be "NULL" 00142 // can be called by "Plugin Details" 00143 bggamma_about, 00144 // configure-function, can be "NULL" 00145 // can be called by "Plugin Details" 00146 bggamma_configure, 00147 // run-function, can be "NULL", if non-Zero and no query defined, 00148 // it is called on menupath->"plugin" 00149 NULL, // run should be "NULL" for Gxsm-Math-Plugin !!! 00150 // cleanup-function, can be "NULL" 00151 // called if present at plugin removeal 00152 bggamma_cleanup 00153 }; 00154 00155 // special math Plugin-Strucure, use 00156 // GxsmMathOneSrcPlugin bggamma_m1s_pi -> "OneSrcMath" 00157 // GxsmMathTwoSrcPlugin bggamma_m2s_pi -> "TwoSrcMath" 00158 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00159 GxsmMathOneSrcPlugin bggamma_m1s_pi 00160 #else 00161 GxsmMathTwoSrcPlugin bggamma_m2s_pi 00162 #endif 00163 = { 00164 // math-function to run, see prototype(s) above!! 00165 bggamma_run 00166 }; 00167 00168 // Text used in Aboutbox, please update!! 00169 static const char *about_text = N_("Gxsm bggamma Plugin\n\n" 00170 "This Plugin does a gamma scaling of the Data:\n" 00171 "range/pow(range,gamma)*pow(dataval-datamin,gamma);" 00172 ); 00173 00174 double GammaDefault = 1.; 00175 double GammaLast = 1.; 00176 double gammaval = 1.; 00177 00178 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 00179 // Essential Plugin Function!! 00180 GxsmPlugin *get_gxsm_plugin_info ( void ){ 00181 bggamma_pi.description = g_strdup_printf(N_("Gxsm MathOneArg bggamma plugin %s"), VERSION); 00182 return &bggamma_pi; 00183 } 00184 00185 // Symbol "get_gxsm_math_one|two_src_plugin_info" is resolved by dlsym from Gxsm, 00186 // used to find out which Math Type the Plugin is!! 00187 // Essential Plugin Function!! 00188 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00189 GxsmMathOneSrcPlugin *get_gxsm_math_one_src_plugin_info( void ) { 00190 return &bggamma_m1s_pi; 00191 } 00192 #else 00193 GxsmMathTwoSrcPlugin *get_gxsm_math_two_src_plugin_info( void ) { 00194 return &bggamma_m2s_pi; 00195 } 00196 #endif 00197 00198 /* Here we go... */ 00199 // init-Function 00200 static void bggamma_init(void) 00201 { 00202 PI_DEBUG (DBG_L2, "bggamma Plugin Init"); 00203 } 00204 00205 // about-Function 00206 static void bggamma_about(void) 00207 { 00208 const gchar *authors[] = { bggamma_pi.authors, NULL}; 00209 gtk_widget_show(gnome_about_new ( bggamma_pi.name, 00210 VERSION, 00211 N_("(C) 2000 the Free Software Foundation"), 00212 about_text, 00213 authors, 00214 NULL, NULL, NULL 00215 )); 00216 } 00217 00218 // configure-Function 00219 static void bggamma_configure(void) 00220 { 00221 if(bggamma_pi.app) 00222 bggamma_pi.app->message("bggamma Plugin Configuration"); 00223 } 00224 00225 // cleanup-Function 00226 static void bggamma_cleanup(void) 00227 { 00228 PI_DEBUG (DBG_L2, "bggamma Plugin Cleanup"); 00229 } 00230 00231 double GammaFkt(double val, double range){ 00232 double gamma=gammaval; 00233 if (gamma != 1.) 00234 return (range/pow(range,gamma)*pow(val,gamma)); 00235 return val; 00236 } 00237 00238 // run-Function 00239 #ifdef GXSM_ONE_SRC_PLUGIN__DEF 00240 static gboolean bggamma_run(Scan *Src, Scan *Dest) 00241 #else 00242 static gboolean bggamma_run(Scan *Src1, Scan *Src2, Scan *Dest) 00243 #endif 00244 { 00245 int line, col; 00246 double hi,lo; 00247 gammaval = GammaLast; 00248 00249 Src->mem2d->HiLo(&hi, &lo, FALSE); 00250 00251 if (fabs(GammaDefault) > 1.) 00252 gammaval = GammaDefault; 00253 else 00254 bggamma_pi.app->ValueRequest 00255 ( "Enter Value", "gamma", 00256 "I need the Gamma value.", 00257 bggamma_pi.app->xsm->Unity, 00258 0., 1., ".3f", &gammaval 00259 ); 00260 GammaLast = gammaval; 00261 00262 for (line=0; line<Dest->data.s.ny; line++) 00263 for (col=0; col<Dest->data.s.nx; col++) 00264 Dest->mem2d->PutDataPkt 00265 (GammaFkt 00266 (Src->mem2d->GetDataPkt 00267 (col, line)-lo, hi-lo), 00268 col, line); 00269 00270 return MATH_OK; 00271 } 00272