1 /* base class for all resample operations
2 *
3 * properties:
4 * - one in, one out
5 * - not point-to-point
6 * - size can change in any way
7 * - bands, type, format etc. all fixed
8 */
9
10 /*
11
12 Copyright (C) 1991-2005 The National Gallery
13
14 This library is free software; you can redistribute it and/or
15 modify it under the terms of the GNU Lesser General Public
16 License as published by the Free Software Foundation; either
17 version 2.1 of the License, or (at your option) any later version.
18
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
23
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 02110-1301 USA
28
29 */
30
31 /*
32
33 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
34
35 */
36
37 /*
38 #define DEBUG
39 */
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif /*HAVE_CONFIG_H*/
44 #include <vips/intl.h>
45
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <math.h>
49
50 #include <vips/vips.h>
51 #include <vips/internal.h>
52
53 #include "presample.h"
54
55 /**
56 * SECTION: resample
57 * @short_description: resample images in various ways
58 * @stability: Stable
59 * @include: vips/vips.h
60 *
61 * There are three types of operation in this section.
62 *
63 * First, vips_affine() applies an affine transform to an image. This is any
64 * sort of 2D transform which preserves straight lines; so any combination of
65 * stretch, sheer, rotate and translate. You supply an interpolator for it to
66 * use to generate pixels, see vips_interpolate_new(). It will not produce
67 * good results for very large shrinks: you'll see aliasing.
68 *
69 * vips_reduce() is like vips_affine(), but it can only shrink images, it can't
70 * enlarge, rotate, or skew. It's very fast and uses an adaptive kernel for
71 * interpolation.
72 *
73 * vips_shrink() is a fast block shrinker. It can quickly reduce images by
74 * large integer factors. It will give poor results for small size reductions:
75 * again, you'll see aliasing.
76 *
77 * Next, vips_resize() specialises in the common task of image reduce and
78 * enlarge. It strings together combinations of vips_shrink(), vips_reduce(),
79 * vips_affine() and others to implement a general, high-quality image
80 * resizer.
81 *
82 * Finally, vips_mapim() can apply arbitrary 2D image transforms to an image.
83 */
84
85 /**
86 * VipsSize:
87 * @VIPS_SIZE_BOTH: size both up and down
88 * @VIPS_SIZE_UP: only upsize
89 * @VIPS_SIZE_DOWN: only downsize
90 * @VIPS_SIZE_FORCE: force size, that is, break aspect ratio
91 *
92 * Controls whether an operation should upsize, downsize, both up and
93 * downsize, or force a size.
94 *
95 * See also: vips_thumbnail().
96 */
97
98 G_DEFINE_ABSTRACT_TYPE( VipsResample, vips_resample, VIPS_TYPE_OPERATION );
99
100 static int
vips_resample_build(VipsObject * object)101 vips_resample_build( VipsObject *object )
102 {
103 VipsResample *resample = VIPS_RESAMPLE( object );
104
105 #ifdef DEBUG
106 printf( "vips_resample_build: " );
107 vips_object_print_name( object );
108 printf( "\n" );
109 #endif /*DEBUG*/
110
111 g_object_set( resample, "out", vips_image_new(), NULL );
112
113 if( VIPS_OBJECT_CLASS( vips_resample_parent_class )->build( object ) )
114 return( -1 );
115
116 return( 0 );
117 }
118
119 static void
vips_resample_class_init(VipsResampleClass * class)120 vips_resample_class_init( VipsResampleClass *class )
121 {
122 GObjectClass *gobject_class = G_OBJECT_CLASS( class );
123 VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
124
125 gobject_class->set_property = vips_object_set_property;
126 gobject_class->get_property = vips_object_get_property;
127
128 vobject_class->nickname = "resample";
129 vobject_class->description = _( "resample operations" );
130 vobject_class->build = vips_resample_build;
131
132 VIPS_ARG_IMAGE( class, "in", 1,
133 _( "Input" ),
134 _( "Input image argument" ),
135 VIPS_ARGUMENT_REQUIRED_INPUT,
136 G_STRUCT_OFFSET( VipsResample, in ) );
137
138 VIPS_ARG_IMAGE( class, "out", 2,
139 _( "Output" ),
140 _( "Output image" ),
141 VIPS_ARGUMENT_REQUIRED_OUTPUT,
142 G_STRUCT_OFFSET( VipsResample, out ) );
143
144 }
145
146 static void
vips_resample_init(VipsResample * resample)147 vips_resample_init( VipsResample *resample )
148 {
149 }
150
151 /* Called from iofuncs to init all operations in this dir. Use a plugin system
152 * instead?
153 */
154 void
vips_resample_operation_init(void)155 vips_resample_operation_init( void )
156 {
157 extern GType vips_thumbnail_file_get_type( void );
158 extern GType vips_thumbnail_buffer_get_type( void );
159 extern GType vips_thumbnail_image_get_type( void );
160 extern GType vips_thumbnail_source_get_type( void );
161 extern GType vips_mapim_get_type( void );
162 extern GType vips_shrink_get_type( void );
163 extern GType vips_shrinkh_get_type( void );
164 extern GType vips_shrinkv_get_type( void );
165 extern GType vips_reduce_get_type( void );
166 extern GType vips_reduceh_get_type( void );
167 extern GType vips_reducev_get_type( void );
168 extern GType vips_quadratic_get_type( void );
169 extern GType vips_affine_get_type( void );
170 extern GType vips_similarity_get_type( void );
171 extern GType vips_rotate_get_type( void );
172 extern GType vips_resize_get_type( void );
173
174 vips_thumbnail_file_get_type();
175 vips_thumbnail_buffer_get_type();
176 vips_thumbnail_image_get_type();
177 vips_thumbnail_source_get_type();
178 vips_mapim_get_type();
179 vips_shrink_get_type();
180 vips_shrinkh_get_type();
181 vips_shrinkv_get_type();
182 vips_reduceh_get_type();
183 vips_reducev_get_type();
184 vips_reduce_get_type();
185 vips_quadratic_get_type();
186 vips_affine_get_type();
187 vips_similarity_get_type();
188 vips_rotate_get_type();
189 vips_resize_get_type();
190 }
191
192