add n-pages metadata item
tiff, magick and pdf load now attach an n-pages metadata item recording the number of pages in the orginal file see https://github.com/jcupitt/libvips/issues/953
This commit is contained in:
parent
4f22e8d1dc
commit
da6f4fd043
@ -18,6 +18,7 @@
|
|||||||
- add @format option to magickload
|
- add @format option to magickload
|
||||||
- jpegload adds a jpeg-chroma-subsample field with eg. 4:4:4 for no
|
- jpegload adds a jpeg-chroma-subsample field with eg. 4:4:4 for no
|
||||||
chrominance subsampling.
|
chrominance subsampling.
|
||||||
|
- tiffload, pdfload, magickload set VIPS_META_N_PAGES "n-pages" metadata item
|
||||||
|
|
||||||
12/3/18 started 8.6.4
|
12/3/18 started 8.6.4
|
||||||
- better fitting of fonts with overhanging edges [Adrià]
|
- better fitting of fonts with overhanging edges [Adrià]
|
||||||
|
@ -134,7 +134,14 @@ typedef struct _Read {
|
|||||||
ImageInfo *image_info;
|
ImageInfo *image_info;
|
||||||
ExceptionInfo exception;
|
ExceptionInfo exception;
|
||||||
|
|
||||||
|
/* Number of pages in image.
|
||||||
|
*/
|
||||||
|
int n_pages;
|
||||||
|
|
||||||
|
/* Number of pages we will read.
|
||||||
|
*/
|
||||||
int n_frames;
|
int n_frames;
|
||||||
|
|
||||||
Image **frames;
|
Image **frames;
|
||||||
int frame_height;
|
int frame_height;
|
||||||
|
|
||||||
@ -203,6 +210,7 @@ read_new( const char *filename, VipsImage *im,
|
|||||||
read->image = NULL;
|
read->image = NULL;
|
||||||
read->image_info = CloneImageInfo( NULL );
|
read->image_info = CloneImageInfo( NULL );
|
||||||
GetExceptionInfo( &read->exception );
|
GetExceptionInfo( &read->exception );
|
||||||
|
read->n_pages = 0;
|
||||||
read->n_frames = 0;
|
read->n_frames = 0;
|
||||||
read->frames = NULL;
|
read->frames = NULL;
|
||||||
read->frame_height = 0;
|
read->frame_height = 0;
|
||||||
@ -488,6 +496,7 @@ parse_header( Read *read )
|
|||||||
which says this is a volumetric image
|
which says this is a volumetric image
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
read->n_pages = GetImageListLength( image );
|
||||||
read->n_frames = 0;
|
read->n_frames = 0;
|
||||||
for( p = image; p; (p = GetNextImageInList( p )) ) {
|
for( p = image; p; (p = GetNextImageInList( p )) ) {
|
||||||
if( p->columns != (unsigned int) im->Xsize ||
|
if( p->columns != (unsigned int) im->Xsize ||
|
||||||
@ -512,7 +521,7 @@ parse_header( Read *read )
|
|||||||
read->n_frames = 1;
|
read->n_frames = 1;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf( "image has %d frames\n", read->n_frames );
|
printf( "will read %d frames\n", read->n_frames );
|
||||||
#endif /*DEBUG*/
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
if( read->n != -1 )
|
if( read->n != -1 )
|
||||||
@ -533,6 +542,8 @@ parse_header( Read *read )
|
|||||||
im->Ysize *= read->n_frames;
|
im->Ysize *= read->n_frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vips_image_set_int( im, VIPS_META_N_PAGES, read->n_pages );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,11 @@ typedef struct _VipsForeignLoadMagick7 {
|
|||||||
ImageInfo *image_info;
|
ImageInfo *image_info;
|
||||||
ExceptionInfo *exception;
|
ExceptionInfo *exception;
|
||||||
|
|
||||||
int n_frames; /* Number of frames in file */
|
/* Number of pages in image.
|
||||||
|
*/
|
||||||
|
int n_pages;
|
||||||
|
|
||||||
|
int n_frames; /* Number of frames we will read */
|
||||||
Image **frames; /* An Image* for each frame */
|
Image **frames; /* An Image* for each frame */
|
||||||
CacheView **cache_view; /* A CacheView for each frame */
|
CacheView **cache_view; /* A CacheView for each frame */
|
||||||
int frame_height;
|
int frame_height;
|
||||||
@ -283,26 +287,6 @@ vips_foreign_load_magick7_dispose( GObject *gobject )
|
|||||||
dispose( gobject );
|
dispose( gobject );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
|
||||||
vips_foreign_load_magick7_genesis_cb( void *client )
|
|
||||||
{
|
|
||||||
#ifdef DEBUG
|
|
||||||
printf( "vips_foreign_load_magick7_genesis:\n" );
|
|
||||||
#endif /*DEBUG*/
|
|
||||||
|
|
||||||
MagickCoreGenesis( vips_get_argv0(), MagickFalse );
|
|
||||||
|
|
||||||
return( NULL );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
vips_foreign_load_magick7_genesis( void )
|
|
||||||
{
|
|
||||||
static GOnce once = G_ONCE_INIT;
|
|
||||||
|
|
||||||
VIPS_ONCE( &once, vips_foreign_load_magick7_genesis_cb, NULL );
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vips_foreign_load_magick7_build( VipsObject *object )
|
vips_foreign_load_magick7_build( VipsObject *object )
|
||||||
{
|
{
|
||||||
@ -578,14 +562,15 @@ vips_foreign_load_magick7_parse( VipsForeignLoadMagick7 *magick7,
|
|||||||
which says this is a volumetric image
|
which says this is a volumetric image
|
||||||
|
|
||||||
*/
|
*/
|
||||||
magick7->n_frames = GetImageListLength( GetFirstImageInList( image ) );
|
magick7->n_pages = GetImageListLength( GetFirstImageInList( image ) );
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf( "image has %d frames\n", magick7->n_frames );
|
printf( "image has %d pages\n", magick7->n_pages );
|
||||||
#endif /*DEBUG*/
|
#endif /*DEBUG*/
|
||||||
|
|
||||||
if( magick7->n != -1 )
|
magick7->n_frames = magick7->n != -1 ?
|
||||||
magick7->n_frames = VIPS_MIN( magick7->n_frames, magick7->n );
|
VIPS_MIN( magick7->n_frames, magick7->n ) :
|
||||||
|
magick7->n_pages;
|
||||||
|
|
||||||
/* So we can finally set the height.
|
/* So we can finally set the height.
|
||||||
*/
|
*/
|
||||||
@ -594,11 +579,13 @@ vips_foreign_load_magick7_parse( VipsForeignLoadMagick7 *magick7,
|
|||||||
out->Ysize *= magick7->n_frames;
|
out->Ysize *= magick7->n_frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vips_image_set_int( out, VIPS_META_N_PAGES, magick7->n_pages );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We don't bother with GetPixelReadMask(), assume it's everywhere. Don't
|
/* We don't bother with GetPixelReadMask(), assume it's everywhere. Don't
|
||||||
* bother with traits, assume taht's always update.
|
* bother with traits, assume that's always updated.
|
||||||
*
|
*
|
||||||
* We do skip index channels. Palette images add extra index channels
|
* We do skip index channels. Palette images add extra index channels
|
||||||
* containing the index value from the file before colourmap lookup.
|
* containing the index value from the file before colourmap lookup.
|
||||||
@ -753,7 +740,7 @@ ismagick7( const char *filename )
|
|||||||
ExceptionInfo *exception;
|
ExceptionInfo *exception;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
vips_foreign_load_magick7_genesis();
|
magick_genesis();
|
||||||
|
|
||||||
/* Horribly slow :-(
|
/* Horribly slow :-(
|
||||||
*/
|
*/
|
||||||
@ -853,7 +840,7 @@ vips_foreign_load_magick7_buffer_is_a_buffer( const void *buf, size_t len )
|
|||||||
ExceptionInfo *exception;
|
ExceptionInfo *exception;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
vips_foreign_load_magick7_genesis();
|
magick_genesis();
|
||||||
|
|
||||||
/* Horribly slow :-(
|
/* Horribly slow :-(
|
||||||
*/
|
*/
|
||||||
|
@ -204,9 +204,10 @@ vips_foreign_load_pdf_set_image( VipsForeignLoadPdf *pdf, VipsImage *out )
|
|||||||
*/
|
*/
|
||||||
vips_image_pipelinev( out, VIPS_DEMAND_STYLE_FATSTRIP, NULL );
|
vips_image_pipelinev( out, VIPS_DEMAND_STYLE_FATSTRIP, NULL );
|
||||||
|
|
||||||
/* Extract and attach metadata.
|
/* Extract and attach metadata. Set the old name too for compat.
|
||||||
*/
|
*/
|
||||||
vips_image_set_int( out, "pdf-n_pages", pdf->n_pages );
|
vips_image_set_int( out, "pdf-n_pages", pdf->n_pages );
|
||||||
|
vips_image_set_int( out, VIPS_META_N_PAGES, pdf->n_pages );
|
||||||
|
|
||||||
for( i = 0; i < n_metadata; i++ ) {
|
for( i = 0; i < n_metadata; i++ ) {
|
||||||
VipsForeignLoadPdfMetadata *metadata =
|
VipsForeignLoadPdfMetadata *metadata =
|
||||||
|
@ -241,9 +241,10 @@ vips_foreign_load_pdf_set_image( VipsForeignLoadPdf *pdf, VipsImage *out )
|
|||||||
*/
|
*/
|
||||||
vips_image_pipelinev( out, VIPS_DEMAND_STYLE_FATSTRIP, NULL );
|
vips_image_pipelinev( out, VIPS_DEMAND_STYLE_FATSTRIP, NULL );
|
||||||
|
|
||||||
/* Extract and attach metadata.
|
/* Extract and attach metadata. Set the old name too for compat.
|
||||||
*/
|
*/
|
||||||
vips_image_set_int( out, "pdf-n_pages", pdf->n_pages );
|
vips_image_set_int( out, "pdf-n_pages", pdf->n_pages );
|
||||||
|
vips_image_set_int( out, VIPS_META_N_PAGES, pdf->n_pages );
|
||||||
|
|
||||||
for( i = 0; i < n_metadata; i++ ) {
|
for( i = 0; i < n_metadata; i++ ) {
|
||||||
VipsForeignLoadPdfMetadata *metadata =
|
VipsForeignLoadPdfMetadata *metadata =
|
||||||
|
@ -177,6 +177,8 @@
|
|||||||
* - remove missing res warning
|
* - remove missing res warning
|
||||||
* 19/5/17
|
* 19/5/17
|
||||||
* - page > 0 could break edge tiles or strips
|
* - page > 0 could break edge tiles or strips
|
||||||
|
* 26/4/18
|
||||||
|
* - add n-pages metadata item
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -283,6 +285,10 @@ typedef struct _Rtiff {
|
|||||||
*/
|
*/
|
||||||
TIFF *tiff;
|
TIFF *tiff;
|
||||||
|
|
||||||
|
/* Number of pages (directories) in image.
|
||||||
|
*/
|
||||||
|
int n_pages;
|
||||||
|
|
||||||
/* The current page we have set.
|
/* The current page we have set.
|
||||||
*/
|
*/
|
||||||
int current_page;
|
int current_page;
|
||||||
@ -1230,6 +1236,8 @@ rtiff_set_header( Rtiff *rtiff, VipsImage *out )
|
|||||||
vips_image_set_int( out,
|
vips_image_set_int( out,
|
||||||
VIPS_META_PAGE_HEIGHT, rtiff->header.height );
|
VIPS_META_PAGE_HEIGHT, rtiff->header.height );
|
||||||
|
|
||||||
|
vips_image_set_int( out, VIPS_META_N_PAGES, rtiff->n_pages );
|
||||||
|
|
||||||
/* Even though we could end up serving tiled data, always hint
|
/* Even though we could end up serving tiled data, always hint
|
||||||
* THINSTRIP, since we're quite happy doing that too, and it could need
|
* THINSTRIP, since we're quite happy doing that too, and it could need
|
||||||
* a lot less memory.
|
* a lot less memory.
|
||||||
@ -1984,6 +1992,7 @@ rtiff_new( VipsImage *out, int page, int n, gboolean autorotate )
|
|||||||
rtiff->n = n;
|
rtiff->n = n;
|
||||||
rtiff->autorotate = autorotate;
|
rtiff->autorotate = autorotate;
|
||||||
rtiff->tiff = NULL;
|
rtiff->tiff = NULL;
|
||||||
|
rtiff->n_pages = 0;
|
||||||
rtiff->current_page = -1;
|
rtiff->current_page = -1;
|
||||||
rtiff->sfn = NULL;
|
rtiff->sfn = NULL;
|
||||||
rtiff->client = NULL;
|
rtiff->client = NULL;
|
||||||
@ -2167,8 +2176,9 @@ rtiff_header_read_all( Rtiff *rtiff )
|
|||||||
|
|
||||||
/* -1 means "to the end".
|
/* -1 means "to the end".
|
||||||
*/
|
*/
|
||||||
|
rtiff->n_pages = rtiff_n_pages( rtiff );
|
||||||
if( rtiff->n == -1 )
|
if( rtiff->n == -1 )
|
||||||
rtiff->n = rtiff_n_pages( rtiff ) - rtiff->page;
|
rtiff->n = rtiff->n_pages - rtiff->page;
|
||||||
|
|
||||||
/* If we're to read many pages, verify that they are all identical.
|
/* If we're to read many pages, verify that they are all identical.
|
||||||
*/
|
*/
|
||||||
|
@ -143,6 +143,13 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define VIPS_META_PAGE_HEIGHT "page-height"
|
#define VIPS_META_PAGE_HEIGHT "page-height"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* VIPS_META_N_PAGES:
|
||||||
|
*
|
||||||
|
* If set, the number of pages in the original file.
|
||||||
|
*/
|
||||||
|
#define VIPS_META_N_PAGES "n-pages"
|
||||||
|
|
||||||
guint64 vips_format_sizeof( VipsBandFormat format );
|
guint64 vips_format_sizeof( VipsBandFormat format );
|
||||||
guint64 vips_format_sizeof_unsafe( VipsBandFormat format );
|
guint64 vips_format_sizeof_unsafe( VipsBandFormat format );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user