2010-01-11 16:08:13 +01:00
|
|
|
/* VIPS thumbnailer
|
|
|
|
*
|
2010-01-14 15:02:46 +01:00
|
|
|
* 11/1/09
|
2010-01-13 18:35:05 +01:00
|
|
|
*
|
|
|
|
* 13/1/09
|
2010-01-13 19:03:27 +01:00
|
|
|
* - decode labq and rad images
|
2010-01-14 15:02:46 +01:00
|
|
|
* - colour management
|
|
|
|
* - better handling of tiny images
|
2010-01-25 17:28:34 +01:00
|
|
|
* 25/1/10
|
|
|
|
* - added "--delete"
|
2010-02-06 11:40:41 +01:00
|
|
|
* 6/2/10
|
|
|
|
* - added "--interpolator"
|
|
|
|
* - added "--nosharpen"
|
|
|
|
* - better 'open' logic, test lazy flag now
|
2010-05-13 22:29:28 +02:00
|
|
|
* 13/5/10
|
|
|
|
* - oops hehe residual sharpen test was reversed
|
|
|
|
* - and the mask coefficients were messed up
|
2010-05-26 17:32:13 +02:00
|
|
|
* 26/5/10
|
|
|
|
* - delete failed if there was a profile
|
2010-07-04 22:05:20 +02:00
|
|
|
* 4/7/10
|
|
|
|
* - oops sharpening was turning off for integer shrinks, thanks Nicolas
|
2010-07-30 14:30:45 +02:00
|
|
|
* 30/7/10
|
|
|
|
* - use new "rd" mode rather than our own open via disc
|
2012-02-08 14:33:19 +01:00
|
|
|
* 8/2/12
|
|
|
|
* - use :seq mode for png images
|
2012-02-08 15:05:58 +01:00
|
|
|
* - shrink to a scanline cache to ensure we request pixels sequentially
|
|
|
|
* from the input
|
2012-06-13 10:40:33 +02:00
|
|
|
* 13/6/12
|
|
|
|
* - update the sequential stuff to the general method
|
2012-06-21 14:32:47 +02:00
|
|
|
* 21/6/12
|
|
|
|
* - remove "--nodelete" option, have a --delete option instead, off by
|
|
|
|
* default
|
|
|
|
* - much more gentle extra sharpening
|
2012-11-13 21:09:30 +01:00
|
|
|
* 13/11/12
|
|
|
|
* - allow absolute paths in -o (thanks fuho)
|
2013-05-03 14:56:38 +02:00
|
|
|
* 3/5/13
|
|
|
|
* - add optional sharpening mask from file
|
2013-07-10 12:05:45 +02:00
|
|
|
* 10/7/13
|
|
|
|
* - rewrite for vips8
|
|
|
|
* - handle embedded jpeg thumbnails
|
2013-11-12 10:53:41 +01:00
|
|
|
* 12/11/13
|
|
|
|
* - add --linear option
|
2013-12-18 15:23:39 +01:00
|
|
|
* 18/12/13
|
|
|
|
* - add --crop option
|
2014-03-05 12:41:16 +01:00
|
|
|
* 5/3/14
|
|
|
|
* - copy main image metadata to embedded thumbnails, thanks ottob
|
2014-03-06 23:41:56 +01:00
|
|
|
* 6/3/14
|
|
|
|
* - add --rotate flag
|
2014-03-07 17:57:20 +01:00
|
|
|
* 7/3/14
|
|
|
|
* - remove the embedded thumbnail reader, embedded thumbnails are too
|
|
|
|
* unlike the main image wrt. rotation / colour / etc.
|
2014-06-30 13:07:00 +02:00
|
|
|
* 30/6/14
|
|
|
|
* - fix interlaced thumbnail output, thanks lovell
|
2014-08-04 10:55:18 +02:00
|
|
|
* 3/8/14
|
2014-08-11 11:26:12 +02:00
|
|
|
* - box shrink less, use interpolator more, if window_size is large
|
2014-08-04 10:55:18 +02:00
|
|
|
* enough
|
2014-08-11 11:26:12 +02:00
|
|
|
* - default to bicubic if available
|
|
|
|
* - add an anti-alias filter between shrink and affine
|
2014-08-11 17:48:51 +02:00
|
|
|
* - support CMYK
|
|
|
|
* - use SEQ_UNBUF for a memory saving
|
2010-01-11 16:08:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
#include <vips/intl.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2010-05-25 18:46:03 +02:00
|
|
|
#include <locale.h>
|
2010-01-11 16:08:13 +01:00
|
|
|
|
|
|
|
#include <vips/vips.h>
|
|
|
|
|
2014-03-06 20:39:18 +01:00
|
|
|
#define ORIENTATION ("exif-ifd0-Orientation")
|
|
|
|
|
2014-08-11 11:26:12 +02:00
|
|
|
/* Default settings. We change the default to bicubic in main() if
|
2014-08-04 10:55:18 +02:00
|
|
|
* this vips has been compiled with bicubic support.
|
|
|
|
*/
|
|
|
|
|
2013-10-23 10:37:45 +02:00
|
|
|
static char *thumbnail_size = "128";
|
|
|
|
static int thumbnail_width = 128;
|
|
|
|
static int thumbnail_height = 128;
|
2010-02-06 11:40:41 +01:00
|
|
|
static char *output_format = "tn_%s.jpg";
|
2012-09-04 15:56:22 +02:00
|
|
|
static char *interpolator = "bilinear";
|
2010-01-14 15:00:12 +01:00
|
|
|
static char *export_profile = NULL;
|
|
|
|
static char *import_profile = NULL;
|
2013-05-06 15:01:29 +02:00
|
|
|
static char *convolution_mask = "mild";
|
2012-06-21 14:32:47 +02:00
|
|
|
static gboolean delete_profile = FALSE;
|
2013-11-12 10:53:41 +01:00
|
|
|
static gboolean linear_processing = FALSE;
|
2013-12-18 15:23:39 +01:00
|
|
|
static gboolean crop_image = FALSE;
|
2014-03-06 20:39:18 +01:00
|
|
|
static gboolean rotate_image = FALSE;
|
2010-01-11 16:08:13 +01:00
|
|
|
|
2013-05-03 14:56:38 +02:00
|
|
|
/* Deprecated and unused.
|
|
|
|
*/
|
|
|
|
static gboolean nosharpen = FALSE;
|
|
|
|
static gboolean nodelete_profile = FALSE;
|
2013-11-09 14:10:11 +01:00
|
|
|
static gboolean verbose = FALSE;
|
2013-05-03 14:56:38 +02:00
|
|
|
|
2010-01-11 16:08:13 +01:00
|
|
|
static GOptionEntry options[] = {
|
2012-07-20 14:34:05 +02:00
|
|
|
{ "size", 's', 0,
|
2013-10-23 10:37:45 +02:00
|
|
|
G_OPTION_ARG_STRING, &thumbnail_size,
|
|
|
|
N_( "shrink to SIZE or to WIDTHxHEIGHT" ),
|
2010-05-26 13:26:09 +02:00
|
|
|
N_( "SIZE" ) },
|
2012-07-20 14:34:05 +02:00
|
|
|
{ "output", 'o', 0,
|
|
|
|
G_OPTION_ARG_STRING, &output_format,
|
2010-05-26 13:26:09 +02:00
|
|
|
N_( "set output to FORMAT" ),
|
|
|
|
N_( "FORMAT" ) },
|
2012-07-20 14:34:05 +02:00
|
|
|
{ "interpolator", 'p', 0,
|
|
|
|
G_OPTION_ARG_STRING, &interpolator,
|
2010-05-26 13:26:09 +02:00
|
|
|
N_( "resample with INTERPOLATOR" ),
|
|
|
|
N_( "INTERPOLATOR" ) },
|
2013-05-03 14:56:38 +02:00
|
|
|
{ "sharpen", 'r', 0,
|
|
|
|
G_OPTION_ARG_STRING, &convolution_mask,
|
2013-05-06 15:01:29 +02:00
|
|
|
N_( "sharpen with none|mild|MASKFILE" ),
|
|
|
|
N_( "none|mild|MASKFILE" ) },
|
2012-07-20 14:34:05 +02:00
|
|
|
{ "eprofile", 'e', 0,
|
|
|
|
G_OPTION_ARG_STRING, &export_profile,
|
2010-05-26 13:26:09 +02:00
|
|
|
N_( "export with PROFILE" ),
|
|
|
|
N_( "PROFILE" ) },
|
2012-07-20 14:34:05 +02:00
|
|
|
{ "iprofile", 'i', 0,
|
|
|
|
G_OPTION_ARG_STRING, &import_profile,
|
2010-05-26 13:26:09 +02:00
|
|
|
N_( "import untagged images with PROFILE" ),
|
|
|
|
N_( "PROFILE" ) },
|
2013-11-12 10:53:41 +01:00
|
|
|
{ "linear", 'a', 0,
|
|
|
|
G_OPTION_ARG_NONE, &linear_processing,
|
|
|
|
N_( "process in linear space" ), NULL },
|
2013-12-18 15:23:39 +01:00
|
|
|
{ "crop", 'c', 0,
|
|
|
|
G_OPTION_ARG_NONE, &crop_image,
|
|
|
|
N_( "crop exactly to SIZE" ), NULL },
|
2014-03-06 20:39:18 +01:00
|
|
|
{ "rotate", 't', 0,
|
|
|
|
G_OPTION_ARG_NONE, &rotate_image,
|
|
|
|
N_( "auto-rotate" ), NULL },
|
2012-07-20 14:34:05 +02:00
|
|
|
{ "delete", 'd', 0,
|
|
|
|
G_OPTION_ARG_NONE, &delete_profile,
|
2012-06-21 14:32:47 +02:00
|
|
|
N_( "delete profile from exported image" ), NULL },
|
2013-08-07 10:57:18 +02:00
|
|
|
{ "verbose", 'v', G_OPTION_FLAG_HIDDEN,
|
2013-11-09 14:10:11 +01:00
|
|
|
G_OPTION_ARG_NONE, &verbose,
|
2013-08-07 10:57:18 +02:00
|
|
|
N_( "(deprecated, does nothing)" ), NULL },
|
2013-05-03 14:56:38 +02:00
|
|
|
{ "nodelete", 'l', G_OPTION_FLAG_HIDDEN,
|
|
|
|
G_OPTION_ARG_NONE, &nodelete_profile,
|
|
|
|
N_( "(deprecated, does nothing)" ), NULL },
|
|
|
|
{ "nosharpen", 'n', G_OPTION_FLAG_HIDDEN,
|
|
|
|
G_OPTION_ARG_NONE, &nosharpen,
|
|
|
|
N_( "(deprecated, does nothing)" ), NULL },
|
2010-01-11 16:08:13 +01:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2014-03-06 20:39:18 +01:00
|
|
|
static VipsAngle
|
|
|
|
get_angle( VipsImage *im )
|
|
|
|
{
|
|
|
|
VipsAngle angle;
|
|
|
|
const char *orientation;
|
|
|
|
|
|
|
|
angle = VIPS_ANGLE_0;
|
|
|
|
|
2014-03-07 00:24:46 +01:00
|
|
|
if( vips_image_get_typeof( im, ORIENTATION ) &&
|
|
|
|
!vips_image_get_string( im, ORIENTATION, &orientation ) ) {
|
|
|
|
if( vips_isprefix( "6", orientation ) )
|
|
|
|
angle = VIPS_ANGLE_90;
|
2014-03-10 14:25:02 +01:00
|
|
|
else if( vips_isprefix( "8", orientation ) )
|
|
|
|
angle = VIPS_ANGLE_270;
|
|
|
|
else if( vips_isprefix( "3", orientation ) )
|
|
|
|
angle = VIPS_ANGLE_180;
|
|
|
|
|
|
|
|
/* Other values do rotate + mirror, don't bother handling them
|
|
|
|
* though, how common can mirroring be.
|
|
|
|
*
|
|
|
|
* See:
|
|
|
|
*
|
|
|
|
* http://www.80sidea.com/archives/2316
|
|
|
|
*/
|
2014-03-06 20:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return( angle );
|
|
|
|
}
|
|
|
|
|
2010-01-11 16:08:13 +01:00
|
|
|
/* Calculate the shrink factors.
|
|
|
|
*
|
|
|
|
* We shrink in two stages: first, a shrink with a block average. This can
|
|
|
|
* only accurately shrink by integer factors. We then do a second shrink with
|
2010-02-05 15:34:38 +01:00
|
|
|
* a supplied interpolator to get the exact size we want.
|
2014-08-04 10:55:18 +02:00
|
|
|
*
|
|
|
|
* We aim to do the second shrink by roughly half the interpolator's
|
|
|
|
* window_size.
|
2010-01-11 16:08:13 +01:00
|
|
|
*/
|
|
|
|
static int
|
2014-08-04 10:55:18 +02:00
|
|
|
calculate_shrink( VipsImage *im, double *residual,
|
|
|
|
VipsInterpolate *interp )
|
2010-01-11 16:08:13 +01:00
|
|
|
{
|
2014-03-06 20:39:18 +01:00
|
|
|
VipsAngle angle = get_angle( im );
|
|
|
|
gboolean rotate = angle == VIPS_ANGLE_90 || angle == VIPS_ANGLE_270;
|
|
|
|
int width = rotate_image && rotate ? im->Ysize : im->Xsize;
|
|
|
|
int height = rotate_image && rotate ? im->Xsize : im->Ysize;
|
2014-08-04 10:55:18 +02:00
|
|
|
const int window_size =
|
|
|
|
interp ? vips_interpolate_get_window_size( interp ) : 2;
|
2014-03-06 20:39:18 +01:00
|
|
|
|
2014-06-09 15:44:06 +02:00
|
|
|
VipsDirection direction;
|
|
|
|
|
2013-10-23 10:37:45 +02:00
|
|
|
/* Calculate the horizontal and vertical shrink we'd need to fit the
|
|
|
|
* image to the bounding box, and pick the biggest.
|
2013-12-18 15:23:39 +01:00
|
|
|
*
|
|
|
|
* In crop mode we aim to fill the bounding box, so we must use the
|
|
|
|
* smaller axis.
|
2010-01-11 16:08:13 +01:00
|
|
|
*/
|
2013-10-23 10:37:45 +02:00
|
|
|
double horizontal = (double) width / thumbnail_width;
|
|
|
|
double vertical = (double) height / thumbnail_height;
|
2014-06-09 15:44:06 +02:00
|
|
|
|
|
|
|
if( crop_image ) {
|
|
|
|
if( horizontal < vertical )
|
|
|
|
direction = VIPS_DIRECTION_HORIZONTAL;
|
|
|
|
else
|
|
|
|
direction = VIPS_DIRECTION_VERTICAL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if( horizontal < vertical )
|
|
|
|
direction = VIPS_DIRECTION_VERTICAL;
|
|
|
|
else
|
|
|
|
direction = VIPS_DIRECTION_HORIZONTAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
double factor = direction == VIPS_DIRECTION_HORIZONTAL ?
|
|
|
|
horizontal : vertical;
|
2010-01-11 16:08:13 +01:00
|
|
|
|
2013-10-23 10:37:45 +02:00
|
|
|
/* If the shrink factor is <= 1.0, we need to zoom rather than shrink.
|
2010-01-13 18:35:05 +01:00
|
|
|
* Just set the factor to 1 in this case.
|
|
|
|
*/
|
2010-01-14 14:39:46 +01:00
|
|
|
double factor2 = factor < 1.0 ? 1.0 : factor;
|
2010-01-13 18:35:05 +01:00
|
|
|
|
2014-08-04 10:55:18 +02:00
|
|
|
/* Int component of factor2.
|
|
|
|
*
|
|
|
|
* We want to shrink by less for interpolators with larger windows.
|
2010-01-11 16:08:13 +01:00
|
|
|
*/
|
2014-08-04 22:25:19 +02:00
|
|
|
int shrink = VIPS_MAX( 1,
|
|
|
|
floor( factor2 ) / VIPS_MAX( 1, window_size / 2 ) );
|
2010-01-11 16:08:13 +01:00
|
|
|
|
2014-06-09 15:44:06 +02:00
|
|
|
if( residual &&
|
|
|
|
direction == VIPS_DIRECTION_HORIZONTAL ) {
|
|
|
|
/* Size after int shrink.
|
2013-10-23 10:37:45 +02:00
|
|
|
*/
|
|
|
|
int iwidth = width / shrink;
|
2010-01-11 16:08:13 +01:00
|
|
|
|
2013-10-23 10:37:45 +02:00
|
|
|
/* Therefore residual scale factor is.
|
|
|
|
*/
|
2014-03-18 18:41:39 +01:00
|
|
|
double hresidual = (width / factor) / iwidth;
|
2014-06-09 15:44:06 +02:00
|
|
|
|
|
|
|
*residual = hresidual;
|
|
|
|
}
|
|
|
|
else if( residual &&
|
|
|
|
direction == VIPS_DIRECTION_VERTICAL ) {
|
|
|
|
int iheight = height / shrink;
|
2014-03-18 18:41:39 +01:00
|
|
|
double vresidual = (height / factor) / iheight;
|
|
|
|
|
2014-06-09 15:44:06 +02:00
|
|
|
*residual = vresidual;
|
2013-10-23 10:37:45 +02:00
|
|
|
}
|
2010-01-11 16:08:13 +01:00
|
|
|
|
|
|
|
return( shrink );
|
|
|
|
}
|
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
/* Find the best jpeg preload shrink.
|
2010-01-11 16:08:13 +01:00
|
|
|
*/
|
2013-07-10 12:05:45 +02:00
|
|
|
static int
|
|
|
|
thumbnail_find_jpegshrink( VipsImage *im )
|
2010-01-11 16:08:13 +01:00
|
|
|
{
|
2014-08-04 10:55:18 +02:00
|
|
|
int shrink = calculate_shrink( im, NULL, NULL );
|
2013-07-10 12:05:45 +02:00
|
|
|
|
2013-11-12 10:53:41 +01:00
|
|
|
/* We can't use pre-shrunk images in linear mode. libjpeg shrinks in Y
|
|
|
|
* (of YCbCR), not linear space.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( linear_processing )
|
|
|
|
return( 1 );
|
|
|
|
else if( shrink >= 8 )
|
2013-07-10 12:05:45 +02:00
|
|
|
return( 8 );
|
|
|
|
else if( shrink >= 4 )
|
|
|
|
return( 4 );
|
|
|
|
else if( shrink >= 2 )
|
|
|
|
return( 2 );
|
|
|
|
else
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open an image, returning the best version of that image for thumbnailing.
|
|
|
|
*
|
|
|
|
* libjpeg supports fast shrink-on-read, so if we have a JPEG, we can ask
|
|
|
|
* VIPS to load a lower resolution version.
|
|
|
|
*/
|
|
|
|
static VipsImage *
|
2013-11-13 10:00:47 +01:00
|
|
|
thumbnail_open( VipsObject *process, const char *filename )
|
2013-07-10 12:05:45 +02:00
|
|
|
{
|
|
|
|
const char *loader;
|
|
|
|
VipsImage *im;
|
|
|
|
|
2013-08-07 10:57:18 +02:00
|
|
|
vips_info( "vipsthumbnail", "thumbnailing %s", filename );
|
2013-07-10 12:05:45 +02:00
|
|
|
|
2013-11-12 10:53:41 +01:00
|
|
|
if( linear_processing )
|
|
|
|
vips_info( "vipsthumbnail", "linear mode" );
|
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
if( !(loader = vips_foreign_find_load( filename )) )
|
|
|
|
return( NULL );
|
|
|
|
|
2013-08-07 10:57:18 +02:00
|
|
|
vips_info( "vipsthumbnail", "selected loader is %s", loader );
|
2013-07-10 12:05:45 +02:00
|
|
|
|
|
|
|
if( strcmp( loader, "VipsForeignLoadJpegFile" ) == 0 ) {
|
2014-03-07 17:57:20 +01:00
|
|
|
int jpegshrink;
|
2013-07-10 12:05:45 +02:00
|
|
|
|
|
|
|
/* This will just read in the header and is quick.
|
|
|
|
*/
|
2014-06-07 17:47:53 +02:00
|
|
|
if( !(im = vips_image_new_from_file( filename, NULL )) )
|
2013-07-10 12:05:45 +02:00
|
|
|
return( NULL );
|
|
|
|
|
2014-03-07 17:57:20 +01:00
|
|
|
jpegshrink = thumbnail_find_jpegshrink( im );
|
|
|
|
|
|
|
|
g_object_unref( im );
|
|
|
|
|
|
|
|
vips_info( "vipsthumbnail",
|
|
|
|
"loading jpeg with factor %d pre-shrink",
|
|
|
|
jpegshrink );
|
|
|
|
|
2014-06-07 17:47:53 +02:00
|
|
|
if( !(im = vips_image_new_from_file( filename,
|
2014-08-11 17:48:51 +02:00
|
|
|
"access", VIPS_ACCESS_SEQUENTIAL_UNBUFFERED,
|
2014-03-07 17:57:20 +01:00
|
|
|
"shrink", jpegshrink,
|
2014-06-07 17:47:53 +02:00
|
|
|
NULL )) )
|
2014-03-07 17:57:20 +01:00
|
|
|
return( NULL );
|
2013-07-10 12:05:45 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* All other formats.
|
|
|
|
*/
|
2014-06-07 17:47:53 +02:00
|
|
|
if( !(im = vips_image_new_from_file( filename,
|
2014-08-11 17:48:51 +02:00
|
|
|
"access", VIPS_ACCESS_SEQUENTIAL_UNBUFFERED,
|
2014-06-07 17:47:53 +02:00
|
|
|
NULL )) )
|
2013-07-10 12:05:45 +02:00
|
|
|
return( NULL );
|
2010-01-11 16:08:13 +01:00
|
|
|
}
|
|
|
|
|
2013-11-13 10:00:47 +01:00
|
|
|
vips_object_local( process, im );
|
2013-07-10 12:05:45 +02:00
|
|
|
|
|
|
|
return( im );
|
2010-01-11 16:08:13 +01:00
|
|
|
}
|
|
|
|
|
2013-12-18 15:23:39 +01:00
|
|
|
static VipsInterpolate *
|
|
|
|
thumbnail_interpolator( VipsObject *process, VipsImage *in )
|
|
|
|
{
|
|
|
|
double residual;
|
|
|
|
VipsInterpolate *interp;
|
|
|
|
|
2014-08-04 10:55:18 +02:00
|
|
|
calculate_shrink( in, &residual, NULL );
|
2013-12-18 15:23:39 +01:00
|
|
|
|
|
|
|
/* For images smaller than the thumbnail, we upscale with nearest
|
2014-08-11 17:48:51 +02:00
|
|
|
* neighbor. Otherwise we make thumbnails that look fuzzy and awful.
|
2013-12-18 15:23:39 +01:00
|
|
|
*/
|
|
|
|
if( !(interp = VIPS_INTERPOLATE( vips_object_new_from_string(
|
|
|
|
g_type_class_ref( VIPS_TYPE_INTERPOLATE ),
|
|
|
|
residual > 1.0 ? "nearest" : interpolator ) )) )
|
|
|
|
return( NULL );
|
|
|
|
|
|
|
|
vips_object_local( process, interp );
|
|
|
|
|
|
|
|
return( interp );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some interpolators look a little soft, so we have an optional sharpening
|
|
|
|
* stage.
|
|
|
|
*/
|
|
|
|
static VipsImage *
|
|
|
|
thumbnail_sharpen( VipsObject *process )
|
|
|
|
{
|
|
|
|
VipsImage *mask;
|
|
|
|
|
|
|
|
if( strcmp( convolution_mask, "none" ) == 0 )
|
|
|
|
mask = NULL;
|
|
|
|
else if( strcmp( convolution_mask, "mild" ) == 0 ) {
|
|
|
|
mask = vips_image_new_matrixv( 3, 3,
|
|
|
|
-1.0, -1.0, -1.0,
|
|
|
|
-1.0, 32.0, -1.0,
|
|
|
|
-1.0, -1.0, -1.0 );
|
|
|
|
vips_image_set_double( mask, "scale", 24 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( !(mask =
|
2014-06-07 17:47:53 +02:00
|
|
|
vips_image_new_from_file( convolution_mask, NULL )) )
|
2013-12-18 15:23:39 +01:00
|
|
|
vips_error_exit( "unable to load sharpen mask" );
|
|
|
|
|
|
|
|
if( mask )
|
|
|
|
vips_object_local( process, mask );
|
|
|
|
|
|
|
|
return( mask );
|
|
|
|
}
|
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
static VipsImage *
|
2013-12-18 15:23:39 +01:00
|
|
|
thumbnail_shrink( VipsObject *process, VipsImage *in,
|
2013-11-12 21:51:16 +01:00
|
|
|
VipsInterpolate *interp, VipsImage *sharpen )
|
2010-01-11 16:08:13 +01:00
|
|
|
{
|
2013-12-18 15:23:39 +01:00
|
|
|
VipsImage **t = (VipsImage **) vips_object_local_array( process, 10 );
|
2013-11-12 10:53:41 +01:00
|
|
|
VipsInterpretation interpretation = linear_processing ?
|
|
|
|
VIPS_INTERPRETATION_XYZ : VIPS_INTERPRETATION_sRGB;
|
2013-07-10 12:05:45 +02:00
|
|
|
|
|
|
|
int shrink;
|
|
|
|
double residual;
|
2013-03-01 10:44:19 +01:00
|
|
|
int tile_width;
|
|
|
|
int tile_height;
|
|
|
|
int nlines;
|
2014-08-11 11:26:12 +02:00
|
|
|
double sigma;
|
2010-01-11 16:08:13 +01:00
|
|
|
|
2013-11-12 10:53:41 +01:00
|
|
|
/* RAD needs special unpacking.
|
2010-01-13 19:03:27 +01:00
|
|
|
*/
|
2013-11-12 21:51:16 +01:00
|
|
|
if( in->Coding == VIPS_CODING_RAD ) {
|
2013-08-07 10:57:18 +02:00
|
|
|
vips_info( "vipsthumbnail", "unpacking Rad to float" );
|
2010-01-13 19:03:27 +01:00
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
/* rad is scrgb.
|
|
|
|
*/
|
2013-11-12 10:53:41 +01:00
|
|
|
if( vips_rad2float( in, &t[0], NULL ) )
|
2013-07-10 12:05:45 +02:00
|
|
|
return( NULL );
|
2013-11-12 10:53:41 +01:00
|
|
|
in = t[0];
|
|
|
|
}
|
2013-07-10 12:05:45 +02:00
|
|
|
|
2013-11-12 10:53:41 +01:00
|
|
|
/* In linear mode, we import right at the start.
|
2014-08-11 17:48:51 +02:00
|
|
|
*
|
|
|
|
* We also have to import the whole image if it's CMYK, since
|
|
|
|
* vips_colourspace() (see below) doesn't know about CMYK.
|
2013-11-12 10:53:41 +01:00
|
|
|
*
|
|
|
|
* This is only going to work for images in device space. If you have
|
|
|
|
* an image in PCS which also has an attached profile, strange things
|
|
|
|
* will happen.
|
|
|
|
*/
|
2014-08-11 17:48:51 +02:00
|
|
|
if( (linear_processing ||
|
|
|
|
in->Type == VIPS_INTERPRETATION_CMYK) &&
|
2013-11-12 10:53:41 +01:00
|
|
|
in->Coding == VIPS_CODING_NONE &&
|
|
|
|
(in->BandFmt == VIPS_FORMAT_UCHAR ||
|
|
|
|
in->BandFmt == VIPS_FORMAT_USHORT) &&
|
|
|
|
(vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ||
|
|
|
|
import_profile) ) {
|
|
|
|
if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) )
|
|
|
|
vips_info( "vipsthumbnail",
|
|
|
|
"importing with embedded profile" );
|
|
|
|
else
|
|
|
|
vips_info( "vipsthumbnail",
|
|
|
|
"importing with profile %s", import_profile );
|
|
|
|
|
|
|
|
if( vips_icc_import( in, &t[1],
|
|
|
|
"input_profile", import_profile,
|
|
|
|
"embedded", TRUE,
|
2013-11-12 18:18:41 +01:00
|
|
|
"pcs", VIPS_PCS_XYZ,
|
2013-11-12 10:53:41 +01:00
|
|
|
NULL ) )
|
|
|
|
return( NULL );
|
|
|
|
|
|
|
|
in = t[1];
|
2010-01-13 19:03:27 +01:00
|
|
|
}
|
|
|
|
|
2013-11-12 10:53:41 +01:00
|
|
|
/* To the processing colourspace. This will unpack LABQ as well.
|
|
|
|
*/
|
|
|
|
vips_info( "vipsthumbnail", "converting to processing space %s",
|
|
|
|
vips_enum_nick( VIPS_TYPE_INTERPRETATION, interpretation ) );
|
|
|
|
if( vips_colourspace( in, &t[2], interpretation, NULL ) )
|
|
|
|
return( NULL );
|
|
|
|
in = t[2];
|
|
|
|
|
2014-08-04 10:55:18 +02:00
|
|
|
shrink = calculate_shrink( in, &residual, interp );
|
2013-07-10 12:05:45 +02:00
|
|
|
|
2013-08-07 10:57:18 +02:00
|
|
|
vips_info( "vipsthumbnail", "integer shrink by %d", shrink );
|
2013-07-10 12:05:45 +02:00
|
|
|
|
|
|
|
if( vips_shrink( in, &t[3], shrink, shrink, NULL ) )
|
|
|
|
return( NULL );
|
|
|
|
in = t[3];
|
2013-03-01 10:44:19 +01:00
|
|
|
|
|
|
|
/* We want to make sure we read the image sequentially.
|
2012-06-18 10:19:31 +02:00
|
|
|
* However, the convolution we may be doing later will force us
|
|
|
|
* into SMALLTILE or maybe FATSTRIP mode and that will break
|
2012-06-21 15:11:39 +02:00
|
|
|
* sequentiality.
|
2012-06-18 10:19:31 +02:00
|
|
|
*
|
|
|
|
* So ... read into a cache where tiles are scanlines, and make sure
|
|
|
|
* we keep enough scanlines to be able to serve a line of tiles.
|
2013-07-31 23:00:52 +02:00
|
|
|
*
|
|
|
|
* We use a threaded tilecache to avoid a deadlock: suppose thread1,
|
|
|
|
* evaluating the top block of the output, is delayed, and thread2,
|
|
|
|
* evaluating the second block, gets here first (this can happen on
|
|
|
|
* a heavily-loaded system).
|
|
|
|
*
|
|
|
|
* With an unthreaded tilecache (as we had before), thread2 will get
|
|
|
|
* the cache lock and start evaling the second block of the shrink.
|
|
|
|
* When it reaches the png reader it will stall until the first block
|
|
|
|
* has been used ... but it never will, since thread1 will block on
|
|
|
|
* this cache lock.
|
2010-01-13 19:03:27 +01:00
|
|
|
*/
|
2014-08-11 11:26:12 +02:00
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
vips_get_tile_size( in,
|
2013-03-01 10:44:19 +01:00
|
|
|
&tile_width, &tile_height, &nlines );
|
2013-07-10 12:05:45 +02:00
|
|
|
if( vips_tilecache( in, &t[4],
|
|
|
|
"tile_width", in->Xsize,
|
2013-03-01 11:29:01 +01:00
|
|
|
"tile_height", 10,
|
|
|
|
"max_tiles", (nlines * 2) / 10,
|
2013-10-01 12:23:42 +02:00
|
|
|
"access", VIPS_ACCESS_SEQUENTIAL,
|
2013-07-31 23:00:52 +02:00
|
|
|
"threaded", TRUE,
|
2014-08-11 11:26:12 +02:00
|
|
|
NULL ) )
|
2013-07-10 12:05:45 +02:00
|
|
|
return( NULL );
|
2014-08-11 11:26:12 +02:00
|
|
|
in = t[4];
|
|
|
|
|
|
|
|
/* If the final affine will be doing a large downsample, we can get
|
|
|
|
* nasty aliasing on hard edges. Blur before affine to smooth this out.
|
|
|
|
*
|
|
|
|
* Don't blur for very small shrinks, blur with radius 1 for x1.5
|
|
|
|
* shrinks, blur radius 2 for x2.5 shrinks and above, etc.
|
|
|
|
*/
|
|
|
|
sigma = ((1.0 / residual) - 0.5) / 1.5;
|
2014-08-11 17:48:51 +02:00
|
|
|
if( residual < 1.0 &&
|
|
|
|
sigma > 0.1 ) {
|
2014-08-11 11:26:12 +02:00
|
|
|
if( vips_gaussmat( &t[9], sigma, 0.2,
|
|
|
|
"separable", TRUE,
|
|
|
|
"integer", TRUE,
|
|
|
|
NULL ) ||
|
|
|
|
vips_convsep( in, &t[5], t[9], NULL ) )
|
|
|
|
return( NULL );
|
|
|
|
vips_info( "vipsthumbnail", "anti-alias, sigma %g",
|
|
|
|
sigma );
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf( "anti-alias blur matrix is:\n" );
|
|
|
|
vips_matrixprint( t[9], NULL );
|
|
|
|
#endif /*DEBUG*/
|
|
|
|
in = t[5];
|
|
|
|
}
|
|
|
|
|
|
|
|
if( vips_affine( in, &t[6], residual, 0, 0, residual,
|
|
|
|
"interpolate", interp,
|
|
|
|
NULL ) )
|
|
|
|
return( NULL );
|
|
|
|
in = t[6];
|
2013-07-10 12:05:45 +02:00
|
|
|
|
2013-08-07 10:57:18 +02:00
|
|
|
vips_info( "vipsthumbnail", "residual scale by %g", residual );
|
|
|
|
vips_info( "vipsthumbnail", "%s interpolation",
|
|
|
|
VIPS_OBJECT_GET_CLASS( interp )->nickname );
|
2012-02-08 15:05:58 +01:00
|
|
|
|
2013-11-12 10:53:41 +01:00
|
|
|
/* Colour management.
|
|
|
|
*
|
|
|
|
* In linear mode, just export. In device space mode, do a combined
|
|
|
|
* import/export to transform to the target space.
|
2010-01-14 14:39:46 +01:00
|
|
|
*/
|
2013-11-12 10:53:41 +01:00
|
|
|
if( linear_processing ) {
|
|
|
|
if( export_profile ||
|
|
|
|
vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) {
|
|
|
|
vips_info( "vipsthumbnail",
|
|
|
|
"exporting to device space with a profile" );
|
2013-11-12 18:18:41 +01:00
|
|
|
if( vips_icc_export( in, &t[7],
|
|
|
|
"output_profile", export_profile,
|
2013-11-12 10:53:41 +01:00
|
|
|
NULL ) )
|
|
|
|
return( NULL );
|
|
|
|
in = t[7];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vips_info( "vipsthumbnail", "converting to sRGB" );
|
2014-08-11 11:26:12 +02:00
|
|
|
if( vips_colourspace( in, &t[7],
|
2013-11-12 10:53:41 +01:00
|
|
|
VIPS_INTERPRETATION_sRGB, NULL ) )
|
|
|
|
return( NULL );
|
2014-08-11 11:26:12 +02:00
|
|
|
in = t[7];
|
2013-11-12 10:53:41 +01:00
|
|
|
}
|
2010-01-14 14:39:46 +01:00
|
|
|
}
|
2013-11-12 10:53:41 +01:00
|
|
|
else if( export_profile &&
|
2013-07-10 12:05:45 +02:00
|
|
|
(vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ||
|
2010-01-14 15:00:12 +01:00
|
|
|
import_profile) ) {
|
2013-08-07 10:57:18 +02:00
|
|
|
if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) )
|
|
|
|
vips_info( "vipsthumbnail",
|
|
|
|
"importing with embedded profile" );
|
|
|
|
else
|
|
|
|
vips_info( "vipsthumbnail",
|
|
|
|
"importing with profile %s", import_profile );
|
|
|
|
|
|
|
|
vips_info( "vipsthumbnail",
|
|
|
|
"exporting with profile %s", export_profile );
|
2010-02-05 15:34:38 +01:00
|
|
|
|
2014-08-11 11:26:12 +02:00
|
|
|
if( vips_icc_transform( in, &t[7], export_profile,
|
2013-07-10 12:05:45 +02:00
|
|
|
"input_profile", import_profile,
|
|
|
|
"embedded", TRUE,
|
|
|
|
NULL ) )
|
|
|
|
return( NULL );
|
2010-01-11 16:08:13 +01:00
|
|
|
|
2014-08-11 11:26:12 +02:00
|
|
|
in = t[7];
|
2013-11-12 10:53:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we are upsampling, don't sharpen, since nearest looks dumb
|
|
|
|
* sharpened.
|
|
|
|
*/
|
|
|
|
if( shrink >= 1 &&
|
|
|
|
residual <= 1.0 &&
|
|
|
|
sharpen ) {
|
|
|
|
vips_info( "vipsthumbnail", "sharpening thumbnail" );
|
2013-11-12 21:51:16 +01:00
|
|
|
if( vips_conv( in, &t[8], sharpen, NULL ) )
|
2013-11-12 10:53:41 +01:00
|
|
|
return( NULL );
|
|
|
|
in = t[8];
|
2010-01-11 16:08:13 +01:00
|
|
|
}
|
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
if( delete_profile &&
|
|
|
|
vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) {
|
2013-08-07 10:57:18 +02:00
|
|
|
vips_info( "vipsthumbnail",
|
|
|
|
"deleting profile from output image" );
|
2013-11-09 14:10:11 +01:00
|
|
|
if( !vips_image_remove( in, VIPS_META_ICC_NAME ) )
|
2013-07-10 12:05:45 +02:00
|
|
|
return( NULL );
|
2010-01-25 15:23:30 +01:00
|
|
|
}
|
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
return( in );
|
2010-01-11 16:08:13 +01:00
|
|
|
}
|
|
|
|
|
2013-12-18 15:23:39 +01:00
|
|
|
/* Crop down to the final size, if crop_image is set.
|
2013-07-10 12:05:45 +02:00
|
|
|
*/
|
2013-11-12 21:51:16 +01:00
|
|
|
static VipsImage *
|
2013-12-18 15:23:39 +01:00
|
|
|
thumbnail_crop( VipsObject *process, VipsImage *im )
|
2013-07-10 12:05:45 +02:00
|
|
|
{
|
2013-12-18 15:23:39 +01:00
|
|
|
VipsImage **t = (VipsImage **) vips_object_local_array( process, 2 );
|
2013-11-13 10:00:47 +01:00
|
|
|
|
2013-12-18 15:23:39 +01:00
|
|
|
if( crop_image ) {
|
|
|
|
int left = (im->Xsize - thumbnail_width) / 2;
|
|
|
|
int top = (im->Ysize - thumbnail_height) / 2;
|
2013-11-13 10:00:47 +01:00
|
|
|
|
2013-12-18 15:23:39 +01:00
|
|
|
if( vips_extract_area( im, &t[0], left, top,
|
|
|
|
thumbnail_width, thumbnail_height, NULL ) )
|
|
|
|
return( NULL );
|
|
|
|
im = t[0];
|
|
|
|
}
|
2010-02-05 15:34:38 +01:00
|
|
|
|
2013-12-18 15:23:39 +01:00
|
|
|
return( im );
|
2010-02-05 15:34:38 +01:00
|
|
|
}
|
|
|
|
|
2014-03-06 20:39:18 +01:00
|
|
|
/* Auto-rotate, if rotate_image is set.
|
|
|
|
*/
|
|
|
|
static VipsImage *
|
|
|
|
thumbnail_rotate( VipsObject *process, VipsImage *im )
|
|
|
|
{
|
2014-08-03 18:59:25 +02:00
|
|
|
VipsImage **t = (VipsImage **) vips_object_local_array( process, 2 );
|
|
|
|
VipsAngle angle = get_angle( im );
|
2014-03-06 20:39:18 +01:00
|
|
|
|
2014-08-03 18:59:25 +02:00
|
|
|
if( rotate_image &&
|
|
|
|
angle != VIPS_ANGLE_0 ) {
|
|
|
|
/* Need to copy to memory, we have to stay seq.
|
|
|
|
*/
|
|
|
|
t[0] = vips_image_new_memory();
|
|
|
|
if( vips_image_write( im, t[0] ) ||
|
|
|
|
vips_rot( t[0], &t[1], angle, NULL ) )
|
2014-03-06 20:39:18 +01:00
|
|
|
return( NULL );
|
2014-08-03 18:59:25 +02:00
|
|
|
im = t[1];
|
2014-03-06 23:41:56 +01:00
|
|
|
|
2014-03-07 00:24:46 +01:00
|
|
|
(void) vips_image_remove( im, ORIENTATION );
|
2014-03-06 20:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return( im );
|
|
|
|
}
|
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
/* Given (eg.) "/poop/somefile.png", write @im to the thumbnail name,
|
|
|
|
* (eg.) "/poop/tn_somefile.jpg".
|
2010-01-11 16:08:13 +01:00
|
|
|
*/
|
2013-07-10 12:05:45 +02:00
|
|
|
static int
|
2014-06-30 13:07:00 +02:00
|
|
|
thumbnail_write( VipsObject *process, VipsImage *im, const char *filename )
|
2010-01-11 16:08:13 +01:00
|
|
|
{
|
|
|
|
char *file;
|
|
|
|
char *p;
|
|
|
|
char buf[FILENAME_MAX];
|
2013-07-10 12:05:45 +02:00
|
|
|
char *output_name;
|
2010-01-11 16:08:13 +01:00
|
|
|
|
|
|
|
file = g_path_get_basename( filename );
|
|
|
|
|
2012-11-13 21:09:30 +01:00
|
|
|
/* Remove the suffix from the file portion.
|
|
|
|
*/
|
2010-01-11 16:08:13 +01:00
|
|
|
if( (p = strrchr( file, '.' )) )
|
|
|
|
*p = '\0';
|
|
|
|
|
2012-11-13 21:09:30 +01:00
|
|
|
/* output_format can be an absolute path, in which case we discard the
|
|
|
|
* path from the incoming file.
|
|
|
|
*/
|
2013-07-10 12:05:45 +02:00
|
|
|
vips_snprintf( buf, FILENAME_MAX, output_format, file );
|
2012-11-13 21:09:30 +01:00
|
|
|
if( g_path_is_absolute( output_format ) )
|
2013-07-10 12:05:45 +02:00
|
|
|
output_name = g_strdup( buf );
|
2012-11-13 21:09:30 +01:00
|
|
|
else {
|
|
|
|
char *dir;
|
|
|
|
|
|
|
|
dir = g_path_get_dirname( filename );
|
2013-07-10 12:05:45 +02:00
|
|
|
output_name = g_build_filename( dir, buf, NULL );
|
2012-11-13 21:09:30 +01:00
|
|
|
g_free( dir );
|
|
|
|
}
|
2010-01-11 16:08:13 +01:00
|
|
|
|
2013-08-07 10:57:18 +02:00
|
|
|
vips_info( "vipsthumbnail",
|
|
|
|
"thumbnailing %s as %s", filename, output_name );
|
2010-01-11 16:08:13 +01:00
|
|
|
|
|
|
|
g_free( file );
|
|
|
|
|
2014-08-03 18:59:25 +02:00
|
|
|
if( vips_image_write_to_file( im, output_name, NULL ) ) {
|
2013-07-10 12:05:45 +02:00
|
|
|
g_free( output_name );
|
2010-01-11 16:08:13 +01:00
|
|
|
return( -1 );
|
|
|
|
}
|
2013-07-10 12:05:45 +02:00
|
|
|
g_free( output_name );
|
2010-01-11 16:08:13 +01:00
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
return( 0 );
|
2010-01-11 16:08:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-11-13 10:00:47 +01:00
|
|
|
thumbnail_process( VipsObject *process, const char *filename )
|
2010-01-11 16:08:13 +01:00
|
|
|
{
|
2014-02-13 09:42:59 +01:00
|
|
|
VipsImage *sharpen = thumbnail_sharpen( process );
|
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
VipsImage *in;
|
|
|
|
VipsInterpolate *interp;
|
2013-11-13 10:00:47 +01:00
|
|
|
VipsImage *thumbnail;
|
2013-12-18 15:23:39 +01:00
|
|
|
VipsImage *crop;
|
2014-03-06 20:39:18 +01:00
|
|
|
VipsImage *rotate;
|
2013-11-13 10:00:47 +01:00
|
|
|
|
|
|
|
if( !(in = thumbnail_open( process, filename )) ||
|
|
|
|
!(interp = thumbnail_interpolator( process, in )) ||
|
|
|
|
!(thumbnail =
|
|
|
|
thumbnail_shrink( process, in, interp, sharpen )) ||
|
2013-12-18 15:23:39 +01:00
|
|
|
!(crop = thumbnail_crop( process, thumbnail )) ||
|
2014-03-06 20:39:18 +01:00
|
|
|
!(rotate = thumbnail_rotate( process, crop )) ||
|
2014-06-30 13:07:00 +02:00
|
|
|
thumbnail_write( process, rotate, filename ) )
|
2010-01-11 16:08:13 +01:00
|
|
|
return( -1 );
|
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
return( 0 );
|
2010-01-11 16:08:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
GOptionContext *context;
|
|
|
|
GError *error = NULL;
|
|
|
|
int i;
|
|
|
|
|
2014-08-18 16:27:10 +02:00
|
|
|
if( vips__init( argv[0] ) )
|
2013-07-10 12:05:45 +02:00
|
|
|
vips_error_exit( "unable to start VIPS" );
|
2010-05-25 18:46:03 +02:00
|
|
|
textdomain( GETTEXT_PACKAGE );
|
|
|
|
setlocale( LC_ALL, "" );
|
2010-01-11 16:08:13 +01:00
|
|
|
|
2014-08-11 11:26:12 +02:00
|
|
|
/* Does this vips have bicubic? Default to that if it
|
2014-08-04 10:55:18 +02:00
|
|
|
* does.
|
|
|
|
*/
|
2014-08-11 11:26:12 +02:00
|
|
|
if( vips_type_find( "VipsInterpolate", "bicubic" ) )
|
2014-08-04 10:55:18 +02:00
|
|
|
interpolator = "bicubic";
|
|
|
|
|
2010-01-11 16:08:13 +01:00
|
|
|
context = g_option_context_new( _( "- thumbnail generator" ) );
|
|
|
|
|
|
|
|
g_option_context_add_main_entries( context, options, GETTEXT_PACKAGE );
|
2013-07-10 12:05:45 +02:00
|
|
|
g_option_context_add_group( context, vips_get_option_group() );
|
2010-01-11 16:08:13 +01:00
|
|
|
|
|
|
|
if( !g_option_context_parse( context, &argc, &argv, &error ) ) {
|
|
|
|
if( error ) {
|
|
|
|
fprintf( stderr, "%s\n", error->message );
|
|
|
|
g_error_free( error );
|
|
|
|
}
|
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
vips_error_exit( "try \"%s --help\"", g_get_prgname() );
|
2010-01-11 16:08:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
g_option_context_free( context );
|
|
|
|
|
2013-10-23 10:37:45 +02:00
|
|
|
if( sscanf( thumbnail_size, "%d x %d",
|
|
|
|
&thumbnail_width, &thumbnail_height ) != 2 ) {
|
|
|
|
if( sscanf( thumbnail_size, "%d", &thumbnail_width ) != 1 )
|
|
|
|
vips_error_exit( "unable to parse size \"%s\" -- "
|
|
|
|
"use eg. 128 or 200x300", thumbnail_size );
|
|
|
|
|
|
|
|
thumbnail_height = thumbnail_width;
|
|
|
|
}
|
|
|
|
|
2013-07-10 12:05:45 +02:00
|
|
|
for( i = 1; i < argc; i++ ) {
|
2013-12-18 15:23:39 +01:00
|
|
|
/* Hang resources for processing this thumbnail off @process.
|
2013-07-10 12:05:45 +02:00
|
|
|
*/
|
2013-11-13 10:00:47 +01:00
|
|
|
VipsObject *process = VIPS_OBJECT( vips_image_new() );
|
2013-07-10 12:05:45 +02:00
|
|
|
|
2013-11-13 10:00:47 +01:00
|
|
|
if( thumbnail_process( process, argv[i] ) ) {
|
2010-01-11 16:08:13 +01:00
|
|
|
fprintf( stderr, "%s: unable to thumbnail %s\n",
|
|
|
|
argv[0], argv[i] );
|
2013-07-10 12:05:45 +02:00
|
|
|
fprintf( stderr, "%s", vips_error_buffer() );
|
|
|
|
vips_error_clear();
|
2010-01-11 16:08:13 +01:00
|
|
|
}
|
|
|
|
|
2013-11-13 10:00:47 +01:00
|
|
|
g_object_unref( process );
|
2013-07-10 12:05:45 +02:00
|
|
|
}
|
|
|
|
|
2011-09-24 11:17:32 +02:00
|
|
|
vips_shutdown();
|
|
|
|
|
2010-01-11 16:08:13 +01:00
|
|
|
return( 0 );
|
|
|
|
}
|