@@ -90,48 +90,6 @@ vips__tiff_init( void )
90
90
TIFFSetWarningHandler ( vips__thandler_warning );
91
91
}
92
92
93
- /* Open TIFF for output.
94
- */
95
- TIFF *
96
- vips__tiff_openout ( const char * path , gboolean bigtiff )
97
- {
98
- TIFF * tif ;
99
- const char * mode = bigtiff ? "w8" : "w" ;
100
-
101
- #ifdef DEBUG
102
- printf ( "vips__tiff_openout( \"%s\", \"%s\" )\n" , path , mode );
103
- #endif /*DEBUG*/
104
-
105
- /* Need the utf-16 version on Windows.
106
- */
107
- #ifdef G_OS_WIN32
108
- {
109
- GError * error = NULL ;
110
- wchar_t * path16 ;
111
-
112
- if ( !(path16 = (wchar_t * )
113
- g_utf8_to_utf16 ( path , -1 , NULL , NULL , & error )) ) {
114
- vips_g_error ( & error );
115
- return ( NULL );
116
- }
117
-
118
- tif = TIFFOpenW ( path16 , mode );
119
-
120
- g_free ( path16 );
121
- }
122
- #else /*!G_OS_WIN32*/
123
- tif = TIFFOpen ( path , mode );
124
- #endif /*G_OS_WIN32*/
125
-
126
- if ( !tif ) {
127
- vips_error ( "tiff" ,
128
- _ ( "unable to open \"%s\" for output" ), path );
129
- return ( NULL );
130
- }
131
-
132
- return ( tif );
133
- }
134
-
135
93
/* TIFF input from a vips source.
136
94
*/
137
95
@@ -152,13 +110,11 @@ openin_source_write( thandle_t st, tdata_t buffer, tsize_t size )
152
110
}
153
111
154
112
static toff_t
155
- openin_source_seek ( thandle_t st , toff_t position , int whence )
113
+ openin_source_seek ( thandle_t st , toff_t offset , int whence )
156
114
{
157
115
VipsSource * source = VIPS_SOURCE ( st );
158
116
159
- /* toff_t is usually uint64, with -1 cast to uint64 to indicate error.
160
- */
161
- return ( (toff_t ) vips_source_seek ( source , position , whence ) );
117
+ return ( (toff_t ) vips_source_seek ( source , offset , whence ) );
162
118
}
163
119
164
120
static int
@@ -240,151 +196,99 @@ vips__tiff_openin_source( VipsSource *source )
240
196
return ( tiff );
241
197
}
242
198
243
- /* TIFF output to a memory buffer .
199
+ /* TIFF output to a target .
244
200
*/
245
201
246
- typedef struct _VipsTiffOpenoutBuffer {
247
- VipsDbuf dbuf ;
248
-
249
- /* On close, consolidate and write the output here.
250
- */
251
- void * * out_data ;
252
- size_t * out_length ;
253
- } VipsTiffOpenoutBuffer ;
254
-
202
+ /* libtiff needs this (!!?!?!) for writing multipage images.
203
+ */
255
204
static tsize_t
256
- openout_buffer_read ( thandle_t st , tdata_t data , tsize_t size )
205
+ openout_target_read ( thandle_t st , tdata_t data , tsize_t size )
257
206
{
258
- VipsTiffOpenoutBuffer * buffer = (VipsTiffOpenoutBuffer * ) st ;
259
-
260
- #ifdef DEBUG
261
- printf ( "openout_buffer_read: %zd bytes\n" , size );
262
- #endif /*DEBUG*/
207
+ VipsTarget * target = (VipsTarget * ) st ;
263
208
264
- return ( vips_dbuf_read ( & buffer -> dbuf , data , size ) );
209
+ return ( vips_target_read ( target , data , size ) );
265
210
}
266
211
267
212
static tsize_t
268
- openout_buffer_write ( thandle_t st , tdata_t data , tsize_t size )
213
+ openout_target_write ( thandle_t st , tdata_t data , tsize_t size )
269
214
{
270
- VipsTiffOpenoutBuffer * buffer = (VipsTiffOpenoutBuffer * ) st ;
215
+ VipsTarget * target = (VipsTarget * ) st ;
271
216
272
- #ifdef DEBUG
273
- printf ( "openout_buffer_write: %zd bytes\n" , size );
274
- #endif /*DEBUG*/
275
-
276
- vips_dbuf_write ( & buffer -> dbuf , data , size );
217
+ if ( vips_target_write ( target , data , size ) )
218
+ return ( (tsize_t ) - 1 );
277
219
278
220
return ( size );
279
221
}
280
222
281
- static int
282
- openout_buffer_close ( thandle_t st )
223
+ static toff_t
224
+ openout_target_seek ( thandle_t st , toff_t offset , int whence )
283
225
{
284
- VipsTiffOpenoutBuffer * buffer = (VipsTiffOpenoutBuffer * ) st ;
285
-
286
- * (buffer -> out_data ) = vips_dbuf_steal ( & buffer -> dbuf ,
287
- buffer -> out_length );
226
+ VipsTarget * target = (VipsTarget * ) st ;
288
227
289
- return ( 0 );
228
+ return ( vips_target_seek ( target , offset , whence ) );
290
229
}
291
230
292
- static toff_t
293
- openout_buffer_seek ( thandle_t st , toff_t position , int whence )
231
+ static int
232
+ openout_target_close ( thandle_t st )
294
233
{
295
- VipsTiffOpenoutBuffer * buffer = (VipsTiffOpenoutBuffer * ) st ;
296
-
297
- #ifdef DEBUG
298
- printf ( "openout_buffer_seek: position %zd, whence %d " ,
299
- position , whence );
300
- switch ( whence ) {
301
- case SEEK_SET :
302
- printf ( "set" );
303
- break ;
304
-
305
- case SEEK_END :
306
- printf ( "end" );
307
- break ;
308
-
309
- case SEEK_CUR :
310
- printf ( "cur" );
311
- break ;
312
-
313
- default :
314
- printf ( "unknown" );
315
- break ;
316
- }
317
- printf ( "\n" );
318
- #endif /*DEBUG*/
234
+ VipsTarget * target = (VipsTarget * ) st ;
319
235
320
- vips_dbuf_seek ( & buffer -> dbuf , position , whence );
236
+ if ( vips_target_end ( target ) )
237
+ return ( -1 );
321
238
322
- return ( vips_dbuf_tell ( & buffer -> dbuf ) );
239
+ return ( 0 );
323
240
}
324
241
325
242
static toff_t
326
- openout_buffer_length ( thandle_t st )
243
+ openout_target_length ( thandle_t st )
327
244
{
328
245
g_assert_not_reached ();
329
246
330
- return ( 0 );
247
+ return ( ( toff_t ) - 1 );
331
248
}
332
249
333
250
static int
334
- openout_buffer_map ( thandle_t st , tdata_t * start , toff_t * len )
251
+ openout_target_map ( thandle_t st , tdata_t * start , toff_t * len )
335
252
{
336
253
g_assert_not_reached ();
337
254
338
- return ( 0 );
255
+ return ( -1 );
339
256
}
340
257
341
258
static void
342
- openout_buffer_unmap ( thandle_t st , tdata_t start , toff_t len )
259
+ openout_target_unmap ( thandle_t st , tdata_t start , toff_t len )
343
260
{
344
261
g_assert_not_reached ();
345
262
346
263
return ;
347
264
}
348
265
349
- /* On TIFFClose(), @data and @length are set to point to the output buffer.
350
- */
351
266
TIFF *
352
- vips__tiff_openout_buffer ( VipsImage * image ,
353
- gboolean bigtiff , void * * out_data , size_t * out_length )
267
+ vips__tiff_openout_target ( VipsTarget * target , gboolean bigtiff )
354
268
{
355
269
const char * mode = bigtiff ? "w8" : "w" ;
356
270
357
- VipsTiffOpenoutBuffer * buffer ;
358
271
TIFF * tiff ;
359
272
360
273
#ifdef DEBUG
361
274
printf ( "vips__tiff_openout_buffer:\n" );
362
275
#endif /*DEBUG*/
363
276
364
- g_assert ( out_data );
365
- g_assert ( out_length );
366
-
367
- buffer = VIPS_NEW ( image , VipsTiffOpenoutBuffer );
368
- vips_dbuf_init ( & buffer -> dbuf );
369
- buffer -> out_data = out_data ;
370
- buffer -> out_length = out_length ;
371
-
372
- if ( !(tiff = TIFFClientOpen ( "memory output" , mode ,
373
- (thandle_t ) buffer ,
374
- openout_buffer_read ,
375
- openout_buffer_write ,
376
- openout_buffer_seek ,
377
- openout_buffer_close ,
378
- openout_buffer_length ,
379
- openout_buffer_map ,
380
- openout_buffer_unmap )) ) {
381
- vips_error ( "vips__tiff_openout_buffer" , "%s" ,
382
- _ ( "unable to open memory buffer for output" ) );
277
+ if ( !(tiff = TIFFClientOpen ( "target output" , mode ,
278
+ (thandle_t ) target ,
279
+ openout_target_read ,
280
+ openout_target_write ,
281
+ openout_target_seek ,
282
+ openout_target_close ,
283
+ openout_target_length ,
284
+ openout_target_map ,
285
+ openout_target_unmap )) ) {
286
+ vips_error ( "vips__tiff_openout_target" , "%s" ,
287
+ _ ( "unable to open target for output" ) );
383
288
return ( NULL );
384
289
}
385
290
386
291
return ( tiff );
387
292
}
388
293
389
294
#endif /*HAVE_TIFF*/
390
-
0 commit comments