add @point subsample mode

to vips_subsample()
This commit is contained in:
John Cupitt 2013-11-02 09:33:10 +00:00
parent 7dfab19bb0
commit e1f2c06772
2 changed files with 29 additions and 7 deletions

View File

@ -9,6 +9,7 @@
vips_image_pipeline() to do both jobs vips_image_pipeline() to do both jobs
- vipsthumbnail allows non-square bounding boxes, thanks seth - vipsthumbnail allows non-square bounding boxes, thanks seth
- add vips_matrixprint() - add vips_matrixprint()
- add @point subsample mode to vips_subsample()
18/10/13 started 7.36.3 18/10/13 started 7.36.3
- fix compiler warnings in ubuntu 13.10 - fix compiler warnings in ubuntu 13.10

View File

@ -11,6 +11,8 @@
* - gtkdoc * - gtkdoc
* 1/6/13 * 1/6/13
* - redo as a class * - redo as a class
* 2/11/13
* - add @point to force point sample mode
*/ */
/* /*
@ -55,12 +57,10 @@
typedef struct _VipsSubsample { typedef struct _VipsSubsample {
VipsConversion parent_instance; VipsConversion parent_instance;
/* The input image.
*/
VipsImage *in; VipsImage *in;
int xfac;
int xfac; /* Subsample factors */
int yfac; int yfac;
gboolean point;
} VipsSubsample; } VipsSubsample;
@ -215,6 +215,7 @@ vips_subsample_build( VipsObject *object )
if( vips_image_pipelinev( conversion->out, if( vips_image_pipelinev( conversion->out,
VIPS_DEMAND_STYLE_THINSTRIP, subsample->in, NULL ) ) VIPS_DEMAND_STYLE_THINSTRIP, subsample->in, NULL ) )
return( -1 ); return( -1 );
/* Prepare output. Note: we round the output width down! /* Prepare output. Note: we round the output width down!
*/ */
conversion->out->Xsize = subsample->in->Xsize / subsample->xfac; conversion->out->Xsize = subsample->in->Xsize / subsample->xfac;
@ -228,13 +229,15 @@ vips_subsample_build( VipsObject *object )
return( -1 ); return( -1 );
} }
/* Generate! If this is a very large shrink, then it's /* Generate! If this is a very large shrink, then it's probably faster
* probably faster to do it a pixel at a time. * to do it a pixel at a time.
*/ */
if( subsample->xfac > 10 ) if( subsample->point ||
subsample->xfac > 10 )
subsample_fn = vips_subsample_point_gen; subsample_fn = vips_subsample_point_gen;
else else
subsample_fn = vips_subsample_line_gen; subsample_fn = vips_subsample_line_gen;
if( vips_image_generate( conversion->out, if( vips_image_generate( conversion->out,
vips_start_one, subsample_fn, vips_stop_one, vips_start_one, subsample_fn, vips_stop_one,
subsample->in, subsample ) ) subsample->in, subsample ) )
@ -284,6 +287,13 @@ vips_subsample_class_init( VipsSubsampleClass *class )
G_STRUCT_OFFSET( VipsSubsample, yfac ), G_STRUCT_OFFSET( VipsSubsample, yfac ),
1, RANGE, 1 ); 1, RANGE, 1 );
VIPS_ARG_BOOL( class, "point", 2,
_( "Point" ),
_( "Point sample" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsSubsample, point ),
FALSE );
} }
static void static void
@ -299,9 +309,20 @@ vips_subsample_init( VipsSubsample *subsample )
* @yfac: vertical shrink factor * @yfac: vertical shrink factor
* @...: %NULL-terminated list of optional named arguments * @...: %NULL-terminated list of optional named arguments
* *
* Optional arguments:
*
* @point: turn on point sample mode
*
* Subsample an image by an integer fraction. This is fast, nearest-neighbour * Subsample an image by an integer fraction. This is fast, nearest-neighbour
* shrink. * shrink.
* *
* For small horizontal shrinks, this operation will fetch lines of pixels
* from @in and then subsample that line. For large shrinks it will fetch
* single pixels.
*
* If @point is set, @in will always be sampled in points. This can be faster
* if the previous operations in the pipeline are very slow.
*
* See also: vips_affine(), vips_shrink(), vips_zoom(). * See also: vips_affine(), vips_shrink(), vips_zoom().
* *
* Returns: 0 on success, -1 on error. * Returns: 0 on success, -1 on error.