vipsthumbnail uses rd mode

This commit is contained in:
John Cupitt 2010-07-30 12:30:45 +00:00
parent 57d7d02214
commit bde8d1048e
3 changed files with 13 additions and 86 deletions

View File

@ -4,6 +4,7 @@
- added im_vips2bufpng()
- use GetTempPath() to pick a temp dir on Windows
- added "rd" mode to im_open()
- vipsthumbnail and vips use "rd"
12/5/10 started 7.22.2
- the conditional image of ifthenelse can be any format, a (!=0) is added if

View File

@ -33,6 +33,15 @@ will read image file
and write a 64 x 64 pixel thumbnail to the file
.B thumbnails/fred.png.
On Unix machines, vips
will create temporary files in "/tmp" by default. Use the environment variable
TMPDIR to change this location. On Windows, vips uses GetTempPath() to pick a
location, see the MS documentation.
Use the --vips-disc-threshold command-line switch, or the IM_DISC_THRESHOLD
environment variable, to make vipsthumbnail use memory rather than temporary
files.
.SH OPTIONS
.TP
.B -s N, --size=N
@ -58,18 +67,6 @@ prepended. You can add format options too, for example
.B tn_%s.jpg:20
will write JPEG images with Q set to 20.
.TP
.B -d N, --disc=N
Set disc use threshold to
.B N.
Images which cannot be opened directly need to be decompressed first. Images
which are smaller than
.B N
are decompressed to memory, images which are larger are decompressed to
temporary files. Use the
.B TMPDIR
environment variable to change the location for temporary files.
.TP
.B -p I, --interpolator=I
Resample with interpolator

View File

@ -19,6 +19,8 @@
* - delete failed if there was a profile
* 4/7/10
* - oops sharpening was turning off for integer shrinks, thanks Nicolas
* 30/7/10
* - use new "rd" mode rather than our own open via disc
*/
#ifdef HAVE_CONFIG_H
@ -36,7 +38,6 @@
static int thumbnail_size = 128;
static char *output_format = "tn_%s.jpg";
static int use_disc_threshold = 1024 * 1024;
static char *interpolator = "bilinear";;
static gboolean nosharpen = FALSE;
static char *export_profile = NULL;
@ -51,9 +52,6 @@ static GOptionEntry options[] = {
{ "output", 'o', 0, G_OPTION_ARG_STRING, &output_format,
N_( "set output to FORMAT" ),
N_( "FORMAT" ) },
{ "disc", 'd', 0, G_OPTION_ARG_INT, &use_disc_threshold,
N_( "set disc use threshold to BYTES" ),
N_( "BYTES" ) },
{ "interpolator", 'p', 0, G_OPTION_ARG_STRING, &interpolator,
N_( "resample with INTERPOLATOR" ),
N_( "INTERPOLATOR" ) },
@ -72,75 +70,6 @@ static GOptionEntry options[] = {
{ NULL }
};
/* Open an image, using a disc temporary for 'large' images.
*/
static IMAGE *
open_image( const char *filename )
{
IMAGE *im;
size_t size;
VipsFormatClass *format;
/* Normally we'd just im_open() the filename. But we want to control
* the process, so we use the lower-level API.
*/
/* Find a format and check the flags. Does this format support lazy
* load? If it does, we can just open the image directly.
*/
if( !(format = vips_format_for_file( filename )) )
return( NULL );
if( vips_format_get_flags( format, filename ) & VIPS_FORMAT_PARTIAL ) {
if( verbose )
printf( "format supports lazy read, "
"working directly from disc file\n" );
return( im_open( filename, "r" ) );
}
/* Get the header and try to predict uncompressed image size.
*/
if( !(im = im_open( "header", "p" )) )
return( NULL );
if( format->header( filename, im ) ) {
im_close( im );
return( NULL );
}
size = IM_IMAGE_SIZEOF_LINE( im ) * im->Ysize;
im_close( im );
/* If it's less than our threshold, decompress to memory.
*/
if( size < use_disc_threshold ) {
if( verbose )
printf( "small file, decompressing to memory\n" );
if( !(im = im_open( filename, "t" )) )
return( NULL );
}
else {
/* This makes a disc temp which be unlinked automatically
* when 'im' is closed. The temp is made in "/tmp", or
* "$TMPDIR/", if the environment variable is set.
*/
if( !(im = im__open_temp( "%s.v" )) )
return( NULL );
if( verbose )
printf( "large file, decompressing to disc temp %s\n",
im->filename );
}
/* Load into im, which is memory or disc, depending.
*/
if( format->load( filename, im ) ) {
im_close( im );
return( NULL );
}
return( im );
}
/* Calculate the shrink factors.
*
* We shrink in two stages: first, a shrink with a block average. This can
@ -370,7 +299,7 @@ thumbnail2( const char *filename )
char *tn_filename;
int result;
if( !(in = open_image( filename )) )
if( !(in = im_open( filename, "rd" )) )
return( -1 );
tn_filename = make_thumbnail_name( filename );