more cleanups after loadable formats

This commit is contained in:
John Cupitt 2008-08-16 17:03:45 +00:00
parent ab57aba02e
commit 72ff1d89c7
30 changed files with 71 additions and 97 deletions

12
TODO
View File

@ -1,12 +1,22 @@
- check man pages for im_isjpeg(), im_jpeg2vips_header() etc.
- write man pages for im_format api
- operations and jesper's types should all use the new register/unregister
model
support backwards compat by calling im_operation_register() automatically
if we see a package_table symbol
package.c needs to have the format_table stuff removed
have new structs with new fields under new names? eg. jesper wants something
to write to a string
check other use cases eg. nip2, python, c++, vips.c
- add new type names, eg. im_region_t, im_image_t etc. and deprecate old
names?
plugin init

View File

@ -52,7 +52,7 @@ typedef im_format_flags (*im_format_flags_fn)( const char * );
/* A VIPS image format.
*/
typedef struct {
typedef struct im__format_t {
const char *name; /* Format name, same as mime */
const char *name_user; /* I18n'd name for users */
int priority; /* Keep formats sorted by this, default 0 */
@ -62,23 +62,23 @@ typedef struct {
im_format_load_fn load; /* Load image from filename */
im_format_save_fn save; /* Save image to filename */
im_format_flags_fn flags;/* Get flags for filename */
} im_format;
} im_format_t;
/* Register/unregister formats.
*/
im_format *im_format_register(
im_format_t *im_format_register(
const char *name, const char *name_user, const char **suffs,
im_format_is_a_fn is_a, im_format_header_fn header,
im_format_load_fn load, im_format_save_fn save,
im_format_flags_fn flags );
void im_format_set_priority( im_format *format, int priority );
void im_format_unregister( im_format *format );
void im_format_set_priority( im_format_t *format, int priority );
void im_format_unregister( im_format_t *format );
/* Map over and find formats.
*/
void *im_format_map( VSListMap2Fn fn, void *a, void *b );
im_format *im_format_for_file( const char *filename );
im_format *im_format_for_name( const char *filename );
im_format_t *im_format_for_file( const char *filename );
im_format_t *im_format_for_name( const char *filename );
#ifdef __cplusplus
}

View File

@ -37,6 +37,23 @@
extern "C" {
#endif /*__cplusplus*/
/* What we store in the Meta hash table. We can't just use GHashTable's
* key/value pairs, since we need to iterate over meta in Meta_traverse order.
*
* We don't refcount at this level ... large meta values are refcounted by
* their GValue implementation, see eg. MetaArea.
*/
typedef struct _Meta {
IMAGE *im;
char *field; /* strdup() of field name */
GValue value; /* copy of value */
} Meta;
void im__meta_init_types( void );
void im__meta_destroy( IMAGE *im );
int im__meta_cp( IMAGE *, const IMAGE * );
/* Default tile geometry.
*/
extern int im__tile_width;

View File

@ -65,19 +65,6 @@ void *im_blob_get( const GValue *value, size_t *data_length );
int im_blob_set( GValue *value, im_callback_fn free_fn,
void *data, size_t length );
/* What we store in the Meta hash table. We can't just use GHashTable's
* key/value pairs, since we need to iterate over meta in Meta_traverse order.
*
* We don't refcount at this level ... large meta values are refcounted by
* their GValue implementation, see eg. MetaArea below.
*/
typedef struct _Meta {
IMAGE *im;
char *field; /* strdup() of field name */
GValue value; /* copy of value */
} Meta;
int im_meta_set( IMAGE *, const char *field, GValue * );
int im_meta_get( IMAGE *, const char *field, GValue * );
GType im_meta_get_type( IMAGE *im, const char *field );
@ -95,12 +82,6 @@ int im_meta_set_blob( IMAGE *im, const char *field,
int im_meta_get_blob( IMAGE *im, const char *field,
void **blob, size_t *blob_length );
/* Internal.
*/
void im__meta_init_types( void );
void im__meta_destroy( IMAGE *im );
int im__meta_cp( IMAGE *, const IMAGE * );
#ifdef __cplusplus
}
#endif /*__cplusplus*/

View File

@ -63,7 +63,7 @@ typedef struct im__buffer_cache_list_t {
/* What we track for each pixel buffer.
*/
typedef struct {
typedef struct im__buffer_t {
int ref_count; /* # of regions referencing us */
IMAGE *im; /* IMAGE we are attached to */

View File

@ -46,7 +46,7 @@
static GSList *format_list = NULL;
static gint
format_compare( im_format *a, im_format *b )
format_compare( im_format_t *a, im_format_t *b )
{
return( b->priority - a->priority );
}
@ -62,15 +62,15 @@ format_sort( void )
/* Register/unregister formats.
*/
im_format *im_format_register(
im_format_t *im_format_register(
const char *name, const char *name_user, const char **suffs,
im_format_is_a_fn is_a, im_format_header_fn header,
im_format_load_fn load, im_format_save_fn save,
im_format_flags_fn flags )
{
im_format *format;
im_format_t *format;
if( !(format = IM_NEW( NULL, im_format )) )
if( !(format = IM_NEW( NULL, im_format_t )) )
return( NULL );
format->name = name;
format->name_user = name_user;
@ -90,7 +90,7 @@ im_format *im_format_register(
return( format );
}
void im_format_set_priority( im_format *format, int priority )
void im_format_set_priority( im_format_t *format, int priority )
{
g_assert( format );
@ -98,7 +98,7 @@ void im_format_set_priority( im_format *format, int priority )
format_sort();
}
void im_format_unregister( im_format *format )
void im_format_unregister( im_format_t *format )
{
format_list = g_slist_remove( format_list, format );
}
@ -108,14 +108,24 @@ void im_format_unregister( im_format *format )
void
im__format_init( void )
{
#ifdef HAVE_JPEG
im__jpeg_register();
#endif /*HAVE_JPEG*/
#ifndef HAVE_PNG
im__png_register();
#endif /*HAVE_PNG*/
im__csv_register();
im__ppm_register();
im__analyze_register();
#ifdef HAVE_OPENEXR
im__exr_register();
#endif /*HAVE_OPENEXR*/
#ifdef HAVE_MAGICK
im__magick_register();
#endif /*HAVE_MAGICK*/
#ifdef HAVE_TIFF
im__tiff_register();
#endif /*HAVE_TIFF*/
}
/* Map a function over all formats.
@ -129,7 +139,7 @@ im_format_map( VSListMap2Fn fn, void *a, void *b )
/* Can this format open this file?
*/
static void *
format_for_file_sub( im_format *format,
format_for_file_sub( im_format_t *format,
const char *filename, const char *name )
{
if( format->is_a ) {
@ -142,12 +152,12 @@ format_for_file_sub( im_format *format,
return( NULL );
}
im_format *
im_format_t *
im_format_for_file( const char *filename )
{
char name[FILENAME_MAX];
char options[FILENAME_MAX];
im_format *format;
im_format_t *format;
/* Break any options off the name ... eg. "fred.tif:jpeg,tile"
* etc.
@ -160,7 +170,7 @@ im_format_for_file( const char *filename )
return( NULL );
}
format = (im_format *) im_format_map(
format = (im_format_t *) im_format_map(
(VSListMap2Fn) format_for_file_sub,
(void *) filename, (void *) name );
@ -177,7 +187,7 @@ im_format_for_file( const char *filename )
* method.
*/
static void *
format_for_name_sub( im_format *format,
format_for_name_sub( im_format_t *format,
const char *filename, const char *name )
{
if( format->save &&
@ -187,7 +197,7 @@ format_for_name_sub( im_format *format,
return( NULL );
}
im_format *
im_format_t *
im_format_for_name( const char *filename )
{
char name[FILENAME_MAX];
@ -198,7 +208,7 @@ im_format_for_name( const char *filename )
*/
im_filename_split( filename, name, options );
return( (im_format *) im_format_map(
return( (im_format_t *) im_format_map(
(VSListMap2Fn) format_for_name_sub,
(void *) filename, (void *) name ) );
}

View File

@ -594,7 +594,7 @@ im__analyze_register( void )
{
im_format_register(
"analyze", /* internal name */
N_( "Analyze 6.0" ), /* i18n'd visible name */
_( "Analyze 6.0" ), /* i18n'd visible name */
analyze_suffs, /* Allowed suffixes */
isanalyze, /* is_a */
analyze2vips_header, /* Load header only */

View File

@ -322,7 +322,7 @@ im__csv_register( void )
{
im_format_register(
"csv", /* internal name */
N_( "CSV" ), /* i18n'd visible name */
_( "CSV" ), /* i18n'd visible name */
csv_suffs, /* Allowed suffixes */
NULL, /* is_a */
csv2vips_header, /* Load header only */

View File

@ -69,8 +69,6 @@ im_exr2vips( const char *name, IMAGE *out )
return( -1 );
}
int im__exr_register( void );
#else /*HAVE_OPENEXR*/
#include <stdio.h>
@ -468,7 +466,7 @@ im__exr_register( void )
{
im_format_register(
"exr", /* internal name */
N_( "OpenEXR" ), /* i18n'd visible name */
_( "OpenEXR" ), /* i18n'd visible name */
exr_suffs, /* Allowed suffixes */
isexr, /* is_a */
exr2vips_header, /* Load header only */

View File

@ -72,11 +72,6 @@ im_jpeg2vips( const char *name, IMAGE *out )
return( -1 );
}
void
im__jpeg_register( void )
{
}
#else /*HAVE_JPEG*/
#include <stdio.h>
@ -728,7 +723,7 @@ im__jpeg_register( void )
{
im_format_register(
"jpeg", /* internal name */
N_( "JPEG" ), /* i18n'd visible name */
_( "JPEG" ), /* i18n'd visible name */
jpeg_suffs, /* Allowed suffixes */
isjpeg, /* is_a */
jpeg2vips_header, /* Load header only */

View File

@ -68,11 +68,6 @@ im_magick2vips( const char *filename, IMAGE *im )
return( -1 );
}
int
im__magick_register( void )
{
}
#else /*HAVE_MAGICK*/
#include <stdio.h>
@ -665,11 +660,11 @@ static const char *magick_suffs[] = { NULL };
void
im__magick_register( void )
{
im_format *format;
im_format_t *format;
format = im_format_register(
"magick", /* internal name */
N_( "libMagick-supported" ),/* i18n'd visible name */
_( "libMagick-supported" ),/* i18n'd visible name */
magick_suffs, /* Allowed suffixes */
ismagick, /* is_a */
magick2vips_header, /* Load header only */

View File

@ -60,11 +60,6 @@ im_png2vips( const char *name, IMAGE *out )
return( -1 );
}
void
im__png_register( void )
{
}
#else /*HAVE_PNG*/
#include <stdio.h>
@ -393,7 +388,7 @@ im__png_register( void )
{
im_format_register(
"png", /* internal name */
N_( "PNG" ), /* i18n'd visible name */
_( "PNG" ), /* i18n'd visible name */
png_suffs, /* Allowed suffixes */
ispng, /* is_a */
png2vips_header, /* Load header only */

View File

@ -508,7 +508,7 @@ im__ppm_register( void )
{
im_format_register(
"ppm", /* internal name */
N_( "PPM/PBM/PNM" ), /* i18n'd visible name */
_( "PPM/PBM/PNM" ), /* i18n'd visible name */
ppm_suffs, /* Allowed suffixes */
isppm, /* is_a */
ppm2vips_header, /* Load header only */

View File

@ -151,11 +151,6 @@ im_tiff2vips( const char *tiffile, IMAGE *im )
return( -1 );
}
void
im__tiff_register( void )
{
}
#else /*HAVE_TIFF*/
#include <stdio.h>
@ -1559,7 +1554,7 @@ im__tiff_register( void )
{
im_format_register(
"tiff", /* internal name */
N_( "TIFF" ), /* i18n'd visible name */
_( "TIFF" ), /* i18n'd visible name */
tiff_suffs, /* Allowed suffixes */
istiff, /* is_a */
tiff2vips_header, /* Load header only */

View File

@ -50,6 +50,7 @@
#include <string.h>
#include <vips/vips.h>
#include <vips/internal.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>

View File

@ -345,7 +345,7 @@ IMAGE *
im_open( const char *filename, const char *mode )
{
IMAGE *im;
im_format *format;
im_format_t *format;
char name[FILENAME_MAX];
char mode2[FILENAME_MAX];

View File

@ -67,6 +67,7 @@
#include <assert.h>
#include <vips/vips.h>
#include <vips/internal.h>
#include "base64.h"

View File

@ -126,7 +126,6 @@ man_MANS = \
im_create_fmask.3 \
im_create_imask.3 \
im_csv2vips.3 \
im_csv2vips_header.3 \
im_dE00_fromLab.3 \
im_debugim.3 \
im_dECMC_fromdisp.3 \
@ -164,7 +163,6 @@ man_MANS = \
im_expntra_vec.3 \
im_exptra.3 \
im_exr2vips.3 \
im_exr2vips_header.3 \
im_extract.3 \
im_extract_area.3 \
im_extract_areabands.3 \
@ -267,19 +265,13 @@ man_MANS = \
im_isfile.3 \
im_isfloat.3 \
im_isint.3 \
im_isjpeg.3 \
im_isMSBfirst.3 \
im_ispartial.3 \
im_ispng.3 \
im_isppm.3 \
im_isscalar.3 \
im_istiff.3 \
im_istifftiled.3 \
im_isuint.3 \
im_isvips.3 \
im_iterate.3 \
im_jpeg2vips.3 \
im_jpeg2vips_header.3 \
im_Lab2disp.3 \
im_Lab2LabQ.3 \
im_Lab2LabS.3 \
@ -322,7 +314,6 @@ man_MANS = \
im_lu_decomp.3 \
im_lu_solve.3 \
im_magick2vips.3 \
im_magick2vips_header.3 \
im_makerw.3 \
im_make_xy.3 \
im_malloc.3 \
@ -396,12 +387,10 @@ man_MANS = \
im_plotmask.3 \
im_plotpoint.3 \
im_png2vips.3 \
im_png2vips_header.3 \
im_poutcheck.3 \
im_powtra.3 \
im_powtra_vec.3 \
im_ppm2vips.3 \
im_ppm2vips_header.3 \
im_prepare.3 \
im_prepare_many.3 \
im_prepare_to.3 \
@ -502,7 +491,6 @@ man_MANS = \
im_text.3 \
im_thresh.3 \
im_tiff2vips.3 \
im_tiff2vips_header.3 \
im_tile_cache.3 \
im_tone_analyse.3 \
im_tone_build.3 \

View File

@ -1 +0,0 @@
.so man3/im_csv2vips.3

View File

@ -1 +0,0 @@
.so man3/im_exr2vips.3

View File

@ -1 +0,0 @@
.so man3/im_iscomplex.3

View File

@ -1 +0,0 @@
.so man3/im_iscomplex.3

View File

@ -1 +0,0 @@
.so man3/im_iscomplex.3

View File

@ -1 +0,0 @@
.so man3/im_iscomplex.3

View File

@ -1 +0,0 @@
.so man3/im_iscomplex.3

View File

@ -1 +0,0 @@
.so man3/im_jpeg2vips.3

View File

@ -1 +0,0 @@
.so man3/im_magick2vips.3

View File

@ -1 +0,0 @@
.so man3/im_png2vips.3

View File

@ -1 +0,0 @@
.so man3/im_ppm2vips.3

View File

@ -1 +0,0 @@
.so man3/im_tiff2vips.3