diff --git a/src/fits2jpeg.c b/src/fits2jpeg.c
--- a/src/fits2jpeg.c
+++ b/src/fits2jpeg.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
- 3. Image resizing options
*---------------------------------------------------------------------------*/
#include "fits2jpeg.h"
{
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;
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;
sptr = strtok(tmpstr, ":");
datamin = atof(sptr);
}
- printinfo("User defined pixel range");
/* Remember.. now we have user specified range */
usrclip = 1;
/* 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;
/* 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,
/* 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;
} /*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) */
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*/