added im_meta_remove

This commit is contained in:
John Cupitt 2010-01-25 14:23:30 +00:00
parent 51130d2368
commit e0d4e0c158
7 changed files with 64 additions and 17 deletions

View File

@ -22,6 +22,7 @@
- "invalidate" is careful to keep images alive, so invalidate callbacks can do - "invalidate" is careful to keep images alive, so invalidate callbacks can do
im_close() im_close()
- flood_blob could loop if start point == ink - flood_blob could loop if start point == ink
- added im_meta_remove()
26/11/09 started 7.20.3 26/11/09 started 7.20.3
- updated en_GB.po translation - updated en_GB.po translation

9
TODO
View File

@ -3,6 +3,15 @@
we'd need to have coordinate transforms broken out for this :-( we'd need to have coordinate transforms broken out for this :-(
- vipsthumbnail should have an option to delete the profile from the final
jpg? handy if you want all your profiles in eg. sRGB
- try writing docs for vipsthumbnail with gtkdoc? then try header etc.
- rename header, edvips as vipsheader, vipsedit
maybe have back compat links?
- should im_rwcheck() copy to disc? - should im_rwcheck() copy to disc?
maybe im_rwcheck_disc() copies to im->filename and maps that maybe im_rwcheck_disc() copies to im->filename and maps that

View File

@ -107,6 +107,7 @@ int im_blob_set( GValue *value, im_callback_fn free_fn,
void *data, size_t length ); void *data, size_t length );
int im_meta_set( IMAGE *, const char *field, GValue * ); int im_meta_set( IMAGE *, const char *field, GValue * );
gboolean im_meta_remove( IMAGE *im, const char *field );
int im_meta_get( IMAGE *, const char *field, GValue * ); int im_meta_get( IMAGE *, const char *field, GValue * );
GType im_meta_get_typeof( IMAGE *im, const char *field ); GType im_meta_get_typeof( IMAGE *im, const char *field );

View File

@ -71,8 +71,6 @@
#include <unistd.h> #include <unistd.h>
#endif /*HAVE_UNISTD_H*/ #endif /*HAVE_UNISTD_H*/
#include <assert.h>
#include <vips/vips.h> #include <vips/vips.h>
#include <vips/internal.h> #include <vips/internal.h>
@ -245,14 +243,14 @@ void
im__meta_destroy( IMAGE *im ) im__meta_destroy( IMAGE *im )
{ {
IM_FREEF( g_hash_table_destroy, im->Meta ); IM_FREEF( g_hash_table_destroy, im->Meta );
assert( !im->Meta_traverse ); g_assert( !im->Meta_traverse );
} }
static void static void
meta_init( IMAGE *im ) meta_init( IMAGE *im )
{ {
if( !im->Meta ) { if( !im->Meta ) {
assert( !im->Meta_traverse ); g_assert( !im->Meta_traverse );
im->Meta = g_hash_table_new_full( g_str_hash, g_str_equal, im->Meta = g_hash_table_new_full( g_str_hash, g_str_equal,
NULL, (GDestroyNotify) meta_free ); NULL, (GDestroyNotify) meta_free );
} }
@ -338,8 +336,8 @@ im_meta_set( IMAGE *im, const char *field, GValue *value )
{ {
Meta *meta; Meta *meta;
assert( field ); g_assert( field );
assert( value ); g_assert( value );
meta_init( im ); meta_init( im );
if( !(meta = meta_new( im, field, value )) ) if( !(meta = meta_new( im, field, value )) )
@ -352,6 +350,28 @@ im_meta_set( IMAGE *im, const char *field, GValue *value )
return( 0 ); return( 0 );
} }
/**
* im_meta_remove:
* @im: image to test
* @field: the name to search for
*
* Find and remove an item of metadata. Return %FALSE if no metadata of that
* name was found.
*
* See also: im_meta_set(), im_meta_get_typeof().
*
* Returns: %TRUE if an item of metadata of that name was found and removed
*/
gboolean
im_meta_remove( IMAGE *im, const char *field )
{
if( im->Meta &&
g_hash_table_remove( im->Meta, field ) )
return( TRUE );
return( FALSE );
}
/** /**
* im_meta_get: * im_meta_get:
* @im: image to get the metadata from * @im: image to get the metadata from
@ -398,8 +418,8 @@ im_meta_get( IMAGE *im, const char *field, GValue *value_copy )
{ {
Meta *meta; Meta *meta;
assert( field ); g_assert( field );
assert( value_copy ); g_assert( value_copy );
/* Defined? /* Defined?
*/ */
@ -432,7 +452,7 @@ im_meta_get_typeof( IMAGE *im, const char *field )
{ {
Meta *meta; Meta *meta;
assert( field ); g_assert( field );
/* Defined? /* Defined?
*/ */
@ -516,7 +536,7 @@ im_save_string_get( const GValue *value )
void void
im_save_string_set( GValue *value, const char *str ) im_save_string_set( GValue *value, const char *str )
{ {
assert( G_VALUE_TYPE( value ) == IM_TYPE_SAVE_STRING ); g_assert( G_VALUE_TYPE( value ) == IM_TYPE_SAVE_STRING );
g_value_set_boxed( value, str ); g_value_set_boxed( value, str );
} }
@ -535,7 +555,7 @@ im_save_string_setf( GValue *value, const char *fmt, ... )
va_list ap; va_list ap;
char *str; char *str;
assert( G_VALUE_TYPE( value ) == IM_TYPE_SAVE_STRING ); g_assert( G_VALUE_TYPE( value ) == IM_TYPE_SAVE_STRING );
va_start( ap, fmt ); va_start( ap, fmt );
str = g_strdup_vprintf( fmt, ap ); str = g_strdup_vprintf( fmt, ap );
@ -736,7 +756,7 @@ area_new_blob( im_callback_fn free_fn, void *blob, size_t blob_length )
static Area * static Area *
area_copy( Area *area ) area_copy( Area *area )
{ {
assert( area->count >= 0 ); g_assert( area->count >= 0 );
area->count += 1; area->count += 1;
@ -750,7 +770,7 @@ area_copy( Area *area )
static void static void
area_unref( Area *area ) area_unref( Area *area )
{ {
assert( area->count > 0 ); g_assert( area->count > 0 );
area->count -= 1; area->count -= 1;
@ -941,7 +961,7 @@ im_ref_string_set( GValue *value, const char *str )
Area *area; Area *area;
char *str_copy; char *str_copy;
assert( G_VALUE_TYPE( value ) == IM_TYPE_REF_STRING ); g_assert( G_VALUE_TYPE( value ) == IM_TYPE_REF_STRING );
if( !(str_copy = im_strdup( NULL, str )) ) if( !(str_copy = im_strdup( NULL, str )) )
return( -1 ); return( -1 );
@ -1182,7 +1202,7 @@ im_blob_set( GValue *value,
{ {
Area *area; Area *area;
assert( G_VALUE_TYPE( value ) == IM_TYPE_BLOB ); g_assert( G_VALUE_TYPE( value ) == IM_TYPE_BLOB );
if( !(area = area_new_blob( free_fn, blob, blob_length )) ) if( !(area = area_new_blob( free_fn, blob, blob_length )) )
return( -1 ); return( -1 );

View File

@ -325,13 +325,18 @@ void VImage::meta_set( const char *field, GValue *value ) throw( VError )
verror(); verror();
} }
gboolean VImage::meta_remove( const char *field )
{
return( im_meta_remove( _ref->im, field ) );
}
void VImage::meta_get( const char *field, GValue *value_copy ) throw( VError ) void VImage::meta_get( const char *field, GValue *value_copy ) throw( VError )
{ {
if( im_meta_get( _ref->im, field, value_copy ) ) if( im_meta_get( _ref->im, field, value_copy ) )
verror(); verror();
} }
GType VImage::meta_get_typeof( const char *field ) throw( VError ) GType VImage::meta_get_typeof( const char *field )
{ {
return( im_meta_get_typeof( _ref->im, field ) ); return( im_meta_get_typeof( _ref->im, field ) );
} }

View File

@ -255,9 +255,12 @@ public:
// we don't wrap GValue, so we can't wrap these for now // we don't wrap GValue, so we can't wrap these for now
void meta_set( const char *field, GValue *value ) throw( VError ); void meta_set( const char *field, GValue *value ) throw( VError );
void meta_get( const char *field, GValue *value_copy ) throw( VError ); void meta_get( const char *field, GValue *value_copy ) throw( VError );
GType meta_get_typeof( const char *field ) throw( VError );
#endif /*SWIG*/ #endif /*SWIG*/
// We can wrap these, fwiw
gboolean meta_remove( const char *field );
GType meta_get_typeof( const char *field );
// convenience functions // convenience functions
int meta_get_int( const char *field ) throw( VError ); int meta_get_int( const char *field ) throw( VError );
double meta_get_double( const char *field ) throw( VError ); double meta_get_double( const char *field ) throw( VError );

View File

@ -26,6 +26,7 @@ static int thumbnail_size = 128;
static char *thumbnail_format = "tn_%s.jpg"; static char *thumbnail_format = "tn_%s.jpg";
static char *export_profile = NULL; static char *export_profile = NULL;
static char *import_profile = NULL; static char *import_profile = NULL;
static gboolean delete_profile = FALSE;
static GOptionEntry options[] = { static GOptionEntry options[] = {
{ "size", 's', 0, G_OPTION_ARG_INT, &thumbnail_size, { "size", 's', 0, G_OPTION_ARG_INT, &thumbnail_size,
@ -38,6 +39,8 @@ static GOptionEntry options[] = {
N_( "export with profile P" ), "P" }, N_( "export with profile P" ), "P" },
{ "iprofile", 'i', 0, G_OPTION_ARG_STRING, &import_profile, { "iprofile", 'i', 0, G_OPTION_ARG_STRING, &import_profile,
N_( "import untagged images with profile P" ), "P" }, N_( "import untagged images with profile P" ), "P" },
{ "delete", 'd', 0, G_OPTION_ARG_NONE, &delete_profile,
N_( "delete profile from exported image" ), NULL },
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
N_( "verbose output" ), NULL }, N_( "verbose output" ), NULL },
{ NULL } { NULL }
@ -253,6 +256,11 @@ shrink_factor( IMAGE *in, IMAGE *out )
x = t[6]; x = t[6];
} }
if( delete_profile ) {
if( im_meta_remove( x, IM_META_ICC_NAME ) && verbose )
printf( "deleting profile from output image\n" );
}
if( im_copy( x, out ) ) if( im_copy( x, out ) )
return( -1 ); return( -1 );