/* Write a libvips NULL-terminated utf-8 string into a entry tagged with a * encoding. UserComment is like this, for example. */ static void vips_exif_set_string_encoding( ExifData *ed, ExifEntry *entry, unsigned long component, const char *data ) { char *str; int len; str = drop_tail( data ); /* libexif can only really save ASCII to things like UserComment. */ #ifdef HAVE_G_STR_TO_ASCII { char *ascii; ascii = g_str_to_ascii( str, NULL ); g_free( str ); str = ascii; } #endif /*HAVE_G_STR_TO_ASCII*/ /* libexif comment strings are not NULL-terminated, and have an * encoding tag (always ASCII) in the first 8 bytes. */ len = strlen( str ); vips_exif_alloc_string( entry, sizeof( ASCII_COMMENT ) - 1 + len ); memcpy( entry->data, ASCII_COMMENT, sizeof( ASCII_COMMENT ) - 1 ); memcpy( entry->data + sizeof( ASCII_COMMENT ) - 1, str, len ); g_free( str ); }
/* Write a libvips NULL-terminated utf-8 string into an ASCII entry. Tags like * ImageDescription work like this. */ static void vips_exif_set_string_ascii( ExifData *ed, ExifEntry *entry, unsigned long component, const char *data ) { char *str; int len; str = drop_tail( data ); /* libexif can only really save ASCII to things like UserComment. */ #ifdef HAVE_G_STR_TO_ASCII { char *ascii; ascii = g_str_to_ascii( str, NULL ); g_free( str ); str = ascii; } #endif /*HAVE_G_STR_TO_ASCII*/ /* ASCII strings are NULL-terminated. */ len = strlen( str ); vips_exif_alloc_string( entry, len + 1 ); memcpy( entry->data, str, len + 1 ); entry->format = EXIF_FORMAT_ASCII; g_free( str ); }
/** * gst_encoding_target_load: * @name: the name of the #GstEncodingTarget to load (automatically * converted to lower case internally as capital letters are not * valid for target names). * @category: (allow-none): the name of the target category, like * #GST_ENCODING_CATEGORY_DEVICE. Can be %NULL * @error: If an error occured, this field will be filled in. * * Searches for the #GstEncodingTarget with the given name, loads it * and returns it. * * If the category name is specified only targets from that category will be * searched for. * * Returns: (transfer full): The #GstEncodingTarget if available, else %NULL. */ GstEncodingTarget * gst_encoding_target_load (const gchar * name, const gchar * category, GError ** error) { gint i; gchar *p, *lname, *lfilename = NULL, *tldir, **encoding_target_dirs; const gchar *envvar; GstEncodingTarget *target = NULL; g_return_val_if_fail (name != NULL, NULL); p = lname = g_str_to_ascii (name, NULL); for (; *p; ++p) *p = g_ascii_tolower (*p); if (!validate_name (lname)) goto invalid_name; if (category && !validate_name (category)) goto invalid_category; lfilename = g_strdup_printf ("%s" GST_ENCODING_TARGET_SUFFIX, lname); envvar = g_getenv ("GST_ENCODING_TARGET_PATH"); if (envvar) { encoding_target_dirs = g_strsplit (envvar, G_SEARCHPATH_SEPARATOR_S, -1); for (i = 0; encoding_target_dirs[i]; i++) { target = gst_encoding_target_subload (encoding_target_dirs[i], category, lfilename, error); if (target) break; } g_strfreev (encoding_target_dirs); if (target) goto done; } /* Try from local profiles */ tldir = g_build_filename (g_get_user_data_dir (), "gstreamer-" GST_API_VERSION, GST_ENCODING_TARGET_DIRECTORY, NULL); target = gst_encoding_target_subload (tldir, category, lfilename, error); g_free (tldir); if (target == NULL) { /* Try from system-wide profiles */ tldir = g_build_filename (GST_DATADIR, "gstreamer-" GST_API_VERSION, GST_ENCODING_TARGET_DIRECTORY, NULL); target = gst_encoding_target_subload (tldir, category, lfilename, error); g_free (tldir); } if (!target) { GList *tmp, *targets = gst_encoding_list_all_targets (NULL); for (tmp = targets; tmp; tmp = tmp->next) { gint i; GstEncodingTarget *tmptarget = tmp->data; gchar **names = g_strsplit (tmptarget->name, ";", -1); for (i = 0; names[i]; i++) { if (!g_strcmp0 (names[i], lname) && (!category || !g_strcmp0 (tmptarget->category, category))) { target = gst_object_ref (tmptarget); break; } } g_strfreev (names); if (target) break; } g_list_free_full (targets, gst_object_unref); } done: g_free (lfilename); g_free (lname); return target; invalid_name: { GST_ERROR ("Invalid name for encoding target : '%s'", name); goto done; } invalid_category: { GST_ERROR ("Invalid name for encoding category : '%s'", category); goto done; } }