GInputStream * _rsvg_io_acquire_stream (const char *href, const char *base_uri, char **mime_type, GCancellable *cancellable, GError **error) { GInputStream *stream; char *data; gsize len; if (!(href && *href)) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid URI"); return NULL; } if (strncmp (href, "data:", 5) == 0) { if (!(data = rsvg_acquire_data_data (href, NULL, mime_type, &len, error))) return NULL; return g_memory_input_stream_new_from_data (data, len, (GDestroyNotify) g_free); } if ((data = rsvg_acquire_file_data (href, base_uri, mime_type, &len, cancellable, NULL))) return g_memory_input_stream_new_from_data (data, len, (GDestroyNotify) g_free); if ((stream = rsvg_acquire_gvfs_stream (href, base_uri, mime_type, cancellable, error))) return stream; return NULL; }
void ghb_load_icons() { GHashTableIter iter; gchar *key; GValue *gval; GValue *icons = ghb_resource_get("icons"); ghb_dict_iter_init(&iter, icons); // middle (void*) cast prevents gcc warning "defreferencing type-punned // pointer will break strict-aliasing rules" while (g_hash_table_iter_next( &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&gval)) { ghb_rawdata_t *rd; gint size; GdkPixbuf *pb; gboolean svg; char *name = g_strdup(key); char *pos; pos = g_strstr_len(name, -1, "."); if (pos != NULL) *pos = '\0'; GInputStream *gis; svg = ghb_value_boolean(ghb_dict_lookup(gval, "svg")); rd = g_value_get_boxed(ghb_dict_lookup(gval, "data")); if (svg) { int ii; int sizes[] = {16, 22, 24, 32, 48, 64, 128, 256, 0}; for (ii = 0; sizes[ii]; ii++) { gis = g_memory_input_stream_new_from_data(rd->data, rd->size, NULL); pb = gdk_pixbuf_new_from_stream_at_scale(gis, sizes[ii], sizes[ii], TRUE, NULL, NULL); g_input_stream_close(gis, NULL, NULL); size = gdk_pixbuf_get_height(pb); gtk_icon_theme_add_builtin_icon(name, size, pb); g_object_unref(pb); } } else { gis = g_memory_input_stream_new_from_data(rd->data, rd->size, NULL); pb = gdk_pixbuf_new_from_stream(gis, NULL, NULL); g_input_stream_close(gis, NULL, NULL); size = gdk_pixbuf_get_height(pb); gtk_icon_theme_add_builtin_icon(name, size, pb); g_object_unref(pb); } g_free(name); } }
void ghb_load_icons() { #if GTK_CHECK_VERSION(3, 14, 0) ghb_icons_register_resource(); gtk_icon_theme_add_resource_path(gtk_icon_theme_get_default(), "/fr/handbrake/ghb/icons"); #else ghb_icons_register_resource(); GResource *icon_res = ghb_icons_get_resource(); char ** children = g_resource_enumerate_children(icon_res, "/fr/handbrake/ghb/icons/scalable/apps", 0, NULL); if (children == NULL) { g_warning("No icons in resources!"); return; } int ii; for (ii = 0; children[ii] != NULL; ii++) { char * path; path = g_strdup_printf("/fr/handbrake/ghb/icons/scalable/apps/%s", children[ii]); GBytes *gbytes = g_resource_lookup_data(icon_res, path, 0, NULL); gsize data_size; gconstpointer data = g_bytes_get_data(gbytes, &data_size); g_free(path); char *pos; char *name = g_strdup(children[ii]); pos = g_strstr_len(name, -1, "."); if (pos != NULL) *pos = '\0'; int jj; int sizes[] = {16, 22, 24, 32, 48, 64, 128, 256, 0}; for (jj = 0; sizes[jj]; jj++) { GdkPixbuf *pb; GInputStream *gis; int size; gis = g_memory_input_stream_new_from_data(data, data_size, NULL); pb = gdk_pixbuf_new_from_stream_at_scale(gis, sizes[jj], sizes[jj], TRUE, NULL, NULL); g_input_stream_close(gis, NULL, NULL); size = gdk_pixbuf_get_height(pb); gtk_icon_theme_add_builtin_icon(name, size, pb); g_object_unref(pb); } g_bytes_unref(gbytes); } g_strfreev(children); #endif }
static void file_buffer_ready_cb (void **buffer, gsize count, GError *error, gpointer user_data) { GthPixbufListTask *self = user_data; GInputStream *istream; GdkPixbuf *pixbuf; if (error != NULL) { gth_task_completed (GTH_TASK (self), error); return; } istream = g_memory_input_stream_new_from_data (*buffer, count, NULL); pixbuf = gdk_pixbuf_new_from_stream (istream, gth_task_get_cancellable (GTH_TASK (self)), &error); if (pixbuf != NULL) { self->priv->original_pixbuf = gdk_pixbuf_apply_embedded_orientation (pixbuf); g_object_unref (pixbuf); } else self->priv->original_pixbuf = NULL; g_object_unref (istream); if (self->priv->original_pixbuf == NULL) { gth_task_completed (GTH_TASK (self), error); return; } gth_pixbuf_task_set_source (GTH_PIXBUF_TASK (self->priv->task), self->priv->original_pixbuf); gth_task_exec (self->priv->task, gth_task_get_cancellable (GTH_TASK (self))); }
static void image_buffer_ready_cb (void **buffer, gsize count, GError *error, gpointer user_data) { PicasaAccountPropertiesDialog *self = user_data; GInputStream *stream; GdkPixbuf *pixbuf; if (error != NULL) { _gtk_error_dialog_from_gerror_show (GTK_WINDOW (self), _("Could not load the file"), &error); return; } stream = g_memory_input_stream_new_from_data (*buffer, count, NULL); pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL); if (pixbuf != NULL) { gtk_widget_show (GET_WIDGET ("challange_box")); gtk_image_set_from_pixbuf (GTK_IMAGE (GET_WIDGET ("challenge_image")), pixbuf); g_object_unref (pixbuf); } g_object_unref (stream); }
void WebSoupRequestManager::didHandleURIRequest(const IPC::DataReference& requestData, uint64_t contentLength, const String& mimeType, uint64_t requestID) { WebSoupRequestAsyncData* data = m_requestMap.get(requestID); ASSERT(data); GRefPtr<GTask> task = data->releaseTask(); ASSERT(task.get()); WebKitSoupRequestGeneric* request = WEBKIT_SOUP_REQUEST_GENERIC(g_task_get_source_object(task.get())); webkitSoupRequestGenericSetContentLength(request, contentLength ? contentLength : -1); webkitSoupRequestGenericSetContentType(request, !mimeType.isEmpty() ? mimeType.utf8().data() : 0); GInputStream* dataStream; if (!requestData.size()) { // Empty reply, just create and empty GMemoryInputStream. dataStream = g_memory_input_stream_new(); m_requestMap.remove(requestID); } else if (requestData.size() == contentLength) { // We don't expect more data, so we can just create a GMemoryInputStream with all the data. dataStream = g_memory_input_stream_new_from_data(g_memdup(requestData.data(), requestData.size()), contentLength, g_free); m_requestMap.remove(requestID); } else { // We expect more data chunks from the UI process. dataStream = webkitSoupRequestInputStreamNew(contentLength); data->stream = dataStream; webkitSoupRequestInputStreamAddData(WEBKIT_SOUP_REQUEST_INPUT_STREAM(dataStream), requestData.data(), requestData.size()); } g_task_return_pointer(task.get(), dataStream, g_object_unref); }
END_TEST START_TEST(test_store_empty_01) { ip_map_t map; ip_map_t *read_map; ipmap_init(&map, 0); GOutputStream *ostream = g_memory_output_stream_new(NULL, 0, g_realloc, g_free); GMemoryOutputStream *mostream = G_MEMORY_OUTPUT_STREAM(ostream); fail_unless(ipmap_save(ostream, &map, NULL), "Could not save map"); GInputStream *istream = g_memory_input_stream_new_from_data (g_memory_output_stream_get_data(mostream), g_memory_output_stream_get_data_size(mostream), NULL); read_map = ipmap_load(istream, NULL); fail_if(read_map == NULL, "Could not read map"); fail_unless(ipmap_is_equal(&map, read_map), "Map not same after saving/loading"); g_object_unref(ostream); g_object_unref(istream); ipmap_done(&map); ipmap_free(read_map); }
END_TEST START_TEST(test_store_empty) { ip_set_t set; ip_set_t *read_set; ipset_init(&set); GOutputStream *ostream = g_memory_output_stream_new(NULL, 0, g_realloc, g_free); GMemoryOutputStream *mostream = G_MEMORY_OUTPUT_STREAM(ostream); fail_unless(ipset_save(ostream, &set, NULL), "Could not save set"); GInputStream *istream = g_memory_input_stream_new_from_data (g_memory_output_stream_get_data(mostream), g_memory_output_stream_get_data_size(mostream), NULL); read_set = ipset_load(istream, NULL); fail_if(read_set == NULL, "Could not read set"); fail_unless(ipset_is_equal(&set, read_set), "Set not same after saving/loading"); g_object_unref(ostream); g_object_unref(istream); ipset_done(&set); ipset_free(read_set); }
static gboolean _cd_do_fill_bookmark_entry (CDEntry *pEntry) { if (pEntry->pIconSurface != NULL || pEntry->cIconName == NULL) return FALSE; gsize out_len = 0; //g_print ("icon : %s\n", pEntry->cIconName); guchar *icon = g_base64_decode (pEntry->cIconName, &out_len); //g_print ("-> out_len : %d\n", out_len); g_return_val_if_fail (icon != NULL, FALSE); //g_print ("-> data : %d\n", icon); GInputStream * is = g_memory_input_stream_new_from_data (icon, out_len, NULL); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream (is, NULL, NULL); g_object_unref (is); double fImageWidth=0, fImageHeight=0; double fZoomX=0, fZoomY=0; pEntry->pIconSurface = cairo_dock_create_surface_from_pixbuf (pixbuf, 1., myDialogsParam.dialogTextDescription.iSize, myDialogsParam.dialogTextDescription.iSize, 0, &fImageWidth, &fImageHeight, &fZoomX, &fZoomY); g_object_unref (pixbuf); g_free (icon); return TRUE; }
static GdkPixbuf* dn_data_url_to_pixbuf(const NPVariant *data_url) { GdkPixbuf *pixbuf = NULL; GInputStream *stream; gsize len; gchar *buffer, *data; GError *err = NULL; buffer = variant_to_string (data_url); if (buffer == NULL) return NULL; g_debug ("%s(\"%s\")", G_STRFUNC, buffer); if (!g_str_has_prefix (buffer, "data:image/png;base64,")) goto out; /* skip the mime type prefix */ data = buffer + 22; g_base64_decode_inplace (data, &len); stream = g_memory_input_stream_new_from_data (data, len, NULL); pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &err); if (err != NULL) { g_debug ("%s error: %s", G_STRFUNC, err->message); g_error_free (err); } out: g_free (buffer); return pixbuf; }
/** * g_resource_open_stream: * @resource: A #GResource * @path: A pathname inside the resource * @lookup_flags: A #GResourceLookupFlags * @error: return location for a #GError, or %NULL * * Looks for a file at the specified @path in the resource and * returns a #GInputStream that lets you read the data. * * @lookup_flags controls the behaviour of the lookup. * * Returns: (transfer full): #GInputStream or %NULL on error. * Free the returned object with g_object_unref() * * Since: 2.32 **/ GInputStream * g_resource_open_stream (GResource *resource, const gchar *path, GResourceLookupFlags lookup_flags, GError **error) { const void *data; gsize data_size; guint32 flags; GInputStream *stream, *stream2; if (!do_lookup (resource, path, lookup_flags, NULL, &flags, &data, &data_size, error)) return NULL; stream = g_memory_input_stream_new_from_data (data, data_size, NULL); g_object_set_data_full (G_OBJECT (stream), "g-resource", g_resource_ref (resource), (GDestroyNotify)g_resource_unref); if (flags & G_RESOURCE_FLAGS_COMPRESSED) { GZlibDecompressor *decompressor = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB); stream2 = g_converter_input_stream_new (stream, G_CONVERTER (decompressor)); g_object_unref (decompressor); g_object_unref (stream); stream = stream2; } return stream; }
/** * dbusmenu_menuitem_property_get_image: * @menuitem: The #DbusmenuMenuitem to look for the property on * @property: The name of the property to look for. * * This function looks on the menu item for a property by the * name of @property. If one exists it tries to turn it into * a #GdkPixbuf. It assumes that the property is a base64 encoded * PNG file like the one created by #dbusmenu_menuite_property_set_image. * * Return value: (transfer full): A pixbuf or #NULL to signal error. */ GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), NULL); g_return_val_if_fail(property != NULL && property[0] != '\0', NULL); gsize length = 0; const guchar * icondata = dbusmenu_menuitem_property_get_byte_array(menuitem, property, &length); /* There is no icon */ if (length == 0) { return NULL; } GInputStream * input = g_memory_input_stream_new_from_data(icondata, length, NULL); if (input == NULL) { g_warning("Cound not create input stream from icon property data"); return NULL; } GError * error = NULL; GdkPixbuf * icon = gdk_pixbuf_new_from_stream(input, NULL, &error); if (error != NULL) { g_warning("Unable to build Pixbuf from icon data: %s", error->message); g_error_free(error); } g_object_unref(input); return icon; }
void AudioFileReader::decodeAudioForBusCreation() { // Build the pipeline (giostreamsrc | filesrc) ! decodebin2 // A deinterleave element is added once a src pad becomes available in decodebin. m_pipeline = gst_pipeline_new(0); GRefPtr<GstBus> bus = webkitGstPipelineGetBus(GST_PIPELINE(m_pipeline)); ASSERT(bus); gst_bus_add_signal_watch(bus.get()); g_signal_connect(bus.get(), "message", G_CALLBACK(messageCallback), this); GstElement* source; if (m_data) { ASSERT(m_dataSize); source = gst_element_factory_make("giostreamsrc", 0); GRefPtr<GInputStream> memoryStream = adoptGRef(g_memory_input_stream_new_from_data(m_data, m_dataSize, 0)); g_object_set(source, "stream", memoryStream.get(), NULL); } else { source = gst_element_factory_make("filesrc", 0); g_object_set(source, "location", m_filePath, NULL); } m_decodebin = gst_element_factory_make(gDecodebinName, "decodebin"); g_signal_connect(m_decodebin.get(), "pad-added", G_CALLBACK(onGStreamerDecodebinPadAddedCallback), this); gst_bin_add_many(GST_BIN(m_pipeline), source, m_decodebin.get(), NULL); gst_element_link_pads_full(source, "src", m_decodebin.get(), "sink", GST_PAD_LINK_CHECK_NOTHING); gst_element_set_state(m_pipeline, GST_STATE_PAUSED); }
static GthImage * _libraw_read_jpeg_data (void *buffer, gsize buffer_size, int requested_size, GCancellable *cancellable, GError **error) { GthImageLoaderFunc loader_func; GInputStream *istream; GthImage *image; loader_func = gth_main_get_image_loader_func ("image/jpeg", GTH_IMAGE_FORMAT_CAIRO_SURFACE); if (loader_func == NULL) return NULL; istream = g_memory_input_stream_new_from_data (buffer, buffer_size, NULL); if (istream == NULL) return NULL; image = loader_func (istream, NULL, requested_size, NULL, NULL, NULL, cancellable, error); g_object_unref (istream); return image; }
static void aboutURISchemeRequestCallback(WebKitURISchemeRequest *request, gpointer userData) { GInputStream *stream; gsize streamLength; const gchar *path; gchar *contents; GError *error; path = webkit_uri_scheme_request_get_path(request); if (!g_strcmp0(path, "minibrowser")) { contents = g_strdup_printf("<html><body><h1>WebKitGTK+ MiniBrowser</h1><p>The WebKit2 test browser of the GTK+ port.</p><p>WebKit version: %d.%d.%d</p></body></html>", webkit_get_major_version(), webkit_get_minor_version(), webkit_get_micro_version()); streamLength = strlen(contents); stream = g_memory_input_stream_new_from_data(contents, streamLength, g_free); webkit_uri_scheme_request_finish(request, stream, streamLength, "text/html"); g_object_unref(stream); } else { error = g_error_new(MINI_BROWSER_ERROR, MINI_BROWSER_ERROR_INVALID_ABOUT_PATH, "Invalid about:%s page.", path); webkit_uri_scheme_request_finish_error(request, error); g_error_free(error); } }
GInputStream * uzbl_scheme_request_send (SoupRequest *request, GCancellable *cancellable, GError **error) { UZBL_UNUSED (cancellable); UZBL_UNUSED (error); UzblSchemeRequest *uzbl_request = UZBL_SCHEME_REQUEST (request); UzblSchemeRequestClass *cls = UZBL_SCHEME_REQUEST_GET_CLASS (uzbl_request); SoupURI *uri = soup_request_get_uri (request); const char *command = g_hash_table_lookup (cls->handlers, uri->scheme); GString *result = g_string_new (""); GArray *args = uzbl_commands_args_new (); const UzblCommand *cmd = uzbl_commands_parse (command, args); if (cmd) { uzbl_commands_args_append (args, soup_uri_to_string (uri, TRUE)); uzbl_commands_run_parsed (cmd, args, result); } uzbl_commands_args_free (args); gchar *end = strchr (result->str, '\n'); size_t line_len = end ? (size_t)(end - result->str) : result->len; uzbl_request->priv->content_length = result->len - line_len - 1; uzbl_request->priv->content_type = g_strndup (result->str, line_len); GInputStream *stream = g_memory_input_stream_new_from_data ( g_strdup (end + 1), uzbl_request->priv->content_length, g_free); g_string_free (result, TRUE); return stream; }
static void on_channel_dat_received (MexDownloadQueue *queue, const char *uri, const char *buffer, gsize count, const GError *dq_error, gpointer userdata) { MexEpgRadiotimes *provider = MEX_EPG_RADIOTIMES (userdata); MexEpgRadiotimesPrivate *priv = provider->priv; GInputStream *input; GDataInputStream *data; GError *error = NULL; gchar *line; MEX_NOTE (EPG, "received %s, size %"G_GSIZE_FORMAT, uri, count); if (dq_error) { g_warning ("Could not download %s: %s", uri, dq_error->message); return; } /* prepare channel2id hash table */ if (priv->channel2id) g_hash_table_unref (priv->channel2id); priv->channel2id = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); /* parse the date line by line */ input = g_memory_input_stream_new_from_data (buffer, count, NULL); data = g_data_input_stream_new (input); /* The first line is empty */ line = g_data_input_stream_read_line (data, NULL, NULL, &error); g_free (line); /* The second line is the disclamer*/ line = g_data_input_stream_read_line (data, NULL, NULL, &error); g_free (line); line = g_data_input_stream_read_line (data, NULL, NULL, &error); while (line) { parse_channels_dat_line (provider, line); g_free (line); line = g_data_input_stream_read_line (data, NULL, NULL, &error); } if (G_UNLIKELY (error)) { g_warning ("Could not read line: %s", error->message); g_clear_error (&error); } g_object_unref (data); g_object_unref (input); g_signal_emit_by_name (provider, "epg-provider-ready", 0); }
static jobject dnd_target_get_image(JNIEnv *env) { GdkPixbuf *buf; GInputStream *stream; jobject result = NULL; GdkAtom targets[] = { TARGET_MIME_PNG_ATOM, TARGET_MIME_JPEG_ATOM, TARGET_MIME_TIFF_ATOM, TARGET_MIME_BMP_ATOM, 0}; GdkAtom *cur_target = targets; selection_data_ctx ctx; while(*cur_target != 0 && result == NULL) { if (dnd_target_receive_data(env, *cur_target, &ctx)) { stream = g_memory_input_stream_new_from_data(ctx.data, ctx.length * (ctx.format / 8), (GDestroyNotify)g_free); buf = gdk_pixbuf_new_from_stream(stream, NULL, NULL); if (buf) { int w; int h; int stride; guchar *data; jbyteArray data_array; jobject buffer; if (!gdk_pixbuf_get_has_alpha(buf)) { GdkPixbuf *tmp_buf = gdk_pixbuf_add_alpha(buf, FALSE, 0, 0, 0); g_object_unref(buf); buf = tmp_buf; } w = gdk_pixbuf_get_width(buf); h = gdk_pixbuf_get_height(buf); stride = gdk_pixbuf_get_rowstride(buf); data = gdk_pixbuf_get_pixels(buf); //Actually, we are converting RGBA to BGRA, but that's the same operation data = (guchar*) convert_BGRA_to_RGBA((int*) data, stride, h); data_array = env->NewByteArray(stride * h); env->SetByteArrayRegion(data_array, 0, stride*h, (jbyte*) data); buffer = env->CallStaticObjectMethod(jByteBufferCls, jByteBufferWrap, data_array); result = env->NewObject(jGtkPixelsCls, jGtkPixelsInit, w, h, buffer); g_object_unref(buf); g_free(data); // data from convert_BGRA_to_RGBA } g_object_unref(stream); } ++cur_target; } return result; }
static gboolean webkit_data_src_uri_set_uri(GstURIHandler* handler, const gchar* uri) { WebkitDataSrc* src = WEBKIT_DATA_SRC(handler); // URI as defined in RFC2397: // "data:" [ mediatype ] [ ";base64" ] "," data // we parse URIs like this one: // data:audio/3gpp;base64,AA... gchar** scheme_and_remains = g_strsplit(uri, ":", 2); gchar** mime_type_and_options = g_strsplit(scheme_and_remains[1], ";", 0); gint options_size = g_strv_length(mime_type_and_options); gchar* data = 0; gchar* mime_type = 0; gint ret = FALSE; // we require uris with a specified mime-type and base64-encoded // data. It doesn't make much sense anyway to play plain/text data // with very few allowed characters (as per the RFC). if (GST_STATE(src) >= GST_STATE_PAUSED) { GST_ERROR_OBJECT(src, "Element already configured. Reset it and retry"); } else if (!options_size) GST_ERROR_OBJECT(src, "A mime-type is needed in %s", uri); else { mime_type = mime_type_and_options[0]; data = mime_type_and_options[options_size-1]; guchar* decoded_data = 0; gsize decoded_size; if (!g_str_has_prefix(data, "base64")) GST_ERROR_OBJECT(src, "Data has to be base64-encoded in %s", uri); else { decoded_data = g_base64_decode(data+7, &decoded_size); GInputStream* stream = g_memory_input_stream_new_from_data(decoded_data, decoded_size, g_free); g_object_set(src->kid, "stream", stream, NULL); g_object_unref(stream); if (src->uri) { g_free(src->uri); src->uri = 0; } src->uri = g_strdup(uri); ret = TRUE; } } g_strfreev(scheme_and_remains); g_strfreev(mime_type_and_options); return ret; }
static GthImage * facebook_thumbnail_loader (GInputStream *istream, GthFileData *file_data, int requested_size, int *original_width, int *original_height, gboolean *loaded_original, gpointer user_data, GCancellable *cancellable, GError **error) { GthImage *image = NULL; FacebookPhoto *photo; const char *uri; photo = (FacebookPhoto *) g_file_info_get_attribute_object (file_data->info, "facebook::object"); uri = facebook_photo_get_thumbnail_url (photo, requested_size); if (uri == NULL) uri = facebook_photo_get_original_url (photo); if (uri != NULL) { GFile *file; void *buffer; gsize size; file = g_file_new_for_uri (uri); if (_g_file_load_in_buffer (file, &buffer, &size, cancellable, error)) { GInputStream *stream; GdkPixbuf *pixbuf; stream = g_memory_input_stream_new_from_data (buffer, size, g_free); pixbuf = gdk_pixbuf_new_from_stream (stream, cancellable, error); if (pixbuf != NULL) { GdkPixbuf *rotated; rotated = gdk_pixbuf_apply_embedded_orientation (pixbuf); g_object_unref (pixbuf); pixbuf = rotated; image = gth_image_new_for_pixbuf (pixbuf); } g_object_unref (pixbuf); g_object_unref (stream); } g_object_unref (file); } else *error = g_error_new_literal (GTH_ERROR, 0, "cannot generate the thumbnail"); return image; }
static gboolean as_icon_node_parse_embedded (AsIcon *icon, GNode *n, GError **error) { AsIconPrivate *priv = GET_PRIVATE (icon); GNode *c; gsize size; g_autofree guchar *data = NULL; g_autoptr(GdkPixbuf) pixbuf = NULL; g_autoptr(GInputStream) stream = NULL; /* get the icon name */ c = as_node_find (n, "name"); if (c == NULL) { g_set_error_literal (error, AS_ICON_ERROR, AS_ICON_ERROR_FAILED, "embedded icons needs <name>"); return FALSE; } g_free (priv->name); priv->name = as_node_take_data (c); /* parse the Base64 data */ c = as_node_find (n, "filecontent"); if (c == NULL) { g_set_error_literal (error, AS_ICON_ERROR, AS_ICON_ERROR_FAILED, "embedded icons needs <filecontent>"); return FALSE; } data = g_base64_decode (as_node_get_data (c), &size); stream = g_memory_input_stream_new_from_data (data, (gssize) size, NULL); if (stream == NULL) { g_set_error_literal (error, AS_ICON_ERROR, AS_ICON_ERROR_FAILED, "failed to load embedded data"); return FALSE; } /* load the image */ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error); if (pixbuf == NULL) return FALSE; as_icon_set_pixbuf (icon, pixbuf); /* save the raw data */ if (priv->data != NULL) g_bytes_unref (priv->data); priv->data = g_bytes_new (data, size); return TRUE; }
GInputStream * ot_variant_read (GVariant *variant) { GMemoryInputStream *ret = NULL; ret = (GMemoryInputStream*)g_memory_input_stream_new_from_data (g_variant_get_data (variant), g_variant_get_size (variant), NULL); g_object_set_data_full ((GObject*)ret, "ot-variant-data", g_variant_ref (variant), (GDestroyNotify) g_variant_unref); return (GInputStream*)ret; }
// Supports data embedded in the URI itself // http://en.wikipedia.org/wiki/Data_URI_scheme // https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs static GInputStream * input_stream_datauri(const gchar *uri) { GInputStream *stream = NULL; gchar * raw_data = NULL; gint header_items_no = 0; gchar **header_items = datauri_parse_header(uri, &raw_data, &header_items_no); const gboolean is_base64 = header_items_no > 1 && g_strcmp0(header_items[1], "base64") == 0; if (is_base64) { gsize len = 0; guchar * data = g_base64_decode (raw_data, &len); stream = g_memory_input_stream_new_from_data (data, len, g_free); } else { gchar *data = g_strdup(raw_data); const gint len = strlen(data); stream = g_memory_input_stream_new_from_data (data, len, g_free); } g_strfreev(header_items); return stream; }
GSList *check_file_load(GSList *ud_list, GFile *file) { g_assert(file); char *data = NULL; gsize len = 0; GError *error = NULL; if (!g_file_load_contents(file, NULL, &data, &len, NULL, &error)) { check_file_error(file, error); g_error_free(error); return 0; } GInputStream *is = g_memory_input_stream_new_from_data(data, len, NULL); GDataInputStream *dis = g_data_input_stream_new(is); char *line = NULL; len = 0; error = NULL; while ((line = g_data_input_stream_read_line_utf8(dis, &len, NULL, &error))) { enum hash_func_e id = HASH_FUNC_INVALID; char *filename = NULL; char *digest = NULL; if ((len >= 8) && check_file_parse_line(line, &id, &filename, &digest)) { if (HASH_FUNC_IS_VALID(id)) gui_enable_hash_func(id); ud_list = check_file_add_uri(ud_list, file, filename, digest); } g_free(line); } if (error) { check_file_error(file, error); g_error_free(error); } else check_file_enable_hinted_hash_func(file); g_object_unref(dis); g_object_unref(is); g_free(data); return ud_list; }
void create_status_icon() { GError *error = NULL; GInputStream *stream = g_memory_input_stream_new_from_data(icon, iconSize, NULL); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream(stream, NULL, &error); if (error) fprintf(stderr, "Unable to create PixBuf: %s\n", error->message); GtkStatusIcon *tray_icon = gtk_status_icon_new_from_pixbuf(pixbuf); g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL); gtk_status_icon_set_tooltip_text(tray_icon, menu_title); gtk_status_icon_set_visible(tray_icon, TRUE); }
/** * ctpl_input_stream_new_for_memory: * @data: Data for which create the stream * @length: length of @data * @destroy: #GDestroyNotify to call on @data when finished, or %NULL * @name: The name of the stream to identify it in error messages * * Creates a new #CtplInputStream for in-memory data. This is a wrapper around * #GMemoryInputStream; see ctpl_input_stream_new(). * * Returns: A new #CtplInputStream for the given data * * Since: 0.2 */ CtplInputStream * ctpl_input_stream_new_for_memory (const gchar *data, gssize length, GDestroyNotify destroy, const gchar *name) { GInputStream *gstream; CtplInputStream *stream; gstream = g_memory_input_stream_new_from_data (data, length, destroy); stream = ctpl_input_stream_new (gstream, name); g_object_unref (gstream); return stream; }
gboolean ostree_raw_file_to_content_stream (GInputStream *input, GFileInfo *file_info, GVariant *xattrs, GInputStream **out_input, guint64 *out_length, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gpointer header_data; gsize header_size; ot_lobj GInputStream *ret_input = NULL; ot_lvariant GVariant *file_header = NULL; ot_lptrarray GPtrArray *streams = NULL; ot_lobj GOutputStream *header_out_stream = NULL; ot_lobj GInputStream *header_in_stream = NULL; file_header = ostree_file_header_new (file_info, xattrs); header_out_stream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); if (!ostree_write_variant_with_size (header_out_stream, file_header, 0, NULL, NULL, cancellable, error)) goto out; if (!g_output_stream_close (header_out_stream, cancellable, error)) goto out; header_size = g_memory_output_stream_get_data_size ((GMemoryOutputStream*) header_out_stream); header_data = g_memory_output_stream_steal_data ((GMemoryOutputStream*) header_out_stream); header_in_stream = g_memory_input_stream_new_from_data (header_data, header_size, g_free); streams = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); g_ptr_array_add (streams, g_object_ref (header_in_stream)); if (input) g_ptr_array_add (streams, g_object_ref (input)); ret_input = (GInputStream*)ostree_chain_input_stream_new (streams); ret = TRUE; ot_transfer_out_value (out_input, &ret_input); if (out_length) *out_length = header_size + g_file_info_get_size (file_info); out: return ret; }
static GtkStatusIcon *create_tray_icon(unsigned char *imageData, unsigned int imageDataLen) { GtkStatusIcon *tray_icon; GError *error = NULL; GInputStream *stream = g_memory_input_stream_new_from_data(imageData, imageDataLen, NULL); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream(stream, NULL, &error); if (error) fprintf(stderr, "Unable to create PixBuf: %s\n", error->message); tray_icon = gtk_status_icon_new_from_pixbuf(pixbuf); g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(handle_open), NULL); g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(tray_icon_on_menu), NULL); gtk_status_icon_set_tooltip_text(tray_icon, menu_title); gtk_status_icon_set_visible(tray_icon, TRUE); return tray_icon; }
/*! \brief Set a picture object's contents from a buffer. * \par Function Description * Sets the contents of the picture \a object by reading image data * from a buffer. The buffer should be in on-disk format. * * \param toplevel The current #TOPLEVEL. * \param object The picture #OBJECT to modify. * \param filename The new filename for the picture. * \param data The new image data buffer. * \param len The size of the data buffer. * \param error Location to return error information. * \return TRUE on success, FALSE on failure. */ gboolean o_picture_set_from_buffer (TOPLEVEL *toplevel, OBJECT *object, const gchar *filename, const gchar *data, size_t len, GError **error) { GdkPixbuf *pixbuf; GInputStream *stream; gchar *tmp; g_return_val_if_fail (toplevel != NULL, FALSE); g_return_val_if_fail (object != NULL, FALSE); g_return_val_if_fail (object->picture != NULL, FALSE); g_return_val_if_fail (data != NULL, FALSE); /* Check that we can actually load the data before making any * changes to the object. */ stream = G_INPUT_STREAM (g_memory_input_stream_new_from_data (data, len, NULL)); pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error); g_object_unref (stream); if (pixbuf == NULL) return FALSE; o_emit_pre_change_notify (toplevel, object); if (object->picture->pixbuf != NULL) { g_object_unref (object->picture->pixbuf); } object->picture->pixbuf = pixbuf; object->picture->ratio = ((double) gdk_pixbuf_get_width(pixbuf) / gdk_pixbuf_get_height(pixbuf)); tmp = g_strdup (filename); g_free (object->picture->filename); object->picture->filename = tmp; gchar *buf = (gchar*) g_realloc (object->picture->file_content, len); /* It's possible that these buffers might overlap, because the * library user hates us. */ memmove (buf, data, len); object->picture->file_content = buf; object->picture->file_length = len; o_emit_change_notify (toplevel, object); return TRUE; }
gboolean tmpl_template_parse_string (TmplTemplate *self, const gchar *str, GError **error) { GInputStream *stream; gboolean ret; g_return_val_if_fail (TMPL_IS_TEMPLATE (self), FALSE); g_return_val_if_fail (str, FALSE); stream = g_memory_input_stream_new_from_data (g_strdup (str), strlen (str), g_free); ret = tmpl_template_parse (self, stream, NULL, error); g_object_unref (stream); return ret; }