From bd8a6980f5c26b953e10316bb1c087ab9a8c2753 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 29 May 2019 10:10:28 +0100 Subject: [PATCH] more consistent behaviour for multi-page load Some loaders were setting page-height even when the user was loading a single page triggering unexpected multi-page behaviour from later savers. New rule: only set page-height when loading more than one page. See https://github.com/libvips/libvips/issues/1318 --- ChangeLog | 1 + libvips/foreign/Makefile.am | 2 +- libvips/foreign/gifload.c | 5 ++--- libvips/foreign/heifload.c | 4 +++- libvips/foreign/{pdfload_pdfium.c => pdfiumload.c} | 3 ++- libvips/foreign/pdfload.c | 3 ++- libvips/foreign/webp2vips.c | 3 ++- 7 files changed, 13 insertions(+), 8 deletions(-) rename libvips/foreign/{pdfload_pdfium.c => pdfiumload.c} (99%) diff --git a/ChangeLog b/ChangeLog index 077985ad..acfe1318 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 24/5/19 started 8.8.1 - improve realpath() use on older libc - better magickload error messages +- more consistent behaviour for page-height metadata 21/9/18 started 8.8.0 - much faster smartcrop [lovell] diff --git a/libvips/foreign/Makefile.am b/libvips/foreign/Makefile.am index 990b8797..b44cf53c 100644 --- a/libvips/foreign/Makefile.am +++ b/libvips/foreign/Makefile.am @@ -11,7 +11,7 @@ libforeign_la_SOURCES = \ gifload.c \ cairo.c \ pdfload.c \ - pdfload_pdfium.c \ + pdfiumload.c \ svgload.c \ radiance.c \ radload.c \ diff --git a/libvips/foreign/gifload.c b/libvips/foreign/gifload.c index fabc0871..4f6a4483 100644 --- a/libvips/foreign/gifload.c +++ b/libvips/foreign/gifload.c @@ -571,11 +571,10 @@ vips_foreign_load_gif_set_header( VipsForeignLoadGif *gif, VipsImage *image ) 1.0, 1.0 ); vips_image_pipelinev( image, VIPS_DEMAND_STYLE_FATSTRIP, NULL ); - if( gif->n_pages > 1 ) { + if( gif->n > 1 ) vips_image_set_int( image, VIPS_META_PAGE_HEIGHT, gif->file->SHeight ); - vips_image_set_int( image, VIPS_META_N_PAGES, gif->n_pages ); - } + vips_image_set_int( image, VIPS_META_N_PAGES, gif->n_pages ); vips_image_set_int( image, "gif-delay", gif->delay ); vips_image_set_int( image, "gif-loop", gif->loop ); if( gif->comment ) diff --git a/libvips/foreign/heifload.c b/libvips/foreign/heifload.c index ecc1140a..d475b076 100644 --- a/libvips/foreign/heifload.c +++ b/libvips/foreign/heifload.c @@ -382,7 +382,9 @@ vips_foreign_load_heif_set_header( VipsForeignLoadHeif *heif, VipsImage *out ) vips_image_set_int( out, "heif-primary", heif->primary_page ); vips_image_set_int( out, "n-pages", heif->n_top ); - vips_image_set_int( out, "page-height", heif->page_height ); + if( heif->n > 1 ) + vips_image_set_int( out, + VIPS_META_PAGE_HEIGHT, heif->page_height ); /* FIXME .. we always decode to RGB in generate. We should check for * all grey images, perhaps. diff --git a/libvips/foreign/pdfload_pdfium.c b/libvips/foreign/pdfiumload.c similarity index 99% rename from libvips/foreign/pdfload_pdfium.c rename to libvips/foreign/pdfiumload.c index 5f62d43c..f0a022f0 100644 --- a/libvips/foreign/pdfload_pdfium.c +++ b/libvips/foreign/pdfiumload.c @@ -363,7 +363,8 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load ) for( i = 1; i < pdf->n; i++ ) if( pdf->pages[i].height != pdf->pages[0].height ) break; - if( i == pdf->n ) + if( i == pdf->n && + pdf->n > 1 ) vips_image_set_int( load->out, VIPS_META_PAGE_HEIGHT, pdf->pages[0].height ); diff --git a/libvips/foreign/pdfload.c b/libvips/foreign/pdfload.c index 49f211e7..86c1d992 100644 --- a/libvips/foreign/pdfload.c +++ b/libvips/foreign/pdfload.c @@ -317,7 +317,8 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load ) for( i = 1; i < pdf->n; i++ ) if( pdf->pages[i].height != pdf->pages[0].height ) break; - if( i == pdf->n ) + if( i == pdf->n && + pdf->n > 1 ) vips_image_set_int( load->out, VIPS_META_PAGE_HEIGHT, pdf->pages[0].height ); diff --git a/libvips/foreign/webp2vips.c b/libvips/foreign/webp2vips.c index cbe999ca..695e87c1 100644 --- a/libvips/foreign/webp2vips.c +++ b/libvips/foreign/webp2vips.c @@ -467,7 +467,8 @@ read_header( Read *read, VipsImage *out ) #endif /*DEBUG*/ vips_image_set_int( out, "gif-loop", loop_count ); - vips_image_set_int( out, "page-height", read->frame_height ); + vips_image_set_int( out, + VIPS_META_PAGE_HEIGHT, read->frame_height ); /* We must get the first frame to get the delay. Frames number * from 1.