From 6e968d46f2d5a6005344bd9c5c88e40ca1243e55 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 25 Nov 2016 18:19:36 +0000 Subject: [PATCH] magick7 now supports page/n --- ChangeLog | 2 +- TODO | 18 ++-------------- libvips/foreign/magick2vips.c | 3 ++- libvips/foreign/magick7load.c | 40 ++++++++++++++++++++++++++--------- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 13772b33..da70784d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,7 +12,7 @@ - add vips_image_get_fields() to help bindings - add tiff multi-page read/write - add VIPS_META_PAGE_HEIGHT metadata -- IM6 magickload supports page/n, all_frames deprecated +- IM6/IM7 magickload supports page/n/page-height, all_frames deprecated 11/11/16 started 8.4.4 - fix crash in vips.exe arg parsing on Windows, thanks Yury diff --git a/TODO b/TODO index 071a054a..2f4c6dd3 100644 --- a/TODO +++ b/TODO @@ -2,27 +2,13 @@ magick, pdf, gif and tiff need to use the same page/n interface - magick: has page and all_frames - - deprecate all_frames, add @n, make all_frames set n == -1 - - do we allow page + all_frames? - - need to check magick2vips.c and magick7load.c - - add page-height - magick6 - deprecated all_frames, added n, added tests + deprecated all_frames, added n, added tests, added page-height magick7 - $ vips magickload nipguide.pdf x.v --all-frames - $ vipsheader x.v - x.v: 595x48836 ushort, 4 bands, rgb16, magickload - - phew + same gifload has page, but no n diff --git a/libvips/foreign/magick2vips.c b/libvips/foreign/magick2vips.c index f6469f5c..c9416819 100644 --- a/libvips/foreign/magick2vips.c +++ b/libvips/foreign/magick2vips.c @@ -237,7 +237,8 @@ read_new( const char *filename, VipsImage *im, /* Some IMs must have the string version set as well. */ - vips_snprintf( page, 256, "%d-%d", read->page, read->page + n ); + vips_snprintf( page, 256, "%d-%d", + read->page, read->page + read->n ); read->image_info->scenes = strdup( page ); #else /*!HAVE_NUMBER_SCENES*/ /* This works with GM 1.2.31 and probably others. diff --git a/libvips/foreign/magick7load.c b/libvips/foreign/magick7load.c index c654f16c..1d483483 100644 --- a/libvips/foreign/magick7load.c +++ b/libvips/foreign/magick7load.c @@ -2,6 +2,8 @@ * * 8/7/16 * - from magickload + * 25/11/16 + * - add @n, deprecate @all_frames (just sets n = -1) */ /* @@ -55,9 +57,13 @@ typedef struct _VipsForeignLoadMagick7 { VipsForeignLoad parent_object; - gboolean all_frames; /* Load all frames */ + /* Deprecated. Just sets n = -1. + */ + gboolean all_frames; + char *density; /* Load at this resolution */ int page; /* Load this page (frame) */ + int n; /* Load this many pages */ Image *image; ImageInfo *image_info; @@ -308,6 +314,9 @@ vips_foreign_load_magick7_build( VipsObject *object ) if( !magick7->image_info ) return( -1 ); + if( magick7->all_frames ) + magick7->n = -1; + /* Canvas resolution for rendering vector formats like SVG. */ VIPS_SETSTR( magick7->image_info->density, magick7->density ); @@ -321,15 +330,16 @@ vips_foreign_load_magick7_build( VipsObject *object ) */ SetImageOption( magick7->image_info, "dcm:display-range", "reset" ); - if( !magick7->all_frames ) { + if( magick7->page > 0 ) { /* I can't find docs for these fields, but this seems to work. */ char page[256]; magick7->image_info->scene = magick7->page; - magick7->image_info->number_scenes = 1; + magick7->image_info->number_scenes = magick7->n; - vips_snprintf( page, 256, "%d", magick7->page ); + vips_snprintf( page, 256, "%d-%d", + magick7->page, magick7->page + magick7->n ); magick7->image_info->scenes = strdup( page ); } @@ -368,7 +378,7 @@ vips_foreign_load_magick7_class_init( VipsForeignLoadMagick7Class *class ) VIPS_ARG_BOOL( class, "all_frames", 3, _( "all_frames" ), _( "Read all frames from an image" ), - VIPS_ARGUMENT_OPTIONAL_INPUT, + VIPS_ARGUMENT_OPTIONAL_INPUT | VIPS_ARGUMENT_DEPRECATED, G_STRUCT_OFFSET( VipsForeignLoadMagick7, all_frames ), FALSE ); @@ -385,11 +395,20 @@ vips_foreign_load_magick7_class_init( VipsForeignLoadMagick7Class *class ) VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsForeignLoadMagick7, page ), 0, 100000, 0 ); + + VIPS_ARG_INT( class, "n", 6, + _( "n" ), + _( "Load this many pages" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsForeignLoadMagick7, n ), + -1, 100000, 1 ); + } static void vips_foreign_load_magick7_init( VipsForeignLoadMagick7 *magick7 ) { + magick7->n = 1; } static void @@ -545,14 +564,15 @@ vips_foreign_load_magick7_parse( VipsForeignLoadMagick7 *magick7, printf( "image has %d frames\n", magick7->n_frames ); #endif /*DEBUG*/ - /* If all_frames is off, just get the first one. - */ - if( !magick7->all_frames ) - magick7->n_frames = 1; + if( magick7->n != -1 ) + magick7->n_frames = VIPS_MIN( magick7->n_frames, magick7->n ); /* So we can finally set the height. */ - out->Ysize *= magick7->n_frames; + if( magick7->n_frames > 1 ) { + vips_image_set_int( out, VIPS_META_PAGE_HEIGHT, out->Ysize ); + out->Ysize *= magick7->n_frames; + } return( 0 ); }