static void add_image_files (GtkWidget *dialog) { GtkFileFilter* filter; GSList *formats, *l; gchar **mimes, **t; filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All image files")); formats = gdk_pixbuf_get_formats (); for (l = formats; l; l = g_slist_next (l)) { mimes = gdk_pixbuf_format_get_mime_types ((GdkPixbufFormat*)l->data); for (t = mimes; *t; t++) gtk_file_filter_add_mime_type (filter, *t); g_strfreev (mimes); } g_slist_free (formats); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter); filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All JPEG files")); gtk_file_filter_add_mime_type (filter, "image/jpeg"); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All files")); gtk_file_filter_add_pattern (filter, "*"); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); }
static GstCaps * gst_gdk_pixbuf_get_capslist (void) { GSList *slist; GSList *slist0; GstCaps *capslist = NULL; GstCaps *return_caps = NULL; GstCaps *tmpl_caps; capslist = gst_caps_new_empty (); slist0 = gdk_pixbuf_get_formats (); for (slist = slist0; slist; slist = g_slist_next (slist)) { GdkPixbufFormat *pixbuf_format; char **mimetypes; char **mimetype; pixbuf_format = slist->data; mimetypes = gdk_pixbuf_format_get_mime_types (pixbuf_format); for (mimetype = mimetypes; *mimetype; mimetype++) { gst_caps_append_structure (capslist, gst_structure_new (*mimetype, NULL)); } g_strfreev (mimetypes); } g_slist_free (slist0); tmpl_caps = gst_static_caps_get (&gst_gdk_pixbuf_sink_template.static_caps); return_caps = gst_caps_intersect (capslist, tmpl_caps); gst_caps_unref (tmpl_caps); gst_caps_unref (capslist); return return_caps; }
gchar * photos_utils_get_extension_from_mime_type (const gchar *mime_type) { g_autoptr (GSList) formats = NULL; GSList *l; gchar *ret_val = NULL; formats = gdk_pixbuf_get_formats (); for (l = formats; l != NULL; l = l->next) { GdkPixbufFormat *format = (GdkPixbufFormat*) l->data; g_auto (GStrv) supported_mime_types = NULL; guint i; supported_mime_types = gdk_pixbuf_format_get_mime_types (format); for (i = 0; supported_mime_types[i] != NULL; i++) { if (g_strcmp0 (mime_type, supported_mime_types[i]) == 0) { ret_val = photos_utils_get_pixbuf_common_suffix (format); break; } } if (ret_val != NULL) break; } return ret_val; }
static GHashTable * get_types_table (void) { static GHashTable *image_mime_types = NULL; GSList *format_list, *l; char **types; int i; if (image_mime_types == NULL) { image_mime_types = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); eel_debug_call_at_shutdown_with_data ((GFreeFunc)g_hash_table_destroy, image_mime_types); format_list = gdk_pixbuf_get_formats (); for (l = format_list; l; l = l->next) { types = gdk_pixbuf_format_get_mime_types (l->data); for (i = 0; i < G_N_ELEMENTS (types); i++) { g_hash_table_insert (image_mime_types, types [i], GUINT_TO_POINTER (1)); } g_free (types); } g_slist_free (format_list); } return image_mime_types; }
gboolean _gdk_pixbuf_mime_type_is_readable (const char *mime_type) { GSList *formats; GSList *scan; gboolean result; if (mime_type == NULL) return FALSE; result = FALSE; formats = gdk_pixbuf_get_formats (); for (scan = formats; ! result && scan; scan = scan->next) { GdkPixbufFormat *format = scan->data; char **mime_types; int i; if (gdk_pixbuf_format_is_disabled (format)) continue; 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) { result = TRUE; break; } } } g_slist_free (formats); return result; }
static GHashTable * get_types_table (void) { static GHashTable *image_mime_types = NULL; GSList *format_list, *l; char **types; int i; if (image_mime_types == NULL) { image_mime_types = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); format_list = gdk_pixbuf_get_formats (); for (l = format_list; l; l = l->next) { types = gdk_pixbuf_format_get_mime_types (l->data); for (i = 0; types[i] != NULL; i++) { g_hash_table_insert (image_mime_types, types [i], GUINT_TO_POINTER (1)); } g_free (types); } g_slist_free (format_list); } return image_mime_types; }
static GdkAtom gimp_clipboard_wait_for_buffer (Gimp *gimp) { GimpClipboard *gimp_clip = gimp_clipboard_get (gimp); GdkAtom *targets; gint n_targets; GdkAtom result = GDK_NONE; targets = gimp_clipboard_wait_for_targets (gimp, &n_targets); if (targets) { GSList *list; for (list = gimp_clip->pixbuf_formats; list; list = g_slist_next (list)) { GdkPixbufFormat *format = list->data; gchar **mime_types; gchar **type; if (gimp->be_verbose) g_printerr ("clipboard: checking pixbuf format '%s'\n", gdk_pixbuf_format_get_name (format)); mime_types = gdk_pixbuf_format_get_mime_types (format); for (type = mime_types; *type; type++) { gchar *mime_type = *type; GdkAtom atom = gdk_atom_intern (mime_type, FALSE); gint i; if (gimp->be_verbose) g_printerr (" - checking mime type '%s'\n", mime_type); for (i = 0; i < n_targets; i++) { if (targets[i] == atom) { result = atom; break; } } if (result != GDK_NONE) break; } g_strfreev (mime_types); if (result != GDK_NONE) break; } g_free (targets); } return result; }
const IE_MimeConfidence * IE_ImpGraphicGdkPixbuf_Sniffer::getMimeConfidence () { static IE_MimeConfidence *mimeConfidence = NULL; if (mimeConfidence) { return mimeConfidence; } GSList *formatList = gdk_pixbuf_get_formats (); GSList *formatIter; GdkPixbufFormat *format; gsize idx; std::vector<std::string> all_mime_types; // dry run to count entries formatIter = formatList; while (formatIter) { gchar **mime_types; format = (GdkPixbufFormat *) formatIter->data; mime_types = gdk_pixbuf_format_get_mime_types (format); gchar **tmp = mime_types; while (*tmp) { all_mime_types.push_back(*tmp); tmp++; } g_strfreev(mime_types); GSList *node; node = formatIter; formatIter = formatIter->next; g_slist_free_1(node); } mimeConfidence = new IE_MimeConfidence[all_mime_types.size() + 1]; idx = 0; for(std::vector<std::string>::iterator iter = all_mime_types.begin(); iter != all_mime_types.end(); ++iter) { mimeConfidence[idx].match = IE_MIME_MATCH_FULL; mimeConfidence[idx].mimetype = *iter; if(*iter == "image/x-wmf") { UT_DEBUGMSG(("WMF mime is only good\n")); mimeConfidence[idx].confidence = UT_CONFIDENCE_GOOD; } else { mimeConfidence[idx].confidence = UT_CONFIDENCE_PERFECT; } idx++; } // null-terminator mimeConfidence[idx].match = IE_MIME_MATCH_BOGUS; mimeConfidence[idx].confidence = UT_CONFIDENCE_ZILCH; return mimeConfidence; }
/** * 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); }
GdkPixbuf * tpaw_pixbuf_from_data_and_mime (gchar *data, gsize data_size, gchar **mime_type) { GdkPixbufLoader *loader; GdkPixbufFormat *format; GdkPixbuf *pixbuf = NULL; gchar **mime_types; GError *error = NULL; if (!data) return NULL; loader = gdk_pixbuf_loader_new (); if (!gdk_pixbuf_loader_write (loader, (guchar *) data, data_size, &error)) { DEBUG ("Failed to write to pixbuf loader: %s", error ? error->message : "No error given"); goto out; } if (!gdk_pixbuf_loader_close (loader, &error)) { DEBUG ("Failed to close pixbuf loader: %s", error ? error->message : "No error given"); goto out; } pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf) { g_object_ref (pixbuf); if (mime_type != NULL) { format = gdk_pixbuf_loader_get_format (loader); mime_types = gdk_pixbuf_format_get_mime_types (format); *mime_type = g_strdup (*mime_types); if (mime_types[1] != NULL) DEBUG ("Loader supports more than one mime " "type! Picking the first one, %s", *mime_type); g_strfreev (mime_types); } } out: g_clear_error (&error); g_object_unref (loader); return pixbuf; }
/** * gtk_selection_data_set_pixbuf: * @selection_data: a #GtkSelectionData * @pixbuf: a #GdkPixbuf * * Sets the contents of the selection from a #GdkPixbuf * The pixbuf is converted to the form determined by * @selection_data->target. * * Returns: %TRUE if the selection was successfully set, * otherwise %FALSE. **/ gboolean gtk_selection_data_set_pixbuf (GtkSelectionData *selection_data, GdkPixbuf *pixbuf) { GSList *formats, *f; gchar **mimes, **m; GdkAtom atom; gboolean result; gchar *str, *type; gsize len; g_return_val_if_fail (selection_data != NULL, FALSE); g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE); formats = gdk_pixbuf_get_formats (); for (f = formats; f; f = f->next) { GdkPixbufFormat *fmt = f->data; mimes = gdk_pixbuf_format_get_mime_types (fmt); for (m = mimes; *m; m++) { atom = g_intern_string (*m); if (selection_data->target == atom) { str = NULL; type = gdk_pixbuf_format_get_name (fmt); result = gdk_pixbuf_save_to_buffer (pixbuf, &str, &len, type, NULL, ((strcmp (type, "png") == 0) ? "compression" : NULL), "2", NULL); if (result) gtk_selection_data_set (selection_data, atom, 8, (guchar *)str, len); g_free (type); g_free (str); g_strfreev (mimes); g_slist_free (formats); return result; } } g_strfreev (mimes); } g_slist_free (formats); return FALSE; }
static VALUE rg_mime_types(VALUE self) { gint i = 0; gchar** mime_types = gdk_pixbuf_format_get_mime_types(_SELF(self)); VALUE array = rb_ary_new(); while(mime_types[i]){ rb_ary_push(array, CSTR2RVAL(mime_types[i])); i++; } g_strfreev(mime_types); return array; }
/** Convert Base64 to pixbuf * @param b64 Base64 encoded data */ GdkPixbuf * pixbuf_decode_base64 (const gchar *b64) { /* see lib/prop_pixbuf.c(data_pixbuf) for a very similar implementation */ GdkPixbuf *pixbuf = NULL; GdkPixbufLoader *loader; GError *error = NULL; loader = gdk_pixbuf_loader_new (); if (loader) { gint state = 0; guint save = 0; # define BUF_SIZE 4096 guchar buf[BUF_SIZE]; gchar *in = (gchar *)b64; /* direct access, not involving another xmlStrDup/xmlFree */ gssize len = strlen (b64); do { gsize step = g_base64_decode_step (in, len > BUF_SIZE ? BUF_SIZE : len, buf, &state, &save); if (!gdk_pixbuf_loader_write (loader, buf, step, &error)) break; in += BUF_SIZE; len -= BUF_SIZE; } while (len > 0); if (gdk_pixbuf_loader_close (loader, error ? NULL : &error)) { GdkPixbufFormat *format = gdk_pixbuf_loader_get_format (loader); gchar *format_name = gdk_pixbuf_format_get_name (format); gchar **mime_types = gdk_pixbuf_format_get_mime_types (format); dia_log_message ("Loaded pixbuf from '%s' with '%s'\n", format_name, mime_types[0]); pixbuf = g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader)); /* attach the mime-type to the pixbuf */ g_object_set_data_full (G_OBJECT (pixbuf), "mime-type", g_strdup (mime_types[0]), (GDestroyNotify)g_free); g_strfreev (mime_types); g_free (format_name); } else { message_warning (_("Failed to load image form diagram:\n%s"), error->message); g_error_free (error); } g_object_unref (loader); } return pixbuf; # undef BUF_SIZE }
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 GList* thunar_apr_provider_get_pages (ThunarxPropertyPageProvider *property_page_provider, GList *files) { GSList *formats; GSList *lp; gchar **mime_types; gchar *scheme; GList *pages = NULL; gint n; /* we can handle only property pages for a single file */ if (G_UNLIKELY (files == NULL || files->next != NULL)) return NULL; /* determine the URI scheme of the file (works only for local files) */ scheme = thunarx_file_info_get_uri_scheme (files->data); if (G_LIKELY (strcmp (scheme, "file") == 0)) { /* ThunarAprDesktopPage case */ if (G_LIKELY (pages == NULL)) { /* check if we have a .desktop file here */ if (thunarx_file_info_has_mime_type (files->data, "application/x-desktop")) pages = g_list_append (pages, g_object_new (THUNAR_APR_TYPE_DESKTOP_PAGE, "file", files->data, NULL)); } /* ThunarAprImagePage case */ if (G_LIKELY (pages == NULL)) { /* determine the supported GdkPixbuf formats */ formats = gdk_pixbuf_get_formats (); for (lp = formats; lp != NULL && pages == NULL; lp = lp->next) { /* check if any of the mime types of this format matches */ mime_types = gdk_pixbuf_format_get_mime_types (lp->data); for (n = 0; mime_types[n] != NULL && pages == NULL; ++n) if (thunarx_file_info_has_mime_type (files->data, mime_types[n])) pages = g_list_append (pages, g_object_new (THUNAR_APR_TYPE_IMAGE_PAGE, "file", files->data, NULL)); g_strfreev (mime_types); } g_slist_free (formats); } } g_free (scheme); return pages; }
char * go_image_format_to_mime (char const *format) { char *ret = NULL; guint i; #ifdef GOFFICE_WITH_GTK GSList *ptr, *pixbuf_fmts; GdkPixbufFormat *pfmt; gchar *name; int cmp; gchar **mimes; #endif const char* formats[] = { "svg", "image/svg,image/svg+xml", "wmf", "x-wmf", "emf", "x-emf", }; if (format == NULL) return NULL; for (i = 0; i < G_N_ELEMENTS (formats); i +=2) if (strcmp (format, formats[i]) == 0) return g_strdup (formats[i+1]); #ifdef GOFFICE_WITH_GTK /* Not a format we have special knowledge about - ask gdk-pixbuf */ pixbuf_fmts = gdk_pixbuf_get_formats (); for (ptr = pixbuf_fmts; ptr != NULL; ptr = ptr->next) { pfmt = (GdkPixbufFormat *)ptr->data; name = gdk_pixbuf_format_get_name (pfmt); cmp = strcmp (format, name); g_free (name); if (cmp == 0) { mimes = gdk_pixbuf_format_get_mime_types (pfmt); ret = g_strjoinv (",", mimes); g_strfreev (mimes); break; } } g_slist_free (pixbuf_fmts); #endif return ret; }
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 */ }
static void gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore) { guint8 *data; GdkPixbufLoader *pixbuf_loader; GdkPixbufFormat *format; data = gst_type_find_peek (tf, 0, GST_GDK_PIXBUF_TYPE_FIND_SIZE); if (data == NULL) return; GST_DEBUG ("creating new loader"); pixbuf_loader = gdk_pixbuf_loader_new (); gdk_pixbuf_loader_write (pixbuf_loader, data, GST_GDK_PIXBUF_TYPE_FIND_SIZE, NULL); format = gdk_pixbuf_loader_get_format (pixbuf_loader); if (format != NULL) { GstCaps *caps; gchar **p; gchar **mlist = gdk_pixbuf_format_get_mime_types (format); for (p = mlist; *p; ++p) { GST_DEBUG ("suggesting mime type %s", *p); caps = gst_caps_new_simple (*p, NULL); gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, caps); gst_caps_free (caps); } g_strfreev (mlist); } GST_DEBUG ("closing pixbuf loader, hope it doesn't hang ..."); /* librsvg 2.4.x has a bug where it triggers an endless loop in trying to close a gzip that's not an svg; fixed upstream but no good way to work around it */ gdk_pixbuf_loader_close (pixbuf_loader, NULL); GST_DEBUG ("closed pixbuf loader"); g_object_unref (G_OBJECT (pixbuf_loader)); }
static void gth_main_register_default_file_loader (void) { GSList *formats; GSList *scan; formats = gdk_pixbuf_get_formats (); for (scan = formats; scan; scan = scan->next) { GdkPixbufFormat *format = scan->data; char **mime_types; int i; if (gdk_pixbuf_format_is_disabled (format)) continue; mime_types = gdk_pixbuf_format_get_mime_types (format); for (i = 0; mime_types[i] != NULL; i++) gth_main_register_pixbuf_loader (gth_pixbuf_animation_new_from_file, mime_types[i], NULL); } }
static GList* gdk_pixbuf_mime_type_list () { GSList *formats, *list; GList *result = NULL; formats = gdk_pixbuf_get_formats (); for (list = formats; list != NULL; list = list->next) { GdkPixbufFormat *format = list->data; gchar **mime_types; if (gdk_pixbuf_format_is_disabled (format)) continue; mime_types = gdk_pixbuf_format_get_mime_types (format); result = g_list_prepend (result, mime_types); } g_slist_free (formats); return result; }
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; }
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; }
GdkPixbuf * IE_ImpGraphic_GdkPixbuf::pixbufForByteBuf (UT_ByteBuf * pBB, std::string & mimetype) { if ( !pBB || !pBB->getLength() ) return NULL; GdkPixbuf * pixbuf = NULL; bool bIsXPM = false; const char * szBuf = reinterpret_cast<const char *>(pBB->getPointer(0)); if((pBB->getLength() > 9) && (strncmp (szBuf, "/* XPM */", 9) == 0)) { bIsXPM = true; } if(bIsXPM) { pixbuf = _loadXPM(pBB); } else { GError * err = 0; GdkPixbufLoader * ldr = 0; ldr = gdk_pixbuf_loader_new (); if (!ldr) { UT_DEBUGMSG (("GdkPixbuf: couldn't create loader! WTF?\n")); UT_ASSERT (ldr); return NULL ; } if (!gdk_pixbuf_loader_write (ldr, static_cast<const guchar *>(pBB->getPointer (0)), static_cast<gsize>(pBB->getLength ()), &err) ) { UT_DEBUGMSG(("DOM: couldn't write to loader: %s\n", err->message)); g_error_free(err); gdk_pixbuf_loader_close (ldr, NULL); g_object_unref (G_OBJECT(ldr)); mimetype.clear(); return NULL ; } gdk_pixbuf_loader_close (ldr, NULL); pixbuf = gdk_pixbuf_loader_get_pixbuf (ldr); GdkPixbufFormat * format = gdk_pixbuf_loader_get_format(ldr); gchar ** mime_types = gdk_pixbuf_format_get_mime_types(format); gchar ** current = mime_types; while(*current) { if((strcmp(*current, "image/jpeg") == 0) || (strcmp(*current, "image/png") == 0)) { mimetype = *current; break; } current++; } g_strfreev(mime_types); // ref before closing the loader if ( pixbuf ) g_object_ref (G_OBJECT(pixbuf)); g_object_unref (G_OBJECT(ldr)); } return pixbuf; }
void GdkpixbufInput::init(void) { GSList * formatlist, * formatlisthead; /* \todo I'm not sure if I need to free this list */ for (formatlist = formatlisthead = gdk_pixbuf_get_formats(); formatlist != NULL; formatlist = g_slist_next(formatlist)) { GdkPixbufFormat *pixformat = (GdkPixbufFormat *)formatlist->data; gchar *name = gdk_pixbuf_format_get_name(pixformat); gchar *description = gdk_pixbuf_format_get_description(pixformat); gchar **extensions = gdk_pixbuf_format_get_extensions(pixformat); gchar **mimetypes = gdk_pixbuf_format_get_mime_types(pixformat); for (int i = 0; extensions[i] != NULL; i++) { for (int j = 0; mimetypes[j] != NULL; j++) { /* thanks but no thanks, we'll handle SVG extensions... */ if (strcmp(extensions[i], "svg") == 0) { continue; } if (strcmp(extensions[i], "svgz") == 0) { continue; } if (strcmp(extensions[i], "svg.gz") == 0) { continue; } gchar *caption = g_strdup_printf(_("%s bitmap image import"), name); gchar *xmlString = g_strdup_printf( "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" "<name>%s</name>\n" "<id>org.inkscape.input.gdkpixbuf.%s</id>\n" "<param name='link' type='optiongroup' appearance='full' _gui-text='" N_("Image Import Type:") "' _gui-description='" N_("Embed results in stand-alone, larger SVG files. Link references a file outside this SVG document and all files must be moved together.") "' >\n" "<_option value='embed' >" N_("Embed") "</_option>\n" "<_option value='link' >" N_("Link") "</_option>\n" "</param>\n" "<param name='dpi' type='optiongroup' appearance='full' _gui-text='" N_("Image DPI:") "' _gui-description='" N_("Take information from file or use default bitmap import resolution as defined in the preferences.") "' >\n" "<_option value='from_file' >" N_("From file") "</_option>\n" "<_option value='from_default' >" N_("Default import resolution") "</_option>\n" "</param>\n" "<param name='scale' type='optiongroup' appearance='full' _gui-text='" N_("Image Rendering Mode:") "' _gui-description='" N_("When an image is upscaled, apply smoothing or keep blocky (pixelated). (Will not work in all browsers.)") "' >\n" "<_option value='auto' >" N_("None (auto)") "</_option>\n" "<_option value='optimizeQuality' >" N_("Smooth (optimizeQuality)") "</_option>\n" "<_option value='optimizeSpeed' >" N_("Blocky (optimizeSpeed)") "</_option>\n" "</param>\n" "<param name=\"do_not_ask\" _gui-description='" N_("Hide the dialog next time and always apply the same actions.") "' gui-text=\"" N_("Don't ask again") "\" type=\"boolean\" >false</param>\n" "<input>\n" "<extension>.%s</extension>\n" "<mimetype>%s</mimetype>\n" "<filetypename>%s (*.%s)</filetypename>\n" "<filetypetooltip>%s</filetypetooltip>\n" "</input>\n" "</inkscape-extension>", caption, extensions[i], extensions[i], mimetypes[j], name, extensions[i], description ); Inkscape::Extension::build_from_mem(xmlString, new GdkpixbufInput()); g_free(xmlString); g_free(caption); } } g_free(name); g_free(description); g_strfreev(mimetypes); g_strfreev(extensions); } g_slist_free(formatlisthead); }
cairo_surface_t * rsvg_cairo_surface_new_from_href (RsvgHandle *handle, const char *href, GError **error) { char *data; gsize data_len; char *mime_type = NULL; GdkPixbufLoader *loader = NULL; GdkPixbuf *pixbuf = NULL; cairo_surface_t *surface = NULL; data = _rsvg_handle_acquire_data (handle, href, &mime_type, &data_len, error); if (data == NULL) return NULL; if (mime_type) { loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, error); } else { loader = gdk_pixbuf_loader_new (); } if (loader == NULL) goto out; if (!gdk_pixbuf_loader_write (loader, (guchar *) data, data_len, error)) { gdk_pixbuf_loader_close (loader, NULL); goto out; } if (!gdk_pixbuf_loader_close (loader, error)) goto out; pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (!pixbuf) { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_FAILED, _("Failed to load image '%s': reason not known, probably a corrupt image file"), href); goto out; } surface = rsvg_cairo_surface_from_pixbuf (pixbuf); if (mime_type == NULL) { /* Try to get the information from the loader */ GdkPixbufFormat *format; char **mime_types; if ((format = gdk_pixbuf_loader_get_format (loader)) != NULL) { mime_types = gdk_pixbuf_format_get_mime_types (format); if (mime_types != NULL) mime_type = g_strdup (mime_types[0]); g_strfreev (mime_types); } } if ((handle->priv->flags & RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA) != 0 && mime_type != NULL && cairo_surface_set_mime_data (surface, mime_type, (guchar *) data, data_len, g_free, data) == CAIRO_STATUS_SUCCESS) { data = NULL; /* transferred to the surface */ } out: if (loader) g_object_unref (loader); g_free (mime_type); g_free (data); return surface; }
/* 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; }