Merge branch 'master' of github.com:jcupitt/libvips

This commit is contained in:
John Cupitt 2016-03-14 13:35:47 +00:00
commit 773b474116
31 changed files with 753 additions and 501 deletions

View File

@ -1,6 +1,6 @@
29/1/16 started 8.3
- add vips_reduce*() ... a fast path for bicubic downsize
- vips_resize() and vips_similarity() use it when they can
- add vips_reduce*() ... a fast path for affine downsize
- vips_resize() uses vips_reduce() with lanczos3 and better anti-alias
- bicubic is better on 32-bit int images
- add pdfload, svgload, gifload for PDF, SVG and GIF rendering
- vipsthumbnail knows about pdfload and svgload
@ -15,14 +15,16 @@
- faster hist_find (Lovell Fuller)
- webpload has a @shrink parameter for shrink-on-load
- vipsthumbnail knows about webp shrink-on-load
- more vips_resize() tuning, a bit quicker now
- better behaviour for vips_cast() shift of non-int types (thanks apacheark)
- python .bandrank() now works like .bandjoin()
- vipsthumbnail --interpolator and --sharpen are deprecated
- switches to disable PPM, Rad and Analyze support
27/1/16 started 8.2.3
- fix a crash with SPARC byte-order labq vips images
- fix parsing of filenames containing brackets, thanks shilpi230
- fix hist_entropy (lovell)
- small fixes to radiance load
12/1/16 started 8.2.2
- changes to ease compiling C++ binding with MSVC [Lovell Fuller]

4
TODO
View File

@ -1,4 +1,8 @@
- try orc version of reducev? and shrinkv? maybe shrinkh?
- try SEQ_UNBUFFERED on jpg source, get out of order error?
- could load pdf thumbnails?

View File

@ -618,6 +618,33 @@ if test x"$with_matio" != "xno"; then
])
fi
# not external libraries, but have options to disable them, helps to
# reduce attack surface
AC_ARG_WITH([ppm],
AS_HELP_STRING([--without-ppm], [build without ppm (default: with)]))
if test x"$with_ppm" != "xno"; then
AC_DEFINE(HAVE_PPM,1,[define to build ppm support.])
with_ppm=yes
fi
AC_ARG_WITH([analyze],
AS_HELP_STRING([--without-analyze], [build without analyze (default: with)]))
if test x"$with_analyze" != "xno"; then
AC_DEFINE(HAVE_ANALYZE,1,[define to build analyze support.])
with_analyze=yes
fi
AC_ARG_WITH([radiance],
AS_HELP_STRING([--without-radiance], [build without radiance (default: with)]))
if test x"$with_radiance" != "xno"; then
AC_DEFINE(HAVE_RADIANCE,1,[define to build radiance support.])
with_radiance=yes
fi
# cfitsio
AC_ARG_WITH([cfitsio],
AS_HELP_STRING([--without-cfitsio], [build without cfitsio (default: test)]))
@ -911,6 +938,9 @@ gobject introspection: $found_introspection
build vips7 Python binding: $with_python
install vips8 Python overrides: $enable_pyvips8
(requires pygobject-3.12.0 or later)
build radiance support: $with_radiance
build analyze support: $with_analyze
build PPM support: $with_ppm
* optional dependencies
use fftw3 for FFT: $with_fftw

View File

@ -18,6 +18,9 @@
* 16/12/14
* - default to int output to match vips_conv()
* - use @precision, not @integer
* 10/3/16
* - allow 1x1 masks
* - better size calc
*/
/*
@ -84,6 +87,10 @@ typedef struct _VipsGaussmatClass {
G_DEFINE_TYPE( VipsGaussmat, vips_gaussmat, VIPS_TYPE_CREATE );
/* Don't allow mask radius to go over this.
*/
#define MASK_SANITY (5000)
static int
vips_gaussmat_build( VipsObject *object )
{
@ -91,7 +98,7 @@ vips_gaussmat_build( VipsObject *object )
VipsCreate *create = VIPS_CREATE( object );
VipsGaussmat *gaussmat = (VipsGaussmat *) object;
double sig2 = 2. * gaussmat->sigma * gaussmat->sigma;
int max_x = 8 * gaussmat->sigma > 5000 ? 5000 : 8 * gaussmat->sigma ;
int max_x = VIPS_CLIP( 0, 8 * gaussmat->sigma, MASK_SANITY );
int x, y;
int width, height;
@ -114,7 +121,7 @@ vips_gaussmat_build( VipsObject *object )
return( -1 );
/* Find the size of the mask. Limit the mask size to 10k x 10k for
* sanity.
* sanity. We allow x == 0, meaning a 1x1 mask.
*/
for( x = 0; x < max_x; x++ ) {
double v = exp( - ((double)(x * x)) / sig2 );
@ -122,11 +129,11 @@ vips_gaussmat_build( VipsObject *object )
if( v < gaussmat->min_ampl )
break;
}
if( x == max_x ) {
if( x >= MASK_SANITY ) {
vips_error( class->nickname, "%s", _( "mask too large" ) );
return( -1 );
}
width = x * 2 + 1;
width = 2 * x - 1;
height = gaussmat->separable ? 1 : width;
vips_image_init_fields( create->out,

View File

@ -42,9 +42,6 @@
#include <vips/vips.h>
#include "../foreign/dbh.h"
#include "../foreign/analyze2vips.h"
static VipsFormatFlags
analyze_flags( const char *filename )
{
@ -61,7 +58,15 @@ isanalyze( const char *filename )
int
im_analyze2vips( const char *filename, IMAGE *out )
{
return( vips__analyze_read( filename, out ) );
VipsImage *t;
if( vips_analyzeload( filename, &t, NULL ) )
return( -1 );
if( vips_image_write( t, out ) ) {
g_object_unref( t );
return( -1 );
}
g_object_unref( t );
return( 0 );
}

View File

@ -50,6 +50,8 @@
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#ifdef HAVE_ANALYZE
#include <ctype.h>
#include <stdio.h>
#include <string.h>
@ -594,3 +596,4 @@ vips__analyze_read( const char *filename, VipsImage *out )
return( 0 );
}
#endif /*HAVE_ANALYZE*/

View File

@ -48,6 +48,8 @@
#include <vips/buf.h>
#include <vips/internal.h>
#ifdef HAVE_ANALYZE
#include "analyze2vips.h"
typedef struct _VipsForeignLoadAnalyze {
@ -142,6 +144,8 @@ vips_foreign_load_analyze_init( VipsForeignLoadAnalyze *analyze )
{
}
#endif /*HAVE_ANALYZE*/
/**
* vips_analyzeload:
* @filename: file to load

View File

@ -1665,22 +1665,31 @@ vips_foreign_operation_init( void )
extern GType vips_foreign_load_gif_file_get_type( void );
extern GType vips_foreign_load_gif_buffer_get_type( void );
vips_foreign_load_rad_get_type();
vips_foreign_save_rad_get_type();
vips_foreign_load_ppm_get_type();
vips_foreign_save_ppm_get_type();
vips_foreign_load_csv_get_type();
vips_foreign_save_csv_get_type();
vips_foreign_load_matrix_get_type();
vips_foreign_save_matrix_get_type();
vips_foreign_print_matrix_get_type();
vips_foreign_load_analyze_get_type();
vips_foreign_load_raw_get_type();
vips_foreign_save_raw_get_type();
vips_foreign_save_raw_fd_get_type();
vips_foreign_load_vips_get_type();
vips_foreign_save_vips_get_type();
#ifdef HAVE_ANALYZE
vips_foreign_load_analyze_get_type();
#endif /*HAVE_ANALYZE*/
#ifdef HAVE_PPM
vips_foreign_load_ppm_get_type();
vips_foreign_save_ppm_get_type();
#endif /*HAVE_PPM*/
#ifdef HAVE_RADIANCE
vips_foreign_load_rad_get_type();
vips_foreign_save_rad_get_type();
#endif /*HAVE_RADIANCE*/
#ifdef HAVE_POPPLER
vips_foreign_load_pdf_get_type();
vips_foreign_load_pdf_file_get_type();

View File

@ -68,6 +68,8 @@
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#ifdef HAVE_PPM
#include <ctype.h>
#include <stdio.h>
#include <string.h>
@ -825,3 +827,5 @@ vips__ppm_save( VipsImage *in, const char *filename,
return( 0 );
}
#endif /*HAVE_PPM*/

View File

@ -48,6 +48,8 @@
#include <vips/buf.h>
#include <vips/internal.h>
#ifdef HAVE_PPM
#include "ppm.h"
typedef struct _VipsForeignLoadPpm {
@ -142,6 +144,8 @@ vips_foreign_load_ppm_init( VipsForeignLoadPpm *ppm )
{
}
#endif /*HAVE_PPM*/
/**
* vips_ppmload:
* @filename: file to load

View File

@ -47,6 +47,8 @@
#include <vips/vips.h>
#ifdef HAVE_PPM
#include "ppm.h"
typedef struct _VipsForeignSavePpm {
@ -144,6 +146,8 @@ vips_foreign_save_ppm_init( VipsForeignSavePpm *ppm )
{
}
#endif /*HAVE_PPM*/
/**
* vips_ppmsave:
* @in: image to save

View File

@ -127,6 +127,8 @@
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#ifdef HAVE_RADIANCE
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
@ -653,16 +655,23 @@ buffer_need( Buffer *buffer, int require )
int remaining;
g_assert( require < BUFFER_MARGIN );
g_assert( buffer->length >= 0 );
g_assert( buffer->position >= 0 );
g_assert( buffer->position <= buffer->length );
remaining = buffer->length - buffer->position;
if( remaining < require ) {
size_t len;
memcpy( buffer->text,
/* Areas can overlap.
*/
memmove( buffer->text,
buffer->text + buffer->position, remaining );
buffer->position = 0;
buffer->length = remaining;
g_assert( buffer->length < BUFFER_MARGIN );
len = fread( buffer->text + buffer->length,
1, BUFFER_SIZE, buffer->fp );
buffer->length += len;
@ -687,6 +696,10 @@ scanline_read_old( Buffer *buffer, COLR *scanline, int width )
{
int rshift;
g_assert( buffer->length >= 0 );
g_assert( buffer->position >= 0 );
g_assert( buffer->position <= buffer->length );
rshift = 0;
while( width > 0 ) {
@ -728,6 +741,10 @@ scanline_read( Buffer *buffer, COLR *scanline, int width )
{
int i, j;
g_assert( buffer->length >= 0 );
g_assert( buffer->position >= 0 );
g_assert( buffer->position <= buffer->length );
/* Detect old-style scanlines.
*/
if( width < MINELEN ||
@ -996,8 +1013,10 @@ static const char *colcor_name[3] = {
static int
rad2vips_get_header( Read *read, VipsImage *out )
{
int i, j;
VipsInterpretation interpretation;
int width;
int height;
int i, j;
if( getheader( read->fin, (gethfunc *) rad2vips_process_line, read ) ||
!fgetsresolu( &read->rs, read->fin ) ) {
@ -1013,9 +1032,17 @@ rad2vips_get_header( Read *read, VipsImage *out )
else
interpretation = VIPS_INTERPRETATION_MULTIBAND;
vips_image_init_fields( out,
scanlen( &read->rs ), numscans( &read->rs ),
4,
width = scanlen( &read->rs );
height = numscans( &read->rs );
if( width <= 0 ||
width > VIPS_MAX_COORD ||
height <= 0 ||
height > VIPS_MAX_COORD ) {
vips_error( "rad2vips", "%s", _( "image size out of bounds" ) );
return( -1 );
}
vips_image_init_fields( out, width, height, 4,
VIPS_FORMAT_UCHAR, VIPS_CODING_RAD,
interpretation,
1, read->aspect );
@ -1080,6 +1107,7 @@ rad2vips_generate( VipsRegion *or,
if( scanline_read( read->buffer, buf, or->im->Xsize ) ) {
vips_error( "rad2vips",
_( "read error line %d" ), r->top + y );
VIPS_GATE_STOP( "rad2vips_generate: work" );
return( -1 );
}
}
@ -1277,3 +1305,5 @@ vips__rad_save( VipsImage *in, const char *filename )
}
const char *vips__rad_suffs[] = { ".hdr", NULL };
#endif /*HAVE_RADIANCE*/

View File

@ -48,6 +48,8 @@
#include <vips/buf.h>
#include <vips/internal.h>
#ifdef HAVE_RADIANCE
#include "radiance.h"
typedef struct _VipsForeignLoadRad {
@ -145,6 +147,8 @@ vips_foreign_load_rad_init( VipsForeignLoadRad *rad )
{
}
#endif /*HAVE_RADIANCE*/
/**
* vips_radload:
* @filename: file to load

View File

@ -47,6 +47,8 @@
#include <vips/vips.h>
#ifdef HAVE_RADIANCE
#include "radiance.h"
typedef struct _VipsForeignSaveRad {
@ -129,6 +131,8 @@ vips_foreign_save_rad_init( VipsForeignSaveRad *rad )
{
}
#endif /*HAVE_RADIANCE*/
/**
* vips_radsave:
* @in: image to save

View File

@ -56,6 +56,7 @@ EXTRA_DIST = version.h.in internal.h enumtemplate
# we need absolute filenames here since this list appears in the src dir as
# well
vips_scan_headers = \
${top_srcdir}/libvips/include/vips/resample.h \
${top_srcdir}/libvips/include/vips/memory.h \
${top_srcdir}/libvips/include/vips/create.h \
${top_srcdir}/libvips/include/vips/foreign.h \

View File

@ -6,6 +6,9 @@
G_BEGIN_DECLS
/* enumerations from "../../../libvips/include/vips/resample.h" */
GType vips_kernel_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_KERNEL (vips_kernel_get_type())
/* enumerations from "../../../libvips/include/vips/foreign.h" */
GType vips_foreign_flags_get_type (void) G_GNUC_CONST;
#define VIPS_TYPE_FOREIGN_FLAGS (vips_foreign_flags_get_type())

View File

@ -38,6 +38,15 @@
extern "C" {
#endif /*__cplusplus*/
typedef enum {
VIPS_KERNEL_NEAREST,
VIPS_KERNEL_LINEAR,
VIPS_KERNEL_CUBIC,
VIPS_KERNEL_LANCZOS2,
VIPS_KERNEL_LANCZOS3,
VIPS_KERNEL_LAST
} VipsKernel;
int vips_shrink( VipsImage *in, VipsImage **out,
double xshrink, double yshrink, ... )
__attribute__((sentinel));

View File

@ -54,6 +54,7 @@ AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@
# we need absolute filenames here since this list appears in the header dir as
# well
vips_scan_headers = \
${top_srcdir}/libvips/include/vips/resample.h \
${top_srcdir}/libvips/include/vips/memory.h \
${top_srcdir}/libvips/include/vips/create.h \
${top_srcdir}/libvips/include/vips/foreign.h \

View File

@ -4,6 +4,28 @@
/* auto-generated enums for vips introspection */
#include <vips/vips.h>
/* enumerations from "../../libvips/include/vips/resample.h" */
GType
vips_kernel_get_type( void )
{
static GType etype = 0;
if( etype == 0 ) {
static const GEnumValue values[] = {
{VIPS_KERNEL_NEAREST, "VIPS_KERNEL_NEAREST", "nearest"},
{VIPS_KERNEL_LINEAR, "VIPS_KERNEL_LINEAR", "linear"},
{VIPS_KERNEL_CUBIC, "VIPS_KERNEL_CUBIC", "cubic"},
{VIPS_KERNEL_LANCZOS2, "VIPS_KERNEL_LANCZOS2", "lanczos2"},
{VIPS_KERNEL_LANCZOS3, "VIPS_KERNEL_LANCZOS3", "lanczos3"},
{VIPS_KERNEL_LAST, "VIPS_KERNEL_LAST", "last"},
{0, NULL, NULL}
};
etype = g_enum_register_static( "VipsKernel", values );
}
return( etype );
}
/* enumerations from "../../libvips/include/vips/foreign.h" */
GType
vips_foreign_flags_get_type( void )

View File

@ -508,6 +508,8 @@ G_DEFINE_TYPE( VipsInterpolateBilinear, vips_interpolate_bilinear,
case VIPS_FORMAT_INT: FLOAT( int ); break; \
case VIPS_FORMAT_FLOAT: FLOAT( float ); break; \
case VIPS_FORMAT_DOUBLE:FLOAT( double ); break; \
case VIPS_FORMAT_COMPLEX: FLOAT( float ); break; \
case VIPS_FORMAT_DPCOMPLEX:FLOAT( double ); break; \
default: \
g_assert( FALSE ); \
} \
@ -521,7 +523,8 @@ vips_interpolate_bilinear_interpolate( VipsInterpolate *interpolate,
*/
const int ps = VIPS_IMAGE_SIZEOF_PEL( in->im );
const int ls = VIPS_REGION_LSKIP( in );
const int b = in->im->Bands;
const int b = in->im->Bands *
(vips_band_format_iscomplex( in->im->BandFmt ) ? 2 : 1);
const int ix = (int) x;
const int iy = (int) y;

View File

@ -65,6 +65,13 @@ typedef struct _VipsResampleClass {
GType vips_resample_get_type( void );
/* The max size of the vector we use.
*/
#define MAX_POINTS (6)
int vips_reduce_get_points( VipsKernel kernel );
void vips_reduce_make_mask( VipsKernel kernel, double x, double *c );
#ifdef __cplusplus
}
#endif /*__cplusplus*/

View File

@ -56,6 +56,10 @@ typedef struct _VipsReduce {
double xshrink; /* Shrink factors */
double yshrink;
/* The thing we use to make the kernel.
*/
VipsKernel kernel;
} VipsReduce;
typedef VipsResampleClass VipsReduceClass;
@ -73,8 +77,12 @@ vips_reduce_build( VipsObject *object )
if( VIPS_OBJECT_CLASS( vips_reduce_parent_class )->build( object ) )
return( -1 );
if( vips_reducev( resample->in, &t[0], reduce->yshrink, NULL ) ||
vips_reduceh( t[0], &t[1], reduce->xshrink, NULL ) ||
if( vips_reducev( resample->in, &t[0], reduce->yshrink,
"kernel", reduce->kernel,
NULL ) ||
vips_reduceh( t[0], &t[1], reduce->xshrink,
"kernel", reduce->kernel,
NULL ) ||
vips_image_write( t[1], resample->out ) )
return( -1 );
@ -113,11 +121,19 @@ vips_reduce_class_init( VipsReduceClass *class )
G_STRUCT_OFFSET( VipsReduce, yshrink ),
1.0, 1000000.0, 1.0 );
VIPS_ARG_ENUM( class, "kernel", 3,
_( "Kernel" ),
_( "Resampling kernel" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsReduce, kernel ),
VIPS_TYPE_KERNEL, VIPS_KERNEL_LANCZOS3 );
}
static void
vips_reduce_init( VipsReduce *reduce )
{
reduce->kernel = VIPS_KERNEL_LANCZOS3;
}
/**
@ -128,7 +144,11 @@ vips_reduce_init( VipsReduce *reduce )
* @shrinke: vertical shrink
* @...: %NULL-terminated list of optional named arguments
*
* Reduce @in by a pair of factors with a pair of 1D cubic interpolators. This
* Optional arguments:
*
* @kernel: #VipsKernel to use to interpolate (default: lanczos3)
*
* Reduce @in by a pair of factors with a pair of 1D interpolators. This
* will not work well for shrink factors greater than two.
*
* This is a very low-level operation: see vips_resize() for a more

View File

@ -1,7 +1,9 @@
/* horizontal reduce by a float factor
/* horizontal reduce by a float factor with lanczos3
*
* 29/1/16
* - from shrinkh.c
* 10/3/16
* - add other kernels
*/
/*
@ -51,54 +53,163 @@
#include "presample.h"
#include "templates.h"
/**
* VipsKernel:
* @VIPS_KERNEL_NEAREST: nearest-neighbour
* @VIPS_KERNEL_LINEAR: linear interpolation
* @VIPS_KERNEL_CUBIC: cubic interpolation
* @VIPS_KERNEL_LANCZOS2: lanczos2 interpolation
* @VIPS_KERNEL_LANCZOS3: lanczos3 interpolation
*
* 1D resampling kernels.
*/
typedef struct _VipsReduceh {
VipsResample parent_instance;
double xshrink; /* Reduce factor */
/* The thing we use to make the kernel.
*/
VipsKernel kernel;
/* Number of points in kernel.
*/
int n_points;
/* Precalculated interpolation matrices. int (used for pel
* sizes up to short), and double (for all others). We go to
* scale + 1 so we can round-to-nearest safely.
*/
int matrixi[VIPS_TRANSFORM_SCALE + 1][MAX_POINTS];
double matrixf[VIPS_TRANSFORM_SCALE + 1][MAX_POINTS];
} VipsReduceh;
typedef VipsResampleClass VipsReducehClass;
/* Precalculated interpolation matrices. int (used for pel
* sizes up to short), and double (for all others). We go to
* scale + 1 so we can round-to-nearest safely.
*/
static int vips_reduceh_matrixi[VIPS_TRANSFORM_SCALE + 1][4];
static double vips_reduceh_matrixf[VIPS_TRANSFORM_SCALE + 1][4];
/* We need C linkage for this.
*/
extern "C" {
G_DEFINE_TYPE( VipsReduceh, vips_reduceh, VIPS_TYPE_RESAMPLE );
}
/* Get n points.
*/
int
vips_reduce_get_points( VipsKernel kernel )
{
switch( kernel ) {
case VIPS_KERNEL_NEAREST:
return( 1 );
case VIPS_KERNEL_LINEAR:
return( 2 );
case VIPS_KERNEL_CUBIC:
return( 4 );
case VIPS_KERNEL_LANCZOS2:
return( 4 );
case VIPS_KERNEL_LANCZOS3:
return( 6 );
default:
g_assert_not_reached();
return( 0 );
}
}
/* Calculate a mask.
*/
void
vips_reduce_make_mask( VipsKernel kernel, double x, double *c )
{
switch( kernel ) {
case VIPS_KERNEL_NEAREST:
c[0] = 1.0;
break;
case VIPS_KERNEL_LINEAR:
c[0] = 1.0 - x;
c[1] = x;
break;
case VIPS_KERNEL_CUBIC:
calculate_coefficients_catmull( x, c );
break;
case VIPS_KERNEL_LANCZOS2:
calculate_coefficients_lanczos( 2, x, c );
break;
case VIPS_KERNEL_LANCZOS3:
calculate_coefficients_lanczos( 3, x, c );
break;
default:
g_assert_not_reached();
break;
}
}
template <typename T, int max_value>
static void inline
reduceh_unsigned_int_tab( VipsPel *pout, const VipsPel *pin,
const int bands, const int *cx )
reduceh_unsigned_int_tab( VipsReduceh *reduceh,
VipsPel *pout, const VipsPel *pin,
const int bands, const int * restrict cx )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int n = reduceh->n_points;
for( int z = 0; z < bands; z++ ) {
int sum;
sum = reduce_sum<T, int>( in, bands, cx, n );
sum = unsigned_fixed_round( sum );
sum = VIPS_CLIP( 0, sum, max_value );
out[z] = sum;
in += 1;
}
}
/* A 4-point interpolation on uint8 is the most common case ... unroll that.
*
* The inner loop here won't vectorise, but our inner loop doesn't run for
* long enough for vectorisation to be useful :-( gcc says it needs about an
* 11-point kernel for the vector version to be worthwhile.
*/
static void inline
reduceh_unsigned_uint8_6tab( VipsPel *out, const VipsPel *in,
const int bands, const int *cx )
{
const int b1 = bands;
const int b2 = b1 + b1;
const int b3 = b1 + b2;
const int b4 = b2 + b2;
const int b5 = b1 + b4;
const int c0 = cx[0];
const int c1 = cx[1];
const int c2 = cx[2];
const int c3 = cx[3];
const int c4 = cx[4];
const int c5 = cx[5];
for( int z = 0; z < bands; z++ ) {
int cubich = unsigned_fixed_round(
c0 * in[0] +
c1 * in[b1] +
c2 * in[b2] +
c3 * in[b3] );
c3 * in[b3] +
c4 * in[b4] +
c5 * in[b5] );
cubich = VIPS_CLIP( 0, cubich, max_value );
cubich = VIPS_CLIP( 0, cubich, 255 );
out[z] = cubich;
@ -108,96 +219,63 @@ reduceh_unsigned_int_tab( VipsPel *pout, const VipsPel *pin,
template <typename T, int min_value, int max_value>
static void inline
reduceh_signed_int_tab( VipsPel *pout, const VipsPel *pin,
const int bands, const int *cx )
reduceh_signed_int_tab( VipsReduceh *reduceh,
VipsPel *pout, const VipsPel *pin,
const int bands, const int * restrict cx )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int b1 = bands;
const int b2 = b1 + b1;
const int b3 = b1 + b2;
const int c0 = cx[0];
const int c1 = cx[1];
const int c2 = cx[2];
const int c3 = cx[3];
const int n = reduceh->n_points;
for( int z = 0; z < bands; z++ ) {
int cubich = signed_fixed_round(
c0 * in[0] +
c1 * in[b1] +
c2 * in[b2] +
c3 * in[b3] );
int sum;
cubich = VIPS_CLIP( min_value, cubich, max_value );
sum = reduce_sum<T, int>( in, bands, cx, n );
sum = signed_fixed_round( sum );
sum = VIPS_CLIP( min_value, sum, max_value );
out[z] = cubich;
out[z] = sum;
in += 1;
}
}
/* Floating-point version, for int/float types.
/* Floating-point version.
*/
template <typename T>
static void inline
reduceh_float_tab( VipsPel *pout, const VipsPel *pin,
reduceh_float_tab( VipsReduceh *reduceh,
VipsPel *pout, const VipsPel *pin,
const int bands, const double *cx )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int b1 = bands;
const int b2 = b1 + b1;
const int b3 = b1 + b2;
const double c0 = cx[0];
const double c1 = cx[1];
const double c2 = cx[2];
const double c3 = cx[3];
const int n = reduceh->n_points;
for( int z = 0; z < bands; z++ ) {
out[z] =
c0 * in[0] +
c1 * in[b1] +
c2 * in[b2] +
c3 * in[b3];
out[z] = reduce_sum<T, double>( in, bands, cx, n );
in += 1;
}
}
/* 32-bit output needs a double intermediate.
/* 32-bit int output needs a double intermediate.
*/
template <typename T, int max_value>
static void inline
reduceh_unsigned_int32_tab( VipsPel *pout, const VipsPel *pin,
const int bands, const double *cx )
reduceh_unsigned_int32_tab( VipsReduceh *reduceh,
VipsPel *pout, const VipsPel *pin,
const int bands, const double * restrict cx )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int b1 = bands;
const int b2 = b1 + b1;
const int b3 = b1 + b2;
const double c0 = cx[0];
const double c1 = cx[1];
const double c2 = cx[2];
const double c3 = cx[3];
const int n = reduceh->n_points;
for( int z = 0; z < bands; z++ ) {
double cubich =
c0 * in[0] +
c1 * in[b1] +
c2 * in[b2] +
c3 * in[b3];
double sum;
cubich = VIPS_CLIP( 0, cubich, max_value );
out[z] = cubich;
sum = reduce_sum<T, double>( in, bands, cx, n );
out[z] = VIPS_CLIP( 0, sum, max_value );
in += 1;
}
@ -205,31 +283,20 @@ reduceh_unsigned_int32_tab( VipsPel *pout, const VipsPel *pin,
template <typename T, int min_value, int max_value>
static void inline
reduceh_signed_int32_tab( VipsPel *pout, const VipsPel *pin,
const int bands, const double *cx )
reduceh_signed_int32_tab( VipsReduceh *reduceh,
VipsPel *pout, const VipsPel *pin,
const int bands, const double * restrict cx )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int b1 = bands;
const int b2 = b1 + b1;
const int b3 = b1 + b2;
const double c0 = cx[0];
const double c1 = cx[1];
const double c2 = cx[2];
const double c3 = cx[3];
const int n = reduceh->n_points;
for( int z = 0; z < bands; z++ ) {
double cubich =
c0 * in[0] +
c1 * in[b1] +
c2 * in[b2] +
c3 * in[b3];
double sum;
cubich = VIPS_CLIP( min_value, cubich, max_value );
out[z] = cubich;
sum = reduce_sum<T, double>( in, bands, cx, n );
sum = VIPS_CLIP( min_value, sum, max_value );
out[z] = sum;
in += 1;
}
@ -239,27 +306,20 @@ reduceh_signed_int32_tab( VipsPel *pout, const VipsPel *pin,
*/
template <typename T>
static void inline
reduceh_notab( VipsPel *pout, const VipsPel *pin,
reduceh_notab( VipsReduceh *reduceh,
VipsPel *pout, const VipsPel *pin,
const int bands, double x )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int n = reduceh->n_points;
const int b1 = bands;
const int b2 = b1 + b1;
const int b3 = b1 + b2;
double cx[MAX_POINTS];
double cx[4];
calculate_coefficients_catmull( x, cx );
vips_reduce_make_mask( reduceh->kernel, x, cx );
for( int z = 0; z < bands; z++ ) {
const T one = in[0];
const T two = in[b1];
const T thr = in[b2];
const T fou = in[b3];
out[z] = cubic_float<T>( one, two, thr, fou, cx );
out[z] = reduce_sum<T, double>( in, bands, cx, n );
in += 1;
}
@ -289,7 +349,7 @@ vips_reduceh_gen( VipsRegion *out_region, void *seq,
s.left = r->left * reduceh->xshrink;
s.top = r->top;
s.width = r->width * reduceh->xshrink + 4;
s.width = r->width * reduceh->xshrink + reduceh->n_points;
s.height = r->height;
if( vips_region_prepare( ir, &s ) )
return( -1 );
@ -309,54 +369,66 @@ vips_reduceh_gen( VipsRegion *out_region, void *seq,
const int sx = X * VIPS_TRANSFORM_SCALE * 2;
const int six = sx & (VIPS_TRANSFORM_SCALE * 2 - 1);
const int tx = (six + 1) >> 1;
const int *cxi = vips_reduceh_matrixi[tx];
const double *cxf = vips_reduceh_matrixf[tx];
const int *cxi = reduceh->matrixi[tx];
const double *cxf = reduceh->matrixf[tx];
switch( in->BandFmt ) {
case VIPS_FORMAT_UCHAR:
reduceh_unsigned_int_tab
<unsigned char, UCHAR_MAX>(
q, p, bands, cxi );
if( reduceh->n_points == 6 )
reduceh_unsigned_uint8_6tab(
q, p, bands, cxi );
else
reduceh_unsigned_int_tab
<unsigned char, UCHAR_MAX>(
reduceh,
q, p, bands, cxi );
break;
case VIPS_FORMAT_CHAR:
reduceh_signed_int_tab
<signed char, SCHAR_MIN, SCHAR_MAX>(
reduceh,
q, p, bands, cxi );
break;
case VIPS_FORMAT_USHORT:
reduceh_unsigned_int_tab
<unsigned short, USHRT_MAX>(
reduceh,
q, p, bands, cxi );
break;
case VIPS_FORMAT_SHORT:
reduceh_signed_int_tab
<signed short, SHRT_MIN, SHRT_MAX>(
reduceh,
q, p, bands, cxi );
break;
case VIPS_FORMAT_UINT:
reduceh_unsigned_int32_tab
<unsigned int, INT_MAX>(
reduceh,
q, p, bands, cxf );
break;
case VIPS_FORMAT_INT:
reduceh_signed_int32_tab
<signed int, INT_MIN, INT_MAX>(
reduceh,
q, p, bands, cxf );
break;
case VIPS_FORMAT_FLOAT:
case VIPS_FORMAT_COMPLEX:
reduceh_float_tab<float>( q, p, bands, cxf );
reduceh_float_tab<float>( reduceh,
q, p, bands, cxf );
break;
case VIPS_FORMAT_DOUBLE:
case VIPS_FORMAT_DPCOMPLEX:
reduceh_notab<double>( q, p, bands, X - ix );
reduceh_notab<double>( reduceh,
q, p, bands, X - ix );
break;
default:
@ -402,6 +474,19 @@ vips_reduceh_build( VipsObject *object )
if( reduceh->xshrink == 1 )
return( vips_image_write( in, resample->out ) );
/* Build the tables of pre-computed coefficients.
*/
reduceh->n_points = vips_reduce_get_points( reduceh->kernel );
for( int x = 0; x < VIPS_TRANSFORM_SCALE + 1; x++ ) {
vips_reduce_make_mask( reduceh->kernel,
(float) x / VIPS_TRANSFORM_SCALE,
reduceh->matrixf[x] );
for( int i = 0; i < reduceh->n_points; i++ )
reduceh->matrixi[x][i] = reduceh->matrixf[x][i] *
VIPS_INTERPOLATE_SCALE;
}
/* Unpack for processing.
*/
if( vips_image_decode( in, &t[0] ) )
@ -411,8 +496,8 @@ vips_reduceh_build( VipsObject *object )
/* Add new pixels around the input so we can interpolate at the edges.
*/
if( vips_embed( in, &t[1],
1, 0,
in->Xsize + 3, in->Ysize,
reduceh->n_points / 2 - 1, 0,
in->Xsize + reduceh->n_points - 1, in->Ysize,
"extend", VIPS_EXTEND_COPY,
NULL ) )
return( -1 );
@ -422,13 +507,14 @@ vips_reduceh_build( VipsObject *object )
VIPS_DEMAND_STYLE_THINSTRIP, in, NULL ) )
return( -1 );
/* Size output. Note: we round the output width down!
/* Size output. Note: we round to nearest to hide rounding errors.
*
* Don't change xres/yres, leave that to the application layer. For
* example, vipsthumbnail knows the true reduce factor (including the
* fractional part), we just see the integer part here.
*/
resample->out->Xsize = (in->Xsize - 3) / reduceh->xshrink;
resample->out->Xsize = VIPS_RINT(
(in->Xsize - reduceh->n_points + 1) / reduceh->xshrink );
if( resample->out->Xsize <= 0 ) {
vips_error( object_class->nickname,
"%s", _( "image has shrunk to nothing" ) );
@ -475,24 +561,19 @@ vips_reduceh_class_init( VipsReducehClass *reduceh_class )
G_STRUCT_OFFSET( VipsReduceh, xshrink ),
1, 1000000, 1 );
/* Build the tables of pre-computed coefficients.
*/
for( int x = 0; x < VIPS_TRANSFORM_SCALE + 1; x++ ) {
calculate_coefficients_catmull(
(float) x / VIPS_TRANSFORM_SCALE,
vips_reduceh_matrixf[x] );
for( int i = 0; i < 4; i++ )
vips_reduceh_matrixi[x][i] =
vips_reduceh_matrixf[x][i] *
VIPS_INTERPOLATE_SCALE;
}
VIPS_ARG_ENUM( reduceh_class, "kernel", 3,
_( "Kernel" ),
_( "Resampling kernel" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsReduceh, kernel ),
VIPS_TYPE_KERNEL, VIPS_KERNEL_LANCZOS3 );
}
static void
vips_reduceh_init( VipsReduceh *reduceh )
{
reduceh->kernel = VIPS_KERNEL_LANCZOS3;
}
/**
@ -502,8 +583,12 @@ vips_reduceh_init( VipsReduceh *reduceh )
* @xshrink: horizontal reduce
* @...: %NULL-terminated list of optional named arguments
*
* Optional arguments:
*
* @kernel: #VipsKernel to use to interpolate (default: lanczos3)
*
* Reduce @in horizontally by a float factor. The pixels in @out are
* interpolated with a 1D cubic mask. This operation will not work well for
* interpolated with a 1D mask. This operation will not work well for
* a reduction of more than a factor of two.
*
* This is a very low-level operation: see vips_resize() for a more

View File

@ -1,7 +1,9 @@
/* vertical reduce by a float factor
/* horizontal reduce by a float factor with lanczos3
*
* 29/1/16
* - from shrinkv.c
* 10/3/16
* - add other kernels
*/
/*
@ -51,57 +53,96 @@
#include "presample.h"
#include "templates.h"
/* The max size of the vector we use.
*/
#define MAX_POINTS (6)
typedef struct _VipsReducev {
VipsResample parent_instance;
double yshrink; /* Shrink factor */
/* The thing we use to make the kernel.
*/
VipsKernel kernel;
/* Number of points in kernel.
*/
int n_points;
/* Precalculated interpolation matrices. int (used for pel
* sizes up to short), and double (for all others). We go to
* scale + 1 so we can round-to-nearest safely.
*/
int matrixi[VIPS_TRANSFORM_SCALE + 1][MAX_POINTS];
double matrixf[VIPS_TRANSFORM_SCALE + 1][MAX_POINTS];
} VipsReducev;
typedef VipsResampleClass VipsReducevClass;
/* Precalculated interpolation matrices. int (used for pel
* sizes up to short), and double (for all others). We go to
* scale + 1 so we can round-to-nearest safely.
*/
static int vips_reducev_matrixi[VIPS_TRANSFORM_SCALE + 1][4];
static double vips_reducev_matrixf[VIPS_TRANSFORM_SCALE + 1][4];
/* We need C linkage for this.
*/
extern "C" {
G_DEFINE_TYPE( VipsReducev, vips_reducev, VIPS_TYPE_RESAMPLE );
}
/* You'd think this would vectorise, but gcc hates mixed types in nested loops
* :-(
*/
template <typename T, int max_value>
static void inline
reducev_unsigned_int_tab( VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip,
const int *cy )
reducev_unsigned_int_tab( VipsReducev *reducev,
VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip, const int * restrict cy )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int n = reducev->n_points;
const int l1 = lskip / sizeof( T );
for( int z = 0; z < ne; z++ ) {
int sum;
sum = reduce_sum<T, int>( in + z, l1, cy, n );
sum = unsigned_fixed_round( sum );
sum = VIPS_CLIP( 0, sum, max_value );
out[z] = sum;
}
}
/* An unrolled version of ^^ for the most common case.
*/
static void inline
reducev_unsigned_uint8_6tab( VipsPel *out, const VipsPel *in,
const int ne, const int lskip, const int *cy )
{
const int l1 = lskip;
const int l2 = l1 + l1;
const int l3 = l1 + l2;
const int l4 = l2 + l2;
const int l5 = l4 + l1;
const int c0 = cy[0];
const int c1 = cy[1];
const int c2 = cy[2];
const int c3 = cy[3];
const int c4 = cy[4];
const int c5 = cy[5];
for( int z = 0; z < ne; z++ ) {
int cubicv = unsigned_fixed_round(
int sum = unsigned_fixed_round(
c0 * in[0] +
c1 * in[l1] +
c2 * in[l2] +
c3 * in[l3] );
c3 * in[l3] +
c4 * in[l4] +
c5 * in[l5] );
cubicv = VIPS_CLIP( 0, cubicv, max_value );
sum = VIPS_CLIP( 0, sum, 255 );
out[z] = cubicv;
out[z] = sum;
in += 1;
}
@ -109,135 +150,81 @@ reducev_unsigned_int_tab( VipsPel *pout, const VipsPel *pin,
template <typename T, int min_value, int max_value>
static void inline
reducev_signed_int_tab( VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip,
const int *cy )
reducev_signed_int_tab( VipsReducev *reducev,
VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip, const int * restrict cy )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int n = reducev->n_points;
const int l1 = lskip / sizeof( T );
const int l2 = l1 + l1;
const int l3 = l1 + l2;
const int c0 = cy[0];
const int c1 = cy[1];
const int c2 = cy[2];
const int c3 = cy[3];
for( int z = 0; z < ne; z++ ) {
int cubicv = signed_fixed_round(
c0 * in[0] +
c1 * in[l1] +
c2 * in[l2] +
c3 * in[l3] );
int sum;
cubicv = VIPS_CLIP( min_value, cubicv, max_value );
sum = reduce_sum<T, int>( in + z, l1, cy, n );
sum = signed_fixed_round( sum );
sum = VIPS_CLIP( min_value, sum, max_value );
out[z] = cubicv;
in += 1;
out[z] = sum;
}
}
/* Floating-point version.
*/
template <typename T>
static void inline
reducev_float_tab( VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip,
const double *cy )
reducev_float_tab( VipsReducev *reducev,
VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip, const double * restrict cy )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int n = reducev->n_points;
const int l1 = lskip / sizeof( T );
const int l2 = l1 + l1;
const int l3 = l1 + l2;
const double c0 = cy[0];
const double c1 = cy[1];
const double c2 = cy[2];
const double c3 = cy[3];
for( int z = 0; z < ne; z++ ) {
out[z] =
c0 * in[0] +
c1 * in[l1] +
c2 * in[l2] +
c3 * in[l3];
in += 1;
}
for( int z = 0; z < ne; z++ )
out[z] = reduce_sum<T, double>( in + z, l1, cy, n );
}
/* 32-bit int version needs a double intermediate.
/* 32-bit int output needs a double intermediate.
*/
template <typename T, int max_value>
static void inline
reducev_unsigned_int32_tab( VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip,
const double *cy )
reducev_unsigned_int32_tab( VipsReducev *reducev,
VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip, const double * restrict cy )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int n = reducev->n_points;
const int l1 = lskip / sizeof( T );
const int l2 = l1 + l1;
const int l3 = l1 + l2;
const double c0 = cy[0];
const double c1 = cy[1];
const double c2 = cy[2];
const double c3 = cy[3];
for( int z = 0; z < ne; z++ ) {
double cubicv =
c0 * in[0] +
c1 * in[l1] +
c2 * in[l2] +
c3 * in[l3];
double sum;
cubicv = VIPS_CLIP( 0, cubicv, max_value );
out[z] = cubicv;
in += 1;
sum = reduce_sum<T, double>( in + z, l1, cy, n );
out[z] = VIPS_CLIP( 0, sum, max_value );
}
}
template <typename T, int min_value, int max_value>
static void inline
reducev_signed_int32_tab( VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip,
const double *cy )
reducev_signed_int32_tab( VipsReducev *reducev,
VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip, const double * restrict cy )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int n = reducev->n_points;
const int l1 = lskip / sizeof( T );
const int l2 = l1 + l1;
const int l3 = l1 + l2;
const double c0 = cy[0];
const double c1 = cy[1];
const double c2 = cy[2];
const double c3 = cy[3];
for( int z = 0; z < ne; z++ ) {
double cubicv =
c0 * in[0] +
c1 * in[l1] +
c2 * in[l2] +
c3 * in[l3];
double sum;
cubicv = VIPS_CLIP( min_value, cubicv, max_value );
out[z] = cubicv;
in += 1;
sum = reduce_sum<T, double>( in + z, l1, cy, n );
out[z] = VIPS_CLIP( min_value, sum, max_value );
}
}
@ -245,35 +232,21 @@ reducev_signed_int32_tab( VipsPel *pout, const VipsPel *pin,
*/
template <typename T>
static void inline
reducev_notab( VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip,
double y )
reducev_notab( VipsReducev *reducev,
VipsPel *pout, const VipsPel *pin,
const int ne, const int lskip, double y )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int n = reducev->n_points;
const int l1 = lskip / sizeof( T );
const int l2 = l1 + l1;
const int l3 = l1 + l2;
double cy[4];
double cy[MAX_POINTS];
calculate_coefficients_catmull( y, cy );
vips_reduce_make_mask( reducev->kernel, y, cy );
const double c0 = cy[0];
const double c1 = cy[1];
const double c2 = cy[2];
const double c3 = cy[3];
for( int z = 0; z < ne; z++ ) {
out[z] =
c0 * in[0] +
c1 * in[l1] +
c2 * in[l2] +
c3 * in[l3];
in += 1;
}
for( int z = 0; z < ne; z++ )
out[z] = reduce_sum<T, double>( in + z, l1, cy, n );
}
static int
@ -301,68 +274,81 @@ vips_reducev_gen( VipsRegion *out_region, void *seq,
s.left = r->left;
s.top = r->top * reducev->yshrink;
s.width = r->width;
s.height = r->height * reducev->yshrink + 4;
s.height = r->height * reducev->yshrink + reducev->n_points;
if( vips_region_prepare( ir, &s ) )
return( -1 );
VIPS_GATE_START( "vips_reducev_gen: work" );
for( int y = 0; y < r->height; y ++ ) {
VipsPel *q = VIPS_REGION_ADDR( out_region, r->left, r->top + y );
VipsPel *q =
VIPS_REGION_ADDR( out_region, r->left, r->top + y );
const double Y = (r->top + y) * reducev->yshrink;
VipsPel *p = VIPS_REGION_ADDR( ir, r->left, (int) Y );
const int sy = Y * VIPS_TRANSFORM_SCALE * 2;
const int siy = sy & (VIPS_TRANSFORM_SCALE * 2 - 1);
const int ty = (siy + 1) >> 1;
const int *cyi = vips_reducev_matrixi[ty];
const double *cyf = vips_reducev_matrixf[ty];
const int *cyi = reducev->matrixi[ty];
const double *cyf = reducev->matrixf[ty];
const int lskip = VIPS_REGION_LSKIP( ir );
switch( in->BandFmt ) {
case VIPS_FORMAT_UCHAR:
reducev_unsigned_int_tab
<unsigned char, UCHAR_MAX>(
q, p, ne, lskip, cyi );
if( reducev->n_points == 6 )
reducev_unsigned_uint8_6tab(
q, p, ne, lskip, cyi );
else
reducev_unsigned_int_tab
<unsigned char, UCHAR_MAX>(
reducev,
q, p, ne, lskip, cyi );
break;
case VIPS_FORMAT_CHAR:
reducev_signed_int_tab
<signed char, SCHAR_MIN, SCHAR_MAX>(
reducev,
q, p, ne, lskip, cyi );
break;
case VIPS_FORMAT_USHORT:
reducev_unsigned_int_tab
<unsigned short, USHRT_MAX>(
reducev,
q, p, ne, lskip, cyi );
break;
case VIPS_FORMAT_SHORT:
reducev_signed_int_tab
<signed short, SHRT_MIN, SHRT_MAX>(
reducev,
q, p, ne, lskip, cyi );
break;
case VIPS_FORMAT_UINT:
reducev_unsigned_int32_tab
<unsigned int, INT_MAX>(
reducev,
q, p, ne, lskip, cyf );
break;
case VIPS_FORMAT_INT:
reducev_signed_int32_tab
<signed int, INT_MIN, INT_MAX>(
reducev,
q, p, ne, lskip, cyf );
break;
case VIPS_FORMAT_FLOAT:
case VIPS_FORMAT_COMPLEX:
reducev_float_tab<float>( q, p, ne, lskip, cyf );
reducev_float_tab<float>( reducev,
q, p, ne, lskip, cyf );
break;
case VIPS_FORMAT_DPCOMPLEX:
case VIPS_FORMAT_DOUBLE:
reducev_notab<double>( q, p, ne, lskip, Y - (int) Y );
reducev_notab<double>( reducev,
q, p, ne, lskip, Y - (int) Y );
break;
default:
@ -403,6 +389,19 @@ vips_reducev_build( VipsObject *object )
if( reducev->yshrink == 1 )
return( vips_image_write( in, resample->out ) );
/* Build the tables of pre-computed coefficients.
*/
reducev->n_points = vips_reduce_get_points( reducev->kernel );
for( int y = 0; y < VIPS_TRANSFORM_SCALE + 1; y++ ) {
vips_reduce_make_mask( reducev->kernel,
(float) y / VIPS_TRANSFORM_SCALE,
reducev->matrixf[y] );
for( int i = 0; i < reducev->n_points; i++ )
reducev->matrixi[y][i] = reducev->matrixf[y][i] *
VIPS_INTERPOLATE_SCALE;
}
/* Unpack for processing.
*/
if( vips_image_decode( in, &t[0] ) )
@ -412,8 +411,8 @@ vips_reducev_build( VipsObject *object )
/* Add new pixels around the input so we can interpolate at the edges.
*/
if( vips_embed( in, &t[1],
0, 1,
in->Xsize, in->Ysize + 3,
0, reducev->n_points / 2 - 1,
in->Xsize, in->Ysize + reducev->n_points - 1,
"extend", VIPS_EXTEND_COPY,
NULL ) )
return( -1 );
@ -423,13 +422,14 @@ vips_reducev_build( VipsObject *object )
VIPS_DEMAND_STYLE_SMALLTILE, in, NULL ) )
return( -1 );
/* Size output. Note: we round the output width down!
/* Size output. Note: we round to nearest to hide rounding errors.
*
* Don't change xres/yres, leave that to the application layer. For
* example, vipsthumbnail knows the true reduce factor (including the
* fractional part), we just see the integer part here.
*/
resample->out->Ysize = (in->Ysize - 3) / reducev->yshrink;
resample->out->Ysize = VIPS_RINT(
(in->Ysize - reducev->n_points + 1) / reducev->yshrink );
if( resample->out->Ysize <= 0 ) {
vips_error( object_class->nickname,
"%s", _( "image has shrunk to nothing" ) );
@ -476,24 +476,19 @@ vips_reducev_class_init( VipsReducevClass *reducev_class )
G_STRUCT_OFFSET( VipsReducev, yshrink ),
1, 1000000, 1 );
/* Build the tables of pre-computed coefficients.
*/
for( int y = 0; y < VIPS_TRANSFORM_SCALE + 1; y++ ) {
calculate_coefficients_catmull(
(float) y / VIPS_TRANSFORM_SCALE,
vips_reducev_matrixf[y] );
for( int i = 0; i < 4; i++ )
vips_reducev_matrixi[y][i] =
vips_reducev_matrixf[y][i] *
VIPS_INTERPOLATE_SCALE;
}
VIPS_ARG_ENUM( reducev_class, "kernel", 3,
_( "Kernel" ),
_( "Resampling kernel" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsReducev, kernel ),
VIPS_TYPE_KERNEL, VIPS_KERNEL_LANCZOS3 );
}
static void
vips_reducev_init( VipsReducev *reducev )
{
reducev->kernel = VIPS_KERNEL_LANCZOS3;
}
/**
@ -503,8 +498,12 @@ vips_reducev_init( VipsReducev *reducev )
* @yshrink: horizontal reduce
* @...: %NULL-terminated list of optional named arguments
*
* Optional arguments:
*
* @kernel: #VipsKernel to use to interpolate (default: lanczos3)
*
* Reduce @in vertically by a float factor. The pixels in @out are
* interpolated with a 1D cubic mask. This operation will not work well for
* interpolated with a 1D mask. This operation will not work well for
* a reduction of more than a factor of two.
*
* This is a very low-level operation: see vips_resize() for a more

View File

@ -8,6 +8,8 @@
* - smarter cache sizing
* 29/2/16
* - shrink more affine less, now we have better anti-alias settings
* 10/3/16
* - revise again, using new vips_reduce() code
*/
/*
@ -65,6 +67,9 @@ typedef struct _VipsResize {
double scale;
double vscale;
/* Deprecated.
*/
VipsInterpolate *interpolate;
double idx;
double idy;
@ -82,11 +87,11 @@ vips_resize_build( VipsObject *object )
VipsResample *resample = VIPS_RESAMPLE( object );
VipsResize *resize = (VipsResize *) object;
VipsImage **t = (VipsImage **)
vips_object_local_array( object, 7 );
VipsImage **t = (VipsImage **) vips_object_local_array( object, 7 );
VipsImage *in;
int window_size;
int target_width;
int target_height;
int int_hshrink;
int int_vshrink;
double hresidual;
@ -97,64 +102,44 @@ vips_resize_build( VipsObject *object )
if( VIPS_OBJECT_CLASS( vips_resize_parent_class )->build( object ) )
return( -1 );
if( !vips_object_argument_isset( object, "interpolate" ) ) {
VipsInterpolate *interpolate;
char *nick;
if( vips_type_find( "VipsInterpolate", "bicubic" ) )
nick = "bicubic";
else
nick = "bilinear";
interpolate = vips_interpolate_new( nick );
g_object_set( object, "interpolate", interpolate, NULL );
VIPS_UNREF( interpolate );
}
/* Unset vscale means it's equal to hscale.
*/
if( !vips_object_argument_isset( object, "vscale" ) )
resize->vscale = resize->scale;
in = resample->in;
window_size = resize->interpolate ?
vips_interpolate_get_window_size( resize->interpolate ) : 2;
/* The image size we are aiming for.
*/
target_width = in->Xsize * resize->scale;
if( vips_object_argument_isset( object, "vscale" ) )
target_height = in->Ysize * resize->vscale;
else
target_height = in->Ysize * resize->scale;
/* If the factor is > 1.0, we need to zoom rather than shrink.
* Just set the int part to 1 in this case.
*/
int_hshrink = resize->scale > 1.0 ?
1 : VIPS_FLOOR( 1.0 / resize->scale );
int_vshrink = resize->vscale > 1.0 ?
1 : VIPS_FLOOR( 1.0 / resize->vscale );
if( vips_object_argument_isset( object, "vscale" ) )
int_vshrink = resize->vscale > 1.0 ?
1 : VIPS_FLOOR( 1.0 / resize->vscale );
else
int_vshrink = int_hshrink;
/* We want to shrink by less for interpolators with large windows.
*/
int_hshrink = VIPS_MAX( 1,
int_hshrink / VIPS_MAX( 1, window_size / 3 ) );
int_vshrink = VIPS_MAX( 1,
int_vshrink / VIPS_MAX( 1, window_size / 3 ) );
if( int_hshrink > 1 ||
int_vshrink > 1 ) {
vips_info( class->nickname, "box shrink by %d x %d",
int_hshrink, int_vshrink );
if( vips_shrink( in, &t[0], int_hshrink, int_vshrink, NULL ) )
return( -1 );
in = t[0];
}
/* Will this produce a residual scale of almost 1? shrink a bit less
* if it will.
/* Do we need a further size adjustment? It's the difference
* between our target size and the size we have after vips_shrink().
*
* This can break the aspect ratio slightly :/ but hopefully no one
* will notice.
*/
if( (in->Xsize * resize->scale) / (in->Xsize / int_hshrink) > 0.9 )
int_hshrink = VIPS_MAX( 1, int_hshrink - 1 );
if( (in->Ysize * resize->vscale) / (in->Ysize / int_vshrink) > 0.9 )
int_vshrink = VIPS_MAX( 1, int_vshrink - 1 );
/* Residual scale factor is.
*/
hresidual = (in->Xsize * resize->scale) / (in->Xsize / int_hshrink);
vresidual = (in->Ysize * resize->vscale) / (in->Ysize / int_vshrink);
/* A copy for enlarge resize.
*/
vips_info( class->nickname, "box shrink by %d x %d",
int_hshrink, int_vshrink );
if( vips_shrink( in, &t[0], int_hshrink, int_vshrink, NULL ) )
return( -1 );
in = t[0];
hresidual = (double) target_width / in->Xsize;
vresidual = (double) target_height / in->Ysize;
/* We want to make sure we read the image sequentially.
* However, the convolution we may be doing later will force us
@ -180,7 +165,7 @@ vips_resize_build( VipsObject *object )
* tile (0,0) and then stall, the whole write system won't stall until
* it tries to allocate tile (0, 2).
*
* We affine down after this, which can be a scale of up to @residual,
* We reduce down after this, which can be a scale of up to @residual,
* perhaps 0.5 or down as low as 0.3 depending on the interpolator. So
* the number of scanlines we need to keep for the worst case is
* 2 * @tile_height / @residual, plus a little extra.
@ -209,51 +194,42 @@ vips_resize_build( VipsObject *object )
/* 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.
* Don't blur for very small shrinks, or very small sigma.
*
* Don't try to be clever for non-rectangular shrinks. We just
* consider the horizontal factor.
*/
sigma = ((1.0 / hresidual) - 0.5) / 2.0;
anti_alias = hresidual < 1.0 && sigma > 0.1;
sigma = (1.0 / hresidual) / 2.3;
anti_alias = hresidual < 0.9 && sigma > 0.45;
if( anti_alias ) {
vips_info( class->nickname, "anti-alias sigma %g", sigma );
if( vips_gaussblur( in, &t[2], sigma, NULL ) )
if( vips_gaussblur( in, &t[1], sigma,
"min_ampl", 0.1,
NULL ) )
return( -1 );
in = t[1];
}
if( hresidual < 1.0 ||
vresidual < 1.0 ) {
vips_info( class->nickname, "residual reduce by %g x %g",
hresidual, vresidual );
if( vips_reduce( in, &t[2],
1.0 / hresidual, 1.0 / vresidual, NULL ) )
return( -1 );
in = t[2];
}
vips_info( class->nickname, "residual affine %g x %g",
hresidual, vresidual );
if( resize->interpolate ) {
const char *nickname =
VIPS_OBJECT_GET_CLASS( resize->interpolate )->nickname;
vips_info( class->nickname, "%s interpolation", nickname );
}
/* We have a special path for bicubic, idx/idy == 0.
*/
if( resize->interpolate &&
strcmp( VIPS_OBJECT_GET_CLASS( resize->interpolate )->nickname,
"bicubic" ) == 0 &&
resize->idx == 0.0 &&
resize->idy == 0.0 ) {
vips_info( class->nickname, "using fast path for residual" );
if( vips_reduce( in, &t[3],
1.0 / hresidual, 1.0 / vresidual, NULL ) )
return( -1 );
}
else {
if( hresidual > 1.0 ||
vresidual > 1.0 ) {
vips_info( class->nickname, "residual scale %g x %g",
hresidual, vresidual );
if( vips_affine( in, &t[3], hresidual, 0, 0, vresidual,
"interpolate", resize->interpolate,
"idx", resize->idx,
"idy", resize->idy,
"interpolate", vips_interpolate_nearest_static(),
NULL ) )
return( -1 );
in = t[3];
}
in = t[3];
/* If we are upsampling, don't sharpen. Also don't sharpen if we
* skipped the anti-alias filter.
@ -261,15 +237,15 @@ vips_resize_build( VipsObject *object )
if( int_hshrink >= 1 &&
anti_alias ) {
vips_info( class->nickname, "final sharpen" );
t[5] = vips_image_new_matrixv( 3, 3,
t[4] = 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( t[5], "scale", 24 );
vips_image_set_double( t[4], "scale", 24 );
if( vips_conv( in, &t[4], t[5], NULL ) )
if( vips_conv( in, &t[5], t[4], NULL ) )
return( -1 );
in = t[4];
in = t[5];
}
if( vips_image_write( in, resample->out ) )
@ -310,25 +286,33 @@ vips_resize_class_init( VipsResizeClass *class )
G_STRUCT_OFFSET( VipsResize, vscale ),
0, 10000000, 0 );
VIPS_ARG_INTERPOLATE( class, "interpolate", 2,
_( "Interpolate" ),
_( "Interpolate pixels with this" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsResize, interpolate ) );
/* We used to let people set the input offset so you could pick centre
* or corner interpolation, but it's not clear this was useful.
*/
VIPS_ARG_DOUBLE( class, "idx", 115,
_( "Input offset" ),
_( "Horizontal input displacement" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
VIPS_ARGUMENT_OPTIONAL_INPUT | VIPS_ARGUMENT_DEPRECATED,
G_STRUCT_OFFSET( VipsResize, idx ),
-10000000, 10000000, 0 );
VIPS_ARG_DOUBLE( class, "idy", 116,
_( "Input offset" ),
_( "Vertical input displacement" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
VIPS_ARGUMENT_OPTIONAL_INPUT | VIPS_ARGUMENT_DEPRECATED,
G_STRUCT_OFFSET( VipsResize, idy ),
-10000000, 10000000, 0 );
/* We used to let people set the interpolator, but it's not clear this
* was useful. Anyway, vips_reduce() no longer has an interpolator
* param.
*/
VIPS_ARG_INTERPOLATE( class, "interpolate", 2,
_( "Interpolate" ),
_( "Interpolate pixels with this" ),
VIPS_ARGUMENT_OPTIONAL_INPUT | VIPS_ARGUMENT_DEPRECATED,
G_STRUCT_OFFSET( VipsResize, interpolate ) );
}
static void
@ -346,29 +330,21 @@ vips_resize_init( VipsResize *resize )
* Optional arguments:
*
* @vscale: vertical scale factor
* @interpolate: interpolate pixels with this
* @idx: input horizontal offset
* @idy: input vertical offset
*
* Resize an image. When upsizing (@scale > 1), the image is simply resized
* with vips_affine() and the supplied @interpolate. When downsizing, the
* image is block-shrunk with vips_shrink() to roughly half the interpolator
* window size above the target size, then blurred with an anti-alias filter,
* then resampled with vips_affine() and the supplied interpolator, then
* sharpened.
* Resize an image. When upsizing (@scale > 1), the image is simply block
* upsized. When downsizing, the
* image is block-shrunk with vips_shrink(), then an anti-alias blur is
* applied with vips_gaussblur(), then the image is shrunk again to the
* target size with vips_reduce().
*
* vips_resize() normally maintains the image apect ratio. If you set
* @vscale, that factor is used for the vertical scale and @scale for the
* horizontal.
*
* @interpolate defaults to bicubic.
*
* @idx, @idy default to zero. Set them to 0.5 to get pixel-centre sampling.
*
* This operation does not change xres or yres. The image resolution needs to
* be updated by the application.
*
* See also: vips_shrink(), vips_affine(), #VipsInterpolate.
* See also: vips_shrink(), vips_reduce(), vips_gaussblur().
*
* Returns: 0 on success, -1 on error
*/

View File

@ -310,3 +310,48 @@ calculate_coefficients_catmull( const double x, double c[4] )
c[1] = ctwo;
c[2] = cthr;
}
/* Given an offset in [0,1] (we can have x == 1 when building tables),
* calculate c0 .. c(a * 2 - 1), the lanczos coefficients. This is called
* from the interpolator as well as from the table builder.
*/
static void inline
calculate_coefficients_lanczos( int a, const double x, double *c )
{
int i;
for( i = 0; i < a * 2; i++ ) {
double xp = (i - a) + (1 - x);
double l;
if( xp == 0.0 )
l = 1.0;
else if( xp < -a )
l = 0.0;
else if( xp > a )
l = 0.0;
else
l = (double) a * sin( VIPS_PI * xp ) *
sin( VIPS_PI * xp / (double) a ) /
(VIPS_PI * VIPS_PI * xp * xp);
c[i] = l;
}
}
/* Our inner loop for resampling with a convolution. Operate on elements of
* size T, gather results in an intermediate of type IT.
*/
template <typename T, typename IT>
static IT
reduce_sum( const T * restrict in, int stride, const IT * restrict c, int n )
{
IT sum;
sum = 0;
for( int i = 0; i < n; i++ )
sum += c[i] * in[i * stride];
return( sum );
}

View File

@ -110,8 +110,8 @@ class TestCreate(unittest.TestCase):
def test_gaussmat(self):
im = Vips.Image.gaussmat(1, 0.1)
self.assertEqual(im.width, 7)
self.assertEqual(im.height, 7)
self.assertEqual(im.width, 5)
self.assertEqual(im.height, 5)
self.assertEqual(im.bands, 1)
self.assertEqual(im.format, Vips.BandFormat.DOUBLE)
self.assertEqual(im.max(), 20)
@ -123,7 +123,7 @@ class TestCreate(unittest.TestCase):
im = Vips.Image.gaussmat(1, 0.1,
separable = True, precision = "float")
self.assertEqual(im.width, 7)
self.assertEqual(im.width, 5)
self.assertEqual(im.height, 1)
self.assertEqual(im.bands, 1)
self.assertEqual(im.format, Vips.BandFormat.DOUBLE)

View File

@ -267,6 +267,11 @@ class TestForeign(unittest.TestCase):
self.save_load("%s.webp", self.colour)
def test_analyzeload(self):
x = Vips.type_find("VipsForeign", "analyzeload")
if not x.is_instantiatable():
print("no analyze support in this vips, skipping test")
return
def analyze_valid(self, im):
a = im(10, 10)
self.assertAlmostEqual(a[0], 3335)
@ -416,10 +421,20 @@ class TestForeign(unittest.TestCase):
self.save_load("%s.mat", self.mono)
def test_ppm(self):
x = Vips.type_find("VipsForeign", "ppmload")
if not x.is_instantiatable():
print("no PPM support in this vips, skipping test")
return
self.save_load("%s.ppm", self.mono)
self.save_load("%s.ppm", self.colour)
def test_rad(self):
x = Vips.type_find("VipsForeign", "radload")
if not x.is_instantiatable():
print("no Radiance support in this vips, skipping test")
return
self.save_load("%s.hdr", self.colour)
def test_dzsave(self):

View File

@ -116,17 +116,41 @@ class TestResample(unittest.TestCase):
def test_reduce(self):
im = Vips.Image.new_from_file("images/IMG_4618.jpg")
# cast down to 0-127, the smallest range, so we aren't messed up by
# clipping
im = im.cast(Vips.BandFormat.CHAR)
bicubic = Vips.Interpolate.new("bicubic")
bilinear = Vips.Interpolate.new("bilinear")
nearest = Vips.Interpolate.new("nearest")
for fac in [1, 1.1, 1.5, 1.999]:
for fmt in all_formats:
x = im.cast(fmt)
r = x.reduce(fac, fac)
r = x.reduce(fac, fac, kernel = "cubic")
a = x.affine([1.0 / fac, 0, 0, 1.0 / fac],
interpolate = bicubic,
oarea = [0, 0, x.width / fac, x.height / fac])
d = (r - a).abs().max()
self.assertLess(d, 5)
self.assertLess(d, 10)
for fac in [1, 1.1, 1.5, 1.999]:
for fmt in all_formats:
x = im.cast(fmt)
r = x.reduce(fac, fac, kernel = "linear")
a = x.affine([1.0 / fac, 0, 0, 1.0 / fac],
interpolate = bilinear,
oarea = [0, 0, x.width / fac, x.height / fac])
d = (r - a).abs().max()
self.assertLess(d, 10)
# for other kernels, just see if avg looks about right
for fac in [1, 1.1, 1.5, 1.999]:
for fmt in all_formats:
for kernel in ["nearest", "lanczos2", "lanczos3"]:
x = im.cast(fmt)
r = x.reduce(fac, fac, kernel = kernel)
d = abs(r.avg() - im.avg())
self.assertLess(d, 2)
def test_resize(self):
im = Vips.Image.new_from_file("images/IMG_4618.jpg")

View File

@ -30,6 +30,7 @@ for interp in nearest bilinear bicubic lbb nohalo vsqbs; do
vipsthumbnail $tmp/t1.v -o $tmp/t2.v --size $size --interpolator $interp
if [ $(vipsheader -f width $tmp/t2.v) -ne $size ]; then
echo failed -- bad size
echo output width is $(vipsheader -f width $tmp/t2.v)
exit
fi
if [ $(vipsheader -f height $tmp/t2.v) -ne $size ]; then

View File

@ -77,6 +77,7 @@
* - add webp --shrink support
* 29/2/16
* - make more use of jpeg shrink-on-load now we've tuned vips_resize()
* - deprecate sharpen and interpolate
*/
#ifdef HAVE_CONFIG_H
@ -103,10 +104,8 @@ static char *thumbnail_size = "128";
static int thumbnail_width = 128;
static int thumbnail_height = 128;
static char *output_format = "tn_%s.jpg";
static char *interpolator = "bilinear";
static char *export_profile = NULL;
static char *import_profile = NULL;
static char *convolution_mask = "none";
static gboolean delete_profile = FALSE;
static gboolean linear_processing = FALSE;
static gboolean crop_image = FALSE;
@ -117,6 +116,8 @@ static gboolean rotate_image = FALSE;
static gboolean nosharpen = FALSE;
static gboolean nodelete_profile = FALSE;
static gboolean verbose = FALSE;
static char *convolution_mask = NULL;
static char *interpolator = NULL;
static GOptionEntry options[] = {
{ "size", 's', 0,
@ -131,14 +132,6 @@ static GOptionEntry options[] = {
G_OPTION_ARG_STRING, &output_format,
N_( "set output format string to FORMAT" ),
N_( "FORMAT" ) },
{ "interpolator", 'p', 0,
G_OPTION_ARG_STRING, &interpolator,
N_( "resample with INTERPOLATOR" ),
N_( "INTERPOLATOR" ) },
{ "sharpen", 'r', 0,
G_OPTION_ARG_STRING, &convolution_mask,
N_( "sharpen with none|mild|MASKFILE" ),
N_( "none|mild|MASKFILE" ) },
{ "eprofile", 'e', 0,
G_OPTION_ARG_STRING, &export_profile,
N_( "export with PROFILE" ),
@ -159,6 +152,7 @@ static GOptionEntry options[] = {
{ "delete", 'd', 0,
G_OPTION_ARG_NONE, &delete_profile,
N_( "delete profile from exported image" ), NULL },
{ "verbose", 'v', G_OPTION_FLAG_HIDDEN,
G_OPTION_ARG_NONE, &verbose,
N_( "(deprecated, does nothing)" ), NULL },
@ -168,6 +162,12 @@ static GOptionEntry options[] = {
{ "nosharpen", 'n', G_OPTION_FLAG_HIDDEN,
G_OPTION_ARG_NONE, &nosharpen,
N_( "(deprecated, does nothing)" ), NULL },
{ "interpolator", 'p', G_OPTION_FLAG_HIDDEN,
G_OPTION_ARG_STRING, &interpolator,
N_( "(deprecated, does nothing)" ), NULL },
{ "sharpen", 'r', G_OPTION_FLAG_HIDDEN,
G_OPTION_ARG_STRING, &convolution_mask,
N_( "(deprecated, does nothing)" ), NULL },
{ NULL }
};
@ -185,7 +185,7 @@ calculate_shrink( VipsImage *im )
VipsDirection direction;
/* Calculate the horizontal and vertical shrink we'd need to fit the
* image to the bounding box, and pick the biggest.
* image to the bounding box, and pick the biggest.
*
* In crop mode we aim to fill the bounding box, so we must use the
* smaller axis.
@ -367,57 +367,8 @@ thumbnail_open( VipsObject *process, const char *filename )
return( im );
}
static VipsInterpolate *
thumbnail_interpolator( VipsObject *process, VipsImage *in )
{
double shrink = calculate_shrink( in );
VipsInterpolate *interp;
/* For images smaller than the thumbnail, we upscale with nearest
* neighbor. Otherwise we make thumbnails that look fuzzy and awful.
*/
if( !(interp = VIPS_INTERPOLATE( vips_object_new_from_string(
g_type_class_ref( VIPS_TYPE_INTERPOLATE ),
shrink <= 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 =
vips_image_new_from_file( convolution_mask, NULL )) )
vips_error_exit( "unable to load sharpen mask" );
if( mask )
vips_object_local( process, mask );
return( mask );
}
static VipsImage *
thumbnail_shrink( VipsObject *process, VipsImage *in,
VipsInterpolate *interp, VipsImage *sharpen )
thumbnail_shrink( VipsObject *process, VipsImage *in )
{
VipsImage **t = (VipsImage **) vips_object_local_array( process, 10 );
VipsInterpretation interpretation = linear_processing ?
@ -518,9 +469,7 @@ thumbnail_shrink( VipsObject *process, VipsImage *in,
shrink = calculate_shrink( in );
if( vips_resize( in, &t[4], 1.0 / shrink,
"interpolate", interp,
NULL ) )
if( vips_resize( in, &t[4], 1.0 / shrink, NULL ) )
return( NULL );
in = t[4];
@ -609,17 +558,6 @@ thumbnail_shrink( VipsObject *process, VipsImage *in,
in = out;
}
/* If we are upsampling, don't sharpen, since nearest looks dumb
* sharpened.
*/
if( shrink > 1.0 &&
sharpen ) {
vips_info( "vipsthumbnail", "sharpening thumbnail" );
if( vips_conv( in, &t[8], sharpen, NULL ) )
return( NULL );
in = t[8];
}
if( delete_profile &&
vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) {
vips_info( "vipsthumbnail",
@ -729,18 +667,13 @@ thumbnail_write( VipsObject *process, VipsImage *im, const char *filename )
static int
thumbnail_process( VipsObject *process, const char *filename )
{
VipsImage *sharpen = thumbnail_sharpen( process );
VipsImage *in;
VipsInterpolate *interp;
VipsImage *thumbnail;
VipsImage *crop;
VipsImage *rotate;
if( !(in = thumbnail_open( process, filename )) ||
!(interp = thumbnail_interpolator( process, in )) ||
!(thumbnail =
thumbnail_shrink( process, in, interp, sharpen )) ||
!(thumbnail = thumbnail_shrink( process, in )) ||
!(crop = thumbnail_crop( process, thumbnail )) ||
!(rotate = thumbnail_rotate( process, crop )) ||
thumbnail_write( process, rotate, filename ) )
@ -763,12 +696,6 @@ main( int argc, char **argv )
textdomain( GETTEXT_PACKAGE );
setlocale( LC_ALL, "" );
/* Does this vips have bicubic? Default to that if it
* does.
*/
if( vips_type_find( "VipsInterpolate", "bicubic" ) )
interpolator = "bicubic";
context = g_option_context_new( _( "- thumbnail generator" ) );
main_group = g_option_group_new( NULL, NULL, NULL, NULL, NULL );