"Fossies" - the Fresh Open Source Software Archive

Member "SAOImageDS9/funtools/doc/imblank.c" (13 Nov 2019, 2568 Bytes) of package /linux/misc/ds9.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <funtools.h>
    2 #include <stdlib.h>
    3 
    4 #ifdef ANSI_FUNC
    5 int 
    6 main (int argc, char **argv)
    7 #else
    8 main(argc, argv)
    9      int argc;
   10      char **argv;
   11 #endif
   12 {
   13   int i;
   14   int bitpix, dim1, dim2;
   15   int total;
   16   double blimit, bvalue;
   17   char *buf;
   18   unsigned char *cbuf;
   19   short *sbuf;
   20   int *ibuf;
   21   float *fbuf;
   22   double *dbuf;
   23   Fun fun, fun2;
   24 
   25   if( argc < 4 ){
   26     fprintf(stderr, "usage: %s iname oname blimit bvalue\n", argv[0]);
   27     exit(1);
   28   }
   29 
   30   /* get blank limit and optional blank value */
   31   blimit = atof(argv[3]);
   32   bvalue = 0;
   33   if( argc >= 5 )
   34     bvalue = atof(argv[4]);
   35 
   36   /* exit on gio errors */
   37   setgerror(2);
   38 
   39   /* open the input FITS file */
   40   if( !(fun = FunOpen(argv[1], "rc", NULL)) )
   41     gerror(stderr, "could not FunOpen input file: %s\n", argv[1]);
   42 
   43   /* open the output FITS image, preparing to copy input params */
   44   if( !(fun2 = FunOpen(argv[2], "w", fun)) )
   45     gerror(stderr, "could not FunOpen output file: %s\n", argv[2]);
   46 
   47   /* extract and bin the data section into an image buffer */
   48   if( !(buf = FunImageGet(fun, NULL, NULL)) )
   49     gerror(stderr, "could not FunImageGet: %s\n", argv[1]);
   50 
   51   /* get required information from funtools structure.
   52      this should come after the ImageGet call, in case that call
   53      changed fun_sect_bitpix value */
   54   FunInfoGet(fun,
   55          FUN_SECT_BITPIX,  &bitpix,
   56          FUN_SECT_DIM1,    &dim1,
   57          FUN_SECT_DIM2,    &dim2,
   58          0);
   59 
   60   /* set appropriate data type buffer to point to image buffer */
   61   switch(bitpix){
   62   case 8:
   63     cbuf = (unsigned char *)buf; break;
   64   case 16:
   65     sbuf = (short *)buf; break;
   66   case 32:
   67     ibuf = (int *)buf; break;
   68   case -32:
   69     fbuf = (float *)buf; break;
   70   case -64:
   71     dbuf = (double *)buf; break;
   72   }
   73 
   74   /* loop through pixels and reset values below limit to value */
   75   total = dim1*dim2;
   76   for(i=0; i<total; i++){
   77     switch(bitpix){
   78     case 8:
   79       if( cbuf[i] <= blimit ) cbuf[i] = bvalue;
   80       break;
   81     case 16:
   82       if( sbuf[i] <= blimit ) sbuf[i] = bvalue;
   83       break;
   84     case 32:
   85       if( ibuf[i] <= blimit ) ibuf[i] = bvalue;
   86       break;
   87     case -32:
   88       if( fbuf[i] <= blimit ) fbuf[i] = bvalue;
   89       break;
   90     case -64:
   91       if( dbuf[i] <= blimit ) dbuf[i] = bvalue;
   92       break;
   93     }
   94   }
   95 
   96   /* write the output image, updating the FITS header from the orig file */
   97   if( !FunImagePut(fun2, buf, 0, 0, 0, NULL) )
   98     gerror(stderr, "could not FunImagePut: %s\n", argv[2]);
   99 
  100   /* free up space */
  101   if( buf ) free(buf);
  102 
  103   /* close output first so that flush happens automatically */
  104   FunClose(fun2);
  105   FunClose(fun);
  106 }