コード例 #1
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;
}
コード例 #2
0
static GthImage *
flickr_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;
	GthThumbLoader *thumb_loader = user_data;
	FlickrPhoto    *photo;
	const char     *uri = NULL;

	photo = (FlickrPhoto *) g_file_info_get_attribute_object (file_data->info, "flickr::object");
	requested_size = gth_thumb_loader_get_requested_size (thumb_loader);
	if (requested_size == FLICKR_SIZE_SMALL_SQUARE)
		uri = photo->url[FLICKR_URL_SQ];
	else if (requested_size == FLICKR_SIZE_THUMBNAIL)
		uri = photo->url[FLICKR_URL_T];
	else if (requested_size == FLICKR_SIZE_SMALL)
		uri = photo->url[FLICKR_URL_S];
	else if (requested_size == FLICKR_SIZE_MEDIUM)
		uri = photo->url[FLICKR_URL_M];

	if (uri == NULL)
		uri = photo->url[FLICKR_URL_O];

	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;
}
コード例 #3
0
ファイル: pixbuf-io.c プロジェクト: KapTmaN/gthumb
GthImage *
gth_pixbuf_new_from_file (GInputStream  *istream,
			  GthFileData   *file_data,
			  int            requested_size,
			  int           *original_width,
			  int           *original_height,
			  gboolean       scale_to_original,
			  GCancellable  *cancellable,
			  GError       **error)
{
	ScaleData        scale_data;
	GdkPixbufLoader *pixbuf_loader;
	GdkPixbuf       *pixbuf;
	GthImage        *image;

	if (original_width != NULL)
		*original_width = -1;
	if (original_height != NULL)
		*original_height = -1;

	scale_data.requested_size = requested_size;
	scale_data.original_width = -1;
	scale_data.original_height = -1;
	scale_data.loader_width = -1;
	scale_data.loader_height = -1;

	pixbuf_loader = gdk_pixbuf_loader_new ();
	g_signal_connect (pixbuf_loader,
			  "size-prepared",
			  G_CALLBACK (pixbuf_loader_size_prepared_cb),
			  &scale_data);
	pixbuf = load_from_stream (pixbuf_loader, istream, requested_size, cancellable, error);

	g_object_unref (pixbuf_loader);

	if ((pixbuf != NULL) && scale_to_original) {
		GdkPixbuf *tmp;

		tmp = _gdk_pixbuf_scale_simple_safe (pixbuf, scale_data.original_width, scale_data.original_height, GDK_INTERP_NEAREST);
		g_object_unref (pixbuf);
		pixbuf = tmp;
	}

	if (pixbuf != NULL) {
		GdkPixbuf *rotated;

		rotated = gdk_pixbuf_apply_embedded_orientation (pixbuf);
		if (rotated != NULL) {
			scale_data.original_width = gdk_pixbuf_get_width (rotated);
			scale_data.original_height = gdk_pixbuf_get_height (rotated);
			g_object_unref (pixbuf);
			pixbuf = rotated;
		}
	}

	image = gth_image_new_for_pixbuf (pixbuf);

	if (original_width != NULL)
		*original_width = scale_data.original_width;
	if (original_height != NULL)
		*original_height = scale_data.original_height;

	_g_object_unref (pixbuf);

	return image;
}
コード例 #4
0
ファイル: actions.c プロジェクト: KapTmaN/gthumb
static void
screenshot_ready_cb (GdkPixbuf *pixbuf,
		     gpointer   user_data)
{
	SaveData  *save_data = user_data;
	GtkWidget *file_sel;

	if (pixbuf == NULL) {
		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (save_data->browser), _("Could not take a screenshot"), NULL);
		save_date_free (save_data);
		return;
	}

	save_data->image = gth_image_new_for_pixbuf (pixbuf);
	file_sel = gth_file_chooser_dialog_new (_("Save Image"), GTK_WINDOW (save_data->browser), "image-saver");
	gtk_window_set_modal (GTK_WINDOW (file_sel), TRUE);

	{
		char        *last_uri;
		GFile       *last_folder;
		GthFileData *file_data;
		char        *prefix;
		char        *display_name;
		int          attempt;

		last_uri = g_settings_get_string (save_data->settings, PREF_GSTREAMER_TOOLS_SCREESHOT_LOCATION);
		if ((last_uri == NULL) || (strcmp (last_uri, "~") == 0) || (strcmp (last_uri, "file://~") == 0)) {
			const char *dir;

			dir = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
			if (dir != NULL)
				last_folder = g_file_new_for_path (dir);
			else
				last_folder = g_file_new_for_uri (get_home_uri ());
		}
		else
			last_folder = g_file_new_for_uri (last_uri);
		gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (file_sel), last_folder, NULL);

		file_data = gth_media_viewer_page_get_file_data (save_data->page);
		prefix = _g_utf8_remove_extension (g_file_info_get_display_name (file_data->info));
		if (prefix == NULL)
			prefix = g_strdup (C_("Filename", "Screenshot"));
		display_name = NULL;
		for (attempt = 1; attempt < MAX_ATTEMPTS; attempt++) {
			GFile *proposed_file;

			g_free (display_name);

			display_name = g_strdup_printf ("%s-%02d.jpeg", prefix, attempt);
			proposed_file = g_file_get_child_for_display_name (last_folder, display_name, NULL);
			if ((proposed_file != NULL) && ! g_file_query_exists (proposed_file, NULL)) {
				g_object_unref (proposed_file);
				break;
			}
		}

		if (display_name != NULL) {
			gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (file_sel), display_name);
			g_free (display_name);
		}

		g_free (prefix);
		g_object_unref (last_folder);
		g_free (last_uri);
	}

	g_signal_connect (GTK_DIALOG (file_sel),
			  "response",
			  G_CALLBACK (save_as_response_cb),
			  save_data);

	gtk_widget_show (file_sel);
}
コード例 #5
0
static GthImage *
picasa_web_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;
	GthThumbLoader *thumb_loader = user_data;
	PicasaWebPhoto *photo;
	const char     *uri;

	photo = (PicasaWebPhoto *) g_file_info_get_attribute_object (file_data->info, "gphoto::object");
	requested_size = gth_thumb_loader_get_requested_size (thumb_loader);
	if (requested_size == 72)
		uri = photo->thumbnail_72;
	else if (requested_size == 144)
		uri = photo->thumbnail_144;
	else if (requested_size == 288)
		uri = photo->thumbnail_288;
	else
		uri = NULL;

	if (uri == NULL)
		uri = photo->uri;

	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;
}
コード例 #6
0
ファイル: main.c プロジェクト: KapTmaN/gthumb
static GthImage *
dcraw_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)
{
    GthImage    *image = NULL;
    GdkPixbuf   *pixbuf;
    gboolean     is_thumbnail;
    gboolean     is_raw;
    gboolean     is_hdr;
    char        *local_file;
    char         *local_file_md5;
    char	     *cache_file;
    char	     *cache_file_esc;
    char	     *local_file_esc;
    char	     *command = NULL;

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

    is_thumbnail = requested_size > 0;
    is_raw = _g_mime_type_is_raw (gth_file_data_get_mime_type (file_data));
    is_hdr = _g_mime_type_is_hdr (gth_file_data_get_mime_type (file_data));

    /* The output filename, and its persistence, depend on the input file
     * type, and whether or not a thumbnail has been requested. */

    local_file = g_file_get_path (file_data->file);
    local_file_md5 = gnome_desktop_thumbnail_md5 (local_file);

    if (is_raw && !is_thumbnail)
        /* Full-sized converted RAW file */
        cache_file = get_cache_full_path (local_file_md5, "conv.pnm");
    else if (is_raw && is_thumbnail)
        /* RAW: thumbnails generated in pnm format. The converted file is later removed. */
        cache_file = get_cache_full_path (local_file_md5, "conv-thumb.pnm");
    else if (is_hdr && is_thumbnail)
        /* HDR: thumbnails generated in tiff format. The converted file is later removed. */
        cache_file = get_cache_full_path (local_file_md5, "conv-thumb.tiff");
    else
        /* Full-sized converted HDR files */
        cache_file = get_cache_full_path (local_file_md5, "conv.tiff");

    g_free (local_file_md5);

    if (cache_file == NULL) {
        g_free (local_file);
        return NULL;
    }

    local_file_esc = g_shell_quote (local_file);
    cache_file_esc = g_shell_quote (cache_file);

    /* Do nothing if an up-to-date converted file is already in the cache */
    if (! g_file_test (cache_file, G_FILE_TEST_EXISTS)
            || (gth_file_data_get_mtime (file_data) > get_file_mtime (cache_file)))
    {
        if (is_raw) {
            if (is_thumbnail) {
                char *first_part;
                char *jpg_thumbnail;
                char *tiff_thumbnail;
                char *ppm_thumbnail;
                char *thumb_command;

                thumb_command = g_strdup_printf ("dcraw -e %s", local_file_esc);
                g_spawn_command_line_sync (thumb_command, NULL, NULL, NULL, NULL);
                g_free (thumb_command);

                first_part = _g_uri_remove_extension (local_file);
                jpg_thumbnail = g_strdup_printf ("%s.thumb.jpg", first_part);
                tiff_thumbnail = g_strdup_printf ("%s.thumb.tiff", first_part);
                ppm_thumbnail = g_strdup_printf ("%s.thumb.ppm", first_part);

                if (g_file_test (jpg_thumbnail, G_FILE_TEST_EXISTS)) {
                    g_free (cache_file);
                    cache_file = g_strdup (jpg_thumbnail);
                }
                else if (g_file_test (tiff_thumbnail, G_FILE_TEST_EXISTS)) {
                    g_free (cache_file);
                    cache_file = g_strdup (tiff_thumbnail);
                }
                else if (g_file_test (ppm_thumbnail, G_FILE_TEST_EXISTS)) {
                    g_free (cache_file);
                    cache_file = g_strdup (ppm_thumbnail);
                }
                else {
                    /* No embedded thumbnail. Read the whole file. */
                    /* Add -h option to speed up thumbnail generation. */
                    command = g_strdup_printf ("dcraw -w -c -h %s > %s",
                                               local_file_esc,
                                               cache_file_esc);
                }

                g_free (first_part);
                g_free (jpg_thumbnail);
                g_free (tiff_thumbnail);
                g_free (ppm_thumbnail);
            }
            else {
                /* -w option = camera-specified white balance */
                command = g_strdup_printf ("dcraw -w -c %s > %s",
                                           local_file_esc,
                                           cache_file_esc);
            }
        }

        if (is_hdr) {
            /* HDR files. We can use the pfssize tool to speed up
               thumbnail generation considerably, so we treat
               thumbnailing as a special case. */
            char *resize_command;

            if (is_thumbnail)
                resize_command = g_strdup_printf (" | pfssize --maxx %d --maxy %d",
                                                  requested_size,
                                                  requested_size);
            else
                resize_command = g_strdup_printf (" ");

            command = g_strconcat ( "pfsin ",
                                    local_file_esc,
                                    resize_command,
                                    " |  pfsclamp  --rgb  | pfstmo_drago03 | pfsout ",
                                    cache_file_esc,
                                    NULL );
            g_free (resize_command);
        }

        if (command != NULL) {
            if (system (command) == -1) {
                g_free (command);
                g_free (cache_file_esc);
                g_free (local_file_esc);
                g_free (cache_file);
                g_free (local_file);

                return NULL;
            }
            g_free (command);
        }
    }

    pixbuf = gdk_pixbuf_new_from_file (cache_file, NULL);

    /* Thumbnail files are already cached, so delete the conversion cache copies */
    if (is_thumbnail) {
        GFile *file;

        file = g_file_new_for_path (cache_file);
        g_file_delete (file, NULL, NULL);
        g_object_unref (file);
    }

    if (pixbuf != NULL) {
        image = gth_image_new_for_pixbuf (pixbuf);
        g_object_unref (pixbuf);
    }

    g_free (cache_file_esc);
    g_free (local_file_esc);
    g_free (cache_file);
    g_free (local_file);

    return image;
}