X-Git-Url: https://cads.iiap.res.in/gitview/?p=fits2jpeg.git;a=blobdiff_plain;f=src%2Fimage.c;fp=src%2Fimage.c;h=6c48d6754c59c4a847efa4c7b26c3e09ef9ca44c;hp=f5f6c466394fac6ab4a855ae576497964b7a7083;hb=2ca6f2c81fda4aaafc2f754241b103370241ff05;hpb=c217f20a424f31d11946263980a8f14ca7a79a0e diff --git a/src/image.c b/src/image.c index f5f6c46..6c48d67 100644 --- a/src/image.c +++ b/src/image.c @@ -24,6 +24,34 @@ /*Header Definitions*/ #include "fits2jpeg.h" +void read_fits(char * fits_file_name, long * xdim, long * ydim, float ** data) +{ + fitsfile *fptr; + int status = 0, nfound, anynull; + long naxes[2]; + long npixels; + float nullval = 0.0; + + fits_open_file(&fptr, fits_file_name, READONLY, &status); + fits_read_keys_lng(fptr, "NAXIS", 1, 2, naxes, &nfound, &status); + if (status) + printerro(strcat(fits_file_name, " <-- Failed to open the file")); + + /* Read in data */ + npixels = naxes[0] * naxes[1]; + (*data) = malloc(sizeof(float) * npixels); + + nullval = 0; + if (fits_read_img(fptr, TFLOAT, 1, npixels, &nullval, (*data), &anynull, + &status)) + printerro(strcat(fits_file_name, " has no valid fits image data")); + + *xdim = naxes[0]; + *ydim = naxes[1]; + + fits_close_file(fptr, &status); +} + /*---------------------------------------------------------------------------* * SCALE_PIXELS: Changes the pixel scale to linear/log/sqroot/etc.. *---------------------------------------------------------------------------*/ @@ -89,39 +117,32 @@ void scale_pixels(int scale, unsigned int npixels, float *data, switch (scale) { case 1 : /* Square root */ - printinfo("Using square-root scale"); scl_data = sqrt((float)JMAXVAL)/(float)JMAXVAL; for (i = 0; i < npixels; ++i) (*image_buffer)[i] = (int)(sqrt(data[i])/scl_data); break; case 2 : /* Square */ - printinfo("Using quadratic scale"); scl_data = pow((float)JMAXVAL,2)/(float)JMAXVAL; for (i = 0; i < npixels; ++i) (*image_buffer)[i] = (int)abs((pow(data[i],2) - 1.0)/scl_data); break; case 3 : /* Cubic */ - printinfo("Using cubic scale"); scl_data = pow((float)JMAXVAL,3)/(float)JMAXVAL; for (i = 0; i < npixels; ++i) (*image_buffer)[i] = (int)abs((pow(data[i],3) - 1.0)/scl_data); break; case 4 : /* log */ - printinfo("Using log scale"); scl_data = log(1.0 + (float)JMAXVAL)/(float)JMAXVAL; for (i = 0; i < npixels; ++i) (*image_buffer)[i] = (int)((log(abs(data[i]) + 1.0))/scl_data); break; - case 5 : - /* contrast stretch */ - printinfo("Performing histogram stretch (normalization)"); - + case 5 : /* contrast stretch */ /* We need to go through the cumulative histogram to pick the - * appropriate values for datamin and datamax */ + * appropriate values for datamin and datamax */ i = 0; while (i < JMAXVAL) { @@ -155,14 +176,11 @@ void scale_pixels(int scale, unsigned int npixels, float *data, } break; - case 6 : - /* histogram equalization */ - printinfo("Performing Histogram Equalization"); + case 6 : /* histogram equalization */ for (i = 0; i < npixels; ++i) (*image_buffer)[i] = cumhist[(*image_buffer)[i]] * JMAXVAL; break; default : - printinfo("Using linear scale"); break; } }