1 /* Various interpolators. 2 * 3 * J.Cupitt, 15/10/08 4 */ 5 6 /* 7 8 This file is part of VIPS. 9 10 VIPS is free software; you can redistribute it and/or modify 11 it under the terms of the GNU Lesser General Public License as published by 12 the Free Software Foundation; either version 2 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU Lesser General Public License for more details. 19 20 You should have received a copy of the GNU Lesser General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 02110-1301 USA 24 25 */ 26 27 /* 28 29 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk 30 31 */ 32 33 #ifndef VIPS_INTERPOLATE_H 34 #define VIPS_INTERPOLATE_H 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif /*__cplusplus*/ 39 40 #define VIPS_TYPE_INTERPOLATE (vips_interpolate_get_type()) 41 #define VIPS_INTERPOLATE( obj ) \ 42 (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ 43 VIPS_TYPE_INTERPOLATE, VipsInterpolate )) 44 #define VIPS_INTERPOLATE_CLASS( klass ) \ 45 (G_TYPE_CHECK_CLASS_CAST( (klass), \ 46 VIPS_TYPE_INTERPOLATE, VipsInterpolateClass)) 47 #define VIPS_IS_INTERPOLATE( obj ) \ 48 (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_INTERPOLATE )) 49 #define VIPS_IS_INTERPOLATE_CLASS( klass ) \ 50 (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_INTERPOLATE )) 51 #define VIPS_INTERPOLATE_GET_CLASS( obj ) \ 52 (G_TYPE_INSTANCE_GET_CLASS( (obj), \ 53 VIPS_TYPE_INTERPOLATE, VipsInterpolateClass )) 54 55 typedef struct _VipsInterpolate { 56 VipsObject parent_object; 57 58 } VipsInterpolate; 59 60 /* An interpolation function. This is a class method, but we have a lookup 61 * function for it to speed up dispatch. Write to the memory at "out", 62 * interpolate the value at position (x, y) in "in". 63 */ 64 typedef void (*VipsInterpolateMethod)( VipsInterpolate *interpolate, 65 void *out, VipsRegion *in, double x, double y ); 66 67 typedef struct _VipsInterpolateClass { 68 VipsObjectClass parent_class; 69 70 /* Write to pixel out(x,y), interpolating from in(x,y). The caller has 71 * to set the regions up. 72 */ 73 VipsInterpolateMethod interpolate; 74 75 /* This interpolator needs a window this many pixels across and down. 76 */ 77 int (*get_window_size)( VipsInterpolate *interpolate ); 78 79 /* Or just set this if you want a constant. 80 */ 81 int window_size; 82 83 /* Stencils are offset by this much. Default to window_size / 2 - 1 84 * (centering) if get_window_offset is NULL and window_offset is -1. 85 */ 86 int (*get_window_offset)( VipsInterpolate *interpolate ); 87 int window_offset; 88 } VipsInterpolateClass; 89 90 /* Don't put spaces around void here, it breaks gtk-doc. 91 */ 92 GType vips_interpolate_get_type(void); 93 void vips_interpolate( VipsInterpolate *interpolate, 94 void *out, VipsRegion *in, double x, double y ); 95 VipsInterpolateMethod vips_interpolate_get_method( VipsInterpolate *interpolate ); 96 int vips_interpolate_get_window_size( VipsInterpolate *interpolate ); 97 int vips_interpolate_get_window_offset( VipsInterpolate *interpolate ); 98 99 /* How many bits of precision we keep for transformations, ie. how many 100 * pre-computed matricies we have. 101 */ 102 #define VIPS_TRANSFORM_SHIFT (6) 103 #define VIPS_TRANSFORM_SCALE (1 << VIPS_TRANSFORM_SHIFT) 104 105 /* How many bits of precision we keep for interpolation, ie. where the decimal 106 * is in the fixed-point tables. For 16-bit pixels, we need 16 bits for the 107 * data and 4 bits to add 16 values together. That leaves 12 bits for the 108 * fractional part. 109 */ 110 #define VIPS_INTERPOLATE_SHIFT (12) 111 #define VIPS_INTERPOLATE_SCALE (1 << VIPS_INTERPOLATE_SHIFT) 112 113 /* Convenience: return static interpolators, no need to unref. 114 */ 115 VipsInterpolate *vips_interpolate_nearest_static( void ); 116 VipsInterpolate *vips_interpolate_bilinear_static( void ); 117 118 /* Convenience: make an interpolator from a nickname. g_object_unref() when 119 * you're done with it. 120 */ 121 VipsInterpolate *vips_interpolate_new( const char *nickname ); 122 123 #ifdef __cplusplus 124 } 125 #endif /*__cplusplus*/ 126 127 #endif /*VIPS_INTERPOLATE_H*/ 128 129