1 #include "loader_common.h"
4 #define SWAP32(x) (x) = \
5 ((((x) & 0x000000ff ) << 24) |\
6 (((x) & 0x0000ff00 ) << 8) |\
7 (((x) & 0x00ff0000 ) >> 8) |\
8 (((x) & 0xff000000 ) >> 24))
11 load(ImlibImage * im, ImlibProgressFunction progress,
12 char progress_granularity, char immediate_load)
14 int w = 0, h = 0, alpha = 0;
21 //f = fopen(im->real_file, "rb");
22 if ( fits_open_file( &f, im->real_file, READONLY, &status) )
33 //char buf[256], buf2[256];
35 /* read the NAXIS1 and NAXIS2 keyword to get image size */
36 if ( fits_read_keys_lng( f, "NAXIS", 1, 2, naxes, &nfound, &status ) ){
37 fits_close_file(f, &status);
45 if (!fgets(buf, 255, f))
51 sscanf(buf, "%s %i %i %i", buf2, &w, &h, &alpha);
52 if (strcmp(buf2, "ARGB"))
58 if (!IMAGE_DIMENSIONS_OK(w, h))
60 fits_close_file(f, &status);
69 SET_FLAG(im->flags, F_HAS_ALPHA);
71 UNSET_FLAG(im->flags, F_HAS_ALPHA);
72 im->format = strdup("fits");
75 if (((!im->data) && (im->loader)) || (immediate_load) || (progress))
81 float *buffer, datamin, datamax, nullval = 0;
85 //gray = ceil(floatvalue * 256)
86 //*ptr = ( ( ( ( (0xff << 8) | gray) << 8) | gray) << 8) | gray
88 /* must set the im->data member before callign progress function */
89 ptr = im->data = malloc(w * h * sizeof(DATA32));
91 buffer = malloc( nbuffer * sizeof( float ) );
95 fits_close_file(f, &status);
101 for (y = 0; y < h; y++)
103 //fread(ptr, im->w, 4, f);
104 fits_read_img( f, TFLOAT, fpixel, nbuffer, &nullval,
105 buffer, &anynull, &status);
106 for( x = 0; x < w; x++ ){
107 if( buffer[ x ] > datamax )
108 datamax = buffer[ x ];
109 if( buffer[ x ] < datamin )
110 datamin = buffer[ x ];
113 for( x = 0; x < w; x++ ){
114 gray = ceil( ( buffer[ x ] - datamin ) / ( datamax - datamin ) * 256 );
115 *ptr = ( ( ( ( (0xff << 8) | gray) << 8) | gray) << 8) | gray ;
128 per = (char)((100 * y) / im->h);
129 if (((per - pper) >= progress_granularity) ||
133 if (!progress(im, per, 0, (y - l), im->w, l))
135 fits_close_file(f, &status);
146 fits_close_file(f, &status);
151 save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
155 int y, pl = 0, alpha = 0;
159 /* no image data? abort */
162 f = fopen(im->real_file, "wb");
165 if (im->flags & F_HAS_ALPHA)
167 fprintf(f, "ARGB %i %i %i\n", im->w, im->h, alpha);
169 for (y = 0; y < im->h; y++)
171 fwrite(ptr, im->w, 4, f);
178 per = (char)((100 * y) / im->h);
179 if (((per - pper) >= progress_granularity) || (y == (im->h - 1)))
182 if (!progress(im, per, 0, (y - l), im->w, l))
198 formats(ImlibLoader * l)
200 char *list_formats[] = { "fits", "fts", "fit" };
205 l->num_formats = (sizeof(list_formats) / sizeof(char *));
206 l->formats = malloc(sizeof(char *) * l->num_formats);
207 for (i = 0; i < l->num_formats; i++)
208 l->formats[i] = strdup(list_formats[i]);