add cubicv, reducev

untested
This commit is contained in:
John Cupitt 2016-01-27 15:01:54 +00:00
parent 3e78bdb6a9
commit 991349c9a7
6 changed files with 709 additions and 41 deletions

View File

@ -10,10 +10,12 @@ libresample_la_SOURCES = \
shrinkh.c \
shrinkv.c \
reduceh.c \
reducev.c \
interpolate.c \
transform.c \
bicubic.cpp \
cubich.cpp \
cubicv.cpp \
lbb.cpp \
nohalo.cpp \
vsqbs.cpp \

View File

@ -119,8 +119,7 @@ cubich_unsigned_int_tab( void *pout, const VipsPel *pin,
const T thr = in[b2];
const T fou = in[b3];
int cubich = cubic_unsigned_int<T>(
one, two, thr, fou, cx );
int cubich = cubic_unsigned_int<T>( one, two, thr, fou, cx );
cubich = VIPS_CLIP( 0, cubich, max_value );
@ -148,8 +147,7 @@ cubich_signed_int_tab( void *pout, const VipsPel *pin,
const T thr = in[b2];
const T fou = in[b3];
int cubich = cubic_signed_int<T>(
one, two, thr, fou, cx );
int cubich = cubic_signed_int<T>( one, two, thr, fou, cx );
cubich = VIPS_CLIP( min_value, cubich, max_value );
@ -179,10 +177,7 @@ cubich_float_tab( void *pout, const VipsPel *pin,
const T thr = in[b2];
const T fou = in[b3];
const T cubich = cubic_float<T>(
one, two, thr, fou, cx );
out[z] = cubich;
out[z] = cubic_float<T>( one, two, thr, fou, cx );
in += 1;
}
@ -212,10 +207,7 @@ cubich_notab( void *pout, const VipsPel *pin,
const T thr = in[b2];
const T fou = in[b3];
const T cubich = cubic_float<T>(
one, two, thr, fou, cx );
out[z] = cubich;
out[z] = cubic_float<T>( one, two, thr, fou, cx );
in += 1;
}
@ -306,33 +298,27 @@ vips_interpolate_cubich_interpolate( VipsInterpolate *interpolate,
break;
case VIPS_FORMAT_UINT:
cubich_float_tab<unsigned int>(
out, p, bands, cxf );
cubich_float_tab<unsigned int>( out, p, bands, cxf );
break;
case VIPS_FORMAT_INT:
cubich_float_tab<signed int>(
out, p, bands, cxf );
cubich_float_tab<signed int>( out, p, bands, cxf );
break;
case VIPS_FORMAT_FLOAT:
cubich_float_tab<float>(
out, p, bands, cxf );
cubich_float_tab<float>( out, p, bands, cxf );
break;
case VIPS_FORMAT_DOUBLE:
cubich_notab<double>(
out, p, bands, x - ix );
cubich_notab<double>( out, p, bands, x - ix );
break;
case VIPS_FORMAT_COMPLEX:
cubich_float_tab<float>(
out, p, bands * 2, cxf );
cubich_float_tab<float>( out, p, bands * 2, cxf );
break;
case VIPS_FORMAT_DPCOMPLEX:
cubich_notab<double>(
out, p, bands * 2, x - ix );
cubich_notab<double>( out, p, bands * 2, x - ix );
break;
default:

378
libvips/resample/cubicv.cpp Normal file
View File

@ -0,0 +1,378 @@
/* vertical cubic (catmull-rom) interpolator
*
* 26/1/16
* - from bicubic.cpp
*/
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
/* Cubic (Catmull-Rom) interpolator derived from Nicolas Robidoux's
* original YAFR resampler with permission and thanks.
*/
/*
#define DEBUG
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <vips/vips.h>
#include <vips/internal.h>
#include "templates.h"
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
#define VIPS_TYPE_INTERPOLATE_CUBICV \
(vips_interpolate_cubicv_get_type())
#define VIPS_INTERPOLATE_CUBICV( obj ) \
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
VIPS_TYPE_INTERPOLATE_CUBICV, VipsInterpolateCubicv ))
#define VIPS_INTERPOLATE_CUBICV_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_CAST( (klass), \
VIPS_TYPE_INTERPOLATE_CUBICV, VipsInterpolateCubicvClass))
#define VIPS_IS_INTERPOLATE_CUBICV( obj ) \
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_INTERPOLATE_CUBICV ))
#define VIPS_IS_INTERPOLATE_CUBICV_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_INTERPOLATE_CUBICV ))
#define VIPS_INTERPOLATE_CUBICV_GET_CLASS( obj ) \
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
VIPS_TYPE_INTERPOLATE_CUBICV, VipsInterpolateCubicvClass ))
typedef VipsInterpolate VipsInterpolateCubicv;
typedef VipsInterpolateClass VipsInterpolateCubicvClass;
/* 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.
*/
/* We could keep a large set of 2d 4x4 matricies, but this actually
* works out slower since for many resizes the thing will no longer
* fit in L1.
*/
static int vips_cubicv_matrixi[VIPS_TRANSFORM_SCALE + 1][4];
static double vips_cubicv_matrixf[VIPS_TRANSFORM_SCALE + 1][4];
/* We need C linkage for this.
*/
extern "C" {
G_DEFINE_TYPE( VipsInterpolateCubicv, vips_interpolate_cubicv,
VIPS_TYPE_INTERPOLATE );
}
/* Pointers to write to / read from, number of bands,
* how many bytes to add to move down a line.
*/
/* T is the type of pixels we are reading and writing.
*/
/* Fixed-point version, for 8 and 16-bit types.
*/
template <typename T, int max_value>
static void inline
cubicv_unsigned_int_tab( void *pout, const VipsPel *pin,
const int bands, const int lskip,
const int *cy )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int l1 = lskip / sizeof( T );
const int l2 = l1 + l1;
const int l3 = l1 + l2;
for( int z = 0; z < bands; z++ ) {
const T uno = in[0];
const T dos = in[l1];
const T tre = in[l2];
const T qua = in[l3];
int cubicv = cubic_unsigned_int<T>( uno, dos, tre, qua, cy );
cubicv = VIPS_CLIP( 0, cubicv, max_value );
out[z] = cubicv;
in += 1;
}
}
template <typename T, int min_value, int max_value>
static void inline
cubicv_signed_int_tab( void *pout, const VipsPel *pin,
const int bands, const int lskip,
const int *cy )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int l1 = lskip / sizeof( T );
const int l2 = l1 + l1;
const int l3 = l1 + l2;
for( int z = 0; z < bands; z++ ) {
const T uno = in[0];
const T dos = in[l1];
const T tre = in[l2];
const T qua = in[l3];
int cubicv = cubic_signed_int<T>( uno, dos, tre, qua, cy );
cubicv = VIPS_CLIP( min_value, cubicv, max_value );
out[z] = cubicv;
in += 1;
}
}
/* Floating-point version, for int/float types.
*/
template <typename T>
static void inline
cubicv_float_tab( void *pout, const VipsPel *pin,
const int bands, const int lskip,
const double *cy )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int l1 = lskip / sizeof( T );
const int l2 = l1 + l1;
const int l3 = l1 + l2;
for( int z = 0; z < bands; z++ ) {
const T uno = in[0];
const T dos = in[l1];
const T tre = in[l2];
const T qua = in[l3];
out[z] = cubic_float<T>( uno, dos, tre, qua, cy );
in += 1;
}
}
/* Ultra-high-quality version for double images.
*/
template <typename T>
static void inline
cubicv_notab( void *pout, const VipsPel *pin,
const int bands, const int lskip,
double y )
{
T* restrict out = (T *) pout;
const T* restrict in = (T *) pin;
const int l1 = lskip / sizeof( T );
const int l2 = l1 + l1;
const int l3 = l1 + l2;
double cy[4];
calculate_coefficients_catmull( y, cy );
for( int z = 0; z < bands; z++ ) {
const T uno = in[0];
const T dos = in[l1];
const T tre = in[l2];
const T qua = in[l3];
out[z] = cubic_float<T>( uno, dos, tre, qua, cy );
in += 1;
}
}
static void
vips_interpolate_cubicv_interpolate( VipsInterpolate *interpolate,
void *out, VipsRegion *in, double x, double y )
{
/* Find the mask index. We round-to-nearest, so we need to generate
* indexes in 0 to VIPS_TRANSFORM_SCALE, 2^n + 1 values. We multiply
* by 2 more than we need to, add one, mask, then shift down again to
* get the extra range.
*/
const int sy = y * VIPS_TRANSFORM_SCALE * 2;
const int siy = sy & (VIPS_TRANSFORM_SCALE * 2 - 1);
const int ty = (siy + 1) >> 1;
/* We know x/y are always positive, so we can just (int) them.
*/
const int ix = (int) x;
const int iy = (int) y;
/* Back and up one to get the top-left of the 4x4.
*/
const VipsPel *p = VIPS_REGION_ADDR( in, ix - 1, iy - 1 );
/* Look up the tables we need.
*/
const int *cyi = vips_cubicv_matrixi[ty];
const double *cyf = vips_cubicv_matrixf[ty];
/* Pel size and line size.
*/
const int bands = in->im->Bands;
const int lskip = VIPS_REGION_LSKIP( in );
g_assert( ix >= in->valid.left );
g_assert( iy - 1 >= in->valid.top );
g_assert( ix < VIPS_RECT_RIGHT( &in->valid ) );
g_assert( iy + 2 < VIPS_RECT_BOTTOM( &in->valid ) );
g_assert( ix == x );
/* Confirm that absolute_y is >= 1, because of window_offset.
*/
g_assert( y >= 1.0 );
#ifdef DEBUG
printf( "vips_interpolate_cubicv_interpolate: %g %g\n", x, y );
printf( "\tleft=%d, top=%d, width=%d, height=%d\n",
ix, iy - 1, 1, 4 );
printf( "\tmasky=%d\n", ty );
#endif /*DEBUG*/
switch( in->im->BandFmt ) {
case VIPS_FORMAT_UCHAR:
cubicv_unsigned_int_tab<unsigned char, UCHAR_MAX>(
out, p, bands, lskip,
cyi );
/*
Handy for benchmarking
cubicv_float_tab<unsigned char>(
out, p, bands, lskip,
cyf );
cubicv_notab<unsigned char>(
out, p, bands, lskip,
y - iy );
*/
break;
case VIPS_FORMAT_CHAR:
cubicv_signed_int_tab<signed char, SCHAR_MIN, SCHAR_MAX>(
out, p, bands, lskip, cyi );
break;
case VIPS_FORMAT_USHORT:
cubicv_unsigned_int_tab<unsigned short, USHRT_MAX>(
out, p, bands, lskip, cyi );
break;
case VIPS_FORMAT_SHORT:
cubicv_signed_int_tab<signed short, SHRT_MIN, SHRT_MAX>(
out, p, bands, lskip, cyi );
break;
case VIPS_FORMAT_UINT:
cubicv_float_tab<unsigned int>( out, p, bands, lskip, cyf );
break;
case VIPS_FORMAT_INT:
cubicv_float_tab<signed int>( out, p, bands, lskip, cyf );
break;
case VIPS_FORMAT_FLOAT:
cubicv_float_tab<float>( out, p, bands, lskip, cyf );
break;
case VIPS_FORMAT_DOUBLE:
cubicv_notab<double>( out, p, bands, lskip, y - iy );
break;
case VIPS_FORMAT_COMPLEX:
cubicv_float_tab<float>( out, p, bands * 2, lskip, cyf );
break;
case VIPS_FORMAT_DPCOMPLEX:
cubicv_notab<double>( out, p, bands * 2, lskip, y - iy );
break;
default:
break;
}
}
static void
vips_interpolate_cubicv_class_init( VipsInterpolateCubicvClass *iclass )
{
VipsObjectClass *object_class = VIPS_OBJECT_CLASS( iclass );
VipsInterpolateClass *interpolate_class =
VIPS_INTERPOLATE_CLASS( iclass );
object_class->nickname = "cubicv";
object_class->description =
_( "vertical cubic interpolation (Catmull-Rom)" );
interpolate_class->interpolate = vips_interpolate_cubicv_interpolate;
interpolate_class->window_size = 4;
/* 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_cubicv_matrixf[y] );
for( int i = 0; i < 4; i++ )
vips_cubicv_matrixi[y][i] =
vips_cubicv_matrixf[y][i] *
VIPS_INTERPOLATE_SCALE;
}
}
static void
vips_interpolate_cubicv_init( VipsInterpolateCubicv *cubicv )
{
#ifdef DEBUG
printf( "vips_interpolate_cubicv_init: " );
vips_object_print( VIPS_OBJECT( cubicv ) );
#endif /*DEBUG*/
}

View File

@ -601,6 +601,7 @@ vips__interpolate_init( void )
{
extern GType vips_interpolate_bicubic_get_type( void );
extern GType vips_interpolate_cubich_get_type( void );
extern GType vips_interpolate_cubicv_get_type( void );
extern GType vips_interpolate_lbb_get_type( void );
extern GType vips_interpolate_nohalo_get_type( void );
extern GType vips_interpolate_vsqbs_get_type( void );
@ -610,6 +611,7 @@ vips__interpolate_init( void )
vips_interpolate_bicubic_get_type();
vips_interpolate_cubich_get_type();
vips_interpolate_cubicv_get_type();
vips_interpolate_lbb_get_type();
vips_interpolate_nohalo_get_type();
vips_interpolate_vsqbs_get_type();

View File

@ -53,7 +53,7 @@
typedef struct _VipsReduceh {
VipsResample parent_instance;
double xreduce; /* Reduce factor */
double xshrink; /* Reduce factor */
VipsInterpolate *interpolate;
} VipsReduceh;
@ -86,9 +86,9 @@ vips_reduceh_gen( VipsRegion *or, void *seq,
r->width, r->height, r->left, r->top );
#endif /*DEBUG*/
s.left = r->left * reduceh->xreduce - window_offset;
s.left = r->left * reduceh->xshrink - window_offset;
s.top = r->top;
s.width = r->width * reduceh->xreduce + window_size - 1;
s.width = r->width * reduceh->xshrink + window_size - 1;
s.height = r->height;
if( vips_region_prepare( ir, &s ) )
return( -1 );
@ -103,7 +103,7 @@ vips_reduceh_gen( VipsRegion *or, void *seq,
for( x = 0; x < r->width; x++ ) {
double X = window_offset +
(r->left + x) * reduceh->xreduce;
(r->left + x) * reduceh->xshrink;
interpolate( reduceh->interpolate, q, ir, X, Y );
@ -157,16 +157,16 @@ vips_reduceh_build( VipsObject *object )
window_offset =
vips_interpolate_get_window_offset( reduceh->interpolate );
if( reduceh->xreduce < 1 ) {
if( reduceh->xshrink < 1 ) {
vips_error( class->nickname,
"%s", _( "reduce factors should be >= 1" ) );
return( -1 );
}
if( reduceh->xreduce > 2 )
if( reduceh->xshrink > 2 )
vips_warn( class->nickname,
"%s", _( "reduce factor greater than 2" ) );
if( reduceh->xreduce == 1 )
if( reduceh->xshrink == 1 )
return( vips_image_write( in, resample->out ) );
/* Unpack for processing.
@ -199,7 +199,7 @@ vips_reduceh_build( VipsObject *object )
* example, vipsthumbnail knows the true reduce factor (including the
* fractional part), we just see the integer part here.
*/
resample->out->Xsize = (in->Xsize - window_size + 1) / reduceh->xreduce;
resample->out->Xsize = (in->Xsize - window_size + 1) / reduceh->xshrink;
if( resample->out->Xsize <= 0 ) {
vips_error( class->nickname,
"%s", _( "image has shrunk to nothing" ) );
@ -233,16 +233,16 @@ vips_reduceh_class_init( VipsReducehClass *class )
gobject_class->get_property = vips_object_get_property;
vobject_class->nickname = "reduceh";
vobject_class->description = _( "reduce an image horizontally" );
vobject_class->description = _( "shrink an image horizontally" );
vobject_class->build = vips_reduceh_build;
operation_class->flags = VIPS_OPERATION_SEQUENTIAL_UNBUFFERED;
VIPS_ARG_DOUBLE( class, "xreduce", 3,
_( "Xreduce" ),
_( "Horizontal reduce factor" ),
VIPS_ARG_DOUBLE( class, "xshrink", 3,
_( "Xshrink" ),
_( "Horizontal shrink factor" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsReduceh, xreduce ),
G_STRUCT_OFFSET( VipsReduceh, xshrink ),
1, 1000000, 1 );
VIPS_ARG_INTERPOLATE( class, "interpolate", 4,
@ -262,9 +262,13 @@ vips_reduceh_init( VipsReduceh *reduceh )
* vips_reduceh:
* @in: input image
* @out: output image
* @xreduce: horizontal reduce
* @xshrink: horizontal reduce
* @...: %NULL-terminated list of optional named arguments
*
* Optional arguments:
*
* @interpolate: interpolate pixels with this, default cubich
*
* 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
* a reduction of more than a factor of two.
@ -280,13 +284,13 @@ vips_reduceh_init( VipsReduceh *reduceh )
* Returns: 0 on success, -1 on error
*/
int
vips_reduceh( VipsImage *in, VipsImage **out, double xreduce, ... )
vips_reduceh( VipsImage *in, VipsImage **out, double xshrink, ... )
{
va_list ap;
int result;
va_start( ap, xreduce );
result = vips_call_split( "reduceh", ap, in, out, xreduce );
va_start( ap, xshrink );
result = vips_call_split( "reduceh", ap, in, out, xshrink );
va_end( ap );
return( result );

296
libvips/resample/reducev.c Normal file
View File

@ -0,0 +1,296 @@
/* horizontal reduce by a float factor
*
* 30/10/15
* - from reducev.c
*/
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
/*
#define DEBUG
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vips/vips.h>
#include <vips/debug.h>
#include <vips/internal.h>
#include "presample.h"
typedef struct _VipsReducev {
VipsResample parent_instance;
double yshrink; /* Shrink factor */
VipsInterpolate *interpolate;
} VipsReducev;
typedef VipsResampleClass VipsReducevClass;
G_DEFINE_TYPE( VipsReducev, vips_reducev, VIPS_TYPE_RESAMPLE );
static int
vips_reducev_gen( VipsRegion *or, void *seq,
void *a, void *b, gboolean *stop )
{
VipsImage *in = (VipsImage *) a;
VipsReducev *reducev = (VipsReducev *) b;
int window_size =
vips_interpolate_get_window_size( reducev->interpolate );
int window_offset =
vips_interpolate_get_window_offset( reducev->interpolate );
const VipsInterpolateMethod interpolate =
vips_interpolate_get_method( reducev->interpolate );
int ps = VIPS_IMAGE_SIZEOF_PEL( in );
VipsRegion *ir = (VipsRegion *) seq;
VipsRect *r = &or->valid;
VipsRect s;
int y;
#ifdef DEBUG
printf( "vips_reducev_gen: generating %d x %d at %d x %d\n",
r->width, r->height, r->left, r->top );
#endif /*DEBUG*/
s.left = r->left;
s.top = r->top * reducev->yshrink - window_offset;
s.width = r->width;
s.height = r->height * reducev->yshrink + window_size - 1;
if( vips_region_prepare( ir, &s ) )
return( -1 );
VIPS_GATE_START( "vips_reducev_gen: work" );
for( y = 0; y < r->height; y ++ ) {
VipsPel *q = VIPS_REGION_ADDR( or, r->left, r->top + y );
double Y = window_offset + (r->top + y) * reducev->yshrink;
int x;
for( x = 0; x < r->width; x++ ) {
double X = r->left + x;
interpolate( reducev->interpolate, q, ir, X, Y );
q += ps;
}
}
VIPS_GATE_STOP( "vips_reducev_gen: work" );
return( 0 );
}
static int
vips_reducev_build( VipsObject *object )
{
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
VipsResample *resample = VIPS_RESAMPLE( object );
VipsReducev *reducev = (VipsReducev *) object;
VipsImage **t = (VipsImage **)
vips_object_local_array( object, 1 );
VipsImage *in;
int window_size;
int window_offset;
if( VIPS_OBJECT_CLASS( vips_reducev_parent_class )->build( object ) )
return( -1 );
in = resample->in;
/* We can't use vips_object_argument_isset(), since it may have been
* set to NULL, see vips_similarity().
*/
if( !reducev->interpolate ) {
VipsInterpolate *interpolate;
interpolate = vips_interpolate_new( "cubich" );
g_object_set( object,
"interpolate", interpolate,
NULL );
g_object_unref( interpolate );
/* coverity gets confused by this, it thinks
* reducev->interpolate may still be null. Assign ourselves,
* even though we don't need to.
*/
reducev->interpolate = interpolate;
}
window_size = vips_interpolate_get_window_size( reducev->interpolate );
window_offset =
vips_interpolate_get_window_offset( reducev->interpolate );
if( reducev->yshrink < 1 ) {
vips_error( class->nickname,
"%s", _( "reduce factors should be >= 1" ) );
return( -1 );
}
if( reducev->yshrink > 2 )
vips_warn( class->nickname,
"%s", _( "reduce factor greater than 2" ) );
if( reducev->yshrink == 1 )
return( vips_image_write( in, resample->out ) );
/* Unpack for processing.
*/
if( vips_image_decode( in, &t[0] ) )
return( -1 );
in = t[0];
/* Add new pixels around the input so we can interpolate at the edges.
*/
if( vips_embed( in, &t[1],
0, window_offset,
in->Xsize, in->Ysize + window_size - 1,
"extend", VIPS_EXTEND_COPY,
NULL ) )
return( -1 );
in = t[1];
/* THINSTRIP will work, anything else will break seq mode. If you
* combine reduce with conv you'll need to use a line cache to maintain
* sequentiality.
*/
if( vips_image_pipelinev( resample->out,
VIPS_DEMAND_STYLE_THINSTRIP, in, NULL ) )
return( -1 );
/* Size output. Note: we round the output width down!
*
* 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 - window_size + 1) / reducev->yshrink;
if( resample->out->Ysize <= 0 ) {
vips_error( class->nickname,
"%s", _( "image has shrunk to nothing" ) );
return( -1 );
}
#ifdef DEBUG
printf( "vips_reducev_build: reducing %d x %d image to %d x %d\n",
in->Xsize, in->Ysize,
resample->out->Xsize, resample->out->Ysize );
#endif /*DEBUG*/
if( vips_image_generate( resample->out,
vips_start_one, vips_reducev_gen, vips_stop_one,
in, reducev ) )
return( -1 );
return( 0 );
}
static void
vips_reducev_class_init( VipsReducevClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
VipsOperationClass *operation_class = VIPS_OPERATION_CLASS( class );
VIPS_DEBUG_MSG( "vips_reducev_class_init\n" );
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
vobject_class->nickname = "reducev";
vobject_class->description = _( "shrink an image vertically" );
vobject_class->build = vips_reducev_build;
operation_class->flags = VIPS_OPERATION_SEQUENTIAL_UNBUFFERED;
VIPS_ARG_DOUBLE( class, "yshrink", 3,
_( "Xshrink" ),
_( "Vertical shrink factor" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsReducev, yshrink ),
1, 1000000, 1 );
VIPS_ARG_INTERPOLATE( class, "interpolate", 4,
_( "Interpolate" ),
_( "Interpolate pixels with this" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsReducev, interpolate ) );
}
static void
vips_reducev_init( VipsReducev *reducev )
{
}
/**
* vips_reducev:
* @in: input image
* @out: output image
* @yshrink: horizontal reduce
* @...: %NULL-terminated list of optional named arguments
*
* Optional arguments:
*
* @interpolate: interpolate pixels with this, default cubicv
*
* 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
* a reduction of more than a factor of two.
*
* This is a very low-level operation: see vips_resize() for a more
* convenient way to resize images.
*
* This operation does not change xres or yres. The image resolution needs to
* be updated by the application.
*
* See also: vips_shrink(), vips_resize(), vips_affine().
*
* Returns: 0 on success, -1 on error
*/
int
vips_reducev( VipsImage *in, VipsImage **out, double yshrink, ... )
{
va_list ap;
int result;
va_start( ap, yshrink );
result = vips_call_split( "reducev", ap, in, out, yshrink );
va_end( ap );
return( result );
}