static void find_out_writable_format_by_extension (gpointer data, gpointer user_data) { GdkPixbufFormat *format = (GdkPixbufFormat*) data; gchar **name = (gchar **) user_data; gchar **extensions = gdk_pixbuf_format_get_extensions (format); gchar **ptr = extensions; gboolean found = FALSE; while (*ptr != NULL) { if (g_strcmp0 (*ptr, *name) == 0 && gdk_pixbuf_format_is_writable (format) == TRUE) { *name = gdk_pixbuf_format_get_name (format); found = TRUE; break; } ptr++; } g_strfreev (extensions); /* Needing to duplicate string here because * gdk_pixbuf_format_get_name will return a duplicated string. */ if (!found) *name = g_strdup (*name); }
GdkPixbufFormat* get_gdk_pixbuf_format_by_extension (gchar *uri) { GSList *pixbuf_formats = NULL; GSList *iter; int i; pixbuf_formats = gdk_pixbuf_get_formats (); for (iter = pixbuf_formats; iter; iter = iter->next) { gchar **extension_list; GdkPixbufFormat *format = iter->data; if (gdk_pixbuf_format_is_disabled (format) || !gdk_pixbuf_format_is_writable (format)) continue; extension_list = gdk_pixbuf_format_get_extensions (format); for (i = 0; extension_list[i] != 0; i++) { if (g_str_has_suffix (uri, extension_list[i])) { g_slist_free (pixbuf_formats); g_strfreev (extension_list); return format; } } g_strfreev (extension_list); } g_slist_free (pixbuf_formats); return NULL; }
void add_if_writable (GdkPixbufFormat *data, _List *list) { if (gdk_pixbuf_format_is_writable (data)) { _String tStr (data->name); (*list) && & tStr ; } }
/** * gtk_content_formats_add_image_targets: * @list: a #GdkContentFormats * @writable: whether to add only targets for which GTK+ knows * how to convert a pixbuf into the format * * Appends the image targets supported by #GtkSelectionData to * the target list. All targets are added with the same @info. **/ GdkContentFormats * gtk_content_formats_add_image_targets (GdkContentFormats *list, gboolean writable) { GdkContentFormatsBuilder *builder; GSList *formats, *f; gchar **mimes, **m; g_return_val_if_fail (list != NULL, NULL); builder = gdk_content_formats_builder_new (); gdk_content_formats_builder_add_formats (builder, list); gdk_content_formats_unref (list); formats = gdk_pixbuf_get_formats (); /* Make sure png comes first */ for (f = formats; f; f = f->next) { GdkPixbufFormat *fmt = f->data; gchar *name; name = gdk_pixbuf_format_get_name (fmt); if (strcmp (name, "png") == 0) { formats = g_slist_delete_link (formats, f); formats = g_slist_prepend (formats, fmt); g_free (name); break; } g_free (name); } for (f = formats; f; f = f->next) { GdkPixbufFormat *fmt = f->data; if (writable && !gdk_pixbuf_format_is_writable (fmt)) continue; mimes = gdk_pixbuf_format_get_mime_types (fmt); for (m = mimes; *m; m++) { gdk_content_formats_builder_add_mime_type (builder, *m); } g_strfreev (mimes); } g_slist_free (formats); return gdk_content_formats_builder_free_to_formats (builder); }
void file_chooser_dialog_add_writable_pixbuf_formats (GtkFileChooser *chooser) { GSList *pixbuf_formats = NULL; GSList *iter; GtkFileFilter *filter; int i; filter = gtk_file_filter_new(); gtk_file_filter_set_name (filter, _("By extension")); g_object_set_data (G_OBJECT(filter), "pixbuf-format", NULL); gtk_file_chooser_add_filter (chooser, filter); pixbuf_formats = gdk_pixbuf_get_formats (); for (iter = pixbuf_formats; iter; iter = iter->next) { GdkPixbufFormat *format = iter->data; gchar *description, *name, *extensions; gchar **extension_list, **mime_types; if (gdk_pixbuf_format_is_disabled (format) || !gdk_pixbuf_format_is_writable (format)) continue; name = gdk_pixbuf_format_get_description (format); extension_list = gdk_pixbuf_format_get_extensions (format); extensions = g_strjoinv (", ", extension_list); g_strfreev (extension_list); description = g_strdup_printf ("%s (%s)", name, extensions); filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, description); g_object_set_data (G_OBJECT (filter), "pixbuf-format", format); gtk_file_chooser_add_filter (chooser, filter); g_free (description); g_free (extensions); g_free (name); mime_types = gdk_pixbuf_format_get_mime_types (format); for (i = 0; mime_types[i] != 0; i++) gtk_file_filter_add_mime_type (filter, mime_types[i]); g_strfreev (mime_types); } g_slist_free (pixbuf_formats); }
static void go_image_build_pixbuf_format_infos (void) { #ifdef GOFFICE_WITH_GTK GdkPixbufFormat *fmt; GSList *l, *pixbuf_fmts; GOImageFormatInfo *format_info; gchar **exts; unsigned i; if (pixbuf_format_done) return; pixbuf_fmts = gdk_pixbuf_get_formats (); pixbuf_format_nbr = g_slist_length (pixbuf_fmts); if (pixbuf_format_nbr > 0) { pixbuf_image_format_infos = g_new (GOImageFormatInfo, pixbuf_format_nbr); for (l = pixbuf_fmts, i = 1, format_info = pixbuf_image_format_infos; l != NULL; l = l->next, i++, format_info++) { fmt = (GdkPixbufFormat *)l->data; format_info->format = GO_IMAGE_FORMAT_UNKNOWN + i; format_info->name = gdk_pixbuf_format_get_name (fmt); format_info->desc = gdk_pixbuf_format_get_description (fmt); exts = gdk_pixbuf_format_get_extensions (fmt); format_info->ext = g_strdup (exts[0]); if (format_info->ext == NULL) format_info->ext = format_info->name; g_strfreev (exts); format_info->has_pixbuf_saver = gdk_pixbuf_format_is_writable (fmt); format_info->is_dpi_useful = FALSE; format_info->alpha_support = FALSE; } } g_slist_free (pixbuf_fmts); #endif /* GOFFICE_WITH_GTK */ pixbuf_format_done = TRUE; }
static gboolean gth_image_saver_jpeg_can_save (GthImageSaver *self, const char *mime_type) { #ifdef HAVE_LIBJPEG return g_content_type_equals (mime_type, "image/jpeg"); #else /* ! HAVE_LIBJPEG */ GSList *formats; GSList *scan; GdkPixbufFormat *jpeg_format; if (! g_content_type_equals (mime_type, "image/jpeg")) return FALSE; formats = gdk_pixbuf_get_formats (); jpeg_format = NULL; for (scan = formats; (jpeg_format == NULL) && (scan != NULL); scan = g_slist_next (scan)) { GdkPixbufFormat *format = scan->data; char **mime_types; int i; mime_types = gdk_pixbuf_format_get_mime_types (format); for (i = 0; mime_types[i] != NULL; i++) if (g_content_type_equals (mime_types[i], "image/jpeg")) break; if (mime_types[i] == NULL) continue; if (! gdk_pixbuf_format_is_writable (format)) continue; jpeg_format = format; } return jpeg_format != NULL; #endif /* HAVE_LIBJPEG */ }
GSList * photos_utils_get_pixbuf_savable_formats (void) { GSList *list; GSList *write_list = NULL; GSList *it; list = gdk_pixbuf_get_formats (); for (it = list; it != NULL; it = it->next) { GdkPixbufFormat *format; format = (GdkPixbufFormat*) it->data; if (gdk_pixbuf_format_is_writable (format)) write_list = g_slist_prepend (write_list, format); } g_slist_free (list); write_list = g_slist_reverse (write_list); return write_list; }
gboolean _g_mime_type_is_writable (const char *mime_type) { GSList *list; GSList *scan; list = gdk_pixbuf_get_formats (); for (scan = list; scan; scan = scan->next) { GdkPixbufFormat *format = scan->data; char **mime_types; int i; mime_types = gdk_pixbuf_format_get_mime_types (format); for (i = 0; mime_types[i] != NULL; i++) if (strcmp (mime_type, mime_types[i]) == 0) return ! gdk_pixbuf_format_is_disabled (format) && gdk_pixbuf_format_is_writable (format); g_strfreev (mime_types); } g_slist_free (list); return FALSE; }
void gimp_clipboard_init (Gimp *gimp) { GimpClipboard *gimp_clip; GSList *list; g_return_if_fail (GIMP_IS_GIMP (gimp)); gimp_clip = gimp_clipboard_get (gimp); g_return_if_fail (gimp_clip == NULL); gimp_clip = g_slice_new0 (GimpClipboard); g_object_set_data_full (G_OBJECT (gimp), GIMP_CLIPBOARD_KEY, gimp_clip, (GDestroyNotify) gimp_clipboard_free); gimp_clip->pixbuf_formats = gimp_pixbuf_get_formats (); for (list = gimp_clip->pixbuf_formats; list; list = g_slist_next (list)) { GdkPixbufFormat *format = list->data; if (gdk_pixbuf_format_is_writable (format)) { gchar **mime_types; gchar **type; mime_types = gdk_pixbuf_format_get_mime_types (format); for (type = mime_types; *type; type++) gimp_clip->n_target_entries++; g_strfreev (mime_types); } } if (gimp_clip->n_target_entries > 0) { gint i = 0; gimp_clip->target_entries = g_new0 (GtkTargetEntry, gimp_clip->n_target_entries); for (list = gimp_clip->pixbuf_formats; list; list = g_slist_next (list)) { GdkPixbufFormat *format = list->data; if (gdk_pixbuf_format_is_writable (format)) { gchar *format_name; gchar **mime_types; gchar **type; format_name = gdk_pixbuf_format_get_name (format); mime_types = gdk_pixbuf_format_get_mime_types (format); for (type = mime_types; *type; type++) { const gchar *mime_type = *type; if (gimp->be_verbose) g_printerr ("clipboard: writable pixbuf format: %s\n", mime_type); gimp_clip->target_entries[i].target = g_strdup (mime_type); gimp_clip->target_entries[i].flags = 0; gimp_clip->target_entries[i].info = i; i++; } g_strfreev (mime_types); g_free (format_name); } } } gimp_clip->n_svg_target_entries = 2; gimp_clip->svg_target_entries = g_new0 (GtkTargetEntry, 2); gimp_clip->svg_target_entries[0].target = g_strdup ("image/svg"); gimp_clip->svg_target_entries[0].flags = 0; gimp_clip->svg_target_entries[0].info = 0; gimp_clip->svg_target_entries[1].target = g_strdup ("image/svg+xml"); gimp_clip->svg_target_entries[1].flags = 0; gimp_clip->svg_target_entries[1].info = 1; }
DIA_PLUGIN_CHECK_INIT PluginInitResult dia_plugin_init(PluginInfo *info) { /* * If GTK is not initialized yet don't register this plug-in. This is * almost the same as app_is_interactive() but avoids to make plug-ins * depend on Dia's app core function. Also what we really need is a * display, not an interactive app ;) */ if (gdk_display_get_default ()) { if (!dia_plugin_info_init(info, "Pixbuf", _("gdk-pixbuf-based bitmap export/import"), _plugin_can_unload, _plugin_unload)) return DIA_PLUGIN_INIT_ERROR; else { GSList* formats = gdk_pixbuf_get_formats (); GSList* sl; /* if we get this far we still may be running non-interactive. To avoid complains * from color_convert() we are initializing ourselves ;) */ color_init (); /* * Instead of hard-coding capabilities, ask GdkPixbuf what's installed */ for (sl = formats; sl != NULL; sl = g_slist_next (sl)) { GdkPixbufFormat* format = (GdkPixbufFormat*)sl->data; if (gdk_pixbuf_format_is_writable (format)) { DiaExportFilter* efilter = g_new0 (DiaExportFilter, 1); gchar* name; name = gdk_pixbuf_format_get_name (format); /* the pixbuf desriptions are too generic for Dia's usage, make our own */ efilter->description = g_strdup_printf ("Pixbuf[%s]", name); /* NOT: gdk_pixbuf_format_get_description (format); */ efilter->extensions = (const gchar**)gdk_pixbuf_format_get_extensions (format); efilter->export_func = export_data; efilter->user_data = g_strdup (name); efilter->unique_name = g_strdup_printf ("pixbuf-%s", (gchar*)efilter->user_data); g_free (name); _export_filters = g_list_append (_export_filters, efilter); filter_register_export(efilter); } /* there is no write only filter */ { DiaImportFilter* ifilter; gchar* name; name = gdk_pixbuf_format_get_name (format); /* filter out the less useful ones to keep the total list reasonable short * (If anyone complains make it configurable via persistence and this default ;-) */ if ( strcmp (name, "ani") == 0 || strcmp (name, "ico") == 0 || strcmp (name, "pcx") == 0 || strcmp (name, "pnm") == 0 || strcmp (name, "ras") == 0 || strcmp (name, "tiff") == 0 || strcmp (name, "wbmp") == 0 || strcmp (name, "xbm") == 0) { g_free (name); continue; } ifilter = g_new0 (DiaImportFilter, 1); /* the pixbuf desriptions are too generic for Dia's usage, make our own */ ifilter->description = g_strdup_printf ("Pixbuf[%s]", name); ifilter->extensions = (const gchar**)gdk_pixbuf_format_get_extensions (format); ifilter->import_func = import_data; ifilter->user_data = gdk_pixbuf_format_get_name (format); /* they are in differnt namespaces aren't they? */ ifilter->unique_name = g_strdup_printf ("pixbuf-%s", name); /* don't use pixbuf loader for vector formats */ if ( strcmp (name, "svg") == 0 || strcmp (name, "svgz") == 0 || strcmp (name, "wmf") == 0 || strcmp (name, "emf") == 0) ifilter->hints = FILTER_DONT_GUESS; g_free (name); _import_filters = g_list_append (_import_filters, ifilter); filter_register_import(ifilter); } } g_slist_free (formats); } } return DIA_PLUGIN_INIT_OK; }
void pixmap_save_cb(GtkWidget *w, gpointer pixmap_ptr _U_) { GtkWidget *save_as_w; #if GTK_CHECK_VERSION(2,22,0) surface_info_t *surface_info = g_object_get_data(G_OBJECT(w), "surface-info"); #else GdkPixmap *pixmap = g_object_get_data(G_OBJECT(w), "pixmap"); #endif GdkPixbuf *pixbuf; GdkPixbufFormat *pixbuf_format; GtkWidget *main_vb, *save_as_type_hb, *type_lb, *type_cm; GSList *file_formats,*ffp; GdkWindow *parent; gchar *format_name; guint format_index = 0; guint default_index = 0; gchar *filename, *file_type; GError *error = NULL; gboolean ret; GtkWidget *msg_dialog; #if GTK_CHECK_VERSION(2,22,0) pixbuf = gdk_pixbuf_get_from_surface (surface_info->surface, 0, 0, surface_info->width, surface_info->height); #else pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0, -1, -1); #endif if(!pixbuf) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%sCould not get image from graph%s", simple_dialog_primary_start(), simple_dialog_primary_end()); return; } save_as_w = file_selection_new("Wireshark: Save Graph As ...", FILE_SELECTION_SAVE); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(save_as_w), TRUE); /* Container for each row of widgets */ main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); file_selection_set_extra_widget(save_as_w, main_vb); gtk_widget_show(main_vb); save_as_type_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE); gtk_box_pack_start(GTK_BOX(main_vb), save_as_type_hb, FALSE, FALSE, 0); gtk_widget_show(save_as_type_hb); type_lb = gtk_label_new("File type: "); gtk_box_pack_start(GTK_BOX(save_as_type_hb), type_lb, FALSE, FALSE, 0); gtk_widget_show(type_lb); type_cm = gtk_combo_box_text_new(); gtk_box_pack_start(GTK_BOX(save_as_type_hb), type_cm, FALSE, FALSE, 0); /* List all of the file formats the gdk-pixbuf library supports */ file_formats = gdk_pixbuf_get_formats(); ffp = file_formats; while(ffp) { pixbuf_format = ffp->data; if (gdk_pixbuf_format_is_writable(pixbuf_format)) { format_name = gdk_pixbuf_format_get_name(pixbuf_format); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(type_cm), format_name); if (!(g_ascii_strcasecmp(format_name, "png"))) default_index = format_index; format_index++; } ffp = g_slist_next(ffp); } g_slist_free(file_formats); gtk_combo_box_set_active(GTK_COMBO_BOX(type_cm), default_index); gtk_widget_show(type_cm); gtk_widget_show(save_as_w); window_present(save_as_w); parent = gtk_widget_get_parent_window(w); gdk_window_set_transient_for(gtk_widget_get_window(save_as_w), parent); /* * Loop until the user either selects a file or gives up. */ for (;;) { if (gtk_dialog_run(GTK_DIALOG(save_as_w)) != GTK_RESPONSE_ACCEPT) { /* They clicked "Cancel" or closed the dialog or.... */ window_destroy(save_as_w); return; } filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(save_as_w)); /* Perhaps the user specified a directory instead of a file. Check whether they did. */ if (test_for_directory(filename) == EISDIR) { /* It's a directory - set the file selection box to display that directory, and leave the selection box displayed. */ set_last_open_dir(filename); g_free(filename); file_selection_set_current_folder(save_as_w, get_last_open_dir()); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(save_as_w), ""); continue; } file_type = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(type_cm)); ret = gdk_pixbuf_save(pixbuf, filename, file_type, &error, NULL); g_free(filename); g_free(file_type); if (!ret) { msg_dialog = gtk_message_dialog_new(GTK_WINDOW(save_as_w), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", error->message); gtk_dialog_run(GTK_DIALOG(msg_dialog)); gtk_widget_destroy(msg_dialog); continue; } window_destroy(save_as_w); return; } }
/* The caller must free the strings stored in satisfactory_format_name and * satisfactory_mime_type. */ static gboolean avatar_chooser_need_mime_type_conversion (const gchar *current_mime_type, gchar **accepted_mime_types, gchar **satisfactory_format_name, gchar **satisfactory_mime_type) { gchar *good_mime_types[] = {"image/jpeg", "image/png", NULL}; guint i; GSList *formats, *l; gboolean found = FALSE; *satisfactory_format_name = NULL; *satisfactory_mime_type = NULL; /* If there is no accepted format there is nothing we can do */ if (accepted_mime_types == NULL || *accepted_mime_types == NULL) { return TRUE; } /* If the current mime type is good and accepted, don't change it! * jpeg is compress better pictures, but png is better for logos and * could have an alpha layer. */ if (str_in_strv (current_mime_type, good_mime_types) && str_in_strv (current_mime_type, accepted_mime_types)) { *satisfactory_mime_type = g_strdup (current_mime_type); *satisfactory_format_name = g_strdup (current_mime_type + strlen ("image/")); return FALSE; } /* The current mime type is either not accepted or not good to use. * Check if one of the good format is supported... */ for (i = 0; good_mime_types[i] != NULL; i++) { if (str_in_strv (good_mime_types[i], accepted_mime_types)) { *satisfactory_mime_type = g_strdup (good_mime_types[i]); *satisfactory_format_name = g_strdup (good_mime_types[i] + strlen ("image/")); return TRUE; } } /* Pick the first supported format we can write */ formats = gdk_pixbuf_get_formats (); for (l = formats; !found && l != NULL; l = l->next) { GdkPixbufFormat *format = l->data; gchar **format_mime_types; gchar **iter; if (!gdk_pixbuf_format_is_writable (format)) { continue; } format_mime_types = gdk_pixbuf_format_get_mime_types (format); for (iter = format_mime_types; *iter != NULL; iter++) { if (str_in_strv (*iter, accepted_mime_types)) { *satisfactory_format_name = gdk_pixbuf_format_get_name (format); *satisfactory_mime_type = g_strdup (*iter); found = TRUE; break; } } g_strfreev (format_mime_types); } g_slist_free (formats); return TRUE; }
static VALUE rg_writable_p(VALUE self) { return CBOOL2RVAL(gdk_pixbuf_format_is_writable(_SELF(self))); }
char* get_save_filename( GtkWindow* parent, const char* cwd, char** type ) { char* file = NULL; GtkFileChooser* dlg = (GtkFileChooser*)gtk_file_chooser_dialog_new( NULL, parent, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL ); GSList* modules, *module; GtkFileFilter *filter; gtk_file_chooser_set_current_folder( dlg, cwd ); GtkWidget* img = gtk_image_new(); gtk_widget_set_size_request( img, 128, 128 ); gtk_file_chooser_set_preview_widget( dlg, img ); g_signal_connect( dlg, "update-preview", G_CALLBACK(on_update_preview), img ); g_signal_connect( dlg, "notify::filter", G_CALLBACK(on_file_save_filter_changed), NULL ); /* /// TODO: determine file type from file name filter = gtk_file_filter_new(); gtk_file_filter_set_name( filter, _("Determined by File Name") ); gtk_file_filter_add_pixbuf_formats( filter ); gtk_file_chooser_add_filter( dlg, filter ); */ modules = gdk_pixbuf_get_formats(); for( module = modules; module; module = module->next ) { char *name, *desc, *tmp; char **exts, **mimes, **mime; GdkPixbufFormat* format = (GdkPixbufFormat*)module->data; if( ! gdk_pixbuf_format_is_writable( format ) ) continue; filter = gtk_file_filter_new(); name = gdk_pixbuf_format_get_name( format ); desc = gdk_pixbuf_format_get_description( format ); exts = gdk_pixbuf_format_get_extensions( format ); mimes = gdk_pixbuf_format_get_mime_types( format ); tmp = g_strdup_printf( "%s (*.%s)", desc, exts[0], NULL ); g_object_set_data_full(G_OBJECT(filter), "type", name, (GDestroyNotify)g_free); g_strfreev(exts); g_free( desc ); gtk_file_filter_set_name( filter, tmp ); g_free( tmp ); for( mime = mimes; *mime ; ++mime ) gtk_file_filter_add_mime_type( filter, *mime ); g_strfreev( mimes ); gtk_file_chooser_add_filter( dlg, filter ); } g_slist_free( modules ); int initial_jpg_quality = pref.jpg_quality; int initial_png_compression = pref.png_compression; if( gtk_dialog_run( (GtkDialog*)dlg ) == GTK_RESPONSE_OK ) { filter = gtk_file_chooser_get_filter( dlg ); file = gtk_file_chooser_get_filename( dlg ); *type = g_object_steal_data(G_OBJECT(filter), "type"); if( !*type ) // auto detection { /// TODO: auto file type } else { /* TODO: append appropriate extension if needed. */ } } gtk_widget_destroy( (GtkWidget*)dlg ); if ((initial_jpg_quality != pref.jpg_quality) || (initial_png_compression != pref.png_compression)) save_preferences(); return file; }
static void images_gdk_format_add_if_writable(GdkPixbufFormat *data, GSList **list){ if(gdk_pixbuf_format_is_writable(data)) *list=g_slist_prepend(*list, data); }/*g_slist_foreach(formats, images_gdk_format_add_if_writable, &gdk_pixbuf_formats);*/