예제 #1
0
/* Image Data in Memory */
static VALUE
initialize_loader(int argc, VALUE *argv, VALUE self)
{
    GdkPixbufLoader* loader;
    GError* error = NULL;
    VALUE arg1, is_mime_type;

    rb_scan_args(argc, argv, "02", &arg1, &is_mime_type);

    if (NIL_P(arg1)) {
        loader = gdk_pixbuf_loader_new();
    } else {
        if (is_mime_type == Qtrue) {
#if RBGDK_PIXBUF_CHECK_VERSION(2,4,0)
            loader = gdk_pixbuf_loader_new_with_mime_type(RVAL2CSTR(arg1), &error);
#else
            rb_warning("Not supported GTK+-2.0/2.2.");
            loader = gdk_pixbuf_loader_new();
#endif
        } else {
            /* Default behavior */
            loader = gdk_pixbuf_loader_new_with_type(RVAL2CSTR(arg1), &error);
        }
        if(error) RAISE_GERROR(error);
    }
    
    G_INITIALIZE(self, loader);
    return Qnil;
}
예제 #2
0
// 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;
}
예제 #3
0
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;
}
예제 #4
0
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;
}
예제 #5
0
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);
	} 
	
}
예제 #6
0
static void
test_area_updated_anim (gconstpointer data)
{
    const char *filename;
    GIOChannel *channel;
    GdkPixbufLoader *loader;

    filename = g_test_get_filename (G_TEST_DIST, data, NULL);

    channel = g_io_channel_new_file (filename, "r", NULL);
    g_assert_nonnull (channel);
    g_io_channel_set_encoding(channel, NULL, NULL);
    /*create loader */
    loader = gdk_pixbuf_loader_new ();
    g_assert_nonnull (loader);

    g_signal_connect (loader, "area-prepared",
                      (GCallback) callback_area_prepared_anim, NULL);
    /* other callbacks will be registered inside callback_area_prepared_anim */

    /*read animation by portions of bytes */
#if 0
    while(loader_write_from_channel(loader, channel, 20) == 20);
#endif
    /* or read it at once */
    loader_write_from_channel (loader, channel, G_MAXSIZE);

    /* free resources */
    g_io_channel_unref (channel);
    gdk_pixbuf_loader_close (loader, NULL);
    g_object_unref (loader);
}
예제 #7
0
파일: utils.c 프로젝트: azuwis/cview
GdkPixbufAnimation *load_anime_from_archive(const char *archname,
        const char *archpath)
{
    GError *error = NULL;
    GdkPixbufLoader *loader = NULL;
    GdkPixbufAnimation *anim = NULL;

    loader = gdk_pixbuf_loader_new();
    if (loader == NULL)
        return NULL;

    if (file_has_extension(archname, "rar")) {
        extract_rar_file_into_loader(loader, archname, archpath);
    } else if (file_has_extension(archname, "zip")) {
        extract_zip_file_into_loader(loader, archname, archpath);
    }
    gdk_pixbuf_loader_close(loader, &error);
    if (error != NULL) {
        g_warning("load image \"%s\" in \"%s\" failed: %s\n", archpath,
                  archname, error->message);
        g_error_free(error);
        g_object_unref(loader);
        return NULL;
    }

    anim = g_object_ref(gdk_pixbuf_loader_get_animation(loader));
    g_object_unref(loader);
    return anim;
}
예제 #8
0
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;
}
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;
}
예제 #10
0
파일: gtkselection.c 프로젝트: sam-m888/gtk
/**
 * 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;
}
예제 #11
0
static void
test_area_updated_ico (gconstpointer data)
{
    const char *filename;
    GIOChannel *channel;
    GdkPixbufLoader *loader;

    filename = g_test_get_filename (G_TEST_DIST, data, NULL);

    /* create channel */
    channel = g_io_channel_new_file(filename, "r", NULL);
    g_assert_nonnull (channel);
    g_io_channel_set_encoding (channel, NULL, NULL);
    /* create loader */
    loader = gdk_pixbuf_loader_new ();
    g_assert_nonnull (loader);

    g_signal_connect(loader, "area-prepared",
                    (GCallback) callback_area_prepared, NULL);
    /* callbacks for "area-updated" and "closed" signals will be connected
     * in callback_area_prepared() */

    /* read image byte by byte */
    while (loader_write_from_channel(loader, channel, 1) == 1);
    /* or read full image at once */
#if 0
    loader_write_from_channel(loader, channel, G_MAXSIZE);
#endif

    /* free resources */
    g_io_channel_unref (channel);

    gdk_pixbuf_loader_close (loader, NULL);
    g_object_unref (loader);
}
예제 #12
0
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;
}
예제 #13
0
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;
}
예제 #14
0
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;
}
예제 #15
0
static GdkPixbufLoader *
create_loader (GFile        *file,
               const guchar *data,
               gsize         size)
{
  GdkPixbufLoader *loader;
  GError *error = NULL;
  char *mime_type;
  char *filename;

  loader = NULL;

  /* need to specify the type here because the gdk_pixbuf_loader_write
     doesn't have access to the filename in order to correct detect
     the image type. */
  filename = g_file_get_basename (file);
  mime_type = g_content_type_guess (filename, data, size, NULL);
  g_free (filename);

  if (mime_type != NULL) {
    loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, &error);
  }

  if (loader == NULL) {
    g_debug ("Unable to create loader for mime type %s: %s", mime_type,
             (error != NULL) ? error->message : "(null)");
    g_clear_error (&error);
    loader = gdk_pixbuf_loader_new ();
  }
  g_free (mime_type);

  return loader;
}
예제 #16
0
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);
}
예제 #17
0
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;
}
예제 #18
0
static void 
input_stream_ready_callback (GObject *source_object,
			     GAsyncResult *res,
			     gpointer user_data)
{
    GnomeGdkPixbufAsyncHandle *handle = user_data;

    handle->file_input_stream = g_file_read_finish (G_FILE (source_object),
						    res, NULL);
    if (handle->file_input_stream == NULL) {
	/* TODO: could map the GError more precisely to the GnomeVFSError */
	load_done (handle, GNOME_VFS_ERROR_GENERIC, NULL);
	return;
    }

    handle->loader = gdk_pixbuf_loader_new ();

    g_input_stream_read_async (G_INPUT_STREAM (handle->file_input_stream),
			       handle->buffer,
			       sizeof (handle->buffer),
			       G_PRIORITY_DEFAULT,
			       handle->cancellable,
			       input_stream_read_callback,
			       handle);
}
예제 #19
0
파일: loader.c 프로젝트: onlyshk/GPicView
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;
}
예제 #20
0
GdkPixbuf *
hd_pixbuf_utils_load_scaled_and_cropped (GFile         *file,
                                         HDImageSize   *size,
                                         char         **etag,
                                         GCancellable  *cancellable,
                                         GError       **error)
{
  GFileInputStream *stream = NULL;
  GdkPixbufLoader *loader = NULL;
  GdkPixbuf *pixbuf = NULL;

  /* Open file for read */
  stream = g_file_read (file, cancellable, error);

  if (!stream)
    goto cleanup;

  /* Create pixbuf loader */
  loader = gdk_pixbuf_loader_new ();
  g_signal_connect (loader, "size-prepared",
                    G_CALLBACK (size_prepared_cb),
                    size);

  if (!get_etag_from_file_input_stream (stream,
                                        etag,
                                        cancellable,
                                        error))
    goto cleanup;

  if (!read_from_input_stream_into_pixbuf_loader (G_INPUT_STREAM (stream),
                                                  loader,
                                                  cancellable,
                                                  error))
    goto cleanup;

  /* Set resulting pixbuf */
  pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
  if (pixbuf)
    {
      GdkPixbuf *rotated = gdk_pixbuf_apply_embedded_orientation (pixbuf);
      pixbuf = scale_and_crop_pixbuf (rotated, size);
      g_object_unref (rotated);
    }
  else
    g_set_error_literal (error,
                         GDK_PIXBUF_ERROR,
                         GDK_PIXBUF_ERROR_FAILED,
                         "NULL Pixbuf returned from loader");

cleanup:
  if (stream)
    g_object_unref (stream);
  if (loader)
    g_object_unref (loader);

  return pixbuf;
}
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;
}
예제 #22
0
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;
  }
}
예제 #23
0
GdkPixbuf *
hd_pixbuf_utils_load_at_size (GFile         *file,
                              HDImageSize   *size,
                              char         **etag,
                              GCancellable  *cancellable,
                              GError       **error)
{
  GFileInputStream *stream = NULL;
  GdkPixbufLoader *loader = NULL;
  GdkPixbuf *pixbuf = NULL;

  stream = g_file_read (file, cancellable, error);

  if (!stream)
    goto cleanup;

  /* Create pixbuf loader */
  loader = gdk_pixbuf_loader_new ();
  g_signal_connect (loader, "size-prepared",
                    G_CALLBACK (size_prepared_exact_cb), size);

  if (!get_etag_from_file_input_stream (stream,
                                        etag,
                                        cancellable,
                                        error))
    goto cleanup;

  if (!read_from_input_stream_into_pixbuf_loader (G_INPUT_STREAM (stream),
                                                  loader,
                                                  cancellable,
                                                  error))
    goto cleanup;

  /* Set resulting pixbuf */
  pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
  if (pixbuf && 
      gdk_pixbuf_get_width (pixbuf) == size->width &&
      gdk_pixbuf_get_height (pixbuf) == size->height)
    {
      g_object_ref (pixbuf);
    }
  else
    g_set_error_literal (error,
                         GDK_PIXBUF_ERROR,
                         GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
                         "No pixbuf in the correct size");

cleanup:
  if (stream)
    g_object_unref (stream);
  if (loader)
    g_object_unref (loader);

  return pixbuf;
}
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 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 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;
    }
}
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;
}
예제 #28
0
/*
  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;
}
예제 #29
0
파일: contacts.c 프로젝트: shr-project/shr
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);
}
예제 #30
0
static void
load_sliced_image (GSimpleAsyncResult *result,
                   GObject *object,
                   GCancellable *cancellable)
{
  AsyncImageData *data;
  GList *res = NULL;
  GdkPixbuf *pix;
  gint width, height, y, x;
  GdkPixbufLoader *loader;
  gchar *buffer = NULL;
  gsize length;

  g_assert (!cancellable);

  data = g_object_get_data (G_OBJECT (result), "load_sliced_image");
  g_assert (data);

  loader = gdk_pixbuf_loader_new ();
  g_signal_connect (loader, "size-prepared", G_CALLBACK (on_loader_size_prepared), data);

  if (!g_file_load_contents (data->gfile, NULL, &buffer, &length, NULL, NULL))
    goto out;

  if (!gdk_pixbuf_loader_write (loader, (const guchar *) buffer, length, NULL))
    goto out;

  if (!gdk_pixbuf_loader_close (loader, NULL))
    goto out;

  pix = gdk_pixbuf_loader_get_pixbuf (loader);
  width = gdk_pixbuf_get_width (pix);
  height = gdk_pixbuf_get_height (pix);
  for (y = 0; y < height; y += data->grid_height * data->scale_factor)
    {
      for (x = 0; x < width; x += data->grid_width * data->scale_factor)
        {
          GdkPixbuf *pixbuf = gdk_pixbuf_new_subpixbuf (pix, x, y,
                                                        data->grid_width * data->scale_factor,
                                                        data->grid_height * data->scale_factor);
          g_assert (pixbuf != NULL);
          res = g_list_append (res, pixbuf);
        }
    }

 out:
  /* We don't need the original pixbuf anymore, which is owned by the loader,
   * though the subpixbufs will hold a reference. */
  g_object_unref (loader);
  g_free (buffer);
  g_simple_async_result_set_op_res_gpointer (result, res, free_glist_unref_gobjects);
}