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:
parent
f131aaa082
commit
8e667fbb3e
@ -4,6 +4,7 @@
|
|||||||
- bicubic is better on 32-bit int images
|
- bicubic is better on 32-bit int images
|
||||||
- add pdfload, svgload, gifload for PDF, SVG and GIF rendering
|
- add pdfload, svgload, gifload for PDF, SVG and GIF rendering
|
||||||
- vipsthumbnail knows about pdfload and svgload
|
- vipsthumbnail knows about pdfload and svgload
|
||||||
|
- added @page param to magickload
|
||||||
|
|
||||||
27/1/16 started 8.2.3
|
27/1/16 started 8.2.3
|
||||||
- fix a crash with SPARC byte-order labq vips images
|
- fix a crash with SPARC byte-order labq vips images
|
||||||
|
@ -50,7 +50,7 @@ im_magick2vips( const char *filename, IMAGE *out )
|
|||||||
#ifdef HAVE_MAGICK
|
#ifdef HAVE_MAGICK
|
||||||
/* Old behaviour was always to read all frames.
|
/* 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
|
#else
|
||||||
vips_error( "im_magick2vips",
|
vips_error( "im_magick2vips",
|
||||||
"%s", _( "no libMagick support in your libvips" ) );
|
"%s", _( "no libMagick support in your libvips" ) );
|
||||||
|
@ -36,14 +36,14 @@ extern "C" {
|
|||||||
#endif /*__cplusplus*/
|
#endif /*__cplusplus*/
|
||||||
|
|
||||||
int vips__magick_read( const char *filename,
|
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,
|
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,
|
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,
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,8 @@
|
|||||||
* 26/2/15
|
* 26/2/15
|
||||||
* - close the read down early for a header read ... this saves an
|
* - close the read down early for a header read ... this saves an
|
||||||
* fd during file read, handy for large numbers of input images
|
* 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;
|
char *filename;
|
||||||
VipsImage *im;
|
VipsImage *im;
|
||||||
gboolean all_frames;
|
gboolean all_frames;
|
||||||
|
int page;
|
||||||
|
|
||||||
Image *image;
|
Image *image;
|
||||||
ImageInfo *image_info;
|
ImageInfo *image_info;
|
||||||
@ -160,8 +163,8 @@ read_close( VipsImage *im, Read *read )
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Read *
|
static Read *
|
||||||
read_new( const char *filename, VipsImage *im, gboolean all_frames,
|
read_new( const char *filename, VipsImage *im,
|
||||||
const char *density )
|
gboolean all_frames, const char *density, int page )
|
||||||
{
|
{
|
||||||
Read *read;
|
Read *read;
|
||||||
static int inited = 0;
|
static int inited = 0;
|
||||||
@ -179,6 +182,7 @@ read_new( const char *filename, VipsImage *im, gboolean all_frames,
|
|||||||
return( NULL );
|
return( NULL );
|
||||||
read->filename = filename ? g_strdup( filename ) : NULL;
|
read->filename = filename ? g_strdup( filename ) : NULL;
|
||||||
read->all_frames = all_frames;
|
read->all_frames = all_frames;
|
||||||
|
read->page = page;
|
||||||
read->im = im;
|
read->im = im;
|
||||||
read->image = NULL;
|
read->image = NULL;
|
||||||
read->image_info = CloneImageInfo( NULL );
|
read->image_info = CloneImageInfo( NULL );
|
||||||
@ -673,8 +677,8 @@ magick_fill_region( VipsRegion *out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
vips__magick_read( const char *filename, VipsImage *out, gboolean all_frames,
|
vips__magick_read( const char *filename, VipsImage *out,
|
||||||
const char *density )
|
gboolean all_frames, const char *density, int page )
|
||||||
{
|
{
|
||||||
Read *read;
|
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 );
|
printf( "magick2vips: vips__magick_read: %s\n", filename );
|
||||||
#endif /*DEBUG*/
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
if( !(read = read_new( filename, out, all_frames, density )) )
|
if( !(read = read_new( filename, out, all_frames, density, page )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
#ifdef HAVE_SETIMAGEOPTION
|
#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" );
|
SetImageOption( read->image_info, "dcm:display-range", "reset" );
|
||||||
#endif /*HAVE_SETIMAGEOPTION*/
|
#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
|
#ifdef DEBUG
|
||||||
printf( "magick2vips: calling ReadImage() ...\n" );
|
printf( "magick2vips: calling ReadImage() ...\n" );
|
||||||
#endif /*DEBUG*/
|
#endif /*DEBUG*/
|
||||||
@ -724,7 +747,7 @@ vips__magick_read( const char *filename, VipsImage *out, gboolean all_frames,
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
vips__magick_read_header( const char *filename, VipsImage *im,
|
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;
|
Read *read;
|
||||||
|
|
||||||
@ -732,7 +755,7 @@ vips__magick_read_header( const char *filename, VipsImage *im,
|
|||||||
printf( "vips__magick_read_header: %s\n", filename );
|
printf( "vips__magick_read_header: %s\n", filename );
|
||||||
#endif /*DEBUG*/
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
if( !(read = read_new( filename, im, all_frames, density )) )
|
if( !(read = read_new( filename, im, all_frames, density, page )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -765,7 +788,7 @@ vips__magick_read_header( const char *filename, VipsImage *im,
|
|||||||
|
|
||||||
int
|
int
|
||||||
vips__magick_read_buffer( const void *buf, const size_t len, VipsImage *out,
|
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;
|
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 );
|
printf( "magick2vips: vips__magick_read_buffer: %p %zu\n", buf, len );
|
||||||
#endif /*DEBUG*/
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
if( !(read = read_new( NULL, out, all_frames, density )) )
|
if( !(read = read_new( NULL, out, all_frames, density, page )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
#ifdef HAVE_SETIMAGEOPTION
|
#ifdef HAVE_SETIMAGEOPTION
|
||||||
@ -810,8 +833,9 @@ vips__magick_read_buffer( const void *buf, const size_t len, VipsImage *out,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
vips__magick_read_buffer_header( const void *buf, const size_t len,
|
vips__magick_read_buffer_header( const void *buf, const size_t len,
|
||||||
VipsImage *im, gboolean all_frames, const char *density )
|
VipsImage *im,
|
||||||
|
gboolean all_frames, const char *density, int page )
|
||||||
{
|
{
|
||||||
Read *read;
|
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 );
|
printf( "vips__magick_read_buffer_header: %p %zu\n", buf, len );
|
||||||
#endif /*DEBUG*/
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
if( !(read = read_new( NULL, im, all_frames, density )) )
|
if( !(read = read_new( NULL, im, all_frames, density, page )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
* - remove header-only loads
|
* - remove header-only loads
|
||||||
* 11/6/13
|
* 11/6/13
|
||||||
* - add @all_frames option, off by default
|
* - add @all_frames option, off by default
|
||||||
|
* 14/2/16
|
||||||
|
* - add @page option, 0 by default
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -59,8 +61,9 @@
|
|||||||
typedef struct _VipsForeignLoadMagick {
|
typedef struct _VipsForeignLoadMagick {
|
||||||
VipsForeignLoad parent_object;
|
VipsForeignLoad parent_object;
|
||||||
|
|
||||||
gboolean all_frames;
|
gboolean all_frames; /* Load all frames */
|
||||||
char *density;
|
char *density; /* Load at this resolution */
|
||||||
|
int page; /* Load this page (frame) */
|
||||||
|
|
||||||
} VipsForeignLoadMagick;
|
} VipsForeignLoadMagick;
|
||||||
|
|
||||||
@ -117,6 +120,13 @@ vips_foreign_load_magick_class_init( VipsForeignLoadMagickClass *class )
|
|||||||
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||||
G_STRUCT_OFFSET( VipsForeignLoadMagick, density ),
|
G_STRUCT_OFFSET( VipsForeignLoadMagick, density ),
|
||||||
NULL );
|
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
|
static void
|
||||||
@ -144,7 +154,7 @@ ismagick( const char *filename )
|
|||||||
|
|
||||||
t = vips_image_new();
|
t = vips_image_new();
|
||||||
vips_error_freeze();
|
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 );
|
g_object_unref( t );
|
||||||
vips_error_thaw();
|
vips_error_thaw();
|
||||||
|
|
||||||
@ -166,7 +176,7 @@ vips_foreign_load_magick_file_header( VipsForeignLoad *load )
|
|||||||
(VipsForeignLoadMagickFile *) load;
|
(VipsForeignLoadMagickFile *) load;
|
||||||
|
|
||||||
if( vips__magick_read( magick_file->filename,
|
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 );
|
return( -1 );
|
||||||
|
|
||||||
VIPS_SETSTR( load->out->filename, magick_file->filename );
|
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();
|
t = vips_image_new();
|
||||||
vips_error_freeze();
|
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 );
|
g_object_unref( t );
|
||||||
vips_error_thaw();
|
vips_error_thaw();
|
||||||
|
|
||||||
@ -249,7 +259,7 @@ vips_foreign_load_magick_buffer_header( VipsForeignLoad *load )
|
|||||||
|
|
||||||
if( vips__magick_read_buffer(
|
if( vips__magick_read_buffer(
|
||||||
magick_buffer->buf->data, magick_buffer->buf->length,
|
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( -1 );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
Loading…
Reference in New Issue
Block a user