static void * vips_operation_class_usage_arg( VipsObjectClass *object_class, GParamSpec *pspec, VipsArgumentClass *argument_class, VipsBuf *buf, VipsOperationClassUsage *usage ) { /* Only show construct args ... others are internal. */ if( usage->required == ((argument_class->flags & VIPS_ARGUMENT_REQUIRED) != 0) && (argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) && !(argument_class->flags & VIPS_ARGUMENT_DEPRECATED) ) { if( usage->message && usage->n == 0 ) vips_buf_appendf( buf, "%s\n", usage->message ); if( usage->oftype ) { vips_buf_appendf( buf, " %-12s - %s, %s %s\n", g_param_spec_get_name( pspec ), g_param_spec_get_blurb( pspec ), (argument_class->flags & VIPS_ARGUMENT_INPUT) ? _( "input" ) : _( "output" ), g_type_name( G_PARAM_SPEC_VALUE_TYPE( pspec ) ) ); } else { if( usage->n > 0 ) vips_buf_appends( buf, " " ); vips_buf_appends( buf, g_param_spec_get_name( pspec ) ); } usage->n += 1; } return( NULL ); }
/* Add a name to a string for a symbol. */ static void * workspace_selected_names_sub( Row *row, NamesInfo *names ) { if( !names->first ) vips_buf_appends( names->buf, names->separator ); /* Hack: if this is a matrix with selected cells, use an extract to * get those cells out. We should really have a row method for this I * guess :-( */ if( row->child_rhs && row->child_rhs->graphic && IS_MATRIX( row->child_rhs->graphic ) && MATRIX( row->child_rhs->graphic )->selected ) { Matrix *matrix = MATRIX( row->child_rhs->graphic ); vips_buf_appends( names->buf, "(" ); row_qualified_name( row, names->buf ); vips_buf_appendf( names->buf, ".extract %d %d %d %d)", matrix->range.left, matrix->range.top, matrix->range.width, matrix->range.height ); } else row_qualified_name( row, names->buf ); names->first = FALSE; return( NULL ); }
/** * im_system: * @im: image to run command on * @cmd: command to run * @out: stdout of command is returned here * * im_system() runs a command on an image, returning the command's output as a * string. The command is executed with popen(), the first '%%s' in the * command being substituted for a filename. * * If the IMAGE is a file on disc, then the filename will be the name of the * real file. If the image is in memory, or the result of a computation, * then a new file is created in the temporary area called something like * "vips_XXXXXX.v", and that filename given to the command. The file is * deleted when the command finishes. * * The environment variable TMPDIR can be used to set the temporary * directory. If it is not set, it defaults to "/tmp". * * In all cases, @log must be freed with im_free(). * * See also: im_system_image(). * * Returns: 0 on success, -1 on error */ int im_system( IMAGE *im, const char *cmd, char **out ) { FILE *fp; if( !im_isfile( im ) ) { IMAGE *disc; if( !(disc = im__open_temp( "%s.v" )) ) return( -1 ); if( im_copy( im, disc ) || im_system( disc, cmd, out ) ) { im_close( disc ); return( -1 ); } im_close( disc ); } else if( (fp = im_popenf( cmd, "r", im->filename )) ) { char line[IM_MAX_STRSIZE]; char txt[IM_MAX_STRSIZE]; VipsBuf buf = VIPS_BUF_STATIC( txt ); while( fgets( line, IM_MAX_STRSIZE, fp ) ) if( !vips_buf_appends( &buf, line ) ) break; pclose( fp ); if( out ) *out = im_strdup( NULL, vips_buf_all( &buf ) ); } return( 0 ); }
static void vips_leak( void ) { char txt[1024]; VipsBuf buf = VIPS_BUF_STATIC( txt ); vips_object_print_all(); if( vips_tracked_get_allocs() || vips_tracked_get_mem() || vips_tracked_get_files() ) { vips_buf_appendf( &buf, "memory: %d allocations, %zd bytes\n", vips_tracked_get_allocs(), vips_tracked_get_mem() ); vips_buf_appendf( &buf, "files: %d open\n", vips_tracked_get_files() ); } vips_buf_appendf( &buf, "memory: high-water mark " ); vips_buf_append_size( &buf, vips_tracked_get_mem_highwater() ); vips_buf_appends( &buf, "\n" ); fprintf( stderr, "%s", vips_buf_all( &buf ) ); vips__type_leak(); }
static void vips_leak( void ) { char txt[1024]; VipsBuf buf = VIPS_BUF_STATIC( txt ); vips_object_print_all(); if( vips_tracked_get_allocs() || vips_tracked_get_mem() || vips_tracked_get_files() ) { vips_buf_appendf( &buf, "memory: %d allocations, %zd bytes\n", vips_tracked_get_allocs(), vips_tracked_get_mem() ); vips_buf_appendf( &buf, "files: %d open\n", vips_tracked_get_files() ); } vips_buf_appendf( &buf, "memory: high-water mark " ); vips_buf_append_size( &buf, vips_tracked_get_mem_highwater() ); vips_buf_appends( &buf, "\n" ); if( strlen( vips_error_buffer() ) > 0 ) vips_buf_appendf( &buf, "error buffer: %s", vips_error_buffer() ); fprintf( stderr, "%s", vips_buf_all( &buf ) ); #ifdef DEBUG vips_buffer_dump_all(); #endif /*DEBUG*/ }
gboolean workspace_load_file_buf( VipsBuf *buf, const char *filename ) { if( callv_string_filenamef( (callv_string_fn) vips_format_for_file, "%s", filename ) ) vips_buf_appends( buf, "Image_file" ); else vips_buf_appends( buf, "Matrix_file" ); vips_buf_appends( buf, " \"" ); vips_buf_appendsc( buf, TRUE, filename ); vips_buf_appends( buf, "\"" ); return( TRUE ); }
/** * im_verror: * @domain: the source of the error * @fmt: printf()-style format string for the error * @ap: arguments to the format string * * Append a message to the error buffer. * * See also: im_error(). */ void im_verror( const char *domain, const char *fmt, va_list ap ) { g_mutex_lock( im__global_lock ); vips_buf_appendf( &im_error_buf, "%s: ", domain ); vips_buf_vappendf( &im_error_buf, fmt, ap ); vips_buf_appends( &im_error_buf, "\n" ); g_mutex_unlock( im__global_lock ); }
/* Make a fully-qualified name for a row's symbol ... walk back up the tally * hierarchy. eg. "A1.fred.x" ... produce a name which will find this row from * a local of context. */ void row_qualified_name_relative( Symbol *context, Row *row, VipsBuf *buf ) { if( !row_get_parent( row ) ) { if( !row->sym ) vips_buf_appends( buf, "(null)" ); else symbol_qualified_name_relative( context, row->sym, buf ); } else { /* Qualify our parents, then do us. */ row_qualified_name_relative( context, row_get_parent( row ), buf ); vips_buf_appends( buf, "." ); vips_buf_appends( buf, row_name( row ) ); } }
static void * row_add_dirty_child_name( Link *link, VipsBuf *buf ) { if( link->child->dirty ) { symbol_qualified_name_relative( link->parent, link->child, buf ); vips_buf_appends( buf, " " ); } return( NULL ); }
/** * vips_verror: * @domain: the source of the error * @fmt: printf()-style format string for the error * @ap: arguments to the format string * * Append a message to the error buffer. * * See also: vips_error(). */ void vips_verror( const char *domain, const char *fmt, va_list ap ) { g_mutex_lock( vips__global_lock ); vips_buf_appendf( &vips_error_buf, "%s: ", domain ); vips_buf_vappendf( &vips_error_buf, fmt, ap ); vips_buf_appends( &vips_error_buf, "\n" ); g_mutex_unlock( vips__global_lock ); VIPS_DEBUG_MSG( "vips_verror: %s\n", fmt ); }
gboolean iimage_replace( iImage *iimage, const char *filename ) { Row *row = HEAPMODEL( iimage )->row; iText *itext = ITEXT( HEAPMODEL( iimage )->rhs->itext ); char txt[MAX_STRSIZE]; VipsBuf buf = VIPS_BUF_STATIC( txt ); vips_buf_appends( &buf, "Image_file \"" ); vips_buf_appendsc( &buf, TRUE, filename ); vips_buf_appends( &buf, "\"" ); if( itext_set_formula( itext, vips_buf_all( &buf ) ) ) { itext_set_edited( itext, TRUE ); workspace_set_modified( row->ws, TRUE ); (void) expr_dirty( row->expr, link_serial_new() ); mainw_recent_add( &mainw_recent_image, filename ); } return( TRUE ); }
static void * row_add_child_name( Link *link, VipsBuf *buf ) { Row *row; if( link->child->expr && (row = link->child->expr->row) ) { row_qualified_name_relative( link->parent, row, buf ); vips_buf_appends( buf, " " ); } return( NULL ); }
/* Return the main caption. */ static const char * iimage_generate_caption( iObject *iobject ) { iImage *iimage = IIMAGE( iobject ); Imageinfo *ii = iimage->value.ii; VipsBuf *buf = &iimage->caption_buffer; vips_buf_rewind( buf ); image_value_caption( &iimage->value, buf ); if( ii ) { vips_buf_appends( buf, ", " ); iobject_info( IOBJECT( iimage->value.ii ), buf ); } return( vips_buf_all( buf ) ); }
static void iimage_info( iObject *iobject, VipsBuf *buf ) { iImage *iimage = IIMAGE( iobject ); Imageinfo *ii = iimage->value.ii; IMAGE *im; if( ii && (im = imageinfo_get( FALSE, ii )) ) { char *filename; if( im_header_get_typeof( im, ORIGINAL_FILENAME ) != 0 ) { if( !im_header_string( im, ORIGINAL_FILENAME, &filename ) ) { vips_buf_appends( buf, _( "Original filename" ) ); vips_buf_appendf( buf, ": %s\n", filename ); } } } }
static void vips_region_sanity( VipsObject *object, VipsBuf *buf ) { VipsRegion *region = VIPS_REGION( object ); (void) vips_object_sanity( VIPS_OBJECT( region->im ) ); switch( region->im->dtype ) { case VIPS_IMAGE_PARTIAL: /* Start and stop can be NULL, but not generate. */ if( !region->im->generate_fn ) vips_buf_appends( buf, "generate NULL in partial\n" ); break; default: break; } VIPS_OBJECT_CLASS( vips_region_parent_class )->sanity( object, buf ); }
static void * iarrow_generate_caption_sub( iImage *iimage, iArrow *iarrow, gboolean *first ) { Workspace *ws = HEAPMODEL( iarrow )->row->ws; Row *row = HEAPMODEL( iimage )->row; /* Suppress this name in the caption if it's a superclass. If this * thing is on a super, it's on the subclass too ... not helpful to * have it twice. */ if( !is_super( row->sym ) ) { if( *first ) *first = FALSE; else vips_buf_appends( &iarrow->caption_buffer, ", " ); row_qualified_name_relative( ws->sym, row, &iarrow->caption_buffer ); } return( NULL ); }
/* Make the insides of an about box. */ static void about_build( iDialog *idlg, GtkWidget *work ) { /* Translators: translate this to a credit for you, and it'll appear in * the About box. */ char *translator_credits = _( "translator_credits" ); GtkWidget *hb; GtkWidget *lab; char txt[MAX_DIALOG_TEXT]; char txt2[MAX_DIALOG_TEXT]; VipsBuf buf = VIPS_BUF_STATIC( txt ); GtkWidget *image; im_snprintf( txt2, MAX_DIALOG_TEXT, _( "About %s." ), PACKAGE ); vips_buf_appendf( &buf, "<b><big>%s</big></b>\n\n", txt2 ); im_snprintf( txt2, MAX_DIALOG_TEXT, _( "%s is an image processing package." ), PACKAGE ); vips_buf_appendf( &buf, "%s\n\n", txt2 ); im_snprintf( txt2, MAX_DIALOG_TEXT, _( "%s comes with ABSOLUTELY NO WARRANTY. This is " "free software and you are welcome to redistribute " "it under certain conditions, see http://www.gnu.org." ), PACKAGE ); vips_buf_appendf( &buf, "%s\n\n", txt2 ); im_snprintf( txt2, MAX_DIALOG_TEXT, _( NIP_COPYRIGHT ), PACKAGE ); vips_buf_appendf( &buf, "%s\n\n", txt2 ); { char buf1[FILENAME_MAX]; char buf2[FILENAME_MAX]; im_snprintf( buf1, FILENAME_MAX, "%s" G_DIR_SEPARATOR_S "start", get_savedir() ); expand_variables( buf1, buf2 ); nativeize_path( buf2 ); escape_markup( buf2, buf1, FILENAME_MAX ); vips_buf_appendf( &buf, "<b>%s:</b> %s\n", _( "Personal start folder" ), buf1 ); } vips_buf_appendf( &buf, "<b>%s:</b> %s\n", _( "Homepage" ), VIPS_HOMEPAGE ); escape_markup( im_version_string(), txt2, MAX_DIALOG_TEXT ); vips_buf_appendf( &buf, "<b>%s:</b> %s\n", _( "Linked to VIPS" ), txt2 ); escape_markup( IM_VERSION_STRING, txt2, MAX_DIALOG_TEXT ); vips_buf_appendf( &buf, "<b>%s:</b> %s\n", _( "Built against VIPS" ), txt2 ); escape_markup( PACKAGE, txt2, MAX_DIALOG_TEXT ); vips_buf_appendf( &buf, "<b>$PACKAGE:</b> %s\n", txt2 ); escape_markup( VERSION, txt2, MAX_DIALOG_TEXT ); vips_buf_appendf( &buf, "<b>$VERSION:</b> %s\n", txt2 ); escape_markup( NN( g_getenv( "VIPSHOME" ) ), txt2, MAX_DIALOG_TEXT ); vips_buf_appendf( &buf, "<b>$VIPSHOME:</b> %s\n", txt2 ); escape_markup( NN( g_getenv( "HOME" ) ), txt2, MAX_DIALOG_TEXT ); vips_buf_appendf( &buf, "<b>$HOME:</b> %s\n", txt2 ); escape_markup( NN( g_getenv( "SAVEDIR" ) ), txt2, MAX_DIALOG_TEXT ); vips_buf_appendf( &buf, "<b>$SAVEDIR:</b> %s\n", txt2 ); escape_markup( PATH_TMP, txt2, MAX_DIALOG_TEXT ); vips_buf_appendf( &buf, "<b>%s:</b> %s\n", _( "Temp files in" ), txt2 ); if( strcmp( translator_credits, "translator_credits" ) != 0 ) { vips_buf_appendf( &buf, "\n" ); vips_buf_appends( &buf, translator_credits ); } vips_buf_appendf( &buf, "\n" ); mainw_find_disc( &buf ); /* Expands to (eg.) "14GB free in /pics/tmp" */ vips_buf_appendf( &buf, _( " in \"%s\"" ), PATH_TMP ); vips_buf_appends( &buf, "\n" ); vips_buf_appendf( &buf, _( "%d cells in heap, %d cells free, %d cells maximum" ), reduce_context->heap->ncells, reduce_context->heap->nfree, reduce_context->heap->max_fn( reduce_context->heap ) ); vips_buf_appends( &buf, "\n" ); vips_buf_appendf( &buf, _( "%d vips calls cached by nip2" ), cache_history_size ); vips_buf_appends( &buf, "\n" ); vips_buf_appendf( &buf, _( "%d vips operations cached by libvips" ), vips_cache_get_size() ); vips_buf_appends( &buf, "\n" ); vips_buf_appendf( &buf, _( "using %d threads" ), im_concurrency_get() ); vips_buf_appends( &buf, "\n" ); vips_buf_appendf( &buf, _( "%d pixel buffers in vips" ), vips_tracked_get_allocs() ); vips_buf_appends( &buf, "\n" ); vips_buf_append_size( &buf, vips_tracked_get_mem() ); vips_buf_appendf( &buf, _( " of ram in pixel buffers" ) ); vips_buf_appends( &buf, "\n" ); vips_buf_append_size( &buf, vips_tracked_get_mem_highwater() ); vips_buf_appendf( &buf, _( " of ram highwater mark" ) ); vips_buf_appends( &buf, "\n" ); hb = gtk_hbox_new( FALSE, 0 ); gtk_container_border_width( GTK_CONTAINER( hb ), 10 ); gtk_container_add( GTK_CONTAINER( work ), hb ); gtk_widget_show( hb ); image = image_new_from_file( "$VIPSHOME/share/$PACKAGE/data/vips-128.png" ); gtk_box_pack_start( GTK_BOX( hb ), image, FALSE, FALSE, 2 ); gtk_widget_show( image ); lab = gtk_label_new( "" ); gtk_label_set_markup( GTK_LABEL( lab ), vips_buf_all( &buf ) ); gtk_label_set_justify( GTK_LABEL( lab ), GTK_JUSTIFY_LEFT ); gtk_label_set_selectable( GTK_LABEL( lab ), TRUE ); gtk_label_set_line_wrap( GTK_LABEL( lab ), TRUE ); gtk_box_pack_start( GTK_BOX( hb ), lab, FALSE, FALSE, 2 ); gtk_widget_show( lab ); }
static void row_info( iObject *iobject, VipsBuf *buf ) { Row *row = ROW( iobject ); vips_buf_appends( buf, _( "Name" ) ); vips_buf_appends( buf, ": " ); row_qualified_name( row, buf ); vips_buf_appends( buf, "\n" ); if( row->expr ) iobject_info( IOBJECT( row->expr ), buf ); if( row->child_rhs && row->child_rhs->itext ) iobject_info( IOBJECT( row->child_rhs->itext ), buf ); if( row->child_rhs && row->child_rhs->graphic ) iobject_info( IOBJECT( row->child_rhs->graphic ), buf ); if( row->top_row->sym ) { if( row->top_row->sym->topchildren ) { row_qualified_name( row, buf ); vips_buf_appends( buf, " " ); /* Expands to eg. "B1 refers to: B2, B3". */ vips_buf_appends( buf, _( "refers to" ) ); vips_buf_appends( buf, ": " ); slist_map_rev( row->top_row->sym->topchildren, (SListMapFn) row_add_child_name, buf ); vips_buf_appends( buf, "\n" ); } if( row->top_row->sym->topparents ) { row_qualified_name( row, buf ); vips_buf_appends( buf, " " ); /* Expands to eg. "B1 is referred to by: B2, B3". */ vips_buf_appends( buf, _( "is referred to by" ) ); vips_buf_appends( buf, ": " ); slist_map_rev( row->top_row->sym->topparents, (SListMapFn) row_add_parent_name, buf ); vips_buf_appends( buf, "\n" ); } } if( row == row->top_row && row->sym && row->sym->dirty ) { Symbol *sym = row->sym; if( sym->ndirtychildren ) { row_qualified_name( row, buf ); vips_buf_appends( buf, " " ); vips_buf_appends( buf, _( "is blocked on" ) ); vips_buf_appends( buf, ": " ); slist_map_rev( sym->topchildren, (SListMapFn) row_add_dirty_child_name, buf ); vips_buf_appends( buf, "\n" ); } } }