Ejemplo n.º 1
0
gboolean
apply_transformation_generic (FileData     *file,
			      GthTransform  transform,
			      GError       **error)
{
	gboolean   success = TRUE;
	GdkPixbuf *original_pixbuf;
	GdkPixbuf *transformed_pixbuf;
	
	if (file == NULL)
		return FALSE;

	if (transform == GTH_TRANSFORM_NONE)
		return TRUE;

	original_pixbuf = gth_pixbuf_new_from_file (file, error, 0, 0, NULL);
	if (original_pixbuf == NULL)
		return FALSE;

	transformed_pixbuf = _gdk_pixbuf_transform (original_pixbuf, transform);
		
	if (is_mime_type_writable (file->mime_type)) {
		const char *image_type = file->mime_type + 6;
		char	   *local_file;
		
		image_type = file->mime_type + 6;
		local_file = get_cache_filename_from_uri (file->path);
		
		success = _gdk_pixbuf_save (transformed_pixbuf,
					    local_file,
					    image_type,
					    error,
					    NULL);
					    
		g_free (local_file);
	} 
	else {
		if (error != NULL)
			*error = g_error_new (GTHUMB_ERROR, 0, _("Image type not supported: %s"), file->mime_type);
		success = FALSE;
	}
	
	g_object_unref (transformed_pixbuf);
	g_object_unref (original_pixbuf);
	
	return success;
}
Ejemplo n.º 2
0
GthImage *
gth_pixbuf_animation_new_from_file (GInputStream  *istream,
				    GthFileData   *file_data,
				    int            requested_size,
				    int           *original_width,
				    int           *original_height,
				    gpointer       user_data,
				    GCancellable  *cancellable,
				    GError       **error)
{
	const char         *mime_type;
	GdkPixbufAnimation *animation;
	char               *path;
	GthImage           *image;

	mime_type = _g_content_type_get_from_stream (istream, (file_data != NULL ? file_data->file : NULL), cancellable, error);
	if (mime_type == NULL)
		return NULL;

	if ((file_data == NULL) || ! g_content_type_equals (mime_type, "image/gif"))
		return gth_pixbuf_new_from_file (istream,
						 file_data,
						 requested_size,
						 original_width,
						 original_height,
						 FALSE,
						 cancellable,
						 error);

	path = g_file_get_path (file_data->file);
	if (path == NULL) {
		if (error != NULL)
			*error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, "Could not load file");
		return NULL;
	}

	animation = gdk_pixbuf_animation_new_from_file (path, error);
	image = gth_image_new ();
	gth_image_set_pixbuf_animation (image, animation);

	g_object_unref (animation);
	g_free (path);

	return image;
}
Ejemplo n.º 3
0
GthImage *
gth_pixbuf_animation_new_from_file (GInputStream  *istream,
				    GthFileData   *file_data,
				    int            requested_size,
				    int           *original_width,
				    int           *original_height,
				    gboolean      *loaded_original,
				    gpointer       user_data,
				    GCancellable  *cancellable,
				    GError       **error)
{
	const char *mime_type;
	GthImage   *image;

	mime_type = _g_content_type_get_from_stream (istream, (file_data != NULL ? file_data->file : NULL), cancellable, error);
	if (mime_type == NULL)
		return NULL;

	image = NULL;
	if (g_content_type_equals (mime_type, "image/gif")) {
		GdkPixbufAnimation *animation;

		animation = gdk_pixbuf_animation_new_from_stream (istream, cancellable, error);
		image = gth_image_new ();
		gth_image_set_pixbuf_animation (image, animation);

		_g_object_unref (animation);
	}
	else
		image = gth_pixbuf_new_from_file (istream,
						  file_data,
						  requested_size,
						  original_width,
						  original_height,
						  loaded_original,
						  FALSE,
						  cancellable,
						  error);

	return image;
}