cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % FFFFF IIIII TTTTT SSSSS % |
| 7 | % F I T SS % |
| 8 | % FFF I T SSS % |
| 9 | % F I T SS % |
| 10 | % F IIIII T SSSSS % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Flexible Image Transport System Images. % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/attribute.h" |
| 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/cache.h" |
| 47 | #include "MagickCore/color-private.h" |
| 48 | #include "MagickCore/colorspace.h" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 49 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 50 | #include "MagickCore/constitute.h" |
| 51 | #include "MagickCore/exception.h" |
| 52 | #include "MagickCore/exception-private.h" |
| 53 | #include "MagickCore/image.h" |
| 54 | #include "MagickCore/image-private.h" |
| 55 | #include "MagickCore/list.h" |
| 56 | #include "MagickCore/magick.h" |
| 57 | #include "MagickCore/memory_.h" |
| 58 | #include "MagickCore/module.h" |
| 59 | #include "MagickCore/monitor.h" |
| 60 | #include "MagickCore/monitor-private.h" |
| 61 | #include "MagickCore/pixel-accessor.h" |
| 62 | #include "MagickCore/property.h" |
| 63 | #include "MagickCore/quantum-private.h" |
| 64 | #include "MagickCore/static.h" |
| 65 | #include "MagickCore/statistic.h" |
| 66 | #include "MagickCore/string_.h" |
| 67 | #include "MagickCore/string-private.h" |
| 68 | #include "MagickCore/module.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | Forward declarations. |
| 72 | */ |
| 73 | #define FITSBlocksize 2880UL |
| 74 | |
| 75 | /* |
| 76 | Forward declarations. |
| 77 | */ |
| 78 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 79 | WriteFITSImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 83 | % % |
| 84 | % % |
| 85 | % % |
| 86 | % I s F I T S % |
| 87 | % % |
| 88 | % % |
| 89 | % % |
| 90 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 91 | % |
| 92 | % IsFITS() returns MagickTrue if the image format type, identified by the |
| 93 | % magick string, is FITS. |
| 94 | % |
| 95 | % The format of the IsFITS method is: |
| 96 | % |
| 97 | % MagickBooleanType IsFITS(const unsigned char *magick,const size_t length) |
| 98 | % |
| 99 | % A description of each parameter follows: |
| 100 | % |
| 101 | % o magick: compare image format pattern against these bytes. |
| 102 | % |
| 103 | % o length: Specifies the length of the magick string. |
| 104 | % |
| 105 | */ |
| 106 | static MagickBooleanType IsFITS(const unsigned char *magick,const size_t length) |
| 107 | { |
| 108 | if (length < 6) |
| 109 | return(MagickFalse); |
| 110 | if (LocaleNCompare((const char *) magick,"IT0",3) == 0) |
| 111 | return(MagickTrue); |
| 112 | if (LocaleNCompare((const char *) magick,"SIMPLE",6) == 0) |
| 113 | return(MagickTrue); |
| 114 | return(MagickFalse); |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 119 | % % |
| 120 | % % |
| 121 | % % |
| 122 | % R e a d F I T S I m a g e % |
| 123 | % % |
| 124 | % % |
| 125 | % % |
| 126 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 127 | % |
| 128 | % ReadFITSImage() reads a FITS image file and returns it. It allocates the |
| 129 | % memory necessary for the new Image structure and returns a pointer to the |
| 130 | % new image. |
| 131 | % |
| 132 | % The format of the ReadFITSImage method is: |
| 133 | % |
| 134 | % Image *ReadFITSImage(const ImageInfo *image_info, |
| 135 | % ExceptionInfo *exception) |
| 136 | % |
| 137 | % A description of each parameter follows: |
| 138 | % |
| 139 | % o image_info: the image info. |
| 140 | % |
| 141 | % o exception: return any errors or warnings in this structure. |
| 142 | % |
| 143 | */ |
| 144 | |
| 145 | static inline double GetFITSPixel(Image *image,int bits_per_pixel) |
| 146 | { |
| 147 | switch (image->depth >> 3) |
| 148 | { |
| 149 | case 1: |
| 150 | return((double) ReadBlobByte(image)); |
| 151 | case 2: |
| 152 | return((double) ((short) ReadBlobShort(image))); |
| 153 | case 4: |
| 154 | { |
| 155 | if (bits_per_pixel > 0) |
cristy | 6cff05d | 2010-09-02 11:22:46 +0000 | [diff] [blame] | 156 | return((double) ((int) ReadBlobLong(image))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 157 | return((double) ReadBlobFloat(image)); |
| 158 | } |
| 159 | case 8: |
| 160 | { |
| 161 | if (bits_per_pixel > 0) |
| 162 | return((double) ((MagickOffsetType) ReadBlobLongLong(image))); |
| 163 | } |
| 164 | default: |
| 165 | break; |
| 166 | } |
| 167 | return(ReadBlobDouble(image)); |
| 168 | } |
| 169 | |
cristy | 4d0ca34 | 2014-05-01 00:42:09 +0000 | [diff] [blame] | 170 | static MagickOffsetType GetFITSPixelExtrema(Image *image, |
| 171 | const int bits_per_pixel,double *minima,double *maxima) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 172 | { |
| 173 | double |
| 174 | pixel; |
| 175 | |
| 176 | MagickOffsetType |
| 177 | offset; |
| 178 | |
| 179 | MagickSizeType |
| 180 | number_pixels; |
| 181 | |
| 182 | register MagickOffsetType |
| 183 | i; |
| 184 | |
| 185 | offset=TellBlob(image); |
cristy | 4d0ca34 | 2014-05-01 00:42:09 +0000 | [diff] [blame] | 186 | if (offset == -1) |
| 187 | return(-1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 188 | number_pixels=(MagickSizeType) image->columns*image->rows; |
| 189 | *minima=GetFITSPixel(image,bits_per_pixel); |
| 190 | *maxima=(*minima); |
| 191 | for (i=1; i < (MagickOffsetType) number_pixels; i++) |
| 192 | { |
| 193 | pixel=GetFITSPixel(image,bits_per_pixel); |
| 194 | if (pixel < *minima) |
| 195 | *minima=pixel; |
| 196 | if (pixel > *maxima) |
| 197 | *maxima=pixel; |
| 198 | } |
cristy | 4d0ca34 | 2014-05-01 00:42:09 +0000 | [diff] [blame] | 199 | return(SeekBlob(image,offset,SEEK_SET)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 200 | } |
| 201 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 202 | static inline double GetFITSPixelRange(const size_t depth) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 203 | { |
| 204 | return((double) ((MagickOffsetType) GetQuantumRange(depth))); |
| 205 | } |
| 206 | |
| 207 | static void SetFITSUnsignedPixels(const size_t length, |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 208 | const size_t bits_per_pixel,const EndianType endian,unsigned char *pixels) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 209 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 210 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | i; |
| 212 | |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 213 | if (endian != MSBEndian) |
| 214 | pixels+=(bits_per_pixel >> 3)-1; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 215 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 216 | { |
| 217 | *pixels^=0x80; |
| 218 | pixels+=bits_per_pixel >> 3; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | static Image *ReadFITSImage(const ImageInfo *image_info, |
| 223 | ExceptionInfo *exception) |
| 224 | { |
| 225 | typedef struct _FITSInfo |
| 226 | { |
| 227 | MagickBooleanType |
| 228 | extend, |
| 229 | simple; |
| 230 | |
| 231 | int |
| 232 | bits_per_pixel, |
| 233 | columns, |
| 234 | rows, |
| 235 | number_axes, |
| 236 | number_planes; |
| 237 | |
| 238 | double |
| 239 | min_data, |
| 240 | max_data, |
| 241 | zero, |
| 242 | scale; |
| 243 | |
| 244 | EndianType |
| 245 | endian; |
| 246 | } FITSInfo; |
| 247 | |
| 248 | char |
| 249 | *comment, |
| 250 | keyword[9], |
| 251 | property[MaxTextExtent], |
| 252 | value[73]; |
| 253 | |
| 254 | double |
| 255 | pixel, |
| 256 | scale; |
| 257 | |
| 258 | FITSInfo |
| 259 | fits_info; |
| 260 | |
| 261 | Image |
| 262 | *image; |
| 263 | |
| 264 | int |
| 265 | c; |
| 266 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 267 | MagickBooleanType |
| 268 | status; |
| 269 | |
| 270 | MagickSizeType |
| 271 | number_pixels; |
| 272 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 273 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 274 | i, |
| 275 | x; |
| 276 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 277 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 278 | *q; |
| 279 | |
| 280 | ssize_t |
cristy | 202de44 | 2011-04-24 18:19:07 +0000 | [diff] [blame] | 281 | count, |
| 282 | scene, |
| 283 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 284 | |
| 285 | /* |
| 286 | Open image file. |
| 287 | */ |
| 288 | assert(image_info != (const ImageInfo *) NULL); |
| 289 | assert(image_info->signature == MagickSignature); |
| 290 | if (image_info->debug != MagickFalse) |
| 291 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 292 | image_info->filename); |
| 293 | assert(exception != (ExceptionInfo *) NULL); |
| 294 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 295 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 296 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 297 | if (status == MagickFalse) |
| 298 | { |
| 299 | image=DestroyImageList(image); |
| 300 | return((Image *) NULL); |
| 301 | } |
| 302 | /* |
| 303 | Initialize image header. |
| 304 | */ |
| 305 | (void) ResetMagickMemory(&fits_info,0,sizeof(fits_info)); |
| 306 | fits_info.extend=MagickFalse; |
| 307 | fits_info.simple=MagickFalse; |
| 308 | fits_info.bits_per_pixel=8; |
| 309 | fits_info.columns=1; |
| 310 | fits_info.rows=1; |
| 311 | fits_info.rows=1; |
| 312 | fits_info.number_planes=1; |
| 313 | fits_info.min_data=0.0; |
| 314 | fits_info.max_data=0.0; |
| 315 | fits_info.zero=0.0; |
| 316 | fits_info.scale=1.0; |
| 317 | fits_info.endian=MSBEndian; |
| 318 | /* |
| 319 | Decode image header. |
| 320 | */ |
| 321 | for (comment=(char *) NULL; EOFBlob(image) == MagickFalse; ) |
| 322 | { |
| 323 | for ( ; EOFBlob(image) == MagickFalse; ) |
| 324 | { |
| 325 | register char |
| 326 | *p; |
| 327 | |
| 328 | count=ReadBlob(image,8,(unsigned char *) keyword); |
| 329 | if (count != 8) |
| 330 | break; |
| 331 | for (i=0; i < 8; i++) |
| 332 | { |
| 333 | if (isspace((int) ((unsigned char) keyword[i])) != 0) |
| 334 | break; |
cristy | 466802f | 2010-02-24 14:18:37 +0000 | [diff] [blame] | 335 | keyword[i]=tolower((int) ((unsigned char) keyword[i])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 336 | } |
| 337 | keyword[i]='\0'; |
| 338 | count=ReadBlob(image,72,(unsigned char *) value); |
cristy | e3216eb | 2014-04-18 17:10:21 +0000 | [diff] [blame] | 339 | value[72]='\0'; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 340 | if (count != 72) |
| 341 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 342 | p=value; |
| 343 | if (*p == '=') |
| 344 | { |
| 345 | p+=2; |
| 346 | while (isspace((int) ((unsigned char) *p)) != 0) |
| 347 | p++; |
| 348 | } |
| 349 | if (LocaleCompare(keyword,"end") == 0) |
| 350 | break; |
| 351 | if (LocaleCompare(keyword,"extend") == 0) |
| 352 | fits_info.extend=(*p == 'T') || (*p == 't') ? MagickTrue : MagickFalse; |
| 353 | if (LocaleCompare(keyword,"simple") == 0) |
| 354 | fits_info.simple=(*p == 'T') || (*p == 't') ? MagickTrue : MagickFalse; |
| 355 | if (LocaleCompare(keyword,"bitpix") == 0) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 356 | fits_info.bits_per_pixel=StringToLong(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 357 | if (LocaleCompare(keyword,"naxis") == 0) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 358 | fits_info.number_axes=StringToLong(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 359 | if (LocaleCompare(keyword,"naxis1") == 0) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 360 | fits_info.columns=StringToLong(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 361 | if (LocaleCompare(keyword,"naxis2") == 0) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 362 | fits_info.rows=StringToLong(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 363 | if (LocaleCompare(keyword,"naxis3") == 0) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 364 | fits_info.number_planes=StringToLong(p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 365 | if (LocaleCompare(keyword,"datamax") == 0) |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 366 | fits_info.max_data=StringToDouble(p,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 367 | if (LocaleCompare(keyword,"datamin") == 0) |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 368 | fits_info.min_data=StringToDouble(p,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 369 | if (LocaleCompare(keyword,"bzero") == 0) |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 370 | fits_info.zero=StringToDouble(p,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 371 | if (LocaleCompare(keyword,"bscale") == 0) |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 372 | fits_info.scale=StringToDouble(p,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 373 | if (LocaleCompare(keyword,"comment") == 0) |
| 374 | { |
| 375 | if (comment == (char *) NULL) |
| 376 | comment=ConstantString(p); |
| 377 | else |
| 378 | (void) ConcatenateString(&comment,p); |
| 379 | } |
| 380 | if (LocaleCompare(keyword,"xendian") == 0) |
| 381 | { |
| 382 | if (LocaleNCompare(p,"big",3) == 0) |
| 383 | fits_info.endian=MSBEndian; |
| 384 | else |
| 385 | fits_info.endian=LSBEndian; |
| 386 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 387 | (void) FormatLocaleString(property,MaxTextExtent,"fits:%s",keyword); |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 388 | (void) SetImageProperty(image,property,p,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 389 | } |
| 390 | c=0; |
| 391 | while (((TellBlob(image) % FITSBlocksize) != 0) && (c != EOF)) |
| 392 | c=ReadBlobByte(image); |
| 393 | if (fits_info.extend == MagickFalse) |
| 394 | break; |
cristy | 11dc2b8 | 2015-01-25 00:11:48 +0000 | [diff] [blame^] | 395 | if ((fits_info.bits_per_pixel != 8) && (fits_info.bits_per_pixel != 16) && |
| 396 | (fits_info.bits_per_pixel != 32) && (fits_info.bits_per_pixel != 64) && |
| 397 | (fits_info.bits_per_pixel != -32) && (fits_info.bits_per_pixel != -64)) |
| 398 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 399 | number_pixels=(MagickSizeType) fits_info.columns*fits_info.rows; |
| 400 | if ((fits_info.simple != MagickFalse) && (fits_info.number_axes >= 1) && |
| 401 | (fits_info.number_axes <= 4) && (number_pixels != 0)) |
| 402 | break; |
| 403 | } |
| 404 | /* |
| 405 | Verify that required image information is defined. |
| 406 | */ |
| 407 | if (comment != (char *) NULL) |
| 408 | { |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 409 | (void) SetImageProperty(image,"comment",comment,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 410 | comment=DestroyString(comment); |
| 411 | } |
| 412 | if (EOFBlob(image) != MagickFalse) |
| 413 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 414 | image->filename); |
| 415 | number_pixels=(MagickSizeType) fits_info.columns*fits_info.rows; |
| 416 | if ((fits_info.simple == MagickFalse) || (fits_info.number_axes < 1) || |
| 417 | (fits_info.number_axes > 4) || (number_pixels == 0)) |
| 418 | ThrowReaderException(CorruptImageError,"ImageTypeNotSupported"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 419 | for (scene=0; scene < (ssize_t) fits_info.number_planes; scene++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 420 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 421 | image->columns=(size_t) fits_info.columns; |
| 422 | image->rows=(size_t) fits_info.rows; |
| 423 | image->depth=(size_t) (fits_info.bits_per_pixel < 0 ? -1 : 1)* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 424 | fits_info.bits_per_pixel; |
| 425 | image->endian=fits_info.endian; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 426 | image->scene=(size_t) scene; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 427 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 428 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 429 | break; |
cristy | acabb84 | 2014-12-14 23:36:33 +0000 | [diff] [blame] | 430 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 431 | if (status == MagickFalse) |
| 432 | return(DestroyImageList(image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 433 | /* |
| 434 | Initialize image structure. |
| 435 | */ |
cristy | d8b3981 | 2013-02-02 02:12:57 +0000 | [diff] [blame] | 436 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
| 437 | if ((fits_info.min_data == 0.0) && (fits_info.max_data == 0.0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 438 | { |
cristy | 3f6782c | 2013-02-06 01:33:50 +0000 | [diff] [blame] | 439 | if (fits_info.zero == 0.0) |
cristy | 4d0ca34 | 2014-05-01 00:42:09 +0000 | [diff] [blame] | 440 | (void) GetFITSPixelExtrema(image,fits_info.bits_per_pixel, |
cristy | d8b3981 | 2013-02-02 02:12:57 +0000 | [diff] [blame] | 441 | &fits_info.min_data,&fits_info.max_data); |
| 442 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 443 | fits_info.max_data=GetFITSPixelRange((size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 444 | fits_info.bits_per_pixel); |
| 445 | } |
| 446 | else |
cristy | d8b3981 | 2013-02-02 02:12:57 +0000 | [diff] [blame] | 447 | fits_info.max_data=GetFITSPixelRange((size_t) fits_info.bits_per_pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 448 | /* |
| 449 | Convert FITS pixels to pixel packets. |
| 450 | */ |
cristy | d8b3981 | 2013-02-02 02:12:57 +0000 | [diff] [blame] | 451 | scale=QuantumRange/(fits_info.max_data-fits_info.min_data); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 452 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 453 | { |
| 454 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 455 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 456 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 457 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 458 | { |
| 459 | pixel=GetFITSPixel(image,fits_info.bits_per_pixel); |
cristy | 163d678 | 2013-01-26 13:54:54 +0000 | [diff] [blame] | 460 | if ((image->depth == 16) || (image->depth == 32) || |
cristy | 9dcadc5 | 2013-01-26 13:53:22 +0000 | [diff] [blame] | 461 | (image->depth == 64)) |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 462 | SetFITSUnsignedPixels(1,image->depth,image->endian, |
| 463 | (unsigned char *) &pixel); |
cristy | 1214288 | 2012-06-17 00:52:29 +0000 | [diff] [blame] | 464 | SetPixelGray(image,ClampToQuantum(scale*(fits_info.scale*(pixel- |
| 465 | fits_info.min_data)+fits_info.zero)),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 466 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 467 | } |
| 468 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 469 | break; |
| 470 | if (image->previous == (Image *) NULL) |
| 471 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 472 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 473 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 474 | if (status == MagickFalse) |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | if (EOFBlob(image) != MagickFalse) |
| 479 | { |
| 480 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 481 | image->filename); |
| 482 | break; |
| 483 | } |
| 484 | /* |
| 485 | Proceed to next image. |
| 486 | */ |
| 487 | if (image_info->number_scenes != 0) |
| 488 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 489 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 490 | if (scene < (ssize_t) (fits_info.number_planes-1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 491 | { |
| 492 | /* |
| 493 | Allocate next image structure. |
| 494 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 495 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 496 | if (GetNextImageInList(image) == (Image *) NULL) |
| 497 | { |
| 498 | image=DestroyImageList(image); |
| 499 | return((Image *) NULL); |
| 500 | } |
| 501 | image=SyncNextImageInList(image); |
| 502 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 503 | GetBlobSize(image)); |
| 504 | if (status == MagickFalse) |
| 505 | break; |
| 506 | } |
| 507 | } |
| 508 | (void) CloseBlob(image); |
| 509 | return(GetFirstImageInList(image)); |
| 510 | } |
| 511 | |
| 512 | /* |
| 513 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 514 | % % |
| 515 | % % |
| 516 | % % |
| 517 | % R e g i s t e r F I T S I m a g e % |
| 518 | % % |
| 519 | % % |
| 520 | % % |
| 521 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 522 | % |
| 523 | % RegisterFITSImage() adds attributes for the FITS image format to |
| 524 | % the list of supported formats. The attributes include the image format |
| 525 | % tag, a method to read and/or write the format, whether the format |
| 526 | % supports the saving of more than one frame to the same file or blob, |
| 527 | % whether the format supports native in-memory I/O, and a brief |
| 528 | % description of the format. |
| 529 | % |
| 530 | % The format of the RegisterFITSImage method is: |
| 531 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 532 | % size_t RegisterFITSImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 533 | % |
| 534 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 535 | ModuleExport size_t RegisterFITSImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 536 | { |
| 537 | MagickInfo |
| 538 | *entry; |
| 539 | |
| 540 | entry=SetMagickInfo("FITS"); |
| 541 | entry->decoder=(DecodeImageHandler *) ReadFITSImage; |
| 542 | entry->encoder=(EncodeImageHandler *) WriteFITSImage; |
| 543 | entry->magick=(IsImageFormatHandler *) IsFITS; |
| 544 | entry->adjoin=MagickFalse; |
| 545 | entry->seekable_stream=MagickTrue; |
| 546 | entry->description=ConstantString("Flexible Image Transport System"); |
| 547 | entry->module=ConstantString("FITS"); |
| 548 | (void) RegisterMagickInfo(entry); |
| 549 | entry=SetMagickInfo("FTS"); |
| 550 | entry->decoder=(DecodeImageHandler *) ReadFITSImage; |
| 551 | entry->encoder=(EncodeImageHandler *) WriteFITSImage; |
| 552 | entry->magick=(IsImageFormatHandler *) IsFITS; |
| 553 | entry->adjoin=MagickFalse; |
| 554 | entry->seekable_stream=MagickTrue; |
| 555 | entry->description=ConstantString("Flexible Image Transport System"); |
| 556 | entry->module=ConstantString("FTS"); |
| 557 | (void) RegisterMagickInfo(entry); |
| 558 | return(MagickImageCoderSignature); |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 563 | % % |
| 564 | % % |
| 565 | % % |
| 566 | % U n r e g i s t e r F I T S I m a g e % |
| 567 | % % |
| 568 | % % |
| 569 | % % |
| 570 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 571 | % |
| 572 | % UnregisterFITSImage() removes format registrations made by the |
| 573 | % FITS module from the list of supported formats. |
| 574 | % |
| 575 | % The format of the UnregisterFITSImage method is: |
| 576 | % |
| 577 | % UnregisterFITSImage(void) |
| 578 | % |
| 579 | */ |
| 580 | ModuleExport void UnregisterFITSImage(void) |
| 581 | { |
| 582 | (void) UnregisterMagickInfo("FITS"); |
| 583 | (void) UnregisterMagickInfo("FTS"); |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 588 | % % |
| 589 | % % |
| 590 | % % |
| 591 | % W r i t e F I T S I m a g e % |
| 592 | % % |
| 593 | % % |
| 594 | % % |
| 595 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 596 | % |
| 597 | % WriteFITSImage() writes a Flexible Image Transport System image to a |
| 598 | % file as gray scale intensities [0..255]. |
| 599 | % |
| 600 | % The format of the WriteFITSImage method is: |
| 601 | % |
| 602 | % MagickBooleanType WriteFITSImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 603 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 604 | % |
| 605 | % A description of each parameter follows. |
| 606 | % |
| 607 | % o image_info: the image info. |
| 608 | % |
| 609 | % o image: The image. |
| 610 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 611 | % o exception: return any errors or warnings in this structure. |
| 612 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 613 | */ |
| 614 | static MagickBooleanType WriteFITSImage(const ImageInfo *image_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 615 | Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 616 | { |
| 617 | char |
| 618 | header[FITSBlocksize], |
| 619 | *fits_info; |
| 620 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 621 | MagickBooleanType |
| 622 | status; |
| 623 | |
| 624 | QuantumInfo |
| 625 | *quantum_info; |
| 626 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 627 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 628 | *p; |
| 629 | |
| 630 | size_t |
| 631 | length; |
| 632 | |
| 633 | ssize_t |
| 634 | count, |
cristy | 2692d59 | 2010-11-01 18:07:27 +0000 | [diff] [blame] | 635 | offset, |
| 636 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 637 | |
| 638 | unsigned char |
| 639 | *pixels; |
| 640 | |
| 641 | /* |
| 642 | Open output image file. |
| 643 | */ |
| 644 | assert(image_info != (const ImageInfo *) NULL); |
| 645 | assert(image_info->signature == MagickSignature); |
| 646 | assert(image != (Image *) NULL); |
| 647 | assert(image->signature == MagickSignature); |
| 648 | if (image->debug != MagickFalse) |
| 649 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 650 | assert(exception != (ExceptionInfo *) NULL); |
| 651 | assert(exception->signature == MagickSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 652 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 653 | if (status == MagickFalse) |
| 654 | return(status); |
cristy | af8d391 | 2014-02-21 14:50:33 +0000 | [diff] [blame] | 655 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 656 | /* |
| 657 | Allocate image memory. |
| 658 | */ |
| 659 | fits_info=(char *) AcquireQuantumMemory(FITSBlocksize,sizeof(*fits_info)); |
| 660 | if (fits_info == (char *) NULL) |
| 661 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 662 | (void) ResetMagickMemory(fits_info,' ',FITSBlocksize*sizeof(*fits_info)); |
| 663 | /* |
| 664 | Initialize image header. |
| 665 | */ |
| 666 | image->depth=GetImageQuantumDepth(image,MagickFalse); |
cristy | 6ea44a9 | 2013-02-03 23:40:10 +0000 | [diff] [blame] | 667 | image->endian=MSBEndian; |
cristy | 5f766ef | 2014-12-14 21:12:47 +0000 | [diff] [blame] | 668 | quantum_info=AcquireQuantumInfo(image_info,image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 669 | if (quantum_info == (QuantumInfo *) NULL) |
| 670 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 671 | offset=0; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 672 | (void) FormatLocaleString(header,FITSBlocksize, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 673 | "SIMPLE = T"); |
| 674 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 675 | offset+=80; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 676 | (void) FormatLocaleString(header,FITSBlocksize,"BITPIX = %10ld", |
cristy | 67e3eab | 2014-06-17 00:25:27 +0000 | [diff] [blame] | 677 | (long) ((quantum_info->format == FloatingPointQuantumFormat ? -1 : 1)* |
| 678 | image->depth)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 679 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 680 | offset+=80; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 681 | (void) FormatLocaleString(header,FITSBlocksize,"NAXIS = %10lu", |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 682 | IsImageGray(image,exception) != MagickFalse ? 2UL : 3UL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 683 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 684 | offset+=80; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 685 | (void) FormatLocaleString(header,FITSBlocksize,"NAXIS1 = %10lu", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 686 | (unsigned long) image->columns); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 687 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 688 | offset+=80; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 689 | (void) FormatLocaleString(header,FITSBlocksize,"NAXIS2 = %10lu", |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 690 | (unsigned long) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 691 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 692 | offset+=80; |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 693 | if (IsImageGray(image,exception) == MagickFalse) |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 694 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 695 | (void) FormatLocaleString(header,FITSBlocksize, |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 696 | "NAXIS3 = %10lu",3UL); |
| 697 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 698 | offset+=80; |
| 699 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 700 | (void) FormatLocaleString(header,FITSBlocksize,"BSCALE = %E",1.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 701 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 702 | offset+=80; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 703 | (void) FormatLocaleString(header,FITSBlocksize,"BZERO = %E", |
cristy | 3ec9e8d | 2013-01-30 16:29:51 +0000 | [diff] [blame] | 704 | image->depth > 8 ? GetFITSPixelRange(image->depth)/2.0 : 0.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 705 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 706 | offset+=80; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 707 | (void) FormatLocaleString(header,FITSBlocksize,"DATAMAX = %E", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 708 | 1.0*((MagickOffsetType) GetQuantumRange(image->depth))); |
| 709 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 710 | offset+=80; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 711 | (void) FormatLocaleString(header,FITSBlocksize,"DATAMIN = %E",0.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 712 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 713 | offset+=80; |
| 714 | if (image->endian == LSBEndian) |
| 715 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 716 | (void) FormatLocaleString(header,FITSBlocksize,"XENDIAN = 'SMALL'"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 717 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 718 | offset+=80; |
| 719 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 720 | (void) FormatLocaleString(header,FITSBlocksize,"HISTORY %.72s", |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 721 | GetMagickVersion((size_t *) NULL)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 722 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 723 | offset+=80; |
| 724 | (void) strncpy(header,"END",FITSBlocksize); |
| 725 | (void) strncpy(fits_info+offset,header,strlen(header)); |
| 726 | offset+=80; |
| 727 | (void) WriteBlob(image,FITSBlocksize,(unsigned char *) fits_info); |
| 728 | /* |
| 729 | Convert image to fits scale PseudoColor class. |
| 730 | */ |
| 731 | pixels=GetQuantumPixels(quantum_info); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 732 | if (IsImageGray(image,exception) != MagickFalse) |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 733 | { |
| 734 | length=GetQuantumExtent(image,quantum_info,GrayQuantum); |
| 735 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
| 736 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 737 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 738 | if (p == (const Quantum *) NULL) |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 739 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 740 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 741 | GrayQuantum,pixels,exception); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 742 | if (image->depth == 16) |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 743 | SetFITSUnsignedPixels(image->columns,image->depth,image->endian, |
| 744 | pixels); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 745 | if (((image->depth == 32) || (image->depth == 64)) && |
| 746 | (quantum_info->format != FloatingPointQuantumFormat)) |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 747 | SetFITSUnsignedPixels(image->columns,image->depth,image->endian, |
| 748 | pixels); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 749 | count=WriteBlob(image,length,pixels); |
| 750 | if (count != (ssize_t) length) |
| 751 | break; |
| 752 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 753 | image->rows); |
| 754 | if (status == MagickFalse) |
| 755 | break; |
| 756 | } |
| 757 | } |
| 758 | else |
| 759 | { |
| 760 | length=GetQuantumExtent(image,quantum_info,RedQuantum); |
| 761 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
| 762 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 763 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 764 | if (p == (const Quantum *) NULL) |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 765 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 766 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 767 | RedQuantum,pixels,exception); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 768 | if (image->depth == 16) |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 769 | SetFITSUnsignedPixels(image->columns,image->depth,image->endian, |
| 770 | pixels); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 771 | if (((image->depth == 32) || (image->depth == 64)) && |
| 772 | (quantum_info->format != FloatingPointQuantumFormat)) |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 773 | SetFITSUnsignedPixels(image->columns,image->depth,image->endian, |
| 774 | pixels); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 775 | count=WriteBlob(image,length,pixels); |
| 776 | if (count != (ssize_t) length) |
| 777 | break; |
| 778 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 779 | image->rows); |
| 780 | if (status == MagickFalse) |
| 781 | break; |
| 782 | } |
| 783 | length=GetQuantumExtent(image,quantum_info,GreenQuantum); |
| 784 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
| 785 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 786 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 787 | if (p == (const Quantum *) NULL) |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 788 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 789 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 790 | GreenQuantum,pixels,exception); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 791 | if (image->depth == 16) |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 792 | SetFITSUnsignedPixels(image->columns,image->depth,image->endian, |
| 793 | pixels); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 794 | if (((image->depth == 32) || (image->depth == 64)) && |
| 795 | (quantum_info->format != FloatingPointQuantumFormat)) |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 796 | SetFITSUnsignedPixels(image->columns,image->depth,image->endian, |
| 797 | pixels); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 798 | count=WriteBlob(image,length,pixels); |
| 799 | if (count != (ssize_t) length) |
| 800 | break; |
| 801 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 802 | image->rows); |
| 803 | if (status == MagickFalse) |
| 804 | break; |
| 805 | } |
| 806 | length=GetQuantumExtent(image,quantum_info,BlueQuantum); |
| 807 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
| 808 | { |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 809 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 810 | if (p == (const Quantum *) NULL) |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 811 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 812 | length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 813 | BlueQuantum,pixels,exception); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 814 | if (image->depth == 16) |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 815 | SetFITSUnsignedPixels(image->columns,image->depth,image->endian, |
| 816 | pixels); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 817 | if (((image->depth == 32) || (image->depth == 64)) && |
| 818 | (quantum_info->format != FloatingPointQuantumFormat)) |
cristy | f84dc8e | 2013-02-02 16:46:26 +0000 | [diff] [blame] | 819 | SetFITSUnsignedPixels(image->columns,image->depth,image->endian, |
| 820 | pixels); |
cristy | fcbcae8 | 2011-04-22 12:53:27 +0000 | [diff] [blame] | 821 | count=WriteBlob(image,length,pixels); |
| 822 | if (count != (ssize_t) length) |
| 823 | break; |
| 824 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 825 | image->rows); |
| 826 | if (status == MagickFalse) |
| 827 | break; |
| 828 | } |
| 829 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 830 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 831 | length=(size_t) (FITSBlocksize-TellBlob(image) % FITSBlocksize); |
| 832 | if (length != 0) |
| 833 | { |
| 834 | (void) ResetMagickMemory(fits_info,0,length*sizeof(*fits_info)); |
| 835 | (void) WriteBlob(image,length,(unsigned char *) fits_info); |
| 836 | } |
| 837 | fits_info=DestroyString(fits_info); |
| 838 | (void) CloseBlob(image); |
| 839 | return(MagickTrue); |
| 840 | } |