index 60420e2..cc97e08 100644 (file)
   4. negate image option
   5. jpeg quality factor
   6. pixel scaling operations moved to image.c
   4. negate image option
   5. jpeg quality factor
   6. pixel scaling operations moved to image.c
-  7. Image resizing works for reducing size. segfaults for zoom > 1 :(
+  7. Image resizing
   TODO
       1. move fits read to image.c
       2. specify output directory
   TODO
       1. move fits read to image.c
       2. specify output directory
-      3. Image resizing options
  *---------------------------------------------------------------------------*/
 
 #include "fits2jpeg.h"
  *---------------------------------------------------------------------------*/
 
 #include "fits2jpeg.h"
@@ -94,7 +93,7 @@ int main(int argc, char *argv[], char *envp[])
 {
     fitsfile *fptr;
 
 {
     fitsfile *fptr;
 
-    int scale = 0, process = 0, status = 0, jpgqual = 100, nfound, anynull;
+    int scale = 0, status = 0, jpgqual = 100, nfound, anynull;
     unsigned int i = 0, j = 0, usrclip = 0, usrnegt = 0, usrzoom = 0;
     long xdim = 0, ydim = 0, naxes[2], row_stride;
     unsigned long npixels = 0;
     unsigned int i = 0, j = 0, usrclip = 0, usrnegt = 0, usrzoom = 0;
     long xdim = 0, ydim = 0, naxes[2], row_stride;
     unsigned long npixels = 0;
@@ -133,6 +132,7 @@ int main(int argc, char *argv[], char *envp[])
             else if (strcmp(optarg, "normalize")==0) scale = 5;
             else if (strcmp(optarg, "equalize") ==0) scale = 6;
             else
             else if (strcmp(optarg, "normalize")==0) scale = 5;
             else if (strcmp(optarg, "equalize") ==0) scale = 6;
             else
+                printwarn(strcat(optarg, " -- Unrecognized option"));
                 scale = 0;
             break;
 
                 scale = 0;
             break;
 
@@ -165,7 +165,6 @@ int main(int argc, char *argv[], char *envp[])
                 sptr = strtok(tmpstr, ":");
                 datamin = atof(sptr);
             }
                 sptr = strtok(tmpstr, ":");
                 datamin = atof(sptr);
             }
-            printinfo("User defined pixel range");
 
             /* Remember.. now we have user specified range */
             usrclip = 1;
 
             /* Remember.. now we have user specified range */
             usrclip = 1;
@@ -187,7 +186,9 @@ int main(int argc, char *argv[], char *envp[])
             /* Do something to scale image
              */
             zoomfact = atof(optarg);
             /* Do something to scale image
              */
             zoomfact = atof(optarg);
-            if (zoomfact < 0.0) zoomfact = 1.0;
+            zoomfact = abs(zoomfact);
+            if (zoomfact < 0.01) zoomfact = 0.01;
+            if (zoomfact > 4.0) zoomfact = 4.0;
             usrzoom = 1;
             break;
 
             usrzoom = 1;
             break;
 
@@ -225,7 +226,7 @@ int main(int argc, char *argv[], char *envp[])
 
         /* Read in data */
         npixels = naxes[0] * naxes[1];
 
         /* Read in data */
         npixels = naxes[0] * naxes[1];
-        data = (float *) malloc(sizeof(float) * npixels);
+        data = malloc(sizeof(float) * npixels);
 
         nullval = 0;
         if (fits_read_img(fptr, TFLOAT, 1, npixels, &nullval, data, &anynull,
 
         nullval = 0;
         if (fits_read_img(fptr, TFLOAT, 1, npixels, &nullval, data, &anynull,
@@ -243,6 +244,7 @@ int main(int argc, char *argv[], char *envp[])
         /* IF user has provided a range, fix them as min & max in image */
         if (usrclip == 1)
         {
         /* IF user has provided a range, fix them as min & max in image */
         if (usrclip == 1)
         {
+            printinfo("user defined pixel range");
             for (i = 0; i < npixels; ++i)
             {
                 if (data[i] > datamax) data[i] = datamax;
             for (i = 0; i < npixels; ++i)
             {
                 if (data[i] > datamax) data[i] = datamax;
@@ -250,9 +252,7 @@ int main(int argc, char *argv[], char *envp[])
             } /*endfor*/
         }
 
             } /*endfor*/
         }
 
-        /* Allocate image buffer */
-        image_buffer = (unsigned char *) malloc(sizeof(char) * npixels);
-        scale_pixels(scale, npixels, data, image_buffer);
+        scale_pixels(scale, npixels, data, &image_buffer);
 
         /* Before we write jpeg, check if there is any requirement to negate
          * the image (usrnegt = 1)                                           */
 
         /* Before we write jpeg, check if there is any requirement to negate
          * the image (usrnegt = 1)                                           */
@@ -264,7 +264,11 @@ int main(int argc, char *argv[], char *envp[])
 
         xdim = naxes[0];
         ydim = naxes[1];
 
         xdim = naxes[0];
         ydim = naxes[1];
-        if (usrzoom == 1) resize_image(&xdim, &ydim, zoomfact, image_buffer);
+        if (usrzoom == 1)
+        {
+            printf("INFO   : Image zoom factor = %3.2f\n", zoomfact);
+            resize_image(&xdim, &ydim, zoomfact, &image_buffer);
+        }
 
         /*Write out data into JPEG file*/
         jpeg_file = fopen(jpeg_file_name, "wb");/* Open JPEG file for writing*/
 
         /*Write out data into JPEG file*/
         jpeg_file = fopen(jpeg_file_name, "wb");/* Open JPEG file for writing*/