From 4f3364a2b03d10df02cd23bf74e9aad430d29cfa Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 15 Apr 2017 13:27:45 +0100 Subject: [PATCH] skip non-image HDUs at start of fits some fits images have header units (HDUs) at the start with extra metadata in ... skip over these see https://github.com/jcupitt/libvips/issues/640 --- ChangeLog | 1 + libvips/foreign/fits.c | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 62473ccf..1ee76505 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ 15/4/17 started 8.6.0 +- supports fits images with leading non-image HDUs, thanks benepo 7/4/17 started 8.5.3 - more link fixing in docs diff --git a/libvips/foreign/fits.c b/libvips/foreign/fits.c index c7f28e41..b3a74df7 100644 --- a/libvips/foreign/fits.c +++ b/libvips/foreign/fits.c @@ -31,6 +31,8 @@ * 26/1/17 aferrero2707 * - use fits_open_diskfile(), not fits_open_file() ... we don't want the * extended filename syntax + * 15/4/17 + * - skip HDUs with zero dimensions, thanks benepo */ /* @@ -221,10 +223,25 @@ vips_fits_get_header( VipsFits *fits, VipsImage *out ) status = 0; - if( fits_get_img_paramll( fits->fptr, - 10, &bitpix, &fits->naxis, fits->naxes, &status ) ) { - vips_fits_error( status ); - return( -1 ); + /* Some FITS images have the first HDU for extra metadata ... skip + * forward until we find a header unit we can load as an image. + */ + for(;;) { + if( fits_get_img_paramll( fits->fptr, + 10, &bitpix, &fits->naxis, fits->naxes, &status ) ) { + vips_fits_error( status ); + return( -1 ); + } + + if( fits->naxis > 0 ) + break; + + if( fits_movrel_hdu( fits->fptr, 1, NULL, &status ) ) { + vips_fits_error( status ); + vips_error( "fits", + "%s", _( "no HDU found with naxes > 0" ) ); + return( -1 ); + } } /* cfitsio does automatic conversion from the format stored in