~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/fits/fitsrw.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
/******************************************************************************/
57
57
 
58
58
#define                                    VERSIO  0.11
59
 
/* Identifikation:    "@(#) <product>              <ver> <dd-mmm-yy>" */
60
 
static char ident[] = "@(#) libfits.c              0.11  20-Dec-97  (%I%)";
61
59
 
62
60
/******************************************************************************/
63
61
/* FITS reading/writing library                                               */
86
84
 
87
85
#include "config.h"
88
86
 
89
 
#include <stdio.h>
90
87
#include <stdlib.h>
91
88
#include <string.h>
92
 
#ifdef HAVE_UNISTD_H
93
 
#include <unistd.h>
94
 
#endif
 
89
 
 
90
#include <glib/gstdio.h>
95
91
 
96
92
#include "fitsrw.h"
97
93
 
350
346
 return (   ((k >= 0x7f7fffff) && (k <= 0x7fffffff))
351
347
         || ((k >= 0x00000001) && (k <= 0x00800000)));
352
348
}
353
 
     
 
349
 
354
350
 
355
351
/*****************************************************************************/
356
352
/* #BEG-PAR                                                                  */
519
515
 if ((!reading) && (!writing))
520
516
   FITS_RETURN ("fits_open: Invalid openmode", NULL);
521
517
 
522
 
 fp = fopen (filename, reading ? "rb" : "wb");
 
518
 fp = g_fopen (filename, reading ? "rb" : "wb");
523
519
 if (fp == NULL) FITS_RETURN ("fits_open: fopen() failed", NULL);
524
520
 
525
521
 ff = fits_new_filestruct ();
560
556
   if (hdulist->used.blank_value) ff->blank_used = 1;
561
557
   if (hdulist->used.nan_value) ff->nan_used = 1;
562
558
 
563
 
   if (n_hdr == 0)   
 
559
   if (n_hdr == 0)
564
560
     ff->hdu_list = hdulist;
565
561
   else
566
562
     last_hdulist->next_hdu = hdulist;
572
568
   if (fseek (fp, hdulist->data_offset+hdulist->data_size, SEEK_SET) < 0)
573
569
     break;
574
570
 }
575
 
 
 
571
 
576
572
 return (ff);
577
573
}
578
574
 
956
952
/*                                                                           */
957
953
/* #END-PAR                                                                  */
958
954
/*****************************************************************************/
959
 
 
 
955
 
960
956
static FITS_HDU_LIST *fits_decode_header (FITS_RECORD_LIST *hdr,
961
957
                        long hdr_offset, long dat_offset)
962
958
 
1101
1097
                    || (   (hdulist->bitpix == -32)
1102
1098
                        && (   fits_ieee32_intel || fits_ieee32_motorola
1103
1099
                            || fits_ieee64_intel || fits_ieee64_motorola));
1104
 
   
 
1100
 
1105
1101
 if (bitpix_supported)
1106
1102
 {
1107
1103
   if (hdulist->used.simple)
1165
1161
static int fits_eval_pixrange (FILE *fp, FITS_HDU_LIST *hdu)
1166
1162
 
1167
1163
{register int maxelem;
1168
 
#define FITSNPIX 4096 
 
1164
#define FITSNPIX 4096
1169
1165
 unsigned char pixdat[FITSNPIX];
1170
1166
 int nelem, bpp;
1171
1167
 int blank_found = 0, nan_found = 0;
1172
 
   
 
1168
 
1173
1169
 if (fseek (fp, hdu->data_offset, SEEK_SET) < 0)
1174
1170
   FITS_RETURN ("fits_eval_pixrange: cant position file", -1);
1175
1171
 
1191
1187
       nelem -= maxelem;
1192
1188
       if (fread ((char *)pixdat, bpp, maxelem, fp) != maxelem)
1193
1189
         FITS_RETURN ("fits_eval_pixrange: error on read bitpix 8 data", -1);
1194
 
  
 
1190
 
1195
1191
       ptr = pixdat;
1196
1192
       if (hdu->used.blank)
1197
1193
       {
1233
1229
       nelem -= maxelem;
1234
1230
       if (fread ((char *)pixdat, bpp, maxelem, fp) != maxelem)
1235
1231
         FITS_RETURN ("fits_eval_pixrange: error on read bitpix 16 data", -1);
1236
 
  
 
1232
 
1237
1233
       ptr = pixdat;
1238
1234
       if (hdu->used.blank)
1239
1235
       {FITS_BITPIX16 blankval = (FITS_BITPIX16)hdu->blank;
1278
1274
       nelem -= maxelem;
1279
1275
       if (fread ((char *)pixdat, bpp, maxelem, fp) != maxelem)
1280
1276
         FITS_RETURN ("fits_eval_pixrange: error on read bitpix 32 data", -1);
1281
 
  
 
1277
 
1282
1278
       ptr = pixdat;
1283
1279
       if (hdu->used.blank)
1284
1280
       {FITS_BITPIX32 blankval = (FITS_BITPIX32)hdu->blank;
1329
1325
       nelem -= maxelem;
1330
1326
       if (fread ((char *)pixdat, bpp, maxelem, fp) != maxelem)
1331
1327
         FITS_RETURN ("fits_eval_pixrange: error on read bitpix -32 data", -1);
1332
 
  
 
1328
 
1333
1329
       ptr = pixdat;
1334
1330
       while (maxelem-- > 0)
1335
1331
       {
1370
1366
       nelem -= maxelem;
1371
1367
       if (fread ((char *)pixdat, bpp, maxelem, fp) != maxelem)
1372
1368
         FITS_RETURN ("fits_eval_pixrange: error on read bitpix -64 data", -1);
1373
 
  
 
1369
 
1374
1370
       ptr = pixdat;
1375
1371
       while (maxelem-- > 0)
1376
1372
       {
1425
1421
 long l_long;
1426
1422
 double l_double;
1427
1423
 char l_card[FITS_CARD_SIZE+1], msg[256];
1428
 
 char *cp = ident, *dst, *end;
 
1424
 char *cp, *dst, *end;
1429
1425
 
1430
1426
 if (card == NULL) return (NULL);
1431
1427
 
1468
1464
       FITS_RETURN ("fits_decode_card: error decoding typ_bitpixm64", NULL);
1469
1465
     data.bitpixm64 = (FITS_BITPIXM64)l_double;
1470
1466
     break;
1471
 
     
 
1467
 
1472
1468
   case typ_fbool:
1473
1469
     cp = l_card+10;
1474
1470
     while (*cp == ' ') cp++;
1596
1592
 
1597
1593
 if (ff->openmode != 'r')
1598
1594
   FITS_RETURN ("fits_image_info: file not open for reading", NULL);
1599
 
   
 
1595
 
1600
1596
 if ((picind < 1) || (picind > ff->n_pic))
1601
1597
   FITS_RETURN ("fits_image_info: picind out of range", NULL);
1602
1598
 
1667
1663
/* The function reads npix pixel values from the file, transforms them       */
1668
1664
/* checking for blank/NaN pixels and stores the transformed values in buf.   */
1669
1665
/* The number of transformed pixels is returned. If the returned value is    */
1670
 
/* less than npix (or even -1), an error has occured.                        */
 
1666
/* less than npix (or even -1), an error has occurred.                       */
1671
1667
/* hdulist must be a pointer returned by fits_seek_image(). Before starting  */
1672
1668
/* to read an image, fits_seek_image() must be called. Even for successive   */
1673
1669
/* images.                                                                   */
1692
1688
 FITS_BITPIXM64 bpm64;
1693
1689
 
1694
1690
 /* initialize */
1695
 
 
 
1691
 
1696
1692
 bpm32 = 0;
1697
1693
 
1698
1694
 if (ff->openmode != 'r') return (-1);   /* Not open for reading */
1944
1940
 if (hdu == NULL) goto err_return;
1945
1941
 if (hdu->naxis < 2) goto err_return;     /* Enough dimensions ? */
1946
1942
 
1947
 
 pgmout = fopen (pgmfile, "wb");
 
1943
 pgmout = g_fopen (pgmfile, "wb");
1948
1944
 if (pgmout == NULL) goto err_return;
1949
1945
 
1950
1946
                                   /* Write PGM header with width/height */
1978
1974
 retval = 0;
1979
1975
 
1980
1976
err_return:
1981
 
 
 
1977
 
1982
1978
 if (fitsin) fits_close (fitsin);
1983
1979
 if (pgmout) fclose (pgmout);
1984
1980
 
2015
2011
 fitsout = fits_open (fitsfile, "w");
2016
2012
 if (fitsout == NULL) goto err_return;
2017
2013
 
2018
 
 pgmin = fopen (pgmfile, "r");
 
2014
 pgmin = g_fopen (pgmfile, "r");
2019
2015
 if (pgmin == NULL) goto err_return;
2020
2016
 
2021
2017
 /* Read signature of PGM file */
2037
2033
   if (fgets (buffer, sizeof (buffer), pgmin) == NULL) goto err_return;
2038
2034
 } while (buffer[0] == '#');
2039
2035
 /* Ignore maxval */
2040
 
 
 
2036
 
2041
2037
 hdu = fits_add_hdu (fitsout);     /* Create a HDU for the FITS file */
2042
2038
 if (hdu == NULL) goto err_return;
2043
2039
 
2057
2053
 
2058
2054
 fits_add_card (hdu, "");
2059
2055
 fits_add_card (hdu, "HISTORY THIS FITS FILE WAS GENERATED BY FITSRW\
2060
 
 USING PGMRAW_TO_FITS"); 
 
2056
 USING PGMRAW_TO_FITS");
2061
2057
 
2062
2058
 /* Write the header. Blocking is done automatically */
2063
2059
 if (fits_write_header (fitsout, hdu) < 0) goto err_return;
2086
2082
 retval = 0;
2087
2083
 
2088
2084
err_return:
2089
 
 
 
2085
 
2090
2086
 if (fitsout) fits_close (fitsout);
2091
2087
 if (pgmin) fclose (pgmin);
2092
2088