still not quite there

works, but is no faster, how odd

john@kiwi:~/pics$ time vips magickload nipguide.pdf[40] x.tif
real	0m0.244s
user	0m0.212s
sys	0m0.040s

$ time vips magickload nipguide.pdf x.tif --page 40
real	0m7.035s
user	0m6.900s
sys	0m0.152s

both give same result
This commit is contained in:
John Cupitt 2016-02-15 08:53:23 +00:00
parent f131aaa082
commit 8e667fbb3e
5 changed files with 58 additions and 23 deletions

View File

@ -4,6 +4,7 @@
- bicubic is better on 32-bit int images
- add pdfload, svgload, gifload for PDF, SVG and GIF rendering
- vipsthumbnail knows about pdfload and svgload
- added @page param to magickload
27/1/16 started 8.2.3
- fix a crash with SPARC byte-order labq vips images

View File

@ -50,7 +50,7 @@ im_magick2vips( const char *filename, IMAGE *out )
#ifdef HAVE_MAGICK
/* Old behaviour was always to read all frames.
*/
return( vips__magick_read( filename, out, TRUE, NULL ) );
return( vips__magick_read( filename, out, TRUE, NULL, 0 ) );
#else
vips_error( "im_magick2vips",
"%s", _( "no libMagick support in your libvips" ) );

View File

@ -36,14 +36,14 @@ extern "C" {
#endif /*__cplusplus*/
int vips__magick_read( const char *filename,
VipsImage *out, gboolean all_frames, const char *density );
VipsImage *out, gboolean all_frames, const char *density, int page );
int vips__magick_read_header( const char *filename,
VipsImage *out, gboolean all_frames, const char *density );
VipsImage *out, gboolean all_frames, const char *density, int page );
int vips__magick_read_buffer( const void *buf, const size_t len,
VipsImage *out, gboolean all_frames, const char *density );
VipsImage *out, gboolean all_frames, const char *density, int page );
int vips__magick_read_buffer_header( const void *buf, const size_t len,
VipsImage *out, gboolean all_frames, const char *density );
VipsImage *out, gboolean all_frames, const char *density, int page );
#ifdef __cplusplus
}

View File

@ -47,6 +47,8 @@
* 26/2/15
* - close the read down early for a header read ... this saves an
* fd during file read, handy for large numbers of input images
* 14/2/16
* - add @page option, 0 by default
*/
/*
@ -116,6 +118,7 @@ typedef struct _Read {
char *filename;
VipsImage *im;
gboolean all_frames;
int page;
Image *image;
ImageInfo *image_info;
@ -160,8 +163,8 @@ read_close( VipsImage *im, Read *read )
}
static Read *
read_new( const char *filename, VipsImage *im, gboolean all_frames,
const char *density )
read_new( const char *filename, VipsImage *im,
gboolean all_frames, const char *density, int page )
{
Read *read;
static int inited = 0;
@ -179,6 +182,7 @@ read_new( const char *filename, VipsImage *im, gboolean all_frames,
return( NULL );
read->filename = filename ? g_strdup( filename ) : NULL;
read->all_frames = all_frames;
read->page = page;
read->im = im;
read->image = NULL;
read->image_info = CloneImageInfo( NULL );
@ -673,8 +677,8 @@ magick_fill_region( VipsRegion *out,
}
int
vips__magick_read( const char *filename, VipsImage *out, gboolean all_frames,
const char *density )
vips__magick_read( const char *filename, VipsImage *out,
gboolean all_frames, const char *density, int page )
{
Read *read;
@ -682,7 +686,7 @@ vips__magick_read( const char *filename, VipsImage *out, gboolean all_frames,
printf( "magick2vips: vips__magick_read: %s\n", filename );
#endif /*DEBUG*/
if( !(read = read_new( filename, out, all_frames, density )) )
if( !(read = read_new( filename, out, all_frames, density, page )) )
return( -1 );
#ifdef HAVE_SETIMAGEOPTION
@ -696,6 +700,25 @@ vips__magick_read( const char *filename, VipsImage *out, gboolean all_frames,
SetImageOption( read->image_info, "dcm:display-range", "reset" );
#endif /*HAVE_SETIMAGEOPTION*/
if( !all_frames ) {
/* Just pick a specific page.
*/
/* This doesn't seem to work, strange.
*
* read->image_info->number_scenes = 1;
* read->image_info->scene = read->page;
*/
/* This works, but is no faster.
*/
char page[256];
vips_snprintf( page, 256, "%d", read->page );
read->image_info->scenes = strdup( page );
}
#ifdef DEBUG
printf( "magick2vips: calling ReadImage() ...\n" );
#endif /*DEBUG*/
@ -724,7 +747,7 @@ vips__magick_read( const char *filename, VipsImage *out, gboolean all_frames,
*/
int
vips__magick_read_header( const char *filename, VipsImage *im,
gboolean all_frames, const char *density )
gboolean all_frames, const char *density, int page )
{
Read *read;
@ -732,7 +755,7 @@ vips__magick_read_header( const char *filename, VipsImage *im,
printf( "vips__magick_read_header: %s\n", filename );
#endif /*DEBUG*/
if( !(read = read_new( filename, im, all_frames, density )) )
if( !(read = read_new( filename, im, all_frames, density, page )) )
return( -1 );
#ifdef DEBUG
@ -765,7 +788,7 @@ vips__magick_read_header( const char *filename, VipsImage *im,
int
vips__magick_read_buffer( const void *buf, const size_t len, VipsImage *out,
gboolean all_frames, const char *density )
gboolean all_frames, const char *density, int page )
{
Read *read;
@ -773,7 +796,7 @@ vips__magick_read_buffer( const void *buf, const size_t len, VipsImage *out,
printf( "magick2vips: vips__magick_read_buffer: %p %zu\n", buf, len );
#endif /*DEBUG*/
if( !(read = read_new( NULL, out, all_frames, density )) )
if( !(read = read_new( NULL, out, all_frames, density, page )) )
return( -1 );
#ifdef HAVE_SETIMAGEOPTION
@ -810,8 +833,9 @@ vips__magick_read_buffer( const void *buf, const size_t len, VipsImage *out,
}
int
vips__magick_read_buffer_header( const void *buf, const size_t len,
VipsImage *im, gboolean all_frames, const char *density )
vips__magick_read_buffer_header( const void *buf, const size_t len,
VipsImage *im,
gboolean all_frames, const char *density, int page )
{
Read *read;
@ -819,7 +843,7 @@ vips__magick_read_buffer_header( const void *buf, const size_t len,
printf( "vips__magick_read_buffer_header: %p %zu\n", buf, len );
#endif /*DEBUG*/
if( !(read = read_new( NULL, im, all_frames, density )) )
if( !(read = read_new( NULL, im, all_frames, density, page )) )
return( -1 );
#ifdef DEBUG

View File

@ -6,6 +6,8 @@
* - remove header-only loads
* 11/6/13
* - add @all_frames option, off by default
* 14/2/16
* - add @page option, 0 by default
*/
/*
@ -59,8 +61,9 @@
typedef struct _VipsForeignLoadMagick {
VipsForeignLoad parent_object;
gboolean all_frames;
char *density;
gboolean all_frames; /* Load all frames */
char *density; /* Load at this resolution */
int page; /* Load this page (frame) */
} VipsForeignLoadMagick;
@ -117,6 +120,13 @@ vips_foreign_load_magick_class_init( VipsForeignLoadMagickClass *class )
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignLoadMagick, density ),
NULL );
VIPS_ARG_INT( class, "page", 5,
_( "Page" ),
_( "Load this page from the file" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignLoadMagick, page ),
0, 100000, 0 );
}
static void
@ -144,7 +154,7 @@ ismagick( const char *filename )
t = vips_image_new();
vips_error_freeze();
result = vips__magick_read_header( filename, t, FALSE, NULL );
result = vips__magick_read_header( filename, t, FALSE, NULL, 0 );
g_object_unref( t );
vips_error_thaw();
@ -166,7 +176,7 @@ vips_foreign_load_magick_file_header( VipsForeignLoad *load )
(VipsForeignLoadMagickFile *) load;
if( vips__magick_read( magick_file->filename,
load->out, magick->all_frames, magick->density ) )
load->out, magick->all_frames, magick->density, magick->page ) )
return( -1 );
VIPS_SETSTR( load->out->filename, magick_file->filename );
@ -226,7 +236,7 @@ vips_foreign_load_magick_buffer_is_a_buffer( const void *buf, size_t len )
t = vips_image_new();
vips_error_freeze();
result = vips__magick_read_buffer_header( buf, len, t, FALSE, NULL );
result = vips__magick_read_buffer_header( buf, len, t, FALSE, NULL, 0 );
g_object_unref( t );
vips_error_thaw();
@ -249,7 +259,7 @@ vips_foreign_load_magick_buffer_header( VipsForeignLoad *load )
if( vips__magick_read_buffer(
magick_buffer->buf->data, magick_buffer->buf->length,
load->out, magick->all_frames, magick->density ) )
load->out, magick->all_frames, magick->density, magick->page ) )
return( -1 );
return( 0 );