X-Git-Url: https://cads.iiap.res.in/gitview/?p=fits2jpeg.git;a=blobdiff_plain;f=src%2Ffits2jpeg.c;fp=src%2Ffits2jpeg.c;h=cc97e082fdaf86914956d97400bec9431cf7ad82;hp=60420e2ff4b747eab5de0a89acaf84f7fa88cd3c;hb=c217f20a424f31d11946263980a8f14ca7a79a0e;hpb=60d065b23a2bdd48da5b8ef3ce591b7b0313c979 diff --git a/src/fits2jpeg.c b/src/fits2jpeg.c index 60420e2..cc97e08 100644 --- a/src/fits2jpeg.c +++ b/src/fits2jpeg.c @@ -77,11 +77,10 @@ 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" @@ -94,7 +93,7 @@ int main(int argc, char *argv[], char *envp[]) { 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; @@ -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 + printwarn(strcat(optarg, " -- Unrecognized option")); scale = 0; break; @@ -165,7 +165,6 @@ int main(int argc, char *argv[], char *envp[]) sptr = strtok(tmpstr, ":"); datamin = atof(sptr); } - printinfo("User defined pixel range"); /* 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); - 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; @@ -225,7 +226,7 @@ int main(int argc, char *argv[], char *envp[]) /* 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, @@ -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) { + printinfo("user defined pixel range"); 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*/ } - /* 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) */ @@ -264,7 +264,11 @@ int main(int argc, char *argv[], char *envp[]) 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*/