make pdf load close early

but only in seq mode
This commit is contained in:
John Cupitt 2018-08-17 11:14:06 +01:00
parent 0b4cef06b7
commit 10d1aeb6f2
4 changed files with 44 additions and 11 deletions

View File

@ -13,8 +13,8 @@ morphological operations, frequency filtering, colour, resampling, statistics
and others. It supports a large range of numeric formats, from 8-bit int
to 128-bit complex. It supports a good range of image formats, including
JPEG, TIFF, PNG, WebP, FITS, Matlab, OpenEXR, PDF, SVG, HDR, PPM, CSV, GIF,
Analyze, DeepZoom, and OpenSlide. It can also load images via ImageMagick
or GraphicsMagick.
Analyze, Nifti, DeepZoom, and OpenSlide. It can also load and save images via
ImageMagick or GraphicsMagick.
It has APIs for
[C](http://jcupitt.github.io/libvips/API/current/using-from-c.html) and

View File

@ -981,7 +981,7 @@ vips_foreign_load_build( VipsObject *object )
/* Tell downstream if we are reading sequentially.
*/
if( sequential )
if( sequential )
vips_image_set_area( load->out,
VIPS_META_SEQUENTIAL, NULL, NULL );

View File

@ -10,6 +10,8 @@
* - use a much larger strip size, thanks bubba
* 8/6/18
* - add background param
* 16/8/18
* - shut down the input file as soon as we can [kleisauke]
*/
/*
@ -116,13 +118,19 @@ typedef VipsForeignLoadClass VipsForeignLoadPdfClass;
G_DEFINE_ABSTRACT_TYPE( VipsForeignLoadPdf, vips_foreign_load_pdf,
VIPS_TYPE_FOREIGN_LOAD );
static void
vips_foreign_load_pdf_close( VipsForeignLoadPdf *pdf )
{
VIPS_UNREF( pdf->page );
VIPS_UNREF( pdf->doc );
}
static void
vips_foreign_load_pdf_dispose( GObject *gobject )
{
VipsForeignLoadPdf *pdf = (VipsForeignLoadPdf *) gobject;
VIPS_UNREF( pdf->page );
VIPS_UNREF( pdf->doc );
vips_foreign_load_pdf_close( pdf );
G_OBJECT_CLASS( vips_foreign_load_pdf_parent_class )->
dispose( gobject );
@ -328,6 +336,7 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
void *seq, void *a, void *b, gboolean *stop )
{
VipsForeignLoadPdf *pdf = (VipsForeignLoadPdf *) a;
VipsForeignLoad *load = (VipsForeignLoad *) pdf;
VipsRect *r = &or->valid;
int top;
@ -386,11 +395,18 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
i += 1;
}
/* In seq mode, we can shut down the input when we render the last
* row.
*/
if( top >= or->im->Ysize &&
load->access == VIPS_ACCESS_SEQUENTIAL )
vips_foreign_load_pdf_close( pdf );
/* Cairo makes pre-multipled BRGA, we must byteswap and unpremultiply.
*/
for( y = 0; y < r->height; y++ )
vips__cairo2rgba(
(guint32 *) VIPS_REGION_ADDR( or, r->left, r->top + y ),
(guint32 *) VIPS_REGION_ADDR( or, r->left, r->top + y ),
r->width );
return( 0 );
@ -763,8 +779,8 @@ vips_pdfload( const char *filename, VipsImage **out, ... )
* * @scale: %gdouble, scale render by this factor
* * @background: #VipsArrayDouble background colour
*
* Read a PDF-formatted memory block into a VIPS image. Exactly as
* vips_pdfload(), but read from a memory buffer.
* Read a PDF-formatted memory buffer into a VIPS image. Exactly as
* vips_pdfload(), but read from memory.
*
* You must not free the buffer while @out is active. The
* #VipsObject::postclose signal on @out is a good place to free.

View File

@ -4,6 +4,8 @@
* - from pdfload.c
* 8/6/18
* - add background param
* 16/8/18
* - shut down the input file as soon as we can [kleisauke]
*/
/*
@ -134,15 +136,22 @@ vips_pdfium_error( void )
vips_error( "pdfload", "%s", _( "unknown error" ) );
}
static void
vips_foreign_load_pdf_close( VipsForeignLoadPdf *pdf )
{
VIPS_FREEF( FPDF_ClosePage, pdf->page );
VIPS_FREEF( FPDF_CloseDocument, pdf->doc );
}
static void
vips_foreign_load_pdf_dispose( GObject *gobject )
{
VipsForeignLoadPdf *pdf = (VipsForeignLoadPdf *) gobject;
VIPS_FREEF( FPDF_ClosePage, pdf->page );
VIPS_FREEF( FPDF_CloseDocument, pdf->doc );
vips_foreign_load_pdf_close( pdf );
G_OBJECT_CLASS( vips_foreign_load_pdf_parent_class )->dispose( gobject );
G_OBJECT_CLASS( vips_foreign_load_pdf_parent_class )->
dispose( gobject );
}
static void *
@ -373,6 +382,7 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
void *seq, void *a, void *b, gboolean *stop )
{
VipsForeignLoadPdf *pdf = (VipsForeignLoadPdf *) a;
VipsForeignLoad *load = (VipsForeignLoad *) pdf;
VipsRect *r = &or->valid;
int top;
@ -423,6 +433,13 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
i += 1;
}
/* In seq mode, we can shut down the input when we render the last
* row.
*/
if( top >= or->im->Ysize &&
load->access == VIPS_ACCESS_SEQUENTIAL )
vips_foreign_load_pdf_close( pdf );
/* PDFium writes BRGA, we must swap.
*
* FIXME ... this is a bit slow.