2001-08-09 17:07:17 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpfileimage.c
|
2002-04-30 01:20:26 +08:00
|
|
|
*
|
2003-04-04 23:11:30 +08:00
|
|
|
* Copyright (C) 2001-2003 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"
|
|
|
|
|
|
|
|
#include "base/temp-buf.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"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
#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-01-06 10:33:08 +08:00
|
|
|
static void gimp_imagefile_class_init (GimpImagefileClass *klass);
|
|
|
|
static void gimp_imagefile_init (GimpImagefile *imagefile);
|
|
|
|
static void gimp_imagefile_finalize (GObject *object);
|
|
|
|
static void gimp_imagefile_name_changed (GimpObject *object);
|
2004-01-06 22:29:35 +08:00
|
|
|
static void gimp_imagefile_info_changed (GimpImagefile *imagefile);
|
2004-01-06 10:33:08 +08:00
|
|
|
static void gimp_imagefile_notify_thumbnail (GimpImagefile *imagefile,
|
|
|
|
GParamSpec *pspec);
|
2003-12-08 17:12:25 +08:00
|
|
|
|
2004-01-06 10:33:08 +08:00
|
|
|
static TempBuf * gimp_imagefile_get_new_preview (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
2004-01-06 22:29:35 +08:00
|
|
|
static TempBuf * gimp_imagefile_load_thumb (GimpImagefile *imagefile,
|
2004-01-06 10:33:08 +08:00
|
|
|
gint size);
|
|
|
|
static gboolean gimp_imagefile_save_thumb (GimpImagefile *imagefile,
|
|
|
|
GimpImage *gimage,
|
|
|
|
gint size,
|
|
|
|
GError **error);
|
|
|
|
|
|
|
|
static gchar * gimp_imagefile_get_description (GimpViewable *viewable,
|
|
|
|
gchar **tooltip);
|
2002-04-18 22:14:50 +08:00
|
|
|
|
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
static guint gimp_imagefile_signals[LAST_SIGNAL] = { 0 };
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
|
|
static GimpViewableClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_imagefile_get_type (void)
|
|
|
|
{
|
|
|
|
static GType imagefile_type = 0;
|
|
|
|
|
|
|
|
if (!imagefile_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo imagefile_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpImagefileClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_imagefile_class_init,
|
2002-04-18 22:14:50 +08:00
|
|
|
NULL, /* class_finalize */
|
2001-08-09 17:07:17 +08:00
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpImagefile),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_imagefile_init,
|
|
|
|
};
|
|
|
|
|
2001-08-11 15:47:35 +08:00
|
|
|
imagefile_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
|
2003-11-14 23:33:40 +08:00
|
|
|
"GimpImagefile",
|
2001-08-09 17:07:17 +08:00
|
|
|
&imagefile_info, 0);
|
|
|
|
}
|
2003-11-14 23:33:40 +08:00
|
|
|
|
2001-08-09 17:07:17 +08:00
|
|
|
return imagefile_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_imagefile_class_init (GimpImagefileClass *klass)
|
|
|
|
{
|
2002-04-17 07:59:53 +08:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpObjectClass *gimp_object_class;
|
2001-08-09 17:07:17 +08:00
|
|
|
GimpViewableClass *viewable_class;
|
2003-12-08 17:12:25 +08:00
|
|
|
gchar *creator;
|
2001-08-09 17:07:17 +08:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2002-04-17 07:59:53 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
2001-08-09 17:07:17 +08:00
|
|
|
|
2002-04-17 04:25:27 +08:00
|
|
|
gimp_imagefile_signals[INFO_CHANGED] =
|
|
|
|
g_signal_new ("info_changed",
|
|
|
|
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-29 07:10:42 +08:00
|
|
|
object_class->finalize = gimp_imagefile_finalize;
|
|
|
|
|
|
|
|
gimp_object_class->name_changed = gimp_imagefile_name_changed;
|
|
|
|
|
|
|
|
viewable_class->name_changed_signal = "info_changed";
|
|
|
|
viewable_class->get_new_preview = gimp_imagefile_get_new_preview;
|
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,
|
2003-12-08 17:12:25 +08:00
|
|
|
gint size)
|
2002-04-17 04:25:27 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
|
|
|
|
|
2003-03-12 05:04:09 +08:00
|
|
|
if (! imagefile->gimp->config->layer_previews)
|
|
|
|
return;
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
if (size < 1)
|
2002-04-30 03:41:45 +08:00
|
|
|
return;
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
gimp_thumbnail_set_uri (imagefile->thumbnail,
|
|
|
|
gimp_object_get_name (GIMP_OBJECT (imagefile)));
|
2002-04-30 09:40:44 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
if (gimp_thumbnail_peek_image (imagefile->thumbnail) >= GIMP_THUMB_STATE_EXISTS)
|
2002-04-17 04:25:27 +08:00
|
|
|
{
|
2002-04-29 07:10:42 +08:00
|
|
|
GimpImage *gimage;
|
|
|
|
GimpPDBStatusType dummy;
|
2003-12-08 17:12:25 +08:00
|
|
|
gboolean success;
|
|
|
|
GError *error = NULL;
|
2002-04-17 04:25:27 +08:00
|
|
|
|
2003-01-25 01:38:24 +08:00
|
|
|
gimage = file_open_image (imagefile->gimp,
|
2003-12-08 17:12:25 +08:00
|
|
|
imagefile->thumbnail->image_uri,
|
|
|
|
imagefile->thumbnail->image_uri,
|
2002-04-29 07:10:42 +08:00
|
|
|
NULL,
|
|
|
|
GIMP_RUN_NONINTERACTIVE,
|
|
|
|
&dummy,
|
|
|
|
NULL);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
|
|
|
if (gimage)
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
success = gimp_imagefile_save_thumb (imagefile,
|
|
|
|
gimage, size, &error);
|
2002-04-17 04:25:27 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (gimage);
|
2002-04-19 20:05:47 +08:00
|
|
|
}
|
2002-04-29 07:10:42 +08:00
|
|
|
else
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
success = gimp_thumbnail_save_failure (imagefile->thumbnail,
|
|
|
|
"The GIMP " GIMP_VERSION,
|
|
|
|
&error);
|
2002-04-29 07:10:42 +08:00
|
|
|
}
|
2002-04-30 01:20:26 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
g_message (error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
2002-04-30 01:20:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-20 01:15:39 +08:00
|
|
|
gboolean
|
2002-04-30 04:27:54 +08:00
|
|
|
gimp_imagefile_save_thumbnail (GimpImagefile *imagefile,
|
|
|
|
GimpImage *gimage)
|
2002-04-19 20:05:47 +08:00
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
gboolean success;
|
|
|
|
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);
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
|
2002-04-30 03:41:45 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
success = gimp_imagefile_save_thumb (imagefile,
|
|
|
|
gimage,
|
|
|
|
gimage->gimp->config->thumbnail_size,
|
|
|
|
&error);
|
2002-04-19 20:05:47 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
if (! success)
|
2002-04-19 20:05:47 +08:00
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
g_message (error->message);
|
|
|
|
g_error_free (error);
|
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);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-09 17:07:17 +08:00
|
|
|
static TempBuf *
|
|
|
|
gimp_imagefile_get_new_preview (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
GimpImagefile *imagefile;
|
2001-11-13 11:31:47 +08:00
|
|
|
TempBuf *temp_buf;
|
|
|
|
|
|
|
|
imagefile = GIMP_IMAGEFILE (viewable);
|
|
|
|
|
2002-02-18 09:28:12 +08:00
|
|
|
if (! GIMP_OBJECT (imagefile)->name)
|
|
|
|
return NULL;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
temp_buf = gimp_imagefile_load_thumb (imagefile, MAX (width, height));
|
2001-11-13 11:31:47 +08:00
|
|
|
|
2003-02-27 00:15:50 +08:00
|
|
|
if (temp_buf)
|
|
|
|
{
|
|
|
|
gint preview_width;
|
|
|
|
gint preview_height;
|
|
|
|
|
2003-11-17 21:34:38 +08:00
|
|
|
gimp_viewable_calc_preview_size (temp_buf->width,
|
2003-02-27 00:15:50 +08:00
|
|
|
temp_buf->height,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
TRUE, 1.0, 1.0,
|
|
|
|
&preview_width,
|
|
|
|
&preview_height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (preview_width < temp_buf->width &&
|
|
|
|
preview_height < temp_buf->height)
|
|
|
|
{
|
|
|
|
TempBuf *scaled_buf;
|
|
|
|
|
|
|
|
scaled_buf = temp_buf_scale (temp_buf,
|
|
|
|
preview_width, preview_height);
|
|
|
|
|
|
|
|
temp_buf_free (temp_buf);
|
|
|
|
|
|
|
|
return scaled_buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-13 11:31:47 +08:00
|
|
|
return temp_buf;
|
|
|
|
}
|
|
|
|
|
2003-04-09 00:01:01 +08:00
|
|
|
static gchar *
|
|
|
|
gimp_imagefile_get_description (GimpViewable *viewable,
|
|
|
|
gchar **tooltip)
|
|
|
|
{
|
|
|
|
GimpImagefile *imagefile;
|
2003-12-08 17:12:25 +08:00
|
|
|
GimpThumbnail *thumbnail;
|
2003-04-09 00:01:01 +08:00
|
|
|
gchar *basename;
|
|
|
|
|
|
|
|
imagefile = GIMP_IMAGEFILE (viewable);
|
2003-12-08 17:12:25 +08:00
|
|
|
thumbnail = imagefile->thumbnail;
|
2003-04-09 00:01:01 +08:00
|
|
|
|
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;
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
filename = file_utils_uri_to_utf8_filename (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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
basename = file_utils_uri_to_utf8_basename (thumbnail->image_uri);
|
|
|
|
|
|
|
|
if (thumbnail->image_width > 0 && thumbnail->image_height > 0)
|
2003-04-09 00:01:01 +08:00
|
|
|
{
|
|
|
|
gchar *tmp = basename;
|
|
|
|
|
|
|
|
basename = g_strdup_printf ("%s (%d x %d)",
|
|
|
|
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;
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
case GIMP_THUMB_STATE_REMOTE:
|
2002-04-29 07:10:42 +08:00
|
|
|
imagefile->description = _("Remote image");
|
2002-04-17 07:59:53 +08:00
|
|
|
imagefile->static_desc = TRUE;
|
|
|
|
break;
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
case GIMP_THUMB_STATE_NOT_FOUND:
|
2003-11-14 23:33:40 +08:00
|
|
|
imagefile->description = _("Could not open");
|
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
|
|
|
|
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
|
|
|
|
|
|
|
g_string_append (str, size);
|
|
|
|
g_free (size);
|
2002-04-30 01:20:26 +08:00
|
|
|
|
|
|
|
g_string_append_c (str, '\n');
|
2002-04-29 07:10:42 +08:00
|
|
|
}
|
|
|
|
|
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:
|
2002-04-30 01:20:26 +08:00
|
|
|
g_string_append (str, _("No preview available"));
|
|
|
|
break;
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
case GIMP_THUMB_STATE_EXISTS:
|
2002-04-30 01:20:26 +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:
|
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:
|
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
|
|
|
{
|
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
|
|
|
{
|
|
|
|
g_string_append_printf (str, _("%d x %d pixels"),
|
2003-12-08 17:12:25 +08:00
|
|
|
thumbnail->image_width,
|
|
|
|
thumbnail->image_height);
|
2002-04-30 01:20:26 +08:00
|
|
|
g_string_append_c (str, '\n');
|
|
|
|
}
|
2003-11-14 23:33:40 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
if (thumbnail->image_type)
|
|
|
|
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);
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
if (thumbnail->image_num_layers == 1)
|
2002-04-30 01:20:26 +08:00
|
|
|
g_string_append (str, _("1 Layer"));
|
|
|
|
else
|
|
|
|
g_string_append_printf (str, _("%d Layers"),
|
2003-12-08 17:12:25 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-11-13 11:31:47 +08:00
|
|
|
static TempBuf *
|
2003-12-08 17:12:25 +08:00
|
|
|
gimp_imagefile_load_thumb (GimpImagefile *imagefile,
|
|
|
|
gint size)
|
2001-11-13 11:31:47 +08:00
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
GimpThumbnail *thumbnail;
|
|
|
|
TempBuf *temp_buf = NULL;
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
|
|
|
GError *error = NULL;
|
2002-04-29 07:10:42 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
thumbnail = imagefile->thumbnail;
|
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
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
pixbuf = gimp_thumbnail_load_thumb (thumbnail, size, &error);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
|
|
if (!pixbuf)
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
if (error)
|
|
|
|
g_message (_("Could not open thumbnail '%s': %s"),
|
|
|
|
thumbnail->thumb_filename, error->message);
|
2002-02-18 09:28:12 +08:00
|
|
|
goto cleanup;
|
2001-11-13 11:31:47 +08:00
|
|
|
}
|
2002-04-29 07:10:42 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
{
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint bytes;
|
|
|
|
guchar *src;
|
|
|
|
guchar *dest;
|
|
|
|
gint y;
|
2001-11-13 11:31:47 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
bytes = gdk_pixbuf_get_n_channels (pixbuf);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
temp_buf = temp_buf_new (width, height, bytes, 0, 0, NULL);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
dest = temp_buf_data (temp_buf);
|
|
|
|
src = gdk_pixbuf_get_pixels (pixbuf);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
memcpy (dest, src, width * bytes);
|
|
|
|
dest += width * bytes;
|
|
|
|
src += gdk_pixbuf_get_rowstride (pixbuf);
|
|
|
|
}
|
|
|
|
}
|
2001-11-13 11:31:47 +08:00
|
|
|
|
2002-02-18 09:28:12 +08:00
|
|
|
cleanup:
|
|
|
|
if (pixbuf)
|
2002-04-29 07:10:42 +08:00
|
|
|
g_object_unref (pixbuf);
|
2002-02-18 09:28:12 +08:00
|
|
|
if (error)
|
|
|
|
g_error_free (error);
|
2001-11-13 11:31:47 +08:00
|
|
|
|
|
|
|
return temp_buf;
|
|
|
|
}
|
|
|
|
|
2002-04-20 01:15:39 +08:00
|
|
|
static gboolean
|
2003-12-08 17:12:25 +08:00
|
|
|
gimp_imagefile_save_thumb (GimpImagefile *imagefile,
|
|
|
|
GimpImage *gimage,
|
|
|
|
gint size,
|
|
|
|
GError **error)
|
2002-04-19 20:05:47 +08:00
|
|
|
{
|
2004-01-06 10:33:08 +08:00
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
GimpImageType type;
|
|
|
|
const gchar *type_str;
|
|
|
|
gint num_layers;
|
|
|
|
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;
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
if (gimage->width <= size && gimage->height <= size)
|
2002-04-19 20:05:47 +08:00
|
|
|
{
|
|
|
|
width = gimage->width;
|
|
|
|
height = gimage->height;
|
2002-04-30 04:27:54 +08:00
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
size = MIN (size, MAX (width, height));
|
2002-04-19 20:05:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gimage->width < gimage->height)
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
height = size;
|
|
|
|
width = MAX (1, (size * gimage->width) / gimage->height);
|
2002-04-19 20:05:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-12-08 17:12:25 +08:00
|
|
|
width = size;
|
|
|
|
height = MAX (1, (size * gimage->height) / gimage->width);
|
2002-04-19 20:05:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-14 23:33:40 +08:00
|
|
|
pixbuf = gimp_viewable_get_new_preview_pixbuf (GIMP_VIEWABLE (gimage),
|
2002-04-19 20:05:47 +08:00
|
|
|
width, height);
|
|
|
|
|
2003-12-27 06:09:09 +08:00
|
|
|
/* when layer previews are disabled, we won't get a pixbuf */
|
|
|
|
if (! pixbuf)
|
|
|
|
return TRUE;
|
|
|
|
|
2004-01-06 10:33:08 +08:00
|
|
|
type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (gimp_image_base_type (gimage));
|
|
|
|
|
|
|
|
if (gimp_image_has_alpha (gimage))
|
|
|
|
type = GIMP_IMAGE_TYPE_WITH_ALPHA (type);
|
|
|
|
|
|
|
|
enum_class = g_type_class_peek (GIMP_TYPE_IMAGE_TYPE);
|
2004-01-06 22:29:35 +08:00
|
|
|
type_str = g_enum_get_value (enum_class, type)->value_name;
|
2004-01-06 10:33:08 +08:00
|
|
|
|
|
|
|
num_layers = gimp_container_num_children (gimage->layers);
|
|
|
|
|
|
|
|
g_object_set (imagefile->thumbnail,
|
|
|
|
"image-width", gimage->width,
|
|
|
|
"image-height", gimage->height,
|
|
|
|
"image-type", type_str,
|
|
|
|
"image-num-layers", num_layers,
|
|
|
|
NULL);
|
|
|
|
|
2003-12-08 17:12:25 +08:00
|
|
|
success = gimp_thumbnail_save_thumb (imagefile->thumbnail,
|
|
|
|
pixbuf,
|
|
|
|
"The GIMP " GIMP_VERSION,
|
|
|
|
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-01-11 07:55:28 +08:00
|
|
|
gimp_imagefile_update (imagefile);
|
2002-04-20 01:15:39 +08:00
|
|
|
|
|
|
|
return success;
|
2002-04-19 20:05:47 +08:00
|
|
|
}
|