Main Page   Data Structures   File List   Data Fields   Globals  

Sadie_FileIO.c

Go to the documentation of this file.
00001 /*
00002 ##########################################
00003 # Sadie_FileIO.c -
00004 #   Set of routines for linking SADIE file I/O routines to tcl/tk.
00005 #
00006 # RCS: $Id: Sadie_FileIO.c,v 2.6 2000/08/15 00:14:49 giri Exp $ 
00007 # 
00008 # Digital Image Analysis Lab
00009 # Dept. of Electrical and Computer Engineering
00010 # University of Arizona
00011 ##########################################
00012 */
00013 
00014 #include <tcl.h>
00015 #include <tk.h>
00016 #include <stdio.h>
00017 #include <string.h>
00018 #include "sadie.h"
00019 #include <math.h>
00020 
00021 /* RCS Indentification information */
00022 static char rcsid[] =
00023   "$Id: Sadie_FileIO.c,v 2.6 2000/08/15 00:14:49 giri Exp $";
00024 
00025 int
00026 Sadie_FileIO_OpenCmd (ClientData client_data, Tcl_Interp * interp, int argc,
00027                       char *argv[])
00028 {
00029   int addrstr;
00030   long filesize;
00031   IMAGE *theimg = NULL;
00032   char msg[SLEN];
00033   Tcl_Obj *tclvar = NULL;
00034 
00035   if (argc <= 3)
00036     {
00037       sprintf (msg, "Usage: Sadie_FileIO_Open filename filesize title");
00038       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00039       return TCL_ERROR;
00040     }
00041 
00042   /* Read the size of the file */
00043   tclvar = Tcl_NewStringObj (argv[2], -1);
00044   if (Tcl_GetLongFromObj (interp, tclvar, &filesize) == TCL_ERROR)
00045     {
00046       return TCL_ERROR;
00047     }
00048   Tcl_DecrRefCount (tclvar);
00049 
00050   DISK2IMG (argv[1], filesize, &theimg);
00051 
00052   if (theimg)
00053     sprintf (theimg->text, "%s", argv[3]);
00054   addrstr = (int) theimg;
00055 
00056   sprintf (msg, "%x", addrstr);
00057   Tcl_SetResult (interp, msg, TCL_VOLATILE);
00058 
00059   return TCL_OK;
00060 }
00061 
00062 int
00063 Sadie_FileIO_OpenTIFFCmd (ClientData client_data, Tcl_Interp * interp,
00064                           int argc, char *argv[])
00065 {
00066   int addrstr;
00067   IMAGE *theimg = NULL;
00068   char msg[SLEN];
00069 
00070   if (argc <= 2)
00071     {
00072       sprintf (msg, "Usage: Sadie_FileIO_OpenTIFF filename title");
00073       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00074       return TCL_ERROR;
00075     }
00076 
00077   TIFF2IMG (argv[1], &theimg);
00078 
00079   if (theimg)
00080     sprintf (theimg->text, "%s", argv[2]);
00081   addrstr = (int) theimg;
00082 
00083   sprintf (msg, "%x", addrstr);
00084   Tcl_SetResult (interp, msg, TCL_VOLATILE);
00085 
00086   return TCL_OK;
00087 }
00088 
00089 int
00090 Sadie_FileIO_OpenPNMCmd (ClientData client_data, Tcl_Interp * interp,
00091                          int argc, char *argv[])
00092 {
00093   int addrstr;
00094   IMAGE *theimg = NULL;
00095   char msg[SLEN];
00096 
00097   if (argc <= 2)
00098     {
00099       sprintf (msg, "Usage: Sadie_FileIO_OpenPNM filename title");
00100       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00101       return TCL_ERROR;
00102     }
00103 
00104   PNM2IMG (argv[1], &theimg);
00105 
00106   if (theimg)
00107     sprintf (theimg->text, "%s", argv[2]);
00108   addrstr = (int) theimg;
00109 
00110   sprintf (msg, "%x", addrstr);
00111   Tcl_SetResult (interp, msg, TCL_VOLATILE);
00112 
00113   return TCL_OK;
00114 }
00115 
00116 int
00117 Sadie_FileIO_ImportCmd (ClientData client_data, Tcl_Interp * interp, int argc,
00118                         char *argv[])
00119 {
00120   int addrstr;
00121   long filesize;
00122   IMAGE *theimg = NULL;
00123   char *name;
00124   int hdrsize;
00125   int nbnd;
00126   int nlin;
00127   int npix;
00128   int nbit;
00129   int option;
00130   int subsamp;
00131   int fromband, toband, incrband, fromline, toline, incrline, frompixel,
00132     topixel, incrpixel;
00133   char msg[SLEN];
00134   Tcl_Obj *tclvar = NULL;
00135 
00136   if (argc <= 19)
00137     {
00138       sprintf (msg, "Sadie_FileIO_Import expects a minimum of 18 arguments");
00139       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00140       return TCL_ERROR;
00141     }
00142 
00143   name = argv[1];
00144 
00145   if (Tcl_GetInt (interp, argv[2], &hdrsize) != TCL_OK)
00146     {
00147       return TCL_ERROR;
00148     }
00149 
00150   if (Tcl_GetInt (interp, argv[3], &nbnd) != TCL_OK)
00151     {
00152       return TCL_ERROR;
00153     }
00154 
00155   if (Tcl_GetInt (interp, argv[4], &nlin) != TCL_OK)
00156     {
00157       return TCL_ERROR;
00158     }
00159 
00160   if (Tcl_GetInt (interp, argv[5], &npix) != TCL_OK)
00161     {
00162       return TCL_ERROR;
00163     }
00164 
00165   if (Tcl_GetInt (interp, argv[6], &nbit) != TCL_OK)
00166     {
00167       return TCL_ERROR;
00168     }
00169 
00170   if (Tcl_GetInt (interp, argv[7], &option) != TCL_OK)
00171     {
00172       return TCL_ERROR;
00173     }
00174 
00175   if (Tcl_GetInt (interp, argv[8], &subsamp) != TCL_OK)
00176     {
00177       return TCL_ERROR;
00178     }
00179 
00180   if (subsamp)
00181     {
00182       if (Tcl_GetInt (interp, argv[9], &fromband) != TCL_OK)
00183         {
00184           return TCL_ERROR;
00185         }
00186 
00187       if (Tcl_GetInt (interp, argv[10], &toband) != TCL_OK)
00188         {
00189           return TCL_ERROR;
00190         }
00191 
00192       if (Tcl_GetInt (interp, argv[11], &incrband) != TCL_OK)
00193         {
00194           return TCL_ERROR;
00195         }
00196 
00197       if (Tcl_GetInt (interp, argv[12], &fromline) != TCL_OK)
00198         {
00199           return TCL_ERROR;
00200         }
00201 
00202       if (Tcl_GetInt (interp, argv[13], &toline) != TCL_OK)
00203         {
00204           return TCL_ERROR;
00205         }
00206 
00207       if (Tcl_GetInt (interp, argv[14], &incrline) != TCL_OK)
00208         {
00209           return TCL_ERROR;
00210         }
00211 
00212       if (Tcl_GetInt (interp, argv[15], &frompixel) != TCL_OK)
00213         {
00214           return TCL_ERROR;
00215         }
00216 
00217       if (Tcl_GetInt (interp, argv[16], &topixel) != TCL_OK)
00218         {
00219           return TCL_ERROR;
00220         }
00221 
00222       if (Tcl_GetInt (interp, argv[17], &incrpixel) != TCL_OK)
00223         {
00224           return TCL_ERROR;
00225         }
00226 
00227       if (fromband > 0)
00228         fromband--;
00229       if (toband > 0)
00230         toband--;
00231       if (fromline > 0)
00232         fromline--;
00233       if (toline > 0)
00234         toline--;
00235       if (frompixel > 0)
00236         frompixel--;
00237       if (topixel > 0)
00238         topixel--;
00239     }
00240   else
00241     {
00242       fromband = 0;
00243       fromline = 0;
00244       frompixel = 0;
00245 
00246       toband = nbnd - 1;
00247       toline = nlin - 1;
00248       topixel = npix - 1;
00249 
00250       incrband = 1;
00251       incrline = 1;
00252       incrpixel = 1;
00253     }
00254 
00255   /* Read the size of the file */
00256   tclvar = Tcl_NewStringObj (argv[18], -1);
00257   if (Tcl_GetLongFromObj (interp, tclvar, &filesize) == TCL_ERROR)
00258     {
00259       return TCL_ERROR;
00260     }
00261   Tcl_DecrRefCount (tclvar);
00262 
00263   IMPORT (name, option, hdrsize, nbnd, nlin, npix, nbit, fromband, fromline,
00264           frompixel, incrband, incrline, incrpixel, toband, toline, topixel,
00265           filesize, &theimg);
00266 
00267   if (theimg)
00268     sprintf (theimg->text, "%s", name);
00269   addrstr = (int) theimg;
00270 
00271   sprintf (msg, "%x", addrstr);
00272   Tcl_SetResult (interp, msg, TCL_VOLATILE);
00273 
00274   return TCL_OK;
00275 }
00276 
00277 int
00278 Sadie_FileIO_SaveCmd (ClientData client_data, Tcl_Interp * interp, int argc,
00279                       char *argv[])
00280 {
00281   int imgaddr;
00282   IMAGE *theimg = NULL;
00283   char *name;
00284   int bitsperpix;
00285   char msg[SLEN];
00286 
00287   if (argc <= 3)
00288     {
00289       sprintf (msg,
00290                "Usage: Sadie_FileIO_Save image_address filename bitsperpixel");
00291       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00292       return TCL_ERROR;
00293     }
00294 
00295   sscanf (argv[1], "%x", &imgaddr);
00296   theimg = (IMAGE *) imgaddr;
00297 
00298   sscanf (argv[3], "%d", &bitsperpix);
00299 
00300   name = argv[2];
00301 
00302   IMG2DISK (theimg, bitsperpix, name);
00303 
00304   return TCL_OK;
00305 }
00306 
00307 int
00308 Sadie_FileIO_SaveEPSCmd (ClientData client_data, Tcl_Interp * interp,
00309                          int argc, char *argv[])
00310 {
00311   int imgaddr;
00312   IMAGE *theimg = NULL;
00313   char *name;
00314   int bitsperpix;
00315   char msg[SLEN];
00316 
00317   if (argc <= 3)
00318     {
00319       sprintf (msg,
00320                "Usage: Sadie_FileIO_SaveEPS image_address filename bitsperpixel");
00321       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00322       return TCL_ERROR;
00323     }
00324 
00325   sscanf (argv[1], "%x", &imgaddr);
00326   theimg = (IMAGE *) imgaddr;
00327 
00328   sscanf (argv[3], "%d", &bitsperpix);
00329 
00330   name = argv[2];
00331 
00332   IMG2EPSF (theimg, name, bitsperpix);
00333 
00334   return TCL_OK;
00335 }
00336 
00337 int
00338 Sadie_FileIO_SaveTIFFCmd (ClientData client_data, Tcl_Interp * interp,
00339                           int argc, char *argv[])
00340 {
00341   int imgaddr;
00342   IMAGE *theimg = NULL;
00343   char *name;
00344   int bitsperpix;
00345   char msg[SLEN];
00346 
00347   if (argc <= 3)
00348     {
00349       sprintf (msg,
00350                "Usage: Sadie_FileIO_SaveTIFF image_address filename bitsperpixel");
00351       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00352       return TCL_ERROR;
00353     }
00354 
00355   sscanf (argv[1], "%x", &imgaddr);
00356   theimg = (IMAGE *) imgaddr;
00357 
00358   sscanf (argv[3], "%d", &bitsperpix);
00359 
00360   name = argv[2];
00361 
00362   IMG2TIFF (theimg, name, bitsperpix);
00363 
00364   return TCL_OK;
00365 }
00366 
00367 int
00368 Sadie_FileIO_SavePNMCmd (ClientData client_data, Tcl_Interp * interp,
00369                          int argc, char *argv[])
00370 {
00371   int imgaddr;
00372   IMAGE *theimg = NULL;
00373   char *name;
00374   int bitsperpix;
00375   char msg[SLEN];
00376 
00377   if (argc <= 2)
00378     {
00379       sprintf (msg, "Usage: Sadie_FileIO_SavePNM image_address filename");
00380       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00381       return TCL_ERROR;
00382     }
00383 
00384   sscanf (argv[1], "%x", &imgaddr);
00385   theimg = (IMAGE *) imgaddr;
00386 
00387   name = argv[2];
00388 
00389   IMG2PNM (theimg, name);
00390 
00391   return TCL_OK;
00392 }
00393 
00394 int
00395 Sadie_FileIO_SaveTEXTCmd (ClientData client_data, Tcl_Interp * interp,
00396                           int argc, char *argv[])
00397 {
00398   int imgaddr;
00399   IMAGE *theimg = NULL;
00400   char *name;
00401   char msg[SLEN];
00402 
00403   if (argc <= 2)
00404     {
00405       sprintf (msg, "Usage: Sadie_FileIO_SaveTEXT image_address filename");
00406       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00407       return TCL_ERROR;
00408     }
00409 
00410   sscanf (argv[1], "%x", &imgaddr);
00411   theimg = (IMAGE *) imgaddr;
00412 
00413   name = argv[2];
00414 
00415   IMG2TEXT (theimg, name);
00416 
00417   return TCL_OK;
00418 }
00419 
00420 /*************************************************************************
00421  *
00422  * This procedure initializes the the Sadie_FileIO procedures when
00423  * this package is loaded.
00424  *
00425  *************************************************************************/
00426 int
00427 Sadie_FileIO_Init (Tcl_Interp * interp)
00428 {
00429   Tcl_CreateCommand (interp, "Sadie_FileIO_Open", Sadie_FileIO_OpenCmd,
00430                      (ClientData) NULL, NULL);
00431   Tcl_CreateCommand (interp, "Sadie_FileIO_OpenTIFF",
00432                      Sadie_FileIO_OpenTIFFCmd, (ClientData) NULL, NULL);
00433   Tcl_CreateCommand (interp, "Sadie_FileIO_OpenPNM", Sadie_FileIO_OpenPNMCmd,
00434                      (ClientData) NULL, NULL);
00435   Tcl_CreateCommand (interp, "Sadie_FileIO_Import", Sadie_FileIO_ImportCmd,
00436                      (ClientData) NULL, NULL);
00437   Tcl_CreateCommand (interp, "Sadie_FileIO_Save", Sadie_FileIO_SaveCmd,
00438                      (ClientData) NULL, NULL);
00439   Tcl_CreateCommand (interp, "Sadie_FileIO_SaveEPS", Sadie_FileIO_SaveEPSCmd,
00440                      (ClientData) NULL, NULL);
00441   Tcl_CreateCommand (interp, "Sadie_FileIO_SaveTIFF",
00442                      Sadie_FileIO_SaveTIFFCmd, (ClientData) NULL, NULL);
00443   Tcl_CreateCommand (interp, "Sadie_FileIO_SavePNM", Sadie_FileIO_SavePNMCmd,
00444                      (ClientData) NULL, NULL);
00445   Tcl_CreateCommand (interp, "Sadie_FileIO_SaveTEXT",
00446                      Sadie_FileIO_SaveTEXTCmd, (ClientData) NULL, NULL);
00447 
00448   return TCL_OK;
00449 }

Generated on Sun May 18 15:36:15 2003 for tclSadie by doxygen1.3