2006-12-10 05:33:38 +08:00
|
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-08-09 17:07:17 +08:00
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
2004-10-09 03:29:33 +08:00
|
|
|
|
* gimpimagefile.c
|
2002-04-30 01:20:26 +08:00
|
|
|
|
*
|
2004-02-28 00:27:06 +08:00
|
|
|
|
* Copyright (C) 2001-2004 Sven Neumann <sven@gimp.org>
|
2002-04-30 01:20:26 +08:00
|
|
|
|
* Michael Natterer <mitch@gimp.org>
|
2001-08-09 17:07:17 +08:00
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2001-11-27 11:52:11 +08:00
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
2003-04-04 23:11:30 +08:00
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2003-12-08 17:12:25 +08:00
|
|
|
|
#include "libgimpthumb/gimpthumb.h"
|
2002-04-30 01:20:26 +08:00
|
|
|
|
|
2001-08-09 17:07:17 +08:00
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
2002-11-19 04:50:31 +08:00
|
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
#include "gimp.h"
|
|
|
|
|
#include "gimpcontainer.h"
|
2004-04-15 07:37:34 +08:00
|
|
|
|
#include "gimpcontext.h"
|
2002-04-17 04:25:27 +08:00
|
|
|
|
#include "gimpimage.h"
|
2001-08-09 17:07:17 +08:00
|
|
|
|
#include "gimpimagefile.h"
|
2002-04-17 04:25:27 +08:00
|
|
|
|
#include "gimpmarshal.h"
|
2007-08-02 22:54:29 +08:00
|
|
|
|
#include "gimppickable.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
|
#include "gimpprogress.h"
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
|
|
|
|
#include "file/file-open.h"
|
2003-04-09 00:01:01 +08:00
|
|
|
|
#include "file/file-utils.h"
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
|
#include "gimp-intl.h"
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
INFO_CHANGED,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static void gimp_imagefile_finalize (GObject *object);
|
2005-12-11 03:24:36 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static void gimp_imagefile_name_changed (GimpObject *object);
|
2005-12-11 03:24:36 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static void gimp_imagefile_info_changed (GimpImagefile *imagefile);
|
|
|
|
|
static void gimp_imagefile_notify_thumbnail (GimpImagefile *imagefile,
|
|
|
|
|
GParamSpec *pspec);
|
2003-12-08 17:12:25 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static GdkPixbuf * gimp_imagefile_get_new_pixbuf (GimpViewable *viewable,
|
2006-08-30 05:44:51 +08:00
|
|
|
|
GimpContext *context,
|
2004-09-27 07:44:24 +08:00
|
|
|
|
gint width,
|
|
|
|
|
gint height);
|
|
|
|
|
static GdkPixbuf * gimp_imagefile_load_thumb (GimpImagefile *imagefile,
|
|
|
|
|
gint width,
|
|
|
|
|
gint height);
|
|
|
|
|
static gboolean gimp_imagefile_save_thumb (GimpImagefile *imagefile,
|
2006-03-29 01:08:36 +08:00
|
|
|
|
GimpImage *image,
|
2004-09-27 07:44:24 +08:00
|
|
|
|
gint size,
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gboolean replace,
|
2004-09-27 07:44:24 +08:00
|
|
|
|
GError **error);
|
2004-01-06 10:33:08 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static gchar * gimp_imagefile_get_description (GimpViewable *viewable,
|
|
|
|
|
gchar **tooltip);
|
2002-04-18 22:14:50 +08:00
|
|
|
|
|
2004-11-14 01:06:06 +08:00
|
|
|
|
static void gimp_thumbnail_set_info_from_image (GimpThumbnail *thumbnail,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
GimpImage *image);
|
|
|
|
|
static void gimp_thumbnail_set_info (GimpThumbnail *thumbnail,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
gint width,
|
|
|
|
|
gint height);
|
|
|
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
|
G_DEFINE_TYPE (GimpImagefile, gimp_imagefile, GIMP_TYPE_VIEWABLE)
|
2002-04-18 22:14:50 +08:00
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
|
#define parent_class gimp_imagefile_parent_class
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
|
static guint gimp_imagefile_signals[LAST_SIGNAL] = { 0 };
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_class_init (GimpImagefileClass *klass)
|
|
|
|
|
{
|
2004-08-11 22:00:08 +08:00
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
|
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gchar *creator;
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
gimp_imagefile_signals[INFO_CHANGED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
|
g_signal_new ("info-changed",
|
2004-08-11 22:00:08 +08:00
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GimpImagefileClass, info_changed),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2002-04-29 07:10:42 +08:00
|
|
|
|
object_class->finalize = gimp_imagefile_finalize;
|
|
|
|
|
|
|
|
|
|
gimp_object_class->name_changed = gimp_imagefile_name_changed;
|
|
|
|
|
|
2005-05-27 21:05:26 +08:00
|
|
|
|
viewable_class->name_changed_signal = "info-changed";
|
2004-09-27 07:44:24 +08:00
|
|
|
|
viewable_class->get_new_pixbuf = gimp_imagefile_get_new_pixbuf;
|
2003-04-09 00:01:01 +08:00
|
|
|
|
viewable_class->get_description = gimp_imagefile_get_description;
|
2002-04-17 07:03:23 +08:00
|
|
|
|
|
2004-01-06 10:33:08 +08:00
|
|
|
|
g_type_class_ref (GIMP_TYPE_IMAGE_TYPE);
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
creator = g_strdup_printf ("gimp-%d.%d",
|
|
|
|
|
GIMP_MAJOR_VERSION, GIMP_MINOR_VERSION);
|
2002-04-18 22:14:50 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gimp_thumb_init (creator, NULL);
|
2002-04-18 22:14:50 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
g_free (creator);
|
2001-08-09 17:07:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_init (GimpImagefile *imagefile)
|
|
|
|
|
{
|
2003-01-25 01:38:24 +08:00
|
|
|
|
imagefile->gimp = NULL;
|
2003-12-08 17:12:25 +08:00
|
|
|
|
imagefile->thumbnail = gimp_thumbnail_new ();
|
2002-04-17 07:59:53 +08:00
|
|
|
|
imagefile->description = NULL;
|
2004-01-06 10:33:08 +08:00
|
|
|
|
|
|
|
|
|
g_signal_connect_object (imagefile->thumbnail, "notify",
|
|
|
|
|
G_CALLBACK (gimp_imagefile_notify_thumbnail),
|
|
|
|
|
imagefile, G_CONNECT_SWAPPED);
|
2001-08-09 17:07:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2002-04-17 07:59:53 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_finalize (GObject *object)
|
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
GimpImagefile *imagefile = GIMP_IMAGEFILE (object);
|
|
|
|
|
|
|
|
|
|
if (imagefile->description)
|
|
|
|
|
{
|
|
|
|
|
if (! imagefile->static_desc)
|
|
|
|
|
g_free (imagefile->description);
|
2002-04-17 07:59:53 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
imagefile->description = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (imagefile->thumbnail)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (imagefile->thumbnail);
|
|
|
|
|
imagefile->thumbnail = NULL;
|
|
|
|
|
}
|
2003-11-14 23:33:40 +08:00
|
|
|
|
|
2002-04-17 07:59:53 +08:00
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-09 17:07:17 +08:00
|
|
|
|
GimpImagefile *
|
2003-01-25 01:38:24 +08:00
|
|
|
|
gimp_imagefile_new (Gimp *gimp,
|
|
|
|
|
const gchar *uri)
|
2001-08-09 17:07:17 +08:00
|
|
|
|
{
|
|
|
|
|
GimpImagefile *imagefile;
|
|
|
|
|
|
2003-01-25 01:38:24 +08:00
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
|
2003-03-12 05:04:09 +08:00
|
|
|
|
imagefile = g_object_new (GIMP_TYPE_IMAGEFILE, NULL);
|
2001-08-11 15:47:35 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
imagefile->gimp = gimp;
|
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
if (uri)
|
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (imagefile), uri);
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
|
|
|
|
return imagefile;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
void
|
2004-01-11 07:55:28 +08:00
|
|
|
|
gimp_imagefile_update (GimpImagefile *imagefile)
|
2002-04-17 04:25:27 +08:00
|
|
|
|
{
|
2004-01-06 10:33:08 +08:00
|
|
|
|
gchar *uri;
|
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
|
|
|
|
|
|
2002-04-17 07:03:23 +08:00
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (imagefile));
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2004-01-06 10:33:08 +08:00
|
|
|
|
g_object_get (imagefile->thumbnail,
|
|
|
|
|
"image-uri", &uri,
|
|
|
|
|
NULL);
|
2003-12-08 17:12:25 +08:00
|
|
|
|
|
2002-04-17 07:03:23 +08:00
|
|
|
|
if (uri)
|
|
|
|
|
{
|
2004-01-11 07:55:28 +08:00
|
|
|
|
GimpImagefile *documents_imagefile = (GimpImagefile *)
|
2003-01-25 01:38:24 +08:00
|
|
|
|
gimp_container_get_child_by_name (imagefile->gimp->documents, uri);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2004-01-11 07:55:28 +08:00
|
|
|
|
if (documents_imagefile != imagefile &&
|
|
|
|
|
GIMP_IS_IMAGEFILE (documents_imagefile))
|
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (documents_imagefile));
|
2004-01-06 10:33:08 +08:00
|
|
|
|
|
|
|
|
|
g_free (uri);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2002-04-30 03:59:02 +08:00
|
|
|
|
gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
|
2004-04-15 07:37:34 +08:00
|
|
|
|
GimpContext *context,
|
2004-08-11 02:47:21 +08:00
|
|
|
|
GimpProgress *progress,
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gint size,
|
|
|
|
|
gboolean replace)
|
2002-04-17 04:25:27 +08:00
|
|
|
|
{
|
2005-02-09 08:47:09 +08:00
|
|
|
|
GimpThumbnail *thumbnail;
|
|
|
|
|
GimpThumbState image_state;
|
2004-03-03 23:30:48 +08:00
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
|
2004-04-15 07:37:34 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_CONTEXT (context));
|
2004-08-11 02:47:21 +08:00
|
|
|
|
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (size < 1)
|
2002-04-30 03:41:45 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2004-03-03 23:30:48 +08:00
|
|
|
|
thumbnail = imagefile->thumbnail;
|
|
|
|
|
|
|
|
|
|
gimp_thumbnail_set_uri (thumbnail,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gimp_object_get_name (GIMP_OBJECT (imagefile)));
|
2002-04-30 09:40:44 +08:00
|
|
|
|
|
2005-02-09 08:47:09 +08:00
|
|
|
|
image_state = gimp_thumbnail_peek_image (thumbnail);
|
|
|
|
|
|
|
|
|
|
if (image_state == GIMP_THUMB_STATE_REMOTE ||
|
|
|
|
|
image_state >= GIMP_THUMB_STATE_EXISTS)
|
2002-04-17 04:25:27 +08:00
|
|
|
|
{
|
2004-11-14 01:06:06 +08:00
|
|
|
|
GimpImage *image;
|
|
|
|
|
gboolean success;
|
|
|
|
|
gint width = 0;
|
|
|
|
|
gint height = 0;
|
|
|
|
|
const gchar *mime_type = NULL;
|
|
|
|
|
GError *error = NULL;
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2004-10-13 07:25:19 +08:00
|
|
|
|
g_object_ref (imagefile);
|
|
|
|
|
|
2004-11-14 01:06:06 +08:00
|
|
|
|
image = file_open_thumbnail (imagefile->gimp, context, progress,
|
|
|
|
|
thumbnail->image_uri, size,
|
2007-12-03 02:05:54 +08:00
|
|
|
|
&mime_type, &width, &height, NULL);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2004-11-14 01:06:06 +08:00
|
|
|
|
if (image)
|
2002-04-17 04:25:27 +08:00
|
|
|
|
{
|
2004-11-14 01:06:06 +08:00
|
|
|
|
gimp_thumbnail_set_info (imagefile->thumbnail,
|
|
|
|
|
mime_type, width, height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GimpPDBStatusType status;
|
|
|
|
|
|
|
|
|
|
image = file_open_image (imagefile->gimp, context, progress,
|
2007-04-17 23:54:01 +08:00
|
|
|
|
thumbnail->image_uri,
|
|
|
|
|
thumbnail->image_uri,
|
|
|
|
|
FALSE, NULL, GIMP_RUN_NONINTERACTIVE,
|
2004-11-14 01:06:06 +08:00
|
|
|
|
&status, &mime_type, NULL);
|
|
|
|
|
|
|
|
|
|
if (image)
|
|
|
|
|
gimp_thumbnail_set_info_from_image (imagefile->thumbnail,
|
|
|
|
|
mime_type, image);
|
|
|
|
|
}
|
2004-05-14 08:01:11 +08:00
|
|
|
|
|
2004-11-14 01:06:06 +08:00
|
|
|
|
if (image)
|
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
success = gimp_imagefile_save_thumb (imagefile,
|
2004-11-14 01:06:06 +08:00
|
|
|
|
image, size, replace,
|
|
|
|
|
&error);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2004-11-14 01:06:06 +08:00
|
|
|
|
g_object_unref (image);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
}
|
2002-04-29 07:10:42 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2004-03-03 23:30:48 +08:00
|
|
|
|
success = gimp_thumbnail_save_failure (thumbnail,
|
2006-12-10 05:49:23 +08:00
|
|
|
|
"GIMP " GIMP_VERSION,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
&error);
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gimp_imagefile_update (imagefile);
|
2002-04-29 07:10:42 +08:00
|
|
|
|
}
|
2002-04-30 01:20:26 +08:00
|
|
|
|
|
2004-10-13 07:25:19 +08:00
|
|
|
|
g_object_unref (imagefile);
|
|
|
|
|
|
2004-10-23 23:30:39 +08:00
|
|
|
|
if (! success)
|
2003-12-08 17:12:25 +08:00
|
|
|
|
{
|
2006-10-09 16:17:22 +08:00
|
|
|
|
gimp_message (imagefile->gimp, G_OBJECT (progress),
|
2006-10-10 02:49:15 +08:00
|
|
|
|
GIMP_MESSAGE_ERROR,
|
|
|
|
|
"%s", error->message);
|
|
|
|
|
g_clear_error (&error);
|
2003-12-08 17:12:25 +08:00
|
|
|
|
}
|
2002-04-30 01:20:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-13 07:25:19 +08:00
|
|
|
|
/* The weak version doesn't ref the imagefile but deals gracefully
|
|
|
|
|
* with an imagefile that is destroyed while the thumbnail is
|
|
|
|
|
* created. Thia allows to use this function w/o the need to block
|
2004-10-23 23:30:39 +08:00
|
|
|
|
* the user interface.
|
2004-10-13 07:25:19 +08:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gimp_imagefile_create_thumbnail_weak (GimpImagefile *imagefile,
|
|
|
|
|
GimpContext *context,
|
|
|
|
|
GimpProgress *progress,
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gint size,
|
|
|
|
|
gboolean replace)
|
2004-10-13 07:25:19 +08:00
|
|
|
|
{
|
|
|
|
|
GimpImagefile *local;
|
|
|
|
|
const gchar *uri;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
|
|
|
|
|
|
|
|
|
|
if (size < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
|
|
|
|
|
if (!uri)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
local = gimp_imagefile_new (imagefile->gimp, uri);
|
|
|
|
|
|
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (imagefile), (gpointer) &imagefile);
|
|
|
|
|
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gimp_imagefile_create_thumbnail (local, context, progress, size, replace);
|
2004-10-13 07:25:19 +08:00
|
|
|
|
|
|
|
|
|
if (imagefile)
|
|
|
|
|
{
|
|
|
|
|
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
|
|
|
|
|
|
|
|
|
|
if (uri &&
|
|
|
|
|
strcmp (uri, gimp_object_get_name (GIMP_OBJECT (local))) == 0)
|
|
|
|
|
{
|
|
|
|
|
gimp_imagefile_update (imagefile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (imagefile),
|
|
|
|
|
(gpointer) &imagefile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (local);
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gboolean
|
|
|
|
|
gimp_imagefile_check_thumbnail (GimpImagefile *imagefile)
|
|
|
|
|
{
|
|
|
|
|
gint size;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), FALSE);
|
|
|
|
|
|
|
|
|
|
size = imagefile->gimp->config->thumbnail_size;
|
|
|
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
|
{
|
|
|
|
|
GimpThumbState state;
|
|
|
|
|
|
|
|
|
|
state = gimp_thumbnail_check_thumb (imagefile->thumbnail, size);
|
|
|
|
|
|
|
|
|
|
return (state == GIMP_THUMB_STATE_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-20 01:15:39 +08:00
|
|
|
|
gboolean
|
2002-04-30 04:27:54 +08:00
|
|
|
|
gimp_imagefile_save_thumbnail (GimpImagefile *imagefile,
|
2004-11-14 01:13:21 +08:00
|
|
|
|
const gchar *mime_type,
|
2006-03-29 01:08:36 +08:00
|
|
|
|
GimpImage *image)
|
2002-04-19 20:05:47 +08:00
|
|
|
|
{
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gint size;
|
|
|
|
|
gboolean success = TRUE;
|
|
|
|
|
GError *error = NULL;
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2002-04-20 01:15:39 +08:00
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), FALSE);
|
2006-03-29 01:08:36 +08:00
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
2002-04-30 03:41:45 +08:00
|
|
|
|
|
2004-10-23 23:30:39 +08:00
|
|
|
|
size = imagefile->gimp->config->thumbnail_size;
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2004-10-23 23:30:39 +08:00
|
|
|
|
if (size > 0)
|
2002-04-19 20:05:47 +08:00
|
|
|
|
{
|
2004-11-14 01:13:21 +08:00
|
|
|
|
gimp_thumbnail_set_info_from_image (imagefile->thumbnail,
|
2006-03-29 01:08:36 +08:00
|
|
|
|
mime_type, image);
|
2004-10-23 23:30:39 +08:00
|
|
|
|
|
|
|
|
|
success = gimp_imagefile_save_thumb (imagefile,
|
2006-03-29 01:08:36 +08:00
|
|
|
|
image, size, FALSE,
|
2004-10-23 23:30:39 +08:00
|
|
|
|
&error);
|
|
|
|
|
if (! success)
|
|
|
|
|
{
|
2006-10-10 02:49:15 +08:00
|
|
|
|
gimp_message (imagefile->gimp, NULL, GIMP_MESSAGE_ERROR,
|
|
|
|
|
"%s", error->message);
|
|
|
|
|
g_clear_error (&error);
|
2004-10-23 23:30:39 +08:00
|
|
|
|
}
|
2003-04-02 19:26:02 +08:00
|
|
|
|
}
|
2002-04-20 01:15:39 +08:00
|
|
|
|
|
|
|
|
|
return success;
|
2002-04-17 04:25:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-18 09:28:12 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_name_changed (GimpObject *object)
|
2001-11-23 07:46:13 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
GimpImagefile *imagefile = GIMP_IMAGEFILE (object);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2002-02-18 09:28:12 +08:00
|
|
|
|
if (GIMP_OBJECT_CLASS (parent_class)->name_changed)
|
|
|
|
|
GIMP_OBJECT_CLASS (parent_class)->name_changed (object);
|
|
|
|
|
|
2004-02-26 01:33:45 +08:00
|
|
|
|
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), NULL);
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gimp_thumbnail_set_uri (imagefile->thumbnail, gimp_object_get_name (object));
|
2001-11-13 11:31:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-06 22:29:35 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_info_changed (GimpImagefile *imagefile)
|
|
|
|
|
{
|
|
|
|
|
if (imagefile->description)
|
|
|
|
|
{
|
|
|
|
|
if (! imagefile->static_desc)
|
|
|
|
|
g_free (imagefile->description);
|
|
|
|
|
|
|
|
|
|
imagefile->description = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_signal_emit (imagefile, gimp_imagefile_signals[INFO_CHANGED], 0);
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-06 10:33:08 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_imagefile_notify_thumbnail (GimpImagefile *imagefile,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (pspec->name, "image-state") == 0 ||
|
|
|
|
|
strcmp (pspec->name, "thumb-state") == 0)
|
|
|
|
|
{
|
2004-01-06 22:29:35 +08:00
|
|
|
|
gimp_imagefile_info_changed (imagefile);
|
2004-01-06 10:33:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static GdkPixbuf *
|
|
|
|
|
gimp_imagefile_get_new_pixbuf (GimpViewable *viewable,
|
2006-08-30 05:44:51 +08:00
|
|
|
|
GimpContext *context,
|
2004-09-27 07:44:24 +08:00
|
|
|
|
gint width,
|
|
|
|
|
gint height)
|
2001-08-09 17:07:17 +08:00
|
|
|
|
{
|
2004-03-03 23:30:48 +08:00
|
|
|
|
GimpImagefile *imagefile = GIMP_IMAGEFILE (viewable);
|
2004-09-27 07:44:24 +08:00
|
|
|
|
GdkPixbuf *pixbuf;
|
2005-06-18 22:16:26 +08:00
|
|
|
|
const gchar *stock_id = NULL;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2002-02-18 09:28:12 +08:00
|
|
|
|
if (! GIMP_OBJECT (imagefile)->name)
|
|
|
|
|
return NULL;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
pixbuf = gimp_imagefile_load_thumb (imagefile, width, height);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2005-06-18 22:16:26 +08:00
|
|
|
|
switch (imagefile->thumbnail->image_state)
|
2003-02-27 00:15:50 +08:00
|
|
|
|
{
|
2005-06-18 22:16:26 +08:00
|
|
|
|
case GIMP_THUMB_STATE_REMOTE:
|
|
|
|
|
stock_id = "gtk-network";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_THUMB_STATE_FOLDER:
|
2005-09-19 20:24:29 +08:00
|
|
|
|
stock_id = "gtk-directory";
|
2005-06-18 22:16:26 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_THUMB_STATE_SPECIAL:
|
|
|
|
|
stock_id = "gtk-harddisk";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_THUMB_STATE_NOT_FOUND:
|
2006-03-31 17:44:20 +08:00
|
|
|
|
stock_id = "gtk-dialog-question";
|
2005-06-18 22:16:26 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2003-02-27 00:15:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-18 22:16:26 +08:00
|
|
|
|
gimp_viewable_set_stock_id (GIMP_VIEWABLE (imagefile), stock_id);
|
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
return pixbuf;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-09 00:01:01 +08:00
|
|
|
|
static gchar *
|
|
|
|
|
gimp_imagefile_get_description (GimpViewable *viewable,
|
|
|
|
|
gchar **tooltip)
|
|
|
|
|
{
|
2004-03-03 23:30:48 +08:00
|
|
|
|
GimpImagefile *imagefile = GIMP_IMAGEFILE (viewable);
|
|
|
|
|
GimpThumbnail *thumbnail = imagefile->thumbnail;
|
2003-04-09 00:01:01 +08:00
|
|
|
|
gchar *basename;
|
|
|
|
|
|
2003-12-08 22:15:25 +08:00
|
|
|
|
if (! thumbnail->image_uri)
|
|
|
|
|
return NULL;
|
2003-04-09 00:01:01 +08:00
|
|
|
|
|
|
|
|
|
if (tooltip)
|
|
|
|
|
{
|
|
|
|
|
gchar *filename;
|
|
|
|
|
const gchar *desc;
|
|
|
|
|
|
2005-10-02 06:43:22 +08:00
|
|
|
|
filename = file_utils_uri_display_name (thumbnail->image_uri);
|
2003-04-09 00:01:01 +08:00
|
|
|
|
desc = gimp_imagefile_get_desc_string (imagefile);
|
|
|
|
|
|
|
|
|
|
if (desc)
|
|
|
|
|
{
|
|
|
|
|
*tooltip = g_strdup_printf ("%s\n%s", filename, desc);
|
|
|
|
|
g_free (filename);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*tooltip = filename;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-02 06:43:22 +08:00
|
|
|
|
basename = file_utils_uri_display_basename (thumbnail->image_uri);
|
2003-12-08 17:12:25 +08:00
|
|
|
|
|
|
|
|
|
if (thumbnail->image_width > 0 && thumbnail->image_height > 0)
|
2003-04-09 00:01:01 +08:00
|
|
|
|
{
|
|
|
|
|
gchar *tmp = basename;
|
|
|
|
|
|
2006-02-28 20:15:51 +08:00
|
|
|
|
basename = g_strdup_printf ("%s (%d × %d)",
|
2003-04-09 00:01:01 +08:00
|
|
|
|
tmp,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
thumbnail->image_width,
|
|
|
|
|
thumbnail->image_height);
|
2003-04-09 00:01:01 +08:00
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return basename;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-17 07:59:53 +08:00
|
|
|
|
const gchar *
|
2003-04-09 00:01:01 +08:00
|
|
|
|
gimp_imagefile_get_desc_string (GimpImagefile *imagefile)
|
2002-04-17 07:59:53 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
GimpThumbnail *thumbnail;
|
|
|
|
|
|
2002-04-17 07:59:53 +08:00
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), NULL);
|
|
|
|
|
|
|
|
|
|
if (imagefile->description)
|
|
|
|
|
return (const gchar *) imagefile->description;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
thumbnail = imagefile->thumbnail;
|
|
|
|
|
|
|
|
|
|
switch (thumbnail->image_state)
|
2002-04-17 07:59:53 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_UNKNOWN:
|
2002-04-29 07:10:42 +08:00
|
|
|
|
imagefile->description = NULL;
|
|
|
|
|
imagefile->static_desc = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
2004-02-26 01:33:45 +08:00
|
|
|
|
case GIMP_THUMB_STATE_FOLDER:
|
|
|
|
|
imagefile->description = _("Folder");
|
|
|
|
|
imagefile->static_desc = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_THUMB_STATE_SPECIAL:
|
|
|
|
|
imagefile->description = _("Special File");
|
|
|
|
|
imagefile->static_desc = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_NOT_FOUND:
|
2004-03-03 23:30:48 +08:00
|
|
|
|
imagefile->description =
|
|
|
|
|
(gchar *) g_strerror (thumbnail->image_not_found_errno);
|
2002-04-29 07:10:42 +08:00
|
|
|
|
imagefile->static_desc = TRUE;
|
2002-04-17 07:59:53 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2002-04-29 07:10:42 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
GString *str = g_string_new (NULL);
|
2002-04-29 07:10:42 +08:00
|
|
|
|
|
2005-02-09 08:47:09 +08:00
|
|
|
|
if (thumbnail->image_state == GIMP_THUMB_STATE_REMOTE)
|
|
|
|
|
{
|
|
|
|
|
g_string_append (str, _("Remote File"));
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (thumbnail->image_filesize > 0)
|
2002-04-29 07:10:42 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gchar *size = gimp_memsize_to_string (thumbnail->image_filesize);
|
2002-04-29 07:10:42 +08:00
|
|
|
|
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
|
|
|
|
|
2002-04-29 07:10:42 +08:00
|
|
|
|
g_string_append (str, size);
|
|
|
|
|
g_free (size);
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
switch (thumbnail->thumb_state)
|
2002-04-29 07:10:42 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_NOT_FOUND:
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
2004-10-25 06:30:52 +08:00
|
|
|
|
g_string_append (str, _("Click to create preview"));
|
2002-04-30 01:20:26 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_EXISTS:
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
2005-10-01 01:50:50 +08:00
|
|
|
|
g_string_append (str, _("Loading preview..."));
|
2002-04-29 07:10:42 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_OLD:
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
2002-04-30 01:20:26 +08:00
|
|
|
|
g_string_append (str, _("Preview is out of date"));
|
2002-04-29 07:10:42 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_FAILED:
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
2002-04-30 01:20:26 +08:00
|
|
|
|
g_string_append (str, _("Cannot create preview"));
|
2002-04-29 07:10:42 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
case GIMP_THUMB_STATE_OK:
|
2002-04-30 01:20:26 +08:00
|
|
|
|
{
|
2005-02-09 08:47:09 +08:00
|
|
|
|
if (thumbnail->image_state == GIMP_THUMB_STATE_REMOTE)
|
|
|
|
|
{
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
|
|
|
|
|
2005-02-09 08:47:09 +08:00
|
|
|
|
g_string_append (str, _("(Preview may be out of date)"));
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (thumbnail->image_width > 0 && thumbnail->image_height > 0)
|
2002-04-30 01:20:26 +08:00
|
|
|
|
{
|
2007-05-20 04:09:56 +08:00
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
|
|
|
|
|
2005-11-03 00:07:07 +08:00
|
|
|
|
g_string_append_printf (str,
|
2006-02-28 20:15:51 +08:00
|
|
|
|
ngettext ("%d × %d pixel",
|
|
|
|
|
"%d × %d pixels",
|
2005-11-03 00:07:07 +08:00
|
|
|
|
thumbnail->image_height),
|
2003-12-08 17:12:25 +08:00
|
|
|
|
thumbnail->image_width,
|
|
|
|
|
thumbnail->image_height);
|
2002-04-30 01:20:26 +08:00
|
|
|
|
}
|
2003-11-14 23:33:40 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (thumbnail->image_type)
|
2007-05-20 04:09:56 +08:00
|
|
|
|
{
|
|
|
|
|
if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
|
|
|
|
|
|
|
|
|
g_string_append (str, gettext (thumbnail->image_type));
|
|
|
|
|
}
|
2002-04-30 01:20:26 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (thumbnail->image_num_layers > 0)
|
2002-04-30 01:20:26 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (thumbnail->image_type)
|
2002-04-30 01:20:26 +08:00
|
|
|
|
g_string_append_len (str, ", ", 2);
|
2007-05-20 04:09:56 +08:00
|
|
|
|
else if (str->len > 0)
|
|
|
|
|
g_string_append_c (str, '\n');
|
2002-04-30 01:20:26 +08:00
|
|
|
|
|
2005-09-21 07:09:51 +08:00
|
|
|
|
g_string_append_printf (str,
|
2005-09-21 07:15:57 +08:00
|
|
|
|
ngettext ("%d layer",
|
|
|
|
|
"%d layers",
|
2005-09-21 07:09:51 +08:00
|
|
|
|
thumbnail->image_num_layers),
|
|
|
|
|
thumbnail->image_num_layers);
|
2002-04-30 01:20:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-04-29 07:10:42 +08:00
|
|
|
|
break;
|
2003-11-14 23:33:40 +08:00
|
|
|
|
|
2002-04-29 07:10:42 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imagefile->description = g_string_free (str, FALSE);
|
2002-04-30 01:20:26 +08:00
|
|
|
|
imagefile->static_desc = FALSE;
|
2002-04-29 07:10:42 +08:00
|
|
|
|
}
|
2002-04-17 07:59:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (const gchar *) imagefile->description;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
static GdkPixbuf *
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gimp_imagefile_load_thumb (GimpImagefile *imagefile,
|
2004-03-03 23:30:48 +08:00
|
|
|
|
gint width,
|
|
|
|
|
gint height)
|
2001-11-13 11:31:47 +08:00
|
|
|
|
{
|
2004-03-03 23:30:48 +08:00
|
|
|
|
GimpThumbnail *thumbnail = imagefile->thumbnail;
|
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
gint size = MAX (width, height);
|
|
|
|
|
gint pixbuf_width;
|
|
|
|
|
gint pixbuf_height;
|
|
|
|
|
gint preview_width;
|
|
|
|
|
gint preview_height;
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (gimp_thumbnail_peek_thumb (thumbnail, size) < GIMP_THUMB_STATE_EXISTS)
|
|
|
|
|
return NULL;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2005-06-15 18:57:33 +08:00
|
|
|
|
if (thumbnail->image_state == GIMP_THUMB_STATE_NOT_FOUND)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
pixbuf = gimp_thumbnail_load_thumb (thumbnail, size, &error);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2004-03-03 23:30:48 +08:00
|
|
|
|
if (! pixbuf)
|
2001-11-13 11:31:47 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (error)
|
2004-09-27 07:44:24 +08:00
|
|
|
|
{
|
2006-10-10 02:49:15 +08:00
|
|
|
|
gimp_message (imagefile->gimp, NULL, GIMP_MESSAGE_ERROR,
|
|
|
|
|
_("Could not open thumbnail '%s': %s"),
|
|
|
|
|
thumbnail->thumb_filename, error->message);
|
|
|
|
|
g_clear_error (&error);
|
2004-09-27 07:44:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
}
|
2002-04-29 07:10:42 +08:00
|
|
|
|
|
2004-03-03 23:30:48 +08:00
|
|
|
|
pixbuf_width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
|
pixbuf_height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
|
|
|
|
|
|
gimp_viewable_calc_preview_size (pixbuf_width,
|
|
|
|
|
pixbuf_height,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
TRUE, 1.0, 1.0,
|
|
|
|
|
&preview_width,
|
|
|
|
|
&preview_height,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (preview_width < pixbuf_width || preview_height < pixbuf_height)
|
|
|
|
|
{
|
2004-09-27 07:44:24 +08:00
|
|
|
|
GdkPixbuf *scaled = gdk_pixbuf_scale_simple (pixbuf,
|
|
|
|
|
preview_width,
|
|
|
|
|
preview_height,
|
|
|
|
|
GDK_INTERP_BILINEAR);
|
2004-03-03 23:30:48 +08:00
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
pixbuf = scaled;
|
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
pixbuf_width = preview_width;
|
|
|
|
|
pixbuf_height = preview_height;
|
2004-03-03 23:30:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
if (gdk_pixbuf_get_n_channels (pixbuf) != 3)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf *tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
|
|
|
|
|
pixbuf_width, pixbuf_height);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
gdk_pixbuf_composite_color (pixbuf, tmp,
|
|
|
|
|
0, 0, pixbuf_width, pixbuf_height,
|
|
|
|
|
0.0, 0.0, 1.0, 1.0,
|
|
|
|
|
GDK_INTERP_NEAREST, 255,
|
|
|
|
|
0, 0, GIMP_CHECK_SIZE_SM,
|
|
|
|
|
0x66666666, 0x99999999);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
pixbuf = tmp;
|
|
|
|
|
}
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
2004-09-27 07:44:24 +08:00
|
|
|
|
return pixbuf;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2002-04-20 01:15:39 +08:00
|
|
|
|
static gboolean
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gimp_imagefile_save_thumb (GimpImagefile *imagefile,
|
2006-03-29 01:08:36 +08:00
|
|
|
|
GimpImage *image,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
gint size,
|
2004-10-23 23:30:39 +08:00
|
|
|
|
gboolean replace,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
GError **error)
|
2002-04-19 20:05:47 +08:00
|
|
|
|
{
|
2004-02-28 00:27:06 +08:00
|
|
|
|
GimpThumbnail *thumbnail = imagefile->thumbnail;
|
2004-01-06 10:33:08 +08:00
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
gint width, height;
|
|
|
|
|
gboolean success = FALSE;
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2003-12-25 20:10:26 +08:00
|
|
|
|
if (size < 1)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
|
if (image->width <= size && image->height <= size)
|
2002-04-19 20:05:47 +08:00
|
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
|
width = image->width;
|
|
|
|
|
height = image->height;
|
2002-04-30 04:27:54 +08:00
|
|
|
|
|
2004-11-03 03:36:23 +08:00
|
|
|
|
size = MAX (width, height);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
|
if (image->width < image->height)
|
2002-04-19 20:05:47 +08:00
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
height = size;
|
2006-03-29 01:08:36 +08:00
|
|
|
|
width = MAX (1, (size * image->width) / image->height);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
|
width = size;
|
2006-03-29 01:08:36 +08:00
|
|
|
|
height = MAX (1, (size * image->height) / image->width);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-02 22:54:29 +08:00
|
|
|
|
/* we need the projection constructed NOW, not some time later */
|
|
|
|
|
gimp_pickable_flush (GIMP_PICKABLE (image->projection));
|
|
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
|
pixbuf = gimp_viewable_get_new_pixbuf (GIMP_VIEWABLE (image),
|
|
|
|
|
/* random context, unused */
|
|
|
|
|
gimp_get_user_context (image->gimp),
|
|
|
|
|
width, height);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2003-12-27 06:09:09 +08:00
|
|
|
|
/* when layer previews are disabled, we won't get a pixbuf */
|
|
|
|
|
if (! pixbuf)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2004-02-28 00:27:06 +08:00
|
|
|
|
success = gimp_thumbnail_save_thumb (thumbnail,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
pixbuf,
|
2006-12-10 05:49:23 +08:00
|
|
|
|
"GIMP " GIMP_VERSION,
|
2003-12-08 17:12:25 +08:00
|
|
|
|
error);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
|
g_object_unref (pixbuf);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
|
if (success)
|
2004-10-23 23:30:39 +08:00
|
|
|
|
{
|
|
|
|
|
if (replace)
|
|
|
|
|
gimp_thumbnail_delete_others (thumbnail, size);
|
|
|
|
|
else
|
|
|
|
|
gimp_thumbnail_delete_failure (thumbnail);
|
|
|
|
|
|
|
|
|
|
gimp_imagefile_update (imagefile);
|
|
|
|
|
}
|
2002-04-20 01:15:39 +08:00
|
|
|
|
|
|
|
|
|
return success;
|
2002-04-19 20:05:47 +08:00
|
|
|
|
}
|
2004-11-14 01:06:06 +08:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_thumbnail_set_info_from_image (GimpThumbnail *thumbnail,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
GimpImage *image)
|
|
|
|
|
{
|
|
|
|
|
GimpEnumDesc *desc;
|
|
|
|
|
GimpImageType type;
|
|
|
|
|
|
|
|
|
|
/* peek the thumbnail to make sure that mtime and filesize are set */
|
|
|
|
|
gimp_thumbnail_peek_image (thumbnail);
|
|
|
|
|
|
|
|
|
|
type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (gimp_image_base_type (image));
|
|
|
|
|
|
|
|
|
|
if (gimp_image_has_alpha (image))
|
|
|
|
|
type = GIMP_IMAGE_TYPE_WITH_ALPHA (type);
|
|
|
|
|
|
|
|
|
|
desc = gimp_enum_get_desc (g_type_class_peek (GIMP_TYPE_IMAGE_TYPE), type);
|
|
|
|
|
|
|
|
|
|
g_object_set (thumbnail,
|
|
|
|
|
"image-mimetype", mime_type,
|
|
|
|
|
"image-width", gimp_image_get_width (image),
|
|
|
|
|
"image-height", gimp_image_get_height (image),
|
|
|
|
|
"image-type", desc->value_desc,
|
|
|
|
|
"image-num-layers", gimp_container_num_children (image->layers),
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_thumbnail_set_info (GimpThumbnail *thumbnail,
|
|
|
|
|
const gchar *mime_type,
|
|
|
|
|
gint width,
|
|
|
|
|
gint height)
|
|
|
|
|
{
|
|
|
|
|
/* peek the thumbnail to make sure that mtime and filesize are set */
|
|
|
|
|
gimp_thumbnail_peek_image (thumbnail);
|
|
|
|
|
|
|
|
|
|
g_object_set (thumbnail,
|
|
|
|
|
"image-mimetype", mime_type,
|
|
|
|
|
"image-width", width,
|
|
|
|
|
"image-height", height,
|
|
|
|
|
"image-type", NULL,
|
|
|
|
|
"image-num-layers", NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|