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
This commit is contained in:
John Cupitt 2017-04-15 13:27:45 +01:00
parent 4094070ecb
commit 4f3364a2b0
2 changed files with 22 additions and 4 deletions

View File

@ -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

View File

@ -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