GdkPixbuf* hybrid_create_pixbuf(const guchar *pixbuf_data, gint pixbuf_len) { GdkPixbufLoader *loader; GdkPixbuf *pixbuf; guchar *default_pixbuf_data; gsize default_pixbuf_size; loader = gdk_pixbuf_loader_new(); if (!pixbuf_data || pixbuf_len == 0) { /**< Load the default. */ g_file_get_contents(PIXMAPS_DIR"icons/icon.png", (gchar**)&default_pixbuf_data, &default_pixbuf_size, NULL); gdk_pixbuf_loader_write(loader, default_pixbuf_data, default_pixbuf_size, NULL); g_free(default_pixbuf_data); } else { gdk_pixbuf_loader_write(loader, pixbuf_data, pixbuf_len, NULL); } gdk_pixbuf_loader_close(loader, NULL); pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); if (pixbuf) { g_object_ref(loader); } g_object_unref(loader); return pixbuf; }
// FIXME: More refactor this function. static GdkPixbuf* pixbuf_from_url_impl(const char* ctype, const MEMFILE* raw, GError** error) { GdkPixbuf* pixbuf = NULL; #ifdef _WIN32 if (ctype && (!strcmp(ctype, "image/jpeg") || !strcmp(ctype, "image/gif"))) { char temp_path[MAX_PATH]; char temp_filename[MAX_PATH]; GetTempPath(sizeof(temp_path), temp_path); GetTempFileName(temp_path, "growl-for-linux-", 0, temp_filename); FILE* const fp = fopen(temp_filename, "wb"); if (fp) { fwrite(memfdata(raw), memfsize(raw), 1, fp); fclose(fp); } pixbuf = gdk_pixbuf_new_from_file(temp_filename, NULL); DeleteFile(temp_filename); } else #endif { GError* _error = NULL; GdkPixbufLoader* const loader = ctype ? gdk_pixbuf_loader_new_with_mime_type(ctype, &_error) : gdk_pixbuf_loader_new(); if (!gerror_set_or_free(error, _error)) { if (gdk_pixbuf_loader_write(loader, (const guchar*) memfcdata(raw), memfsize(raw), &_error)) pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); else gerror_set_or_free(error, _error); gdk_pixbuf_loader_close(loader, NULL); } } return pixbuf; }
static GdkPixbuf * data_to_pixbuf (const GValue *cvalue) { GdkPixbuf *retpixbuf = NULL; if (G_VALUE_TYPE (cvalue) == GDA_TYPE_BINARY) { const GdaBinary *bin; GdkPixbufLoader *loader; bin = gda_value_get_binary (cvalue); if (!bin->data) goto out; loader = gdk_pixbuf_loader_new (); if (gdk_pixbuf_loader_write (loader, bin->data, bin->binary_length, NULL)) { if (gdk_pixbuf_loader_close (loader, NULL)) { retpixbuf = gdk_pixbuf_loader_get_pixbuf (loader); g_object_ref (retpixbuf); } else gdk_pixbuf_loader_close (loader, NULL); } else gdk_pixbuf_loader_close (loader, NULL); g_object_unref (loader); } out: return retpixbuf; }
GdkPixbuf *o_picture_pixbuf_from_buffer (gchar *file_content, gsize file_length, GError **err) { GdkPixbufLoader *loader; GdkPixbuf *pixbuf; loader = gdk_pixbuf_loader_new(); gdk_pixbuf_loader_write (loader, (guchar *)file_content, file_length, err); if (err != NULL && *err != NULL) return NULL; gdk_pixbuf_loader_close (loader, err); if (err != NULL && *err != NULL) return NULL; pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf != NULL) g_object_ref (pixbuf); g_object_unref (loader); return pixbuf; }
static GdkPixbuf * gst_thumbnailer_buffer_to_pixbuf (GstBuffer *buffer) { GstMapInfo info; GdkPixbuf *pixbuf = NULL; GdkPixbufLoader *loader; if (!gst_buffer_map (buffer, &info, GST_MAP_READ)) return NULL; loader = gdk_pixbuf_loader_new (); if (gdk_pixbuf_loader_write (loader, info.data, info.size, NULL) && gdk_pixbuf_loader_close (loader, NULL)) { pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf != NULL) g_object_ref (pixbuf); } g_object_unref (loader); gst_buffer_unmap (buffer, &info); return pixbuf; }
/** * gtk_selection_data_get_pixbuf: * @selection_data: a #GtkSelectionData * * Gets the contents of the selection data as a #GdkPixbuf. * * Returns: (nullable) (transfer full): if the selection data * contained a recognized image type and it could be converted to a * #GdkPixbuf, a newly allocated pixbuf is returned, otherwise * %NULL. If the result is non-%NULL it must be freed with * g_object_unref(). **/ GdkPixbuf * gtk_selection_data_get_pixbuf (const GtkSelectionData *selection_data) { GdkPixbufLoader *loader; GdkPixbuf *result = NULL; g_return_val_if_fail (selection_data != NULL, NULL); if (selection_data->length > 0) { loader = gdk_pixbuf_loader_new (); gdk_pixbuf_loader_write (loader, selection_data->data, selection_data->length, NULL); gdk_pixbuf_loader_close (loader, NULL); result = gdk_pixbuf_loader_get_pixbuf (loader); if (result) g_object_ref (result); g_object_unref (loader); } return result; }
static GdkPixbuf * avatar_create_pixbuf (TwituxAvatar *avatar, gint size) { GdkPixbuf *tmp_pixbuf; GdkPixbuf *ret_pixbuf; GdkPixbufLoader *loader; GError *error = NULL; int orig_width; int orig_height; int scale_width; int scale_height; if (!avatar) { return NULL; } loader = gdk_pixbuf_loader_new (); if (!gdk_pixbuf_loader_write (loader, avatar->data, avatar->len, &error)) { g_warning ("Couldn't write avatar image: %p with " "length: %" G_GSIZE_FORMAT " to pixbuf loader: %s", avatar->data, avatar->len, error->message); g_error_free (error); return NULL; } gdk_pixbuf_loader_close (loader, NULL); tmp_pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); scale_width = orig_width = gdk_pixbuf_get_width (tmp_pixbuf); scale_height = orig_height = gdk_pixbuf_get_height (tmp_pixbuf); if (scale_height > scale_width) { scale_width = (gdouble) size * (gdouble) scale_width / (double) scale_height; scale_height = size; } else { scale_height = (gdouble) size * (gdouble) scale_height / (gdouble) scale_width; scale_width = size; } ret_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 32, 32); gdk_pixbuf_fill (ret_pixbuf, 0x00000000); gdk_pixbuf_scale (tmp_pixbuf, ret_pixbuf, (size - scale_width)/2, (size - scale_height)/2, scale_width, scale_height, (size - scale_width)/2, (size - scale_height)/2, (double)scale_width/(double)orig_width, (double)scale_height/(double)orig_height, GDK_INTERP_BILINEAR); if (avatar_pixbuf_is_opaque (ret_pixbuf)) { avatar_pixbuf_roundify (ret_pixbuf); } g_object_unref (loader); return ret_pixbuf; }
static GdkPixbuf* decode_image (const char *val) { int i; GError *error = NULL; GdkPixbuf *res = NULL; struct { const char *prefix; const char *mime_type; } formats[] = { { "data:image/x-icon;base64,", "image/x-icon" }, { "data:image/png;base64,", "image/png" } }; g_return_val_if_fail (val, NULL); for (i = 0; i < G_N_ELEMENTS (formats); i++) { if (g_str_has_prefix (val, formats[i].prefix)) { gsize len; guchar *data = NULL; char *unescaped; unescaped = g_uri_unescape_string (val + strlen (formats[i].prefix), NULL); if (unescaped) { data = g_base64_decode (unescaped, &len); g_free (unescaped); } if (data) { GdkPixbufLoader *loader; loader = gdk_pixbuf_loader_new_with_mime_type (formats[i].mime_type, &error); if (loader && gdk_pixbuf_loader_write (loader, data, len, &error) && gdk_pixbuf_loader_close (loader, &error)) { res = gdk_pixbuf_loader_get_pixbuf (loader); g_object_ref (res); } g_object_unref (loader); g_free (data); } } } if (!res) { if (error) { g_warning ("%s\n", error->message); g_error_free (error); } else g_warning ("incorrect data uri"); } return res; }
static void extract_zip_file_into_loader(GdkPixbufLoader * loader, const char *archname, const char *archpath) { if (loader == NULL) return; ZZIP_DIR *dir = zzip_dir_open(archname, 0); ZZIP_FILE *fp = zzip_file_open(dir, archpath, 0); if (fp) { guchar buf[ZIPBUFSIZE]; GError *error = NULL; zzip_ssize_t len; while ((len = zzip_file_read(fp, buf, ZIPBUFSIZE))) { gdk_pixbuf_loader_write(loader, buf, len, &error); if (error != NULL) { g_warning("load image in zip failed: %s\n", error->message); g_error_free(error); zzip_dir_close(dir); return; } } zzip_file_close(fp); } zzip_dir_close(dir); }
/* Read count_bytes from the channel and write them to the loader. * Returns number of bytes written. * count_bytes = G_MAXSIZE means read as many bytes as possible. */ static gsize loader_write_from_channel (GdkPixbufLoader *loader, GIOChannel *channel, gsize count_bytes) { guchar* buffer; gsize bytes_read; GIOStatus read_status; if(count_bytes < G_MAXSIZE) { /* read no more than 'count_bytes' bytes */ buffer = g_malloc(count_bytes); read_status = g_io_channel_read_chars (channel, (gchar*) buffer, count_bytes, &bytes_read, NULL); } else { /*read up to end */ read_status = g_io_channel_read_to_end (channel, (gchar**) &buffer, &bytes_read, NULL); } if ((read_status != G_IO_STATUS_NORMAL) && (read_status != G_IO_STATUS_EOF)) g_assert_not_reached (); if (!gdk_pixbuf_loader_write(loader, buffer, bytes_read, NULL)) g_assert_not_reached (); g_free (buffer); return bytes_read; }
static GdkPixbuf * get_icon_from_message (SoupMessage *msg, GetIconURLData *data, GError **error) { GdkPixbufLoader *loader; GdkPixbuf *pixbuf; loader = gdk_pixbuf_loader_new_with_mime_type (data->mime_type, error); if (loader == NULL) return NULL; gdk_pixbuf_loader_write (loader, (guchar *) msg->response_body->data, msg->response_body->length, error); pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf) { gfloat aspect_ratio; gint height; /* Preserve the aspect-ratio of the original image */ aspect_ratio = (gfloat) data->width / data->height; height = (gint) (PREFERED_WIDTH / aspect_ratio); pixbuf = gdk_pixbuf_scale_simple (pixbuf, PREFERED_WIDTH, height, GDK_INTERP_HYPER); } gdk_pixbuf_loader_close (loader, NULL); g_object_unref (loader); return pixbuf; }
static GdkPixbuf * totem_gst_buffer_to_pixbuf (GstBuffer *buffer) { GdkPixbufLoader *loader; GdkPixbuf *pixbuf = NULL; GError *err = NULL; GstMapInfo info; if (!gst_buffer_map (buffer, &info, GST_MAP_READ)) { GST_WARNING("could not map memory buffer"); return NULL; } loader = gdk_pixbuf_loader_new (); if (gdk_pixbuf_loader_write (loader, info.data, info.size, &err) && gdk_pixbuf_loader_close (loader, &err)) { pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf) g_object_ref (pixbuf); } else { GST_WARNING("could not convert tag image to pixbuf: %s", err->message); g_error_free (err); } g_object_unref (loader); gst_buffer_unmap (buffer, &info); return pixbuf; }
static void mem_test (const gchar *bytes, gsize len) { gboolean did_fail = FALSE; GError *err = NULL; GdkPixbufLoader *loader; GList *loaders = NULL; GList *i; do { loader = gdk_pixbuf_loader_new (); gdk_pixbuf_loader_write (loader, (guchar *) bytes, len, &err); if (err) { g_error_free (err); err = NULL; did_fail = TRUE; } gdk_pixbuf_loader_close (loader, &err); if (err) { g_error_free (err); err = NULL; did_fail = TRUE; } loaders = g_list_prepend (loaders, loader); } while (!did_fail); for (i = loaders; i != NULL; i = i->next) g_object_unref (i->data); g_list_free (loaders); }
static GdkPixbuf * pixbuf_from_buddy_icon (PurpleBuddyIcon *buddy_icon) { GdkPixbuf *icon; const guchar *data; size_t len; GdkPixbufLoader *loader; data = purple_buddy_icon_get_data (buddy_icon, &len); loader = gdk_pixbuf_loader_new (); gdk_pixbuf_loader_set_size (loader, 48, 48); gdk_pixbuf_loader_write (loader, data, len, NULL); gdk_pixbuf_loader_close (loader, NULL); icon = gdk_pixbuf_loader_get_pixbuf (loader); if (icon) { g_object_ref (icon); } g_object_unref (loader); return icon; }
void tray_icon_set_image_from_data(void *icon, const char *data, unsigned long size) { GdkPixbufLoader *loader; GdkPixbufAnimation *animation; gboolean rc; TrayIcon *ticon; if (icon == NULL) return; ticon = (TrayIcon *) icon; loader=gdk_pixbuf_loader_new(); rc = gdk_pixbuf_loader_write (loader, (const guchar *)data, (gsize) size,NULL); gdk_pixbuf_loader_close (loader,NULL); if(rc) { // get animation animation=gdk_pixbuf_loader_get_animation(loader); gtk_image_set_from_animation (GTK_IMAGE (ticon->image),animation); } }
static gint update_timeout(gpointer data) { ProgressFileStatus *status = data; gboolean done; done = TRUE; if (!feof(status->imagefile)) { gint nbytes; nbytes = fread(status->buf, 1, status->readlen, status->imagefile); done = !gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (status->loader), status->buf, nbytes); } if (done) { gtk_widget_queue_draw(*status->rgbwin); gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (status->loader)); gtk_object_destroy (GTK_OBJECT(status->loader)); fclose (status->imagefile); g_free (status->buf); } return !done; }
static GdkPixbuf *make_scaled_pixbuf(const guchar * url_text, gsize len) { /* make pixbuf */ GdkPixbufLoader *loader; GdkPixbuf *src = NULL, *dest = NULL; g_return_val_if_fail(url_text != NULL, NULL); g_return_val_if_fail(len > 0, NULL); loader = gdk_pixbuf_loader_new(); gdk_pixbuf_loader_write(loader, url_text, len, NULL); gdk_pixbuf_loader_close(loader, NULL); src = gdk_pixbuf_loader_get_pixbuf(loader); if (src) { dest = gdk_pixbuf_scale_simple(src, purple_prefs_get_int(TWITTER_PREF_CONV_ICON_SIZE), purple_prefs_get_int(TWITTER_PREF_CONV_ICON_SIZE), GDK_INTERP_HYPER); } else { dest = NULL; } g_object_unref(G_OBJECT(loader)); return dest; }
GdkPixbufAnimation* load_animation_from_stream(GInputStream* input_stream, GCancellable* generator_cancellable) { GError** error = NULL; gboolean res = TRUE; gssize n_read = 0; guchar buffer[65535]; GdkPixbufAnimation* animation = NULL; GdkPixbufLoader* loader = NULL; loader = gdk_pixbuf_loader_new(); while (1) { n_read = g_input_stream_read (input_stream, buffer, sizeof (buffer), generator_cancellable, error); if (n_read < 0) { res = FALSE; error = NULL; break; return NULL; } if (n_read == 0) { break; } if (!gdk_pixbuf_loader_write (loader, buffer, n_read, error)) { res = FALSE; error = NULL; break; } } animation = NULL; if (res) { animation = gdk_pixbuf_loader_get_animation(loader); if (animation) { g_object_ref (animation); } } if (!gdk_pixbuf_loader_close (loader, error)) { res = FALSE; error = NULL; g_object_unref (loader); return; } return animation; }
static size_t nsp_feed_download_icon_cb (char *buffer, size_t size, size_t nitems, void *data) { GdkPixbufLoader *loader = (GdkPixbufLoader *) data; if (gdk_pixbuf_loader_write (loader, (guchar *) buffer, size * nitems, NULL)) return size * nitems; return 0; }
GdkPixbuf * eel_gdk_pixbuf_load_from_stream_at_size (GInputStream *stream, int size) { char buffer[LOAD_BUFFER_SIZE]; gssize bytes_read; GdkPixbufLoader *loader; GdkPixbuf *pixbuf; gboolean got_eos; g_return_val_if_fail (stream != NULL, NULL); got_eos = FALSE; loader = gdk_pixbuf_loader_new (); if (size > 0) { g_signal_connect (loader, "size-prepared", G_CALLBACK (pixbuf_loader_size_prepared), GINT_TO_POINTER (size)); } while (1) { bytes_read = g_input_stream_read (stream, buffer, sizeof (buffer), NULL, NULL); if (bytes_read < 0) { break; } if (bytes_read == 0) { got_eos = TRUE; break; } if (!gdk_pixbuf_loader_write (loader, buffer, bytes_read, NULL)) { break; } } g_input_stream_close (stream, NULL, NULL); gdk_pixbuf_loader_close (loader, NULL); pixbuf = NULL; if (got_eos) { pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf != NULL) { g_object_ref (pixbuf); } } g_object_unref (loader); return pixbuf; }
GdkPixbuf * hito_vcard_get_photo_pixbuf (EVCard *card) { GdkPixbuf *ret; GList *list = NULL; list = hito_vcard_get_named_attributes (card, EVC_PHOTO); if (list) { GdkPixbufLoader *ploader; guchar *buf; gsize size; const gchar *value; gchar *type, *type_up; int cmp = 0; value = e_vcard_attribute_get_value ((EVCardAttribute *)list->data); if (!value) { g_list_free (list); return NULL; } type = hito_vcard_attribute_get_type (list->data); if (type) { type_up = g_ascii_strup (type, -1); cmp = strcmp (type_up, "URL"); g_free (type); g_free (type_up); /* TODO: we can't deal with images from URLs yet */ if (!cmp) { g_list_free (list); return NULL; } } buf = g_base64_decode (value, &size); ploader = gdk_pixbuf_loader_new (); g_signal_connect (G_OBJECT (ploader), "size-prepared", G_CALLBACK (contact_photo_size), NULL); gdk_pixbuf_loader_write (ploader, buf, size, NULL); gdk_pixbuf_loader_close (ploader, NULL); ret = g_object_ref (gdk_pixbuf_loader_get_pixbuf (ploader)); g_object_unref (ploader); g_list_free (list); return ret; } else { return NULL; } }
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; }
static gssize tny_gtk_pixbuf_stream_write_default (TnyStream *self, const char *buffer, gsize n) { TnyGtkPixbufStreamPriv *priv = TNY_GTK_PIXBUF_STREAM_GET_PRIVATE (self); gssize wr = (gssize) n; if (!gdk_pixbuf_loader_write (priv->loader, (const guchar *) buffer, n, NULL)) wr = -1; return (gssize) wr; }
static GstFlowReturn gst_gdk_pixbuf_chain (GstPad * pad, GstBuffer * buf) { GstGdkPixbuf *filter; GstFlowReturn ret = GST_FLOW_OK; GError *error = NULL; GstClockTime timestamp; guint8 *data; guint size; filter = GST_GDK_PIXBUF (gst_pad_get_parent (pad)); timestamp = GST_BUFFER_TIMESTAMP (buf); if (GST_CLOCK_TIME_IS_VALID (timestamp)) filter->last_timestamp = timestamp; GST_LOG_OBJECT (filter, "buffer with ts: %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp)); if (filter->pixbuf_loader == NULL) filter->pixbuf_loader = gdk_pixbuf_loader_new (); data = GST_BUFFER_DATA (buf); size = GST_BUFFER_SIZE (buf); GST_LOG_OBJECT (filter, "Writing buffer size %d", size); if (!gdk_pixbuf_loader_write (filter->pixbuf_loader, data, size, &error)) goto error; /* packetised mode? */ if (filter->framerate_numerator != 0) { gdk_pixbuf_loader_close (filter->pixbuf_loader, NULL); ret = gst_gdk_pixbuf_flush (filter); g_object_unref (filter->pixbuf_loader); filter->pixbuf_loader = NULL; } gst_buffer_unref (buf); gst_object_unref (filter); return ret; /* ERRORS */ error: { GST_ELEMENT_ERROR (filter, STREAM, DECODE, (NULL), ("gdk_pixbuf_loader_write error: %s", error->message)); g_error_free (error); gst_buffer_unref (buf); gst_object_unref (filter); return GST_FLOW_ERROR; } }
static GstFlowReturn gst_gdk_pixbuf_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) { GstGdkPixbufDec *filter; GstFlowReturn ret = GST_FLOW_OK; GError *error = NULL; GstClockTime timestamp; GstMapInfo map; filter = GST_GDK_PIXBUF_DEC (parent); timestamp = GST_BUFFER_TIMESTAMP (buf); if (GST_CLOCK_TIME_IS_VALID (timestamp)) filter->last_timestamp = timestamp; GST_LOG_OBJECT (filter, "buffer with ts: %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp)); if (filter->pixbuf_loader == NULL) filter->pixbuf_loader = gdk_pixbuf_loader_new (); gst_buffer_map (buf, &map, GST_MAP_READ); GST_LOG_OBJECT (filter, "Writing buffer size %d", (gint) map.size); if (!gdk_pixbuf_loader_write (filter->pixbuf_loader, map.data, map.size, &error)) goto error; /* packetised mode? *//* FIXME: shouln't this be fps_d != 0, since 0/1 * might be packetised mode but variable framerate */ if (filter->in_fps_n != 0) { gdk_pixbuf_loader_close (filter->pixbuf_loader, NULL); ret = gst_gdk_pixbuf_dec_flush (filter); g_object_unref (filter->pixbuf_loader); filter->pixbuf_loader = NULL; } gst_buffer_unmap (buf, &map); gst_buffer_unref (buf); return ret; /* ERRORS */ error: { GST_ELEMENT_ERROR (filter, STREAM, DECODE, (NULL), ("gdk_pixbuf_loader_write error: %s", error->message)); g_error_free (error); gst_buffer_unmap (buf, &map); gst_buffer_unref (buf); return GST_FLOW_ERROR; } }
static GdkPixbuf * load_from_stream (GdkPixbufLoader *loader, GInputStream *stream, int requested_size, GCancellable *cancellable, GError **error) { GdkPixbuf *pixbuf; gssize n_read; guchar buffer[LOAD_BUFFER_SIZE]; gboolean res; res = TRUE; while (1) { n_read = g_input_stream_read (stream, buffer, sizeof (buffer), cancellable, error); if (n_read < 0) { res = FALSE; error = NULL; /* Ignore further errors */ break; } if (n_read == 0) break; if (! gdk_pixbuf_loader_write (loader, buffer, n_read, error)) { res = FALSE; error = NULL; break; } } if (! gdk_pixbuf_loader_close (loader, error)) { res = FALSE; error = NULL; } pixbuf = NULL; if (res) { pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf) g_object_ref (pixbuf); } return pixbuf; }
GdkPixbuf * XAP_UnixDialog_FileOpenSaveAs::pixbufForByteBuf (UT_ByteBuf * pBB) { 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 ( FALSE== 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)); return NULL ; } gdk_pixbuf_loader_close (ldr, NULL); pixbuf = gdk_pixbuf_loader_get_pixbuf (ldr); // ref before closing the loader if ( pixbuf ) g_object_ref (G_OBJECT(pixbuf)); g_object_unref (G_OBJECT(ldr)); } return pixbuf; }
static VALUE loader_write(VALUE self, VALUE data) { GError *error = NULL; gboolean res; res = gdk_pixbuf_loader_write(_SELF(self), (const guchar*)RVAL2CSTR(data), RSTRING_LEN(data), &error); if (error) RAISE_GERROR(error); return CBOOL2RVAL(res); }
/* Read skin image (pure jpeg data) */ int skin_read_image(SKIN_INFOS *si, FILE *fp, GError **err) { GdkPixbufLoader *loader; gboolean result; guchar *buf; gsize count; struct stat st; // Extract image from skin fseek(fp, si->jpeg_offset, SEEK_SET); fstat(fileno(fp), &st); count = st.st_size - si->jpeg_offset; buf = g_malloc(count * sizeof(guchar)); count = fread(buf, sizeof(guchar), count, fp); // Feed the pixbuf loader with our jpeg data loader = gdk_pixbuf_loader_new(); result = gdk_pixbuf_loader_write(loader, buf, count, err); g_free(buf); if(result == FALSE) { g_object_unref(loader); return -1; } result = gdk_pixbuf_loader_close(loader, err); if(result == FALSE) { g_object_unref(loader); return -1; } // and get the pixbuf si->raw = gdk_pixbuf_loader_get_pixbuf(loader); if(si->raw == NULL) { g_set_error(err, SKIN_ERROR, SKIN_ERROR_INVALID, _("Unable to load background image")); g_object_unref(loader); return -1; } si->sx = si->sy = 1.0; si->image = g_object_ref(si->raw); g_object_ref(si->raw); // Get new skin size si->width = gdk_pixbuf_get_width(si->image); si->height = gdk_pixbuf_get_height(si->image); g_object_unref(loader); return 0; }
void moko_contacts_get_photo (MokoContacts *contacts, MokoContact *m_contact) { MokoContactsPrivate *priv; EContact *e_contact; EContactPhoto *photo; GError *err = NULL; GdkPixbufLoader *loader; g_return_if_fail (MOKO_IS_CONTACTS (contacts)); g_return_if_fail (m_contact); priv = contacts->priv; if (!e_book_get_contact (priv->book, m_contact->uid, &e_contact, &err)) { g_warning ("%s\n", err->message); m_contact->photo = gdk_pixbuf_new_from_file (PKGDATADIR"/person.png", NULL); if (m_contact->photo) g_object_ref (m_contact->photo); return; } photo = e_contact_get (e_contact, E_CONTACT_PHOTO); if (!photo) { m_contact->photo = gdk_pixbuf_new_from_file (PKGDATADIR"/person.png", NULL); if (m_contact->photo) g_object_ref (m_contact->photo); return; } loader = gdk_pixbuf_loader_new (); gdk_pixbuf_loader_write (loader, photo->data.inlined.data, photo->data.inlined.length, NULL); gdk_pixbuf_loader_close (loader, NULL); m_contact->photo = gdk_pixbuf_loader_get_pixbuf (loader); if (GDK_IS_PIXBUF (m_contact->photo)) g_object_ref (m_contact->photo); else { m_contact->photo = gdk_pixbuf_new_from_file (PKGDATADIR"/person.png", NULL); if (m_contact->photo) g_object_ref (m_contact->photo); } g_object_unref (loader); e_contact_photo_free (photo); }