diff --git a/src/image.c b/src/image.c
--- a/src/image.c
+++ b/src/image.c
/*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..
*---------------------------------------------------------------------------*/
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)
{
}
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;
}
}