/* Send a file to out. Used to transmit the preludes. */ static int transmit_file( char *mode, char *name, FILE *out ) { const char *prefix; char buf[PATH_MAX]; FILE *in; if( !(prefix = im_guess_prefix( argv0, "VIPSHOME" )) ) return( -1 ); /* Send it! */ im_snprintf( buf, PATH_MAX, "%s/share/vips/vips2dj/%s/%s", prefix, mode, name ); if( !(in = fopen( buf, "r" )) ) { im_errormsg( "vips2dj: can't find \"%s\"", name ); return( -1 ); } if( copy_bytes( in, out ) ) { fclose( in ); return( -1 ); } fclose( in ); return( 0 ); }
/* Mark up a top/sub pair for a dialog box. */ static void box_vmarkup( char *out, const char *top, const char *sub, va_list ap ) { char buf1[MAX_DIALOG_TEXT]; char buf2[MAX_DIALOG_TEXT]; char buf3[MAX_DIALOG_TEXT]; escape_markup( top, buf1, MAX_DIALOG_TEXT ); (void) im_vsnprintf( buf2, MAX_DIALOG_TEXT, sub, ap ); escape_markup( buf2, buf3, MAX_DIALOG_TEXT ); (void) im_snprintf( out, MAX_DIALOG_TEXT, "<b><big>%s</big></b>", buf1 ); if( strcmp( buf3, "" ) != 0 ) { int len = strlen( out ); (void) im_snprintf( out + len, MAX_DIALOG_TEXT - len, "\n\n%s", buf3 ); } }
static void toolkitview_refresh( vObject *vobject ) { Toolkitview *kview = TOOLKITVIEW( vobject ); Toolkit *kit = TOOLKIT( VOBJECT( kview )->iobject ); Toolkitgroupview *kitgview = kview->kitgview; GtkWidget *menu = kitgview->menu; gboolean changed = FALSE; #ifdef DEBUG printf( "toolkitview_refresh: " ); iobject_print( VOBJECT( kview )->iobject ); #endif /*DEBUG*/ /* Make a button ready for the sub-menu. */ if( !kview->item ) { kview->item = gtk_menu_item_new_with_label( IOBJECT( kit )->name ); gtk_menu_shell_insert( GTK_MENU_SHELL( menu ), kview->item, ICONTAINER( kit )->pos + TOOLKITVIEW_MENU_OFFSET ); gtk_widget_show( kview->item ); kview->destroy_sid = g_signal_connect( kview->item, "destroy", G_CALLBACK( toolkitview_destroy_cb ), kview ); changed = TRUE; } if( !kview->menu ) { iWindow *iwnd = IWINDOW( iwindow_get_root( menu ) ); char path[256]; kview->menu = gtk_menu_new(); gtk_menu_set_accel_group( GTK_MENU( kview->menu ), iwnd->accel_group ); im_snprintf( path, 256, "<mainw>/Toolkits/%s", IOBJECT( kit )->name ); gtk_menu_set_accel_path( GTK_MENU( kview->menu ), path ); changed = TRUE; } if( changed ) gtk_menu_item_set_submenu( GTK_MENU_ITEM( kview->item ), kview->menu ); widget_visible( kview->item, ICONTAINER( kit )->children != NULL ); VOBJECT_CLASS( parent_class )->refresh( vobject ); }
/* Pop up a help window for a tag. */ void box_help( GtkWidget *par, const char *name ) { int i; for( i = 0; i < IM_NUMBER( box_helpindex ); i++ ) if( strcmp( name, box_helpindex[i][0] ) == 0 ) { char url[512]; im_snprintf( url, 512, "file://%s/%s", NIP_DOCPATH, box_helpindex[i][1] ); box_url( par, url ); return; } error_top( _( "Help page not found." ) ); error_sub( _( "No indexed help page found for tag \"%s\"" ), name ); iwindow_alert( par, GTK_MESSAGE_ERROR ); }
/* Do a image call. */ static void apply_image_call( Reduce *rc, const char *name, HeapNode **arg, PElement *out ) { Heap *heap = rc->heap; PElement rhs; char buf[FILENAME_MAX]; char filename[FILENAME_MAX]; char mode[FILENAME_MAX]; char *fn; Imageinfo *ii; /* Get string. */ PEPOINTRIGHT( arg[0], &rhs ); (void) reduce_get_string( rc, &rhs, buf, FILENAME_MAX ); /* The buf might be something like n3862.pyr.tif:1, ie. contain some * load options. Split and search just for the filename component. */ im_filename_split( buf, filename, mode ); /* Try to load image from given string. */ if( !(fn = path_find_file( filename )) ) reduce_throw( rc ); /* Reattach the mode and load. */ im_snprintf( buf, FILENAME_MAX, "%s:%s", fn, mode ); if( !(ii = imageinfo_new_input( main_imageinfogroup, NULL, heap, buf )) ) { IM_FREE( fn ); reduce_throw( rc ); } IM_FREE( fn ); PEPUTP( out, ELEMENT_MANAGED, ii ); MANAGED_UNREF( ii ); }
gboolean workspace_load_compat( Workspace *ws, int major, int minor ) { char pathname[FILENAME_MAX]; GSList *path; int best_major; int best_minor; if( workspace_have_compat( major, minor, &best_major, &best_minor ) ) { /* Make a private toolkitgroup local to this workspace to * hold the compatibility defs we are planning to load. */ UNREF( ws->kitg ); ws->kitg = toolkitgroup_new( ws->sym ); g_object_ref( G_OBJECT( ws->kitg ) ); iobject_sink( IOBJECT( ws->kitg ) ); im_snprintf( pathname, FILENAME_MAX, "$VIPSHOME/share/" PACKAGE "/compat/%d.%d", best_major, best_minor ); path = path_parse( pathname ); if( path_map( path, "*.def", (path_map_fn) workspace_load_toolkit, ws->kitg ) ) { path_free2( path ); return( FALSE ); } path_free2( path ); ws->compat_major = best_major; ws->compat_minor = best_minor; } else { /* No compat defs necessary for this ws. */ ws->compat_major = 0; ws->compat_minor = 0; } return( TRUE ); }
/* Given (eg.) "/poop/somefile.png", make the thumbnail name, * "/poop/tn_somefile.jpg". */ static char * make_thumbnail_name( const char *filename ) { char *file; char *p; char buf[FILENAME_MAX]; char *result; file = g_path_get_basename( filename ); /* Remove the suffix from the file portion. */ if( (p = strrchr( file, '.' )) ) *p = '\0'; /* output_format can be an absolute path, in which case we discard the * path from the incoming file. */ im_snprintf( buf, FILENAME_MAX, output_format, file ); if( g_path_is_absolute( output_format ) ) result = g_strdup( buf ); else { char *dir; dir = g_path_get_dirname( filename ); result = g_build_filename( dir, buf, NULL ); g_free( dir ); } if( verbose ) printf( "thumbnailing %s as %s\n", filename, result ); g_free( file ); return( result ); }
static int vips_fits_get_header( VipsFits *fits, VipsImage *out ) { int status; int bitpix; int width, height, bands, format, type; int keysexist; int i; status = 0; if( fits_get_img_paramll( fits->fptr, 10, &bitpix, &fits->naxis, fits->naxes, &status ) ) { vips_fits_error( status ); return( -1 ); } #ifdef VIPS_DEBUG VIPS_DEBUG_MSG( "naxis = %d\n", fits->naxis ); for( i = 0; i < fits->naxis; i++ ) VIPS_DEBUG_MSG( "%d) %lld\n", i, fits->naxes[i] ); #endif /*VIPS_DEBUG*/ width = 1; height = 1; bands = 1; switch( fits->naxis ) { /* If you add more dimensions here, adjust data read below. See also * the definition of MAX_DIMENSIONS above. */ case 10: case 9: case 8: case 7: case 6: case 5: case 4: for( i = fits->naxis; i > 3; i-- ) if( fits->naxes[i - 1] != 1 ) { im_error( "fits", "%s", _( "dimensions above 3 " "must be size 1" ) ); return( -1 ); } case 3: bands = fits->naxes[2]; case 2: height = fits->naxes[1]; case 1: width = fits->naxes[0]; break; default: im_error( "fits", _( "bad number of axis %d" ), fits->naxis ); return( -1 ); } /* Are we in one-band mode? */ if( fits->band_select != -1 ) bands = 1; /* Get image format. We want the 'raw' format of the image, our caller * can convert using the meta info if they want. */ for( i = 0; i < VIPS_NUMBER( fits2vips_formats ); i++ ) if( fits2vips_formats[i][0] == bitpix ) break; if( i == VIPS_NUMBER( fits2vips_formats ) ) { im_error( "fits", _( "unsupported bitpix %d\n" ), bitpix ); return( -1 ); } format = fits2vips_formats[i][1]; fits->datatype = fits2vips_formats[i][2]; if( bands == 1 ) { if( format == VIPS_FORMAT_USHORT ) type = VIPS_INTERPRETATION_GREY16; else type = VIPS_INTERPRETATION_B_W; } else if( bands == 3 ) { if( format == VIPS_FORMAT_USHORT ) type = VIPS_INTERPRETATION_RGB16; else type = VIPS_INTERPRETATION_RGB; } else type = VIPS_INTERPRETATION_MULTIBAND; im_initdesc( out, width, height, bands, im_bits_of_fmt( format ), format, VIPS_CODING_NONE, type, 1.0, 1.0, 0, 0 ); /* Read all keys into meta. */ if( fits_get_hdrspace( fits->fptr, &keysexist, NULL, &status ) ) { vips_fits_error( status ); return( -1 ); } for( i = 0; i < keysexist; i++ ) { char record[81]; char vipsname[100]; if( fits_read_record( fits->fptr, i + 1, record, &status ) ) { vips_fits_error( status ); return( -1 ); } VIPS_DEBUG_MSG( "fits2vips: setting meta on vips image:\n" ); VIPS_DEBUG_MSG( " record == \"%s\"\n", record ); /* FITS lets keys repeat. For example, HISTORY appears many * times, each time with a fresh line of history attached. We * have to include the key index in the vips name we assign. */ im_snprintf( vipsname, 100, "fits-%d", i ); if( im_meta_set_string( out, vipsname, record ) ) return( -1 ); } return( 0 ); }
/* 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 ); }