add @scale option

and set xres/yres
This commit is contained in:
John Cupitt 2016-02-08 16:57:37 +00:00
parent adfd25a5ed
commit 5db2c64d90
3 changed files with 36 additions and 8 deletions

2
TODO
View File

@ -4,8 +4,6 @@
- add file type sniffing .. "%PDF" should be enough - add file type sniffing .. "%PDF" should be enough
- metadata: xres/yres
- trim page edges? we often have black now - trim page edges? we often have black now
- new vips_reduce: - new vips_reduce:

View File

@ -2857,12 +2857,14 @@ vips_matload( const char *filename, VipsImage **out, ... )
* *
* @page: %gint, load this page, numbered from zero * @page: %gint, load this page, numbered from zero
* @dpi: %gdouble, render at this DPI * @dpi: %gdouble, render at this DPI
* @scale: %gdouble, scale render by this factor
* *
* Render a PDF file into a VIPS image. * Render a PDF file into a VIPS image.
* *
* Use @page to select a page to render, numbering from zero. * Use @page to select a page to render, numbering from zero.
* *
* Use @dpi to set the rendering resolution. The default is 72. * Use @dpi to set the rendering resolution. The default is 72. Alternatively
* you can scale the rendering by @scale.
* *
* This function only reads the image header and does not render any pixel * This function only reads the image header and does not render any pixel
* data. Rendering only occurs when pixels are accessed. * data. Rendering only occurs when pixels are accessed.

View File

@ -97,6 +97,21 @@ vips_foreign_load_poppler_dispose( GObject *gobject )
dispose( gobject ); dispose( gobject );
} }
static int
vips_foreign_load_poppler_build( VipsObject *object )
{
VipsForeignLoadPoppler *poppler = (VipsForeignLoadPoppler *) object;
if( !vips_object_argument_isset( object, "scale" ) )
poppler->scale = poppler->dpi / 72.0;
if( VIPS_OBJECT_CLASS( vips_foreign_load_poppler_parent_class )->
build( object ) )
return( -1 );
return( 0 );
}
static VipsForeignFlags static VipsForeignFlags
vips_foreign_load_poppler_get_flags_filename( const char *filename ) vips_foreign_load_poppler_get_flags_filename( const char *filename )
{ {
@ -136,17 +151,21 @@ vips_foreign_load_poppler_parse( VipsForeignLoadPoppler *poppler,
PopplerRectangle crop_box; PopplerRectangle crop_box;
double width; double width;
double height; double height;
double res;
int i; int i;
char *str;
poppler_page_get_size( poppler->page, &width, &height ); poppler_page_get_size( poppler->page, &width, &height );
poppler_page_get_crop_box( poppler->page, &crop_box ); poppler_page_get_crop_box( poppler->page, &crop_box );
/* We need pixels/mm for vips.
*/
res = poppler->dpi / 25.4;
vips_image_init_fields( out, vips_image_init_fields( out,
width * poppler->scale, height * poppler->scale, width * poppler->scale, height * poppler->scale,
4, VIPS_FORMAT_UCHAR, 4, VIPS_FORMAT_UCHAR,
VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB, 1.0, 1.0 ); VIPS_CODING_NONE, VIPS_INTERPRETATION_sRGB, res, res );
VIPS_SETSTR( out->filename, poppler->filename ); VIPS_SETSTR( out->filename, poppler->filename );
@ -163,6 +182,8 @@ vips_foreign_load_poppler_parse( VipsForeignLoadPoppler *poppler,
VipsForeignLoadPopperMetadata *metadata = VipsForeignLoadPopperMetadata *metadata =
&vips_foreign_load_poppler_metadata[i]; &vips_foreign_load_poppler_metadata[i];
char *str;
if( (str = metadata->poppler_fetch( poppler->doc )) ) { if( (str = metadata->poppler_fetch( poppler->doc )) ) {
vips_image_set_string( out, metadata->field, str ); vips_image_set_string( out, metadata->field, str );
g_free( str ); g_free( str );
@ -179,8 +200,6 @@ vips_foreign_load_poppler_header( VipsForeignLoad *load )
char *path; char *path;
GError *error = NULL; GError *error = NULL;
poppler->scale = poppler->dpi / 72.0;
/* We need an absolute path for a URI. /* We need an absolute path for a URI.
*/ */
path = vips_realpath( poppler->filename ); path = vips_realpath( poppler->filename );
@ -309,6 +328,7 @@ vips_foreign_load_poppler_class_init( VipsForeignLoadPopplerClass *class )
object_class->nickname = "popplerload"; object_class->nickname = "popplerload";
object_class->description = _( "load PDF with poppler" ); object_class->description = _( "load PDF with poppler" );
object_class->build = vips_foreign_load_poppler_build;
foreign_class->suffs = vips_foreign_poppler_suffs; foreign_class->suffs = vips_foreign_poppler_suffs;
@ -332,19 +352,27 @@ vips_foreign_load_poppler_class_init( VipsForeignLoadPopplerClass *class )
G_STRUCT_OFFSET( VipsForeignLoadPoppler, page_no ), G_STRUCT_OFFSET( VipsForeignLoadPoppler, page_no ),
0, 100000, 0 ); 0, 100000, 0 );
VIPS_ARG_DOUBLE( class, "dpi", 10, VIPS_ARG_DOUBLE( class, "dpi", 11,
_( "DPI" ), _( "DPI" ),
_( "Render at this DPI" ), _( "Render at this DPI" ),
VIPS_ARGUMENT_OPTIONAL_INPUT, VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignLoadPoppler, dpi ), G_STRUCT_OFFSET( VipsForeignLoadPoppler, dpi ),
0.001, 100000.0, 72.0 ); 0.001, 100000.0, 72.0 );
VIPS_ARG_DOUBLE( class, "scale", 12,
_( "Scale" ),
_( "Scale output by this factor" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignLoadPoppler, scale ),
0.001, 100000.0, 1.0 );
} }
static void static void
vips_foreign_load_poppler_init( VipsForeignLoadPoppler *poppler ) vips_foreign_load_poppler_init( VipsForeignLoadPoppler *poppler )
{ {
poppler->dpi = 72.0; poppler->dpi = 72.0;
poppler->scale = 1.0;
} }
#endif /*HAVE_POPPLER*/ #endif /*HAVE_POPPLER*/