예제 #1
0
static void
new_from_stream_thread (GSimpleAsyncResult *result,
			GInputStream       *stream,
			GCancellable       *cancellable)
{
	GdkPixbuf *pixbuf;
	AtScaleData *data;
	GError *error = NULL;

	/* If data != NULL, we're scaling the pixbuf while loading it */
	data = g_simple_async_result_get_op_res_gpointer (result);
	if (data != NULL)
		pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, data->width, data->height, data->preserve_aspect_ratio, cancellable, &error);
	else
		pixbuf = gdk_pixbuf_new_from_stream (stream, cancellable, &error);

	g_simple_async_result_set_op_res_gpointer (result, NULL, NULL);

	/* Set the new pixbuf as the result, or error out */
	if (pixbuf == NULL) {
		g_simple_async_result_set_from_error (result, error);
		g_error_free (error);
	} else {
		g_simple_async_result_set_op_res_gpointer (result, pixbuf, g_object_unref);
	}
}
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 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);
}
예제 #4
0
static void
load_file (GTask               *task,
           MetaBackgroundImage *image,
           gpointer             task_data,
           GCancellable        *cancellable)
{
  GError *error = NULL;
  GdkPixbuf *pixbuf;
  GFileInputStream *stream;

  stream = g_file_read (image->file, NULL, &error);
  if (stream == NULL)
    {
      g_task_return_error (task, error);
      return;
    }

  pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), NULL, &error);
  g_object_unref (stream);

  if (pixbuf == NULL)
    {
      g_task_return_error (task, error);
      return;
    }

  g_task_return_pointer (task, pixbuf, (GDestroyNotify) g_object_unref);
}
예제 #5
0
GdkPixbuf*
utils_download_picture(SoupSession* soup, const gchar* url)
{
    SoupMessage* msg;
    GdkPixbuf* ret = NULL;
    GInputStream* input;
    GError* err = NULL;

    msg = soup_message_new("GET", url);
    input = soup_session_send(soup, msg, NULL, &err);

    if (err)
    {
        g_warning("{Utils} Error downloading picture code '%d' message '%s'", err->code, err->message);
        g_error_free(err);
    }
    else
    {
        ret = gdk_pixbuf_new_from_stream(input, NULL, NULL);

        g_input_stream_close(input, NULL, NULL);
    }

    g_object_unref(msg);

    return ret;
}
예제 #6
0
/**
 * 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;
}
예제 #7
0
파일: gdktexture.c 프로젝트: GNOME/gtk
/**
 * gdk_texture_new_from_file:
 * @file: #GFile to load
 * @error: Return location for an error
 *
 * Creates a new texture by loading an image from a file.  The file format is
 * detected automatically. If %NULL is returned, then @error will be set.
 *
 * Return value: A newly-created #GdkTexture or %NULL if an error occured.
 **/
GdkTexture *
gdk_texture_new_from_file (GFile   *file,
                           GError **error)
{
  GdkTexture *texture;
  GdkPixbuf *pixbuf;
  GInputStream *stream;

  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  stream = G_INPUT_STREAM (g_file_read (file, NULL, error));
  if (stream == NULL)
    return NULL;

  pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
  g_object_unref (stream);
  if (pixbuf == NULL)
    return NULL;

  texture = gdk_texture_new_for_pixbuf (pixbuf);
  g_object_unref (pixbuf);

  return texture;
}
예제 #8
0
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 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;
}
예제 #10
0
static GdkPixbuf *
about_dialog_load_logo (void)
{
  GdkPixbuf    *pixbuf = NULL;
  GFile        *file;
  GInputStream *input;

  file = gimp_data_directory_file ("images",
#ifdef GIMP_UNSTABLE
                                   "gimp-devel-logo.png",
#else
                                   "gimp-logo.png",
#endif
                                   NULL);

  input = G_INPUT_STREAM (g_file_read (file, NULL, NULL));
  g_object_unref (file);

  if (input)
    {
      pixbuf = gdk_pixbuf_new_from_stream (input, NULL, NULL);
      g_object_unref (input);
    }

  return pixbuf;
}
예제 #11
0
bool ImageHandler::insertImage(GFile * file, double x, double y) {
	XOJ_CHECK_TYPE(ImageHandler);

	GError * err = NULL;
	GFileInputStream * in = g_file_read(file, NULL, &err);

	g_object_unref(file);

	GdkPixbuf * pixbuf = NULL;

	if (!err) {
		pixbuf = gdk_pixbuf_new_from_stream(G_INPUT_STREAM(in), NULL, &err);
		g_input_stream_close(G_INPUT_STREAM(in), NULL, NULL);
	} else {
		GtkWidget * dialog = gtk_message_dialog_new((GtkWindow*) *control->getWindow(), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
				_("This image could not be loaded. Error message: %s"), err->message);
		gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(this->control->getWindow()->getWindow()));
		gtk_dialog_run(GTK_DIALOG(dialog));
		gtk_widget_destroy(dialog);
		g_error_free(err);
		return false;
	}

	Image * img = new Image();
	img->setX(x);
	img->setY(y);
	img->setImage(pixbuf);

	int width = gdk_pixbuf_get_width(pixbuf);
	int height = gdk_pixbuf_get_height(pixbuf);
	gdk_pixbuf_unref(pixbuf);

	double zoom = 1;

	PageRef page = view->getPage();

	if (x + width > page.getWidth() || y + height > page.getHeight()) {
		double maxZoomX = (page.getWidth() - x) / width;
		double maxZoomY = (page.getHeight() - y) / height;

		if (maxZoomX < maxZoomY) {
			zoom = maxZoomX;
		} else {
			zoom = maxZoomY;
		}
	}

	img->setWidth(width * zoom);
	img->setHeight(height * zoom);

	page.getSelectedLayer()->addElement(img);

	InsertUndoAction * insertUndo = new InsertUndoAction(page, page.getSelectedLayer(), img, view);
	control->getUndoRedoHandler()->addUndoAction(insertUndo);

	view->rerenderElement(img);

	return true;
}
예제 #12
0
/*
 *	CBoardDevice::Init()
 *
 *  Initializes the device
 *
 *	Returns:	True if the initializing was successful and false if it failed.
 */
bool CBoardDevice::Init(GtkFixed *board_area, CBoardDeviceGroup *device_group)
{
	this->device_group = device_group;

	// Load the bitmap
	GdkPixbuf *bg_pixbuf = gdk_pixbuf_new_from_stream(CFile(image_file.c_str()).get_input_stream(), NULL, NULL);
	if(bg_pixbuf == NULL)
		return false;

	bitmap_x = bitmap_y = 0;
	
	width = gdk_pixbuf_get_width(bg_pixbuf);
	height = gdk_pixbuf_get_height(bg_pixbuf);

	// Check if the type is LED, PUSH or TOGGLE
	if(!strcmp(type.c_str(), "LED") ||
	   !strcmp(type.c_str(), "PUSH") ||
	   !strcmp(type.c_str(), "TOGGLE"))
	{
		// Set the appropriate width and height of the bitmap
		width = width / 2;

		// Check if PUSH because pushbuttons have the value 1 if they are up
		if(!strcmp(type.c_str(), "PUSH"))
			bitmap_x = 1;
	}
	// Check if the type is SSLED
	else if(!strcmp(type.c_str(), "SSLED"))
	{
		// Set the appropriate width and height of the bitmap
		width = width / 8;
		height = height / 16;
	}
	
	GtkWidget *bg_viewport = gtk_viewport_new(NULL, NULL);
	gtk_widget_set_events(bg_viewport, GDK_BUTTON_RELEASE_MASK);
	g_signal_connect(G_OBJECT(bg_viewport), "button-press-event", G_CALLBACK(device_button_pressed), this);
	g_signal_connect(G_OBJECT(bg_viewport), "button-release-event", G_CALLBACK(device_button_released), this);
	gtk_widget_show(bg_viewport);
	
	GtkWidget *bg_image = gtk_image_new_from_pixbuf(bg_pixbuf);
	gtk_widget_show(bg_image);
	
	gtk_container_add((GtkContainer*)bg_viewport, bg_image);
	gtk_viewport_set_shadow_type((GtkViewport*)bg_viewport, GTK_SHADOW_NONE);
	gtk_widget_set_size_request(bg_viewport, width, height);
	gtk_adjustment_set_upper(gtk_viewport_get_hadjustment((GtkViewport*)bg_viewport), width);
	gtk_adjustment_set_upper(gtk_viewport_get_vadjustment((GtkViewport*)bg_viewport), height);
	gtk_fixed_put(board_area, bg_viewport, coords.x, coords.y);
	
	g_object_unref(bg_pixbuf);
	
	viewport = (GtkViewport*)bg_viewport;
	
	ShowCorrectImage();

	return true;
}
예제 #13
0
static gboolean
gtk_css_image_url_parse (GtkCssImage  *image,
                         GtkCssParser *parser)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
  GdkPixbuf *pixbuf;
  GFile *file;
  cairo_t *cr;
  GError *error = NULL;
  GFileInputStream *input;

  file = _gtk_css_parser_read_url (parser);
  if (file == NULL)
    return FALSE;

  /* We special case resources here so we can use
     gdk_pixbuf_new_from_resource, which in turn has some special casing
     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
  if (g_file_has_uri_scheme (file, "resource"))
    {
      char *uri = g_file_get_uri (file);
      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);

      pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
      g_free (resource_path);
      g_free (uri);
    }
  else
    {
      input = g_file_read (file, NULL, &error);
      if (input == NULL)
	{
	  _gtk_css_parser_take_error (parser, error);
	  return FALSE;
	}

      pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
      g_object_unref (input);
    }
  g_object_unref (file);

  if (pixbuf == NULL)
    {
      _gtk_css_parser_take_error (parser, error);
      return FALSE;
    }

  url->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                             gdk_pixbuf_get_width (pixbuf),
                                             gdk_pixbuf_get_height (pixbuf));
  cr = cairo_create (url->surface);
  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);
  g_object_unref (pixbuf);

  return TRUE;
}
예제 #14
0
파일: icons.c 프로젝트: Doluci/HandBrake
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);
    }
}
예제 #15
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;
}
예제 #16
0
static GtkCssImage *
gtk_css_image_url_load_image (GtkCssImageUrl *url)
{
  GdkPixbuf *pixbuf;
  GError *error = NULL;
  GFileInputStream *input;

  if (url->loaded_image)
    return url->loaded_image;

  /* We special case resources here so we can use
     gdk_pixbuf_new_from_resource, which in turn has some special casing
     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
  if (g_file_has_uri_scheme (url->file, "resource"))
    {
      char *uri = g_file_get_uri (url->file);
      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);

      pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
      g_free (resource_path);
      g_free (uri);
    }
  else
    {
      input = g_file_read (url->file, NULL, &error);
      if (input != NULL)
	{
          pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
          g_object_unref (input);
	}
      else
        {
          pixbuf = NULL;
        }
    }

  if (pixbuf == NULL)
    {
      cairo_surface_t *empty = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);

      /* XXX: Can we get the error somehow sent to the CssProvider?
       * I don't like just dumping it to stderr or losing it completely. */
      g_warning ("Error loading image: %s", error->message);
      g_error_free (error);
      url->loaded_image = _gtk_css_image_surface_new (empty);
      cairo_surface_destroy (empty);
      return url->loaded_image; 
    }

  url->loaded_image = _gtk_css_image_surface_new_for_pixbuf (pixbuf);
  g_object_unref (pixbuf);

  return url->loaded_image;
}
예제 #17
0
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;
}
예제 #18
0
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;
}
예제 #19
0
파일: gtkcssimageurl.c 프로젝트: GNOME/gtk
static gboolean
gtk_css_image_url_parse (GtkCssImage  *image,
                         GtkCssParser *parser)
{
  GtkCssImageUrl *self = GTK_CSS_IMAGE_URL (image);
  char *url, *scheme;

  url = gtk_css_parser_consume_url (parser);
  if (url == NULL)
    return FALSE;

  scheme = g_uri_parse_scheme (url);
  if (scheme && g_ascii_strcasecmp (scheme, "data") == 0)
    {
      GInputStream *stream;
      GdkPixbuf *pixbuf;
      GBytes *bytes;
      GError *error = NULL;

      bytes = gtk_css_data_url_parse (url, NULL, &error);
      if (bytes)
        {
          stream = g_memory_input_stream_new_from_bytes (bytes);
          pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &error);
          g_object_unref (stream);
          if (pixbuf == NULL)
            {
              gtk_css_parser_emit_error (parser,
                                         gtk_css_parser_get_start_location (parser),
                                         gtk_css_parser_get_end_location (parser),
                                         error);
              g_clear_error (&error);
            }
          else
            {
              GdkTexture *texture = gdk_texture_new_for_pixbuf (pixbuf);
              self->loaded_image = gtk_css_image_paintable_new (GDK_PAINTABLE (texture), GDK_PAINTABLE (texture));
              g_object_unref (texture);
              g_object_unref (pixbuf);
            }
        }
    }
  else
    {
      self->file = gtk_css_parser_resolve_url (parser, url);
    }

  g_free (url);
  g_free (scheme);

  return TRUE;
}
예제 #20
0
파일: tray.c 프로젝트: shurcooL/trayhost
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);
}
예제 #21
0
static GdkPixbuf *
nemo_get_thumbnail_frame (void)
{
	static GdkPixbuf *thumbnail_frame = NULL;

	if (thumbnail_frame == NULL) {
		GInputStream *stream = g_resources_open_stream ("/org/nemo/icons/thumbnail_frame.png", 0, NULL);
		if (stream != NULL) {
			thumbnail_frame = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
			g_object_unref (stream);
		}
	}
	
	return thumbnail_frame;
}
예제 #22
0
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;
}
예제 #23
0
/*! \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;
}
예제 #24
0
/**
 * gel_ui_pixbuf_from_stream:
 * @stream: (transfer none): A #GInputStream
 *
 * Creates a #GdkPixbuf from a #GInputStream
 *
 * Returns: (transfer full): The new #GdkPixbuf or %NULL
 */
GdkPixbuf*
gel_ui_pixbuf_from_stream(const GInputStream *stream)
{
	g_return_val_if_fail(G_IS_INPUT_STREAM(stream), NULL);

	g_seekable_seek((GSeekable *) stream, 0, G_SEEK_SET, NULL, NULL);

	GError *error = NULL;
	GdkPixbuf *ret = gdk_pixbuf_new_from_stream((GInputStream *) stream, NULL, &error);
	if (ret == NULL)
	{
		g_warning(_("Cannot load image from input stream %p: %s"), stream, error->message);
		g_error_free(error);
		return NULL;
	}
	return ret;
}
예제 #25
0
GdkPixbuf*
utils_download_picture(SoupSession* soup, const gchar* url)
{
    SoupMessage* msg;
    GdkPixbuf* ret;
    GInputStream* input;

    msg = soup_message_new("GET", url);
    input = soup_session_send(soup, msg, NULL, NULL);

    ret = gdk_pixbuf_new_from_stream(input, NULL, NULL);

    g_input_stream_close(input, NULL, NULL);
    g_object_unref(msg);

    return ret;
}
예제 #26
0
static GdkPixbuf *
robohash_part_get_pixbuf (int set, int element, int part)
{
  GdkPixbuf *pixbuf;
  GInputStream *stream;
  const char *data;
  gsize size;

  data = robohash_bits_get (set, element, part, &size);
  if (data == NULL)
    return NULL;

  stream = g_memory_input_stream_new_from_data (data, size, NULL);
  pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
  g_object_unref (stream);
  return pixbuf;
}
static void
test_serialize (void)
{
  GError *error = NULL;
  GdkPixbuf *pixbuf;
  GdkPixbuf *pixbuf2;
  GVariant *data;
  GIcon *icon;
  GInputStream *stream;

  pixbuf = gdk_pixbuf_new_from_file (g_test_get_filename (G_TEST_DIST, "test-image.png", NULL), &error);
  g_assert_no_error (error);
  g_assert (pixbuf != NULL);

  /* turn it into a GVariant */
  data = g_icon_serialize (G_ICON (pixbuf));

  /* back to a GIcon, but this will be a GBytesIcon, not GdkPixbuf */
  icon = g_icon_deserialize (data);
  g_assert (G_IS_BYTES_ICON (icon));

  /* but since that is a GLoadableIcon, we can load it again */
  stream = g_loadable_icon_load (G_LOADABLE_ICON (icon), 0, NULL, NULL, &error);
  g_assert_no_error (error);
  pixbuf2 = gdk_pixbuf_new_from_stream (stream, NULL, &error);
  g_assert_no_error (error);

  /* make sure that the pixels are the same.
   * our _serialize() uses png, so this should be perfect.
   */
  {
    guchar *pixels_a, *pixels_b;
    guint len_a, len_b;
    pixels_a = gdk_pixbuf_get_pixels_with_length (pixbuf, &len_a);
    pixels_b = gdk_pixbuf_get_pixels_with_length (pixbuf2, &len_b);
    g_assert (len_a == len_b);
    g_assert (memcmp (pixels_a, pixels_b, len_a) == 0);
  }

  g_object_unref (pixbuf2);
  g_object_unref (pixbuf);
  g_object_unref (stream);
  g_variant_unref (data);

}
예제 #28
0
void
background_init (void)
{
	// Inline data declaration:
	extern char _binary_textures_background_png_start[];
	extern char _binary_textures_background_png_end[];

	char *start = _binary_textures_background_png_start;
	size_t len = _binary_textures_background_png_end
		   - _binary_textures_background_png_start;

	GInputStream *stream;
	GdkPixbuf *pixbuf;

	// Create an input stream from inline data:
	stream = g_memory_input_stream_new_from_data(start, len, NULL);

	// Generate a pixbuf from the input stream:
	pixbuf = gdk_pixbuf_new_from_stream(stream, NULL, NULL);

	// Destroy the stream:
	g_object_unref(stream);

	// Generate an OpenGL texture from pixbuf;
	// hack a bit by not accounting for pixbuf rowstride:
	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D, texture);

	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
		gdk_pixbuf_get_width(pixbuf),
		gdk_pixbuf_get_height(pixbuf), 0, GL_RGB, GL_UNSIGNED_BYTE,
		gdk_pixbuf_get_pixels(pixbuf));

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	// Generate empty buffer:
	glGenBuffers(1, &vbo);

	// Generate empty vertex array object:
	glGenVertexArrays(1, &vao);
}
예제 #29
0
파일: utils.c 프로젝트: pingax/pragha
GdkPixbuf *vgdk_pixbuf_new_from_memory(const char *data, size_t size)
{
	GInputStream *buffer_stream=NULL;
	GdkPixbuf *buffer_pix=NULL;
	GError *err = NULL;

	buffer_stream = g_memory_input_stream_new_from_data (data, size, NULL);
	
	buffer_pix = gdk_pixbuf_new_from_stream(buffer_stream, NULL, &err);
	g_input_stream_close(buffer_stream, NULL, NULL);
	g_object_unref(buffer_stream);

	if(buffer_pix == NULL){
		g_warning("vgdk_pixbuf_new_from_memory: %s\n",err->message);
		g_error_free (err);	
	}
	return buffer_pix;
}
예제 #30
0
void XojOpenDlg::updatePreviewCallback(GtkFileChooser* fileChooser, void* userData)
{
	gchar* filename = gtk_file_chooser_get_preview_filename(fileChooser);

	if (!filename)
	{
		gtk_file_chooser_set_preview_widget_active(fileChooser, false);
		return;
	}

	string filepath = filename;
	g_free(filename);
	filename = NULL;

	if (filepath.size() <= 4 || filepath.substr(filepath.size() - 4) != ".xoj")
	{
		gtk_file_chooser_set_preview_widget_active(fileChooser, false);
		return;
	}

	XojPreviewExtractor extractor;
	PreviewExtractResult result = extractor.readFile(filepath);

	if (result != PREVIEW_RESULT_IMAGE_READ)
	{
		gtk_file_chooser_set_preview_widget_active(fileChooser, false);
		return;
	}

	GError* error = NULL;
	GInputStream* in = g_memory_input_stream_new_from_data(extractor.getData().c_str(), extractor.getData().length(), NULL);
	GdkPixbuf* pixbuf = gdk_pixbuf_new_from_stream(in, NULL, &error);
	g_input_stream_close(in, NULL, &error);

	if (pixbuf)
	{
		GtkWidget * image = gtk_file_chooser_get_preview_widget(fileChooser);
		gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
		g_object_unref(pixbuf);
		gtk_file_chooser_set_preview_widget_active(fileChooser, true);
	}
}