1 /* the GTypes we define
2  *
3  * 27/10/11
4  * 	- from header.h
5  */
6 
7 /*
8 
9     This file is part of VIPS.
10 
11     VIPS is free software; you can redistribute it and/or modify
12     it under the terms of the GNU Lesser General Public License as published by
13     the Free Software Foundation; either version 2 of the License, or
14     (at your option) any later version.
15 
16     This program is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     GNU Lesser General Public License for more details.
20 
21     You should have received a copy of the GNU Lesser General Public License
22     along with this program; if not, write to the Free Software
23     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24     02110-1301  USA
25 
26  */
27 
28 /*
29 
30     These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
31 
32  */
33 
34 #ifndef VIPS_TYPE_H
35 #define VIPS_TYPE_H
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /*__cplusplus*/
40 
41 /* A very simple boxed type for testing. Just holds an int.
42  */
43 typedef struct _VipsThing {
44 	int i;
45 } VipsThing;
46 
47 /**
48  * VIPS_TYPE_THING:
49  *
50  * The #GType for a #VipsThing.
51  */
52 #define VIPS_TYPE_THING (vips_thing_get_type())
53 GType vips_thing_get_type(void);
54 VipsThing *vips_thing_new( int i );
55 
56 /* A ref-counted area of memory. Can hold arrays of things as well.
57  */
58 typedef struct _VipsArea {
59 	void *data;
60 	size_t length;		/* 0 if not known */
61 
62 	/* If this area represents an array, the number of elements in the
63 	 * array. Equal to length / sizeof(element).
64 	 */
65 	int n;
66 
67 	/*< private >*/
68 
69 	/* Reference count and lock.
70 	 *
71 	 * We could use an atomic int, but this is not a high-traffic data
72 	 * structure, so a simple GMutex is OK.
73 	 */
74 	int count;
75 	GMutex *lock;
76 
77 	/* Things like ICC profiles need their own free functions.
78 	 *
79 	 * Set client to anything you like -- VipsArea doesn't use this.
80 	 */
81 	VipsCallbackFn free_fn;
82 	void *client;
83 
84 	/* If we are holding an array (for example, an array of double), the
85 	 * GType of the elements and their size. 0 for not known.
86 	 *
87 	 * n is always length / sizeof_type, we keep it as a member for
88 	 * convenience.
89 	 */
90 	GType type;
91 	size_t sizeof_type;
92 } VipsArea;
93 
94 VipsArea *vips_area_copy( VipsArea *area );
95 int vips_area_free_cb( void *mem, VipsArea *area );
96 void vips_area_unref( VipsArea *area );
97 
98 VipsArea *vips_area_new( VipsCallbackFn free_fn, void *data );
99 VipsArea *vips_area_new_array( GType type, size_t sizeof_type, int n );
100 VipsArea *vips_area_new_array_object( int n );
101 void *vips_area_get_data( VipsArea *area,
102 	size_t *length, int *n, GType *type, size_t *sizeof_type );
103 
104 #ifdef VIPS_DEBUG
105 #define VIPS_ARRAY_ADDR( X, I ) \
106 	(((I) >= 0 && (I) < VIPS_AREA( X )->n) ? \
107 	 (void *) ((VipsPel *) VIPS_AREA( X )->data + \
108 		VIPS_AREA( X )->sizeof_type * (I)) : \
109 	 (fprintf( stderr, \
110 		"VIPS_ARRAY_ADDR: index out of bounds, " \
111 		"file \"%s\", line %d\n" \
112 		"(index %d should have been within [0,%d])\n", \
113 		__FILE__, __LINE__, \
114 		(I), VIPS_AREA( X )->n ), NULL ))
115 #else /*!VIPS_DEBUG*/
116 #define VIPS_ARRAY_ADDR( X, I ) \
117 	((void *) \
118 	 ((VipsPel *) VIPS_AREA( X )->data + VIPS_AREA( X )->sizeof_type * (I)))
119 #endif /*VIPS_DEBUG*/
120 
121 /**
122  * VIPS_TYPE_AREA:
123  *
124  * The #GType for a #VipsArea.
125  */
126 #define VIPS_TYPE_AREA (vips_area_get_type())
127 #define VIPS_AREA( X ) ((VipsArea *) (X))
128 GType vips_area_get_type(void);
129 
130 /**
131  * VIPS_TYPE_SAVE_STRING:
132  *
133  * The #GType for a #VipsSaveString.
134  */
135 #define VIPS_TYPE_SAVE_STRING (vips_save_string_get_type())
136 GType vips_save_string_get_type(void);
137 
138 /**
139  * VIPS_TYPE_REF_STRING:
140  *
141  * The #GType for a #VipsRefString.
142  */
143 #define VIPS_TYPE_REF_STRING (vips_ref_string_get_type())
144 
145 typedef struct _VipsRefString {
146 	VipsArea area;
147 } VipsRefString;
148 
149 VipsRefString *vips_ref_string_new( const char *str );
150 const char *vips_ref_string_get( VipsRefString *refstr, size_t *length );
151 GType vips_ref_string_get_type(void);
152 
153 /**
154  * VIPS_TYPE_BLOB:
155  *
156  * The %GType for a #VipsBlob.
157  */
158 #define VIPS_TYPE_BLOB (vips_blob_get_type())
159 
160 typedef struct _VipsBlob {
161 	VipsArea area;
162 } VipsBlob;
163 
164 VipsBlob *vips_blob_new( VipsCallbackFn free_fn,
165 	const void *data, size_t length );
166 VipsBlob *vips_blob_copy( const void *data, size_t length );
167 const void *vips_blob_get( VipsBlob *blob, size_t *length );
168 void vips_blob_set( VipsBlob *blob,
169 	VipsCallbackFn free_fn, const void *data, size_t length );
170 GType vips_blob_get_type(void);
171 
172 /**
173  * VIPS_TYPE_ARRAY_DOUBLE:
174  *
175  * The #GType for a #VipsArrayDouble.
176  */
177 #define VIPS_TYPE_ARRAY_DOUBLE (vips_array_double_get_type())
178 
179 typedef struct _VipsArrayDouble {
180 	VipsArea area;
181 } VipsArrayDouble;
182 
183 VipsArrayDouble *vips_array_double_new( const double *array, int n );
184 VipsArrayDouble *vips_array_double_newv( int n, ... );
185 double *vips_array_double_get( VipsArrayDouble *array, int *n );
186 GType vips_array_double_get_type(void);
187 
188 /**
189  * VIPS_TYPE_ARRAY_INT:
190  *
191  * The #GType for a #VipsArrayInt.
192  */
193 #define VIPS_TYPE_ARRAY_INT (vips_array_int_get_type())
194 
195 typedef struct _VipsArrayInt {
196 	VipsArea area;
197 } VipsArrayInt;
198 
199 VipsArrayInt *vips_array_int_new( const int *array, int n );
200 VipsArrayInt *vips_array_int_newv( int n, ... );
201 int *vips_array_int_get( VipsArrayInt *array, int *n );
202 GType vips_array_int_get_type(void);
203 
204 /**
205  * VIPS_TYPE_ARRAY_IMAGE:
206  *
207  * The #GType for a #VipsArrayImage.
208  */
209 #define VIPS_TYPE_ARRAY_IMAGE (vips_array_image_get_type())
210 
211 typedef struct _VipsArrayImage {
212 	VipsArea area;
213 } VipsArrayImage;
214 
215 /* See image.h for vips_array_image_new() etc., they need to be declared after
216  * VipsImage.
217  */
218 GType vips_array_image_get_type(void);
219 
220 void vips_value_set_area( GValue *value, VipsCallbackFn free_fn, void *data );
221 void *vips_value_get_area( const GValue *value, size_t *length );
222 
223 const char *vips_value_get_save_string( const GValue *value );
224 void vips_value_set_save_string( GValue *value, const char *str );
225 void vips_value_set_save_stringf( GValue *value, const char *fmt, ... )
226 	__attribute__((format(printf, 2, 3)));
227 
228 const char *vips_value_get_ref_string( const GValue *value, size_t *length );
229 void vips_value_set_ref_string( GValue *value, const char *str );
230 
231 void *vips_value_get_blob( const GValue *value, size_t *length );
232 void vips_value_set_blob( GValue *value,
233 	VipsCallbackFn free_fn, const void *data, size_t length );
234 void vips_value_set_blob_free( GValue *value, void *data, size_t length );
235 
236 void vips_value_set_array( GValue *value,
237 	int n, GType type, size_t sizeof_type );
238 void *vips_value_get_array( const GValue *value,
239 	int *n, GType *type, size_t *sizeof_type );
240 
241 double *vips_value_get_array_double( const GValue *value, int *n );
242 void vips_value_set_array_double( GValue *value, const double *array, int n );
243 
244 int *vips_value_get_array_int( const GValue *value, int *n );
245 void vips_value_set_array_int( GValue *value, const int *array, int n );
246 
247 GObject **vips_value_get_array_object( const GValue *value, int *n );
248 void vips_value_set_array_object( GValue *value, int n );
249 
250 /* See also image.h, that has vips_array_image_get(), vips_array_image_new(),
251  * vips_value_get_array_image() and vips_value_set_array_image(). They need
252  * to be declared after VipsImage.
253  */
254 
255 #ifdef __cplusplus
256 }
257 #endif /*__cplusplus*/
258 
259 #endif /*VIPS_TYPE_H*/
260