add fail-on to thumbnail

see https://github.com/libvips/libvips/discussions/2781
This commit is contained in:
John Cupitt 2022-04-28 09:08:34 +01:00
parent 43db3985d0
commit f06c9f3bcf
2 changed files with 28 additions and 0 deletions

View File

@ -18,6 +18,7 @@
- update libnsgif API [tlsa]
- deprecate "properties" option to dzsave (now always on)
- always set the min stack size for pthreads, if we can
- add fail-on to thumbnail
26/11/21 started 8.12.3
- better arg checking for hist_find_ndim [travisbell]

View File

@ -35,6 +35,8 @@
* mode
* 14/4/22
* - add a seq to thumbnail_image to stop cache thrashing
* 28/4/22
* - add fail-on
*/
/*
@ -113,6 +115,7 @@ typedef struct _VipsThumbnail {
char *export_profile;
char *import_profile;
VipsIntent intent;
VipsFailOn fail_on;
/* Bits of info we read from the input image when we get the header of
* the original.
@ -1017,6 +1020,13 @@ vips_thumbnail_class_init( VipsThumbnailClass *class )
G_STRUCT_OFFSET( VipsThumbnail, intent ),
VIPS_TYPE_INTENT, VIPS_INTENT_RELATIVE );
VIPS_ARG_ENUM( class, "fail-on", 121,
_( "Fail on" ),
_( "Error level to fail on" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsThumbnail, fail_on ),
VIPS_TYPE_FAIL_ON, VIPS_FAIL_ON_NONE );
/* BOOL args which default TRUE arguments don't work with the
* command-line -- GOption does not allow --auto-rotate=false.
*
@ -1039,6 +1049,7 @@ vips_thumbnail_init( VipsThumbnail *thumbnail )
thumbnail->height = 1;
thumbnail->auto_rotate = TRUE;
thumbnail->intent = VIPS_INTENT_RELATIVE;
thumbnail->fail_on = VIPS_FAIL_ON_NONE;
}
typedef struct _VipsThumbnailFile {
@ -1084,6 +1095,7 @@ vips_thumbnail_file_open( VipsThumbnail *thumbnail, double factor )
if( vips_isprefix( "VipsForeignLoadJpeg", thumbnail->loader ) ) {
return( vips_image_new_from_file( file->filename,
"access", VIPS_ACCESS_SEQUENTIAL,
"fail-on", thumbnail->fail_on,
"shrink", (int) factor,
NULL ) );
}
@ -1091,6 +1103,7 @@ vips_thumbnail_file_open( VipsThumbnail *thumbnail, double factor )
thumbnail->loader ) ) {
return( vips_image_new_from_file( file->filename,
"access", VIPS_ACCESS_SEQUENTIAL,
"fail-on", thumbnail->fail_on,
"level", (int) factor,
NULL ) );
}
@ -1099,6 +1112,7 @@ vips_thumbnail_file_open( VipsThumbnail *thumbnail, double factor )
vips_isprefix( "VipsForeignLoadWebp", thumbnail->loader ) ) {
return( vips_image_new_from_file( file->filename,
"access", VIPS_ACCESS_SEQUENTIAL,
"fail-on", thumbnail->fail_on,
"scale", 1.0 / factor,
NULL ) );
}
@ -1108,6 +1122,7 @@ vips_thumbnail_file_open( VipsThumbnail *thumbnail, double factor )
if( thumbnail->page_pyramid )
return( vips_image_new_from_file( file->filename,
"access", VIPS_ACCESS_SEQUENTIAL,
"fail-on", thumbnail->fail_on,
"page", (int) factor,
NULL ) );
else
@ -1122,27 +1137,32 @@ vips_thumbnail_file_open( VipsThumbnail *thumbnail, double factor )
if( thumbnail->subifd_pyramid )
return( vips_image_new_from_file( file->filename,
"access", VIPS_ACCESS_SEQUENTIAL,
"fail-on", thumbnail->fail_on,
"subifd", (int) factor,
NULL ) );
else if( thumbnail->page_pyramid )
return( vips_image_new_from_file( file->filename,
"access", VIPS_ACCESS_SEQUENTIAL,
"fail-on", thumbnail->fail_on,
"page", (int) factor,
NULL ) );
else
return( vips_image_new_from_file( file->filename,
"access", VIPS_ACCESS_SEQUENTIAL,
"fail-on", thumbnail->fail_on,
NULL ) );
}
else if( vips_isprefix( "VipsForeignLoadHeif", thumbnail->loader ) ) {
return( vips_image_new_from_file( file->filename,
"access", VIPS_ACCESS_SEQUENTIAL,
"fail-on", thumbnail->fail_on,
"thumbnail", (int) factor,
NULL ) );
}
else {
return( vips_image_new_from_file( file->filename,
"access", VIPS_ACCESS_SEQUENTIAL,
"fail-on", thumbnail->fail_on,
NULL ) );
}
}
@ -1194,6 +1214,7 @@ vips_thumbnail_file_init( VipsThumbnailFile *file )
* * @import_profile: %gchararray, fallback import ICC profile
* * @export_profile: %gchararray, export ICC profile
* * @intent: #VipsIntent, rendering intent
* * @fail_on: #VipsFailOn, load error types to fail on
*
* Make a thumbnail from a file. Shrinking is done in three stages: using any
* shrink-on-load features available in the file import library, using a block
@ -1238,6 +1259,9 @@ vips_thumbnail_file_init( VipsThumbnailFile *file )
* Use @intent to set the rendering intent for any ICC transform. The default
* is #VIPS_INTENT_RELATIVE.
*
* Use @fail_on to control the types of error that will cause loading to fail.
* The default is #VIPS_FAIL_ON_NONE, ie. thumbnail is permissive.
*
* See also: vips_thumbnail_buffer().
*
* Returns: 0 on success, -1 on error.
@ -1439,6 +1463,7 @@ vips_thumbnail_buffer_init( VipsThumbnailBuffer *buffer )
* * @import_profile: %gchararray, fallback import ICC profile
* * @export_profile: %gchararray, export ICC profile
* * @intent: #VipsIntent, rendering intent
* * @fail_on: #VipsFailOn, load error types to fail on
* * @option_string: %gchararray, extra loader options
*
* Exactly as vips_thumbnail(), but read from a memory buffer. One extra
@ -1652,6 +1677,7 @@ vips_thumbnail_source_init( VipsThumbnailSource *source )
* * @import_profile: %gchararray, fallback import ICC profile
* * @export_profile: %gchararray, export ICC profile
* * @intent: #VipsIntent, rendering intent
* * @fail_on: #VipsFailOn, load error types to fail on
* * @option_string: %gchararray, extra loader options
*
* Exactly as vips_thumbnail(), but read from a source. One extra
@ -1768,6 +1794,7 @@ vips_thumbnail_image_init( VipsThumbnailImage *image )
* * @import_profile: %gchararray, fallback import ICC profile
* * @export_profile: %gchararray, export ICC profile
* * @intent: #VipsIntent, rendering intent
* * @fail_on: #VipsFailOn, load error types to fail on
*
* Exactly as vips_thumbnail(), but read from an existing image.
*